blob: 9a594c78f158ede9b96b786cdab434388a98820a [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__,
Rakesh Sunki9eaa6772017-04-04 11:37:03 -0700684 cfg_debug.cmd, map_order_val);
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700685 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();
Rakesh Sunkif680e0f2017-03-30 14:47:55 -07001104 /*
1105 * 8-bit bitmap which allows the Host to associate this publish
1106 * with a particular Post-NAN Connectivity attribute which has
1107 * been sent down in a NanConfigureRequest/NanEnableRequest
1108 * message. If the DE fails to find a configured Post-NAN
1109 * connectivity attributes referenced by the bitmap, the DE will
1110 * return an error code to the Host. If the Publish is
1111 * configured to use a Post-NAN Connectivity attribute and the
1112 * Host does not refresh the Post-NAN Connectivity attribute the
1113 * Publish will be canceled and the Host will be sent a
1114 * PublishTerminatedIndication message.
1115 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001116 req.connmap = 0x10;
1117 }
1118
1119 if (tx_match_filter) {
1120 req.tx_match_filter_len = filter_len_tx;
1121 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
1122 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
1123 }
1124
1125 if (rx_match_filter) {
1126 req.rx_match_filter_len = filter_len_rx;
1127 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
1128 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
1129 }
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001130
1131 if (service_name) {
1132 strlcpy((char *) req.service_name, service_name,
1133 strlen(service_name) + 1);
1134 req.service_name_len = strlen(service_name);
1135 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001136
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001137 if (ndp_enable) {
1138 if (strcasecmp(ndp_enable, "enable") == 0)
1139 req.sdea_params.config_nan_data_path = 1;
1140 else
1141 req.sdea_params.config_nan_data_path = 0;
1142
1143 if (ndp_type)
1144 req.sdea_params.ndp_type = atoi(ndp_type);
1145
1146 if (data_path_security) {
1147 if (strcasecmp(data_path_security, "secure") == 0) {
1148 req.sdea_params.security_cfg =
1149 NAN_DP_CONFIG_SECURITY;
1150 } else if (strcasecmp(data_path_security, "open") ==
1151 0) {
1152 req.sdea_params.security_cfg =
1153 NAN_DP_CONFIG_NO_SECURITY;
1154 }
1155 }
1156
1157 if (dut->nan_pmk_len == NAN_PMK_INFO_LEN) {
1158 memcpy(&req.key_info.body.pmk_info.pmk[0],
1159 &dut->nan_pmk[0], NAN_PMK_INFO_LEN);
1160 req.key_info.body.pmk_info.pmk_len = NAN_PMK_INFO_LEN;
1161 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
1162 __func__, req.key_info.body.pmk_info.pmk_len);
1163 }
1164 }
Rakesh Sunki48060402017-03-30 14:47:55 -07001165 if (range_required && strcasecmp(range_required, "enable") == 0) {
1166 req.sdea_params.ranging_state = NAN_RANGING_ENABLE;
1167 req.sdea_params.range_report = NAN_ENABLE_RANGE_REPORT;
1168 }
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001169
Rakesh Sunki107356c2017-03-30 14:47:55 -07001170 ret = nan_publish_request(0, global_interface_handle, &req);
1171 if (ret != WIFI_SUCCESS)
1172 send_resp(dut, conn, SIGMA_ERROR, "Unable to publish");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001173
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001174 if (ndp_enable)
1175 dut->ndp_enable = 1;
1176
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001177 return 0;
1178}
1179
1180
1181static int nan_further_availability_rx(struct sigma_dut *dut,
1182 struct sigma_conn *conn,
1183 struct sigma_cmd *cmd)
1184{
1185 const char *master_pref = get_param(cmd, "MasterPref");
1186 const char *rand_fac = get_param(cmd, "RandFactor");
1187 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001188 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001189 struct timespec abstime;
1190
1191 NanEnableRequest req;
1192
1193 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001194 req.cluster_low = 0;
1195 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001196 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001197
1198 if (master_pref)
1199 req.master_pref = strtoul(master_pref, NULL, 0);
1200
1201 if (rand_fac) {
1202 int rand_fac_val = strtoul(rand_fac, NULL, 0);
1203
1204 req.config_random_factor_force = 1;
1205 req.random_factor_force_val = rand_fac_val;
1206 }
1207
1208 if (hop_count) {
1209 int hop_count_val = strtoul(hop_count, NULL, 0);
1210
1211 req.config_hop_count_force = 1;
1212 req.hop_count_force_val = hop_count_val;
1213 }
1214
Rakesh Sunki107356c2017-03-30 14:47:55 -07001215 ret = nan_enable_request(0, global_interface_handle, &req);
1216 if (ret != WIFI_SUCCESS) {
1217 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
1218 return 0;
1219 }
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001220
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001221 abstime.tv_sec = 4;
1222 abstime.tv_nsec = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001223 wait(abstime);
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001224
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001225 return 0;
1226}
1227
1228
1229static int nan_further_availability_tx(struct sigma_dut *dut,
1230 struct sigma_conn *conn,
1231 struct sigma_cmd *cmd)
1232{
1233 const char *master_pref = get_param(cmd, "MasterPref");
1234 const char *rand_fac = get_param(cmd, "RandFactor");
1235 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001236 wifi_error ret;
1237
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001238 NanEnableRequest req;
1239 NanConfigRequest configReq;
1240
1241 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001242 req.cluster_low = 0;
1243 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001244 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001245
1246 if (master_pref)
1247 req.master_pref = strtoul(master_pref, NULL, 0);
1248
1249 if (rand_fac) {
1250 int rand_fac_val = strtoul(rand_fac, NULL, 0);
1251
1252 req.config_random_factor_force = 1;
1253 req.random_factor_force_val = rand_fac_val;
1254 }
1255
1256 if (hop_count) {
1257 int hop_count_val = strtoul(hop_count, NULL, 0);
1258
1259 req.config_hop_count_force = 1;
1260 req.hop_count_force_val = hop_count_val;
1261 }
1262
Rakesh Sunki107356c2017-03-30 14:47:55 -07001263 ret = nan_enable_request(0, global_interface_handle, &req);
1264 if (ret != WIFI_SUCCESS) {
1265 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
1266 return 0;
1267 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001268
1269 /* Start the config of fam */
1270
1271 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001272
1273 configReq.config_fam = 1;
1274 configReq.fam_val.numchans = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001275 configReq.fam_val.famchan[0].entry_control = 0;
1276 configReq.fam_val.famchan[0].class_val = 81;
1277 configReq.fam_val.famchan[0].channel = 6;
1278 configReq.fam_val.famchan[0].mapid = 0;
1279 configReq.fam_val.famchan[0].avail_interval_bitmap = 0x7ffffffe;
1280
Rakesh Sunki107356c2017-03-30 14:47:55 -07001281 ret = nan_config_request(0, global_interface_handle, &configReq);
1282 if (ret != WIFI_SUCCESS)
1283 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001284
1285 return 0;
1286}
1287
1288
1289int sigma_nan_transmit_followup(struct sigma_dut *dut,
1290 struct sigma_conn *conn,
1291 struct sigma_cmd *cmd)
1292{
1293 const char *mac = get_param(cmd, "mac");
1294 const char *requestor_id = get_param(cmd, "RemoteInstanceId");
1295 const char *local_id = get_param(cmd, "LocalInstanceId");
1296 const char *service_name = get_param(cmd, "servicename");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001297 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001298 NanTransmitFollowupRequest req;
1299
1300 memset(&req, 0, sizeof(NanTransmitFollowupRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001301 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001302 req.addr[0] = 0xFF;
1303 req.addr[1] = 0xFF;
1304 req.addr[2] = 0xFF;
1305 req.addr[3] = 0xFF;
1306 req.addr[4] = 0xFF;
1307 req.addr[5] = 0xFF;
1308 req.priority = NAN_TX_PRIORITY_NORMAL;
1309 req.dw_or_faw = 0;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001310
1311 if (service_name)
1312 req.service_specific_info_len = strlen(service_name);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001313
1314 if (requestor_id) {
1315 /* int requestor_id_val = atoi(requestor_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001316 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001317 }
1318 if (local_id) {
1319 /* int local_id_val = atoi(local_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001320 req.publish_subscribe_id = global_header_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001321 }
1322
1323 if (mac == NULL) {
1324 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid MAC Address");
1325 return -1;
1326 }
1327 nan_parse_mac_address(dut, mac, req.addr);
1328
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001329 if (requestor_id)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001330 req.requestor_instance_id = strtoul(requestor_id, NULL, 0);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001331
Rakesh Sunki107356c2017-03-30 14:47:55 -07001332 ret = nan_transmit_followup_request(0, global_interface_handle, &req);
1333 if (ret != WIFI_SUCCESS) {
1334 send_resp(dut, conn, SIGMA_ERROR,
1335 "Unable to complete nan transmit followup");
1336 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001337
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001338 return 0;
1339}
1340
Rakesh Sunki107356c2017-03-30 14:47:55 -07001341
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001342/* NotifyResponse invoked to notify the status of the Request */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001343void nan_notify_response(transaction_id id, NanResponseMsg *rsp_data)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001344{
1345 sigma_dut_print(global_dut, DUT_MSG_INFO,
Rakesh Sunkifdbd60b2017-03-30 14:47:55 -07001346 "%s: status %d response_type %d",
1347 __func__, rsp_data->status, rsp_data->response_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001348 if (rsp_data->response_type == NAN_RESPONSE_STATS &&
1349 rsp_data->body.stats_response.stats_type ==
1350 NAN_STATS_ID_DE_TIMING_SYNC) {
1351 NanSyncStats *pSyncStats;
1352
1353 sigma_dut_print(global_dut, DUT_MSG_INFO,
1354 "%s: stats_type %d", __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001355 rsp_data->body.stats_response.stats_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001356 pSyncStats = &rsp_data->body.stats_response.data.sync_stats;
1357 memcpy(&global_nan_sync_stats, pSyncStats,
1358 sizeof(NanSyncStats));
1359 pthread_cond_signal(&gCondition);
Rakesh Sunki4d5912d2017-03-30 14:47:55 -07001360 } else if (rsp_data->response_type == NAN_RESPONSE_PUBLISH) {
1361 sigma_dut_print(global_dut, DUT_MSG_INFO,
1362 "%s: publish_id %d\n",
1363 __func__,
1364 rsp_data->body.publish_response.publish_id);
1365 global_publish_id = rsp_data->body.publish_response.publish_id;
1366 } else if (rsp_data->response_type == NAN_RESPONSE_SUBSCRIBE) {
1367 sigma_dut_print(global_dut, DUT_MSG_INFO,
1368 "%s: subscribe_id %d\n",
1369 __func__,
1370 rsp_data->body.subscribe_response.subscribe_id);
1371 global_subscribe_id =
1372 rsp_data->body.subscribe_response.subscribe_id;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001374}
1375
1376
1377/* Events Callback */
1378void nan_event_publish_replied(NanPublishRepliedInd *event)
1379{
1380 sigma_dut_print(global_dut, DUT_MSG_INFO,
1381 "%s: handle %d " MAC_ADDR_STR " rssi:%d",
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001382 __func__, event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001383 MAC_ADDR_ARRAY(event->addr), event->rssi_value);
1384 event_anyresponse = 1;
1385 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001386 "EventName,Replied,RemoteInstanceID %d,mac," MAC_ADDR_STR,
1387 (event->requestor_instance_id >> 24),
1388 MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001389}
1390
1391
1392/* Events Callback */
1393void nan_event_publish_terminated(NanPublishTerminatedInd *event)
1394{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001395 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: publish_id %d reason %d",
1396 __func__, event->publish_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001397}
1398
1399
1400/* Events Callback */
1401void nan_event_match(NanMatchInd *event)
1402{
1403 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001404 "%s: Pub/Sub Id %d remote_requestor_id %08x "
1405 MAC_ADDR_STR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001406 " rssi:%d",
1407 __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001408 event->publish_subscribe_id,
1409 event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001410 MAC_ADDR_ARRAY(event->addr),
1411 event->rssi_value);
1412 event_anyresponse = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001413 global_header_handle = event->publish_subscribe_id;
1414 global_match_handle = event->requestor_instance_id;
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001415 memcpy(global_peer_mac_addr, event->addr, sizeof(global_peer_mac_addr));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001416
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001417 /* memset(event_resp_buf, 0, sizeof(event_resp_buf)); */
1418 /* global_pub_sub_handle = event->header.handle; */
1419 /* Print the SSI */
1420 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing SSI:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001421 nan_hex_dump(global_dut, event->service_specific_info,
1422 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001423 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1424 "EventName,DiscoveryResult,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001425 MAC_ADDR_STR " ", (event->requestor_instance_id >> 24),
1426 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001427
1428 /* Print the match filter */
1429 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing sdf match filter:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001430 nan_hex_dump(global_dut, event->sdf_match_filter,
1431 event->sdf_match_filter_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001432
1433 /* Print the conn_capability */
1434 sigma_dut_print(global_dut, DUT_MSG_INFO,
1435 "Printing PostConnectivity Capability");
1436 if (event->is_conn_capability_valid) {
1437 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfd supported:%s",
1438 event->conn_capability.is_wfd_supported ?
1439 "yes" : "no");
1440 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfds supported:%s",
1441 (event->conn_capability.is_wfds_supported ?
1442 "yes" : "no"));
1443 sigma_dut_print(global_dut, DUT_MSG_INFO, "TDLS supported:%s",
1444 (event->conn_capability.is_tdls_supported ?
1445 "yes" : "no"));
1446 sigma_dut_print(global_dut, DUT_MSG_INFO, "IBSS supported:%s",
1447 (event->conn_capability.is_ibss_supported ?
1448 "yes" : "no"));
1449 sigma_dut_print(global_dut, DUT_MSG_INFO, "Mesh supported:%s",
1450 (event->conn_capability.is_mesh_supported ?
1451 "yes" : "no"));
1452 sigma_dut_print(global_dut, DUT_MSG_INFO, "Infra Field:%d",
1453 event->conn_capability.wlan_infra_field);
1454 } else {
1455 sigma_dut_print(global_dut, DUT_MSG_INFO,
1456 "PostConnectivity Capability not present");
1457 }
1458
1459 /* Print the discovery_attr */
1460 sigma_dut_print(global_dut, DUT_MSG_INFO,
1461 "Printing PostDiscovery Attribute");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001462 if (event->num_rx_discovery_attr) {
1463 int idx;
1464
1465 for (idx = 0; idx < event->num_rx_discovery_attr; idx++) {
1466 sigma_dut_print(global_dut, DUT_MSG_INFO,
1467 "PostDiscovery Attribute - %d", idx);
1468 sigma_dut_print(global_dut, DUT_MSG_INFO,
1469 "Conn Type:%d Device Role:%d"
1470 MAC_ADDR_STR,
1471 event->discovery_attr[idx].type,
1472 event->discovery_attr[idx].role,
1473 MAC_ADDR_ARRAY(event->discovery_attr[idx].addr));
1474 sigma_dut_print(global_dut, DUT_MSG_INFO,
1475 "Duration:%d MapId:%d "
1476 "avail_interval_bitmap:%04x",
1477 event->discovery_attr[idx].duration,
1478 event->discovery_attr[idx].mapid,
1479 event->discovery_attr[idx].avail_interval_bitmap);
1480 sigma_dut_print(global_dut, DUT_MSG_INFO,
1481 "Printing Mesh Id:");
1482 nan_hex_dump(global_dut,
1483 event->discovery_attr[idx].mesh_id,
1484 event->discovery_attr[idx].mesh_id_len);
1485 sigma_dut_print(global_dut, DUT_MSG_INFO,
1486 "Printing Infrastructure Ssid:");
1487 nan_hex_dump(global_dut,
1488 event->discovery_attr[idx].infrastructure_ssid_val,
1489 event->discovery_attr[idx].infrastructure_ssid_len);
1490 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001491 } else {
1492 sigma_dut_print(global_dut, DUT_MSG_INFO,
1493 "PostDiscovery attribute not present");
1494 }
1495
1496 /* Print the fam */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001497 if (event->num_chans) {
1498 nan_print_further_availability_chan(global_dut,
1499 event->num_chans,
1500 &event->famchan[0]);
1501 } else {
1502 sigma_dut_print(global_dut, DUT_MSG_INFO,
1503 "Further Availability Map not present");
1504 }
1505 if (event->cluster_attribute_len) {
1506 sigma_dut_print(global_dut, DUT_MSG_INFO,
1507 "Printing Cluster Attribute:");
1508 nan_hex_dump(global_dut, event->cluster_attribute,
1509 event->cluster_attribute_len);
1510 } else {
1511 sigma_dut_print(global_dut, DUT_MSG_INFO,
1512 "Cluster Attribute not present");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001513 }
1514}
1515
1516
1517/* Events Callback */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001518void nan_event_match_expired(NanMatchExpiredInd *event)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001519{
1520 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001521 "%s: publish_subscribe_id %d match_handle %08x",
1522 __func__, event->publish_subscribe_id,
1523 event->requestor_instance_id);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001524}
1525
1526
1527/* Events Callback */
1528void nan_event_subscribe_terminated(NanSubscribeTerminatedInd *event)
1529{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001530 sigma_dut_print(global_dut, DUT_MSG_INFO,
1531 "%s: Subscribe Id %d reason %d",
1532 __func__, event->subscribe_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001533}
1534
1535
1536/* Events Callback */
1537void nan_event_followup(NanFollowupInd *event)
1538{
1539 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001540 "%s: Publish/Subscribe Id %d match_handle 0x%08x dw_or_faw %d "
1541 MAC_ADDR_STR, __func__, event->publish_subscribe_id,
1542 event->requestor_instance_id, event->dw_or_faw,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001543 MAC_ADDR_ARRAY(event->addr));
1544
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001545 global_match_handle = event->publish_subscribe_id;
1546 global_header_handle = event->requestor_instance_id;
1547 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Printing SSI", __func__);
1548 nan_hex_dump(global_dut, event->service_specific_info,
1549 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001550 event_anyresponse = 1;
1551 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1552 "EventName,FollowUp,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001553 MAC_ADDR_STR " ", event->requestor_instance_id >> 24,
1554 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001555}
1556
1557
1558/* Events Callback */
1559void nan_event_disceng_event(NanDiscEngEventInd *event)
1560{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001561 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: event_type %d",
1562 __func__, event->event_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001563
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001564 if (event->event_type == NAN_EVENT_ID_JOINED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001565 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Joined cluster "
1566 MAC_ADDR_STR,
1567 __func__,
1568 MAC_ADDR_ARRAY(event->data.cluster.addr));
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001569 /* To ensure sta_get_events to get the events
1570 * only after joining the NAN cluster. */
1571 pthread_cond_signal(&gCondition);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001572 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001573 if (event->event_type == NAN_EVENT_ID_STARTED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001574 sigma_dut_print(global_dut, DUT_MSG_INFO,
1575 "%s: Started cluster " MAC_ADDR_STR,
1576 __func__,
1577 MAC_ADDR_ARRAY(event->data.cluster.addr));
1578 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001579 if (event->event_type == NAN_EVENT_ID_DISC_MAC_ADDR) {
1580 sigma_dut_print(global_dut, DUT_MSG_INFO,
1581 "%s: Discovery Mac Address "
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001582 MAC_ADDR_STR,
1583 __func__,
1584 MAC_ADDR_ARRAY(event->data.mac_addr.addr));
1585 memcpy(global_nan_mac_addr, event->data.mac_addr.addr,
1586 sizeof(global_nan_mac_addr));
1587 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001588}
1589
1590
1591/* Events Callback */
1592void nan_event_disabled(NanDisabledInd *event)
1593{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001594 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: reason %d",
1595 __func__, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001596 /* pthread_cond_signal(&gCondition); */
1597}
1598
1599
Rakesh Sunki4c086672017-03-30 14:47:55 -07001600/* Events callback */
1601static void ndp_event_data_indication(NanDataPathRequestInd *event)
1602{
1603 sigma_dut_print(global_dut, DUT_MSG_INFO,
1604 "%s: Service Instance Id: %d Peer Discovery MAC ADDR "
1605 MAC_ADDR_STR
1606 " NDP Instance Id: %d App Info len %d App Info %s",
1607 __func__,
1608 event->service_instance_id,
1609 MAC_ADDR_ARRAY(event->peer_disc_mac_addr),
1610 event->ndp_instance_id,
1611 event->app_info.ndp_app_info_len,
1612 event->app_info.ndp_app_info);
1613
1614 global_ndp_instance_id = event->ndp_instance_id;
1615}
1616
1617
1618/* Events callback */
1619static void ndp_event_data_confirm(NanDataPathConfirmInd *event)
1620{
1621 sigma_dut_print(global_dut, DUT_MSG_INFO,
1622 "Received NDP Confirm Indication");
1623
1624 global_ndp_instance_id = event->ndp_instance_id;
1625 if (system("ifconfig nan0 up") != 0) {
1626 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1627 "Failed to set nan interface up");
1628 return;
1629 }
1630 if (system("ip -6 route add fe80::/64 dev nan0 table local") != 0) {
1631 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1632 "Failed to run:ip -6 route replace fe80::/64 dev nan0 table local");
1633 return;
1634 }
1635}
1636
1637
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001638void * my_thread_function(void *ptr)
1639{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001640 wifi_event_loop(global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001641 pthread_exit(0);
1642 return (void *) NULL;
1643}
1644
1645
1646static NanCallbackHandler callbackHandler = {
1647 .NotifyResponse = nan_notify_response,
1648 .EventPublishReplied = nan_event_publish_replied,
1649 .EventPublishTerminated = nan_event_publish_terminated,
1650 .EventMatch = nan_event_match,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001651 .EventMatchExpired = nan_event_match_expired,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001652 .EventSubscribeTerminated = nan_event_subscribe_terminated,
1653 .EventFollowup = nan_event_followup,
1654 .EventDiscEngEvent = nan_event_disceng_event,
1655 .EventDisabled = nan_event_disabled,
Rakesh Sunki4c086672017-03-30 14:47:55 -07001656 .EventDataRequest = ndp_event_data_indication,
1657 .EventDataConfirm = ndp_event_data_confirm,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001658};
1659
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001660
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001661void nan_init(struct sigma_dut *dut)
1662{
1663 pthread_t thread1; /* thread variables */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001664 wifi_error err = wifi_initialize(&global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001665
1666 if (err) {
1667 printf("wifi hal initialize failed\n");
1668 return;
1669 }
1670
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001671 global_interface_handle = wifi_get_iface_handle(global_wifi_handle,
1672 (char *) "wlan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001673 /* create threads 1 */
1674 pthread_create(&thread1, NULL, &my_thread_function, NULL);
1675
1676 pthread_mutex_init(&gMutex, NULL);
1677 pthread_cond_init(&gCondition, NULL);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001678 if (global_interface_handle)
1679 nan_register_handler(global_interface_handle, callbackHandler);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001680}
1681
1682
1683void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1684 struct sigma_cmd *cmd)
1685{
1686 sigma_dut_print(dut, DUT_MSG_INFO, "NAN sta_reset_default");
1687
1688 if (nan_state == 0) {
1689 nan_init(dut);
1690 nan_state = 1;
1691 }
1692 is_fam = 0;
1693 event_anyresponse = 0;
1694 global_dut = dut;
Rakesh Sunki7d37f412017-03-30 14:47:55 -07001695 memset(&dut->nan_pmk[0], 0, NAN_PMK_INFO_LEN);
1696 dut->nan_pmk_len = 0;
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001697 dut->sta_channel = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001698 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001699 memset(&global_nan_sync_stats, 0, sizeof(global_nan_sync_stats));
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001700
Rakesh Sunki8a630b82017-03-30 14:47:55 -07001701 sigma_nan_data_end(dut, cmd);
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001702 nan_data_interface_delete(0, global_interface_handle, (char *) "nan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001703 sigma_nan_disable(dut, conn, cmd);
1704}
1705
1706
1707int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1708 struct sigma_cmd *cmd)
1709{
1710 const char *program = get_param(cmd, "Prog");
1711 const char *nan_op = get_param(cmd, "NANOp");
1712 const char *method_type = get_param(cmd, "MethodType");
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001713 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001714 char resp_buf[100];
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001715 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001716
1717 if (program == NULL)
1718 return -1;
1719
1720 if (strcasecmp(program, "NAN") != 0) {
1721 send_resp(dut, conn, SIGMA_ERROR,
1722 "ErrorCode,Unsupported program");
1723 return 0;
1724 }
1725
1726 if (nan_op) {
1727 /*
1728 * NANOp has been specified.
1729 * We will build a nan_enable or nan_disable command.
1730 */
1731 if (strcasecmp(nan_op, "On") == 0) {
1732 if (sigma_nan_enable(dut, conn, cmd) == 0) {
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001733 ret = nan_data_interface_create(
1734 0, global_interface_handle,
1735 (char *) "nan0");
1736 if (ret != WIFI_SUCCESS) {
1737 sigma_dut_print(
1738 global_dut, DUT_MSG_ERROR,
1739 "Unable to create NAN data interface");
1740 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001741 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1742 MAC_ADDR_STR,
1743 MAC_ADDR_ARRAY(global_nan_mac_addr));
1744 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1745 } else {
1746 send_resp(dut, conn, SIGMA_ERROR,
1747 "NAN_ENABLE_FAILED");
1748 return -1;
1749 }
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001750
1751 if (band && strcasecmp(band, "24g") == 0) {
1752 sigma_dut_print(dut, DUT_MSG_INFO,
1753 "%s: Setting band to 2G Only",
1754 __func__);
1755 sigma_ndp_configure_band(
1756 dut, conn, cmd,
1757 NAN_DATA_PATH_SUPPORTED_BAND_2G);
1758 } else if (band && dut->sta_channel > 12) {
1759 sigma_ndp_configure_band(
1760 dut, conn, cmd,
1761 NAN_DATA_PATH_SUPPORT_DUAL_BAND);
1762 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001763 } else if (strcasecmp(nan_op, "Off") == 0) {
1764 sigma_nan_disable(dut, conn, cmd);
1765 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1766 }
1767 }
1768 if (nan_state && nan_op == NULL) {
1769 if (method_type) {
1770 if (strcasecmp(method_type, "Publish") == 0) {
1771 sigma_nan_publish_request(dut, conn, cmd);
1772 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1773 }
1774 if (strcasecmp(method_type, "Subscribe") == 0) {
1775 sigma_nan_subscribe_request(dut, conn, cmd);
1776 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1777 }
1778 if (strcasecmp(method_type, "Followup") == 0) {
1779 sigma_nan_transmit_followup(dut, conn, cmd);
1780 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1781 }
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001782 if (strcasecmp(method_type, "DataRequest") == 0) {
1783 sigma_nan_data_request(dut, conn, cmd);
1784 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1785 }
Rakesh Sunkia5cc2842017-03-30 14:47:55 -07001786 if (strcasecmp(method_type, "DataResponse") == 0) {
1787 sigma_dut_print(dut, DUT_MSG_INFO,
1788 "%s: method_type is DataResponse",
1789 __func__);
1790 sigma_nan_data_response(dut, conn, cmd);
1791 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1792 }
Rakesh Sunki8a630b82017-03-30 14:47:55 -07001793 if (strcasecmp(method_type, "DataEnd") == 0) {
1794 sigma_nan_data_end(dut, cmd);
1795 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1796 }
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -07001797 if (strcasecmp(method_type, "rangerequest") == 0) {
1798 sigma_dut_print(dut, DUT_MSG_INFO,
1799 "%s: method_type is rangerequest",
1800 __func__);
1801 sigma_nan_range_request(dut, cmd);
1802 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1803 }
1804 if (strcasecmp(method_type, "cancelrange") == 0) {
1805 sigma_dut_print(dut, DUT_MSG_INFO,
1806 "%s: method_type is cancelrange",
1807 __func__);
1808 sigma_nan_cancel_range(dut, cmd);
1809 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1810 }
Rakesh Sunkib2b65162017-03-30 14:47:55 -07001811 if (strcasecmp(method_type, "SchedUpdate") == 0) {
1812 sigma_dut_print(dut, DUT_MSG_INFO,
1813 "%s: method_type is SchedUpdate",
1814 __func__);
1815 sigma_nan_schedule_update(dut, cmd);
1816 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1817 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001818 } else {
1819 sigma_nan_config_enable(dut, conn, cmd);
1820 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1821 MAC_ADDR_STR,
1822 MAC_ADDR_ARRAY(global_nan_mac_addr));
1823 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1824 }
1825 }
1826
1827 return 0;
1828}
1829
1830
1831int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1832 struct sigma_cmd *cmd)
1833{
1834
1835 const char *program = get_param(cmd, "Program");
1836 const char *parameter = get_param(cmd, "Parameter");
1837 char resp_buf[100];
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001838 NanStatsRequest req;
1839 struct timespec abstime;
1840 u64 master_rank;
1841 u8 master_pref;
1842 u8 random_factor;
1843 u8 hop_count;
1844 u32 beacon_transmit_time;
1845 u32 ndp_channel_freq;
1846 u32 ndp_channel_freq2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001847
1848 if (program == NULL) {
1849 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Program Name");
1850 return -1;
1851 }
1852 if (strcasecmp(program, "NAN") != 0) {
1853 send_resp(dut, conn, SIGMA_ERROR,
1854 "ErrorCode,Unsupported program");
1855 return 0;
1856 }
1857
1858 if (parameter == NULL) {
1859 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Parameter");
1860 return -1;
1861 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001862
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001863 memset(&req, 0, sizeof(NanStatsRequest));
1864 req.stats_type = (NanStatsType) NAN_STATS_ID_DE_TIMING_SYNC;
1865 nan_stats_request(0, global_interface_handle, &req);
1866 /*
1867 * To ensure sta_get_events to get the events
1868 * only after joining the NAN cluster
1869 */
1870 abstime.tv_sec = 4;
1871 abstime.tv_nsec = 0;
1872 wait(abstime);
1873
1874 master_rank = global_nan_sync_stats.myRank;
1875 master_pref = (global_nan_sync_stats.myRank & 0xFF00000000000000) >> 56;
1876 random_factor = (global_nan_sync_stats.myRank & 0x00FF000000000000) >>
1877 48;
1878 hop_count = global_nan_sync_stats.currAmHopCount;
1879 beacon_transmit_time = global_nan_sync_stats.currAmBTT;
1880 ndp_channel_freq = global_nan_sync_stats.ndpChannelFreq;
1881 ndp_channel_freq2 = global_nan_sync_stats.ndpChannelFreq2;
1882
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001883 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001884 "%s: NanStatsRequest Master_pref:%02x, Random_factor:%02x, hop_count:%02x beacon_transmit_time:%d ndp_channel_freq:%d ndp_channel_freq2:%d",
1885 __func__, master_pref, random_factor,
1886 hop_count, beacon_transmit_time,
1887 ndp_channel_freq, ndp_channel_freq2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001888
1889 if (strcasecmp(parameter, "MasterPref") == 0) {
1890 snprintf(resp_buf, sizeof(resp_buf), "MasterPref,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001891 master_pref);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001892 } else if (strcasecmp(parameter, "MasterRank") == 0) {
1893 snprintf(resp_buf, sizeof(resp_buf), "MasterRank,0x%lx",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001894 master_rank);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001895 } else if (strcasecmp(parameter, "RandFactor") == 0) {
1896 snprintf(resp_buf, sizeof(resp_buf), "RandFactor,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001897 random_factor);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001898 } else if (strcasecmp(parameter, "HopCount") == 0) {
1899 snprintf(resp_buf, sizeof(resp_buf), "HopCount,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001900 hop_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001901 } else if (strcasecmp(parameter, "BeaconTransTime") == 0) {
1902 snprintf(resp_buf, sizeof(resp_buf), "BeaconTransTime 0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001903 beacon_transmit_time);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001904 } else if (strcasecmp(parameter, "NANStatus") == 0) {
1905 if (nan_state == 1)
1906 snprintf(resp_buf, sizeof(resp_buf), "On");
1907 else
1908 snprintf(resp_buf, sizeof(resp_buf), "Off");
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001909 } else if (strcasecmp(parameter, "NDPChannel") == 0) {
1910 if (ndp_channel_freq != 0 && ndp_channel_freq2 != 0) {
1911 snprintf(resp_buf, sizeof(resp_buf),
1912 "ndpchannel,%d,ndpchannel,%d",
1913 freq_to_channel(ndp_channel_freq),
1914 freq_to_channel(ndp_channel_freq2));
1915 } else if (ndp_channel_freq != 0) {
1916 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1917 freq_to_channel(ndp_channel_freq));
1918 } else if (ndp_channel_freq2 != 0) {
1919 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1920 freq_to_channel(ndp_channel_freq2));
1921 } else {
1922 sigma_dut_print(dut, DUT_MSG_ERROR,
1923 "%s: No Negotiated NDP Channels", __func__);
1924 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001925 } else {
1926 send_resp(dut, conn, SIGMA_ERROR, "Invalid Parameter");
1927 return 0;
1928 }
1929
1930 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1931 return 0;
1932}
1933
1934
1935int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1936 struct sigma_cmd *cmd)
1937{
1938 const char *action = get_param(cmd, "Action");
1939
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001940 if (!action)
1941 return 0;
1942
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001943 /* Check action for start, stop and get events. */
1944 if (strcasecmp(action, "Start") == 0) {
1945 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1946 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1947 } else if (strcasecmp(action, "Stop") == 0) {
1948 event_anyresponse = 0;
1949 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1950 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1951 } else if (strcasecmp(action, "Get") == 0) {
1952 if (event_anyresponse == 1) {
1953 send_resp(dut, conn, SIGMA_COMPLETE,
1954 global_event_resp_buf);
1955 } else {
1956 send_resp(dut, conn, SIGMA_COMPLETE, "EventList,NONE");
1957 }
1958 }
1959 return 0;
1960}
Rakesh Sunki4b75f962017-03-30 14:47:55 -07001961
1962#else /* #if NAN_CERT_VERSION */
1963
1964int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
1965 struct sigma_conn *conn,
1966 struct sigma_cmd *cmd)
1967{
1968 return 1;
1969}
1970
1971
1972int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1973 struct sigma_cmd *cmd)
1974{
1975 return 0;
1976
1977}
1978
1979
1980void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1981 struct sigma_cmd *cmd)
1982{
1983 return;
1984}
1985
1986
1987int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1988 struct sigma_cmd *cmd)
1989{
1990 return 0;
1991}
1992
1993
1994int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1995 struct sigma_cmd *cmd)
1996{
1997 return 0;
1998}
1999
2000#endif /* #if NAN_CERT_VERSION */