libwifi 0.0.3
An 802.11 Frame Parsing and Generation library in C
deauthentication.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 "deauthentication.h"
17#include "common.h"
18
19#include <errno.h>
20#include <stdlib.h>
21#include <string.h>
22
41int libwifi_parse_deauth(struct libwifi_parsed_deauth *deauth, struct libwifi_frame *frame) {
42 memset(deauth, 0, sizeof(struct libwifi_parsed_deauth));
43
44 int tags_len = 0;
45
47 return -EINVAL;
48 }
49
50 deauth->ordered = frame->frame_control.flags.ordered;
51
52 if (deauth->ordered) {
53 memcpy(&deauth->frame_header.ordered, &frame->header.mgmt_ordered,
55 tags_len = (frame->len - sizeof(struct libwifi_mgmt_ordered_frame_header) -
56 sizeof(struct libwifi_deauth_fixed_parameters));
57 } else {
58 memcpy(&deauth->frame_header.unordered, &frame->header.mgmt_unordered,
60 tags_len = (frame->len - sizeof(struct libwifi_mgmt_unordered_frame_header) -
61 sizeof(struct libwifi_deauth_fixed_parameters));
62 }
63
64 unsigned char *body = (unsigned char *) frame->body;
65
66 memcpy(&deauth->fixed_parameters, body, sizeof(struct libwifi_deauth_fixed_parameters));
67 body += sizeof(struct libwifi_deauth_fixed_parameters);
68
69 deauth->tags.parameters = malloc(tags_len);
70 memcpy(&deauth->tags.parameters, body, tags_len);
71 memcpy(&deauth->tags.length, &tags_len, sizeof(tags_len));
72
73 return 0;
74}
@ SUBTYPE_DEAUTH
Definition: frame.h:49
@ TYPE_MANAGEMENT
Definition: frame.h:31
int libwifi_parse_deauth(struct libwifi_parsed_deauth *deauth, struct libwifi_frame *frame)
TODO: potentally write a parsed_to_gen function that converts a parsed deauth back into something tha...
Deauthentication Layout ────────────────────────── ┌──────────────────────────┐ │ Header │ Bytes: 24 ...
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
struct libwifi_tagged_parameters tags
struct libwifi_deauth_fixed_parameters fixed_parameters
union libwifi_mgmt_frame_header frame_header
unsigned char * parameters
Definition: tag.h:235
unsigned char * body
Definition: tag.h:1
struct libwifi_mgmt_unordered_frame_header mgmt_unordered
Definition: frame.h:290
struct libwifi_mgmt_ordered_frame_header mgmt_ordered
Definition: frame.h:289
struct libwifi_mgmt_ordered_frame_header ordered
Definition: frame.h:300
struct libwifi_mgmt_unordered_frame_header unordered
Definition: frame.h:301