libwifi 0.0.3
An 802.11 Frame Parsing and Generation library in C
probe_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/probe_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 "common.h"
23#include "probe_response.h"
24
25#include <errno.h>
26#include <stdlib.h>
27#include <string.h>
28
42int libwifi_parse_probe_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->bssid, frame->header.mgmt_ordered.addr3, 6);
51 } else {
52 memcpy(bss->bssid, frame->header.mgmt_unordered.addr3, 6);
53 }
54
55 // Fixed Parameters must be present
56 if (frame->len <= (frame->header_len + sizeof(struct libwifi_probe_resp_fixed_parameters))) {
57 return -EINVAL;
58 }
59
60 // At least one Tagged Parameter must be present
61 if (frame->len < (frame->header_len + sizeof(struct libwifi_probe_resp_fixed_parameters) + 2)) {
62 return -EINVAL;
63 }
64
65 struct libwifi_probe_resp_fixed_parameters *fixed_params =
68 bss->encryption_info |= WEP;
69 }
70
71 bss->tags.length =
72 (frame->len - (frame->header_len + sizeof(struct libwifi_probe_resp_fixed_parameters)));
73 const unsigned char *tagged_params = frame->body + sizeof(struct libwifi_probe_resp_fixed_parameters);
74 bss->tags.parameters = malloc(bss->tags.length);
75 memcpy(bss->tags.parameters, tagged_params, bss->tags.length);
76
77 // Iterate through common BSS tagged parameters (WPA, RSN, etc)
78 struct libwifi_tag_iterator it;
79 memset(&it, 0, sizeof(struct libwifi_tag_iterator));
80 if (libwifi_tag_iterator_init(&it, bss->tags.parameters, bss->tags.length) != 0) {
81 return -EINVAL;
82 }
83 if (libwifi_bss_tag_parser(bss, &it) != 0) {
84 return -EINVAL;
85 };
86
87 return 0;
88}
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_PROBE_RESP
Definition: frame.h:42
@ TYPE_MANAGEMENT
Definition: frame.h:31
int libwifi_parse_probe_resp(struct libwifi_bss *bss, struct libwifi_frame *frame)
libwifi_parse_probe_resp will parse useful information out of a Probe Response into a struct libwifi_...
struct libwifi_tagged_parameters tags
Definition: common.h:56
uint64_t encryption_info
Definition: common.h:52
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
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