blob: 02b41fd9df1ce2bcc21d3b84a57577de40329cfc [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / UNIX domain socket -based control interface
Roshan Pius3a1667e2018-07-03 15:17:14 -07003 * Copyright (c) 2004-2018, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#ifndef CONFIG_NATIVE_WINDOWS
12
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080013#ifdef CONFIG_TESTING_OPTIONS
Hai Shalomfdcde762020-04-02 11:19:20 -070014#ifdef __NetBSD__
15#include <net/if_ether.h>
16#else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080017#include <net/ethernet.h>
Hai Shalomfdcde762020-04-02 11:19:20 -070018#endif
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080019#include <netinet/ip.h>
20#endif /* CONFIG_TESTING_OPTIONS */
21
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include <sys/un.h>
23#include <sys/stat.h>
24#include <stddef.h>
25
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080026#ifdef CONFIG_CTRL_IFACE_UDP
27#include <netdb.h>
28#endif /* CONFIG_CTRL_IFACE_UDP */
29
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "utils/common.h"
31#include "utils/eloop.h"
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -070032#include "utils/module_tests.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "common/version.h"
34#include "common/ieee802_11_defs.h"
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080035#include "common/ctrl_iface_common.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070036#ifdef CONFIG_DPP
37#include "common/dpp.h"
38#endif /* CONFIG_DPP */
39#include "common/wpa_ctrl.h"
Dmitry Shmidtff787d52015-01-12 13:01:47 -080040#include "crypto/tls.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070041#include "drivers/driver.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080042#include "eapol_auth/eapol_auth_sm.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043#include "radius/radius_client.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080044#include "radius/radius_server.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080045#include "l2_packet/l2_packet.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#include "ap/hostapd.h"
47#include "ap/ap_config.h"
48#include "ap/ieee802_1x.h"
49#include "ap/wpa_auth.h"
Hai Shalom899fcc72020-10-19 14:38:18 -070050#include "ap/pmksa_cache_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070051#include "ap/ieee802_11.h"
52#include "ap/sta_info.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070053#include "ap/wps_hostapd.h"
54#include "ap/ctrl_iface_ap.h"
55#include "ap/ap_drv_ops.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080056#include "ap/hs20.h"
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -080057#include "ap/wnm_ap.h"
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -070058#include "ap/wpa_auth.h"
Dmitry Shmidt7f656022015-02-25 14:36:37 -080059#include "ap/beacon.h"
Dmitry Shmidt849734c2016-05-27 09:59:01 -070060#include "ap/neighbor_db.h"
61#include "ap/rrm.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070062#include "ap/dpp_hostapd.h"
Hai Shalomfdcde762020-04-02 11:19:20 -070063#include "ap/dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070064#include "wps/wps_defs.h"
65#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080066#include "fst/fst_ctrl_iface.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070067#include "config_file.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070068#include "ctrl_iface.h"
69
70
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080071#define HOSTAPD_CLI_DUP_VALUE_MAX_LEN 256
72
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080073#ifdef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080074#define HOSTAPD_CTRL_IFACE_PORT 8877
75#define HOSTAPD_CTRL_IFACE_PORT_LIMIT 50
76#define HOSTAPD_GLOBAL_CTRL_IFACE_PORT 8878
77#define HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT 50
78#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070079
80static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
Anton Nayshtutf715e8d2014-11-16 16:52:49 +020081 enum wpa_msg_type type,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070082 const char *buf, size_t len);
83
84
85static int hostapd_ctrl_iface_attach(struct hostapd_data *hapd,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080086 struct sockaddr_storage *from,
Roshan Pius3a1667e2018-07-03 15:17:14 -070087 socklen_t fromlen, const char *input)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070088{
Roshan Pius3a1667e2018-07-03 15:17:14 -070089 return ctrl_iface_attach(&hapd->ctrl_dst, from, fromlen, input);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070090}
91
92
93static int hostapd_ctrl_iface_detach(struct hostapd_data *hapd,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080094 struct sockaddr_storage *from,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070095 socklen_t fromlen)
96{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -080097 return ctrl_iface_detach(&hapd->ctrl_dst, from, fromlen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070098}
99
100
101static int hostapd_ctrl_iface_level(struct hostapd_data *hapd,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800102 struct sockaddr_storage *from,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103 socklen_t fromlen,
104 char *level)
105{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800106 return ctrl_iface_level(&hapd->ctrl_dst, from, fromlen, level);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700107}
108
109
110static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
111 const char *txtaddr)
112{
113 u8 addr[ETH_ALEN];
114 struct sta_info *sta;
115
116 wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);
117
118 if (hwaddr_aton(txtaddr, addr))
119 return -1;
120
121 sta = ap_get_sta(hapd, addr);
122 if (sta)
123 return 0;
124
125 wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
126 "notification", MAC2STR(addr));
127 sta = ap_sta_add(hapd, addr);
128 if (sta == NULL)
129 return -1;
130
131 hostapd_new_assoc_sta(hapd, sta, 0);
132 return 0;
133}
134
135
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700136#ifdef NEED_AP_MLME
137static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
138 const char *txtaddr)
139{
140 u8 addr[ETH_ALEN];
141 u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];
142
143 wpa_printf(MSG_DEBUG, "CTRL_IFACE SA_QUERY %s", txtaddr);
144
145 if (hwaddr_aton(txtaddr, addr) ||
146 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0)
147 return -1;
148
149 ieee802_11_send_sa_query_req(hapd, addr, trans_id);
150
151 return 0;
152}
153#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154
155
156#ifdef CONFIG_WPS
157static int hostapd_ctrl_iface_wps_pin(struct hostapd_data *hapd, char *txt)
158{
159 char *pin = os_strchr(txt, ' ');
160 char *timeout_txt;
161 int timeout;
162 u8 addr_buf[ETH_ALEN], *addr = NULL;
163 char *pos;
164
165 if (pin == NULL)
166 return -1;
167 *pin++ = '\0';
168
169 timeout_txt = os_strchr(pin, ' ');
170 if (timeout_txt) {
171 *timeout_txt++ = '\0';
172 timeout = atoi(timeout_txt);
173 pos = os_strchr(timeout_txt, ' ');
174 if (pos) {
175 *pos++ = '\0';
176 if (hwaddr_aton(pos, addr_buf) == 0)
177 addr = addr_buf;
178 }
179 } else
180 timeout = 0;
181
182 return hostapd_wps_add_pin(hapd, addr, txt, pin, timeout);
183}
184
185
186static int hostapd_ctrl_iface_wps_check_pin(
187 struct hostapd_data *hapd, char *cmd, char *buf, size_t buflen)
188{
189 char pin[9];
190 size_t len;
191 char *pos;
192 int ret;
193
194 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
195 (u8 *) cmd, os_strlen(cmd));
196 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
197 if (*pos < '0' || *pos > '9')
198 continue;
199 pin[len++] = *pos;
200 if (len == 9) {
201 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
202 return -1;
203 }
204 }
205 if (len != 4 && len != 8) {
206 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
207 return -1;
208 }
209 pin[len] = '\0';
210
211 if (len == 8) {
212 unsigned int pin_val;
213 pin_val = atoi(pin);
214 if (!wps_pin_valid(pin_val)) {
215 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
216 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800217 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700218 return -1;
219 return ret;
220 }
221 }
222
223 ret = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800224 if (os_snprintf_error(buflen, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700225 return -1;
226
227 return ret;
228}
229
230
Dmitry Shmidt04949592012-07-19 12:16:46 -0700231#ifdef CONFIG_WPS_NFC
232static int hostapd_ctrl_iface_wps_nfc_tag_read(struct hostapd_data *hapd,
233 char *pos)
234{
235 size_t len;
236 struct wpabuf *buf;
237 int ret;
238
239 len = os_strlen(pos);
240 if (len & 0x01)
241 return -1;
242 len /= 2;
243
244 buf = wpabuf_alloc(len);
245 if (buf == NULL)
246 return -1;
247 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
248 wpabuf_free(buf);
249 return -1;
250 }
251
252 ret = hostapd_wps_nfc_tag_read(hapd, buf);
253 wpabuf_free(buf);
254
255 return ret;
256}
257
258
259static int hostapd_ctrl_iface_wps_nfc_config_token(struct hostapd_data *hapd,
260 char *cmd, char *reply,
261 size_t max_len)
262{
263 int ndef;
264 struct wpabuf *buf;
265 int res;
266
267 if (os_strcmp(cmd, "WPS") == 0)
268 ndef = 0;
269 else if (os_strcmp(cmd, "NDEF") == 0)
270 ndef = 1;
271 else
272 return -1;
273
274 buf = hostapd_wps_nfc_config_token(hapd, ndef);
275 if (buf == NULL)
276 return -1;
277
278 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
279 wpabuf_len(buf));
280 reply[res++] = '\n';
281 reply[res] = '\0';
282
283 wpabuf_free(buf);
284
285 return res;
286}
287
288
289static int hostapd_ctrl_iface_wps_nfc_token_gen(struct hostapd_data *hapd,
290 char *reply, size_t max_len,
291 int ndef)
292{
293 struct wpabuf *buf;
294 int res;
295
296 buf = hostapd_wps_nfc_token_gen(hapd, ndef);
297 if (buf == NULL)
298 return -1;
299
300 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
301 wpabuf_len(buf));
302 reply[res++] = '\n';
303 reply[res] = '\0';
304
305 wpabuf_free(buf);
306
307 return res;
308}
309
310
311static int hostapd_ctrl_iface_wps_nfc_token(struct hostapd_data *hapd,
312 char *cmd, char *reply,
313 size_t max_len)
314{
315 if (os_strcmp(cmd, "WPS") == 0)
316 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
317 max_len, 0);
318
319 if (os_strcmp(cmd, "NDEF") == 0)
320 return hostapd_ctrl_iface_wps_nfc_token_gen(hapd, reply,
321 max_len, 1);
322
323 if (os_strcmp(cmd, "enable") == 0)
324 return hostapd_wps_nfc_token_enable(hapd);
325
326 if (os_strcmp(cmd, "disable") == 0) {
327 hostapd_wps_nfc_token_disable(hapd);
328 return 0;
329 }
330
331 return -1;
332}
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800333
334
335static int hostapd_ctrl_iface_nfc_get_handover_sel(struct hostapd_data *hapd,
336 char *cmd, char *reply,
337 size_t max_len)
338{
339 struct wpabuf *buf;
340 int res;
341 char *pos;
342 int ndef;
343
344 pos = os_strchr(cmd, ' ');
345 if (pos == NULL)
346 return -1;
347 *pos++ = '\0';
348
349 if (os_strcmp(cmd, "WPS") == 0)
350 ndef = 0;
351 else if (os_strcmp(cmd, "NDEF") == 0)
352 ndef = 1;
353 else
354 return -1;
355
356 if (os_strcmp(pos, "WPS-CR") == 0)
357 buf = hostapd_wps_nfc_hs_cr(hapd, ndef);
358 else
359 buf = NULL;
360 if (buf == NULL)
361 return -1;
362
363 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
364 wpabuf_len(buf));
365 reply[res++] = '\n';
366 reply[res] = '\0';
367
368 wpabuf_free(buf);
369
370 return res;
371}
372
373
374static int hostapd_ctrl_iface_nfc_report_handover(struct hostapd_data *hapd,
375 char *cmd)
376{
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800377 size_t len;
378 struct wpabuf *req, *sel;
379 int ret;
380 char *pos, *role, *type, *pos2;
381
382 role = cmd;
383 pos = os_strchr(role, ' ');
384 if (pos == NULL)
385 return -1;
386 *pos++ = '\0';
387
388 type = pos;
389 pos = os_strchr(type, ' ');
390 if (pos == NULL)
391 return -1;
392 *pos++ = '\0';
393
394 pos2 = os_strchr(pos, ' ');
395 if (pos2 == NULL)
396 return -1;
397 *pos2++ = '\0';
398
399 len = os_strlen(pos);
400 if (len & 0x01)
401 return -1;
402 len /= 2;
403
404 req = wpabuf_alloc(len);
405 if (req == NULL)
406 return -1;
407 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
408 wpabuf_free(req);
409 return -1;
410 }
411
412 len = os_strlen(pos2);
413 if (len & 0x01) {
414 wpabuf_free(req);
415 return -1;
416 }
417 len /= 2;
418
419 sel = wpabuf_alloc(len);
420 if (sel == NULL) {
421 wpabuf_free(req);
422 return -1;
423 }
424 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
425 wpabuf_free(req);
426 wpabuf_free(sel);
427 return -1;
428 }
429
430 if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0) {
431 ret = hostapd_wps_nfc_report_handover(hapd, req, sel);
432 } else {
433 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
434 "reported: role=%s type=%s", role, type);
435 ret = -1;
436 }
437 wpabuf_free(req);
438 wpabuf_free(sel);
439
440 return ret;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800441}
442
Dmitry Shmidt04949592012-07-19 12:16:46 -0700443#endif /* CONFIG_WPS_NFC */
444
445
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446static int hostapd_ctrl_iface_wps_ap_pin(struct hostapd_data *hapd, char *txt,
447 char *buf, size_t buflen)
448{
449 int timeout = 300;
450 char *pos;
451 const char *pin_txt;
452
453 pos = os_strchr(txt, ' ');
454 if (pos)
455 *pos++ = '\0';
456
457 if (os_strcmp(txt, "disable") == 0) {
458 hostapd_wps_ap_pin_disable(hapd);
459 return os_snprintf(buf, buflen, "OK\n");
460 }
461
462 if (os_strcmp(txt, "random") == 0) {
463 if (pos)
464 timeout = atoi(pos);
465 pin_txt = hostapd_wps_ap_pin_random(hapd, timeout);
466 if (pin_txt == NULL)
467 return -1;
468 return os_snprintf(buf, buflen, "%s", pin_txt);
469 }
470
471 if (os_strcmp(txt, "get") == 0) {
472 pin_txt = hostapd_wps_ap_pin_get(hapd);
473 if (pin_txt == NULL)
474 return -1;
475 return os_snprintf(buf, buflen, "%s", pin_txt);
476 }
477
478 if (os_strcmp(txt, "set") == 0) {
479 char *pin;
480 if (pos == NULL)
481 return -1;
482 pin = pos;
483 pos = os_strchr(pos, ' ');
484 if (pos) {
485 *pos++ = '\0';
486 timeout = atoi(pos);
487 }
488 if (os_strlen(pin) > buflen)
489 return -1;
490 if (hostapd_wps_ap_pin_set(hapd, pin, timeout) < 0)
491 return -1;
492 return os_snprintf(buf, buflen, "%s", pin);
493 }
494
495 return -1;
496}
497
498
499static int hostapd_ctrl_iface_wps_config(struct hostapd_data *hapd, char *txt)
500{
501 char *pos;
502 char *ssid, *auth, *encr = NULL, *key = NULL;
503
504 ssid = txt;
505 pos = os_strchr(txt, ' ');
506 if (!pos)
507 return -1;
508 *pos++ = '\0';
509
510 auth = pos;
511 pos = os_strchr(pos, ' ');
512 if (pos) {
513 *pos++ = '\0';
514 encr = pos;
515 pos = os_strchr(pos, ' ');
516 if (pos) {
517 *pos++ = '\0';
518 key = pos;
519 }
520 }
521
522 return hostapd_wps_config_ap(hapd, ssid, auth, encr, key);
523}
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700524
525
526static const char * pbc_status_str(enum pbc_status status)
527{
528 switch (status) {
529 case WPS_PBC_STATUS_DISABLE:
530 return "Disabled";
531 case WPS_PBC_STATUS_ACTIVE:
532 return "Active";
533 case WPS_PBC_STATUS_TIMEOUT:
534 return "Timed-out";
535 case WPS_PBC_STATUS_OVERLAP:
536 return "Overlap";
537 default:
538 return "Unknown";
539 }
540}
541
542
543static int hostapd_ctrl_iface_wps_get_status(struct hostapd_data *hapd,
544 char *buf, size_t buflen)
545{
546 int ret;
547 char *pos, *end;
548
549 pos = buf;
550 end = buf + buflen;
551
552 ret = os_snprintf(pos, end - pos, "PBC Status: %s\n",
553 pbc_status_str(hapd->wps_stats.pbc_status));
554
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800555 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700556 return pos - buf;
557 pos += ret;
558
559 ret = os_snprintf(pos, end - pos, "Last WPS result: %s\n",
560 (hapd->wps_stats.status == WPS_STATUS_SUCCESS ?
561 "Success":
562 (hapd->wps_stats.status == WPS_STATUS_FAILURE ?
563 "Failed" : "None")));
564
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800565 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700566 return pos - buf;
567 pos += ret;
568
569 /* If status == Failure - Add possible Reasons */
570 if(hapd->wps_stats.status == WPS_STATUS_FAILURE &&
571 hapd->wps_stats.failure_reason > 0) {
572 ret = os_snprintf(pos, end - pos,
573 "Failure Reason: %s\n",
574 wps_ei_str(hapd->wps_stats.failure_reason));
575
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800576 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700577 return pos - buf;
578 pos += ret;
579 }
580
581 if (hapd->wps_stats.status) {
582 ret = os_snprintf(pos, end - pos, "Peer Address: " MACSTR "\n",
583 MAC2STR(hapd->wps_stats.peer_addr));
584
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800585 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700586 return pos - buf;
587 pos += ret;
588 }
589
590 return pos - buf;
591}
592
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593#endif /* CONFIG_WPS */
594
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800595#ifdef CONFIG_HS20
596
597static int hostapd_ctrl_iface_hs20_wnm_notif(struct hostapd_data *hapd,
598 const char *cmd)
599{
600 u8 addr[ETH_ALEN];
601 const char *url;
602
603 if (hwaddr_aton(cmd, addr))
604 return -1;
605 url = cmd + 17;
606 if (*url == '\0') {
607 url = NULL;
608 } else {
609 if (*url != ' ')
610 return -1;
611 url++;
612 if (*url == '\0')
613 url = NULL;
614 }
615
616 return hs20_send_wnm_notification(hapd, addr, 1, url);
617}
618
619
620static int hostapd_ctrl_iface_hs20_deauth_req(struct hostapd_data *hapd,
621 const char *cmd)
622{
623 u8 addr[ETH_ALEN];
624 int code, reauth_delay, ret;
625 const char *pos;
626 size_t url_len;
627 struct wpabuf *req;
628
629 /* <STA MAC Addr> <Code(0/1)> <Re-auth-Delay(sec)> [URL] */
630 if (hwaddr_aton(cmd, addr))
631 return -1;
632
633 pos = os_strchr(cmd, ' ');
634 if (pos == NULL)
635 return -1;
636 pos++;
637 code = atoi(pos);
638
639 pos = os_strchr(pos, ' ');
640 if (pos == NULL)
641 return -1;
642 pos++;
643 reauth_delay = atoi(pos);
644
645 url_len = 0;
646 pos = os_strchr(pos, ' ');
647 if (pos) {
648 pos++;
649 url_len = os_strlen(pos);
650 }
651
652 req = wpabuf_alloc(4 + url_len);
653 if (req == NULL)
654 return -1;
655 wpabuf_put_u8(req, code);
656 wpabuf_put_le16(req, reauth_delay);
657 wpabuf_put_u8(req, url_len);
658 if (pos)
659 wpabuf_put_data(req, pos, url_len);
660
661 wpa_printf(MSG_DEBUG, "HS 2.0: Send WNM-Notification to " MACSTR
662 " to indicate imminent deauthentication (code=%d "
663 "reauth_delay=%d)", MAC2STR(addr), code, reauth_delay);
664 ret = hs20_send_wnm_notification_deauth_req(hapd, addr, req);
665 wpabuf_free(req);
666 return ret;
667}
668
669#endif /* CONFIG_HS20 */
670
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671
Dmitry Shmidt051af732013-10-22 13:52:46 -0700672#ifdef CONFIG_INTERWORKING
673
674static int hostapd_ctrl_iface_set_qos_map_set(struct hostapd_data *hapd,
675 const char *cmd)
676{
677 u8 qos_map_set[16 + 2 * 21], count = 0;
678 const char *pos = cmd;
679 int val, ret;
680
681 for (;;) {
682 if (count == sizeof(qos_map_set)) {
683 wpa_printf(MSG_ERROR, "Too many qos_map_set parameters");
684 return -1;
685 }
686
687 val = atoi(pos);
688 if (val < 0 || val > 255) {
689 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
690 return -1;
691 }
692
693 qos_map_set[count++] = val;
694 pos = os_strchr(pos, ',');
695 if (!pos)
696 break;
697 pos++;
698 }
699
700 if (count < 16 || count & 1) {
701 wpa_printf(MSG_INFO, "Invalid QoS Map Set");
702 return -1;
703 }
704
705 ret = hostapd_drv_set_qos_map(hapd, qos_map_set, count);
706 if (ret) {
707 wpa_printf(MSG_INFO, "Failed to set QoS Map Set");
708 return -1;
709 }
710
711 os_memcpy(hapd->conf->qos_map_set, qos_map_set, count);
712 hapd->conf->qos_map_set_len = count;
713
714 return 0;
715}
716
717
718static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
719 const char *cmd)
720{
721 u8 addr[ETH_ALEN];
722 struct sta_info *sta;
723 struct wpabuf *buf;
724 u8 *qos_map_set = hapd->conf->qos_map_set;
725 u8 qos_map_set_len = hapd->conf->qos_map_set_len;
726 int ret;
727
728 if (!qos_map_set_len) {
729 wpa_printf(MSG_INFO, "QoS Map Set is not set");
730 return -1;
731 }
732
733 if (hwaddr_aton(cmd, addr))
734 return -1;
735
736 sta = ap_get_sta(hapd, addr);
737 if (sta == NULL) {
738 wpa_printf(MSG_DEBUG, "Station " MACSTR " not found "
739 "for QoS Map Configuration message",
740 MAC2STR(addr));
741 return -1;
742 }
743
744 if (!sta->qos_map_enabled) {
745 wpa_printf(MSG_DEBUG, "Station " MACSTR " did not indicate "
746 "support for QoS Map", MAC2STR(addr));
747 return -1;
748 }
749
750 buf = wpabuf_alloc(2 + 2 + qos_map_set_len);
751 if (buf == NULL)
752 return -1;
753
754 wpabuf_put_u8(buf, WLAN_ACTION_QOS);
755 wpabuf_put_u8(buf, QOS_QOS_MAP_CONFIG);
756
757 /* QoS Map Set Element */
758 wpabuf_put_u8(buf, WLAN_EID_QOS_MAP_SET);
759 wpabuf_put_u8(buf, qos_map_set_len);
760 wpabuf_put_data(buf, qos_map_set, qos_map_set_len);
761
762 ret = hostapd_drv_send_action(hapd, hapd->iface->freq, 0, addr,
763 wpabuf_head(buf), wpabuf_len(buf));
764 wpabuf_free(buf);
765
766 return ret;
767}
768
769#endif /* CONFIG_INTERWORKING */
770
771
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700772#ifdef CONFIG_WNM_AP
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800773
774static int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data *hapd,
775 const char *cmd)
776{
777 u8 addr[ETH_ALEN];
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800778 int disassoc_timer;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800779 struct sta_info *sta;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800780
781 if (hwaddr_aton(cmd, addr))
782 return -1;
783 if (cmd[17] != ' ')
784 return -1;
785 disassoc_timer = atoi(cmd + 17);
786
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800787 sta = ap_get_sta(hapd, addr);
788 if (sta == NULL) {
789 wpa_printf(MSG_DEBUG, "Station " MACSTR
790 " not found for disassociation imminent message",
791 MAC2STR(addr));
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800792 return -1;
793 }
794
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800795 return wnm_send_disassoc_imminent(hapd, sta, disassoc_timer);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800796}
797
798
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800799static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
800 const char *cmd)
801{
802 u8 addr[ETH_ALEN];
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700803 const char *url, *timerstr;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700804 int disassoc_timer;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800805 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800806
807 if (hwaddr_aton(cmd, addr))
808 return -1;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700809
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800810 sta = ap_get_sta(hapd, addr);
811 if (sta == NULL) {
812 wpa_printf(MSG_DEBUG, "Station " MACSTR
813 " not found for ESS disassociation imminent message",
814 MAC2STR(addr));
815 return -1;
816 }
817
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700818 timerstr = cmd + 17;
819 if (*timerstr != ' ')
820 return -1;
821 timerstr++;
822 disassoc_timer = atoi(timerstr);
823 if (disassoc_timer < 0 || disassoc_timer > 65535)
824 return -1;
825
826 url = os_strchr(timerstr, ' ');
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700827 if (url == NULL)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800828 return -1;
829 url++;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800830
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800831 return wnm_send_ess_disassoc_imminent(hapd, sta, url, disassoc_timer);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800832}
833
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800834
835static int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data *hapd,
836 const char *cmd)
837{
838 u8 addr[ETH_ALEN];
839 const char *pos, *end;
840 int disassoc_timer = 0;
841 struct sta_info *sta;
842 u8 req_mode = 0, valid_int = 0x01;
843 u8 bss_term_dur[12];
844 char *url = NULL;
845 int ret;
846 u8 nei_rep[1000];
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700847 int nei_len;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800848 u8 mbo[10];
849 size_t mbo_len = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800850
851 if (hwaddr_aton(cmd, addr)) {
852 wpa_printf(MSG_DEBUG, "Invalid STA MAC address");
853 return -1;
854 }
855
856 sta = ap_get_sta(hapd, addr);
857 if (sta == NULL) {
858 wpa_printf(MSG_DEBUG, "Station " MACSTR
859 " not found for BSS TM Request message",
860 MAC2STR(addr));
861 return -1;
862 }
863
864 pos = os_strstr(cmd, " disassoc_timer=");
865 if (pos) {
866 pos += 16;
867 disassoc_timer = atoi(pos);
868 if (disassoc_timer < 0 || disassoc_timer > 65535) {
869 wpa_printf(MSG_DEBUG, "Invalid disassoc_timer");
870 return -1;
871 }
872 }
873
874 pos = os_strstr(cmd, " valid_int=");
875 if (pos) {
876 pos += 11;
877 valid_int = atoi(pos);
878 }
879
880 pos = os_strstr(cmd, " bss_term=");
881 if (pos) {
882 pos += 10;
883 req_mode |= WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED;
884 /* TODO: TSF configurable/learnable */
885 bss_term_dur[0] = 4; /* Subelement ID */
886 bss_term_dur[1] = 10; /* Length */
Hai Shalom5f92bc92019-04-18 11:54:11 -0700887 os_memset(&bss_term_dur[2], 0, 8);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800888 end = os_strchr(pos, ',');
889 if (end == NULL) {
890 wpa_printf(MSG_DEBUG, "Invalid bss_term data");
891 return -1;
892 }
893 end++;
894 WPA_PUT_LE16(&bss_term_dur[10], atoi(end));
895 }
896
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700897 nei_len = ieee802_11_parse_candidate_list(cmd, nei_rep,
898 sizeof(nei_rep));
899 if (nei_len < 0)
900 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800901
902 pos = os_strstr(cmd, " url=");
903 if (pos) {
904 size_t len;
905 pos += 5;
906 end = os_strchr(pos, ' ');
907 if (end)
908 len = end - pos;
909 else
910 len = os_strlen(pos);
911 url = os_malloc(len + 1);
912 if (url == NULL)
913 return -1;
914 os_memcpy(url, pos, len);
915 url[len] = '\0';
916 req_mode |= WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
917 }
918
919 if (os_strstr(cmd, " pref=1"))
920 req_mode |= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED;
921 if (os_strstr(cmd, " abridged=1"))
922 req_mode |= WNM_BSS_TM_REQ_ABRIDGED;
923 if (os_strstr(cmd, " disassoc_imminent=1"))
924 req_mode |= WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
925
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800926#ifdef CONFIG_MBO
927 pos = os_strstr(cmd, "mbo=");
928 if (pos) {
929 unsigned int mbo_reason, cell_pref, reassoc_delay;
930 u8 *mbo_pos = mbo;
931
932 ret = sscanf(pos, "mbo=%u:%u:%u", &mbo_reason,
933 &reassoc_delay, &cell_pref);
934 if (ret != 3) {
935 wpa_printf(MSG_DEBUG,
936 "MBO requires three arguments: mbo=<reason>:<reassoc_delay>:<cell_pref>");
Dmitry Shmidt29333592017-01-09 12:27:11 -0800937 ret = -1;
938 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800939 }
940
941 if (mbo_reason > MBO_TRANSITION_REASON_PREMIUM_AP) {
942 wpa_printf(MSG_DEBUG,
943 "Invalid MBO transition reason code %u",
944 mbo_reason);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800945 ret = -1;
946 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800947 }
948
949 /* Valid values for Cellular preference are: 0, 1, 255 */
950 if (cell_pref != 0 && cell_pref != 1 && cell_pref != 255) {
951 wpa_printf(MSG_DEBUG,
952 "Invalid MBO cellular capability %u",
953 cell_pref);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800954 ret = -1;
955 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800956 }
957
958 if (reassoc_delay > 65535 ||
959 (reassoc_delay &&
960 !(req_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT))) {
961 wpa_printf(MSG_DEBUG,
962 "MBO: Assoc retry delay is only valid in disassoc imminent mode");
Dmitry Shmidt29333592017-01-09 12:27:11 -0800963 ret = -1;
964 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800965 }
966
967 *mbo_pos++ = MBO_ATTR_ID_TRANSITION_REASON;
968 *mbo_pos++ = 1;
969 *mbo_pos++ = mbo_reason;
970 *mbo_pos++ = MBO_ATTR_ID_CELL_DATA_PREF;
971 *mbo_pos++ = 1;
972 *mbo_pos++ = cell_pref;
973
974 if (reassoc_delay) {
975 *mbo_pos++ = MBO_ATTR_ID_ASSOC_RETRY_DELAY;
976 *mbo_pos++ = 2;
977 WPA_PUT_LE16(mbo_pos, reassoc_delay);
978 mbo_pos += 2;
979 }
980
981 mbo_len = mbo_pos - mbo;
982 }
983#endif /* CONFIG_MBO */
984
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800985 ret = wnm_send_bss_tm_req(hapd, sta, req_mode, disassoc_timer,
986 valid_int, bss_term_dur, url,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700987 nei_len ? nei_rep : NULL, nei_len,
988 mbo_len ? mbo : NULL, mbo_len);
Paul Stewart092955c2017-02-06 09:13:09 -0800989#ifdef CONFIG_MBO
Dmitry Shmidt29333592017-01-09 12:27:11 -0800990fail:
Paul Stewart092955c2017-02-06 09:13:09 -0800991#endif /* CONFIG_MBO */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800992 os_free(url);
993 return ret;
994}
995
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800996
997static int hostapd_ctrl_iface_coloc_intf_req(struct hostapd_data *hapd,
998 const char *cmd)
999{
1000 u8 addr[ETH_ALEN];
1001 struct sta_info *sta;
1002 const char *pos;
1003 unsigned int auto_report, timeout;
1004
1005 if (hwaddr_aton(cmd, addr)) {
1006 wpa_printf(MSG_DEBUG, "Invalid STA MAC address");
1007 return -1;
1008 }
1009
1010 sta = ap_get_sta(hapd, addr);
1011 if (!sta) {
1012 wpa_printf(MSG_DEBUG, "Station " MACSTR
1013 " not found for Collocated Interference Request",
1014 MAC2STR(addr));
1015 return -1;
1016 }
1017
1018 pos = cmd + 17;
1019 if (*pos != ' ')
1020 return -1;
1021 pos++;
1022 auto_report = atoi(pos);
1023 pos = os_strchr(pos, ' ');
1024 if (!pos)
1025 return -1;
1026 pos++;
1027 timeout = atoi(pos);
1028
1029 return wnm_send_coloc_intf_req(hapd, sta, auto_report, timeout);
1030}
1031
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001032#endif /* CONFIG_WNM_AP */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001033
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001034
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001035static int hostapd_ctrl_iface_get_key_mgmt(struct hostapd_data *hapd,
1036 char *buf, size_t buflen)
1037{
1038 int ret = 0;
1039 char *pos, *end;
1040
1041 pos = buf;
1042 end = buf + buflen;
1043
1044 WPA_ASSERT(hapd->conf->wpa_key_mgmt);
1045
1046 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK) {
1047 ret = os_snprintf(pos, end - pos, "WPA-PSK ");
1048 if (os_snprintf_error(end - pos, ret))
1049 return pos - buf;
1050 pos += ret;
1051 }
1052 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1053 ret = os_snprintf(pos, end - pos, "WPA-EAP ");
1054 if (os_snprintf_error(end - pos, ret))
1055 return pos - buf;
1056 pos += ret;
1057 }
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001058#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001059 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1060 ret = os_snprintf(pos, end - pos, "FT-PSK ");
1061 if (os_snprintf_error(end - pos, ret))
1062 return pos - buf;
1063 pos += ret;
1064 }
1065 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1066 ret = os_snprintf(pos, end - pos, "FT-EAP ");
1067 if (os_snprintf_error(end - pos, ret))
1068 return pos - buf;
1069 pos += ret;
1070 }
Roshan Pius3a1667e2018-07-03 15:17:14 -07001071#ifdef CONFIG_SHA384
1072 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X_SHA384) {
1073 ret = os_snprintf(pos, end - pos, "FT-EAP-SHA384 ");
1074 if (os_snprintf_error(end - pos, ret))
1075 return pos - buf;
1076 pos += ret;
1077 }
1078#endif /* CONFIG_SHA384 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001079#ifdef CONFIG_SAE
1080 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_SAE) {
1081 ret = os_snprintf(pos, end - pos, "FT-SAE ");
1082 if (os_snprintf_error(end - pos, ret))
1083 return pos - buf;
1084 pos += ret;
1085 }
1086#endif /* CONFIG_SAE */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001087#ifdef CONFIG_FILS
1088 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
1089 ret = os_snprintf(pos, end - pos, "FT-FILS-SHA256 ");
1090 if (os_snprintf_error(end - pos, ret))
1091 return pos - buf;
1092 pos += ret;
1093 }
1094 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
1095 ret = os_snprintf(pos, end - pos, "FT-FILS-SHA384 ");
1096 if (os_snprintf_error(end - pos, ret))
1097 return pos - buf;
1098 pos += ret;
1099 }
1100#endif /* CONFIG_FILS */
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001101#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001102 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
1103 ret = os_snprintf(pos, end - pos, "WPA-PSK-SHA256 ");
1104 if (os_snprintf_error(end - pos, ret))
1105 return pos - buf;
1106 pos += ret;
1107 }
1108 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1109 ret = os_snprintf(pos, end - pos, "WPA-EAP-SHA256 ");
1110 if (os_snprintf_error(end - pos, ret))
1111 return pos - buf;
1112 pos += ret;
1113 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001114#ifdef CONFIG_SAE
1115 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_SAE) {
1116 ret = os_snprintf(pos, end - pos, "SAE ");
1117 if (os_snprintf_error(end - pos, ret))
1118 return pos - buf;
1119 pos += ret;
1120 }
1121#endif /* CONFIG_SAE */
1122 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
1123 ret = os_snprintf(pos, end - pos, "WPA-EAP-SUITE-B ");
1124 if (os_snprintf_error(end - pos, ret))
1125 return pos - buf;
1126 pos += ret;
1127 }
1128 if (hapd->conf->wpa_key_mgmt &
1129 WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
1130 ret = os_snprintf(pos, end - pos,
1131 "WPA-EAP-SUITE-B-192 ");
1132 if (os_snprintf_error(end - pos, ret))
1133 return pos - buf;
1134 pos += ret;
1135 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001136#ifdef CONFIG_FILS
1137 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
1138 ret = os_snprintf(pos, end - pos, "FILS-SHA256 ");
1139 if (os_snprintf_error(end - pos, ret))
1140 return pos - buf;
1141 pos += ret;
1142 }
1143 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
1144 ret = os_snprintf(pos, end - pos, "FILS-SHA384 ");
1145 if (os_snprintf_error(end - pos, ret))
1146 return pos - buf;
1147 pos += ret;
1148 }
1149#endif /* CONFIG_FILS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001150
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001151#ifdef CONFIG_OWE
1152 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) {
1153 ret = os_snprintf(pos, end - pos, "OWE ");
1154 if (os_snprintf_error(end - pos, ret))
1155 return pos - buf;
1156 pos += ret;
1157 }
1158#endif /* CONFIG_OWE */
1159
1160#ifdef CONFIG_DPP
1161 if (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) {
1162 ret = os_snprintf(pos, end - pos, "DPP ");
1163 if (os_snprintf_error(end - pos, ret))
1164 return pos - buf;
1165 pos += ret;
1166 }
1167#endif /* CONFIG_DPP */
1168
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001169 if (pos > buf && *(pos - 1) == ' ') {
1170 *(pos - 1) = '\0';
1171 pos--;
1172 }
1173
1174 return pos - buf;
1175}
1176
1177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178static int hostapd_ctrl_iface_get_config(struct hostapd_data *hapd,
1179 char *buf, size_t buflen)
1180{
1181 int ret;
1182 char *pos, *end;
1183
1184 pos = buf;
1185 end = buf + buflen;
1186
1187 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n"
1188 "ssid=%s\n",
1189 MAC2STR(hapd->own_addr),
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001190 wpa_ssid_txt(hapd->conf->ssid.ssid,
1191 hapd->conf->ssid.ssid_len));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001192 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001193 return pos - buf;
1194 pos += ret;
1195
1196#ifdef CONFIG_WPS
1197 ret = os_snprintf(pos, end - pos, "wps_state=%s\n",
1198 hapd->conf->wps_state == 0 ? "disabled" :
1199 (hapd->conf->wps_state == 1 ? "not configured" :
1200 "configured"));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001201 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202 return pos - buf;
1203 pos += ret;
1204
1205 if (hapd->conf->wps_state && hapd->conf->wpa &&
1206 hapd->conf->ssid.wpa_passphrase) {
1207 ret = os_snprintf(pos, end - pos, "passphrase=%s\n",
1208 hapd->conf->ssid.wpa_passphrase);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001209 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001210 return pos - buf;
1211 pos += ret;
1212 }
1213
1214 if (hapd->conf->wps_state && hapd->conf->wpa &&
1215 hapd->conf->ssid.wpa_psk &&
1216 hapd->conf->ssid.wpa_psk->group) {
1217 char hex[PMK_LEN * 2 + 1];
1218 wpa_snprintf_hex(hex, sizeof(hex),
1219 hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
1220 ret = os_snprintf(pos, end - pos, "psk=%s\n", hex);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001221 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001222 return pos - buf;
1223 pos += ret;
1224 }
1225#endif /* CONFIG_WPS */
1226
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001227 if (hapd->conf->wpa) {
1228 ret = os_snprintf(pos, end - pos, "wpa=%d\n", hapd->conf->wpa);
1229 if (os_snprintf_error(end - pos, ret))
1230 return pos - buf;
1231 pos += ret;
1232 }
1233
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 if (hapd->conf->wpa && hapd->conf->wpa_key_mgmt) {
1235 ret = os_snprintf(pos, end - pos, "key_mgmt=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001236 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001237 return pos - buf;
1238 pos += ret;
1239
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001240 pos += hostapd_ctrl_iface_get_key_mgmt(hapd, pos, end - pos);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001241
1242 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001243 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244 return pos - buf;
1245 pos += ret;
1246 }
1247
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001248 if (hapd->conf->wpa) {
1249 ret = os_snprintf(pos, end - pos, "group_cipher=%s\n",
1250 wpa_cipher_txt(hapd->conf->wpa_group));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001251 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252 return pos - buf;
1253 pos += ret;
1254 }
1255
1256 if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->rsn_pairwise) {
1257 ret = os_snprintf(pos, end - pos, "rsn_pairwise_cipher=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001258 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259 return pos - buf;
1260 pos += ret;
1261
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001262 ret = wpa_write_ciphers(pos, end, hapd->conf->rsn_pairwise,
1263 " ");
1264 if (ret < 0)
1265 return pos - buf;
1266 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267
1268 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001269 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270 return pos - buf;
1271 pos += ret;
1272 }
1273
1274 if ((hapd->conf->wpa & WPA_PROTO_WPA) && hapd->conf->wpa_pairwise) {
1275 ret = os_snprintf(pos, end - pos, "wpa_pairwise_cipher=");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001276 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001277 return pos - buf;
1278 pos += ret;
1279
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001280 ret = wpa_write_ciphers(pos, end, hapd->conf->wpa_pairwise,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001281 " ");
1282 if (ret < 0)
1283 return pos - buf;
1284 pos += ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001285
1286 ret = os_snprintf(pos, end - pos, "\n");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001287 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001288 return pos - buf;
1289 pos += ret;
1290 }
1291
Hai Shalomfdcde762020-04-02 11:19:20 -07001292 if (hapd->conf->wpa && hapd->conf->wpa_deny_ptk0_rekey) {
1293 ret = os_snprintf(pos, end - pos, "wpa_deny_ptk0_rekey=%d\n",
1294 hapd->conf->wpa_deny_ptk0_rekey);
1295 if (os_snprintf_error(end - pos, ret))
1296 return pos - buf;
1297 pos += ret;
1298 }
1299
1300 if ((hapd->conf->wpa & WPA_PROTO_RSN) && hapd->conf->extended_key_id) {
1301 ret = os_snprintf(pos, end - pos, "extended_key_id=%d\n",
1302 hapd->conf->extended_key_id);
1303 if (os_snprintf_error(end - pos, ret))
1304 return pos - buf;
1305 pos += ret;
1306 }
1307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308 return pos - buf;
1309}
1310
1311
Roshan Pius3a1667e2018-07-03 15:17:14 -07001312static void hostapd_disassoc_accept_mac(struct hostapd_data *hapd)
1313{
1314 struct sta_info *sta;
1315 struct vlan_description vlan_id;
1316
1317 if (hapd->conf->macaddr_acl != DENY_UNLESS_ACCEPTED)
1318 return;
1319
1320 for (sta = hapd->sta_list; sta; sta = sta->next) {
1321 if (!hostapd_maclist_found(hapd->conf->accept_mac,
1322 hapd->conf->num_accept_mac,
1323 sta->addr, &vlan_id) ||
1324 (vlan_id.notempty &&
1325 vlan_compare(&vlan_id, sta->vlan_desc)))
1326 ap_sta_disconnect(hapd, sta, sta->addr,
1327 WLAN_REASON_UNSPECIFIED);
1328 }
1329}
1330
1331
1332static void hostapd_disassoc_deny_mac(struct hostapd_data *hapd)
1333{
1334 struct sta_info *sta;
1335 struct vlan_description vlan_id;
1336
1337 for (sta = hapd->sta_list; sta; sta = sta->next) {
1338 if (hostapd_maclist_found(hapd->conf->deny_mac,
1339 hapd->conf->num_deny_mac, sta->addr,
1340 &vlan_id) &&
1341 (!vlan_id.notempty ||
1342 !vlan_compare(&vlan_id, sta->vlan_desc)))
1343 ap_sta_disconnect(hapd, sta, sta->addr,
1344 WLAN_REASON_UNSPECIFIED);
1345 }
1346}
1347
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001348
1349static int hostapd_ctrl_iface_set_band(struct hostapd_data *hapd,
1350 const char *band)
1351{
1352 union wpa_event_data event;
1353 enum set_band setband;
1354
1355 if (os_strcmp(band, "AUTO") == 0)
1356 setband = WPA_SETBAND_AUTO;
1357 else if (os_strcmp(band, "5G") == 0)
1358 setband = WPA_SETBAND_5G;
1359 else if (os_strcmp(band, "2G") == 0)
1360 setband = WPA_SETBAND_2G;
1361 else
1362 return -1;
1363
1364 if (hostapd_drv_set_band(hapd, setband) == 0) {
1365 os_memset(&event, 0, sizeof(event));
1366 event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
1367 event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
1368 wpa_supplicant_event(hapd, EVENT_CHANNEL_LIST_CHANGED, &event);
1369 }
1370
1371 return 0;
1372}
1373
1374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375static int hostapd_ctrl_iface_set(struct hostapd_data *hapd, char *cmd)
1376{
1377 char *value;
1378 int ret = 0;
1379
1380 value = os_strchr(cmd, ' ');
1381 if (value == NULL)
1382 return -1;
1383 *value++ = '\0';
1384
1385 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
1386 if (0) {
1387#ifdef CONFIG_WPS_TESTING
1388 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
1389 long int val;
1390 val = strtol(value, NULL, 0);
1391 if (val < 0 || val > 0xff) {
1392 ret = -1;
1393 wpa_printf(MSG_DEBUG, "WPS: Invalid "
1394 "wps_version_number %ld", val);
1395 } else {
1396 wps_version_number = val;
1397 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
1398 "version %u.%u",
1399 (wps_version_number & 0xf0) >> 4,
1400 wps_version_number & 0x0f);
1401 hostapd_wps_update_ie(hapd);
1402 }
1403 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
1404 wps_testing_dummy_cred = atoi(value);
1405 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
1406 wps_testing_dummy_cred);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001407 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
1408 wps_corrupt_pkhash = atoi(value);
1409 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
1410 wps_corrupt_pkhash);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001411#endif /* CONFIG_WPS_TESTING */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001412#ifdef CONFIG_TESTING_OPTIONS
1413 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
1414 hapd->ext_mgmt_frame_handling = atoi(value);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001415 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
1416 hapd->ext_eapol_frame_io = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001417#ifdef CONFIG_DPP
1418 } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
1419 os_free(hapd->dpp_config_obj_override);
1420 hapd->dpp_config_obj_override = os_strdup(value);
1421 } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
1422 os_free(hapd->dpp_discovery_override);
1423 hapd->dpp_discovery_override = os_strdup(value);
1424 } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
1425 os_free(hapd->dpp_groups_override);
1426 hapd->dpp_groups_override = os_strdup(value);
1427 } else if (os_strcasecmp(cmd,
1428 "dpp_ignore_netaccesskey_mismatch") == 0) {
1429 hapd->dpp_ignore_netaccesskey_mismatch = atoi(value);
Roshan Pius3a1667e2018-07-03 15:17:14 -07001430 } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
1431 dpp_test = atoi(value);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07001432 } else if (os_strcasecmp(cmd, "dpp_version_override") == 0) {
1433 dpp_version_override = atoi(value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001434#endif /* CONFIG_DPP */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001435#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001436#ifdef CONFIG_MBO
1437 } else if (os_strcasecmp(cmd, "mbo_assoc_disallow") == 0) {
1438 int val;
1439
1440 if (!hapd->conf->mbo_enabled)
1441 return -1;
1442
1443 val = atoi(value);
1444 if (val < 0 || val > 1)
1445 return -1;
1446
1447 hapd->mbo_assoc_disallow = val;
1448 ieee802_11_update_beacons(hapd->iface);
1449
1450 /*
1451 * TODO: Need to configure drivers that do AP MLME offload with
1452 * disallowing station logic.
1453 */
1454#endif /* CONFIG_MBO */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001455#ifdef CONFIG_DPP
1456 } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
1457 os_free(hapd->dpp_configurator_params);
1458 hapd->dpp_configurator_params = os_strdup(value);
1459#endif /* CONFIG_DPP */
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001460 } else if (os_strcasecmp(cmd, "setband") == 0) {
1461 ret = hostapd_ctrl_iface_set_band(hapd, value);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462 } else {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001463 ret = hostapd_set_iface(hapd->iconf, hapd->conf, cmd, value);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001464 if (ret)
1465 return ret;
1466
1467 if (os_strcasecmp(cmd, "deny_mac_file") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07001468 hostapd_disassoc_deny_mac(hapd);
1469 } else if (os_strcasecmp(cmd, "accept_mac_file") == 0) {
1470 hostapd_disassoc_accept_mac(hapd);
Hai Shalom39ba6fc2019-01-22 12:40:38 -08001471 } else if (os_strncmp(cmd, "wme_ac_", 7) == 0 ||
1472 os_strncmp(cmd, "wmm_ac_", 7) == 0) {
1473 hapd->parameter_set_count++;
1474 if (ieee802_11_update_beacons(hapd->iface))
1475 wpa_printf(MSG_DEBUG,
1476 "Failed to update beacons with WMM parameters");
Hai Shalomc3565922019-10-28 11:58:20 -07001477 } else if (os_strcmp(cmd, "wpa_passphrase") == 0 ||
1478 os_strcmp(cmd, "sae_password") == 0 ||
1479 os_strcmp(cmd, "sae_pwe") == 0) {
1480 if (hapd->started)
1481 hostapd_setup_sae_pt(hapd->conf);
Hai Shalom899fcc72020-10-19 14:38:18 -07001482 } else if (os_strcasecmp(cmd, "transition_disable") == 0) {
1483 wpa_auth_set_transition_disable(hapd->wpa_auth,
1484 hapd->conf->transition_disable);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001485 }
Hai Shalomb755a2a2020-04-23 21:49:02 -07001486
1487#ifdef CONFIG_TESTING_OPTIONS
1488 if (os_strcmp(cmd, "ft_rsnxe_used") == 0)
1489 wpa_auth_set_ft_rsnxe_used(hapd->wpa_auth,
1490 hapd->conf->ft_rsnxe_used);
Hai Shalom899fcc72020-10-19 14:38:18 -07001491 else if (os_strcmp(cmd, "oci_freq_override_eapol_m3") == 0)
1492 wpa_auth_set_ocv_override_freq(
1493 hapd->wpa_auth, WPA_AUTH_OCV_OVERRIDE_EAPOL_M3,
1494 atoi(value));
1495 else if (os_strcmp(cmd, "oci_freq_override_eapol_g1") == 0)
1496 wpa_auth_set_ocv_override_freq(
1497 hapd->wpa_auth, WPA_AUTH_OCV_OVERRIDE_EAPOL_G1,
1498 atoi(value));
1499 else if (os_strcmp(cmd, "oci_freq_override_ft_assoc") == 0)
1500 wpa_auth_set_ocv_override_freq(
1501 hapd->wpa_auth, WPA_AUTH_OCV_OVERRIDE_FT_ASSOC,
1502 atoi(value));
1503 else if (os_strcmp(cmd, "oci_freq_override_fils_assoc") == 0)
1504 wpa_auth_set_ocv_override_freq(
1505 hapd->wpa_auth,
1506 WPA_AUTH_OCV_OVERRIDE_FILS_ASSOC, atoi(value));
Kai Shie75b0652020-11-24 20:31:29 -08001507 else if (os_strcasecmp(cmd, "skip_send_eapol") == 0)
1508 wpa_auth_set_skip_send_eapol(hapd->wpa_auth, atoi(value));
1509 else if (os_strcasecmp(cmd, "enable_eapol_large_timeout") == 0)
1510 wpa_auth_set_enable_eapol_large_timeout(hapd->wpa_auth, atoi(value));
Hai Shalomb755a2a2020-04-23 21:49:02 -07001511#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001512 }
1513
1514 return ret;
1515}
1516
1517
1518static int hostapd_ctrl_iface_get(struct hostapd_data *hapd, char *cmd,
1519 char *buf, size_t buflen)
1520{
1521 int res;
1522
1523 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
1524
1525 if (os_strcmp(cmd, "version") == 0) {
1526 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001527 if (os_snprintf_error(buflen, res))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528 return -1;
1529 return res;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001530 } else if (os_strcmp(cmd, "tls_library") == 0) {
1531 res = tls_get_library_version(buf, buflen);
1532 if (os_snprintf_error(buflen, res))
1533 return -1;
1534 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001535 }
1536
1537 return -1;
1538}
1539
1540
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001541static int hostapd_ctrl_iface_enable(struct hostapd_iface *iface)
1542{
1543 if (hostapd_enable_iface(iface) < 0) {
1544 wpa_printf(MSG_ERROR, "Enabling of interface failed");
1545 return -1;
1546 }
1547 return 0;
1548}
1549
1550
1551static int hostapd_ctrl_iface_reload(struct hostapd_iface *iface)
1552{
1553 if (hostapd_reload_iface(iface) < 0) {
1554 wpa_printf(MSG_ERROR, "Reloading of interface failed");
1555 return -1;
1556 }
1557 return 0;
1558}
1559
1560
1561static int hostapd_ctrl_iface_disable(struct hostapd_iface *iface)
1562{
1563 if (hostapd_disable_iface(iface) < 0) {
1564 wpa_printf(MSG_ERROR, "Disabling of interface failed");
1565 return -1;
1566 }
1567 return 0;
1568}
1569
1570
Hai Shalom74f70d42019-02-11 14:42:39 -08001571static int
1572hostapd_ctrl_iface_kick_mismatch_psk_sta_iter(struct hostapd_data *hapd,
1573 struct sta_info *sta, void *ctx)
1574{
1575 struct hostapd_wpa_psk *psk;
1576 const u8 *pmk;
1577 int pmk_len;
1578 int pmk_match;
1579 int sta_match;
1580 int bss_match;
1581 int reason;
1582
1583 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
1584
1585 for (psk = hapd->conf->ssid.wpa_psk; pmk && psk; psk = psk->next) {
1586 pmk_match = PMK_LEN == pmk_len &&
1587 os_memcmp(psk->psk, pmk, pmk_len) == 0;
1588 sta_match = psk->group == 0 &&
1589 os_memcmp(sta->addr, psk->addr, ETH_ALEN) == 0;
1590 bss_match = psk->group == 1;
1591
1592 if (pmk_match && (sta_match || bss_match))
1593 return 0;
1594 }
1595
1596 wpa_printf(MSG_INFO, "STA " MACSTR
1597 " PSK/passphrase no longer valid - disconnect",
1598 MAC2STR(sta->addr));
1599 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
1600 hostapd_drv_sta_deauth(hapd, sta->addr, reason);
1601 ap_sta_deauthenticate(hapd, sta, reason);
1602
1603 return 0;
1604}
1605
1606
1607static int hostapd_ctrl_iface_reload_wpa_psk(struct hostapd_data *hapd)
1608{
1609 struct hostapd_bss_config *conf = hapd->conf;
1610 int err;
1611
1612 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
1613
1614 err = hostapd_setup_wpa_psk(conf);
1615 if (err < 0) {
1616 wpa_printf(MSG_ERROR, "Reloading WPA-PSK passwords failed: %d",
1617 err);
1618 return -1;
1619 }
1620
1621 ap_for_each_sta(hapd, hostapd_ctrl_iface_kick_mismatch_psk_sta_iter,
1622 NULL);
1623
1624 return 0;
1625}
1626
1627
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001628#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001629
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001630static int hostapd_ctrl_iface_radar(struct hostapd_data *hapd, char *cmd)
1631{
1632 union wpa_event_data data;
1633 char *pos, *param;
1634 enum wpa_event_type event;
1635
1636 wpa_printf(MSG_DEBUG, "RADAR TEST: %s", cmd);
1637
1638 os_memset(&data, 0, sizeof(data));
1639
1640 param = os_strchr(cmd, ' ');
1641 if (param == NULL)
1642 return -1;
1643 *param++ = '\0';
1644
1645 if (os_strcmp(cmd, "DETECTED") == 0)
1646 event = EVENT_DFS_RADAR_DETECTED;
1647 else if (os_strcmp(cmd, "CAC-FINISHED") == 0)
1648 event = EVENT_DFS_CAC_FINISHED;
1649 else if (os_strcmp(cmd, "CAC-ABORTED") == 0)
1650 event = EVENT_DFS_CAC_ABORTED;
1651 else if (os_strcmp(cmd, "NOP-FINISHED") == 0)
1652 event = EVENT_DFS_NOP_FINISHED;
1653 else {
1654 wpa_printf(MSG_DEBUG, "Unsupported RADAR test command: %s",
1655 cmd);
1656 return -1;
1657 }
1658
1659 pos = os_strstr(param, "freq=");
1660 if (pos)
1661 data.dfs_event.freq = atoi(pos + 5);
1662
1663 pos = os_strstr(param, "ht_enabled=1");
1664 if (pos)
1665 data.dfs_event.ht_enabled = 1;
1666
1667 pos = os_strstr(param, "chan_offset=");
1668 if (pos)
1669 data.dfs_event.chan_offset = atoi(pos + 12);
1670
1671 pos = os_strstr(param, "chan_width=");
1672 if (pos)
1673 data.dfs_event.chan_width = atoi(pos + 11);
1674
1675 pos = os_strstr(param, "cf1=");
1676 if (pos)
1677 data.dfs_event.cf1 = atoi(pos + 4);
1678
1679 pos = os_strstr(param, "cf2=");
1680 if (pos)
1681 data.dfs_event.cf2 = atoi(pos + 4);
1682
1683 wpa_supplicant_event(hapd, event, &data);
1684
1685 return 0;
1686}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001687
1688
1689static int hostapd_ctrl_iface_mgmt_tx(struct hostapd_data *hapd, char *cmd)
1690{
1691 size_t len;
1692 u8 *buf;
1693 int res;
1694
1695 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
1696
1697 len = os_strlen(cmd);
1698 if (len & 1)
1699 return -1;
1700 len /= 2;
1701
1702 buf = os_malloc(len);
1703 if (buf == NULL)
1704 return -1;
1705
1706 if (hexstr2bin(cmd, buf, len) < 0) {
1707 os_free(buf);
1708 return -1;
1709 }
1710
Hai Shalomfdcde762020-04-02 11:19:20 -07001711 res = hostapd_drv_send_mlme(hapd, buf, len, 0, NULL, 0, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001712 os_free(buf);
1713 return res;
1714}
1715
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001716
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001717static int hostapd_ctrl_iface_mgmt_tx_status_process(struct hostapd_data *hapd,
1718 char *cmd)
1719{
1720 char *pos, *param;
1721 size_t len;
1722 u8 *buf;
1723 int stype = 0, ok = 0;
1724 union wpa_event_data event;
1725
1726 if (!hapd->ext_mgmt_frame_handling)
1727 return -1;
1728
1729 /* stype=<val> ok=<0/1> buf=<frame hexdump> */
1730
1731 wpa_printf(MSG_DEBUG, "External MGMT TX status process: %s", cmd);
1732
1733 pos = cmd;
1734 param = os_strstr(pos, "stype=");
1735 if (param) {
1736 param += 6;
1737 stype = atoi(param);
1738 }
1739
1740 param = os_strstr(pos, " ok=");
1741 if (param) {
1742 param += 4;
1743 ok = atoi(param);
1744 }
1745
1746 param = os_strstr(pos, " buf=");
1747 if (!param)
1748 return -1;
1749 param += 5;
1750
1751 len = os_strlen(param);
1752 if (len & 1)
1753 return -1;
1754 len /= 2;
1755
1756 buf = os_malloc(len);
1757 if (!buf || hexstr2bin(param, buf, len) < 0) {
1758 os_free(buf);
1759 return -1;
1760 }
1761
1762 os_memset(&event, 0, sizeof(event));
1763 event.tx_status.type = WLAN_FC_TYPE_MGMT;
1764 event.tx_status.data = buf;
1765 event.tx_status.data_len = len;
1766 event.tx_status.stype = stype;
1767 event.tx_status.ack = ok;
1768 hapd->ext_mgmt_frame_handling = 0;
1769 wpa_supplicant_event(hapd, EVENT_TX_STATUS, &event);
1770 hapd->ext_mgmt_frame_handling = 1;
1771
1772 os_free(buf);
1773
1774 return 0;
1775}
1776
1777
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08001778static int hostapd_ctrl_iface_mgmt_rx_process(struct hostapd_data *hapd,
1779 char *cmd)
1780{
1781 char *pos, *param;
1782 size_t len;
1783 u8 *buf;
1784 int freq = 0, datarate = 0, ssi_signal = 0;
1785 union wpa_event_data event;
1786
1787 if (!hapd->ext_mgmt_frame_handling)
1788 return -1;
1789
1790 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
1791
1792 wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
1793
1794 pos = cmd;
1795 param = os_strstr(pos, "freq=");
1796 if (param) {
1797 param += 5;
1798 freq = atoi(param);
1799 }
1800
1801 param = os_strstr(pos, " datarate=");
1802 if (param) {
1803 param += 10;
1804 datarate = atoi(param);
1805 }
1806
1807 param = os_strstr(pos, " ssi_signal=");
1808 if (param) {
1809 param += 12;
1810 ssi_signal = atoi(param);
1811 }
1812
1813 param = os_strstr(pos, " frame=");
1814 if (param == NULL)
1815 return -1;
1816 param += 7;
1817
1818 len = os_strlen(param);
1819 if (len & 1)
1820 return -1;
1821 len /= 2;
1822
1823 buf = os_malloc(len);
1824 if (buf == NULL)
1825 return -1;
1826
1827 if (hexstr2bin(param, buf, len) < 0) {
1828 os_free(buf);
1829 return -1;
1830 }
1831
1832 os_memset(&event, 0, sizeof(event));
1833 event.rx_mgmt.freq = freq;
1834 event.rx_mgmt.frame = buf;
1835 event.rx_mgmt.frame_len = len;
1836 event.rx_mgmt.ssi_signal = ssi_signal;
1837 event.rx_mgmt.datarate = datarate;
1838 hapd->ext_mgmt_frame_handling = 0;
1839 wpa_supplicant_event(hapd, EVENT_RX_MGMT, &event);
1840 hapd->ext_mgmt_frame_handling = 1;
1841
1842 os_free(buf);
1843
1844 return 0;
1845}
1846
1847
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001848static int hostapd_ctrl_iface_eapol_rx(struct hostapd_data *hapd, char *cmd)
1849{
1850 char *pos;
1851 u8 src[ETH_ALEN], *buf;
1852 int used;
1853 size_t len;
1854
1855 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
1856
1857 pos = cmd;
1858 used = hwaddr_aton2(pos, src);
1859 if (used < 0)
1860 return -1;
1861 pos += used;
1862 while (*pos == ' ')
1863 pos++;
1864
1865 len = os_strlen(pos);
1866 if (len & 1)
1867 return -1;
1868 len /= 2;
1869
1870 buf = os_malloc(len);
1871 if (buf == NULL)
1872 return -1;
1873
1874 if (hexstr2bin(pos, buf, len) < 0) {
1875 os_free(buf);
1876 return -1;
1877 }
1878
1879 ieee802_1x_receive(hapd, src, buf, len);
1880 os_free(buf);
1881
1882 return 0;
1883}
1884
1885
1886static u16 ipv4_hdr_checksum(const void *buf, size_t len)
1887{
1888 size_t i;
1889 u32 sum = 0;
1890 const u16 *pos = buf;
1891
1892 for (i = 0; i < len / 2; i++)
1893 sum += *pos++;
1894
1895 while (sum >> 16)
1896 sum = (sum & 0xffff) + (sum >> 16);
1897
1898 return sum ^ 0xffff;
1899}
1900
1901
1902#define HWSIM_PACKETLEN 1500
1903#define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
1904
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07001905static void hostapd_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
1906 size_t len)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001907{
1908 struct hostapd_data *hapd = ctx;
1909 const struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07001910 struct ip ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001911 const u8 *pos;
1912 unsigned int i;
Hai Shalom81f62d82019-07-22 12:10:00 -07001913 char extra[30];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001914
Hai Shalom81f62d82019-07-22 12:10:00 -07001915 if (len < sizeof(*eth) + sizeof(ip) || len > HWSIM_PACKETLEN) {
1916 wpa_printf(MSG_DEBUG,
1917 "test data: RX - ignore unexpected length %d",
1918 (int) len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001919 return;
Hai Shalom81f62d82019-07-22 12:10:00 -07001920 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001921
1922 eth = (const struct ether_header *) buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001923 os_memcpy(&ip, eth + 1, sizeof(ip));
1924 pos = &buf[sizeof(*eth) + sizeof(ip)];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001925
Hai Shalomfdcde762020-04-02 11:19:20 -07001926 if (ip.ip_hl != 5 || ip.ip_v != 4 ||
1927 ntohs(ip.ip_len) > HWSIM_IP_LEN) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001928 wpa_printf(MSG_DEBUG,
Hai Shalom899fcc72020-10-19 14:38:18 -07001929 "test data: RX - ignore unexpected IP header");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001930 return;
Hai Shalom81f62d82019-07-22 12:10:00 -07001931 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001932
Hai Shalomfdcde762020-04-02 11:19:20 -07001933 for (i = 0; i < ntohs(ip.ip_len) - sizeof(ip); i++) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001934 if (*pos != (u8) i) {
1935 wpa_printf(MSG_DEBUG,
1936 "test data: RX - ignore mismatching payload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001937 return;
Hai Shalom81f62d82019-07-22 12:10:00 -07001938 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001939 pos++;
1940 }
1941
Hai Shalom81f62d82019-07-22 12:10:00 -07001942 extra[0] = '\0';
Hai Shalomfdcde762020-04-02 11:19:20 -07001943 if (ntohs(ip.ip_len) != HWSIM_IP_LEN)
1944 os_snprintf(extra, sizeof(extra), " len=%d", ntohs(ip.ip_len));
Hai Shalom81f62d82019-07-22 12:10:00 -07001945 wpa_msg(hapd->msg_ctx, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR "%s",
1946 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost), extra);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001947}
1948
1949
1950static int hostapd_ctrl_iface_data_test_config(struct hostapd_data *hapd,
1951 char *cmd)
1952{
1953 int enabled = atoi(cmd);
1954 char *pos;
1955 const char *ifname;
1956
1957 if (!enabled) {
1958 if (hapd->l2_test) {
1959 l2_packet_deinit(hapd->l2_test);
1960 hapd->l2_test = NULL;
1961 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1962 "test data: Disabled");
1963 }
1964 return 0;
1965 }
1966
1967 if (hapd->l2_test)
1968 return 0;
1969
1970 pos = os_strstr(cmd, " ifname=");
1971 if (pos)
1972 ifname = pos + 8;
1973 else
1974 ifname = hapd->conf->iface;
1975
1976 hapd->l2_test = l2_packet_init(ifname, hapd->own_addr,
1977 ETHERTYPE_IP, hostapd_data_test_rx,
1978 hapd, 1);
1979 if (hapd->l2_test == NULL)
1980 return -1;
1981
1982 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: Enabled");
1983
1984 return 0;
1985}
1986
1987
1988static int hostapd_ctrl_iface_data_test_tx(struct hostapd_data *hapd, char *cmd)
1989{
1990 u8 dst[ETH_ALEN], src[ETH_ALEN];
Hai Shalom81f62d82019-07-22 12:10:00 -07001991 char *pos, *pos2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001992 int used;
1993 long int val;
1994 u8 tos;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001995 u8 buf[2 + HWSIM_PACKETLEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001996 struct ether_header *eth;
Hai Shalomfdcde762020-04-02 11:19:20 -07001997 struct ip *ip;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001998 u8 *dpos;
1999 unsigned int i;
Hai Shalom81f62d82019-07-22 12:10:00 -07002000 size_t send_len = HWSIM_IP_LEN;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002001
2002 if (hapd->l2_test == NULL)
2003 return -1;
2004
Hai Shalom81f62d82019-07-22 12:10:00 -07002005 /* format: <dst> <src> <tos> [len=<length>] */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002006
2007 pos = cmd;
2008 used = hwaddr_aton2(pos, dst);
2009 if (used < 0)
2010 return -1;
2011 pos += used;
2012 while (*pos == ' ')
2013 pos++;
2014 used = hwaddr_aton2(pos, src);
2015 if (used < 0)
2016 return -1;
2017 pos += used;
2018
Hai Shalom81f62d82019-07-22 12:10:00 -07002019 val = strtol(pos, &pos2, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002020 if (val < 0 || val > 0xff)
2021 return -1;
2022 tos = val;
2023
Hai Shalom81f62d82019-07-22 12:10:00 -07002024 pos = os_strstr(pos2, " len=");
2025 if (pos) {
2026 i = atoi(pos + 5);
2027 if (i < sizeof(*ip) || i > HWSIM_IP_LEN)
2028 return -1;
2029 send_len = i;
2030 }
2031
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002032 eth = (struct ether_header *) &buf[2];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002033 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
2034 os_memcpy(eth->ether_shost, src, ETH_ALEN);
2035 eth->ether_type = htons(ETHERTYPE_IP);
Hai Shalomfdcde762020-04-02 11:19:20 -07002036 ip = (struct ip *) (eth + 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002037 os_memset(ip, 0, sizeof(*ip));
Hai Shalomfdcde762020-04-02 11:19:20 -07002038 ip->ip_hl = 5;
2039 ip->ip_v = 4;
2040 ip->ip_ttl = 64;
2041 ip->ip_tos = tos;
2042 ip->ip_len = htons(send_len);
2043 ip->ip_p = 1;
2044 ip->ip_src.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
2045 ip->ip_dst.s_addr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
2046 ip->ip_sum = ipv4_hdr_checksum(ip, sizeof(*ip));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002047 dpos = (u8 *) (ip + 1);
Hai Shalom81f62d82019-07-22 12:10:00 -07002048 for (i = 0; i < send_len - sizeof(*ip); i++)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002049 *dpos++ = i;
2050
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002051 if (l2_packet_send(hapd->l2_test, dst, ETHERTYPE_IP, &buf[2],
Hai Shalom81f62d82019-07-22 12:10:00 -07002052 sizeof(struct ether_header) + send_len) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002053 return -1;
2054
2055 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: TX dst=" MACSTR
2056 " src=" MACSTR " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
2057
2058 return 0;
2059}
2060
2061
2062static int hostapd_ctrl_iface_data_test_frame(struct hostapd_data *hapd,
2063 char *cmd)
2064{
2065 u8 *buf;
2066 struct ether_header *eth;
2067 struct l2_packet_data *l2 = NULL;
2068 size_t len;
2069 u16 ethertype;
2070 int res = -1;
2071 const char *ifname = hapd->conf->iface;
2072
2073 if (os_strncmp(cmd, "ifname=", 7) == 0) {
2074 cmd += 7;
2075 ifname = cmd;
2076 cmd = os_strchr(cmd, ' ');
2077 if (cmd == NULL)
2078 return -1;
2079 *cmd++ = '\0';
2080 }
2081
2082 len = os_strlen(cmd);
2083 if (len & 1 || len < ETH_HLEN * 2)
2084 return -1;
2085 len /= 2;
2086
2087 buf = os_malloc(len);
2088 if (buf == NULL)
2089 return -1;
2090
2091 if (hexstr2bin(cmd, buf, len) < 0)
2092 goto done;
2093
2094 eth = (struct ether_header *) buf;
2095 ethertype = ntohs(eth->ether_type);
2096
2097 l2 = l2_packet_init(ifname, hapd->own_addr, ethertype,
2098 hostapd_data_test_rx, hapd, 1);
2099 if (l2 == NULL)
2100 goto done;
2101
2102 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
2103 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "test data: TX frame res=%d", res);
2104done:
2105 if (l2)
2106 l2_packet_deinit(l2);
2107 os_free(buf);
2108
2109 return res < 0 ? -1 : 0;
2110}
2111
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002112
2113static int hostapd_ctrl_test_alloc_fail(struct hostapd_data *hapd, char *cmd)
2114{
2115#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002116 char *pos;
2117
2118 wpa_trace_fail_after = atoi(cmd);
2119 pos = os_strchr(cmd, ':');
2120 if (pos) {
2121 pos++;
2122 os_strlcpy(wpa_trace_fail_func, pos,
2123 sizeof(wpa_trace_fail_func));
2124 } else {
2125 wpa_trace_fail_after = 0;
2126 }
2127
2128 return 0;
2129#else /* WPA_TRACE_BFD */
2130 return -1;
2131#endif /* WPA_TRACE_BFD */
2132}
2133
2134
2135static int hostapd_ctrl_get_alloc_fail(struct hostapd_data *hapd,
2136 char *buf, size_t buflen)
2137{
2138#ifdef WPA_TRACE_BFD
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002139 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
2140 wpa_trace_fail_func);
2141#else /* WPA_TRACE_BFD */
2142 return -1;
2143#endif /* WPA_TRACE_BFD */
2144}
2145
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002146
2147static int hostapd_ctrl_test_fail(struct hostapd_data *hapd, char *cmd)
2148{
2149#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002150 char *pos;
2151
2152 wpa_trace_test_fail_after = atoi(cmd);
2153 pos = os_strchr(cmd, ':');
2154 if (pos) {
2155 pos++;
2156 os_strlcpy(wpa_trace_test_fail_func, pos,
2157 sizeof(wpa_trace_test_fail_func));
2158 } else {
2159 wpa_trace_test_fail_after = 0;
2160 }
2161
2162 return 0;
2163#else /* WPA_TRACE_BFD */
2164 return -1;
2165#endif /* WPA_TRACE_BFD */
2166}
2167
2168
2169static int hostapd_ctrl_get_fail(struct hostapd_data *hapd,
2170 char *buf, size_t buflen)
2171{
2172#ifdef WPA_TRACE_BFD
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002173 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
2174 wpa_trace_test_fail_func);
2175#else /* WPA_TRACE_BFD */
2176 return -1;
2177#endif /* WPA_TRACE_BFD */
2178}
2179
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002180
2181static int hostapd_ctrl_reset_pn(struct hostapd_data *hapd, const char *cmd)
2182{
2183 struct sta_info *sta;
2184 u8 addr[ETH_ALEN];
2185 u8 zero[WPA_TK_MAX_LEN];
2186
2187 os_memset(zero, 0, sizeof(zero));
2188
2189 if (hwaddr_aton(cmd, addr))
2190 return -1;
2191
Hai Shalom4fbc08f2020-05-18 12:37:00 -07002192 if (is_broadcast_ether_addr(addr) && os_strstr(cmd, " BIGTK")) {
2193 if (hapd->last_bigtk_alg == WPA_ALG_NONE)
2194 return -1;
2195
2196 wpa_printf(MSG_INFO, "TESTING: Reset BIPN for BIGTK");
2197
2198 /* First, use a zero key to avoid any possible duplicate key
2199 * avoidance in the driver. */
2200 if (hostapd_drv_set_key(hapd->conf->iface, hapd,
2201 hapd->last_bigtk_alg,
2202 broadcast_ether_addr,
2203 hapd->last_bigtk_key_idx, 0, 1, NULL, 0,
2204 zero, hapd->last_bigtk_len,
2205 KEY_FLAG_GROUP_TX_DEFAULT) < 0)
2206 return -1;
2207
2208 /* Set the previously configured key to reset its TSC */
2209 return hostapd_drv_set_key(hapd->conf->iface, hapd,
2210 hapd->last_bigtk_alg,
2211 broadcast_ether_addr,
2212 hapd->last_bigtk_key_idx, 0, 1, NULL,
2213 0, hapd->last_bigtk,
2214 hapd->last_bigtk_len,
2215 KEY_FLAG_GROUP_TX_DEFAULT);
2216 }
2217
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002218 if (is_broadcast_ether_addr(addr) && os_strstr(cmd, "IGTK")) {
2219 if (hapd->last_igtk_alg == WPA_ALG_NONE)
2220 return -1;
2221
2222 wpa_printf(MSG_INFO, "TESTING: Reset IPN for IGTK");
2223
2224 /* First, use a zero key to avoid any possible duplicate key
2225 * avoidance in the driver. */
2226 if (hostapd_drv_set_key(hapd->conf->iface, hapd,
2227 hapd->last_igtk_alg,
2228 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002229 hapd->last_igtk_key_idx, 0, 1, NULL, 0,
2230 zero, hapd->last_igtk_len,
2231 KEY_FLAG_GROUP_TX_DEFAULT) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002232 return -1;
2233
2234 /* Set the previously configured key to reset its TSC */
2235 return hostapd_drv_set_key(hapd->conf->iface, hapd,
2236 hapd->last_igtk_alg,
2237 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002238 hapd->last_igtk_key_idx, 0, 1, NULL,
2239 0, hapd->last_igtk,
2240 hapd->last_igtk_len,
2241 KEY_FLAG_GROUP_TX_DEFAULT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002242 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002243
2244 if (is_broadcast_ether_addr(addr)) {
2245 if (hapd->last_gtk_alg == WPA_ALG_NONE)
2246 return -1;
2247
2248 wpa_printf(MSG_INFO, "TESTING: Reset PN for GTK");
2249
2250 /* First, use a zero key to avoid any possible duplicate key
2251 * avoidance in the driver. */
2252 if (hostapd_drv_set_key(hapd->conf->iface, hapd,
2253 hapd->last_gtk_alg,
2254 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002255 hapd->last_gtk_key_idx, 0, 1, NULL, 0,
2256 zero, hapd->last_gtk_len,
2257 KEY_FLAG_GROUP_TX_DEFAULT) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002258 return -1;
2259
2260 /* Set the previously configured key to reset its TSC */
2261 return hostapd_drv_set_key(hapd->conf->iface, hapd,
2262 hapd->last_gtk_alg,
2263 broadcast_ether_addr,
Hai Shalomfdcde762020-04-02 11:19:20 -07002264 hapd->last_gtk_key_idx, 0, 1, NULL,
2265 0, hapd->last_gtk,
2266 hapd->last_gtk_len,
2267 KEY_FLAG_GROUP_TX_DEFAULT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002268 }
2269
2270 sta = ap_get_sta(hapd, addr);
2271 if (!sta)
2272 return -1;
2273
2274 if (sta->last_tk_alg == WPA_ALG_NONE)
2275 return -1;
2276
2277 wpa_printf(MSG_INFO, "TESTING: Reset PN for " MACSTR,
2278 MAC2STR(sta->addr));
2279
2280 /* First, use a zero key to avoid any possible duplicate key avoidance
2281 * in the driver. */
2282 if (hostapd_drv_set_key(hapd->conf->iface, hapd, sta->last_tk_alg,
Hai Shalomfdcde762020-04-02 11:19:20 -07002283 sta->addr, sta->last_tk_key_idx, 0, 1, NULL, 0,
2284 zero, sta->last_tk_len,
2285 KEY_FLAG_PAIRWISE_RX_TX) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002286 return -1;
2287
2288 /* Set the previously configured key to reset its TSC/RSC */
2289 return hostapd_drv_set_key(hapd->conf->iface, hapd, sta->last_tk_alg,
Hai Shalomfdcde762020-04-02 11:19:20 -07002290 sta->addr, sta->last_tk_key_idx, 0, 1, NULL,
2291 0, sta->last_tk, sta->last_tk_len,
2292 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002293}
2294
2295
2296static int hostapd_ctrl_set_key(struct hostapd_data *hapd, const char *cmd)
2297{
2298 u8 addr[ETH_ALEN];
2299 const char *pos = cmd;
2300 enum wpa_alg alg;
Hai Shalomfdcde762020-04-02 11:19:20 -07002301 enum key_flag key_flag;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002302 int idx, set_tx;
2303 u8 seq[6], key[WPA_TK_MAX_LEN];
2304 size_t key_len;
2305
Hai Shalomfdcde762020-04-02 11:19:20 -07002306 /* parameters: alg addr idx set_tx seq key key_flag */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002307
2308 alg = atoi(pos);
2309 pos = os_strchr(pos, ' ');
2310 if (!pos)
2311 return -1;
2312 pos++;
2313 if (hwaddr_aton(pos, addr))
2314 return -1;
2315 pos += 17;
2316 if (*pos != ' ')
2317 return -1;
2318 pos++;
2319 idx = atoi(pos);
2320 pos = os_strchr(pos, ' ');
2321 if (!pos)
2322 return -1;
2323 pos++;
2324 set_tx = atoi(pos);
2325 pos = os_strchr(pos, ' ');
2326 if (!pos)
2327 return -1;
2328 pos++;
Hai Shalom74f70d42019-02-11 14:42:39 -08002329 if (hexstr2bin(pos, seq, sizeof(seq)) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002330 return -1;
2331 pos += 2 * 6;
2332 if (*pos != ' ')
2333 return -1;
2334 pos++;
Hai Shalomfdcde762020-04-02 11:19:20 -07002335 if (!os_strchr(pos, ' '))
2336 return -1;
2337 key_len = (os_strchr(pos, ' ') - pos) / 2;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002338 if (hexstr2bin(pos, key, key_len) < 0)
2339 return -1;
Hai Shalomfdcde762020-04-02 11:19:20 -07002340 pos += 2 * key_len;
2341 if (*pos != ' ')
2342 return -1;
2343
2344 pos++;
2345 key_flag = atoi(pos);
2346 pos = os_strchr(pos, ' ');
2347 if (pos)
2348 return -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002349
2350 wpa_printf(MSG_INFO, "TESTING: Set key");
Hai Shalomfdcde762020-04-02 11:19:20 -07002351 return hostapd_drv_set_key(hapd->conf->iface, hapd, alg, addr, idx, 0,
2352 set_tx, seq, 6, key, key_len, key_flag);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002353}
2354
2355
2356static void restore_tk(void *ctx1, void *ctx2)
2357{
2358 struct hostapd_data *hapd = ctx1;
2359 struct sta_info *sta = ctx2;
2360
2361 wpa_printf(MSG_INFO, "TESTING: Restore TK for " MACSTR,
2362 MAC2STR(sta->addr));
2363 /* This does not really restore the TSC properly, so this will result
2364 * in replay protection issues for now since there is no clean way of
2365 * preventing encryption of a single EAPOL frame. */
2366 hostapd_drv_set_key(hapd->conf->iface, hapd, sta->last_tk_alg,
Hai Shalomfdcde762020-04-02 11:19:20 -07002367 sta->addr, sta->last_tk_key_idx, 0, 1, NULL, 0,
2368 sta->last_tk, sta->last_tk_len,
2369 KEY_FLAG_PAIRWISE_RX_TX);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002370}
2371
2372
2373static int hostapd_ctrl_resend_m1(struct hostapd_data *hapd, const char *cmd)
2374{
2375 struct sta_info *sta;
2376 u8 addr[ETH_ALEN];
2377 int plain = os_strstr(cmd, "plaintext") != NULL;
2378
2379 if (hwaddr_aton(cmd, addr))
2380 return -1;
2381
2382 sta = ap_get_sta(hapd, addr);
2383 if (!sta || !sta->wpa_sm)
2384 return -1;
2385
2386 if (plain && sta->last_tk_alg == WPA_ALG_NONE)
2387 plain = 0; /* no need for special processing */
2388 if (plain) {
2389 wpa_printf(MSG_INFO, "TESTING: Clear TK for " MACSTR,
2390 MAC2STR(sta->addr));
2391 hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
Hai Shalomfdcde762020-04-02 11:19:20 -07002392 sta->addr, sta->last_tk_key_idx, 0, 0, NULL,
2393 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002394 }
2395
2396 wpa_printf(MSG_INFO, "TESTING: Send M1 to " MACSTR, MAC2STR(sta->addr));
2397 return wpa_auth_resend_m1(sta->wpa_sm,
2398 os_strstr(cmd, "change-anonce") != NULL,
2399 plain ? restore_tk : NULL, hapd, sta);
2400}
2401
2402
2403static int hostapd_ctrl_resend_m3(struct hostapd_data *hapd, const char *cmd)
2404{
2405 struct sta_info *sta;
2406 u8 addr[ETH_ALEN];
2407 int plain = os_strstr(cmd, "plaintext") != NULL;
2408
2409 if (hwaddr_aton(cmd, addr))
2410 return -1;
2411
2412 sta = ap_get_sta(hapd, addr);
2413 if (!sta || !sta->wpa_sm)
2414 return -1;
2415
2416 if (plain && sta->last_tk_alg == WPA_ALG_NONE)
2417 plain = 0; /* no need for special processing */
2418 if (plain) {
2419 wpa_printf(MSG_INFO, "TESTING: Clear TK for " MACSTR,
2420 MAC2STR(sta->addr));
2421 hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
Hai Shalomfdcde762020-04-02 11:19:20 -07002422 sta->addr, sta->last_tk_key_idx, 0, 0, NULL,
2423 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002424 }
2425
2426 wpa_printf(MSG_INFO, "TESTING: Send M3 to " MACSTR, MAC2STR(sta->addr));
2427 return wpa_auth_resend_m3(sta->wpa_sm,
2428 plain ? restore_tk : NULL, hapd, sta);
2429}
2430
2431
2432static int hostapd_ctrl_resend_group_m1(struct hostapd_data *hapd,
2433 const char *cmd)
2434{
2435 struct sta_info *sta;
2436 u8 addr[ETH_ALEN];
2437 int plain = os_strstr(cmd, "plaintext") != NULL;
2438
2439 if (hwaddr_aton(cmd, addr))
2440 return -1;
2441
2442 sta = ap_get_sta(hapd, addr);
2443 if (!sta || !sta->wpa_sm)
2444 return -1;
2445
2446 if (plain && sta->last_tk_alg == WPA_ALG_NONE)
2447 plain = 0; /* no need for special processing */
2448 if (plain) {
2449 wpa_printf(MSG_INFO, "TESTING: Clear TK for " MACSTR,
2450 MAC2STR(sta->addr));
2451 hostapd_drv_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
Hai Shalomfdcde762020-04-02 11:19:20 -07002452 sta->addr, sta->last_tk_key_idx, 0, 0, NULL,
2453 0, NULL, 0, KEY_FLAG_PAIRWISE);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002454 }
2455
2456 wpa_printf(MSG_INFO,
2457 "TESTING: Send group M1 for the same GTK and zero RSC to "
2458 MACSTR, MAC2STR(sta->addr));
2459 return wpa_auth_resend_group_m1(sta->wpa_sm,
2460 plain ? restore_tk : NULL, hapd, sta);
2461}
2462
Hai Shalomfdcde762020-04-02 11:19:20 -07002463
Hai Shalom899fcc72020-10-19 14:38:18 -07002464static int hostapd_ctrl_get_pmksa_pmk(struct hostapd_data *hapd, const u8 *addr,
2465 char *buf, size_t buflen)
2466{
2467 struct rsn_pmksa_cache_entry *pmksa;
2468
2469 pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, addr, NULL);
2470 if (!pmksa)
2471 return -1;
2472
2473 return wpa_snprintf_hex(buf, buflen, pmksa->pmk, pmksa->pmk_len);
2474}
2475
2476
Hai Shalomfdcde762020-04-02 11:19:20 -07002477static int hostapd_ctrl_get_pmk(struct hostapd_data *hapd, const char *cmd,
2478 char *buf, size_t buflen)
2479{
2480 struct sta_info *sta;
2481 u8 addr[ETH_ALEN];
2482 const u8 *pmk;
2483 int pmk_len;
2484
2485 if (hwaddr_aton(cmd, addr))
2486 return -1;
2487
2488 sta = ap_get_sta(hapd, addr);
2489 if (!sta || !sta->wpa_sm) {
2490 wpa_printf(MSG_DEBUG, "No STA WPA state machine for " MACSTR,
2491 MAC2STR(addr));
Hai Shalom899fcc72020-10-19 14:38:18 -07002492 return hostapd_ctrl_get_pmksa_pmk(hapd, addr, buf, buflen);
Hai Shalomfdcde762020-04-02 11:19:20 -07002493 }
2494 pmk = wpa_auth_get_pmk(sta->wpa_sm, &pmk_len);
Hai Shalom899fcc72020-10-19 14:38:18 -07002495 if (!pmk || !pmk_len) {
Hai Shalomfdcde762020-04-02 11:19:20 -07002496 wpa_printf(MSG_DEBUG, "No PMK stored for " MACSTR,
2497 MAC2STR(addr));
Hai Shalom899fcc72020-10-19 14:38:18 -07002498 return hostapd_ctrl_get_pmksa_pmk(hapd, addr, buf, buflen);
Hai Shalomfdcde762020-04-02 11:19:20 -07002499 }
2500
2501 return wpa_snprintf_hex(buf, buflen, pmk, pmk_len);
2502}
2503
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002504#endif /* CONFIG_TESTING_OPTIONS */
2505
2506
Hai Shalomb755a2a2020-04-23 21:49:02 -07002507#ifdef NEED_AP_MLME
Hai Shalomfdcde762020-04-02 11:19:20 -07002508static int hostapd_ctrl_check_freq_params(struct hostapd_freq_params *params)
2509{
2510 switch (params->bandwidth) {
2511 case 0:
2512 /* bandwidth not specified: use 20 MHz by default */
2513 /* fall-through */
2514 case 20:
2515 if (params->center_freq1 &&
2516 params->center_freq1 != params->freq)
2517 return -1;
2518
2519 if (params->center_freq2 || params->sec_channel_offset)
2520 return -1;
2521 break;
2522 case 40:
2523 if (params->center_freq2 || !params->sec_channel_offset)
2524 return -1;
2525
2526 if (!params->center_freq1)
2527 break;
2528 switch (params->sec_channel_offset) {
2529 case 1:
2530 if (params->freq + 10 != params->center_freq1)
2531 return -1;
2532 break;
2533 case -1:
2534 if (params->freq - 10 != params->center_freq1)
2535 return -1;
2536 break;
2537 default:
2538 return -1;
2539 }
2540 break;
2541 case 80:
2542 if (!params->center_freq1 || !params->sec_channel_offset)
2543 return 1;
2544
2545 switch (params->sec_channel_offset) {
2546 case 1:
2547 if (params->freq - 10 != params->center_freq1 &&
2548 params->freq + 30 != params->center_freq1)
2549 return 1;
2550 break;
2551 case -1:
2552 if (params->freq + 10 != params->center_freq1 &&
2553 params->freq - 30 != params->center_freq1)
2554 return -1;
2555 break;
2556 default:
2557 return -1;
2558 }
2559
2560 /* Adjacent and overlapped are not allowed for 80+80 */
2561 if (params->center_freq2 &&
2562 params->center_freq1 - params->center_freq2 <= 80 &&
2563 params->center_freq2 - params->center_freq1 <= 80)
2564 return 1;
2565 break;
2566 case 160:
2567 if (!params->center_freq1 || params->center_freq2 ||
2568 !params->sec_channel_offset)
2569 return -1;
2570
2571 switch (params->sec_channel_offset) {
2572 case 1:
2573 if (params->freq + 70 != params->center_freq1 &&
2574 params->freq + 30 != params->center_freq1 &&
2575 params->freq - 10 != params->center_freq1 &&
2576 params->freq - 50 != params->center_freq1)
2577 return -1;
2578 break;
2579 case -1:
2580 if (params->freq + 50 != params->center_freq1 &&
2581 params->freq + 10 != params->center_freq1 &&
2582 params->freq - 30 != params->center_freq1 &&
2583 params->freq - 70 != params->center_freq1)
2584 return -1;
2585 break;
2586 default:
2587 return -1;
2588 }
2589 break;
2590 default:
2591 return -1;
2592 }
2593
2594 return 0;
2595}
Hai Shalomb755a2a2020-04-23 21:49:02 -07002596#endif /* NEED_AP_MLME */
Hai Shalomfdcde762020-04-02 11:19:20 -07002597
2598
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002599static int hostapd_ctrl_iface_chan_switch(struct hostapd_iface *iface,
2600 char *pos)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002601{
2602#ifdef NEED_AP_MLME
2603 struct csa_settings settings;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002604 int ret;
Hai Shalomfdcde762020-04-02 11:19:20 -07002605 int dfs_range = 0;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002606 unsigned int i;
Hai Shalomfdcde762020-04-02 11:19:20 -07002607 int bandwidth;
2608 u8 chan;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002609
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002610 ret = hostapd_parse_csa_settings(pos, &settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002611 if (ret)
2612 return ret;
2613
Hai Shalomfdcde762020-04-02 11:19:20 -07002614 ret = hostapd_ctrl_check_freq_params(&settings.freq_params);
2615 if (ret) {
2616 wpa_printf(MSG_INFO,
2617 "chanswitch: invalid frequency settings provided");
2618 return ret;
2619 }
2620
2621 switch (settings.freq_params.bandwidth) {
2622 case 40:
2623 bandwidth = CHAN_WIDTH_40;
2624 break;
2625 case 80:
2626 if (settings.freq_params.center_freq2)
2627 bandwidth = CHAN_WIDTH_80P80;
2628 else
2629 bandwidth = CHAN_WIDTH_80;
2630 break;
2631 case 160:
2632 bandwidth = CHAN_WIDTH_160;
2633 break;
2634 default:
2635 bandwidth = CHAN_WIDTH_20;
2636 break;
2637 }
2638
2639 if (settings.freq_params.center_freq1)
2640 dfs_range += hostapd_is_dfs_overlap(
2641 iface, bandwidth, settings.freq_params.center_freq1);
2642 else
2643 dfs_range += hostapd_is_dfs_overlap(
2644 iface, bandwidth, settings.freq_params.freq);
2645
2646 if (settings.freq_params.center_freq2)
2647 dfs_range += hostapd_is_dfs_overlap(
2648 iface, bandwidth, settings.freq_params.center_freq2);
2649
2650 if (dfs_range) {
2651 ret = ieee80211_freq_to_chan(settings.freq_params.freq, &chan);
2652 if (ret == NUM_HOSTAPD_MODES) {
2653 wpa_printf(MSG_ERROR,
2654 "Failed to get channel for (freq=%d, sec_channel_offset=%d, bw=%d)",
2655 settings.freq_params.freq,
2656 settings.freq_params.sec_channel_offset,
2657 settings.freq_params.bandwidth);
2658 return -1;
2659 }
2660
2661 settings.freq_params.channel = chan;
2662
2663 wpa_printf(MSG_DEBUG,
2664 "DFS/CAC to (channel=%u, freq=%d, sec_channel_offset=%d, bw=%d, center_freq1=%d)",
2665 settings.freq_params.channel,
2666 settings.freq_params.freq,
2667 settings.freq_params.sec_channel_offset,
2668 settings.freq_params.bandwidth,
2669 settings.freq_params.center_freq1);
2670
2671 /* Perform CAC and switch channel */
2672 hostapd_switch_channel_fallback(iface, &settings.freq_params);
2673 return 0;
2674 }
2675
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002676 for (i = 0; i < iface->num_bss; i++) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07002677
2678 /* Save CHAN_SWITCH VHT config */
2679 hostapd_chan_switch_vht_config(
2680 iface->bss[i], settings.freq_params.vht_enabled);
2681
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07002682 ret = hostapd_switch_channel(iface->bss[i], &settings);
2683 if (ret) {
2684 /* FIX: What do we do if CSA fails in the middle of
2685 * submitting multi-BSS CSA requests? */
2686 return ret;
2687 }
2688 }
2689
2690 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002691#else /* NEED_AP_MLME */
2692 return -1;
2693#endif /* NEED_AP_MLME */
2694}
2695
2696
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002697static int hostapd_ctrl_iface_mib(struct hostapd_data *hapd, char *reply,
2698 int reply_size, const char *param)
2699{
2700#ifdef RADIUS_SERVER
2701 if (os_strcmp(param, "radius_server") == 0) {
2702 return radius_server_get_mib(hapd->radius_srv, reply,
2703 reply_size);
2704 }
2705#endif /* RADIUS_SERVER */
2706 return -1;
2707}
2708
2709
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002710static int hostapd_ctrl_iface_vendor(struct hostapd_data *hapd, char *cmd,
2711 char *buf, size_t buflen)
2712{
2713 int ret;
2714 char *pos;
2715 u8 *data = NULL;
2716 unsigned int vendor_id, subcmd;
2717 struct wpabuf *reply;
2718 size_t data_len = 0;
2719
2720 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
2721 vendor_id = strtoul(cmd, &pos, 16);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002722 if (!isblank((unsigned char) *pos))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002723 return -EINVAL;
2724
2725 subcmd = strtoul(pos, &pos, 10);
2726
2727 if (*pos != '\0') {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08002728 if (!isblank((unsigned char) *pos++))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07002729 return -EINVAL;
2730 data_len = os_strlen(pos);
2731 }
2732
2733 if (data_len) {
2734 data_len /= 2;
2735 data = os_malloc(data_len);
2736 if (!data)
2737 return -ENOBUFS;
2738
2739 if (hexstr2bin(pos, data, data_len)) {
2740 wpa_printf(MSG_DEBUG,
2741 "Vendor command: wrong parameter format");
2742 os_free(data);
2743 return -EINVAL;
2744 }
2745 }
2746
2747 reply = wpabuf_alloc((buflen - 1) / 2);
2748 if (!reply) {
2749 os_free(data);
2750 return -ENOBUFS;
2751 }
2752
2753 ret = hostapd_drv_vendor_cmd(hapd, vendor_id, subcmd, data, data_len,
2754 reply);
2755
2756 if (ret == 0)
2757 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
2758 wpabuf_len(reply));
2759
2760 wpabuf_free(reply);
2761 os_free(data);
2762
2763 return ret;
2764}
2765
2766
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002767static int hostapd_ctrl_iface_eapol_reauth(struct hostapd_data *hapd,
2768 const char *cmd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002769{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002770 u8 addr[ETH_ALEN];
2771 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002772
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002773 if (hwaddr_aton(cmd, addr))
2774 return -1;
2775
2776 sta = ap_get_sta(hapd, addr);
2777 if (!sta || !sta->eapol_sm)
2778 return -1;
2779
2780 eapol_auth_reauthenticate(sta->eapol_sm);
2781 return 0;
2782}
2783
2784
2785static int hostapd_ctrl_iface_eapol_set(struct hostapd_data *hapd, char *cmd)
2786{
2787 u8 addr[ETH_ALEN];
2788 struct sta_info *sta;
2789 char *pos = cmd, *param;
2790
2791 if (hwaddr_aton(pos, addr) || pos[17] != ' ')
2792 return -1;
2793 pos += 18;
2794 param = pos;
2795 pos = os_strchr(pos, ' ');
2796 if (!pos)
2797 return -1;
2798 *pos++ = '\0';
2799
2800 sta = ap_get_sta(hapd, addr);
2801 if (!sta || !sta->eapol_sm)
2802 return -1;
2803
2804 return eapol_auth_set_conf(sta->eapol_sm, param, pos);
2805}
2806
2807
2808static int hostapd_ctrl_iface_log_level(struct hostapd_data *hapd, char *cmd,
2809 char *buf, size_t buflen)
2810{
2811 char *pos, *end, *stamp;
2812 int ret;
2813
2814 /* cmd: "LOG_LEVEL [<level>]" */
2815 if (*cmd == '\0') {
2816 pos = buf;
2817 end = buf + buflen;
2818 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2819 "Timestamp: %d\n",
2820 debug_level_str(wpa_debug_level),
2821 wpa_debug_timestamp);
2822 if (os_snprintf_error(end - pos, ret))
2823 ret = 0;
2824
2825 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002826 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002827
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002828 while (*cmd == ' ')
2829 cmd++;
2830
2831 stamp = os_strchr(cmd, ' ');
2832 if (stamp) {
2833 *stamp++ = '\0';
2834 while (*stamp == ' ') {
2835 stamp++;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002836 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002837 }
2838
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002839 if (os_strlen(cmd)) {
2840 int level = str_to_debug_level(cmd);
2841 if (level < 0)
2842 return -1;
2843 wpa_debug_level = level;
2844 }
2845
2846 if (stamp && os_strlen(stamp))
2847 wpa_debug_timestamp = atoi(stamp);
2848
2849 os_memcpy(buf, "OK\n", 3);
2850 return 3;
2851}
2852
2853
2854#ifdef NEED_AP_MLME
2855static int hostapd_ctrl_iface_track_sta_list(struct hostapd_data *hapd,
2856 char *buf, size_t buflen)
2857{
2858 struct hostapd_iface *iface = hapd->iface;
2859 char *pos, *end;
2860 struct hostapd_sta_info *info;
2861 struct os_reltime now;
2862
Dmitry Shmidt7d175302016-09-06 13:11:34 -07002863 if (!iface->num_sta_seen)
2864 return 0;
2865
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002866 sta_track_expire(iface, 0);
2867
2868 pos = buf;
2869 end = buf + buflen;
2870
2871 os_get_reltime(&now);
2872 dl_list_for_each_reverse(info, &iface->sta_seen,
2873 struct hostapd_sta_info, list) {
2874 struct os_reltime age;
2875 int ret;
2876
2877 os_reltime_sub(&now, &info->last_seen, &age);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08002878 ret = os_snprintf(pos, end - pos, MACSTR " %u %d\n",
2879 MAC2STR(info->addr), (unsigned int) age.sec,
2880 info->ssi_signal);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002881 if (os_snprintf_error(end - pos, ret))
2882 break;
2883 pos += ret;
2884 }
2885
2886 return pos - buf;
2887}
2888#endif /* NEED_AP_MLME */
2889
2890
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002891static int hostapd_ctrl_iface_req_lci(struct hostapd_data *hapd,
2892 const char *cmd)
2893{
2894 u8 addr[ETH_ALEN];
2895
2896 if (hwaddr_aton(cmd, addr)) {
2897 wpa_printf(MSG_INFO, "CTRL: REQ_LCI: Invalid MAC address");
2898 return -1;
2899 }
2900
2901 return hostapd_send_lci_req(hapd, addr);
2902}
2903
2904
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -07002905static int hostapd_ctrl_iface_req_range(struct hostapd_data *hapd, char *cmd)
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002906{
2907 u8 addr[ETH_ALEN];
2908 char *token, *context = NULL;
2909 int random_interval, min_ap;
2910 u8 responders[ETH_ALEN * RRM_RANGE_REQ_MAX_RESPONDERS];
2911 unsigned int n_responders;
2912
2913 token = str_token(cmd, " ", &context);
2914 if (!token || hwaddr_aton(token, addr)) {
2915 wpa_printf(MSG_INFO,
2916 "CTRL: REQ_RANGE - Bad destination address");
2917 return -1;
2918 }
2919
2920 token = str_token(cmd, " ", &context);
2921 if (!token)
2922 return -1;
2923
2924 random_interval = atoi(token);
2925 if (random_interval < 0 || random_interval > 0xffff)
2926 return -1;
2927
2928 token = str_token(cmd, " ", &context);
2929 if (!token)
2930 return -1;
2931
2932 min_ap = atoi(token);
2933 if (min_ap <= 0 || min_ap > WLAN_RRM_RANGE_REQ_MAX_MIN_AP)
2934 return -1;
2935
2936 n_responders = 0;
2937 while ((token = str_token(cmd, " ", &context))) {
2938 if (n_responders == RRM_RANGE_REQ_MAX_RESPONDERS) {
2939 wpa_printf(MSG_INFO,
2940 "CTRL: REQ_RANGE: Too many responders");
2941 return -1;
2942 }
2943
2944 if (hwaddr_aton(token, responders + n_responders * ETH_ALEN)) {
2945 wpa_printf(MSG_INFO,
2946 "CTRL: REQ_RANGE: Bad responder address");
2947 return -1;
2948 }
2949
2950 n_responders++;
2951 }
2952
2953 if (!n_responders) {
2954 wpa_printf(MSG_INFO,
2955 "CTRL: REQ_RANGE - No FTM responder address");
2956 return -1;
2957 }
2958
2959 return hostapd_send_range_req(hapd, addr, random_interval, min_ap,
2960 responders, n_responders);
2961}
2962
2963
Dmitry Shmidt29333592017-01-09 12:27:11 -08002964static int hostapd_ctrl_iface_req_beacon(struct hostapd_data *hapd,
2965 const char *cmd, char *reply,
2966 size_t reply_size)
2967{
2968 u8 addr[ETH_ALEN];
2969 const char *pos;
2970 struct wpabuf *req;
2971 int ret;
2972 u8 req_mode = 0;
2973
2974 if (hwaddr_aton(cmd, addr))
2975 return -1;
2976 pos = os_strchr(cmd, ' ');
2977 if (!pos)
2978 return -1;
2979 pos++;
2980 if (os_strncmp(pos, "req_mode=", 9) == 0) {
2981 int val = hex2byte(pos + 9);
2982
2983 if (val < 0)
2984 return -1;
2985 req_mode = val;
2986 pos += 11;
2987 pos = os_strchr(pos, ' ');
2988 if (!pos)
2989 return -1;
2990 pos++;
2991 }
2992 req = wpabuf_parse_bin(pos);
2993 if (!req)
2994 return -1;
2995
2996 ret = hostapd_send_beacon_req(hapd, addr, req_mode, req);
2997 wpabuf_free(req);
2998 if (ret >= 0)
2999 ret = os_snprintf(reply, reply_size, "%d", ret);
3000 return ret;
3001}
3002
3003
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003004static int hostapd_ctrl_iface_show_neighbor(struct hostapd_data *hapd,
3005 char *buf, size_t buflen)
3006{
3007 if (!(hapd->conf->radio_measurements[0] &
3008 WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
3009 wpa_printf(MSG_ERROR,
3010 "CTRL: SHOW_NEIGHBOR: Neighbor report is not enabled");
3011 return -1;
3012 }
3013
3014 return hostapd_neighbor_show(hapd, buf, buflen);
3015}
3016
3017
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003018static int hostapd_ctrl_iface_set_neighbor(struct hostapd_data *hapd, char *buf)
3019{
3020 struct wpa_ssid_value ssid;
3021 u8 bssid[ETH_ALEN];
3022 struct wpabuf *nr, *lci = NULL, *civic = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003023 int stationary = 0;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003024 char *tmp;
3025 int ret;
3026
3027 if (!(hapd->conf->radio_measurements[0] &
3028 WLAN_RRM_CAPS_NEIGHBOR_REPORT)) {
3029 wpa_printf(MSG_ERROR,
3030 "CTRL: SET_NEIGHBOR: Neighbor report is not enabled");
3031 return -1;
3032 }
3033
3034 if (hwaddr_aton(buf, bssid)) {
3035 wpa_printf(MSG_ERROR, "CTRL: SET_NEIGHBOR: Bad BSSID");
3036 return -1;
3037 }
3038
3039 tmp = os_strstr(buf, "ssid=");
3040 if (!tmp || ssid_parse(tmp + 5, &ssid)) {
3041 wpa_printf(MSG_ERROR,
3042 "CTRL: SET_NEIGHBOR: Bad or missing SSID");
3043 return -1;
3044 }
3045 buf = os_strchr(tmp + 6, tmp[5] == '"' ? '"' : ' ');
3046 if (!buf)
3047 return -1;
3048
3049 tmp = os_strstr(buf, "nr=");
3050 if (!tmp) {
3051 wpa_printf(MSG_ERROR,
3052 "CTRL: SET_NEIGHBOR: Missing Neighbor Report element");
3053 return -1;
3054 }
3055
3056 buf = os_strchr(tmp, ' ');
3057 if (buf)
3058 *buf++ = '\0';
3059
3060 nr = wpabuf_parse_bin(tmp + 3);
3061 if (!nr) {
3062 wpa_printf(MSG_ERROR,
3063 "CTRL: SET_NEIGHBOR: Bad Neighbor Report element");
3064 return -1;
3065 }
3066
3067 if (!buf)
3068 goto set;
3069
3070 tmp = os_strstr(buf, "lci=");
3071 if (tmp) {
3072 buf = os_strchr(tmp, ' ');
3073 if (buf)
3074 *buf++ = '\0';
3075 lci = wpabuf_parse_bin(tmp + 4);
3076 if (!lci) {
3077 wpa_printf(MSG_ERROR,
3078 "CTRL: SET_NEIGHBOR: Bad LCI subelement");
3079 wpabuf_free(nr);
3080 return -1;
3081 }
3082 }
3083
3084 if (!buf)
3085 goto set;
3086
3087 tmp = os_strstr(buf, "civic=");
3088 if (tmp) {
3089 buf = os_strchr(tmp, ' ');
3090 if (buf)
3091 *buf++ = '\0';
3092 civic = wpabuf_parse_bin(tmp + 6);
3093 if (!civic) {
3094 wpa_printf(MSG_ERROR,
3095 "CTRL: SET_NEIGHBOR: Bad civic subelement");
3096 wpabuf_free(nr);
3097 wpabuf_free(lci);
3098 return -1;
3099 }
3100 }
3101
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003102 if (!buf)
3103 goto set;
3104
3105 if (os_strstr(buf, "stat"))
3106 stationary = 1;
3107
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003108set:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08003109 ret = hostapd_neighbor_set(hapd, bssid, &ssid, nr, lci, civic,
3110 stationary);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003111
3112 wpabuf_free(nr);
3113 wpabuf_free(lci);
3114 wpabuf_free(civic);
3115
3116 return ret;
3117}
3118
3119
3120static int hostapd_ctrl_iface_remove_neighbor(struct hostapd_data *hapd,
3121 char *buf)
3122{
3123 struct wpa_ssid_value ssid;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003124 struct wpa_ssid_value *ssidp = NULL;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003125 u8 bssid[ETH_ALEN];
3126 char *tmp;
3127
3128 if (hwaddr_aton(buf, bssid)) {
3129 wpa_printf(MSG_ERROR, "CTRL: REMOVE_NEIGHBOR: Bad BSSID");
3130 return -1;
3131 }
3132
3133 tmp = os_strstr(buf, "ssid=");
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003134 if (tmp) {
3135 ssidp = &ssid;
3136 if (ssid_parse(tmp + 5, &ssid)) {
3137 wpa_printf(MSG_ERROR,
3138 "CTRL: REMOVE_NEIGHBOR: Bad SSID");
3139 return -1;
3140 }
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003141 }
3142
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003143 return hostapd_neighbor_remove(hapd, bssid, ssidp);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003144}
3145
3146
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07003147static int hostapd_ctrl_driver_flags(struct hostapd_iface *iface, char *buf,
3148 size_t buflen)
3149{
3150 int ret, i;
3151 char *pos, *end;
3152
3153 ret = os_snprintf(buf, buflen, "%016llX:\n",
3154 (long long unsigned) iface->drv_flags);
3155 if (os_snprintf_error(buflen, ret))
3156 return -1;
3157
3158 pos = buf + ret;
3159 end = buf + buflen;
3160
3161 for (i = 0; i < 64; i++) {
3162 if (iface->drv_flags & (1LLU << i)) {
3163 ret = os_snprintf(pos, end - pos, "%s\n",
3164 driver_flag_to_string(1LLU << i));
3165 if (os_snprintf_error(end - pos, ret))
3166 return -1;
3167 pos += ret;
3168 }
3169 }
3170
3171 return pos - buf;
3172}
3173
3174
Hai Shalomb755a2a2020-04-23 21:49:02 -07003175static int hostapd_ctrl_driver_flags2(struct hostapd_iface *iface, char *buf,
3176 size_t buflen)
3177{
3178 int ret, i;
3179 char *pos, *end;
3180
3181 ret = os_snprintf(buf, buflen, "%016llX:\n",
3182 (long long unsigned) iface->drv_flags2);
3183 if (os_snprintf_error(buflen, ret))
3184 return -1;
3185
3186 pos = buf + ret;
3187 end = buf + buflen;
3188
3189 for (i = 0; i < 64; i++) {
3190 if (iface->drv_flags2 & (1LLU << i)) {
3191 ret = os_snprintf(pos, end - pos, "%s\n",
3192 driver_flag2_to_string(1LLU << i));
3193 if (os_snprintf_error(end - pos, ret))
3194 return -1;
3195 pos += ret;
3196 }
3197 }
3198
3199 return pos - buf;
3200}
3201
3202
Roshan Pius3a1667e2018-07-03 15:17:14 -07003203static int hostapd_ctrl_iface_acl_del_mac(struct mac_acl_entry **acl, int *num,
3204 const char *txtaddr)
3205{
3206 u8 addr[ETH_ALEN];
3207 struct vlan_description vlan_id;
3208
3209 if (!(*num))
3210 return 0;
3211
3212 if (hwaddr_aton(txtaddr, addr))
3213 return -1;
3214
3215 if (hostapd_maclist_found(*acl, *num, addr, &vlan_id))
3216 hostapd_remove_acl_mac(acl, num, addr);
3217
3218 return 0;
3219}
3220
3221
3222static void hostapd_ctrl_iface_acl_clear_list(struct mac_acl_entry **acl,
3223 int *num)
3224{
3225 while (*num)
3226 hostapd_remove_acl_mac(acl, num, (*acl)[0].addr);
3227}
3228
3229
3230static int hostapd_ctrl_iface_acl_show_mac(struct mac_acl_entry *acl, int num,
3231 char *buf, size_t buflen)
3232{
3233 int i = 0, len = 0, ret = 0;
3234
3235 if (!acl)
3236 return 0;
3237
3238 while (i < num) {
3239 ret = os_snprintf(buf + len, buflen - len,
3240 MACSTR " VLAN_ID=%d\n",
3241 MAC2STR(acl[i].addr),
3242 acl[i].vlan_id.untagged);
3243 if (ret < 0 || (size_t) ret >= buflen - len)
3244 return len;
3245 i++;
3246 len += ret;
3247 }
3248 return len;
3249}
3250
3251
3252static int hostapd_ctrl_iface_acl_add_mac(struct mac_acl_entry **acl, int *num,
3253 const char *cmd)
3254{
3255 u8 addr[ETH_ALEN];
3256 struct vlan_description vlan_id;
3257 int ret = 0, vlanid = 0;
3258 const char *pos;
3259
3260 if (hwaddr_aton(cmd, addr))
3261 return -1;
3262
3263 pos = os_strstr(cmd, "VLAN_ID=");
3264 if (pos)
3265 vlanid = atoi(pos + 8);
3266
3267 if (!hostapd_maclist_found(*acl, *num, addr, &vlan_id)) {
3268 ret = hostapd_add_acl_maclist(acl, num, vlanid, addr);
3269 if (ret != -1 && *acl)
3270 qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
3271 }
3272
3273 return ret < 0 ? -1 : 0;
3274}
3275
3276
Hai Shalom021b0b52019-04-10 11:17:58 -07003277static int hostapd_ctrl_iface_get_capability(struct hostapd_data *hapd,
3278 const char *field, char *buf,
3279 size_t buflen)
3280{
3281 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s'", field);
3282
3283#ifdef CONFIG_DPP
3284 if (os_strcmp(field, "dpp") == 0) {
3285 int res;
3286
3287#ifdef CONFIG_DPP2
3288 res = os_snprintf(buf, buflen, "DPP=2");
3289#else /* CONFIG_DPP2 */
3290 res = os_snprintf(buf, buflen, "DPP=1");
3291#endif /* CONFIG_DPP2 */
3292 if (os_snprintf_error(buflen, res))
3293 return -1;
3294 return res;
3295 }
3296#endif /* CONFIG_DPP */
3297
3298 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3299 field);
3300
3301 return -1;
3302}
3303
3304
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003305static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
3306 char *buf, char *reply,
3307 int reply_size,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003308 struct sockaddr_storage *from,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003309 socklen_t fromlen)
3310{
3311 int reply_len, res;
3312
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003313 os_memcpy(reply, "OK\n", 3);
3314 reply_len = 3;
3315
3316 if (os_strcmp(buf, "PING") == 0) {
3317 os_memcpy(reply, "PONG\n", 5);
3318 reply_len = 5;
3319 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
3320 if (wpa_debug_reopen_file() < 0)
3321 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003322 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
3323 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003324 } else if (os_strcmp(buf, "STATUS") == 0) {
3325 reply_len = hostapd_ctrl_iface_status(hapd, reply,
3326 reply_size);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003327 } else if (os_strcmp(buf, "STATUS-DRIVER") == 0) {
3328 reply_len = hostapd_drv_status(hapd, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003329 } else if (os_strcmp(buf, "MIB") == 0) {
3330 reply_len = ieee802_11_get_mib(hapd, reply, reply_size);
3331 if (reply_len >= 0) {
3332 res = wpa_get_mib(hapd->wpa_auth, reply + reply_len,
3333 reply_size - reply_len);
3334 if (res < 0)
3335 reply_len = -1;
3336 else
3337 reply_len += res;
3338 }
3339 if (reply_len >= 0) {
3340 res = ieee802_1x_get_mib(hapd, reply + reply_len,
3341 reply_size - reply_len);
3342 if (res < 0)
3343 reply_len = -1;
3344 else
3345 reply_len += res;
3346 }
3347#ifndef CONFIG_NO_RADIUS
3348 if (reply_len >= 0) {
3349 res = radius_client_get_mib(hapd->radius,
3350 reply + reply_len,
3351 reply_size - reply_len);
3352 if (res < 0)
3353 reply_len = -1;
3354 else
3355 reply_len += res;
3356 }
3357#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003358 } else if (os_strncmp(buf, "MIB ", 4) == 0) {
3359 reply_len = hostapd_ctrl_iface_mib(hapd, reply, reply_size,
3360 buf + 4);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003361 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
3362 reply_len = hostapd_ctrl_iface_sta_first(hapd, reply,
3363 reply_size);
3364 } else if (os_strncmp(buf, "STA ", 4) == 0) {
3365 reply_len = hostapd_ctrl_iface_sta(hapd, buf + 4, reply,
3366 reply_size);
3367 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
3368 reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
3369 reply_size);
3370 } else if (os_strcmp(buf, "ATTACH") == 0) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07003371 if (hostapd_ctrl_iface_attach(hapd, from, fromlen, NULL))
3372 reply_len = -1;
3373 } else if (os_strncmp(buf, "ATTACH ", 7) == 0) {
3374 if (hostapd_ctrl_iface_attach(hapd, from, fromlen, buf + 7))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003375 reply_len = -1;
3376 } else if (os_strcmp(buf, "DETACH") == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003377 if (hostapd_ctrl_iface_detach(hapd, from, fromlen))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003378 reply_len = -1;
3379 } else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003380 if (hostapd_ctrl_iface_level(hapd, from, fromlen,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003381 buf + 6))
3382 reply_len = -1;
3383 } else if (os_strncmp(buf, "NEW_STA ", 8) == 0) {
3384 if (hostapd_ctrl_iface_new_sta(hapd, buf + 8))
3385 reply_len = -1;
3386 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
3387 if (hostapd_ctrl_iface_deauthenticate(hapd, buf + 15))
3388 reply_len = -1;
3389 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
3390 if (hostapd_ctrl_iface_disassociate(hapd, buf + 13))
3391 reply_len = -1;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07003392#ifdef CONFIG_TAXONOMY
3393 } else if (os_strncmp(buf, "SIGNATURE ", 10) == 0) {
3394 reply_len = hostapd_ctrl_iface_signature(hapd, buf + 10,
3395 reply, reply_size);
3396#endif /* CONFIG_TAXONOMY */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003397 } else if (os_strncmp(buf, "POLL_STA ", 9) == 0) {
3398 if (hostapd_ctrl_iface_poll_sta(hapd, buf + 9))
3399 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003400 } else if (os_strcmp(buf, "STOP_AP") == 0) {
3401 if (hostapd_ctrl_iface_stop_ap(hapd))
3402 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003403#ifdef NEED_AP_MLME
3404 } else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
3405 if (hostapd_ctrl_iface_sa_query(hapd, buf + 9))
3406 reply_len = -1;
3407#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003408#ifdef CONFIG_WPS
3409 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
3410 if (hostapd_ctrl_iface_wps_pin(hapd, buf + 8))
3411 reply_len = -1;
3412 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
3413 reply_len = hostapd_ctrl_iface_wps_check_pin(
3414 hapd, buf + 14, reply, reply_size);
3415 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
3416 if (hostapd_wps_button_pushed(hapd, NULL))
3417 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003418 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
3419 if (hostapd_wps_cancel(hapd))
3420 reply_len = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003421 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
3422 reply_len = hostapd_ctrl_iface_wps_ap_pin(hapd, buf + 11,
3423 reply, reply_size);
3424 } else if (os_strncmp(buf, "WPS_CONFIG ", 11) == 0) {
3425 if (hostapd_ctrl_iface_wps_config(hapd, buf + 11) < 0)
3426 reply_len = -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003427 } else if (os_strncmp(buf, "WPS_GET_STATUS", 13) == 0) {
3428 reply_len = hostapd_ctrl_iface_wps_get_status(hapd, reply,
3429 reply_size);
Dmitry Shmidt04949592012-07-19 12:16:46 -07003430#ifdef CONFIG_WPS_NFC
3431 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
3432 if (hostapd_ctrl_iface_wps_nfc_tag_read(hapd, buf + 17))
3433 reply_len = -1;
3434 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
3435 reply_len = hostapd_ctrl_iface_wps_nfc_config_token(
3436 hapd, buf + 21, reply, reply_size);
3437 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
3438 reply_len = hostapd_ctrl_iface_wps_nfc_token(
3439 hapd, buf + 14, reply, reply_size);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003440 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
3441 reply_len = hostapd_ctrl_iface_nfc_get_handover_sel(
3442 hapd, buf + 21, reply, reply_size);
3443 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
3444 if (hostapd_ctrl_iface_nfc_report_handover(hapd, buf + 20))
3445 reply_len = -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003446#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003447#endif /* CONFIG_WPS */
Dmitry Shmidt051af732013-10-22 13:52:46 -07003448#ifdef CONFIG_INTERWORKING
3449 } else if (os_strncmp(buf, "SET_QOS_MAP_SET ", 16) == 0) {
3450 if (hostapd_ctrl_iface_set_qos_map_set(hapd, buf + 16))
3451 reply_len = -1;
3452 } else if (os_strncmp(buf, "SEND_QOS_MAP_CONF ", 18) == 0) {
3453 if (hostapd_ctrl_iface_send_qos_map_conf(hapd, buf + 18))
3454 reply_len = -1;
3455#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08003456#ifdef CONFIG_HS20
3457 } else if (os_strncmp(buf, "HS20_WNM_NOTIF ", 15) == 0) {
3458 if (hostapd_ctrl_iface_hs20_wnm_notif(hapd, buf + 15))
3459 reply_len = -1;
3460 } else if (os_strncmp(buf, "HS20_DEAUTH_REQ ", 16) == 0) {
3461 if (hostapd_ctrl_iface_hs20_deauth_req(hapd, buf + 16))
3462 reply_len = -1;
3463#endif /* CONFIG_HS20 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003464#ifdef CONFIG_WNM_AP
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003465 } else if (os_strncmp(buf, "DISASSOC_IMMINENT ", 18) == 0) {
3466 if (hostapd_ctrl_iface_disassoc_imminent(hapd, buf + 18))
3467 reply_len = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003468 } else if (os_strncmp(buf, "ESS_DISASSOC ", 13) == 0) {
3469 if (hostapd_ctrl_iface_ess_disassoc(hapd, buf + 13))
3470 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003471 } else if (os_strncmp(buf, "BSS_TM_REQ ", 11) == 0) {
3472 if (hostapd_ctrl_iface_bss_tm_req(hapd, buf + 11))
3473 reply_len = -1;
Hai Shalom39ba6fc2019-01-22 12:40:38 -08003474 } else if (os_strncmp(buf, "COLOC_INTF_REQ ", 15) == 0) {
3475 if (hostapd_ctrl_iface_coloc_intf_req(hapd, buf + 15))
3476 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003477#endif /* CONFIG_WNM_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003478 } else if (os_strcmp(buf, "GET_CONFIG") == 0) {
3479 reply_len = hostapd_ctrl_iface_get_config(hapd, reply,
3480 reply_size);
3481 } else if (os_strncmp(buf, "SET ", 4) == 0) {
3482 if (hostapd_ctrl_iface_set(hapd, buf + 4))
3483 reply_len = -1;
3484 } else if (os_strncmp(buf, "GET ", 4) == 0) {
3485 reply_len = hostapd_ctrl_iface_get(hapd, buf + 4, reply,
3486 reply_size);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003487 } else if (os_strncmp(buf, "ENABLE", 6) == 0) {
3488 if (hostapd_ctrl_iface_enable(hapd->iface))
3489 reply_len = -1;
Hai Shalom74f70d42019-02-11 14:42:39 -08003490 } else if (os_strcmp(buf, "RELOAD_WPA_PSK") == 0) {
3491 if (hostapd_ctrl_iface_reload_wpa_psk(hapd))
3492 reply_len = -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07003493 } else if (os_strncmp(buf, "RELOAD", 6) == 0) {
3494 if (hostapd_ctrl_iface_reload(hapd->iface))
3495 reply_len = -1;
3496 } else if (os_strncmp(buf, "DISABLE", 7) == 0) {
3497 if (hostapd_ctrl_iface_disable(hapd->iface))
3498 reply_len = -1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003499 } else if (os_strcmp(buf, "UPDATE_BEACON") == 0) {
3500 if (ieee802_11_set_beacon(hapd))
3501 reply_len = -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003502#ifdef CONFIG_TESTING_OPTIONS
3503 } else if (os_strncmp(buf, "RADAR ", 6) == 0) {
3504 if (hostapd_ctrl_iface_radar(hapd, buf + 6))
3505 reply_len = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003506 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
3507 if (hostapd_ctrl_iface_mgmt_tx(hapd, buf + 8))
3508 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003509 } else if (os_strncmp(buf, "MGMT_TX_STATUS_PROCESS ", 23) == 0) {
3510 if (hostapd_ctrl_iface_mgmt_tx_status_process(hapd,
3511 buf + 23) < 0)
3512 reply_len = -1;
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08003513 } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
3514 if (hostapd_ctrl_iface_mgmt_rx_process(hapd, buf + 16) < 0)
3515 reply_len = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003516 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
3517 if (hostapd_ctrl_iface_eapol_rx(hapd, buf + 9) < 0)
3518 reply_len = -1;
3519 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
3520 if (hostapd_ctrl_iface_data_test_config(hapd, buf + 17) < 0)
3521 reply_len = -1;
3522 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
3523 if (hostapd_ctrl_iface_data_test_tx(hapd, buf + 13) < 0)
3524 reply_len = -1;
3525 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
3526 if (hostapd_ctrl_iface_data_test_frame(hapd, buf + 16) < 0)
3527 reply_len = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003528 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
3529 if (hostapd_ctrl_test_alloc_fail(hapd, buf + 16) < 0)
3530 reply_len = -1;
3531 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
3532 reply_len = hostapd_ctrl_get_alloc_fail(hapd, reply,
3533 reply_size);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003534 } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
3535 if (hostapd_ctrl_test_fail(hapd, buf + 10) < 0)
3536 reply_len = -1;
3537 } else if (os_strcmp(buf, "GET_FAIL") == 0) {
3538 reply_len = hostapd_ctrl_get_fail(hapd, reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003539 } else if (os_strncmp(buf, "RESET_PN ", 9) == 0) {
3540 if (hostapd_ctrl_reset_pn(hapd, buf + 9) < 0)
3541 reply_len = -1;
3542 } else if (os_strncmp(buf, "SET_KEY ", 8) == 0) {
3543 if (hostapd_ctrl_set_key(hapd, buf + 8) < 0)
3544 reply_len = -1;
3545 } else if (os_strncmp(buf, "RESEND_M1 ", 10) == 0) {
3546 if (hostapd_ctrl_resend_m1(hapd, buf + 10) < 0)
3547 reply_len = -1;
3548 } else if (os_strncmp(buf, "RESEND_M3 ", 10) == 0) {
3549 if (hostapd_ctrl_resend_m3(hapd, buf + 10) < 0)
3550 reply_len = -1;
3551 } else if (os_strncmp(buf, "RESEND_GROUP_M1 ", 16) == 0) {
3552 if (hostapd_ctrl_resend_group_m1(hapd, buf + 16) < 0)
3553 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003554 } else if (os_strcmp(buf, "REKEY_GTK") == 0) {
3555 if (wpa_auth_rekey_gtk(hapd->wpa_auth) < 0)
3556 reply_len = -1;
Hai Shalomfdcde762020-04-02 11:19:20 -07003557 } else if (os_strncmp(buf, "GET_PMK ", 8) == 0) {
3558 reply_len = hostapd_ctrl_get_pmk(hapd, buf + 8, reply,
3559 reply_size);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003560#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003561 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003562 if (hostapd_ctrl_iface_chan_switch(hapd->iface, buf + 12))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003563 reply_len = -1;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07003564 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
3565 reply_len = hostapd_ctrl_iface_vendor(hapd, buf + 7, reply,
3566 reply_size);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003567 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
3568 ieee802_1x_erp_flush(hapd);
3569#ifdef RADIUS_SERVER
3570 radius_server_erp_flush(hapd->radius_srv);
3571#endif /* RADIUS_SERVER */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003572 } else if (os_strncmp(buf, "EAPOL_REAUTH ", 13) == 0) {
3573 if (hostapd_ctrl_iface_eapol_reauth(hapd, buf + 13))
3574 reply_len = -1;
3575 } else if (os_strncmp(buf, "EAPOL_SET ", 10) == 0) {
3576 if (hostapd_ctrl_iface_eapol_set(hapd, buf + 10))
3577 reply_len = -1;
3578 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
3579 reply_len = hostapd_ctrl_iface_log_level(
3580 hapd, buf + 9, reply, reply_size);
3581#ifdef NEED_AP_MLME
3582 } else if (os_strcmp(buf, "TRACK_STA_LIST") == 0) {
3583 reply_len = hostapd_ctrl_iface_track_sta_list(
3584 hapd, reply, reply_size);
3585#endif /* NEED_AP_MLME */
Dmitry Shmidte4663042016-04-04 10:07:49 -07003586 } else if (os_strcmp(buf, "PMKSA") == 0) {
3587 reply_len = hostapd_ctrl_iface_pmksa_list(hapd, reply,
3588 reply_size);
3589 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
3590 hostapd_ctrl_iface_pmksa_flush(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003591 } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
3592 if (hostapd_ctrl_iface_pmksa_add(hapd, buf + 10) < 0)
3593 reply_len = -1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003594 } else if (os_strncmp(buf, "SET_NEIGHBOR ", 13) == 0) {
3595 if (hostapd_ctrl_iface_set_neighbor(hapd, buf + 13))
3596 reply_len = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003597 } else if (os_strcmp(buf, "SHOW_NEIGHBOR") == 0) {
3598 reply_len = hostapd_ctrl_iface_show_neighbor(hapd, reply,
3599 reply_size);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07003600 } else if (os_strncmp(buf, "REMOVE_NEIGHBOR ", 16) == 0) {
3601 if (hostapd_ctrl_iface_remove_neighbor(hapd, buf + 16))
3602 reply_len = -1;
3603 } else if (os_strncmp(buf, "REQ_LCI ", 8) == 0) {
3604 if (hostapd_ctrl_iface_req_lci(hapd, buf + 8))
3605 reply_len = -1;
3606 } else if (os_strncmp(buf, "REQ_RANGE ", 10) == 0) {
3607 if (hostapd_ctrl_iface_req_range(hapd, buf + 10))
3608 reply_len = -1;
Dmitry Shmidt29333592017-01-09 12:27:11 -08003609 } else if (os_strncmp(buf, "REQ_BEACON ", 11) == 0) {
3610 reply_len = hostapd_ctrl_iface_req_beacon(hapd, buf + 11,
3611 reply, reply_size);
Dmitry Shmidt58d12ad2016-07-28 10:07:03 -07003612 } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
3613 reply_len = hostapd_ctrl_driver_flags(hapd->iface, reply,
3614 reply_size);
Hai Shalomb755a2a2020-04-23 21:49:02 -07003615 } else if (os_strcmp(buf, "DRIVER_FLAGS2") == 0) {
3616 reply_len = hostapd_ctrl_driver_flags2(hapd->iface, reply,
3617 reply_size);
Dmitry Shmidt29333592017-01-09 12:27:11 -08003618 } else if (os_strcmp(buf, "TERMINATE") == 0) {
3619 eloop_terminate();
Roshan Pius3a1667e2018-07-03 15:17:14 -07003620 } else if (os_strncmp(buf, "ACCEPT_ACL ", 11) == 0) {
3621 if (os_strncmp(buf + 11, "ADD_MAC ", 8) == 0) {
3622 if (!hostapd_ctrl_iface_acl_add_mac(
3623 &hapd->conf->accept_mac,
3624 &hapd->conf->num_accept_mac, buf + 19))
3625 hostapd_disassoc_accept_mac(hapd);
3626 else
3627 reply_len = -1;
3628 } else if (os_strncmp((buf + 11), "DEL_MAC ", 8) == 0) {
3629 hostapd_ctrl_iface_acl_del_mac(
3630 &hapd->conf->accept_mac,
3631 &hapd->conf->num_accept_mac, buf + 19);
3632 } else if (os_strcmp(buf + 11, "SHOW") == 0) {
3633 reply_len = hostapd_ctrl_iface_acl_show_mac(
3634 hapd->conf->accept_mac,
3635 hapd->conf->num_accept_mac, reply, reply_size);
3636 } else if (os_strcmp(buf + 11, "CLEAR") == 0) {
3637 hostapd_ctrl_iface_acl_clear_list(
3638 &hapd->conf->accept_mac,
3639 &hapd->conf->num_accept_mac);
3640 }
3641 } else if (os_strncmp(buf, "DENY_ACL ", 9) == 0) {
3642 if (os_strncmp(buf + 9, "ADD_MAC ", 8) == 0) {
3643 if (!hostapd_ctrl_iface_acl_add_mac(
3644 &hapd->conf->deny_mac,
3645 &hapd->conf->num_deny_mac, buf + 17))
3646 hostapd_disassoc_deny_mac(hapd);
3647 } else if (os_strncmp(buf + 9, "DEL_MAC ", 8) == 0) {
3648 hostapd_ctrl_iface_acl_del_mac(
3649 &hapd->conf->deny_mac,
3650 &hapd->conf->num_deny_mac, buf + 17);
3651 } else if (os_strcmp(buf + 9, "SHOW") == 0) {
3652 reply_len = hostapd_ctrl_iface_acl_show_mac(
3653 hapd->conf->deny_mac,
3654 hapd->conf->num_deny_mac, reply, reply_size);
3655 } else if (os_strcmp(buf + 9, "CLEAR") == 0) {
3656 hostapd_ctrl_iface_acl_clear_list(
3657 &hapd->conf->deny_mac,
3658 &hapd->conf->num_deny_mac);
3659 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003660#ifdef CONFIG_DPP
3661 } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
3662 res = hostapd_dpp_qr_code(hapd, buf + 12);
3663 if (res < 0) {
3664 reply_len = -1;
3665 } else {
3666 reply_len = os_snprintf(reply, reply_size, "%d", res);
3667 if (os_snprintf_error(reply_size, reply_len))
3668 reply_len = -1;
3669 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08003670 } else if (os_strncmp(buf, "DPP_NFC_URI ", 12) == 0) {
3671 res = hostapd_dpp_nfc_uri(hapd, buf + 12);
3672 if (res < 0) {
3673 reply_len = -1;
3674 } else {
3675 reply_len = os_snprintf(reply, reply_size, "%d", res);
3676 if (os_snprintf_error(reply_size, reply_len))
3677 reply_len = -1;
3678 }
Hai Shalomfdcde762020-04-02 11:19:20 -07003679 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_REQ ", 21) == 0) {
3680 res = hostapd_dpp_nfc_handover_req(hapd, buf + 20);
3681 if (res < 0) {
3682 reply_len = -1;
3683 } else {
3684 reply_len = os_snprintf(reply, reply_size, "%d", res);
3685 if (os_snprintf_error(reply_size, reply_len))
3686 reply_len = -1;
3687 }
3688 } else if (os_strncmp(buf, "DPP_NFC_HANDOVER_SEL ", 21) == 0) {
3689 res = hostapd_dpp_nfc_handover_sel(hapd, buf + 20);
3690 if (res < 0) {
3691 reply_len = -1;
3692 } else {
3693 reply_len = os_snprintf(reply, reply_size, "%d", res);
3694 if (os_snprintf_error(reply_size, reply_len))
3695 reply_len = -1;
3696 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003697 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003698 res = dpp_bootstrap_gen(hapd->iface->interfaces->dpp, buf + 18);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003699 if (res < 0) {
3700 reply_len = -1;
3701 } else {
3702 reply_len = os_snprintf(reply, reply_size, "%d", res);
3703 if (os_snprintf_error(reply_size, reply_len))
3704 reply_len = -1;
3705 }
3706 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003707 if (dpp_bootstrap_remove(hapd->iface->interfaces->dpp,
3708 buf + 21) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003709 reply_len = -1;
3710 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
3711 const char *uri;
3712
Hai Shalom021b0b52019-04-10 11:17:58 -07003713 uri = dpp_bootstrap_get_uri(hapd->iface->interfaces->dpp,
3714 atoi(buf + 22));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003715 if (!uri) {
3716 reply_len = -1;
3717 } else {
3718 reply_len = os_snprintf(reply, reply_size, "%s", uri);
3719 if (os_snprintf_error(reply_size, reply_len))
3720 reply_len = -1;
3721 }
3722 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003723 reply_len = dpp_bootstrap_info(hapd->iface->interfaces->dpp,
3724 atoi(buf + 19),
3725 reply, reply_size);
Hai Shalomfdcde762020-04-02 11:19:20 -07003726 } else if (os_strncmp(buf, "DPP_BOOTSTRAP_SET ", 18) == 0) {
3727 if (dpp_bootstrap_set(hapd->iface->interfaces->dpp,
3728 atoi(buf + 18),
3729 os_strchr(buf + 18, ' ')) < 0)
3730 reply_len = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003731 } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
3732 if (hostapd_dpp_auth_init(hapd, buf + 13) < 0)
3733 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003734 } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
3735 if (hostapd_dpp_listen(hapd, buf + 11) < 0)
3736 reply_len = -1;
3737 } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
3738 hostapd_dpp_stop(hapd);
3739 hostapd_dpp_listen_stop(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003740 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003741 res = dpp_configurator_add(hapd->iface->interfaces->dpp,
3742 buf + 20);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003743 if (res < 0) {
3744 reply_len = -1;
3745 } else {
3746 reply_len = os_snprintf(reply, reply_size, "%d", res);
3747 if (os_snprintf_error(reply_size, reply_len))
3748 reply_len = -1;
3749 }
3750 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003751 if (dpp_configurator_remove(hapd->iface->interfaces->dpp,
3752 buf + 24) < 0)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003753 reply_len = -1;
Roshan Pius3a1667e2018-07-03 15:17:14 -07003754 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
Hai Shalom74f70d42019-02-11 14:42:39 -08003755 if (hostapd_dpp_configurator_sign(hapd, buf + 21) < 0)
Roshan Pius3a1667e2018-07-03 15:17:14 -07003756 reply_len = -1;
3757 } else if (os_strncmp(buf, "DPP_CONFIGURATOR_GET_KEY ", 25) == 0) {
Hai Shalom021b0b52019-04-10 11:17:58 -07003758 reply_len = dpp_configurator_get_key_id(
3759 hapd->iface->interfaces->dpp,
3760 atoi(buf + 25),
3761 reply, reply_size);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003762 } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
3763 res = hostapd_dpp_pkex_add(hapd, buf + 12);
3764 if (res < 0) {
3765 reply_len = -1;
3766 } else {
3767 reply_len = os_snprintf(reply, reply_size, "%d", res);
3768 if (os_snprintf_error(reply_size, reply_len))
3769 reply_len = -1;
3770 }
3771 } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
3772 if (hostapd_dpp_pkex_remove(hapd, buf + 16) < 0)
3773 reply_len = -1;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003774#ifdef CONFIG_DPP2
Hai Shalom899fcc72020-10-19 14:38:18 -07003775 } else if (os_strncmp(buf, "DPP_CONTROLLER_START ", 21) == 0) {
3776 if (hostapd_dpp_controller_start(hapd, buf + 20) < 0)
3777 reply_len = -1;
3778 } else if (os_strcmp(buf, "DPP_CONTROLLER_START") == 0) {
3779 if (hostapd_dpp_controller_start(hapd, NULL) < 0)
3780 reply_len = -1;
3781 } else if (os_strcmp(buf, "DPP_CONTROLLER_STOP") == 0) {
3782 dpp_controller_stop(hapd->iface->interfaces->dpp);
Hai Shalom4fbc08f2020-05-18 12:37:00 -07003783 } else if (os_strncmp(buf, "DPP_CHIRP ", 10) == 0) {
3784 if (hostapd_dpp_chirp(hapd, buf + 9) < 0)
3785 reply_len = -1;
3786 } else if (os_strcmp(buf, "DPP_STOP_CHIRP") == 0) {
3787 hostapd_dpp_chirp_stop(hapd);
3788#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003789#endif /* CONFIG_DPP */
Roshan Pius3a1667e2018-07-03 15:17:14 -07003790#ifdef RADIUS_SERVER
3791 } else if (os_strncmp(buf, "DAC_REQUEST ", 12) == 0) {
3792 if (radius_server_dac_request(hapd->radius_srv, buf + 12) < 0)
3793 reply_len = -1;
3794#endif /* RADIUS_SERVER */
Hai Shalom021b0b52019-04-10 11:17:58 -07003795 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
3796 reply_len = hostapd_ctrl_iface_get_capability(
3797 hapd, buf + 15, reply, reply_size);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003798 } else {
3799 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
3800 reply_len = 16;
3801 }
3802
3803 if (reply_len < 0) {
3804 os_memcpy(reply, "FAIL\n", 5);
3805 reply_len = 5;
3806 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003807
3808 return reply_len;
3809}
3810
3811
3812static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
3813 void *sock_ctx)
3814{
3815 struct hostapd_data *hapd = eloop_ctx;
3816 char buf[4096];
3817 int res;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003818 struct sockaddr_storage from;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003819 socklen_t fromlen = sizeof(from);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003820 char *reply, *pos = buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003821 const int reply_size = 4096;
3822 int reply_len;
3823 int level = MSG_DEBUG;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003824#ifdef CONFIG_CTRL_IFACE_UDP
Hai Shalomfdcde762020-04-02 11:19:20 -07003825 unsigned char lcookie[CTRL_IFACE_COOKIE_LEN];
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003826#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003827
3828 res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
3829 (struct sockaddr *) &from, &fromlen);
3830 if (res < 0) {
3831 wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
3832 strerror(errno));
3833 return;
3834 }
3835 buf[res] = '\0';
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003836
3837 reply = os_malloc(reply_size);
3838 if (reply == NULL) {
3839 if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
3840 fromlen) < 0) {
3841 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
3842 strerror(errno));
3843 }
3844 return;
3845 }
3846
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003847#ifdef CONFIG_CTRL_IFACE_UDP
3848 if (os_strcmp(buf, "GET_COOKIE") == 0) {
3849 os_memcpy(reply, "COOKIE=", 7);
Hai Shalomfdcde762020-04-02 11:19:20 -07003850 wpa_snprintf_hex(reply + 7, 2 * CTRL_IFACE_COOKIE_LEN + 1,
3851 hapd->ctrl_iface_cookie,
3852 CTRL_IFACE_COOKIE_LEN);
3853 reply_len = 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003854 goto done;
3855 }
3856
3857 if (os_strncmp(buf, "COOKIE=", 7) != 0 ||
Hai Shalomfdcde762020-04-02 11:19:20 -07003858 hexstr2bin(buf + 7, lcookie, CTRL_IFACE_COOKIE_LEN) < 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003859 wpa_printf(MSG_DEBUG,
3860 "CTRL: No cookie in the request - drop request");
3861 os_free(reply);
3862 return;
3863 }
3864
Hai Shalomfdcde762020-04-02 11:19:20 -07003865 if (os_memcmp(hapd->ctrl_iface_cookie, lcookie,
3866 CTRL_IFACE_COOKIE_LEN) != 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003867 wpa_printf(MSG_DEBUG,
3868 "CTRL: Invalid cookie in the request - drop request");
3869 os_free(reply);
3870 return;
3871 }
3872
Hai Shalomfdcde762020-04-02 11:19:20 -07003873 pos = buf + 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003874 while (*pos == ' ')
3875 pos++;
3876#endif /* CONFIG_CTRL_IFACE_UDP */
3877
3878 if (os_strcmp(pos, "PING") == 0)
3879 level = MSG_EXCESSIVE;
3880 wpa_hexdump_ascii(level, "RX ctrl_iface", pos, res);
3881
3882 reply_len = hostapd_ctrl_iface_receive_process(hapd, pos,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003883 reply, reply_size,
3884 &from, fromlen);
3885
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003886#ifdef CONFIG_CTRL_IFACE_UDP
3887done:
3888#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003889 if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
3890 fromlen) < 0) {
3891 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
3892 strerror(errno));
3893 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003894 os_free(reply);
3895}
3896
3897
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003898#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003899static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd)
3900{
3901 char *buf;
3902 size_t len;
3903
3904 if (hapd->conf->ctrl_interface == NULL)
3905 return NULL;
3906
3907 len = os_strlen(hapd->conf->ctrl_interface) +
3908 os_strlen(hapd->conf->iface) + 2;
3909 buf = os_malloc(len);
3910 if (buf == NULL)
3911 return NULL;
3912
3913 os_snprintf(buf, len, "%s/%s",
3914 hapd->conf->ctrl_interface, hapd->conf->iface);
3915 buf[len - 1] = '\0';
3916 return buf;
3917}
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003918#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003919
3920
Dmitry Shmidt7a53dbb2015-06-11 13:13:53 -07003921static void hostapd_ctrl_iface_msg_cb(void *ctx, int level,
3922 enum wpa_msg_type type,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003923 const char *txt, size_t len)
3924{
3925 struct hostapd_data *hapd = ctx;
3926 if (hapd == NULL)
3927 return;
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02003928 hostapd_ctrl_iface_send(hapd, level, type, txt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003929}
3930
3931
3932int hostapd_ctrl_iface_init(struct hostapd_data *hapd)
3933{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003934#ifdef CONFIG_CTRL_IFACE_UDP
3935 int port = HOSTAPD_CTRL_IFACE_PORT;
3936 char p[32] = { 0 };
3937 char port_str[40], *tmp;
3938 char *pos;
3939 struct addrinfo hints = { 0 }, *res, *saveres;
3940 int n;
3941
3942 if (hapd->ctrl_sock > -1) {
3943 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
3944 return 0;
3945 }
3946
3947 if (hapd->conf->ctrl_interface == NULL)
3948 return 0;
3949
3950 pos = os_strstr(hapd->conf->ctrl_interface, "udp:");
3951 if (pos) {
3952 pos += 4;
3953 port = atoi(pos);
3954 if (port <= 0) {
3955 wpa_printf(MSG_ERROR, "Invalid ctrl_iface UDP port");
3956 goto fail;
3957 }
3958 }
3959
3960 dl_list_init(&hapd->ctrl_dst);
3961 hapd->ctrl_sock = -1;
Hai Shalomfdcde762020-04-02 11:19:20 -07003962 os_get_random(hapd->ctrl_iface_cookie, CTRL_IFACE_COOKIE_LEN);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08003963
3964#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3965 hints.ai_flags = AI_PASSIVE;
3966#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3967
3968#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
3969 hints.ai_family = AF_INET6;
3970#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3971 hints.ai_family = AF_INET;
3972#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
3973 hints.ai_socktype = SOCK_DGRAM;
3974
3975try_again:
3976 os_snprintf(p, sizeof(p), "%d", port);
3977 n = getaddrinfo(NULL, p, &hints, &res);
3978 if (n) {
3979 wpa_printf(MSG_ERROR, "getaddrinfo(): %s", gai_strerror(n));
3980 goto fail;
3981 }
3982
3983 saveres = res;
3984 hapd->ctrl_sock = socket(res->ai_family, res->ai_socktype,
3985 res->ai_protocol);
3986 if (hapd->ctrl_sock < 0) {
3987 wpa_printf(MSG_ERROR, "socket(PF_INET): %s", strerror(errno));
3988 goto fail;
3989 }
3990
3991 if (bind(hapd->ctrl_sock, res->ai_addr, res->ai_addrlen) < 0) {
3992 port--;
3993 if ((HOSTAPD_CTRL_IFACE_PORT - port) <
3994 HOSTAPD_CTRL_IFACE_PORT_LIMIT && !pos)
3995 goto try_again;
3996 wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
3997 goto fail;
3998 }
3999
4000 freeaddrinfo(saveres);
4001
4002 os_snprintf(port_str, sizeof(port_str), "udp:%d", port);
4003 tmp = os_strdup(port_str);
4004 if (tmp) {
4005 os_free(hapd->conf->ctrl_interface);
4006 hapd->conf->ctrl_interface = tmp;
4007 }
4008 wpa_printf(MSG_DEBUG, "ctrl_iface_init UDP port: %d", port);
4009
4010 if (eloop_register_read_sock(hapd->ctrl_sock,
4011 hostapd_ctrl_iface_receive, hapd, NULL) <
4012 0) {
4013 hostapd_ctrl_iface_deinit(hapd);
4014 return -1;
4015 }
4016
4017 hapd->msg_ctx = hapd;
4018 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4019
4020 return 0;
4021
4022fail:
4023 if (hapd->ctrl_sock >= 0)
4024 close(hapd->ctrl_sock);
4025 return -1;
4026#else /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004027 struct sockaddr_un addr;
4028 int s = -1;
4029 char *fname = NULL;
4030
Dmitry Shmidt04949592012-07-19 12:16:46 -07004031 if (hapd->ctrl_sock > -1) {
4032 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
4033 return 0;
4034 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004035
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004036 dl_list_init(&hapd->ctrl_dst);
4037
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004038 if (hapd->conf->ctrl_interface == NULL)
4039 return 0;
4040
4041 if (mkdir(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
4042 if (errno == EEXIST) {
4043 wpa_printf(MSG_DEBUG, "Using existing control "
4044 "interface directory.");
4045 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004046 wpa_printf(MSG_ERROR, "mkdir[ctrl_interface]: %s",
4047 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004048 goto fail;
4049 }
4050 }
4051
4052 if (hapd->conf->ctrl_interface_gid_set &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004053 lchown(hapd->conf->ctrl_interface, -1,
4054 hapd->conf->ctrl_interface_gid) < 0) {
4055 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004056 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004057 return -1;
4058 }
4059
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004060 if (!hapd->conf->ctrl_interface_gid_set &&
4061 hapd->iface->interfaces->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004062 lchown(hapd->conf->ctrl_interface, -1,
4063 hapd->iface->interfaces->ctrl_iface_group) < 0) {
4064 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004065 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004066 return -1;
4067 }
4068
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004069#ifdef ANDROID
4070 /*
4071 * Android is using umask 0077 which would leave the control interface
4072 * directory without group access. This breaks things since Wi-Fi
4073 * framework assumes that this directory can be accessed by other
4074 * applications in the wifi group. Fix this by adding group access even
4075 * if umask value would prevent this.
4076 */
4077 if (chmod(hapd->conf->ctrl_interface, S_IRWXU | S_IRWXG) < 0) {
4078 wpa_printf(MSG_ERROR, "CTRL: Could not chmod directory: %s",
4079 strerror(errno));
4080 /* Try to continue anyway */
4081 }
4082#endif /* ANDROID */
4083
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004084 if (os_strlen(hapd->conf->ctrl_interface) + 1 +
4085 os_strlen(hapd->conf->iface) >= sizeof(addr.sun_path))
4086 goto fail;
4087
4088 s = socket(PF_UNIX, SOCK_DGRAM, 0);
4089 if (s < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004090 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004091 goto fail;
4092 }
4093
4094 os_memset(&addr, 0, sizeof(addr));
4095#ifdef __FreeBSD__
4096 addr.sun_len = sizeof(addr);
4097#endif /* __FreeBSD__ */
4098 addr.sun_family = AF_UNIX;
4099 fname = hostapd_ctrl_iface_path(hapd);
4100 if (fname == NULL)
4101 goto fail;
4102 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
4103 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4104 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
4105 strerror(errno));
4106 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4107 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
4108 " allow connections - assuming it was left"
4109 "over from forced program termination");
4110 if (unlink(fname) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004111 wpa_printf(MSG_ERROR,
4112 "Could not unlink existing ctrl_iface socket '%s': %s",
4113 fname, strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004114 goto fail;
4115 }
4116 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
4117 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004118 wpa_printf(MSG_ERROR,
4119 "hostapd-ctrl-iface: bind(PF_UNIX): %s",
4120 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004121 goto fail;
4122 }
4123 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
4124 "ctrl_iface socket '%s'", fname);
4125 } else {
4126 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
4127 "be in use - cannot override it");
4128 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
4129 "not used anymore", fname);
4130 os_free(fname);
4131 fname = NULL;
4132 goto fail;
4133 }
4134 }
4135
4136 if (hapd->conf->ctrl_interface_gid_set &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004137 lchown(fname, -1, hapd->conf->ctrl_interface_gid) < 0) {
4138 wpa_printf(MSG_ERROR, "lchown[ctrl_interface/ifname]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004139 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004140 goto fail;
4141 }
4142
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004143 if (!hapd->conf->ctrl_interface_gid_set &&
4144 hapd->iface->interfaces->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004145 lchown(fname, -1, hapd->iface->interfaces->ctrl_iface_group) < 0) {
4146 wpa_printf(MSG_ERROR, "lchown[ctrl_interface/ifname]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004147 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004148 goto fail;
4149 }
4150
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004151 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004152 wpa_printf(MSG_ERROR, "chmod[ctrl_interface/ifname]: %s",
4153 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004154 goto fail;
4155 }
4156 os_free(fname);
4157
4158 hapd->ctrl_sock = s;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004159 if (eloop_register_read_sock(s, hostapd_ctrl_iface_receive, hapd,
4160 NULL) < 0) {
4161 hostapd_ctrl_iface_deinit(hapd);
4162 return -1;
4163 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004164 hapd->msg_ctx = hapd;
4165 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4166
4167 return 0;
4168
4169fail:
4170 if (s >= 0)
4171 close(s);
4172 if (fname) {
4173 unlink(fname);
4174 os_free(fname);
4175 }
4176 return -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004177#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004178}
4179
4180
4181void hostapd_ctrl_iface_deinit(struct hostapd_data *hapd)
4182{
4183 struct wpa_ctrl_dst *dst, *prev;
4184
4185 if (hapd->ctrl_sock > -1) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004186#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004187 char *fname;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004188#endif /* !CONFIG_CTRL_IFACE_UDP */
4189
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004190 eloop_unregister_read_sock(hapd->ctrl_sock);
4191 close(hapd->ctrl_sock);
4192 hapd->ctrl_sock = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004193#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004194 fname = hostapd_ctrl_iface_path(hapd);
4195 if (fname)
4196 unlink(fname);
4197 os_free(fname);
4198
4199 if (hapd->conf->ctrl_interface &&
4200 rmdir(hapd->conf->ctrl_interface) < 0) {
4201 if (errno == ENOTEMPTY) {
4202 wpa_printf(MSG_DEBUG, "Control interface "
4203 "directory not empty - leaving it "
4204 "behind");
4205 } else {
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004206 wpa_printf(MSG_ERROR,
4207 "rmdir[ctrl_interface=%s]: %s",
4208 hapd->conf->ctrl_interface,
4209 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004210 }
4211 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004212#endif /* !CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004213 }
4214
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004215 dl_list_for_each_safe(dst, prev, &hapd->ctrl_dst, struct wpa_ctrl_dst,
4216 list)
4217 os_free(dst);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004218
4219#ifdef CONFIG_TESTING_OPTIONS
4220 l2_packet_deinit(hapd->l2_test);
4221 hapd->l2_test = NULL;
4222#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004223}
4224
4225
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004226static int hostapd_ctrl_iface_add(struct hapd_interfaces *interfaces,
4227 char *buf)
4228{
4229 if (hostapd_add_iface(interfaces, buf) < 0) {
4230 wpa_printf(MSG_ERROR, "Adding interface %s failed", buf);
4231 return -1;
4232 }
4233 return 0;
4234}
4235
4236
4237static int hostapd_ctrl_iface_remove(struct hapd_interfaces *interfaces,
4238 char *buf)
4239{
4240 if (hostapd_remove_iface(interfaces, buf) < 0) {
4241 wpa_printf(MSG_ERROR, "Removing interface %s failed", buf);
4242 return -1;
4243 }
4244 return 0;
4245}
4246
4247
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004248static int hostapd_global_ctrl_iface_attach(struct hapd_interfaces *interfaces,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004249 struct sockaddr_storage *from,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004250 socklen_t fromlen, char *input)
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004251{
Roshan Pius3a1667e2018-07-03 15:17:14 -07004252 return ctrl_iface_attach(&interfaces->global_ctrl_dst, from, fromlen,
4253 input);
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004254}
4255
4256
4257static int hostapd_global_ctrl_iface_detach(struct hapd_interfaces *interfaces,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004258 struct sockaddr_storage *from,
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004259 socklen_t fromlen)
4260{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004261 return ctrl_iface_detach(&interfaces->global_ctrl_dst, from, fromlen);
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004262}
4263
4264
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004265static void hostapd_ctrl_iface_flush(struct hapd_interfaces *interfaces)
4266{
4267#ifdef CONFIG_WPS_TESTING
4268 wps_version_number = 0x20;
4269 wps_testing_dummy_cred = 0;
4270 wps_corrupt_pkhash = 0;
4271#endif /* CONFIG_WPS_TESTING */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004272
4273#ifdef CONFIG_TESTING_OPTIONS
4274#ifdef CONFIG_DPP
4275 dpp_test = DPP_TEST_DISABLED;
Hai Shalom4fbc08f2020-05-18 12:37:00 -07004276#ifdef CONFIG_DPP2
4277 dpp_version_override = 2;
4278#else /* CONFIG_DPP2 */
4279 dpp_version_override = 1;
4280#endif /* CONFIG_DPP2 */
Roshan Pius3a1667e2018-07-03 15:17:14 -07004281#endif /* CONFIG_DPP */
4282#endif /* CONFIG_TESTING_OPTIONS */
4283
4284#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07004285 dpp_global_clear(interfaces->dpp);
Roshan Pius3a1667e2018-07-03 15:17:14 -07004286#endif /* CONFIG_DPP */
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004287}
4288
4289
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004290#ifdef CONFIG_FST
4291
4292static int
4293hostapd_global_ctrl_iface_fst_attach(struct hapd_interfaces *interfaces,
4294 const char *cmd)
4295{
4296 char ifname[IFNAMSIZ + 1];
4297 struct fst_iface_cfg cfg;
4298 struct hostapd_data *hapd;
4299 struct fst_wpa_obj iface_obj;
4300
4301 if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
4302 hapd = hostapd_get_iface(interfaces, ifname);
4303 if (hapd) {
4304 if (hapd->iface->fst) {
4305 wpa_printf(MSG_INFO, "FST: Already attached");
4306 return -1;
4307 }
4308 fst_hostapd_fill_iface_obj(hapd, &iface_obj);
4309 hapd->iface->fst = fst_attach(ifname, hapd->own_addr,
4310 &iface_obj, &cfg);
4311 if (hapd->iface->fst)
4312 return 0;
4313 }
4314 }
4315
4316 return -EINVAL;
4317}
4318
4319
4320static int
4321hostapd_global_ctrl_iface_fst_detach(struct hapd_interfaces *interfaces,
4322 const char *cmd)
4323{
4324 char ifname[IFNAMSIZ + 1];
4325 struct hostapd_data * hapd;
4326
4327 if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
4328 hapd = hostapd_get_iface(interfaces, ifname);
4329 if (hapd) {
4330 if (!fst_iface_detach(ifname)) {
4331 hapd->iface->fst = NULL;
4332 hapd->iface->fst_ies = NULL;
4333 return 0;
4334 }
4335 }
4336 }
4337
4338 return -EINVAL;
4339}
4340
4341#endif /* CONFIG_FST */
4342
4343
4344static struct hostapd_data *
4345hostapd_interfaces_get_hapd(struct hapd_interfaces *interfaces,
4346 const char *ifname)
4347{
4348 size_t i, j;
4349
4350 for (i = 0; i < interfaces->count; i++) {
4351 struct hostapd_iface *iface = interfaces->iface[i];
4352
4353 for (j = 0; j < iface->num_bss; j++) {
4354 struct hostapd_data *hapd;
4355
4356 hapd = iface->bss[j];
4357 if (os_strcmp(ifname, hapd->conf->iface) == 0)
4358 return hapd;
4359 }
4360 }
4361
4362 return NULL;
4363}
4364
4365
4366static int hostapd_ctrl_iface_dup_param(struct hostapd_data *src_hapd,
4367 struct hostapd_data *dst_hapd,
4368 const char *param)
4369{
4370 int res;
4371 char *value;
4372
4373 value = os_zalloc(HOSTAPD_CLI_DUP_VALUE_MAX_LEN);
4374 if (!value) {
4375 wpa_printf(MSG_ERROR,
4376 "DUP: cannot allocate buffer to stringify %s",
4377 param);
4378 goto error_return;
4379 }
4380
4381 if (os_strcmp(param, "wpa") == 0) {
4382 os_snprintf(value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN, "%d",
4383 src_hapd->conf->wpa);
4384 } else if (os_strcmp(param, "wpa_key_mgmt") == 0 &&
4385 src_hapd->conf->wpa_key_mgmt) {
4386 res = hostapd_ctrl_iface_get_key_mgmt(
4387 src_hapd, value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN);
4388 if (os_snprintf_error(HOSTAPD_CLI_DUP_VALUE_MAX_LEN, res))
4389 goto error_stringify;
4390 } else if (os_strcmp(param, "wpa_pairwise") == 0 &&
4391 src_hapd->conf->wpa_pairwise) {
4392 res = wpa_write_ciphers(value,
4393 value + HOSTAPD_CLI_DUP_VALUE_MAX_LEN,
4394 src_hapd->conf->wpa_pairwise, " ");
4395 if (res < 0)
4396 goto error_stringify;
4397 } else if (os_strcmp(param, "rsn_pairwise") == 0 &&
4398 src_hapd->conf->rsn_pairwise) {
4399 res = wpa_write_ciphers(value,
4400 value + HOSTAPD_CLI_DUP_VALUE_MAX_LEN,
4401 src_hapd->conf->rsn_pairwise, " ");
4402 if (res < 0)
4403 goto error_stringify;
4404 } else if (os_strcmp(param, "wpa_passphrase") == 0 &&
4405 src_hapd->conf->ssid.wpa_passphrase) {
4406 os_snprintf(value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN, "%s",
4407 src_hapd->conf->ssid.wpa_passphrase);
4408 } else if (os_strcmp(param, "wpa_psk") == 0 &&
4409 src_hapd->conf->ssid.wpa_psk_set) {
4410 wpa_snprintf_hex(value, HOSTAPD_CLI_DUP_VALUE_MAX_LEN,
4411 src_hapd->conf->ssid.wpa_psk->psk, PMK_LEN);
4412 } else {
4413 wpa_printf(MSG_WARNING, "DUP: %s cannot be duplicated", param);
4414 goto error_return;
4415 }
4416
4417 res = hostapd_set_iface(dst_hapd->iconf, dst_hapd->conf, param, value);
4418 os_free(value);
4419 return res;
4420
4421error_stringify:
4422 wpa_printf(MSG_ERROR, "DUP: cannot stringify %s", param);
4423error_return:
4424 os_free(value);
4425 return -1;
4426}
4427
4428
4429static int
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004430hostapd_global_ctrl_iface_interfaces(struct hapd_interfaces *interfaces,
4431 const char *input,
4432 char *reply, int reply_size)
4433{
4434 size_t i, j;
4435 int res;
4436 char *pos, *end;
4437 struct hostapd_iface *iface;
4438 int show_ctrl = 0;
4439
4440 if (input)
4441 show_ctrl = !!os_strstr(input, "ctrl");
4442
4443 pos = reply;
4444 end = reply + reply_size;
4445
4446 for (i = 0; i < interfaces->count; i++) {
4447 iface = interfaces->iface[i];
4448
4449 for (j = 0; j < iface->num_bss; j++) {
4450 struct hostapd_bss_config *conf;
4451
4452 conf = iface->conf->bss[j];
4453 if (show_ctrl)
4454 res = os_snprintf(pos, end - pos,
4455 "%s ctrl_iface=%s\n",
4456 conf->iface,
4457 conf->ctrl_interface ?
4458 conf->ctrl_interface : "N/A");
4459 else
4460 res = os_snprintf(pos, end - pos, "%s\n",
4461 conf->iface);
4462 if (os_snprintf_error(end - pos, res)) {
4463 *pos = '\0';
4464 return pos - reply;
4465 }
4466 pos += res;
4467 }
4468 }
4469
4470 return pos - reply;
4471}
4472
4473
4474static int
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004475hostapd_global_ctrl_iface_dup_network(struct hapd_interfaces *interfaces,
4476 char *cmd)
4477{
4478 char *p_start = cmd, *p_end;
4479 struct hostapd_data *src_hapd, *dst_hapd;
4480
4481 /* cmd: "<src ifname> <dst ifname> <variable name> */
4482
4483 p_end = os_strchr(p_start, ' ');
4484 if (!p_end) {
4485 wpa_printf(MSG_ERROR, "DUP: no src ifname found in cmd: '%s'",
4486 cmd);
4487 return -1;
4488 }
4489
4490 *p_end = '\0';
4491 src_hapd = hostapd_interfaces_get_hapd(interfaces, p_start);
4492 if (!src_hapd) {
4493 wpa_printf(MSG_ERROR, "DUP: no src ifname found: '%s'",
4494 p_start);
4495 return -1;
4496 }
4497
4498 p_start = p_end + 1;
4499 p_end = os_strchr(p_start, ' ');
4500 if (!p_end) {
4501 wpa_printf(MSG_ERROR, "DUP: no dst ifname found in cmd: '%s'",
4502 cmd);
4503 return -1;
4504 }
4505
4506 *p_end = '\0';
4507 dst_hapd = hostapd_interfaces_get_hapd(interfaces, p_start);
4508 if (!dst_hapd) {
4509 wpa_printf(MSG_ERROR, "DUP: no dst ifname found: '%s'",
4510 p_start);
4511 return -1;
4512 }
4513
4514 p_start = p_end + 1;
4515 return hostapd_ctrl_iface_dup_param(src_hapd, dst_hapd, p_start);
4516}
4517
4518
4519static int hostapd_global_ctrl_iface_ifname(struct hapd_interfaces *interfaces,
4520 const char *ifname,
4521 char *buf, char *reply,
4522 int reply_size,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004523 struct sockaddr_storage *from,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004524 socklen_t fromlen)
4525{
4526 struct hostapd_data *hapd;
4527
4528 hapd = hostapd_interfaces_get_hapd(interfaces, ifname);
4529 if (hapd == NULL) {
4530 int res;
4531
4532 res = os_snprintf(reply, reply_size, "FAIL-NO-IFNAME-MATCH\n");
4533 if (os_snprintf_error(reply_size, res))
4534 return -1;
4535 return res;
4536 }
4537
4538 return hostapd_ctrl_iface_receive_process(hapd, buf, reply,reply_size,
4539 from, fromlen);
4540}
4541
4542
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004543static void hostapd_global_ctrl_iface_receive(int sock, void *eloop_ctx,
4544 void *sock_ctx)
4545{
Hai Shalomfdcde762020-04-02 11:19:20 -07004546 struct hapd_interfaces *interfaces = eloop_ctx;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004547 char buffer[256], *buf = buffer;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004548 int res;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004549 struct sockaddr_storage from;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004550 socklen_t fromlen = sizeof(from);
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004551 char *reply;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004552 int reply_len;
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004553 const int reply_size = 4096;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004554#ifdef CONFIG_CTRL_IFACE_UDP
Hai Shalomfdcde762020-04-02 11:19:20 -07004555 unsigned char lcookie[CTRL_IFACE_COOKIE_LEN];
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004556#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004557
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004558 res = recvfrom(sock, buffer, sizeof(buffer) - 1, 0,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004559 (struct sockaddr *) &from, &fromlen);
4560 if (res < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004561 wpa_printf(MSG_ERROR, "recvfrom(ctrl_iface): %s",
4562 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004563 return;
4564 }
4565 buf[res] = '\0';
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004566 wpa_printf(MSG_DEBUG, "Global ctrl_iface command: %s", buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004567
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004568 reply = os_malloc(reply_size);
4569 if (reply == NULL) {
4570 if (sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
4571 fromlen) < 0) {
4572 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
4573 strerror(errno));
4574 }
4575 return;
4576 }
4577
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004578 os_memcpy(reply, "OK\n", 3);
4579 reply_len = 3;
4580
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004581#ifdef CONFIG_CTRL_IFACE_UDP
4582 if (os_strcmp(buf, "GET_COOKIE") == 0) {
4583 os_memcpy(reply, "COOKIE=", 7);
Hai Shalomfdcde762020-04-02 11:19:20 -07004584 wpa_snprintf_hex(reply + 7, 2 * CTRL_IFACE_COOKIE_LEN + 1,
4585 interfaces->ctrl_iface_cookie,
4586 CTRL_IFACE_COOKIE_LEN);
4587 reply_len = 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004588 goto send_reply;
4589 }
4590
4591 if (os_strncmp(buf, "COOKIE=", 7) != 0 ||
Hai Shalomfdcde762020-04-02 11:19:20 -07004592 hexstr2bin(buf + 7, lcookie, CTRL_IFACE_COOKIE_LEN) < 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004593 wpa_printf(MSG_DEBUG,
4594 "CTRL: No cookie in the request - drop request");
4595 os_free(reply);
4596 return;
4597 }
4598
Hai Shalomfdcde762020-04-02 11:19:20 -07004599 if (os_memcmp(interfaces->ctrl_iface_cookie, lcookie,
4600 CTRL_IFACE_COOKIE_LEN) != 0) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004601 wpa_printf(MSG_DEBUG,
4602 "CTRL: Invalid cookie in the request - drop request");
4603 os_free(reply);
4604 return;
4605 }
4606
Hai Shalomfdcde762020-04-02 11:19:20 -07004607 buf += 7 + 2 * CTRL_IFACE_COOKIE_LEN;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004608 while (*buf == ' ')
4609 buf++;
4610#endif /* CONFIG_CTRL_IFACE_UDP */
4611
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004612 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
4613 char *pos = os_strchr(buf + 7, ' ');
4614
4615 if (pos) {
4616 *pos++ = '\0';
4617 reply_len = hostapd_global_ctrl_iface_ifname(
4618 interfaces, buf + 7, pos, reply, reply_size,
4619 &from, fromlen);
4620 goto send_reply;
4621 }
4622 }
4623
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004624 if (os_strcmp(buf, "PING") == 0) {
4625 os_memcpy(reply, "PONG\n", 5);
4626 reply_len = 5;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004627 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
4628 if (wpa_debug_reopen_file() < 0)
4629 reply_len = -1;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08004630 } else if (os_strcmp(buf, "FLUSH") == 0) {
4631 hostapd_ctrl_iface_flush(interfaces);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004632 } else if (os_strncmp(buf, "ADD ", 4) == 0) {
4633 if (hostapd_ctrl_iface_add(interfaces, buf + 4) < 0)
4634 reply_len = -1;
4635 } else if (os_strncmp(buf, "REMOVE ", 7) == 0) {
4636 if (hostapd_ctrl_iface_remove(interfaces, buf + 7) < 0)
4637 reply_len = -1;
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004638 } else if (os_strcmp(buf, "ATTACH") == 0) {
4639 if (hostapd_global_ctrl_iface_attach(interfaces, &from,
Roshan Pius3a1667e2018-07-03 15:17:14 -07004640 fromlen, NULL))
4641 reply_len = -1;
4642 } else if (os_strncmp(buf, "ATTACH ", 7) == 0) {
4643 if (hostapd_global_ctrl_iface_attach(interfaces, &from,
4644 fromlen, buf + 7))
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004645 reply_len = -1;
4646 } else if (os_strcmp(buf, "DETACH") == 0) {
4647 if (hostapd_global_ctrl_iface_detach(interfaces, &from,
4648 fromlen))
4649 reply_len = -1;
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -08004650#ifdef CONFIG_MODULE_TESTS
4651 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
Dmitry Shmidt7f93d6f2014-02-21 11:22:49 -08004652 if (hapd_module_tests() < 0)
4653 reply_len = -1;
4654#endif /* CONFIG_MODULE_TESTS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004655#ifdef CONFIG_FST
4656 } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
4657 if (!hostapd_global_ctrl_iface_fst_attach(interfaces, buf + 11))
4658 reply_len = os_snprintf(reply, reply_size, "OK\n");
4659 else
4660 reply_len = -1;
4661 } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
4662 if (!hostapd_global_ctrl_iface_fst_detach(interfaces, buf + 11))
4663 reply_len = os_snprintf(reply, reply_size, "OK\n");
4664 else
4665 reply_len = -1;
4666 } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
4667 reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
4668#endif /* CONFIG_FST */
4669 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
4670 if (!hostapd_global_ctrl_iface_dup_network(interfaces,
4671 buf + 12))
4672 reply_len = os_snprintf(reply, reply_size, "OK\n");
4673 else
4674 reply_len = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004675 } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
4676 reply_len = hostapd_global_ctrl_iface_interfaces(
4677 interfaces, buf + 10, reply, sizeof(buffer));
4678 } else if (os_strcmp(buf, "TERMINATE") == 0) {
4679 eloop_terminate();
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004680 } else {
4681 wpa_printf(MSG_DEBUG, "Unrecognized global ctrl_iface command "
4682 "ignored");
4683 reply_len = -1;
4684 }
4685
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004686send_reply:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004687 if (reply_len < 0) {
4688 os_memcpy(reply, "FAIL\n", 5);
4689 reply_len = 5;
4690 }
4691
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004692 if (sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
4693 fromlen) < 0) {
4694 wpa_printf(MSG_DEBUG, "CTRL: sendto failed: %s",
4695 strerror(errno));
4696 }
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004697 os_free(reply);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004698}
4699
4700
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004701#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004702static char * hostapd_global_ctrl_iface_path(struct hapd_interfaces *interface)
4703{
4704 char *buf;
4705 size_t len;
4706
4707 if (interface->global_iface_path == NULL)
4708 return NULL;
4709
4710 len = os_strlen(interface->global_iface_path) +
4711 os_strlen(interface->global_iface_name) + 2;
4712 buf = os_malloc(len);
4713 if (buf == NULL)
4714 return NULL;
4715
4716 os_snprintf(buf, len, "%s/%s", interface->global_iface_path,
4717 interface->global_iface_name);
4718 buf[len - 1] = '\0';
4719 return buf;
4720}
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004721#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004722
4723
4724int hostapd_global_ctrl_iface_init(struct hapd_interfaces *interface)
4725{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004726#ifdef CONFIG_CTRL_IFACE_UDP
4727 int port = HOSTAPD_GLOBAL_CTRL_IFACE_PORT;
4728 char p[32] = { 0 };
4729 char *pos;
4730 struct addrinfo hints = { 0 }, *res, *saveres;
4731 int n;
4732
4733 if (interface->global_ctrl_sock > -1) {
4734 wpa_printf(MSG_DEBUG, "ctrl_iface already exists!");
4735 return 0;
4736 }
4737
4738 if (interface->global_iface_path == NULL)
4739 return 0;
4740
4741 pos = os_strstr(interface->global_iface_path, "udp:");
4742 if (pos) {
4743 pos += 4;
4744 port = atoi(pos);
4745 if (port <= 0) {
4746 wpa_printf(MSG_ERROR, "Invalid global ctrl UDP port");
4747 goto fail;
4748 }
4749 }
4750
Hai Shalomfdcde762020-04-02 11:19:20 -07004751 os_get_random(interface->ctrl_iface_cookie, CTRL_IFACE_COOKIE_LEN);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004752
4753#ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
4754 hints.ai_flags = AI_PASSIVE;
4755#endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
4756
4757#ifdef CONFIG_CTRL_IFACE_UDP_IPV6
4758 hints.ai_family = AF_INET6;
4759#else /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4760 hints.ai_family = AF_INET;
4761#endif /* CONFIG_CTRL_IFACE_UDP_IPV6 */
4762 hints.ai_socktype = SOCK_DGRAM;
4763
4764try_again:
4765 os_snprintf(p, sizeof(p), "%d", port);
4766 n = getaddrinfo(NULL, p, &hints, &res);
4767 if (n) {
4768 wpa_printf(MSG_ERROR, "getaddrinfo(): %s", gai_strerror(n));
4769 goto fail;
4770 }
4771
4772 saveres = res;
4773 interface->global_ctrl_sock = socket(res->ai_family, res->ai_socktype,
4774 res->ai_protocol);
4775 if (interface->global_ctrl_sock < 0) {
4776 wpa_printf(MSG_ERROR, "socket(PF_INET): %s", strerror(errno));
4777 goto fail;
4778 }
4779
4780 if (bind(interface->global_ctrl_sock, res->ai_addr, res->ai_addrlen) <
4781 0) {
4782 port++;
4783 if ((port - HOSTAPD_GLOBAL_CTRL_IFACE_PORT) <
4784 HOSTAPD_GLOBAL_CTRL_IFACE_PORT_LIMIT && !pos)
4785 goto try_again;
4786 wpa_printf(MSG_ERROR, "bind(AF_INET): %s", strerror(errno));
4787 goto fail;
4788 }
4789
4790 freeaddrinfo(saveres);
4791
4792 wpa_printf(MSG_DEBUG, "global ctrl_iface_init UDP port: %d", port);
4793
4794 if (eloop_register_read_sock(interface->global_ctrl_sock,
4795 hostapd_global_ctrl_iface_receive,
4796 interface, NULL) < 0) {
4797 hostapd_global_ctrl_iface_deinit(interface);
4798 return -1;
4799 }
4800
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004801 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4802
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004803 return 0;
4804
4805fail:
4806 if (interface->global_ctrl_sock >= 0)
4807 close(interface->global_ctrl_sock);
4808 return -1;
4809#else /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004810 struct sockaddr_un addr;
4811 int s = -1;
4812 char *fname = NULL;
4813
4814 if (interface->global_iface_path == NULL) {
4815 wpa_printf(MSG_DEBUG, "ctrl_iface not configured!");
4816 return 0;
4817 }
4818
4819 if (mkdir(interface->global_iface_path, S_IRWXU | S_IRWXG) < 0) {
4820 if (errno == EEXIST) {
4821 wpa_printf(MSG_DEBUG, "Using existing control "
4822 "interface directory.");
4823 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004824 wpa_printf(MSG_ERROR, "mkdir[ctrl_interface]: %s",
4825 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004826 goto fail;
4827 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004828 } else if (interface->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004829 lchown(interface->global_iface_path, -1,
4830 interface->ctrl_iface_group) < 0) {
4831 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004832 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004833 goto fail;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004834 }
4835
4836 if (os_strlen(interface->global_iface_path) + 1 +
4837 os_strlen(interface->global_iface_name) >= sizeof(addr.sun_path))
4838 goto fail;
4839
4840 s = socket(PF_UNIX, SOCK_DGRAM, 0);
4841 if (s < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004842 wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004843 goto fail;
4844 }
4845
4846 os_memset(&addr, 0, sizeof(addr));
4847#ifdef __FreeBSD__
4848 addr.sun_len = sizeof(addr);
4849#endif /* __FreeBSD__ */
4850 addr.sun_family = AF_UNIX;
4851 fname = hostapd_global_ctrl_iface_path(interface);
4852 if (fname == NULL)
4853 goto fail;
4854 os_strlcpy(addr.sun_path, fname, sizeof(addr.sun_path));
4855 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4856 wpa_printf(MSG_DEBUG, "ctrl_iface bind(PF_UNIX) failed: %s",
4857 strerror(errno));
4858 if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
4859 wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
4860 " allow connections - assuming it was left"
4861 "over from forced program termination");
4862 if (unlink(fname) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004863 wpa_printf(MSG_ERROR,
4864 "Could not unlink existing ctrl_iface socket '%s': %s",
4865 fname, strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004866 goto fail;
4867 }
4868 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) <
4869 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004870 wpa_printf(MSG_ERROR, "bind(PF_UNIX): %s",
4871 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004872 goto fail;
4873 }
4874 wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
4875 "ctrl_iface socket '%s'", fname);
4876 } else {
4877 wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
4878 "be in use - cannot override it");
4879 wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
4880 "not used anymore", fname);
4881 os_free(fname);
4882 fname = NULL;
4883 goto fail;
4884 }
4885 }
4886
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004887 if (interface->ctrl_iface_group &&
Hai Shalom74f70d42019-02-11 14:42:39 -08004888 lchown(fname, -1, interface->ctrl_iface_group) < 0) {
4889 wpa_printf(MSG_ERROR, "lchown[ctrl_interface]: %s",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004890 strerror(errno));
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07004891 goto fail;
4892 }
4893
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004894 if (chmod(fname, S_IRWXU | S_IRWXG) < 0) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004895 wpa_printf(MSG_ERROR, "chmod[ctrl_interface/ifname]: %s",
4896 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004897 goto fail;
4898 }
4899 os_free(fname);
4900
4901 interface->global_ctrl_sock = s;
4902 eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
4903 interface, NULL);
4904
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004905 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
4906
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004907 return 0;
4908
4909fail:
4910 if (s >= 0)
4911 close(s);
4912 if (fname) {
4913 unlink(fname);
4914 os_free(fname);
4915 }
4916 return -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004917#endif /* CONFIG_CTRL_IFACE_UDP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004918}
4919
4920
4921void hostapd_global_ctrl_iface_deinit(struct hapd_interfaces *interfaces)
4922{
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004923#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004924 char *fname = NULL;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004925#endif /* CONFIG_CTRL_IFACE_UDP */
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004926 struct wpa_ctrl_dst *dst, *prev;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004927
4928 if (interfaces->global_ctrl_sock > -1) {
4929 eloop_unregister_read_sock(interfaces->global_ctrl_sock);
4930 close(interfaces->global_ctrl_sock);
4931 interfaces->global_ctrl_sock = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004932#ifndef CONFIG_CTRL_IFACE_UDP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004933 fname = hostapd_global_ctrl_iface_path(interfaces);
4934 if (fname) {
4935 unlink(fname);
4936 os_free(fname);
4937 }
4938
4939 if (interfaces->global_iface_path &&
4940 rmdir(interfaces->global_iface_path) < 0) {
4941 if (errno == ENOTEMPTY) {
4942 wpa_printf(MSG_DEBUG, "Control interface "
4943 "directory not empty - leaving it "
4944 "behind");
4945 } else {
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004946 wpa_printf(MSG_ERROR,
4947 "rmdir[ctrl_interface=%s]: %s",
4948 interfaces->global_iface_path,
4949 strerror(errno));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004950 }
4951 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004952#endif /* CONFIG_CTRL_IFACE_UDP */
Anton Nayshtutf715e8d2014-11-16 16:52:49 +02004953 }
4954
4955 os_free(interfaces->global_iface_path);
4956 interfaces->global_iface_path = NULL;
4957
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08004958 dl_list_for_each_safe(dst, prev, &interfaces->global_ctrl_dst,
4959 struct wpa_ctrl_dst, list)
4960 os_free(dst);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004961}
4962
4963
Roshan Pius3a1667e2018-07-03 15:17:14 -07004964static int hostapd_ctrl_check_event_enabled(struct wpa_ctrl_dst *dst,
4965 const char *buf)
4966{
4967 /* Enable Probe Request events based on explicit request.
4968 * Other events are enabled by default.
4969 */
4970 if (str_starts(buf, RX_PROBE_REQUEST))
4971 return !!(dst->events & WPA_EVENT_RX_PROBE_REQUEST);
4972 return 1;
4973}
4974
4975
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004976static void hostapd_ctrl_iface_send_internal(int sock, struct dl_list *ctrl_dst,
4977 const char *ifname, int level,
4978 const char *buf, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004979{
4980 struct wpa_ctrl_dst *dst, *next;
4981 struct msghdr msg;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004982 int idx, res;
4983 struct iovec io[5];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004984 char levelstr[10];
4985
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004986 if (sock < 0 || dl_list_empty(ctrl_dst))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004987 return;
4988
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004989 res = os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
4990 if (os_snprintf_error(sizeof(levelstr), res))
4991 return;
4992 idx = 0;
4993 if (ifname) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004994 io[idx].iov_base = "IFNAME=";
4995 io[idx].iov_len = 7;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08004996 idx++;
4997 io[idx].iov_base = (char *) ifname;
4998 io[idx].iov_len = os_strlen(ifname);
4999 idx++;
5000 io[idx].iov_base = " ";
5001 io[idx].iov_len = 1;
5002 idx++;
5003 }
5004 io[idx].iov_base = levelstr;
5005 io[idx].iov_len = os_strlen(levelstr);
5006 idx++;
5007 io[idx].iov_base = (char *) buf;
5008 io[idx].iov_len = len;
5009 idx++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005010 os_memset(&msg, 0, sizeof(msg));
5011 msg.msg_iov = io;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005012 msg.msg_iovlen = idx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005013
5014 idx = 0;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08005015 dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
Roshan Pius3a1667e2018-07-03 15:17:14 -07005016 if ((level >= dst->debug_level) &&
5017 hostapd_ctrl_check_event_enabled(dst, buf)) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08005018 sockaddr_print(MSG_DEBUG, "CTRL_IFACE monitor send",
5019 &dst->addr, dst->addrlen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005020 msg.msg_name = &dst->addr;
5021 msg.msg_namelen = dst->addrlen;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005022 if (sendmsg(sock, &msg, 0) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005023 int _errno = errno;
5024 wpa_printf(MSG_INFO, "CTRL_IFACE monitor[%d]: "
5025 "%d - %s",
5026 idx, errno, strerror(errno));
5027 dst->errors++;
5028 if (dst->errors > 10 || _errno == ENOENT) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005029 ctrl_iface_detach(ctrl_dst,
5030 &dst->addr,
5031 dst->addrlen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005032 }
5033 } else
5034 dst->errors = 0;
5035 }
5036 idx++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005037 }
5038}
5039
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08005040
5041static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level,
5042 enum wpa_msg_type type,
5043 const char *buf, size_t len)
5044{
5045 if (type != WPA_MSG_NO_GLOBAL) {
5046 hostapd_ctrl_iface_send_internal(
5047 hapd->iface->interfaces->global_ctrl_sock,
5048 &hapd->iface->interfaces->global_ctrl_dst,
5049 type != WPA_MSG_PER_INTERFACE ?
5050 NULL : hapd->conf->iface,
5051 level, buf, len);
5052 }
5053
5054 if (type != WPA_MSG_ONLY_GLOBAL) {
5055 hostapd_ctrl_iface_send_internal(
5056 hapd->ctrl_sock, &hapd->ctrl_dst,
5057 NULL, level, buf, len);
5058 }
5059}
5060
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005061#endif /* CONFIG_NATIVE_WINDOWS */