blob: c16d293c3e05b0f5c699d9dc0cd7796308744886 [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;
363 enum ap_pmf {
364 AP_PMF_DISABLED,
365 AP_PMF_OPTIONAL,
366 AP_PMF_REQUIRED
367 } ap_pmf;
368 enum ap_cipher {
369 AP_CCMP,
370 AP_TKIP,
371 AP_WEP,
372 AP_PLAIN,
373 AP_CCMP_TKIP
374 } ap_cipher;
375 char ap_passphrase[65];
376 char ap_wepkey[27];
377 char ap_radius_ipaddr[20];
378 int ap_radius_port;
379 char ap_radius_password[200];
380 char ap2_radius_ipaddr[20];
381 int ap2_radius_port;
382 char ap2_radius_password[200];
383 int ap_tdls_prohibit;
384 int ap_tdls_prohibit_chswitch;
385 int ap_hs2;
386 int ap_dgaf_disable;
387 int ap_p2p_cross_connect;
388 int ap_oper_name;
389 int ap_wan_metrics;
390 int ap_conn_capab;
391 int ap_oper_class;
392
393 int ap_interworking;
394 int ap_access_net_type;
395 int ap_internet;
396 int ap_venue_group;
397 int ap_venue_type;
398 char ap_hessid[20];
399 char ap_roaming_cons[100];
400 int ap_venue_name;
401 int ap_net_auth_type;
402 int ap_nai_realm_list;
403 char ap_domain_name_list[1000];
404 int ap_ip_addr_type_avail;
405 char ap_plmn_mcc[10][4];
406 char ap_plmn_mnc[10][4];
407 int ap_gas_cb_delay;
408 int ap_proxy_arp;
409 int ap2_proxy_arp;
410 int ap_l2tif;
411 int ap_anqpserver;
412 int ap_anqpserver_on;
413 int ap_osu_provider_list;
414 int ap_qos_map_set;
415 int ap_bss_load;
416 char ap_osu_server_uri[10][256];
417 char ap_osu_ssid[33];
418 int ap_osu_method[10];
419 int ap_osu_icon_tag;
420
421 int ap_fake_pkhash;
422 int ap_disable_protection;
423 int ap_allow_vht_wep;
424 int ap_allow_vht_tkip;
425
426 enum ap_vht_chwidth {
427 AP_20_40_VHT_OPER_CHWIDTH,
428 AP_80_VHT_OPER_CHWIDTH,
429 AP_160_VHT_OPER_CHWIDTH
430 } ap_vht_chwidth;
431 int ap_txBF;
432 int ap_mu_txBF;
Pradeep Reddy POTTETIfba27db2015-11-20 16:42:22 +0530433 enum ap_regulatory_mode {
434 AP_80211D_MODE_DISABLED,
435 AP_80211D_MODE_ENABLED,
436 } ap_regulatory_mode;
437 enum ap_dfs_mode {
438 AP_DFS_MODE_DISABLED,
439 AP_DFS_MODE_ENABLED,
440 } ap_dfs_mode;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200441
442 const char *hostapd_debug_log;
443
444#ifdef CONFIG_TRAFFIC_AGENT
445 /* Traffic Agent */
446 struct sigma_stream streams[MAX_SIGMA_STREAMS];
447 int stream_id;
448 int num_streams;
449 pthread_t thr;
450#endif /* CONFIG_TRAFFIC_AGENT */
451
452 int throughput_pktsize; /* If non-zero, override pktsize for throughput
453 * tests */
454 int no_timestamps;
455
456 const char *sniffer_ifname;
457 const char *set_macaddr;
458 int tmp_mac_addr;
459 int ap_is_dual;
460 enum ap_mode ap_mode_1;
461 enum ap_chwidth ap_chwidth_1;
462 int ap_channel_1;
463 char ap_countrycode[3];
464
465 int ap_wpsnfc;
466
467#ifdef CONFIG_SNIFFER
468 pid_t sniffer_pid;
469 char sniffer_filename[200];
470#endif /* CONFIG_SNIFFER */
471
472 int last_set_ip_config_ipv6;
473
474 int tid_to_handle[8]; /* Mapping of TID to handle */
475 int dialog_token; /* Used for generating unique handle for an addTs */
476
477 enum sigma_program {
478 PROGRAM_UNKNOWN = 0,
479 PROGRAM_TDLS,
480 PROGRAM_HS2,
481 PROGRAM_HS2_R2,
482 PROGRAM_WFD,
483 PROGRAM_PMF,
484 PROGRAM_WPS,
485 PROGRAM_60GHZ,
486 PROGRAM_HT,
487 PROGRAM_VHT,
488 PROGRAM_NAN,
489 } program;
490
491 enum device_type {
492 device_type_unknown,
493 AP_unknown,
494 AP_testbed,
495 AP_dut,
496 STA_unknown,
497 STA_testbed,
498 STA_dut
499 } device_type;
500
501 enum {
502 DEVROLE_UNKNOWN = 0,
503 DEVROLE_STA,
504 DEVROLE_PCP,
505 } dev_role;
506
507 const char *version;
508 int no_ip_addr_set;
509 int sta_channel;
510
511 const char *summary_log;
512 const char *hostapd_entropy_log;
513
514 int iface_down_on_reset;
515 int write_stats; /* traffic stream e2e*.txt files */
516};
517
518
519enum sigma_dut_print_level {
520 DUT_MSG_DEBUG, DUT_MSG_INFO, DUT_MSG_ERROR
521};
522
523void sigma_dut_print(struct sigma_dut *dut, int level, const char *fmt, ...)
524PRINTF_FORMAT(3, 4);
525
526void sigma_dut_summary(struct sigma_dut *dut, const char *fmt, ...)
527PRINTF_FORMAT(2, 3);
528
529
530enum sigma_status {
531 SIGMA_RUNNING, SIGMA_INVALID, SIGMA_ERROR, SIGMA_COMPLETE
532};
533
534void send_resp(struct sigma_dut *dut, struct sigma_conn *conn,
535 enum sigma_status status, char *buf);
536
537const char * get_param(struct sigma_cmd *cmd, const char *name);
538
539int sigma_dut_reg_cmd(const char *cmd,
540 int (*validate)(struct sigma_cmd *cmd),
541 int (*process)(struct sigma_dut *dut,
542 struct sigma_conn *conn,
543 struct sigma_cmd *cmd));
544
545void sigma_dut_register_cmds(void);
546
547int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
548 struct sigma_cmd *cmd);
549int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
550 struct sigma_cmd *cmd);
551int cmd_ap_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
552 struct sigma_cmd *cmd);
553int cmd_wlantest_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
554 struct sigma_cmd *cmd);
555
556enum driver_type {
557 DRIVER_NOT_SET,
558 DRIVER_ATHEROS,
559 DRIVER_WCN,
560 DRIVER_MAC80211,
561 DRIVER_AR6003,
562 DRIVER_WIL6210,
563 DRIVER_QNXNTO,
564 DRIVER_OPENWRT
565};
566
567enum openwrt_driver_type {
568 OPENWRT_DRIVER_NOT_SET,
569 OPENWRT_DRIVER_ATHEROS
570};
571
572#define DRIVER_NAME_60G "wil6210"
573
574int set_wifi_chip(const char *chip_type);
575enum driver_type get_driver_type(void);
576enum openwrt_driver_type get_openwrt_driver_type(void);
577int file_exists(const char *fname);
578
579struct wpa_ctrl;
580
581int wps_connection_event(struct sigma_dut *dut, struct sigma_conn *conn,
582 struct wpa_ctrl *ctrl, const char *intf, int p2p_resp);
583int ascii2hexstr(const char *str, char *hex);
584void disconnect_station(struct sigma_dut *dut);
585void nfc_status(struct sigma_dut *dut, const char *state, const char *oper);
586int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
587 size_t buf_len);
588int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd);
589int is_ip_addr(const char *str);
590int run_system(struct sigma_dut *dut, const char *cmd);
591int cmd_wlantest_set_channel(struct sigma_dut *dut, struct sigma_conn *conn,
592 struct sigma_cmd *cmd);
593void sniffer_close(struct sigma_dut *dut);
594
595/* ap.c */
596void ath_disable_txbf(struct sigma_dut *dut, const char *intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -0800597void ath_config_dyn_bw_sig(struct sigma_dut *dut, const char *ifname,
598 const char *val);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -0800599void novap_reset(struct sigma_dut *dut, const char *ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200600
601/* sta.c */
602int set_ps(const char *intf, struct sigma_dut *dut, int enabled);
603void ath_set_zero_crc(struct sigma_dut *dut, const char *val);
604void ath_set_cts_width(struct sigma_dut *dut, const char *ifname,
605 const char *val);
606int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
607 const char *intf, const char *val);
608
609/* p2p.c */
610int p2p_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
611 struct sigma_cmd *cmd);
612
613/* utils.h */
614enum sigma_program sigma_program_to_enum(const char *prog);
615
616/* uapsd_stream.c */
617void receive_uapsd(struct sigma_stream *s);
Pradeep Reddy POTTETI79594042015-11-23 12:59:12 +0530618void send_uapsd_console(struct sigma_stream *s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200619
620/* nan.c */
621int nan_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
622 struct sigma_cmd *cmd);
623int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
624 struct sigma_cmd *cmd);
625int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
626 struct sigma_cmd *cmd);
627int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
628 struct sigma_cmd *cmd);
629int nan_cmd_sta_transmit_followup(struct sigma_dut *dut,
630 struct sigma_conn *conn,
631 struct sigma_cmd *cmd);
632void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
633 struct sigma_cmd *cmd);
634int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
635 struct sigma_conn *conn,
636 struct sigma_cmd *cmd);
637
638#endif /* SIGMA_DUT_H */