1 /*
2  * hostapd - command line interface for hostapd daemon
3  * Copyright (c) 2004-2022, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #include "includes.h"
10 #include "common/wpa_ctrl.h"
11 #include "common/ieee802_11_defs.h"
12 #include "utils/common.h"
13 #include "utils/eloop.h"
14 #include "utils/edit.h"
15 #include "common/version.h"
16 #include "common/cli.h"
17 #include "hostapd_cli_zephyr.h"
18 
19 static DEFINE_DL_LIST(stations); /* struct cli_txt_entry */
20 
21 #define CMD_BUF_LEN 1024
22 
hostapd_cli_cmd(struct wpa_ctrl * ctrl,const char * cmd,int min_args,int argc,char * argv[])23 static int hostapd_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd,
24 			   int min_args, int argc, char *argv[])
25 {
26 	char buf[CMD_BUF_LEN] = {0};
27 	int ret = 0;
28 	bool interactive = 0;
29 
30 	for (int i = 0; i < argc; i++) {
31 		if (strcmp(argv[i], "interactive") == 0) {
32 			interactive = 1;
33 			argv[i] = NULL;
34 			argc--;
35 			break;
36 		}
37 	}
38 
39 	if (argc < min_args) {
40 		wpa_printf(MSG_INFO, "Invalid %s command - at least %d argument%s "
41 		       "required.\n", cmd, min_args,
42 		       min_args > 1 ? "s are" : " is");
43 		return -1;
44 	}
45 
46 	if (write_cmd(buf, CMD_BUF_LEN, cmd, argc, argv) < 0){
47 		ret = -1;
48 		goto out;
49 	}
50 
51 	if (interactive)
52 		ret = hostapd_ctrl_command_interactive(ctrl, buf);
53 	else
54 		ret = hostapd_ctrl_command(ctrl, buf);
55 
56 out:
57 	return ret;
58 
59 }
60 
hostapd_cli_cmd_set(struct wpa_ctrl * ctrl,int argc,char * argv[])61 static int hostapd_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
62 {
63 	char cmd[256];
64 	int res;
65 
66 	if (argc == 1) {
67 		res = os_snprintf(cmd, sizeof(cmd), "SET %s ", argv[0]);
68 		if (os_snprintf_error(sizeof(cmd), res)) {
69 			wpa_printf(MSG_INFO, "Too long SET command.\n");
70 			return -1;
71 		}
72 		return hostapd_cli_cmd(ctrl, cmd, 0, argc, argv);
73 	}
74 
75 	return hostapd_cli_cmd(ctrl, "SET", 2, argc, argv);
76 }
77 
78 
hostapd_complete_set(const char * str,int pos)79 static char ** hostapd_complete_set(const char *str, int pos)
80 {
81         int arg = get_cmd_arg_num(str, pos);
82         const char *fields[] = {
83 #ifdef CONFIG_WPS_TESTING
84                 "wps_version_number", "wps_testing_stub_cred",
85                 "wps_corrupt_pkhash",
86 #endif /* CONFIG_WPS_TESTING */
87 #ifdef CONFIG_INTERWORKING
88                 "gas_frag_limit",
89 #endif /* CONFIG_INTERWORKING */
90 #ifdef CONFIG_TESTING_OPTIONS
91                 "ext_mgmt_frame_handling", "ext_eapol_frame_io",
92 #endif /* CONFIG_TESTING_OPTIONS */
93 #ifdef CONFIG_MBO
94                 "mbo_assoc_disallow",
95 #endif /* CONFIG_MBO */
96                 "deny_mac_file", "accept_mac_file",
97         };
98         int i, num_fields = ARRAY_SIZE(fields);
99 
100         if (arg == 1) {
101                 char **res;
102 
103                 res = os_calloc(num_fields + 1, sizeof(char *));
104                 if (!res)
105                         return NULL;
106                 for (i = 0; i < num_fields; i++) {
107                         res[i] = os_strdup(fields[i]);
108                         if (!res[i])
109                                 return res;
110                 }
111                 return res;
112         }
113         return NULL;
114 }
115 
116 
hostapd_cli_cmd_disassociate(struct wpa_ctrl * ctrl,int argc,char * argv[])117 static int hostapd_cli_cmd_disassociate(struct wpa_ctrl *ctrl, int argc,
118                                         char *argv[])
119 {
120         char buf[64];
121         if (argc < 1) {
122                 printf("Invalid 'disassociate' command - exactly one "
123                        "argument, STA address, is required.\n");
124                 return -1;
125         }
126         if (argc > 1)
127                 os_snprintf(buf, sizeof(buf), "DISASSOCIATE %s %s",
128                             argv[0], argv[1]);
129         else
130                 os_snprintf(buf, sizeof(buf), "DISASSOCIATE %s", argv[0]);
131         return hostapd_ctrl_command(ctrl, buf);
132 }
133 
134 
hostapd_cli_cmd_deauthenticate(struct wpa_ctrl * ctrl,int argc,char * argv[])135 static int hostapd_cli_cmd_deauthenticate(struct wpa_ctrl *ctrl, int argc,
136                                           char *argv[])
137 {
138         char buf[64];
139         if (argc < 1) {
140                 printf("Invalid 'deauthenticate' command - exactly one "
141                        "argument, STA address, is required.\n");
142                 return -1;
143         }
144         if (argc > 1)
145                 os_snprintf(buf, sizeof(buf), "DEAUTHENTICATE %s %s",
146                             argv[0], argv[1]);
147         else
148                 os_snprintf(buf, sizeof(buf), "DEAUTHENTICATE %s", argv[0]);
149         return hostapd_ctrl_command(ctrl, buf);
150 }
151 
152 
hostapd_cli_cmd_status(struct wpa_ctrl * ctrl,int argc,char * argv[])153 static int hostapd_cli_cmd_status(struct wpa_ctrl *ctrl, int argc, char *argv[])
154 {
155 	if (argc > 0 && os_strcmp(argv[0], "driver") == 0)
156 		return hostapd_ctrl_command(ctrl, "STATUS-DRIVER");
157 	return hostapd_ctrl_command(ctrl, "STATUS");
158 }
159 
160 
hostapd_cli_cmd_enable(struct wpa_ctrl * ctrl,int argc,char * argv[])161 static int hostapd_cli_cmd_enable(struct wpa_ctrl *ctrl, int argc,
162                                   char *argv[])
163 {
164         return hostapd_ctrl_command(ctrl, "ENABLE");
165 }
166 
167 
hostapd_cli_cmd_reload(struct wpa_ctrl * ctrl,int argc,char * argv[])168 static int hostapd_cli_cmd_reload(struct wpa_ctrl *ctrl, int argc,
169                                   char *argv[])
170 {
171         return hostapd_ctrl_command(ctrl, "RELOAD");
172 }
173 
174 
hostapd_cli_cmd_disable(struct wpa_ctrl * ctrl,int argc,char * argv[])175 static int hostapd_cli_cmd_disable(struct wpa_ctrl *ctrl, int argc,
176                                    char *argv[])
177 {
178         return hostapd_ctrl_command(ctrl, "DISABLE");
179 }
180 
181 
hostapd_cli_cmd_update_beacon(struct wpa_ctrl * ctrl,int argc,char * argv[])182 static int hostapd_cli_cmd_update_beacon(struct wpa_ctrl *ctrl, int argc,
183                                          char *argv[])
184 {
185         return hostapd_ctrl_command(ctrl, "UPDATE_BEACON");
186 }
187 
188 
hostapd_cli_cmd_sta(struct wpa_ctrl * ctrl,int argc,char * argv[])189 static int hostapd_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
190 {
191 	char buf[64];
192 	if (argc < 1) {
193 		printf("Invalid 'sta' command - at least one argument, STA "
194 		       "address, is required.\n");
195 		return -1;
196 	}
197 	if (argc > 1)
198 		os_snprintf(buf, sizeof(buf), "STA %s %s", argv[0], argv[1]);
199 	else
200 		os_snprintf(buf, sizeof(buf), "STA %s", argv[0]);
201 	return hostapd_ctrl_command(ctrl, buf);
202 }
203 
204 
hostapd_complete_stations(const char * str,int pos)205 static char ** hostapd_complete_stations(const char *str, int pos)
206 {
207 	int arg = get_cmd_arg_num(str, pos);
208 	char **res = NULL;
209 
210 	switch (arg) {
211 	case 1:
212 		res = cli_txt_list_array(&stations);
213 		break;
214 	}
215 
216 	return res;
217 }
218 
219 
hostapd_cli_cmd_new_sta(struct wpa_ctrl * ctrl,int argc,char * argv[])220 static int hostapd_cli_cmd_new_sta(struct wpa_ctrl *ctrl, int argc,
221 				   char *argv[])
222 {
223 	char buf[64];
224 	if (argc != 1) {
225 		printf("Invalid 'new_sta' command - exactly one argument, STA "
226 		       "address, is required.\n");
227 		return -1;
228 	}
229 	os_snprintf(buf, sizeof(buf), "NEW_STA %s", argv[0]);
230 	return hostapd_ctrl_command(ctrl, buf);
231 }
232 
233 
hostapd_cli_cmd_chan_switch(struct wpa_ctrl * ctrl,int argc,char * argv[])234 static int hostapd_cli_cmd_chan_switch(struct wpa_ctrl *ctrl,
235                                        int argc, char *argv[])
236 {
237         char cmd[256];
238         int res;
239         int i;
240         char *tmp;
241         int total;
242 
243         if (argc < 2) {
244                 printf("Invalid chan_switch command: needs at least two "
245                        "arguments (count and freq)\n"
246                        "usage: <cs_count> <freq> [sec_channel_offset=] "
247                        "[center_freq1=] [center_freq2=] [bandwidth=] "
248                        "[blocktx] [ht|vht]\n");
249                 return -1;
250         }
251 
252         res = os_snprintf(cmd, sizeof(cmd), "CHAN_SWITCH %s %s",
253                           argv[0], argv[1]);
254         if (os_snprintf_error(sizeof(cmd), res)) {
255                 printf("Too long CHAN_SWITCH command.\n");
256                 return -1;
257         }
258 
259         total = res;
260         for (i = 2; i < argc; i++) {
261                 tmp = cmd + total;
262                 res = os_snprintf(tmp, sizeof(cmd) - total, " %s", argv[i]);
263                 if (os_snprintf_error(sizeof(cmd) - total, res)) {
264                         printf("Too long CHAN_SWITCH command.\n");
265                         return -1;
266                 }
267                 total += res;
268         }
269         return hostapd_ctrl_command(ctrl, cmd);
270 }
271 
272 
hostapd_cli_cmd_ping(struct wpa_ctrl * ctrl,int argc,char * argv[])273 static int hostapd_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
274 {
275         return hostapd_ctrl_command(ctrl, "PING");
276 }
277 
278 
hostapd_cli_cmd_relog(struct wpa_ctrl * ctrl,int argc,char * argv[])279 static int hostapd_cli_cmd_relog(struct wpa_ctrl *ctrl, int argc, char *argv[])
280 {
281         return hostapd_ctrl_command(ctrl, "RELOG");
282 }
283 
284 
hostapd_cli_cmd_mib(struct wpa_ctrl * ctrl,int argc,char * argv[])285 static int hostapd_cli_cmd_mib(struct wpa_ctrl *ctrl, int argc, char *argv[])
286 {
287         if (argc > 0) {
288                 char buf[100];
289                 os_snprintf(buf, sizeof(buf), "MIB %s", argv[0]);
290                 return hostapd_ctrl_command(ctrl, buf);
291         }
292         return hostapd_ctrl_command(ctrl, "MIB");
293 }
294 
295 
296 #ifdef CONFIG_TAXONOMY
hostapd_cli_cmd_signature(struct wpa_ctrl * ctrl,int argc,char * argv[])297 static int hostapd_cli_cmd_signature(struct wpa_ctrl *ctrl, int argc,
298 				     char *argv[])
299 {
300 	char buf[64];
301 
302 	if (argc != 1) {
303 		printf("Invalid 'signature' command - exactly one argument, STA address, is required.\n");
304 		return -1;
305 	}
306 	os_snprintf(buf, sizeof(buf), "SIGNATURE %s", argv[0]);
307 	return hostapd_ctrl_command(ctrl, buf);
308 }
309 #endif /* CONFIG_TAXONOMY */
310 
311 
hostapd_cli_cmd_sa_query(struct wpa_ctrl * ctrl,int argc,char * argv[])312 static int hostapd_cli_cmd_sa_query(struct wpa_ctrl *ctrl, int argc,
313 				    char *argv[])
314 {
315 	char buf[64];
316 	if (argc != 1) {
317 		printf("Invalid 'sa_query' command - exactly one argument, "
318 		       "STA address, is required.\n");
319 		return -1;
320 	}
321 	os_snprintf(buf, sizeof(buf), "SA_QUERY %s", argv[0]);
322 	return hostapd_ctrl_command(ctrl, buf);
323 }
324 
325 
326 #ifdef CONFIG_WPS
hostapd_cli_cmd_wps_pin(struct wpa_ctrl * ctrl,int argc,char * argv[])327 static int hostapd_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc,
328 				   char *argv[])
329 {
330 	char buf[256];
331 	if (argc < 2) {
332 		printf("Invalid 'wps_pin' command - at least two arguments, "
333 		       "UUID and PIN, are required.\n");
334 		return -1;
335 	}
336 	if (argc > 3)
337 		os_snprintf(buf, sizeof(buf), "WPS_PIN %s %s %s %s",
338 			 argv[0], argv[1], argv[2], argv[3]);
339 	else if (argc > 2)
340 		os_snprintf(buf, sizeof(buf), "WPS_PIN %s %s %s",
341 			 argv[0], argv[1], argv[2]);
342 	else
343 		os_snprintf(buf, sizeof(buf), "WPS_PIN %s %s", argv[0], argv[1]);
344 	return hostapd_ctrl_command(ctrl, buf);
345 }
346 
347 
hostapd_cli_cmd_wps_check_pin(struct wpa_ctrl * ctrl,int argc,char * argv[])348 static int hostapd_cli_cmd_wps_check_pin(struct wpa_ctrl *ctrl, int argc,
349 					 char *argv[])
350 {
351 	char cmd[256];
352 	int res;
353 
354 	if (argc != 1 && argc != 2) {
355 		printf("Invalid WPS_CHECK_PIN command: needs one argument:\n"
356 		       "- PIN to be verified\n");
357 		return -1;
358 	}
359 
360 	if (argc == 2)
361 		res = os_snprintf(cmd, sizeof(cmd), "WPS_CHECK_PIN %s %s",
362 				  argv[0], argv[1]);
363 	else
364 		res = os_snprintf(cmd, sizeof(cmd), "WPS_CHECK_PIN %s",
365 				  argv[0]);
366 	if (os_snprintf_error(sizeof(cmd), res)) {
367 		printf("Too long WPS_CHECK_PIN command.\n");
368 		return -1;
369 	}
370 	return hostapd_ctrl_command(ctrl, cmd);
371 }
372 
373 
hostapd_cli_cmd_wps_pbc(struct wpa_ctrl * ctrl,int argc,char * argv[])374 static int hostapd_cli_cmd_wps_pbc(struct wpa_ctrl *ctrl, int argc,
375 				   char *argv[])
376 {
377 	return hostapd_ctrl_command(ctrl, "WPS_PBC");
378 }
379 
380 
hostapd_cli_cmd_wps_cancel(struct wpa_ctrl * ctrl,int argc,char * argv[])381 static int hostapd_cli_cmd_wps_cancel(struct wpa_ctrl *ctrl, int argc,
382 				      char *argv[])
383 {
384 	return hostapd_ctrl_command(ctrl, "WPS_CANCEL");
385 }
386 
387 
388 #ifdef CONFIG_WPS_NFC
hostapd_cli_cmd_wps_nfc_tag_read(struct wpa_ctrl * ctrl,int argc,char * argv[])389 static int hostapd_cli_cmd_wps_nfc_tag_read(struct wpa_ctrl *ctrl, int argc,
390 					    char *argv[])
391 {
392 	int ret;
393 	char *buf;
394 	size_t buflen;
395 
396 	if (argc != 1) {
397 		printf("Invalid 'wps_nfc_tag_read' command - one argument "
398 		       "is required.\n");
399 		return -1;
400 	}
401 
402 	buflen = 18 + os_strlen(argv[0]);
403 	buf = os_malloc(buflen);
404 	if (buf == NULL)
405 		return -1;
406 	os_snprintf(buf, buflen, "WPS_NFC_TAG_READ %s", argv[0]);
407 
408 	ret = hostapd_ctrl_command(ctrl, buf);
409 	os_free(buf);
410 
411 	return ret;
412 }
413 
414 
hostapd_cli_cmd_wps_nfc_config_token(struct wpa_ctrl * ctrl,int argc,char * argv[])415 static int hostapd_cli_cmd_wps_nfc_config_token(struct wpa_ctrl *ctrl,
416 						int argc, char *argv[])
417 {
418 	char cmd[64];
419 	int res;
420 
421 	if (argc != 1) {
422 		printf("Invalid 'wps_nfc_config_token' command - one argument "
423 		       "is required.\n");
424 		return -1;
425 	}
426 
427 	res = os_snprintf(cmd, sizeof(cmd), "WPS_NFC_CONFIG_TOKEN %s",
428 			  argv[0]);
429 	if (os_snprintf_error(sizeof(cmd), res)) {
430 		printf("Too long WPS_NFC_CONFIG_TOKEN command.\n");
431 		return -1;
432 	}
433 	return hostapd_ctrl_command(ctrl, cmd);
434 }
435 
436 
hostapd_cli_cmd_wps_nfc_token(struct wpa_ctrl * ctrl,int argc,char * argv[])437 static int hostapd_cli_cmd_wps_nfc_token(struct wpa_ctrl *ctrl,
438 					 int argc, char *argv[])
439 {
440 	char cmd[64];
441 	int res;
442 
443 	if (argc != 1) {
444 		printf("Invalid 'wps_nfc_token' command - one argument is "
445 		       "required.\n");
446 		return -1;
447 	}
448 
449 	res = os_snprintf(cmd, sizeof(cmd), "WPS_NFC_TOKEN %s", argv[0]);
450 	if (os_snprintf_error(sizeof(cmd), res)) {
451 		printf("Too long WPS_NFC_TOKEN command.\n");
452 		return -1;
453 	}
454 	return hostapd_ctrl_command(ctrl, cmd);
455 }
456 
457 
hostapd_cli_cmd_nfc_get_handover_sel(struct wpa_ctrl * ctrl,int argc,char * argv[])458 static int hostapd_cli_cmd_nfc_get_handover_sel(struct wpa_ctrl *ctrl,
459 						int argc, char *argv[])
460 {
461 	char cmd[64];
462 	int res;
463 
464 	if (argc != 2) {
465 		printf("Invalid 'nfc_get_handover_sel' command - two arguments "
466 		       "are required.\n");
467 		return -1;
468 	}
469 
470 	res = os_snprintf(cmd, sizeof(cmd), "NFC_GET_HANDOVER_SEL %s %s",
471 			  argv[0], argv[1]);
472 	if (os_snprintf_error(sizeof(cmd), res)) {
473 		printf("Too long NFC_GET_HANDOVER_SEL command.\n");
474 		return -1;
475 	}
476 	return hostapd_ctrl_command(ctrl, cmd);
477 }
478 
479 #endif /* CONFIG_WPS_NFC */
480 
481 
hostapd_cli_cmd_wps_ap_pin(struct wpa_ctrl * ctrl,int argc,char * argv[])482 static int hostapd_cli_cmd_wps_ap_pin(struct wpa_ctrl *ctrl, int argc,
483 				      char *argv[])
484 {
485 	char buf[64];
486 	if (argc < 1) {
487 		printf("Invalid 'wps_ap_pin' command - at least one argument "
488 		       "is required.\n");
489 		return -1;
490 	}
491 	if (argc > 2)
492 		os_snprintf(buf, sizeof(buf), "WPS_AP_PIN %s %s %s",
493 			 argv[0], argv[1], argv[2]);
494 	else if (argc > 1)
495 		os_snprintf(buf, sizeof(buf), "WPS_AP_PIN %s %s",
496 			 argv[0], argv[1]);
497 	else
498 		os_snprintf(buf, sizeof(buf), "WPS_AP_PIN %s", argv[0]);
499 	return hostapd_ctrl_command(ctrl, buf);
500 }
501 
502 
hostapd_cli_cmd_wps_get_status(struct wpa_ctrl * ctrl,int argc,char * argv[])503 static int hostapd_cli_cmd_wps_get_status(struct wpa_ctrl *ctrl, int argc,
504 					  char *argv[])
505 {
506 	return hostapd_ctrl_command(ctrl, "WPS_GET_STATUS");
507 }
508 
509 
hostapd_cli_cmd_wps_config(struct wpa_ctrl * ctrl,int argc,char * argv[])510 static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc,
511 				      char *argv[])
512 {
513 	char buf[256];
514 	char ssid_hex[2 * SSID_MAX_LEN + 1];
515 	char key_hex[2 * 64 + 1];
516 	int i;
517 
518 	if (argc < 1) {
519 		printf("Invalid 'wps_config' command - at least two arguments "
520 		       "are required.\n");
521 		return -1;
522 	}
523 
524 	ssid_hex[0] = '\0';
525 	for (i = 0; i < SSID_MAX_LEN; i++) {
526 		if (argv[0][i] == '\0')
527 			break;
528 		os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[0][i]);
529 	}
530 
531 	key_hex[0] = '\0';
532 	if (argc > 3) {
533 		for (i = 0; i < 64; i++) {
534 			if (argv[3][i] == '\0')
535 				break;
536 			os_snprintf(&key_hex[i * 2], 3, "%02x",
537 				    argv[3][i]);
538 		}
539 	}
540 
541 	if (argc > 3)
542 		os_snprintf(buf, sizeof(buf), "WPS_CONFIG %s %s %s %s",
543 			 ssid_hex, argv[1], argv[2], key_hex);
544 	else if (argc > 2)
545 		os_snprintf(buf, sizeof(buf), "WPS_CONFIG %s %s %s",
546 			 ssid_hex, argv[1], argv[2]);
547 	else
548 		os_snprintf(buf, sizeof(buf), "WPS_CONFIG %s %s",
549 			 ssid_hex, argv[1]);
550 	return hostapd_ctrl_command(ctrl, buf);
551 }
552 #endif /* CONFIG_WPS */
553 
554 
hostapd_cli_cmd_disassoc_imminent(struct wpa_ctrl * ctrl,int argc,char * argv[])555 static int hostapd_cli_cmd_disassoc_imminent(struct wpa_ctrl *ctrl, int argc,
556 					     char *argv[])
557 {
558 	char buf[300];
559 	int res;
560 
561 	if (argc < 2) {
562 		printf("Invalid 'disassoc_imminent' command - two arguments "
563 		       "(STA addr and Disassociation Timer) are needed\n");
564 		return -1;
565 	}
566 
567 	res = os_snprintf(buf, sizeof(buf), "DISASSOC_IMMINENT %s %s",
568 			  argv[0], argv[1]);
569 	if (os_snprintf_error(sizeof(buf), res))
570 		return -1;
571 	return hostapd_ctrl_command(ctrl, buf);
572 }
573 
574 
hostapd_cli_cmd_ess_disassoc(struct wpa_ctrl * ctrl,int argc,char * argv[])575 static int hostapd_cli_cmd_ess_disassoc(struct wpa_ctrl *ctrl, int argc,
576 					char *argv[])
577 {
578 	char buf[300];
579 	int res;
580 
581 	if (argc < 3) {
582 		printf("Invalid 'ess_disassoc' command - three arguments (STA "
583 		       "addr, disassoc timer, and URL) are needed\n");
584 		return -1;
585 	}
586 
587 	res = os_snprintf(buf, sizeof(buf), "ESS_DISASSOC %s %s %s",
588 			  argv[0], argv[1], argv[2]);
589 	if (os_snprintf_error(sizeof(buf), res))
590 		return -1;
591 	return hostapd_ctrl_command(ctrl, buf);
592 }
593 
594 
hostapd_cli_cmd_bss_tm_req(struct wpa_ctrl * ctrl,int argc,char * argv[])595 static int hostapd_cli_cmd_bss_tm_req(struct wpa_ctrl *ctrl, int argc,
596 				      char *argv[])
597 {
598 	char buf[2000], *tmp;
599 	int res, i, total;
600 
601 	if (argc < 1) {
602 		printf("Invalid 'bss_tm_req' command - at least one argument (STA addr) is needed\n");
603 		return -1;
604 	}
605 
606 	res = os_snprintf(buf, sizeof(buf), "BSS_TM_REQ %s", argv[0]);
607 	if (os_snprintf_error(sizeof(buf), res))
608 		return -1;
609 
610 	total = res;
611 	for (i = 1; i < argc; i++) {
612 		tmp = &buf[total];
613 		res = os_snprintf(tmp, sizeof(buf) - total, " %s", argv[i]);
614 		if (os_snprintf_error(sizeof(buf) - total, res))
615 			return -1;
616 		total += res;
617 	}
618 	return hostapd_ctrl_command(ctrl, buf);
619 }
620 
621 
hostapd_cli_cmd_get_config(struct wpa_ctrl * ctrl,int argc,char * argv[])622 static int hostapd_cli_cmd_get_config(struct wpa_ctrl *ctrl, int argc,
623 				      char *argv[])
624 {
625 	return hostapd_ctrl_command(ctrl, "GET_CONFIG");
626 }
627 
628 
wpa_ctrl_command_sta(struct wpa_ctrl * ctrl,const char * cmd,char * addr,size_t addr_len,int print)629 static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, const char *cmd,
630 				char *addr, size_t addr_len, int print)
631 {
632 	char buf[1024], *pos;
633 	size_t len;
634 	int ret;
635 
636 	len = sizeof(buf) - 1;
637 	ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), buf, &len,
638 			       hostapd_cli_msg_cb);
639 	if (ret == -2) {
640 		printf("'%s' command timed out.\n", cmd);
641 		return -2;
642 	} else if (ret < 0) {
643 		printf("'%s' command failed.\n", cmd);
644 		return -1;
645 	}
646 
647 	buf[len] = '\0';
648 	if (memcmp(buf, "FAIL", 4) == 0)
649 		return -1;
650 	if (print)
651 		printf("%s", buf);
652 
653 	pos = buf;
654 	while (*pos != '\0' && *pos != '\n')
655 		pos++;
656 	*pos = '\0';
657 	os_strlcpy(addr, buf, addr_len);
658 	return 0;
659 }
660 
661 
hostapd_cli_cmd_all_sta(struct wpa_ctrl * ctrl,int argc,char * argv[])662 static int hostapd_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc,
663 				   char *argv[])
664 {
665 	char addr[32], cmd[64];
666 
667 	if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 1))
668 		return 0;
669 	do {
670 		os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
671 	} while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 1) == 0);
672 
673 	return -1;
674 }
675 
676 
hostapd_cli_cmd_list_sta(struct wpa_ctrl * ctrl,int argc,char * argv[])677 static int hostapd_cli_cmd_list_sta(struct wpa_ctrl *ctrl, int argc,
678 				    char *argv[])
679 {
680 	char addr[32], cmd[64];
681 
682 	if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
683 		return 0;
684 	do {
685 		if (os_strcmp(addr, "") != 0)
686 			printf("%s\n", addr);
687 		os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
688 	} while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
689 
690 	return 0;
691 }
692 
693 
hostapd_cli_cmd_set_qos_map_set(struct wpa_ctrl * ctrl,int argc,char * argv[])694 static int hostapd_cli_cmd_set_qos_map_set(struct wpa_ctrl *ctrl,
695 					   int argc, char *argv[])
696 {
697 	char buf[200];
698 	int res;
699 
700 	if (argc != 1) {
701 		printf("Invalid 'set_qos_map_set' command - "
702 		       "one argument (comma delimited QoS map set) "
703 		       "is needed\n");
704 		return -1;
705 	}
706 
707 	res = os_snprintf(buf, sizeof(buf), "SET_QOS_MAP_SET %s", argv[0]);
708 	if (os_snprintf_error(sizeof(buf), res))
709 		return -1;
710 	return hostapd_ctrl_command(ctrl, buf);
711 }
712 
713 
hostapd_cli_cmd_send_qos_map_conf(struct wpa_ctrl * ctrl,int argc,char * argv[])714 static int hostapd_cli_cmd_send_qos_map_conf(struct wpa_ctrl *ctrl,
715 					     int argc, char *argv[])
716 {
717 	char buf[50];
718 	int res;
719 
720 	if (argc != 1) {
721 		printf("Invalid 'send_qos_map_conf' command - "
722 		       "one argument (STA addr) is needed\n");
723 		return -1;
724 	}
725 
726 	res = os_snprintf(buf, sizeof(buf), "SEND_QOS_MAP_CONF %s", argv[0]);
727 	if (os_snprintf_error(sizeof(buf), res))
728 		return -1;
729 	return hostapd_ctrl_command(ctrl, buf);
730 }
731 
732 
hostapd_cli_cmd_hs20_wnm_notif(struct wpa_ctrl * ctrl,int argc,char * argv[])733 static int hostapd_cli_cmd_hs20_wnm_notif(struct wpa_ctrl *ctrl, int argc,
734 					  char *argv[])
735 {
736 	char buf[300];
737 	int res;
738 
739 	if (argc < 2) {
740 		printf("Invalid 'hs20_wnm_notif' command - two arguments (STA "
741 		       "addr and URL) are needed\n");
742 		return -1;
743 	}
744 
745 	res = os_snprintf(buf, sizeof(buf), "HS20_WNM_NOTIF %s %s",
746 			  argv[0], argv[1]);
747 	if (os_snprintf_error(sizeof(buf), res))
748 		return -1;
749 	return hostapd_ctrl_command(ctrl, buf);
750 }
751 
752 
hostapd_cli_cmd_hs20_deauth_req(struct wpa_ctrl * ctrl,int argc,char * argv[])753 static int hostapd_cli_cmd_hs20_deauth_req(struct wpa_ctrl *ctrl, int argc,
754 					   char *argv[])
755 {
756 	char buf[300];
757 	int res;
758 
759 	if (argc < 3) {
760 		printf("Invalid 'hs20_deauth_req' command - at least three arguments (STA addr, Code, Re-auth Delay) are needed\n");
761 		return -1;
762 	}
763 
764 	if (argc > 3)
765 		res = os_snprintf(buf, sizeof(buf),
766 				  "HS20_DEAUTH_REQ %s %s %s %s",
767 				  argv[0], argv[1], argv[2], argv[3]);
768 	else
769 		res = os_snprintf(buf, sizeof(buf),
770 				  "HS20_DEAUTH_REQ %s %s %s",
771 				  argv[0], argv[1], argv[2]);
772 	if (os_snprintf_error(sizeof(buf), res))
773 		return -1;
774 	return hostapd_ctrl_command(ctrl, buf);
775 }
776 
777 
hostapd_cli_cmd_get(struct wpa_ctrl * ctrl,int argc,char * argv[])778 static int hostapd_cli_cmd_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
779 {
780 	char cmd[256];
781 	int res;
782 
783 	if (argc != 1) {
784 		printf("Invalid GET command: needs one argument (variable "
785 		       "name)\n");
786 		return -1;
787 	}
788 
789 	res = os_snprintf(cmd, sizeof(cmd), "GET %s", argv[0]);
790 	if (os_snprintf_error(sizeof(cmd), res)) {
791 		printf("Too long GET command.\n");
792 		return -1;
793 	}
794 	return hostapd_ctrl_command(ctrl, cmd);
795 }
796 
797 
hostapd_complete_get(const char * str,int pos)798 static char ** hostapd_complete_get(const char *str, int pos)
799 {
800 	int arg = get_cmd_arg_num(str, pos);
801 	const char *fields[] = {
802 		"version", "tls_library",
803 	};
804 	int i, num_fields = ARRAY_SIZE(fields);
805 
806 	if (arg == 1) {
807 		char **res;
808 
809 		res = os_calloc(num_fields + 1, sizeof(char *));
810 		if (!res)
811 			return NULL;
812 		for (i = 0; i < num_fields; i++) {
813 			res[i] = os_strdup(fields[i]);
814 			if (!res[i])
815 				return res;
816 		}
817 		return res;
818 	}
819 	return NULL;
820 }
821 
822 
823 #ifdef CONFIG_FST
hostapd_cli_cmd_fst(struct wpa_ctrl * ctrl,int argc,char * argv[])824 static int hostapd_cli_cmd_fst(struct wpa_ctrl *ctrl, int argc, char *argv[])
825 {
826 	char cmd[256];
827 	int res;
828 	int i;
829 	int total;
830 
831 	if (argc <= 0) {
832 		printf("FST command: parameters are required.\n");
833 		return -1;
834 	}
835 
836 	total = os_snprintf(cmd, sizeof(cmd), "FST-MANAGER");
837 
838 	for (i = 0; i < argc; i++) {
839 		res = os_snprintf(cmd + total, sizeof(cmd) - total, " %s",
840 				  argv[i]);
841 		if (os_snprintf_error(sizeof(cmd) - total, res)) {
842 			printf("Too long fst command.\n");
843 			return -1;
844 		}
845 		total += res;
846 	}
847 	return hostapd_ctrl_command(ctrl, cmd);
848 }
849 #endif /* CONFIG_FST */
850 
851 
hostapd_cli_cmd_vendor(struct wpa_ctrl * ctrl,int argc,char * argv[])852 static int hostapd_cli_cmd_vendor(struct wpa_ctrl *ctrl, int argc, char *argv[])
853 {
854 	char cmd[256];
855 	int res;
856 
857 	if (argc < 2 || argc > 4) {
858 		printf("Invalid vendor command\n"
859 		       "usage: <vendor id> <command id> [<hex formatted command argument>] [nested=<0|1>]\n");
860 		return -1;
861 	}
862 
863 	res = os_snprintf(cmd, sizeof(cmd), "VENDOR %s %s %s%s%s", argv[0],
864 			  argv[1], argc >= 3 ? argv[2] : "",
865 			  argc == 4 ? " " : "", argc == 4 ? argv[3] : "");
866 	if (os_snprintf_error(sizeof(cmd), res)) {
867 		printf("Too long VENDOR command.\n");
868 		return -1;
869 	}
870 	return hostapd_ctrl_command(ctrl, cmd);
871 }
872 
873 
hostapd_cli_cmd_erp_flush(struct wpa_ctrl * ctrl,int argc,char * argv[])874 static int hostapd_cli_cmd_erp_flush(struct wpa_ctrl *ctrl, int argc,
875 				     char *argv[])
876 {
877 	return hostapd_ctrl_command(ctrl, "ERP_FLUSH");
878 }
879 
880 
hostapd_cli_cmd_log_level(struct wpa_ctrl * ctrl,int argc,char * argv[])881 static int hostapd_cli_cmd_log_level(struct wpa_ctrl *ctrl, int argc,
882 				     char *argv[])
883 {
884 	char cmd[256];
885 	int res;
886 
887 	res = os_snprintf(cmd, sizeof(cmd), "LOG_LEVEL%s%s%s%s",
888 			  argc >= 1 ? " " : "",
889 			  argc >= 1 ? argv[0] : "",
890 			  argc == 2 ? " " : "",
891 			  argc == 2 ? argv[1] : "");
892 	if (os_snprintf_error(sizeof(cmd), res)) {
893 		printf("Too long option\n");
894 		return -1;
895 	}
896 	return hostapd_ctrl_command(ctrl, cmd);
897 }
898 
899 
hostapd_cli_cmd_raw(struct wpa_ctrl * ctrl,int argc,char * argv[])900 static int hostapd_cli_cmd_raw(struct wpa_ctrl *ctrl, int argc, char *argv[])
901 {
902 	if (argc == 0)
903 		return -1;
904 	return hostapd_cli_cmd(ctrl, argv[0], 0, argc - 1, &argv[1]);
905 }
906 
907 
hostapd_cli_cmd_pmksa(struct wpa_ctrl * ctrl,int argc,char * argv[])908 static int hostapd_cli_cmd_pmksa(struct wpa_ctrl *ctrl, int argc, char *argv[])
909 {
910 	return hostapd_ctrl_command(ctrl, "PMKSA");
911 }
912 
913 
hostapd_cli_cmd_pmksa_flush(struct wpa_ctrl * ctrl,int argc,char * argv[])914 static int hostapd_cli_cmd_pmksa_flush(struct wpa_ctrl *ctrl, int argc,
915 				       char *argv[])
916 {
917 	return hostapd_ctrl_command(ctrl, "PMKSA_FLUSH");
918 }
919 
920 
hostapd_cli_cmd_set_neighbor(struct wpa_ctrl * ctrl,int argc,char * argv[])921 static int hostapd_cli_cmd_set_neighbor(struct wpa_ctrl *ctrl, int argc,
922 					char *argv[])
923 {
924 	char cmd[2048];
925 	int res;
926 
927 	if (argc < 3 || argc > 6) {
928 		printf("Invalid set_neighbor command: needs 3-6 arguments\n");
929 		return -1;
930 	}
931 
932 	res = os_snprintf(cmd, sizeof(cmd), "SET_NEIGHBOR %s %s %s %s %s %s",
933 			  argv[0], argv[1], argv[2], argc >= 4 ? argv[3] : "",
934 			  argc >= 5 ? argv[4] : "", argc == 6 ? argv[5] : "");
935 	if (os_snprintf_error(sizeof(cmd), res)) {
936 		printf("Too long SET_NEIGHBOR command.\n");
937 		return -1;
938 	}
939 	return hostapd_ctrl_command(ctrl, cmd);
940 }
941 
942 
hostapd_cli_cmd_show_neighbor(struct wpa_ctrl * ctrl,int argc,char * argv[])943 static int hostapd_cli_cmd_show_neighbor(struct wpa_ctrl *ctrl, int argc,
944 					 char *argv[])
945 {
946 	return hostapd_ctrl_command(ctrl, "SHOW_NEIGHBOR");
947 }
948 
949 
hostapd_cli_cmd_remove_neighbor(struct wpa_ctrl * ctrl,int argc,char * argv[])950 static int hostapd_cli_cmd_remove_neighbor(struct wpa_ctrl *ctrl, int argc,
951 					   char *argv[])
952 {
953 	return hostapd_cli_cmd(ctrl, "REMOVE_NEIGHBOR", 1, argc, argv);
954 }
955 
956 
hostapd_cli_cmd_req_lci(struct wpa_ctrl * ctrl,int argc,char * argv[])957 static int hostapd_cli_cmd_req_lci(struct wpa_ctrl *ctrl, int argc,
958 				   char *argv[])
959 {
960 	char cmd[256];
961 	int res;
962 
963 	if (argc != 1) {
964 		printf("Invalid req_lci command - requires destination address\n");
965 		return -1;
966 	}
967 
968 	res = os_snprintf(cmd, sizeof(cmd), "REQ_LCI %s", argv[0]);
969 	if (os_snprintf_error(sizeof(cmd), res)) {
970 		printf("Too long REQ_LCI command.\n");
971 		return -1;
972 	}
973 	return hostapd_ctrl_command(ctrl, cmd);
974 }
975 
976 
hostapd_cli_cmd_req_range(struct wpa_ctrl * ctrl,int argc,char * argv[])977 static int hostapd_cli_cmd_req_range(struct wpa_ctrl *ctrl, int argc,
978 				     char *argv[])
979 {
980 	if (argc < 4) {
981 		printf("Invalid req_range command: needs at least 4 arguments - dest address, randomization interval, min AP count, and 1 to 16 AP addresses\n");
982 		return -1;
983 	}
984 
985 	return hostapd_cli_cmd(ctrl, "REQ_RANGE", 4, argc, argv);
986 }
987 
988 
hostapd_cli_cmd_driver_flags(struct wpa_ctrl * ctrl,int argc,char * argv[])989 static int hostapd_cli_cmd_driver_flags(struct wpa_ctrl *ctrl, int argc,
990 					char *argv[])
991 {
992 	return hostapd_ctrl_command(ctrl, "DRIVER_FLAGS");
993 }
994 
995 
996 #ifdef CONFIG_DPP
997 
hostapd_cli_cmd_dpp_qr_code(struct wpa_ctrl * ctrl,int argc,char * argv[])998 static int hostapd_cli_cmd_dpp_qr_code(struct wpa_ctrl *ctrl, int argc,
999 				       char *argv[])
1000 {
1001 	return hostapd_cli_cmd(ctrl, "DPP_QR_CODE", 1, argc, argv);
1002 }
1003 
1004 
hostapd_cli_cmd_dpp_bootstrap_gen(struct wpa_ctrl * ctrl,int argc,char * argv[])1005 static int hostapd_cli_cmd_dpp_bootstrap_gen(struct wpa_ctrl *ctrl, int argc,
1006 					     char *argv[])
1007 {
1008 	return hostapd_cli_cmd(ctrl, "DPP_BOOTSTRAP_GEN", 1, argc, argv);
1009 }
1010 
1011 
hostapd_cli_cmd_dpp_bootstrap_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])1012 static int hostapd_cli_cmd_dpp_bootstrap_remove(struct wpa_ctrl *ctrl, int argc,
1013 						char *argv[])
1014 {
1015 	return hostapd_cli_cmd(ctrl, "DPP_BOOTSTRAP_REMOVE", 1, argc, argv);
1016 }
1017 
1018 
hostapd_cli_cmd_dpp_bootstrap_get_uri(struct wpa_ctrl * ctrl,int argc,char * argv[])1019 static int hostapd_cli_cmd_dpp_bootstrap_get_uri(struct wpa_ctrl *ctrl,
1020 						 int argc, char *argv[])
1021 {
1022 	return hostapd_cli_cmd(ctrl, "DPP_BOOTSTRAP_GET_URI", 1, argc, argv);
1023 }
1024 
1025 
hostapd_cli_cmd_dpp_bootstrap_info(struct wpa_ctrl * ctrl,int argc,char * argv[])1026 static int hostapd_cli_cmd_dpp_bootstrap_info(struct wpa_ctrl *ctrl, int argc,
1027 					      char *argv[])
1028 {
1029 	return hostapd_cli_cmd(ctrl, "DPP_BOOTSTRAP_INFO", 1, argc, argv);
1030 }
1031 
1032 
hostapd_cli_cmd_dpp_bootstrap_set(struct wpa_ctrl * ctrl,int argc,char * argv[])1033 static int hostapd_cli_cmd_dpp_bootstrap_set(struct wpa_ctrl *ctrl, int argc,
1034 					     char *argv[])
1035 {
1036 	return hostapd_cli_cmd(ctrl, "DPP_BOOTSTRAP_SET", 1, argc, argv);
1037 }
1038 
1039 
hostapd_cli_cmd_dpp_auth_init(struct wpa_ctrl * ctrl,int argc,char * argv[])1040 static int hostapd_cli_cmd_dpp_auth_init(struct wpa_ctrl *ctrl, int argc,
1041 					 char *argv[])
1042 {
1043 	return hostapd_cli_cmd(ctrl, "DPP_AUTH_INIT", 1, argc, argv);
1044 }
1045 
1046 
hostapd_cli_cmd_dpp_listen(struct wpa_ctrl * ctrl,int argc,char * argv[])1047 static int hostapd_cli_cmd_dpp_listen(struct wpa_ctrl *ctrl, int argc,
1048 				      char *argv[])
1049 {
1050 	return hostapd_cli_cmd(ctrl, "DPP_LISTEN", 1, argc, argv);
1051 }
1052 
1053 
hostapd_cli_cmd_dpp_stop_listen(struct wpa_ctrl * ctrl,int argc,char * argv[])1054 static int hostapd_cli_cmd_dpp_stop_listen(struct wpa_ctrl *ctrl, int argc,
1055 					   char *argv[])
1056 {
1057 	return hostapd_ctrl_command(ctrl, "DPP_STOP_LISTEN");
1058 }
1059 
1060 
hostapd_cli_cmd_dpp_configurator_add(struct wpa_ctrl * ctrl,int argc,char * argv[])1061 static int hostapd_cli_cmd_dpp_configurator_add(struct wpa_ctrl *ctrl, int argc,
1062 						char *argv[])
1063 {
1064 	return hostapd_cli_cmd(ctrl, "DPP_CONFIGURATOR_ADD", 0, argc, argv);
1065 }
1066 
1067 
hostapd_cli_cmd_dpp_configurator_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])1068 static int hostapd_cli_cmd_dpp_configurator_remove(struct wpa_ctrl *ctrl,
1069 						   int argc, char *argv[])
1070 {
1071 	return hostapd_cli_cmd(ctrl, "DPP_CONFIGURATOR_REMOVE", 1, argc, argv);
1072 }
1073 
1074 
hostapd_cli_cmd_dpp_configurator_get_key(struct wpa_ctrl * ctrl,int argc,char * argv[])1075 static int hostapd_cli_cmd_dpp_configurator_get_key(struct wpa_ctrl *ctrl,
1076 						    int argc, char *argv[])
1077 {
1078 	return hostapd_cli_cmd(ctrl, "DPP_CONFIGURATOR_GET_KEY", 1, argc, argv);
1079 }
1080 
1081 
hostapd_cli_cmd_dpp_configurator_sign(struct wpa_ctrl * ctrl,int argc,char * argv[])1082 static int hostapd_cli_cmd_dpp_configurator_sign(struct wpa_ctrl *ctrl,
1083 						 int argc, char *argv[])
1084 {
1085        return hostapd_cli_cmd(ctrl, "DPP_CONFIGURATOR_SIGN", 1, argc, argv);
1086 }
1087 
1088 
hostapd_cli_cmd_dpp_pkex_add(struct wpa_ctrl * ctrl,int argc,char * argv[])1089 static int hostapd_cli_cmd_dpp_pkex_add(struct wpa_ctrl *ctrl, int argc,
1090 					char *argv[])
1091 {
1092 	return hostapd_cli_cmd(ctrl, "DPP_PKEX_ADD", 1, argc, argv);
1093 }
1094 
1095 
hostapd_cli_cmd_dpp_pkex_remove(struct wpa_ctrl * ctrl,int argc,char * argv[])1096 static int hostapd_cli_cmd_dpp_pkex_remove(struct wpa_ctrl *ctrl, int argc,
1097 					   char *argv[])
1098 {
1099 	return hostapd_cli_cmd(ctrl, "DPP_PKEX_REMOVE", 1, argc, argv);
1100 }
1101 
1102 
1103 #ifdef CONFIG_DPP2
1104 
hostapd_cli_cmd_dpp_controller_start(struct wpa_ctrl * ctrl,int argc,char * argv[])1105 static int hostapd_cli_cmd_dpp_controller_start(struct wpa_ctrl *ctrl, int argc,
1106 						char *argv[])
1107 {
1108 	return hostapd_cli_cmd(ctrl, "DPP_CONTROLLER_START", 1, argc, argv);
1109 }
1110 
1111 
hostapd_cli_cmd_dpp_controller_stop(struct wpa_ctrl * ctrl,int argc,char * argv[])1112 static int hostapd_cli_cmd_dpp_controller_stop(struct wpa_ctrl *ctrl, int argc,
1113 					       char *argv[])
1114 {
1115 	return hostapd_ctrl_command(ctrl, "DPP_CONTROLLER_STOP");
1116 }
1117 
1118 
hostapd_cli_cmd_dpp_chirp(struct wpa_ctrl * ctrl,int argc,char * argv[])1119 static int hostapd_cli_cmd_dpp_chirp(struct wpa_ctrl *ctrl, int argc,
1120 				     char *argv[])
1121 {
1122 	return hostapd_cli_cmd(ctrl, "DPP_CHIRP", 1, argc, argv);
1123 }
1124 
1125 
hostapd_cli_cmd_dpp_stop_chirp(struct wpa_ctrl * ctrl,int argc,char * argv[])1126 static int hostapd_cli_cmd_dpp_stop_chirp(struct wpa_ctrl *ctrl, int argc,
1127 					  char *argv[])
1128 {
1129 	return hostapd_ctrl_command(ctrl, "DPP_STOP_CHIRP");
1130 }
1131 
1132 #endif /* CONFIG_DPP2 */
1133 #endif /* CONFIG_DPP */
1134 
1135 
hostapd_cli_cmd_accept_macacl(struct wpa_ctrl * ctrl,int argc,char * argv[])1136 static int hostapd_cli_cmd_accept_macacl(struct wpa_ctrl *ctrl, int argc,
1137 					 char *argv[])
1138 {
1139 	return hostapd_cli_cmd(ctrl, "ACCEPT_ACL", 1, argc, argv);
1140 }
1141 
1142 
hostapd_cli_cmd_deny_macacl(struct wpa_ctrl * ctrl,int argc,char * argv[])1143 static int hostapd_cli_cmd_deny_macacl(struct wpa_ctrl *ctrl, int argc,
1144 				       char *argv[])
1145 {
1146 	return hostapd_cli_cmd(ctrl, "DENY_ACL", 1, argc, argv);
1147 }
1148 
1149 
hostapd_cli_cmd_poll_sta(struct wpa_ctrl * ctrl,int argc,char * argv[])1150 static int hostapd_cli_cmd_poll_sta(struct wpa_ctrl *ctrl, int argc,
1151 				    char *argv[])
1152 {
1153 	return hostapd_cli_cmd(ctrl, "POLL_STA", 1, argc, argv);
1154 }
1155 
1156 
hostapd_cli_cmd_req_beacon(struct wpa_ctrl * ctrl,int argc,char * argv[])1157 static int hostapd_cli_cmd_req_beacon(struct wpa_ctrl *ctrl, int argc,
1158 				      char *argv[])
1159 {
1160 	return hostapd_cli_cmd(ctrl, "REQ_BEACON", 2, argc, argv);
1161 }
1162 
1163 
hostapd_cli_cmd_reload_wpa_psk(struct wpa_ctrl * ctrl,int argc,char * argv[])1164 static int hostapd_cli_cmd_reload_wpa_psk(struct wpa_ctrl *ctrl, int argc,
1165 					  char *argv[])
1166 {
1167 	return hostapd_ctrl_command(ctrl, "RELOAD_WPA_PSK");
1168 }
1169 
1170 
1171 struct hostapd_cli_cmd {
1172 	const char *cmd;
1173 	int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
1174 	char ** (*completion)(const char *str, int pos);
1175 	const char *usage;
1176 };
1177 
1178 static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
1179 	{ "status", hostapd_cli_cmd_status, NULL,
1180 	  "= show interface status info" },
1181 	{ "set", hostapd_cli_cmd_set, hostapd_complete_set,
1182 	  "<name> <value> = set runtime variables" },
1183 	{ "sta", hostapd_cli_cmd_sta, hostapd_complete_stations,
1184 	  "<addr> = get MIB variables for one station" },
1185 	{ "all_sta", hostapd_cli_cmd_all_sta, NULL,
1186 	   "= get MIB variables for all stations" },
1187 	{ "list_sta", hostapd_cli_cmd_list_sta, NULL,
1188 	   "= list all stations" },
1189 	{ "new_sta", hostapd_cli_cmd_new_sta, NULL,
1190 	  "<addr> = add a new station" },
1191 	{ "deauthenticate", hostapd_cli_cmd_deauthenticate,
1192 	  hostapd_complete_stations,
1193 	  "<addr> = deauthenticate a station" },
1194 	{ "disassociate", hostapd_cli_cmd_disassociate,
1195 	  hostapd_complete_stations,
1196 	  "<addr> = disassociate a station" },
1197 	{ "enable", hostapd_cli_cmd_enable, NULL,
1198 	  "= enable hostapd on current interface" },
1199 	{ "reload", hostapd_cli_cmd_reload, NULL,
1200 	  "= reload configuration for current interface" },
1201 	{ "disable", hostapd_cli_cmd_disable, NULL,
1202 	  "= disable hostapd on current interface" },
1203 	{ "update_beacon", hostapd_cli_cmd_update_beacon, NULL,
1204 	  "= update Beacon frame contents\n"},
1205 	{ "chan_switch", hostapd_cli_cmd_chan_switch, NULL,
1206 	  "<cs_count> <freq> [sec_channel_offset=] [center_freq1=]\n"
1207 	  "  [center_freq2=] [bandwidth=] [blocktx] [ht|vht]\n"
1208 	  "  = initiate channel switch announcement" },
1209 	{ "ping", hostapd_cli_cmd_ping, NULL,
1210 	  "= pings hostapd" },
1211 	{ "mib", hostapd_cli_cmd_mib, NULL,
1212 	  "= get MIB variables (dot1x, dot11, radius)" },
1213 	{ "relog", hostapd_cli_cmd_relog, NULL,
1214 	  "= reload/truncate debug log output file" },
1215 #ifdef CONFIG_TAXONOMY
1216 	{ "signature", hostapd_cli_cmd_signature, hostapd_complete_stations,
1217 	  "<addr> = get taxonomy signature for a station" },
1218 #endif /* CONFIG_TAXONOMY */
1219 	{ "sa_query", hostapd_cli_cmd_sa_query, hostapd_complete_stations,
1220 	  "<addr> = send SA Query to a station" },
1221 #ifdef CONFIG_WPS
1222 	{ "wps_pin", hostapd_cli_cmd_wps_pin, NULL,
1223 	  "<uuid> <pin> [timeout] [addr] = add WPS Enrollee PIN" },
1224 	{ "wps_check_pin", hostapd_cli_cmd_wps_check_pin, NULL,
1225 	  "<PIN> = verify PIN checksum" },
1226 	{ "wps_pbc", hostapd_cli_cmd_wps_pbc, NULL,
1227 	  "= indicate button pushed to initiate PBC" },
1228 	{ "wps_cancel", hostapd_cli_cmd_wps_cancel, NULL,
1229 	  "= cancel the pending WPS operation" },
1230 #ifdef CONFIG_WPS_NFC
1231 	{ "wps_nfc_tag_read", hostapd_cli_cmd_wps_nfc_tag_read, NULL,
1232 	  "<hexdump> = report read NFC tag with WPS data" },
1233 	{ "wps_nfc_config_token", hostapd_cli_cmd_wps_nfc_config_token, NULL,
1234 	  "<WPS/NDEF> = build NFC configuration token" },
1235 	{ "wps_nfc_token", hostapd_cli_cmd_wps_nfc_token, NULL,
1236 	  "<WPS/NDEF/enable/disable> = manager NFC password token" },
1237 	{ "nfc_get_handover_sel", hostapd_cli_cmd_nfc_get_handover_sel, NULL,
1238 	  NULL },
1239 #endif /* CONFIG_WPS_NFC */
1240 	{ "wps_ap_pin", hostapd_cli_cmd_wps_ap_pin, NULL,
1241 	  "<cmd> [params..] = enable/disable AP PIN" },
1242 	{ "wps_config", hostapd_cli_cmd_wps_config, NULL,
1243 	  "<SSID> <auth> <encr> <key> = configure AP" },
1244 	{ "wps_get_status", hostapd_cli_cmd_wps_get_status, NULL,
1245 	  "= show current WPS status" },
1246 #endif /* CONFIG_WPS */
1247 	{ "disassoc_imminent", hostapd_cli_cmd_disassoc_imminent, NULL,
1248 	  "= send Disassociation Imminent notification" },
1249 	{ "ess_disassoc", hostapd_cli_cmd_ess_disassoc, NULL,
1250 	  "= send ESS Dissassociation Imminent notification" },
1251 	{ "bss_tm_req", hostapd_cli_cmd_bss_tm_req, NULL,
1252 	  "= send BSS Transition Management Request" },
1253 	{ "get_config", hostapd_cli_cmd_get_config, NULL,
1254 	  "= show current configuration" },
1255 #ifdef CONFIG_FST
1256 	{ "fst", hostapd_cli_cmd_fst, NULL,
1257 	  "<params...> = send FST-MANAGER control interface command" },
1258 #endif /* CONFIG_FST */
1259 	{ "raw", hostapd_cli_cmd_raw, NULL,
1260 	  "<params..> = send unprocessed command" },
1261 	{ "get", hostapd_cli_cmd_get, hostapd_complete_get,
1262 	  "<name> = get runtime info" },
1263 	{ "set_qos_map_set", hostapd_cli_cmd_set_qos_map_set, NULL,
1264 	  "<arg,arg,...> = set QoS Map set element" },
1265 	{ "send_qos_map_conf", hostapd_cli_cmd_send_qos_map_conf,
1266 	  hostapd_complete_stations,
1267 	  "<addr> = send QoS Map Configure frame" },
1268 	{ "hs20_wnm_notif", hostapd_cli_cmd_hs20_wnm_notif, NULL,
1269 	  "<addr> <url>\n"
1270 	  "  = send WNM-Notification Subscription Remediation Request" },
1271 	{ "hs20_deauth_req", hostapd_cli_cmd_hs20_deauth_req, NULL,
1272 	  "<addr> <code (0/1)> <Re-auth-Delay(sec)> [url]\n"
1273 	  "  = send WNM-Notification imminent deauthentication indication" },
1274 	{ "vendor", hostapd_cli_cmd_vendor, NULL,
1275 	  "<vendor id> <sub command id> [<hex formatted data>]\n"
1276 	  "  = send vendor driver command" },
1277 	{ "erp_flush", hostapd_cli_cmd_erp_flush, NULL,
1278 	  "= drop all ERP keys"},
1279 	{ "log_level", hostapd_cli_cmd_log_level, NULL,
1280 	  "[level] = show/change log verbosity level" },
1281 	{ "pmksa", hostapd_cli_cmd_pmksa, NULL,
1282 	  " = show PMKSA cache entries" },
1283 	{ "pmksa_flush", hostapd_cli_cmd_pmksa_flush, NULL,
1284 	  " = flush PMKSA cache" },
1285 	{ "set_neighbor", hostapd_cli_cmd_set_neighbor, NULL,
1286 	  "<addr> <ssid=> <nr=> [lci=] [civic=] [stat]\n"
1287 	  "  = add AP to neighbor database" },
1288 	{ "show_neighbor", hostapd_cli_cmd_show_neighbor, NULL,
1289 	  "  = show neighbor database entries" },
1290 	{ "remove_neighbor", hostapd_cli_cmd_remove_neighbor, NULL,
1291 	  "<addr> [ssid=<hex>] = remove AP from neighbor database" },
1292 	{ "req_lci", hostapd_cli_cmd_req_lci, hostapd_complete_stations,
1293 	  "<addr> = send LCI request to a station"},
1294 	{ "req_range", hostapd_cli_cmd_req_range, NULL,
1295 	  " = send FTM range request"},
1296 	{ "driver_flags", hostapd_cli_cmd_driver_flags, NULL,
1297 	  " = show supported driver flags"},
1298 #ifdef CONFIG_DPP
1299 	{ "dpp_qr_code", hostapd_cli_cmd_dpp_qr_code, NULL,
1300 	  "report a scanned DPP URI from a QR Code" },
1301 	{ "dpp_bootstrap_gen", hostapd_cli_cmd_dpp_bootstrap_gen, NULL,
1302 	  "type=<qrcode> [chan=..] [mac=..] [info=..] [curve=..] [key=..] = generate DPP bootstrap information" },
1303 	{ "dpp_bootstrap_remove", hostapd_cli_cmd_dpp_bootstrap_remove, NULL,
1304 	  "*|<id> = remove DPP bootstrap information" },
1305 	{ "dpp_bootstrap_get_uri", hostapd_cli_cmd_dpp_bootstrap_get_uri, NULL,
1306 	  "<id> = get DPP bootstrap URI" },
1307 	{ "dpp_bootstrap_info", hostapd_cli_cmd_dpp_bootstrap_info, NULL,
1308 	  "<id> = show DPP bootstrap information" },
1309 	{ "dpp_bootstrap_set", hostapd_cli_cmd_dpp_bootstrap_set, NULL,
1310 	  "<id> [conf=..] [ssid=<SSID>] [ssid_charset=#] [psk=<PSK>] [pass=<passphrase>] [configurator=<id>] [conn_status=#] [akm_use_selector=<0|1>] [group_id=..] [expiry=#] [csrattrs=..] = set DPP configurator parameters" },
1311 	{ "dpp_auth_init", hostapd_cli_cmd_dpp_auth_init, NULL,
1312 	  "peer=<id> [own=<id>] = initiate DPP bootstrapping" },
1313 	{ "dpp_listen", hostapd_cli_cmd_dpp_listen, NULL,
1314 	  "<freq in MHz> = start DPP listen" },
1315 	{ "dpp_stop_listen", hostapd_cli_cmd_dpp_stop_listen, NULL,
1316 	  "= stop DPP listen" },
1317 	{ "dpp_configurator_add", hostapd_cli_cmd_dpp_configurator_add, NULL,
1318 	  "[curve=..] [key=..] = add DPP configurator" },
1319 	{ "dpp_configurator_remove", hostapd_cli_cmd_dpp_configurator_remove,
1320 	  NULL,
1321 	  "*|<id> = remove DPP configurator" },
1322 	{ "dpp_configurator_get_key", hostapd_cli_cmd_dpp_configurator_get_key,
1323 	  NULL,
1324 	  "<id> = Get DPP configurator's private key" },
1325 	{ "dpp_configurator_sign", hostapd_cli_cmd_dpp_configurator_sign, NULL,
1326 	  "conf=<role> configurator=<id> = generate self DPP configuration" },
1327 	{ "dpp_pkex_add", hostapd_cli_cmd_dpp_pkex_add, NULL,
1328 	  "add PKEX code" },
1329 	{ "dpp_pkex_remove", hostapd_cli_cmd_dpp_pkex_remove, NULL,
1330 	  "*|<id> = remove DPP pkex information" },
1331 #ifdef CONFIG_DPP2
1332 	{ "dpp_controller_start", hostapd_cli_cmd_dpp_controller_start, NULL,
1333 	  "[tcp_port=<port>] [role=..] = start DPP controller" },
1334 	{ "dpp_controller_stop", hostapd_cli_cmd_dpp_controller_stop, NULL,
1335 	  "= stop DPP controller" },
1336 	{ "dpp_chirp", hostapd_cli_cmd_dpp_chirp, NULL,
1337 	  "own=<BI ID> iter=<count> = start DPP chirp" },
1338 	{ "dpp_stop_chirp", hostapd_cli_cmd_dpp_stop_chirp, NULL,
1339 	  "= stop DPP chirp" },
1340 #endif /* CONFIG_DPP2 */
1341 #endif /* CONFIG_DPP */
1342 	{ "accept_acl", hostapd_cli_cmd_accept_macacl, NULL,
1343 	  "=Add/Delete/Show/Clear accept MAC ACL" },
1344 	{ "deny_acl", hostapd_cli_cmd_deny_macacl, NULL,
1345 	  "=Add/Delete/Show/Clear deny MAC ACL" },
1346 	{ "poll_sta", hostapd_cli_cmd_poll_sta, hostapd_complete_stations,
1347 	  "<addr> = poll a STA to check connectivity with a QoS null frame" },
1348 	{ "req_beacon", hostapd_cli_cmd_req_beacon, NULL,
1349 	  "<addr> [req_mode=] <measurement request hexdump>  = send a Beacon report request to a station" },
1350 	{ "reload_wpa_psk", hostapd_cli_cmd_reload_wpa_psk, NULL,
1351 	  "= reload wpa_psk_file only" },
1352 	{ NULL, NULL, NULL, NULL }
1353 };
1354 
hostapd_request(struct wpa_ctrl * ctrl,int argc,char * argv[])1355 int hostapd_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
1356 {
1357 	const struct hostapd_cli_cmd *cmd, *match = NULL;
1358 	int count;
1359 	int ret = 0;
1360 
1361 	count = 0;
1362 	cmd = hostapd_cli_commands;
1363 	while (cmd->cmd) {
1364 		if (strncasecmp(cmd->cmd, argv[0], strlen(argv[0])) == 0) {
1365 			match = cmd;
1366 			if (os_strcasecmp(cmd->cmd, argv[0]) == 0) {
1367 				/* we have an exact match */
1368 				count = 1;
1369 				break;
1370 			}
1371 			count++;
1372 		}
1373 		cmd++;
1374 	}
1375 
1376 	if (count > 1) {
1377 		printf("Ambiguous command '%s'; possible commands:", argv[0]);
1378 		cmd = hostapd_cli_commands;
1379 		while (cmd->cmd) {
1380 			if (strncasecmp(cmd->cmd, argv[0], strlen(argv[0])) ==
1381 			    0) {
1382 				printf(" %s", cmd->cmd);
1383 			}
1384 			cmd++;
1385 		}
1386 		printf("\n");
1387 		ret = 1;
1388 	} else if (count == 0) {
1389 		printf("Unknown command '%s'\n", argv[0]);
1390 		ret = 1;
1391 	} else {
1392 		ret = match->handler(ctrl, argc - 1, &argv[1]);
1393 	}
1394 	return ret;
1395 }
1396 
1397