xref: /wlan-dirver/utils/sigma-dut/sigma_dut.h (revision 0a9876c1b05c4ed875e1276642ad1117145e7faa)
1 /*
2  * Sigma Control API DUT (station/AP)
3  * Copyright (c) 2010-2011, Atheros Communications, Inc.
4  * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
5  * Copyright (c) 2018-2019, The Linux Foundation
6  * All Rights Reserved.
7  * Licensed under the Clear BSD license. See README for more details.
8  */
9 
10 #ifndef SIGMA_DUT_H
11 #define SIGMA_DUT_H
12 
13 #ifdef __GNUC__
14 #define _GNU_SOURCE	1
15 #endif
16 
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <stdarg.h>
20 #include <string.h>
21 #include <errno.h>
22 #include <unistd.h>
23 #include <time.h>
24 #include <sys/time.h>
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <net/if.h>
28 #ifdef __QNXNTO__
29 #include <sys/select.h>
30 #include <net/if_ether.h>
31 #endif /* __QNXNTO__ */
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34 #ifdef CONFIG_TRAFFIC_AGENT
35 #include <pthread.h>
36 #endif /* CONFIG_TRAFFIC_AGENT */
37 #ifdef NL80211_SUPPORT
38 #include <netlink/genl/family.h>
39 #include <netlink/genl/ctrl.h>
40 #include <netlink/genl/genl.h>
41 #include "qca-vendor_copy.h"
42 #include "nl80211_copy.h"
43 #endif /* NL80211_SUPPORT */
44 #ifdef ANDROID_WIFI_HAL
45 #include "wifi_hal.h"
46 #endif /*ANDROID_WIFI_HAL*/
47 
48 
49 #ifdef __GNUC__
50 #define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, (a), (b))))
51 #else
52 #define PRINTF_FORMAT(a,b)
53 #endif
54 
55 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
56 
57 #ifndef SIGMA_TMPDIR
58 #define SIGMA_TMPDIR "/tmp"
59 #endif /* SIGMA_TMPDIR */
60 
61 #ifndef SIGMA_DUT_VER
62 #define SIGMA_DUT_VER "(unknown)"
63 #endif /* SIGMA_DUT_VER */
64 
65 #ifndef ETH_ALEN
66 #define ETH_ALEN 6
67 #endif
68 
69 #ifndef ETH_P_ARP
70 #define ETH_P_ARP 0x0806
71 #endif
72 
73 #ifndef ARRAY_SIZE
74 #define ARRAY_SIZE(x) (sizeof((x)) / (sizeof(((x)[0]))))
75 #endif
76 
77 #define IPV6_ADDR_LEN 16
78 
79 struct sigma_dut;
80 
81 #define MAX_PARAMS 100
82 #define MAX_RADIO 3
83 
84 #define NAN_AWARE_IFACE "wifi-aware0"
85 
86 /* Set default operating channel width 80 MHz */
87 #define VHT_DEFAULT_OPER_CHWIDTH AP_80_VHT_OPER_CHWIDTH
88 
89 typedef unsigned int u32;
90 typedef uint16_t u16;
91 typedef unsigned char u8;
92 
93 struct ieee80211_hdr_3addr {
94 	uint16_t frame_control;
95 	uint16_t duration_id;
96 	uint8_t addr1[ETH_ALEN];
97 	uint8_t addr2[ETH_ALEN];
98 	uint8_t addr3[ETH_ALEN];
99 	uint16_t seq_ctrl;
100 } __attribute__((packed));
101 
102 struct wfa_p2p_attribute {
103 	uint8_t id;
104 	uint16_t len;
105 	uint8_t variable[0];
106 } __attribute__((packed));
107 
108 #define WPA_GET_BE32(a) ((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \
109 			 (((u32) (a)[2]) << 8) | ((u32) (a)[3]))
110 #define WPA_PUT_BE32(a, val)					\
111 	do {							\
112 		(a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff);	\
113 		(a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff);	\
114 		(a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff);	\
115 		(a)[3] = (u8) (((u32) (val)) & 0xff);		\
116 	} while (0)
117 
118 struct sigma_cmd {
119 	char *params[MAX_PARAMS];
120 	char *values[MAX_PARAMS];
121 	int count;
122 };
123 
124 #define MAX_CMD_LEN 4096
125 
126 struct sigma_conn {
127 	int s;
128 	struct sockaddr_in addr;
129 	socklen_t addrlen;
130 	char buf[MAX_CMD_LEN + 5];
131 	int pos;
132 	int waiting_completion;
133 };
134 
135 enum sigma_cmd_result {
136 	STATUS_SENT_ERROR = -3,
137 	ERROR_SEND_STATUS = -2,
138 	INVALID_SEND_STATUS = -1,
139 	STATUS_SENT = 0,
140 	SUCCESS_SEND_STATUS = 1
141 };
142 
143 struct sigma_cmd_handler {
144 	struct sigma_cmd_handler *next;
145 	char *cmd;
146 	int (*validate)(struct sigma_cmd *cmd);
147 	/* process return value:
148 	 * -2 = failed, caller will send status,ERROR
149 	 * -1 = failed, caller will send status,INVALID
150 	 * 0 = response already sent
151 	 * 1 = success, caller will send status,COMPLETE
152 	 */
153 	enum sigma_cmd_result (*process)(struct sigma_dut *dut,
154 					 struct sigma_conn *conn,
155 					 struct sigma_cmd *cmd);
156 };
157 
158 #define P2P_GRP_ID_LEN 128
159 #define IP_ADDR_STR_LEN 16
160 
161 struct wfa_cs_p2p_group {
162 	struct wfa_cs_p2p_group *next;
163 	char ifname[IFNAMSIZ];
164 	int go;
165 	char grpid[P2P_GRP_ID_LEN];
166 	char ssid[33];
167 };
168 
169 #ifdef CONFIG_TRAFFIC_AGENT
170 
171 #define MAX_SIGMA_STREAMS 16
172 #define MAX_SIGMA_STATS 6000
173 
174 struct sigma_frame_stats {
175 	unsigned int seqnum;
176 	unsigned int local_sec;
177 	unsigned int local_usec;
178 	unsigned int remote_sec;
179 	unsigned int remote_usec;
180 };
181 
182 struct sigma_stream {
183 	enum sigma_stream_profile {
184 		SIGMA_PROFILE_FILE_TRANSFER,
185 		SIGMA_PROFILE_MULTICAST,
186 		SIGMA_PROFILE_IPTV,
187 		SIGMA_PROFILE_TRANSACTION,
188 		SIGMA_PROFILE_START_SYNC,
189 		SIGMA_PROFILE_UAPSD
190 	} profile;
191 	int sender;
192 	struct in_addr dst;
193 	int dst_port;
194 	struct in_addr src;
195 	int src_port;
196 	int frame_rate;
197 	int duration;
198 	unsigned int payload_size;
199 	int start_delay;
200 	int max_cnt;
201 	enum sigma_traffic_class {
202 		SIGMA_TC_VOICE,
203 		SIGMA_TC_VIDEO,
204 		SIGMA_TC_BACKGROUND,
205 		SIGMA_TC_BEST_EFFORT
206 	} tc;
207 	int user_priority;
208 	int user_priority_set;
209 	int started;
210 	int no_timestamps;
211 
212 	int sock;
213 	pthread_t thr;
214 	int stop;
215 	int ta_send_in_progress;
216 	int trans_proto;
217 
218 	/* Statistics */
219 	int tx_act_frames; /*
220 			    * Number of frames generated by the traffic
221 			    * generator application. The name is defined in the
222 			    * Sigma CAPI spec.
223 			    */
224 	int tx_frames;
225 	int rx_frames;
226 	unsigned long long tx_payload_bytes;
227 	unsigned long long rx_payload_bytes;
228 	int out_of_seq_frames;
229 	struct sigma_frame_stats *stats;
230 	unsigned int num_stats;
231 	unsigned int stream_id;
232 
233 	/* U-APSD */
234 	unsigned int sta_id;
235 	unsigned int rx_cookie;
236 	unsigned int uapsd_sta_tc;
237 	unsigned int uapsd_rx_state;
238 	unsigned int uapsd_tx_state;
239 	unsigned int tx_stop_cnt;
240 	unsigned int tx_hello_cnt;
241 	pthread_t uapsd_send_thr;
242 	pthread_cond_t tx_thr_cond;
243 	pthread_mutex_t tx_thr_mutex;
244 	int reset_rx;
245 	int num_retry;
246 	char ifname[IFNAMSIZ]; /* ifname from the command */
247 	struct sigma_dut *dut; /* for traffic agent thread to access context */
248 	/* console */
249 	char test_name[9]; /* test case name */
250 	int can_quit;
251 	int reset;
252 };
253 
254 #endif /* CONFIG_TRAFFIC_AGENT */
255 
256 /* extended scheduling test */
257 enum sigma_ese_type {
258 	ESE_CBAP,
259 	ESE_SP,
260 };
261 
262 struct sigma_ese_alloc {
263 	unsigned int percent_bi;
264 	enum sigma_ese_type type;
265 	unsigned int src_aid, dst_aid;
266 };
267 
268 #define ESE_BCAST_AID	255
269 #define MAX_ESE_ALLOCS	4
270 
271 #define NUM_AP_AC 4
272 #define AP_AC_BE 0
273 #define AP_AC_BK 1
274 #define AP_AC_VI 2
275 #define AP_AC_VO 3
276 
277 #define MAX_WLAN_TAGS 3
278 #define MBO_MAX_PREF_BSSIDS 10
279 #define MAX_FT_BSS_LIST 10
280 
281 #define TRANSPORT_PROTO_TYPE_TCP 0x06
282 #define TRANSPORT_PROTO_TYPE_UDP 0x11
283 #define NAN_TRANSPORT_PORT_DEFAULT 7000
284 #define NAN_TRANSPORT_PROTOCOL_DEFAULT TRANSPORT_PROTO_TYPE_TCP
285 
286 enum value_not_set_enabled_disabled {
287 	VALUE_NOT_SET,
288 	VALUE_ENABLED,
289 	VALUE_DISABLED
290 };
291 
292 enum sec_ch_offset {
293 	SEC_CH_NO,
294 	SEC_CH_40ABOVE,
295 	SEC_CH_40BELOW
296 };
297 
298 struct mbo_pref_ap {
299 	int ap_ne_class;
300 	int ap_ne_op_ch;
301 	int ap_ne_pref;
302 	unsigned char mac_addr[ETH_ALEN];
303 };
304 
305 #ifdef NL80211_SUPPORT
306 #define SOCK_BUF_SIZE (32 * 1024)
307 struct nl80211_ctx {
308 	struct nl_sock *sock;
309 	int netlink_familyid;
310 	int nlctrl_familyid;
311 	size_t sock_buf_size;
312 };
313 #endif /* NL80211_SUPPORT */
314 
315 /* hardcoded long WSC IE values to force fragmentation */
316 #define WPS_LONG_DEVICE_NAME	"Qti1234511adtest1234567890123456"
317 #define WPS_LONG_MANUFACTURER	"Qti1234511adQti1234511adQti1234511adQti1234511adQti1234511ad"
318 #define WPS_LONG_MODEL_NAME	"Qti1234511adtest1234567890123456"
319 #define WPS_LONG_MODEL_NUMBER	"11111111111111111111111111111111"
320 #define WPS_LONG_SERIAL_NUMBER	"22222222222222222222222222222222"
321 
322 enum akm_suite_values {
323 	AKM_WPA_EAP = 1,
324 	AKM_WPA_PSK = 2,
325 	AKM_FT_EAP = 3,
326 	AKM_FT_PSK = 4,
327 	AKM_EAP_SHA256 = 5,
328 	AKM_PSK_SHA256 = 6,
329 	AKM_SAE = 8,
330 	AKM_FT_SAE = 9,
331 	AKM_SUITE_B = 12,
332 	AKM_FT_SUITE_B = 13,
333 	AKM_FILS_SHA256 = 14,
334 	AKM_FILS_SHA384 = 15,
335 	AKM_FT_FILS_SHA256 = 16,
336 	AKM_FT_FILS_SHA384 = 17,
337 
338 };
339 
340 struct sigma_dut {
341 	const char *main_ifname;
342 	char *main_ifname_2g;
343 	char *main_ifname_5g;
344 	const char *station_ifname;
345 	char *station_ifname_2g;
346 	char *station_ifname_5g;
347 	char *p2p_ifname_buf;
348 	int use_5g;
349 	int sta_2g_started;
350 	int sta_5g_started;
351 
352 	int s; /* server TCP socket */
353 	int debug_level;
354 	int stdout_debug;
355 	struct sigma_cmd_handler *cmds;
356 	int response_sent;
357 
358 	const char *sigma_tmpdir;
359 
360 	/* Default timeout value (seconds) for commands */
361 	unsigned int default_timeout;
362 
363 	int next_streamid;
364 
365 	const char *bridge; /* bridge interface to use in AP mode */
366 
367 	enum sigma_mode {
368 		SIGMA_MODE_UNKNOWN,
369 		SIGMA_MODE_STATION,
370 		SIGMA_MODE_AP,
371 		SIGMA_MODE_SNIFFER
372 	} mode;
373 
374 	/*
375 	 * Local cached values to handle API that does not provide all the
376 	 * needed information with commands that actually trigger some
377 	 * operations.
378 	 */
379 	int listen_chn;
380 	int persistent;
381 	int intra_bss;
382 	int noa_duration;
383 	int noa_interval;
384 	int noa_count;
385 	enum wfa_cs_wps_method {
386 		WFA_CS_WPS_NOT_READY,
387 		WFA_CS_WPS_PBC,
388 		WFA_CS_WPS_PIN_DISPLAY,
389 		WFA_CS_WPS_PIN_LABEL,
390 		WFA_CS_WPS_PIN_KEYPAD
391 	} wps_method;
392 	char wps_pin[9];
393 
394 	struct wfa_cs_p2p_group *groups;
395 
396 	char infra_ssid[33];
397 	int infra_network_id;
398 
399 	enum p2p_mode {
400 		P2P_IDLE, P2P_DISCOVER, P2P_LISTEN, P2P_DISABLE
401 	} p2p_mode;
402 
403 	int go;
404 	int p2p_client;
405 	const char *p2p_ifname;
406 
407 	int client_uapsd;
408 
409 	char arp_ipaddr[IP_ADDR_STR_LEN];
410 	char arp_ifname[IFNAMSIZ + 1];
411 
412 	enum sta_pmf {
413 		STA_PMF_DISABLED,
414 		STA_PMF_OPTIONAL,
415 		STA_PMF_REQUIRED
416 	} sta_pmf;
417 
418 	int sta_ft_ds;
419 
420 	int no_tpk_expiration;
421 
422 	int er_oper_performed;
423 	char er_oper_bssid[20];
424 	int amsdu_size;
425 	int back_rcv_buf;
426 
427 	int testbed_flag_txsp;
428 	int testbed_flag_rxsp;
429 	int chwidth;
430 
431 	unsigned int akm_values;
432 
433 	/* AP configuration */
434 	char ap_ssid[33];
435 	/*
436 	 * WLAN-TAG of 1 will use 'ap_' variables;
437 	 * tag higher than 1 will use 'ap_tag_' variables.
438 	 */
439 	char ap_tag_ssid[MAX_WLAN_TAGS - 1][33];
440 	enum ap_mode {
441 		AP_11a,
442 		AP_11g,
443 		AP_11b,
444 		AP_11na,
445 		AP_11ng,
446 		AP_11ac,
447 		AP_11ad,
448 		AP_11ax,
449 		AP_inval
450 	} ap_mode;
451 	int ap_channel;
452 	int ap_rts;
453 	int ap_frgmnt;
454 	int ap_bcnint;
455 	int ap_start_disabled;
456 	struct qos_params {
457 		int ac;
458 		int cwmin;
459 		int cwmax;
460 		int aifs;
461 		int txop;
462 		int acm;
463 	} ap_qos[NUM_AP_AC], ap_sta_qos[NUM_AP_AC];
464 	enum value_not_set_enabled_disabled ap_noack;
465 	enum value_not_set_enabled_disabled ap_ampdu;
466 	enum value_not_set_enabled_disabled ap_amsdu;
467 	enum value_not_set_enabled_disabled ap_rx_amsdu;
468 	int ap_ampdu_exp;
469 	enum value_not_set_enabled_disabled ap_addba_reject;
470 	int ap_fixed_rate;
471 	int ap_mcs;
472 	int ap_rx_streams;
473 	int ap_tx_streams;
474 	unsigned int ap_vhtmcs_map;
475 	enum value_not_set_enabled_disabled ap_ldpc;
476 	enum value_not_set_enabled_disabled ap_sig_rts;
477 	enum ap_chwidth {
478 		AP_20,
479 		AP_40,
480 		AP_80,
481 		AP_160,
482 		AP_80_80,
483 		AP_AUTO
484 	} ap_chwidth;
485 	enum ap_chwidth default_11na_ap_chwidth;
486 	enum ap_chwidth default_11ng_ap_chwidth;
487 	int ap_tx_stbc;
488 	enum value_not_set_enabled_disabled ap_dyn_bw_sig;
489 	int ap_sgi80;
490 	int ap_p2p_mgmt;
491 	enum ap_key_mgmt {
492 		AP_OPEN,
493 		AP_WPA2_PSK,
494 		AP_WPA_PSK,
495 		AP_WPA2_EAP,
496 		AP_WPA_EAP,
497 		AP_WPA2_EAP_MIXED,
498 		AP_WPA2_PSK_MIXED,
499 		AP_WPA2_SAE,
500 		AP_WPA2_PSK_SAE,
501 		AP_SUITEB,
502 		AP_WPA2_OWE,
503 		AP_WPA2_EAP_OSEN,
504 		AP_WPA2_FT_EAP,
505 		AP_WPA2_FT_PSK,
506 		AP_WPA2_EAP_SHA256,
507 		AP_WPA2_PSK_SHA256,
508 		AP_WPA2_ENT_FT_EAP,
509 		AP_OSEN,
510 	} ap_key_mgmt;
511 	enum ap_tag_key_mgmt {
512 		AP2_OPEN,
513 		AP2_OSEN,
514 		AP2_WPA2_PSK,
515 		AP2_WPA2_OWE,
516 	} ap_tag_key_mgmt[MAX_WLAN_TAGS - 1];
517 	int ap_add_sha256;
518 	int ap_add_sha384;
519 	int ap_rsn_preauth;
520 	enum ap_pmf {
521 		AP_PMF_DISABLED,
522 		AP_PMF_OPTIONAL,
523 		AP_PMF_REQUIRED
524 	} ap_pmf;
525 	enum ap_cipher {
526 		AP_NO_GROUP_CIPHER_SET,
527 		AP_CCMP,
528 		AP_TKIP,
529 		AP_WEP,
530 		AP_PLAIN,
531 		AP_CCMP_TKIP,
532 		AP_GCMP_256,
533 		AP_GCMP_128,
534 		AP_CCMP_256,
535 		AP_CCMP_128_GCMP_256,
536 	} ap_cipher, ap_group_cipher;
537 	enum ap_group_mgmt_cipher {
538 		AP_NO_GROUP_MGMT_CIPHER_SET,
539 		AP_BIP_GMAC_256,
540 		AP_BIP_CMAC_256,
541 		AP_BIP_GMAC_128,
542 		AP_BIP_CMAC_128,
543 	} ap_group_mgmt_cipher;
544 	char *ap_sae_groups;
545 	int sae_anti_clogging_threshold;
546 	int sae_reflection;
547 	int ap_sae_commit_status;
548 	int ap_sae_pk_omit;
549 	int sae_confirm_immediate;
550 	char ap_passphrase[101];
551 	char ap_psk[65];
552 	char *ap_sae_passwords;
553 	char *ap_sae_pk_modifier;
554 	char *ap_sae_pk_keypair;
555 	int ap_sae_pk;
556 	char ap_wepkey[27];
557 	char ap_radius_ipaddr[20];
558 	int ap_radius_port;
559 	char ap_radius_password[200];
560 	char ap2_radius_ipaddr[20];
561 	int ap2_radius_port;
562 	char ap2_radius_password[200];
563 	int ap_tdls_prohibit;
564 	int ap_tdls_prohibit_chswitch;
565 	int ap_hs2;
566 	int ap_dgaf_disable;
567 	int ap_p2p_cross_connect;
568 	int ap_oper_name;
569 	int ap_wan_metrics;
570 	int ap_conn_capab;
571 	int ap_oper_class;
572 
573 	int ap_interworking;
574 	int ap_access_net_type;
575 	int ap_internet;
576 	int ap_venue_group;
577 	int ap_venue_type;
578 	char ap_hessid[20];
579 	char ap_roaming_cons[100];
580 	int ap_venue_name;
581 	int ap_net_auth_type;
582 	int ap_nai_realm_list;
583 	char ap_domain_name_list[1000];
584 	int ap_ip_addr_type_avail;
585 	char ap_plmn_mcc[10][4];
586 	char ap_plmn_mnc[10][4];
587 	int ap_gas_cb_delay;
588 	int ap_proxy_arp;
589 	int ap2_proxy_arp;
590 	int ap2_osu;
591 	int ap_l2tif;
592 	int ap_anqpserver;
593 	int ap_anqpserver_on;
594 	int ap_osu_provider_list;
595 	int ap_osu_provider_nai_list;
596 	int ap_qos_map_set;
597 	int ap_bss_load;
598 	char ap_osu_server_uri[10][256];
599 	char ap_osu_ssid[33];
600 	int ap_osu_method[10];
601 	int ap_osu_icon_tag;
602 	int ap_venue_url;
603 	int ap_advice_of_charge;
604 	int ap_oper_icon_metadata;
605 	int ap_tnc_file_name;
606 	unsigned int ap_tnc_time_stamp;
607 
608 	int ap_fake_pkhash;
609 	int ap_disable_protection;
610 	int ap_allow_vht_wep;
611 	int ap_allow_vht_tkip;
612 
613 	enum ap_vht_chwidth {
614 		AP_20_40_VHT_OPER_CHWIDTH,
615 		AP_80_VHT_OPER_CHWIDTH,
616 		AP_160_VHT_OPER_CHWIDTH
617 	} ap_vht_chwidth;
618 	int ap_txBF;
619 	int ap_mu_txBF;
620 	enum ap_regulatory_mode {
621 		AP_80211D_MODE_DISABLED,
622 		AP_80211D_MODE_ENABLED,
623 	} ap_regulatory_mode;
624 	enum ap_dfs_mode {
625 		AP_DFS_MODE_DISABLED,
626 		AP_DFS_MODE_ENABLED,
627 	} ap_dfs_mode;
628 	int ap_ndpa_frame;
629 
630 	int ap_lci;
631 	char ap_val_lci[33];
632 	char ap_infoz[17];
633 	int ap_lcr;
634 	char ap_val_lcr[400];
635 	int ap_rrm;
636 	int ap_rtt;
637 	int ap_neighap; /* number of configured neighbor APs */
638 	unsigned char ap_val_neighap[3][6];
639 	int ap_opchannel; /* number of oper channels */
640 	int ap_val_opchannel[3];
641 	int ap_scan;
642 	int ap_fqdn_held;
643 	int ap_fqdn_supl;
644 	int ap_msnt_type;
645 
646 	int ap_mbo;
647 	int ap_ne_class;
648 	int ap_ne_op_ch;
649 	int ap_set_bssidpref;
650 	int ap_btmreq_disassoc_imnt;
651 	int ap_btmreq_term_bit;
652 	int ap_disassoc_timer;
653 	int ap_btmreq_bss_term_dur;
654 	enum reg_domain {
655 		REG_DOMAIN_NOT_SET,
656 		REG_DOMAIN_LOCAL,
657 		REG_DOMAIN_GLOBAL
658 	} ap_reg_domain;
659 	char ap_mobility_domain[10];
660 	unsigned char ap_cell_cap_pref;
661 	int ap_ft_oa;
662 	enum value_not_set_enabled_disabled ap_ft_ds;
663 	int ap_name;
664 	int ap_interface_5g;
665 	int ap_interface_2g;
666 	int ap_assoc_delay;
667 	int ap_btmreq_bss_term_tsf;
668 	int ap_fils_dscv_int;
669 	int ap_nairealm_int;
670 	char ap_nairealm[33];
671 	int ap_blechanutil;
672 	int ap_ble_admit_cap;
673 	int ap_datappdudura;
674 	int ap_airtimefract;
675 	char ap_dhcpserv_ipaddr[20];
676 	int ap_dhcp_stop;
677 	int ap_bawinsize;
678 	int ap_blestacnt;
679 	int ap_ul_availcap;
680 	int ap_dl_availcap;
681 	int ap_akm;
682 	unsigned int ap_akm_values;
683 	int ap_pmksa;
684 	int ap_pmksa_caching;
685 	int ap_beacon_prot;
686 	u8 ap_transition_disable;
687 	int ap_80plus80;
688 	int ap_oper_chn;
689 
690 	struct mbo_pref_ap mbo_pref_aps[MBO_MAX_PREF_BSSIDS];
691 	struct mbo_pref_ap mbo_self_ap_tuple;
692 	int mbo_pref_ap_cnt;
693 	unsigned char ft_bss_mac_list[MAX_FT_BSS_LIST][ETH_ALEN];
694 	int ft_bss_mac_cnt;
695 
696 	char *ar_ltf;
697 
698 	int ap_numsounddim;
699 	unsigned int he_mcsnssmap;
700 	int he_ul_mcs;
701 	int he_mmss;
702 	int he_srctrl_allow;
703 
704 	int ap_ocvc;
705 
706 	enum value_not_set_enabled_disabled ap_oce;
707 	enum value_not_set_enabled_disabled ap_filsdscv;
708 	enum value_not_set_enabled_disabled ap_filshlp;
709 	enum value_not_set_enabled_disabled ap_broadcast_ssid;
710 	enum value_not_set_enabled_disabled ap_rnr;
711 	enum value_not_set_enabled_disabled ap_esp;
712 
713 	enum value_not_set_enabled_disabled ap_he_ulofdma;
714 	enum value_not_set_enabled_disabled ap_he_dlofdma;
715 	enum value_not_set_enabled_disabled ap_bcc;
716 	enum value_not_set_enabled_disabled ap_he_frag;
717 	enum value_not_set_enabled_disabled ap_mu_edca;
718 	enum value_not_set_enabled_disabled ap_he_rtsthrshld;
719 	enum value_not_set_enabled_disabled ap_mbssid;
720 	enum value_not_set_enabled_disabled ap_twtresp;
721 	enum value_not_set_enabled_disabled he_sounding;
722 	enum value_not_set_enabled_disabled he_set_sta_1x1;
723 
724 	enum ppdu {
725 		PPDU_NOT_SET,
726 		PPDU_MU,
727 		PPDU_SU,
728 		PPDU_ER,
729 		PPDU_TB,
730 		PPDU_HESU,
731 	} ap_he_ppdu;
732 
733 	enum bufsize {
734 		BA_BUFSIZE_NOT_SET,
735 		BA_BUFSIZE_64,
736 		BA_BUFSIZE_256,
737 	} ap_ba_bufsize;
738 
739 	enum mimo {
740 		MIMO_NOT_SET,
741 		MIMO_DL,
742 		MIMO_UL,
743 	} ap_he_mimo;
744 
745 	struct sigma_ese_alloc ap_ese_allocs[MAX_ESE_ALLOCS];
746 	int ap_num_ese_allocs;
747 
748 	const char *hostapd_debug_log;
749 	const char *wpa_supplicant_debug_log;
750 
751 #ifdef CONFIG_TRAFFIC_AGENT
752 	/* Traffic Agent */
753 	struct sigma_stream streams[MAX_SIGMA_STREAMS];
754 	int stream_id;
755 	int num_streams;
756 	pthread_t thr;
757 #endif /* CONFIG_TRAFFIC_AGENT */
758 
759 	unsigned int throughput_pktsize; /* If non-zero, override pktsize for
760 					  * throughput tests */
761 	int no_timestamps;
762 
763 	const char *sniffer_ifname;
764 	const char *set_macaddr;
765 	int tmp_mac_addr;
766 	int ap_is_dual;
767 	enum ap_mode ap_mode_1;
768 	enum ap_chwidth ap_chwidth_1;
769 	int ap_channel_1;
770 	char ap_countrycode[3];
771 
772 	int ap_wpsnfc;
773 
774 	enum ap_wme {
775 		AP_WME_OFF,
776 		AP_WME_ON,
777 	} ap_wme;
778 
779 	enum ap_wmmps {
780 		AP_WMMPS_OFF,
781 		AP_WMMPS_ON,
782 	} ap_wmmps;
783 
784 	enum sec_ch_offset ap_chwidth_offset;
785 
786 	char *ap_dpp_conf_addr;
787 	char *ap_dpp_conf_pkhash;
788 
789 #ifdef CONFIG_SNIFFER
790 	pid_t sniffer_pid;
791 	char sniffer_filename[200];
792 #endif /* CONFIG_SNIFFER */
793 
794 	int last_set_ip_config_ipv6;
795 #ifdef MIRACAST
796 	pthread_t rtsp_thread_handle;
797 	int wfd_device_type; /* 0 for source, 1 for sink */
798 	char peer_mac_address[32];
799 	char modified_peer_mac_address[32];
800 	void *miracast_lib;
801 	const char *miracast_lib_path;
802 	char mdns_instance_name[64];
803 #endif /* MIRACAST */
804 
805 	int tid_to_handle[8]; /* Mapping of TID to handle */
806 	int dialog_token; /* Used for generating unique handle for an addTs */
807 
808 	enum sigma_program {
809 		PROGRAM_UNKNOWN = 0,
810 		PROGRAM_TDLS,
811 		PROGRAM_HS2,
812 		PROGRAM_HS2_R2,
813 		PROGRAM_WFD,
814 		PROGRAM_DISPLAYR2,
815 		PROGRAM_PMF,
816 		PROGRAM_WPS,
817 		PROGRAM_60GHZ,
818 		PROGRAM_HT,
819 		PROGRAM_VHT,
820 		PROGRAM_NAN,
821 		PROGRAM_LOC,
822 		PROGRAM_MBO,
823 		PROGRAM_IOTLP,
824 		PROGRAM_DPP,
825 		PROGRAM_OCE,
826 		PROGRAM_WPA3,
827 		PROGRAM_HE,
828 		PROGRAM_HS2_R3,
829 		PROGRAM_QM,
830 	} program;
831 
832 	enum device_type {
833 		device_type_unknown,
834 		AP_unknown,
835 		AP_testbed,
836 		AP_dut,
837 		STA_unknown,
838 		STA_testbed,
839 		STA_dut
840 	} device_type;
841 
842 	enum {
843 		DEVROLE_UNKNOWN = 0,
844 		DEVROLE_STA,
845 		DEVROLE_PCP,
846 		DEVROLE_STA_CFON,
847 		DEVROLE_AP,
848 	} dev_role;
849 
850 	enum wps_band {
851 		WPS_BAND_NON_60G = 0,
852 		WPS_BAND_60G,
853 	} band;
854 
855 	int wps_disable; /* Used for 60G to disable PCP from sending WPS IE */
856 	int wsc_fragment; /* simulate WSC IE fragmentation */
857 	int eap_fragment; /* simulate EAP fragmentation */
858 	int wps_forced_version; /* Used to force reported WPS version */
859 	enum {
860 		/* no change */
861 		FORCE_RSN_IE_NONE = 0,
862 		/* if exists, remove and clear privacy bit */
863 		FORCE_RSN_IE_REMOVE,
864 		/* if not exists, add and set privacy bit */
865 		FORCE_RSN_IE_ADD,
866 	} force_rsn_ie; /* override RSN IE in association request */
867 
868 	const char *version;
869 	int no_ip_addr_set;
870 	int sta_channel;
871 
872 	const char *summary_log;
873 	const char *hostapd_entropy_log;
874 
875 	int iface_down_on_reset;
876 	int write_stats; /* traffic stream e2e*.txt files */
877 	int sim_no_username; /* do not set SIM username to use real SIM */
878 
879 	const char *vendor_name; /* device_get_info vendor override */
880 	const char *model_name; /* device_get_info model override */
881 	const char *version_name; /* device_get_info version override */
882 	const char *log_file_dir; /* Directory to generate log file */
883 	FILE *log_file_fd; /* Pointer to log file */
884 
885 	int ndp_enable; /* Flag which is set once the NDP is setup */
886 
887 	int ndpe; /* Flag indicating NDPE is supported */
888 	u16 trans_port; /* transport port number for TCP/UDP connection */
889 	u8 trans_proto; /* transport protocol, 0x06: TCP, 0x11: UDP */
890 	u8 nan_ipv6_addr[IPV6_ADDR_LEN]; /* NAN IPv6 address */
891 	u8 nan_ipv6_len; /* NAN IPv6 address length */
892 
893 	/* Length of nan_pmk in octets */
894 	u8 nan_pmk_len;
895 
896 	/*
897 	 * PMK: Info is optional in Discovery phase. PMK info can
898 	 *  be passed during the NDP session.
899 	 */
900 	u8 nan_pmk[32];
901 
902 	enum value_not_set_enabled_disabled wnm_bss_max_feature;
903 	int wnm_bss_max_idle_time;
904 	enum value_not_set_enabled_disabled wnm_bss_max_protection;
905 
906 	char *non_pref_ch_list; /* MBO: non-preferred channel report */
907 	char *btm_query_cand_list; /* Candidate list for BTM Query */
908 
909 	char *sae_commit_override;
910 	char *rsne_override;
911 	char *rsnxe_override_eapol;
912 	int sta_associate_wait_connect;
913 	char server_cert_hash[65];
914 	int server_cert_tod;
915 	int sta_tod_policy;
916 	const char *hostapd_bin;
917 	int use_hostapd_pid_file;
918 	const char *hostapd_ifname;
919 	int hostapd_running;
920 
921 	char *dpp_peer_uri;
922 	int dpp_local_bootstrap;
923 	int dpp_conf_id;
924 
925 	u8 fils_hlp;
926 	pthread_t hlp_thread;
927 
928 #ifdef NL80211_SUPPORT
929 	struct nl80211_ctx *nl_ctx;
930 	int config_rsnie;
931 #endif /* NL80211_SUPPORT */
932 
933 	int sta_nss;
934 
935 #ifdef ANDROID
936 	int nanservicediscoveryinprogress;
937 #endif /* ANDROID */
938 
939 	const char *priv_cmd; /* iwpriv / cfg80211tool command name */
940 
941 	unsigned int wpa_log_size;
942 	char dev_start_test_runtime_id[100];
943 #ifdef ANDROID_WIFI_HAL
944 	wifi_interface_handle wifi_hal_iface_handle;
945 	wifi_handle wifi_hal_handle;
946 	bool wifi_hal_initialized;
947 #endif /*ANDROID_WIFI_HAL*/
948 
949 	int sae_h2e_default;
950 	enum {
951 		SAE_PWE_DEFAULT,
952 		SAE_PWE_LOOP,
953 		SAE_PWE_H2E
954 	} sae_pwe;
955 	int owe_ptk_workaround;
956 	int ocvc;
957 };
958 
959 
960 enum sigma_dut_print_level {
961 	DUT_MSG_DEBUG, DUT_MSG_INFO, DUT_MSG_ERROR
962 };
963 
964 void sigma_dut_print(struct sigma_dut *dut, int level, const char *fmt, ...)
965 PRINTF_FORMAT(3, 4);
966 
967 void sigma_dut_summary(struct sigma_dut *dut, const char *fmt, ...)
968 PRINTF_FORMAT(2, 3);
969 
970 
971 enum sigma_status {
972 	SIGMA_RUNNING, SIGMA_INVALID, SIGMA_ERROR, SIGMA_COMPLETE
973 };
974 
975 void send_resp(struct sigma_dut *dut, struct sigma_conn *conn,
976 	       enum sigma_status status, const char *buf);
977 
978 const char * get_param(struct sigma_cmd *cmd, const char *name);
979 const char * get_param_indexed(struct sigma_cmd *cmd, const char *name,
980 			       int index);
981 
982 int sigma_dut_reg_cmd(const char *cmd,
983 		      int (*validate)(struct sigma_cmd *cmd),
984 		      enum sigma_cmd_result (*process)(struct sigma_dut *dut,
985 						       struct sigma_conn *conn,
986 						       struct sigma_cmd *cmd));
987 
988 void sigma_dut_register_cmds(void);
989 
990 enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
991 					 struct sigma_conn *conn,
992 					 struct sigma_cmd *cmd);
993 int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
994 			  struct sigma_cmd *cmd);
995 enum sigma_cmd_result cmd_ap_send_frame(struct sigma_dut *dut,
996 					struct sigma_conn *conn,
997 					struct sigma_cmd *cmd);
998 enum sigma_cmd_result cmd_wlantest_send_frame(struct sigma_dut *dut,
999 					      struct sigma_conn *conn,
1000 					      struct sigma_cmd *cmd);
1001 int sta_cfon_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
1002 			  struct sigma_cmd *cmd);
1003 int sta_cfon_get_mac_address(struct sigma_dut *dut, struct sigma_conn *conn,
1004 			     struct sigma_cmd *cmd);
1005 int sta_cfon_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1006 			   struct sigma_cmd *cmd);
1007 
1008 enum driver_type {
1009 	DRIVER_NOT_SET,
1010 	DRIVER_ATHEROS,
1011 	DRIVER_WCN,
1012 	DRIVER_MAC80211,
1013 	DRIVER_AR6003,
1014 	DRIVER_WIL6210,
1015 	DRIVER_QNXNTO,
1016 	DRIVER_OPENWRT,
1017 	DRIVER_LINUX_WCN,
1018 };
1019 
1020 enum openwrt_driver_type {
1021 	OPENWRT_DRIVER_NOT_SET,
1022 	OPENWRT_DRIVER_ATHEROS
1023 };
1024 
1025 #define DRIVER_NAME_60G "wil6210"
1026 
1027 int set_wifi_chip(const char *chip_type);
1028 enum driver_type get_driver_type(struct sigma_dut *dut);
1029 enum openwrt_driver_type get_openwrt_driver_type(void);
1030 int file_exists(const char *fname);
1031 
1032 struct wpa_ctrl;
1033 
1034 int wps_connection_event(struct sigma_dut *dut, struct sigma_conn *conn,
1035 			 struct wpa_ctrl *ctrl, const char *intf, int p2p_resp);
1036 int ascii2hexstr(const char *str, char *hex);
1037 void disconnect_station(struct sigma_dut *dut);
1038 void nfc_status(struct sigma_dut *dut, const char *state, const char *oper);
1039 int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
1040 		  size_t buf_len);
1041 int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd);
1042 int is_ip_addr(const char *str);
1043 int run_system(struct sigma_dut *dut, const char *cmd);
1044 int run_system_wrapper(struct sigma_dut *dut, const char *cmd, ...);
1045 int run_iwpriv(struct sigma_dut *dut, const char *ifname, const char *cmd, ...);
1046 enum sigma_cmd_result cmd_wlantest_set_channel(struct sigma_dut *dut,
1047 					       struct sigma_conn *conn,
1048 					       struct sigma_cmd *cmd);
1049 void wlantest_register_cmds(void);
1050 void sniffer_close(struct sigma_dut *dut);
1051 
1052 /* sigma_dut.c */
1053 int wifi_hal_initialize(struct sigma_dut *dut);
1054 
1055 /* ap.c */
1056 void ap_register_cmds(void);
1057 void ath_disable_txbf(struct sigma_dut *dut, const char *intf);
1058 void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
1059 			   const char *val);
1060 void novap_reset(struct sigma_dut *dut, const char *ifname, int reset);
1061 int get_hwaddr(const char *ifname, unsigned char *hwaddr);
1062 enum sigma_cmd_result cmd_ap_config_commit(struct sigma_dut *dut,
1063 					   struct sigma_conn *conn,
1064 					   struct sigma_cmd *cmd);
1065 int ap_wps_registration(struct sigma_dut *dut, struct sigma_conn *conn,
1066 			struct sigma_cmd *cmd);
1067 const char * get_hostapd_ifname(struct sigma_dut *dut);
1068 
1069 /* sta.c */
1070 void sta_register_cmds(void);
1071 int set_ps(const char *intf, struct sigma_dut *dut, int enabled);
1072 void ath_set_zero_crc(struct sigma_dut *dut, const char *val);
1073 void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
1074 		       const char *val);
1075 int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
1076 		  const char *intf, const char *val);
1077 int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
1078 			 int abft_len);
1079 int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
1080 			   struct sigma_cmd *cmd);
1081 int hwaddr_aton(const char *txt, unsigned char *addr);
1082 int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1083 		  const char *ip, const char *mask);
1084 int set_ipv4_gw(struct sigma_dut *dut, const char *gw);
1085 int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
1086 		   struct sigma_cmd *cmd, const char *param);
1087 int wil6210_set_ese(struct sigma_dut *dut, int count,
1088 		    struct sigma_ese_alloc *allocs);
1089 int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
1090 			struct sigma_ese_alloc *allocs, int *allocs_size);
1091 int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs);
1092 int sta_set_addba_buf_size(struct sigma_dut *dut,
1093 			   const char *intf, int bufsize);
1094 #ifdef NL80211_SUPPORT
1095 int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
1096 		   enum qca_wlan_he_ltf_cfg ltf);
1097 #endif /* NL80211_SUPPORT */
1098 
1099 /* p2p.c */
1100 void p2p_register_cmds(void);
1101 int p2p_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1102 			      struct sigma_cmd *cmd);
1103 void p2p_create_event_thread(struct sigma_dut *dut);
1104 void stop_event_thread(void);
1105 void start_dhcp(struct sigma_dut *dut, const char *group_ifname, int go);
1106 void stop_dhcp(struct sigma_dut *dut, const char *group_ifname, int go);
1107 int p2p_discover_peer(struct sigma_dut *dut, const char *ifname,
1108 		      const char *peer, int full);
1109 enum sigma_cmd_result cmd_sta_p2p_reset(struct sigma_dut *dut,
1110 					struct sigma_conn *conn,
1111 					struct sigma_cmd *cmd);
1112 
1113 /* basic.c */
1114 void basic_register_cmds(void);
1115 void get_ver(const char *cmd, char *buf, size_t buflen);
1116 
1117 /* utils.c */
1118 enum sigma_program sigma_program_to_enum(const char *prog);
1119 int hex_byte(const char *str);
1120 int parse_hexstr(const char *hex, unsigned char *buf, size_t buflen);
1121 int parse_mac_address(struct sigma_dut *dut, const char *arg,
1122 		      unsigned char *addr);
1123 int is_60g_sigma_dut(struct sigma_dut *dut);
1124 unsigned int channel_to_freq(struct sigma_dut *dut, unsigned int channel);
1125 unsigned int freq_to_channel(unsigned int freq);
1126 int is_ipv6_addr(const char *str);
1127 void convert_mac_addr_to_ipv6_lladdr(u8 *mac_addr, char *ipv6_buf,
1128 				     size_t buf_len);
1129 size_t convert_mac_addr_to_ipv6_linklocal(const u8 *mac_addr, u8 *ipv6);
1130 
1131 #ifndef ANDROID
1132 size_t strlcpy(char *dest, const char *src, size_t siz);
1133 size_t strlcat(char *dst, const char *str, size_t size);
1134 #endif /* ANDROID */
1135 void hex_dump(struct sigma_dut *dut, u8 *data, size_t len);
1136 int get_wps_pin_from_mac(struct sigma_dut *dut, const char *macaddr,
1137 			 char *pin, size_t len);
1138 void str_remove_chars(char *str, char ch);
1139 
1140 int get_wps_forced_version(struct sigma_dut *dut, const char *str);
1141 int base64_encode(const char *src, size_t len, char *out, size_t out_len);
1142 int random_get_bytes(char *buf, size_t len);
1143 int get_enable_disable(const char *val);
1144 int wcn_driver_cmd(const char *ifname, char *buf);
1145 
1146 /* uapsd_stream.c */
1147 void receive_uapsd(struct sigma_stream *s);
1148 void send_uapsd_console(struct sigma_stream *s);
1149 
1150 /* nan.c */
1151 int nan_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
1152 			      struct sigma_cmd *cmd);
1153 int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1154 			      struct sigma_cmd *cmd);
1155 int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1156 			    struct sigma_cmd *cmd);
1157 int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1158 			   struct sigma_cmd *cmd);
1159 int nan_cmd_sta_transmit_followup(struct sigma_dut *dut,
1160 				  struct sigma_conn *conn,
1161 				  struct sigma_cmd *cmd);
1162 void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1163 			       struct sigma_cmd *cmd);
1164 int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
1165 				      struct sigma_conn *conn,
1166 				      struct sigma_cmd *cmd);
1167 
1168 /* ftm.c */
1169 int loc_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1170 			    struct sigma_cmd *cmd);
1171 int loc_cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
1172 			   struct sigma_cmd *cmd);
1173 int loc_cmd_sta_preset_testparameters(struct sigma_dut *dut,
1174 				      struct sigma_conn *conn,
1175 				      struct sigma_cmd *cmd);
1176 int lowi_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1177 			       struct sigma_cmd *cmd);
1178 
1179 /* dpp.c */
1180 enum sigma_cmd_result dpp_dev_exec_action(struct sigma_dut *dut,
1181 					  struct sigma_conn *conn,
1182 					  struct sigma_cmd *cmd);
1183 
1184 /* dhcp.c */
1185 void process_fils_hlp(struct sigma_dut *dut);
1186 void hlp_thread_cleanup(struct sigma_dut *dut);
1187 
1188 #ifdef NL80211_SUPPORT
1189 struct nl80211_ctx * nl80211_init(struct sigma_dut *dut);
1190 void nl80211_deinit(struct sigma_dut *dut, struct nl80211_ctx *ctx);
1191 struct nl_msg * nl80211_drv_msg(struct sigma_dut *dut, struct nl80211_ctx *ctx,
1192 				int ifindex, int flags,
1193 				uint8_t cmd);
1194 int send_and_recv_msgs(struct sigma_dut *dut, struct nl80211_ctx *ctx,
1195 		       struct nl_msg *nlmsg,
1196 		       int (*valid_handler)(struct nl_msg *, void *),
1197 		       void *valid_data);
1198 #endif /* NL80211_SUPPORT */
1199 
1200 void traffic_register_cmds(void);
1201 void traffic_agent_register_cmds(void);
1202 void powerswitch_register_cmds(void);
1203 void atheros_register_cmds(void);
1204 void dev_register_cmds(void);
1205 void sniffer_register_cmds(void);
1206 void server_register_cmds(void);
1207 void miracast_register_cmds(void);
1208 int set_ipv6_addr(struct sigma_dut *dut, const char *ip, const char *mask,
1209 		  const char *ifname);
1210 
1211 #endif /* SIGMA_DUT_H */
1212