blob: b4bd29fd281e66aa7baee14508a4d51b61f89a19 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
4 * Copyright (c) 2011-2015, Qualcomm Atheros, Inc.
5 * All Rights Reserved.
6 * Licensed under the Clear BSD license. See README for more details.
7 */
8
9#ifndef SIGMA_DUT_H
10#define SIGMA_DUT_H
11
12#include <stdlib.h>
13#include <stdio.h>
14#include <stdarg.h>
15#include <string.h>
16#include <errno.h>
17#include <unistd.h>
18#include <time.h>
19#include <sys/time.h>
20#include <sys/types.h>
21#include <sys/socket.h>
22#include <net/if.h>
23#ifdef __QNXNTO__
24#include <sys/select.h>
25#include <net/if_ether.h>
26#endif /* __QNXNTO__ */
27#include <netinet/in.h>
28#include <arpa/inet.h>
29#ifdef CONFIG_TRAFFIC_AGENT
30#include <pthread.h>
31#endif /* CONFIG_TRAFFIC_AGENT */
32
33
34#ifdef __GNUC__
35#define PRINTF_FORMAT(a,b) __attribute__ ((format (printf, (a), (b))))
36#else
37#define PRINTF_FORMAT(a,b)
38#endif
39
40#ifndef SIGMA_TMPDIR
41#define SIGMA_TMPDIR "/tmp"
42#endif /* SIGMA_TMPDIR */
43
44#ifndef SIGMA_DUT_VER
45#define SIGMA_DUT_VER "(unknown)"
46#endif /* SIGMA_DUT_VER */
47
48#ifndef ETH_ALEN
49#define ETH_ALEN 6
50#endif
51
52#ifndef ETH_P_ARP
53#define ETH_P_ARP 0x0806
54#endif
55
56struct sigma_dut;
57
58#define MAX_PARAMS 100
59#define MAX_RADIO 2
60
61/* Set default operating channel width 80 MHz */
62#define VHT_DEFAULT_OPER_CHWIDTH AP_80_VHT_OPER_CHWIDTH
63
64typedef unsigned int u32;
65typedef unsigned char u8;
66
67#define WPA_GET_BE32(a) ((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \
68 (((u32) (a)[2]) << 8) | ((u32) (a)[3]))
69#define WPA_PUT_BE32(a, val) \
70 do { \
71 (a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \
72 (a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \
73 (a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \
74 (a)[3] = (u8) (((u32) (val)) & 0xff); \
75 } while (0)
76
77struct sigma_cmd {
78 char *params[MAX_PARAMS];
79 char *values[MAX_PARAMS];
80 int count;
81};
82
83#define MAX_CMD_LEN 2048
84
85struct sigma_conn {
86 int s;
87 struct sockaddr_in addr;
88 socklen_t addrlen;
89 char buf[MAX_CMD_LEN + 5];
90 int pos;
91 int waiting_completion;
92};
93
94#define SIGMA_DUT_ERROR_CALLER_SEND_STATUS -2
95#define SIGMA_DUT_INVALID_CALLER_SEND_STATUS -1
96#define SIGMA_DUT_SUCCESS_STATUS_SENT 0
97#define SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS 1
98
99struct sigma_cmd_handler {
100 struct sigma_cmd_handler *next;
101 char *cmd;
102 int (*validate)(struct sigma_cmd *cmd);
103 /* process return value:
104 * -2 = failed, caller will send status,ERROR
105 * -1 = failed, caller will send status,INVALID
106 * 0 = success, response already sent
107 * 1 = success, caller will send status,COMPLETE
108 */
109 int (*process)(struct sigma_dut *dut, struct sigma_conn *conn,
110 struct sigma_cmd *cmd);
111};
112
113#define P2P_GRP_ID_LEN 128
114#define IP_ADDR_STR_LEN 16
115
116struct wfa_cs_p2p_group {
117 struct wfa_cs_p2p_group *next;
118 char ifname[IFNAMSIZ];
119 int go;
120 char grpid[P2P_GRP_ID_LEN];
121 char ssid[33];
122};
123
124#ifdef CONFIG_TRAFFIC_AGENT
125
126#define MAX_SIGMA_STREAMS 16
127#define MAX_SIGMA_STATS 6000
128
129struct sigma_frame_stats {
130 unsigned int seqnum;
131 unsigned int local_sec;
132 unsigned int local_usec;
133 unsigned int remote_sec;
134 unsigned int remote_usec;
135};
136
137struct sigma_stream {
138 enum sigma_stream_profile {
139 SIGMA_PROFILE_FILE_TRANSFER,
140 SIGMA_PROFILE_MULTICAST,
141 SIGMA_PROFILE_IPTV,
142 SIGMA_PROFILE_TRANSACTION,
143 SIGMA_PROFILE_START_SYNC,
144 SIGMA_PROFILE_UAPSD
145 } profile;
146 int sender;
147 struct in_addr dst;
148 int dst_port;
149 struct in_addr src;
150 int src_port;
151 int frame_rate;
152 int duration;
153 int payload_size;
154 int start_delay;
155 int max_cnt;
156 enum sigma_traffic_class {
157 SIGMA_TC_VOICE,
158 SIGMA_TC_VIDEO,
159 SIGMA_TC_BACKGROUND,
160 SIGMA_TC_BEST_EFFORT
161 } tc;
162 int user_priority;
163 int user_priority_set;
164 int started;
165 int no_timestamps;
166
167 int sock;
168 pthread_t thr;
169 int stop;
170 int ta_send_in_progress;
171 int trans_proto;
172
173 /* Statistics */
174 int tx_act_frames; /*
175 * Number of frames generated by the traffic
176 * generator application. The name is defined in the
177 * Sigma CAPI spec.
178 */
179 int tx_frames;
180 int rx_frames;
181 unsigned long long tx_payload_bytes;
182 unsigned long long rx_payload_bytes;
183 int out_of_seq_frames;
184 struct sigma_frame_stats *stats;
185 unsigned int num_stats;
186 unsigned int stream_id;
187
188 /* U-APSD */
189 unsigned int sta_id;
190 unsigned int rx_cookie;
191 unsigned int uapsd_sta_tc;
192 unsigned int uapsd_rx_state;
193 unsigned int uapsd_tx_state;
194 unsigned int tx_stop_cnt;
195 unsigned int tx_hello_cnt;
196 pthread_t uapsd_send_thr;
197 pthread_cond_t tx_thr_cond;
198 pthread_mutex_t tx_thr_mutex;
199 int reset_rx;
200 int num_retry;
201 char ifname[IFNAMSIZ]; /* ifname from the command */
202 struct sigma_dut *dut; /* for traffic agent thread to access context */
Pradeep Reddy POTTETI79594042015-11-23 12:59:12 +0530203 /* console */
204 char test_name[9]; /* test case name */
205 int can_quit;
206 int reset;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200207};
208
209#endif /* CONFIG_TRAFFIC_AGENT */
210
211
212#define NUM_AP_AC 4
213#define AP_AC_BE 0
214#define AP_AC_BK 1
215#define AP_AC_VI 2
216#define AP_AC_VO 3
217
218struct sigma_dut {
219 int s; /* server TCP socket */
220 int debug_level;
221 int stdout_debug;
222 struct sigma_cmd_handler *cmds;
223
224 /* Default timeout value (seconds) for commands */
225 unsigned int default_timeout;
226
227 int next_streamid;
228
229 const char *bridge; /* bridge interface to use in AP mode */
230
231 enum sigma_mode {
232 SIGMA_MODE_UNKNOWN,
233 SIGMA_MODE_STATION,
234 SIGMA_MODE_AP,
235 SIGMA_MODE_SNIFFER
236 } mode;
237
238 /*
239 * Local cached values to handle API that does not provide all the
240 * needed information with commands that actually trigger some
241 * operations.
242 */
243 int listen_chn;
244 int persistent;
245 int intra_bss;
246 int noa_duration;
247 int noa_interval;
248 int noa_count;
249 enum wfa_cs_wps_method {
250 WFA_CS_WPS_NOT_READY,
251 WFA_CS_WPS_PBC,
252 WFA_CS_WPS_PIN_DISPLAY,
253 WFA_CS_WPS_PIN_LABEL,
254 WFA_CS_WPS_PIN_KEYPAD
255 } wps_method;
256 char wps_pin[9];
257
258 struct wfa_cs_p2p_group *groups;
259
260 char infra_ssid[33];
261 int infra_network_id;
262
263 enum p2p_mode {
264 P2P_IDLE, P2P_DISCOVER, P2P_LISTEN, P2P_DISABLE
265 } p2p_mode;
266
267 int go;
268 int p2p_client;
269
270 int client_uapsd;
271
272 char arp_ipaddr[IP_ADDR_STR_LEN];
273 char arp_ifname[IFNAMSIZ + 1];
274
275 enum sta_pmf {
276 STA_PMF_DISABLED,
277 STA_PMF_OPTIONAL,
278 STA_PMF_REQUIRED
279 } sta_pmf;
280
281 int no_tpk_expiration;
282
283 int er_oper_performed;
284 char er_oper_bssid[20];
285 int amsdu_size;
286 int back_rcv_buf;
287
288 int testbed_flag_txsp;
289 int testbed_flag_rxsp;
290 int chwidth;
291
292 /* AP configuration */
293 char ap_ssid[33];
294 char ap2_ssid[33];
295 enum ap_mode {
296 AP_11a,
297 AP_11g,
298 AP_11b,
299 AP_11na,
300 AP_11ng,
301 AP_11ac,
302 AP_inval
303 } ap_mode;
304 int ap_channel;
305 int ap_rts;
306 int ap_frgmnt;
307 int ap_bcnint;
308 struct qos_params {
309 int ac;
310 int cwmin;
311 int cwmax;
312 int aifs;
313 int txop;
314 int acm;
315 } ap_qos[NUM_AP_AC], ap_sta_qos[NUM_AP_AC];
316 enum ap_noack_values {
317 AP_NOACK_NOT_SET,
318 AP_NOACK_ENABLED,
319 AP_NOACK_DISABLED
320 } ap_noack;
321 int ap_ampdu;
322 int ap_amsdu;
323 int ap_rx_amsdu;
324 int ap_ampdu_exp;
325 int ap_addba_reject;
326 int ap_fixed_rate;
327 int ap_mcs;
328 int ap_rx_streams;
329 int ap_tx_streams;
330 unsigned int ap_vhtmcs_map;
331 int ap_ldpc;
332 int ap_sig_rts;
333 enum ap_chwidth {
334 AP_20,
335 AP_40,
336 AP_80,
337 AP_160,
338 AP_AUTO
339 } ap_chwidth;
340 enum ap_chwidth default_ap_chwidth;
341 int ap_tx_stbc;
342 enum ap_dyn_bw_sig_values {
343 AP_DYN_BW_SGNL_NOT_SET,
344 AP_DYN_BW_SGNL_ENABLED,
345 AP_DYN_BW_SGNL_DISABLED
346 } ap_dyn_bw_sig;
347 int ap_sgi80;
348 int ap_p2p_mgmt;
349 enum ap_key_mgmt {
350 AP_OPEN,
351 AP_WPA2_PSK,
352 AP_WPA_PSK,
353 AP_WPA2_EAP,
354 AP_WPA_EAP,
355 AP_WPA2_EAP_MIXED,
356 AP_WPA2_PSK_MIXED
357 } ap_key_mgmt;
358 enum ap2_key_mgmt {
359 AP2_OPEN,
360 AP2_OSEN
361 } ap2_key_mgmt;
362 int ap_add_sha256;
Sarvepalli, Rajesh Babu24dc7e42016-03-18 21:27:26 +0530363 int ap_rsn_preauth;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200364 enum ap_pmf {
365 AP_PMF_DISABLED,
366 AP_PMF_OPTIONAL,
367 AP_PMF_REQUIRED
368 } ap_pmf;
369 enum ap_cipher {
370 AP_CCMP,
371 AP_TKIP,
372 AP_WEP,
373 AP_PLAIN,
374 AP_CCMP_TKIP
375 } ap_cipher;
376 char ap_passphrase[65];
377 char ap_wepkey[27];
378 char ap_radius_ipaddr[20];
379 int ap_radius_port;
380 char ap_radius_password[200];
381 char ap2_radius_ipaddr[20];
382 int ap2_radius_port;
383 char ap2_radius_password[200];
384 int ap_tdls_prohibit;
385 int ap_tdls_prohibit_chswitch;
386 int ap_hs2;
387 int ap_dgaf_disable;
388 int ap_p2p_cross_connect;
389 int ap_oper_name;
390 int ap_wan_metrics;
391 int ap_conn_capab;
392 int ap_oper_class;
393
394 int ap_interworking;
395 int ap_access_net_type;
396 int ap_internet;
397 int ap_venue_group;
398 int ap_venue_type;
399 char ap_hessid[20];
400 char ap_roaming_cons[100];
401 int ap_venue_name;
402 int ap_net_auth_type;
403 int ap_nai_realm_list;
404 char ap_domain_name_list[1000];
405 int ap_ip_addr_type_avail;
406 char ap_plmn_mcc[10][4];
407 char ap_plmn_mnc[10][4];
408 int ap_gas_cb_delay;
409 int ap_proxy_arp;
410 int ap2_proxy_arp;
411 int ap_l2tif;
412 int ap_anqpserver;
413 int ap_anqpserver_on;
414 int ap_osu_provider_list;
415 int ap_qos_map_set;
416 int ap_bss_load;
417 char ap_osu_server_uri[10][256];
418 char ap_osu_ssid[33];
419 int ap_osu_method[10];
420 int ap_osu_icon_tag;
421
422 int ap_fake_pkhash;
423 int ap_disable_protection;
424 int ap_allow_vht_wep;
425 int ap_allow_vht_tkip;
426
427 enum ap_vht_chwidth {
428 AP_20_40_VHT_OPER_CHWIDTH,
429 AP_80_VHT_OPER_CHWIDTH,
430 AP_160_VHT_OPER_CHWIDTH
431 } ap_vht_chwidth;
432 int ap_txBF;
433 int ap_mu_txBF;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530434 enum ap_regulatory_mode {
435 AP_80211D_MODE_DISABLED,
436 AP_80211D_MODE_ENABLED,
437 } ap_regulatory_mode;
438 enum ap_dfs_mode {
439 AP_DFS_MODE_DISABLED,
440 AP_DFS_MODE_ENABLED,
441 } ap_dfs_mode;
priyadharshini gowthaman264d5442016-02-25 15:52:22 -0800442 int ap_ndpa_frame;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200443
444 const char *hostapd_debug_log;
445
446#ifdef CONFIG_TRAFFIC_AGENT
447 /* Traffic Agent */
448 struct sigma_stream streams[MAX_SIGMA_STREAMS];
449 int stream_id;
450 int num_streams;
451 pthread_t thr;
452#endif /* CONFIG_TRAFFIC_AGENT */
453
454 int throughput_pktsize; /* If non-zero, override pktsize for throughput
455 * tests */
456 int no_timestamps;
457
458 const char *sniffer_ifname;
459 const char *set_macaddr;
460 int tmp_mac_addr;
461 int ap_is_dual;
462 enum ap_mode ap_mode_1;
463 enum ap_chwidth ap_chwidth_1;
464 int ap_channel_1;
465 char ap_countrycode[3];
466
467 int ap_wpsnfc;
468
Pradeep Reddy POTTETI0d3db632016-03-11 15:21:11 +0530469 enum ap_wme {
470 AP_WME_OFF,
471 AP_WME_ON,
472 } ap_wme;
473
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200474#ifdef CONFIG_SNIFFER
475 pid_t sniffer_pid;
476 char sniffer_filename[200];
477#endif /* CONFIG_SNIFFER */
478
479 int last_set_ip_config_ipv6;
480
481 int tid_to_handle[8]; /* Mapping of TID to handle */
482 int dialog_token; /* Used for generating unique handle for an addTs */
483
484 enum sigma_program {
485 PROGRAM_UNKNOWN = 0,
486 PROGRAM_TDLS,
487 PROGRAM_HS2,
488 PROGRAM_HS2_R2,
489 PROGRAM_WFD,
490 PROGRAM_PMF,
491 PROGRAM_WPS,
492 PROGRAM_60GHZ,
493 PROGRAM_HT,
494 PROGRAM_VHT,
495 PROGRAM_NAN,
496 } program;
497
498 enum device_type {
499 device_type_unknown,
500 AP_unknown,
501 AP_testbed,
502 AP_dut,
503 STA_unknown,
504 STA_testbed,
505 STA_dut
506 } device_type;
507
508 enum {
509 DEVROLE_UNKNOWN = 0,
510 DEVROLE_STA,
511 DEVROLE_PCP,
512 } dev_role;
513
514 const char *version;
515 int no_ip_addr_set;
516 int sta_channel;
517
518 const char *summary_log;
519 const char *hostapd_entropy_log;
520
521 int iface_down_on_reset;
522 int write_stats; /* traffic stream e2e*.txt files */
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +0530523 int sim_no_username; /* do not set SIM username to use real SIM */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200524};
525
526
527enum sigma_dut_print_level {
528 DUT_MSG_DEBUG, DUT_MSG_INFO, DUT_MSG_ERROR
529};
530
531void sigma_dut_print(struct sigma_dut *dut, int level, const char *fmt, ...)
532PRINTF_FORMAT(3, 4);
533
534void sigma_dut_summary(struct sigma_dut *dut, const char *fmt, ...)
535PRINTF_FORMAT(2, 3);
536
537
538enum sigma_status {
539 SIGMA_RUNNING, SIGMA_INVALID, SIGMA_ERROR, SIGMA_COMPLETE
540};
541
542void send_resp(struct sigma_dut *dut, struct sigma_conn *conn,
543 enum sigma_status status, char *buf);
544
545const char * get_param(struct sigma_cmd *cmd, const char *name);
546
547int sigma_dut_reg_cmd(const char *cmd,
548 int (*validate)(struct sigma_cmd *cmd),
549 int (*process)(struct sigma_dut *dut,
550 struct sigma_conn *conn,
551 struct sigma_cmd *cmd));
552
553void sigma_dut_register_cmds(void);
554
555int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
556 struct sigma_cmd *cmd);
557int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
558 struct sigma_cmd *cmd);
559int cmd_ap_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
560 struct sigma_cmd *cmd);
561int cmd_wlantest_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
562 struct sigma_cmd *cmd);
563
564enum driver_type {
565 DRIVER_NOT_SET,
566 DRIVER_ATHEROS,
567 DRIVER_WCN,
568 DRIVER_MAC80211,
569 DRIVER_AR6003,
570 DRIVER_WIL6210,
571 DRIVER_QNXNTO,
Sreelakshmi Konamkib692f102016-04-26 19:47:00 +0530572 DRIVER_OPENWRT,
573 DRIVER_LINUX_WCN,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200574};
575
576enum openwrt_driver_type {
577 OPENWRT_DRIVER_NOT_SET,
578 OPENWRT_DRIVER_ATHEROS
579};
580
581#define DRIVER_NAME_60G "wil6210"
582
583int set_wifi_chip(const char *chip_type);
584enum driver_type get_driver_type(void);
585enum openwrt_driver_type get_openwrt_driver_type(void);
586int file_exists(const char *fname);
587
588struct wpa_ctrl;
589
590int wps_connection_event(struct sigma_dut *dut, struct sigma_conn *conn,
591 struct wpa_ctrl *ctrl, const char *intf, int p2p_resp);
592int ascii2hexstr(const char *str, char *hex);
593void disconnect_station(struct sigma_dut *dut);
594void nfc_status(struct sigma_dut *dut, const char *state, const char *oper);
595int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
596 size_t buf_len);
597int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd);
598int is_ip_addr(const char *str);
599int run_system(struct sigma_dut *dut, const char *cmd);
600int cmd_wlantest_set_channel(struct sigma_dut *dut, struct sigma_conn *conn,
601 struct sigma_cmd *cmd);
602void sniffer_close(struct sigma_dut *dut);
603
604/* ap.c */
605void ath_disable_txbf(struct sigma_dut *dut, const char *intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800606void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
607 const char *val);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -0800608void novap_reset(struct sigma_dut *dut, const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200609
610/* sta.c */
611int set_ps(const char *intf, struct sigma_dut *dut, int enabled);
612void ath_set_zero_crc(struct sigma_dut *dut, const char *val);
613void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
614 const char *val);
615int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
616 const char *intf, const char *val);
617
618/* p2p.c */
619int p2p_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
620 struct sigma_cmd *cmd);
621
622/* utils.h */
623enum sigma_program sigma_program_to_enum(const char *prog);
624
625/* uapsd_stream.c */
626void receive_uapsd(struct sigma_stream *s);
Pradeep Reddy POTTETI79594042015-11-23 12:59:12 +0530627void send_uapsd_console(struct sigma_stream *s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200628
629/* nan.c */
630int nan_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
631 struct sigma_cmd *cmd);
632int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
633 struct sigma_cmd *cmd);
634int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
635 struct sigma_cmd *cmd);
636int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
637 struct sigma_cmd *cmd);
638int nan_cmd_sta_transmit_followup(struct sigma_dut *dut,
639 struct sigma_conn *conn,
640 struct sigma_cmd *cmd);
641void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
642 struct sigma_cmd *cmd);
643int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
644 struct sigma_conn *conn,
645 struct sigma_cmd *cmd);
646
647#endif /* SIGMA_DUT_H */