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