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/misc/byteswap.h"
18
19#include <errno.h>
20#include <stdlib.h>
21#include <string.h>
22
27 return sizeof(struct libwifi_mgmt_unordered_frame_header) + probe_req->tags.length;
28}
29
35 const unsigned char receiver[6],
36 const unsigned char transmitter[6],
37 const unsigned char address3[6],
38 const char *ssid,
39 uint8_t channel) {
40 memset(probe_req, 0, sizeof(struct libwifi_probe_req));
41
44 memcpy(&probe_req->frame_header.addr1, receiver, 6);
45 memcpy(&probe_req->frame_header.addr2, transmitter, 6);
46 memcpy(&probe_req->frame_header.addr3, address3, 6);
47 probe_req->frame_header.seq_control.sequence_number = (rand() % 4096);
48
49 int ret = libwifi_quick_add_tag(&probe_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid));
50 if (ret != 0) {
51 return ret;
52 }
53
54 ret = libwifi_quick_add_tag(&probe_req->tags, TAG_DS_PARAMETER, (const unsigned char *) &channel, 1);
55 return ret;
56}
57
62size_t libwifi_dump_probe_req(struct libwifi_probe_req *probe_req, unsigned char *buf, size_t buf_len) {
63 size_t probe_req_len = libwifi_get_probe_req_length(probe_req);
64 if (probe_req_len > buf_len) {
65 return -EINVAL;
66 }
67
68 size_t offset = 0;
69 memcpy(buf + offset, &probe_req->frame_header, sizeof(struct libwifi_mgmt_unordered_frame_header));
70 offset += sizeof(struct libwifi_mgmt_unordered_frame_header);
71
72 memcpy(buf + offset, probe_req->tags.parameters, probe_req->tags.length);
73 offset += probe_req->tags.length;
74
75 return probe_req_len;
76}
77
83 free(probe_req->tags.parameters);
84}
struct libwifi_tagged_parameters tags
Definition: assoc_request.h:2
struct libwifi_radiotap_channel channel
Definition: radiotap.h:3
@ SUBTYPE_PROBE_REQ
Definition: frame.h:41
@ TYPE_MANAGEMENT
Definition: frame.h:31
int libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], const unsigned char transmitter[6], const unsigned char address3[6], const char *ssid, uint8_t channel)
The generated probe request frame is made with sane defaults defined in common.h.
Definition: probe_request.c:34
void libwifi_free_probe_req(struct libwifi_probe_req *probe_req)
Because the tagged parameters memory is managed inside of the library, the library must be the one to...
Definition: probe_request.c:82
size_t libwifi_dump_probe_req(struct libwifi_probe_req *probe_req, unsigned char *buf, size_t buf_len)
Copy a libwifi_probe_req into a regular unsigned char buffer.
Definition: probe_request.c:62
size_t libwifi_get_probe_req_length(struct libwifi_probe_req *probe_req)
The length of a probe request frame is the sum of the header length plus the tagged parameters length...
Definition: probe_request.c:26
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
struct libwifi_tagged_parameters tags
Definition: probe_request.h:35
struct libwifi_mgmt_unordered_frame_header frame_header
Definition: probe_request.h:34
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