153 lines
4.3 KiB
C
153 lines
4.3 KiB
C
/*
|
|
*
|
|
* Wireless daemon for Linux
|
|
*
|
|
* Copyright (C) 2014 Intel Corporation. All rights reserved.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include <config.h>
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include <stdlib.h>
|
|
#include <ell/ell.h>
|
|
|
|
#include "src/ie.h"
|
|
|
|
struct test_data {
|
|
unsigned int num_ie;
|
|
unsigned int len;
|
|
unsigned char *buf;
|
|
};
|
|
|
|
struct ie {
|
|
unsigned char type;
|
|
unsigned char len;
|
|
unsigned char value[];
|
|
} __attribute__ ((packed));
|
|
|
|
static void ie_test_reader(const void *data)
|
|
{
|
|
const struct test_data *test = data;
|
|
struct ie_tlv_iter iter;
|
|
struct ie *ie;
|
|
unsigned int count = 0, pos = 0;
|
|
char *str;
|
|
|
|
ie_tlv_iter_init(&iter, test->buf, test->len);
|
|
|
|
while (ie_tlv_iter_next(&iter)) {
|
|
ie = (struct ie *)&test->buf[pos];
|
|
str = l_util_hexstring(&test->buf[pos + 2], ie->len);
|
|
printf("IE %d [%d/%d/%s]\n", count, ie->type, ie->len, str);
|
|
l_free(str);
|
|
|
|
assert(iter.tag == test->buf[pos++]);
|
|
assert(iter.len == test->buf[pos++]);
|
|
assert(!memcmp(iter.data, test->buf + pos, iter.len));
|
|
pos += ie->len;
|
|
|
|
count++;
|
|
}
|
|
|
|
assert(count == test->num_ie);
|
|
}
|
|
|
|
|
|
static unsigned char beacon_frame[] = {
|
|
/* IEEE 802.11 Beacon frame */
|
|
0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
|
|
0xff, 0xff, 0xc8, 0xd7, 0x19, 0x39, 0xbe, 0x77,
|
|
0xc8, 0xd7, 0x19, 0x39, 0xbe, 0x77, 0x50, 0xa2,
|
|
|
|
/* IEEE 802.11 wireless LAN managment frame
|
|
* - Fixed parameters (12 bytes)
|
|
*/
|
|
0x87, 0x81, 0x31, 0xe6, 0x29, 0x02, 0x00, 0x00,
|
|
0x64, 0x00, 0x11, 0x00,
|
|
|
|
/* - Tagged parameters (TLV format, 252 bytes).
|
|
* This starts at byte position 36
|
|
*/
|
|
0x00, 0x0c, 0x57, 0x65, 0x73, 0x31, 0x4f, 0x70,
|
|
0x65, 0x6e, 0x57, 0x4c, 0x41, 0x4e, 0x01, 0x08,
|
|
0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c,
|
|
0x05, 0x04, 0x00, 0x01, 0x00, 0x00, 0x30, 0x14,
|
|
0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
|
|
0x00, 0x0f, 0xac, 0x04, 0x01, 0x00, 0x00, 0x0f,
|
|
0xac, 0x02, 0x0c, 0x00, 0x0b, 0x05, 0x02, 0x00,
|
|
0x02, 0x00, 0x00, 0x2d, 0x1a, 0x6f, 0x08, 0x17,
|
|
0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d,
|
|
0x16, 0x24, 0x0d, 0x16, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a,
|
|
0x0e, 0x14, 0x00, 0x0a, 0x00, 0x2c, 0x01, 0xc8,
|
|
0x00, 0x14, 0x00, 0x05, 0x00, 0x19, 0x00, 0x7f,
|
|
0x08, 0x01, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
|
|
0x40, 0xbf, 0x0c, 0x32, 0x58, 0x82, 0x0f, 0xea,
|
|
0xff, 0x00, 0x00, 0xea, 0xff, 0x00, 0x00, 0xc0,
|
|
0x05, 0x01, 0x2a, 0x00, 0x00, 0x00, 0xc3, 0x04,
|
|
0x02, 0x02, 0x02, 0x02, 0xdd, 0x31, 0x00, 0x50,
|
|
0xf2, 0x04, 0x10, 0x4a, 0x00, 0x01, 0x10, 0x10,
|
|
0x44, 0x00, 0x01, 0x02, 0x10, 0x47, 0x00, 0x10,
|
|
0x98, 0x42, 0x13, 0x05, 0x23, 0x6e, 0xde, 0x3a,
|
|
0xfa, 0x13, 0x0a, 0x79, 0x44, 0x0f, 0xab, 0x43,
|
|
0x10, 0x3c, 0x00, 0x01, 0x03, 0x10, 0x49, 0x00,
|
|
0x06, 0x00, 0x37, 0x2a, 0x00, 0x01, 0x20, 0xdd,
|
|
0x09, 0x00, 0x10, 0x18, 0x02, 0x02, 0x00, 0x1c,
|
|
0x00, 0x00, 0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02,
|
|
0x01, 0x01, 0x80, 0x00, 0x03, 0xa4, 0x00, 0x00,
|
|
0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00,
|
|
0x62, 0x32, 0x2f, 0x00, 0x01, 0x9a, 0xc1, 0xc8,
|
|
};
|
|
|
|
static unsigned char *append_data(unsigned char *buf, struct ie *ie,
|
|
unsigned int *total_len)
|
|
{
|
|
unsigned char *ptr;
|
|
unsigned old, len = ie->len + 1 + 1;
|
|
|
|
old = *total_len;
|
|
*total_len += len;
|
|
|
|
ptr = realloc(buf, *total_len);
|
|
|
|
memcpy(ptr + old, ie, len);
|
|
|
|
return ptr;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
struct test_data tc1 = { 0 };
|
|
|
|
l_test_init(&argc, &argv);
|
|
|
|
tc1.buf = &beacon_frame[36];
|
|
tc1.num_ie = 15;
|
|
tc1.len = 252;
|
|
l_test_add("/ie/reader/static", ie_test_reader, &tc1);
|
|
|
|
return l_test_run();
|
|
}
|