libwifi 0.0.3
An 802.11 Frame Parsing and Generation library in C
reassoc_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 "reassoc_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
38int libwifi_parse_reassoc_req(struct libwifi_sta *sta, struct libwifi_frame *frame) {
39 memset(sta, 0, sizeof(struct libwifi_sta));
40
42 return -EINVAL;
43 }
44
45 if (frame->frame_control.flags.ordered) {
46 memcpy(sta->transmitter, frame->header.mgmt_ordered.addr2, 6);
47 memcpy(sta->bssid, frame->header.mgmt_ordered.addr3, 6);
48 } else {
49 memcpy(sta->transmitter, frame->header.mgmt_unordered.addr2, 6);
50 memcpy(sta->bssid, frame->header.mgmt_unordered.addr3, 6);
51 }
52
53 if (sta->transmitter[0] & 0x02) {
54 sta->randomized = 1;
55 } else {
56 sta->randomized = 0;
57 }
58
59 // Fixed Parameters must be present
60 if (frame->len <= (frame->header_len + sizeof(struct libwifi_reassoc_req_fixed_parameters))) {
61 return -EINVAL;
62 }
63
64 sta->tags.length = (frame->len - frame->header_len);
65 const unsigned char *tagged_params = frame->body;
66 sta->tags.parameters = malloc(sta->tags.length);
67 memcpy(sta->tags.parameters, tagged_params, sta->tags.length);
68
69 struct libwifi_tag_iterator it;
70 if (libwifi_tag_iterator_init(&it, sta->tags.parameters, sta->tags.length) != 0) {
71 return -EINVAL;
72 }
73
74 if (libwifi_sta_tag_parser(sta, &it) != 0) {
75 return -EINVAL;
76 }
77
78 return 0;
79}
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_REASSOC_REQ
Definition: frame.h:39
@ TYPE_MANAGEMENT
Definition: frame.h:31
int libwifi_parse_reassoc_req(struct libwifi_sta *sta, struct libwifi_frame *frame)
libwifi_parse_reassoc_req will parse useful fields into a struct libwifi_sta.
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
Reassociation Request Layout ─────────────────────────────── ┌───────────────────────────────┐ │ Head...
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