libwifi 0.0.3
An 802.11 Frame Parsing and Generation library in C
probe_request.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 "probe_request.h"
17#include "../../core/frame/tag_iterator.h"
18#include "common.h"
19
20#include <errno.h>
21#include <stdlib.h>
22#include <string.h>
23
36int libwifi_parse_probe_req(struct libwifi_sta *sta, struct libwifi_frame *frame) {
37 memset(sta, 0, sizeof(struct libwifi_sta));
38
40 return -EINVAL;
41 }
42
43 if (frame->frame_control.flags.ordered) {
44 memcpy(sta->transmitter, frame->header.mgmt_ordered.addr2, 6);
45 memcpy(sta->bssid, frame->header.mgmt_ordered.addr3, 6);
46 } else {
47 memcpy(sta->transmitter, frame->header.mgmt_unordered.addr2, 6);
48 memcpy(sta->bssid, frame->header.mgmt_unordered.addr3, 6);
49 }
50
51 if (sta->transmitter[0] & 0x02) {
52 sta->randomized = 1;
53 } else {
54 sta->randomized = 0;
55 }
56
57 sta->tags.length = (frame->len - frame->header_len);
58 const unsigned char *tagged_params = frame->body;
59 sta->tags.parameters = malloc(sta->tags.length);
60 memcpy(sta->tags.parameters, tagged_params, sta->tags.length);
61
62 struct libwifi_tag_iterator it;
63 if (libwifi_tag_iterator_init(&it, sta->tags.parameters, sta->tags.length) != 0) {
64 return -EINVAL;
65 }
66
67 if (libwifi_sta_tag_parser(sta, &it) != 0) {
68 return -EINVAL;
69 }
70
71 return 0;
72}
int libwifi_sta_tag_parser(struct libwifi_sta *sta, struct libwifi_tag_iterator *it)
This function is a parser for common and useful tags found in frames usually originating from the STA...
Definition: common.c:177
@ SUBTYPE_PROBE_REQ
Definition: frame.h:41
@ TYPE_MANAGEMENT
Definition: frame.h:31
int libwifi_parse_probe_req(struct libwifi_sta *sta, struct libwifi_frame *frame)
libwifi_parse_probe_req will parse useful fields into a struct libwifi_sta.
Definition: probe_request.c:36
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
struct libwifi_tagged_parameters tags
Definition: common.h:89
unsigned char transmitter[6]
Definition: common.h:84
uint8_t randomized
Definition: common.h:83
unsigned char bssid[6]
Definition: common.h:86
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
struct libwifi_mgmt_unordered_frame_header mgmt_unordered
Definition: frame.h:290
struct libwifi_mgmt_ordered_frame_header mgmt_ordered
Definition: frame.h:289