blob: 30fa47f2db7f5803dc555cd9a119c1cea8ae987d [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / UNIX domain socket -based control interface
Roshan Pius3a1667e2018-07-03 15:17:14 -07003 * Copyright (c) 2004-2018, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#ifndef CONFIG_NATIVE_WINDOWS
12
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -070014#ifdef __NetBSD__
15#include <net/if_ether.h>
16#else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080017#include <net/ethernet.h>
Hai Shalomfdcde762020-04-02 11:19:20 -070018#endif
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080019#include <netinet/ip.h>
20#endif /* CONFIG_TESTING_OPTIONS */
21
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include <sys/un.h>
23#include <sys/stat.h>
24#include <stddef.h>
25
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080026#ifdef CONFIG_CTRL_IFACE_UDP
27#include <netdb.h>
28#endif /* CONFIG_CTRL_IFACE_UDP */
29
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "utils/common.h"
31#include "utils/eloop.h"
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -070032#include "utils/module_tests.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "common/version.h"
34#include "common/ieee802_11_defs.h"
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080035#include "common/ctrl_iface_common.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070036#ifdef CONFIG_DPP
37#include "common/dpp.h"
38#endif /* CONFIG_DPP */
39#include "common/wpa_ctrl.h"
Dmitry Shmidtff787d52015-01-12 13:01:47 -080040#include "crypto/tls.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "drivers/driver.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080042#include "eapol_auth/eapol_auth_sm.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "radius/radius_client.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080044#include "radius/radius_server.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080045#include "l2_packet/l2_packet.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#include "ap/hostapd.h"
47#include "ap/ap_config.h"
48#include "ap/ieee802_1x.h"
49#include "ap/wpa_auth.h"
Hai Shalom899fcc72020-10-19 14:38:18 -070050#include "ap/pmksa_cache_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070051#include "ap/ieee802_11.h"
52#include "ap/sta_info.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070053#include "ap/wps_hostapd.h"
54#include "ap/ctrl_iface_ap.h"
55#include "ap/ap_drv_ops.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080056#include "ap/hs20.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080057#include "ap/wnm_ap.h"
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -070058#include "ap/wpa_auth.h"
Dmitry Shmidt7f656022015-02-25 14:36:37 -080059#include "ap/beacon.h"
Dmitry Shmidt849734c2016-05-27 09:59:01 -070060#include "ap/neighbor_db.h"
61#include "ap/rrm.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070062#include "ap/dpp_hostapd.h"
Hai Shalomfdcde762020-04-02 11:19:20 -070063#include "ap/dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070064#include "wps/wps_defs.h"
65#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080066#include "fst/fst_ctrl_iface.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070067#include "config_file.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070068#include "ctrl_iface.h"
69
70
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080071#define HOSTAPD_CLI_DUP_VALUE_MAX_LEN 256
72
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080073#ifdef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080074#define HOSTAPD_CTRL_IFACE_PORT 8877
75#define HOSTAPD_CTRL_IFACE_PORT_LIMIT 50
76#define HOSTAPD_GLOBAL_CTRL_IFACE_PORT 8878
77#define HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT 50
78#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070079
80static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
Anton Nayshtutf715e8d2014-11-16 16:52:49 +020081 enum wpa_msg_type type,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070082 const char *buf, size_t len);
83
84
85static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080086 struct sockaddr_storage *from,
Roshan Pius3a1667e2018-07-03 15:17:14 -070087 socklen_t fromlen, const char *input)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070088{
Roshan Pius3a1667e2018-07-03 15:17:14 -070089 return ctrl_iface_attach(&hapd->ctrl_dst, from, fromlen, input);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070090}
91
92
93static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080094 struct sockaddr_storage *from,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070095 socklen_t fromlen)
96{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080097 return ctrl_iface_detach(&hapd->ctrl_dst, from, fromlen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070098}
99
100
101static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800102 struct sockaddr_storage *from,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103 socklen_t fromlen,
104 char *level)
105{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800106 return ctrl_iface_level(&hapd->ctrl_dst, from, fromlen, level);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700107}
108
109
110static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
111 const char *txtaddr)
112{
113 u8 addr[ETH_ALEN];
114 struct sta_info *sta;
115
116 wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);
117
118 if (hwaddr_aton(txtaddr, addr))
119 return -1;
120
121 sta = ap_get_sta(hapd, addr);
122 if (sta)
123 return 0;
124
125 wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
126 "notification", MAC2STR(addr));
127 sta = ap_sta_add(hapd, addr);
128 if (sta == NULL)
129 return -1;
130
131 hostapd_new_assoc_sta(hapd, sta, 0);
132 return 0;
133}
134
135
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700136#ifdef NEED_AP_MLME
137static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
138 const char *txtaddr)
139{
140 u8 addr[ETH_ALEN];
141 u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
142
143 wpa_printf(MSG_DEBUG, "CTRL_IFACE SA_QUERY %s", txtaddr);
144
145 if (hwaddr_aton(txtaddr, addr) ||
146 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0)
147 return -1;
148
149 ieee802_11_send_sa_query_req(hapd, addr, trans_id);
150
151 return 0;
152}
153#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154
155
156#ifdef CONFIG_WPS
157static int hostapd_ctrl_iface_wps_pin(struct hostapd_data *hapd, char *txt)
158{
159 char *pin = os_strchr(txt, ' ');
160 char *timeout_txt;
161 int timeout;
162 u8 addr_buf[ETH_ALEN], *addr = NULL;
163 char *pos;
164
165 if (pin == NULL)
166 return -1;
167 *pin++ = '\0';
168
169 timeout_txt = os_strchr(pin, ' ');
170 if (timeout_txt) {
171 *timeout_txt++ = '\0';
172 timeout = atoi(timeout_txt);
173 pos = os_strchr(timeout_txt, ' ');
174 if (pos) {
175 *pos++ = '\0';
176 if (hwaddr_aton(pos, addr_buf) == 0)
177 addr = addr_buf;
178 }
179 } else
180 timeout = 0;
181
182 return hostapd_wps_add_pin(hapd, addr, txt, pin, timeout);
183}
184
185
186static int hostapd_ctrl_iface_wps_check_pin(
187 struct hostapd_data *hapd, char *cmd, char *buf, size_t buflen)
188{
189 char pin[9];
190 size_t len;
191 char *pos;
192 int ret;
193
194 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
195 (u8 *) cmd, os_strlen(cmd));
196 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
197 if (*pos < '0' || *pos > '9')
198 continue;
199 pin[len++] = *pos;
200 if (len == 9) {
201 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
202 return -1;
203 }
204 }
205 if (len != 4 && len != 8) {
206 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
207 return -1;
208 }
209 pin[len] = '\0';
210
211 if (len == 8) {
212 unsigned int pin_val;
213 pin_val = atoi(pin);
214 if (!wps_pin_valid(pin_val)) {
215 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
216 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800217 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700218 return -1;
219 return ret;
220 }
221 }
222
223 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800224 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700225 return -1;
226
227 return ret;
228}
229
230
Dmitry Shmidt04949592012-07-19 12:16:46 -0700231#ifdef CONFIG_WPS_NFC
232static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data *hapd,
233 char *pos)
234{
235 size_t len;
236 struct wpabuf *buf;
237 int ret;
238
239 len = os_strlen(pos);
240 if (len & 0x01)
241 return -1;
242 len /= 2;
243
244 buf = wpabuf_alloc(len);
245 if (buf == NULL)
246 return -1;
247 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
248 wpabuf_free(buf);
249 return -1;
250 }
251
252 ret = hostapd_wps_nfc_tag_read(hapd, buf);
253 wpabuf_free(buf);
254
255 return ret;
256}
257
258
259static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data *hapd,
260 char *cmd, char *reply,
261 size_t max_len)
262{
263 int ndef;
264 struct wpabuf *buf;
265 int res;
266
267 if (os_strcmp(cmd, "WPS") == 0)
268 ndef = 0;
269 else if (os_strcmp(cmd, "NDEF") == 0)
270 ndef = 1;
271 else
272 return -1;
273
274 buf = hostapd_wps_nfc_config_token(hapd, ndef);
275 if (buf == NULL)
276 return -1;
277
278 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
279 wpabuf_len(buf));
280 reply[res++] = '\n';
281 reply[res] = '\0';
282
283 wpabuf_free(buf);
284
285 return res;
286}
287
288
289static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data *hapd,
290 char *reply, size_t max_len,
291 int ndef)
292{
293 struct wpabuf *buf;
294 int res;
295
296 buf = hostapd_wps_nfc_token_gen(hapd, ndef);
297 if (buf == NULL)
298 return -1;
299
300 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
301 wpabuf_len(buf));
302 reply[res++] = '\n';
303 reply[res] = '\0';
304
305 wpabuf_free(buf);
306
307 return res;
308}
309
310
311static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data *hapd,
312 char *cmd, char *reply,
313 size_t max_len)
314{
315 if (os_strcmp(cmd, "WPS") == 0)
316 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
317 max_len, 0);
318
319 if (os_strcmp(cmd, "NDEF") == 0)
320 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
321 max_len, 1);
322
323 if (os_strcmp(cmd, "enable") == 0)
324 return hostapd_wps_nfc_token_enable(hapd);
325
326 if (os_strcmp(cmd, "disable") == 0) {
327 hostapd_wps_nfc_token_disable(hapd);
328 return 0;
329 }
330
331 return -1;
332}
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800333
334
335static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data *hapd,
336 char *cmd, char *reply,
337 size_t max_len)
338{
339 struct wpabuf *buf;
340 int res;
341 char *pos;
342 int ndef;
343
344 pos = os_strchr(cmd, ' ');
345 if (pos == NULL)
346 return -1;
347 *pos++ = '\0';
348
349 if (os_strcmp(cmd, "WPS") == 0)
350 ndef = 0;
351 else if (os_strcmp(cmd, "NDEF") == 0)
352 ndef = 1;
353 else
354 return -1;
355
356 if (os_strcmp(pos, "WPS-CR") == 0)
357 buf = hostapd_wps_nfc_hs_cr(hapd, ndef);
358 else
359 buf = NULL;
360 if (buf == NULL)
361 return -1;
362
363 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
364 wpabuf_len(buf));
365 reply[res++] = '\n';
366 reply[res] = '\0';
367
368 wpabuf_free(buf);
369
370 return res;
371}
372
373
374static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data *hapd,
375 char *cmd)
376{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800377 size_t len;
378 struct wpabuf *req, *sel;
379 int ret;
380 char *pos, *role, *type, *pos2;
381
382 role = cmd;
383 pos = os_strchr(role, ' ');
384 if (pos == NULL)
385 return -1;
386 *pos++ = '\0';
387
388 type = pos;
389 pos = os_strchr(type, ' ');
390 if (pos == NULL)
391 return -1;
392 *pos++ = '\0';
393
394 pos2 = os_strchr(pos, ' ');
395 if (pos2 == NULL)
396 return -1;
397 *pos2++ = '\0';
398
399 len = os_strlen(pos);
400 if (len & 0x01)
401 return -1;
402 len /= 2;
403
404 req = wpabuf_alloc(len);
405 if (req == NULL)
406 return -1;
407 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
408 wpabuf_free(req);
409 return -1;
410 }
411
412 len = os_strlen(pos2);
413 if (len & 0x01) {
414 wpabuf_free(req);
415 return -1;
416 }
417 len /= 2;
418
419 sel = wpabuf_alloc(len);
420 if (sel == NULL) {
421 wpabuf_free(req);
422 return -1;
423 }
424 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
425 wpabuf_free(req);
426 wpabuf_free(sel);
427 return -1;
428 }
429
430 if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) {
431 ret = hostapd_wps_nfc_report_handover(hapd, req, sel);
432 } else {
433 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
434 "reported: role=%s type=%s", role, type);
435 ret = -1;
436 }
437 wpabuf_free(req);
438 wpabuf_free(sel);
439
440 return ret;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800441}
442
Dmitry Shmidt04949592012-07-19 12:16:46 -0700443#endif /* CONFIG_WPS_NFC */
444
445
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data *hapd, char *txt,
447 char *buf, size_t buflen)
448{
449 int timeout = 300;
450 char *pos;
451 const char *pin_txt;
452
453 pos = os_strchr(txt, ' ');
454 if (pos)
455 *pos++ = '\0';
456
457 if (os_strcmp(txt, "disable") == 0) {
458 hostapd_wps_ap_pin_disable(hapd);
459 return os_snprintf(buf, buflen, "OK\n");
460 }
461
462 if (os_strcmp(txt, "random") == 0) {
463 if (pos)
464 timeout = atoi(pos);
465 pin_txt = hostapd_wps_ap_pin_random(hapd, timeout);
466 if (pin_txt == NULL)
467 return -1;
468 return os_snprintf(buf, buflen, "%s", pin_txt);
469 }
470
471 if (os_strcmp(txt, "get") == 0) {
472 pin_txt = hostapd_wps_ap_pin_get(hapd);
473 if (pin_txt == NULL)
474 return -1;
475 return os_snprintf(buf, buflen, "%s", pin_txt);
476 }
477
478 if (os_strcmp(txt, "set") == 0) {
479 char *pin;
480 if (pos == NULL)
481 return -1;
482 pin = pos;
483 pos = os_strchr(pos, ' ');
484 if (pos) {
485 *pos++ = '\0';
486 timeout = atoi(pos);
487 }
488 if (os_strlen(pin) > buflen)
489 return -1;
490 if (hostapd_wps_ap_pin_set(hapd, pin, timeout) < 0)
491 return -1;
492 return os_snprintf(buf, buflen, "%s", pin);
493 }
494
495 return -1;
496}
497
498
499static int hostapd_ctrl_iface_wps_config(struct hostapd_data *hapd, char *txt)
500{
501 char *pos;
502 char *ssid, *auth, *encr = NULL, *key = NULL;
503
504 ssid = txt;
505 pos = os_strchr(txt, ' ');
506 if (!pos)
507 return -1;
508 *pos++ = '\0';
509
510 auth = pos;
511 pos = os_strchr(pos, ' ');
512 if (pos) {
513 *pos++ = '\0';
514 encr = pos;
515 pos = os_strchr(pos, ' ');
516 if (pos) {
517 *pos++ = '\0';
518 key = pos;
519 }
520 }
521
522 return hostapd_wps_config_ap(hapd, ssid, auth, encr, key);
523}
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700524
525
526static const char * pbc_status_str(enum pbc_status status)
527{
528 switch (status) {
529 case WPS_PBC_STATUS_DISABLE:
530 return "Disabled";
531 case WPS_PBC_STATUS_ACTIVE:
532 return "Active";
533 case WPS_PBC_STATUS_TIMEOUT:
534 return "Timed-out";
535 case WPS_PBC_STATUS_OVERLAP:
536 return "Overlap";
537 default:
538 return "Unknown";
539 }
540}
541
542
543static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
544 char *buf, size_t buflen)
545{
546 int ret;
547 char *pos, *end;
548
549 pos = buf;
550 end = buf + buflen;
551
552 ret = os_snprintf(pos, end - pos, "PBC Status: %s\n",
553 pbc_status_str(hapd->wps_stats.pbc_status));
554
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800555 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700556 return pos - buf;
557 pos += ret;
558
559 ret = os_snprintf(pos, end - pos, "Last WPS result: %s\n",
560 (hapd->wps_stats.status == WPS_STATUS_SUCCESS ?
561 "Success":
562 (hapd->wps_stats.status == WPS_STATUS_FAILURE ?
563 "Failed" : "None")));
564
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800565 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700566 return pos - buf;
567 pos += ret;
568
569 /* If status == Failure - Add possible Reasons */
570 if(hapd->wps_stats.status == WPS_STATUS_FAILURE &&
571 hapd->wps_stats.failure_reason > 0) {
572 ret = os_snprintf(pos, end - pos,
573 "Failure Reason: %s\n",
574 wps_ei_str(hapd->wps_stats.failure_reason));
575
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800576 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700577 return pos - buf;
578 pos += ret;
579 }
580
581 if (hapd->wps_stats.status) {
582 ret = os_snprintf(pos, end - pos, "Peer Address: " MACSTR "\n",
583 MAC2STR(hapd->wps_stats.peer_addr));
584
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800585 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700586 return pos - buf;
587 pos += ret;
588 }
589
590 return pos - buf;
591}
592
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593#endif /* CONFIG_WPS */
594
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800595#ifdef CONFIG_HS20
596
597static int hostapd_ctrl_iface_hs20_wnm_notif(struct hostapd_data *hapd,
598 const char *cmd)
599{
600 u8 addr[ETH_ALEN];
601 const char *url;
602
603 if (hwaddr_aton(cmd, addr))
604 return -1;
605 url = cmd + 17;
606 if (*url == '\0') {
607 url = NULL;
608 } else {
609 if (*url != ' ')
610 return -1;
611 url++;
612 if (*url == '\0')
613 url = NULL;
614 }
615
616 return hs20_send_wnm_notification(hapd, addr, 1, url);
617}
618
619
620static int hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data *hapd,
621 const char *cmd)
622{
623 u8 addr[ETH_ALEN];
624 int code, reauth_delay, ret;
625 const char *pos;
626 size_t url_len;
627 struct wpabuf *req;
628
629 /* <STA MAC Addr> <Code(0/1)> <Re-auth-Delay(sec)> [URL] */
630 if (hwaddr_aton(cmd, addr))
631 return -1;
632
633 pos = os_strchr(cmd, ' ');
634 if (pos == NULL)
635 return -1;
636 pos++;
637 code = atoi(pos);
638
639 pos = os_strchr(pos, ' ');
640 if (pos == NULL)
641 return -1;
642 pos++;
643 reauth_delay = atoi(pos);
644
645 url_len = 0;
646 pos = os_strchr(pos, ' ');
647 if (pos) {
648 pos++;
649 url_len = os_strlen(pos);
650 }
651
652 req = wpabuf_alloc(4 + url_len);
653 if (req == NULL)
654 return -1;
655 wpabuf_put_u8(req, code);
656 wpabuf_put_le16(req, reauth_delay);
657 wpabuf_put_u8(req, url_len);
658 if (pos)
659 wpabuf_put_data(req, pos, url_len);
660
661 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to " MACSTR
662 " to indicate imminent deauthentication (code=%d "
663 "reauth_delay=%d)", MAC2STR(addr), code, reauth_delay);
664 ret = hs20_send_wnm_notification_deauth_req(hapd, addr, req);
665 wpabuf_free(req);
666 return ret;
667}
668
669#endif /* CONFIG_HS20 */
670
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671
Dmitry Shmidt051af732013-10-22 13:52:46 -0700672#ifdef CONFIG_INTERWORKING
673
674static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data *hapd,
675 const char *cmd)
676{
677 u8 qos_map_set[16 + 2 * 21], count = 0;
678 const char *pos = cmd;
679 int val, ret;
680
681 for (;;) {
682 if (count == sizeof(qos_map_set)) {
683 wpa_printf(MSG_ERROR, "Too many qos_map_set parameters");
684 return -1;
685 }
686
687 val = atoi(pos);
688 if (val < 0 || val > 255) {
689 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
690 return -1;
691 }
692
693 qos_map_set[count++] = val;
694 pos = os_strchr(pos, ',');
695 if (!pos)
696 break;
697 pos++;
698 }
699
700 if (count < 16 || count & 1) {
701 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
702 return -1;
703 }
704
705 ret = hostapd_drv_set_qos_map(hapd, qos_map_set, count);
706 if (ret) {
707 wpa_printf(MSG_INFO, "Failed to set QoS Map Set");
708 return -1;
709 }
710
711 os_memcpy(hapd->conf->qos_map_set, qos_map_set, count);
712 hapd->conf->qos_map_set_len = count;
713
714 return 0;
715}
716
717
718static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
719 const char *cmd)
720{
721 u8 addr[ETH_ALEN];
722 struct sta_info *sta;
723 struct wpabuf *buf;
724 u8 *qos_map_set = hapd->conf->qos_map_set;
725 u8 qos_map_set_len = hapd->conf->qos_map_set_len;
726 int ret;
727
728 if (!qos_map_set_len) {
729 wpa_printf(MSG_INFO, "QoS Map Set is not set");
730 return -1;
731 }
732
733 if (hwaddr_aton(cmd, addr))
734 return -1;
735
736 sta = ap_get_sta(hapd, addr);
737 if (sta == NULL) {
738 wpa_printf(MSG_DEBUG, "Station " MACSTR " not found "
739 "for QoS Map Configuration message",
740 MAC2STR(addr));
741 return -1;
742 }
743
744 if (!sta->qos_map_enabled) {
745 wpa_printf(MSG_DEBUG, "Station " MACSTR " did not indicate "
746 "support for QoS Map", MAC2STR(addr));
747 return -1;
748 }
749
750 buf = wpabuf_alloc(2 + 2 + qos_map_set_len);
751 if (buf == NULL)
752 return -1;
753
754 wpabuf_put_u8(buf, WLAN_ACTION_QOS);
755 wpabuf_put_u8(buf, QOS_QOS_MAP_CONFIG);
756
757 /* QoS Map Set Element */
758 wpabuf_put_u8(buf, WLAN_EID_QOS_MAP_SET);
759 wpabuf_put_u8(buf, qos_map_set_len);
760 wpabuf_put_data(buf, qos_map_set, qos_map_set_len);
761
762 ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
763 wpabuf_head(buf), wpabuf_len(buf));
764 wpabuf_free(buf);
765
766 return ret;
767}
768
769#endif /* CONFIG_INTERWORKING */
770
771
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700772#ifdef CONFIG_WNM_AP
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800773
774static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data *hapd,
775 const char *cmd)
776{
777 u8 addr[ETH_ALEN];
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800778 int disassoc_timer;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800779 struct sta_info *sta;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800780
781 if (hwaddr_aton(cmd, addr))
782 return -1;
783 if (cmd[17] != ' ')
784 return -1;
785 disassoc_timer = atoi(cmd + 17);
786
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800787 sta = ap_get_sta(hapd, addr);
788 if (sta == NULL) {
789 wpa_printf(MSG_DEBUG, "Station " MACSTR
790 " not found for disassociation imminent message",
791 MAC2STR(addr));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800792 return -1;
793 }
794
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800795 return wnm_send_disassoc_imminent(hapd, sta, disassoc_timer);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800796}
797
798
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800799static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
800 const char *cmd)
801{
802 u8 addr[ETH_ALEN];
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700803 const char *url, *timerstr;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700804 int disassoc_timer;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800805 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800806
807 if (hwaddr_aton(cmd, addr))
808 return -1;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700809
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800810 sta = ap_get_sta(hapd, addr);
811 if (sta == NULL) {
812 wpa_printf(MSG_DEBUG, "Station " MACSTR
813 " not found for ESS disassociation imminent message",
814 MAC2STR(addr));
815 return -1;
816 }
817
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700818 timerstr = cmd + 17;
819 if (*timerstr != ' ')
820 return -1;
821 timerstr++;
822 disassoc_timer = atoi(timerstr);
823 if (disassoc_timer < 0 || disassoc_timer > 65535)
824 return -1;
825
826 url = os_strchr(timerstr, ' ');
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700827 if (url == NULL)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800828 return -1;
829 url++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800830
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800831 return wnm_send_ess_disassoc_imminent(hapd, sta, url, disassoc_timer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800832}
833
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800834
835static int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data *hapd,
836 const char *cmd)
837{
838 u8 addr[ETH_ALEN];
839 const char *pos, *end;
840 int disassoc_timer = 0;
841 struct sta_info *sta;
842 u8 req_mode = 0, valid_int = 0x01;
843 u8 bss_term_dur[12];
844 char *url = NULL;
845 int ret;
846 u8 nei_rep[1000];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700847 int nei_len;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800848 u8 mbo[10];
849 size_t mbo_len = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800850
851 if (hwaddr_aton(cmd, addr)) {
852 wpa_printf(MSG_DEBUG, "Invalid STA MAC address");
853 return -1;
854 }
855
856 sta = ap_get_sta(hapd, addr);
857 if (sta == NULL) {
858 wpa_printf(MSG_DEBUG, "Station " MACSTR
859 " not found for BSS TM Request message",
860 MAC2STR(addr));
861 return -1;
862 }
863
864 pos = os_strstr(cmd, " disassoc_timer=");
865 if (pos) {
866 pos += 16;
867 disassoc_timer = atoi(pos);
868 if (disassoc_timer < 0 || disassoc_timer > 65535) {
869 wpa_printf(MSG_DEBUG, "Invalid disassoc_timer");
870 return -1;
871 }
872 }
873
874 pos = os_strstr(cmd, " valid_int=");
875 if (pos) {
876 pos += 11;
877 valid_int = atoi(pos);
878 }
879
880 pos = os_strstr(cmd, " bss_term=");
881 if (pos) {
882 pos += 10;
883 req_mode |= WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED;
884 /* TODO: TSF configurable/learnable */
885 bss_term_dur[0] = 4; /* Subelement ID */
886 bss_term_dur[1] = 10; /* Length */
Hai Shalom5f92bc92019-04-18 11:54:11 -0700887 os_memset(&bss_term_dur[2], 0, 8);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800888 end = os_strchr(pos, ',');
889 if (end == NULL) {
890 wpa_printf(MSG_DEBUG, "Invalid bss_term data");
891 return -1;
892 }
893 end++;
894 WPA_PUT_LE16(&bss_term_dur[10], atoi(end));
895 }
896
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700897 nei_len = ieee802_11_parse_candidate_list(cmd, nei_rep,
898 sizeof(nei_rep));
899 if (nei_len < 0)
900 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800901
902 pos = os_strstr(cmd, " url=");
903 if (pos) {
904 size_t len;
905 pos += 5;
906 end = os_strchr(pos, ' ');
907 if (end)
908 len = end - pos;
909 else
910 len = os_strlen(pos);
911 url = os_malloc(len + 1);
912 if (url == NULL)
913 return -1;
914 os_memcpy(url, pos, len);
915 url[len] = '\0';
916 req_mode |= WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
917 }
918
919 if (os_strstr(cmd, " pref=1"))
920 req_mode |= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED;
921 if (os_strstr(cmd, " abridged=1"))
922 req_mode |= WNM_BSS_TM_REQ_ABRIDGED;
923 if (os_strstr(cmd, " disassoc_imminent=1"))
924 req_mode |= WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
925
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800926#ifdef CONFIG_MBO
927 pos = os_strstr(cmd, "mbo=");
928 if (pos) {
929 unsigned int mbo_reason, cell_pref, reassoc_delay;
930 u8 *mbo_pos = mbo;
931
932 ret = sscanf(pos, "mbo=%u:%u:%u", &mbo_reason,
933 &reassoc_delay, &cell_pref);
934 if (ret != 3) {
935 wpa_printf(MSG_DEBUG,
936 "MBO requires three arguments: mbo=<reason>:<reassoc_delay>:<cell_pref>");
Dmitry Shmidt29333592017-01-09 12:27:11 -0800937 ret = -1;
938 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800939 }
940
941 if (mbo_reason > MBO_TRANSITION_REASON_PREMIUM_AP) {
942 wpa_printf(MSG_DEBUG,
943 "Invalid MBO transition reason code %u",
944 mbo_reason);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800945 ret = -1;
946 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800947 }
948
949 /* Valid values for Cellular preference are: 0, 1, 255 */
950 if (cell_pref != 0 && cell_pref != 1 && cell_pref != 255) {
951 wpa_printf(MSG_DEBUG,
952 "Invalid MBO cellular capability %u",
953 cell_pref);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800954 ret = -1;
955 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800956 }
957
958 if (reassoc_delay > 65535 ||
959 (reassoc_delay &&
960 !(req_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT))) {
961 wpa_printf(MSG_DEBUG,
962 "MBO: Assoc retry delay is only valid in disassoc imminent mode");
Dmitry Shmidt29333592017-01-09 12:27:11 -0800963 ret = -1;
964 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800965 }
966
967 *mbo_pos++ = MBO_ATTR_ID_TRANSITION_REASON;
968 *mbo_pos++ = 1;
969 *mbo_pos++ = mbo_reason;
970 *mbo_pos++ = MBO_ATTR_ID_CELL_DATA_PREF;
971 *mbo_pos++ = 1;
972 *mbo_pos++ = cell_pref;
973
974 if (reassoc_delay) {
975 *mbo_pos++ = MBO_ATTR_ID_ASSOC_RETRY_DELAY;
976 *mbo_pos++ = 2;
977 WPA_PUT_LE16(mbo_pos, reassoc_delay);
978 mbo_pos += 2;
979 }
980
981 mbo_len = mbo_pos - mbo;
982 }
983#endif /* CONFIG_MBO */
984
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800985 ret = wnm_send_bss_tm_req(hapd, sta, req_mode, disassoc_timer,
986 valid_int, bss_term_dur, url,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700987 nei_len ? nei_rep : NULL, nei_len,
988 mbo_len ? mbo : NULL, mbo_len);
Paul Stewart092955c2017-02-06 09:13:09 -0800989#ifdef CONFIG_MBO
Dmitry Shmidt29333592017-01-09 12:27:11 -0800990fail:
Paul Stewart092955c2017-02-06 09:13:09 -0800991#endif /* CONFIG_MBO */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800992 os_free(url);
993 return ret;
994}
995
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800996
997static int hostapd_ctrl_iface_coloc_intf_req(struct hostapd_data *hapd,
998 const char *cmd)
999{
1000 u8 addr[ETH_ALEN];
1001 struct sta_info *sta;
1002 const char *pos;
1003 unsigned int auto_report, timeout;
1004
1005 if (hwaddr_aton(cmd, addr)) {
1006 wpa_printf(MSG_DEBUG, "Invalid STA MAC address");
1007 return -1;
1008 }
1009
1010 sta = ap_get_sta(hapd, addr);
1011 if (!sta) {
1012 wpa_printf(MSG_DEBUG, "Station " MACSTR
1013 " not found for Collocated Interference Request",
1014 MAC2STR(addr));
1015 return -1;
1016 }
1017
1018 pos = cmd + 17;
1019 if (*pos != ' ')
1020 return -1;
1021 pos++;
1022 auto_report = atoi(pos);
1023 pos = os_strchr(pos, ' ');
1024 if (!pos)
1025 return -1;
1026 pos++;
1027 timeout = atoi(pos);
1028
1029 return wnm_send_coloc_intf_req(hapd, sta, auto_report, timeout);
1030}
1031
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001032#endif /* CONFIG_WNM_AP */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001033
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001034
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001035static int hostapd_ctrl_iface_get_key_mgmt(struct hostapd_data *hapd,
1036 char *buf, size_t buflen)
1037{
1038 int ret = 0;
1039 char *pos, *end;
1040
1041 pos = buf;
1042 end = buf + buflen;
1043
1044 WPA_ASSERT(hapd->conf->wpa_key_mgmt);
1045
1046 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
1047 ret = os_snprintf(pos, end - pos, "WPA-PSK ");
1048 if (os_snprintf_error(end - pos, ret))
1049 return pos - buf;
1050 pos += ret;
1051 }
1052 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1053 ret = os_snprintf(pos, end - pos, "WPA-EAP ");
1054 if (os_snprintf_error(end - pos, ret))
1055 return pos - buf;
1056 pos += ret;
1057 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001058#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001059 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1060 ret = os_snprintf(pos, end - pos, "FT-PSK ");
1061 if (os_snprintf_error(end - pos, ret))
1062 return pos - buf;
1063 pos += ret;
1064 }
1065 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1066 ret = os_snprintf(pos, end - pos, "FT-EAP ");
1067 if (os_snprintf_error(end - pos, ret))
1068 return pos - buf;
1069 pos += ret;
1070 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001071#ifdef CONFIG_SHA384
1072 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) {
1073 ret = os_snprintf(pos, end - pos, "FT-EAP-SHA384 ");
1074 if (os_snprintf_error(end - pos, ret))
1075 return pos - buf;
1076 pos += ret;
1077 }
1078#endif /* CONFIG_SHA384 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001079#ifdef CONFIG_SAE
1080 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_SAE) {
1081 ret = os_snprintf(pos, end - pos, "FT-SAE ");
1082 if (os_snprintf_error(end - pos, ret))
1083 return pos - buf;
1084 pos += ret;
1085 }
1086#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001087#ifdef CONFIG_FILS
1088 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
1089 ret = os_snprintf(pos, end - pos, "FT-FILS-SHA256 ");
1090 if (os_snprintf_error(end - pos, ret))
1091 return pos - buf;
1092 pos += ret;
1093 }
1094 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
1095 ret = os_snprintf(pos, end - pos, "FT-FILS-SHA384 ");
1096 if (os_snprintf_error(end - pos, ret))
1097 return pos - buf;
1098 pos += ret;
1099 }
1100#endif /* CONFIG_FILS */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001101#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001102 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
1103 ret = os_snprintf(pos, end - pos, "WPA-PSK-SHA256 ");
1104 if (os_snprintf_error(end - pos, ret))
1105 return pos - buf;
1106 pos += ret;
1107 }
1108 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1109 ret = os_snprintf(pos, end - pos, "WPA-EAP-SHA256 ");
1110 if (os_snprintf_error(end - pos, ret))
1111 return pos - buf;
1112 pos += ret;
1113 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001114#ifdef CONFIG_SAE
1115 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_SAE) {
1116 ret = os_snprintf(pos, end - pos, "SAE ");
1117 if (os_snprintf_error(end - pos, ret))
1118 return pos - buf;
1119 pos += ret;
1120 }
1121#endif /* CONFIG_SAE */
1122 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
1123 ret = os_snprintf(pos, end - pos, "WPA-EAP-SUITE-B ");
1124 if (os_snprintf_error(end - pos, ret))
1125 return pos - buf;
1126 pos += ret;
1127 }
1128 if (hapd->conf->wpa_key_mgmt &
1129 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
1130 ret = os_snprintf(pos, end - pos,
1131 "WPA-EAP-SUITE-B-192 ");
1132 if (os_snprintf_error(end - pos, ret))
1133 return pos - buf;
1134 pos += ret;
1135 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001136#ifdef CONFIG_FILS
1137 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
1138 ret = os_snprintf(pos, end - pos, "FILS-SHA256 ");
1139 if (os_snprintf_error(end - pos, ret))
1140 return pos - buf;
1141 pos += ret;
1142 }
1143 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
1144 ret = os_snprintf(pos, end - pos, "FILS-SHA384 ");
1145 if (os_snprintf_error(end - pos, ret))
1146 return pos - buf;
1147 pos += ret;
1148 }
1149#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001150
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001151#ifdef CONFIG_OWE
1152 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) {
1153 ret = os_snprintf(pos, end - pos, "OWE ");
1154 if (os_snprintf_error(end - pos, ret))
1155 return pos - buf;
1156 pos += ret;
1157 }
1158#endif /* CONFIG_OWE */
1159
1160#ifdef CONFIG_DPP
1161 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) {
1162 ret = os_snprintf(pos, end - pos, "DPP ");
1163 if (os_snprintf_error(end - pos, ret))
1164 return pos - buf;
1165 pos += ret;
1166 }
1167#endif /* CONFIG_DPP */
1168
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001169 if (pos > buf && *(pos - 1) == ' ') {
1170 *(pos - 1) = '\0';
1171 pos--;
1172 }
1173
1174 return pos - buf;
1175}
1176
1177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
1179 char *buf, size_t buflen)
1180{
1181 int ret;
1182 char *pos, *end;
1183
1184 pos = buf;
1185 end = buf + buflen;
1186
1187 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
1188 "ssid=%s\n",
1189 MAC2STR(hapd->own_addr),
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001190 wpa_ssid_txt(hapd->conf->ssid.ssid,
1191 hapd->conf->ssid.ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001192 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001193 return pos - buf;
1194 pos += ret;
1195
1196#ifdef CONFIG_WPS
1197 ret = os_snprintf(pos, end - pos, "wps_state=%s\n",
1198 hapd->conf->wps_state == 0 ? "disabled" :
1199 (hapd->conf->wps_state == 1 ? "not configured" :
1200 "configured"));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001201 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202 return pos - buf;
1203 pos += ret;
1204
1205 if (hapd->conf->wps_state && hapd->conf->wpa &&
1206 hapd->conf->ssid.wpa_passphrase) {
1207 ret = os_snprintf(pos, end - pos, "passphrase=%s\n",
1208 hapd->conf->ssid.wpa_passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001209 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001210 return pos - buf;
1211 pos += ret;
1212 }
1213
1214 if (hapd->conf->wps_state && hapd->conf->wpa &&
1215 hapd->conf->ssid.wpa_psk &&
1216 hapd->conf->ssid.wpa_psk->group) {
1217 char hex[PMK_LEN * 2 + 1];
1218 wpa_snprintf_hex(hex, sizeof(hex),
1219 hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
1220 ret = os_snprintf(pos, end - pos, "psk=%s\n", hex);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001221 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 return pos - buf;
1223 pos += ret;
1224 }
1225#endif /* CONFIG_WPS */
1226
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001227 if (hapd->conf->wpa) {
1228 ret = os_snprintf(pos, end - pos, "wpa=%d\n", hapd->conf->wpa);
1229 if (os_snprintf_error(end - pos, ret))
1230 return pos - buf;
1231 pos += ret;
1232 }
1233
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 if (hapd->conf->wpa && hapd->conf->wpa_key_mgmt) {
1235 ret = os_snprintf(pos, end - pos, "key_mgmt=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001236 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237 return pos - buf;
1238 pos += ret;
1239
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001240 pos += hostapd_ctrl_iface_get_key_mgmt(hapd, pos, end - pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001241
1242 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001243 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244 return pos - buf;
1245 pos += ret;
1246 }
1247
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001248 if (hapd->conf->wpa) {
1249 ret = os_snprintf(pos, end - pos, "group_cipher=%s\n",
1250 wpa_cipher_txt(hapd->conf->wpa_group));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001251 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252 return pos - buf;
1253 pos += ret;
1254 }
1255
1256 if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->rsn_pairwise) {
1257 ret = os_snprintf(pos, end - pos, "rsn_pairwise_cipher=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001258 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259 return pos - buf;
1260 pos += ret;
1261
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001262 ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
1263 " ");
1264 if (ret < 0)
1265 return pos - buf;
1266 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267
1268 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001269 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270 return pos - buf;
1271 pos += ret;
1272 }
1273
1274 if ((hapd->conf->wpa & WPA_PROTO_WPA) && hapd->conf->wpa_pairwise) {
1275 ret = os_snprintf(pos, end - pos, "wpa_pairwise_cipher=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001276 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001277 return pos - buf;
1278 pos += ret;
1279
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001280 ret = wpa_write_ciphers(pos, end, hapd->conf->wpa_pairwise,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001281 " ");
1282 if (ret < 0)
1283 return pos - buf;
1284 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001285
1286 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001287 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001288 return pos - buf;
1289 pos += ret;
1290 }
1291
Hai Shalomfdcde762020-04-02 11:19:20 -07001292 if (hapd->conf->wpa && hapd->conf->wpa_deny_ptk0_rekey) {
1293 ret = os_snprintf(pos, end - pos, "wpa_deny_ptk0_rekey=%d\n",
1294 hapd->conf->wpa_deny_ptk0_rekey);
1295 if (os_snprintf_error(end - pos, ret))
1296 return pos - buf;
1297 pos += ret;
1298 }
1299
1300 if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->extended_key_id) {
1301 ret = os_snprintf(pos, end - pos, "extended_key_id=%d\n",
1302 hapd->conf->extended_key_id);
1303 if (os_snprintf_error(end - pos, ret))
1304 return pos - buf;
1305 pos += ret;
1306 }
1307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308 return pos - buf;
1309}
1310
1311
Roshan Pius3a1667e2018-07-03 15:17:14 -07001312static void hostapd_disassoc_accept_mac(struct hostapd_data *hapd)
1313{
1314 struct sta_info *sta;
1315 struct vlan_description vlan_id;
1316
1317 if (hapd->conf->macaddr_acl != DENY_UNLESS_ACCEPTED)
1318 return;
1319
1320 for (sta = hapd->sta_list; sta; sta = sta->next) {
1321 if (!hostapd_maclist_found(hapd->conf->accept_mac,
1322 hapd->conf->num_accept_mac,
1323 sta->addr, &vlan_id) ||
1324 (vlan_id.notempty &&
1325 vlan_compare(&vlan_id, sta->vlan_desc)))
1326 ap_sta_disconnect(hapd, sta, sta->addr,
1327 WLAN_REASON_UNSPECIFIED);
1328 }
1329}
1330
1331
1332static void hostapd_disassoc_deny_mac(struct hostapd_data *hapd)
1333{
1334 struct sta_info *sta;
1335 struct vlan_description vlan_id;
1336
1337 for (sta = hapd->sta_list; sta; sta = sta->next) {
1338 if (hostapd_maclist_found(hapd->conf->deny_mac,
1339 hapd->conf->num_deny_mac, sta->addr,
1340 &vlan_id) &&
1341 (!vlan_id.notempty ||
1342 !vlan_compare(&vlan_id, sta->vlan_desc)))
1343 ap_sta_disconnect(hapd, sta, sta->addr,
1344 WLAN_REASON_UNSPECIFIED);
1345 }
1346}
1347
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001348
1349static int hostapd_ctrl_iface_set_band(struct hostapd_data *hapd,
1350 const char *band)
1351{
1352 union wpa_event_data event;
1353 enum set_band setband;
1354
1355 if (os_strcmp(band, "AUTO") == 0)
1356 setband = WPA_SETBAND_AUTO;
1357 else if (os_strcmp(band, "5G") == 0)
1358 setband = WPA_SETBAND_5G;
1359 else if (os_strcmp(band, "2G") == 0)
1360 setband = WPA_SETBAND_2G;
1361 else
1362 return -1;
1363
1364 if (hostapd_drv_set_band(hapd, setband) == 0) {
1365 os_memset(&event, 0, sizeof(event));
1366 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
1367 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
1368 wpa_supplicant_event(hapd, EVENT_CHANNEL_LIST_CHANGED, &event);
1369 }
1370
1371 return 0;
1372}
1373
1374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
1376{
1377 char *value;
1378 int ret = 0;
1379
1380 value = os_strchr(cmd, ' ');
1381 if (value == NULL)
1382 return -1;
1383 *value++ = '\0';
1384
1385 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
1386 if (0) {
1387#ifdef CONFIG_WPS_TESTING
1388 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
1389 long int val;
1390 val = strtol(value, NULL, 0);
1391 if (val < 0 || val > 0xff) {
1392 ret = -1;
1393 wpa_printf(MSG_DEBUG, "WPS: Invalid "
1394 "wps_version_number %ld", val);
1395 } else {
1396 wps_version_number = val;
1397 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
1398 "version %u.%u",
1399 (wps_version_number & 0xf0) >> 4,
1400 wps_version_number & 0x0f);
1401 hostapd_wps_update_ie(hapd);
1402 }
1403 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
1404 wps_testing_dummy_cred = atoi(value);
1405 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
1406 wps_testing_dummy_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001407 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
1408 wps_corrupt_pkhash = atoi(value);
1409 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
1410 wps_corrupt_pkhash);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001411#endif /* CONFIG_WPS_TESTING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001412#ifdef CONFIG_TESTING_OPTIONS
1413 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
1414 hapd->ext_mgmt_frame_handling = atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001415 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
1416 hapd->ext_eapol_frame_io = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001417#ifdef CONFIG_DPP
1418 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
1419 os_free(hapd->dpp_config_obj_override);
1420 hapd->dpp_config_obj_override = os_strdup(value);
1421 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
1422 os_free(hapd->dpp_discovery_override);
1423 hapd->dpp_discovery_override = os_strdup(value);
1424 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
1425 os_free(hapd->dpp_groups_override);
1426 hapd->dpp_groups_override = os_strdup(value);
1427 } else if (os_strcasecmp(cmd,
1428 "dpp_ignore_netaccesskey_mismatch") == 0) {
1429 hapd->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001430 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
1431 dpp_test = atoi(value);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001432 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
1433 dpp_version_override = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001434#endif /* CONFIG_DPP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001435#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001436#ifdef CONFIG_MBO
1437 } else if (os_strcasecmp(cmd, "mbo_assoc_disallow") == 0) {
1438 int val;
1439
1440 if (!hapd->conf->mbo_enabled)
1441 return -1;
1442
1443 val = atoi(value);
1444 if (val < 0 || val > 1)
1445 return -1;
1446
1447 hapd->mbo_assoc_disallow = val;
1448 ieee802_11_update_beacons(hapd->iface);
1449
1450 /*
1451 * TODO: Need to configure drivers that do AP MLME offload with
1452 * disallowing station logic.
1453 */
1454#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001455#ifdef CONFIG_DPP
1456 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
1457 os_free(hapd->dpp_configurator_params);
1458 hapd->dpp_configurator_params = os_strdup(value);
1459#endif /* CONFIG_DPP */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001460 } else if (os_strcasecmp(cmd, "setband") == 0) {
1461 ret = hostapd_ctrl_iface_set_band(hapd, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462 } else {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001463 ret = hostapd_set_iface(hapd->iconf, hapd->conf, cmd, value);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001464 if (ret)
1465 return ret;
1466
1467 if (os_strcasecmp(cmd, "deny_mac_file") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001468 hostapd_disassoc_deny_mac(hapd);
1469 } else if (os_strcasecmp(cmd, "accept_mac_file") == 0) {
1470 hostapd_disassoc_accept_mac(hapd);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001471 } else if (os_strncmp(cmd, "wme_ac_", 7) == 0 ||
1472 os_strncmp(cmd, "wmm_ac_", 7) == 0) {
1473 hapd->parameter_set_count++;
1474 if (ieee802_11_update_beacons(hapd->iface))
1475 wpa_printf(MSG_DEBUG,
1476 "Failed to update beacons with WMM parameters");
Hai Shalomc3565922019-10-28 11:58:20 -07001477 } else if (os_strcmp(cmd, "wpa_passphrase") == 0 ||
1478 os_strcmp(cmd, "sae_password") == 0 ||
1479 os_strcmp(cmd, "sae_pwe") == 0) {
1480 if (hapd->started)
1481 hostapd_setup_sae_pt(hapd->conf);
Hai Shalom899fcc72020-10-19 14:38:18 -07001482 } else if (os_strcasecmp(cmd, "transition_disable") == 0) {
1483 wpa_auth_set_transition_disable(hapd->wpa_auth,
1484 hapd->conf->transition_disable);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001485 }
Hai Shalomb755a2a2020-04-23 21:49:02 -07001486
1487#ifdef CONFIG_TESTING_OPTIONS
1488 if (os_strcmp(cmd, "ft_rsnxe_used") == 0)
1489 wpa_auth_set_ft_rsnxe_used(hapd->wpa_auth,
1490 hapd->conf->ft_rsnxe_used);
Hai Shalom899fcc72020-10-19 14:38:18 -07001491 else if (os_strcmp(cmd, "oci_freq_override_eapol_m3") == 0)
1492 wpa_auth_set_ocv_override_freq(
1493 hapd->wpa_auth, WPA_AUTH_OCV_OVERRIDE_EAPOL_M3,
1494 atoi(value));
1495 else if (os_strcmp(cmd, "oci_freq_override_eapol_g1") == 0)
1496 wpa_auth_set_ocv_override_freq(
1497 hapd->wpa_auth, WPA_AUTH_OCV_OVERRIDE_EAPOL_G1,
1498 atoi(value));
1499 else if (os_strcmp(cmd, "oci_freq_override_ft_assoc") == 0)
1500 wpa_auth_set_ocv_override_freq(
1501 hapd->wpa_auth, WPA_AUTH_OCV_OVERRIDE_FT_ASSOC,
1502 atoi(value));
1503 else if (os_strcmp(cmd, "oci_freq_override_fils_assoc") == 0)
1504 wpa_auth_set_ocv_override_freq(
1505 hapd->wpa_auth,
1506 WPA_AUTH_OCV_OVERRIDE_FILS_ASSOC, atoi(value));
Hai Shalomb755a2a2020-04-23 21:49:02 -07001507#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001508 }
1509
1510 return ret;
1511}
1512
1513
1514static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
1515 char *buf, size_t buflen)
1516{
1517 int res;
1518
1519 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
1520
1521 if (os_strcmp(cmd, "version") == 0) {
1522 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001523 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001524 return -1;
1525 return res;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001526 } else if (os_strcmp(cmd, "tls_library") == 0) {
1527 res = tls_get_library_version(buf, buflen);
1528 if (os_snprintf_error(buflen, res))
1529 return -1;
1530 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531 }
1532
1533 return -1;
1534}
1535
1536
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001537static int hostapd_ctrl_iface_enable(struct hostapd_iface *iface)
1538{
1539 if (hostapd_enable_iface(iface) < 0) {
1540 wpa_printf(MSG_ERROR, "Enabling of interface failed");
1541 return -1;
1542 }
1543 return 0;
1544}
1545
1546
1547static int hostapd_ctrl_iface_reload(struct hostapd_iface *iface)
1548{
1549 if (hostapd_reload_iface(iface) < 0) {
1550 wpa_printf(MSG_ERROR, "Reloading of interface failed");
1551 return -1;
1552 }
1553 return 0;
1554}
1555
1556
1557static int hostapd_ctrl_iface_disable(struct hostapd_iface *iface)
1558{
1559 if (hostapd_disable_iface(iface) < 0) {
1560 wpa_printf(MSG_ERROR, "Disabling of interface failed");
1561 return -1;
1562 }
1563 return 0;
1564}
1565
1566
Hai Shalom74f70d42019-02-11 14:42:39 -08001567static int
1568hostapd_ctrl_iface_kick_mismatch_psk_sta_iter(struct hostapd_data *hapd,
1569 struct sta_info *sta, void *ctx)
1570{
1571 struct hostapd_wpa_psk *psk;
1572 const u8 *pmk;
1573 int pmk_len;
1574 int pmk_match;
1575 int sta_match;
1576 int bss_match;
1577 int reason;
1578
1579 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
1580
1581 for (psk = hapd->conf->ssid.wpa_psk; pmk && psk; psk = psk->next) {
1582 pmk_match = PMK_LEN == pmk_len &&
1583 os_memcmp(psk->psk, pmk, pmk_len) == 0;
1584 sta_match = psk->group == 0 &&
1585 os_memcmp(sta->addr, psk->addr, ETH_ALEN) == 0;
1586 bss_match = psk->group == 1;
1587
1588 if (pmk_match && (sta_match || bss_match))
1589 return 0;
1590 }
1591
1592 wpa_printf(MSG_INFO, "STA " MACSTR
1593 " PSK/passphrase no longer valid - disconnect",
1594 MAC2STR(sta->addr));
1595 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
1596 hostapd_drv_sta_deauth(hapd, sta->addr, reason);
1597 ap_sta_deauthenticate(hapd, sta, reason);
1598
1599 return 0;
1600}
1601
1602
1603static int hostapd_ctrl_iface_reload_wpa_psk(struct hostapd_data *hapd)
1604{
1605 struct hostapd_bss_config *conf = hapd->conf;
1606 int err;
1607
1608 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
1609
1610 err = hostapd_setup_wpa_psk(conf);
1611 if (err < 0) {
1612 wpa_printf(MSG_ERROR, "Reloading WPA-PSK passwords failed: %d",
1613 err);
1614 return -1;
1615 }
1616
1617 ap_for_each_sta(hapd, hostapd_ctrl_iface_kick_mismatch_psk_sta_iter,
1618 NULL);
1619
1620 return 0;
1621}
1622
1623
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001624#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001625
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001626static int hostapd_ctrl_iface_radar(struct hostapd_data *hapd, char *cmd)
1627{
1628 union wpa_event_data data;
1629 char *pos, *param;
1630 enum wpa_event_type event;
1631
1632 wpa_printf(MSG_DEBUG, "RADAR TEST: %s", cmd);
1633
1634 os_memset(&data, 0, sizeof(data));
1635
1636 param = os_strchr(cmd, ' ');
1637 if (param == NULL)
1638 return -1;
1639 *param++ = '\0';
1640
1641 if (os_strcmp(cmd, "DETECTED") == 0)
1642 event = EVENT_DFS_RADAR_DETECTED;
1643 else if (os_strcmp(cmd, "CAC-FINISHED") == 0)
1644 event = EVENT_DFS_CAC_FINISHED;
1645 else if (os_strcmp(cmd, "CAC-ABORTED") == 0)
1646 event = EVENT_DFS_CAC_ABORTED;
1647 else if (os_strcmp(cmd, "NOP-FINISHED") == 0)
1648 event = EVENT_DFS_NOP_FINISHED;
1649 else {
1650 wpa_printf(MSG_DEBUG, "Unsupported RADAR test command: %s",
1651 cmd);
1652 return -1;
1653 }
1654
1655 pos = os_strstr(param, "freq=");
1656 if (pos)
1657 data.dfs_event.freq = atoi(pos + 5);
1658
1659 pos = os_strstr(param, "ht_enabled=1");
1660 if (pos)
1661 data.dfs_event.ht_enabled = 1;
1662
1663 pos = os_strstr(param, "chan_offset=");
1664 if (pos)
1665 data.dfs_event.chan_offset = atoi(pos + 12);
1666
1667 pos = os_strstr(param, "chan_width=");
1668 if (pos)
1669 data.dfs_event.chan_width = atoi(pos + 11);
1670
1671 pos = os_strstr(param, "cf1=");
1672 if (pos)
1673 data.dfs_event.cf1 = atoi(pos + 4);
1674
1675 pos = os_strstr(param, "cf2=");
1676 if (pos)
1677 data.dfs_event.cf2 = atoi(pos + 4);
1678
1679 wpa_supplicant_event(hapd, event, &data);
1680
1681 return 0;
1682}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001683
1684
1685static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data *hapd, char *cmd)
1686{
1687 size_t len;
1688 u8 *buf;
1689 int res;
1690
1691 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
1692
1693 len = os_strlen(cmd);
1694 if (len & 1)
1695 return -1;
1696 len /= 2;
1697
1698 buf = os_malloc(len);
1699 if (buf == NULL)
1700 return -1;
1701
1702 if (hexstr2bin(cmd, buf, len) < 0) {
1703 os_free(buf);
1704 return -1;
1705 }
1706
Hai Shalomfdcde762020-04-02 11:19:20 -07001707 res = hostapd_drv_send_mlme(hapd, buf, len, 0, NULL, 0, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001708 os_free(buf);
1709 return res;
1710}
1711
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001712
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001713static int hostapd_ctrl_iface_mgmt_tx_status_process(struct hostapd_data *hapd,
1714 char *cmd)
1715{
1716 char *pos, *param;
1717 size_t len;
1718 u8 *buf;
1719 int stype = 0, ok = 0;
1720 union wpa_event_data event;
1721
1722 if (!hapd->ext_mgmt_frame_handling)
1723 return -1;
1724
1725 /* stype=<val> ok=<0/1> buf=<frame hexdump> */
1726
1727 wpa_printf(MSG_DEBUG, "External MGMT TX status process: %s", cmd);
1728
1729 pos = cmd;
1730 param = os_strstr(pos, "stype=");
1731 if (param) {
1732 param += 6;
1733 stype = atoi(param);
1734 }
1735
1736 param = os_strstr(pos, " ok=");
1737 if (param) {
1738 param += 4;
1739 ok = atoi(param);
1740 }
1741
1742 param = os_strstr(pos, " buf=");
1743 if (!param)
1744 return -1;
1745 param += 5;
1746
1747 len = os_strlen(param);
1748 if (len & 1)
1749 return -1;
1750 len /= 2;
1751
1752 buf = os_malloc(len);
1753 if (!buf || hexstr2bin(param, buf, len) < 0) {
1754 os_free(buf);
1755 return -1;
1756 }
1757
1758 os_memset(&event, 0, sizeof(event));
1759 event.tx_status.type = WLAN_FC_TYPE_MGMT;
1760 event.tx_status.data = buf;
1761 event.tx_status.data_len = len;
1762 event.tx_status.stype = stype;
1763 event.tx_status.ack = ok;
1764 hapd->ext_mgmt_frame_handling = 0;
1765 wpa_supplicant_event(hapd, EVENT_TX_STATUS, &event);
1766 hapd->ext_mgmt_frame_handling = 1;
1767
1768 os_free(buf);
1769
1770 return 0;
1771}
1772
1773
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001774static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data *hapd,
1775 char *cmd)
1776{
1777 char *pos, *param;
1778 size_t len;
1779 u8 *buf;
1780 int freq = 0, datarate = 0, ssi_signal = 0;
1781 union wpa_event_data event;
1782
1783 if (!hapd->ext_mgmt_frame_handling)
1784 return -1;
1785
1786 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
1787
1788 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
1789
1790 pos = cmd;
1791 param = os_strstr(pos, "freq=");
1792 if (param) {
1793 param += 5;
1794 freq = atoi(param);
1795 }
1796
1797 param = os_strstr(pos, " datarate=");
1798 if (param) {
1799 param += 10;
1800 datarate = atoi(param);
1801 }
1802
1803 param = os_strstr(pos, " ssi_signal=");
1804 if (param) {
1805 param += 12;
1806 ssi_signal = atoi(param);
1807 }
1808
1809 param = os_strstr(pos, " frame=");
1810 if (param == NULL)
1811 return -1;
1812 param += 7;
1813
1814 len = os_strlen(param);
1815 if (len & 1)
1816 return -1;
1817 len /= 2;
1818
1819 buf = os_malloc(len);
1820 if (buf == NULL)
1821 return -1;
1822
1823 if (hexstr2bin(param, buf, len) < 0) {
1824 os_free(buf);
1825 return -1;
1826 }
1827
1828 os_memset(&event, 0, sizeof(event));
1829 event.rx_mgmt.freq = freq;
1830 event.rx_mgmt.frame = buf;
1831 event.rx_mgmt.frame_len = len;
1832 event.rx_mgmt.ssi_signal = ssi_signal;
1833 event.rx_mgmt.datarate = datarate;
1834 hapd->ext_mgmt_frame_handling = 0;
1835 wpa_supplicant_event(hapd, EVENT_RX_MGMT, &event);
1836 hapd->ext_mgmt_frame_handling = 1;
1837
1838 os_free(buf);
1839
1840 return 0;
1841}
1842
1843
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001844static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data *hapd, char *cmd)
1845{
1846 char *pos;
1847 u8 src[ETH_ALEN], *buf;
1848 int used;
1849 size_t len;
1850
1851 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
1852
1853 pos = cmd;
1854 used = hwaddr_aton2(pos, src);
1855 if (used < 0)
1856 return -1;
1857 pos += used;
1858 while (*pos == ' ')
1859 pos++;
1860
1861 len = os_strlen(pos);
1862 if (len & 1)
1863 return -1;
1864 len /= 2;
1865
1866 buf = os_malloc(len);
1867 if (buf == NULL)
1868 return -1;
1869
1870 if (hexstr2bin(pos, buf, len) < 0) {
1871 os_free(buf);
1872 return -1;
1873 }
1874
1875 ieee802_1x_receive(hapd, src, buf, len);
1876 os_free(buf);
1877
1878 return 0;
1879}
1880
1881
1882static u16 ipv4_hdr_checksum(const void *buf, size_t len)
1883{
1884 size_t i;
1885 u32 sum = 0;
1886 const u16 *pos = buf;
1887
1888 for (i = 0; i < len / 2; i++)
1889 sum += *pos++;
1890
1891 while (sum >> 16)
1892 sum = (sum & 0xffff) + (sum >> 16);
1893
1894 return sum ^ 0xffff;
1895}
1896
1897
1898#define HWSIM_PACKETLEN 1500
1899#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1900
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07001901static void hostapd_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
1902 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001903{
1904 struct hostapd_data *hapd = ctx;
1905 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07001906 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001907 const u8 *pos;
1908 unsigned int i;
Hai Shalom81f62d82019-07-22 12:10:00 -07001909 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001910
Hai Shalom81f62d82019-07-22 12:10:00 -07001911 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
1912 wpa_printf(MSG_DEBUG,
1913 "test data: RX - ignore unexpected length %d",
1914 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001915 return;
Hai Shalom81f62d82019-07-22 12:10:00 -07001916 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001917
1918 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001919 os_memcpy(&ip, eth + 1, sizeof(ip));
1920 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001921
Hai Shalomfdcde762020-04-02 11:19:20 -07001922 if (ip.ip_hl != 5 || ip.ip_v != 4 ||
1923 ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001924 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07001925 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001926 return;
Hai Shalom81f62d82019-07-22 12:10:00 -07001927 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001928
Hai Shalomfdcde762020-04-02 11:19:20 -07001929 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001930 if (*pos != (u8) i) {
1931 wpa_printf(MSG_DEBUG,
1932 "test data: RX - ignore mismatching payload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001933 return;
Hai Shalom81f62d82019-07-22 12:10:00 -07001934 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001935 pos++;
1936 }
1937
Hai Shalom81f62d82019-07-22 12:10:00 -07001938 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07001939 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
1940 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom81f62d82019-07-22 12:10:00 -07001941 wpa_msg(hapd->msg_ctx, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
1942 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001943}
1944
1945
1946static int hostapd_ctrl_iface_data_test_config(struct hostapd_data *hapd,
1947 char *cmd)
1948{
1949 int enabled = atoi(cmd);
1950 char *pos;
1951 const char *ifname;
1952
1953 if (!enabled) {
1954 if (hapd->l2_test) {
1955 l2_packet_deinit(hapd->l2_test);
1956 hapd->l2_test = NULL;
1957 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1958 "test data: Disabled");
1959 }
1960 return 0;
1961 }
1962
1963 if (hapd->l2_test)
1964 return 0;
1965
1966 pos = os_strstr(cmd, " ifname=");
1967 if (pos)
1968 ifname = pos + 8;
1969 else
1970 ifname = hapd->conf->iface;
1971
1972 hapd->l2_test = l2_packet_init(ifname, hapd->own_addr,
1973 ETHERTYPE_IP, hostapd_data_test_rx,
1974 hapd, 1);
1975 if (hapd->l2_test == NULL)
1976 return -1;
1977
1978 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: Enabled");
1979
1980 return 0;
1981}
1982
1983
1984static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data *hapd, char *cmd)
1985{
1986 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom81f62d82019-07-22 12:10:00 -07001987 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001988 int used;
1989 long int val;
1990 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001991 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001992 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07001993 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001994 u8 *dpos;
1995 unsigned int i;
Hai Shalom81f62d82019-07-22 12:10:00 -07001996 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001997
1998 if (hapd->l2_test == NULL)
1999 return -1;
2000
Hai Shalom81f62d82019-07-22 12:10:00 -07002001 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002002
2003 pos = cmd;
2004 used = hwaddr_aton2(pos, dst);
2005 if (used < 0)
2006 return -1;
2007 pos += used;
2008 while (*pos == ' ')
2009 pos++;
2010 used = hwaddr_aton2(pos, src);
2011 if (used < 0)
2012 return -1;
2013 pos += used;
2014
Hai Shalom81f62d82019-07-22 12:10:00 -07002015 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002016 if (val < 0 || val > 0xff)
2017 return -1;
2018 tos = val;
2019
Hai Shalom81f62d82019-07-22 12:10:00 -07002020 pos = os_strstr(pos2, " len=");
2021 if (pos) {
2022 i = atoi(pos + 5);
2023 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
2024 return -1;
2025 send_len = i;
2026 }
2027
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002028 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002029 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
2030 os_memcpy(eth->ether_shost, src, ETH_ALEN);
2031 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -07002032 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002033 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -07002034 ip->ip_hl = 5;
2035 ip->ip_v = 4;
2036 ip->ip_ttl = 64;
2037 ip->ip_tos = tos;
2038 ip->ip_len = htons(send_len);
2039 ip->ip_p = 1;
2040 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
2041 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
2042 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002043 dpos = (u8 *) (ip + 1);
Hai Shalom81f62d82019-07-22 12:10:00 -07002044 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002045 *dpos++ = i;
2046
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002047 if (l2_packet_send(hapd->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom81f62d82019-07-22 12:10:00 -07002048 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002049 return -1;
2050
2051 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: TX dst=" MACSTR
2052 " src=" MACSTR " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
2053
2054 return 0;
2055}
2056
2057
2058static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data *hapd,
2059 char *cmd)
2060{
2061 u8 *buf;
2062 struct ether_header *eth;
2063 struct l2_packet_data *l2 = NULL;
2064 size_t len;
2065 u16 ethertype;
2066 int res = -1;
2067 const char *ifname = hapd->conf->iface;
2068
2069 if (os_strncmp(cmd, "ifname=", 7) == 0) {
2070 cmd += 7;
2071 ifname = cmd;
2072 cmd = os_strchr(cmd, ' ');
2073 if (cmd == NULL)
2074 return -1;
2075 *cmd++ = '\0';
2076 }
2077
2078 len = os_strlen(cmd);
2079 if (len & 1 || len < ETH_HLEN * 2)
2080 return -1;
2081 len /= 2;
2082
2083 buf = os_malloc(len);
2084 if (buf == NULL)
2085 return -1;
2086
2087 if (hexstr2bin(cmd, buf, len) < 0)
2088 goto done;
2089
2090 eth = (struct ether_header *) buf;
2091 ethertype = ntohs(eth->ether_type);
2092
2093 l2 = l2_packet_init(ifname, hapd->own_addr, ethertype,
2094 hostapd_data_test_rx, hapd, 1);
2095 if (l2 == NULL)
2096 goto done;
2097
2098 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
2099 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: TX frame res=%d", res);
2100done:
2101 if (l2)
2102 l2_packet_deinit(l2);
2103 os_free(buf);
2104
2105 return res < 0 ? -1 : 0;
2106}
2107
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002108
2109static int hostapd_ctrl_test_alloc_fail(struct hostapd_data *hapd, char *cmd)
2110{
2111#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002112 char *pos;
2113
2114 wpa_trace_fail_after = atoi(cmd);
2115 pos = os_strchr(cmd, ':');
2116 if (pos) {
2117 pos++;
2118 os_strlcpy(wpa_trace_fail_func, pos,
2119 sizeof(wpa_trace_fail_func));
2120 } else {
2121 wpa_trace_fail_after = 0;
2122 }
2123
2124 return 0;
2125#else /* WPA_TRACE_BFD */
2126 return -1;
2127#endif /* WPA_TRACE_BFD */
2128}
2129
2130
2131static int hostapd_ctrl_get_alloc_fail(struct hostapd_data *hapd,
2132 char *buf, size_t buflen)
2133{
2134#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002135 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
2136 wpa_trace_fail_func);
2137#else /* WPA_TRACE_BFD */
2138 return -1;
2139#endif /* WPA_TRACE_BFD */
2140}
2141
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002142
2143static int hostapd_ctrl_test_fail(struct hostapd_data *hapd, char *cmd)
2144{
2145#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002146 char *pos;
2147
2148 wpa_trace_test_fail_after = atoi(cmd);
2149 pos = os_strchr(cmd, ':');
2150 if (pos) {
2151 pos++;
2152 os_strlcpy(wpa_trace_test_fail_func, pos,
2153 sizeof(wpa_trace_test_fail_func));
2154 } else {
2155 wpa_trace_test_fail_after = 0;
2156 }
2157
2158 return 0;
2159#else /* WPA_TRACE_BFD */
2160 return -1;
2161#endif /* WPA_TRACE_BFD */
2162}
2163
2164
2165static int hostapd_ctrl_get_fail(struct hostapd_data *hapd,
2166 char *buf, size_t buflen)
2167{
2168#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002169 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
2170 wpa_trace_test_fail_func);
2171#else /* WPA_TRACE_BFD */
2172 return -1;
2173#endif /* WPA_TRACE_BFD */
2174}
2175
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002176
2177static int hostapd_ctrl_reset_pn(struct hostapd_data *hapd, const char *cmd)
2178{
2179 struct sta_info *sta;
2180 u8 addr[ETH_ALEN];
2181 u8 zero[WPA_TK_MAX_LEN];
2182
2183 os_memset(zero, 0, sizeof(zero));
2184
2185 if (hwaddr_aton(cmd, addr))
2186 return -1;
2187
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002188 if (is_broadcast_ether_addr(addr) && os_strstr(cmd, " BIGTK")) {
2189 if (hapd->last_bigtk_alg == WPA_ALG_NONE)
2190 return -1;
2191
2192 wpa_printf(MSG_INFO, "TESTING: Reset BIPN for BIGTK");
2193
2194 /* First, use a zero key to avoid any possible duplicate key
2195 * avoidance in the driver. */
2196 if (hostapd_drv_set_key(hapd->conf->iface, hapd,
2197 hapd->last_bigtk_alg,
2198 broadcast_ether_addr,
2199 hapd->last_bigtk_key_idx, 0, 1, NULL, 0,
2200 zero, hapd->last_bigtk_len,
2201 KEY_FLAG_GROUP_TX_DEFAULT) < 0)
2202 return -1;
2203
2204 /* Set the previously configured key to reset its TSC */
2205 return hostapd_drv_set_key(hapd->conf->iface, hapd,
2206 hapd->last_bigtk_alg,
2207 broadcast_ether_addr,
2208 hapd->last_bigtk_key_idx, 0, 1, NULL,
2209 0, hapd->last_bigtk,
2210 hapd->last_bigtk_len,
2211 KEY_FLAG_GROUP_TX_DEFAULT);
2212 }
2213
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002214 if (is_broadcast_ether_addr(addr) && os_strstr(cmd, "IGTK")) {
2215 if (hapd->last_igtk_alg == WPA_ALG_NONE)
2216 return -1;
2217
2218 wpa_printf(MSG_INFO, "TESTING: Reset IPN for IGTK");
2219
2220 /* First, use a zero key to avoid any possible duplicate key
2221 * avoidance in the driver. */
2222 if (hostapd_drv_set_key(hapd->conf->iface, hapd,
2223 hapd->last_igtk_alg,
2224 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002225 hapd->last_igtk_key_idx, 0, 1, NULL, 0,
2226 zero, hapd->last_igtk_len,
2227 KEY_FLAG_GROUP_TX_DEFAULT) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002228 return -1;
2229
2230 /* Set the previously configured key to reset its TSC */
2231 return hostapd_drv_set_key(hapd->conf->iface, hapd,
2232 hapd->last_igtk_alg,
2233 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002234 hapd->last_igtk_key_idx, 0, 1, NULL,
2235 0, hapd->last_igtk,
2236 hapd->last_igtk_len,
2237 KEY_FLAG_GROUP_TX_DEFAULT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002238 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002239
2240 if (is_broadcast_ether_addr(addr)) {
2241 if (hapd->last_gtk_alg == WPA_ALG_NONE)
2242 return -1;
2243
2244 wpa_printf(MSG_INFO, "TESTING: Reset PN for GTK");
2245
2246 /* First, use a zero key to avoid any possible duplicate key
2247 * avoidance in the driver. */
2248 if (hostapd_drv_set_key(hapd->conf->iface, hapd,
2249 hapd->last_gtk_alg,
2250 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002251 hapd->last_gtk_key_idx, 0, 1, NULL, 0,
2252 zero, hapd->last_gtk_len,
2253 KEY_FLAG_GROUP_TX_DEFAULT) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002254 return -1;
2255
2256 /* Set the previously configured key to reset its TSC */
2257 return hostapd_drv_set_key(hapd->conf->iface, hapd,
2258 hapd->last_gtk_alg,
2259 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002260 hapd->last_gtk_key_idx, 0, 1, NULL,
2261 0, hapd->last_gtk,
2262 hapd->last_gtk_len,
2263 KEY_FLAG_GROUP_TX_DEFAULT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002264 }
2265
2266 sta = ap_get_sta(hapd, addr);
2267 if (!sta)
2268 return -1;
2269
2270 if (sta->last_tk_alg == WPA_ALG_NONE)
2271 return -1;
2272
2273 wpa_printf(MSG_INFO, "TESTING: Reset PN for " MACSTR,
2274 MAC2STR(sta->addr));
2275
2276 /* First, use a zero key to avoid any possible duplicate key avoidance
2277 * in the driver. */
2278 if (hostapd_drv_set_key(hapd->conf->iface, hapd, sta->last_tk_alg,
Hai Shalomfdcde762020-04-02 11:19:20 -07002279 sta->addr, sta->last_tk_key_idx, 0, 1, NULL, 0,
2280 zero, sta->last_tk_len,
2281 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002282 return -1;
2283
2284 /* Set the previously configured key to reset its TSC/RSC */
2285 return hostapd_drv_set_key(hapd->conf->iface, hapd, sta->last_tk_alg,
Hai Shalomfdcde762020-04-02 11:19:20 -07002286 sta->addr, sta->last_tk_key_idx, 0, 1, NULL,
2287 0, sta->last_tk, sta->last_tk_len,
2288 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002289}
2290
2291
2292static int hostapd_ctrl_set_key(struct hostapd_data *hapd, const char *cmd)
2293{
2294 u8 addr[ETH_ALEN];
2295 const char *pos = cmd;
2296 enum wpa_alg alg;
Hai Shalomfdcde762020-04-02 11:19:20 -07002297 enum key_flag key_flag;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002298 int idx, set_tx;
2299 u8 seq[6], key[WPA_TK_MAX_LEN];
2300 size_t key_len;
2301
Hai Shalomfdcde762020-04-02 11:19:20 -07002302 /* parameters: alg addr idx set_tx seq key key_flag */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002303
2304 alg = atoi(pos);
2305 pos = os_strchr(pos, ' ');
2306 if (!pos)
2307 return -1;
2308 pos++;
2309 if (hwaddr_aton(pos, addr))
2310 return -1;
2311 pos += 17;
2312 if (*pos != ' ')
2313 return -1;
2314 pos++;
2315 idx = atoi(pos);
2316 pos = os_strchr(pos, ' ');
2317 if (!pos)
2318 return -1;
2319 pos++;
2320 set_tx = atoi(pos);
2321 pos = os_strchr(pos, ' ');
2322 if (!pos)
2323 return -1;
2324 pos++;
Hai Shalom74f70d42019-02-11 14:42:39 -08002325 if (hexstr2bin(pos, seq, sizeof(seq)) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002326 return -1;
2327 pos += 2 * 6;
2328 if (*pos != ' ')
2329 return -1;
2330 pos++;
Hai Shalomfdcde762020-04-02 11:19:20 -07002331 if (!os_strchr(pos, ' '))
2332 return -1;
2333 key_len = (os_strchr(pos, ' ') - pos) / 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002334 if (hexstr2bin(pos, key, key_len) < 0)
2335 return -1;
Hai Shalomfdcde762020-04-02 11:19:20 -07002336 pos += 2 * key_len;
2337 if (*pos != ' ')
2338 return -1;
2339
2340 pos++;
2341 key_flag = atoi(pos);
2342 pos = os_strchr(pos, ' ');
2343 if (pos)
2344 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002345
2346 wpa_printf(MSG_INFO, "TESTING: Set key");
Hai Shalomfdcde762020-04-02 11:19:20 -07002347 return hostapd_drv_set_key(hapd->conf->iface, hapd, alg, addr, idx, 0,
2348 set_tx, seq, 6, key, key_len, key_flag);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002349}
2350
2351
2352static void restore_tk(void *ctx1, void *ctx2)
2353{
2354 struct hostapd_data *hapd = ctx1;
2355 struct sta_info *sta = ctx2;
2356
2357 wpa_printf(MSG_INFO, "TESTING: Restore TK for " MACSTR,
2358 MAC2STR(sta->addr));
2359 /* This does not really restore the TSC properly, so this will result
2360 * in replay protection issues for now since there is no clean way of
2361 * preventing encryption of a single EAPOL frame. */
2362 hostapd_drv_set_key(hapd->conf->iface, hapd, sta->last_tk_alg,
Hai Shalomfdcde762020-04-02 11:19:20 -07002363 sta->addr, sta->last_tk_key_idx, 0, 1, NULL, 0,
2364 sta->last_tk, sta->last_tk_len,
2365 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002366}
2367
2368
2369static int hostapd_ctrl_resend_m1(struct hostapd_data *hapd, const char *cmd)
2370{
2371 struct sta_info *sta;
2372 u8 addr[ETH_ALEN];
2373 int plain = os_strstr(cmd, "plaintext") != NULL;
2374
2375 if (hwaddr_aton(cmd, addr))
2376 return -1;
2377
2378 sta = ap_get_sta(hapd, addr);
2379 if (!sta || !sta->wpa_sm)
2380 return -1;
2381
2382 if (plain && sta->last_tk_alg == WPA_ALG_NONE)
2383 plain = 0; /* no need for special processing */
2384 if (plain) {
2385 wpa_printf(MSG_INFO, "TESTING: Clear TK for " MACSTR,
2386 MAC2STR(sta->addr));
2387 hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
Hai Shalomfdcde762020-04-02 11:19:20 -07002388 sta->addr, sta->last_tk_key_idx, 0, 0, NULL,
2389 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002390 }
2391
2392 wpa_printf(MSG_INFO, "TESTING: Send M1 to " MACSTR, MAC2STR(sta->addr));
2393 return wpa_auth_resend_m1(sta->wpa_sm,
2394 os_strstr(cmd, "change-anonce") != NULL,
2395 plain ? restore_tk : NULL, hapd, sta);
2396}
2397
2398
2399static int hostapd_ctrl_resend_m3(struct hostapd_data *hapd, const char *cmd)
2400{
2401 struct sta_info *sta;
2402 u8 addr[ETH_ALEN];
2403 int plain = os_strstr(cmd, "plaintext") != NULL;
2404
2405 if (hwaddr_aton(cmd, addr))
2406 return -1;
2407
2408 sta = ap_get_sta(hapd, addr);
2409 if (!sta || !sta->wpa_sm)
2410 return -1;
2411
2412 if (plain && sta->last_tk_alg == WPA_ALG_NONE)
2413 plain = 0; /* no need for special processing */
2414 if (plain) {
2415 wpa_printf(MSG_INFO, "TESTING: Clear TK for " MACSTR,
2416 MAC2STR(sta->addr));
2417 hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
Hai Shalomfdcde762020-04-02 11:19:20 -07002418 sta->addr, sta->last_tk_key_idx, 0, 0, NULL,
2419 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002420 }
2421
2422 wpa_printf(MSG_INFO, "TESTING: Send M3 to " MACSTR, MAC2STR(sta->addr));
2423 return wpa_auth_resend_m3(sta->wpa_sm,
2424 plain ? restore_tk : NULL, hapd, sta);
2425}
2426
2427
2428static int hostapd_ctrl_resend_group_m1(struct hostapd_data *hapd,
2429 const char *cmd)
2430{
2431 struct sta_info *sta;
2432 u8 addr[ETH_ALEN];
2433 int plain = os_strstr(cmd, "plaintext") != NULL;
2434
2435 if (hwaddr_aton(cmd, addr))
2436 return -1;
2437
2438 sta = ap_get_sta(hapd, addr);
2439 if (!sta || !sta->wpa_sm)
2440 return -1;
2441
2442 if (plain && sta->last_tk_alg == WPA_ALG_NONE)
2443 plain = 0; /* no need for special processing */
2444 if (plain) {
2445 wpa_printf(MSG_INFO, "TESTING: Clear TK for " MACSTR,
2446 MAC2STR(sta->addr));
2447 hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
Hai Shalomfdcde762020-04-02 11:19:20 -07002448 sta->addr, sta->last_tk_key_idx, 0, 0, NULL,
2449 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002450 }
2451
2452 wpa_printf(MSG_INFO,
2453 "TESTING: Send group M1 for the same GTK and zero RSC to "
2454 MACSTR, MAC2STR(sta->addr));
2455 return wpa_auth_resend_group_m1(sta->wpa_sm,
2456 plain ? restore_tk : NULL, hapd, sta);
2457}
2458
Hai Shalomfdcde762020-04-02 11:19:20 -07002459
Hai Shalom899fcc72020-10-19 14:38:18 -07002460static int hostapd_ctrl_get_pmksa_pmk(struct hostapd_data *hapd, const u8 *addr,
2461 char *buf, size_t buflen)
2462{
2463 struct rsn_pmksa_cache_entry *pmksa;
2464
2465 pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, addr, NULL);
2466 if (!pmksa)
2467 return -1;
2468
2469 return wpa_snprintf_hex(buf, buflen, pmksa->pmk, pmksa->pmk_len);
2470}
2471
2472
Hai Shalomfdcde762020-04-02 11:19:20 -07002473static int hostapd_ctrl_get_pmk(struct hostapd_data *hapd, const char *cmd,
2474 char *buf, size_t buflen)
2475{
2476 struct sta_info *sta;
2477 u8 addr[ETH_ALEN];
2478 const u8 *pmk;
2479 int pmk_len;
2480
2481 if (hwaddr_aton(cmd, addr))
2482 return -1;
2483
2484 sta = ap_get_sta(hapd, addr);
2485 if (!sta || !sta->wpa_sm) {
2486 wpa_printf(MSG_DEBUG, "No STA WPA state machine for " MACSTR,
2487 MAC2STR(addr));
Hai Shalom899fcc72020-10-19 14:38:18 -07002488 return hostapd_ctrl_get_pmksa_pmk(hapd, addr, buf, buflen);
Hai Shalomfdcde762020-04-02 11:19:20 -07002489 }
2490 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
Hai Shalom899fcc72020-10-19 14:38:18 -07002491 if (!pmk || !pmk_len) {
Hai Shalomfdcde762020-04-02 11:19:20 -07002492 wpa_printf(MSG_DEBUG, "No PMK stored for " MACSTR,
2493 MAC2STR(addr));
Hai Shalom899fcc72020-10-19 14:38:18 -07002494 return hostapd_ctrl_get_pmksa_pmk(hapd, addr, buf, buflen);
Hai Shalomfdcde762020-04-02 11:19:20 -07002495 }
2496
2497 return wpa_snprintf_hex(buf, buflen, pmk, pmk_len);
2498}
2499
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002500#endif /* CONFIG_TESTING_OPTIONS */
2501
2502
Hai Shalomb755a2a2020-04-23 21:49:02 -07002503#ifdef NEED_AP_MLME
Hai Shalomfdcde762020-04-02 11:19:20 -07002504static int hostapd_ctrl_check_freq_params(struct hostapd_freq_params *params)
2505{
2506 switch (params->bandwidth) {
2507 case 0:
2508 /* bandwidth not specified: use 20 MHz by default */
2509 /* fall-through */
2510 case 20:
2511 if (params->center_freq1 &&
2512 params->center_freq1 != params->freq)
2513 return -1;
2514
2515 if (params->center_freq2 || params->sec_channel_offset)
2516 return -1;
2517 break;
2518 case 40:
2519 if (params->center_freq2 || !params->sec_channel_offset)
2520 return -1;
2521
2522 if (!params->center_freq1)
2523 break;
2524 switch (params->sec_channel_offset) {
2525 case 1:
2526 if (params->freq + 10 != params->center_freq1)
2527 return -1;
2528 break;
2529 case -1:
2530 if (params->freq - 10 != params->center_freq1)
2531 return -1;
2532 break;
2533 default:
2534 return -1;
2535 }
2536 break;
2537 case 80:
2538 if (!params->center_freq1 || !params->sec_channel_offset)
2539 return 1;
2540
2541 switch (params->sec_channel_offset) {
2542 case 1:
2543 if (params->freq - 10 != params->center_freq1 &&
2544 params->freq + 30 != params->center_freq1)
2545 return 1;
2546 break;
2547 case -1:
2548 if (params->freq + 10 != params->center_freq1 &&
2549 params->freq - 30 != params->center_freq1)
2550 return -1;
2551 break;
2552 default:
2553 return -1;
2554 }
2555
2556 /* Adjacent and overlapped are not allowed for 80+80 */
2557 if (params->center_freq2 &&
2558 params->center_freq1 - params->center_freq2 <= 80 &&
2559 params->center_freq2 - params->center_freq1 <= 80)
2560 return 1;
2561 break;
2562 case 160:
2563 if (!params->center_freq1 || params->center_freq2 ||
2564 !params->sec_channel_offset)
2565 return -1;
2566
2567 switch (params->sec_channel_offset) {
2568 case 1:
2569 if (params->freq + 70 != params->center_freq1 &&
2570 params->freq + 30 != params->center_freq1 &&
2571 params->freq - 10 != params->center_freq1 &&
2572 params->freq - 50 != params->center_freq1)
2573 return -1;
2574 break;
2575 case -1:
2576 if (params->freq + 50 != params->center_freq1 &&
2577 params->freq + 10 != params->center_freq1 &&
2578 params->freq - 30 != params->center_freq1 &&
2579 params->freq - 70 != params->center_freq1)
2580 return -1;
2581 break;
2582 default:
2583 return -1;
2584 }
2585 break;
2586 default:
2587 return -1;
2588 }
2589
2590 return 0;
2591}
Hai Shalomb755a2a2020-04-23 21:49:02 -07002592#endif /* NEED_AP_MLME */
Hai Shalomfdcde762020-04-02 11:19:20 -07002593
2594
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002595static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface *iface,
2596 char *pos)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002597{
2598#ifdef NEED_AP_MLME
2599 struct csa_settings settings;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002600 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -07002601 int dfs_range = 0;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002602 unsigned int i;
Hai Shalomfdcde762020-04-02 11:19:20 -07002603 int bandwidth;
2604 u8 chan;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002605
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002606 ret = hostapd_parse_csa_settings(pos, &settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002607 if (ret)
2608 return ret;
2609
Hai Shalomfdcde762020-04-02 11:19:20 -07002610 ret = hostapd_ctrl_check_freq_params(&settings.freq_params);
2611 if (ret) {
2612 wpa_printf(MSG_INFO,
2613 "chanswitch: invalid frequency settings provided");
2614 return ret;
2615 }
2616
2617 switch (settings.freq_params.bandwidth) {
2618 case 40:
2619 bandwidth = CHAN_WIDTH_40;
2620 break;
2621 case 80:
2622 if (settings.freq_params.center_freq2)
2623 bandwidth = CHAN_WIDTH_80P80;
2624 else
2625 bandwidth = CHAN_WIDTH_80;
2626 break;
2627 case 160:
2628 bandwidth = CHAN_WIDTH_160;
2629 break;
2630 default:
2631 bandwidth = CHAN_WIDTH_20;
2632 break;
2633 }
2634
2635 if (settings.freq_params.center_freq1)
2636 dfs_range += hostapd_is_dfs_overlap(
2637 iface, bandwidth, settings.freq_params.center_freq1);
2638 else
2639 dfs_range += hostapd_is_dfs_overlap(
2640 iface, bandwidth, settings.freq_params.freq);
2641
2642 if (settings.freq_params.center_freq2)
2643 dfs_range += hostapd_is_dfs_overlap(
2644 iface, bandwidth, settings.freq_params.center_freq2);
2645
2646 if (dfs_range) {
2647 ret = ieee80211_freq_to_chan(settings.freq_params.freq, &chan);
2648 if (ret == NUM_HOSTAPD_MODES) {
2649 wpa_printf(MSG_ERROR,
2650 "Failed to get channel for (freq=%d, sec_channel_offset=%d, bw=%d)",
2651 settings.freq_params.freq,
2652 settings.freq_params.sec_channel_offset,
2653 settings.freq_params.bandwidth);
2654 return -1;
2655 }
2656
2657 settings.freq_params.channel = chan;
2658
2659 wpa_printf(MSG_DEBUG,
2660 "DFS/CAC to (channel=%u, freq=%d, sec_channel_offset=%d, bw=%d, center_freq1=%d)",
2661 settings.freq_params.channel,
2662 settings.freq_params.freq,
2663 settings.freq_params.sec_channel_offset,
2664 settings.freq_params.bandwidth,
2665 settings.freq_params.center_freq1);
2666
2667 /* Perform CAC and switch channel */
2668 hostapd_switch_channel_fallback(iface, &settings.freq_params);
2669 return 0;
2670 }
2671
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002672 for (i = 0; i < iface->num_bss; i++) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002673
2674 /* Save CHAN_SWITCH VHT config */
2675 hostapd_chan_switch_vht_config(
2676 iface->bss[i], settings.freq_params.vht_enabled);
2677
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002678 ret = hostapd_switch_channel(iface->bss[i], &settings);
2679 if (ret) {
2680 /* FIX: What do we do if CSA fails in the middle of
2681 * submitting multi-BSS CSA requests? */
2682 return ret;
2683 }
2684 }
2685
2686 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002687#else /* NEED_AP_MLME */
2688 return -1;
2689#endif /* NEED_AP_MLME */
2690}
2691
2692
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002693static int hostapd_ctrl_iface_mib(struct hostapd_data *hapd, char *reply,
2694 int reply_size, const char *param)
2695{
2696#ifdef RADIUS_SERVER
2697 if (os_strcmp(param, "radius_server") == 0) {
2698 return radius_server_get_mib(hapd->radius_srv, reply,
2699 reply_size);
2700 }
2701#endif /* RADIUS_SERVER */
2702 return -1;
2703}
2704
2705
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002706static int hostapd_ctrl_iface_vendor(struct hostapd_data *hapd, char *cmd,
2707 char *buf, size_t buflen)
2708{
2709 int ret;
2710 char *pos;
2711 u8 *data = NULL;
2712 unsigned int vendor_id, subcmd;
2713 struct wpabuf *reply;
2714 size_t data_len = 0;
2715
2716 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
2717 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002718 if (!isblank((unsigned char) *pos))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002719 return -EINVAL;
2720
2721 subcmd = strtoul(pos, &pos, 10);
2722
2723 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002724 if (!isblank((unsigned char) *pos++))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002725 return -EINVAL;
2726 data_len = os_strlen(pos);
2727 }
2728
2729 if (data_len) {
2730 data_len /= 2;
2731 data = os_malloc(data_len);
2732 if (!data)
2733 return -ENOBUFS;
2734
2735 if (hexstr2bin(pos, data, data_len)) {
2736 wpa_printf(MSG_DEBUG,
2737 "Vendor command: wrong parameter format");
2738 os_free(data);
2739 return -EINVAL;
2740 }
2741 }
2742
2743 reply = wpabuf_alloc((buflen - 1) / 2);
2744 if (!reply) {
2745 os_free(data);
2746 return -ENOBUFS;
2747 }
2748
2749 ret = hostapd_drv_vendor_cmd(hapd, vendor_id, subcmd, data, data_len,
2750 reply);
2751
2752 if (ret == 0)
2753 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
2754 wpabuf_len(reply));
2755
2756 wpabuf_free(reply);
2757 os_free(data);
2758
2759 return ret;
2760}
2761
2762
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002763static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data *hapd,
2764 const char *cmd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002765{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002766 u8 addr[ETH_ALEN];
2767 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002768
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002769 if (hwaddr_aton(cmd, addr))
2770 return -1;
2771
2772 sta = ap_get_sta(hapd, addr);
2773 if (!sta || !sta->eapol_sm)
2774 return -1;
2775
2776 eapol_auth_reauthenticate(sta->eapol_sm);
2777 return 0;
2778}
2779
2780
2781static int hostapd_ctrl_iface_eapol_set(struct hostapd_data *hapd, char *cmd)
2782{
2783 u8 addr[ETH_ALEN];
2784 struct sta_info *sta;
2785 char *pos = cmd, *param;
2786
2787 if (hwaddr_aton(pos, addr) || pos[17] != ' ')
2788 return -1;
2789 pos += 18;
2790 param = pos;
2791 pos = os_strchr(pos, ' ');
2792 if (!pos)
2793 return -1;
2794 *pos++ = '\0';
2795
2796 sta = ap_get_sta(hapd, addr);
2797 if (!sta || !sta->eapol_sm)
2798 return -1;
2799
2800 return eapol_auth_set_conf(sta->eapol_sm, param, pos);
2801}
2802
2803
2804static int hostapd_ctrl_iface_log_level(struct hostapd_data *hapd, char *cmd,
2805 char *buf, size_t buflen)
2806{
2807 char *pos, *end, *stamp;
2808 int ret;
2809
2810 /* cmd: "LOG_LEVEL [<level>]" */
2811 if (*cmd == '\0') {
2812 pos = buf;
2813 end = buf + buflen;
2814 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2815 "Timestamp: %d\n",
2816 debug_level_str(wpa_debug_level),
2817 wpa_debug_timestamp);
2818 if (os_snprintf_error(end - pos, ret))
2819 ret = 0;
2820
2821 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002822 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002823
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002824 while (*cmd == ' ')
2825 cmd++;
2826
2827 stamp = os_strchr(cmd, ' ');
2828 if (stamp) {
2829 *stamp++ = '\0';
2830 while (*stamp == ' ') {
2831 stamp++;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002832 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002833 }
2834
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002835 if (os_strlen(cmd)) {
2836 int level = str_to_debug_level(cmd);
2837 if (level < 0)
2838 return -1;
2839 wpa_debug_level = level;
2840 }
2841
2842 if (stamp && os_strlen(stamp))
2843 wpa_debug_timestamp = atoi(stamp);
2844
2845 os_memcpy(buf, "OK\n", 3);
2846 return 3;
2847}
2848
2849
2850#ifdef NEED_AP_MLME
2851static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data *hapd,
2852 char *buf, size_t buflen)
2853{
2854 struct hostapd_iface *iface = hapd->iface;
2855 char *pos, *end;
2856 struct hostapd_sta_info *info;
2857 struct os_reltime now;
2858
Dmitry Shmidt7d175302016-09-06 13:11:34 -07002859 if (!iface->num_sta_seen)
2860 return 0;
2861
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002862 sta_track_expire(iface, 0);
2863
2864 pos = buf;
2865 end = buf + buflen;
2866
2867 os_get_reltime(&now);
2868 dl_list_for_each_reverse(info, &iface->sta_seen,
2869 struct hostapd_sta_info, list) {
2870 struct os_reltime age;
2871 int ret;
2872
2873 os_reltime_sub(&now, &info->last_seen, &age);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002874 ret = os_snprintf(pos, end - pos, MACSTR " %u %d\n",
2875 MAC2STR(info->addr), (unsigned int) age.sec,
2876 info->ssi_signal);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002877 if (os_snprintf_error(end - pos, ret))
2878 break;
2879 pos += ret;
2880 }
2881
2882 return pos - buf;
2883}
2884#endif /* NEED_AP_MLME */
2885
2886
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002887static int hostapd_ctrl_iface_req_lci(struct hostapd_data *hapd,
2888 const char *cmd)
2889{
2890 u8 addr[ETH_ALEN];
2891
2892 if (hwaddr_aton(cmd, addr)) {
2893 wpa_printf(MSG_INFO, "CTRL: REQ_LCI: Invalid MAC address");
2894 return -1;
2895 }
2896
2897 return hostapd_send_lci_req(hapd, addr);
2898}
2899
2900
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07002901static int hostapd_ctrl_iface_req_range(struct hostapd_data *hapd, char *cmd)
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002902{
2903 u8 addr[ETH_ALEN];
2904 char *token, *context = NULL;
2905 int random_interval, min_ap;
2906 u8 responders[ETH_ALEN * RRM_RANGE_REQ_MAX_RESPONDERS];
2907 unsigned int n_responders;
2908
2909 token = str_token(cmd, " ", &context);
2910 if (!token || hwaddr_aton(token, addr)) {
2911 wpa_printf(MSG_INFO,
2912 "CTRL: REQ_RANGE - Bad destination address");
2913 return -1;
2914 }
2915
2916 token = str_token(cmd, " ", &context);
2917 if (!token)
2918 return -1;
2919
2920 random_interval = atoi(token);
2921 if (random_interval < 0 || random_interval > 0xffff)
2922 return -1;
2923
2924 token = str_token(cmd, " ", &context);
2925 if (!token)
2926 return -1;
2927
2928 min_ap = atoi(token);
2929 if (min_ap <= 0 || min_ap > WLAN_RRM_RANGE_REQ_MAX_MIN_AP)
2930 return -1;
2931
2932 n_responders = 0;
2933 while ((token = str_token(cmd, " ", &context))) {
2934 if (n_responders == RRM_RANGE_REQ_MAX_RESPONDERS) {
2935 wpa_printf(MSG_INFO,
2936 "CTRL: REQ_RANGE: Too many responders");
2937 return -1;
2938 }
2939
2940 if (hwaddr_aton(token, responders + n_responders * ETH_ALEN)) {
2941 wpa_printf(MSG_INFO,
2942 "CTRL: REQ_RANGE: Bad responder address");
2943 return -1;
2944 }
2945
2946 n_responders++;
2947 }
2948
2949 if (!n_responders) {
2950 wpa_printf(MSG_INFO,
2951 "CTRL: REQ_RANGE - No FTM responder address");
2952 return -1;
2953 }
2954
2955 return hostapd_send_range_req(hapd, addr, random_interval, min_ap,
2956 responders, n_responders);
2957}
2958
2959
Dmitry Shmidt29333592017-01-09 12:27:11 -08002960static int hostapd_ctrl_iface_req_beacon(struct hostapd_data *hapd,
2961 const char *cmd, char *reply,
2962 size_t reply_size)
2963{
2964 u8 addr[ETH_ALEN];
2965 const char *pos;
2966 struct wpabuf *req;
2967 int ret;
2968 u8 req_mode = 0;
2969
2970 if (hwaddr_aton(cmd, addr))
2971 return -1;
2972 pos = os_strchr(cmd, ' ');
2973 if (!pos)
2974 return -1;
2975 pos++;
2976 if (os_strncmp(pos, "req_mode=", 9) == 0) {
2977 int val = hex2byte(pos + 9);
2978
2979 if (val < 0)
2980 return -1;
2981 req_mode = val;
2982 pos += 11;
2983 pos = os_strchr(pos, ' ');
2984 if (!pos)
2985 return -1;
2986 pos++;
2987 }
2988 req = wpabuf_parse_bin(pos);
2989 if (!req)
2990 return -1;
2991
2992 ret = hostapd_send_beacon_req(hapd, addr, req_mode, req);
2993 wpabuf_free(req);
2994 if (ret >= 0)
2995 ret = os_snprintf(reply, reply_size, "%d", ret);
2996 return ret;
2997}
2998
2999
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003000static int hostapd_ctrl_iface_show_neighbor(struct hostapd_data *hapd,
3001 char *buf, size_t buflen)
3002{
3003 if (!(hapd->conf->radio_measurements[0] &
3004 WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
3005 wpa_printf(MSG_ERROR,
3006 "CTRL: SHOW_NEIGHBOR: Neighbor report is not enabled");
3007 return -1;
3008 }
3009
3010 return hostapd_neighbor_show(hapd, buf, buflen);
3011}
3012
3013
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003014static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data *hapd, char *buf)
3015{
3016 struct wpa_ssid_value ssid;
3017 u8 bssid[ETH_ALEN];
3018 struct wpabuf *nr, *lci = NULL, *civic = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003019 int stationary = 0;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003020 char *tmp;
3021 int ret;
3022
3023 if (!(hapd->conf->radio_measurements[0] &
3024 WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
3025 wpa_printf(MSG_ERROR,
3026 "CTRL: SET_NEIGHBOR: Neighbor report is not enabled");
3027 return -1;
3028 }
3029
3030 if (hwaddr_aton(buf, bssid)) {
3031 wpa_printf(MSG_ERROR, "CTRL: SET_NEIGHBOR: Bad BSSID");
3032 return -1;
3033 }
3034
3035 tmp = os_strstr(buf, "ssid=");
3036 if (!tmp || ssid_parse(tmp + 5, &ssid)) {
3037 wpa_printf(MSG_ERROR,
3038 "CTRL: SET_NEIGHBOR: Bad or missing SSID");
3039 return -1;
3040 }
3041 buf = os_strchr(tmp + 6, tmp[5] == '"' ? '"' : ' ');
3042 if (!buf)
3043 return -1;
3044
3045 tmp = os_strstr(buf, "nr=");
3046 if (!tmp) {
3047 wpa_printf(MSG_ERROR,
3048 "CTRL: SET_NEIGHBOR: Missing Neighbor Report element");
3049 return -1;
3050 }
3051
3052 buf = os_strchr(tmp, ' ');
3053 if (buf)
3054 *buf++ = '\0';
3055
3056 nr = wpabuf_parse_bin(tmp + 3);
3057 if (!nr) {
3058 wpa_printf(MSG_ERROR,
3059 "CTRL: SET_NEIGHBOR: Bad Neighbor Report element");
3060 return -1;
3061 }
3062
3063 if (!buf)
3064 goto set;
3065
3066 tmp = os_strstr(buf, "lci=");
3067 if (tmp) {
3068 buf = os_strchr(tmp, ' ');
3069 if (buf)
3070 *buf++ = '\0';
3071 lci = wpabuf_parse_bin(tmp + 4);
3072 if (!lci) {
3073 wpa_printf(MSG_ERROR,
3074 "CTRL: SET_NEIGHBOR: Bad LCI subelement");
3075 wpabuf_free(nr);
3076 return -1;
3077 }
3078 }
3079
3080 if (!buf)
3081 goto set;
3082
3083 tmp = os_strstr(buf, "civic=");
3084 if (tmp) {
3085 buf = os_strchr(tmp, ' ');
3086 if (buf)
3087 *buf++ = '\0';
3088 civic = wpabuf_parse_bin(tmp + 6);
3089 if (!civic) {
3090 wpa_printf(MSG_ERROR,
3091 "CTRL: SET_NEIGHBOR: Bad civic subelement");
3092 wpabuf_free(nr);
3093 wpabuf_free(lci);
3094 return -1;
3095 }
3096 }
3097
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003098 if (!buf)
3099 goto set;
3100
3101 if (os_strstr(buf, "stat"))
3102 stationary = 1;
3103
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003104set:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003105 ret = hostapd_neighbor_set(hapd, bssid, &ssid, nr, lci, civic,
3106 stationary);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003107
3108 wpabuf_free(nr);
3109 wpabuf_free(lci);
3110 wpabuf_free(civic);
3111
3112 return ret;
3113}
3114
3115
3116static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data *hapd,
3117 char *buf)
3118{
3119 struct wpa_ssid_value ssid;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003120 struct wpa_ssid_value *ssidp = NULL;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003121 u8 bssid[ETH_ALEN];
3122 char *tmp;
3123
3124 if (hwaddr_aton(buf, bssid)) {
3125 wpa_printf(MSG_ERROR, "CTRL: REMOVE_NEIGHBOR: Bad BSSID");
3126 return -1;
3127 }
3128
3129 tmp = os_strstr(buf, "ssid=");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003130 if (tmp) {
3131 ssidp = &ssid;
3132 if (ssid_parse(tmp + 5, &ssid)) {
3133 wpa_printf(MSG_ERROR,
3134 "CTRL: REMOVE_NEIGHBOR: Bad SSID");
3135 return -1;
3136 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003137 }
3138
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003139 return hostapd_neighbor_remove(hapd, bssid, ssidp);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003140}
3141
3142
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07003143static int hostapd_ctrl_driver_flags(struct hostapd_iface *iface, char *buf,
3144 size_t buflen)
3145{
3146 int ret, i;
3147 char *pos, *end;
3148
3149 ret = os_snprintf(buf, buflen, "%016llX:\n",
3150 (long long unsigned) iface->drv_flags);
3151 if (os_snprintf_error(buflen, ret))
3152 return -1;
3153
3154 pos = buf + ret;
3155 end = buf + buflen;
3156
3157 for (i = 0; i < 64; i++) {
3158 if (iface->drv_flags & (1LLU << i)) {
3159 ret = os_snprintf(pos, end - pos, "%s\n",
3160 driver_flag_to_string(1LLU << i));
3161 if (os_snprintf_error(end - pos, ret))
3162 return -1;
3163 pos += ret;
3164 }
3165 }
3166
3167 return pos - buf;
3168}
3169
3170
Hai Shalomb755a2a2020-04-23 21:49:02 -07003171static int hostapd_ctrl_driver_flags2(struct hostapd_iface *iface, char *buf,
3172 size_t buflen)
3173{
3174 int ret, i;
3175 char *pos, *end;
3176
3177 ret = os_snprintf(buf, buflen, "%016llX:\n",
3178 (long long unsigned) iface->drv_flags2);
3179 if (os_snprintf_error(buflen, ret))
3180 return -1;
3181
3182 pos = buf + ret;
3183 end = buf + buflen;
3184
3185 for (i = 0; i < 64; i++) {
3186 if (iface->drv_flags2 & (1LLU << i)) {
3187 ret = os_snprintf(pos, end - pos, "%s\n",
3188 driver_flag2_to_string(1LLU << i));
3189 if (os_snprintf_error(end - pos, ret))
3190 return -1;
3191 pos += ret;
3192 }
3193 }
3194
3195 return pos - buf;
3196}
3197
3198
Roshan Pius3a1667e2018-07-03 15:17:14 -07003199static int hostapd_ctrl_iface_acl_del_mac(struct mac_acl_entry **acl, int *num,
3200 const char *txtaddr)
3201{
3202 u8 addr[ETH_ALEN];
3203 struct vlan_description vlan_id;
3204
3205 if (!(*num))
3206 return 0;
3207
3208 if (hwaddr_aton(txtaddr, addr))
3209 return -1;
3210
3211 if (hostapd_maclist_found(*acl, *num, addr, &vlan_id))
3212 hostapd_remove_acl_mac(acl, num, addr);
3213
3214 return 0;
3215}
3216
3217
3218static void hostapd_ctrl_iface_acl_clear_list(struct mac_acl_entry **acl,
3219 int *num)
3220{
3221 while (*num)
3222 hostapd_remove_acl_mac(acl, num, (*acl)[0].addr);
3223}
3224
3225
3226static int hostapd_ctrl_iface_acl_show_mac(struct mac_acl_entry *acl, int num,
3227 char *buf, size_t buflen)
3228{
3229 int i = 0, len = 0, ret = 0;
3230
3231 if (!acl)
3232 return 0;
3233
3234 while (i < num) {
3235 ret = os_snprintf(buf + len, buflen - len,
3236 MACSTR " VLAN_ID=%d\n",
3237 MAC2STR(acl[i].addr),
3238 acl[i].vlan_id.untagged);
3239 if (ret < 0 || (size_t) ret >= buflen - len)
3240 return len;
3241 i++;
3242 len += ret;
3243 }
3244 return len;
3245}
3246
3247
3248static int hostapd_ctrl_iface_acl_add_mac(struct mac_acl_entry **acl, int *num,
3249 const char *cmd)
3250{
3251 u8 addr[ETH_ALEN];
3252 struct vlan_description vlan_id;
3253 int ret = 0, vlanid = 0;
3254 const char *pos;
3255
3256 if (hwaddr_aton(cmd, addr))
3257 return -1;
3258
3259 pos = os_strstr(cmd, "VLAN_ID=");
3260 if (pos)
3261 vlanid = atoi(pos + 8);
3262
3263 if (!hostapd_maclist_found(*acl, *num, addr, &vlan_id)) {
3264 ret = hostapd_add_acl_maclist(acl, num, vlanid, addr);
3265 if (ret != -1 && *acl)
3266 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
3267 }
3268
3269 return ret < 0 ? -1 : 0;
3270}
3271
3272
Hai Shalom021b0b52019-04-10 11:17:58 -07003273static int hostapd_ctrl_iface_get_capability(struct hostapd_data *hapd,
3274 const char *field, char *buf,
3275 size_t buflen)
3276{
3277 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'", field);
3278
3279#ifdef CONFIG_DPP
3280 if (os_strcmp(field, "dpp") == 0) {
3281 int res;
3282
3283#ifdef CONFIG_DPP2
3284 res = os_snprintf(buf, buflen, "DPP=2");
3285#else /* CONFIG_DPP2 */
3286 res = os_snprintf(buf, buflen, "DPP=1");
3287#endif /* CONFIG_DPP2 */
3288 if (os_snprintf_error(buflen, res))
3289 return -1;
3290 return res;
3291 }
3292#endif /* CONFIG_DPP */
3293
3294 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3295 field);
3296
3297 return -1;
3298}
3299
3300
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003301static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
3302 char *buf, char *reply,
3303 int reply_size,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003304 struct sockaddr_storage *from,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003305 socklen_t fromlen)
3306{
3307 int reply_len, res;
3308
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003309 os_memcpy(reply, "OK\n", 3);
3310 reply_len = 3;
3311
3312 if (os_strcmp(buf, "PING") == 0) {
3313 os_memcpy(reply, "PONG\n", 5);
3314 reply_len = 5;
3315 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
3316 if (wpa_debug_reopen_file() < 0)
3317 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003318 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
3319 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003320 } else if (os_strcmp(buf, "STATUS") == 0) {
3321 reply_len = hostapd_ctrl_iface_status(hapd, reply,
3322 reply_size);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003323 } else if (os_strcmp(buf, "STATUS-DRIVER") == 0) {
3324 reply_len = hostapd_drv_status(hapd, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003325 } else if (os_strcmp(buf, "MIB") == 0) {
3326 reply_len = ieee802_11_get_mib(hapd, reply, reply_size);
3327 if (reply_len >= 0) {
3328 res = wpa_get_mib(hapd->wpa_auth, reply + reply_len,
3329 reply_size - reply_len);
3330 if (res < 0)
3331 reply_len = -1;
3332 else
3333 reply_len += res;
3334 }
3335 if (reply_len >= 0) {
3336 res = ieee802_1x_get_mib(hapd, reply + reply_len,
3337 reply_size - reply_len);
3338 if (res < 0)
3339 reply_len = -1;
3340 else
3341 reply_len += res;
3342 }
3343#ifndef CONFIG_NO_RADIUS
3344 if (reply_len >= 0) {
3345 res = radius_client_get_mib(hapd->radius,
3346 reply + reply_len,
3347 reply_size - reply_len);
3348 if (res < 0)
3349 reply_len = -1;
3350 else
3351 reply_len += res;
3352 }
3353#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003354 } else if (os_strncmp(buf, "MIB ", 4) == 0) {
3355 reply_len = hostapd_ctrl_iface_mib(hapd, reply, reply_size,
3356 buf + 4);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003357 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
3358 reply_len = hostapd_ctrl_iface_sta_first(hapd, reply,
3359 reply_size);
3360 } else if (os_strncmp(buf, "STA ", 4) == 0) {
3361 reply_len = hostapd_ctrl_iface_sta(hapd, buf + 4, reply,
3362 reply_size);
3363 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
3364 reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
3365 reply_size);
3366 } else if (os_strcmp(buf, "ATTACH") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003367 if (hostapd_ctrl_iface_attach(hapd, from, fromlen, NULL))
3368 reply_len = -1;
3369 } else if (os_strncmp(buf, "ATTACH ", 7) == 0) {
3370 if (hostapd_ctrl_iface_attach(hapd, from, fromlen, buf + 7))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003371 reply_len = -1;
3372 } else if (os_strcmp(buf, "DETACH") == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003373 if (hostapd_ctrl_iface_detach(hapd, from, fromlen))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003374 reply_len = -1;
3375 } else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003376 if (hostapd_ctrl_iface_level(hapd, from, fromlen,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003377 buf + 6))
3378 reply_len = -1;
3379 } else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
3380 if (hostapd_ctrl_iface_new_sta(hapd, buf + 8))
3381 reply_len = -1;
3382 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
3383 if (hostapd_ctrl_iface_deauthenticate(hapd, buf + 15))
3384 reply_len = -1;
3385 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
3386 if (hostapd_ctrl_iface_disassociate(hapd, buf + 13))
3387 reply_len = -1;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003388#ifdef CONFIG_TAXONOMY
3389 } else if (os_strncmp(buf, "SIGNATURE ", 10) == 0) {
3390 reply_len = hostapd_ctrl_iface_signature(hapd, buf + 10,
3391 reply, reply_size);
3392#endif /* CONFIG_TAXONOMY */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003393 } else if (os_strncmp(buf, "POLL_STA ", 9) == 0) {
3394 if (hostapd_ctrl_iface_poll_sta(hapd, buf + 9))
3395 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003396 } else if (os_strcmp(buf, "STOP_AP") == 0) {
3397 if (hostapd_ctrl_iface_stop_ap(hapd))
3398 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003399#ifdef NEED_AP_MLME
3400 } else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
3401 if (hostapd_ctrl_iface_sa_query(hapd, buf + 9))
3402 reply_len = -1;
3403#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003404#ifdef CONFIG_WPS
3405 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
3406 if (hostapd_ctrl_iface_wps_pin(hapd, buf + 8))
3407 reply_len = -1;
3408 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
3409 reply_len = hostapd_ctrl_iface_wps_check_pin(
3410 hapd, buf + 14, reply, reply_size);
3411 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
3412 if (hostapd_wps_button_pushed(hapd, NULL))
3413 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003414 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
3415 if (hostapd_wps_cancel(hapd))
3416 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003417 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
3418 reply_len = hostapd_ctrl_iface_wps_ap_pin(hapd, buf + 11,
3419 reply, reply_size);
3420 } else if (os_strncmp(buf, "WPS_CONFIG ", 11) == 0) {
3421 if (hostapd_ctrl_iface_wps_config(hapd, buf + 11) < 0)
3422 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003423 } else if (os_strncmp(buf, "WPS_GET_STATUS", 13) == 0) {
3424 reply_len = hostapd_ctrl_iface_wps_get_status(hapd, reply,
3425 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003426#ifdef CONFIG_WPS_NFC
3427 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
3428 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd, buf + 17))
3429 reply_len = -1;
3430 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
3431 reply_len = hostapd_ctrl_iface_wps_nfc_config_token(
3432 hapd, buf + 21, reply, reply_size);
3433 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
3434 reply_len = hostapd_ctrl_iface_wps_nfc_token(
3435 hapd, buf + 14, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003436 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
3437 reply_len = hostapd_ctrl_iface_nfc_get_handover_sel(
3438 hapd, buf + 21, reply, reply_size);
3439 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
3440 if (hostapd_ctrl_iface_nfc_report_handover(hapd, buf + 20))
3441 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003442#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003443#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003444#ifdef CONFIG_INTERWORKING
3445 } else if (os_strncmp(buf, "SET_QOS_MAP_SET ", 16) == 0) {
3446 if (hostapd_ctrl_iface_set_qos_map_set(hapd, buf + 16))
3447 reply_len = -1;
3448 } else if (os_strncmp(buf, "SEND_QOS_MAP_CONF ", 18) == 0) {
3449 if (hostapd_ctrl_iface_send_qos_map_conf(hapd, buf + 18))
3450 reply_len = -1;
3451#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003452#ifdef CONFIG_HS20
3453 } else if (os_strncmp(buf, "HS20_WNM_NOTIF ", 15) == 0) {
3454 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd, buf + 15))
3455 reply_len = -1;
3456 } else if (os_strncmp(buf, "HS20_DEAUTH_REQ ", 16) == 0) {
3457 if (hostapd_ctrl_iface_hs20_deauth_req(hapd, buf + 16))
3458 reply_len = -1;
3459#endif /* CONFIG_HS20 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003460#ifdef CONFIG_WNM_AP
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003461 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
3462 if (hostapd_ctrl_iface_disassoc_imminent(hapd, buf + 18))
3463 reply_len = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003464 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
3465 if (hostapd_ctrl_iface_ess_disassoc(hapd, buf + 13))
3466 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003467 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
3468 if (hostapd_ctrl_iface_bss_tm_req(hapd, buf + 11))
3469 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003470 } else if (os_strncmp(buf, "COLOC_INTF_REQ ", 15) == 0) {
3471 if (hostapd_ctrl_iface_coloc_intf_req(hapd, buf + 15))
3472 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003473#endif /* CONFIG_WNM_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003474 } else if (os_strcmp(buf, "GET_CONFIG") == 0) {
3475 reply_len = hostapd_ctrl_iface_get_config(hapd, reply,
3476 reply_size);
3477 } else if (os_strncmp(buf, "SET ", 4) == 0) {
3478 if (hostapd_ctrl_iface_set(hapd, buf + 4))
3479 reply_len = -1;
3480 } else if (os_strncmp(buf, "GET ", 4) == 0) {
3481 reply_len = hostapd_ctrl_iface_get(hapd, buf + 4, reply,
3482 reply_size);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003483 } else if (os_strncmp(buf, "ENABLE", 6) == 0) {
3484 if (hostapd_ctrl_iface_enable(hapd->iface))
3485 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003486 } else if (os_strcmp(buf, "RELOAD_WPA_PSK") == 0) {
3487 if (hostapd_ctrl_iface_reload_wpa_psk(hapd))
3488 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003489 } else if (os_strncmp(buf, "RELOAD", 6) == 0) {
3490 if (hostapd_ctrl_iface_reload(hapd->iface))
3491 reply_len = -1;
3492 } else if (os_strncmp(buf, "DISABLE", 7) == 0) {
3493 if (hostapd_ctrl_iface_disable(hapd->iface))
3494 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003495 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
3496 if (ieee802_11_set_beacon(hapd))
3497 reply_len = -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003498#ifdef CONFIG_TESTING_OPTIONS
3499 } else if (os_strncmp(buf, "RADAR ", 6) == 0) {
3500 if (hostapd_ctrl_iface_radar(hapd, buf + 6))
3501 reply_len = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003502 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
3503 if (hostapd_ctrl_iface_mgmt_tx(hapd, buf + 8))
3504 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003505 } else if (os_strncmp(buf, "MGMT_TX_STATUS_PROCESS ", 23) == 0) {
3506 if (hostapd_ctrl_iface_mgmt_tx_status_process(hapd,
3507 buf + 23) < 0)
3508 reply_len = -1;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003509 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
3510 if (hostapd_ctrl_iface_mgmt_rx_process(hapd, buf + 16) < 0)
3511 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003512 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
3513 if (hostapd_ctrl_iface_eapol_rx(hapd, buf + 9) < 0)
3514 reply_len = -1;
3515 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
3516 if (hostapd_ctrl_iface_data_test_config(hapd, buf + 17) < 0)
3517 reply_len = -1;
3518 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
3519 if (hostapd_ctrl_iface_data_test_tx(hapd, buf + 13) < 0)
3520 reply_len = -1;
3521 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
3522 if (hostapd_ctrl_iface_data_test_frame(hapd, buf + 16) < 0)
3523 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003524 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
3525 if (hostapd_ctrl_test_alloc_fail(hapd, buf + 16) < 0)
3526 reply_len = -1;
3527 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
3528 reply_len = hostapd_ctrl_get_alloc_fail(hapd, reply,
3529 reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003530 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
3531 if (hostapd_ctrl_test_fail(hapd, buf + 10) < 0)
3532 reply_len = -1;
3533 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
3534 reply_len = hostapd_ctrl_get_fail(hapd, reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003535 } else if (os_strncmp(buf, "RESET_PN ", 9) == 0) {
3536 if (hostapd_ctrl_reset_pn(hapd, buf + 9) < 0)
3537 reply_len = -1;
3538 } else if (os_strncmp(buf, "SET_KEY ", 8) == 0) {
3539 if (hostapd_ctrl_set_key(hapd, buf + 8) < 0)
3540 reply_len = -1;
3541 } else if (os_strncmp(buf, "RESEND_M1 ", 10) == 0) {
3542 if (hostapd_ctrl_resend_m1(hapd, buf + 10) < 0)
3543 reply_len = -1;
3544 } else if (os_strncmp(buf, "RESEND_M3 ", 10) == 0) {
3545 if (hostapd_ctrl_resend_m3(hapd, buf + 10) < 0)
3546 reply_len = -1;
3547 } else if (os_strncmp(buf, "RESEND_GROUP_M1 ", 16) == 0) {
3548 if (hostapd_ctrl_resend_group_m1(hapd, buf + 16) < 0)
3549 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003550 } else if (os_strcmp(buf, "REKEY_GTK") == 0) {
3551 if (wpa_auth_rekey_gtk(hapd->wpa_auth) < 0)
3552 reply_len = -1;
Hai Shalomfdcde762020-04-02 11:19:20 -07003553 } else if (os_strncmp(buf, "GET_PMK ", 8) == 0) {
3554 reply_len = hostapd_ctrl_get_pmk(hapd, buf + 8, reply,
3555 reply_size);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003556#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003557 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003558 if (hostapd_ctrl_iface_chan_switch(hapd->iface, buf + 12))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003559 reply_len = -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003560 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
3561 reply_len = hostapd_ctrl_iface_vendor(hapd, buf + 7, reply,
3562 reply_size);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003563 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
3564 ieee802_1x_erp_flush(hapd);
3565#ifdef RADIUS_SERVER
3566 radius_server_erp_flush(hapd->radius_srv);
3567#endif /* RADIUS_SERVER */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003568 } else if (os_strncmp(buf, "EAPOL_REAUTH ", 13) == 0) {
3569 if (hostapd_ctrl_iface_eapol_reauth(hapd, buf + 13))
3570 reply_len = -1;
3571 } else if (os_strncmp(buf, "EAPOL_SET ", 10) == 0) {
3572 if (hostapd_ctrl_iface_eapol_set(hapd, buf + 10))
3573 reply_len = -1;
3574 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
3575 reply_len = hostapd_ctrl_iface_log_level(
3576 hapd, buf + 9, reply, reply_size);
3577#ifdef NEED_AP_MLME
3578 } else if (os_strcmp(buf, "TRACK_STA_LIST") == 0) {
3579 reply_len = hostapd_ctrl_iface_track_sta_list(
3580 hapd, reply, reply_size);
3581#endif /* NEED_AP_MLME */
Dmitry Shmidte4663042016-04-04 10:07:49 -07003582 } else if (os_strcmp(buf, "PMKSA") == 0) {
3583 reply_len = hostapd_ctrl_iface_pmksa_list(hapd, reply,
3584 reply_size);
3585 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
3586 hostapd_ctrl_iface_pmksa_flush(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003587 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
3588 if (hostapd_ctrl_iface_pmksa_add(hapd, buf + 10) < 0)
3589 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003590 } else if (os_strncmp(buf, "SET_NEIGHBOR ", 13) == 0) {
3591 if (hostapd_ctrl_iface_set_neighbor(hapd, buf + 13))
3592 reply_len = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003593 } else if (os_strcmp(buf, "SHOW_NEIGHBOR") == 0) {
3594 reply_len = hostapd_ctrl_iface_show_neighbor(hapd, reply,
3595 reply_size);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003596 } else if (os_strncmp(buf, "REMOVE_NEIGHBOR ", 16) == 0) {
3597 if (hostapd_ctrl_iface_remove_neighbor(hapd, buf + 16))
3598 reply_len = -1;
3599 } else if (os_strncmp(buf, "REQ_LCI ", 8) == 0) {
3600 if (hostapd_ctrl_iface_req_lci(hapd, buf + 8))
3601 reply_len = -1;
3602 } else if (os_strncmp(buf, "REQ_RANGE ", 10) == 0) {
3603 if (hostapd_ctrl_iface_req_range(hapd, buf + 10))
3604 reply_len = -1;
Dmitry Shmidt29333592017-01-09 12:27:11 -08003605 } else if (os_strncmp(buf, "REQ_BEACON ", 11) == 0) {
3606 reply_len = hostapd_ctrl_iface_req_beacon(hapd, buf + 11,
3607 reply, reply_size);
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07003608 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
3609 reply_len = hostapd_ctrl_driver_flags(hapd->iface, reply,
3610 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -07003611 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
3612 reply_len = hostapd_ctrl_driver_flags2(hapd->iface, reply,
3613 reply_size);
Dmitry Shmidt29333592017-01-09 12:27:11 -08003614 } else if (os_strcmp(buf, "TERMINATE") == 0) {
3615 eloop_terminate();
Roshan Pius3a1667e2018-07-03 15:17:14 -07003616 } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) {
3617 if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) {
3618 if (!hostapd_ctrl_iface_acl_add_mac(
3619 &hapd->conf->accept_mac,
3620 &hapd->conf->num_accept_mac, buf + 19))
3621 hostapd_disassoc_accept_mac(hapd);
3622 else
3623 reply_len = -1;
3624 } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) {
3625 hostapd_ctrl_iface_acl_del_mac(
3626 &hapd->conf->accept_mac,
3627 &hapd->conf->num_accept_mac, buf + 19);
3628 } else if (os_strcmp(buf + 11, "SHOW") == 0) {
3629 reply_len = hostapd_ctrl_iface_acl_show_mac(
3630 hapd->conf->accept_mac,
3631 hapd->conf->num_accept_mac, reply, reply_size);
3632 } else if (os_strcmp(buf + 11, "CLEAR") == 0) {
3633 hostapd_ctrl_iface_acl_clear_list(
3634 &hapd->conf->accept_mac,
3635 &hapd->conf->num_accept_mac);
3636 }
3637 } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) {
3638 if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) {
3639 if (!hostapd_ctrl_iface_acl_add_mac(
3640 &hapd->conf->deny_mac,
3641 &hapd->conf->num_deny_mac, buf + 17))
3642 hostapd_disassoc_deny_mac(hapd);
3643 } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) {
3644 hostapd_ctrl_iface_acl_del_mac(
3645 &hapd->conf->deny_mac,
3646 &hapd->conf->num_deny_mac, buf + 17);
3647 } else if (os_strcmp(buf + 9, "SHOW") == 0) {
3648 reply_len = hostapd_ctrl_iface_acl_show_mac(
3649 hapd->conf->deny_mac,
3650 hapd->conf->num_deny_mac, reply, reply_size);
3651 } else if (os_strcmp(buf + 9, "CLEAR") == 0) {
3652 hostapd_ctrl_iface_acl_clear_list(
3653 &hapd->conf->deny_mac,
3654 &hapd->conf->num_deny_mac);
3655 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003656#ifdef CONFIG_DPP
3657 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
3658 res = hostapd_dpp_qr_code(hapd, buf + 12);
3659 if (res < 0) {
3660 reply_len = -1;
3661 } else {
3662 reply_len = os_snprintf(reply, reply_size, "%d", res);
3663 if (os_snprintf_error(reply_size, reply_len))
3664 reply_len = -1;
3665 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003666 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
3667 res = hostapd_dpp_nfc_uri(hapd, buf + 12);
3668 if (res < 0) {
3669 reply_len = -1;
3670 } else {
3671 reply_len = os_snprintf(reply, reply_size, "%d", res);
3672 if (os_snprintf_error(reply_size, reply_len))
3673 reply_len = -1;
3674 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003675 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
3676 res = hostapd_dpp_nfc_handover_req(hapd, buf + 20);
3677 if (res < 0) {
3678 reply_len = -1;
3679 } else {
3680 reply_len = os_snprintf(reply, reply_size, "%d", res);
3681 if (os_snprintf_error(reply_size, reply_len))
3682 reply_len = -1;
3683 }
3684 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
3685 res = hostapd_dpp_nfc_handover_sel(hapd, buf + 20);
3686 if (res < 0) {
3687 reply_len = -1;
3688 } else {
3689 reply_len = os_snprintf(reply, reply_size, "%d", res);
3690 if (os_snprintf_error(reply_size, reply_len))
3691 reply_len = -1;
3692 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003693 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003694 res = dpp_bootstrap_gen(hapd->iface->interfaces->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003695 if (res < 0) {
3696 reply_len = -1;
3697 } else {
3698 reply_len = os_snprintf(reply, reply_size, "%d", res);
3699 if (os_snprintf_error(reply_size, reply_len))
3700 reply_len = -1;
3701 }
3702 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003703 if (dpp_bootstrap_remove(hapd->iface->interfaces->dpp,
3704 buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003705 reply_len = -1;
3706 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
3707 const char *uri;
3708
Hai Shalom021b0b52019-04-10 11:17:58 -07003709 uri = dpp_bootstrap_get_uri(hapd->iface->interfaces->dpp,
3710 atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003711 if (!uri) {
3712 reply_len = -1;
3713 } else {
3714 reply_len = os_snprintf(reply, reply_size, "%s", uri);
3715 if (os_snprintf_error(reply_size, reply_len))
3716 reply_len = -1;
3717 }
3718 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003719 reply_len = dpp_bootstrap_info(hapd->iface->interfaces->dpp,
3720 atoi(buf + 19),
3721 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -07003722 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
3723 if (dpp_bootstrap_set(hapd->iface->interfaces->dpp,
3724 atoi(buf + 18),
3725 os_strchr(buf + 18, ' ')) < 0)
3726 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003727 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
3728 if (hostapd_dpp_auth_init(hapd, buf + 13) < 0)
3729 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003730 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
3731 if (hostapd_dpp_listen(hapd, buf + 11) < 0)
3732 reply_len = -1;
3733 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
3734 hostapd_dpp_stop(hapd);
3735 hostapd_dpp_listen_stop(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003736 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003737 res = dpp_configurator_add(hapd->iface->interfaces->dpp,
3738 buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003739 if (res < 0) {
3740 reply_len = -1;
3741 } else {
3742 reply_len = os_snprintf(reply, reply_size, "%d", res);
3743 if (os_snprintf_error(reply_size, reply_len))
3744 reply_len = -1;
3745 }
3746 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003747 if (dpp_configurator_remove(hapd->iface->interfaces->dpp,
3748 buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003749 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003750 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003751 if (hostapd_dpp_configurator_sign(hapd, buf + 21) < 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -07003752 reply_len = -1;
3753 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003754 reply_len = dpp_configurator_get_key_id(
3755 hapd->iface->interfaces->dpp,
3756 atoi(buf + 25),
3757 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003758 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
3759 res = hostapd_dpp_pkex_add(hapd, buf + 12);
3760 if (res < 0) {
3761 reply_len = -1;
3762 } else {
3763 reply_len = os_snprintf(reply, reply_size, "%d", res);
3764 if (os_snprintf_error(reply_size, reply_len))
3765 reply_len = -1;
3766 }
3767 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
3768 if (hostapd_dpp_pkex_remove(hapd, buf + 16) < 0)
3769 reply_len = -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003770#ifdef CONFIG_DPP2
Hai Shalom899fcc72020-10-19 14:38:18 -07003771 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
3772 if (hostapd_dpp_controller_start(hapd, buf + 20) < 0)
3773 reply_len = -1;
3774 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
3775 if (hostapd_dpp_controller_start(hapd, NULL) < 0)
3776 reply_len = -1;
3777 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
3778 dpp_controller_stop(hapd->iface->interfaces->dpp);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003779 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
3780 if (hostapd_dpp_chirp(hapd, buf + 9) < 0)
3781 reply_len = -1;
3782 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
3783 hostapd_dpp_chirp_stop(hapd);
3784#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003785#endif /* CONFIG_DPP */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003786#ifdef RADIUS_SERVER
3787 } else if (os_strncmp(buf, "DAC_REQUEST ", 12) == 0) {
3788 if (radius_server_dac_request(hapd->radius_srv, buf + 12) < 0)
3789 reply_len = -1;
3790#endif /* RADIUS_SERVER */
Hai Shalom021b0b52019-04-10 11:17:58 -07003791 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
3792 reply_len = hostapd_ctrl_iface_get_capability(
3793 hapd, buf + 15, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003794 } else {
3795 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
3796 reply_len = 16;
3797 }
3798
3799 if (reply_len < 0) {
3800 os_memcpy(reply, "FAIL\n", 5);
3801 reply_len = 5;
3802 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003803
3804 return reply_len;
3805}
3806
3807
3808static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
3809 void *sock_ctx)
3810{
3811 struct hostapd_data *hapd = eloop_ctx;
3812 char buf[4096];
3813 int res;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003814 struct sockaddr_storage from;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003815 socklen_t fromlen = sizeof(from);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003816 char *reply, *pos = buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003817 const int reply_size = 4096;
3818 int reply_len;
3819 int level = MSG_DEBUG;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003820#ifdef CONFIG_CTRL_IFACE_UDP
Hai Shalomfdcde762020-04-02 11:19:20 -07003821 unsigned char lcookie[CTRL_IFACE_COOKIE_LEN];
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003822#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003823
3824 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
3825 (struct sockaddr *) &from, &fromlen);
3826 if (res < 0) {
3827 wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
3828 strerror(errno));
3829 return;
3830 }
3831 buf[res] = '\0';
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003832
3833 reply = os_malloc(reply_size);
3834 if (reply == NULL) {
3835 if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
3836 fromlen) < 0) {
3837 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
3838 strerror(errno));
3839 }
3840 return;
3841 }
3842
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003843#ifdef CONFIG_CTRL_IFACE_UDP
3844 if (os_strcmp(buf, "GET_COOKIE") == 0) {
3845 os_memcpy(reply, "COOKIE=", 7);
Hai Shalomfdcde762020-04-02 11:19:20 -07003846 wpa_snprintf_hex(reply + 7, 2 * CTRL_IFACE_COOKIE_LEN + 1,
3847 hapd->ctrl_iface_cookie,
3848 CTRL_IFACE_COOKIE_LEN);
3849 reply_len = 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003850 goto done;
3851 }
3852
3853 if (os_strncmp(buf, "COOKIE=", 7) != 0 ||
Hai Shalomfdcde762020-04-02 11:19:20 -07003854 hexstr2bin(buf + 7, lcookie, CTRL_IFACE_COOKIE_LEN) < 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003855 wpa_printf(MSG_DEBUG,
3856 "CTRL: No cookie in the request - drop request");
3857 os_free(reply);
3858 return;
3859 }
3860
Hai Shalomfdcde762020-04-02 11:19:20 -07003861 if (os_memcmp(hapd->ctrl_iface_cookie, lcookie,
3862 CTRL_IFACE_COOKIE_LEN) != 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003863 wpa_printf(MSG_DEBUG,
3864 "CTRL: Invalid cookie in the request - drop request");
3865 os_free(reply);
3866 return;
3867 }
3868
Hai Shalomfdcde762020-04-02 11:19:20 -07003869 pos = buf + 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003870 while (*pos == ' ')
3871 pos++;
3872#endif /* CONFIG_CTRL_IFACE_UDP */
3873
3874 if (os_strcmp(pos, "PING") == 0)
3875 level = MSG_EXCESSIVE;
3876 wpa_hexdump_ascii(level, "RX ctrl_iface", pos, res);
3877
3878 reply_len = hostapd_ctrl_iface_receive_process(hapd, pos,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003879 reply, reply_size,
3880 &from, fromlen);
3881
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003882#ifdef CONFIG_CTRL_IFACE_UDP
3883done:
3884#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003885 if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
3886 fromlen) < 0) {
3887 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
3888 strerror(errno));
3889 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003890 os_free(reply);
3891}
3892
3893
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003894#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003895static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd)
3896{
3897 char *buf;
3898 size_t len;
3899
3900 if (hapd->conf->ctrl_interface == NULL)
3901 return NULL;
3902
3903 len = os_strlen(hapd->conf->ctrl_interface) +
3904 os_strlen(hapd->conf->iface) + 2;
3905 buf = os_malloc(len);
3906 if (buf == NULL)
3907 return NULL;
3908
3909 os_snprintf(buf, len, "%s/%s",
3910 hapd->conf->ctrl_interface, hapd->conf->iface);
3911 buf[len - 1] = '\0';
3912 return buf;
3913}
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003914#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003915
3916
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07003917static void hostapd_ctrl_iface_msg_cb(void *ctx, int level,
3918 enum wpa_msg_type type,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003919 const char *txt, size_t len)
3920{
3921 struct hostapd_data *hapd = ctx;
3922 if (hapd == NULL)
3923 return;
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02003924 hostapd_ctrl_iface_send(hapd, level, type, txt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003925}
3926
3927
3928int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
3929{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003930#ifdef CONFIG_CTRL_IFACE_UDP
3931 int port = HOSTAPD_CTRL_IFACE_PORT;
3932 char p[32] = { 0 };
3933 char port_str[40], *tmp;
3934 char *pos;
3935 struct addrinfo hints = { 0 }, *res, *saveres;
3936 int n;
3937
3938 if (hapd->ctrl_sock > -1) {
3939 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
3940 return 0;
3941 }
3942
3943 if (hapd->conf->ctrl_interface == NULL)
3944 return 0;
3945
3946 pos = os_strstr(hapd->conf->ctrl_interface, "udp:");
3947 if (pos) {
3948 pos += 4;
3949 port = atoi(pos);
3950 if (port <= 0) {
3951 wpa_printf(MSG_ERROR, "Invalid ctrl_iface UDP port");
3952 goto fail;
3953 }
3954 }
3955
3956 dl_list_init(&hapd->ctrl_dst);
3957 hapd->ctrl_sock = -1;
Hai Shalomfdcde762020-04-02 11:19:20 -07003958 os_get_random(hapd->ctrl_iface_cookie, CTRL_IFACE_COOKIE_LEN);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003959
3960#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3961 hints.ai_flags = AI_PASSIVE;
3962#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3963
3964#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3965 hints.ai_family = AF_INET6;
3966#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3967 hints.ai_family = AF_INET;
3968#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3969 hints.ai_socktype = SOCK_DGRAM;
3970
3971try_again:
3972 os_snprintf(p, sizeof(p), "%d", port);
3973 n = getaddrinfo(NULL, p, &hints, &res);
3974 if (n) {
3975 wpa_printf(MSG_ERROR, "getaddrinfo(): %s", gai_strerror(n));
3976 goto fail;
3977 }
3978
3979 saveres = res;
3980 hapd->ctrl_sock = socket(res->ai_family, res->ai_socktype,
3981 res->ai_protocol);
3982 if (hapd->ctrl_sock < 0) {
3983 wpa_printf(MSG_ERROR, "socket(PF_INET): %s", strerror(errno));
3984 goto fail;
3985 }
3986
3987 if (bind(hapd->ctrl_sock, res->ai_addr, res->ai_addrlen) < 0) {
3988 port--;
3989 if ((HOSTAPD_CTRL_IFACE_PORT - port) <
3990 HOSTAPD_CTRL_IFACE_PORT_LIMIT && !pos)
3991 goto try_again;
3992 wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
3993 goto fail;
3994 }
3995
3996 freeaddrinfo(saveres);
3997
3998 os_snprintf(port_str, sizeof(port_str), "udp:%d", port);
3999 tmp = os_strdup(port_str);
4000 if (tmp) {
4001 os_free(hapd->conf->ctrl_interface);
4002 hapd->conf->ctrl_interface = tmp;
4003 }
4004 wpa_printf(MSG_DEBUG, "ctrl_iface_init UDP port: %d", port);
4005
4006 if (eloop_register_read_sock(hapd->ctrl_sock,
4007 hostapd_ctrl_iface_receive, hapd, NULL) <
4008 0) {
4009 hostapd_ctrl_iface_deinit(hapd);
4010 return -1;
4011 }
4012
4013 hapd->msg_ctx = hapd;
4014 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4015
4016 return 0;
4017
4018fail:
4019 if (hapd->ctrl_sock >= 0)
4020 close(hapd->ctrl_sock);
4021 return -1;
4022#else /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004023 struct sockaddr_un addr;
4024 int s = -1;
4025 char *fname = NULL;
4026
Dmitry Shmidt04949592012-07-19 12:16:46 -07004027 if (hapd->ctrl_sock > -1) {
4028 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
4029 return 0;
4030 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004031
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004032 dl_list_init(&hapd->ctrl_dst);
4033
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004034 if (hapd->conf->ctrl_interface == NULL)
4035 return 0;
4036
4037 if (mkdir(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
4038 if (errno == EEXIST) {
4039 wpa_printf(MSG_DEBUG, "Using existing control "
4040 "interface directory.");
4041 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004042 wpa_printf(MSG_ERROR, "mkdir[ctrl_interface]: %s",
4043 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004044 goto fail;
4045 }
4046 }
4047
4048 if (hapd->conf->ctrl_interface_gid_set &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004049 lchown(hapd->conf->ctrl_interface, -1,
4050 hapd->conf->ctrl_interface_gid) < 0) {
4051 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004052 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004053 return -1;
4054 }
4055
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004056 if (!hapd->conf->ctrl_interface_gid_set &&
4057 hapd->iface->interfaces->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004058 lchown(hapd->conf->ctrl_interface, -1,
4059 hapd->iface->interfaces->ctrl_iface_group) < 0) {
4060 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004061 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004062 return -1;
4063 }
4064
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004065#ifdef ANDROID
4066 /*
4067 * Android is using umask 0077 which would leave the control interface
4068 * directory without group access. This breaks things since Wi-Fi
4069 * framework assumes that this directory can be accessed by other
4070 * applications in the wifi group. Fix this by adding group access even
4071 * if umask value would prevent this.
4072 */
4073 if (chmod(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
4074 wpa_printf(MSG_ERROR, "CTRL: Could not chmod directory: %s",
4075 strerror(errno));
4076 /* Try to continue anyway */
4077 }
4078#endif /* ANDROID */
4079
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004080 if (os_strlen(hapd->conf->ctrl_interface) + 1 +
4081 os_strlen(hapd->conf->iface) >= sizeof(addr.sun_path))
4082 goto fail;
4083
4084 s = socket(PF_UNIX, SOCK_DGRAM, 0);
4085 if (s < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004086 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004087 goto fail;
4088 }
4089
4090 os_memset(&addr, 0, sizeof(addr));
4091#ifdef __FreeBSD__
4092 addr.sun_len = sizeof(addr);
4093#endif /* __FreeBSD__ */
4094 addr.sun_family = AF_UNIX;
4095 fname = hostapd_ctrl_iface_path(hapd);
4096 if (fname == NULL)
4097 goto fail;
4098 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
4099 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4100 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
4101 strerror(errno));
4102 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4103 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
4104 " allow connections - assuming it was left"
4105 "over from forced program termination");
4106 if (unlink(fname) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004107 wpa_printf(MSG_ERROR,
4108 "Could not unlink existing ctrl_iface socket '%s': %s",
4109 fname, strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004110 goto fail;
4111 }
4112 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
4113 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004114 wpa_printf(MSG_ERROR,
4115 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
4116 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004117 goto fail;
4118 }
4119 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
4120 "ctrl_iface socket '%s'", fname);
4121 } else {
4122 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
4123 "be in use - cannot override it");
4124 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
4125 "not used anymore", fname);
4126 os_free(fname);
4127 fname = NULL;
4128 goto fail;
4129 }
4130 }
4131
4132 if (hapd->conf->ctrl_interface_gid_set &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004133 lchown(fname, -1, hapd->conf->ctrl_interface_gid) < 0) {
4134 wpa_printf(MSG_ERROR, "lchown[ctrl_interface/ifname]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004135 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004136 goto fail;
4137 }
4138
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004139 if (!hapd->conf->ctrl_interface_gid_set &&
4140 hapd->iface->interfaces->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004141 lchown(fname, -1, hapd->iface->interfaces->ctrl_iface_group) < 0) {
4142 wpa_printf(MSG_ERROR, "lchown[ctrl_interface/ifname]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004143 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004144 goto fail;
4145 }
4146
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004147 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004148 wpa_printf(MSG_ERROR, "chmod[ctrl_interface/ifname]: %s",
4149 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004150 goto fail;
4151 }
4152 os_free(fname);
4153
4154 hapd->ctrl_sock = s;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004155 if (eloop_register_read_sock(s, hostapd_ctrl_iface_receive, hapd,
4156 NULL) < 0) {
4157 hostapd_ctrl_iface_deinit(hapd);
4158 return -1;
4159 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004160 hapd->msg_ctx = hapd;
4161 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4162
4163 return 0;
4164
4165fail:
4166 if (s >= 0)
4167 close(s);
4168 if (fname) {
4169 unlink(fname);
4170 os_free(fname);
4171 }
4172 return -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004173#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004174}
4175
4176
4177void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
4178{
4179 struct wpa_ctrl_dst *dst, *prev;
4180
4181 if (hapd->ctrl_sock > -1) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004182#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004183 char *fname;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004184#endif /* !CONFIG_CTRL_IFACE_UDP */
4185
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004186 eloop_unregister_read_sock(hapd->ctrl_sock);
4187 close(hapd->ctrl_sock);
4188 hapd->ctrl_sock = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004189#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004190 fname = hostapd_ctrl_iface_path(hapd);
4191 if (fname)
4192 unlink(fname);
4193 os_free(fname);
4194
4195 if (hapd->conf->ctrl_interface &&
4196 rmdir(hapd->conf->ctrl_interface) < 0) {
4197 if (errno == ENOTEMPTY) {
4198 wpa_printf(MSG_DEBUG, "Control interface "
4199 "directory not empty - leaving it "
4200 "behind");
4201 } else {
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004202 wpa_printf(MSG_ERROR,
4203 "rmdir[ctrl_interface=%s]: %s",
4204 hapd->conf->ctrl_interface,
4205 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004206 }
4207 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004208#endif /* !CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004209 }
4210
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004211 dl_list_for_each_safe(dst, prev, &hapd->ctrl_dst, struct wpa_ctrl_dst,
4212 list)
4213 os_free(dst);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004214
4215#ifdef CONFIG_TESTING_OPTIONS
4216 l2_packet_deinit(hapd->l2_test);
4217 hapd->l2_test = NULL;
4218#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004219}
4220
4221
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004222static int hostapd_ctrl_iface_add(struct hapd_interfaces *interfaces,
4223 char *buf)
4224{
4225 if (hostapd_add_iface(interfaces, buf) < 0) {
4226 wpa_printf(MSG_ERROR, "Adding interface %s failed", buf);
4227 return -1;
4228 }
4229 return 0;
4230}
4231
4232
4233static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces,
4234 char *buf)
4235{
4236 if (hostapd_remove_iface(interfaces, buf) < 0) {
4237 wpa_printf(MSG_ERROR, "Removing interface %s failed", buf);
4238 return -1;
4239 }
4240 return 0;
4241}
4242
4243
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004244static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004245 struct sockaddr_storage *from,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004246 socklen_t fromlen, char *input)
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004247{
Roshan Pius3a1667e2018-07-03 15:17:14 -07004248 return ctrl_iface_attach(&interfaces->global_ctrl_dst, from, fromlen,
4249 input);
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004250}
4251
4252
4253static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces *interfaces,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004254 struct sockaddr_storage *from,
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004255 socklen_t fromlen)
4256{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004257 return ctrl_iface_detach(&interfaces->global_ctrl_dst, from, fromlen);
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004258}
4259
4260
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004261static void hostapd_ctrl_iface_flush(struct hapd_interfaces *interfaces)
4262{
4263#ifdef CONFIG_WPS_TESTING
4264 wps_version_number = 0x20;
4265 wps_testing_dummy_cred = 0;
4266 wps_corrupt_pkhash = 0;
4267#endif /* CONFIG_WPS_TESTING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004268
4269#ifdef CONFIG_TESTING_OPTIONS
4270#ifdef CONFIG_DPP
4271 dpp_test = DPP_TEST_DISABLED;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004272#ifdef CONFIG_DPP2
4273 dpp_version_override = 2;
4274#else /* CONFIG_DPP2 */
4275 dpp_version_override = 1;
4276#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004277#endif /* CONFIG_DPP */
4278#endif /* CONFIG_TESTING_OPTIONS */
4279
4280#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07004281 dpp_global_clear(interfaces->dpp);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004282#endif /* CONFIG_DPP */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004283}
4284
4285
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004286#ifdef CONFIG_FST
4287
4288static int
4289hostapd_global_ctrl_iface_fst_attach(struct hapd_interfaces *interfaces,
4290 const char *cmd)
4291{
4292 char ifname[IFNAMSIZ + 1];
4293 struct fst_iface_cfg cfg;
4294 struct hostapd_data *hapd;
4295 struct fst_wpa_obj iface_obj;
4296
4297 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
4298 hapd = hostapd_get_iface(interfaces, ifname);
4299 if (hapd) {
4300 if (hapd->iface->fst) {
4301 wpa_printf(MSG_INFO, "FST: Already attached");
4302 return -1;
4303 }
4304 fst_hostapd_fill_iface_obj(hapd, &iface_obj);
4305 hapd->iface->fst = fst_attach(ifname, hapd->own_addr,
4306 &iface_obj, &cfg);
4307 if (hapd->iface->fst)
4308 return 0;
4309 }
4310 }
4311
4312 return -EINVAL;
4313}
4314
4315
4316static int
4317hostapd_global_ctrl_iface_fst_detach(struct hapd_interfaces *interfaces,
4318 const char *cmd)
4319{
4320 char ifname[IFNAMSIZ + 1];
4321 struct hostapd_data * hapd;
4322
4323 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
4324 hapd = hostapd_get_iface(interfaces, ifname);
4325 if (hapd) {
4326 if (!fst_iface_detach(ifname)) {
4327 hapd->iface->fst = NULL;
4328 hapd->iface->fst_ies = NULL;
4329 return 0;
4330 }
4331 }
4332 }
4333
4334 return -EINVAL;
4335}
4336
4337#endif /* CONFIG_FST */
4338
4339
4340static struct hostapd_data *
4341hostapd_interfaces_get_hapd(struct hapd_interfaces *interfaces,
4342 const char *ifname)
4343{
4344 size_t i, j;
4345
4346 for (i = 0; i < interfaces->count; i++) {
4347 struct hostapd_iface *iface = interfaces->iface[i];
4348
4349 for (j = 0; j < iface->num_bss; j++) {
4350 struct hostapd_data *hapd;
4351
4352 hapd = iface->bss[j];
4353 if (os_strcmp(ifname, hapd->conf->iface) == 0)
4354 return hapd;
4355 }
4356 }
4357
4358 return NULL;
4359}
4360
4361
4362static int hostapd_ctrl_iface_dup_param(struct hostapd_data *src_hapd,
4363 struct hostapd_data *dst_hapd,
4364 const char *param)
4365{
4366 int res;
4367 char *value;
4368
4369 value = os_zalloc(HOSTAPD_CLI_DUP_VALUE_MAX_LEN);
4370 if (!value) {
4371 wpa_printf(MSG_ERROR,
4372 "DUP: cannot allocate buffer to stringify %s",
4373 param);
4374 goto error_return;
4375 }
4376
4377 if (os_strcmp(param, "wpa") == 0) {
4378 os_snprintf(value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN, "%d",
4379 src_hapd->conf->wpa);
4380 } else if (os_strcmp(param, "wpa_key_mgmt") == 0 &&
4381 src_hapd->conf->wpa_key_mgmt) {
4382 res = hostapd_ctrl_iface_get_key_mgmt(
4383 src_hapd, value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN);
4384 if (os_snprintf_error(HOSTAPD_CLI_DUP_VALUE_MAX_LEN, res))
4385 goto error_stringify;
4386 } else if (os_strcmp(param, "wpa_pairwise") == 0 &&
4387 src_hapd->conf->wpa_pairwise) {
4388 res = wpa_write_ciphers(value,
4389 value + HOSTAPD_CLI_DUP_VALUE_MAX_LEN,
4390 src_hapd->conf->wpa_pairwise, " ");
4391 if (res < 0)
4392 goto error_stringify;
4393 } else if (os_strcmp(param, "rsn_pairwise") == 0 &&
4394 src_hapd->conf->rsn_pairwise) {
4395 res = wpa_write_ciphers(value,
4396 value + HOSTAPD_CLI_DUP_VALUE_MAX_LEN,
4397 src_hapd->conf->rsn_pairwise, " ");
4398 if (res < 0)
4399 goto error_stringify;
4400 } else if (os_strcmp(param, "wpa_passphrase") == 0 &&
4401 src_hapd->conf->ssid.wpa_passphrase) {
4402 os_snprintf(value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN, "%s",
4403 src_hapd->conf->ssid.wpa_passphrase);
4404 } else if (os_strcmp(param, "wpa_psk") == 0 &&
4405 src_hapd->conf->ssid.wpa_psk_set) {
4406 wpa_snprintf_hex(value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN,
4407 src_hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
4408 } else {
4409 wpa_printf(MSG_WARNING, "DUP: %s cannot be duplicated", param);
4410 goto error_return;
4411 }
4412
4413 res = hostapd_set_iface(dst_hapd->iconf, dst_hapd->conf, param, value);
4414 os_free(value);
4415 return res;
4416
4417error_stringify:
4418 wpa_printf(MSG_ERROR, "DUP: cannot stringify %s", param);
4419error_return:
4420 os_free(value);
4421 return -1;
4422}
4423
4424
4425static int
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004426hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces *interfaces,
4427 const char *input,
4428 char *reply, int reply_size)
4429{
4430 size_t i, j;
4431 int res;
4432 char *pos, *end;
4433 struct hostapd_iface *iface;
4434 int show_ctrl = 0;
4435
4436 if (input)
4437 show_ctrl = !!os_strstr(input, "ctrl");
4438
4439 pos = reply;
4440 end = reply + reply_size;
4441
4442 for (i = 0; i < interfaces->count; i++) {
4443 iface = interfaces->iface[i];
4444
4445 for (j = 0; j < iface->num_bss; j++) {
4446 struct hostapd_bss_config *conf;
4447
4448 conf = iface->conf->bss[j];
4449 if (show_ctrl)
4450 res = os_snprintf(pos, end - pos,
4451 "%s ctrl_iface=%s\n",
4452 conf->iface,
4453 conf->ctrl_interface ?
4454 conf->ctrl_interface : "N/A");
4455 else
4456 res = os_snprintf(pos, end - pos, "%s\n",
4457 conf->iface);
4458 if (os_snprintf_error(end - pos, res)) {
4459 *pos = '\0';
4460 return pos - reply;
4461 }
4462 pos += res;
4463 }
4464 }
4465
4466 return pos - reply;
4467}
4468
4469
4470static int
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004471hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces *interfaces,
4472 char *cmd)
4473{
4474 char *p_start = cmd, *p_end;
4475 struct hostapd_data *src_hapd, *dst_hapd;
4476
4477 /* cmd: "<src ifname> <dst ifname> <variable name> */
4478
4479 p_end = os_strchr(p_start, ' ');
4480 if (!p_end) {
4481 wpa_printf(MSG_ERROR, "DUP: no src ifname found in cmd: '%s'",
4482 cmd);
4483 return -1;
4484 }
4485
4486 *p_end = '\0';
4487 src_hapd = hostapd_interfaces_get_hapd(interfaces, p_start);
4488 if (!src_hapd) {
4489 wpa_printf(MSG_ERROR, "DUP: no src ifname found: '%s'",
4490 p_start);
4491 return -1;
4492 }
4493
4494 p_start = p_end + 1;
4495 p_end = os_strchr(p_start, ' ');
4496 if (!p_end) {
4497 wpa_printf(MSG_ERROR, "DUP: no dst ifname found in cmd: '%s'",
4498 cmd);
4499 return -1;
4500 }
4501
4502 *p_end = '\0';
4503 dst_hapd = hostapd_interfaces_get_hapd(interfaces, p_start);
4504 if (!dst_hapd) {
4505 wpa_printf(MSG_ERROR, "DUP: no dst ifname found: '%s'",
4506 p_start);
4507 return -1;
4508 }
4509
4510 p_start = p_end + 1;
4511 return hostapd_ctrl_iface_dup_param(src_hapd, dst_hapd, p_start);
4512}
4513
4514
4515static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces *interfaces,
4516 const char *ifname,
4517 char *buf, char *reply,
4518 int reply_size,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004519 struct sockaddr_storage *from,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004520 socklen_t fromlen)
4521{
4522 struct hostapd_data *hapd;
4523
4524 hapd = hostapd_interfaces_get_hapd(interfaces, ifname);
4525 if (hapd == NULL) {
4526 int res;
4527
4528 res = os_snprintf(reply, reply_size, "FAIL-NO-IFNAME-MATCH\n");
4529 if (os_snprintf_error(reply_size, res))
4530 return -1;
4531 return res;
4532 }
4533
4534 return hostapd_ctrl_iface_receive_process(hapd, buf, reply,reply_size,
4535 from, fromlen);
4536}
4537
4538
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004539static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
4540 void *sock_ctx)
4541{
Hai Shalomfdcde762020-04-02 11:19:20 -07004542 struct hapd_interfaces *interfaces = eloop_ctx;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004543 char buffer[256], *buf = buffer;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004544 int res;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004545 struct sockaddr_storage from;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004546 socklen_t fromlen = sizeof(from);
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004547 char *reply;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004548 int reply_len;
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004549 const int reply_size = 4096;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004550#ifdef CONFIG_CTRL_IFACE_UDP
Hai Shalomfdcde762020-04-02 11:19:20 -07004551 unsigned char lcookie[CTRL_IFACE_COOKIE_LEN];
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004552#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004553
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004554 res = recvfrom(sock, buffer, sizeof(buffer) - 1, 0,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004555 (struct sockaddr *) &from, &fromlen);
4556 if (res < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004557 wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
4558 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004559 return;
4560 }
4561 buf[res] = '\0';
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004562 wpa_printf(MSG_DEBUG, "Global ctrl_iface command: %s", buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004563
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004564 reply = os_malloc(reply_size);
4565 if (reply == NULL) {
4566 if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
4567 fromlen) < 0) {
4568 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
4569 strerror(errno));
4570 }
4571 return;
4572 }
4573
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004574 os_memcpy(reply, "OK\n", 3);
4575 reply_len = 3;
4576
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004577#ifdef CONFIG_CTRL_IFACE_UDP
4578 if (os_strcmp(buf, "GET_COOKIE") == 0) {
4579 os_memcpy(reply, "COOKIE=", 7);
Hai Shalomfdcde762020-04-02 11:19:20 -07004580 wpa_snprintf_hex(reply + 7, 2 * CTRL_IFACE_COOKIE_LEN + 1,
4581 interfaces->ctrl_iface_cookie,
4582 CTRL_IFACE_COOKIE_LEN);
4583 reply_len = 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004584 goto send_reply;
4585 }
4586
4587 if (os_strncmp(buf, "COOKIE=", 7) != 0 ||
Hai Shalomfdcde762020-04-02 11:19:20 -07004588 hexstr2bin(buf + 7, lcookie, CTRL_IFACE_COOKIE_LEN) < 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004589 wpa_printf(MSG_DEBUG,
4590 "CTRL: No cookie in the request - drop request");
4591 os_free(reply);
4592 return;
4593 }
4594
Hai Shalomfdcde762020-04-02 11:19:20 -07004595 if (os_memcmp(interfaces->ctrl_iface_cookie, lcookie,
4596 CTRL_IFACE_COOKIE_LEN) != 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004597 wpa_printf(MSG_DEBUG,
4598 "CTRL: Invalid cookie in the request - drop request");
4599 os_free(reply);
4600 return;
4601 }
4602
Hai Shalomfdcde762020-04-02 11:19:20 -07004603 buf += 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004604 while (*buf == ' ')
4605 buf++;
4606#endif /* CONFIG_CTRL_IFACE_UDP */
4607
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004608 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
4609 char *pos = os_strchr(buf + 7, ' ');
4610
4611 if (pos) {
4612 *pos++ = '\0';
4613 reply_len = hostapd_global_ctrl_iface_ifname(
4614 interfaces, buf + 7, pos, reply, reply_size,
4615 &from, fromlen);
4616 goto send_reply;
4617 }
4618 }
4619
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004620 if (os_strcmp(buf, "PING") == 0) {
4621 os_memcpy(reply, "PONG\n", 5);
4622 reply_len = 5;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004623 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
4624 if (wpa_debug_reopen_file() < 0)
4625 reply_len = -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004626 } else if (os_strcmp(buf, "FLUSH") == 0) {
4627 hostapd_ctrl_iface_flush(interfaces);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004628 } else if (os_strncmp(buf, "ADD ", 4) == 0) {
4629 if (hostapd_ctrl_iface_add(interfaces, buf + 4) < 0)
4630 reply_len = -1;
4631 } else if (os_strncmp(buf, "REMOVE ", 7) == 0) {
4632 if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0)
4633 reply_len = -1;
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004634 } else if (os_strcmp(buf, "ATTACH") == 0) {
4635 if (hostapd_global_ctrl_iface_attach(interfaces, &from,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004636 fromlen, NULL))
4637 reply_len = -1;
4638 } else if (os_strncmp(buf, "ATTACH ", 7) == 0) {
4639 if (hostapd_global_ctrl_iface_attach(interfaces, &from,
4640 fromlen, buf + 7))
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004641 reply_len = -1;
4642 } else if (os_strcmp(buf, "DETACH") == 0) {
4643 if (hostapd_global_ctrl_iface_detach(interfaces, &from,
4644 fromlen))
4645 reply_len = -1;
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -08004646#ifdef CONFIG_MODULE_TESTS
4647 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -08004648 if (hapd_module_tests() < 0)
4649 reply_len = -1;
4650#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004651#ifdef CONFIG_FST
4652 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
4653 if (!hostapd_global_ctrl_iface_fst_attach(interfaces, buf + 11))
4654 reply_len = os_snprintf(reply, reply_size, "OK\n");
4655 else
4656 reply_len = -1;
4657 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
4658 if (!hostapd_global_ctrl_iface_fst_detach(interfaces, buf + 11))
4659 reply_len = os_snprintf(reply, reply_size, "OK\n");
4660 else
4661 reply_len = -1;
4662 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
4663 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
4664#endif /* CONFIG_FST */
4665 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
4666 if (!hostapd_global_ctrl_iface_dup_network(interfaces,
4667 buf + 12))
4668 reply_len = os_snprintf(reply, reply_size, "OK\n");
4669 else
4670 reply_len = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004671 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
4672 reply_len = hostapd_global_ctrl_iface_interfaces(
4673 interfaces, buf + 10, reply, sizeof(buffer));
4674 } else if (os_strcmp(buf, "TERMINATE") == 0) {
4675 eloop_terminate();
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004676 } else {
4677 wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
4678 "ignored");
4679 reply_len = -1;
4680 }
4681
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004682send_reply:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004683 if (reply_len < 0) {
4684 os_memcpy(reply, "FAIL\n", 5);
4685 reply_len = 5;
4686 }
4687
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004688 if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
4689 fromlen) < 0) {
4690 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
4691 strerror(errno));
4692 }
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004693 os_free(reply);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004694}
4695
4696
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004697#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004698static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces *interface)
4699{
4700 char *buf;
4701 size_t len;
4702
4703 if (interface->global_iface_path == NULL)
4704 return NULL;
4705
4706 len = os_strlen(interface->global_iface_path) +
4707 os_strlen(interface->global_iface_name) + 2;
4708 buf = os_malloc(len);
4709 if (buf == NULL)
4710 return NULL;
4711
4712 os_snprintf(buf, len, "%s/%s", interface->global_iface_path,
4713 interface->global_iface_name);
4714 buf[len - 1] = '\0';
4715 return buf;
4716}
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004717#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004718
4719
4720int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
4721{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004722#ifdef CONFIG_CTRL_IFACE_UDP
4723 int port = HOSTAPD_GLOBAL_CTRL_IFACE_PORT;
4724 char p[32] = { 0 };
4725 char *pos;
4726 struct addrinfo hints = { 0 }, *res, *saveres;
4727 int n;
4728
4729 if (interface->global_ctrl_sock > -1) {
4730 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
4731 return 0;
4732 }
4733
4734 if (interface->global_iface_path == NULL)
4735 return 0;
4736
4737 pos = os_strstr(interface->global_iface_path, "udp:");
4738 if (pos) {
4739 pos += 4;
4740 port = atoi(pos);
4741 if (port <= 0) {
4742 wpa_printf(MSG_ERROR, "Invalid global ctrl UDP port");
4743 goto fail;
4744 }
4745 }
4746
Hai Shalomfdcde762020-04-02 11:19:20 -07004747 os_get_random(interface->ctrl_iface_cookie, CTRL_IFACE_COOKIE_LEN);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004748
4749#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
4750 hints.ai_flags = AI_PASSIVE;
4751#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
4752
4753#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
4754 hints.ai_family = AF_INET6;
4755#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4756 hints.ai_family = AF_INET;
4757#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4758 hints.ai_socktype = SOCK_DGRAM;
4759
4760try_again:
4761 os_snprintf(p, sizeof(p), "%d", port);
4762 n = getaddrinfo(NULL, p, &hints, &res);
4763 if (n) {
4764 wpa_printf(MSG_ERROR, "getaddrinfo(): %s", gai_strerror(n));
4765 goto fail;
4766 }
4767
4768 saveres = res;
4769 interface->global_ctrl_sock = socket(res->ai_family, res->ai_socktype,
4770 res->ai_protocol);
4771 if (interface->global_ctrl_sock < 0) {
4772 wpa_printf(MSG_ERROR, "socket(PF_INET): %s", strerror(errno));
4773 goto fail;
4774 }
4775
4776 if (bind(interface->global_ctrl_sock, res->ai_addr, res->ai_addrlen) <
4777 0) {
4778 port++;
4779 if ((port - HOSTAPD_GLOBAL_CTRL_IFACE_PORT) <
4780 HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT && !pos)
4781 goto try_again;
4782 wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
4783 goto fail;
4784 }
4785
4786 freeaddrinfo(saveres);
4787
4788 wpa_printf(MSG_DEBUG, "global ctrl_iface_init UDP port: %d", port);
4789
4790 if (eloop_register_read_sock(interface->global_ctrl_sock,
4791 hostapd_global_ctrl_iface_receive,
4792 interface, NULL) < 0) {
4793 hostapd_global_ctrl_iface_deinit(interface);
4794 return -1;
4795 }
4796
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004797 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4798
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004799 return 0;
4800
4801fail:
4802 if (interface->global_ctrl_sock >= 0)
4803 close(interface->global_ctrl_sock);
4804 return -1;
4805#else /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004806 struct sockaddr_un addr;
4807 int s = -1;
4808 char *fname = NULL;
4809
4810 if (interface->global_iface_path == NULL) {
4811 wpa_printf(MSG_DEBUG, "ctrl_iface not configured!");
4812 return 0;
4813 }
4814
4815 if (mkdir(interface->global_iface_path, S_IRWXU | S_IRWXG) < 0) {
4816 if (errno == EEXIST) {
4817 wpa_printf(MSG_DEBUG, "Using existing control "
4818 "interface directory.");
4819 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004820 wpa_printf(MSG_ERROR, "mkdir[ctrl_interface]: %s",
4821 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004822 goto fail;
4823 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004824 } else if (interface->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004825 lchown(interface->global_iface_path, -1,
4826 interface->ctrl_iface_group) < 0) {
4827 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004828 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004829 goto fail;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004830 }
4831
4832 if (os_strlen(interface->global_iface_path) + 1 +
4833 os_strlen(interface->global_iface_name) >= sizeof(addr.sun_path))
4834 goto fail;
4835
4836 s = socket(PF_UNIX, SOCK_DGRAM, 0);
4837 if (s < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004838 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004839 goto fail;
4840 }
4841
4842 os_memset(&addr, 0, sizeof(addr));
4843#ifdef __FreeBSD__
4844 addr.sun_len = sizeof(addr);
4845#endif /* __FreeBSD__ */
4846 addr.sun_family = AF_UNIX;
4847 fname = hostapd_global_ctrl_iface_path(interface);
4848 if (fname == NULL)
4849 goto fail;
4850 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
4851 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4852 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
4853 strerror(errno));
4854 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4855 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
4856 " allow connections - assuming it was left"
4857 "over from forced program termination");
4858 if (unlink(fname) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004859 wpa_printf(MSG_ERROR,
4860 "Could not unlink existing ctrl_iface socket '%s': %s",
4861 fname, strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004862 goto fail;
4863 }
4864 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
4865 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004866 wpa_printf(MSG_ERROR, "bind(PF_UNIX): %s",
4867 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004868 goto fail;
4869 }
4870 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
4871 "ctrl_iface socket '%s'", fname);
4872 } else {
4873 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
4874 "be in use - cannot override it");
4875 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
4876 "not used anymore", fname);
4877 os_free(fname);
4878 fname = NULL;
4879 goto fail;
4880 }
4881 }
4882
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004883 if (interface->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004884 lchown(fname, -1, interface->ctrl_iface_group) < 0) {
4885 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004886 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004887 goto fail;
4888 }
4889
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004890 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004891 wpa_printf(MSG_ERROR, "chmod[ctrl_interface/ifname]: %s",
4892 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004893 goto fail;
4894 }
4895 os_free(fname);
4896
4897 interface->global_ctrl_sock = s;
4898 eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
4899 interface, NULL);
4900
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004901 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4902
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004903 return 0;
4904
4905fail:
4906 if (s >= 0)
4907 close(s);
4908 if (fname) {
4909 unlink(fname);
4910 os_free(fname);
4911 }
4912 return -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004913#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004914}
4915
4916
4917void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interfaces)
4918{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004919#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004920 char *fname = NULL;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004921#endif /* CONFIG_CTRL_IFACE_UDP */
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004922 struct wpa_ctrl_dst *dst, *prev;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004923
4924 if (interfaces->global_ctrl_sock > -1) {
4925 eloop_unregister_read_sock(interfaces->global_ctrl_sock);
4926 close(interfaces->global_ctrl_sock);
4927 interfaces->global_ctrl_sock = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004928#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004929 fname = hostapd_global_ctrl_iface_path(interfaces);
4930 if (fname) {
4931 unlink(fname);
4932 os_free(fname);
4933 }
4934
4935 if (interfaces->global_iface_path &&
4936 rmdir(interfaces->global_iface_path) < 0) {
4937 if (errno == ENOTEMPTY) {
4938 wpa_printf(MSG_DEBUG, "Control interface "
4939 "directory not empty - leaving it "
4940 "behind");
4941 } else {
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004942 wpa_printf(MSG_ERROR,
4943 "rmdir[ctrl_interface=%s]: %s",
4944 interfaces->global_iface_path,
4945 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004946 }
4947 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004948#endif /* CONFIG_CTRL_IFACE_UDP */
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004949 }
4950
4951 os_free(interfaces->global_iface_path);
4952 interfaces->global_iface_path = NULL;
4953
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004954 dl_list_for_each_safe(dst, prev, &interfaces->global_ctrl_dst,
4955 struct wpa_ctrl_dst, list)
4956 os_free(dst);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004957}
4958
4959
Roshan Pius3a1667e2018-07-03 15:17:14 -07004960static int hostapd_ctrl_check_event_enabled(struct wpa_ctrl_dst *dst,
4961 const char *buf)
4962{
4963 /* Enable Probe Request events based on explicit request.
4964 * Other events are enabled by default.
4965 */
4966 if (str_starts(buf, RX_PROBE_REQUEST))
4967 return !!(dst->events & WPA_EVENT_RX_PROBE_REQUEST);
4968 return 1;
4969}
4970
4971
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004972static void hostapd_ctrl_iface_send_internal(int sock, struct dl_list *ctrl_dst,
4973 const char *ifname, int level,
4974 const char *buf, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004975{
4976 struct wpa_ctrl_dst *dst, *next;
4977 struct msghdr msg;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004978 int idx, res;
4979 struct iovec io[5];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004980 char levelstr[10];
4981
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004982 if (sock < 0 || dl_list_empty(ctrl_dst))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004983 return;
4984
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004985 res = os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
4986 if (os_snprintf_error(sizeof(levelstr), res))
4987 return;
4988 idx = 0;
4989 if (ifname) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004990 io[idx].iov_base = "IFNAME=";
4991 io[idx].iov_len = 7;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004992 idx++;
4993 io[idx].iov_base = (char *) ifname;
4994 io[idx].iov_len = os_strlen(ifname);
4995 idx++;
4996 io[idx].iov_base = " ";
4997 io[idx].iov_len = 1;
4998 idx++;
4999 }
5000 io[idx].iov_base = levelstr;
5001 io[idx].iov_len = os_strlen(levelstr);
5002 idx++;
5003 io[idx].iov_base = (char *) buf;
5004 io[idx].iov_len = len;
5005 idx++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005006 os_memset(&msg, 0, sizeof(msg));
5007 msg.msg_iov = io;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005008 msg.msg_iovlen = idx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005009
5010 idx = 0;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08005011 dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005012 if ((level >= dst->debug_level) &&
5013 hostapd_ctrl_check_event_enabled(dst, buf)) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08005014 sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor send",
5015 &dst->addr, dst->addrlen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005016 msg.msg_name = &dst->addr;
5017 msg.msg_namelen = dst->addrlen;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005018 if (sendmsg(sock, &msg, 0) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005019 int _errno = errno;
5020 wpa_printf(MSG_INFO, "CTRL_IFACE monitor[%d]: "
5021 "%d - %s",
5022 idx, errno, strerror(errno));
5023 dst->errors++;
5024 if (dst->errors > 10 || _errno == ENOENT) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005025 ctrl_iface_detach(ctrl_dst,
5026 &dst->addr,
5027 dst->addrlen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005028 }
5029 } else
5030 dst->errors = 0;
5031 }
5032 idx++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005033 }
5034}
5035
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005036
5037static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
5038 enum wpa_msg_type type,
5039 const char *buf, size_t len)
5040{
5041 if (type != WPA_MSG_NO_GLOBAL) {
5042 hostapd_ctrl_iface_send_internal(
5043 hapd->iface->interfaces->global_ctrl_sock,
5044 &hapd->iface->interfaces->global_ctrl_dst,
5045 type != WPA_MSG_PER_INTERFACE ?
5046 NULL : hapd->conf->iface,
5047 level, buf, len);
5048 }
5049
5050 if (type != WPA_MSG_ONLY_GLOBAL) {
5051 hostapd_ctrl_iface_send_internal(
5052 hapd->ctrl_sock, &hapd->ctrl_dst,
5053 NULL, level, buf, len);
5054 }
5055}
5056
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005057#endif /* CONFIG_NATIVE_WINDOWS */