libwifi 0.0.3
An 802.11 Frame Parsing and Generation library in C
assoc_response.c
Go to the documentation of this file.
1/* Copyright 2021 The libwifi Authors
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "../../core/frame/management/assoc_response.h"
17#include "../../core/frame/frame.h"
18#include "../../core/frame/tag.h"
19#include "../../core/frame/tag_iterator.h"
20#include "../../core/misc/types.h"
21#include "../../parse/misc/security.h"
22#include "assoc_response.h"
23#include "common.h"
24
25#include <errno.h>
26#include <stdlib.h>
27#include <string.h>
28
42int libwifi_parse_assoc_resp(struct libwifi_bss *bss, struct libwifi_frame *frame) {
43 memset(bss, 0, sizeof(struct libwifi_bss));
44
46 return -EINVAL;
47 }
48
49 if (frame->frame_control.flags.ordered) {
50 memcpy(bss->receiver, frame->header.mgmt_ordered.addr1, 6);
51 memcpy(bss->transmitter, frame->header.mgmt_ordered.addr2, 6);
52 memcpy(bss->bssid, frame->header.mgmt_ordered.addr3, 6);
53 } else {
54 memcpy(bss->receiver, frame->header.mgmt_unordered.addr1, 6);
55 memcpy(bss->transmitter, frame->header.mgmt_unordered.addr2, 6);
56 memcpy(bss->bssid, frame->header.mgmt_unordered.addr3, 6);
57 }
58
59 // Fixed Parameters must be present
60 if (frame->len <= (frame->header_len + sizeof(struct libwifi_assoc_resp_fixed_parameters))) {
61 return -EINVAL;
62 }
63
64 // At least one Tagged Parameter must be present
65 if (frame->len < (frame->header_len + sizeof(struct libwifi_assoc_resp_fixed_parameters) + 2)) {
66 return -EINVAL;
67 }
68
69 struct libwifi_assoc_resp_fixed_parameters *fixed_params =
72 bss->encryption_info |= WEP;
73 }
74
75 bss->tags.length =
76 (frame->len - (frame->header_len + sizeof(struct libwifi_assoc_resp_fixed_parameters)));
77 const unsigned char *tagged_params = frame->body + sizeof(struct libwifi_assoc_resp_fixed_parameters);
78 bss->tags.parameters = malloc(bss->tags.length);
79 memcpy(bss->tags.parameters, tagged_params, bss->tags.length);
80
81 // Iterate through common BSS tagged parameters (WPA, RSN, etc)
82 struct libwifi_tag_iterator it;
83 memset(&it, 0, sizeof(struct libwifi_tag_iterator));
84 if (libwifi_tag_iterator_init(&it, bss->tags.parameters, bss->tags.length) != 0) {
85 return -EINVAL;
86 }
87 if (libwifi_bss_tag_parser(bss, &it) != 0) {
88 return -EINVAL;
89 };
90
91 return 0;
92}
int libwifi_bss_tag_parser(struct libwifi_bss *bss, struct libwifi_tag_iterator *it)
This function is a parser for common and useful tags found in frames usually originating from the BSS...
Definition: common.c:139
#define WEP
Definition: security.h:86
@ SUBTYPE_ASSOC_RESP
Definition: frame.h:38
@ TYPE_MANAGEMENT
Definition: frame.h:31
int libwifi_parse_assoc_resp(struct libwifi_bss *bss, struct libwifi_frame *frame)
libwifi_parse_assoc_resp will parse useful information out of a Probe Response into a struct libwifi_...
struct libwifi_tagged_parameters tags
Definition: common.h:56
unsigned char transmitter[6]
Definition: common.h:45
uint64_t encryption_info
Definition: common.h:52
unsigned char receiver[6]
Definition: common.h:46
unsigned char bssid[6]
Definition: common.h:47
unsigned int ordered
Definition: frame.h:115
unsigned int type
Definition: frame.h:123
struct libwifi_frame_ctrl_flags flags
Definition: frame.h:125
unsigned int subtype
Definition: frame.h:124
union libwifi_frame_header header
Definition: frame.h:312
unsigned char * body
Definition: frame.h:314
size_t len
Definition: frame.h:311
struct libwifi_frame_ctrl frame_control
Definition: frame.h:310
size_t header_len
Definition: frame.h:313
unsigned char addr3[6]
Definition: frame.h:185
unsigned char addr2[6]
Definition: frame.h:184
unsigned char addr1[6]
Definition: frame.h:183
A libwifi_tag_iterator is used to iterate through a list of tagged parameters in a wifi frame.
Definition: tag_iterator.h:28
unsigned char * parameters
Definition: tag.h:235
int libwifi_tag_iterator_init(struct libwifi_tag_iterator *it, const void *tags_start, size_t data_len)
Initialise a libwifi frame tag iterator.
Definition: tag_iterator.c:21
#define libwifi_check_capabilities(x, cap)
Definition: types.h:199
@ CAPABILITIES_PRIVACY
Definition: types.h:205
struct libwifi_mgmt_unordered_frame_header mgmt_unordered
Definition: frame.h:290
struct libwifi_mgmt_ordered_frame_header mgmt_ordered
Definition: frame.h:289