1 /*
2 * Control interface for shared AP commands
3 * Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "utils/includes.h"
10
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
13 #include "common/sae.h"
14 #include "eapol_auth/eapol_auth_sm.h"
15 #include "fst/fst_ctrl_iface.h"
16 #include "hostapd.h"
17 #include "ieee802_1x.h"
18 #include "wpa_auth.h"
19 #include "ieee802_11.h"
20 #include "sta_info.h"
21 #include "wps_hostapd.h"
22 #include "p2p_hostapd.h"
23 #include "ctrl_iface_ap.h"
24 #include "ap_drv_ops.h"
25 #include "mbo_ap.h"
26 #include "taxonomy.h"
27
28
hostapd_write_ht_mcs_bitmask(char * buf,size_t buflen,size_t curr_len,const u8 * mcs_set)29 static size_t hostapd_write_ht_mcs_bitmask(char *buf, size_t buflen,
30 size_t curr_len, const u8 *mcs_set)
31 {
32 int ret;
33 size_t len = curr_len;
34
35 ret = os_snprintf(buf + len, buflen - len,
36 "ht_mcs_bitmask=");
37 if (os_snprintf_error(buflen - len, ret))
38 return len;
39 len += ret;
40
41 /* 77 first bits (+ 3 reserved bits) */
42 len += wpa_snprintf_hex(buf + len, buflen - len, mcs_set, 10);
43
44 ret = os_snprintf(buf + len, buflen - len, "\n");
45 if (os_snprintf_error(buflen - len, ret))
46 return curr_len;
47 len += ret;
48
49 return len;
50 }
51
52
hostapd_get_sta_tx_rx(struct hostapd_data * hapd,struct sta_info * sta,char * buf,size_t buflen)53 static int hostapd_get_sta_tx_rx(struct hostapd_data *hapd,
54 struct sta_info *sta,
55 char *buf, size_t buflen)
56 {
57 struct hostap_sta_driver_data data;
58 int ret;
59 int len = 0;
60
61 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
62 return 0;
63
64 ret = os_snprintf(buf, buflen, "rx_packets=%lu\ntx_packets=%lu\n"
65 "rx_bytes=%llu\ntx_bytes=%llu\ninactive_msec=%lu\n"
66 "signal=%d\n",
67 data.rx_packets, data.tx_packets,
68 data.rx_bytes, data.tx_bytes, data.inactive_msec,
69 data.signal);
70 if (os_snprintf_error(buflen, ret))
71 return 0;
72 len += ret;
73
74 ret = os_snprintf(buf + len, buflen - len, "rx_rate_info=%lu",
75 data.current_rx_rate);
76 if (os_snprintf_error(buflen - len, ret))
77 return len;
78 len += ret;
79 if (data.flags & STA_DRV_DATA_RX_MCS) {
80 ret = os_snprintf(buf + len, buflen - len, " mcs %u",
81 data.rx_mcs);
82 if (!os_snprintf_error(buflen - len, ret))
83 len += ret;
84 }
85 if (data.flags & STA_DRV_DATA_RX_VHT_MCS) {
86 ret = os_snprintf(buf + len, buflen - len, " vhtmcs %u",
87 data.rx_vhtmcs);
88 if (!os_snprintf_error(buflen - len, ret))
89 len += ret;
90 }
91 if (data.flags & STA_DRV_DATA_RX_VHT_NSS) {
92 ret = os_snprintf(buf + len, buflen - len, " vhtnss %u",
93 data.rx_vht_nss);
94 if (!os_snprintf_error(buflen - len, ret))
95 len += ret;
96 }
97 if (data.flags & STA_DRV_DATA_RX_SHORT_GI) {
98 ret = os_snprintf(buf + len, buflen - len, " shortGI");
99 if (!os_snprintf_error(buflen - len, ret))
100 len += ret;
101 }
102 ret = os_snprintf(buf + len, buflen - len, "\n");
103 if (!os_snprintf_error(buflen - len, ret))
104 len += ret;
105
106 ret = os_snprintf(buf + len, buflen - len, "tx_rate_info=%lu",
107 data.current_tx_rate);
108 if (os_snprintf_error(buflen - len, ret))
109 return len;
110 len += ret;
111 if (data.flags & STA_DRV_DATA_TX_MCS) {
112 ret = os_snprintf(buf + len, buflen - len, " mcs %u",
113 data.tx_mcs);
114 if (!os_snprintf_error(buflen - len, ret))
115 len += ret;
116 }
117 if (data.flags & STA_DRV_DATA_TX_VHT_MCS) {
118 ret = os_snprintf(buf + len, buflen - len, " vhtmcs %u",
119 data.tx_vhtmcs);
120 if (!os_snprintf_error(buflen - len, ret))
121 len += ret;
122 }
123 if (data.flags & STA_DRV_DATA_TX_VHT_NSS) {
124 ret = os_snprintf(buf + len, buflen - len, " vhtnss %u",
125 data.tx_vht_nss);
126 if (!os_snprintf_error(buflen - len, ret))
127 len += ret;
128 }
129 if (data.flags & STA_DRV_DATA_TX_SHORT_GI) {
130 ret = os_snprintf(buf + len, buflen - len, " shortGI");
131 if (!os_snprintf_error(buflen - len, ret))
132 len += ret;
133 }
134 ret = os_snprintf(buf + len, buflen - len, "\n");
135 if (!os_snprintf_error(buflen - len, ret))
136 len += ret;
137
138 if ((sta->flags & WLAN_STA_VHT) && sta->vht_capabilities) {
139 ret = os_snprintf(buf + len, buflen - len,
140 "rx_vht_mcs_map=%04x\n"
141 "tx_vht_mcs_map=%04x\n",
142 le_to_host16(sta->vht_capabilities->
143 vht_supported_mcs_set.rx_map),
144 le_to_host16(sta->vht_capabilities->
145 vht_supported_mcs_set.tx_map));
146 if (!os_snprintf_error(buflen - len, ret))
147 len += ret;
148 }
149
150 if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities) {
151 len = hostapd_write_ht_mcs_bitmask(buf, buflen, len,
152 sta->ht_capabilities->
153 supported_mcs_set);
154 }
155
156 if (data.flags & STA_DRV_DATA_LAST_ACK_RSSI) {
157 ret = os_snprintf(buf + len, buflen - len,
158 "last_ack_signal=%d\n", data.last_ack_rssi);
159 if (!os_snprintf_error(buflen - len, ret))
160 len += ret;
161 }
162
163 return len;
164 }
165
166
hostapd_get_sta_conn_time(struct sta_info * sta,char * buf,size_t buflen)167 static int hostapd_get_sta_conn_time(struct sta_info *sta,
168 char *buf, size_t buflen)
169 {
170 struct os_reltime age;
171 int ret;
172
173 if (!sta->connected_time.sec)
174 return 0;
175
176 os_reltime_age(&sta->connected_time, &age);
177
178 ret = os_snprintf(buf, buflen, "connected_time=%u\n",
179 (unsigned int) age.sec);
180 if (os_snprintf_error(buflen, ret))
181 return 0;
182 return ret;
183 }
184
185
timeout_next_str(int val)186 static const char * timeout_next_str(int val)
187 {
188 switch (val) {
189 case STA_NULLFUNC:
190 return "NULLFUNC POLL";
191 case STA_DISASSOC:
192 return "DISASSOC";
193 case STA_DEAUTH:
194 return "DEAUTH";
195 case STA_REMOVE:
196 return "REMOVE";
197 case STA_DISASSOC_FROM_CLI:
198 return "DISASSOC_FROM_CLI";
199 }
200
201 return "?";
202 }
203
204
hostapd_ctrl_iface_sta_mib(struct hostapd_data * hapd,struct sta_info * sta,char * buf,size_t buflen)205 static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
206 struct sta_info *sta,
207 char *buf, size_t buflen)
208 {
209 int len, res, ret, i;
210 const char *keyid;
211
212 if (!sta)
213 return 0;
214
215 len = 0;
216 ret = os_snprintf(buf + len, buflen - len, MACSTR "\nflags=",
217 MAC2STR(sta->addr));
218 if (os_snprintf_error(buflen - len, ret))
219 return len;
220 len += ret;
221
222 ret = ap_sta_flags_txt(sta->flags, buf + len, buflen - len);
223 if (ret < 0)
224 return len;
225 len += ret;
226
227 ret = os_snprintf(buf + len, buflen - len, "\naid=%d\ncapability=0x%x\n"
228 "listen_interval=%d\nsupported_rates=",
229 sta->aid, sta->capability, sta->listen_interval);
230 if (os_snprintf_error(buflen - len, ret))
231 return len;
232 len += ret;
233
234 for (i = 0; i < sta->supported_rates_len; i++) {
235 ret = os_snprintf(buf + len, buflen - len, "%02x%s",
236 sta->supported_rates[i],
237 i + 1 < sta->supported_rates_len ? " " : "");
238 if (os_snprintf_error(buflen - len, ret))
239 return len;
240 len += ret;
241 }
242
243 ret = os_snprintf(buf + len, buflen - len, "\ntimeout_next=%s\n",
244 timeout_next_str(sta->timeout_next));
245 if (os_snprintf_error(buflen - len, ret))
246 return len;
247 len += ret;
248
249 res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len);
250 if (res >= 0)
251 len += res;
252 res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len);
253 if (res >= 0)
254 len += res;
255 res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
256 if (res >= 0)
257 len += res;
258 res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len,
259 buflen - len);
260 if (res >= 0)
261 len += res;
262 res = hostapd_p2p_get_mib_sta(hapd, sta, buf + len, buflen - len);
263 if (res >= 0)
264 len += res;
265
266 len += hostapd_get_sta_tx_rx(hapd, sta, buf + len, buflen - len);
267 len += hostapd_get_sta_conn_time(sta, buf + len, buflen - len);
268
269 #ifdef CONFIG_SAE
270 if (sta->sae && sta->sae->state == SAE_ACCEPTED) {
271 res = os_snprintf(buf + len, buflen - len, "sae_group=%d\n",
272 sta->sae->group);
273 if (!os_snprintf_error(buflen - len, res))
274 len += res;
275 }
276 #endif /* CONFIG_SAE */
277
278 if (sta->vlan_id > 0) {
279 res = os_snprintf(buf + len, buflen - len, "vlan_id=%d\n",
280 sta->vlan_id);
281 if (!os_snprintf_error(buflen - len, res))
282 len += res;
283 }
284
285 res = mbo_ap_get_info(sta, buf + len, buflen - len);
286 if (res >= 0)
287 len += res;
288
289 if (sta->supp_op_classes &&
290 buflen - len > (unsigned) (17 + 2 * sta->supp_op_classes[0])) {
291 len += os_snprintf(buf + len, buflen - len, "supp_op_classes=");
292 len += wpa_snprintf_hex(buf + len, buflen - len,
293 sta->supp_op_classes + 1,
294 sta->supp_op_classes[0]);
295 len += os_snprintf(buf + len, buflen - len, "\n");
296 }
297
298 if (sta->power_capab) {
299 ret = os_snprintf(buf + len, buflen - len,
300 "min_txpower=%d\n"
301 "max_txpower=%d\n",
302 sta->min_tx_power, sta->max_tx_power);
303 if (!os_snprintf_error(buflen - len, ret))
304 len += ret;
305 }
306
307 #ifdef CONFIG_IEEE80211AC
308 if ((sta->flags & WLAN_STA_VHT) && sta->vht_capabilities) {
309 res = os_snprintf(buf + len, buflen - len,
310 "vht_caps_info=0x%08x\n",
311 le_to_host32(sta->vht_capabilities->
312 vht_capabilities_info));
313 if (!os_snprintf_error(buflen - len, res))
314 len += res;
315 }
316 #endif /* CONFIG_IEEE80211AC */
317
318 #ifdef CONFIG_IEEE80211N
319 if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities) {
320 res = os_snprintf(buf + len, buflen - len,
321 "ht_caps_info=0x%04x\n",
322 le_to_host16(sta->ht_capabilities->
323 ht_capabilities_info));
324 if (!os_snprintf_error(buflen - len, res))
325 len += res;
326 }
327 #endif /* CONFIG_IEEE80211N */
328
329 if (sta->ext_capability &&
330 buflen - len > (unsigned) (11 + 2 * sta->ext_capability[0])) {
331 len += os_snprintf(buf + len, buflen - len, "ext_capab=");
332 len += wpa_snprintf_hex(buf + len, buflen - len,
333 sta->ext_capability + 1,
334 sta->ext_capability[0]);
335 len += os_snprintf(buf + len, buflen - len, "\n");
336 }
337
338 if (sta->flags & WLAN_STA_WDS && sta->ifname_wds) {
339 ret = os_snprintf(buf + len, buflen - len,
340 "wds_sta_ifname=%s\n", sta->ifname_wds);
341 if (!os_snprintf_error(buflen - len, ret))
342 len += ret;
343 }
344
345 keyid = ap_sta_wpa_get_keyid(hapd, sta);
346 if (keyid) {
347 ret = os_snprintf(buf + len, buflen - len, "keyid=%s\n", keyid);
348 if (!os_snprintf_error(buflen - len, ret))
349 len += ret;
350 }
351
352 return len;
353 }
354
355
hostapd_ctrl_iface_sta_first(struct hostapd_data * hapd,char * buf,size_t buflen)356 int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
357 char *buf, size_t buflen)
358 {
359 return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
360 }
361
362
hostapd_ctrl_iface_sta(struct hostapd_data * hapd,const char * txtaddr,char * buf,size_t buflen)363 int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
364 char *buf, size_t buflen)
365 {
366 u8 addr[ETH_ALEN];
367 int ret;
368 const char *pos;
369 struct sta_info *sta;
370
371 if (hwaddr_aton(txtaddr, addr)) {
372 ret = os_snprintf(buf, buflen, "FAIL\n");
373 if (os_snprintf_error(buflen, ret))
374 return 0;
375 return ret;
376 }
377
378 sta = ap_get_sta(hapd, addr);
379 if (sta == NULL)
380 return -1;
381
382 pos = os_strchr(txtaddr, ' ');
383 if (pos) {
384 pos++;
385
386 #ifdef HOSTAPD_DUMP_STATE
387 if (os_strcmp(pos, "eapol") == 0) {
388 if (sta->eapol_sm == NULL)
389 return -1;
390 return eapol_auth_dump_state(sta->eapol_sm, buf,
391 buflen);
392 }
393 #endif /* HOSTAPD_DUMP_STATE */
394
395 return -1;
396 }
397
398 ret = hostapd_ctrl_iface_sta_mib(hapd, sta, buf, buflen);
399 ret += fst_ctrl_iface_mb_info(addr, buf + ret, buflen - ret);
400
401 return ret;
402 }
403
404
hostapd_ctrl_iface_sta_next(struct hostapd_data * hapd,const char * txtaddr,char * buf,size_t buflen)405 int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
406 char *buf, size_t buflen)
407 {
408 u8 addr[ETH_ALEN];
409 struct sta_info *sta;
410 int ret;
411
412 if (hwaddr_aton(txtaddr, addr) ||
413 (sta = ap_get_sta(hapd, addr)) == NULL) {
414 ret = os_snprintf(buf, buflen, "FAIL\n");
415 if (os_snprintf_error(buflen, ret))
416 return 0;
417 return ret;
418 }
419
420 if (!sta->next)
421 return 0;
422
423 return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
424 }
425
426
427 #ifdef CONFIG_P2P_MANAGER
p2p_manager_disconnect(struct hostapd_data * hapd,u16 stype,u8 minor_reason_code,const u8 * addr)428 static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype,
429 u8 minor_reason_code, const u8 *addr)
430 {
431 struct ieee80211_mgmt *mgmt;
432 int ret;
433 u8 *pos;
434
435 if (!hapd->drv_priv || !hapd->driver->send_frame)
436 return -1;
437
438 mgmt = os_zalloc(sizeof(*mgmt) + 100);
439 if (mgmt == NULL)
440 return -1;
441
442 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, stype);
443 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "P2P: Disconnect STA " MACSTR
444 " with minor reason code %u (stype=%u (%s))",
445 MAC2STR(addr), minor_reason_code, stype,
446 fc2str(le_to_host16(mgmt->frame_control)));
447
448 os_memcpy(mgmt->da, addr, ETH_ALEN);
449 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
450 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
451 if (stype == WLAN_FC_STYPE_DEAUTH) {
452 mgmt->u.deauth.reason_code =
453 host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
454 pos = mgmt->u.deauth.variable;
455 } else {
456 mgmt->u.disassoc.reason_code =
457 host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
458 pos = mgmt->u.disassoc.variable;
459 }
460
461 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
462 *pos++ = 4 + 3 + 1;
463 WPA_PUT_BE32(pos, P2P_IE_VENDOR_TYPE);
464 pos += 4;
465
466 *pos++ = P2P_ATTR_MINOR_REASON_CODE;
467 WPA_PUT_LE16(pos, 1);
468 pos += 2;
469 *pos++ = minor_reason_code;
470
471 ret = hapd->driver->send_frame(hapd->drv_priv, (u8 *) mgmt,
472 pos - (u8 *) mgmt, 1);
473 os_free(mgmt);
474
475 return ret < 0 ? -1 : 0;
476 }
477 #endif /* CONFIG_P2P_MANAGER */
478
479
hostapd_ctrl_iface_deauthenticate(struct hostapd_data * hapd,const char * txtaddr)480 int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
481 const char *txtaddr)
482 {
483 u8 addr[ETH_ALEN];
484 struct sta_info *sta;
485 const char *pos;
486 u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
487
488 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DEAUTHENTICATE %s",
489 txtaddr);
490
491 if (hwaddr_aton(txtaddr, addr))
492 return -1;
493
494 pos = os_strstr(txtaddr, " reason=");
495 if (pos)
496 reason = atoi(pos + 8);
497
498 pos = os_strstr(txtaddr, " test=");
499 if (pos) {
500 struct ieee80211_mgmt mgmt;
501 int encrypt;
502 if (!hapd->drv_priv || !hapd->driver->send_frame)
503 return -1;
504 pos += 6;
505 encrypt = atoi(pos);
506 os_memset(&mgmt, 0, sizeof(mgmt));
507 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
508 WLAN_FC_STYPE_DEAUTH);
509 os_memcpy(mgmt.da, addr, ETH_ALEN);
510 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
511 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
512 mgmt.u.deauth.reason_code = host_to_le16(reason);
513 if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt,
514 IEEE80211_HDRLEN +
515 sizeof(mgmt.u.deauth),
516 encrypt) < 0)
517 return -1;
518 return 0;
519 }
520
521 #ifdef CONFIG_P2P_MANAGER
522 pos = os_strstr(txtaddr, " p2p=");
523 if (pos) {
524 return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DEAUTH,
525 atoi(pos + 5), addr);
526 }
527 #endif /* CONFIG_P2P_MANAGER */
528
529 if (os_strstr(txtaddr, " tx=0"))
530 hostapd_drv_sta_remove(hapd, addr);
531 else
532 hostapd_drv_sta_deauth(hapd, addr, reason);
533 sta = ap_get_sta(hapd, addr);
534 if (sta)
535 ap_sta_deauthenticate(hapd, sta, reason);
536 else if (addr[0] == 0xff)
537 hostapd_free_stas(hapd);
538
539 return 0;
540 }
541
542
hostapd_ctrl_iface_disassociate(struct hostapd_data * hapd,const char * txtaddr)543 int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
544 const char *txtaddr)
545 {
546 u8 addr[ETH_ALEN];
547 struct sta_info *sta;
548 const char *pos;
549 u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
550
551 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DISASSOCIATE %s",
552 txtaddr);
553
554 if (hwaddr_aton(txtaddr, addr))
555 return -1;
556
557 pos = os_strstr(txtaddr, " reason=");
558 if (pos)
559 reason = atoi(pos + 8);
560
561 pos = os_strstr(txtaddr, " test=");
562 if (pos) {
563 struct ieee80211_mgmt mgmt;
564 int encrypt;
565 if (!hapd->drv_priv || !hapd->driver->send_frame)
566 return -1;
567 pos += 6;
568 encrypt = atoi(pos);
569 os_memset(&mgmt, 0, sizeof(mgmt));
570 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
571 WLAN_FC_STYPE_DISASSOC);
572 os_memcpy(mgmt.da, addr, ETH_ALEN);
573 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
574 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
575 mgmt.u.disassoc.reason_code = host_to_le16(reason);
576 if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt,
577 IEEE80211_HDRLEN +
578 sizeof(mgmt.u.deauth),
579 encrypt) < 0)
580 return -1;
581 return 0;
582 }
583
584 #ifdef CONFIG_P2P_MANAGER
585 pos = os_strstr(txtaddr, " p2p=");
586 if (pos) {
587 return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DISASSOC,
588 atoi(pos + 5), addr);
589 }
590 #endif /* CONFIG_P2P_MANAGER */
591
592 if (os_strstr(txtaddr, " tx=0"))
593 hostapd_drv_sta_remove(hapd, addr);
594 else
595 hostapd_drv_sta_disassoc(hapd, addr, reason);
596 sta = ap_get_sta(hapd, addr);
597 if (sta)
598 ap_sta_disassociate(hapd, sta, reason);
599 else if (addr[0] == 0xff)
600 hostapd_free_stas(hapd);
601
602 return 0;
603 }
604
605
606 #ifdef CONFIG_TAXONOMY
hostapd_ctrl_iface_signature(struct hostapd_data * hapd,const char * txtaddr,char * buf,size_t buflen)607 int hostapd_ctrl_iface_signature(struct hostapd_data *hapd,
608 const char *txtaddr,
609 char *buf, size_t buflen)
610 {
611 u8 addr[ETH_ALEN];
612 struct sta_info *sta;
613
614 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE SIGNATURE %s", txtaddr);
615
616 if (hwaddr_aton(txtaddr, addr))
617 return -1;
618
619 sta = ap_get_sta(hapd, addr);
620 if (!sta)
621 return -1;
622
623 return retrieve_sta_taxonomy(hapd, sta, buf, buflen);
624 }
625 #endif /* CONFIG_TAXONOMY */
626
627
hostapd_ctrl_iface_poll_sta(struct hostapd_data * hapd,const char * txtaddr)628 int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd,
629 const char *txtaddr)
630 {
631 u8 addr[ETH_ALEN];
632 struct sta_info *sta;
633
634 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE POLL_STA %s", txtaddr);
635
636 if (hwaddr_aton(txtaddr, addr))
637 return -1;
638
639 sta = ap_get_sta(hapd, addr);
640 if (!sta)
641 return -1;
642
643 hostapd_drv_poll_client(hapd, hapd->own_addr, addr,
644 sta->flags & WLAN_STA_WMM);
645 return 0;
646 }
647
648
hostapd_ctrl_iface_status(struct hostapd_data * hapd,char * buf,size_t buflen)649 int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
650 size_t buflen)
651 {
652 struct hostapd_iface *iface = hapd->iface;
653 struct hostapd_hw_modes *mode = iface->current_mode;
654 int len = 0, ret, j;
655 size_t i;
656
657 ret = os_snprintf(buf + len, buflen - len,
658 "state=%s\n"
659 "phy=%s\n"
660 "freq=%d\n"
661 "num_sta_non_erp=%d\n"
662 "num_sta_no_short_slot_time=%d\n"
663 "num_sta_no_short_preamble=%d\n"
664 "olbc=%d\n"
665 "num_sta_ht_no_gf=%d\n"
666 "num_sta_no_ht=%d\n"
667 "num_sta_ht_20_mhz=%d\n"
668 "num_sta_ht40_intolerant=%d\n"
669 "olbc_ht=%d\n"
670 "ht_op_mode=0x%x\n",
671 hostapd_state_text(iface->state),
672 iface->phy,
673 iface->freq,
674 iface->num_sta_non_erp,
675 iface->num_sta_no_short_slot_time,
676 iface->num_sta_no_short_preamble,
677 iface->olbc,
678 iface->num_sta_ht_no_gf,
679 iface->num_sta_no_ht,
680 iface->num_sta_ht_20mhz,
681 iface->num_sta_ht40_intolerant,
682 iface->olbc_ht,
683 iface->ht_op_mode);
684 if (os_snprintf_error(buflen - len, ret))
685 return len;
686 len += ret;
687
688 if (!iface->cac_started || !iface->dfs_cac_ms) {
689 ret = os_snprintf(buf + len, buflen - len,
690 "cac_time_seconds=%d\n"
691 "cac_time_left_seconds=N/A\n",
692 iface->dfs_cac_ms / 1000);
693 } else {
694 /* CAC started and CAC time set - calculate remaining time */
695 struct os_reltime now;
696 unsigned int left_time;
697
698 os_reltime_age(&iface->dfs_cac_start, &now);
699 left_time = iface->dfs_cac_ms / 1000 - now.sec;
700 ret = os_snprintf(buf + len, buflen - len,
701 "cac_time_seconds=%u\n"
702 "cac_time_left_seconds=%u\n",
703 iface->dfs_cac_ms / 1000,
704 left_time);
705 }
706 if (os_snprintf_error(buflen - len, ret))
707 return len;
708 len += ret;
709
710 ret = os_snprintf(buf + len, buflen - len,
711 "channel=%u\n"
712 "secondary_channel=%d\n"
713 "ieee80211n=%d\n"
714 "ieee80211ac=%d\n"
715 "beacon_int=%u\n"
716 "dtim_period=%d\n",
717 iface->conf->channel,
718 iface->conf->ieee80211n && !hapd->conf->disable_11n ?
719 iface->conf->secondary_channel : 0,
720 iface->conf->ieee80211n && !hapd->conf->disable_11n,
721 iface->conf->ieee80211ac &&
722 !hapd->conf->disable_11ac,
723 iface->conf->beacon_int,
724 hapd->conf->dtim_period);
725 if (os_snprintf_error(buflen - len, ret))
726 return len;
727 len += ret;
728 if (iface->conf->ieee80211ac && !hapd->conf->disable_11ac) {
729 ret = os_snprintf(buf + len, buflen - len,
730 "vht_oper_chwidth=%d\n"
731 "vht_oper_centr_freq_seg0_idx=%d\n"
732 "vht_oper_centr_freq_seg1_idx=%d\n"
733 "vht_caps_info=%08x\n",
734 iface->conf->vht_oper_chwidth,
735 iface->conf->vht_oper_centr_freq_seg0_idx,
736 iface->conf->vht_oper_centr_freq_seg1_idx,
737 iface->conf->vht_capab);
738 if (os_snprintf_error(buflen - len, ret))
739 return len;
740 len += ret;
741 }
742
743 if (iface->conf->ieee80211ac && !hapd->conf->disable_11ac && mode) {
744 u16 rxmap = WPA_GET_LE16(&mode->vht_mcs_set[0]);
745 u16 txmap = WPA_GET_LE16(&mode->vht_mcs_set[4]);
746
747 ret = os_snprintf(buf + len, buflen - len,
748 "rx_vht_mcs_map=%04x\n"
749 "tx_vht_mcs_map=%04x\n",
750 rxmap, txmap);
751 if (os_snprintf_error(buflen - len, ret))
752 return len;
753 len += ret;
754 }
755
756 if (iface->conf->ieee80211n && !hapd->conf->disable_11n) {
757 ret = os_snprintf(buf + len, buflen - len,
758 "ht_caps_info=%04x\n",
759 hapd->iconf->ht_capab);
760 if (os_snprintf_error(buflen - len, ret))
761 return len;
762 len += ret;
763 }
764
765 if (iface->conf->ieee80211n && !hapd->conf->disable_11n && mode) {
766 len = hostapd_write_ht_mcs_bitmask(buf, buflen, len,
767 mode->mcs_set);
768 }
769
770 if (iface->current_rates && iface->num_rates) {
771 ret = os_snprintf(buf + len, buflen - len, "supported_rates=");
772 if (os_snprintf_error(buflen - len, ret))
773 return len;
774 len += ret;
775
776 for (j = 0; j < iface->num_rates; j++) {
777 ret = os_snprintf(buf + len, buflen - len, "%s%02x",
778 j > 0 ? " " : "",
779 iface->current_rates[j].rate / 5);
780 if (os_snprintf_error(buflen - len, ret))
781 return len;
782 len += ret;
783 }
784 ret = os_snprintf(buf + len, buflen - len, "\n");
785 if (os_snprintf_error(buflen - len, ret))
786 return len;
787 len += ret;
788 }
789
790 for (j = 0; mode && j < mode->num_channels; j++) {
791 if (mode->channels[j].freq == iface->freq) {
792 ret = os_snprintf(buf + len, buflen - len,
793 "max_txpower=%u\n",
794 mode->channels[j].max_tx_power);
795 if (os_snprintf_error(buflen - len, ret))
796 return len;
797 len += ret;
798 break;
799 }
800 }
801
802 for (i = 0; i < iface->num_bss; i++) {
803 struct hostapd_data *bss = iface->bss[i];
804 ret = os_snprintf(buf + len, buflen - len,
805 "bss[%d]=%s\n"
806 "bssid[%d]=" MACSTR "\n"
807 "ssid[%d]=%s\n"
808 "num_sta[%d]=%d\n",
809 (int) i, bss->conf->iface,
810 (int) i, MAC2STR(bss->own_addr),
811 (int) i,
812 wpa_ssid_txt(bss->conf->ssid.ssid,
813 bss->conf->ssid.ssid_len),
814 (int) i, bss->num_sta);
815 if (os_snprintf_error(buflen - len, ret))
816 return len;
817 len += ret;
818 }
819
820 if (hapd->conf->chan_util_avg_period) {
821 ret = os_snprintf(buf + len, buflen - len,
822 "chan_util_avg=%u\n",
823 iface->chan_util_average);
824 if (os_snprintf_error(buflen - len, ret))
825 return len;
826 len += ret;
827 }
828
829 return len;
830 }
831
832
hostapd_parse_csa_settings(const char * pos,struct csa_settings * settings)833 int hostapd_parse_csa_settings(const char *pos,
834 struct csa_settings *settings)
835 {
836 char *end;
837
838 os_memset(settings, 0, sizeof(*settings));
839 settings->cs_count = strtol(pos, &end, 10);
840 if (pos == end) {
841 wpa_printf(MSG_ERROR, "chanswitch: invalid cs_count provided");
842 return -1;
843 }
844
845 settings->freq_params.freq = atoi(end);
846 if (settings->freq_params.freq == 0) {
847 wpa_printf(MSG_ERROR, "chanswitch: invalid freq provided");
848 return -1;
849 }
850
851 #define SET_CSA_SETTING(str) \
852 do { \
853 const char *pos2 = os_strstr(pos, " " #str "="); \
854 if (pos2) { \
855 pos2 += sizeof(" " #str "=") - 1; \
856 settings->freq_params.str = atoi(pos2); \
857 } \
858 } while (0)
859
860 SET_CSA_SETTING(center_freq1);
861 SET_CSA_SETTING(center_freq2);
862 SET_CSA_SETTING(bandwidth);
863 SET_CSA_SETTING(sec_channel_offset);
864 settings->freq_params.ht_enabled = !!os_strstr(pos, " ht");
865 settings->freq_params.vht_enabled = !!os_strstr(pos, " vht");
866 settings->block_tx = !!os_strstr(pos, " blocktx");
867 #undef SET_CSA_SETTING
868
869 return 0;
870 }
871
872
hostapd_ctrl_iface_stop_ap(struct hostapd_data * hapd)873 int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd)
874 {
875 return hostapd_drv_stop_ap(hapd);
876 }
877
878
hostapd_ctrl_iface_pmksa_list(struct hostapd_data * hapd,char * buf,size_t len)879 int hostapd_ctrl_iface_pmksa_list(struct hostapd_data *hapd, char *buf,
880 size_t len)
881 {
882 return wpa_auth_pmksa_list(hapd->wpa_auth, buf, len);
883 }
884
885
hostapd_ctrl_iface_pmksa_flush(struct hostapd_data * hapd)886 void hostapd_ctrl_iface_pmksa_flush(struct hostapd_data *hapd)
887 {
888 wpa_auth_pmksa_flush(hapd->wpa_auth);
889 }
890
891
hostapd_ctrl_iface_pmksa_add(struct hostapd_data * hapd,char * cmd)892 int hostapd_ctrl_iface_pmksa_add(struct hostapd_data *hapd, char *cmd)
893 {
894 u8 spa[ETH_ALEN];
895 u8 pmkid[PMKID_LEN];
896 u8 pmk[PMK_LEN_MAX];
897 size_t pmk_len;
898 char *pos, *pos2;
899 int akmp = 0, expiration = 0;
900
901 /*
902 * Entry format:
903 * <STA addr> <PMKID> <PMK> <expiration in seconds> <akmp>
904 */
905
906 if (hwaddr_aton(cmd, spa))
907 return -1;
908
909 pos = os_strchr(cmd, ' ');
910 if (!pos)
911 return -1;
912 pos++;
913
914 if (hexstr2bin(pos, pmkid, PMKID_LEN) < 0)
915 return -1;
916
917 pos = os_strchr(pos, ' ');
918 if (!pos)
919 return -1;
920 pos++;
921
922 pos2 = os_strchr(pos, ' ');
923 if (!pos2)
924 return -1;
925 pmk_len = (pos2 - pos) / 2;
926 if (pmk_len < PMK_LEN || pmk_len > PMK_LEN_MAX ||
927 hexstr2bin(pos, pmk, pmk_len) < 0)
928 return -1;
929
930 pos = pos2 + 1;
931
932 if (sscanf(pos, "%d %d", &expiration, &akmp) != 2)
933 return -1;
934
935 return wpa_auth_pmksa_add2(hapd->wpa_auth, spa, pmk, pmk_len,
936 pmkid, expiration, akmp);
937 }
938
939
940 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
941 #ifdef CONFIG_MESH
942
hostapd_ctrl_iface_pmksa_list_mesh(struct hostapd_data * hapd,const u8 * addr,char * buf,size_t len)943 int hostapd_ctrl_iface_pmksa_list_mesh(struct hostapd_data *hapd,
944 const u8 *addr, char *buf, size_t len)
945 {
946 return wpa_auth_pmksa_list_mesh(hapd->wpa_auth, addr, buf, len);
947 }
948
949
hostapd_ctrl_iface_pmksa_create_entry(const u8 * aa,char * cmd)950 void * hostapd_ctrl_iface_pmksa_create_entry(const u8 *aa, char *cmd)
951 {
952 u8 spa[ETH_ALEN];
953 u8 pmkid[PMKID_LEN];
954 u8 pmk[PMK_LEN_MAX];
955 char *pos;
956 int expiration;
957
958 /*
959 * Entry format:
960 * <BSSID> <PMKID> <PMK> <expiration in seconds>
961 */
962
963 if (hwaddr_aton(cmd, spa))
964 return NULL;
965
966 pos = os_strchr(cmd, ' ');
967 if (!pos)
968 return NULL;
969 pos++;
970
971 if (hexstr2bin(pos, pmkid, PMKID_LEN) < 0)
972 return NULL;
973
974 pos = os_strchr(pos, ' ');
975 if (!pos)
976 return NULL;
977 pos++;
978
979 if (hexstr2bin(pos, pmk, PMK_LEN) < 0)
980 return NULL;
981
982 pos = os_strchr(pos, ' ');
983 if (!pos)
984 return NULL;
985 pos++;
986
987 if (sscanf(pos, "%d", &expiration) != 1)
988 return NULL;
989
990 return wpa_auth_pmksa_create_entry(aa, spa, pmk, pmkid, expiration);
991 }
992
993 #endif /* CONFIG_MESH */
994 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
995