libwifi 0.0.3
An 802.11 Frame Parsing and Generation library in C
reassoc_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 "reassoc_response.h"
17#include "../../core/frame/tag.h"
18#include "../../core/frame/tag_iterator.h"
19#include "../../core/misc/byteswap.h"
20#include "../../core/misc/epoch.h"
21#include "../../core/misc/types.h"
22#include "common.h"
23
24#include <errno.h>
25#include <stdint.h>
26#include <stdlib.h>
27#include <string.h>
28#include <sys/types.h>
29
35 return sizeof(struct libwifi_mgmt_unordered_frame_header) +
37 reassoc_resp->tags.length;
38}
39
45 int ret = 0;
46
47 if (reassoc_resp->tags.length != 0) {
48 ret = libwifi_remove_tag(&reassoc_resp->tags, TAG_DS_PARAMETER);
49 if (ret != 0) {
50 return ret;
51 }
52 }
53
54 const unsigned char *chan = (const unsigned char *) &channel;
55 ret = libwifi_quick_add_tag(&reassoc_resp->tags, TAG_DS_PARAMETER, chan, 1);
56
57 return ret;
58}
59
65 const unsigned char receiver[6],
66 const unsigned char transmitter[6],
67 const unsigned char address3[6],
68 uint8_t channel) {
69 memset(reassoc_resp, 0, sizeof(struct libwifi_reassoc_resp));
70
73 memcpy(&reassoc_resp->frame_header.addr1, receiver, 6);
74 memcpy(&reassoc_resp->frame_header.addr2, transmitter, 6);
75 memcpy(&reassoc_resp->frame_header.addr3, address3, 6);
76
79 reassoc_resp->fixed_parameters.association_id = rand() % 4096;
80
81 int ret = libwifi_set_reassoc_resp_channel(reassoc_resp, channel);
82
83 return ret;
84}
85
90size_t libwifi_dump_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, unsigned char *buf,
91 size_t buf_len) {
92 size_t reassoc_resp_len = libwifi_get_reassoc_resp_length(reassoc_resp);
93 if (reassoc_resp_len > buf_len) {
94 return -EINVAL;
95 }
96
97 size_t offset = 0;
98 memcpy(buf + offset, &reassoc_resp->frame_header, sizeof(struct libwifi_mgmt_unordered_frame_header));
99 offset += sizeof(struct libwifi_mgmt_unordered_frame_header);
100
101 memcpy(buf + offset, &reassoc_resp->fixed_parameters,
103 offset += sizeof(struct libwifi_reassoc_resp_fixed_parameters);
104
105 memcpy(buf + offset, reassoc_resp->tags.parameters, reassoc_resp->tags.length);
106 offset += reassoc_resp->tags.length;
107
108 return reassoc_resp_len;
109}
110
116 free(reassoc_resp->tags.parameters);
117}
#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_RESP
Definition: frame.h:40
@ 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
size_t libwifi_get_reassoc_resp_length(struct libwifi_reassoc_resp *reassoc_resp)
The length of a reassociation response frame is the sum of the header length, the fixed parameters le...
size_t libwifi_dump_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, unsigned char *buf, size_t buf_len)
Copy a libwifi_reassoc_resp into a regular unsigned char buffer.
void libwifi_free_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp)
Because the tagged parameters memory is managed inside of the library, the library must be the one to...
int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel)
Simple helper to set the reassociation response DS tag by removing it and then adding it back with th...
int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], const unsigned char transmitter[6], const unsigned char address3[6], uint8_t channel)
The generated reassoc_resp frame is made with sane defaults defined in common.h.
unsigned int type
Definition: frame.h:123
unsigned int subtype
Definition: frame.h:124
struct libwifi_frame_ctrl frame_control
Definition: frame.h:208
struct libwifi_tagged_parameters tags
struct libwifi_reassoc_resp_fixed_parameters fixed_parameters
struct libwifi_mgmt_unordered_frame_header frame_header
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
int libwifi_remove_tag(struct libwifi_tagged_parameters *tags, int tag_number)
Remove a tagged parameter from a list of frame tagged parameters.
Definition: tag.c:55
@ TAG_DS_PARAMETER
Definition: tag.h:27
size_t length
Definition: tag.h:0
@ STATUS_SUCCESS
Definition: types.h:88