blob: 88e96bcff1428e0e9acdc6909122247a975ac628 [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (NAN functionality)
Rakesh Sunki4b75f962017-03-30 14:47:55 -07003 * Copyright (c) 2014-2017, Qualcomm Atheros, Inc.
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004 * All Rights Reserved.
5 * Licensed under the Clear BSD license. See README for more details.
6 */
7
8#include "sigma_dut.h"
9#include <sys/stat.h>
10#include "wpa_ctrl.h"
11#include "wpa_helpers.h"
12#include "wifi_hal.h"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -070013#include "nan_cert.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014
Rakesh Sunki4b75f962017-03-30 14:47:55 -070015#if NAN_CERT_VERSION >= 2
16
Jouni Malinencd4e3c32015-10-29 12:39:56 +020017pthread_cond_t gCondition;
18pthread_mutex_t gMutex;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -070019wifi_handle global_wifi_handle;
20wifi_interface_handle global_interface_handle;
Rakesh Sunkid51e8982017-03-30 14:47:55 -070021static NanSyncStats global_nan_sync_stats;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020022static int nan_state = 0;
23static int event_anyresponse = 0;
24static int is_fam = 0;
25
Rakesh Sunki4c086672017-03-30 14:47:55 -070026static uint16_t global_ndp_instance_id = 0;
Rakesh Sunki4d5912d2017-03-30 14:47:55 -070027static uint16_t global_publish_id = 0;
28static uint16_t global_subscribe_id = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020029uint16_t global_header_handle = 0;
30uint32_t global_match_handle = 0;
31
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -070032#define DEFAULT_SVC "QNanCluster"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020033#define MAC_ADDR_ARRAY(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
34#define MAC_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
35#ifndef ETH_ALEN
36#define ETH_ALEN 6
37#endif
38
39struct sigma_dut *global_dut = NULL;
40static char global_nan_mac_addr[ETH_ALEN];
Rakesh Sunki14cfcd22017-03-30 14:47:55 -070041static char global_peer_mac_addr[ETH_ALEN];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020042static char global_event_resp_buf[1024];
43
44static int nan_further_availability_tx(struct sigma_dut *dut,
45 struct sigma_conn *conn,
46 struct sigma_cmd *cmd);
47static int nan_further_availability_rx(struct sigma_dut *dut,
48 struct sigma_conn *conn,
49 struct sigma_cmd *cmd);
50
51
52void nan_hex_dump(struct sigma_dut *dut, uint8_t *data, size_t len)
53{
54 char buf[512];
55 uint16_t index;
56 uint8_t *ptr;
57 int pos;
58
59 memset(buf, 0, sizeof(buf));
60 ptr = data;
61 pos = 0;
62 for (index = 0; index < len; index++) {
63 pos += sprintf(&(buf[pos]), "%02x ", *ptr++);
64 if (pos > 508)
65 break;
66 }
67 sigma_dut_print(dut, DUT_MSG_INFO, "HEXDUMP len=[%d]", (int) len);
68 sigma_dut_print(dut, DUT_MSG_INFO, "buf:%s", buf);
69}
70
71
72int nan_parse_hex(unsigned char c)
73{
74 if (c >= '0' && c <= '9')
75 return c - '0';
76 if (c >= 'a' && c <= 'f')
77 return c - 'a' + 10;
78 if (c >= 'A' && c <= 'F')
79 return c - 'A' + 10;
80 return 0;
81}
82
83
84int nan_parse_token(const char *tokenIn, u8 *tokenOut, int *filterLen)
85{
86 int total_len = 0, len = 0;
87 char *saveptr = NULL;
88
89 tokenIn = strtok_r((char *) tokenIn, ":", &saveptr);
90 while (tokenIn != NULL) {
91 len = strlen(tokenIn);
92 if (len == 1 && *tokenIn == '*')
93 len = 0;
94 tokenOut[total_len++] = (u8) len;
95 if (len != 0)
96 memcpy((u8 *) tokenOut + total_len, tokenIn, len);
97 total_len += len;
98 tokenIn = strtok_r(NULL, ":", &saveptr);
99 }
100 *filterLen = total_len;
101 return 0;
102}
103
104
105int nan_parse_mac_address(struct sigma_dut *dut, const char *arg, u8 *addr)
106{
107 if (strlen(arg) != 17) {
108 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid mac address %s",
109 arg);
110 sigma_dut_print(dut, DUT_MSG_ERROR,
111 "expected format xx:xx:xx:xx:xx:xx");
112 return -1;
113 }
114
115 addr[0] = nan_parse_hex(arg[0]) << 4 | nan_parse_hex(arg[1]);
116 addr[1] = nan_parse_hex(arg[3]) << 4 | nan_parse_hex(arg[4]);
117 addr[2] = nan_parse_hex(arg[6]) << 4 | nan_parse_hex(arg[7]);
118 addr[3] = nan_parse_hex(arg[9]) << 4 | nan_parse_hex(arg[10]);
119 addr[4] = nan_parse_hex(arg[12]) << 4 | nan_parse_hex(arg[13]);
120 addr[5] = nan_parse_hex(arg[15]) << 4 | nan_parse_hex(arg[16]);
121
122 return 0;
123}
124
125
126int nan_parse_mac_address_list(struct sigma_dut *dut, const char *input,
127 u8 *output, u16 max_addr_allowed)
128{
129 /*
130 * Reads a list of mac address separated by space. Each MAC address
131 * should have the format of aa:bb:cc:dd:ee:ff.
132 */
133 char *saveptr;
134 char *token;
135 int i = 0;
136
137 for (i = 0; i < max_addr_allowed; i++) {
138 token = strtok_r((i == 0) ? (char *) input : NULL,
139 " ", &saveptr);
140 if (token) {
141 nan_parse_mac_address(dut, token, output);
142 output += NAN_MAC_ADDR_LEN;
143 } else
144 break;
145 }
146
147 sigma_dut_print(dut, DUT_MSG_INFO, "Num MacAddress:%d", i);
148
149 return i;
150}
151
152
153int nan_parse_hex_string(struct sigma_dut *dut, const char *input,
154 u8 *output, int *outputlen)
155{
156 int i = 0;
157 int j = 0;
158
159 for (i = 0; i < (int) strlen(input) && j < *outputlen; i += 2) {
160 output[j] = nan_parse_hex(input[i]);
161 if (i + 1 < (int) strlen(input)) {
162 output[j] = ((output[j] << 4) |
163 nan_parse_hex(input[i + 1]));
164 }
165 j++;
166 }
167 *outputlen = j;
168 sigma_dut_print(dut, DUT_MSG_INFO, "Input:%s inputlen:%d outputlen:%d",
169 input, (int) strlen(input), (int) *outputlen);
170 return 0;
171}
172
173
174int wait(struct timespec abstime)
175{
176 struct timeval now;
177
178 gettimeofday(&now, NULL);
179
180 abstime.tv_sec += now.tv_sec;
181 if (((abstime.tv_nsec + now.tv_usec * 1000) > 1000 * 1000 * 1000) ||
182 (abstime.tv_nsec + now.tv_usec * 1000 < 0)) {
183 abstime.tv_sec += 1;
184 abstime.tv_nsec += now.tv_usec * 1000;
185 abstime.tv_nsec -= 1000 * 1000 * 1000;
186 } else {
187 abstime.tv_nsec += now.tv_usec * 1000;
188 }
189
190 return pthread_cond_timedwait(&gCondition, &gMutex, &abstime);
191}
192
193
194int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
195 struct sigma_conn *conn,
196 struct sigma_cmd *cmd)
197{
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700198 const char *oper_chan = get_param(cmd, "oper_chn");
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700199 const char *pmk = get_param(cmd, "PMK");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200200
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700201 if (oper_chan) {
202 sigma_dut_print(dut, DUT_MSG_INFO, "Operating Channel: %s",
203 oper_chan);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700204 dut->sta_channel = atoi(oper_chan);
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700205 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700207 if (pmk) {
208 int pmk_len;
209
210 sigma_dut_print(dut, DUT_MSG_INFO, "%s given string pmk: %s",
211 __func__, pmk);
212 memset(dut->nan_pmk, 0, NAN_PMK_INFO_LEN);
213 dut->nan_pmk_len = 0;
214 pmk_len = NAN_PMK_INFO_LEN;
215 nan_parse_hex_string(dut, &pmk[2], &dut->nan_pmk[0], &pmk_len);
216 dut->nan_pmk_len = pmk_len;
217 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
218 __func__, dut->nan_pmk_len);
219 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex pmk", __func__);
220 nan_hex_dump(dut, &dut->nan_pmk[0], dut->nan_pmk_len);
221 }
222
Rakesh Sunki14bff1d2017-03-30 14:47:55 -0700223 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200224 return 0;
225}
226
227
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700228void nan_print_further_availability_chan(struct sigma_dut *dut,
229 u8 num_chans,
230 NanFurtherAvailabilityChannel *fachan)
231{
232 int idx;
233
234 sigma_dut_print(dut, DUT_MSG_INFO,
235 "********Printing FurtherAvailabilityChan Info******");
236 sigma_dut_print(dut, DUT_MSG_INFO, "Numchans:%d", num_chans);
237 for (idx = 0; idx < num_chans; idx++) {
238 sigma_dut_print(dut, DUT_MSG_INFO,
239 "[%d]: NanAvailDuration:%d class_val:%02x channel:%d",
240 idx, fachan->entry_control,
241 fachan->class_val, fachan->channel);
242 sigma_dut_print(dut, DUT_MSG_INFO,
243 "[%d]: mapid:%d Availability bitmap:%08x",
244 idx, fachan->mapid,
245 fachan->avail_interval_bitmap);
246 }
247 sigma_dut_print(dut, DUT_MSG_INFO,
248 "*********************Done**********************");
249}
250
251
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200252int sigma_nan_enable(struct sigma_dut *dut, struct sigma_conn *conn,
253 struct sigma_cmd *cmd)
254{
255 const char *master_pref = get_param(cmd, "MasterPref");
256 const char *rand_fac = get_param(cmd, "RandFactor");
257 const char *hop_count = get_param(cmd, "HopCount");
258 const char *high_tsf = get_param(cmd, "HighTSF");
259 const char *sdftx_band = get_param(cmd, "SDFTxBand");
260 const char *oper_chan = get_param(cmd, "oper_chn");
261 const char *further_avail_ind = get_param(cmd, "FurtherAvailInd");
262 const char *band = get_param(cmd, "Band");
263 const char *only_5g = get_param(cmd, "5GOnly");
Rakesh Sunki38dd72e2017-03-30 14:47:55 -0700264 const char *nan_availability = get_param(cmd, "NANAvailability");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200265 struct timespec abstime;
266 NanEnableRequest req;
267
268 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200269 req.cluster_low = 0;
270 req.cluster_high = 0xFFFF;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700271 req.master_pref = 100;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200272
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700273 /* This is a debug hack to beacon in channel 11 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200274 if (oper_chan) {
275 req.config_2dot4g_support = 1;
276 req.support_2dot4g_val = 111;
277 }
278
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200279 if (master_pref) {
280 int master_pref_val = strtoul(master_pref, NULL, 0);
281
282 req.master_pref = master_pref_val;
283 }
284
285 if (rand_fac) {
286 int rand_fac_val = strtoul(rand_fac, NULL, 0);
287
288 req.config_random_factor_force = 1;
289 req.random_factor_force_val = rand_fac_val;
290 }
291
292 if (hop_count) {
293 int hop_count_val = strtoul(hop_count, NULL, 0);
294
295 req.config_hop_count_force = 1;
296 req.hop_count_force_val = hop_count_val;
297 }
298
299 if (sdftx_band) {
300 if (strcasecmp(sdftx_band, "5G") == 0) {
301 req.config_2dot4g_support = 1;
302 req.support_2dot4g_val = 0;
303 }
304 }
305
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700306 sigma_dut_print(dut, DUT_MSG_INFO,
307 "%s: Setting dual band 2.4 GHz and 5 GHz by default",
308 __func__);
309 /* Enable 2.4 GHz support */
310 req.config_2dot4g_support = 1;
311 req.support_2dot4g_val = 1;
312 req.config_2dot4g_beacons = 1;
313 req.beacon_2dot4g_val = 1;
314 req.config_2dot4g_sdf = 1;
315 req.sdf_2dot4g_val = 1;
316
317 /* Enable 5 GHz support */
318 req.config_support_5g = 1;
319 req.support_5g_val = 1;
320 req.config_5g_beacons = 1;
321 req.beacon_5g_val = 1;
322 req.config_5g_sdf = 1;
323 req.sdf_5g_val = 1;
324
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200325 if (band) {
326 if (strcasecmp(band, "24G") == 0) {
327 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700328 "Band 2.4 GHz selected, disable 5 GHz");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 /* Disable 5G support */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700330 req.config_support_5g = 1;
331 req.support_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200332 req.config_5g_beacons = 1;
333 req.beacon_5g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700334 req.config_5g_sdf = 1;
335 req.sdf_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200336 }
337 }
338
339 if (further_avail_ind) {
340 sigma_dut_print(dut, DUT_MSG_INFO, "FAM Test Enabled");
341 if (strcasecmp(further_avail_ind, "tx") == 0) {
342 is_fam = 1;
343 nan_further_availability_tx(dut, conn, cmd);
344 return 0;
345 } else if (strcasecmp(further_avail_ind, "rx") == 0) {
346 nan_further_availability_rx(dut, conn, cmd);
347 return 0;
348 }
349 }
350
351 if (only_5g && atoi(only_5g)) {
352 sigma_dut_print(dut, DUT_MSG_INFO, "5GHz only enabled");
353 req.config_2dot4g_support = 1;
354 req.support_2dot4g_val = 1;
355 req.config_2dot4g_beacons = 1;
356 req.beacon_2dot4g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700357 req.config_2dot4g_sdf = 1;
358 req.sdf_2dot4g_val = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200359 }
360
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700361 nan_enable_request(0, global_interface_handle, &req);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700362
Rakesh Sunki38dd72e2017-03-30 14:47:55 -0700363 if (nan_availability) {
364 int cmd_len, size;
365 NanDebugParams cfg_debug;
366
367 sigma_dut_print(dut, DUT_MSG_INFO,
368 "%s given string nan_availability: %s",
369 __func__, nan_availability);
370 memset(&cfg_debug, 0, sizeof(NanDebugParams));
371 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_AVAILABILITY;
372 size = NAN_MAX_DEBUG_MESSAGE_DATA_LEN;
373 nan_parse_hex_string(dut, &nan_availability[2],
374 &cfg_debug.debug_cmd_data[0], &size);
375 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex nan_availability",
376 __func__);
377 nan_hex_dump(dut, &cfg_debug.debug_cmd_data[0], size);
378 cmd_len = size + sizeof(u32);
379 nan_debug_command_config(0, global_interface_handle,
380 cfg_debug, cmd_len);
381 }
382
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700383 /* To ensure sta_get_events to get the events
384 * only after joining the NAN cluster. */
385 abstime.tv_sec = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200386 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700387 wait(abstime);
388
389 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200390}
391
392
393int sigma_nan_disable(struct sigma_dut *dut, struct sigma_conn *conn,
394 struct sigma_cmd *cmd)
395{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200396 struct timespec abstime;
397
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700398 nan_disable_request(0, global_interface_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200399
400 abstime.tv_sec = 4;
401 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700402 wait(abstime);
403
404 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200405}
406
407
408int sigma_nan_config_enable(struct sigma_dut *dut, struct sigma_conn *conn,
409 struct sigma_cmd *cmd)
410{
411 const char *master_pref = get_param(cmd, "MasterPref");
412 const char *rand_fac = get_param(cmd, "RandFactor");
413 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700414 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200415 struct timespec abstime;
416 NanConfigRequest req;
417
418 memset(&req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200419 req.config_rssi_proximity = 1;
420 req.rssi_proximity = 70;
421
422 if (master_pref) {
423 int master_pref_val = strtoul(master_pref, NULL, 0);
424
425 req.config_master_pref = 1;
426 req.master_pref = master_pref_val;
427 }
428
429 if (rand_fac) {
430 int rand_fac_val = strtoul(rand_fac, NULL, 0);
431
432 req.config_random_factor_force = 1;
433 req.random_factor_force_val = rand_fac_val;
434 }
435
436 if (hop_count) {
437 int hop_count_val = strtoul(hop_count, NULL, 0);
438
439 req.config_hop_count_force = 1;
440 req.hop_count_force_val = hop_count_val;
441 }
442
Rakesh Sunki107356c2017-03-30 14:47:55 -0700443 ret = nan_config_request(0, global_interface_handle, &req);
444 if (ret != WIFI_SUCCESS)
445 send_resp(dut, conn, SIGMA_ERROR, "NAN config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200446
447 abstime.tv_sec = 4;
448 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700449 wait(abstime);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200450
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700451 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200452}
453
454
455static int sigma_nan_subscribe_request(struct sigma_dut *dut,
456 struct sigma_conn *conn,
457 struct sigma_cmd *cmd)
458{
459 const char *subscribe_type = get_param(cmd, "SubscribeType");
460 const char *service_name = get_param(cmd, "ServiceName");
461 const char *disc_range = get_param(cmd, "DiscoveryRange");
462 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
463 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
464 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
465 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
466 const char *include_bit = get_param(cmd, "IncludeBit");
467 const char *mac = get_param(cmd, "MAC");
468 const char *srf_type = get_param(cmd, "SRFType");
469 NanSubscribeRequest req;
470 int filter_len_rx = 0, filter_len_tx = 0;
471 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
472 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -0700473 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200474
475 memset(&req, 0, sizeof(NanSubscribeRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200476 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -0700477 req.period = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200478 req.subscribe_type = 1;
479 req.serviceResponseFilter = 1; /* MAC */
480 req.serviceResponseInclude = 0;
481 req.ssiRequiredForMatchIndication = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700482 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200483 req.subscribe_count = 0;
484
485 if (subscribe_type) {
486 if (strcasecmp(subscribe_type, "Active") == 0) {
487 req.subscribe_type = 1;
488 } else if (strcasecmp(subscribe_type, "Passive") == 0) {
489 req.subscribe_type = 0;
490 } else if (strcasecmp(subscribe_type, "Cancel") == 0) {
491 NanSubscribeCancelRequest req;
492
493 memset(&req, 0, sizeof(NanSubscribeCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -0700494 ret = nan_subscribe_cancel_request(
495 0, global_interface_handle, &req);
496 if (ret != WIFI_SUCCESS) {
497 send_resp(dut, conn, SIGMA_ERROR,
498 "NAN subscribe cancel request failed");
499 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200500 return 0;
501 }
502 }
503
504 if (disc_range)
505 req.rssi_threshold_flag = atoi(disc_range);
506
507 if (sdftx_dw)
508 req.subscribe_count = atoi(sdftx_dw);
509
510 /* Check this once again if config can be called here (TBD) */
511 if (discrange_ltd)
512 req.rssi_threshold_flag = atoi(discrange_ltd);
513
514 if (include_bit) {
515 int include_bit_val = atoi(include_bit);
516
517 req.serviceResponseInclude = include_bit_val;
518 sigma_dut_print(dut, DUT_MSG_INFO, "Includebit set %d",
519 req.serviceResponseInclude);
520 }
521
522 if (srf_type) {
523 int srf_type_val = atoi(srf_type);
524
525 if (srf_type_val == 1)
526 req.serviceResponseFilter = 0; /* Bloom */
527 else
528 req.serviceResponseFilter = 1; /* MAC */
529 req.useServiceResponseFilter = 1;
530 sigma_dut_print(dut, DUT_MSG_INFO, "srfFilter %d",
531 req.serviceResponseFilter);
532 }
533
534 if (mac) {
535 sigma_dut_print(dut, DUT_MSG_INFO, "MAC_ADDR List %s", mac);
536 req.num_intf_addr_present = nan_parse_mac_address_list(
537 dut, mac, &req.intf_addr[0][0],
538 NAN_MAX_SUBSCRIBE_MAX_ADDRESS);
539 }
540
541 memset(input_rx, 0, sizeof(input_rx));
542 memset(input_tx, 0, sizeof(input_tx));
543 if (rx_match_filter) {
544 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
545 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
546 filter_len_rx);
547 }
548 if (tx_match_filter) {
549 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
550 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
551 filter_len_tx);
552 }
553
554 if (tx_match_filter) {
555 req.tx_match_filter_len = filter_len_tx;
556 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
557 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
558 }
559 if (rx_match_filter) {
560 req.rx_match_filter_len = filter_len_rx;
561 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
562 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
563 }
564
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700565 if (service_name) {
566 strlcpy((char *) req.service_name, service_name,
567 strlen(service_name) + 1);
568 req.service_name_len = strlen(service_name);
569 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200570
Rakesh Sunki107356c2017-03-30 14:47:55 -0700571 ret = nan_subscribe_request(0, global_interface_handle, &req);
572 if (ret != WIFI_SUCCESS) {
573 send_resp(dut, conn, SIGMA_ERROR,
574 "NAN subscribe request failed");
575 }
576
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200577 return 0;
578}
579
580
Rakesh Sunkid7344c02017-03-30 14:47:55 -0700581static int sigma_ndp_configure_band(struct sigma_dut *dut,
582 struct sigma_conn *conn,
583 struct sigma_cmd *cmd,
584 NdpSupportedBand band_config_val)
585{
586 wifi_error ret;
587 NanDebugParams cfg_debug;
588 int size;
589
590 memset(&cfg_debug, 0, sizeof(NanDebugParams));
591 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SUPPORTED_BANDS;
592 memcpy(cfg_debug.debug_cmd_data, &band_config_val, sizeof(int));
593 sigma_dut_print(dut, DUT_MSG_INFO, "%s:setting debug cmd=0x%x",
594 __func__, cfg_debug.cmd);
595 size = sizeof(u32) + sizeof(int);
596 ret = nan_debug_command_config(0, global_interface_handle, cfg_debug,
597 size);
598 if (ret != WIFI_SUCCESS)
599 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
600
601 return 0;
602}
603
604
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700605static int sigma_nan_data_request(struct sigma_dut *dut,
606 struct sigma_conn *conn,
607 struct sigma_cmd *cmd)
608{
609 const char *ndp_security = get_param(cmd, "DataPathSecurity");
610 const char *ndp_resp_mac = get_param(cmd, "RespNanMac");
611 const char *include_immutable = get_param(cmd, "includeimmutable");
612 const char *avoid_channel = get_param(cmd, "avoidchannel");
613 const char *invalid_nan_schedule = get_param(cmd, "InvalidNANSchedule");
614 const char *map_order = get_param(cmd, "maporder");
615 wifi_error ret;
616 NanDataPathInitiatorRequest init_req;
617 NanDebugParams cfg_debug;
618 int size;
619
620 memset(&init_req, 0, sizeof(NanDataPathInitiatorRequest));
621
622 if (ndp_security) {
623 if (strcasecmp(ndp_security, "open") == 0)
624 init_req.ndp_cfg.security_cfg =
625 NAN_DP_CONFIG_NO_SECURITY;
626 else if (strcasecmp(ndp_security, "secure") == 0)
627 init_req.ndp_cfg.security_cfg = NAN_DP_CONFIG_SECURITY;
628 }
629
630 if (include_immutable) {
631 int include_immutable_val = 0;
632
633 memset(&cfg_debug, 0, sizeof(NanDebugParams));
634 cfg_debug.cmd = NAN_TEST_MODE_CMD_NDP_INCLUDE_IMMUTABLE;
635 include_immutable_val = atoi(include_immutable);
636 memcpy(cfg_debug.debug_cmd_data, &include_immutable_val,
637 sizeof(int));
638 size = sizeof(u32) + sizeof(int);
639 nan_debug_command_config(0, global_interface_handle,
640 cfg_debug, size);
641 }
642
643 if (avoid_channel) {
644 int avoid_channel_freq = 0;
645
646 memset(&cfg_debug, 0, sizeof(NanDebugParams));
647 avoid_channel_freq = channel_to_freq(atoi(avoid_channel));
648 cfg_debug.cmd = NAN_TEST_MODE_CMD_NDP_AVOID_CHANNEL;
649 memcpy(cfg_debug.debug_cmd_data, &avoid_channel_freq,
650 sizeof(int));
651 size = sizeof(u32) + sizeof(int);
652 nan_debug_command_config(0, global_interface_handle,
653 cfg_debug, size);
654 }
655
656 if (invalid_nan_schedule) {
657 int invalid_nan_schedule_type = 0;
658
659 memset(&cfg_debug, 0, sizeof(NanDebugParams));
660 invalid_nan_schedule_type = atoi(invalid_nan_schedule);
661 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_TYPE;
662 memcpy(cfg_debug.debug_cmd_data,
663 &invalid_nan_schedule_type, sizeof(int));
664 size = sizeof(u32) + sizeof(int);
665 sigma_dut_print(dut, DUT_MSG_INFO,
666 "%s: invalid schedule type: cmd type = %d and command data = %d",
667 __func__, cfg_debug.cmd,
668 invalid_nan_schedule_type);
669 nan_debug_command_config(0, global_interface_handle,
670 cfg_debug, size);
671 }
672
673 if (map_order) {
674 int map_order_val = 0;
675
676 memset(&cfg_debug, 0, sizeof(NanDebugParams));
677 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_AVAILABILITY_MAP_ORDER;
678 map_order_val = atoi(map_order);
679 memcpy(cfg_debug.debug_cmd_data, &map_order_val, sizeof(int));
680 size = sizeof(u32) + sizeof(int);
681 sigma_dut_print(dut, DUT_MSG_INFO,
682 "%s: map order: cmd type = %d and command data = %d",
683 __func__,
684 cfg_debug.cmd, invalid_nan_schedule_type);
685 nan_debug_command_config(0, global_interface_handle,
686 cfg_debug, size);
687 }
688
689 /*
690 * Setting this flag, so that interface for ping6 command
691 * is set appropriately in traffic_send_ping().
692 */
693 dut->ndp_enable = 1;
694
695 /*
696 * Intended sleep after NAN data interface create
697 * before the NAN data request
698 */
699 sleep(4);
700
701 init_req.requestor_instance_id = global_match_handle;
702 strlcpy((char *) init_req.ndp_iface, "nan0",
703 sizeof(init_req.ndp_iface));
704
705 if (ndp_resp_mac) {
706 nan_parse_mac_address(dut, ndp_resp_mac,
707 init_req.peer_disc_mac_addr);
708 sigma_dut_print(
709 dut, DUT_MSG_INFO, "PEER MAC ADDR: " MAC_ADDR_STR,
710 MAC_ADDR_ARRAY(init_req.peer_disc_mac_addr));
711 } else {
712 memcpy(init_req.peer_disc_mac_addr, global_peer_mac_addr,
713 sizeof(init_req.peer_disc_mac_addr));
714 }
715
716 /* Not requesting the channel and letting FW decide */
717 if (dut->sta_channel == 0) {
718 init_req.channel_request_type = NAN_DP_CHANNEL_NOT_REQUESTED;
719 init_req.channel = 0;
720 } else {
721 init_req.channel_request_type = NAN_DP_FORCE_CHANNEL_SETUP;
722 init_req.channel = channel_to_freq(dut->sta_channel);
723 }
724 sigma_dut_print(dut, DUT_MSG_INFO,
725 "%s: Initiator Request: Channel = %d Channel Request Type = %d",
726 __func__, init_req.channel,
727 init_req.channel_request_type);
728
729 if (dut->nan_pmk_len == NAN_PMK_INFO_LEN) {
730 memcpy(&init_req.key_info.body.pmk_info.pmk[0],
731 &dut->nan_pmk[0], NAN_PMK_INFO_LEN);
732 init_req.key_info.body.pmk_info.pmk_len = NAN_PMK_INFO_LEN;
733 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
734 __func__,
735 init_req.key_info.body.pmk_info.pmk_len);
736 }
737
738 ret = nan_data_request_initiator(0, global_interface_handle, &init_req);
739 if (ret != WIFI_SUCCESS) {
740 send_resp(dut, conn, SIGMA_ERROR,
741 "Unable to initiate nan data request");
742 return 0;
743 }
744
745 return 0;
746}
747
748
Rakesh Sunkia5cc2842017-03-30 14:47:55 -0700749static int sigma_nan_data_response(struct sigma_dut *dut,
750 struct sigma_conn *conn,
751 struct sigma_cmd *cmd)
752{
753 const char *ndl_response = get_param(cmd, "NDLresponse");
754 const char *m4_response_type = get_param(cmd, "M4ResponseType");
755 wifi_error ret;
756 NanDebugParams cfg_debug;
757 int size;
758
759 if (ndl_response) {
760 int auto_responder_mode_val = 0;
761
762 sigma_dut_print(dut, DUT_MSG_INFO,
763 "%s: ndl_response = (%s) is passed",
764 __func__, ndl_response);
765 memset(&cfg_debug, 0, sizeof(NanDebugParams));
766 cfg_debug.cmd = NAN_TEST_MODE_CMD_AUTO_RESPONDER_MODE;
767 if (strcasecmp(ndl_response, "Auto") == 0) {
768 auto_responder_mode_val = NAN_DATA_RESPONDER_MODE_AUTO;
769 } else if (strcasecmp(ndl_response, "Reject") == 0) {
770 auto_responder_mode_val =
771 NAN_DATA_RESPONDER_MODE_REJECT;
772 } else if (strcasecmp(ndl_response, "Accept") == 0) {
773 auto_responder_mode_val =
774 NAN_DATA_RESPONDER_MODE_ACCEPT;
775 } else if (strcasecmp(ndl_response, "Counter") == 0) {
776 auto_responder_mode_val =
777 NAN_DATA_RESPONDER_MODE_COUNTER;
778 } else {
779 sigma_dut_print(dut, DUT_MSG_ERROR,
780 "%s: Invalid ndl_response",
781 __func__);
782 return 0;
783 }
784 memcpy(cfg_debug.debug_cmd_data, &auto_responder_mode_val,
785 sizeof(int));
786 size = sizeof(u32) + sizeof(int);
787 ret = nan_debug_command_config(0, global_interface_handle,
788 cfg_debug, size);
789 if (ret != WIFI_SUCCESS) {
790 send_resp(dut, conn, SIGMA_ERROR,
791 "Nan config request failed");
792 }
793 }
794
795 if (m4_response_type) {
796 int m4_response_type_val = 0;
797
798 sigma_dut_print(dut, DUT_MSG_INFO,
799 "%s: m4_response_type = (%s) is passed",
800 __func__, m4_response_type);
801 memset(&cfg_debug, 0, sizeof(NanDebugParams));
802 cfg_debug.cmd = NAN_TEST_MODE_CMD_M4_RESPONSE_TYPE;
803 if (strcasecmp(m4_response_type, "Accept") == 0)
804 m4_response_type_val = NAN_DATA_PATH_M4_RESPONSE_ACCEPT;
805 else if (strcasecmp(m4_response_type, "Reject") == 0)
806 m4_response_type_val = NAN_DATA_PATH_M4_RESPONSE_REJECT;
807 else if (strcasecmp(m4_response_type, "BadMic") == 0)
808 m4_response_type_val = NAN_DATA_PATH_M4_RESPONSE_BADMIC;
809
810 memcpy(cfg_debug.debug_cmd_data, &m4_response_type_val,
811 sizeof(int));
812 size = sizeof(u32) + sizeof(int);
813 ret = nan_debug_command_config(0, global_interface_handle,
814 cfg_debug, size);
815 if (ret != WIFI_SUCCESS) {
816 send_resp(dut, conn, SIGMA_ERROR,
817 "Nan config request failed");
818 }
819 }
820
821 return 0;
822}
823
824
Rakesh Sunki8a630b82017-03-30 14:47:55 -0700825static int sigma_nan_data_end(struct sigma_dut *dut, struct sigma_cmd *cmd)
826{
827 const char *nmf_security_config = get_param(cmd, "Security");
828 NanDataPathEndRequest req;
829 NanDebugParams cfg_debug;
830 int size;
831
832 memset(&req, 0, sizeof(NanDataPathEndRequest));
833 memset(&cfg_debug, 0, sizeof(NanDebugParams));
834 if (nmf_security_config) {
835 int nmf_security_config_val = 0;
836
837 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_NMF_CLEAR_CONFIG;
838 if (strcasecmp(nmf_security_config, "open") == 0)
839 nmf_security_config_val = NAN_NMF_CLEAR_ENABLE;
840 else if (strcasecmp(nmf_security_config, "secure") == 0)
841 nmf_security_config_val = NAN_NMF_CLEAR_DISABLE;
842 memcpy(cfg_debug.debug_cmd_data,
843 &nmf_security_config_val, sizeof(int));
844 size = sizeof(u32) + sizeof(int);
845 sigma_dut_print(dut, DUT_MSG_INFO,
846 "%s: nmf_security_config_val -- cmd type = %d and command data = %d",
847 __func__, cfg_debug.cmd,
848 nmf_security_config_val);
849 nan_debug_command_config(0, global_interface_handle,
850 cfg_debug, size);
851 }
852
853 req.num_ndp_instances = 1;
854 req.ndp_instance_id[0] = global_ndp_instance_id;
855
856 nan_data_end(0, global_interface_handle, &req);
857 return 0;
858}
859
860
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -0700861static int sigma_nan_range_request(struct sigma_dut *dut,
862 struct sigma_cmd *cmd)
863{
864 const char *dest_mac = get_param(cmd, "destmac");
865 NanSubscribeRequest req;
866
867 memset(&req, 0, sizeof(NanSubscribeRequest));
868 req.period = 1;
869 req.subscribe_type = NAN_SUBSCRIBE_TYPE_ACTIVE;
870 req.serviceResponseFilter = NAN_SRF_ATTR_BLOOM_FILTER;
871 req.serviceResponseInclude = NAN_SRF_INCLUDE_RESPOND;
872 req.ssiRequiredForMatchIndication = NAN_SSI_NOT_REQUIRED_IN_MATCH_IND;
873 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
874 req.subscribe_count = 0;
875 strlcpy((char *) req.service_name, DEFAULT_SVC,
876 NAN_MAX_SERVICE_NAME_LEN);
877 req.service_name_len = strlen((char *) req.service_name);
878
879 req.subscribe_id = global_subscribe_id;
880 req.sdea_params.ranging_state = 1;
881 req.sdea_params.range_report = NAN_ENABLE_RANGE_REPORT;
882 req.range_response_cfg.requestor_instance_id = global_match_handle;
883 req.range_response_cfg.ranging_response = NAN_RANGE_REQUEST_ACCEPT;
884 req.ranging_cfg.config_ranging_indications =
885 NAN_RANGING_INDICATE_CONTINUOUS_MASK;
886 if (dest_mac) {
887 nan_parse_mac_address(dut, dest_mac,
888 req.range_response_cfg.peer_addr);
889 sigma_dut_print(
890 dut, DUT_MSG_INFO, "peer mac addr: " MAC_ADDR_STR,
891 MAC_ADDR_ARRAY(req.range_response_cfg.peer_addr));
892 }
893 nan_subscribe_request(0, global_interface_handle, &req);
894
895 return 0;
896}
897
898
899static int sigma_nan_cancel_range(struct sigma_dut *dut,
900 struct sigma_cmd *cmd)
901{
902 const char *dest_mac = get_param(cmd, "destmac");
903 NanPublishRequest req;
904
905 memset(&req, 0, sizeof(NanPublishRequest));
906 req.ttl = 0;
907 req.period = 1;
908 req.publish_match_indicator = 1;
909 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
910 req.tx_type = NAN_TX_TYPE_BROADCAST;
911 req.publish_count = 0;
912 strlcpy((char *) req.service_name, DEFAULT_SVC,
913 NAN_MAX_SERVICE_NAME_LEN);
914 req.service_name_len = strlen((char *) req.service_name);
915 req.publish_id = global_publish_id;
916 req.range_response_cfg.ranging_response = NAN_RANGE_REQUEST_CANCEL;
917 if (dest_mac) {
918 nan_parse_mac_address(dut, dest_mac,
919 req.range_response_cfg.peer_addr);
920 sigma_dut_print(
921 dut, DUT_MSG_INFO, "peer mac addr: " MAC_ADDR_STR,
922 MAC_ADDR_ARRAY(req.range_response_cfg.peer_addr));
923 }
924 nan_publish_request(0, global_interface_handle, &req);
925
926 return 0;
927}
928
929
Rakesh Sunkib2b65162017-03-30 14:47:55 -0700930static int sigma_nan_schedule_update(struct sigma_dut *dut,
931 struct sigma_cmd *cmd)
932{
933 const char *schedule_update_type = get_param(cmd, "type");
934 const char *channel_availability = get_param(cmd,
935 "ChannelAvailability");
936 const char *responder_nmi_mac = get_param(cmd, "ResponderNMI");
937 NanDebugParams cfg_debug;
938 int size = 0;
939
940 memset(&cfg_debug, 0, sizeof(NanDebugParams));
941
942 if (!schedule_update_type)
943 return 0;
944
945 if (strcasecmp(schedule_update_type, "ULWnotify") == 0) {
946 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_ULW_NOTIFY;
947 size = sizeof(u32);
948 sigma_dut_print(dut, DUT_MSG_INFO,
949 "%s: Schedule Update cmd type = %d", __func__,
950 cfg_debug.cmd);
951 if (channel_availability) {
952 int channel_availability_val;
953
954 channel_availability_val = atoi(channel_availability);
955 size += sizeof(int);
956 memcpy(cfg_debug.debug_cmd_data,
957 &channel_availability_val, sizeof(int));
958 sigma_dut_print(dut, DUT_MSG_INFO,
959 "%s: Schedule Update cmd data = %d size = %d",
960 __func__, channel_availability_val,
961 size);
962 }
963 } else if (strcasecmp(schedule_update_type, "NDLnegotiate") == 0) {
964 cfg_debug.cmd =
965 NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NEGOTIATE;
966 size = sizeof(u32);
967 sigma_dut_print(dut, DUT_MSG_INFO,
968 "%s: Schedule Update cmd type = %d", __func__,
969 cfg_debug.cmd);
970 if (responder_nmi_mac) {
971 u8 responder_nmi_mac_addr[NAN_MAC_ADDR_LEN];
972
973 nan_parse_mac_address(dut, responder_nmi_mac,
974 responder_nmi_mac_addr);
975 size += NAN_MAC_ADDR_LEN;
976 memcpy(cfg_debug.debug_cmd_data, responder_nmi_mac_addr,
977 NAN_MAC_ADDR_LEN);
978 sigma_dut_print(dut, DUT_MSG_INFO,
979 "%s: RESPONDER NMI MAC: "MAC_ADDR_STR,
980 __func__,
981 MAC_ADDR_ARRAY(responder_nmi_mac_addr));
982 sigma_dut_print(dut, DUT_MSG_INFO,
983 "%s: Schedule Update: cmd size = %d",
984 __func__, size);
985 }
986 } else if (strcasecmp(schedule_update_type, "NDLnotify") == 0) {
987 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NOTIFY;
988 size = sizeof(u32);
989 sigma_dut_print(dut, DUT_MSG_INFO,
990 "%s: Schedule Update cmd type = %d", __func__,
991 cfg_debug.cmd);
992 }
993
994 nan_debug_command_config(0, global_interface_handle, cfg_debug, size);
995
996 return 0;
997}
998
999
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001000int config_post_disc_attr(void)
1001{
Rakesh Sunki107356c2017-03-30 14:47:55 -07001002 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001003 NanConfigRequest configReq;
1004
1005 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001006
1007 /* Configure Post disc attr */
1008 /* Make these defines and use correct enum */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001009 configReq.num_config_discovery_attr = 1;
1010 configReq.discovery_attr_val[0].type = 4; /* Further Nan discovery */
1011 configReq.discovery_attr_val[0].role = 0;
1012 configReq.discovery_attr_val[0].transmit_freq = 1;
1013 configReq.discovery_attr_val[0].duration = 0;
1014 configReq.discovery_attr_val[0].avail_interval_bitmap = 0x00000008;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001015
Rakesh Sunki107356c2017-03-30 14:47:55 -07001016 ret = nan_config_request(0, global_interface_handle, &configReq);
1017 if (ret != WIFI_SUCCESS) {
1018 sigma_dut_print(global_dut, DUT_MSG_INFO,
1019 "NAN config request failed while configuring post discovery attribute");
1020 }
1021
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001022 return 0;
1023}
1024
1025
1026int sigma_nan_publish_request(struct sigma_dut *dut, struct sigma_conn *conn,
1027 struct sigma_cmd *cmd)
1028{
1029 const char *publish_type = get_param(cmd, "PublishType");
1030 const char *service_name = get_param(cmd, "ServiceName");
1031 const char *disc_range = get_param(cmd, "DiscoveryRange");
1032 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
1033 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
1034 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
1035 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001036 const char *ndp_enable = get_param(cmd, "DataPathFlag");
1037 const char *ndp_type = get_param(cmd, "DataPathType");
1038 const char *data_path_security = get_param(cmd, "datapathsecurity");
Rakesh Sunki48060402017-03-30 14:47:55 -07001039 const char *range_required = get_param(cmd, "rangerequired");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001040 NanPublishRequest req;
1041 int filter_len_rx = 0, filter_len_tx = 0;
1042 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
1043 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -07001044 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001045
1046 memset(&req, 0, sizeof(NanPublishRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001047 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -07001048 req.period = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001049 req.publish_match_indicator = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001050 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
1051 req.tx_type = NAN_TX_TYPE_BROADCAST;
1052 req.publish_count = 0;
Rakesh Sunki0a0eea82017-03-30 14:47:55 -07001053 req.service_responder_policy = NAN_SERVICE_ACCEPT_POLICY_ALL;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001054
1055 if (service_name) {
1056 strlcpy((char *) req.service_name, service_name,
1057 strlen(service_name) + 1);
1058 req.service_name_len = strlen(service_name);
1059 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001060
1061 if (publish_type) {
1062 if (strcasecmp(publish_type, "Solicited") == 0) {
1063 req.publish_type = NAN_PUBLISH_TYPE_SOLICITED;
Rakesh Sunki62644ab2017-03-30 14:47:55 -07001064 } else if (strcasecmp(publish_type, "Unsolicited") == 0) {
1065 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001066 } else if (strcasecmp(publish_type, "Cancel") == 0) {
1067 NanPublishCancelRequest req;
1068
1069 memset(&req, 0, sizeof(NanPublishCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -07001070 ret = nan_publish_cancel_request(
1071 0, global_interface_handle, &req);
1072 if (ret != WIFI_SUCCESS) {
1073 send_resp(dut, conn, SIGMA_ERROR,
1074 "Unable to cancel nan publish request");
1075 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001076 return 0;
1077 }
1078 }
1079
1080 if (disc_range)
1081 req.rssi_threshold_flag = atoi(disc_range);
1082
1083 if (sdftx_dw)
1084 req.publish_count = atoi(sdftx_dw);
1085
1086 if (discrange_ltd)
1087 req.rssi_threshold_flag = atoi(discrange_ltd);
1088
1089 memset(input_rx, 0, sizeof(input_rx));
1090 memset(input_tx, 0, sizeof(input_tx));
1091 if (rx_match_filter) {
1092 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
1093 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
1094 filter_len_rx);
1095 }
1096 if (tx_match_filter) {
1097 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
1098 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
1099 filter_len_tx);
1100 }
1101
1102 if (is_fam == 1) {
1103 config_post_disc_attr();
1104 /* TODO: Add comments regarding this step */
1105 req.connmap = 0x10;
1106 }
1107
1108 if (tx_match_filter) {
1109 req.tx_match_filter_len = filter_len_tx;
1110 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
1111 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
1112 }
1113
1114 if (rx_match_filter) {
1115 req.rx_match_filter_len = filter_len_rx;
1116 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
1117 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
1118 }
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001119
1120 if (service_name) {
1121 strlcpy((char *) req.service_name, service_name,
1122 strlen(service_name) + 1);
1123 req.service_name_len = strlen(service_name);
1124 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001125
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001126 if (ndp_enable) {
1127 if (strcasecmp(ndp_enable, "enable") == 0)
1128 req.sdea_params.config_nan_data_path = 1;
1129 else
1130 req.sdea_params.config_nan_data_path = 0;
1131
1132 if (ndp_type)
1133 req.sdea_params.ndp_type = atoi(ndp_type);
1134
1135 if (data_path_security) {
1136 if (strcasecmp(data_path_security, "secure") == 0) {
1137 req.sdea_params.security_cfg =
1138 NAN_DP_CONFIG_SECURITY;
1139 } else if (strcasecmp(data_path_security, "open") ==
1140 0) {
1141 req.sdea_params.security_cfg =
1142 NAN_DP_CONFIG_NO_SECURITY;
1143 }
1144 }
1145
1146 if (dut->nan_pmk_len == NAN_PMK_INFO_LEN) {
1147 memcpy(&req.key_info.body.pmk_info.pmk[0],
1148 &dut->nan_pmk[0], NAN_PMK_INFO_LEN);
1149 req.key_info.body.pmk_info.pmk_len = NAN_PMK_INFO_LEN;
1150 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
1151 __func__, req.key_info.body.pmk_info.pmk_len);
1152 }
1153 }
Rakesh Sunki48060402017-03-30 14:47:55 -07001154 if (range_required && strcasecmp(range_required, "enable") == 0) {
1155 req.sdea_params.ranging_state = NAN_RANGING_ENABLE;
1156 req.sdea_params.range_report = NAN_ENABLE_RANGE_REPORT;
1157 }
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001158
Rakesh Sunki107356c2017-03-30 14:47:55 -07001159 ret = nan_publish_request(0, global_interface_handle, &req);
1160 if (ret != WIFI_SUCCESS)
1161 send_resp(dut, conn, SIGMA_ERROR, "Unable to publish");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001162
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001163 if (ndp_enable)
1164 dut->ndp_enable = 1;
1165
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001166 return 0;
1167}
1168
1169
1170static int nan_further_availability_rx(struct sigma_dut *dut,
1171 struct sigma_conn *conn,
1172 struct sigma_cmd *cmd)
1173{
1174 const char *master_pref = get_param(cmd, "MasterPref");
1175 const char *rand_fac = get_param(cmd, "RandFactor");
1176 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001177 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001178 struct timespec abstime;
1179
1180 NanEnableRequest req;
1181
1182 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001183 req.cluster_low = 0;
1184 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001185 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001186
1187 if (master_pref)
1188 req.master_pref = strtoul(master_pref, NULL, 0);
1189
1190 if (rand_fac) {
1191 int rand_fac_val = strtoul(rand_fac, NULL, 0);
1192
1193 req.config_random_factor_force = 1;
1194 req.random_factor_force_val = rand_fac_val;
1195 }
1196
1197 if (hop_count) {
1198 int hop_count_val = strtoul(hop_count, NULL, 0);
1199
1200 req.config_hop_count_force = 1;
1201 req.hop_count_force_val = hop_count_val;
1202 }
1203
Rakesh Sunki107356c2017-03-30 14:47:55 -07001204 ret = nan_enable_request(0, global_interface_handle, &req);
1205 if (ret != WIFI_SUCCESS) {
1206 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
1207 return 0;
1208 }
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001209
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001210 abstime.tv_sec = 4;
1211 abstime.tv_nsec = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001212 wait(abstime);
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001213
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001214 return 0;
1215}
1216
1217
1218static int nan_further_availability_tx(struct sigma_dut *dut,
1219 struct sigma_conn *conn,
1220 struct sigma_cmd *cmd)
1221{
1222 const char *master_pref = get_param(cmd, "MasterPref");
1223 const char *rand_fac = get_param(cmd, "RandFactor");
1224 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001225 wifi_error ret;
1226
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001227 NanEnableRequest req;
1228 NanConfigRequest configReq;
1229
1230 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001231 req.cluster_low = 0;
1232 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001233 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001234
1235 if (master_pref)
1236 req.master_pref = strtoul(master_pref, NULL, 0);
1237
1238 if (rand_fac) {
1239 int rand_fac_val = strtoul(rand_fac, NULL, 0);
1240
1241 req.config_random_factor_force = 1;
1242 req.random_factor_force_val = rand_fac_val;
1243 }
1244
1245 if (hop_count) {
1246 int hop_count_val = strtoul(hop_count, NULL, 0);
1247
1248 req.config_hop_count_force = 1;
1249 req.hop_count_force_val = hop_count_val;
1250 }
1251
Rakesh Sunki107356c2017-03-30 14:47:55 -07001252 ret = nan_enable_request(0, global_interface_handle, &req);
1253 if (ret != WIFI_SUCCESS) {
1254 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
1255 return 0;
1256 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001257
1258 /* Start the config of fam */
1259
1260 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001261
1262 configReq.config_fam = 1;
1263 configReq.fam_val.numchans = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001264 configReq.fam_val.famchan[0].entry_control = 0;
1265 configReq.fam_val.famchan[0].class_val = 81;
1266 configReq.fam_val.famchan[0].channel = 6;
1267 configReq.fam_val.famchan[0].mapid = 0;
1268 configReq.fam_val.famchan[0].avail_interval_bitmap = 0x7ffffffe;
1269
Rakesh Sunki107356c2017-03-30 14:47:55 -07001270 ret = nan_config_request(0, global_interface_handle, &configReq);
1271 if (ret != WIFI_SUCCESS)
1272 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001273
1274 return 0;
1275}
1276
1277
1278int sigma_nan_transmit_followup(struct sigma_dut *dut,
1279 struct sigma_conn *conn,
1280 struct sigma_cmd *cmd)
1281{
1282 const char *mac = get_param(cmd, "mac");
1283 const char *requestor_id = get_param(cmd, "RemoteInstanceId");
1284 const char *local_id = get_param(cmd, "LocalInstanceId");
1285 const char *service_name = get_param(cmd, "servicename");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001286 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001287 NanTransmitFollowupRequest req;
1288
1289 memset(&req, 0, sizeof(NanTransmitFollowupRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001290 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001291 req.addr[0] = 0xFF;
1292 req.addr[1] = 0xFF;
1293 req.addr[2] = 0xFF;
1294 req.addr[3] = 0xFF;
1295 req.addr[4] = 0xFF;
1296 req.addr[5] = 0xFF;
1297 req.priority = NAN_TX_PRIORITY_NORMAL;
1298 req.dw_or_faw = 0;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001299
1300 if (service_name)
1301 req.service_specific_info_len = strlen(service_name);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001302
1303 if (requestor_id) {
1304 /* int requestor_id_val = atoi(requestor_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001305 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001306 }
1307 if (local_id) {
1308 /* int local_id_val = atoi(local_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001309 req.publish_subscribe_id = global_header_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001310 }
1311
1312 if (mac == NULL) {
1313 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid MAC Address");
1314 return -1;
1315 }
1316 nan_parse_mac_address(dut, mac, req.addr);
1317
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001318 if (requestor_id)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001319 req.requestor_instance_id = strtoul(requestor_id, NULL, 0);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001320
Rakesh Sunki107356c2017-03-30 14:47:55 -07001321 ret = nan_transmit_followup_request(0, global_interface_handle, &req);
1322 if (ret != WIFI_SUCCESS) {
1323 send_resp(dut, conn, SIGMA_ERROR,
1324 "Unable to complete nan transmit followup");
1325 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001326
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001327 return 0;
1328}
1329
Rakesh Sunki107356c2017-03-30 14:47:55 -07001330
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001331/* NotifyResponse invoked to notify the status of the Request */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001332void nan_notify_response(transaction_id id, NanResponseMsg *rsp_data)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001333{
1334 sigma_dut_print(global_dut, DUT_MSG_INFO,
Rakesh Sunkifdbd60b2017-03-30 14:47:55 -07001335 "%s: status %d response_type %d",
1336 __func__, rsp_data->status, rsp_data->response_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001337 if (rsp_data->response_type == NAN_RESPONSE_STATS &&
1338 rsp_data->body.stats_response.stats_type ==
1339 NAN_STATS_ID_DE_TIMING_SYNC) {
1340 NanSyncStats *pSyncStats;
1341
1342 sigma_dut_print(global_dut, DUT_MSG_INFO,
1343 "%s: stats_type %d", __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001344 rsp_data->body.stats_response.stats_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001345 pSyncStats = &rsp_data->body.stats_response.data.sync_stats;
1346 memcpy(&global_nan_sync_stats, pSyncStats,
1347 sizeof(NanSyncStats));
1348 pthread_cond_signal(&gCondition);
Rakesh Sunki4d5912d2017-03-30 14:47:55 -07001349 } else if (rsp_data->response_type == NAN_RESPONSE_PUBLISH) {
1350 sigma_dut_print(global_dut, DUT_MSG_INFO,
1351 "%s: publish_id %d\n",
1352 __func__,
1353 rsp_data->body.publish_response.publish_id);
1354 global_publish_id = rsp_data->body.publish_response.publish_id;
1355 } else if (rsp_data->response_type == NAN_RESPONSE_SUBSCRIBE) {
1356 sigma_dut_print(global_dut, DUT_MSG_INFO,
1357 "%s: subscribe_id %d\n",
1358 __func__,
1359 rsp_data->body.subscribe_response.subscribe_id);
1360 global_subscribe_id =
1361 rsp_data->body.subscribe_response.subscribe_id;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001362 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001363}
1364
1365
1366/* Events Callback */
1367void nan_event_publish_replied(NanPublishRepliedInd *event)
1368{
1369 sigma_dut_print(global_dut, DUT_MSG_INFO,
1370 "%s: handle %d " MAC_ADDR_STR " rssi:%d",
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001371 __func__, event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001372 MAC_ADDR_ARRAY(event->addr), event->rssi_value);
1373 event_anyresponse = 1;
1374 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001375 "EventName,Replied,RemoteInstanceID %d,mac," MAC_ADDR_STR,
1376 (event->requestor_instance_id >> 24),
1377 MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001378}
1379
1380
1381/* Events Callback */
1382void nan_event_publish_terminated(NanPublishTerminatedInd *event)
1383{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001384 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: publish_id %d reason %d",
1385 __func__, event->publish_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001386}
1387
1388
1389/* Events Callback */
1390void nan_event_match(NanMatchInd *event)
1391{
1392 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001393 "%s: Pub/Sub Id %d remote_requestor_id %08x "
1394 MAC_ADDR_STR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001395 " rssi:%d",
1396 __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001397 event->publish_subscribe_id,
1398 event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001399 MAC_ADDR_ARRAY(event->addr),
1400 event->rssi_value);
1401 event_anyresponse = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001402 global_header_handle = event->publish_subscribe_id;
1403 global_match_handle = event->requestor_instance_id;
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001404 memcpy(global_peer_mac_addr, event->addr, sizeof(global_peer_mac_addr));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001405
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001406 /* memset(event_resp_buf, 0, sizeof(event_resp_buf)); */
1407 /* global_pub_sub_handle = event->header.handle; */
1408 /* Print the SSI */
1409 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing SSI:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001410 nan_hex_dump(global_dut, event->service_specific_info,
1411 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001412 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1413 "EventName,DiscoveryResult,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001414 MAC_ADDR_STR " ", (event->requestor_instance_id >> 24),
1415 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001416
1417 /* Print the match filter */
1418 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing sdf match filter:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001419 nan_hex_dump(global_dut, event->sdf_match_filter,
1420 event->sdf_match_filter_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001421
1422 /* Print the conn_capability */
1423 sigma_dut_print(global_dut, DUT_MSG_INFO,
1424 "Printing PostConnectivity Capability");
1425 if (event->is_conn_capability_valid) {
1426 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfd supported:%s",
1427 event->conn_capability.is_wfd_supported ?
1428 "yes" : "no");
1429 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfds supported:%s",
1430 (event->conn_capability.is_wfds_supported ?
1431 "yes" : "no"));
1432 sigma_dut_print(global_dut, DUT_MSG_INFO, "TDLS supported:%s",
1433 (event->conn_capability.is_tdls_supported ?
1434 "yes" : "no"));
1435 sigma_dut_print(global_dut, DUT_MSG_INFO, "IBSS supported:%s",
1436 (event->conn_capability.is_ibss_supported ?
1437 "yes" : "no"));
1438 sigma_dut_print(global_dut, DUT_MSG_INFO, "Mesh supported:%s",
1439 (event->conn_capability.is_mesh_supported ?
1440 "yes" : "no"));
1441 sigma_dut_print(global_dut, DUT_MSG_INFO, "Infra Field:%d",
1442 event->conn_capability.wlan_infra_field);
1443 } else {
1444 sigma_dut_print(global_dut, DUT_MSG_INFO,
1445 "PostConnectivity Capability not present");
1446 }
1447
1448 /* Print the discovery_attr */
1449 sigma_dut_print(global_dut, DUT_MSG_INFO,
1450 "Printing PostDiscovery Attribute");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001451 if (event->num_rx_discovery_attr) {
1452 int idx;
1453
1454 for (idx = 0; idx < event->num_rx_discovery_attr; idx++) {
1455 sigma_dut_print(global_dut, DUT_MSG_INFO,
1456 "PostDiscovery Attribute - %d", idx);
1457 sigma_dut_print(global_dut, DUT_MSG_INFO,
1458 "Conn Type:%d Device Role:%d"
1459 MAC_ADDR_STR,
1460 event->discovery_attr[idx].type,
1461 event->discovery_attr[idx].role,
1462 MAC_ADDR_ARRAY(event->discovery_attr[idx].addr));
1463 sigma_dut_print(global_dut, DUT_MSG_INFO,
1464 "Duration:%d MapId:%d "
1465 "avail_interval_bitmap:%04x",
1466 event->discovery_attr[idx].duration,
1467 event->discovery_attr[idx].mapid,
1468 event->discovery_attr[idx].avail_interval_bitmap);
1469 sigma_dut_print(global_dut, DUT_MSG_INFO,
1470 "Printing Mesh Id:");
1471 nan_hex_dump(global_dut,
1472 event->discovery_attr[idx].mesh_id,
1473 event->discovery_attr[idx].mesh_id_len);
1474 sigma_dut_print(global_dut, DUT_MSG_INFO,
1475 "Printing Infrastructure Ssid:");
1476 nan_hex_dump(global_dut,
1477 event->discovery_attr[idx].infrastructure_ssid_val,
1478 event->discovery_attr[idx].infrastructure_ssid_len);
1479 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001480 } else {
1481 sigma_dut_print(global_dut, DUT_MSG_INFO,
1482 "PostDiscovery attribute not present");
1483 }
1484
1485 /* Print the fam */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001486 if (event->num_chans) {
1487 nan_print_further_availability_chan(global_dut,
1488 event->num_chans,
1489 &event->famchan[0]);
1490 } else {
1491 sigma_dut_print(global_dut, DUT_MSG_INFO,
1492 "Further Availability Map not present");
1493 }
1494 if (event->cluster_attribute_len) {
1495 sigma_dut_print(global_dut, DUT_MSG_INFO,
1496 "Printing Cluster Attribute:");
1497 nan_hex_dump(global_dut, event->cluster_attribute,
1498 event->cluster_attribute_len);
1499 } else {
1500 sigma_dut_print(global_dut, DUT_MSG_INFO,
1501 "Cluster Attribute not present");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001502 }
1503}
1504
1505
1506/* Events Callback */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001507void nan_event_match_expired(NanMatchExpiredInd *event)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001508{
1509 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001510 "%s: publish_subscribe_id %d match_handle %08x",
1511 __func__, event->publish_subscribe_id,
1512 event->requestor_instance_id);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001513}
1514
1515
1516/* Events Callback */
1517void nan_event_subscribe_terminated(NanSubscribeTerminatedInd *event)
1518{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001519 sigma_dut_print(global_dut, DUT_MSG_INFO,
1520 "%s: Subscribe Id %d reason %d",
1521 __func__, event->subscribe_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001522}
1523
1524
1525/* Events Callback */
1526void nan_event_followup(NanFollowupInd *event)
1527{
1528 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001529 "%s: Publish/Subscribe Id %d match_handle 0x%08x dw_or_faw %d "
1530 MAC_ADDR_STR, __func__, event->publish_subscribe_id,
1531 event->requestor_instance_id, event->dw_or_faw,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001532 MAC_ADDR_ARRAY(event->addr));
1533
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001534 global_match_handle = event->publish_subscribe_id;
1535 global_header_handle = event->requestor_instance_id;
1536 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Printing SSI", __func__);
1537 nan_hex_dump(global_dut, event->service_specific_info,
1538 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001539 event_anyresponse = 1;
1540 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1541 "EventName,FollowUp,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001542 MAC_ADDR_STR " ", event->requestor_instance_id >> 24,
1543 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001544}
1545
1546
1547/* Events Callback */
1548void nan_event_disceng_event(NanDiscEngEventInd *event)
1549{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001550 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: event_type %d",
1551 __func__, event->event_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001552
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001553 if (event->event_type == NAN_EVENT_ID_JOINED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001554 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Joined cluster "
1555 MAC_ADDR_STR,
1556 __func__,
1557 MAC_ADDR_ARRAY(event->data.cluster.addr));
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001558 /* To ensure sta_get_events to get the events
1559 * only after joining the NAN cluster. */
1560 pthread_cond_signal(&gCondition);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001561 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001562 if (event->event_type == NAN_EVENT_ID_STARTED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001563 sigma_dut_print(global_dut, DUT_MSG_INFO,
1564 "%s: Started cluster " MAC_ADDR_STR,
1565 __func__,
1566 MAC_ADDR_ARRAY(event->data.cluster.addr));
1567 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001568 if (event->event_type == NAN_EVENT_ID_DISC_MAC_ADDR) {
1569 sigma_dut_print(global_dut, DUT_MSG_INFO,
1570 "%s: Discovery Mac Address "
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001571 MAC_ADDR_STR,
1572 __func__,
1573 MAC_ADDR_ARRAY(event->data.mac_addr.addr));
1574 memcpy(global_nan_mac_addr, event->data.mac_addr.addr,
1575 sizeof(global_nan_mac_addr));
1576 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001577}
1578
1579
1580/* Events Callback */
1581void nan_event_disabled(NanDisabledInd *event)
1582{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001583 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: reason %d",
1584 __func__, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001585 /* pthread_cond_signal(&gCondition); */
1586}
1587
1588
Rakesh Sunki4c086672017-03-30 14:47:55 -07001589/* Events callback */
1590static void ndp_event_data_indication(NanDataPathRequestInd *event)
1591{
1592 sigma_dut_print(global_dut, DUT_MSG_INFO,
1593 "%s: Service Instance Id: %d Peer Discovery MAC ADDR "
1594 MAC_ADDR_STR
1595 " NDP Instance Id: %d App Info len %d App Info %s",
1596 __func__,
1597 event->service_instance_id,
1598 MAC_ADDR_ARRAY(event->peer_disc_mac_addr),
1599 event->ndp_instance_id,
1600 event->app_info.ndp_app_info_len,
1601 event->app_info.ndp_app_info);
1602
1603 global_ndp_instance_id = event->ndp_instance_id;
1604}
1605
1606
1607/* Events callback */
1608static void ndp_event_data_confirm(NanDataPathConfirmInd *event)
1609{
1610 sigma_dut_print(global_dut, DUT_MSG_INFO,
1611 "Received NDP Confirm Indication");
1612
1613 global_ndp_instance_id = event->ndp_instance_id;
1614 if (system("ifconfig nan0 up") != 0) {
1615 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1616 "Failed to set nan interface up");
1617 return;
1618 }
1619 if (system("ip -6 route add fe80::/64 dev nan0 table local") != 0) {
1620 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1621 "Failed to run:ip -6 route replace fe80::/64 dev nan0 table local");
1622 return;
1623 }
1624}
1625
1626
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001627void * my_thread_function(void *ptr)
1628{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001629 wifi_event_loop(global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001630 pthread_exit(0);
1631 return (void *) NULL;
1632}
1633
1634
1635static NanCallbackHandler callbackHandler = {
1636 .NotifyResponse = nan_notify_response,
1637 .EventPublishReplied = nan_event_publish_replied,
1638 .EventPublishTerminated = nan_event_publish_terminated,
1639 .EventMatch = nan_event_match,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001640 .EventMatchExpired = nan_event_match_expired,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641 .EventSubscribeTerminated = nan_event_subscribe_terminated,
1642 .EventFollowup = nan_event_followup,
1643 .EventDiscEngEvent = nan_event_disceng_event,
1644 .EventDisabled = nan_event_disabled,
Rakesh Sunki4c086672017-03-30 14:47:55 -07001645 .EventDataRequest = ndp_event_data_indication,
1646 .EventDataConfirm = ndp_event_data_confirm,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001647};
1648
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001649
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001650void nan_init(struct sigma_dut *dut)
1651{
1652 pthread_t thread1; /* thread variables */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001653 wifi_error err = wifi_initialize(&global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001654
1655 if (err) {
1656 printf("wifi hal initialize failed\n");
1657 return;
1658 }
1659
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001660 global_interface_handle = wifi_get_iface_handle(global_wifi_handle,
1661 (char *) "wlan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001662 /* create threads 1 */
1663 pthread_create(&thread1, NULL, &my_thread_function, NULL);
1664
1665 pthread_mutex_init(&gMutex, NULL);
1666 pthread_cond_init(&gCondition, NULL);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001667 if (global_interface_handle)
1668 nan_register_handler(global_interface_handle, callbackHandler);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001669}
1670
1671
1672void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1673 struct sigma_cmd *cmd)
1674{
1675 sigma_dut_print(dut, DUT_MSG_INFO, "NAN sta_reset_default");
1676
1677 if (nan_state == 0) {
1678 nan_init(dut);
1679 nan_state = 1;
1680 }
1681 is_fam = 0;
1682 event_anyresponse = 0;
1683 global_dut = dut;
Rakesh Sunki7d37f412017-03-30 14:47:55 -07001684 memset(&dut->nan_pmk[0], 0, NAN_PMK_INFO_LEN);
1685 dut->nan_pmk_len = 0;
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001686 dut->sta_channel = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001687 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001688 memset(&global_nan_sync_stats, 0, sizeof(global_nan_sync_stats));
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001689
Rakesh Sunki8a630b82017-03-30 14:47:55 -07001690 sigma_nan_data_end(dut, cmd);
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001691 nan_data_interface_delete(0, global_interface_handle, (char *) "nan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001692 sigma_nan_disable(dut, conn, cmd);
1693}
1694
1695
1696int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1697 struct sigma_cmd *cmd)
1698{
1699 const char *program = get_param(cmd, "Prog");
1700 const char *nan_op = get_param(cmd, "NANOp");
1701 const char *method_type = get_param(cmd, "MethodType");
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001702 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001703 char resp_buf[100];
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001704 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001705
1706 if (program == NULL)
1707 return -1;
1708
1709 if (strcasecmp(program, "NAN") != 0) {
1710 send_resp(dut, conn, SIGMA_ERROR,
1711 "ErrorCode,Unsupported program");
1712 return 0;
1713 }
1714
1715 if (nan_op) {
1716 /*
1717 * NANOp has been specified.
1718 * We will build a nan_enable or nan_disable command.
1719 */
1720 if (strcasecmp(nan_op, "On") == 0) {
1721 if (sigma_nan_enable(dut, conn, cmd) == 0) {
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001722 ret = nan_data_interface_create(
1723 0, global_interface_handle,
1724 (char *) "nan0");
1725 if (ret != WIFI_SUCCESS) {
1726 sigma_dut_print(
1727 global_dut, DUT_MSG_ERROR,
1728 "Unable to create NAN data interface");
1729 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001730 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1731 MAC_ADDR_STR,
1732 MAC_ADDR_ARRAY(global_nan_mac_addr));
1733 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1734 } else {
1735 send_resp(dut, conn, SIGMA_ERROR,
1736 "NAN_ENABLE_FAILED");
1737 return -1;
1738 }
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001739
1740 if (band && strcasecmp(band, "24g") == 0) {
1741 sigma_dut_print(dut, DUT_MSG_INFO,
1742 "%s: Setting band to 2G Only",
1743 __func__);
1744 sigma_ndp_configure_band(
1745 dut, conn, cmd,
1746 NAN_DATA_PATH_SUPPORTED_BAND_2G);
1747 } else if (band && dut->sta_channel > 12) {
1748 sigma_ndp_configure_band(
1749 dut, conn, cmd,
1750 NAN_DATA_PATH_SUPPORT_DUAL_BAND);
1751 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001752 } else if (strcasecmp(nan_op, "Off") == 0) {
1753 sigma_nan_disable(dut, conn, cmd);
1754 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1755 }
1756 }
1757 if (nan_state && nan_op == NULL) {
1758 if (method_type) {
1759 if (strcasecmp(method_type, "Publish") == 0) {
1760 sigma_nan_publish_request(dut, conn, cmd);
1761 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1762 }
1763 if (strcasecmp(method_type, "Subscribe") == 0) {
1764 sigma_nan_subscribe_request(dut, conn, cmd);
1765 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1766 }
1767 if (strcasecmp(method_type, "Followup") == 0) {
1768 sigma_nan_transmit_followup(dut, conn, cmd);
1769 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1770 }
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001771 if (strcasecmp(method_type, "DataRequest") == 0) {
1772 sigma_nan_data_request(dut, conn, cmd);
1773 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1774 }
Rakesh Sunkia5cc2842017-03-30 14:47:55 -07001775 if (strcasecmp(method_type, "DataResponse") == 0) {
1776 sigma_dut_print(dut, DUT_MSG_INFO,
1777 "%s: method_type is DataResponse",
1778 __func__);
1779 sigma_nan_data_response(dut, conn, cmd);
1780 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1781 }
Rakesh Sunki8a630b82017-03-30 14:47:55 -07001782 if (strcasecmp(method_type, "DataEnd") == 0) {
1783 sigma_nan_data_end(dut, cmd);
1784 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1785 }
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -07001786 if (strcasecmp(method_type, "rangerequest") == 0) {
1787 sigma_dut_print(dut, DUT_MSG_INFO,
1788 "%s: method_type is rangerequest",
1789 __func__);
1790 sigma_nan_range_request(dut, cmd);
1791 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1792 }
1793 if (strcasecmp(method_type, "cancelrange") == 0) {
1794 sigma_dut_print(dut, DUT_MSG_INFO,
1795 "%s: method_type is cancelrange",
1796 __func__);
1797 sigma_nan_cancel_range(dut, cmd);
1798 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1799 }
Rakesh Sunkib2b65162017-03-30 14:47:55 -07001800 if (strcasecmp(method_type, "SchedUpdate") == 0) {
1801 sigma_dut_print(dut, DUT_MSG_INFO,
1802 "%s: method_type is SchedUpdate",
1803 __func__);
1804 sigma_nan_schedule_update(dut, cmd);
1805 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1806 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001807 } else {
1808 sigma_nan_config_enable(dut, conn, cmd);
1809 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1810 MAC_ADDR_STR,
1811 MAC_ADDR_ARRAY(global_nan_mac_addr));
1812 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1813 }
1814 }
1815
1816 return 0;
1817}
1818
1819
1820int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1821 struct sigma_cmd *cmd)
1822{
1823
1824 const char *program = get_param(cmd, "Program");
1825 const char *parameter = get_param(cmd, "Parameter");
1826 char resp_buf[100];
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001827 NanStatsRequest req;
1828 struct timespec abstime;
1829 u64 master_rank;
1830 u8 master_pref;
1831 u8 random_factor;
1832 u8 hop_count;
1833 u32 beacon_transmit_time;
1834 u32 ndp_channel_freq;
1835 u32 ndp_channel_freq2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001836
1837 if (program == NULL) {
1838 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Program Name");
1839 return -1;
1840 }
1841 if (strcasecmp(program, "NAN") != 0) {
1842 send_resp(dut, conn, SIGMA_ERROR,
1843 "ErrorCode,Unsupported program");
1844 return 0;
1845 }
1846
1847 if (parameter == NULL) {
1848 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Parameter");
1849 return -1;
1850 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001851
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001852 memset(&req, 0, sizeof(NanStatsRequest));
1853 req.stats_type = (NanStatsType) NAN_STATS_ID_DE_TIMING_SYNC;
1854 nan_stats_request(0, global_interface_handle, &req);
1855 /*
1856 * To ensure sta_get_events to get the events
1857 * only after joining the NAN cluster
1858 */
1859 abstime.tv_sec = 4;
1860 abstime.tv_nsec = 0;
1861 wait(abstime);
1862
1863 master_rank = global_nan_sync_stats.myRank;
1864 master_pref = (global_nan_sync_stats.myRank & 0xFF00000000000000) >> 56;
1865 random_factor = (global_nan_sync_stats.myRank & 0x00FF000000000000) >>
1866 48;
1867 hop_count = global_nan_sync_stats.currAmHopCount;
1868 beacon_transmit_time = global_nan_sync_stats.currAmBTT;
1869 ndp_channel_freq = global_nan_sync_stats.ndpChannelFreq;
1870 ndp_channel_freq2 = global_nan_sync_stats.ndpChannelFreq2;
1871
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001872 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001873 "%s: NanStatsRequest Master_pref:%02x, Random_factor:%02x, hop_count:%02x beacon_transmit_time:%d ndp_channel_freq:%d ndp_channel_freq2:%d",
1874 __func__, master_pref, random_factor,
1875 hop_count, beacon_transmit_time,
1876 ndp_channel_freq, ndp_channel_freq2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001877
1878 if (strcasecmp(parameter, "MasterPref") == 0) {
1879 snprintf(resp_buf, sizeof(resp_buf), "MasterPref,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001880 master_pref);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001881 } else if (strcasecmp(parameter, "MasterRank") == 0) {
1882 snprintf(resp_buf, sizeof(resp_buf), "MasterRank,0x%lx",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001883 master_rank);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001884 } else if (strcasecmp(parameter, "RandFactor") == 0) {
1885 snprintf(resp_buf, sizeof(resp_buf), "RandFactor,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001886 random_factor);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001887 } else if (strcasecmp(parameter, "HopCount") == 0) {
1888 snprintf(resp_buf, sizeof(resp_buf), "HopCount,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001889 hop_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001890 } else if (strcasecmp(parameter, "BeaconTransTime") == 0) {
1891 snprintf(resp_buf, sizeof(resp_buf), "BeaconTransTime 0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001892 beacon_transmit_time);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001893 } else if (strcasecmp(parameter, "NANStatus") == 0) {
1894 if (nan_state == 1)
1895 snprintf(resp_buf, sizeof(resp_buf), "On");
1896 else
1897 snprintf(resp_buf, sizeof(resp_buf), "Off");
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001898 } else if (strcasecmp(parameter, "NDPChannel") == 0) {
1899 if (ndp_channel_freq != 0 && ndp_channel_freq2 != 0) {
1900 snprintf(resp_buf, sizeof(resp_buf),
1901 "ndpchannel,%d,ndpchannel,%d",
1902 freq_to_channel(ndp_channel_freq),
1903 freq_to_channel(ndp_channel_freq2));
1904 } else if (ndp_channel_freq != 0) {
1905 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1906 freq_to_channel(ndp_channel_freq));
1907 } else if (ndp_channel_freq2 != 0) {
1908 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1909 freq_to_channel(ndp_channel_freq2));
1910 } else {
1911 sigma_dut_print(dut, DUT_MSG_ERROR,
1912 "%s: No Negotiated NDP Channels", __func__);
1913 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001914 } else {
1915 send_resp(dut, conn, SIGMA_ERROR, "Invalid Parameter");
1916 return 0;
1917 }
1918
1919 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1920 return 0;
1921}
1922
1923
1924int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1925 struct sigma_cmd *cmd)
1926{
1927 const char *action = get_param(cmd, "Action");
1928
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001929 if (!action)
1930 return 0;
1931
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 /* Check action for start, stop and get events. */
1933 if (strcasecmp(action, "Start") == 0) {
1934 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1935 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1936 } else if (strcasecmp(action, "Stop") == 0) {
1937 event_anyresponse = 0;
1938 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1939 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1940 } else if (strcasecmp(action, "Get") == 0) {
1941 if (event_anyresponse == 1) {
1942 send_resp(dut, conn, SIGMA_COMPLETE,
1943 global_event_resp_buf);
1944 } else {
1945 send_resp(dut, conn, SIGMA_COMPLETE, "EventList,NONE");
1946 }
1947 }
1948 return 0;
1949}
Rakesh Sunki4b75f962017-03-30 14:47:55 -07001950
1951#else /* #if NAN_CERT_VERSION */
1952
1953int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
1954 struct sigma_conn *conn,
1955 struct sigma_cmd *cmd)
1956{
1957 return 1;
1958}
1959
1960
1961int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1962 struct sigma_cmd *cmd)
1963{
1964 return 0;
1965
1966}
1967
1968
1969void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1970 struct sigma_cmd *cmd)
1971{
1972 return;
1973}
1974
1975
1976int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1977 struct sigma_cmd *cmd)
1978{
1979 return 0;
1980}
1981
1982
1983int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1984 struct sigma_cmd *cmd)
1985{
1986 return 0;
1987}
1988
1989#endif /* #if NAN_CERT_VERSION */