diff options
author | Marc <foxtrot@malloc.me> | 2022-01-15 21:51:44 +0000 |
---|---|---|
committer | Marc <foxtrot@malloc.me> | 2022-01-15 21:51:44 +0000 |
commit | d8911a911d493199e2caa66486b40ef7c5c9eef7 (patch) | |
tree | faeefc10cbc4a6fef67f03419afd1c3904f5f7a3 | |
parent | 275825dde0c4120135d1a563fd861d8bf141729a (diff) | |
download | libwifi-d8911a911d493199e2caa66486b40ef7c5c9eef7.tar.gz libwifi-d8911a911d493199e2caa66486b40ef7c5c9eef7.tar.bz2 libwifi-d8911a911d493199e2caa66486b40ef7c5c9eef7.zip |
gen: Add ability to set different BSSID than Transmitter for Beacons
-rw-r--r-- | src/libwifi/gen/management/beacon.c | 9 | ||||
-rw-r--r-- | src/libwifi/gen/management/beacon.h | 9 | ||||
-rw-r--r-- | utils/src/test_generation.c | 11 |
3 files changed, 21 insertions, 8 deletions
diff --git a/src/libwifi/gen/management/beacon.c b/src/libwifi/gen/management/beacon.c index 8703205..f884c6e 100644 --- a/src/libwifi/gen/management/beacon.c +++ b/src/libwifi/gen/management/beacon.c | |||
@@ -77,14 +77,19 @@ int libwifi_set_beacon_channel(struct libwifi_beacon *beacon, uint8_t channel) { | |||
77 | * The generated beacon frame is made with sane defaults defined in common.h. | 77 | * 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. | 78 | * Three tagged parameters are also added to the beacon: SSID, Channel and Supported Rates. |
79 | */ | 79 | */ |
80 | int libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], | 80 | int libwifi_create_beacon(struct libwifi_beacon *beacon, |
81 | const unsigned char transmitter[6], const char *ssid, uint8_t channel) { | 81 | const unsigned char receiver[6], |
82 | const unsigned char transmitter[6], | ||
83 | const unsigned char bssid[6], | ||
84 | const char *ssid, | ||
85 | uint8_t channel) { | ||
82 | memset(beacon, 0, sizeof(struct libwifi_beacon)); | 86 | memset(beacon, 0, sizeof(struct libwifi_beacon)); |
83 | 87 | ||
84 | beacon->frame_header.frame_control.type = TYPE_MANAGEMENT; | 88 | beacon->frame_header.frame_control.type = TYPE_MANAGEMENT; |
85 | beacon->frame_header.frame_control.subtype = SUBTYPE_BEACON; | 89 | beacon->frame_header.frame_control.subtype = SUBTYPE_BEACON; |
86 | memcpy(&beacon->frame_header.addr1, receiver, 6); | 90 | memcpy(&beacon->frame_header.addr1, receiver, 6); |
87 | memcpy(&beacon->frame_header.addr2, transmitter, 6); | 91 | memcpy(&beacon->frame_header.addr2, transmitter, 6); |
92 | memcpy(&beacon->frame_header.addr3, bssid, 6); | ||
88 | beacon->frame_header.seq_control.sequence_number = (rand() % 4096); | 93 | beacon->frame_header.seq_control.sequence_number = (rand() % 4096); |
89 | 94 | ||
90 | beacon->fixed_parameters.timestamp = BYTESWAP64(libwifi_get_epoch()); | 95 | beacon->fixed_parameters.timestamp = BYTESWAP64(libwifi_get_epoch()); |
diff --git a/src/libwifi/gen/management/beacon.h b/src/libwifi/gen/management/beacon.h index 971df88..943be55 100644 --- a/src/libwifi/gen/management/beacon.h +++ b/src/libwifi/gen/management/beacon.h | |||
@@ -51,12 +51,17 @@ size_t libwifi_get_beacon_length(struct libwifi_beacon *beacon); | |||
51 | * @param beacon A struct libwifi_beacon | 51 | * @param beacon A struct libwifi_beacon |
52 | * @param receiver The receiver MAC address, aka address 1 | 52 | * @param receiver The receiver MAC address, aka address 1 |
53 | * @param transmitter The source MAC address, aka address 2 | 53 | * @param transmitter The source MAC address, aka address 2 |
54 | * @param bssid The BSSID MAC address, aka address 3 | ||
54 | * @param ssid The SSID of the beacon. Maximum length is 32 characters | 55 | * @param ssid The SSID of the beacon. Maximum length is 32 characters |
55 | * @param channel The desired channel of the beacon | 56 | * @param channel The desired channel of the beacon |
56 | * | 57 | * |
57 | */ | 58 | */ |
58 | int libwifi_create_beacon(struct libwifi_beacon *beacon, const unsigned char receiver[6], | 59 | int libwifi_create_beacon(struct libwifi_beacon *beacon, |
59 | const unsigned char transmitter[6], const char *ssid, uint8_t channel); | 60 | const unsigned char receiver[6], |
61 | const unsigned char transmitter[6], | ||
62 | const unsigned char bssid[6], | ||
63 | const char *ssid, | ||
64 | uint8_t channel); | ||
60 | 65 | ||
61 | /** | 66 | /** |
62 | * Dump a struct libwifi_beacon into a raw format for packet injection. | 67 | * Dump a struct libwifi_beacon into a raw format for packet injection. |
diff --git a/utils/src/test_generation.c b/utils/src/test_generation.c index 314ce34..f269fe4 100644 --- a/utils/src/test_generation.c +++ b/utils/src/test_generation.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <libwifi.h> | 2 | #include <libwifi.h> |
3 | #include <libwifi/core/frame/tag.h> | ||
3 | #include <pcap.h> | 4 | #include <pcap.h> |
4 | #include <pcap/dlt.h> | 5 | #include <pcap/dlt.h> |
5 | #include <pcap/pcap.h> | 6 | #include <pcap/pcap.h> |
@@ -55,7 +56,8 @@ static unsigned char to[] = TO_MAC; | |||
55 | static unsigned char from[] = FROM_MAC; | 56 | static unsigned char from[] = FROM_MAC; |
56 | static unsigned char bcast[] = BCAST_MAC; | 57 | static unsigned char bcast[] = BCAST_MAC; |
57 | static unsigned char reassoc_mac[] = REASSOC_MAC; | 58 | static unsigned char reassoc_mac[] = REASSOC_MAC; |
58 | static unsigned char tag_data[] = "\x00\x00\00\x01This is a 221 tag from libwifi.\n"; | 59 | static unsigned char tag_data1[] = "\x00\x13\x37\x01Hello, World!\n"; |
60 | static unsigned char tag_data2[] = "\x00\x20\x91\x00Goodbye, World!\n"; | ||
59 | 61 | ||
60 | static int mode = 0; | 62 | static int mode = 0; |
61 | static int inject_mode = 0; | 63 | static int inject_mode = 0; |
@@ -147,8 +149,9 @@ void inject_beacons(int random_mac) { | |||
147 | } else { | 149 | } else { |
148 | memcpy(txmac, FROM_MAC, 6); | 150 | memcpy(txmac, FROM_MAC, 6); |
149 | } | 151 | } |
150 | libwifi_create_beacon(&beacon, bcast, txmac, BEACON_SSID, CHANNEL); | 152 | libwifi_create_beacon(&beacon, bcast, txmac, txmac, "wifi-beacon", CHANNEL); |
151 | libwifi_quick_add_tag(&beacon.tags, TAG_VENDOR_SPECIFIC, tag_data, sizeof(tag_data)); | 153 | libwifi_quick_add_tag(&beacon.tags, TAG_VENDOR_SPECIFIC, tag_data1, sizeof(tag_data1)); |
154 | libwifi_quick_add_tag(&beacon.tags, TAG_VENDOR_SPECIFIC, tag_data2, sizeof(tag_data2)); | ||
152 | 155 | ||
153 | unsigned char *buf = NULL; | 156 | unsigned char *buf = NULL; |
154 | size_t buf_sz = libwifi_get_beacon_length(&beacon); | 157 | size_t buf_sz = libwifi_get_beacon_length(&beacon); |
@@ -184,7 +187,7 @@ void inject_probe_responses() { | |||
184 | memset(&probe_resp, 0, sizeof(struct libwifi_probe_resp)); | 187 | memset(&probe_resp, 0, sizeof(struct libwifi_probe_resp)); |
185 | 188 | ||
186 | libwifi_create_probe_resp(&probe_resp, to, from, PROBE_RESP_SSID, CHANNEL); | 189 | libwifi_create_probe_resp(&probe_resp, to, from, PROBE_RESP_SSID, CHANNEL); |
187 | libwifi_quick_add_tag(&probe_resp.tags, TAG_VENDOR_SPECIFIC, tag_data, sizeof(tag_data)); | 190 | libwifi_quick_add_tag(&probe_resp.tags, TAG_VENDOR_SPECIFIC, tag_data1, sizeof(tag_data1)); |
188 | 191 | ||
189 | unsigned char *buf = NULL; | 192 | unsigned char *buf = NULL; |
190 | size_t buf_sz = libwifi_get_probe_resp_length(&probe_resp); | 193 | size_t buf_sz = libwifi_get_probe_resp_length(&probe_resp); |