From 6024cc15cf1d67b1d3c180f9e2d9fd49c508ce05 Mon Sep 17 00:00:00 2001 From: Andreas Schultz Date: Tue, 3 May 2016 10:28:38 +0200 Subject: [PATCH] fix interpretation of Add WLAN's capability field RFC 5416 copies the order of the capability flags from the IEEE 802.11 capability IE. However, the bit ordering assumtions in RFC 5416 differ from IEEE 802.11 (in the RFC the MSB is numbered 0, in IEEE 802.11 the MSB is numbere 15). RFC 5416 therefore specifies the capability flags bit reversed compared to IEEE 802.11. --- src/wtp/wtp_radio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wtp/wtp_radio.c b/src/wtp/wtp_radio.c index b9edf5d..ab6b012 100644 --- a/src/wtp/wtp_radio.c +++ b/src/wtp/wtp_radio.c @@ -652,6 +652,16 @@ void wtp_radio_receive_data_packet(uint8_t radioid, unsigned short binding, cons } } +/* source http://stackoverflow.com/a/16994674 */ +static uint16_t reverse(register uint16_t x) +{ + x = (((x & 0xaaaa) >> 1) | ((x & 0x5555) << 1)); + x = (((x & 0xcccc) >> 2) | ((x & 0x3333) << 2)); + x = (((x & 0xf0f0) >> 4) | ((x & 0x0f0f) << 4)); + x = (((x & 0xff00) >> 8) | ((x & 0x00ff) << 8)); + return x; +} + /* */ uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, struct capwap_80211_assignbssid_element* bssid) @@ -700,7 +710,7 @@ uint32_t wtp_radio_create_wlan(struct capwap_parsed_packet* packet, params.wlanid = addwlan->wlanid; params.ssid = (const char*)addwlan->ssid; params.ssid_hidden = addwlan->suppressssid; - params.capability = addwlan->capability; + params.capability = reverse(addwlan->capability); params.qos = addwlan->qos; params.authmode = addwlan->authmode; params.macmode = addwlan->macmode;