libwifi 0.0.3
An 802.11 Frame Parsing and Generation library in C
data.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 "data.h"
17
18#include <errno.h>
19#include <stdlib.h>
20#include <string.h>
21
22int libwifi_parse_data(struct libwifi_data *data, struct libwifi_frame *frame) {
23 if (frame->frame_control.type != TYPE_DATA) {
24 return -EINVAL;
25 }
26
27 if (frame->flags & LIBWIFI_FLAGS_IS_QOS) {
28 memcpy(data->receiver, frame->header.data_qos.addr1, 6);
29 memcpy(data->transmitter, frame->header.data_qos.addr2, 6);
30 } else {
31 memcpy(data->receiver, frame->header.data.addr1, 6);
32 memcpy(data->transmitter, frame->header.data.addr2, 6);
33 }
34
35 data->body_len = frame->len - frame->header_len;
36
37 data->body = malloc(data->body_len);
38 if (data->body == NULL) {
39 return -ENOMEM;
40 }
41 memcpy(frame->body, data->body, data->body_len);
42
43 return 0;
44}
45
46void libwifi_free_data(struct libwifi_data *data) {
47 free(data->body);
48}
int libwifi_parse_data(struct libwifi_data *data, struct libwifi_frame *frame)
Definition: data.c:22
void libwifi_free_data(struct libwifi_data *data)
Definition: data.c:46
@ TYPE_DATA
Definition: frame.h:33
#define LIBWIFI_FLAGS_IS_QOS
Definition: frame.h:26
unsigned char addr2[6]
Definition: frame.h:251
unsigned char addr1[6]
Definition: frame.h:250
unsigned char addr2[6]
Definition: frame.h:279
unsigned char addr1[6]
Definition: frame.h:278
unsigned char transmitter[6]
Definition: data.h:26
size_t body_len
Definition: data.h:29
unsigned char * body
Definition: data.h:28
unsigned char receiver[6]
Definition: data.h:27
unsigned int type
Definition: frame.h:123
union libwifi_frame_header header
Definition: frame.h:312
uint16_t flags
Definition: frame.h:309
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
struct libwifi_data_qos_frame_header data_qos
Definition: frame.h:293
struct libwifi_data_frame_header data
Definition: frame.h:292