blob: ad994d426452b761c52e1438dc344b33c40fe92b [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"
Hai Shalom60840252021-02-19 19:02:11 -080040#include "common/ptksa_cache.h"
Dmitry Shmidtff787d52015-01-12 13:01:47 -080041#include "crypto/tls.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042#include "drivers/driver.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080043#include "eapol_auth/eapol_auth_sm.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044#include "radius/radius_client.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080045#include "radius/radius_server.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080046#include "l2_packet/l2_packet.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070047#include "ap/hostapd.h"
48#include "ap/ap_config.h"
49#include "ap/ieee802_1x.h"
50#include "ap/wpa_auth.h"
Hai Shalom899fcc72020-10-19 14:38:18 -070051#include "ap/pmksa_cache_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070052#include "ap/ieee802_11.h"
53#include "ap/sta_info.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070054#include "ap/wps_hostapd.h"
55#include "ap/ctrl_iface_ap.h"
56#include "ap/ap_drv_ops.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080057#include "ap/hs20.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080058#include "ap/wnm_ap.h"
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -070059#include "ap/wpa_auth.h"
Dmitry Shmidt7f656022015-02-25 14:36:37 -080060#include "ap/beacon.h"
Dmitry Shmidt849734c2016-05-27 09:59:01 -070061#include "ap/neighbor_db.h"
62#include "ap/rrm.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070063#include "ap/dpp_hostapd.h"
Hai Shalomfdcde762020-04-02 11:19:20 -070064#include "ap/dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070065#include "wps/wps_defs.h"
66#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080067#include "fst/fst_ctrl_iface.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070068#include "config_file.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069#include "ctrl_iface.h"
70
71
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080072#define HOSTAPD_CLI_DUP_VALUE_MAX_LEN 256
73
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080074#ifdef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080075#define HOSTAPD_CTRL_IFACE_PORT 8877
76#define HOSTAPD_CTRL_IFACE_PORT_LIMIT 50
77#define HOSTAPD_GLOBAL_CTRL_IFACE_PORT 8878
78#define HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT 50
79#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080
81static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
Anton Nayshtutf715e8d2014-11-16 16:52:49 +020082 enum wpa_msg_type type,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083 const char *buf, size_t len);
84
85
86static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080087 struct sockaddr_storage *from,
Roshan Pius3a1667e2018-07-03 15:17:14 -070088 socklen_t fromlen, const char *input)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089{
Roshan Pius3a1667e2018-07-03 15:17:14 -070090 return ctrl_iface_attach(&hapd->ctrl_dst, from, fromlen, input);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070091}
92
93
94static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080095 struct sockaddr_storage *from,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070096 socklen_t fromlen)
97{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080098 return ctrl_iface_detach(&hapd->ctrl_dst, from, fromlen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070099}
100
101
102static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800103 struct sockaddr_storage *from,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 socklen_t fromlen,
105 char *level)
106{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800107 return ctrl_iface_level(&hapd->ctrl_dst, from, fromlen, level);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700108}
109
110
111static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
112 const char *txtaddr)
113{
114 u8 addr[ETH_ALEN];
115 struct sta_info *sta;
116
117 wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);
118
119 if (hwaddr_aton(txtaddr, addr))
120 return -1;
121
122 sta = ap_get_sta(hapd, addr);
123 if (sta)
124 return 0;
125
126 wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
127 "notification", MAC2STR(addr));
128 sta = ap_sta_add(hapd, addr);
129 if (sta == NULL)
130 return -1;
131
132 hostapd_new_assoc_sta(hapd, sta, 0);
133 return 0;
134}
135
136
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700137#ifdef NEED_AP_MLME
138static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
139 const char *txtaddr)
140{
141 u8 addr[ETH_ALEN];
142 u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
143
144 wpa_printf(MSG_DEBUG, "CTRL_IFACE SA_QUERY %s", txtaddr);
145
146 if (hwaddr_aton(txtaddr, addr) ||
147 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0)
148 return -1;
149
150 ieee802_11_send_sa_query_req(hapd, addr, trans_id);
151
152 return 0;
153}
154#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700155
156
157#ifdef CONFIG_WPS
158static int hostapd_ctrl_iface_wps_pin(struct hostapd_data *hapd, char *txt)
159{
160 char *pin = os_strchr(txt, ' ');
161 char *timeout_txt;
162 int timeout;
163 u8 addr_buf[ETH_ALEN], *addr = NULL;
164 char *pos;
165
166 if (pin == NULL)
167 return -1;
168 *pin++ = '\0';
169
170 timeout_txt = os_strchr(pin, ' ');
171 if (timeout_txt) {
172 *timeout_txt++ = '\0';
173 timeout = atoi(timeout_txt);
174 pos = os_strchr(timeout_txt, ' ');
175 if (pos) {
176 *pos++ = '\0';
177 if (hwaddr_aton(pos, addr_buf) == 0)
178 addr = addr_buf;
179 }
180 } else
181 timeout = 0;
182
183 return hostapd_wps_add_pin(hapd, addr, txt, pin, timeout);
184}
185
186
187static int hostapd_ctrl_iface_wps_check_pin(
188 struct hostapd_data *hapd, char *cmd, char *buf, size_t buflen)
189{
190 char pin[9];
191 size_t len;
192 char *pos;
193 int ret;
194
195 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
196 (u8 *) cmd, os_strlen(cmd));
197 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
198 if (*pos < '0' || *pos > '9')
199 continue;
200 pin[len++] = *pos;
201 if (len == 9) {
202 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
203 return -1;
204 }
205 }
206 if (len != 4 && len != 8) {
207 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
208 return -1;
209 }
210 pin[len] = '\0';
211
212 if (len == 8) {
213 unsigned int pin_val;
214 pin_val = atoi(pin);
215 if (!wps_pin_valid(pin_val)) {
216 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
217 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800218 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 return -1;
220 return ret;
221 }
222 }
223
224 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800225 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226 return -1;
227
228 return ret;
229}
230
231
Dmitry Shmidt04949592012-07-19 12:16:46 -0700232#ifdef CONFIG_WPS_NFC
233static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data *hapd,
234 char *pos)
235{
236 size_t len;
237 struct wpabuf *buf;
238 int ret;
239
240 len = os_strlen(pos);
241 if (len & 0x01)
242 return -1;
243 len /= 2;
244
245 buf = wpabuf_alloc(len);
246 if (buf == NULL)
247 return -1;
248 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
249 wpabuf_free(buf);
250 return -1;
251 }
252
253 ret = hostapd_wps_nfc_tag_read(hapd, buf);
254 wpabuf_free(buf);
255
256 return ret;
257}
258
259
260static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data *hapd,
261 char *cmd, char *reply,
262 size_t max_len)
263{
264 int ndef;
265 struct wpabuf *buf;
266 int res;
267
268 if (os_strcmp(cmd, "WPS") == 0)
269 ndef = 0;
270 else if (os_strcmp(cmd, "NDEF") == 0)
271 ndef = 1;
272 else
273 return -1;
274
275 buf = hostapd_wps_nfc_config_token(hapd, ndef);
276 if (buf == NULL)
277 return -1;
278
279 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
280 wpabuf_len(buf));
281 reply[res++] = '\n';
282 reply[res] = '\0';
283
284 wpabuf_free(buf);
285
286 return res;
287}
288
289
290static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data *hapd,
291 char *reply, size_t max_len,
292 int ndef)
293{
294 struct wpabuf *buf;
295 int res;
296
297 buf = hostapd_wps_nfc_token_gen(hapd, ndef);
298 if (buf == NULL)
299 return -1;
300
301 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
302 wpabuf_len(buf));
303 reply[res++] = '\n';
304 reply[res] = '\0';
305
306 wpabuf_free(buf);
307
308 return res;
309}
310
311
312static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data *hapd,
313 char *cmd, char *reply,
314 size_t max_len)
315{
316 if (os_strcmp(cmd, "WPS") == 0)
317 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
318 max_len, 0);
319
320 if (os_strcmp(cmd, "NDEF") == 0)
321 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
322 max_len, 1);
323
324 if (os_strcmp(cmd, "enable") == 0)
325 return hostapd_wps_nfc_token_enable(hapd);
326
327 if (os_strcmp(cmd, "disable") == 0) {
328 hostapd_wps_nfc_token_disable(hapd);
329 return 0;
330 }
331
332 return -1;
333}
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800334
335
336static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data *hapd,
337 char *cmd, char *reply,
338 size_t max_len)
339{
340 struct wpabuf *buf;
341 int res;
342 char *pos;
343 int ndef;
344
345 pos = os_strchr(cmd, ' ');
346 if (pos == NULL)
347 return -1;
348 *pos++ = '\0';
349
350 if (os_strcmp(cmd, "WPS") == 0)
351 ndef = 0;
352 else if (os_strcmp(cmd, "NDEF") == 0)
353 ndef = 1;
354 else
355 return -1;
356
357 if (os_strcmp(pos, "WPS-CR") == 0)
358 buf = hostapd_wps_nfc_hs_cr(hapd, ndef);
359 else
360 buf = NULL;
361 if (buf == NULL)
362 return -1;
363
364 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
365 wpabuf_len(buf));
366 reply[res++] = '\n';
367 reply[res] = '\0';
368
369 wpabuf_free(buf);
370
371 return res;
372}
373
374
375static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data *hapd,
376 char *cmd)
377{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800378 size_t len;
379 struct wpabuf *req, *sel;
380 int ret;
381 char *pos, *role, *type, *pos2;
382
383 role = cmd;
384 pos = os_strchr(role, ' ');
385 if (pos == NULL)
386 return -1;
387 *pos++ = '\0';
388
389 type = pos;
390 pos = os_strchr(type, ' ');
391 if (pos == NULL)
392 return -1;
393 *pos++ = '\0';
394
395 pos2 = os_strchr(pos, ' ');
396 if (pos2 == NULL)
397 return -1;
398 *pos2++ = '\0';
399
400 len = os_strlen(pos);
401 if (len & 0x01)
402 return -1;
403 len /= 2;
404
405 req = wpabuf_alloc(len);
406 if (req == NULL)
407 return -1;
408 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
409 wpabuf_free(req);
410 return -1;
411 }
412
413 len = os_strlen(pos2);
414 if (len & 0x01) {
415 wpabuf_free(req);
416 return -1;
417 }
418 len /= 2;
419
420 sel = wpabuf_alloc(len);
421 if (sel == NULL) {
422 wpabuf_free(req);
423 return -1;
424 }
425 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
426 wpabuf_free(req);
427 wpabuf_free(sel);
428 return -1;
429 }
430
431 if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) {
432 ret = hostapd_wps_nfc_report_handover(hapd, req, sel);
433 } else {
434 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
435 "reported: role=%s type=%s", role, type);
436 ret = -1;
437 }
438 wpabuf_free(req);
439 wpabuf_free(sel);
440
441 return ret;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800442}
443
Dmitry Shmidt04949592012-07-19 12:16:46 -0700444#endif /* CONFIG_WPS_NFC */
445
446
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700447static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data *hapd, char *txt,
448 char *buf, size_t buflen)
449{
450 int timeout = 300;
451 char *pos;
452 const char *pin_txt;
453
454 pos = os_strchr(txt, ' ');
455 if (pos)
456 *pos++ = '\0';
457
458 if (os_strcmp(txt, "disable") == 0) {
459 hostapd_wps_ap_pin_disable(hapd);
460 return os_snprintf(buf, buflen, "OK\n");
461 }
462
463 if (os_strcmp(txt, "random") == 0) {
464 if (pos)
465 timeout = atoi(pos);
466 pin_txt = hostapd_wps_ap_pin_random(hapd, timeout);
467 if (pin_txt == NULL)
468 return -1;
469 return os_snprintf(buf, buflen, "%s", pin_txt);
470 }
471
472 if (os_strcmp(txt, "get") == 0) {
473 pin_txt = hostapd_wps_ap_pin_get(hapd);
474 if (pin_txt == NULL)
475 return -1;
476 return os_snprintf(buf, buflen, "%s", pin_txt);
477 }
478
479 if (os_strcmp(txt, "set") == 0) {
480 char *pin;
481 if (pos == NULL)
482 return -1;
483 pin = pos;
484 pos = os_strchr(pos, ' ');
485 if (pos) {
486 *pos++ = '\0';
487 timeout = atoi(pos);
488 }
489 if (os_strlen(pin) > buflen)
490 return -1;
491 if (hostapd_wps_ap_pin_set(hapd, pin, timeout) < 0)
492 return -1;
493 return os_snprintf(buf, buflen, "%s", pin);
494 }
495
496 return -1;
497}
498
499
500static int hostapd_ctrl_iface_wps_config(struct hostapd_data *hapd, char *txt)
501{
502 char *pos;
503 char *ssid, *auth, *encr = NULL, *key = NULL;
504
505 ssid = txt;
506 pos = os_strchr(txt, ' ');
507 if (!pos)
508 return -1;
509 *pos++ = '\0';
510
511 auth = pos;
512 pos = os_strchr(pos, ' ');
513 if (pos) {
514 *pos++ = '\0';
515 encr = pos;
516 pos = os_strchr(pos, ' ');
517 if (pos) {
518 *pos++ = '\0';
519 key = pos;
520 }
521 }
522
523 return hostapd_wps_config_ap(hapd, ssid, auth, encr, key);
524}
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700525
526
527static const char * pbc_status_str(enum pbc_status status)
528{
529 switch (status) {
530 case WPS_PBC_STATUS_DISABLE:
531 return "Disabled";
532 case WPS_PBC_STATUS_ACTIVE:
533 return "Active";
534 case WPS_PBC_STATUS_TIMEOUT:
535 return "Timed-out";
536 case WPS_PBC_STATUS_OVERLAP:
537 return "Overlap";
538 default:
539 return "Unknown";
540 }
541}
542
543
544static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
545 char *buf, size_t buflen)
546{
547 int ret;
548 char *pos, *end;
549
550 pos = buf;
551 end = buf + buflen;
552
553 ret = os_snprintf(pos, end - pos, "PBC Status: %s\n",
554 pbc_status_str(hapd->wps_stats.pbc_status));
555
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800556 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700557 return pos - buf;
558 pos += ret;
559
560 ret = os_snprintf(pos, end - pos, "Last WPS result: %s\n",
561 (hapd->wps_stats.status == WPS_STATUS_SUCCESS ?
562 "Success":
563 (hapd->wps_stats.status == WPS_STATUS_FAILURE ?
564 "Failed" : "None")));
565
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800566 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700567 return pos - buf;
568 pos += ret;
569
570 /* If status == Failure - Add possible Reasons */
571 if(hapd->wps_stats.status == WPS_STATUS_FAILURE &&
572 hapd->wps_stats.failure_reason > 0) {
573 ret = os_snprintf(pos, end - pos,
574 "Failure Reason: %s\n",
575 wps_ei_str(hapd->wps_stats.failure_reason));
576
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800577 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700578 return pos - buf;
579 pos += ret;
580 }
581
582 if (hapd->wps_stats.status) {
583 ret = os_snprintf(pos, end - pos, "Peer Address: " MACSTR "\n",
584 MAC2STR(hapd->wps_stats.peer_addr));
585
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800586 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700587 return pos - buf;
588 pos += ret;
589 }
590
591 return pos - buf;
592}
593
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700594#endif /* CONFIG_WPS */
595
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800596#ifdef CONFIG_HS20
597
598static int hostapd_ctrl_iface_hs20_wnm_notif(struct hostapd_data *hapd,
599 const char *cmd)
600{
601 u8 addr[ETH_ALEN];
602 const char *url;
603
604 if (hwaddr_aton(cmd, addr))
605 return -1;
606 url = cmd + 17;
607 if (*url == '\0') {
608 url = NULL;
609 } else {
610 if (*url != ' ')
611 return -1;
612 url++;
613 if (*url == '\0')
614 url = NULL;
615 }
616
617 return hs20_send_wnm_notification(hapd, addr, 1, url);
618}
619
620
621static int hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data *hapd,
622 const char *cmd)
623{
624 u8 addr[ETH_ALEN];
625 int code, reauth_delay, ret;
626 const char *pos;
627 size_t url_len;
628 struct wpabuf *req;
629
630 /* <STA MAC Addr> <Code(0/1)> <Re-auth-Delay(sec)> [URL] */
631 if (hwaddr_aton(cmd, addr))
632 return -1;
633
634 pos = os_strchr(cmd, ' ');
635 if (pos == NULL)
636 return -1;
637 pos++;
638 code = atoi(pos);
639
640 pos = os_strchr(pos, ' ');
641 if (pos == NULL)
642 return -1;
643 pos++;
644 reauth_delay = atoi(pos);
645
646 url_len = 0;
647 pos = os_strchr(pos, ' ');
648 if (pos) {
649 pos++;
650 url_len = os_strlen(pos);
651 }
652
653 req = wpabuf_alloc(4 + url_len);
654 if (req == NULL)
655 return -1;
656 wpabuf_put_u8(req, code);
657 wpabuf_put_le16(req, reauth_delay);
658 wpabuf_put_u8(req, url_len);
659 if (pos)
660 wpabuf_put_data(req, pos, url_len);
661
662 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to " MACSTR
663 " to indicate imminent deauthentication (code=%d "
664 "reauth_delay=%d)", MAC2STR(addr), code, reauth_delay);
665 ret = hs20_send_wnm_notification_deauth_req(hapd, addr, req);
666 wpabuf_free(req);
667 return ret;
668}
669
670#endif /* CONFIG_HS20 */
671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700672
Dmitry Shmidt051af732013-10-22 13:52:46 -0700673#ifdef CONFIG_INTERWORKING
674
675static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data *hapd,
676 const char *cmd)
677{
678 u8 qos_map_set[16 + 2 * 21], count = 0;
679 const char *pos = cmd;
680 int val, ret;
681
682 for (;;) {
683 if (count == sizeof(qos_map_set)) {
684 wpa_printf(MSG_ERROR, "Too many qos_map_set parameters");
685 return -1;
686 }
687
688 val = atoi(pos);
689 if (val < 0 || val > 255) {
690 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
691 return -1;
692 }
693
694 qos_map_set[count++] = val;
695 pos = os_strchr(pos, ',');
696 if (!pos)
697 break;
698 pos++;
699 }
700
701 if (count < 16 || count & 1) {
702 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
703 return -1;
704 }
705
706 ret = hostapd_drv_set_qos_map(hapd, qos_map_set, count);
707 if (ret) {
708 wpa_printf(MSG_INFO, "Failed to set QoS Map Set");
709 return -1;
710 }
711
712 os_memcpy(hapd->conf->qos_map_set, qos_map_set, count);
713 hapd->conf->qos_map_set_len = count;
714
715 return 0;
716}
717
718
719static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
720 const char *cmd)
721{
722 u8 addr[ETH_ALEN];
723 struct sta_info *sta;
724 struct wpabuf *buf;
725 u8 *qos_map_set = hapd->conf->qos_map_set;
726 u8 qos_map_set_len = hapd->conf->qos_map_set_len;
727 int ret;
728
729 if (!qos_map_set_len) {
730 wpa_printf(MSG_INFO, "QoS Map Set is not set");
731 return -1;
732 }
733
734 if (hwaddr_aton(cmd, addr))
735 return -1;
736
737 sta = ap_get_sta(hapd, addr);
738 if (sta == NULL) {
739 wpa_printf(MSG_DEBUG, "Station " MACSTR " not found "
740 "for QoS Map Configuration message",
741 MAC2STR(addr));
742 return -1;
743 }
744
745 if (!sta->qos_map_enabled) {
746 wpa_printf(MSG_DEBUG, "Station " MACSTR " did not indicate "
747 "support for QoS Map", MAC2STR(addr));
748 return -1;
749 }
750
751 buf = wpabuf_alloc(2 + 2 + qos_map_set_len);
752 if (buf == NULL)
753 return -1;
754
755 wpabuf_put_u8(buf, WLAN_ACTION_QOS);
756 wpabuf_put_u8(buf, QOS_QOS_MAP_CONFIG);
757
758 /* QoS Map Set Element */
759 wpabuf_put_u8(buf, WLAN_EID_QOS_MAP_SET);
760 wpabuf_put_u8(buf, qos_map_set_len);
761 wpabuf_put_data(buf, qos_map_set, qos_map_set_len);
762
763 ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
764 wpabuf_head(buf), wpabuf_len(buf));
765 wpabuf_free(buf);
766
767 return ret;
768}
769
770#endif /* CONFIG_INTERWORKING */
771
772
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700773#ifdef CONFIG_WNM_AP
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800774
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800775static int hostapd_ctrl_iface_coloc_intf_req(struct hostapd_data *hapd,
776 const char *cmd)
777{
778 u8 addr[ETH_ALEN];
779 struct sta_info *sta;
780 const char *pos;
781 unsigned int auto_report, timeout;
782
783 if (hwaddr_aton(cmd, addr)) {
784 wpa_printf(MSG_DEBUG, "Invalid STA MAC address");
785 return -1;
786 }
787
788 sta = ap_get_sta(hapd, addr);
789 if (!sta) {
790 wpa_printf(MSG_DEBUG, "Station " MACSTR
791 " not found for Collocated Interference Request",
792 MAC2STR(addr));
793 return -1;
794 }
795
796 pos = cmd + 17;
797 if (*pos != ' ')
798 return -1;
799 pos++;
800 auto_report = atoi(pos);
801 pos = os_strchr(pos, ' ');
802 if (!pos)
803 return -1;
804 pos++;
805 timeout = atoi(pos);
806
807 return wnm_send_coloc_intf_req(hapd, sta, auto_report, timeout);
808}
809
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700810#endif /* CONFIG_WNM_AP */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800811
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800812
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800813static int hostapd_ctrl_iface_get_key_mgmt(struct hostapd_data *hapd,
814 char *buf, size_t buflen)
815{
816 int ret = 0;
817 char *pos, *end;
818
819 pos = buf;
820 end = buf + buflen;
821
822 WPA_ASSERT(hapd->conf->wpa_key_mgmt);
823
824 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
825 ret = os_snprintf(pos, end - pos, "WPA-PSK ");
826 if (os_snprintf_error(end - pos, ret))
827 return pos - buf;
828 pos += ret;
829 }
830 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
831 ret = os_snprintf(pos, end - pos, "WPA-EAP ");
832 if (os_snprintf_error(end - pos, ret))
833 return pos - buf;
834 pos += ret;
835 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800836#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800837 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
838 ret = os_snprintf(pos, end - pos, "FT-PSK ");
839 if (os_snprintf_error(end - pos, ret))
840 return pos - buf;
841 pos += ret;
842 }
843 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
844 ret = os_snprintf(pos, end - pos, "FT-EAP ");
845 if (os_snprintf_error(end - pos, ret))
846 return pos - buf;
847 pos += ret;
848 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700849#ifdef CONFIG_SHA384
850 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) {
851 ret = os_snprintf(pos, end - pos, "FT-EAP-SHA384 ");
852 if (os_snprintf_error(end - pos, ret))
853 return pos - buf;
854 pos += ret;
855 }
856#endif /* CONFIG_SHA384 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800857#ifdef CONFIG_SAE
858 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_SAE) {
859 ret = os_snprintf(pos, end - pos, "FT-SAE ");
860 if (os_snprintf_error(end - pos, ret))
861 return pos - buf;
862 pos += ret;
863 }
864#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800865#ifdef CONFIG_FILS
866 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
867 ret = os_snprintf(pos, end - pos, "FT-FILS-SHA256 ");
868 if (os_snprintf_error(end - pos, ret))
869 return pos - buf;
870 pos += ret;
871 }
872 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
873 ret = os_snprintf(pos, end - pos, "FT-FILS-SHA384 ");
874 if (os_snprintf_error(end - pos, ret))
875 return pos - buf;
876 pos += ret;
877 }
878#endif /* CONFIG_FILS */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800879#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800880 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
881 ret = os_snprintf(pos, end - pos, "WPA-PSK-SHA256 ");
882 if (os_snprintf_error(end - pos, ret))
883 return pos - buf;
884 pos += ret;
885 }
886 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
887 ret = os_snprintf(pos, end - pos, "WPA-EAP-SHA256 ");
888 if (os_snprintf_error(end - pos, ret))
889 return pos - buf;
890 pos += ret;
891 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800892#ifdef CONFIG_SAE
893 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_SAE) {
894 ret = os_snprintf(pos, end - pos, "SAE ");
895 if (os_snprintf_error(end - pos, ret))
896 return pos - buf;
897 pos += ret;
898 }
899#endif /* CONFIG_SAE */
900 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
901 ret = os_snprintf(pos, end - pos, "WPA-EAP-SUITE-B ");
902 if (os_snprintf_error(end - pos, ret))
903 return pos - buf;
904 pos += ret;
905 }
906 if (hapd->conf->wpa_key_mgmt &
907 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
908 ret = os_snprintf(pos, end - pos,
909 "WPA-EAP-SUITE-B-192 ");
910 if (os_snprintf_error(end - pos, ret))
911 return pos - buf;
912 pos += ret;
913 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800914#ifdef CONFIG_FILS
915 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
916 ret = os_snprintf(pos, end - pos, "FILS-SHA256 ");
917 if (os_snprintf_error(end - pos, ret))
918 return pos - buf;
919 pos += ret;
920 }
921 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
922 ret = os_snprintf(pos, end - pos, "FILS-SHA384 ");
923 if (os_snprintf_error(end - pos, ret))
924 return pos - buf;
925 pos += ret;
926 }
927#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800928
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700929#ifdef CONFIG_OWE
930 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) {
931 ret = os_snprintf(pos, end - pos, "OWE ");
932 if (os_snprintf_error(end - pos, ret))
933 return pos - buf;
934 pos += ret;
935 }
936#endif /* CONFIG_OWE */
937
938#ifdef CONFIG_DPP
939 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) {
940 ret = os_snprintf(pos, end - pos, "DPP ");
941 if (os_snprintf_error(end - pos, ret))
942 return pos - buf;
943 pos += ret;
944 }
945#endif /* CONFIG_DPP */
946
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800947 if (pos > buf && *(pos - 1) == ' ') {
948 *(pos - 1) = '\0';
949 pos--;
950 }
951
952 return pos - buf;
953}
954
955
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700956static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
957 char *buf, size_t buflen)
958{
959 int ret;
960 char *pos, *end;
961
962 pos = buf;
963 end = buf + buflen;
964
965 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
966 "ssid=%s\n",
967 MAC2STR(hapd->own_addr),
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700968 wpa_ssid_txt(hapd->conf->ssid.ssid,
969 hapd->conf->ssid.ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800970 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971 return pos - buf;
972 pos += ret;
973
974#ifdef CONFIG_WPS
975 ret = os_snprintf(pos, end - pos, "wps_state=%s\n",
976 hapd->conf->wps_state == 0 ? "disabled" :
977 (hapd->conf->wps_state == 1 ? "not configured" :
978 "configured"));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800979 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700980 return pos - buf;
981 pos += ret;
982
983 if (hapd->conf->wps_state && hapd->conf->wpa &&
984 hapd->conf->ssid.wpa_passphrase) {
985 ret = os_snprintf(pos, end - pos, "passphrase=%s\n",
986 hapd->conf->ssid.wpa_passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800987 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988 return pos - buf;
989 pos += ret;
990 }
991
992 if (hapd->conf->wps_state && hapd->conf->wpa &&
993 hapd->conf->ssid.wpa_psk &&
994 hapd->conf->ssid.wpa_psk->group) {
995 char hex[PMK_LEN * 2 + 1];
996 wpa_snprintf_hex(hex, sizeof(hex),
997 hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
998 ret = os_snprintf(pos, end - pos, "psk=%s\n", hex);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800999 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000 return pos - buf;
1001 pos += ret;
1002 }
Hai Shalom60840252021-02-19 19:02:11 -08001003
1004 if (hapd->conf->multi_ap) {
1005 struct hostapd_ssid *ssid = &hapd->conf->multi_ap_backhaul_ssid;
1006
1007 ret = os_snprintf(pos, end - pos, "multi_ap=%d\n",
1008 hapd->conf->multi_ap);
1009 if (os_snprintf_error(end - pos, ret))
1010 return pos - buf;
1011 pos += ret;
1012
1013 if (ssid->ssid_len) {
1014 ret = os_snprintf(pos, end - pos,
1015 "multi_ap_backhaul_ssid=%s\n",
1016 wpa_ssid_txt(ssid->ssid,
1017 ssid->ssid_len));
1018 if (os_snprintf_error(end - pos, ret))
1019 return pos - buf;
1020 pos += ret;
1021 }
1022
1023 if (hapd->conf->wps_state && hapd->conf->wpa &&
1024 ssid->wpa_passphrase) {
1025 ret = os_snprintf(pos, end - pos,
1026 "multi_ap_backhaul_wpa_passphrase=%s\n",
1027 ssid->wpa_passphrase);
1028 if (os_snprintf_error(end - pos, ret))
1029 return pos - buf;
1030 pos += ret;
1031 }
1032
1033 if (hapd->conf->wps_state && hapd->conf->wpa &&
1034 ssid->wpa_psk &&
1035 ssid->wpa_psk->group) {
1036 char hex[PMK_LEN * 2 + 1];
1037
1038 wpa_snprintf_hex(hex, sizeof(hex), ssid->wpa_psk->psk,
1039 PMK_LEN);
1040 ret = os_snprintf(pos, end - pos,
1041 "multi_ap_backhaul_wpa_psk=%s\n",
1042 hex);
1043 forced_memzero(hex, sizeof(hex));
1044 if (os_snprintf_error(end - pos, ret))
1045 return pos - buf;
1046 pos += ret;
1047 }
1048 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049#endif /* CONFIG_WPS */
1050
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001051 if (hapd->conf->wpa) {
1052 ret = os_snprintf(pos, end - pos, "wpa=%d\n", hapd->conf->wpa);
1053 if (os_snprintf_error(end - pos, ret))
1054 return pos - buf;
1055 pos += ret;
1056 }
1057
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001058 if (hapd->conf->wpa && hapd->conf->wpa_key_mgmt) {
1059 ret = os_snprintf(pos, end - pos, "key_mgmt=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001060 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061 return pos - buf;
1062 pos += ret;
1063
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001064 pos += hostapd_ctrl_iface_get_key_mgmt(hapd, pos, end - pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065
1066 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001067 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001068 return pos - buf;
1069 pos += ret;
1070 }
1071
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001072 if (hapd->conf->wpa) {
1073 ret = os_snprintf(pos, end - pos, "group_cipher=%s\n",
1074 wpa_cipher_txt(hapd->conf->wpa_group));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001075 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 return pos - buf;
1077 pos += ret;
1078 }
1079
1080 if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->rsn_pairwise) {
1081 ret = os_snprintf(pos, end - pos, "rsn_pairwise_cipher=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001082 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083 return pos - buf;
1084 pos += ret;
1085
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001086 ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
1087 " ");
1088 if (ret < 0)
1089 return pos - buf;
1090 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001091
1092 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001093 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094 return pos - buf;
1095 pos += ret;
1096 }
1097
1098 if ((hapd->conf->wpa & WPA_PROTO_WPA) && hapd->conf->wpa_pairwise) {
1099 ret = os_snprintf(pos, end - pos, "wpa_pairwise_cipher=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001100 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101 return pos - buf;
1102 pos += ret;
1103
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001104 ret = wpa_write_ciphers(pos, end, hapd->conf->wpa_pairwise,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001105 " ");
1106 if (ret < 0)
1107 return pos - buf;
1108 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109
1110 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001111 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001112 return pos - buf;
1113 pos += ret;
1114 }
1115
Hai Shalomfdcde762020-04-02 11:19:20 -07001116 if (hapd->conf->wpa && hapd->conf->wpa_deny_ptk0_rekey) {
1117 ret = os_snprintf(pos, end - pos, "wpa_deny_ptk0_rekey=%d\n",
1118 hapd->conf->wpa_deny_ptk0_rekey);
1119 if (os_snprintf_error(end - pos, ret))
1120 return pos - buf;
1121 pos += ret;
1122 }
1123
1124 if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->extended_key_id) {
1125 ret = os_snprintf(pos, end - pos, "extended_key_id=%d\n",
1126 hapd->conf->extended_key_id);
1127 if (os_snprintf_error(end - pos, ret))
1128 return pos - buf;
1129 pos += ret;
1130 }
1131
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132 return pos - buf;
1133}
1134
1135
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001136static int hostapd_ctrl_iface_set_band(struct hostapd_data *hapd,
Hai Shalom60840252021-02-19 19:02:11 -08001137 const char *bands)
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001138{
1139 union wpa_event_data event;
Hai Shalom60840252021-02-19 19:02:11 -08001140 u32 setband_mask = WPA_SETBAND_AUTO;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001141
Hai Shalom60840252021-02-19 19:02:11 -08001142 /*
1143 * For example:
1144 * SET setband 2G,6G
1145 * SET setband 5G
1146 * SET setband AUTO
1147 */
1148 if (!os_strstr(bands, "AUTO")) {
1149 if (os_strstr(bands, "5G"))
1150 setband_mask |= WPA_SETBAND_5G;
1151 if (os_strstr(bands, "6G"))
1152 setband_mask |= WPA_SETBAND_6G;
1153 if (os_strstr(bands, "2G"))
1154 setband_mask |= WPA_SETBAND_2G;
1155 if (setband_mask == WPA_SETBAND_AUTO)
1156 return -1;
1157 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001158
Hai Shalom60840252021-02-19 19:02:11 -08001159 if (hostapd_drv_set_band(hapd, setband_mask) == 0) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001160 os_memset(&event, 0, sizeof(event));
1161 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
1162 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
1163 wpa_supplicant_event(hapd, EVENT_CHANNEL_LIST_CHANGED, &event);
1164 }
1165
1166 return 0;
1167}
1168
1169
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001170static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
1171{
1172 char *value;
1173 int ret = 0;
1174
1175 value = os_strchr(cmd, ' ');
1176 if (value == NULL)
1177 return -1;
1178 *value++ = '\0';
1179
1180 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
1181 if (0) {
1182#ifdef CONFIG_WPS_TESTING
1183 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
1184 long int val;
1185 val = strtol(value, NULL, 0);
1186 if (val < 0 || val > 0xff) {
1187 ret = -1;
1188 wpa_printf(MSG_DEBUG, "WPS: Invalid "
1189 "wps_version_number %ld", val);
1190 } else {
1191 wps_version_number = val;
1192 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
1193 "version %u.%u",
1194 (wps_version_number & 0xf0) >> 4,
1195 wps_version_number & 0x0f);
1196 hostapd_wps_update_ie(hapd);
1197 }
Hai Shaloma20dcd72022-02-04 13:43:00 -08001198 } else if (os_strcasecmp(cmd, "wps_testing_stub_cred") == 0) {
1199 wps_testing_stub_cred = atoi(value);
1200 wpa_printf(MSG_DEBUG, "WPS: Testing - stub_cred=%d",
1201 wps_testing_stub_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001202 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
1203 wps_corrupt_pkhash = atoi(value);
1204 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
1205 wps_corrupt_pkhash);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001206#endif /* CONFIG_WPS_TESTING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001207#ifdef CONFIG_TESTING_OPTIONS
1208 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
1209 hapd->ext_mgmt_frame_handling = atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001210 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
1211 hapd->ext_eapol_frame_io = atoi(value);
Hai Shaloma20dcd72022-02-04 13:43:00 -08001212 } else if (os_strcasecmp(cmd, "force_backlog_bytes") == 0) {
1213 hapd->force_backlog_bytes = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001214#ifdef CONFIG_DPP
1215 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
1216 os_free(hapd->dpp_config_obj_override);
1217 hapd->dpp_config_obj_override = os_strdup(value);
1218 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
1219 os_free(hapd->dpp_discovery_override);
1220 hapd->dpp_discovery_override = os_strdup(value);
1221 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
1222 os_free(hapd->dpp_groups_override);
1223 hapd->dpp_groups_override = os_strdup(value);
1224 } else if (os_strcasecmp(cmd,
1225 "dpp_ignore_netaccesskey_mismatch") == 0) {
1226 hapd->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001227 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
1228 dpp_test = atoi(value);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001229 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
1230 dpp_version_override = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001231#endif /* CONFIG_DPP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001232#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001233#ifdef CONFIG_MBO
1234 } else if (os_strcasecmp(cmd, "mbo_assoc_disallow") == 0) {
1235 int val;
1236
1237 if (!hapd->conf->mbo_enabled)
1238 return -1;
1239
1240 val = atoi(value);
Hai Shaloma20dcd72022-02-04 13:43:00 -08001241 if (val < 0 || val > MBO_ASSOC_DISALLOW_REASON_LOW_RSSI)
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001242 return -1;
1243
1244 hapd->mbo_assoc_disallow = val;
1245 ieee802_11_update_beacons(hapd->iface);
1246
1247 /*
1248 * TODO: Need to configure drivers that do AP MLME offload with
1249 * disallowing station logic.
1250 */
1251#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001252#ifdef CONFIG_DPP
1253 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
1254 os_free(hapd->dpp_configurator_params);
1255 hapd->dpp_configurator_params = os_strdup(value);
Sunil Ravia04bd252022-05-02 22:54:18 -07001256#ifdef CONFIG_DPP2
1257 dpp_controller_set_params(hapd->iface->interfaces->dpp, value);
1258#endif /* CONFIG_DPP2 */
Hai Shaloma20dcd72022-02-04 13:43:00 -08001259 } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
1260 hapd->dpp_init_max_tries = atoi(value);
1261 } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
1262 hapd->dpp_init_retry_time = atoi(value);
1263 } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
1264 hapd->dpp_resp_wait_time = atoi(value);
1265 } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
1266 hapd->dpp_resp_max_tries = atoi(value);
1267 } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
1268 hapd->dpp_resp_retry_time = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001269#endif /* CONFIG_DPP */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001270 } else if (os_strcasecmp(cmd, "setband") == 0) {
1271 ret = hostapd_ctrl_iface_set_band(hapd, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001272 } else {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001273 ret = hostapd_set_iface(hapd->iconf, hapd->conf, cmd, value);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001274 if (ret)
1275 return ret;
1276
1277 if (os_strcasecmp(cmd, "deny_mac_file") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001278 hostapd_disassoc_deny_mac(hapd);
1279 } else if (os_strcasecmp(cmd, "accept_mac_file") == 0) {
1280 hostapd_disassoc_accept_mac(hapd);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001281 } else if (os_strncmp(cmd, "wme_ac_", 7) == 0 ||
1282 os_strncmp(cmd, "wmm_ac_", 7) == 0) {
1283 hapd->parameter_set_count++;
1284 if (ieee802_11_update_beacons(hapd->iface))
1285 wpa_printf(MSG_DEBUG,
1286 "Failed to update beacons with WMM parameters");
Hai Shalomc3565922019-10-28 11:58:20 -07001287 } else if (os_strcmp(cmd, "wpa_passphrase") == 0 ||
1288 os_strcmp(cmd, "sae_password") == 0 ||
1289 os_strcmp(cmd, "sae_pwe") == 0) {
1290 if (hapd->started)
1291 hostapd_setup_sae_pt(hapd->conf);
Hai Shalom899fcc72020-10-19 14:38:18 -07001292 } else if (os_strcasecmp(cmd, "transition_disable") == 0) {
1293 wpa_auth_set_transition_disable(hapd->wpa_auth,
1294 hapd->conf->transition_disable);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001295 }
Hai Shalomb755a2a2020-04-23 21:49:02 -07001296
1297#ifdef CONFIG_TESTING_OPTIONS
1298 if (os_strcmp(cmd, "ft_rsnxe_used") == 0)
1299 wpa_auth_set_ft_rsnxe_used(hapd->wpa_auth,
1300 hapd->conf->ft_rsnxe_used);
Hai Shalom899fcc72020-10-19 14:38:18 -07001301 else if (os_strcmp(cmd, "oci_freq_override_eapol_m3") == 0)
1302 wpa_auth_set_ocv_override_freq(
1303 hapd->wpa_auth, WPA_AUTH_OCV_OVERRIDE_EAPOL_M3,
1304 atoi(value));
1305 else if (os_strcmp(cmd, "oci_freq_override_eapol_g1") == 0)
1306 wpa_auth_set_ocv_override_freq(
1307 hapd->wpa_auth, WPA_AUTH_OCV_OVERRIDE_EAPOL_G1,
1308 atoi(value));
1309 else if (os_strcmp(cmd, "oci_freq_override_ft_assoc") == 0)
1310 wpa_auth_set_ocv_override_freq(
1311 hapd->wpa_auth, WPA_AUTH_OCV_OVERRIDE_FT_ASSOC,
1312 atoi(value));
1313 else if (os_strcmp(cmd, "oci_freq_override_fils_assoc") == 0)
1314 wpa_auth_set_ocv_override_freq(
1315 hapd->wpa_auth,
1316 WPA_AUTH_OCV_OVERRIDE_FILS_ASSOC, atoi(value));
Kai Shie75b0652020-11-24 20:31:29 -08001317 else if (os_strcasecmp(cmd, "skip_send_eapol") == 0)
1318 wpa_auth_set_skip_send_eapol(hapd->wpa_auth, atoi(value));
1319 else if (os_strcasecmp(cmd, "enable_eapol_large_timeout") == 0)
1320 wpa_auth_set_enable_eapol_large_timeout(hapd->wpa_auth, atoi(value));
Hai Shalomb755a2a2020-04-23 21:49:02 -07001321#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001322 }
1323
1324 return ret;
1325}
1326
1327
1328static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
1329 char *buf, size_t buflen)
1330{
1331 int res;
1332
1333 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
1334
1335 if (os_strcmp(cmd, "version") == 0) {
1336 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001337 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001338 return -1;
1339 return res;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001340 } else if (os_strcmp(cmd, "tls_library") == 0) {
1341 res = tls_get_library_version(buf, buflen);
1342 if (os_snprintf_error(buflen, res))
1343 return -1;
1344 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 }
1346
1347 return -1;
1348}
1349
1350
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001351static int hostapd_ctrl_iface_enable(struct hostapd_iface *iface)
1352{
1353 if (hostapd_enable_iface(iface) < 0) {
1354 wpa_printf(MSG_ERROR, "Enabling of interface failed");
1355 return -1;
1356 }
1357 return 0;
1358}
1359
1360
1361static int hostapd_ctrl_iface_reload(struct hostapd_iface *iface)
1362{
1363 if (hostapd_reload_iface(iface) < 0) {
1364 wpa_printf(MSG_ERROR, "Reloading of interface failed");
1365 return -1;
1366 }
1367 return 0;
1368}
1369
1370
1371static int hostapd_ctrl_iface_disable(struct hostapd_iface *iface)
1372{
1373 if (hostapd_disable_iface(iface) < 0) {
1374 wpa_printf(MSG_ERROR, "Disabling of interface failed");
1375 return -1;
1376 }
1377 return 0;
1378}
1379
1380
Hai Shalom74f70d42019-02-11 14:42:39 -08001381static int
1382hostapd_ctrl_iface_kick_mismatch_psk_sta_iter(struct hostapd_data *hapd,
1383 struct sta_info *sta, void *ctx)
1384{
1385 struct hostapd_wpa_psk *psk;
1386 const u8 *pmk;
1387 int pmk_len;
1388 int pmk_match;
1389 int sta_match;
1390 int bss_match;
1391 int reason;
1392
1393 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
1394
1395 for (psk = hapd->conf->ssid.wpa_psk; pmk && psk; psk = psk->next) {
1396 pmk_match = PMK_LEN == pmk_len &&
1397 os_memcmp(psk->psk, pmk, pmk_len) == 0;
1398 sta_match = psk->group == 0 &&
1399 os_memcmp(sta->addr, psk->addr, ETH_ALEN) == 0;
1400 bss_match = psk->group == 1;
1401
1402 if (pmk_match && (sta_match || bss_match))
1403 return 0;
1404 }
1405
1406 wpa_printf(MSG_INFO, "STA " MACSTR
1407 " PSK/passphrase no longer valid - disconnect",
1408 MAC2STR(sta->addr));
1409 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
1410 hostapd_drv_sta_deauth(hapd, sta->addr, reason);
1411 ap_sta_deauthenticate(hapd, sta, reason);
1412
1413 return 0;
1414}
1415
1416
1417static int hostapd_ctrl_iface_reload_wpa_psk(struct hostapd_data *hapd)
1418{
1419 struct hostapd_bss_config *conf = hapd->conf;
1420 int err;
1421
1422 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
1423
1424 err = hostapd_setup_wpa_psk(conf);
1425 if (err < 0) {
1426 wpa_printf(MSG_ERROR, "Reloading WPA-PSK passwords failed: %d",
1427 err);
1428 return -1;
1429 }
1430
1431 ap_for_each_sta(hapd, hostapd_ctrl_iface_kick_mismatch_psk_sta_iter,
1432 NULL);
1433
1434 return 0;
1435}
1436
1437
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001438#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001439
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001440static int hostapd_ctrl_iface_radar(struct hostapd_data *hapd, char *cmd)
1441{
1442 union wpa_event_data data;
1443 char *pos, *param;
1444 enum wpa_event_type event;
1445
1446 wpa_printf(MSG_DEBUG, "RADAR TEST: %s", cmd);
1447
1448 os_memset(&data, 0, sizeof(data));
1449
1450 param = os_strchr(cmd, ' ');
1451 if (param == NULL)
1452 return -1;
1453 *param++ = '\0';
1454
1455 if (os_strcmp(cmd, "DETECTED") == 0)
1456 event = EVENT_DFS_RADAR_DETECTED;
1457 else if (os_strcmp(cmd, "CAC-FINISHED") == 0)
1458 event = EVENT_DFS_CAC_FINISHED;
1459 else if (os_strcmp(cmd, "CAC-ABORTED") == 0)
1460 event = EVENT_DFS_CAC_ABORTED;
1461 else if (os_strcmp(cmd, "NOP-FINISHED") == 0)
1462 event = EVENT_DFS_NOP_FINISHED;
1463 else {
1464 wpa_printf(MSG_DEBUG, "Unsupported RADAR test command: %s",
1465 cmd);
1466 return -1;
1467 }
1468
1469 pos = os_strstr(param, "freq=");
1470 if (pos)
1471 data.dfs_event.freq = atoi(pos + 5);
1472
1473 pos = os_strstr(param, "ht_enabled=1");
1474 if (pos)
1475 data.dfs_event.ht_enabled = 1;
1476
1477 pos = os_strstr(param, "chan_offset=");
1478 if (pos)
1479 data.dfs_event.chan_offset = atoi(pos + 12);
1480
1481 pos = os_strstr(param, "chan_width=");
1482 if (pos)
1483 data.dfs_event.chan_width = atoi(pos + 11);
1484
1485 pos = os_strstr(param, "cf1=");
1486 if (pos)
1487 data.dfs_event.cf1 = atoi(pos + 4);
1488
1489 pos = os_strstr(param, "cf2=");
1490 if (pos)
1491 data.dfs_event.cf2 = atoi(pos + 4);
1492
1493 wpa_supplicant_event(hapd, event, &data);
1494
1495 return 0;
1496}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001497
1498
1499static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data *hapd, char *cmd)
1500{
1501 size_t len;
1502 u8 *buf;
1503 int res;
1504
1505 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
1506
1507 len = os_strlen(cmd);
1508 if (len & 1)
1509 return -1;
1510 len /= 2;
1511
1512 buf = os_malloc(len);
1513 if (buf == NULL)
1514 return -1;
1515
1516 if (hexstr2bin(cmd, buf, len) < 0) {
1517 os_free(buf);
1518 return -1;
1519 }
1520
Hai Shalomfdcde762020-04-02 11:19:20 -07001521 res = hostapd_drv_send_mlme(hapd, buf, len, 0, NULL, 0, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001522 os_free(buf);
1523 return res;
1524}
1525
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001526
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001527static int hostapd_ctrl_iface_mgmt_tx_status_process(struct hostapd_data *hapd,
1528 char *cmd)
1529{
1530 char *pos, *param;
1531 size_t len;
1532 u8 *buf;
1533 int stype = 0, ok = 0;
1534 union wpa_event_data event;
1535
1536 if (!hapd->ext_mgmt_frame_handling)
1537 return -1;
1538
1539 /* stype=<val> ok=<0/1> buf=<frame hexdump> */
1540
1541 wpa_printf(MSG_DEBUG, "External MGMT TX status process: %s", cmd);
1542
1543 pos = cmd;
1544 param = os_strstr(pos, "stype=");
1545 if (param) {
1546 param += 6;
1547 stype = atoi(param);
1548 }
1549
1550 param = os_strstr(pos, " ok=");
1551 if (param) {
1552 param += 4;
1553 ok = atoi(param);
1554 }
1555
1556 param = os_strstr(pos, " buf=");
1557 if (!param)
1558 return -1;
1559 param += 5;
1560
1561 len = os_strlen(param);
1562 if (len & 1)
1563 return -1;
1564 len /= 2;
1565
1566 buf = os_malloc(len);
1567 if (!buf || hexstr2bin(param, buf, len) < 0) {
1568 os_free(buf);
1569 return -1;
1570 }
1571
1572 os_memset(&event, 0, sizeof(event));
1573 event.tx_status.type = WLAN_FC_TYPE_MGMT;
1574 event.tx_status.data = buf;
1575 event.tx_status.data_len = len;
1576 event.tx_status.stype = stype;
1577 event.tx_status.ack = ok;
1578 hapd->ext_mgmt_frame_handling = 0;
1579 wpa_supplicant_event(hapd, EVENT_TX_STATUS, &event);
1580 hapd->ext_mgmt_frame_handling = 1;
1581
1582 os_free(buf);
1583
1584 return 0;
1585}
1586
1587
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001588static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data *hapd,
1589 char *cmd)
1590{
1591 char *pos, *param;
1592 size_t len;
1593 u8 *buf;
1594 int freq = 0, datarate = 0, ssi_signal = 0;
1595 union wpa_event_data event;
1596
1597 if (!hapd->ext_mgmt_frame_handling)
1598 return -1;
1599
1600 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
1601
1602 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
1603
1604 pos = cmd;
1605 param = os_strstr(pos, "freq=");
1606 if (param) {
1607 param += 5;
1608 freq = atoi(param);
1609 }
1610
1611 param = os_strstr(pos, " datarate=");
1612 if (param) {
1613 param += 10;
1614 datarate = atoi(param);
1615 }
1616
1617 param = os_strstr(pos, " ssi_signal=");
1618 if (param) {
1619 param += 12;
1620 ssi_signal = atoi(param);
1621 }
1622
1623 param = os_strstr(pos, " frame=");
1624 if (param == NULL)
1625 return -1;
1626 param += 7;
1627
1628 len = os_strlen(param);
1629 if (len & 1)
1630 return -1;
1631 len /= 2;
1632
1633 buf = os_malloc(len);
1634 if (buf == NULL)
1635 return -1;
1636
1637 if (hexstr2bin(param, buf, len) < 0) {
1638 os_free(buf);
1639 return -1;
1640 }
1641
1642 os_memset(&event, 0, sizeof(event));
1643 event.rx_mgmt.freq = freq;
1644 event.rx_mgmt.frame = buf;
1645 event.rx_mgmt.frame_len = len;
1646 event.rx_mgmt.ssi_signal = ssi_signal;
1647 event.rx_mgmt.datarate = datarate;
1648 hapd->ext_mgmt_frame_handling = 0;
1649 wpa_supplicant_event(hapd, EVENT_RX_MGMT, &event);
1650 hapd->ext_mgmt_frame_handling = 1;
1651
1652 os_free(buf);
1653
1654 return 0;
1655}
1656
1657
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001658static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data *hapd, char *cmd)
1659{
1660 char *pos;
1661 u8 src[ETH_ALEN], *buf;
1662 int used;
1663 size_t len;
1664
1665 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
1666
1667 pos = cmd;
1668 used = hwaddr_aton2(pos, src);
1669 if (used < 0)
1670 return -1;
1671 pos += used;
1672 while (*pos == ' ')
1673 pos++;
1674
1675 len = os_strlen(pos);
1676 if (len & 1)
1677 return -1;
1678 len /= 2;
1679
1680 buf = os_malloc(len);
1681 if (buf == NULL)
1682 return -1;
1683
1684 if (hexstr2bin(pos, buf, len) < 0) {
1685 os_free(buf);
1686 return -1;
1687 }
1688
1689 ieee802_1x_receive(hapd, src, buf, len);
1690 os_free(buf);
1691
1692 return 0;
1693}
1694
1695
Hai Shaloma20dcd72022-02-04 13:43:00 -08001696static int hostapd_ctrl_iface_eapol_tx(struct hostapd_data *hapd, char *cmd)
1697{
1698 char *pos, *pos2;
1699 u8 dst[ETH_ALEN], *buf;
1700 int used, ret;
1701 size_t len;
1702 unsigned int prev;
1703 int encrypt = 0;
1704
1705 wpa_printf(MSG_DEBUG, "External EAPOL TX: %s", cmd);
1706
1707 pos = cmd;
1708 used = hwaddr_aton2(pos, dst);
1709 if (used < 0)
1710 return -1;
1711 pos += used;
1712 while (*pos == ' ')
1713 pos++;
1714
1715 pos2 = os_strchr(pos, ' ');
1716 if (pos2) {
1717 len = pos2 - pos;
1718 encrypt = os_strstr(pos2, "encrypt=1") != NULL;
1719 } else {
1720 len = os_strlen(pos);
1721 }
1722 if (len & 1)
1723 return -1;
1724 len /= 2;
1725
1726 buf = os_malloc(len);
1727 if (!buf || hexstr2bin(pos, buf, len) < 0) {
1728 os_free(buf);
1729 return -1;
1730 }
1731
1732 prev = hapd->ext_eapol_frame_io;
1733 hapd->ext_eapol_frame_io = 0;
1734 ret = hostapd_wpa_auth_send_eapol(hapd, dst, buf, len, encrypt);
1735 hapd->ext_eapol_frame_io = prev;
1736 os_free(buf);
1737
1738 return ret;
1739}
1740
1741
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001742static u16 ipv4_hdr_checksum(const void *buf, size_t len)
1743{
1744 size_t i;
1745 u32 sum = 0;
1746 const u16 *pos = buf;
1747
1748 for (i = 0; i < len / 2; i++)
1749 sum += *pos++;
1750
1751 while (sum >> 16)
1752 sum = (sum & 0xffff) + (sum >> 16);
1753
1754 return sum ^ 0xffff;
1755}
1756
1757
1758#define HWSIM_PACKETLEN 1500
1759#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1760
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07001761static void hostapd_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
1762 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001763{
1764 struct hostapd_data *hapd = ctx;
1765 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07001766 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001767 const u8 *pos;
1768 unsigned int i;
Hai Shalom81f62d82019-07-22 12:10:00 -07001769 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001770
Hai Shalom81f62d82019-07-22 12:10:00 -07001771 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
1772 wpa_printf(MSG_DEBUG,
1773 "test data: RX - ignore unexpected length %d",
1774 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001775 return;
Hai Shalom81f62d82019-07-22 12:10:00 -07001776 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001777
1778 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001779 os_memcpy(&ip, eth + 1, sizeof(ip));
1780 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001781
Hai Shalomfdcde762020-04-02 11:19:20 -07001782 if (ip.ip_hl != 5 || ip.ip_v != 4 ||
1783 ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001784 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07001785 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001786 return;
Hai Shalom81f62d82019-07-22 12:10:00 -07001787 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001788
Hai Shalomfdcde762020-04-02 11:19:20 -07001789 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001790 if (*pos != (u8) i) {
1791 wpa_printf(MSG_DEBUG,
1792 "test data: RX - ignore mismatching payload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001793 return;
Hai Shalom81f62d82019-07-22 12:10:00 -07001794 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001795 pos++;
1796 }
1797
Hai Shalom81f62d82019-07-22 12:10:00 -07001798 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07001799 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
1800 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom81f62d82019-07-22 12:10:00 -07001801 wpa_msg(hapd->msg_ctx, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
1802 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001803}
1804
1805
1806static int hostapd_ctrl_iface_data_test_config(struct hostapd_data *hapd,
1807 char *cmd)
1808{
1809 int enabled = atoi(cmd);
1810 char *pos;
1811 const char *ifname;
1812
1813 if (!enabled) {
1814 if (hapd->l2_test) {
1815 l2_packet_deinit(hapd->l2_test);
1816 hapd->l2_test = NULL;
1817 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1818 "test data: Disabled");
1819 }
1820 return 0;
1821 }
1822
1823 if (hapd->l2_test)
1824 return 0;
1825
1826 pos = os_strstr(cmd, " ifname=");
1827 if (pos)
1828 ifname = pos + 8;
1829 else
1830 ifname = hapd->conf->iface;
1831
1832 hapd->l2_test = l2_packet_init(ifname, hapd->own_addr,
1833 ETHERTYPE_IP, hostapd_data_test_rx,
1834 hapd, 1);
1835 if (hapd->l2_test == NULL)
1836 return -1;
1837
1838 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: Enabled");
1839
1840 return 0;
1841}
1842
1843
1844static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data *hapd, char *cmd)
1845{
1846 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom81f62d82019-07-22 12:10:00 -07001847 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001848 int used;
1849 long int val;
1850 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001851 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001852 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07001853 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001854 u8 *dpos;
1855 unsigned int i;
Hai Shalom81f62d82019-07-22 12:10:00 -07001856 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001857
1858 if (hapd->l2_test == NULL)
1859 return -1;
1860
Hai Shalom81f62d82019-07-22 12:10:00 -07001861 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001862
1863 pos = cmd;
1864 used = hwaddr_aton2(pos, dst);
1865 if (used < 0)
1866 return -1;
1867 pos += used;
1868 while (*pos == ' ')
1869 pos++;
1870 used = hwaddr_aton2(pos, src);
1871 if (used < 0)
1872 return -1;
1873 pos += used;
1874
Hai Shalom81f62d82019-07-22 12:10:00 -07001875 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001876 if (val < 0 || val > 0xff)
1877 return -1;
1878 tos = val;
1879
Hai Shalom81f62d82019-07-22 12:10:00 -07001880 pos = os_strstr(pos2, " len=");
1881 if (pos) {
1882 i = atoi(pos + 5);
1883 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
1884 return -1;
1885 send_len = i;
1886 }
1887
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001888 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001889 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
1890 os_memcpy(eth->ether_shost, src, ETH_ALEN);
1891 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -07001892 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001893 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -07001894 ip->ip_hl = 5;
1895 ip->ip_v = 4;
1896 ip->ip_ttl = 64;
1897 ip->ip_tos = tos;
1898 ip->ip_len = htons(send_len);
1899 ip->ip_p = 1;
1900 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
1901 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
1902 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001903 dpos = (u8 *) (ip + 1);
Hai Shalom81f62d82019-07-22 12:10:00 -07001904 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001905 *dpos++ = i;
1906
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001907 if (l2_packet_send(hapd->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom81f62d82019-07-22 12:10:00 -07001908 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001909 return -1;
1910
1911 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: TX dst=" MACSTR
1912 " src=" MACSTR " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
1913
1914 return 0;
1915}
1916
1917
1918static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data *hapd,
1919 char *cmd)
1920{
1921 u8 *buf;
1922 struct ether_header *eth;
1923 struct l2_packet_data *l2 = NULL;
1924 size_t len;
1925 u16 ethertype;
1926 int res = -1;
1927 const char *ifname = hapd->conf->iface;
1928
1929 if (os_strncmp(cmd, "ifname=", 7) == 0) {
1930 cmd += 7;
1931 ifname = cmd;
1932 cmd = os_strchr(cmd, ' ');
1933 if (cmd == NULL)
1934 return -1;
1935 *cmd++ = '\0';
1936 }
1937
1938 len = os_strlen(cmd);
1939 if (len & 1 || len < ETH_HLEN * 2)
1940 return -1;
1941 len /= 2;
1942
1943 buf = os_malloc(len);
1944 if (buf == NULL)
1945 return -1;
1946
1947 if (hexstr2bin(cmd, buf, len) < 0)
1948 goto done;
1949
1950 eth = (struct ether_header *) buf;
1951 ethertype = ntohs(eth->ether_type);
1952
1953 l2 = l2_packet_init(ifname, hapd->own_addr, ethertype,
1954 hostapd_data_test_rx, hapd, 1);
1955 if (l2 == NULL)
1956 goto done;
1957
1958 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
1959 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: TX frame res=%d", res);
1960done:
1961 if (l2)
1962 l2_packet_deinit(l2);
1963 os_free(buf);
1964
1965 return res < 0 ? -1 : 0;
1966}
1967
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001968
1969static int hostapd_ctrl_test_alloc_fail(struct hostapd_data *hapd, char *cmd)
1970{
1971#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001972 char *pos;
1973
1974 wpa_trace_fail_after = atoi(cmd);
1975 pos = os_strchr(cmd, ':');
1976 if (pos) {
1977 pos++;
1978 os_strlcpy(wpa_trace_fail_func, pos,
1979 sizeof(wpa_trace_fail_func));
1980 } else {
1981 wpa_trace_fail_after = 0;
1982 }
1983
1984 return 0;
1985#else /* WPA_TRACE_BFD */
1986 return -1;
1987#endif /* WPA_TRACE_BFD */
1988}
1989
1990
1991static int hostapd_ctrl_get_alloc_fail(struct hostapd_data *hapd,
1992 char *buf, size_t buflen)
1993{
1994#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001995 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
1996 wpa_trace_fail_func);
1997#else /* WPA_TRACE_BFD */
1998 return -1;
1999#endif /* WPA_TRACE_BFD */
2000}
2001
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002002
2003static int hostapd_ctrl_test_fail(struct hostapd_data *hapd, char *cmd)
2004{
2005#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002006 char *pos;
2007
2008 wpa_trace_test_fail_after = atoi(cmd);
2009 pos = os_strchr(cmd, ':');
2010 if (pos) {
2011 pos++;
2012 os_strlcpy(wpa_trace_test_fail_func, pos,
2013 sizeof(wpa_trace_test_fail_func));
2014 } else {
2015 wpa_trace_test_fail_after = 0;
2016 }
2017
2018 return 0;
2019#else /* WPA_TRACE_BFD */
2020 return -1;
2021#endif /* WPA_TRACE_BFD */
2022}
2023
2024
2025static int hostapd_ctrl_get_fail(struct hostapd_data *hapd,
2026 char *buf, size_t buflen)
2027{
2028#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002029 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
2030 wpa_trace_test_fail_func);
2031#else /* WPA_TRACE_BFD */
2032 return -1;
2033#endif /* WPA_TRACE_BFD */
2034}
2035
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002036
2037static int hostapd_ctrl_reset_pn(struct hostapd_data *hapd, const char *cmd)
2038{
2039 struct sta_info *sta;
2040 u8 addr[ETH_ALEN];
2041 u8 zero[WPA_TK_MAX_LEN];
2042
2043 os_memset(zero, 0, sizeof(zero));
2044
2045 if (hwaddr_aton(cmd, addr))
2046 return -1;
2047
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002048 if (is_broadcast_ether_addr(addr) && os_strstr(cmd, " BIGTK")) {
2049 if (hapd->last_bigtk_alg == WPA_ALG_NONE)
2050 return -1;
2051
2052 wpa_printf(MSG_INFO, "TESTING: Reset BIPN for BIGTK");
2053
2054 /* First, use a zero key to avoid any possible duplicate key
2055 * avoidance in the driver. */
2056 if (hostapd_drv_set_key(hapd->conf->iface, hapd,
2057 hapd->last_bigtk_alg,
2058 broadcast_ether_addr,
2059 hapd->last_bigtk_key_idx, 0, 1, NULL, 0,
2060 zero, hapd->last_bigtk_len,
2061 KEY_FLAG_GROUP_TX_DEFAULT) < 0)
2062 return -1;
2063
2064 /* Set the previously configured key to reset its TSC */
2065 return hostapd_drv_set_key(hapd->conf->iface, hapd,
2066 hapd->last_bigtk_alg,
2067 broadcast_ether_addr,
2068 hapd->last_bigtk_key_idx, 0, 1, NULL,
2069 0, hapd->last_bigtk,
2070 hapd->last_bigtk_len,
2071 KEY_FLAG_GROUP_TX_DEFAULT);
2072 }
2073
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002074 if (is_broadcast_ether_addr(addr) && os_strstr(cmd, "IGTK")) {
2075 if (hapd->last_igtk_alg == WPA_ALG_NONE)
2076 return -1;
2077
2078 wpa_printf(MSG_INFO, "TESTING: Reset IPN for IGTK");
2079
2080 /* First, use a zero key to avoid any possible duplicate key
2081 * avoidance in the driver. */
2082 if (hostapd_drv_set_key(hapd->conf->iface, hapd,
2083 hapd->last_igtk_alg,
2084 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002085 hapd->last_igtk_key_idx, 0, 1, NULL, 0,
2086 zero, hapd->last_igtk_len,
2087 KEY_FLAG_GROUP_TX_DEFAULT) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002088 return -1;
2089
2090 /* Set the previously configured key to reset its TSC */
2091 return hostapd_drv_set_key(hapd->conf->iface, hapd,
2092 hapd->last_igtk_alg,
2093 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002094 hapd->last_igtk_key_idx, 0, 1, NULL,
2095 0, hapd->last_igtk,
2096 hapd->last_igtk_len,
2097 KEY_FLAG_GROUP_TX_DEFAULT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002098 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002099
2100 if (is_broadcast_ether_addr(addr)) {
2101 if (hapd->last_gtk_alg == WPA_ALG_NONE)
2102 return -1;
2103
2104 wpa_printf(MSG_INFO, "TESTING: Reset PN for GTK");
2105
2106 /* First, use a zero key to avoid any possible duplicate key
2107 * avoidance in the driver. */
2108 if (hostapd_drv_set_key(hapd->conf->iface, hapd,
2109 hapd->last_gtk_alg,
2110 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002111 hapd->last_gtk_key_idx, 0, 1, NULL, 0,
2112 zero, hapd->last_gtk_len,
2113 KEY_FLAG_GROUP_TX_DEFAULT) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002114 return -1;
2115
2116 /* Set the previously configured key to reset its TSC */
2117 return hostapd_drv_set_key(hapd->conf->iface, hapd,
2118 hapd->last_gtk_alg,
2119 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002120 hapd->last_gtk_key_idx, 0, 1, NULL,
2121 0, hapd->last_gtk,
2122 hapd->last_gtk_len,
2123 KEY_FLAG_GROUP_TX_DEFAULT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002124 }
2125
2126 sta = ap_get_sta(hapd, addr);
2127 if (!sta)
2128 return -1;
2129
2130 if (sta->last_tk_alg == WPA_ALG_NONE)
2131 return -1;
2132
2133 wpa_printf(MSG_INFO, "TESTING: Reset PN for " MACSTR,
2134 MAC2STR(sta->addr));
2135
2136 /* First, use a zero key to avoid any possible duplicate key avoidance
2137 * in the driver. */
2138 if (hostapd_drv_set_key(hapd->conf->iface, hapd, sta->last_tk_alg,
Hai Shalomfdcde762020-04-02 11:19:20 -07002139 sta->addr, sta->last_tk_key_idx, 0, 1, NULL, 0,
2140 zero, sta->last_tk_len,
2141 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002142 return -1;
2143
2144 /* Set the previously configured key to reset its TSC/RSC */
2145 return hostapd_drv_set_key(hapd->conf->iface, hapd, sta->last_tk_alg,
Hai Shalomfdcde762020-04-02 11:19:20 -07002146 sta->addr, sta->last_tk_key_idx, 0, 1, NULL,
2147 0, sta->last_tk, sta->last_tk_len,
2148 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002149}
2150
2151
2152static int hostapd_ctrl_set_key(struct hostapd_data *hapd, const char *cmd)
2153{
2154 u8 addr[ETH_ALEN];
2155 const char *pos = cmd;
2156 enum wpa_alg alg;
Hai Shalomfdcde762020-04-02 11:19:20 -07002157 enum key_flag key_flag;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002158 int idx, set_tx;
2159 u8 seq[6], key[WPA_TK_MAX_LEN];
2160 size_t key_len;
2161
Hai Shalomfdcde762020-04-02 11:19:20 -07002162 /* parameters: alg addr idx set_tx seq key key_flag */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002163
2164 alg = atoi(pos);
2165 pos = os_strchr(pos, ' ');
2166 if (!pos)
2167 return -1;
2168 pos++;
2169 if (hwaddr_aton(pos, addr))
2170 return -1;
2171 pos += 17;
2172 if (*pos != ' ')
2173 return -1;
2174 pos++;
2175 idx = atoi(pos);
2176 pos = os_strchr(pos, ' ');
2177 if (!pos)
2178 return -1;
2179 pos++;
2180 set_tx = atoi(pos);
2181 pos = os_strchr(pos, ' ');
2182 if (!pos)
2183 return -1;
2184 pos++;
Hai Shalom74f70d42019-02-11 14:42:39 -08002185 if (hexstr2bin(pos, seq, sizeof(seq)) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002186 return -1;
2187 pos += 2 * 6;
2188 if (*pos != ' ')
2189 return -1;
2190 pos++;
Hai Shalomfdcde762020-04-02 11:19:20 -07002191 if (!os_strchr(pos, ' '))
2192 return -1;
2193 key_len = (os_strchr(pos, ' ') - pos) / 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002194 if (hexstr2bin(pos, key, key_len) < 0)
2195 return -1;
Hai Shalomfdcde762020-04-02 11:19:20 -07002196 pos += 2 * key_len;
2197 if (*pos != ' ')
2198 return -1;
2199
2200 pos++;
2201 key_flag = atoi(pos);
2202 pos = os_strchr(pos, ' ');
2203 if (pos)
2204 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002205
2206 wpa_printf(MSG_INFO, "TESTING: Set key");
Hai Shalomfdcde762020-04-02 11:19:20 -07002207 return hostapd_drv_set_key(hapd->conf->iface, hapd, alg, addr, idx, 0,
2208 set_tx, seq, 6, key, key_len, key_flag);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002209}
2210
2211
2212static void restore_tk(void *ctx1, void *ctx2)
2213{
2214 struct hostapd_data *hapd = ctx1;
2215 struct sta_info *sta = ctx2;
2216
2217 wpa_printf(MSG_INFO, "TESTING: Restore TK for " MACSTR,
2218 MAC2STR(sta->addr));
2219 /* This does not really restore the TSC properly, so this will result
2220 * in replay protection issues for now since there is no clean way of
2221 * preventing encryption of a single EAPOL frame. */
2222 hostapd_drv_set_key(hapd->conf->iface, hapd, sta->last_tk_alg,
Hai Shalomfdcde762020-04-02 11:19:20 -07002223 sta->addr, sta->last_tk_key_idx, 0, 1, NULL, 0,
2224 sta->last_tk, sta->last_tk_len,
2225 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002226}
2227
2228
2229static int hostapd_ctrl_resend_m1(struct hostapd_data *hapd, const char *cmd)
2230{
2231 struct sta_info *sta;
2232 u8 addr[ETH_ALEN];
2233 int plain = os_strstr(cmd, "plaintext") != NULL;
2234
2235 if (hwaddr_aton(cmd, addr))
2236 return -1;
2237
2238 sta = ap_get_sta(hapd, addr);
2239 if (!sta || !sta->wpa_sm)
2240 return -1;
2241
2242 if (plain && sta->last_tk_alg == WPA_ALG_NONE)
2243 plain = 0; /* no need for special processing */
2244 if (plain) {
2245 wpa_printf(MSG_INFO, "TESTING: Clear TK for " MACSTR,
2246 MAC2STR(sta->addr));
2247 hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
Hai Shalomfdcde762020-04-02 11:19:20 -07002248 sta->addr, sta->last_tk_key_idx, 0, 0, NULL,
2249 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002250 }
2251
2252 wpa_printf(MSG_INFO, "TESTING: Send M1 to " MACSTR, MAC2STR(sta->addr));
2253 return wpa_auth_resend_m1(sta->wpa_sm,
2254 os_strstr(cmd, "change-anonce") != NULL,
2255 plain ? restore_tk : NULL, hapd, sta);
2256}
2257
2258
2259static int hostapd_ctrl_resend_m3(struct hostapd_data *hapd, const char *cmd)
2260{
2261 struct sta_info *sta;
2262 u8 addr[ETH_ALEN];
2263 int plain = os_strstr(cmd, "plaintext") != NULL;
2264
2265 if (hwaddr_aton(cmd, addr))
2266 return -1;
2267
2268 sta = ap_get_sta(hapd, addr);
2269 if (!sta || !sta->wpa_sm)
2270 return -1;
2271
2272 if (plain && sta->last_tk_alg == WPA_ALG_NONE)
2273 plain = 0; /* no need for special processing */
2274 if (plain) {
2275 wpa_printf(MSG_INFO, "TESTING: Clear TK for " MACSTR,
2276 MAC2STR(sta->addr));
2277 hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
Hai Shalomfdcde762020-04-02 11:19:20 -07002278 sta->addr, sta->last_tk_key_idx, 0, 0, NULL,
2279 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002280 }
2281
2282 wpa_printf(MSG_INFO, "TESTING: Send M3 to " MACSTR, MAC2STR(sta->addr));
2283 return wpa_auth_resend_m3(sta->wpa_sm,
2284 plain ? restore_tk : NULL, hapd, sta);
2285}
2286
2287
2288static int hostapd_ctrl_resend_group_m1(struct hostapd_data *hapd,
2289 const char *cmd)
2290{
2291 struct sta_info *sta;
2292 u8 addr[ETH_ALEN];
2293 int plain = os_strstr(cmd, "plaintext") != NULL;
2294
2295 if (hwaddr_aton(cmd, addr))
2296 return -1;
2297
2298 sta = ap_get_sta(hapd, addr);
2299 if (!sta || !sta->wpa_sm)
2300 return -1;
2301
2302 if (plain && sta->last_tk_alg == WPA_ALG_NONE)
2303 plain = 0; /* no need for special processing */
2304 if (plain) {
2305 wpa_printf(MSG_INFO, "TESTING: Clear TK for " MACSTR,
2306 MAC2STR(sta->addr));
2307 hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
Hai Shalomfdcde762020-04-02 11:19:20 -07002308 sta->addr, sta->last_tk_key_idx, 0, 0, NULL,
2309 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002310 }
2311
2312 wpa_printf(MSG_INFO,
2313 "TESTING: Send group M1 for the same GTK and zero RSC to "
2314 MACSTR, MAC2STR(sta->addr));
2315 return wpa_auth_resend_group_m1(sta->wpa_sm,
2316 plain ? restore_tk : NULL, hapd, sta);
2317}
2318
Hai Shalomfdcde762020-04-02 11:19:20 -07002319
Hai Shaloma20dcd72022-02-04 13:43:00 -08002320static int hostapd_ctrl_rekey_ptk(struct hostapd_data *hapd, const char *cmd)
2321{
2322 struct sta_info *sta;
2323 u8 addr[ETH_ALEN];
2324
2325 if (hwaddr_aton(cmd, addr))
2326 return -1;
2327
2328 sta = ap_get_sta(hapd, addr);
2329 if (!sta || !sta->wpa_sm)
2330 return -1;
2331
2332 return wpa_auth_rekey_ptk(hapd->wpa_auth, sta->wpa_sm);
2333}
2334
2335
Hai Shalom899fcc72020-10-19 14:38:18 -07002336static int hostapd_ctrl_get_pmksa_pmk(struct hostapd_data *hapd, const u8 *addr,
2337 char *buf, size_t buflen)
2338{
2339 struct rsn_pmksa_cache_entry *pmksa;
2340
2341 pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, addr, NULL);
2342 if (!pmksa)
2343 return -1;
2344
2345 return wpa_snprintf_hex(buf, buflen, pmksa->pmk, pmksa->pmk_len);
2346}
2347
2348
Hai Shalomfdcde762020-04-02 11:19:20 -07002349static int hostapd_ctrl_get_pmk(struct hostapd_data *hapd, const char *cmd,
2350 char *buf, size_t buflen)
2351{
2352 struct sta_info *sta;
2353 u8 addr[ETH_ALEN];
2354 const u8 *pmk;
2355 int pmk_len;
2356
2357 if (hwaddr_aton(cmd, addr))
2358 return -1;
2359
2360 sta = ap_get_sta(hapd, addr);
2361 if (!sta || !sta->wpa_sm) {
2362 wpa_printf(MSG_DEBUG, "No STA WPA state machine for " MACSTR,
2363 MAC2STR(addr));
Hai Shalom899fcc72020-10-19 14:38:18 -07002364 return hostapd_ctrl_get_pmksa_pmk(hapd, addr, buf, buflen);
Hai Shalomfdcde762020-04-02 11:19:20 -07002365 }
2366 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
Hai Shalom899fcc72020-10-19 14:38:18 -07002367 if (!pmk || !pmk_len) {
Hai Shalomfdcde762020-04-02 11:19:20 -07002368 wpa_printf(MSG_DEBUG, "No PMK stored for " MACSTR,
2369 MAC2STR(addr));
Hai Shalom899fcc72020-10-19 14:38:18 -07002370 return hostapd_ctrl_get_pmksa_pmk(hapd, addr, buf, buflen);
Hai Shalomfdcde762020-04-02 11:19:20 -07002371 }
2372
2373 return wpa_snprintf_hex(buf, buflen, pmk, pmk_len);
2374}
2375
Hai Shaloma20dcd72022-02-04 13:43:00 -08002376
2377static int hostapd_ctrl_register_frame(struct hostapd_data *hapd,
2378 const char *cmd)
2379{
2380 u16 type;
2381 char *pos, *end;
2382 u8 match[10];
2383 size_t match_len;
2384 bool multicast = false;
2385
2386 type = strtol(cmd, &pos, 16);
2387 if (*pos != ' ')
2388 return -1;
2389 pos++;
2390 end = os_strchr(pos, ' ');
2391 if (end) {
2392 match_len = end - pos;
2393 multicast = os_strstr(end, "multicast") != NULL;
2394 } else {
2395 match_len = os_strlen(pos) / 2;
2396 }
2397 if (hexstr2bin(pos, match, match_len))
2398 return -1;
2399
2400 return hostapd_drv_register_frame(hapd, type, match, match_len,
2401 multicast);
2402}
2403
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002404#endif /* CONFIG_TESTING_OPTIONS */
2405
2406
Hai Shalomb755a2a2020-04-23 21:49:02 -07002407#ifdef NEED_AP_MLME
Hai Shalomfdcde762020-04-02 11:19:20 -07002408static int hostapd_ctrl_check_freq_params(struct hostapd_freq_params *params)
2409{
2410 switch (params->bandwidth) {
2411 case 0:
2412 /* bandwidth not specified: use 20 MHz by default */
2413 /* fall-through */
2414 case 20:
2415 if (params->center_freq1 &&
2416 params->center_freq1 != params->freq)
2417 return -1;
2418
2419 if (params->center_freq2 || params->sec_channel_offset)
2420 return -1;
2421 break;
2422 case 40:
2423 if (params->center_freq2 || !params->sec_channel_offset)
2424 return -1;
2425
2426 if (!params->center_freq1)
2427 break;
2428 switch (params->sec_channel_offset) {
2429 case 1:
2430 if (params->freq + 10 != params->center_freq1)
2431 return -1;
2432 break;
2433 case -1:
2434 if (params->freq - 10 != params->center_freq1)
2435 return -1;
2436 break;
2437 default:
2438 return -1;
2439 }
2440 break;
2441 case 80:
2442 if (!params->center_freq1 || !params->sec_channel_offset)
2443 return 1;
2444
2445 switch (params->sec_channel_offset) {
2446 case 1:
2447 if (params->freq - 10 != params->center_freq1 &&
2448 params->freq + 30 != params->center_freq1)
2449 return 1;
2450 break;
2451 case -1:
2452 if (params->freq + 10 != params->center_freq1 &&
2453 params->freq - 30 != params->center_freq1)
2454 return -1;
2455 break;
2456 default:
2457 return -1;
2458 }
2459
2460 /* Adjacent and overlapped are not allowed for 80+80 */
2461 if (params->center_freq2 &&
2462 params->center_freq1 - params->center_freq2 <= 80 &&
2463 params->center_freq2 - params->center_freq1 <= 80)
2464 return 1;
2465 break;
2466 case 160:
2467 if (!params->center_freq1 || params->center_freq2 ||
2468 !params->sec_channel_offset)
2469 return -1;
2470
2471 switch (params->sec_channel_offset) {
2472 case 1:
2473 if (params->freq + 70 != params->center_freq1 &&
2474 params->freq + 30 != params->center_freq1 &&
2475 params->freq - 10 != params->center_freq1 &&
2476 params->freq - 50 != params->center_freq1)
2477 return -1;
2478 break;
2479 case -1:
2480 if (params->freq + 50 != params->center_freq1 &&
2481 params->freq + 10 != params->center_freq1 &&
2482 params->freq - 30 != params->center_freq1 &&
2483 params->freq - 70 != params->center_freq1)
2484 return -1;
2485 break;
2486 default:
2487 return -1;
2488 }
2489 break;
2490 default:
2491 return -1;
2492 }
2493
2494 return 0;
2495}
Hai Shalomb755a2a2020-04-23 21:49:02 -07002496#endif /* NEED_AP_MLME */
Hai Shalomfdcde762020-04-02 11:19:20 -07002497
2498
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002499static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface *iface,
2500 char *pos)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002501{
2502#ifdef NEED_AP_MLME
2503 struct csa_settings settings;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002504 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -07002505 int dfs_range = 0;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002506 unsigned int i;
Hai Shalomfdcde762020-04-02 11:19:20 -07002507 int bandwidth;
2508 u8 chan;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002509
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002510 ret = hostapd_parse_csa_settings(pos, &settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002511 if (ret)
2512 return ret;
2513
Hai Shalomfdcde762020-04-02 11:19:20 -07002514 ret = hostapd_ctrl_check_freq_params(&settings.freq_params);
2515 if (ret) {
2516 wpa_printf(MSG_INFO,
2517 "chanswitch: invalid frequency settings provided");
2518 return ret;
2519 }
2520
2521 switch (settings.freq_params.bandwidth) {
2522 case 40:
2523 bandwidth = CHAN_WIDTH_40;
2524 break;
2525 case 80:
2526 if (settings.freq_params.center_freq2)
2527 bandwidth = CHAN_WIDTH_80P80;
2528 else
2529 bandwidth = CHAN_WIDTH_80;
2530 break;
2531 case 160:
2532 bandwidth = CHAN_WIDTH_160;
2533 break;
2534 default:
2535 bandwidth = CHAN_WIDTH_20;
2536 break;
2537 }
2538
2539 if (settings.freq_params.center_freq1)
2540 dfs_range += hostapd_is_dfs_overlap(
2541 iface, bandwidth, settings.freq_params.center_freq1);
2542 else
2543 dfs_range += hostapd_is_dfs_overlap(
2544 iface, bandwidth, settings.freq_params.freq);
2545
2546 if (settings.freq_params.center_freq2)
2547 dfs_range += hostapd_is_dfs_overlap(
2548 iface, bandwidth, settings.freq_params.center_freq2);
2549
2550 if (dfs_range) {
2551 ret = ieee80211_freq_to_chan(settings.freq_params.freq, &chan);
2552 if (ret == NUM_HOSTAPD_MODES) {
2553 wpa_printf(MSG_ERROR,
2554 "Failed to get channel for (freq=%d, sec_channel_offset=%d, bw=%d)",
2555 settings.freq_params.freq,
2556 settings.freq_params.sec_channel_offset,
2557 settings.freq_params.bandwidth);
2558 return -1;
2559 }
2560
2561 settings.freq_params.channel = chan;
2562
2563 wpa_printf(MSG_DEBUG,
2564 "DFS/CAC to (channel=%u, freq=%d, sec_channel_offset=%d, bw=%d, center_freq1=%d)",
2565 settings.freq_params.channel,
2566 settings.freq_params.freq,
2567 settings.freq_params.sec_channel_offset,
2568 settings.freq_params.bandwidth,
2569 settings.freq_params.center_freq1);
2570
2571 /* Perform CAC and switch channel */
2572 hostapd_switch_channel_fallback(iface, &settings.freq_params);
2573 return 0;
2574 }
2575
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002576 for (i = 0; i < iface->num_bss; i++) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002577
Sunil Ravia04bd252022-05-02 22:54:18 -07002578 /* Save CHAN_SWITCH VHT, HE, and EHT config */
Hai Shalom60840252021-02-19 19:02:11 -08002579 hostapd_chan_switch_config(iface->bss[i],
2580 &settings.freq_params);
Roshan Pius3a1667e2018-07-03 15:17:14 -07002581
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002582 ret = hostapd_switch_channel(iface->bss[i], &settings);
2583 if (ret) {
2584 /* FIX: What do we do if CSA fails in the middle of
2585 * submitting multi-BSS CSA requests? */
2586 return ret;
2587 }
2588 }
2589
2590 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002591#else /* NEED_AP_MLME */
2592 return -1;
2593#endif /* NEED_AP_MLME */
2594}
2595
2596
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002597static int hostapd_ctrl_iface_mib(struct hostapd_data *hapd, char *reply,
2598 int reply_size, const char *param)
2599{
2600#ifdef RADIUS_SERVER
2601 if (os_strcmp(param, "radius_server") == 0) {
2602 return radius_server_get_mib(hapd->radius_srv, reply,
2603 reply_size);
2604 }
2605#endif /* RADIUS_SERVER */
2606 return -1;
2607}
2608
2609
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002610static int hostapd_ctrl_iface_vendor(struct hostapd_data *hapd, char *cmd,
2611 char *buf, size_t buflen)
2612{
2613 int ret;
Hai Shalom60840252021-02-19 19:02:11 -08002614 char *pos, *temp = NULL;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002615 u8 *data = NULL;
2616 unsigned int vendor_id, subcmd;
Hai Shalom60840252021-02-19 19:02:11 -08002617 enum nested_attr nested_attr_flag = NESTED_ATTR_UNSPECIFIED;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002618 struct wpabuf *reply;
2619 size_t data_len = 0;
2620
Hai Shalom60840252021-02-19 19:02:11 -08002621 /**
2622 * cmd: <vendor id> <subcommand id> [<hex formatted data>]
2623 * [nested=<0|1>]
2624 */
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002625 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002626 if (!isblank((unsigned char) *pos))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002627 return -EINVAL;
2628
2629 subcmd = strtoul(pos, &pos, 10);
2630
2631 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002632 if (!isblank((unsigned char) *pos++))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002633 return -EINVAL;
Hai Shalom60840252021-02-19 19:02:11 -08002634
2635 temp = os_strchr(pos, ' ');
2636 data_len = temp ? (size_t) (temp - pos) : os_strlen(pos);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002637 }
2638
2639 if (data_len) {
2640 data_len /= 2;
2641 data = os_malloc(data_len);
2642 if (!data)
2643 return -ENOBUFS;
2644
2645 if (hexstr2bin(pos, data, data_len)) {
2646 wpa_printf(MSG_DEBUG,
2647 "Vendor command: wrong parameter format");
2648 os_free(data);
2649 return -EINVAL;
2650 }
2651 }
2652
Hai Shalom60840252021-02-19 19:02:11 -08002653 pos = os_strstr(cmd, "nested=");
2654 if (pos)
2655 nested_attr_flag = atoi(pos + 7) ? NESTED_ATTR_USED :
2656 NESTED_ATTR_NOT_USED;
2657
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002658 reply = wpabuf_alloc((buflen - 1) / 2);
2659 if (!reply) {
2660 os_free(data);
2661 return -ENOBUFS;
2662 }
2663
2664 ret = hostapd_drv_vendor_cmd(hapd, vendor_id, subcmd, data, data_len,
Hai Shalom60840252021-02-19 19:02:11 -08002665 nested_attr_flag, reply);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002666
2667 if (ret == 0)
2668 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
2669 wpabuf_len(reply));
2670
2671 wpabuf_free(reply);
2672 os_free(data);
2673
2674 return ret;
2675}
2676
2677
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002678static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data *hapd,
2679 const char *cmd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002680{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002681 u8 addr[ETH_ALEN];
2682 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002683
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002684 if (hwaddr_aton(cmd, addr))
2685 return -1;
2686
2687 sta = ap_get_sta(hapd, addr);
2688 if (!sta || !sta->eapol_sm)
2689 return -1;
2690
2691 eapol_auth_reauthenticate(sta->eapol_sm);
2692 return 0;
2693}
2694
2695
2696static int hostapd_ctrl_iface_eapol_set(struct hostapd_data *hapd, char *cmd)
2697{
2698 u8 addr[ETH_ALEN];
2699 struct sta_info *sta;
2700 char *pos = cmd, *param;
2701
2702 if (hwaddr_aton(pos, addr) || pos[17] != ' ')
2703 return -1;
2704 pos += 18;
2705 param = pos;
2706 pos = os_strchr(pos, ' ');
2707 if (!pos)
2708 return -1;
2709 *pos++ = '\0';
2710
2711 sta = ap_get_sta(hapd, addr);
2712 if (!sta || !sta->eapol_sm)
2713 return -1;
2714
2715 return eapol_auth_set_conf(sta->eapol_sm, param, pos);
2716}
2717
2718
2719static int hostapd_ctrl_iface_log_level(struct hostapd_data *hapd, char *cmd,
2720 char *buf, size_t buflen)
2721{
2722 char *pos, *end, *stamp;
2723 int ret;
2724
2725 /* cmd: "LOG_LEVEL [<level>]" */
2726 if (*cmd == '\0') {
2727 pos = buf;
2728 end = buf + buflen;
2729 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2730 "Timestamp: %d\n",
2731 debug_level_str(wpa_debug_level),
2732 wpa_debug_timestamp);
2733 if (os_snprintf_error(end - pos, ret))
2734 ret = 0;
2735
2736 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002737 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002738
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002739 while (*cmd == ' ')
2740 cmd++;
2741
2742 stamp = os_strchr(cmd, ' ');
2743 if (stamp) {
2744 *stamp++ = '\0';
2745 while (*stamp == ' ') {
2746 stamp++;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002747 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002748 }
2749
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002750 if (os_strlen(cmd)) {
2751 int level = str_to_debug_level(cmd);
2752 if (level < 0)
2753 return -1;
2754 wpa_debug_level = level;
2755 }
2756
2757 if (stamp && os_strlen(stamp))
2758 wpa_debug_timestamp = atoi(stamp);
2759
2760 os_memcpy(buf, "OK\n", 3);
2761 return 3;
2762}
2763
2764
2765#ifdef NEED_AP_MLME
2766static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data *hapd,
2767 char *buf, size_t buflen)
2768{
2769 struct hostapd_iface *iface = hapd->iface;
2770 char *pos, *end;
2771 struct hostapd_sta_info *info;
2772 struct os_reltime now;
2773
Dmitry Shmidt7d175302016-09-06 13:11:34 -07002774 if (!iface->num_sta_seen)
2775 return 0;
2776
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002777 sta_track_expire(iface, 0);
2778
2779 pos = buf;
2780 end = buf + buflen;
2781
2782 os_get_reltime(&now);
2783 dl_list_for_each_reverse(info, &iface->sta_seen,
2784 struct hostapd_sta_info, list) {
2785 struct os_reltime age;
2786 int ret;
2787
2788 os_reltime_sub(&now, &info->last_seen, &age);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002789 ret = os_snprintf(pos, end - pos, MACSTR " %u %d\n",
2790 MAC2STR(info->addr), (unsigned int) age.sec,
2791 info->ssi_signal);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002792 if (os_snprintf_error(end - pos, ret))
2793 break;
2794 pos += ret;
2795 }
2796
2797 return pos - buf;
2798}
2799#endif /* NEED_AP_MLME */
2800
2801
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002802static int hostapd_ctrl_iface_req_lci(struct hostapd_data *hapd,
2803 const char *cmd)
2804{
2805 u8 addr[ETH_ALEN];
2806
2807 if (hwaddr_aton(cmd, addr)) {
2808 wpa_printf(MSG_INFO, "CTRL: REQ_LCI: Invalid MAC address");
2809 return -1;
2810 }
2811
2812 return hostapd_send_lci_req(hapd, addr);
2813}
2814
2815
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07002816static int hostapd_ctrl_iface_req_range(struct hostapd_data *hapd, char *cmd)
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002817{
2818 u8 addr[ETH_ALEN];
2819 char *token, *context = NULL;
2820 int random_interval, min_ap;
2821 u8 responders[ETH_ALEN * RRM_RANGE_REQ_MAX_RESPONDERS];
2822 unsigned int n_responders;
2823
2824 token = str_token(cmd, " ", &context);
2825 if (!token || hwaddr_aton(token, addr)) {
2826 wpa_printf(MSG_INFO,
2827 "CTRL: REQ_RANGE - Bad destination address");
2828 return -1;
2829 }
2830
2831 token = str_token(cmd, " ", &context);
2832 if (!token)
2833 return -1;
2834
2835 random_interval = atoi(token);
2836 if (random_interval < 0 || random_interval > 0xffff)
2837 return -1;
2838
2839 token = str_token(cmd, " ", &context);
2840 if (!token)
2841 return -1;
2842
2843 min_ap = atoi(token);
2844 if (min_ap <= 0 || min_ap > WLAN_RRM_RANGE_REQ_MAX_MIN_AP)
2845 return -1;
2846
2847 n_responders = 0;
2848 while ((token = str_token(cmd, " ", &context))) {
2849 if (n_responders == RRM_RANGE_REQ_MAX_RESPONDERS) {
2850 wpa_printf(MSG_INFO,
2851 "CTRL: REQ_RANGE: Too many responders");
2852 return -1;
2853 }
2854
2855 if (hwaddr_aton(token, responders + n_responders * ETH_ALEN)) {
2856 wpa_printf(MSG_INFO,
2857 "CTRL: REQ_RANGE: Bad responder address");
2858 return -1;
2859 }
2860
2861 n_responders++;
2862 }
2863
2864 if (!n_responders) {
2865 wpa_printf(MSG_INFO,
2866 "CTRL: REQ_RANGE - No FTM responder address");
2867 return -1;
2868 }
2869
2870 return hostapd_send_range_req(hapd, addr, random_interval, min_ap,
2871 responders, n_responders);
2872}
2873
2874
Dmitry Shmidt29333592017-01-09 12:27:11 -08002875static int hostapd_ctrl_iface_req_beacon(struct hostapd_data *hapd,
2876 const char *cmd, char *reply,
2877 size_t reply_size)
2878{
2879 u8 addr[ETH_ALEN];
2880 const char *pos;
2881 struct wpabuf *req;
2882 int ret;
2883 u8 req_mode = 0;
2884
2885 if (hwaddr_aton(cmd, addr))
2886 return -1;
2887 pos = os_strchr(cmd, ' ');
2888 if (!pos)
2889 return -1;
2890 pos++;
2891 if (os_strncmp(pos, "req_mode=", 9) == 0) {
2892 int val = hex2byte(pos + 9);
2893
2894 if (val < 0)
2895 return -1;
2896 req_mode = val;
2897 pos += 11;
2898 pos = os_strchr(pos, ' ');
2899 if (!pos)
2900 return -1;
2901 pos++;
2902 }
2903 req = wpabuf_parse_bin(pos);
2904 if (!req)
2905 return -1;
2906
2907 ret = hostapd_send_beacon_req(hapd, addr, req_mode, req);
2908 wpabuf_free(req);
2909 if (ret >= 0)
2910 ret = os_snprintf(reply, reply_size, "%d", ret);
2911 return ret;
2912}
2913
2914
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08002915static int hostapd_ctrl_iface_show_neighbor(struct hostapd_data *hapd,
2916 char *buf, size_t buflen)
2917{
2918 if (!(hapd->conf->radio_measurements[0] &
2919 WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
2920 wpa_printf(MSG_ERROR,
2921 "CTRL: SHOW_NEIGHBOR: Neighbor report is not enabled");
2922 return -1;
2923 }
2924
2925 return hostapd_neighbor_show(hapd, buf, buflen);
2926}
2927
2928
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002929static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data *hapd, char *buf)
2930{
2931 struct wpa_ssid_value ssid;
2932 u8 bssid[ETH_ALEN];
2933 struct wpabuf *nr, *lci = NULL, *civic = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002934 int stationary = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -08002935 int bss_parameters = 0;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002936 char *tmp;
Hai Shaloma20dcd72022-02-04 13:43:00 -08002937 int ret = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002938
2939 if (!(hapd->conf->radio_measurements[0] &
2940 WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
2941 wpa_printf(MSG_ERROR,
2942 "CTRL: SET_NEIGHBOR: Neighbor report is not enabled");
2943 return -1;
2944 }
2945
2946 if (hwaddr_aton(buf, bssid)) {
2947 wpa_printf(MSG_ERROR, "CTRL: SET_NEIGHBOR: Bad BSSID");
2948 return -1;
2949 }
2950
2951 tmp = os_strstr(buf, "ssid=");
2952 if (!tmp || ssid_parse(tmp + 5, &ssid)) {
2953 wpa_printf(MSG_ERROR,
2954 "CTRL: SET_NEIGHBOR: Bad or missing SSID");
2955 return -1;
2956 }
2957 buf = os_strchr(tmp + 6, tmp[5] == '"' ? '"' : ' ');
2958 if (!buf)
2959 return -1;
2960
2961 tmp = os_strstr(buf, "nr=");
2962 if (!tmp) {
2963 wpa_printf(MSG_ERROR,
2964 "CTRL: SET_NEIGHBOR: Missing Neighbor Report element");
2965 return -1;
2966 }
2967
2968 buf = os_strchr(tmp, ' ');
2969 if (buf)
2970 *buf++ = '\0';
2971
2972 nr = wpabuf_parse_bin(tmp + 3);
2973 if (!nr) {
2974 wpa_printf(MSG_ERROR,
2975 "CTRL: SET_NEIGHBOR: Bad Neighbor Report element");
2976 return -1;
2977 }
2978
2979 if (!buf)
2980 goto set;
2981
2982 tmp = os_strstr(buf, "lci=");
2983 if (tmp) {
2984 buf = os_strchr(tmp, ' ');
2985 if (buf)
2986 *buf++ = '\0';
2987 lci = wpabuf_parse_bin(tmp + 4);
2988 if (!lci) {
2989 wpa_printf(MSG_ERROR,
2990 "CTRL: SET_NEIGHBOR: Bad LCI subelement");
Hai Shaloma20dcd72022-02-04 13:43:00 -08002991 goto fail;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002992 }
2993 }
2994
2995 if (!buf)
2996 goto set;
2997
2998 tmp = os_strstr(buf, "civic=");
2999 if (tmp) {
3000 buf = os_strchr(tmp, ' ');
3001 if (buf)
3002 *buf++ = '\0';
3003 civic = wpabuf_parse_bin(tmp + 6);
3004 if (!civic) {
3005 wpa_printf(MSG_ERROR,
3006 "CTRL: SET_NEIGHBOR: Bad civic subelement");
Hai Shaloma20dcd72022-02-04 13:43:00 -08003007 goto fail;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003008 }
3009 }
3010
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003011 if (!buf)
3012 goto set;
3013
3014 if (os_strstr(buf, "stat"))
3015 stationary = 1;
3016
Hai Shaloma20dcd72022-02-04 13:43:00 -08003017 tmp = os_strstr(buf, "bss_parameter=");
3018 if (tmp) {
3019 bss_parameters = atoi(tmp + 14);
3020 if (bss_parameters < 0 || bss_parameters > 0xff) {
3021 wpa_printf(MSG_ERROR,
3022 "CTRL: SET_NEIGHBOR: Bad bss_parameters subelement");
3023 goto fail;
3024 }
3025 }
3026
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003027set:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003028 ret = hostapd_neighbor_set(hapd, bssid, &ssid, nr, lci, civic,
Hai Shaloma20dcd72022-02-04 13:43:00 -08003029 stationary, bss_parameters);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003030
Hai Shaloma20dcd72022-02-04 13:43:00 -08003031fail:
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003032 wpabuf_free(nr);
3033 wpabuf_free(lci);
3034 wpabuf_free(civic);
3035
3036 return ret;
3037}
3038
3039
3040static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data *hapd,
3041 char *buf)
3042{
3043 struct wpa_ssid_value ssid;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003044 struct wpa_ssid_value *ssidp = NULL;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003045 u8 bssid[ETH_ALEN];
3046 char *tmp;
3047
3048 if (hwaddr_aton(buf, bssid)) {
3049 wpa_printf(MSG_ERROR, "CTRL: REMOVE_NEIGHBOR: Bad BSSID");
3050 return -1;
3051 }
3052
3053 tmp = os_strstr(buf, "ssid=");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003054 if (tmp) {
3055 ssidp = &ssid;
3056 if (ssid_parse(tmp + 5, &ssid)) {
3057 wpa_printf(MSG_ERROR,
3058 "CTRL: REMOVE_NEIGHBOR: Bad SSID");
3059 return -1;
3060 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003061 }
3062
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003063 return hostapd_neighbor_remove(hapd, bssid, ssidp);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003064}
3065
3066
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07003067static int hostapd_ctrl_driver_flags(struct hostapd_iface *iface, char *buf,
3068 size_t buflen)
3069{
3070 int ret, i;
3071 char *pos, *end;
3072
3073 ret = os_snprintf(buf, buflen, "%016llX:\n",
3074 (long long unsigned) iface->drv_flags);
3075 if (os_snprintf_error(buflen, ret))
3076 return -1;
3077
3078 pos = buf + ret;
3079 end = buf + buflen;
3080
3081 for (i = 0; i < 64; i++) {
3082 if (iface->drv_flags & (1LLU << i)) {
3083 ret = os_snprintf(pos, end - pos, "%s\n",
3084 driver_flag_to_string(1LLU << i));
3085 if (os_snprintf_error(end - pos, ret))
3086 return -1;
3087 pos += ret;
3088 }
3089 }
3090
3091 return pos - buf;
3092}
3093
3094
Hai Shalomb755a2a2020-04-23 21:49:02 -07003095static int hostapd_ctrl_driver_flags2(struct hostapd_iface *iface, char *buf,
3096 size_t buflen)
3097{
3098 int ret, i;
3099 char *pos, *end;
3100
3101 ret = os_snprintf(buf, buflen, "%016llX:\n",
3102 (long long unsigned) iface->drv_flags2);
3103 if (os_snprintf_error(buflen, ret))
3104 return -1;
3105
3106 pos = buf + ret;
3107 end = buf + buflen;
3108
3109 for (i = 0; i < 64; i++) {
3110 if (iface->drv_flags2 & (1LLU << i)) {
3111 ret = os_snprintf(pos, end - pos, "%s\n",
3112 driver_flag2_to_string(1LLU << i));
3113 if (os_snprintf_error(end - pos, ret))
3114 return -1;
3115 pos += ret;
3116 }
3117 }
3118
3119 return pos - buf;
3120}
3121
3122
Hai Shalom021b0b52019-04-10 11:17:58 -07003123static int hostapd_ctrl_iface_get_capability(struct hostapd_data *hapd,
3124 const char *field, char *buf,
3125 size_t buflen)
3126{
3127 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'", field);
3128
3129#ifdef CONFIG_DPP
3130 if (os_strcmp(field, "dpp") == 0) {
3131 int res;
3132
Hai Shaloma20dcd72022-02-04 13:43:00 -08003133#ifdef CONFIG_DPP3
3134 res = os_snprintf(buf, buflen, "DPP=3");
3135#elif defined(CONFIG_DPP2)
Hai Shalom021b0b52019-04-10 11:17:58 -07003136 res = os_snprintf(buf, buflen, "DPP=2");
3137#else /* CONFIG_DPP2 */
3138 res = os_snprintf(buf, buflen, "DPP=1");
3139#endif /* CONFIG_DPP2 */
3140 if (os_snprintf_error(buflen, res))
3141 return -1;
3142 return res;
3143 }
3144#endif /* CONFIG_DPP */
3145
3146 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3147 field);
3148
3149 return -1;
3150}
3151
3152
Hai Shaloma20dcd72022-02-04 13:43:00 -08003153#ifdef ANDROID
3154static int hostapd_ctrl_iface_driver_cmd(struct hostapd_data *hapd, char *cmd,
3155 char *buf, size_t buflen)
3156{
3157 int ret;
3158
3159 ret = hostapd_drv_driver_cmd(hapd, cmd, buf, buflen);
3160 if (ret == 0) {
3161 ret = os_snprintf(buf, buflen, "%s\n", "OK");
3162 if (os_snprintf_error(buflen, ret))
3163 ret = -1;
3164 }
3165 return ret;
3166}
3167#endif /* ANDROID */
3168
3169
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003170static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
3171 char *buf, char *reply,
3172 int reply_size,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003173 struct sockaddr_storage *from,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003174 socklen_t fromlen)
3175{
3176 int reply_len, res;
3177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003178 os_memcpy(reply, "OK\n", 3);
3179 reply_len = 3;
3180
3181 if (os_strcmp(buf, "PING") == 0) {
3182 os_memcpy(reply, "PONG\n", 5);
3183 reply_len = 5;
3184 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
3185 if (wpa_debug_reopen_file() < 0)
3186 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003187 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
3188 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003189 } else if (os_strcmp(buf, "STATUS") == 0) {
3190 reply_len = hostapd_ctrl_iface_status(hapd, reply,
3191 reply_size);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003192 } else if (os_strcmp(buf, "STATUS-DRIVER") == 0) {
3193 reply_len = hostapd_drv_status(hapd, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003194 } else if (os_strcmp(buf, "MIB") == 0) {
3195 reply_len = ieee802_11_get_mib(hapd, reply, reply_size);
3196 if (reply_len >= 0) {
3197 res = wpa_get_mib(hapd->wpa_auth, reply + reply_len,
3198 reply_size - reply_len);
3199 if (res < 0)
3200 reply_len = -1;
3201 else
3202 reply_len += res;
3203 }
3204 if (reply_len >= 0) {
3205 res = ieee802_1x_get_mib(hapd, reply + reply_len,
3206 reply_size - reply_len);
3207 if (res < 0)
3208 reply_len = -1;
3209 else
3210 reply_len += res;
3211 }
3212#ifndef CONFIG_NO_RADIUS
3213 if (reply_len >= 0) {
3214 res = radius_client_get_mib(hapd->radius,
3215 reply + reply_len,
3216 reply_size - reply_len);
3217 if (res < 0)
3218 reply_len = -1;
3219 else
3220 reply_len += res;
3221 }
3222#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003223 } else if (os_strncmp(buf, "MIB ", 4) == 0) {
3224 reply_len = hostapd_ctrl_iface_mib(hapd, reply, reply_size,
3225 buf + 4);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003226 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
3227 reply_len = hostapd_ctrl_iface_sta_first(hapd, reply,
3228 reply_size);
3229 } else if (os_strncmp(buf, "STA ", 4) == 0) {
3230 reply_len = hostapd_ctrl_iface_sta(hapd, buf + 4, reply,
3231 reply_size);
3232 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
3233 reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
3234 reply_size);
3235 } else if (os_strcmp(buf, "ATTACH") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003236 if (hostapd_ctrl_iface_attach(hapd, from, fromlen, NULL))
3237 reply_len = -1;
3238 } else if (os_strncmp(buf, "ATTACH ", 7) == 0) {
3239 if (hostapd_ctrl_iface_attach(hapd, from, fromlen, buf + 7))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003240 reply_len = -1;
3241 } else if (os_strcmp(buf, "DETACH") == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003242 if (hostapd_ctrl_iface_detach(hapd, from, fromlen))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003243 reply_len = -1;
3244 } else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003245 if (hostapd_ctrl_iface_level(hapd, from, fromlen,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003246 buf + 6))
3247 reply_len = -1;
3248 } else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
3249 if (hostapd_ctrl_iface_new_sta(hapd, buf + 8))
3250 reply_len = -1;
3251 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
3252 if (hostapd_ctrl_iface_deauthenticate(hapd, buf + 15))
3253 reply_len = -1;
3254 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
3255 if (hostapd_ctrl_iface_disassociate(hapd, buf + 13))
3256 reply_len = -1;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003257#ifdef CONFIG_TAXONOMY
3258 } else if (os_strncmp(buf, "SIGNATURE ", 10) == 0) {
3259 reply_len = hostapd_ctrl_iface_signature(hapd, buf + 10,
3260 reply, reply_size);
3261#endif /* CONFIG_TAXONOMY */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003262 } else if (os_strncmp(buf, "POLL_STA ", 9) == 0) {
3263 if (hostapd_ctrl_iface_poll_sta(hapd, buf + 9))
3264 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003265 } else if (os_strcmp(buf, "STOP_AP") == 0) {
3266 if (hostapd_ctrl_iface_stop_ap(hapd))
3267 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003268#ifdef NEED_AP_MLME
3269 } else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
3270 if (hostapd_ctrl_iface_sa_query(hapd, buf + 9))
3271 reply_len = -1;
3272#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003273#ifdef CONFIG_WPS
3274 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
3275 if (hostapd_ctrl_iface_wps_pin(hapd, buf + 8))
3276 reply_len = -1;
3277 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
3278 reply_len = hostapd_ctrl_iface_wps_check_pin(
3279 hapd, buf + 14, reply, reply_size);
3280 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
3281 if (hostapd_wps_button_pushed(hapd, NULL))
3282 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003283 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
3284 if (hostapd_wps_cancel(hapd))
3285 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003286 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
3287 reply_len = hostapd_ctrl_iface_wps_ap_pin(hapd, buf + 11,
3288 reply, reply_size);
3289 } else if (os_strncmp(buf, "WPS_CONFIG ", 11) == 0) {
3290 if (hostapd_ctrl_iface_wps_config(hapd, buf + 11) < 0)
3291 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003292 } else if (os_strncmp(buf, "WPS_GET_STATUS", 13) == 0) {
3293 reply_len = hostapd_ctrl_iface_wps_get_status(hapd, reply,
3294 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003295#ifdef CONFIG_WPS_NFC
3296 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
3297 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd, buf + 17))
3298 reply_len = -1;
3299 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
3300 reply_len = hostapd_ctrl_iface_wps_nfc_config_token(
3301 hapd, buf + 21, reply, reply_size);
3302 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
3303 reply_len = hostapd_ctrl_iface_wps_nfc_token(
3304 hapd, buf + 14, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003305 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
3306 reply_len = hostapd_ctrl_iface_nfc_get_handover_sel(
3307 hapd, buf + 21, reply, reply_size);
3308 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
3309 if (hostapd_ctrl_iface_nfc_report_handover(hapd, buf + 20))
3310 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003311#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003312#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003313#ifdef CONFIG_INTERWORKING
3314 } else if (os_strncmp(buf, "SET_QOS_MAP_SET ", 16) == 0) {
3315 if (hostapd_ctrl_iface_set_qos_map_set(hapd, buf + 16))
3316 reply_len = -1;
3317 } else if (os_strncmp(buf, "SEND_QOS_MAP_CONF ", 18) == 0) {
3318 if (hostapd_ctrl_iface_send_qos_map_conf(hapd, buf + 18))
3319 reply_len = -1;
3320#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003321#ifdef CONFIG_HS20
3322 } else if (os_strncmp(buf, "HS20_WNM_NOTIF ", 15) == 0) {
3323 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd, buf + 15))
3324 reply_len = -1;
3325 } else if (os_strncmp(buf, "HS20_DEAUTH_REQ ", 16) == 0) {
3326 if (hostapd_ctrl_iface_hs20_deauth_req(hapd, buf + 16))
3327 reply_len = -1;
3328#endif /* CONFIG_HS20 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003329#ifdef CONFIG_WNM_AP
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003330 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
3331 if (hostapd_ctrl_iface_disassoc_imminent(hapd, buf + 18))
3332 reply_len = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003333 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
3334 if (hostapd_ctrl_iface_ess_disassoc(hapd, buf + 13))
3335 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003336 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
3337 if (hostapd_ctrl_iface_bss_tm_req(hapd, buf + 11))
3338 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003339 } else if (os_strncmp(buf, "COLOC_INTF_REQ ", 15) == 0) {
3340 if (hostapd_ctrl_iface_coloc_intf_req(hapd, buf + 15))
3341 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003342#endif /* CONFIG_WNM_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003343 } else if (os_strcmp(buf, "GET_CONFIG") == 0) {
3344 reply_len = hostapd_ctrl_iface_get_config(hapd, reply,
3345 reply_size);
3346 } else if (os_strncmp(buf, "SET ", 4) == 0) {
3347 if (hostapd_ctrl_iface_set(hapd, buf + 4))
3348 reply_len = -1;
3349 } else if (os_strncmp(buf, "GET ", 4) == 0) {
3350 reply_len = hostapd_ctrl_iface_get(hapd, buf + 4, reply,
3351 reply_size);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003352 } else if (os_strncmp(buf, "ENABLE", 6) == 0) {
3353 if (hostapd_ctrl_iface_enable(hapd->iface))
3354 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003355 } else if (os_strcmp(buf, "RELOAD_WPA_PSK") == 0) {
3356 if (hostapd_ctrl_iface_reload_wpa_psk(hapd))
3357 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003358 } else if (os_strncmp(buf, "RELOAD", 6) == 0) {
3359 if (hostapd_ctrl_iface_reload(hapd->iface))
3360 reply_len = -1;
3361 } else if (os_strncmp(buf, "DISABLE", 7) == 0) {
3362 if (hostapd_ctrl_iface_disable(hapd->iface))
3363 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003364 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
3365 if (ieee802_11_set_beacon(hapd))
3366 reply_len = -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003367#ifdef CONFIG_TESTING_OPTIONS
3368 } else if (os_strncmp(buf, "RADAR ", 6) == 0) {
3369 if (hostapd_ctrl_iface_radar(hapd, buf + 6))
3370 reply_len = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003371 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
3372 if (hostapd_ctrl_iface_mgmt_tx(hapd, buf + 8))
3373 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003374 } else if (os_strncmp(buf, "MGMT_TX_STATUS_PROCESS ", 23) == 0) {
3375 if (hostapd_ctrl_iface_mgmt_tx_status_process(hapd,
3376 buf + 23) < 0)
3377 reply_len = -1;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003378 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
3379 if (hostapd_ctrl_iface_mgmt_rx_process(hapd, buf + 16) < 0)
3380 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003381 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
3382 if (hostapd_ctrl_iface_eapol_rx(hapd, buf + 9) < 0)
3383 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08003384 } else if (os_strncmp(buf, "EAPOL_TX ", 9) == 0) {
3385 if (hostapd_ctrl_iface_eapol_tx(hapd, buf + 9) < 0)
3386 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003387 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
3388 if (hostapd_ctrl_iface_data_test_config(hapd, buf + 17) < 0)
3389 reply_len = -1;
3390 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
3391 if (hostapd_ctrl_iface_data_test_tx(hapd, buf + 13) < 0)
3392 reply_len = -1;
3393 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
3394 if (hostapd_ctrl_iface_data_test_frame(hapd, buf + 16) < 0)
3395 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003396 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
3397 if (hostapd_ctrl_test_alloc_fail(hapd, buf + 16) < 0)
3398 reply_len = -1;
3399 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
3400 reply_len = hostapd_ctrl_get_alloc_fail(hapd, reply,
3401 reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003402 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
3403 if (hostapd_ctrl_test_fail(hapd, buf + 10) < 0)
3404 reply_len = -1;
3405 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
3406 reply_len = hostapd_ctrl_get_fail(hapd, reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003407 } else if (os_strncmp(buf, "RESET_PN ", 9) == 0) {
3408 if (hostapd_ctrl_reset_pn(hapd, buf + 9) < 0)
3409 reply_len = -1;
3410 } else if (os_strncmp(buf, "SET_KEY ", 8) == 0) {
3411 if (hostapd_ctrl_set_key(hapd, buf + 8) < 0)
3412 reply_len = -1;
3413 } else if (os_strncmp(buf, "RESEND_M1 ", 10) == 0) {
3414 if (hostapd_ctrl_resend_m1(hapd, buf + 10) < 0)
3415 reply_len = -1;
3416 } else if (os_strncmp(buf, "RESEND_M3 ", 10) == 0) {
3417 if (hostapd_ctrl_resend_m3(hapd, buf + 10) < 0)
3418 reply_len = -1;
3419 } else if (os_strncmp(buf, "RESEND_GROUP_M1 ", 16) == 0) {
3420 if (hostapd_ctrl_resend_group_m1(hapd, buf + 16) < 0)
3421 reply_len = -1;
Hai Shaloma20dcd72022-02-04 13:43:00 -08003422 } else if (os_strncmp(buf, "REKEY_PTK ", 10) == 0) {
3423 if (hostapd_ctrl_rekey_ptk(hapd, buf + 10) < 0)
3424 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003425 } else if (os_strcmp(buf, "REKEY_GTK") == 0) {
3426 if (wpa_auth_rekey_gtk(hapd->wpa_auth) < 0)
3427 reply_len = -1;
Hai Shalomfdcde762020-04-02 11:19:20 -07003428 } else if (os_strncmp(buf, "GET_PMK ", 8) == 0) {
3429 reply_len = hostapd_ctrl_get_pmk(hapd, buf + 8, reply,
3430 reply_size);
Hai Shaloma20dcd72022-02-04 13:43:00 -08003431 } else if (os_strncmp(buf, "REGISTER_FRAME ", 15) == 0) {
3432 if (hostapd_ctrl_register_frame(hapd, buf + 16) < 0)
3433 reply_len = -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003434#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003435 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003436 if (hostapd_ctrl_iface_chan_switch(hapd->iface, buf + 12))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003437 reply_len = -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003438 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
3439 reply_len = hostapd_ctrl_iface_vendor(hapd, buf + 7, reply,
3440 reply_size);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003441 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
3442 ieee802_1x_erp_flush(hapd);
3443#ifdef RADIUS_SERVER
3444 radius_server_erp_flush(hapd->radius_srv);
3445#endif /* RADIUS_SERVER */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003446 } else if (os_strncmp(buf, "EAPOL_REAUTH ", 13) == 0) {
3447 if (hostapd_ctrl_iface_eapol_reauth(hapd, buf + 13))
3448 reply_len = -1;
3449 } else if (os_strncmp(buf, "EAPOL_SET ", 10) == 0) {
3450 if (hostapd_ctrl_iface_eapol_set(hapd, buf + 10))
3451 reply_len = -1;
3452 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
3453 reply_len = hostapd_ctrl_iface_log_level(
3454 hapd, buf + 9, reply, reply_size);
3455#ifdef NEED_AP_MLME
3456 } else if (os_strcmp(buf, "TRACK_STA_LIST") == 0) {
3457 reply_len = hostapd_ctrl_iface_track_sta_list(
3458 hapd, reply, reply_size);
3459#endif /* NEED_AP_MLME */
Dmitry Shmidte4663042016-04-04 10:07:49 -07003460 } else if (os_strcmp(buf, "PMKSA") == 0) {
3461 reply_len = hostapd_ctrl_iface_pmksa_list(hapd, reply,
3462 reply_size);
3463 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
3464 hostapd_ctrl_iface_pmksa_flush(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003465 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
3466 if (hostapd_ctrl_iface_pmksa_add(hapd, buf + 10) < 0)
3467 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003468 } else if (os_strncmp(buf, "SET_NEIGHBOR ", 13) == 0) {
3469 if (hostapd_ctrl_iface_set_neighbor(hapd, buf + 13))
3470 reply_len = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003471 } else if (os_strcmp(buf, "SHOW_NEIGHBOR") == 0) {
3472 reply_len = hostapd_ctrl_iface_show_neighbor(hapd, reply,
3473 reply_size);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003474 } else if (os_strncmp(buf, "REMOVE_NEIGHBOR ", 16) == 0) {
3475 if (hostapd_ctrl_iface_remove_neighbor(hapd, buf + 16))
3476 reply_len = -1;
3477 } else if (os_strncmp(buf, "REQ_LCI ", 8) == 0) {
3478 if (hostapd_ctrl_iface_req_lci(hapd, buf + 8))
3479 reply_len = -1;
3480 } else if (os_strncmp(buf, "REQ_RANGE ", 10) == 0) {
3481 if (hostapd_ctrl_iface_req_range(hapd, buf + 10))
3482 reply_len = -1;
Dmitry Shmidt29333592017-01-09 12:27:11 -08003483 } else if (os_strncmp(buf, "REQ_BEACON ", 11) == 0) {
3484 reply_len = hostapd_ctrl_iface_req_beacon(hapd, buf + 11,
3485 reply, reply_size);
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07003486 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
3487 reply_len = hostapd_ctrl_driver_flags(hapd->iface, reply,
3488 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -07003489 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
3490 reply_len = hostapd_ctrl_driver_flags2(hapd->iface, reply,
3491 reply_size);
Dmitry Shmidt29333592017-01-09 12:27:11 -08003492 } else if (os_strcmp(buf, "TERMINATE") == 0) {
3493 eloop_terminate();
Roshan Pius3a1667e2018-07-03 15:17:14 -07003494 } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) {
3495 if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08003496 if (hostapd_ctrl_iface_acl_add_mac(
3497 &hapd->conf->accept_mac,
Sunil Ravia04bd252022-05-02 22:54:18 -07003498 &hapd->conf->num_accept_mac, buf + 19) ||
3499 hostapd_set_acl(hapd))
Hai Shalom60840252021-02-19 19:02:11 -08003500 reply_len = -1;
3501 } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) {
Sunil Ravia04bd252022-05-02 22:54:18 -07003502 if (hostapd_ctrl_iface_acl_del_mac(
Roshan Pius3a1667e2018-07-03 15:17:14 -07003503 &hapd->conf->accept_mac,
Sunil Ravia04bd252022-05-02 22:54:18 -07003504 &hapd->conf->num_accept_mac, buf + 19) ||
3505 hostapd_set_acl(hapd) ||
3506 hostapd_disassoc_accept_mac(hapd))
Roshan Pius3a1667e2018-07-03 15:17:14 -07003507 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003508 } else if (os_strcmp(buf + 11, "SHOW") == 0) {
3509 reply_len = hostapd_ctrl_iface_acl_show_mac(
3510 hapd->conf->accept_mac,
3511 hapd->conf->num_accept_mac, reply, reply_size);
3512 } else if (os_strcmp(buf + 11, "CLEAR") == 0) {
3513 hostapd_ctrl_iface_acl_clear_list(
3514 &hapd->conf->accept_mac,
3515 &hapd->conf->num_accept_mac);
Sunil Ravia04bd252022-05-02 22:54:18 -07003516 if (hostapd_set_acl(hapd) ||
3517 hostapd_disassoc_accept_mac(hapd))
3518 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003519 }
3520 } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) {
3521 if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) {
Sunil Ravia04bd252022-05-02 22:54:18 -07003522 if (hostapd_ctrl_iface_acl_add_mac(
Roshan Pius3a1667e2018-07-03 15:17:14 -07003523 &hapd->conf->deny_mac,
Sunil Ravia04bd252022-05-02 22:54:18 -07003524 &hapd->conf->num_deny_mac, buf + 17) ||
3525 hostapd_set_acl(hapd) ||
3526 hostapd_disassoc_deny_mac(hapd))
Hai Shalom60840252021-02-19 19:02:11 -08003527 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003528 } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) {
Hai Shalom60840252021-02-19 19:02:11 -08003529 if (hostapd_ctrl_iface_acl_del_mac(
3530 &hapd->conf->deny_mac,
Sunil Ravia04bd252022-05-02 22:54:18 -07003531 &hapd->conf->num_deny_mac, buf + 17) ||
3532 hostapd_set_acl(hapd))
Hai Shalom60840252021-02-19 19:02:11 -08003533 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003534 } else if (os_strcmp(buf + 9, "SHOW") == 0) {
3535 reply_len = hostapd_ctrl_iface_acl_show_mac(
3536 hapd->conf->deny_mac,
3537 hapd->conf->num_deny_mac, reply, reply_size);
3538 } else if (os_strcmp(buf + 9, "CLEAR") == 0) {
3539 hostapd_ctrl_iface_acl_clear_list(
3540 &hapd->conf->deny_mac,
3541 &hapd->conf->num_deny_mac);
Sunil Ravia04bd252022-05-02 22:54:18 -07003542 if (hostapd_set_acl(hapd))
3543 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003544 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003545#ifdef CONFIG_DPP
3546 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
3547 res = hostapd_dpp_qr_code(hapd, buf + 12);
3548 if (res < 0) {
3549 reply_len = -1;
3550 } else {
3551 reply_len = os_snprintf(reply, reply_size, "%d", res);
3552 if (os_snprintf_error(reply_size, reply_len))
3553 reply_len = -1;
3554 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003555 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
3556 res = hostapd_dpp_nfc_uri(hapd, buf + 12);
3557 if (res < 0) {
3558 reply_len = -1;
3559 } else {
3560 reply_len = os_snprintf(reply, reply_size, "%d", res);
3561 if (os_snprintf_error(reply_size, reply_len))
3562 reply_len = -1;
3563 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003564 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
3565 res = hostapd_dpp_nfc_handover_req(hapd, buf + 20);
3566 if (res < 0) {
3567 reply_len = -1;
3568 } else {
3569 reply_len = os_snprintf(reply, reply_size, "%d", res);
3570 if (os_snprintf_error(reply_size, reply_len))
3571 reply_len = -1;
3572 }
3573 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
3574 res = hostapd_dpp_nfc_handover_sel(hapd, buf + 20);
3575 if (res < 0) {
3576 reply_len = -1;
3577 } else {
3578 reply_len = os_snprintf(reply, reply_size, "%d", res);
3579 if (os_snprintf_error(reply_size, reply_len))
3580 reply_len = -1;
3581 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003582 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003583 res = dpp_bootstrap_gen(hapd->iface->interfaces->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003584 if (res < 0) {
3585 reply_len = -1;
3586 } else {
3587 reply_len = os_snprintf(reply, reply_size, "%d", res);
3588 if (os_snprintf_error(reply_size, reply_len))
3589 reply_len = -1;
3590 }
3591 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003592 if (dpp_bootstrap_remove(hapd->iface->interfaces->dpp,
3593 buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003594 reply_len = -1;
3595 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
3596 const char *uri;
3597
Hai Shalom021b0b52019-04-10 11:17:58 -07003598 uri = dpp_bootstrap_get_uri(hapd->iface->interfaces->dpp,
3599 atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003600 if (!uri) {
3601 reply_len = -1;
3602 } else {
3603 reply_len = os_snprintf(reply, reply_size, "%s", uri);
3604 if (os_snprintf_error(reply_size, reply_len))
3605 reply_len = -1;
3606 }
3607 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003608 reply_len = dpp_bootstrap_info(hapd->iface->interfaces->dpp,
3609 atoi(buf + 19),
3610 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -07003611 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
3612 if (dpp_bootstrap_set(hapd->iface->interfaces->dpp,
3613 atoi(buf + 18),
3614 os_strchr(buf + 18, ' ')) < 0)
3615 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003616 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
3617 if (hostapd_dpp_auth_init(hapd, buf + 13) < 0)
3618 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003619 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
3620 if (hostapd_dpp_listen(hapd, buf + 11) < 0)
3621 reply_len = -1;
3622 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
3623 hostapd_dpp_stop(hapd);
3624 hostapd_dpp_listen_stop(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003625 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003626 res = dpp_configurator_add(hapd->iface->interfaces->dpp,
3627 buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003628 if (res < 0) {
3629 reply_len = -1;
3630 } else {
3631 reply_len = os_snprintf(reply, reply_size, "%d", res);
3632 if (os_snprintf_error(reply_size, reply_len))
3633 reply_len = -1;
3634 }
Sunil Ravia04bd252022-05-02 22:54:18 -07003635 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SET ", 21) == 0) {
3636 if (dpp_configurator_set(hapd->iface->interfaces->dpp,
3637 buf + 20) < 0)
3638 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003639 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003640 if (dpp_configurator_remove(hapd->iface->interfaces->dpp,
3641 buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003642 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003643 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003644 if (hostapd_dpp_configurator_sign(hapd, buf + 21) < 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -07003645 reply_len = -1;
3646 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003647 reply_len = dpp_configurator_get_key_id(
3648 hapd->iface->interfaces->dpp,
3649 atoi(buf + 25),
3650 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003651 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
3652 res = hostapd_dpp_pkex_add(hapd, buf + 12);
3653 if (res < 0) {
3654 reply_len = -1;
3655 } else {
3656 reply_len = os_snprintf(reply, reply_size, "%d", res);
3657 if (os_snprintf_error(reply_size, reply_len))
3658 reply_len = -1;
3659 }
3660 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
3661 if (hostapd_dpp_pkex_remove(hapd, buf + 16) < 0)
3662 reply_len = -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003663#ifdef CONFIG_DPP2
Hai Shalom899fcc72020-10-19 14:38:18 -07003664 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
3665 if (hostapd_dpp_controller_start(hapd, buf + 20) < 0)
3666 reply_len = -1;
3667 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
3668 if (hostapd_dpp_controller_start(hapd, NULL) < 0)
3669 reply_len = -1;
3670 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
3671 dpp_controller_stop(hapd->iface->interfaces->dpp);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003672 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
3673 if (hostapd_dpp_chirp(hapd, buf + 9) < 0)
3674 reply_len = -1;
3675 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
3676 hostapd_dpp_chirp_stop(hapd);
3677#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003678#endif /* CONFIG_DPP */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003679#ifdef RADIUS_SERVER
3680 } else if (os_strncmp(buf, "DAC_REQUEST ", 12) == 0) {
3681 if (radius_server_dac_request(hapd->radius_srv, buf + 12) < 0)
3682 reply_len = -1;
3683#endif /* RADIUS_SERVER */
Hai Shalom021b0b52019-04-10 11:17:58 -07003684 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
3685 reply_len = hostapd_ctrl_iface_get_capability(
3686 hapd, buf + 15, reply, reply_size);
Hai Shalom60840252021-02-19 19:02:11 -08003687#ifdef CONFIG_PASN
3688 } else if (os_strcmp(buf, "PTKSA_CACHE_LIST") == 0) {
3689 reply_len = ptksa_cache_list(hapd->ptksa, reply, reply_size);
3690#endif /* CONFIG_PASN */
Hai Shaloma20dcd72022-02-04 13:43:00 -08003691#ifdef ANDROID
3692 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
3693 reply_len = hostapd_ctrl_iface_driver_cmd(hapd, buf + 7, reply,
3694 reply_size);
3695#endif /* ANDROID */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003696 } else {
3697 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
3698 reply_len = 16;
3699 }
3700
3701 if (reply_len < 0) {
3702 os_memcpy(reply, "FAIL\n", 5);
3703 reply_len = 5;
3704 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003705
3706 return reply_len;
3707}
3708
3709
3710static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
3711 void *sock_ctx)
3712{
3713 struct hostapd_data *hapd = eloop_ctx;
3714 char buf[4096];
3715 int res;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003716 struct sockaddr_storage from;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003717 socklen_t fromlen = sizeof(from);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003718 char *reply, *pos = buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003719 const int reply_size = 4096;
3720 int reply_len;
3721 int level = MSG_DEBUG;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003722#ifdef CONFIG_CTRL_IFACE_UDP
Hai Shalomfdcde762020-04-02 11:19:20 -07003723 unsigned char lcookie[CTRL_IFACE_COOKIE_LEN];
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003724#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003725
3726 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
3727 (struct sockaddr *) &from, &fromlen);
3728 if (res < 0) {
3729 wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
3730 strerror(errno));
3731 return;
3732 }
3733 buf[res] = '\0';
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003734
3735 reply = os_malloc(reply_size);
3736 if (reply == NULL) {
3737 if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
3738 fromlen) < 0) {
3739 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
3740 strerror(errno));
3741 }
3742 return;
3743 }
3744
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003745#ifdef CONFIG_CTRL_IFACE_UDP
3746 if (os_strcmp(buf, "GET_COOKIE") == 0) {
3747 os_memcpy(reply, "COOKIE=", 7);
Hai Shalomfdcde762020-04-02 11:19:20 -07003748 wpa_snprintf_hex(reply + 7, 2 * CTRL_IFACE_COOKIE_LEN + 1,
3749 hapd->ctrl_iface_cookie,
3750 CTRL_IFACE_COOKIE_LEN);
3751 reply_len = 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003752 goto done;
3753 }
3754
3755 if (os_strncmp(buf, "COOKIE=", 7) != 0 ||
Hai Shalomfdcde762020-04-02 11:19:20 -07003756 hexstr2bin(buf + 7, lcookie, CTRL_IFACE_COOKIE_LEN) < 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003757 wpa_printf(MSG_DEBUG,
3758 "CTRL: No cookie in the request - drop request");
3759 os_free(reply);
3760 return;
3761 }
3762
Hai Shalomfdcde762020-04-02 11:19:20 -07003763 if (os_memcmp(hapd->ctrl_iface_cookie, lcookie,
3764 CTRL_IFACE_COOKIE_LEN) != 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003765 wpa_printf(MSG_DEBUG,
3766 "CTRL: Invalid cookie in the request - drop request");
3767 os_free(reply);
3768 return;
3769 }
3770
Hai Shalomfdcde762020-04-02 11:19:20 -07003771 pos = buf + 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003772 while (*pos == ' ')
3773 pos++;
3774#endif /* CONFIG_CTRL_IFACE_UDP */
3775
3776 if (os_strcmp(pos, "PING") == 0)
3777 level = MSG_EXCESSIVE;
3778 wpa_hexdump_ascii(level, "RX ctrl_iface", pos, res);
3779
3780 reply_len = hostapd_ctrl_iface_receive_process(hapd, pos,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003781 reply, reply_size,
3782 &from, fromlen);
3783
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003784#ifdef CONFIG_CTRL_IFACE_UDP
3785done:
3786#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003787 if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
3788 fromlen) < 0) {
3789 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
3790 strerror(errno));
3791 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003792 os_free(reply);
3793}
3794
3795
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003796#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003797static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd)
3798{
3799 char *buf;
3800 size_t len;
3801
3802 if (hapd->conf->ctrl_interface == NULL)
3803 return NULL;
3804
3805 len = os_strlen(hapd->conf->ctrl_interface) +
3806 os_strlen(hapd->conf->iface) + 2;
3807 buf = os_malloc(len);
3808 if (buf == NULL)
3809 return NULL;
3810
3811 os_snprintf(buf, len, "%s/%s",
3812 hapd->conf->ctrl_interface, hapd->conf->iface);
3813 buf[len - 1] = '\0';
3814 return buf;
3815}
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003816#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003817
3818
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07003819static void hostapd_ctrl_iface_msg_cb(void *ctx, int level,
3820 enum wpa_msg_type type,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003821 const char *txt, size_t len)
3822{
3823 struct hostapd_data *hapd = ctx;
3824 if (hapd == NULL)
3825 return;
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02003826 hostapd_ctrl_iface_send(hapd, level, type, txt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003827}
3828
3829
3830int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
3831{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003832#ifdef CONFIG_CTRL_IFACE_UDP
3833 int port = HOSTAPD_CTRL_IFACE_PORT;
3834 char p[32] = { 0 };
3835 char port_str[40], *tmp;
3836 char *pos;
3837 struct addrinfo hints = { 0 }, *res, *saveres;
3838 int n;
3839
3840 if (hapd->ctrl_sock > -1) {
3841 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
3842 return 0;
3843 }
3844
3845 if (hapd->conf->ctrl_interface == NULL)
3846 return 0;
3847
3848 pos = os_strstr(hapd->conf->ctrl_interface, "udp:");
3849 if (pos) {
3850 pos += 4;
3851 port = atoi(pos);
3852 if (port <= 0) {
3853 wpa_printf(MSG_ERROR, "Invalid ctrl_iface UDP port");
3854 goto fail;
3855 }
3856 }
3857
3858 dl_list_init(&hapd->ctrl_dst);
3859 hapd->ctrl_sock = -1;
Hai Shalomfdcde762020-04-02 11:19:20 -07003860 os_get_random(hapd->ctrl_iface_cookie, CTRL_IFACE_COOKIE_LEN);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003861
3862#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3863 hints.ai_flags = AI_PASSIVE;
3864#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3865
3866#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3867 hints.ai_family = AF_INET6;
3868#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3869 hints.ai_family = AF_INET;
3870#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3871 hints.ai_socktype = SOCK_DGRAM;
3872
3873try_again:
3874 os_snprintf(p, sizeof(p), "%d", port);
3875 n = getaddrinfo(NULL, p, &hints, &res);
3876 if (n) {
3877 wpa_printf(MSG_ERROR, "getaddrinfo(): %s", gai_strerror(n));
3878 goto fail;
3879 }
3880
3881 saveres = res;
3882 hapd->ctrl_sock = socket(res->ai_family, res->ai_socktype,
3883 res->ai_protocol);
3884 if (hapd->ctrl_sock < 0) {
3885 wpa_printf(MSG_ERROR, "socket(PF_INET): %s", strerror(errno));
3886 goto fail;
3887 }
3888
3889 if (bind(hapd->ctrl_sock, res->ai_addr, res->ai_addrlen) < 0) {
3890 port--;
3891 if ((HOSTAPD_CTRL_IFACE_PORT - port) <
3892 HOSTAPD_CTRL_IFACE_PORT_LIMIT && !pos)
3893 goto try_again;
3894 wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
3895 goto fail;
3896 }
3897
3898 freeaddrinfo(saveres);
3899
3900 os_snprintf(port_str, sizeof(port_str), "udp:%d", port);
3901 tmp = os_strdup(port_str);
3902 if (tmp) {
3903 os_free(hapd->conf->ctrl_interface);
3904 hapd->conf->ctrl_interface = tmp;
3905 }
3906 wpa_printf(MSG_DEBUG, "ctrl_iface_init UDP port: %d", port);
3907
3908 if (eloop_register_read_sock(hapd->ctrl_sock,
3909 hostapd_ctrl_iface_receive, hapd, NULL) <
3910 0) {
3911 hostapd_ctrl_iface_deinit(hapd);
3912 return -1;
3913 }
3914
3915 hapd->msg_ctx = hapd;
3916 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
3917
3918 return 0;
3919
3920fail:
3921 if (hapd->ctrl_sock >= 0)
3922 close(hapd->ctrl_sock);
3923 return -1;
3924#else /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003925 struct sockaddr_un addr;
3926 int s = -1;
3927 char *fname = NULL;
3928
Dmitry Shmidt04949592012-07-19 12:16:46 -07003929 if (hapd->ctrl_sock > -1) {
3930 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
3931 return 0;
3932 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003933
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003934 dl_list_init(&hapd->ctrl_dst);
3935
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003936 if (hapd->conf->ctrl_interface == NULL)
3937 return 0;
3938
3939 if (mkdir(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
3940 if (errno == EEXIST) {
3941 wpa_printf(MSG_DEBUG, "Using existing control "
3942 "interface directory.");
3943 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003944 wpa_printf(MSG_ERROR, "mkdir[ctrl_interface]: %s",
3945 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003946 goto fail;
3947 }
3948 }
3949
3950 if (hapd->conf->ctrl_interface_gid_set &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003951 lchown(hapd->conf->ctrl_interface, -1,
3952 hapd->conf->ctrl_interface_gid) < 0) {
3953 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003954 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003955 return -1;
3956 }
3957
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003958 if (!hapd->conf->ctrl_interface_gid_set &&
3959 hapd->iface->interfaces->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08003960 lchown(hapd->conf->ctrl_interface, -1,
3961 hapd->iface->interfaces->ctrl_iface_group) < 0) {
3962 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003963 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003964 return -1;
3965 }
3966
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003967#ifdef ANDROID
3968 /*
3969 * Android is using umask 0077 which would leave the control interface
3970 * directory without group access. This breaks things since Wi-Fi
3971 * framework assumes that this directory can be accessed by other
3972 * applications in the wifi group. Fix this by adding group access even
3973 * if umask value would prevent this.
3974 */
3975 if (chmod(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
3976 wpa_printf(MSG_ERROR, "CTRL: Could not chmod directory: %s",
3977 strerror(errno));
3978 /* Try to continue anyway */
3979 }
3980#endif /* ANDROID */
3981
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003982 if (os_strlen(hapd->conf->ctrl_interface) + 1 +
3983 os_strlen(hapd->conf->iface) >= sizeof(addr.sun_path))
3984 goto fail;
3985
3986 s = socket(PF_UNIX, SOCK_DGRAM, 0);
3987 if (s < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003988 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003989 goto fail;
3990 }
3991
3992 os_memset(&addr, 0, sizeof(addr));
3993#ifdef __FreeBSD__
3994 addr.sun_len = sizeof(addr);
3995#endif /* __FreeBSD__ */
3996 addr.sun_family = AF_UNIX;
3997 fname = hostapd_ctrl_iface_path(hapd);
3998 if (fname == NULL)
3999 goto fail;
4000 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
4001 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4002 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
4003 strerror(errno));
4004 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4005 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
4006 " allow connections - assuming it was left"
4007 "over from forced program termination");
4008 if (unlink(fname) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004009 wpa_printf(MSG_ERROR,
4010 "Could not unlink existing ctrl_iface socket '%s': %s",
4011 fname, strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004012 goto fail;
4013 }
4014 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
4015 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004016 wpa_printf(MSG_ERROR,
4017 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
4018 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004019 goto fail;
4020 }
4021 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
4022 "ctrl_iface socket '%s'", fname);
4023 } else {
4024 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
4025 "be in use - cannot override it");
4026 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
4027 "not used anymore", fname);
4028 os_free(fname);
4029 fname = NULL;
4030 goto fail;
4031 }
4032 }
4033
4034 if (hapd->conf->ctrl_interface_gid_set &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004035 lchown(fname, -1, hapd->conf->ctrl_interface_gid) < 0) {
4036 wpa_printf(MSG_ERROR, "lchown[ctrl_interface/ifname]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004037 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004038 goto fail;
4039 }
4040
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004041 if (!hapd->conf->ctrl_interface_gid_set &&
4042 hapd->iface->interfaces->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004043 lchown(fname, -1, hapd->iface->interfaces->ctrl_iface_group) < 0) {
4044 wpa_printf(MSG_ERROR, "lchown[ctrl_interface/ifname]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004045 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004046 goto fail;
4047 }
4048
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004049 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004050 wpa_printf(MSG_ERROR, "chmod[ctrl_interface/ifname]: %s",
4051 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004052 goto fail;
4053 }
4054 os_free(fname);
4055
4056 hapd->ctrl_sock = s;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004057 if (eloop_register_read_sock(s, hostapd_ctrl_iface_receive, hapd,
4058 NULL) < 0) {
4059 hostapd_ctrl_iface_deinit(hapd);
4060 return -1;
4061 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004062 hapd->msg_ctx = hapd;
4063 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4064
4065 return 0;
4066
4067fail:
4068 if (s >= 0)
4069 close(s);
4070 if (fname) {
4071 unlink(fname);
4072 os_free(fname);
4073 }
4074 return -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004075#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004076}
4077
4078
4079void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
4080{
4081 struct wpa_ctrl_dst *dst, *prev;
4082
4083 if (hapd->ctrl_sock > -1) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004084#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004085 char *fname;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004086#endif /* !CONFIG_CTRL_IFACE_UDP */
4087
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004088 eloop_unregister_read_sock(hapd->ctrl_sock);
4089 close(hapd->ctrl_sock);
4090 hapd->ctrl_sock = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004091#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004092 fname = hostapd_ctrl_iface_path(hapd);
4093 if (fname)
4094 unlink(fname);
4095 os_free(fname);
4096
4097 if (hapd->conf->ctrl_interface &&
4098 rmdir(hapd->conf->ctrl_interface) < 0) {
4099 if (errno == ENOTEMPTY) {
4100 wpa_printf(MSG_DEBUG, "Control interface "
4101 "directory not empty - leaving it "
4102 "behind");
4103 } else {
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004104 wpa_printf(MSG_ERROR,
4105 "rmdir[ctrl_interface=%s]: %s",
4106 hapd->conf->ctrl_interface,
4107 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004108 }
4109 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004110#endif /* !CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004111 }
4112
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004113 dl_list_for_each_safe(dst, prev, &hapd->ctrl_dst, struct wpa_ctrl_dst,
4114 list)
4115 os_free(dst);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004116
4117#ifdef CONFIG_TESTING_OPTIONS
4118 l2_packet_deinit(hapd->l2_test);
4119 hapd->l2_test = NULL;
4120#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004121}
4122
4123
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004124static int hostapd_ctrl_iface_add(struct hapd_interfaces *interfaces,
4125 char *buf)
4126{
4127 if (hostapd_add_iface(interfaces, buf) < 0) {
4128 wpa_printf(MSG_ERROR, "Adding interface %s failed", buf);
4129 return -1;
4130 }
4131 return 0;
4132}
4133
4134
4135static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces,
4136 char *buf)
4137{
4138 if (hostapd_remove_iface(interfaces, buf) < 0) {
4139 wpa_printf(MSG_ERROR, "Removing interface %s failed", buf);
4140 return -1;
4141 }
4142 return 0;
4143}
4144
4145
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004146static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004147 struct sockaddr_storage *from,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004148 socklen_t fromlen, char *input)
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004149{
Roshan Pius3a1667e2018-07-03 15:17:14 -07004150 return ctrl_iface_attach(&interfaces->global_ctrl_dst, from, fromlen,
4151 input);
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004152}
4153
4154
4155static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces *interfaces,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004156 struct sockaddr_storage *from,
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004157 socklen_t fromlen)
4158{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004159 return ctrl_iface_detach(&interfaces->global_ctrl_dst, from, fromlen);
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004160}
4161
4162
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004163static void hostapd_ctrl_iface_flush(struct hapd_interfaces *interfaces)
4164{
4165#ifdef CONFIG_WPS_TESTING
4166 wps_version_number = 0x20;
Hai Shaloma20dcd72022-02-04 13:43:00 -08004167 wps_testing_stub_cred = 0;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004168 wps_corrupt_pkhash = 0;
4169#endif /* CONFIG_WPS_TESTING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004170
4171#ifdef CONFIG_TESTING_OPTIONS
4172#ifdef CONFIG_DPP
4173 dpp_test = DPP_TEST_DISABLED;
Hai Shaloma20dcd72022-02-04 13:43:00 -08004174#ifdef CONFIG_DPP3
4175 dpp_version_override = 3;
4176#elif defined(CONFIG_DPP2)
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004177 dpp_version_override = 2;
4178#else /* CONFIG_DPP2 */
4179 dpp_version_override = 1;
4180#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004181#endif /* CONFIG_DPP */
4182#endif /* CONFIG_TESTING_OPTIONS */
4183
4184#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07004185 dpp_global_clear(interfaces->dpp);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004186#endif /* CONFIG_DPP */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004187}
4188
4189
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004190#ifdef CONFIG_FST
4191
4192static int
4193hostapd_global_ctrl_iface_fst_attach(struct hapd_interfaces *interfaces,
4194 const char *cmd)
4195{
4196 char ifname[IFNAMSIZ + 1];
4197 struct fst_iface_cfg cfg;
4198 struct hostapd_data *hapd;
4199 struct fst_wpa_obj iface_obj;
4200
4201 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
4202 hapd = hostapd_get_iface(interfaces, ifname);
4203 if (hapd) {
4204 if (hapd->iface->fst) {
4205 wpa_printf(MSG_INFO, "FST: Already attached");
4206 return -1;
4207 }
4208 fst_hostapd_fill_iface_obj(hapd, &iface_obj);
4209 hapd->iface->fst = fst_attach(ifname, hapd->own_addr,
4210 &iface_obj, &cfg);
4211 if (hapd->iface->fst)
4212 return 0;
4213 }
4214 }
4215
4216 return -EINVAL;
4217}
4218
4219
4220static int
4221hostapd_global_ctrl_iface_fst_detach(struct hapd_interfaces *interfaces,
4222 const char *cmd)
4223{
4224 char ifname[IFNAMSIZ + 1];
4225 struct hostapd_data * hapd;
4226
4227 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
4228 hapd = hostapd_get_iface(interfaces, ifname);
4229 if (hapd) {
4230 if (!fst_iface_detach(ifname)) {
4231 hapd->iface->fst = NULL;
4232 hapd->iface->fst_ies = NULL;
4233 return 0;
4234 }
4235 }
4236 }
4237
4238 return -EINVAL;
4239}
4240
4241#endif /* CONFIG_FST */
4242
4243
4244static struct hostapd_data *
4245hostapd_interfaces_get_hapd(struct hapd_interfaces *interfaces,
4246 const char *ifname)
4247{
4248 size_t i, j;
4249
4250 for (i = 0; i < interfaces->count; i++) {
4251 struct hostapd_iface *iface = interfaces->iface[i];
4252
4253 for (j = 0; j < iface->num_bss; j++) {
4254 struct hostapd_data *hapd;
4255
4256 hapd = iface->bss[j];
4257 if (os_strcmp(ifname, hapd->conf->iface) == 0)
4258 return hapd;
4259 }
4260 }
4261
4262 return NULL;
4263}
4264
4265
4266static int hostapd_ctrl_iface_dup_param(struct hostapd_data *src_hapd,
4267 struct hostapd_data *dst_hapd,
4268 const char *param)
4269{
4270 int res;
4271 char *value;
4272
4273 value = os_zalloc(HOSTAPD_CLI_DUP_VALUE_MAX_LEN);
4274 if (!value) {
4275 wpa_printf(MSG_ERROR,
4276 "DUP: cannot allocate buffer to stringify %s",
4277 param);
4278 goto error_return;
4279 }
4280
4281 if (os_strcmp(param, "wpa") == 0) {
4282 os_snprintf(value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN, "%d",
4283 src_hapd->conf->wpa);
4284 } else if (os_strcmp(param, "wpa_key_mgmt") == 0 &&
4285 src_hapd->conf->wpa_key_mgmt) {
4286 res = hostapd_ctrl_iface_get_key_mgmt(
4287 src_hapd, value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN);
4288 if (os_snprintf_error(HOSTAPD_CLI_DUP_VALUE_MAX_LEN, res))
4289 goto error_stringify;
4290 } else if (os_strcmp(param, "wpa_pairwise") == 0 &&
4291 src_hapd->conf->wpa_pairwise) {
4292 res = wpa_write_ciphers(value,
4293 value + HOSTAPD_CLI_DUP_VALUE_MAX_LEN,
4294 src_hapd->conf->wpa_pairwise, " ");
4295 if (res < 0)
4296 goto error_stringify;
4297 } else if (os_strcmp(param, "rsn_pairwise") == 0 &&
4298 src_hapd->conf->rsn_pairwise) {
4299 res = wpa_write_ciphers(value,
4300 value + HOSTAPD_CLI_DUP_VALUE_MAX_LEN,
4301 src_hapd->conf->rsn_pairwise, " ");
4302 if (res < 0)
4303 goto error_stringify;
4304 } else if (os_strcmp(param, "wpa_passphrase") == 0 &&
4305 src_hapd->conf->ssid.wpa_passphrase) {
4306 os_snprintf(value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN, "%s",
4307 src_hapd->conf->ssid.wpa_passphrase);
4308 } else if (os_strcmp(param, "wpa_psk") == 0 &&
4309 src_hapd->conf->ssid.wpa_psk_set) {
4310 wpa_snprintf_hex(value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN,
4311 src_hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
4312 } else {
4313 wpa_printf(MSG_WARNING, "DUP: %s cannot be duplicated", param);
4314 goto error_return;
4315 }
4316
4317 res = hostapd_set_iface(dst_hapd->iconf, dst_hapd->conf, param, value);
4318 os_free(value);
4319 return res;
4320
4321error_stringify:
4322 wpa_printf(MSG_ERROR, "DUP: cannot stringify %s", param);
4323error_return:
4324 os_free(value);
4325 return -1;
4326}
4327
4328
4329static int
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004330hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces *interfaces,
4331 const char *input,
4332 char *reply, int reply_size)
4333{
4334 size_t i, j;
4335 int res;
4336 char *pos, *end;
4337 struct hostapd_iface *iface;
4338 int show_ctrl = 0;
4339
4340 if (input)
4341 show_ctrl = !!os_strstr(input, "ctrl");
4342
4343 pos = reply;
4344 end = reply + reply_size;
4345
4346 for (i = 0; i < interfaces->count; i++) {
4347 iface = interfaces->iface[i];
4348
4349 for (j = 0; j < iface->num_bss; j++) {
4350 struct hostapd_bss_config *conf;
4351
4352 conf = iface->conf->bss[j];
4353 if (show_ctrl)
4354 res = os_snprintf(pos, end - pos,
4355 "%s ctrl_iface=%s\n",
4356 conf->iface,
4357 conf->ctrl_interface ?
4358 conf->ctrl_interface : "N/A");
4359 else
4360 res = os_snprintf(pos, end - pos, "%s\n",
4361 conf->iface);
4362 if (os_snprintf_error(end - pos, res)) {
4363 *pos = '\0';
4364 return pos - reply;
4365 }
4366 pos += res;
4367 }
4368 }
4369
4370 return pos - reply;
4371}
4372
4373
4374static int
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004375hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces *interfaces,
4376 char *cmd)
4377{
4378 char *p_start = cmd, *p_end;
4379 struct hostapd_data *src_hapd, *dst_hapd;
4380
4381 /* cmd: "<src ifname> <dst ifname> <variable name> */
4382
4383 p_end = os_strchr(p_start, ' ');
4384 if (!p_end) {
4385 wpa_printf(MSG_ERROR, "DUP: no src ifname found in cmd: '%s'",
4386 cmd);
4387 return -1;
4388 }
4389
4390 *p_end = '\0';
4391 src_hapd = hostapd_interfaces_get_hapd(interfaces, p_start);
4392 if (!src_hapd) {
4393 wpa_printf(MSG_ERROR, "DUP: no src ifname found: '%s'",
4394 p_start);
4395 return -1;
4396 }
4397
4398 p_start = p_end + 1;
4399 p_end = os_strchr(p_start, ' ');
4400 if (!p_end) {
4401 wpa_printf(MSG_ERROR, "DUP: no dst ifname found in cmd: '%s'",
4402 cmd);
4403 return -1;
4404 }
4405
4406 *p_end = '\0';
4407 dst_hapd = hostapd_interfaces_get_hapd(interfaces, p_start);
4408 if (!dst_hapd) {
4409 wpa_printf(MSG_ERROR, "DUP: no dst ifname found: '%s'",
4410 p_start);
4411 return -1;
4412 }
4413
4414 p_start = p_end + 1;
4415 return hostapd_ctrl_iface_dup_param(src_hapd, dst_hapd, p_start);
4416}
4417
4418
4419static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces *interfaces,
4420 const char *ifname,
4421 char *buf, char *reply,
4422 int reply_size,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004423 struct sockaddr_storage *from,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004424 socklen_t fromlen)
4425{
4426 struct hostapd_data *hapd;
4427
4428 hapd = hostapd_interfaces_get_hapd(interfaces, ifname);
4429 if (hapd == NULL) {
4430 int res;
4431
4432 res = os_snprintf(reply, reply_size, "FAIL-NO-IFNAME-MATCH\n");
4433 if (os_snprintf_error(reply_size, res))
4434 return -1;
4435 return res;
4436 }
4437
4438 return hostapd_ctrl_iface_receive_process(hapd, buf, reply,reply_size,
4439 from, fromlen);
4440}
4441
4442
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004443static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
4444 void *sock_ctx)
4445{
Hai Shalomfdcde762020-04-02 11:19:20 -07004446 struct hapd_interfaces *interfaces = eloop_ctx;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004447 char buffer[256], *buf = buffer;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004448 int res;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004449 struct sockaddr_storage from;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004450 socklen_t fromlen = sizeof(from);
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004451 char *reply;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004452 int reply_len;
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004453 const int reply_size = 4096;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004454#ifdef CONFIG_CTRL_IFACE_UDP
Hai Shalomfdcde762020-04-02 11:19:20 -07004455 unsigned char lcookie[CTRL_IFACE_COOKIE_LEN];
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004456#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004457
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004458 res = recvfrom(sock, buffer, sizeof(buffer) - 1, 0,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004459 (struct sockaddr *) &from, &fromlen);
4460 if (res < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004461 wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
4462 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004463 return;
4464 }
4465 buf[res] = '\0';
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004466 wpa_printf(MSG_DEBUG, "Global ctrl_iface command: %s", buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004467
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004468 reply = os_malloc(reply_size);
4469 if (reply == NULL) {
4470 if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
4471 fromlen) < 0) {
4472 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
4473 strerror(errno));
4474 }
4475 return;
4476 }
4477
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004478 os_memcpy(reply, "OK\n", 3);
4479 reply_len = 3;
4480
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004481#ifdef CONFIG_CTRL_IFACE_UDP
4482 if (os_strcmp(buf, "GET_COOKIE") == 0) {
4483 os_memcpy(reply, "COOKIE=", 7);
Hai Shalomfdcde762020-04-02 11:19:20 -07004484 wpa_snprintf_hex(reply + 7, 2 * CTRL_IFACE_COOKIE_LEN + 1,
4485 interfaces->ctrl_iface_cookie,
4486 CTRL_IFACE_COOKIE_LEN);
4487 reply_len = 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004488 goto send_reply;
4489 }
4490
4491 if (os_strncmp(buf, "COOKIE=", 7) != 0 ||
Hai Shalomfdcde762020-04-02 11:19:20 -07004492 hexstr2bin(buf + 7, lcookie, CTRL_IFACE_COOKIE_LEN) < 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004493 wpa_printf(MSG_DEBUG,
4494 "CTRL: No cookie in the request - drop request");
4495 os_free(reply);
4496 return;
4497 }
4498
Hai Shalomfdcde762020-04-02 11:19:20 -07004499 if (os_memcmp(interfaces->ctrl_iface_cookie, lcookie,
4500 CTRL_IFACE_COOKIE_LEN) != 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004501 wpa_printf(MSG_DEBUG,
4502 "CTRL: Invalid cookie in the request - drop request");
4503 os_free(reply);
4504 return;
4505 }
4506
Hai Shalomfdcde762020-04-02 11:19:20 -07004507 buf += 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004508 while (*buf == ' ')
4509 buf++;
4510#endif /* CONFIG_CTRL_IFACE_UDP */
4511
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004512 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
4513 char *pos = os_strchr(buf + 7, ' ');
4514
4515 if (pos) {
4516 *pos++ = '\0';
4517 reply_len = hostapd_global_ctrl_iface_ifname(
4518 interfaces, buf + 7, pos, reply, reply_size,
4519 &from, fromlen);
4520 goto send_reply;
4521 }
4522 }
4523
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004524 if (os_strcmp(buf, "PING") == 0) {
4525 os_memcpy(reply, "PONG\n", 5);
4526 reply_len = 5;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004527 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
4528 if (wpa_debug_reopen_file() < 0)
4529 reply_len = -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004530 } else if (os_strcmp(buf, "FLUSH") == 0) {
4531 hostapd_ctrl_iface_flush(interfaces);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004532 } else if (os_strncmp(buf, "ADD ", 4) == 0) {
4533 if (hostapd_ctrl_iface_add(interfaces, buf + 4) < 0)
4534 reply_len = -1;
4535 } else if (os_strncmp(buf, "REMOVE ", 7) == 0) {
4536 if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0)
4537 reply_len = -1;
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004538 } else if (os_strcmp(buf, "ATTACH") == 0) {
4539 if (hostapd_global_ctrl_iface_attach(interfaces, &from,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004540 fromlen, NULL))
4541 reply_len = -1;
4542 } else if (os_strncmp(buf, "ATTACH ", 7) == 0) {
4543 if (hostapd_global_ctrl_iface_attach(interfaces, &from,
4544 fromlen, buf + 7))
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004545 reply_len = -1;
4546 } else if (os_strcmp(buf, "DETACH") == 0) {
4547 if (hostapd_global_ctrl_iface_detach(interfaces, &from,
4548 fromlen))
4549 reply_len = -1;
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -08004550#ifdef CONFIG_MODULE_TESTS
4551 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -08004552 if (hapd_module_tests() < 0)
4553 reply_len = -1;
4554#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004555#ifdef CONFIG_FST
4556 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
4557 if (!hostapd_global_ctrl_iface_fst_attach(interfaces, buf + 11))
4558 reply_len = os_snprintf(reply, reply_size, "OK\n");
4559 else
4560 reply_len = -1;
4561 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
4562 if (!hostapd_global_ctrl_iface_fst_detach(interfaces, buf + 11))
4563 reply_len = os_snprintf(reply, reply_size, "OK\n");
4564 else
4565 reply_len = -1;
4566 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
4567 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
4568#endif /* CONFIG_FST */
4569 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
4570 if (!hostapd_global_ctrl_iface_dup_network(interfaces,
4571 buf + 12))
4572 reply_len = os_snprintf(reply, reply_size, "OK\n");
4573 else
4574 reply_len = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004575 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
4576 reply_len = hostapd_global_ctrl_iface_interfaces(
4577 interfaces, buf + 10, reply, sizeof(buffer));
4578 } else if (os_strcmp(buf, "TERMINATE") == 0) {
4579 eloop_terminate();
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004580 } else {
4581 wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
4582 "ignored");
4583 reply_len = -1;
4584 }
4585
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004586send_reply:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004587 if (reply_len < 0) {
4588 os_memcpy(reply, "FAIL\n", 5);
4589 reply_len = 5;
4590 }
4591
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004592 if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
4593 fromlen) < 0) {
4594 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
4595 strerror(errno));
4596 }
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004597 os_free(reply);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004598}
4599
4600
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004601#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004602static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces *interface)
4603{
4604 char *buf;
4605 size_t len;
4606
4607 if (interface->global_iface_path == NULL)
4608 return NULL;
4609
4610 len = os_strlen(interface->global_iface_path) +
4611 os_strlen(interface->global_iface_name) + 2;
4612 buf = os_malloc(len);
4613 if (buf == NULL)
4614 return NULL;
4615
4616 os_snprintf(buf, len, "%s/%s", interface->global_iface_path,
4617 interface->global_iface_name);
4618 buf[len - 1] = '\0';
4619 return buf;
4620}
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004621#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004622
4623
4624int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
4625{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004626#ifdef CONFIG_CTRL_IFACE_UDP
4627 int port = HOSTAPD_GLOBAL_CTRL_IFACE_PORT;
4628 char p[32] = { 0 };
4629 char *pos;
4630 struct addrinfo hints = { 0 }, *res, *saveres;
4631 int n;
4632
4633 if (interface->global_ctrl_sock > -1) {
4634 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
4635 return 0;
4636 }
4637
4638 if (interface->global_iface_path == NULL)
4639 return 0;
4640
4641 pos = os_strstr(interface->global_iface_path, "udp:");
4642 if (pos) {
4643 pos += 4;
4644 port = atoi(pos);
4645 if (port <= 0) {
4646 wpa_printf(MSG_ERROR, "Invalid global ctrl UDP port");
4647 goto fail;
4648 }
4649 }
4650
Hai Shalomfdcde762020-04-02 11:19:20 -07004651 os_get_random(interface->ctrl_iface_cookie, CTRL_IFACE_COOKIE_LEN);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004652
4653#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
4654 hints.ai_flags = AI_PASSIVE;
4655#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
4656
4657#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
4658 hints.ai_family = AF_INET6;
4659#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4660 hints.ai_family = AF_INET;
4661#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4662 hints.ai_socktype = SOCK_DGRAM;
4663
4664try_again:
4665 os_snprintf(p, sizeof(p), "%d", port);
4666 n = getaddrinfo(NULL, p, &hints, &res);
4667 if (n) {
4668 wpa_printf(MSG_ERROR, "getaddrinfo(): %s", gai_strerror(n));
4669 goto fail;
4670 }
4671
4672 saveres = res;
4673 interface->global_ctrl_sock = socket(res->ai_family, res->ai_socktype,
4674 res->ai_protocol);
4675 if (interface->global_ctrl_sock < 0) {
4676 wpa_printf(MSG_ERROR, "socket(PF_INET): %s", strerror(errno));
4677 goto fail;
4678 }
4679
4680 if (bind(interface->global_ctrl_sock, res->ai_addr, res->ai_addrlen) <
4681 0) {
4682 port++;
4683 if ((port - HOSTAPD_GLOBAL_CTRL_IFACE_PORT) <
4684 HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT && !pos)
4685 goto try_again;
4686 wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
4687 goto fail;
4688 }
4689
4690 freeaddrinfo(saveres);
4691
4692 wpa_printf(MSG_DEBUG, "global ctrl_iface_init UDP port: %d", port);
4693
4694 if (eloop_register_read_sock(interface->global_ctrl_sock,
4695 hostapd_global_ctrl_iface_receive,
4696 interface, NULL) < 0) {
4697 hostapd_global_ctrl_iface_deinit(interface);
4698 return -1;
4699 }
4700
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004701 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4702
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004703 return 0;
4704
4705fail:
4706 if (interface->global_ctrl_sock >= 0)
4707 close(interface->global_ctrl_sock);
4708 return -1;
4709#else /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004710 struct sockaddr_un addr;
4711 int s = -1;
4712 char *fname = NULL;
4713
4714 if (interface->global_iface_path == NULL) {
4715 wpa_printf(MSG_DEBUG, "ctrl_iface not configured!");
4716 return 0;
4717 }
4718
4719 if (mkdir(interface->global_iface_path, S_IRWXU | S_IRWXG) < 0) {
4720 if (errno == EEXIST) {
4721 wpa_printf(MSG_DEBUG, "Using existing control "
4722 "interface directory.");
4723 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004724 wpa_printf(MSG_ERROR, "mkdir[ctrl_interface]: %s",
4725 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004726 goto fail;
4727 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004728 } else if (interface->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004729 lchown(interface->global_iface_path, -1,
4730 interface->ctrl_iface_group) < 0) {
4731 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004732 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004733 goto fail;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004734 }
4735
4736 if (os_strlen(interface->global_iface_path) + 1 +
4737 os_strlen(interface->global_iface_name) >= sizeof(addr.sun_path))
4738 goto fail;
4739
4740 s = socket(PF_UNIX, SOCK_DGRAM, 0);
4741 if (s < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004742 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004743 goto fail;
4744 }
4745
4746 os_memset(&addr, 0, sizeof(addr));
4747#ifdef __FreeBSD__
4748 addr.sun_len = sizeof(addr);
4749#endif /* __FreeBSD__ */
4750 addr.sun_family = AF_UNIX;
4751 fname = hostapd_global_ctrl_iface_path(interface);
4752 if (fname == NULL)
4753 goto fail;
4754 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
4755 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4756 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
4757 strerror(errno));
4758 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4759 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
4760 " allow connections - assuming it was left"
4761 "over from forced program termination");
4762 if (unlink(fname) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004763 wpa_printf(MSG_ERROR,
4764 "Could not unlink existing ctrl_iface socket '%s': %s",
4765 fname, strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004766 goto fail;
4767 }
4768 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
4769 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004770 wpa_printf(MSG_ERROR, "bind(PF_UNIX): %s",
4771 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004772 goto fail;
4773 }
4774 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
4775 "ctrl_iface socket '%s'", fname);
4776 } else {
4777 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
4778 "be in use - cannot override it");
4779 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
4780 "not used anymore", fname);
4781 os_free(fname);
4782 fname = NULL;
4783 goto fail;
4784 }
4785 }
4786
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004787 if (interface->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004788 lchown(fname, -1, interface->ctrl_iface_group) < 0) {
4789 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004790 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004791 goto fail;
4792 }
4793
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004794 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004795 wpa_printf(MSG_ERROR, "chmod[ctrl_interface/ifname]: %s",
4796 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004797 goto fail;
4798 }
4799 os_free(fname);
4800
4801 interface->global_ctrl_sock = s;
4802 eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
4803 interface, NULL);
4804
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004805 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4806
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004807 return 0;
4808
4809fail:
4810 if (s >= 0)
4811 close(s);
4812 if (fname) {
4813 unlink(fname);
4814 os_free(fname);
4815 }
4816 return -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004817#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004818}
4819
4820
4821void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interfaces)
4822{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004823#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004824 char *fname = NULL;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004825#endif /* CONFIG_CTRL_IFACE_UDP */
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004826 struct wpa_ctrl_dst *dst, *prev;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004827
4828 if (interfaces->global_ctrl_sock > -1) {
4829 eloop_unregister_read_sock(interfaces->global_ctrl_sock);
4830 close(interfaces->global_ctrl_sock);
4831 interfaces->global_ctrl_sock = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004832#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004833 fname = hostapd_global_ctrl_iface_path(interfaces);
4834 if (fname) {
4835 unlink(fname);
4836 os_free(fname);
4837 }
4838
4839 if (interfaces->global_iface_path &&
4840 rmdir(interfaces->global_iface_path) < 0) {
4841 if (errno == ENOTEMPTY) {
4842 wpa_printf(MSG_DEBUG, "Control interface "
4843 "directory not empty - leaving it "
4844 "behind");
4845 } else {
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004846 wpa_printf(MSG_ERROR,
4847 "rmdir[ctrl_interface=%s]: %s",
4848 interfaces->global_iface_path,
4849 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004850 }
4851 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004852#endif /* CONFIG_CTRL_IFACE_UDP */
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004853 }
4854
4855 os_free(interfaces->global_iface_path);
4856 interfaces->global_iface_path = NULL;
4857
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004858 dl_list_for_each_safe(dst, prev, &interfaces->global_ctrl_dst,
4859 struct wpa_ctrl_dst, list)
4860 os_free(dst);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004861}
4862
4863
Roshan Pius3a1667e2018-07-03 15:17:14 -07004864static int hostapd_ctrl_check_event_enabled(struct wpa_ctrl_dst *dst,
4865 const char *buf)
4866{
4867 /* Enable Probe Request events based on explicit request.
4868 * Other events are enabled by default.
4869 */
4870 if (str_starts(buf, RX_PROBE_REQUEST))
4871 return !!(dst->events & WPA_EVENT_RX_PROBE_REQUEST);
4872 return 1;
4873}
4874
4875
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004876static void hostapd_ctrl_iface_send_internal(int sock, struct dl_list *ctrl_dst,
4877 const char *ifname, int level,
4878 const char *buf, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004879{
4880 struct wpa_ctrl_dst *dst, *next;
4881 struct msghdr msg;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004882 int idx, res;
4883 struct iovec io[5];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004884 char levelstr[10];
4885
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004886 if (sock < 0 || dl_list_empty(ctrl_dst))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004887 return;
4888
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004889 res = os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
4890 if (os_snprintf_error(sizeof(levelstr), res))
4891 return;
4892 idx = 0;
4893 if (ifname) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004894 io[idx].iov_base = "IFNAME=";
4895 io[idx].iov_len = 7;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004896 idx++;
4897 io[idx].iov_base = (char *) ifname;
4898 io[idx].iov_len = os_strlen(ifname);
4899 idx++;
4900 io[idx].iov_base = " ";
4901 io[idx].iov_len = 1;
4902 idx++;
4903 }
4904 io[idx].iov_base = levelstr;
4905 io[idx].iov_len = os_strlen(levelstr);
4906 idx++;
4907 io[idx].iov_base = (char *) buf;
4908 io[idx].iov_len = len;
4909 idx++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004910 os_memset(&msg, 0, sizeof(msg));
4911 msg.msg_iov = io;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004912 msg.msg_iovlen = idx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004913
4914 idx = 0;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004915 dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07004916 if ((level >= dst->debug_level) &&
4917 hostapd_ctrl_check_event_enabled(dst, buf)) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004918 sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor send",
4919 &dst->addr, dst->addrlen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004920 msg.msg_name = &dst->addr;
4921 msg.msg_namelen = dst->addrlen;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004922 if (sendmsg(sock, &msg, 0) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004923 int _errno = errno;
4924 wpa_printf(MSG_INFO, "CTRL_IFACE monitor[%d]: "
4925 "%d - %s",
4926 idx, errno, strerror(errno));
4927 dst->errors++;
4928 if (dst->errors > 10 || _errno == ENOENT) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004929 ctrl_iface_detach(ctrl_dst,
4930 &dst->addr,
4931 dst->addrlen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004932 }
4933 } else
4934 dst->errors = 0;
4935 }
4936 idx++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004937 }
4938}
4939
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004940
4941static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
4942 enum wpa_msg_type type,
4943 const char *buf, size_t len)
4944{
4945 if (type != WPA_MSG_NO_GLOBAL) {
4946 hostapd_ctrl_iface_send_internal(
4947 hapd->iface->interfaces->global_ctrl_sock,
4948 &hapd->iface->interfaces->global_ctrl_dst,
4949 type != WPA_MSG_PER_INTERFACE ?
4950 NULL : hapd->conf->iface,
4951 level, buf, len);
4952 }
4953
4954 if (type != WPA_MSG_ONLY_GLOBAL) {
4955 hostapd_ctrl_iface_send_internal(
4956 hapd->ctrl_sock, &hapd->ctrl_dst,
4957 NULL, level, buf, len);
4958 }
4959}
4960
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004961#endif /* CONFIG_NATIVE_WINDOWS */