eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

test-mpdu.c (12505B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2013-2019  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #ifdef HAVE_CONFIG_H
     24 #include <config.h>
     25 #endif
     26 
     27 #include <stdio.h>
     28 #include <string.h>
     29 #include <assert.h>
     30 #include <ell/ell.h>
     31 
     32 #include "src/mpdu.h"
     33 #include "src/ie.h"
     34 
     35 struct deauthentication_data {
     36 	const unsigned char *frame;
     37 	size_t frame_len;
     38 	uint16_t duration;
     39 	const unsigned char dest[6];
     40 	const unsigned char src[6];
     41 	const unsigned char bssid[6];
     42 	uint8_t fragment_number;
     43 	uint16_t sequence_number;
     44 };
     45 
     46 static const unsigned char deauthentication_data_1[] = {
     47 	0xc0, 0x00, 0x3a, 0x01, 0x00, 0x0f, 0xb5, 0x88,
     48 	0xac, 0x82, 0x00, 0x14, 0x6c, 0x7e, 0x40, 0x80,
     49 	0x00, 0x14, 0x6c, 0x7e, 0x40, 0x80, 0x70, 0x22,
     50 	0x01, 0x00
     51 };
     52 
     53 static struct deauthentication_data deauthentication_test_1 = {
     54 	.frame = deauthentication_data_1,
     55 	.frame_len = sizeof(deauthentication_data_1),
     56 	.duration = 314,
     57 	.dest = { 0x00, 0x0f, 0xb5, 0x88, 0xac, 0x82 },
     58 	.src = { 0x00, 0x14, 0x6c, 0x7e, 0x40, 0x80 },
     59 	.bssid = { 0x00, 0x14, 0x6c, 0x7e, 0x40, 0x80 },
     60 	.fragment_number = 0,
     61 	.sequence_number = 551,
     62 };
     63 
     64 static void deauthentication_test(const void *data)
     65 {
     66 	const struct deauthentication_data *test = data;
     67 	const struct mmpdu_header *mpdu;
     68 
     69 	mpdu = mpdu_validate(test->frame, test->frame_len);
     70 	assert(mpdu);
     71 
     72 	assert(mpdu->fc.type == MPDU_TYPE_MANAGEMENT);
     73 	assert(mpdu->fc.subtype == MPDU_MANAGEMENT_SUBTYPE_DEAUTHENTICATION);
     74 	assert(mpdu->fc.protocol_version == 0x00);
     75 
     76 	assert(L_LE16_TO_CPU(mpdu->duration) == test->duration);
     77 	assert(!memcmp(mpdu->address_1, test->dest, 6));
     78 	assert(!memcmp(mpdu->address_2, test->src, 6));
     79 	assert(!memcmp(mpdu->address_3, test->bssid, 6));
     80 
     81 	assert(L_LE16_TO_CPU(mpdu->fragment_number) == test->fragment_number);
     82 	assert(MPDU_SEQUENCE_NUMBER(*mpdu) == test->sequence_number);
     83 }
     84 
     85 struct test_frame_data {
     86 	const uint8_t *data;
     87 	size_t len;
     88 	bool good;
     89 };
     90 
     91 static const uint8_t probe_req_good1[] = {
     92 	/* Header */
     93 	0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00,
     94 	0x00, 0x00, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x50, 0x64,
     95 	/*
     96 	 * SSID, Supported Rates, Extended Supported Rates, DSSS Parameter Set,
     97 	 * HT Capabilities, Vendor Specific, Vendor Specific
     98 	 */
     99 	0x00, 0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x01, 0x08, 0x02, 0x04, 0x0b,
    100 	0x16, 0x0c, 0x12, 0x18, 0x24, 0x32, 0x04, 0x30, 0x48, 0x60, 0x6c, 0x03,
    101 	0x01, 0x06, 0x2d, 0x1a, 0x7e, 0x10, 0x1b, 0xff, 0xff, 0x00, 0x00, 0x00,
    102 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
    103 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdd, 0x69, 0x00, 0x50, 0xf2, 0x04,
    104 	0x10, 0x4a, 0x00, 0x01, 0x10, 0x10, 0x3a, 0x00, 0x01, 0x00, 0x10, 0x08,
    105 	0x00, 0x02, 0x31, 0x48, 0x10, 0x47, 0x00, 0x10, 0xd9, 0xec, 0x65, 0xb2,
    106 	0x32, 0xe4, 0x53, 0x8d, 0xb2, 0x6c, 0x3f, 0x2b, 0x86, 0xf7, 0xa8, 0xd5,
    107 	0x10, 0x54, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    108 	0x10, 0x3c, 0x00, 0x01, 0x03, 0x10, 0x02, 0x00, 0x02, 0x00, 0x00, 0x10,
    109 	0x09, 0x00, 0x02, 0x00, 0x00, 0x10, 0x12, 0x00, 0x02, 0x00, 0x00, 0x10,
    110 	0x21, 0x00, 0x01, 0x20, 0x10, 0x23, 0x00, 0x01, 0x20, 0x10, 0x24, 0x00,
    111 	0x01, 0x20, 0x10, 0x11, 0x00, 0x01, 0x20, 0x10, 0x49, 0x00, 0x06, 0x00,
    112 	0x37, 0x2a, 0x00, 0x01, 0x20, 0xdd, 0x11, 0x50, 0x6f, 0x9a, 0x09, 0x02,
    113 	0x02, 0x00, 0x25, 0x00, 0x06, 0x05, 0x00, 0x58, 0x58, 0x04, 0x51, 0x01,
    114 };
    115 static const struct test_frame_data probe_req_good1_data =
    116 	{ probe_req_good1, sizeof(probe_req_good1), true };
    117 
    118 static const uint8_t probe_req_good2[] = {
    119 	/* Header */
    120 	0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00,
    121 	0x00, 0x00, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x50, 0x64,
    122 	/* SSID, Supported Rates, Extended Supported Rates */
    123 	0x00, 0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x01, 0x08, 0x02, 0x04, 0x0b,
    124 	0x16, 0x0c, 0x12, 0x18, 0x24, 0x32, 0x04, 0x30, 0x48, 0x60, 0x6c,
    125 };
    126 static const struct test_frame_data probe_req_good2_data =
    127 	{ probe_req_good2, sizeof(probe_req_good2), true };
    128 
    129 static const uint8_t probe_req_ie_out_of_order1[] = {
    130 	/* Header */
    131 	0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00,
    132 	0x00, 0x00, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x50, 0x64,
    133 	/* SSID, Extended Supported Rates, Supported Rates */
    134 	0x00, 0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x32, 0x04, 0x30, 0x48, 0x60,
    135 	0x6c, 0x01, 0x08, 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24,
    136 };
    137 
    138 static const struct test_frame_data probe_req_ie_out_of_order1_data = {
    139 	probe_req_ie_out_of_order1, sizeof(probe_req_ie_out_of_order1), true
    140 };
    141 
    142 static const uint8_t probe_req_ie_duplicate1[] = {
    143 	/* Header */
    144 	0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00,
    145 	0x00, 0x00, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x50, 0x64,
    146 	/* SSID, SSID, Supported Rates, Extended Supported Rates */
    147 	0x00, 0x05, 0x74, 0x65, 0x73, 0x74, 0x31, 0x00, 0x05, 0x74, 0x65, 0x73,
    148 	0x74, 0x32, 0x01, 0x08, 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24,
    149 	0x32, 0x04, 0x30, 0x48, 0x60, 0x6c,
    150 };
    151 
    152 static const struct test_frame_data probe_req_ie_duplicate1_data = {
    153 	probe_req_ie_duplicate1, sizeof(probe_req_ie_duplicate1), false
    154 };
    155 
    156 static const uint8_t probe_req_ie_out_of_order2[] = {
    157 	0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xda, 0xa1,
    158 	0x19, 0x11, 0xec, 0x70, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x50, 0x25,
    159 	0x00, 0x00, 0x01, 0x04, 0x02, 0x04, 0x0b, 0x16, 0x32, 0x08, 0x0c, 0x12,
    160 	0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, 0x03, 0x01, 0x06, 0x2d, 0x1a, 0x6e,
    161 	0x01, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    162 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    163 	0x00, 0xdd, 0x07, 0x00, 0x50, 0xf2, 0x08, 0x00, 0x01, 0x00, 0x7f, 0x05,
    164 	0x00, 0x00, 0x0a, 0x02, 0x01,
    165 };
    166 
    167 static const struct test_frame_data probe_req_ie_out_of_order2_data = {
    168 	probe_req_ie_out_of_order2, sizeof(probe_req_ie_out_of_order2), true
    169 };
    170 
    171 static const uint8_t assoc_rsp_ie_ooo_tolerated_dup[] = {
    172 	/* Association Response Flags (24 bytes)*/
    173 	0x10, 0x00, 0x24, 0x00, 0xe8, 0x8d, 0xa6, 0x77, 0xa7, 0x37, 0x0a, 0x58,
    174 	0x28, 0x16, 0x65, 0x42, 0x0a, 0x58, 0x28, 0x16, 0x65, 0x42, 0x40, 0x14,
    175 	/* Fixed Parameters (6 bytes) */
    176 	0x31, 0x19, 0x00, 0x00, 0x08, 0xc0,
    177 	/* Tagged parameters: 364 bytes */
    178 	/* Support Rates [1] (10 bytes) */
    179 	0x01, 0x08, 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c,
    180 	/* Vendor Specific [221] (12 bytes) */
    181 	0xdd, 0x0a, 0x50, 0x6f, 0x9a, 0x1b, 0x06, 0x01, 0x20, 0x07, 0x01, 0x03,
    182 	/* RM Enabled Capabilities [70] (7 bytes) */
    183 	0x46, 0x05, 0x02, 0x00, 0x00, 0x00, 0x00,
    184 	/* Vendor Specific [221] (26 bytes) */
    185 	0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, 0x86, 0x00, 0x03, 0xa4,
    186 	0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00, 0x62, 0x32,
    187 	0x2f, 0x00,
    188 	/* HT Capabilities [45] (28 bytes) */
    189 	0x2d, 0x1a, 0xef, 0x09, 0x03, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
    190 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
    191 	0x04, 0x87, 0x19, 0x00,
    192 	/* HT Information [61] (24 bytes)*/
    193 	0x3d, 0x16, 0x24, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    194 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    195 	/* Vendor Specific [221] (32 bytes) */
    196 	0xdd, 0x1e, 0x00, 0x90, 0x4c, 0x33, 0xef, 0x09, 0x03, 0xff, 0xff, 0xff,
    197 	0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    198 	0x00, 0x00, 0x00, 0x18, 0x04, 0x87, 0x19, 0x00,
    199 	/* Vendor Specific [221] (28 bytes) */
    200 	0xdd, 0x1a, 0x00, 0x90, 0x4c, 0x34, 0x24, 0x05, 0x06, 0x00, 0x00, 0x00,
    201 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    202 	0x00, 0x00, 0x00, 0x00,
    203 	/* BSS Max Idle Period [90] (5 bytes)*/
    204 	0x5a, 0x03, 0xe0, 0x01, 0x00,
    205 	/* VHT Capabilities [191] (14 bytes)*/
    206 	0xbf, 0x0c, 0xf5, 0x39, 0xc3, 0x33, 0x9a, 0xff, 0x30, 0x0c, 0x9a, 0xff,
    207 	0x30, 0x2c,
    208 	/* VHT Operation [192] (7 bytes) */
    209 	0xc0, 0x05, 0x01, 0x2a, 0x00, 0xfc, 0xff,
    210 	/* Extended: HE Capabilities 80211ax/D3.0 [256 + 35] (38 bytes) */
    211 	0xff, 0x24, 0x23, 0x05, 0x00, 0x08, 0x1a, 0x44, 0x10, 0x0c, 0x20, 0xce,
    212 	0x92, 0x6f, 0x1b, 0xaf, 0xd4, 0x11, 0x0c, 0x00, 0xaa, 0xff, 0xaa, 0xff,
    213 	0xaa, 0xff, 0xaa, 0xff, 0x3b, 0x1c, 0xc7, 0x71, 0x1c, 0xc7, 0x71, 0x1c,
    214 	0xc7, 0x71,
    215 	/* Extended: HE Operation 80211ax/D3.0 [256 + 36] (9 bytes) */
    216 	0xff, 0x07, 0x24, 0xf4, 0x3f, 0x00, 0x17, 0xfc, 0xff,
    217 	/* Extended: Spatial Reuse Parameter Set [256 + 39] (4 bytes) */
    218 	0xff, 0x02, 0x27, 0x03,
    219 	/* Extended: MU EDCA Parameter Set [256 + 38] (16 bytes) */
    220 	0xff, 0x0e, 0x26, 0x06, 0x00, 0xff, 0x00, 0x20, 0xff, 0x00, 0x40, 0xff,
    221 	0x00, 0x60, 0xff, 0x00,
    222 	/* Extended Capabilities [127] (13 bytes) */
    223 	0x7f, 0x0b, 0x00, 0x00, 0x08, 0x80, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40,
    224 	0x00,
    225 	/* Vendor Specific [221] (9 bytes) */
    226 	0xdd, 0x07, 0x00, 0x0c, 0x43, 0x00, 0x00, 0x00, 0x00,
    227 	/* Vendor Specific [221] (35 bytes) */
    228 	0xdd, 0x21, 0x00, 0x0c, 0xe7, 0x00, 0x00, 0x00, 0x00, 0xbf, 0x0c, 0xb1,
    229 	0x01, 0xc0, 0x33, 0x2a, 0xff, 0x92, 0x04, 0x2a, 0xff, 0x92, 0x04, 0xc0,
    230 	0x05, 0x00, 0x00, 0x00, 0x2a, 0xff, 0xc3, 0x03, 0x01, 0x02, 0x02,
    231 	/* Vendor Specific [221] (9 bytes) */
    232 	0xdd, 0x07, 0x50, 0x6f, 0x9a, 0x16, 0x01, 0x01, 0x00,
    233 	/* RSN Extension [244] (3 bytes) */
    234 	0xf4, 0x01, 0x20,
    235 	/* Vendor Specific [221] (9 bytes) */ /* Legal duplicate IE */
    236 	0xdd, 0x07, 0x50, 0x6f, 0x9a, 0x16, 0x01, 0x01, 0x00,
    237 	/* FILS Indication [240] (4 bytes) */
    238 	0xf0, 0x02, 0x00, 0x00,
    239 	/* RSN Extension [244] (3 bytes) */ /* TECHNICALLY ILLEGAL cloned ie */
    240 	0xf4, 0x01, 0x20,
    241 	/* Vendor Specific [221] (19 bytes) */
    242 	0xdd, 0x11, 0x00, 0x0c, 0xe7, 0x01, 0x00, 0x00, 0x00, 0x04, 0x08, 0x02,
    243 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    244 };
    245 
    246 static const struct test_frame_data assoc_rsp_ie_ooo_tolerated_dup_data = {
    247 	assoc_rsp_ie_ooo_tolerated_dup, sizeof(assoc_rsp_ie_ooo_tolerated_dup), true
    248 };
    249 
    250 static void ie_order_test(const void *data)
    251 {
    252 	const struct test_frame_data *frame = data;
    253 
    254 	assert(!!mpdu_validate(frame->data, frame->len) == frame->good);
    255 }
    256 
    257 static void ie_sort_test(const void *data)
    258 {
    259 	static uint8_t ie_fils_session[] = { IE_TYPE_EXTENSION, 1, 4 };
    260 	static uint8_t ie_mde[] = { IE_TYPE_MOBILITY_DOMAIN, 0 };
    261 	static uint8_t ie_ssid[] = { IE_TYPE_SSID, 0 };
    262 	static uint8_t ie_rsn[] = { IE_TYPE_RSN, 0 };
    263 	struct iovec ies[64];
    264 	size_t n_ies = 0;
    265 	uint8_t *ie;
    266 
    267 	/* Make up some IEs, only the first 3 bytes matter */
    268 	ies[n_ies].iov_base = ie_fils_session;
    269 	ies[n_ies++].iov_len = sizeof(ie_fils_session);
    270 
    271 	ies[n_ies].iov_base = ie_mde;
    272 	ies[n_ies++].iov_len = sizeof(ie_mde);
    273 
    274 	ies[n_ies].iov_base = ie_ssid;
    275 	ies[n_ies++].iov_len = sizeof(ie_ssid);
    276 
    277 	ies[n_ies].iov_base = ie_rsn;
    278 	ies[n_ies++].iov_len = sizeof(ie_rsn);
    279 
    280 	mpdu_sort_ies(MPDU_MANAGEMENT_SUBTYPE_ASSOCIATION_REQUEST, ies, n_ies);
    281 
    282 	ie = ies[0].iov_base;
    283 	assert(ie[0] == IE_TYPE_SSID);
    284 
    285 	ie = ies[1].iov_base;
    286 	assert(ie[0] == IE_TYPE_RSN);
    287 
    288 	ie = ies[2].iov_base;
    289 	assert(ie[0] == IE_TYPE_MOBILITY_DOMAIN);
    290 
    291 	ie = ies[3].iov_base;
    292 	assert(ie[0] == IE_TYPE_EXTENSION && ie[2] == 4);
    293 }
    294 
    295 int main(int argc, char *argv[])
    296 {
    297 	l_test_init(&argc, &argv);
    298 
    299 	l_test_add("/Management Frame/Deauthentication Frame 1",
    300 			deauthentication_test, &deauthentication_test_1);
    301 
    302 	l_test_add("/IE order/Good 1", ie_order_test, &probe_req_good1_data);
    303 	l_test_add("/IE order/Good 2", ie_order_test, &probe_req_good2_data);
    304 	l_test_add("/IE order/Good (Out of Order IE) 1", ie_order_test,
    305 				&probe_req_ie_out_of_order1_data);
    306 	l_test_add("/IE order/Bad (Duplicate + Out of Order IE) 1",
    307 				ie_order_test,
    308 				&probe_req_ie_duplicate1_data);
    309 	l_test_add("/IE order/Ugly (Duplicate + Out of Order IE) 2",
    310 				ie_order_test,
    311 				&assoc_rsp_ie_ooo_tolerated_dup_data);
    312 	l_test_add("/IE order/Good (Out of Order IE) 2", ie_order_test,
    313 				&probe_req_ie_out_of_order2_data);
    314 
    315 	l_test_add("/IE order/Sorting", ie_sort_test, NULL);
    316 
    317 	return l_test_run();
    318 }