2 * hostapd / Client taxonomy
3 * Copyright (c) 2015 Google, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
8 * Parse a series of IEs, as in Probe Request or (Re)Association Request frames,
9 * and render them to a descriptive string. The tag number of standard options
10 * is written to the string, while the vendor ID and subtag are written for
14 * 0,1,50,45,221(00904c,51)
15 * 0,1,33,36,48,45,221(00904c,51),221(0050f2,2)
18 #include "utils/includes.h"
20 #include "utils/common.h"
21 #include "common/wpa_ctrl.h"
26 /* Copy a string with no funny schtuff allowed; only alphanumerics. */
27 static void no_mischief_strncpy(char *dst, const char *src, size_t n)
31 for (i = 0; i < n; i++) {
32 unsigned char s = src[i];
33 int is_lower = s >= 'a' && s <= 'z';
34 int is_upper = s >= 'A' && s <= 'Z';
35 int is_digit = s >= '0' && s <= '9';
37 if (is_lower || is_upper || is_digit) {
38 /* TODO: if any manufacturer uses Unicode within the
39 * WPS header, it will get mangled here. */
42 /* Note that even spaces will be transformed to
43 * underscores, so 'Nexus 7' will turn into 'Nexus_7'.
44 * This is deliberate, to make the string easier to
52 static int get_wps_name(char *name, size_t name_len,
53 const u8 *data, size_t data_len)
55 /* Inside the WPS IE are a series of attributes, using two byte IDs
56 * and two byte lengths. We're looking for the model name, if
58 while (data_len >= 4) {
61 id = WPA_GET_BE16(data);
62 elen = WPA_GET_BE16(data + 2);
70 /* Model name, like 'Nexus 7' */
71 size_t n = (elen < name_len) ? elen : name_len;
72 no_mischief_strncpy(name, (const char *) data, n);
84 static void ie_to_string(char *fstr, size_t fstr_len, const struct wpabuf *ies)
87 char *fend = fstr + fstr_len;
88 char htcap[7 + 4 + 1]; /* ",htcap:" + %04hx + trailing NUL */
89 char htagg[7 + 2 + 1]; /* ",htagg:" + %02hx + trailing NUL */
90 char htmcs[7 + 8 + 1]; /* ",htmcs:" + %08x + trailing NUL */
91 char vhtcap[8 + 8 + 1]; /* ",vhtcap:" + %08x + trailing NUL */
92 char vhtrxmcs[10 + 8 + 1]; /* ",vhtrxmcs:" + %08x + trailing NUL */
93 char vhttxmcs[10 + 8 + 1]; /* ",vhttxmcs:" + %08x + trailing NUL */
94 #define MAX_EXTCAP 254
95 char extcap[8 + 2 * MAX_EXTCAP + 1]; /* ",extcap:" + hex + trailing NUL
97 char txpow[7 + 4 + 1]; /* ",txpow:" + %04hx + trailing NUL */
98 #define WPS_NAME_LEN 32
99 char wps[WPS_NAME_LEN + 5 + 1]; /* room to prepend ",wps:" + trailing
106 os_memset(htcap, 0, sizeof(htcap));
107 os_memset(htagg, 0, sizeof(htagg));
108 os_memset(htmcs, 0, sizeof(htmcs));
109 os_memset(vhtcap, 0, sizeof(vhtcap));
110 os_memset(vhtrxmcs, 0, sizeof(vhtrxmcs));
111 os_memset(vhttxmcs, 0, sizeof(vhttxmcs));
112 os_memset(extcap, 0, sizeof(extcap));
113 os_memset(txpow, 0, sizeof(txpow));
114 os_memset(wps, 0, sizeof(wps));
119 ie = wpabuf_head(ies);
120 ie_len = wpabuf_len(ies);
122 while (ie_len >= 2) {
124 char *sep = (num++ == 0) ? "" : ",";
133 if (id == WLAN_EID_VENDOR_SPECIFIC && elen >= 4) {
134 /* Vendor specific */
135 if (WPA_GET_BE32(ie) == WPS_IE_VENDOR_TYPE) {
137 char model_name[WPS_NAME_LEN + 1];
138 const u8 *data = &ie[4];
139 size_t data_len = elen - 4;
141 os_memset(model_name, 0, sizeof(model_name));
142 if (get_wps_name(model_name, WPS_NAME_LEN, data,
144 os_snprintf(wps, sizeof(wps),
145 ",wps:%s", model_name);
149 ret = os_snprintf(fpos, fend - fpos,
150 "%s%d(%02x%02x%02x,%d)",
151 sep, id, ie[0], ie[1], ie[2], ie[3]);
153 if (id == WLAN_EID_HT_CAP && elen >= 2) {
154 /* HT Capabilities (802.11n) */
155 os_snprintf(htcap, sizeof(htcap),
159 if (id == WLAN_EID_HT_CAP && elen >= 3) {
160 /* HT Capabilities (802.11n), A-MPDU information
162 os_snprintf(htagg, sizeof(htagg),
163 ",htagg:%02hx", (u16) ie[2]);
165 if (id == WLAN_EID_HT_CAP && elen >= 7) {
166 /* HT Capabilities (802.11n), MCS information */
167 os_snprintf(htmcs, sizeof(htmcs),
169 (u16) WPA_GET_LE32(ie + 3));
171 if (id == WLAN_EID_VHT_CAP && elen >= 4) {
172 /* VHT Capabilities (802.11ac) */
173 os_snprintf(vhtcap, sizeof(vhtcap),
177 if (id == WLAN_EID_VHT_CAP && elen >= 8) {
178 /* VHT Capabilities (802.11ac), RX MCS
180 os_snprintf(vhtrxmcs, sizeof(vhtrxmcs),
182 WPA_GET_LE32(ie + 4));
184 if (id == WLAN_EID_VHT_CAP && elen >= 12) {
185 /* VHT Capabilities (802.11ac), TX MCS
187 os_snprintf(vhttxmcs, sizeof(vhttxmcs),
189 WPA_GET_LE32(ie + 8));
191 if (id == WLAN_EID_EXT_CAPAB) {
192 /* Extended Capabilities */
194 int len = (elen < MAX_EXTCAP) ? elen :
198 p += os_snprintf(extcap, sizeof(extcap),
200 for (i = 0; i < len; i++) {
203 lim = sizeof(extcap) -
207 p += os_snprintf(p, lim, "%02x",
211 if (id == WLAN_EID_PWR_CAPABILITY && elen == 2) {
213 os_snprintf(txpow, sizeof(txpow),
218 ret = os_snprintf(fpos, fend - fpos, "%s%d", sep, id);
220 if (os_snprintf_error(fend - fpos, ret))
228 ret = os_snprintf(fpos, fend - fpos, "%s%s%s%s%s%s%s%s%s",
229 htcap, htagg, htmcs, vhtcap, vhtrxmcs, vhttxmcs,
231 if (os_snprintf_error(fend - fpos, ret)) {
238 int retrieve_sta_taxonomy(const struct hostapd_data *hapd,
239 struct sta_info *sta, char *buf, size_t buflen)
244 if (!sta->probe_ie_taxonomy || !sta->assoc_ie_taxonomy)
247 ret = os_snprintf(buf, buflen, "wifi4|probe:");
248 if (os_snprintf_error(buflen, ret))
253 ie_to_string(pos, end - pos, sta->probe_ie_taxonomy);
254 pos = os_strchr(pos, '\0');
257 ret = os_snprintf(pos, end - pos, "|assoc:");
258 if (os_snprintf_error(end - pos, ret))
261 ie_to_string(pos, end - pos, sta->assoc_ie_taxonomy);
262 pos = os_strchr(pos, '\0');
267 void taxonomy_sta_info_probe_req(const struct hostapd_data *hapd,
268 struct sta_info *sta,
269 const u8 *ie, size_t ie_len)
271 wpabuf_free(sta->probe_ie_taxonomy);
272 sta->probe_ie_taxonomy = wpabuf_alloc_copy(ie, ie_len);
276 void taxonomy_hostapd_sta_info_probe_req(const struct hostapd_data *hapd,
277 struct hostapd_sta_info *info,
278 const u8 *ie, size_t ie_len)
280 wpabuf_free(info->probe_ie_taxonomy);
281 info->probe_ie_taxonomy = wpabuf_alloc_copy(ie, ie_len);
285 void taxonomy_sta_info_assoc_req(const struct hostapd_data *hapd,
286 struct sta_info *sta,
287 const u8 *ie, size_t ie_len)
289 wpabuf_free(sta->assoc_ie_taxonomy);
290 sta->assoc_ie_taxonomy = wpabuf_alloc_copy(ie, ie_len);