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 "common.h"
18
19#include <errno.h>
20#include <stdlib.h>
21#include <string.h>
22
28 return sizeof(struct libwifi_mgmt_unordered_frame_header) +
30 reassoc_req->tags.length;
31}
32
38 const unsigned char receiver[6],
39 const unsigned char transmitter[6],
40 const unsigned char address3[6],
41 const unsigned char current_ap[6],
42 const char *ssid,
43 uint8_t channel) {
44 memset(reassoc_req, 0, sizeof(struct libwifi_reassoc_req));
45
48 memcpy(&reassoc_req->frame_header.addr1, receiver, 6);
49 memcpy(&reassoc_req->frame_header.addr2, transmitter, 6);
50 memcpy(&reassoc_req->frame_header.addr3, address3, 6);
51 reassoc_req->frame_header.seq_control.sequence_number = (rand() % 4096);
52
55 memcpy(&reassoc_req->fixed_parameters.current_ap_address, current_ap, 6);
56
57 int ret = libwifi_quick_add_tag(&reassoc_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid));
58 if (ret != 0) {
59 return ret;
60 }
61
62 ret = libwifi_quick_add_tag(&reassoc_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1);
63
64 return ret;
65}
66
71size_t libwifi_dump_reassoc_req(struct libwifi_reassoc_req *reassoc_req, unsigned char *buf, size_t buf_len) {
72 size_t reassoc_req_len = libwifi_get_reassoc_req_length(reassoc_req);
73 if (reassoc_req_len > buf_len) {
74 return -EINVAL;
75 }
76
77 size_t offset = 0;
78 memcpy(buf + offset, &reassoc_req->frame_header, sizeof(struct libwifi_mgmt_unordered_frame_header));
79 offset += sizeof(struct libwifi_mgmt_unordered_frame_header);
80
81 memcpy(buf + offset, &reassoc_req->fixed_parameters, sizeof(struct libwifi_reassoc_req_fixed_parameters));
82 offset += sizeof(struct libwifi_reassoc_req_fixed_parameters);
83
84 memcpy(buf + offset, reassoc_req->tags.parameters, reassoc_req->tags.length);
85 offset += reassoc_req->tags.length;
86
87 return reassoc_req_len;
88}
89
95 free(reassoc_req->tags.parameters);
96}
#define BYTESWAP16(x)
Definition: byteswap.h:22
struct libwifi_tagged_parameters tags
Definition: assoc_request.h:2
struct libwifi_radiotap_channel channel
Definition: radiotap.h:3
@ SUBTYPE_REASSOC_REQ
Definition: frame.h:39
@ TYPE_MANAGEMENT
Definition: frame.h:31
#define LIBWIFI_DEFAULT_AP_CAPABS
A sane default for an AP-side capabilities information field.
Definition: common.h:24
#define LIBWIFI_DEFAULT_LISTEN_INTERVAL
A sane default for the listen_interval field.
Definition: common.h:38
void libwifi_free_reassoc_req(struct libwifi_reassoc_req *reassoc_req)
Because the tagged parameters memory is managed inside of the library, the library must be the one to...
int libwifi_create_reassoc_req(struct libwifi_reassoc_req *reassoc_req, const unsigned char receiver[6], const unsigned char transmitter[6], const unsigned char address3[6], const unsigned char current_ap[6], const char *ssid, uint8_t channel)
The generated reassociation request frame is made with sane defaults defined in common....
size_t libwifi_get_reassoc_req_length(struct libwifi_reassoc_req *reassoc_req)
The length of a reassociation request frame is the sum of the header length, the fixed parameters len...
size_t libwifi_dump_reassoc_req(struct libwifi_reassoc_req *reassoc_req, unsigned char *buf, size_t buf_len)
Copy a libwifi_reassoc_req into a regular unsigned char buffer.
unsigned int type
Definition: frame.h:123
unsigned int subtype
Definition: frame.h:124
struct libwifi_seq_control seq_control
Definition: frame.h:213
struct libwifi_frame_ctrl frame_control
Definition: frame.h:208
Reassociation Request Layout ─────────────────────────────── ┌───────────────────────────────┐ │ Head...
struct libwifi_tagged_parameters tags
struct libwifi_reassoc_req_fixed_parameters fixed_parameters
struct libwifi_mgmt_unordered_frame_header frame_header
unsigned int sequence_number
Definition: frame.h:133
unsigned char * parameters
Definition: tag.h:235
int libwifi_quick_add_tag(struct libwifi_tagged_parameters *tags, int tag_number, const unsigned char *tag_data, size_t tag_length)
Add a tagged parameter via tag number and data to a management frame.
Definition: tag.c:118
@ TAG_SSID
Definition: tag.h:24
@ TAG_DS_PARAMETER
Definition: tag.h:27
size_t length
Definition: tag.h:0