+static void print_ht_capa(const uint8_t type, uint8_t len, const uint8_t *data)
+{
+ printf("\n");
+ print_ht_capability(data[0] | (data[1] << 8));
+ print_ampdu_length(data[2] & 3);
+ print_ampdu_spacing((data[2] >> 2) & 7);
+ print_ht_mcs(data + 3);
+}
+
+static const char* ntype_11u(uint8_t t)
+{
+ switch (t) {
+ case 0: return "Private";
+ case 1: return "Private with Guest";
+ case 2: return "Chargeable Public";
+ case 3: return "Free Public";
+ case 4: return "Personal Device";
+ case 5: return "Emergency Services Only";
+ case 14: return "Test or Experimental";
+ case 15: return "Wildcard";
+ default: return "Reserved";
+ }
+}
+
+static const char* vgroup_11u(uint8_t t)
+{
+ switch (t) {
+ case 0: return "Unspecified";
+ case 1: return "Assembly";
+ case 2: return "Business";
+ case 3: return "Educational";
+ case 4: return "Factory and Industrial";
+ case 5: return "Institutional";
+ case 6: return "Mercantile";
+ case 7: return "Residential";
+ case 8: return "Storage";
+ case 9: return "Utility and Miscellaneous";
+ case 10: return "Vehicular";
+ case 11: return "Outdoor";
+ default: return "Reserved";
+ }
+}
+
+static void print_interworking(const uint8_t type, uint8_t len, const uint8_t *data)
+{
+ /* See Section 7.3.2.92 in the 802.11u spec. */
+ printf("\n");
+ if (len >= 1) {
+ uint8_t ano = data[0];
+ printf("\t\tNetwork Options: 0x%hx\n", (unsigned short)(ano));
+ printf("\t\t\tNetwork Type: %i (%s)\n",
+ (int)(ano & 0xf), ntype_11u(ano & 0xf));
+ if (ano & (1<<4))
+ printf("\t\t\tInternet\n");
+ if (ano & (1<<5))
+ printf("\t\t\tASRA\n");
+ if (ano & (1<<6))
+ printf("\t\t\tESR\n");
+ if (ano & (1<<7))
+ printf("\t\t\tUESA\n");
+ }
+ if ((len == 3) || (len == 9)) {
+ printf("\t\tVenue Group: %i (%s)\n",
+ (int)(data[1]), vgroup_11u(data[1]));
+ printf("\t\tVenue Type: %i\n", (int)(data[2]));
+ }
+ if (len == 9)
+ printf("\t\tHESSID: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
+ data[3], data[4], data[5], data[6], data[7], data[8]);
+ else if (len == 7)
+ printf("\t\tHESSID: %02hx:%02hx:%02hx:%02hx:%02hx:%02hx\n",
+ data[1], data[2], data[3], data[4], data[5], data[6]);
+}
+
+static void print_11u_advert(const uint8_t type, uint8_t len, const uint8_t *data)
+{
+ /* See Section 7.3.2.93 in the 802.11u spec. */
+ /* TODO: This code below does not decode private protocol IDs */
+ int idx = 0;
+ printf("\n");
+ while (idx < (len - 1)) {
+ uint8_t qri = data[idx];
+ uint8_t proto_id = data[idx + 1];
+ printf("\t\tQuery Response Info: 0x%hx\n", (unsigned short)(qri));
+ printf("\t\t\tQuery Response Length Limit: %i\n",
+ (qri & 0x7f));
+ if (qri & (1<<7))
+ printf("\t\t\tPAME-BI\n");
+ switch(proto_id) {
+ case 0:
+ printf("\t\t\tANQP\n"); break;
+ case 1:
+ printf("\t\t\tMIH Information Service\n"); break;
+ case 2:
+ printf("\t\t\tMIH Command and Event Services Capability Discovery\n"); break;
+ case 3:
+ printf("\t\t\tEmergency Alert System (EAS)\n"); break;
+ case 221:
+ printf("\t\t\tVendor Specific\n"); break;
+ default:
+ printf("\t\t\tReserved: %i\n", proto_id); break;
+ }
+ idx += 2;
+ }
+}
+
+static void print_11u_rcon(const uint8_t type, uint8_t len, const uint8_t *data)
+{
+ /* See Section 7.3.2.96 in the 802.11u spec. */
+ int idx = 0;
+ int ln0 = data[1] & 0xf;
+ int ln1 = ((data[1] & 0xf0) >> 4);
+ int ln2 = 0;
+ printf("\n");
+
+ if (ln1)
+ ln2 = len - 2 - ln0 - ln1;
+
+ printf("\t\tANQP OIs: %i\n", data[0]);
+
+ if (ln0 > 0) {
+ printf("\t\tOI 1: ");
+ if (2 + ln0 > len) {
+ printf("Invalid IE length.\n");
+ } else {
+ for (idx = 0; idx < ln0; idx++) {
+ printf("%02hx", data[2 + idx]);
+ }
+ printf("\n");
+ }
+ }
+
+ if (ln1 > 0) {
+ printf("\t\tOI 2: ");
+ if (2 + ln0 + ln1 > len) {
+ printf("Invalid IE length.\n");
+ } else {
+ for (idx = 0; idx < ln1; idx++) {
+ printf("%02hx", data[2 + ln0 + idx]);
+ }
+ printf("\n");
+ }
+ }
+
+ if (ln2 > 0) {
+ printf("\t\tOI 3: ");
+ if (2 + ln0 + ln1 + ln2 > len) {
+ printf("Invalid IE length.\n");
+ } else {
+ for (idx = 0; idx < ln2; idx++) {
+ printf("%02hx", data[2 + ln0 + ln1 + idx]);
+ }
+ printf("\n");
+ }
+ }
+}
+
+static const char *ht_secondary_offset[4] = {
+ "no secondary",
+ "above",
+ "[reserved!]",
+ "below",
+};
+
+static void print_ht_op(const uint8_t type, uint8_t len, const uint8_t *data)
+{
+ static const char *protection[4] = {
+ "no",
+ "nonmember",
+ "20 MHz",
+ "non-HT mixed",
+ };
+ static const char *sta_chan_width[2] = {
+ "20 MHz",
+ "any",
+ };
+
+ printf("\n");
+ printf("\t\t * primary channel: %d\n", data[0]);
+ printf("\t\t * secondary channel offset: %s\n",
+ ht_secondary_offset[data[1] & 0x3]);
+ printf("\t\t * STA channel width: %s\n", sta_chan_width[(data[1] & 0x4)>>2]);
+ printf("\t\t * RIFS: %d\n", (data[1] & 0x8)>>3);
+ printf("\t\t * HT protection: %s\n", protection[data[2] & 0x3]);
+ printf("\t\t * non-GF present: %d\n", (data[2] & 0x4) >> 2);
+ printf("\t\t * OBSS non-GF present: %d\n", (data[2] & 0x10) >> 4);
+ printf("\t\t * dual beacon: %d\n", (data[4] & 0x40) >> 6);
+ printf("\t\t * dual CTS protection: %d\n", (data[4] & 0x80) >> 7);
+ printf("\t\t * STBC beacon: %d\n", data[5] & 0x1);
+ printf("\t\t * L-SIG TXOP Prot: %d\n", (data[5] & 0x2) >> 1);
+ printf("\t\t * PCO active: %d\n", (data[5] & 0x4) >> 2);
+ printf("\t\t * PCO phase: %d\n", (data[5] & 0x8) >> 3);
+}
+