about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libwifi/core/core.h4
-rw-r--r--src/libwifi/gen/management/action.c18
-rw-r--r--src/libwifi/gen/management/action.h32
-rw-r--r--src/libwifi/gen/management/assoc_request.c10
-rw-r--r--src/libwifi/gen/management/assoc_request.h36
-rw-r--r--src/libwifi/gen/management/assoc_response.c11
-rw-r--r--src/libwifi/gen/management/assoc_response.h27
-rw-r--r--src/libwifi/gen/management/atim.c8
-rw-r--r--src/libwifi/gen/management/atim.h15
-rw-r--r--src/libwifi/gen/management/authentication.c12
-rw-r--r--src/libwifi/gen/management/authentication.h31
-rw-r--r--src/libwifi/gen/management/beacon.c18
-rw-r--r--src/libwifi/gen/management/beacon.h30
-rw-r--r--src/libwifi/gen/management/deauthentication.c9
-rw-r--r--src/libwifi/gen/management/deauthentication.h22
-rw-r--r--src/libwifi/gen/management/disassociation.c9
-rw-r--r--src/libwifi/gen/management/disassociation.h22
-rw-r--r--src/libwifi/gen/management/probe_request.c11
-rw-r--r--src/libwifi/gen/management/probe_request.h27
-rw-r--r--src/libwifi/gen/management/probe_response.c22
-rw-r--r--src/libwifi/gen/management/probe_response.h39
-rw-r--r--src/libwifi/gen/management/reassoc_request.c15
-rw-r--r--src/libwifi/gen/management/reassoc_request.h41
-rw-r--r--src/libwifi/gen/management/reassoc_response.c19
-rw-r--r--src/libwifi/gen/management/reassoc_response.h25
-rw-r--r--src/libwifi/gen/management/timing_ad.c15
-rw-r--r--src/libwifi/gen/management/timing_ad.h50
27 files changed, 394 insertions, 184 deletions
diff --git a/src/libwifi/core/core.h b/src/libwifi/core/core.h index 02e6d45..75043a6 100644 --- a/src/libwifi/core/core.h +++ b/src/libwifi/core/core.h
@@ -16,7 +16,9 @@
16#ifndef LIBWIFI_CORE_H 16#ifndef LIBWIFI_CORE_H
17#define LIBWIFI_CORE_H 17#define LIBWIFI_CORE_H
18 18
19#define LIBWIFI_VERSION "0.0.1" 19#ifndef LIBWIFI_VERSION
20#define LIBWIFI_VERSION "UNSET_VERSION"
21#endif
20 22
21/** 23/**
22 * Commonly used fixed fields 24 * Commonly used fixed fields
diff --git a/src/libwifi/gen/management/action.c b/src/libwifi/gen/management/action.c index 04d7a5f..dc37987 100644 --- a/src/libwifi/gen/management/action.c +++ b/src/libwifi/gen/management/action.c
@@ -46,15 +46,18 @@ void libwifi_free_action_detail(struct libwifi_action_detail *detail) {
46 } 46 }
47} 47}
48 48
49int libwifi_create_action(struct libwifi_action *action, const unsigned char receiver[6], 49int libwifi_create_action(struct libwifi_action *action,
50 const unsigned char transmitter[6], uint8_t category) { 50 const unsigned char receiver[6],
51 const unsigned char transmitter[6],
52 const unsigned char address3[6],
53 uint8_t category) {
51 memset(action, 0, sizeof(struct libwifi_action)); 54 memset(action, 0, sizeof(struct libwifi_action));
52 55
53 action->frame_header.frame_control.type = TYPE_MANAGEMENT; 56 action->frame_header.frame_control.type = TYPE_MANAGEMENT;
54 action->frame_header.frame_control.subtype = SUBTYPE_ACTION; 57 action->frame_header.frame_control.subtype = SUBTYPE_ACTION;
55 memcpy(&action->frame_header.addr1, receiver, 6); 58 memcpy(&action->frame_header.addr1, receiver, 6);
56 memcpy(&action->frame_header.addr2, transmitter, 6); 59 memcpy(&action->frame_header.addr2, transmitter, 6);
57 memcpy(&action->frame_header.addr3, transmitter, 6); 60 memcpy(&action->frame_header.addr3, address3, 6);
58 61
59 action->frame_header.seq_control.sequence_number = (rand() % 4096); 62 action->frame_header.seq_control.sequence_number = (rand() % 4096);
60 63
@@ -63,15 +66,18 @@ int libwifi_create_action(struct libwifi_action *action, const unsigned char rec
63 return 0; 66 return 0;
64} 67}
65 68
66int libwifi_create_action_no_ack(struct libwifi_action *action, const unsigned char receiver[6], 69int libwifi_create_action_no_ack(struct libwifi_action *action,
67 const unsigned char transmitter[6], uint8_t category) { 70 const unsigned char receiver[6],
71 const unsigned char transmitter[6],
72 const unsigned char address3[6],
73 uint8_t category) {
68 memset(action, 0, sizeof(struct libwifi_action)); 74 memset(action, 0, sizeof(struct libwifi_action));
69 75
70 action->frame_header.frame_control.type = TYPE_MANAGEMENT; 76 action->frame_header.frame_control.type = TYPE_MANAGEMENT;
71 action->frame_header.frame_control.subtype = SUBTYPE_ACTION_NOACK; 77 action->frame_header.frame_control.subtype = SUBTYPE_ACTION_NOACK;
72 memcpy(&action->frame_header.addr1, receiver, 6); 78 memcpy(&action->frame_header.addr1, receiver, 6);
73 memcpy(&action->frame_header.addr2, transmitter, 6); 79 memcpy(&action->frame_header.addr2, transmitter, 6);
74 memcpy(&action->frame_header.addr3, transmitter, 6); 80 memcpy(&action->frame_header.addr3, address3, 6);
75 81
76 action->frame_header.seq_control.sequence_number = (rand() % 4096); 82 action->frame_header.seq_control.sequence_number = (rand() % 4096);
77 83
diff --git a/src/libwifi/gen/management/action.h b/src/libwifi/gen/management/action.h index ae1b5cc..2073f7d 100644 --- a/src/libwifi/gen/management/action.h +++ b/src/libwifi/gen/management/action.h
@@ -23,12 +23,13 @@
23 * Create a detail for an action frame by supplying raw data and it's length. 23 * Create a detail for an action frame by supplying raw data and it's length.
24 * New data can be added to an existing libwifi_action_detail. 24 * New data can be added to an existing libwifi_action_detail.
25 * 25 *
26 * @param detail A libwifi_action_detail struct 26 * @param detail A libwifi_action_detail struct
27 * @param data Raw data to be added to the libwifi_action_detail 27 * @param data Raw data to be added to the libwifi_action_detail
28 * @param data_len Length of the raw data 28 * @param data_len Length of the raw data
29 * @return Length of the action 29 * @return Length of the action, or negative error
30 */ 30 */
31size_t libwifi_add_action_detail(struct libwifi_action_detail *detail, const unsigned char *data, 31size_t libwifi_add_action_detail(struct libwifi_action_detail *detail,
32 const unsigned char *data,
32 size_t data_len); 33 size_t data_len);
33 34
34/** 35/**
@@ -44,13 +45,20 @@ void libwifi_free_action_detail(struct libwifi_action_detail *detail);
44 * @param action A new libwifi_action struct 45 * @param action A new libwifi_action struct
45 * @param receiver The receiver MAC address 46 * @param receiver The receiver MAC address
46 * @param transmitter The transmitter MAC address 47 * @param transmitter The transmitter MAC address
48 * @param address3 The address 3 frame field value, typically the BSSID
47 * @param category The action frame category 49 * @param category The action frame category
48 * @return zero on success 50 * @return Zero on success, or negative error
49 */ 51 */
50int libwifi_create_action(struct libwifi_action *action, const unsigned char receiver[6], 52int libwifi_create_action(struct libwifi_action *action,
51 const unsigned char transmitter[6], uint8_t category); 53 const unsigned char receiver[6],
52int libwifi_create_action_no_ack(struct libwifi_action *action, const unsigned char receiver[6], 54 const unsigned char transmitter[6],
53 const unsigned char transmitter[6], uint8_t category); 55 const unsigned char address3[6],
56 uint8_t category);
57int libwifi_create_action_no_ack(struct libwifi_action *action,
58 const unsigned char receiver[6],
59 const unsigned char transmitter[6],
60 const unsigned char address3[6],
61 uint8_t category);
54 62
55/** 63/**
56 * Get the length of a given libwifi_action 64 * Get the length of a given libwifi_action
@@ -63,10 +71,10 @@ size_t libwifi_get_action_length(struct libwifi_action *action);
63/** 71/**
64 * Dump a given libwifi_action to a raw buffer 72 * Dump a given libwifi_action to a raw buffer
65 * 73 *
66 * @param action A used libwifi_action struct 74 * @param action A used libwifi_action struct
67 * @param buf A buffer receiver 75 * @param buf A buffer receiver
68 * @param buf_len The length of the given buf 76 * @param buf_len The length of the given buf
69 * @return Bytes written to the buf 77 * @return Bytes written to the buf, or negative error
70 */ 78 */
71size_t libwifi_dump_action(struct libwifi_action *action, unsigned char *buf, size_t buf_len); 79size_t libwifi_dump_action(struct libwifi_action *action, unsigned char *buf, size_t buf_len);
72 80
diff --git a/src/libwifi/gen/management/assoc_request.c b/src/libwifi/gen/management/assoc_request.c index 268b167..e9d720e 100644 --- a/src/libwifi/gen/management/assoc_request.c +++ b/src/libwifi/gen/management/assoc_request.c
@@ -33,15 +33,19 @@ size_t libwifi_get_assoc_req_length(struct libwifi_assoc_req *assoc_req) {
33 * The generated association request frame is made with sane defaults defined in common.h. 33 * The generated association request frame is made with sane defaults defined in common.h.
34 * Two tagged parameters are also added to the association request: SSID and Channel. 34 * Two tagged parameters are also added to the association request: SSID and Channel.
35 */ 35 */
36int libwifi_create_assoc_req(struct libwifi_assoc_req *assoc_req, const unsigned char receiver[6], 36int libwifi_create_assoc_req(struct libwifi_assoc_req *assoc_req,
37 const unsigned char transmitter[6], const char *ssid, uint8_t channel) { 37 const unsigned char receiver[6],
38 const unsigned char transmitter[6],
39 const unsigned char address3[6],
40 const char *ssid,
41 uint8_t channel) {
38 memset(assoc_req, 0, sizeof(struct libwifi_assoc_req)); 42 memset(assoc_req, 0, sizeof(struct libwifi_assoc_req));
39 43
40 assoc_req->frame_header.frame_control.type = TYPE_MANAGEMENT; 44 assoc_req->frame_header.frame_control.type = TYPE_MANAGEMENT;
41 assoc_req->frame_header.frame_control.subtype = SUBTYPE_ASSOC_REQ; 45 assoc_req->frame_header.frame_control.subtype = SUBTYPE_ASSOC_REQ;
42 memcpy(&assoc_req->frame_header.addr1, receiver, 6); 46 memcpy(&assoc_req->frame_header.addr1, receiver, 6);
43 memcpy(&assoc_req->frame_header.addr2, transmitter, 6); 47 memcpy(&assoc_req->frame_header.addr2, transmitter, 6);
44 memcpy(&assoc_req->frame_header.addr3, receiver, 6); 48 memcpy(&assoc_req->frame_header.addr3, address3, 6);
45 assoc_req->frame_header.seq_control.sequence_number = (rand() % 4096); 49 assoc_req->frame_header.seq_control.sequence_number = (rand() % 4096);
46 50
47 assoc_req->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); 51 assoc_req->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS);
diff --git a/src/libwifi/gen/management/assoc_request.h b/src/libwifi/gen/management/assoc_request.h index 85cbd3b..fc43d03 100644 --- a/src/libwifi/gen/management/assoc_request.h +++ b/src/libwifi/gen/management/assoc_request.h
@@ -24,16 +24,44 @@
24 * Create a new association request 24 * Create a new association request
25 * 25 *
26 * @param assoc_req A new libwifi_assoc_req struct 26 * @param assoc_req A new libwifi_assoc_req struct
27 * @param receiver The receiver MAC address 27 * @param receiver The receiver MAC address
28 * @param transmitter The transmitter MAC address 28 * @param transmitter The transmitter MAC address
29 * @param address3 The address 3 frame field value, typically the BSSID
29 * @param ssid The desired BSS SSID 30 * @param ssid The desired BSS SSID
30 * @param channel The desired channel 31 * @param channel The desired channel
31 * @param zero on success 32 * @param Zero on success, or negative error
33 */
34int libwifi_create_assoc_req(struct libwifi_assoc_req *assoc_req,
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
41/**
42 * Get the length of a given libwifi_assoc_req
43 *
44 * @param assoc_req A libwifi_assoc_req struct
45 * @return Length of the given libwifi_assoc_req
32 */ 46 */
33int libwifi_create_assoc_req(struct libwifi_assoc_req *assoc_req, const unsigned char receiver[6],
34 const unsigned char transmitter[6], const char *ssid, uint8_t channel);
35size_t libwifi_get_assoc_req_length(struct libwifi_assoc_req *assoc_req); 47size_t libwifi_get_assoc_req_length(struct libwifi_assoc_req *assoc_req);
48
49/**
50 * Dump a libwifi_assoc_req into a raw format for packet injection.
51 *
52 * @param assoc_req A libwifi_assoc_req struct
53 * @param buf The buffer to dump into
54 * @param buf_len The length of the supplied buffer
55 * @param The amount of bytes dumped, or negative error
56 */
36size_t libwifi_dump_assoc_req(struct libwifi_assoc_req *assoc_req, unsigned char *buf, size_t buf_len); 57size_t libwifi_dump_assoc_req(struct libwifi_assoc_req *assoc_req, unsigned char *buf, size_t buf_len);
58
59
60/**
61 * Free any memory claimed by a libwifi_assoc_req back to the system.
62 *
63 * @param assoc_req A libwifi_assoc_req
64 */
37void libwifi_free_assoc_req(struct libwifi_assoc_req *assoc_req); 65void libwifi_free_assoc_req(struct libwifi_assoc_req *assoc_req);
38 66
39#endif /* LIBWIFI_GEN_ASSOCREQUEST_H */ 67#endif /* LIBWIFI_GEN_ASSOCREQUEST_H */
diff --git a/src/libwifi/gen/management/assoc_response.c b/src/libwifi/gen/management/assoc_response.c index 70f53d6..0fd145c 100644 --- a/src/libwifi/gen/management/assoc_response.c +++ b/src/libwifi/gen/management/assoc_response.c
@@ -33,7 +33,8 @@
33 */ 33 */
34size_t libwifi_get_assoc_resp_length(struct libwifi_assoc_resp *assoc_resp) { 34size_t libwifi_get_assoc_resp_length(struct libwifi_assoc_resp *assoc_resp) {
35 return sizeof(struct libwifi_mgmt_unordered_frame_header) + 35 return sizeof(struct libwifi_mgmt_unordered_frame_header) +
36 sizeof(struct libwifi_assoc_resp_fixed_parameters) + assoc_resp->tags.length; 36 sizeof(struct libwifi_assoc_resp_fixed_parameters) +
37 assoc_resp->tags.length;
37} 38}
38 39
39/** 40/**
@@ -61,14 +62,18 @@ int libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_
61 * The generated association response frame is made with sane defaults defined in common.h and core/types.h. 62 * The generated association response frame is made with sane defaults defined in common.h and core/types.h.
62 * Two tagged parameters are also added to the association response: Channel and Supported Rates. 63 * Two tagged parameters are also added to the association response: Channel and Supported Rates.
63 */ 64 */
64int libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], 65int libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp,
65 const unsigned char transmitter[6], uint8_t channel) { 66 const unsigned char receiver[6],
67 const unsigned char transmitter[6],
68 const unsigned char address3[6],
69 uint8_t channel) {
66 memset(assoc_resp, 0, sizeof(struct libwifi_assoc_resp)); 70 memset(assoc_resp, 0, sizeof(struct libwifi_assoc_resp));
67 71
68 assoc_resp->frame_header.frame_control.type = TYPE_MANAGEMENT; 72 assoc_resp->frame_header.frame_control.type = TYPE_MANAGEMENT;
69 assoc_resp->frame_header.frame_control.subtype = SUBTYPE_ASSOC_RESP; 73 assoc_resp->frame_header.frame_control.subtype = SUBTYPE_ASSOC_RESP;
70 memcpy(&assoc_resp->frame_header.addr1, receiver, 6); 74 memcpy(&assoc_resp->frame_header.addr1, receiver, 6);
71 memcpy(&assoc_resp->frame_header.addr2, transmitter, 6); 75 memcpy(&assoc_resp->frame_header.addr2, transmitter, 6);
76 memcpy(&assoc_resp->frame_header.addr3, address3, 6);
72 77
73 assoc_resp->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); 78 assoc_resp->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS);
74 assoc_resp->fixed_parameters.status_code = STATUS_SUCCESS; 79 assoc_resp->fixed_parameters.status_code = STATUS_SUCCESS;
diff --git a/src/libwifi/gen/management/assoc_response.h b/src/libwifi/gen/management/assoc_response.h index 07ad4b4..cac0171 100644 --- a/src/libwifi/gen/management/assoc_response.h +++ b/src/libwifi/gen/management/assoc_response.h
@@ -22,7 +22,8 @@
22 * Set the channel of a libwifi_assoc_resp. 22 * Set the channel of a libwifi_assoc_resp.
23 * 23 *
24 * @param assoc_resp A libwifi_assoc_resp 24 * @param assoc_resp A libwifi_assoc_resp
25 * @param channel The new channel 25 * @param channel The new channel
26 * @return Zero on success, or negative error
26 */ 27 */
27int libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel); 28int libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_t channel);
28 29
@@ -30,7 +31,7 @@ int libwifi_set_assoc_resp_channel(struct libwifi_assoc_resp *assoc_resp, uint8_
30 * Calculate the length of a given libwifi_assoc_resp 31 * Calculate the length of a given libwifi_assoc_resp
31 * 32 *
32 * @param assoc_resp A libwifi_assoc_resp 33 * @param assoc_resp A libwifi_assoc_resp
33 * @return The length of the given assoc_resp 34 * @return The length of the given assoc_resp, or negative error
34 */ 35 */
35size_t libwifi_get_assoc_resp_length(struct libwifi_assoc_resp *assoc_resp); 36size_t libwifi_get_assoc_resp_length(struct libwifi_assoc_resp *assoc_resp);
36 37
@@ -40,22 +41,26 @@ size_t libwifi_get_assoc_resp_length(struct libwifi_assoc_resp *assoc_resp);
40 * A generated libwifi assoc_resp can be "dumped" into a buffer for packet injection 41 * A generated libwifi assoc_resp can be "dumped" into a buffer for packet injection
41 * via the libwifi_dump_assoc_resp. 42 * via the libwifi_dump_assoc_resp.
42 * 43 *
43 * @param assoc_resp A libwifi_assoc_resp 44 * @param assoc_resp A libwifi_assoc_resp
44 * @param receiver The receiver MAC address, aka address 1 45 * @param receiver The receiver MAC address, aka address 1
45 * @param transmitter The source MAC address, aka address 2 46 * @param transmitter The source MAC address, aka address 2
46 * @param channel The desired channel of the assoc_resp 47 * @param address3 The address 3 frame field value, typically the BSSID
47 * 48 * @param channel The desired channel of the assoc_resp
49 * @return Zero on success, or negative error
48 */ 50 */
49int libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp, const unsigned char receiver[6], 51int libwifi_create_assoc_resp(struct libwifi_assoc_resp *assoc_resp,
50 const unsigned char transmitter[6], uint8_t channel); 52 const unsigned char receiver[6],
53 const unsigned char transmitter[6],
54 const unsigned char address3[6],
55 uint8_t channel);
51 56
52/** 57/**
53 * Dump a libwifi_assoc_resp into a raw format for packet injection. 58 * Dump a libwifi_assoc_resp into a raw format for packet injection.
54 * 59 *
55 * @param assoc_resp A libwifi_assoc_resp 60 * @param assoc_resp A libwifi_assoc_resp
56 * @param buf The output buffer for the frame data 61 * @param buf The output buffer for the frame data
57 * @param buf_len The length of the output buffer 62 * @param buf_len The length of the output buffer
58 * @return The length of the dumped assoc_resp 63 * @return The length of the dumped assoc_resp, or negative error
59 */ 64 */
60size_t libwifi_dump_assoc_resp(struct libwifi_assoc_resp *assoc_resp, unsigned char *buf, size_t buf_len); 65size_t libwifi_dump_assoc_resp(struct libwifi_assoc_resp *assoc_resp, unsigned char *buf, size_t buf_len);
61 66
diff --git a/src/libwifi/gen/management/atim.c b/src/libwifi/gen/management/atim.c index 960a2de..60b5203 100644 --- a/src/libwifi/gen/management/atim.c +++ b/src/libwifi/gen/management/atim.c
@@ -18,15 +18,17 @@
18#include <stdlib.h> 18#include <stdlib.h>
19#include <string.h> 19#include <string.h>
20 20
21int libwifi_create_atim(struct libwifi_atim *atim, const unsigned char transmitter[6], 21int libwifi_create_atim(struct libwifi_atim *atim,
22 const unsigned char receiver[6], const unsigned char bssid[6]) { 22 const unsigned char transmitter[6],
23 const unsigned char receiver[6],
24 const unsigned char address3[6]) {
23 memset(atim, 0, sizeof(struct libwifi_atim)); 25 memset(atim, 0, sizeof(struct libwifi_atim));
24 26
25 atim->frame_header.frame_control.type = TYPE_MANAGEMENT; 27 atim->frame_header.frame_control.type = TYPE_MANAGEMENT;
26 atim->frame_header.frame_control.subtype = SUBTYPE_ATIM; 28 atim->frame_header.frame_control.subtype = SUBTYPE_ATIM;
27 memcpy(&atim->frame_header.addr1, transmitter, 6); 29 memcpy(&atim->frame_header.addr1, transmitter, 6);
28 memcpy(&atim->frame_header.addr2, receiver, 6); 30 memcpy(&atim->frame_header.addr2, receiver, 6);
29 memcpy(&atim->frame_header.addr3, bssid, 6); 31 memcpy(&atim->frame_header.addr3, address3, 6);
30 atim->frame_header.frame_control.flags.power_mgmt = 1; 32 atim->frame_header.frame_control.flags.power_mgmt = 1;
31 atim->frame_header.duration = (rand() % 4096); 33 atim->frame_header.duration = (rand() % 4096);
32 atim->frame_header.seq_control.sequence_number = (rand() % 4096); 34 atim->frame_header.seq_control.sequence_number = (rand() % 4096);
diff --git a/src/libwifi/gen/management/atim.h b/src/libwifi/gen/management/atim.h index d9a306a..ca3b8a4 100644 --- a/src/libwifi/gen/management/atim.h +++ b/src/libwifi/gen/management/atim.h
@@ -18,7 +18,18 @@
18 18
19#include "../../core/frame/management/atim.h" 19#include "../../core/frame/management/atim.h"
20 20
21int libwifi_create_atim(struct libwifi_atim *atim, const unsigned char transmitter[6], 21/**
22 const unsigned char receiver[6], const unsigned char bssid[6]); 22 * Generate a populated ATIM frame.
23 *
24 * @param atim A new libwifi_atim struct
25 * @param transmitter The transmitter address, aka address 1
26 * @param receiver The receiver address, aka address 2
27 * @param address3 The address 3 frame value, typically the BSSID
28 * @return Zero on success, or negative error
29*/
30int libwifi_create_atim(struct libwifi_atim *atim,
31 const unsigned char transmitter[6],
32 const unsigned char receiver[6],
33 const unsigned char address3[6]);
23 34
24#endif /* LIBWIFI_GEN_ATIM_H */ 35#endif /* LIBWIFI_GEN_ATIM_H */
diff --git a/src/libwifi/gen/management/authentication.c b/src/libwifi/gen/management/authentication.c index e8ffea2..fa1d769 100644 --- a/src/libwifi/gen/management/authentication.c +++ b/src/libwifi/gen/management/authentication.c
@@ -32,16 +32,20 @@ size_t libwifi_get_auth_length(struct libwifi_auth *auth) {
32/** 32/**
33 * The generated authentication frame is made with sane defaults defined in common.h. 33 * The generated authentication frame is made with sane defaults defined in common.h.
34 */ 34 */
35int libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], 35int libwifi_create_auth(struct libwifi_auth *auth,
36 const unsigned char transmitter[6], uint16_t algorithm_number, 36 const unsigned char receiver[6],
37 uint16_t transaction_sequence, uint16_t status_code) { 37 const unsigned char transmitter[6],
38 const unsigned char address3[6],
39 uint16_t algorithm_number,
40 uint16_t transaction_sequence,
41 uint16_t status_code) {
38 memset(auth, 0, sizeof(struct libwifi_auth)); 42 memset(auth, 0, sizeof(struct libwifi_auth));
39 43
40 auth->frame_header.frame_control.type = TYPE_MANAGEMENT; 44 auth->frame_header.frame_control.type = TYPE_MANAGEMENT;
41 auth->frame_header.frame_control.subtype = SUBTYPE_AUTH; 45 auth->frame_header.frame_control.subtype = SUBTYPE_AUTH;
42 memcpy(&auth->frame_header.addr1, receiver, 6); 46 memcpy(&auth->frame_header.addr1, receiver, 6);
43 memcpy(&auth->frame_header.addr2, transmitter, 6); 47 memcpy(&auth->frame_header.addr2, transmitter, 6);
44 memcpy(&auth->frame_header.addr3, transmitter, 6); 48 memcpy(&auth->frame_header.addr3, address3, 6);
45 auth->frame_header.seq_control.sequence_number = (rand() % 4096); 49 auth->frame_header.seq_control.sequence_number = (rand() % 4096);
46 50
47 auth->fixed_parameters.algorithm_number = algorithm_number; 51 auth->fixed_parameters.algorithm_number = algorithm_number;
diff --git a/src/libwifi/gen/management/authentication.h b/src/libwifi/gen/management/authentication.h index 75e8dcf..5468c5f 100644 --- a/src/libwifi/gen/management/authentication.h +++ b/src/libwifi/gen/management/authentication.h
@@ -24,7 +24,7 @@
24 * Calculate the length of a given libwifi_auth 24 * Calculate the length of a given libwifi_auth
25 * 25 *
26 * @param auth A libwifi_auth 26 * @param auth A libwifi_auth
27 * @return The length of the given auth 27 * @return The length of the given auth
28 */ 28 */
29size_t libwifi_get_auth_length(struct libwifi_auth *auth); 29size_t libwifi_get_auth_length(struct libwifi_auth *auth);
30 30
@@ -34,23 +34,30 @@ size_t libwifi_get_auth_length(struct libwifi_auth *auth);
34 * A generated libwifi auth can be "dumped" into a buffer for packet injection 34 * A generated libwifi auth can be "dumped" into a buffer for packet injection
35 * via the libwifi_dump_auth. 35 * via the libwifi_dump_auth.
36 * 36 *
37 * @param auth A libwifi_auth 37 * @param auth A libwifi_auth
38 * @param receiver The receiver MAC address, aka address 1 38 * @param receiver The receiver MAC address, aka address 1
39 * @param transmitter The source MAC address, aka address 2 39 * @param transmitter The source MAC address, aka address 2
40 * @param algorithm_number Algorithm type to use 40 * @param address3 The address 3 frame field value, typically the BSSID
41 * 41 * @param algorithm_number Algorithm type to use, as defined in the IEEE802.11 spec
42 * @param transaction_sequence Transaction sequence value to use
43 * @param status_code Status code to use, as defined in the IEEE802.11 spec
44 * @return Zero on success, or negative error
42 */ 45 */
43int libwifi_create_auth(struct libwifi_auth *auth, const unsigned char receiver[6], 46int libwifi_create_auth(struct libwifi_auth *auth,
44 const unsigned char transmitter[6], uint16_t algorithm_number, 47 const unsigned char receiver[6],
45 uint16_t transaction_sequence, uint16_t status_code); 48 const unsigned char transmitter[6],
49 const unsigned char address3[6],
50 uint16_t algorithm_number,
51 uint16_t transaction_sequence,
52 uint16_t status_code);
46 53
47/** 54/**
48 * Dump a libwifi_auth into a raw format for packet injection. 55 * Dump a libwifi_auth into a raw format for packet injection.
49 * 56 *
50 * @param auth A libwifi_auth 57 * @param auth A libwifi_auth
51 * @param buf The output buffer for the frame data 58 * @param buf The output buffer for the frame data
52 * @param buf_len The length of the output buffer 59 * @param buf_len The length of the output buffer
53 * @return The length of the dumped auth 60 * @return The length of the dumped auth, or negative error
54 */ 61 */
55size_t libwifi_dump_auth(struct libwifi_auth *auth, unsigned char *buf, size_t buf_len); 62size_t libwifi_dump_auth(struct libwifi_auth *auth, unsigned char *buf, size_t buf_len);
56 63
diff --git a/src/libwifi/gen/management/beacon.c b/src/libwifi/gen/management/beacon.c index f884c6e..ab99254 100644 --- a/src/libwifi/gen/management/beacon.c +++ b/src/libwifi/gen/management/beacon.c
@@ -32,7 +32,8 @@
32 */ 32 */
33size_t libwifi_get_beacon_length(struct libwifi_beacon *beacon) { 33size_t libwifi_get_beacon_length(struct libwifi_beacon *beacon) {
34 return sizeof(struct libwifi_mgmt_unordered_frame_header) + 34 return sizeof(struct libwifi_mgmt_unordered_frame_header) +
35 sizeof(struct libwifi_beacon_fixed_parameters) + beacon->tags.length; 35 sizeof(struct libwifi_beacon_fixed_parameters) +
36 beacon->tags.length;
36} 37}
37 38
38/** 39/**
@@ -75,12 +76,12 @@ int libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel) {
75 76
76/** 77/**
77 * The generated beacon frame is made with sane defaults defined in common.h. 78 * The generated beacon frame is made with sane defaults defined in common.h.
78 * Three tagged parameters are also added to the beacon: SSID, Channel and Supported Rates. 79 * Two tagged parameters are also added to the beacon: SSID and Channel.
79 */ 80 */
80int libwifi_create_beacon(struct libwifi_beacon *beacon, 81int libwifi_create_beacon(struct libwifi_beacon *beacon,
81 const unsigned char receiver[6], 82 const unsigned char receiver[6],
82 const unsigned char transmitter[6], 83 const unsigned char transmitter[6],
83 const unsigned char bssid[6], 84 const unsigned char address3[6],
84 const char *ssid, 85 const char *ssid,
85 uint8_t channel) { 86 uint8_t channel) {
86 memset(beacon, 0, sizeof(struct libwifi_beacon)); 87 memset(beacon, 0, sizeof(struct libwifi_beacon));
@@ -89,18 +90,19 @@ int libwifi_create_beacon(struct libwifi_beacon *beacon,
89 beacon->frame_header.frame_control.subtype = SUBTYPE_BEACON; 90 beacon->frame_header.frame_control.subtype = SUBTYPE_BEACON;
90 memcpy(&beacon->frame_header.addr1, receiver, 6); 91 memcpy(&beacon->frame_header.addr1, receiver, 6);
91 memcpy(&beacon->frame_header.addr2, transmitter, 6); 92 memcpy(&beacon->frame_header.addr2, transmitter, 6);
92 memcpy(&beacon->frame_header.addr3, bssid, 6); 93 memcpy(&beacon->frame_header.addr3, address3, 6);
93 beacon->frame_header.seq_control.sequence_number = (rand() % 4096); 94 beacon->frame_header.seq_control.sequence_number = (rand() % 4096);
94 95
95 beacon->fixed_parameters.timestamp = BYTESWAP64(libwifi_get_epoch()); 96 beacon->fixed_parameters.timestamp = BYTESWAP64(libwifi_get_epoch());
96 beacon->fixed_parameters.beacon_interval = BYTESWAP16(LIBWIFI_DEFAULT_BEACON_INTERVAL); 97 beacon->fixed_parameters.beacon_interval = BYTESWAP16(LIBWIFI_DEFAULT_BEACON_INTERVAL);
97 beacon->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); 98 beacon->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS);
98 99
99 libwifi_set_beacon_ssid(beacon, ssid); 100 int ret = libwifi_set_beacon_ssid(beacon, ssid);
100 libwifi_set_beacon_channel(beacon, channel); 101 if (ret != 0) {
102 return ret;
103 }
101 104
102 const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES; 105 ret = libwifi_set_beacon_channel(beacon, channel);
103 int ret = libwifi_quick_add_tag(&beacon->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1);
104 106
105 return ret; 107 return ret;
106} 108}
diff --git a/src/libwifi/gen/management/beacon.h b/src/libwifi/gen/management/beacon.h index 943be55..631a475 100644 --- a/src/libwifi/gen/management/beacon.h +++ b/src/libwifi/gen/management/beacon.h
@@ -22,23 +22,25 @@
22 * Set the SSID of a struct libwifi_beacon. 22 * Set the SSID of a struct libwifi_beacon.
23 * 23 *
24 * @param beacon A struct libwifi_beacon 24 * @param beacon A struct libwifi_beacon
25 * @param ssid The new SSID 25 * @param ssid The new SSID
26 * @return Zero on success, or negative error
26 */ 27 */
27int libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid); 28int libwifi_set_beacon_ssid(struct libwifi_beacon *beacon, const char *ssid);
28 29
29/** 30/**
30 * Set the channel of a struct libwifi_beacon. 31 * Set the channel of a struct libwifi_beacon.
31 * 32 *
32 * @param beacon A struct libwifi_beacon 33 * @param beacon A struct libwifi_beacon
33 * @param channel The new channel 34 * @param channel The new channel
35 * @return Zero on success, or negative error
34 */ 36 */
35int libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel); 37int libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel);
36 38
37/** 39/**
38 * Calculate the length of a given struct libwifi_beacon 40 * Calculate the length of a given struct libwifi_beacon
39 * 41 *
40 * @param beacon A struct libwifi_beacon 42 * @param beacon A libwifi_beacon struct
41 * @return The length of the given beacon 43 * @return The length of the given beacon, or negative error
42 */ 44 */
43size_t libwifi_get_beacon_length(struct libwifi_beacon *beacon); 45size_t libwifi_get_beacon_length(struct libwifi_beacon *beacon);
44 46
@@ -48,28 +50,28 @@ size_t libwifi_get_beacon_length(struct libwifi_beacon *beacon);
48 * A generated libwifi beacon can be "dumped" into a buffer for packet injection 50 * A generated libwifi beacon can be "dumped" into a buffer for packet injection
49 * via the libwifi_dump_beacon. 51 * via the libwifi_dump_beacon.
50 * 52 *
51 * @param beacon A struct libwifi_beacon 53 * @param beacon A struct libwifi_beacon
52 * @param receiver The receiver MAC address, aka address 1 54 * @param receiver The receiver MAC address, aka address 1
53 * @param transmitter The source MAC address, aka address 2 55 * @param transmitter The source MAC address, aka address 2
54 * @param bssid The BSSID MAC address, aka address 3 56 * @param address3 The address 3 frame field value, typically the BSSID
55 * @param ssid The SSID of the beacon. Maximum length is 32 characters 57 * @param ssid The SSID of the beacon. Maximum length is 32 characters
56 * @param channel The desired channel of the beacon 58 * @param channel The desired channel of the beacon
57 * 59 * @return Zero on success, or negative error
58 */ 60 */
59int libwifi_create_beacon(struct libwifi_beacon *beacon, 61int libwifi_create_beacon(struct libwifi_beacon *beacon,
60 const unsigned char receiver[6], 62 const unsigned char receiver[6],
61 const unsigned char transmitter[6], 63 const unsigned char transmitter[6],
62 const unsigned char bssid[6], 64 const unsigned char address3[6],
63 const char *ssid, 65 const char *ssid,
64 uint8_t channel); 66 uint8_t channel);
65 67
66/** 68/**
67 * Dump a struct libwifi_beacon into a raw format for packet injection. 69 * Dump a struct libwifi_beacon into a raw format for packet injection.
68 * 70 *
69 * @param beacon A struct libwifi_beacon 71 * @param beacon A struct libwifi_beacon
70 * @param buf The output buffer for the frame data 72 * @param buf The output buffer for the frame data
71 * @param buf_len The length of the output buffer 73 * @param buf_len The length of the output buffer
72 * @return The length of the dumped beacon 74 * @return The length of the dumped beacon, or negative error
73 */ 75 */
74size_t libwifi_dump_beacon(struct libwifi_beacon *beacon, unsigned char *buf, size_t buf_len); 76size_t libwifi_dump_beacon(struct libwifi_beacon *beacon, unsigned char *buf, size_t buf_len);
75 77
diff --git a/src/libwifi/gen/management/deauthentication.c b/src/libwifi/gen/management/deauthentication.c index 14f2c26..a388a6e 100644 --- a/src/libwifi/gen/management/deauthentication.c +++ b/src/libwifi/gen/management/deauthentication.c
@@ -33,15 +33,18 @@ size_t libwifi_get_deauth_length(struct libwifi_deauth *deauth) {
33 * The generated deauthentication frame contains only the supplied receiver, transmitter and reason_code by 33 * The generated deauthentication frame contains only the supplied receiver, transmitter and reason_code by
34 * default. 34 * default.
35 */ 35 */
36int libwifi_create_deauth(struct libwifi_deauth *deauth, const unsigned char receiver[6], 36int libwifi_create_deauth(struct libwifi_deauth *deauth,
37 const unsigned char transmitter[6], uint16_t reason_code) { 37 const unsigned char receiver[6],
38 const unsigned char transmitter[6],
39 const unsigned char address3[6],
40 uint16_t reason_code) {
38 memset(deauth, 0, sizeof(struct libwifi_deauth)); 41 memset(deauth, 0, sizeof(struct libwifi_deauth));
39 42
40 deauth->frame_header.frame_control.type = TYPE_MANAGEMENT; 43 deauth->frame_header.frame_control.type = TYPE_MANAGEMENT;
41 deauth->frame_header.frame_control.subtype = SUBTYPE_DEAUTH; 44 deauth->frame_header.frame_control.subtype = SUBTYPE_DEAUTH;
42 memcpy(&deauth->frame_header.addr1, receiver, 6); 45 memcpy(&deauth->frame_header.addr1, receiver, 6);
43 memcpy(&deauth->frame_header.addr2, transmitter, 6); 46 memcpy(&deauth->frame_header.addr2, transmitter, 6);
44 memcpy(&deauth->frame_header.addr3, transmitter, 6); 47 memcpy(&deauth->frame_header.addr3, address3, 6);
45 48
46 deauth->frame_header.seq_control.sequence_number = (rand() % 4096); 49 deauth->frame_header.seq_control.sequence_number = (rand() % 4096);
47 50
diff --git a/src/libwifi/gen/management/deauthentication.h b/src/libwifi/gen/management/deauthentication.h index 902241d..f118ade 100644 --- a/src/libwifi/gen/management/deauthentication.h +++ b/src/libwifi/gen/management/deauthentication.h
@@ -24,7 +24,7 @@
24 * Calculate the length of a given libwifi_deauth 24 * Calculate the length of a given libwifi_deauth
25 * 25 *
26 * @param deauth A libwifi_deauth 26 * @param deauth A libwifi_deauth
27 * @return The length of the given deauth 27 * @return The length of the given deauth
28 */ 28 */
29size_t libwifi_get_deauth_length(struct libwifi_deauth *deauth); 29size_t libwifi_get_deauth_length(struct libwifi_deauth *deauth);
30 30
@@ -34,22 +34,26 @@ size_t libwifi_get_deauth_length(struct libwifi_deauth *deauth);
34 * A generated libwifi deauth can be "dumped" into a buffer for packet injection 34 * A generated libwifi deauth can be "dumped" into a buffer for packet injection
35 * via the libwifi_dump_deauth. 35 * via the libwifi_dump_deauth.
36 * 36 *
37 * @param deauth A libwifi_deauth 37 * @param deauth A libwifi_deauth
38 * @param receiver The receiver MAC address, aka address 1 38 * @param receiver The receiver MAC address, aka address 1
39 * @param transmitter The source MAC address, aka address 2 39 * @param transmitter The source MAC address, aka address 2
40 * @param address3 The address 3 frame field value, typically the BSSID
40 * @param reason_code The deauth reason code 41 * @param reason_code The deauth reason code
41 * 42 * @return Zero on success, or negative error
42 */ 43 */
43int libwifi_create_deauth(struct libwifi_deauth *deauth, const unsigned char receiver[6], 44int libwifi_create_deauth(struct libwifi_deauth *deauth,
44 const unsigned char transmitter[6], uint16_t reason_code); 45 const unsigned char receiver[6],
46 const unsigned char transmitter[6],
47 const unsigned char address3[6],
48 uint16_t reason_code);
45 49
46/** 50/**
47 * Dump a libwifi_deauth into a raw format for packet injection. 51 * Dump a libwifi_deauth into a raw format for packet injection.
48 * 52 *
49 * @param deauth A libwifi_deauth 53 * @param deauth A libwifi_deauth
50 * @param buf The output buffer for the frame data 54 * @param buf The output buffer for the frame data
51 * @param buf_len The length of the output buffer 55 * @param buf_len The length of the output buffer
52 * @return The length of the dumped deauth 56 * @return The length of the dumped deauth, or negative error
53 */ 57 */
54size_t libwifi_dump_deauth(struct libwifi_deauth *deauth, unsigned char *buf, size_t buf_len); 58size_t libwifi_dump_deauth(struct libwifi_deauth *deauth, unsigned char *buf, size_t buf_len);
55 59
diff --git a/src/libwifi/gen/management/disassociation.c b/src/libwifi/gen/management/disassociation.c index d6cf237..dde1f1e 100644 --- a/src/libwifi/gen/management/disassociation.c +++ b/src/libwifi/gen/management/disassociation.c
@@ -33,15 +33,18 @@ size_t libwifi_get_disassoc_length(struct libwifi_disassoc *disassoc) {
33 * The generated disassociation frame contains only the supplied receiver, transmitter and reason_code by 33 * The generated disassociation frame contains only the supplied receiver, transmitter and reason_code by
34 * default. 34 * default.
35 */ 35 */
36int libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], 36int libwifi_create_disassoc(struct libwifi_disassoc *disassoc,
37 const unsigned char transmitter[6], uint16_t reason_code) { 37 const unsigned char receiver[6],
38 const unsigned char transmitter[6],
39 const unsigned char address3[6],
40 uint16_t reason_code) {
38 memset(disassoc, 0, sizeof(struct libwifi_disassoc)); 41 memset(disassoc, 0, sizeof(struct libwifi_disassoc));
39 42
40 disassoc->frame_header.frame_control.type = TYPE_MANAGEMENT; 43 disassoc->frame_header.frame_control.type = TYPE_MANAGEMENT;
41 disassoc->frame_header.frame_control.subtype = SUBTYPE_DISASSOC; 44 disassoc->frame_header.frame_control.subtype = SUBTYPE_DISASSOC;
42 memcpy(&disassoc->frame_header.addr1, receiver, 6); 45 memcpy(&disassoc->frame_header.addr1, receiver, 6);
43 memcpy(&disassoc->frame_header.addr2, transmitter, 6); 46 memcpy(&disassoc->frame_header.addr2, transmitter, 6);
44 memcpy(&disassoc->frame_header.addr3, transmitter, 6); 47 memcpy(&disassoc->frame_header.addr3, address3, 6);
45 48
46 disassoc->frame_header.seq_control.sequence_number = (rand() % 4096); 49 disassoc->frame_header.seq_control.sequence_number = (rand() % 4096);
47 50
diff --git a/src/libwifi/gen/management/disassociation.h b/src/libwifi/gen/management/disassociation.h index 10f1db9..d4cfc29 100644 --- a/src/libwifi/gen/management/disassociation.h +++ b/src/libwifi/gen/management/disassociation.h
@@ -24,7 +24,7 @@
24 * Calculate the length of a given libwifi_disassoc 24 * Calculate the length of a given libwifi_disassoc
25 * 25 *
26 * @param disassoc A libwifi_disassoc 26 * @param disassoc A libwifi_disassoc
27 * @return The length of the given disassoc 27 * @return The length of the given disassoc, or negative error
28 */ 28 */
29size_t libwifi_get_disassoc_length(struct libwifi_disassoc *disassoc); 29size_t libwifi_get_disassoc_length(struct libwifi_disassoc *disassoc);
30 30
@@ -34,22 +34,26 @@ size_t libwifi_get_disassoc_length(struct libwifi_disassoc *disassoc);
34 * A generated libwifi disassoc can be "dumped" into a buffer for packet injection 34 * A generated libwifi disassoc can be "dumped" into a buffer for packet injection
35 * via the libwifi_dump_disassoc. 35 * via the libwifi_dump_disassoc.
36 * 36 *
37 * @param disassoc A libwifi_disassoc 37 * @param disassoc A libwifi_disassoc
38 * @param receiver The receiver MAC address, aka address 1 38 * @param receiver The receiver MAC address, aka address 1
39 * @param transmitter The source MAC address, aka address 2 39 * @param transmitter The source MAC address, aka address 2
40 * @param address3 The address 3 frame field value, typically the BSSID
40 * @param reason_code The disassoc reason code 41 * @param reason_code The disassoc reason code
41 * 42 * @return Zero on success, or negative error
42 */ 43 */
43int libwifi_create_disassoc(struct libwifi_disassoc *disassoc, const unsigned char receiver[6], 44int libwifi_create_disassoc(struct libwifi_disassoc *disassoc,
44 const unsigned char transmitter[6], uint16_t reason_code); 45 const unsigned char receiver[6],
46 const unsigned char transmitter[6],
47 const unsigned char address3[6],
48 uint16_t reason_code);
45 49
46/** 50/**
47 * Dump a libwifi_disassoc into a raw format for packet injection. 51 * Dump a libwifi_disassoc into a raw format for packet injection.
48 * 52 *
49 * @param disassoc A libwifi_disassoc 53 * @param disassoc A libwifi_disassoc
50 * @param buf The output buffer for the frame data 54 * @param buf The output buffer for the frame data
51 * @param buf_len The length of the output buffer 55 * @param buf_len The length of the output buffer
52 * @return The length of the dumped disassoc 56 * @return The length of the dumped disassoc, or negative error
53 */ 57 */
54size_t libwifi_dump_disassoc(struct libwifi_disassoc *disassoc, unsigned char *buf, size_t buf_len); 58size_t libwifi_dump_disassoc(struct libwifi_disassoc *disassoc, unsigned char *buf, size_t buf_len);
55 59
diff --git a/src/libwifi/gen/management/probe_request.c b/src/libwifi/gen/management/probe_request.c index 95cdcdb..8e4ce60 100644 --- a/src/libwifi/gen/management/probe_request.c +++ b/src/libwifi/gen/management/probe_request.c
@@ -31,16 +31,19 @@ size_t libwifi_get_probe_req_length(struct libwifi_probe_req *probe_req) {
31 * The generated probe request frame is made with sane defaults defined in common.h. 31 * The generated probe request frame is made with sane defaults defined in common.h.
32 * Two tagged parameters are also added to the beacon: SSID and Channel. 32 * Two tagged parameters are also added to the beacon: SSID and Channel.
33 */ 33 */
34int libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], 34int libwifi_create_probe_req(struct libwifi_probe_req *probe_req,
35 const unsigned char transmitter[6], const unsigned char bssid[6], 35 const unsigned char receiver[6],
36 const char *ssid, uint8_t channel) { 36 const unsigned char transmitter[6],
37 const unsigned char address3[6],
38 const char *ssid,
39 uint8_t channel) {
37 memset(probe_req, 0, sizeof(struct libwifi_probe_req)); 40 memset(probe_req, 0, sizeof(struct libwifi_probe_req));
38 41
39 probe_req->frame_header.frame_control.type = TYPE_MANAGEMENT; 42 probe_req->frame_header.frame_control.type = TYPE_MANAGEMENT;
40 probe_req->frame_header.frame_control.subtype = SUBTYPE_PROBE_REQ; 43 probe_req->frame_header.frame_control.subtype = SUBTYPE_PROBE_REQ;
41 memcpy(&probe_req->frame_header.addr1, receiver, 6); 44 memcpy(&probe_req->frame_header.addr1, receiver, 6);
42 memcpy(&probe_req->frame_header.addr2, transmitter, 6); 45 memcpy(&probe_req->frame_header.addr2, transmitter, 6);
43 memcpy(&probe_req->frame_header.addr3, bssid, 6); 46 memcpy(&probe_req->frame_header.addr3, address3, 6);
44 probe_req->frame_header.seq_control.sequence_number = (rand() % 4096); 47 probe_req->frame_header.seq_control.sequence_number = (rand() % 4096);
45 48
46 int ret = libwifi_quick_add_tag(&probe_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid)); 49 int ret = libwifi_quick_add_tag(&probe_req->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid));
diff --git a/src/libwifi/gen/management/probe_request.h b/src/libwifi/gen/management/probe_request.h index c71897b..47dc23a 100644 --- a/src/libwifi/gen/management/probe_request.h +++ b/src/libwifi/gen/management/probe_request.h
@@ -24,7 +24,7 @@
24 * Calculate the length of a given libwifi_probe_req 24 * Calculate the length of a given libwifi_probe_req
25 * 25 *
26 * @param probe_req A libwifi_probe_req 26 * @param probe_req A libwifi_probe_req
27 * @return The length of the given probe_req 27 * @return The length of the given probe_req, or negative error
28 */ 28 */
29size_t libwifi_get_probe_req_length(struct libwifi_probe_req *probe_req); 29size_t libwifi_get_probe_req_length(struct libwifi_probe_req *probe_req);
30 30
@@ -34,23 +34,28 @@ size_t libwifi_get_probe_req_length(struct libwifi_probe_req *probe_req);
34 * A generated libwifi probe_req can be "dumped" into a buffer for packet injection 34 * A generated libwifi probe_req can be "dumped" into a buffer for packet injection
35 * via the libwifi_dump_probe_req. 35 * via the libwifi_dump_probe_req.
36 * 36 *
37 * @param probe_req A libwifi_probe_req 37 * @param probe_req A libwifi_probe_req
38 * @param receiver The receiver MAC address, aka address 1 38 * @param receiver The receiver MAC address, aka address 1
39 * @param transmitter The source MAC address, aka address 2 39 * @param transmitter The source MAC address, aka address 2
40 * @param reason_code The probe_req reason code 40 * @param address3 The address 3 frame field value, typically the BSSID
41 * 41 * @param ssid The probe request SSID
42 * @param channel The probe request channel
43 * @return Zero on success, or negative error
42 */ 44 */
43int libwifi_create_probe_req(struct libwifi_probe_req *probe_req, const unsigned char receiver[6], 45int libwifi_create_probe_req(struct libwifi_probe_req *probe_req,
44 const unsigned char transmitter[6], const unsigned char bssid[6], 46 const unsigned char receiver[6],
45 const char *ssid, uint8_t channel); 47 const unsigned char transmitter[6],
48 const unsigned char address3[6],
49 const char *ssid,
50 uint8_t channel);
46 51
47/** 52/**
48 * Dump a libwifi_probe_req into a raw format for packet injection. 53 * Dump a libwifi_probe_req into a raw format for packet injection.
49 * 54 *
50 * @param probe_req A libwifi_probe_req 55 * @param probe_req A libwifi_probe_req
51 * @param buf The output buffer for the frame data 56 * @param buf The output buffer for the frame data
52 * @param buf_len The length of the output buffer 57 * @param buf_len The length of the output buffer
53 * @return The length of the dumped probe_req 58 * @return The length of the dumped probe_req, or negative error
54 */ 59 */
55size_t libwifi_dump_probe_req(struct libwifi_probe_req *probe_req, unsigned char *buf, size_t buf_len); 60size_t libwifi_dump_probe_req(struct libwifi_probe_req *probe_req, unsigned char *buf, size_t buf_len);
56 61
diff --git a/src/libwifi/gen/management/probe_response.c b/src/libwifi/gen/management/probe_response.c index 6c1e990..603d0c4 100644 --- a/src/libwifi/gen/management/probe_response.c +++ b/src/libwifi/gen/management/probe_response.c
@@ -32,7 +32,8 @@
32 */ 32 */
33size_t libwifi_get_probe_resp_length(struct libwifi_probe_resp *probe_resp) { 33size_t libwifi_get_probe_resp_length(struct libwifi_probe_resp *probe_resp) {
34 return sizeof(struct libwifi_mgmt_unordered_frame_header) + 34 return sizeof(struct libwifi_mgmt_unordered_frame_header) +
35 sizeof(struct libwifi_probe_resp_fixed_parameters) + probe_resp->tags.length; 35 sizeof(struct libwifi_probe_resp_fixed_parameters) +
36 probe_resp->tags.length;
36} 37}
37 38
38/** 39/**
@@ -48,7 +49,7 @@ int libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const cha
48 } 49 }
49 } 50 }
50 51
51 ret = libwifi_quick_add_tag(&probe_resp->tags, TAG_SSID, (void *) ssid, strlen(ssid)); 52 ret = libwifi_quick_add_tag(&probe_resp->tags, TAG_SSID, (const unsigned char *) ssid, strlen(ssid));
52 53
53 return ret; 54 return ret;
54} 55}
@@ -75,16 +76,21 @@ int libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_
75 76
76/** 77/**
77 * The generated probe response frame is made with sane defaults defined in common.h. 78 * The generated probe response frame is made with sane defaults defined in common.h.
78 * Three tagged parameters are also added to the probe response: SSID, Channel and Supported Rates. 79 * Two tagged parameters are also added to the probe response: SSID and Channel.
79 */ 80 */
80int libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], 81int libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp,
81 const unsigned char transmitter[6], const char *ssid, uint8_t channel) { 82 const unsigned char receiver[6],
83 const unsigned char transmitter[6],
84 const unsigned char address3[6],
85 const char *ssid,
86 uint8_t channel) {
82 memset(probe_resp, 0, sizeof(struct libwifi_probe_resp)); 87 memset(probe_resp, 0, sizeof(struct libwifi_probe_resp));
83 88
84 probe_resp->frame_header.frame_control.type = TYPE_MANAGEMENT; 89 probe_resp->frame_header.frame_control.type = TYPE_MANAGEMENT;
85 probe_resp->frame_header.frame_control.subtype = SUBTYPE_PROBE_RESP; 90 probe_resp->frame_header.frame_control.subtype = SUBTYPE_PROBE_RESP;
86 memcpy(&probe_resp->frame_header.addr1, receiver, 6); 91 memcpy(&probe_resp->frame_header.addr1, receiver, 6);
87 memcpy(&probe_resp->frame_header.addr2, transmitter, 6); 92 memcpy(&probe_resp->frame_header.addr2, transmitter, 6);
93 memcpy(&probe_resp->frame_header.addr3, address3, 6);
88 94
89 probe_resp->frame_header.seq_control.sequence_number = (rand() % 4096); 95 probe_resp->frame_header.seq_control.sequence_number = (rand() % 4096);
90 probe_resp->fixed_parameters.timestamp = BYTESWAP64(libwifi_get_epoch()); 96 probe_resp->fixed_parameters.timestamp = BYTESWAP64(libwifi_get_epoch());
@@ -98,12 +104,6 @@ int libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsig
98 } 104 }
99 105
100 ret = libwifi_set_probe_resp_channel(probe_resp, channel); 106 ret = libwifi_set_probe_resp_channel(probe_resp, channel);
101 if (ret != 0) {
102 return ret;
103 }
104
105 const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES;
106 ret = libwifi_quick_add_tag(&probe_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1);
107 107
108 return ret; 108 return ret;
109} 109}
diff --git a/src/libwifi/gen/management/probe_response.h b/src/libwifi/gen/management/probe_response.h index 80f5451..4e49a6e 100644 --- a/src/libwifi/gen/management/probe_response.h +++ b/src/libwifi/gen/management/probe_response.h
@@ -21,24 +21,26 @@
21/** 21/**
22 * Set the SSID of a libwifi_probe_resp. 22 * Set the SSID of a libwifi_probe_resp.
23 * 23 *
24 * @param probe_resp A libwifi_probe_resp 24 * @param probe_resp A libwifi_probe_resp struct
25 * @param ssid The new SSID 25 * @param ssid The new SSID
26 * @return Zero on success, or negative error
26 */ 27 */
27int libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid); 28int libwifi_set_probe_resp_ssid(struct libwifi_probe_resp *probe_resp, const char *ssid);
28 29
29/** 30/**
30 * Set the channel of a libwifi_probe_resp. 31 * Set the channel of a libwifi_probe_resp.
31 * 32 *
32 * @param probe_resp A libwifi_probe_resp 33 * @param probe_resp A libwifi_probe_resp struct
33 * @param channel The new channel 34 * @param channel The new channel
35 * @return Zero on success, or negative error
34 */ 36 */
35int libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel); 37int libwifi_set_probe_resp_channel(struct libwifi_probe_resp *probe_resp, uint8_t channel);
36 38
37/** 39/**
38 * Calculate the length of a given libwifi_probe_resp 40 * Calculate the length of a given libwifi_probe_resp
39 * 41 *
40 * @param probe_resp A libwifi_probe_resp 42 * @param probe_resp A libwifi_probe_resp struct
41 * @return The length of the given probe_resp 43 * @return The length of the given probe_resp, or negative error
42 */ 44 */
43size_t libwifi_get_probe_resp_length(struct libwifi_probe_resp *probe_resp); 45size_t libwifi_get_probe_resp_length(struct libwifi_probe_resp *probe_resp);
44 46
@@ -48,23 +50,28 @@ size_t libwifi_get_probe_resp_length(struct libwifi_probe_resp *probe_resp);
48 * A generated libwifi probe_resp can be "dumped" into a buffer for packet injection 50 * A generated libwifi probe_resp can be "dumped" into a buffer for packet injection
49 * via the libwifi_dump_probe_resp. 51 * via the libwifi_dump_probe_resp.
50 * 52 *
51 * @param probe_resp A libwifi_probe_resp 53 * @param probe_resp A libwifi_probe_resp
52 * @param receiver The receiver MAC address, aka address 1 54 * @param receiver The receiver MAC address, aka address 1
53 * @param transmitter The source MAC address, aka address 2 55 * @param transmitter The source MAC address, aka address 2
54 * @param ssid The SSID of the probe_resp. Maximum length is 32 characters 56 * @param address3 The address 3 frame field value, typically the BSSID
55 * @param channel The desired channel of the probe_resp 57 * @param ssid The SSID of the probe_resp. Maximum length is 32 characters
56 * 58 * @param channel The desired channel of the probe_resp
59 * @return Zero on success, or negative error
57 */ 60 */
58int libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp, const unsigned char receiver[6], 61int libwifi_create_probe_resp(struct libwifi_probe_resp *probe_resp,
59 const unsigned char transmitter[6], const char *ssid, uint8_t channel); 62 const unsigned char receiver[6],
63 const unsigned char transmitter[6],
64 const unsigned char address3[6],
65 const char *ssid,
66 uint8_t channel);
60 67
61/** 68/**
62 * Dump a libwifi_probe_resp into a raw format for packet injection. 69 * Dump a libwifi_probe_resp into a raw format for packet injection.
63 * 70 *
64 * @param probe_resp A libwifi_probe_resp 71 * @param probe_resp A libwifi_probe_resp
65 * @param buf The output buffer for the frame data 72 * @param buf The output buffer for the frame data
66 * @param buf_len The length of the output buffer 73 * @param buf_len The length of the output buffer
67 * @return The length of the dumped probe_resp 74 * @return The length of the dumped probe_resp, or negative error
68 */ 75 */
69size_t libwifi_dump_probe_resp(struct libwifi_probe_resp *probe_resp, unsigned char *buf, size_t buf_len); 76size_t libwifi_dump_probe_resp(struct libwifi_probe_resp *probe_resp, unsigned char *buf, size_t buf_len);
70 77
diff --git a/src/libwifi/gen/management/reassoc_request.c b/src/libwifi/gen/management/reassoc_request.c index 9e9bcd8..ed61a50 100644 --- a/src/libwifi/gen/management/reassoc_request.c +++ b/src/libwifi/gen/management/reassoc_request.c
@@ -26,23 +26,28 @@
26 */ 26 */
27size_t libwifi_get_reassoc_req_length(struct libwifi_reassoc_req *reassoc_req) { 27size_t libwifi_get_reassoc_req_length(struct libwifi_reassoc_req *reassoc_req) {
28 return sizeof(struct libwifi_mgmt_unordered_frame_header) + 28 return sizeof(struct libwifi_mgmt_unordered_frame_header) +
29 sizeof(struct libwifi_reassoc_req_fixed_parameters) + reassoc_req->tags.length; 29 sizeof(struct libwifi_reassoc_req_fixed_parameters) +
30 reassoc_req->tags.length;
30} 31}
31 32
32/** 33/**
33 * The generated reassociation request frame is made with sane defaults defined in common.h. 34 * The generated reassociation request frame is made with sane defaults defined in common.h.
34 * Two tagged parameters are also added to the reassociation frame: SSID and Channel 35 * Two tagged parameters are also added to the reassociation frame: SSID and Channel
35 */ 36 */
36int libwifi_create_reassoc_req(struct libwifi_reassoc_req *reassoc_req, const unsigned char receiver[6], 37int libwifi_create_reassoc_req(struct libwifi_reassoc_req *reassoc_req,
37 const unsigned char transmitter[6], const unsigned char current_ap[6], 38 const unsigned char receiver[6],
38 const char *ssid, uint8_t channel) { 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) {
39 memset(reassoc_req, 0, sizeof(struct libwifi_reassoc_req)); 44 memset(reassoc_req, 0, sizeof(struct libwifi_reassoc_req));
40 45
41 reassoc_req->frame_header.frame_control.type = TYPE_MANAGEMENT; 46 reassoc_req->frame_header.frame_control.type = TYPE_MANAGEMENT;
42 reassoc_req->frame_header.frame_control.subtype = SUBTYPE_REASSOC_REQ; 47 reassoc_req->frame_header.frame_control.subtype = SUBTYPE_REASSOC_REQ;
43 memcpy(&reassoc_req->frame_header.addr1, receiver, 6); 48 memcpy(&reassoc_req->frame_header.addr1, receiver, 6);
44 memcpy(&reassoc_req->frame_header.addr2, transmitter, 6); 49 memcpy(&reassoc_req->frame_header.addr2, transmitter, 6);
45 memcpy(&reassoc_req->frame_header.addr3, receiver, 6); 50 memcpy(&reassoc_req->frame_header.addr3, address3, 6);
46 reassoc_req->frame_header.seq_control.sequence_number = (rand() % 4096); 51 reassoc_req->frame_header.seq_control.sequence_number = (rand() % 4096);
47 52
48 reassoc_req->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); 53 reassoc_req->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS);
diff --git a/src/libwifi/gen/management/reassoc_request.h b/src/libwifi/gen/management/reassoc_request.h index 3db971f..04dbb14 100644 --- a/src/libwifi/gen/management/reassoc_request.h +++ b/src/libwifi/gen/management/reassoc_request.h
@@ -20,11 +20,48 @@
20#include "../../core/frame/management/common.h" 20#include "../../core/frame/management/common.h"
21#include "../../core/frame/management/reassoc_request.h" 21#include "../../core/frame/management/reassoc_request.h"
22 22
23int libwifi_create_reassoc_req(struct libwifi_reassoc_req *reassoc_req, const unsigned char receiver[6], 23/**
24 const unsigned char transmitter[6], const unsigned char current_ap[6], 24 * Create a new libwifi reassociation request
25 *
26 * @param reassoc_req A new libwifi_reassoc_req struct
27 * @param receiver The receiver MAC address
28 * @param transmitter The transmitter MAC address
29 * @param address3 The address 3 frame field value, typically the BSSID
30 * @param current_ap The current AP BSSID
31 * @param ssid The desired BSS SSID
32 * @param channel The desired channel
33 * @return Zero on success, or negative error
34 */
35int libwifi_create_reassoc_req(struct libwifi_reassoc_req *reassoc_req,
36 const unsigned char receiver[6],
37 const unsigned char transmitter[6],
38 const unsigned char address3[6],
39 const unsigned char current_ap[6],
25 const char *ssid, uint8_t channel); 40 const char *ssid, uint8_t channel);
41
42/**
43 * Get the length of a given libwifi_reassoc_req
44 *
45 * @param reassoc_req A libwifi_reassoc_req struct
46 * @return The length of the given libwifi_reassoc_req, or negative error
47 */
26size_t libwifi_get_reassoc_req_length(struct libwifi_reassoc_req *reassoc_req); 48size_t libwifi_get_reassoc_req_length(struct libwifi_reassoc_req *reassoc_req);
49
50/**
51 * Dump a libwifi_reassoc_req into a raw format for packet injection.
52 *
53 * @param reassoc_req A libwifi_reassoc_req struct
54 * @param buf The buffer to dump into
55 * @param buf_len The length of the supplied buffer
56 * @return The amount of bytes dumped, or negative error
57 */
27size_t libwifi_dump_reassoc_req(struct libwifi_reassoc_req *reassoc_req, unsigned char *buf, size_t buf_len); 58size_t libwifi_dump_reassoc_req(struct libwifi_reassoc_req *reassoc_req, unsigned char *buf, size_t buf_len);
59
60/**
61 * Free any memory claimed by a libwifi_reassoc_req back to the system.
62 *
63 * @param reassoc_req A libwifi_reassoc_req
64 */
28void libwifi_free_reassoc_req(struct libwifi_reassoc_req *reassoc_req); 65void libwifi_free_reassoc_req(struct libwifi_reassoc_req *reassoc_req);
29 66
30#endif /* LIBWIFI_GEN_REASSOCREQUEST_H */ 67#endif /* LIBWIFI_GEN_REASSOCREQUEST_H */
diff --git a/src/libwifi/gen/management/reassoc_response.c b/src/libwifi/gen/management/reassoc_response.c index 30a2389..5d85a86 100644 --- a/src/libwifi/gen/management/reassoc_response.c +++ b/src/libwifi/gen/management/reassoc_response.c
@@ -33,7 +33,8 @@
33 */ 33 */
34size_t libwifi_get_reassoc_resp_length(struct libwifi_reassoc_resp *reassoc_resp) { 34size_t libwifi_get_reassoc_resp_length(struct libwifi_reassoc_resp *reassoc_resp) {
35 return sizeof(struct libwifi_mgmt_unordered_frame_header) + 35 return sizeof(struct libwifi_mgmt_unordered_frame_header) +
36 sizeof(struct libwifi_reassoc_resp_fixed_parameters) + reassoc_resp->tags.length; 36 sizeof(struct libwifi_reassoc_resp_fixed_parameters) +
37 reassoc_resp->tags.length;
37} 38}
38 39
39/** 40/**
@@ -58,28 +59,26 @@ int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp,
58 59
59/** 60/**
60 * The generated reassoc_resp frame is made with sane defaults defined in common.h. 61 * The generated reassoc_resp frame is made with sane defaults defined in common.h.
61 * Three tagged parameters are also added to the reassoc_resp: SSID, Channel and Supported Rates. 62 * One tagged parameters is also added to the reassoc_resp: Channel.
62 */ 63 */
63int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], 64int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp,
64 const unsigned char transmitter[6], uint8_t channel) { 65 const unsigned char receiver[6],
66 const unsigned char transmitter[6],
67 const unsigned char address3[6],
68 uint8_t channel) {
65 memset(reassoc_resp, 0, sizeof(struct libwifi_reassoc_resp)); 69 memset(reassoc_resp, 0, sizeof(struct libwifi_reassoc_resp));
66 70
67 reassoc_resp->frame_header.frame_control.type = TYPE_MANAGEMENT; 71 reassoc_resp->frame_header.frame_control.type = TYPE_MANAGEMENT;
68 reassoc_resp->frame_header.frame_control.subtype = SUBTYPE_REASSOC_RESP; 72 reassoc_resp->frame_header.frame_control.subtype = SUBTYPE_REASSOC_RESP;
69 memcpy(&reassoc_resp->frame_header.addr1, receiver, 6); 73 memcpy(&reassoc_resp->frame_header.addr1, receiver, 6);
70 memcpy(&reassoc_resp->frame_header.addr2, transmitter, 6); 74 memcpy(&reassoc_resp->frame_header.addr2, transmitter, 6);
75 memcpy(&reassoc_resp->frame_header.addr3, address3, 6);
71 76
72 reassoc_resp->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS); 77 reassoc_resp->fixed_parameters.capabilities_information = BYTESWAP16(LIBWIFI_DEFAULT_AP_CAPABS);
73 reassoc_resp->fixed_parameters.status_code = STATUS_SUCCESS; 78 reassoc_resp->fixed_parameters.status_code = STATUS_SUCCESS;
74 reassoc_resp->fixed_parameters.association_id = rand() % 4096; 79 reassoc_resp->fixed_parameters.association_id = rand() % 4096;
75 80
76 int ret = libwifi_set_reassoc_resp_channel(reassoc_resp, channel); 81 int ret = libwifi_set_reassoc_resp_channel(reassoc_resp, channel);
77 if (ret != 0) {
78 return ret;
79 }
80
81 const unsigned char supported_rates[] = LIBWIFI_DEFAULT_SUPP_RATES;
82 ret = libwifi_quick_add_tag(&reassoc_resp->tags, TAG_SUPP_RATES, supported_rates, sizeof(supported_rates) - 1);
83 82
84 return ret; 83 return ret;
85} 84}
diff --git a/src/libwifi/gen/management/reassoc_response.h b/src/libwifi/gen/management/reassoc_response.h index 420ed66..9db4696 100644 --- a/src/libwifi/gen/management/reassoc_response.h +++ b/src/libwifi/gen/management/reassoc_response.h
@@ -22,7 +22,8 @@
22 * Set the channel of a libwifi_reassoc_resp. 22 * Set the channel of a libwifi_reassoc_resp.
23 * 23 *
24 * @param reassoc_resp A libwifi_reassoc_resp 24 * @param reassoc_resp A libwifi_reassoc_resp
25 * @param channel The new channel 25 * @param channel The desired channel
26 * @return Zero on success, or negative error
26 */ 27 */
27int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel); 28int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp, uint8_t channel);
28 29
@@ -30,7 +31,7 @@ int libwifi_set_reassoc_resp_channel(struct libwifi_reassoc_resp *reassoc_resp,
30 * Calculate the length of a given libwifi_reassoc_resp 31 * Calculate the length of a given libwifi_reassoc_resp
31 * 32 *
32 * @param reassoc_resp A libwifi_reassoc_resp 33 * @param reassoc_resp A libwifi_reassoc_resp
33 * @return The length of the given reassoc_resp 34 * @return The length of the given reassoc_resp, or negative error
34 */ 35 */
35size_t libwifi_get_reassoc_resp_length(struct libwifi_reassoc_resp *reassoc_resp); 36size_t libwifi_get_reassoc_resp_length(struct libwifi_reassoc_resp *reassoc_resp);
36 37
@@ -41,13 +42,17 @@ size_t libwifi_get_reassoc_resp_length(struct libwifi_reassoc_resp *reassoc_resp
41 * via the libwifi_dump_reassoc_resp. 42 * via the libwifi_dump_reassoc_resp.
42 * 43 *
43 * @param reassoc_resp A libwifi_reassoc_resp 44 * @param reassoc_resp A libwifi_reassoc_resp
44 * @param receiver The receiver MAC address, aka address 1 45 * @param receiver The receiver MAC address, aka address 1
45 * @param transmitter The source MAC address, aka address 2 46 * @param transmitter The source MAC address, aka address 2
46 * @param channel The desired channel of the reassoc_resp 47 * @param address3 The address 3 frame field value, typically the BSSID
47 * 48 * @param channel The desired channel of the reassoc_resp
49 * @return Zero on success, or negative error
48 */ 50 */
49int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const unsigned char receiver[6], 51int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp,
50 const unsigned char transmitter[6], uint8_t channel); 52 const unsigned char receiver[6],
53 const unsigned char transmitter[6],
54 const unsigned char address3[6],
55 uint8_t channel);
51 56
52/** 57/**
53 * Dump a libwifi_reassoc_resp into a raw format for packet injection. 58 * Dump a libwifi_reassoc_resp into a raw format for packet injection.
@@ -55,7 +60,7 @@ int libwifi_create_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, const
55 * @param reassoc_resp A libwifi_reassoc_resp 60 * @param reassoc_resp A libwifi_reassoc_resp
56 * @param buf The output buffer for the frame data 61 * @param buf The output buffer for the frame data
57 * @param buf_len The length of the output buffer 62 * @param buf_len The length of the output buffer
58 * @return The length of the dumped reassoc_resp 63 * @return The length of the dumped reassoc_resp, or negative error
59 */ 64 */
60size_t libwifi_dump_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, unsigned char *buf, 65size_t libwifi_dump_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, unsigned char *buf,
61 size_t buf_len); 66 size_t buf_len);
@@ -63,7 +68,7 @@ size_t libwifi_dump_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp, unsi
63/** 68/**
64 * Free any memory claimed by a libwifi_reassoc_resp back to the system. 69 * Free any memory claimed by a libwifi_reassoc_resp back to the system.
65 * 70 *
66 * @param reassoc_resp A libwifi_reassoc_resp 71 * @param reassoc_resp A libwifi_reassoc_resp struct
67 */ 72 */
68void libwifi_free_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp); 73void libwifi_free_reassoc_resp(struct libwifi_reassoc_resp *reassoc_resp);
69 74
diff --git a/src/libwifi/gen/management/timing_ad.c b/src/libwifi/gen/management/timing_ad.c index 61b9003..73a1188 100644 --- a/src/libwifi/gen/management/timing_ad.c +++ b/src/libwifi/gen/management/timing_ad.c
@@ -23,16 +23,23 @@
23#include <stdlib.h> 23#include <stdlib.h>
24#include <string.h> 24#include <string.h>
25 25
26int libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], 26int libwifi_create_timing_advert(struct libwifi_timing_advert *adv,
27 const unsigned char transmitter[6], struct libwifi_timing_advert_fields *adv_fields, 27 const unsigned char destination[6],
28 const char country[3], uint16_t max_reg_power, uint8_t max_tx_power, uint8_t tx_power_used, 28 const unsigned char transmitter[6],
29 uint8_t noise_floor) { 29 const unsigned char address3[6],
30 struct libwifi_timing_advert_fields *adv_fields,
31 const char country[3],
32 uint16_t max_reg_power,
33 uint8_t max_tx_power,
34 uint8_t tx_power_used,
35 uint8_t noise_floor) {
30 memset(adv, 0, sizeof(struct libwifi_timing_advert)); 36 memset(adv, 0, sizeof(struct libwifi_timing_advert));
31 37
32 adv->frame_header.frame_control.type = TYPE_MANAGEMENT; 38 adv->frame_header.frame_control.type = TYPE_MANAGEMENT;
33 adv->frame_header.frame_control.subtype = SUBTYPE_TIME_ADV; 39 adv->frame_header.frame_control.subtype = SUBTYPE_TIME_ADV;
34 memcpy(&adv->frame_header.addr1, destination, 6); 40 memcpy(&adv->frame_header.addr1, destination, 6);
35 memcpy(&adv->frame_header.addr2, transmitter, 6); 41 memcpy(&adv->frame_header.addr2, transmitter, 6);
42 memcpy(&adv->frame_header.addr3, address3, 6);
36 adv->frame_header.seq_control.sequence_number = (rand() % 4096); 43 adv->frame_header.seq_control.sequence_number = (rand() % 4096);
37 44
38 adv->fixed_parameters.timestamp = BYTESWAP64(libwifi_get_epoch()); 45 adv->fixed_parameters.timestamp = BYTESWAP64(libwifi_get_epoch());
diff --git a/src/libwifi/gen/management/timing_ad.h b/src/libwifi/gen/management/timing_ad.h index 51c7729..7f0de18 100644 --- a/src/libwifi/gen/management/timing_ad.h +++ b/src/libwifi/gen/management/timing_ad.h
@@ -18,15 +18,57 @@
18 18
19#include "../../core/frame/management/timing_ad.h" 19#include "../../core/frame/management/timing_ad.h"
20 20
21int libwifi_create_timing_advert(struct libwifi_timing_advert *adv, const unsigned char destination[6], 21/**
22 const unsigned char transmitter[6], struct libwifi_timing_advert_fields *adv_fields, 22 * Create a populated libwifi_timing_advert struct
23 const char country[3], uint16_t max_reg_power, uint8_t max_tx_power, uint8_t tx_power_used, 23 *
24 uint8_t noise_floor); 24 * A generated libwifi timing advert can be "dumped" into a buffer for packet injection
25 * via the libwifi_dump_timing_advert function.
26 *
27 * @param adv A new libwifi_timing_advert struct
28 * @param receiver The receiver MAC address, aka address 1
29 * @param transmitter The source MAC address, aka address 2
30 * @param address3 The address 3 frame field value, typically the BSSID
31 * @param adv_fields A libwifi_timing_advert_fields struct
32 * @param country The ISO 3166-1 country code field value
33 * @param max_reg_power Maximum Regulatory Power value
34 * @param max_tx_power Maximum Transmit Power value
35 * @param tx_power_used Transmit Power Used value
36 * @param noise_floor Noise Floor value
37 * @return Zero on success, or negative errno
38 */
39int libwifi_create_timing_advert(struct libwifi_timing_advert *adv,
40 const unsigned char receiver[6],
41 const unsigned char transmitter[6],
42 const unsigned char address3[6],
43 struct libwifi_timing_advert_fields *adv_fields,
44 const char country[3],
45 uint16_t max_reg_power,
46 uint8_t max_tx_power,
47 uint8_t tx_power_used,
48 uint8_t noise_floor);
25 49
50/**
51 * Get the length of the specified libwifi_timing_advert struct
52 *
53 * @return Length of the specified timing advert, or negative error
54 */
26size_t libwifi_get_timing_advert_length(struct libwifi_timing_advert *adv); 55size_t libwifi_get_timing_advert_length(struct libwifi_timing_advert *adv);
27 56
57/**
58 * Dump a libwifi_timing_advert into a raw format for packet injection.
59 *
60 * @param adv A libwifi_timing_advert
61 * @param buf The output buffer for the frame data
62 * @param buf_len The length of the output buffer
63 * @return The length of the dumped timing advert, or negative error
64 */
28size_t libwifi_dump_timing_advert(struct libwifi_timing_advert *adv, unsigned char *buf, size_t buf_len); 65size_t libwifi_dump_timing_advert(struct libwifi_timing_advert *adv, unsigned char *buf, size_t buf_len);
29 66
67/**
68 * Free any memory claimed by a libwifi_timing_advert back to the system.
69 *
70 * @param adv A libwifi_timing_advert struct
71 */
30void libwifi_free_timing_advert(struct libwifi_timing_advert *adv); 72void libwifi_free_timing_advert(struct libwifi_timing_advert *adv);
31 73
32#endif /* LIBWIFI_GEN_TIMINGAD_H */ 74#endif /* LIBWIFI_GEN_TIMINGAD_H */