blob: 67ad3d1e81fc5c11ae3c90bbc385238f37511361 [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];
Rakesh Sunki42363682017-05-16 15:00:42 -070043static u8 global_publish_service_name[NAN_MAX_SERVICE_NAME_LEN];
44static u32 global_publish_service_name_len = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020045
46static int nan_further_availability_tx(struct sigma_dut *dut,
47 struct sigma_conn *conn,
48 struct sigma_cmd *cmd);
49static int nan_further_availability_rx(struct sigma_dut *dut,
50 struct sigma_conn *conn,
51 struct sigma_cmd *cmd);
52
53
54void nan_hex_dump(struct sigma_dut *dut, uint8_t *data, size_t len)
55{
56 char buf[512];
57 uint16_t index;
58 uint8_t *ptr;
59 int pos;
60
61 memset(buf, 0, sizeof(buf));
62 ptr = data;
63 pos = 0;
64 for (index = 0; index < len; index++) {
65 pos += sprintf(&(buf[pos]), "%02x ", *ptr++);
66 if (pos > 508)
67 break;
68 }
69 sigma_dut_print(dut, DUT_MSG_INFO, "HEXDUMP len=[%d]", (int) len);
70 sigma_dut_print(dut, DUT_MSG_INFO, "buf:%s", buf);
71}
72
73
74int nan_parse_hex(unsigned char c)
75{
76 if (c >= '0' && c <= '9')
77 return c - '0';
78 if (c >= 'a' && c <= 'f')
79 return c - 'a' + 10;
80 if (c >= 'A' && c <= 'F')
81 return c - 'A' + 10;
82 return 0;
83}
84
85
86int nan_parse_token(const char *tokenIn, u8 *tokenOut, int *filterLen)
87{
88 int total_len = 0, len = 0;
89 char *saveptr = NULL;
90
91 tokenIn = strtok_r((char *) tokenIn, ":", &saveptr);
92 while (tokenIn != NULL) {
93 len = strlen(tokenIn);
94 if (len == 1 && *tokenIn == '*')
95 len = 0;
96 tokenOut[total_len++] = (u8) len;
97 if (len != 0)
98 memcpy((u8 *) tokenOut + total_len, tokenIn, len);
99 total_len += len;
100 tokenIn = strtok_r(NULL, ":", &saveptr);
101 }
102 *filterLen = total_len;
103 return 0;
104}
105
106
107int nan_parse_mac_address(struct sigma_dut *dut, const char *arg, u8 *addr)
108{
109 if (strlen(arg) != 17) {
110 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid mac address %s",
111 arg);
112 sigma_dut_print(dut, DUT_MSG_ERROR,
113 "expected format xx:xx:xx:xx:xx:xx");
114 return -1;
115 }
116
117 addr[0] = nan_parse_hex(arg[0]) << 4 | nan_parse_hex(arg[1]);
118 addr[1] = nan_parse_hex(arg[3]) << 4 | nan_parse_hex(arg[4]);
119 addr[2] = nan_parse_hex(arg[6]) << 4 | nan_parse_hex(arg[7]);
120 addr[3] = nan_parse_hex(arg[9]) << 4 | nan_parse_hex(arg[10]);
121 addr[4] = nan_parse_hex(arg[12]) << 4 | nan_parse_hex(arg[13]);
122 addr[5] = nan_parse_hex(arg[15]) << 4 | nan_parse_hex(arg[16]);
123
124 return 0;
125}
126
127
128int nan_parse_mac_address_list(struct sigma_dut *dut, const char *input,
129 u8 *output, u16 max_addr_allowed)
130{
131 /*
132 * Reads a list of mac address separated by space. Each MAC address
133 * should have the format of aa:bb:cc:dd:ee:ff.
134 */
135 char *saveptr;
136 char *token;
137 int i = 0;
138
139 for (i = 0; i < max_addr_allowed; i++) {
140 token = strtok_r((i == 0) ? (char *) input : NULL,
141 " ", &saveptr);
142 if (token) {
143 nan_parse_mac_address(dut, token, output);
144 output += NAN_MAC_ADDR_LEN;
145 } else
146 break;
147 }
148
149 sigma_dut_print(dut, DUT_MSG_INFO, "Num MacAddress:%d", i);
150
151 return i;
152}
153
154
155int nan_parse_hex_string(struct sigma_dut *dut, const char *input,
156 u8 *output, int *outputlen)
157{
158 int i = 0;
159 int j = 0;
160
161 for (i = 0; i < (int) strlen(input) && j < *outputlen; i += 2) {
162 output[j] = nan_parse_hex(input[i]);
163 if (i + 1 < (int) strlen(input)) {
164 output[j] = ((output[j] << 4) |
165 nan_parse_hex(input[i + 1]));
166 }
167 j++;
168 }
169 *outputlen = j;
170 sigma_dut_print(dut, DUT_MSG_INFO, "Input:%s inputlen:%d outputlen:%d",
171 input, (int) strlen(input), (int) *outputlen);
172 return 0;
173}
174
175
176int wait(struct timespec abstime)
177{
178 struct timeval now;
179
180 gettimeofday(&now, NULL);
181
182 abstime.tv_sec += now.tv_sec;
183 if (((abstime.tv_nsec + now.tv_usec * 1000) > 1000 * 1000 * 1000) ||
184 (abstime.tv_nsec + now.tv_usec * 1000 < 0)) {
185 abstime.tv_sec += 1;
186 abstime.tv_nsec += now.tv_usec * 1000;
187 abstime.tv_nsec -= 1000 * 1000 * 1000;
188 } else {
189 abstime.tv_nsec += now.tv_usec * 1000;
190 }
191
192 return pthread_cond_timedwait(&gCondition, &gMutex, &abstime);
193}
194
195
196int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
197 struct sigma_conn *conn,
198 struct sigma_cmd *cmd)
199{
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700200 const char *oper_chan = get_param(cmd, "oper_chn");
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700201 const char *pmk = get_param(cmd, "PMK");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200202
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700203 if (oper_chan) {
204 sigma_dut_print(dut, DUT_MSG_INFO, "Operating Channel: %s",
205 oper_chan);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700206 dut->sta_channel = atoi(oper_chan);
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700207 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200208
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700209 if (pmk) {
210 int pmk_len;
211
212 sigma_dut_print(dut, DUT_MSG_INFO, "%s given string pmk: %s",
213 __func__, pmk);
214 memset(dut->nan_pmk, 0, NAN_PMK_INFO_LEN);
215 dut->nan_pmk_len = 0;
216 pmk_len = NAN_PMK_INFO_LEN;
217 nan_parse_hex_string(dut, &pmk[2], &dut->nan_pmk[0], &pmk_len);
218 dut->nan_pmk_len = pmk_len;
219 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
220 __func__, dut->nan_pmk_len);
221 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex pmk", __func__);
222 nan_hex_dump(dut, &dut->nan_pmk[0], dut->nan_pmk_len);
223 }
224
Rakesh Sunki14bff1d2017-03-30 14:47:55 -0700225 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200226 return 0;
227}
228
229
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700230void nan_print_further_availability_chan(struct sigma_dut *dut,
231 u8 num_chans,
232 NanFurtherAvailabilityChannel *fachan)
233{
234 int idx;
235
236 sigma_dut_print(dut, DUT_MSG_INFO,
237 "********Printing FurtherAvailabilityChan Info******");
238 sigma_dut_print(dut, DUT_MSG_INFO, "Numchans:%d", num_chans);
239 for (idx = 0; idx < num_chans; idx++) {
240 sigma_dut_print(dut, DUT_MSG_INFO,
241 "[%d]: NanAvailDuration:%d class_val:%02x channel:%d",
242 idx, fachan->entry_control,
243 fachan->class_val, fachan->channel);
244 sigma_dut_print(dut, DUT_MSG_INFO,
245 "[%d]: mapid:%d Availability bitmap:%08x",
246 idx, fachan->mapid,
247 fachan->avail_interval_bitmap);
248 }
249 sigma_dut_print(dut, DUT_MSG_INFO,
250 "*********************Done**********************");
251}
252
253
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200254int sigma_nan_enable(struct sigma_dut *dut, struct sigma_conn *conn,
255 struct sigma_cmd *cmd)
256{
257 const char *master_pref = get_param(cmd, "MasterPref");
258 const char *rand_fac = get_param(cmd, "RandFactor");
259 const char *hop_count = get_param(cmd, "HopCount");
260 const char *high_tsf = get_param(cmd, "HighTSF");
261 const char *sdftx_band = get_param(cmd, "SDFTxBand");
262 const char *oper_chan = get_param(cmd, "oper_chn");
263 const char *further_avail_ind = get_param(cmd, "FurtherAvailInd");
264 const char *band = get_param(cmd, "Band");
265 const char *only_5g = get_param(cmd, "5GOnly");
Rakesh Sunki38dd72e2017-03-30 14:47:55 -0700266 const char *nan_availability = get_param(cmd, "NANAvailability");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200267 struct timespec abstime;
268 NanEnableRequest req;
269
270 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200271 req.cluster_low = 0;
272 req.cluster_high = 0xFFFF;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700273 req.master_pref = 100;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200274
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700275 /* This is a debug hack to beacon in channel 11 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200276 if (oper_chan) {
277 req.config_2dot4g_support = 1;
278 req.support_2dot4g_val = 111;
279 }
280
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200281 if (master_pref) {
282 int master_pref_val = strtoul(master_pref, NULL, 0);
283
284 req.master_pref = master_pref_val;
285 }
286
287 if (rand_fac) {
288 int rand_fac_val = strtoul(rand_fac, NULL, 0);
289
290 req.config_random_factor_force = 1;
291 req.random_factor_force_val = rand_fac_val;
292 }
293
294 if (hop_count) {
295 int hop_count_val = strtoul(hop_count, NULL, 0);
296
297 req.config_hop_count_force = 1;
298 req.hop_count_force_val = hop_count_val;
299 }
300
301 if (sdftx_band) {
302 if (strcasecmp(sdftx_band, "5G") == 0) {
303 req.config_2dot4g_support = 1;
304 req.support_2dot4g_val = 0;
305 }
306 }
307
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700308 sigma_dut_print(dut, DUT_MSG_INFO,
309 "%s: Setting dual band 2.4 GHz and 5 GHz by default",
310 __func__);
311 /* Enable 2.4 GHz support */
312 req.config_2dot4g_support = 1;
313 req.support_2dot4g_val = 1;
314 req.config_2dot4g_beacons = 1;
315 req.beacon_2dot4g_val = 1;
316 req.config_2dot4g_sdf = 1;
317 req.sdf_2dot4g_val = 1;
318
319 /* Enable 5 GHz support */
320 req.config_support_5g = 1;
321 req.support_5g_val = 1;
322 req.config_5g_beacons = 1;
323 req.beacon_5g_val = 1;
324 req.config_5g_sdf = 1;
325 req.sdf_5g_val = 1;
326
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200327 if (band) {
328 if (strcasecmp(band, "24G") == 0) {
329 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700330 "Band 2.4 GHz selected, disable 5 GHz");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200331 /* Disable 5G support */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700332 req.config_support_5g = 1;
333 req.support_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200334 req.config_5g_beacons = 1;
335 req.beacon_5g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700336 req.config_5g_sdf = 1;
337 req.sdf_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200338 }
339 }
340
341 if (further_avail_ind) {
342 sigma_dut_print(dut, DUT_MSG_INFO, "FAM Test Enabled");
343 if (strcasecmp(further_avail_ind, "tx") == 0) {
344 is_fam = 1;
345 nan_further_availability_tx(dut, conn, cmd);
346 return 0;
347 } else if (strcasecmp(further_avail_ind, "rx") == 0) {
348 nan_further_availability_rx(dut, conn, cmd);
349 return 0;
350 }
351 }
352
353 if (only_5g && atoi(only_5g)) {
354 sigma_dut_print(dut, DUT_MSG_INFO, "5GHz only enabled");
355 req.config_2dot4g_support = 1;
356 req.support_2dot4g_val = 1;
357 req.config_2dot4g_beacons = 1;
358 req.beacon_2dot4g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700359 req.config_2dot4g_sdf = 1;
360 req.sdf_2dot4g_val = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200361 }
362
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700363 nan_enable_request(0, global_interface_handle, &req);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700364
Rakesh Sunki38dd72e2017-03-30 14:47:55 -0700365 if (nan_availability) {
366 int cmd_len, size;
367 NanDebugParams cfg_debug;
368
369 sigma_dut_print(dut, DUT_MSG_INFO,
370 "%s given string nan_availability: %s",
371 __func__, nan_availability);
372 memset(&cfg_debug, 0, sizeof(NanDebugParams));
373 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_AVAILABILITY;
374 size = NAN_MAX_DEBUG_MESSAGE_DATA_LEN;
375 nan_parse_hex_string(dut, &nan_availability[2],
376 &cfg_debug.debug_cmd_data[0], &size);
377 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex nan_availability",
378 __func__);
379 nan_hex_dump(dut, &cfg_debug.debug_cmd_data[0], size);
380 cmd_len = size + sizeof(u32);
381 nan_debug_command_config(0, global_interface_handle,
382 cfg_debug, cmd_len);
383 }
384
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700385 /* To ensure sta_get_events to get the events
386 * only after joining the NAN cluster. */
387 abstime.tv_sec = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200388 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700389 wait(abstime);
390
391 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200392}
393
394
395int sigma_nan_disable(struct sigma_dut *dut, struct sigma_conn *conn,
396 struct sigma_cmd *cmd)
397{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200398 struct timespec abstime;
399
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700400 nan_disable_request(0, global_interface_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200401
402 abstime.tv_sec = 4;
403 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700404 wait(abstime);
405
406 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200407}
408
409
410int sigma_nan_config_enable(struct sigma_dut *dut, struct sigma_conn *conn,
411 struct sigma_cmd *cmd)
412{
413 const char *master_pref = get_param(cmd, "MasterPref");
414 const char *rand_fac = get_param(cmd, "RandFactor");
415 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700416 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200417 struct timespec abstime;
418 NanConfigRequest req;
419
420 memset(&req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200421 req.config_rssi_proximity = 1;
422 req.rssi_proximity = 70;
423
424 if (master_pref) {
425 int master_pref_val = strtoul(master_pref, NULL, 0);
426
427 req.config_master_pref = 1;
428 req.master_pref = master_pref_val;
429 }
430
431 if (rand_fac) {
432 int rand_fac_val = strtoul(rand_fac, NULL, 0);
433
434 req.config_random_factor_force = 1;
435 req.random_factor_force_val = rand_fac_val;
436 }
437
438 if (hop_count) {
439 int hop_count_val = strtoul(hop_count, NULL, 0);
440
441 req.config_hop_count_force = 1;
442 req.hop_count_force_val = hop_count_val;
443 }
444
Rakesh Sunki107356c2017-03-30 14:47:55 -0700445 ret = nan_config_request(0, global_interface_handle, &req);
446 if (ret != WIFI_SUCCESS)
447 send_resp(dut, conn, SIGMA_ERROR, "NAN config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200448
449 abstime.tv_sec = 4;
450 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700451 wait(abstime);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200452
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700453 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200454}
455
456
457static int sigma_nan_subscribe_request(struct sigma_dut *dut,
458 struct sigma_conn *conn,
459 struct sigma_cmd *cmd)
460{
461 const char *subscribe_type = get_param(cmd, "SubscribeType");
462 const char *service_name = get_param(cmd, "ServiceName");
463 const char *disc_range = get_param(cmd, "DiscoveryRange");
464 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
465 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
466 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
467 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
468 const char *include_bit = get_param(cmd, "IncludeBit");
469 const char *mac = get_param(cmd, "MAC");
470 const char *srf_type = get_param(cmd, "SRFType");
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700471 const char *awake_dw_interval = get_param(cmd, "awakeDWint");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200472 NanSubscribeRequest req;
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700473 NanConfigRequest config_req;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200474 int filter_len_rx = 0, filter_len_tx = 0;
475 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
476 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -0700477 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200478
479 memset(&req, 0, sizeof(NanSubscribeRequest));
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700480 memset(&config_req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200481 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -0700482 req.period = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200483 req.subscribe_type = 1;
484 req.serviceResponseFilter = 1; /* MAC */
485 req.serviceResponseInclude = 0;
486 req.ssiRequiredForMatchIndication = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700487 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200488 req.subscribe_count = 0;
489
490 if (subscribe_type) {
491 if (strcasecmp(subscribe_type, "Active") == 0) {
492 req.subscribe_type = 1;
493 } else if (strcasecmp(subscribe_type, "Passive") == 0) {
494 req.subscribe_type = 0;
495 } else if (strcasecmp(subscribe_type, "Cancel") == 0) {
496 NanSubscribeCancelRequest req;
497
498 memset(&req, 0, sizeof(NanSubscribeCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -0700499 ret = nan_subscribe_cancel_request(
500 0, global_interface_handle, &req);
501 if (ret != WIFI_SUCCESS) {
502 send_resp(dut, conn, SIGMA_ERROR,
503 "NAN subscribe cancel request failed");
504 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200505 return 0;
506 }
507 }
508
509 if (disc_range)
510 req.rssi_threshold_flag = atoi(disc_range);
511
512 if (sdftx_dw)
513 req.subscribe_count = atoi(sdftx_dw);
514
515 /* Check this once again if config can be called here (TBD) */
516 if (discrange_ltd)
517 req.rssi_threshold_flag = atoi(discrange_ltd);
518
519 if (include_bit) {
520 int include_bit_val = atoi(include_bit);
521
522 req.serviceResponseInclude = include_bit_val;
523 sigma_dut_print(dut, DUT_MSG_INFO, "Includebit set %d",
524 req.serviceResponseInclude);
525 }
526
527 if (srf_type) {
528 int srf_type_val = atoi(srf_type);
529
530 if (srf_type_val == 1)
531 req.serviceResponseFilter = 0; /* Bloom */
532 else
533 req.serviceResponseFilter = 1; /* MAC */
534 req.useServiceResponseFilter = 1;
535 sigma_dut_print(dut, DUT_MSG_INFO, "srfFilter %d",
536 req.serviceResponseFilter);
537 }
538
539 if (mac) {
540 sigma_dut_print(dut, DUT_MSG_INFO, "MAC_ADDR List %s", mac);
541 req.num_intf_addr_present = nan_parse_mac_address_list(
542 dut, mac, &req.intf_addr[0][0],
543 NAN_MAX_SUBSCRIBE_MAX_ADDRESS);
544 }
545
546 memset(input_rx, 0, sizeof(input_rx));
547 memset(input_tx, 0, sizeof(input_tx));
548 if (rx_match_filter) {
549 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
550 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
551 filter_len_rx);
552 }
553 if (tx_match_filter) {
554 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
555 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
556 filter_len_tx);
557 }
558
559 if (tx_match_filter) {
560 req.tx_match_filter_len = filter_len_tx;
561 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
562 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
563 }
564 if (rx_match_filter) {
565 req.rx_match_filter_len = filter_len_rx;
566 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
567 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
568 }
569
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700570 if (service_name) {
571 strlcpy((char *) req.service_name, service_name,
572 strlen(service_name) + 1);
573 req.service_name_len = strlen(service_name);
574 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200575
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700576 if (awake_dw_interval) {
577 int input_dw_interval_val = atoi(awake_dw_interval);
578 int awake_dw_int = 0;
579
580 if (input_dw_interval_val > NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL) {
581 sigma_dut_print(dut, DUT_MSG_INFO,
582 "%s: input active dw interval = %d overwritting dw interval to Max allowed dw interval 16",
583 __func__, input_dw_interval_val);
584 input_dw_interval_val =
585 NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL;
586 }
587 sigma_dut_print(dut, DUT_MSG_INFO,
588 "%s: input active DW interval = %d",
589 __func__, input_dw_interval_val);
590 /*
591 * Indicates the interval for Sync beacons and SDF's in 2.4 GHz
592 * or 5 GHz band. Valid values of DW Interval are: 1, 2, 3, 4,
593 * and 5; 0 is reserved. The SDF includes in OTA when enabled.
594 * The publish/subscribe period values don't override the device
595 * level configurations.
596 * input_dw_interval_val is provided by the user are in the
597 * format 2^n-1 = 1/2/4/8/16. Internal implementation expects n
598 * to be passed to indicate the awake_dw_interval.
599 */
600 if (input_dw_interval_val == 1 ||
601 input_dw_interval_val % 2 == 0) {
602 while (input_dw_interval_val > 0) {
603 input_dw_interval_val >>= 1;
604 awake_dw_int++;
605 }
606 }
607 sigma_dut_print(dut, DUT_MSG_INFO,
608 "%s:converted active DW interval = %d",
609 __func__, awake_dw_int);
610 config_req.config_dw.config_2dot4g_dw_band = 1;
611 config_req.config_dw.dw_2dot4g_interval_val = awake_dw_int;
612 config_req.config_dw.config_5g_dw_band = 1;
613 config_req.config_dw.dw_5g_interval_val = awake_dw_int;
614 ret = nan_config_request(0, global_interface_handle,
615 &config_req);
616 if (ret != WIFI_SUCCESS) {
617 sigma_dut_print(dut, DUT_MSG_ERROR,
618 "%s:NAN config request failed",
619 __func__);
620 return -2;
621 }
622 }
623
Rakesh Sunki107356c2017-03-30 14:47:55 -0700624 ret = nan_subscribe_request(0, global_interface_handle, &req);
625 if (ret != WIFI_SUCCESS) {
626 send_resp(dut, conn, SIGMA_ERROR,
627 "NAN subscribe request failed");
628 }
629
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200630 return 0;
631}
632
633
Rakesh Sunkid7344c02017-03-30 14:47:55 -0700634static int sigma_ndp_configure_band(struct sigma_dut *dut,
635 struct sigma_conn *conn,
636 struct sigma_cmd *cmd,
637 NdpSupportedBand band_config_val)
638{
639 wifi_error ret;
640 NanDebugParams cfg_debug;
641 int size;
642
643 memset(&cfg_debug, 0, sizeof(NanDebugParams));
644 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SUPPORTED_BANDS;
645 memcpy(cfg_debug.debug_cmd_data, &band_config_val, sizeof(int));
646 sigma_dut_print(dut, DUT_MSG_INFO, "%s:setting debug cmd=0x%x",
647 __func__, cfg_debug.cmd);
648 size = sizeof(u32) + sizeof(int);
649 ret = nan_debug_command_config(0, global_interface_handle, cfg_debug,
650 size);
651 if (ret != WIFI_SUCCESS)
652 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
653
654 return 0;
655}
656
657
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700658static int sigma_nan_data_request(struct sigma_dut *dut,
659 struct sigma_conn *conn,
660 struct sigma_cmd *cmd)
661{
662 const char *ndp_security = get_param(cmd, "DataPathSecurity");
663 const char *ndp_resp_mac = get_param(cmd, "RespNanMac");
664 const char *include_immutable = get_param(cmd, "includeimmutable");
665 const char *avoid_channel = get_param(cmd, "avoidchannel");
666 const char *invalid_nan_schedule = get_param(cmd, "InvalidNANSchedule");
667 const char *map_order = get_param(cmd, "maporder");
668 wifi_error ret;
669 NanDataPathInitiatorRequest init_req;
670 NanDebugParams cfg_debug;
671 int size;
672
673 memset(&init_req, 0, sizeof(NanDataPathInitiatorRequest));
674
675 if (ndp_security) {
676 if (strcasecmp(ndp_security, "open") == 0)
677 init_req.ndp_cfg.security_cfg =
678 NAN_DP_CONFIG_NO_SECURITY;
679 else if (strcasecmp(ndp_security, "secure") == 0)
680 init_req.ndp_cfg.security_cfg = NAN_DP_CONFIG_SECURITY;
681 }
682
683 if (include_immutable) {
684 int include_immutable_val = 0;
685
686 memset(&cfg_debug, 0, sizeof(NanDebugParams));
687 cfg_debug.cmd = NAN_TEST_MODE_CMD_NDP_INCLUDE_IMMUTABLE;
688 include_immutable_val = atoi(include_immutable);
689 memcpy(cfg_debug.debug_cmd_data, &include_immutable_val,
690 sizeof(int));
691 size = sizeof(u32) + sizeof(int);
692 nan_debug_command_config(0, global_interface_handle,
693 cfg_debug, size);
694 }
695
696 if (avoid_channel) {
697 int avoid_channel_freq = 0;
698
699 memset(&cfg_debug, 0, sizeof(NanDebugParams));
700 avoid_channel_freq = channel_to_freq(atoi(avoid_channel));
701 cfg_debug.cmd = NAN_TEST_MODE_CMD_NDP_AVOID_CHANNEL;
702 memcpy(cfg_debug.debug_cmd_data, &avoid_channel_freq,
703 sizeof(int));
704 size = sizeof(u32) + sizeof(int);
705 nan_debug_command_config(0, global_interface_handle,
706 cfg_debug, size);
707 }
708
709 if (invalid_nan_schedule) {
710 int invalid_nan_schedule_type = 0;
711
712 memset(&cfg_debug, 0, sizeof(NanDebugParams));
713 invalid_nan_schedule_type = atoi(invalid_nan_schedule);
714 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_TYPE;
715 memcpy(cfg_debug.debug_cmd_data,
716 &invalid_nan_schedule_type, sizeof(int));
717 size = sizeof(u32) + sizeof(int);
718 sigma_dut_print(dut, DUT_MSG_INFO,
719 "%s: invalid schedule type: cmd type = %d and command data = %d",
720 __func__, cfg_debug.cmd,
721 invalid_nan_schedule_type);
722 nan_debug_command_config(0, global_interface_handle,
723 cfg_debug, size);
724 }
725
726 if (map_order) {
727 int map_order_val = 0;
728
729 memset(&cfg_debug, 0, sizeof(NanDebugParams));
730 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_AVAILABILITY_MAP_ORDER;
731 map_order_val = atoi(map_order);
732 memcpy(cfg_debug.debug_cmd_data, &map_order_val, sizeof(int));
733 size = sizeof(u32) + sizeof(int);
734 sigma_dut_print(dut, DUT_MSG_INFO,
735 "%s: map order: cmd type = %d and command data = %d",
736 __func__,
Rakesh Sunki9eaa6772017-04-04 11:37:03 -0700737 cfg_debug.cmd, map_order_val);
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700738 nan_debug_command_config(0, global_interface_handle,
739 cfg_debug, size);
740 }
741
742 /*
743 * Setting this flag, so that interface for ping6 command
744 * is set appropriately in traffic_send_ping().
745 */
746 dut->ndp_enable = 1;
747
748 /*
749 * Intended sleep after NAN data interface create
750 * before the NAN data request
751 */
752 sleep(4);
753
754 init_req.requestor_instance_id = global_match_handle;
755 strlcpy((char *) init_req.ndp_iface, "nan0",
756 sizeof(init_req.ndp_iface));
757
758 if (ndp_resp_mac) {
759 nan_parse_mac_address(dut, ndp_resp_mac,
760 init_req.peer_disc_mac_addr);
761 sigma_dut_print(
762 dut, DUT_MSG_INFO, "PEER MAC ADDR: " MAC_ADDR_STR,
763 MAC_ADDR_ARRAY(init_req.peer_disc_mac_addr));
764 } else {
765 memcpy(init_req.peer_disc_mac_addr, global_peer_mac_addr,
766 sizeof(init_req.peer_disc_mac_addr));
767 }
768
769 /* Not requesting the channel and letting FW decide */
770 if (dut->sta_channel == 0) {
771 init_req.channel_request_type = NAN_DP_CHANNEL_NOT_REQUESTED;
772 init_req.channel = 0;
773 } else {
774 init_req.channel_request_type = NAN_DP_FORCE_CHANNEL_SETUP;
775 init_req.channel = channel_to_freq(dut->sta_channel);
776 }
777 sigma_dut_print(dut, DUT_MSG_INFO,
778 "%s: Initiator Request: Channel = %d Channel Request Type = %d",
779 __func__, init_req.channel,
780 init_req.channel_request_type);
781
782 if (dut->nan_pmk_len == NAN_PMK_INFO_LEN) {
783 memcpy(&init_req.key_info.body.pmk_info.pmk[0],
784 &dut->nan_pmk[0], NAN_PMK_INFO_LEN);
785 init_req.key_info.body.pmk_info.pmk_len = NAN_PMK_INFO_LEN;
786 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
787 __func__,
788 init_req.key_info.body.pmk_info.pmk_len);
789 }
790
791 ret = nan_data_request_initiator(0, global_interface_handle, &init_req);
792 if (ret != WIFI_SUCCESS) {
793 send_resp(dut, conn, SIGMA_ERROR,
794 "Unable to initiate nan data request");
795 return 0;
796 }
797
798 return 0;
799}
800
801
Rakesh Sunkia5cc2842017-03-30 14:47:55 -0700802static int sigma_nan_data_response(struct sigma_dut *dut,
803 struct sigma_conn *conn,
804 struct sigma_cmd *cmd)
805{
806 const char *ndl_response = get_param(cmd, "NDLresponse");
807 const char *m4_response_type = get_param(cmd, "M4ResponseType");
808 wifi_error ret;
809 NanDebugParams cfg_debug;
810 int size;
811
812 if (ndl_response) {
813 int auto_responder_mode_val = 0;
814
815 sigma_dut_print(dut, DUT_MSG_INFO,
816 "%s: ndl_response = (%s) is passed",
817 __func__, ndl_response);
818 memset(&cfg_debug, 0, sizeof(NanDebugParams));
819 cfg_debug.cmd = NAN_TEST_MODE_CMD_AUTO_RESPONDER_MODE;
820 if (strcasecmp(ndl_response, "Auto") == 0) {
821 auto_responder_mode_val = NAN_DATA_RESPONDER_MODE_AUTO;
822 } else if (strcasecmp(ndl_response, "Reject") == 0) {
823 auto_responder_mode_val =
824 NAN_DATA_RESPONDER_MODE_REJECT;
825 } else if (strcasecmp(ndl_response, "Accept") == 0) {
826 auto_responder_mode_val =
827 NAN_DATA_RESPONDER_MODE_ACCEPT;
828 } else if (strcasecmp(ndl_response, "Counter") == 0) {
829 auto_responder_mode_val =
830 NAN_DATA_RESPONDER_MODE_COUNTER;
831 } else {
832 sigma_dut_print(dut, DUT_MSG_ERROR,
833 "%s: Invalid ndl_response",
834 __func__);
835 return 0;
836 }
837 memcpy(cfg_debug.debug_cmd_data, &auto_responder_mode_val,
838 sizeof(int));
839 size = sizeof(u32) + sizeof(int);
840 ret = nan_debug_command_config(0, global_interface_handle,
841 cfg_debug, size);
842 if (ret != WIFI_SUCCESS) {
843 send_resp(dut, conn, SIGMA_ERROR,
844 "Nan config request failed");
845 }
846 }
847
848 if (m4_response_type) {
849 int m4_response_type_val = 0;
850
851 sigma_dut_print(dut, DUT_MSG_INFO,
852 "%s: m4_response_type = (%s) is passed",
853 __func__, m4_response_type);
854 memset(&cfg_debug, 0, sizeof(NanDebugParams));
855 cfg_debug.cmd = NAN_TEST_MODE_CMD_M4_RESPONSE_TYPE;
856 if (strcasecmp(m4_response_type, "Accept") == 0)
857 m4_response_type_val = NAN_DATA_PATH_M4_RESPONSE_ACCEPT;
858 else if (strcasecmp(m4_response_type, "Reject") == 0)
859 m4_response_type_val = NAN_DATA_PATH_M4_RESPONSE_REJECT;
860 else if (strcasecmp(m4_response_type, "BadMic") == 0)
861 m4_response_type_val = NAN_DATA_PATH_M4_RESPONSE_BADMIC;
862
863 memcpy(cfg_debug.debug_cmd_data, &m4_response_type_val,
864 sizeof(int));
865 size = sizeof(u32) + sizeof(int);
866 ret = nan_debug_command_config(0, global_interface_handle,
867 cfg_debug, size);
868 if (ret != WIFI_SUCCESS) {
869 send_resp(dut, conn, SIGMA_ERROR,
870 "Nan config request failed");
871 }
872 }
873
874 return 0;
875}
876
877
Rakesh Sunki8a630b82017-03-30 14:47:55 -0700878static int sigma_nan_data_end(struct sigma_dut *dut, struct sigma_cmd *cmd)
879{
880 const char *nmf_security_config = get_param(cmd, "Security");
881 NanDataPathEndRequest req;
882 NanDebugParams cfg_debug;
883 int size;
884
885 memset(&req, 0, sizeof(NanDataPathEndRequest));
886 memset(&cfg_debug, 0, sizeof(NanDebugParams));
887 if (nmf_security_config) {
888 int nmf_security_config_val = 0;
889
890 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_NMF_CLEAR_CONFIG;
891 if (strcasecmp(nmf_security_config, "open") == 0)
892 nmf_security_config_val = NAN_NMF_CLEAR_ENABLE;
893 else if (strcasecmp(nmf_security_config, "secure") == 0)
894 nmf_security_config_val = NAN_NMF_CLEAR_DISABLE;
895 memcpy(cfg_debug.debug_cmd_data,
896 &nmf_security_config_val, sizeof(int));
897 size = sizeof(u32) + sizeof(int);
898 sigma_dut_print(dut, DUT_MSG_INFO,
899 "%s: nmf_security_config_val -- cmd type = %d and command data = %d",
900 __func__, cfg_debug.cmd,
901 nmf_security_config_val);
902 nan_debug_command_config(0, global_interface_handle,
903 cfg_debug, size);
904 }
905
906 req.num_ndp_instances = 1;
907 req.ndp_instance_id[0] = global_ndp_instance_id;
908
909 nan_data_end(0, global_interface_handle, &req);
910 return 0;
911}
912
913
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -0700914static int sigma_nan_range_request(struct sigma_dut *dut,
915 struct sigma_cmd *cmd)
916{
917 const char *dest_mac = get_param(cmd, "destmac");
918 NanSubscribeRequest req;
919
920 memset(&req, 0, sizeof(NanSubscribeRequest));
921 req.period = 1;
922 req.subscribe_type = NAN_SUBSCRIBE_TYPE_ACTIVE;
923 req.serviceResponseFilter = NAN_SRF_ATTR_BLOOM_FILTER;
924 req.serviceResponseInclude = NAN_SRF_INCLUDE_RESPOND;
925 req.ssiRequiredForMatchIndication = NAN_SSI_NOT_REQUIRED_IN_MATCH_IND;
926 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
927 req.subscribe_count = 0;
928 strlcpy((char *) req.service_name, DEFAULT_SVC,
929 NAN_MAX_SERVICE_NAME_LEN);
930 req.service_name_len = strlen((char *) req.service_name);
931
932 req.subscribe_id = global_subscribe_id;
933 req.sdea_params.ranging_state = 1;
934 req.sdea_params.range_report = NAN_ENABLE_RANGE_REPORT;
935 req.range_response_cfg.requestor_instance_id = global_match_handle;
936 req.range_response_cfg.ranging_response = NAN_RANGE_REQUEST_ACCEPT;
937 req.ranging_cfg.config_ranging_indications =
938 NAN_RANGING_INDICATE_CONTINUOUS_MASK;
939 if (dest_mac) {
940 nan_parse_mac_address(dut, dest_mac,
941 req.range_response_cfg.peer_addr);
942 sigma_dut_print(
943 dut, DUT_MSG_INFO, "peer mac addr: " MAC_ADDR_STR,
944 MAC_ADDR_ARRAY(req.range_response_cfg.peer_addr));
945 }
946 nan_subscribe_request(0, global_interface_handle, &req);
947
948 return 0;
949}
950
951
952static int sigma_nan_cancel_range(struct sigma_dut *dut,
953 struct sigma_cmd *cmd)
954{
955 const char *dest_mac = get_param(cmd, "destmac");
956 NanPublishRequest req;
957
958 memset(&req, 0, sizeof(NanPublishRequest));
959 req.ttl = 0;
960 req.period = 1;
961 req.publish_match_indicator = 1;
962 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
963 req.tx_type = NAN_TX_TYPE_BROADCAST;
964 req.publish_count = 0;
965 strlcpy((char *) req.service_name, DEFAULT_SVC,
966 NAN_MAX_SERVICE_NAME_LEN);
967 req.service_name_len = strlen((char *) req.service_name);
968 req.publish_id = global_publish_id;
969 req.range_response_cfg.ranging_response = NAN_RANGE_REQUEST_CANCEL;
970 if (dest_mac) {
971 nan_parse_mac_address(dut, dest_mac,
972 req.range_response_cfg.peer_addr);
973 sigma_dut_print(
974 dut, DUT_MSG_INFO, "peer mac addr: " MAC_ADDR_STR,
975 MAC_ADDR_ARRAY(req.range_response_cfg.peer_addr));
976 }
977 nan_publish_request(0, global_interface_handle, &req);
978
979 return 0;
980}
981
982
Rakesh Sunkib2b65162017-03-30 14:47:55 -0700983static int sigma_nan_schedule_update(struct sigma_dut *dut,
984 struct sigma_cmd *cmd)
985{
986 const char *schedule_update_type = get_param(cmd, "type");
987 const char *channel_availability = get_param(cmd,
988 "ChannelAvailability");
989 const char *responder_nmi_mac = get_param(cmd, "ResponderNMI");
990 NanDebugParams cfg_debug;
991 int size = 0;
992
993 memset(&cfg_debug, 0, sizeof(NanDebugParams));
994
995 if (!schedule_update_type)
996 return 0;
997
998 if (strcasecmp(schedule_update_type, "ULWnotify") == 0) {
999 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_ULW_NOTIFY;
1000 size = sizeof(u32);
1001 sigma_dut_print(dut, DUT_MSG_INFO,
1002 "%s: Schedule Update cmd type = %d", __func__,
1003 cfg_debug.cmd);
1004 if (channel_availability) {
1005 int channel_availability_val;
1006
1007 channel_availability_val = atoi(channel_availability);
1008 size += sizeof(int);
1009 memcpy(cfg_debug.debug_cmd_data,
1010 &channel_availability_val, sizeof(int));
1011 sigma_dut_print(dut, DUT_MSG_INFO,
1012 "%s: Schedule Update cmd data = %d size = %d",
1013 __func__, channel_availability_val,
1014 size);
1015 }
1016 } else if (strcasecmp(schedule_update_type, "NDLnegotiate") == 0) {
1017 cfg_debug.cmd =
1018 NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NEGOTIATE;
1019 size = sizeof(u32);
1020 sigma_dut_print(dut, DUT_MSG_INFO,
1021 "%s: Schedule Update cmd type = %d", __func__,
1022 cfg_debug.cmd);
1023 if (responder_nmi_mac) {
1024 u8 responder_nmi_mac_addr[NAN_MAC_ADDR_LEN];
1025
1026 nan_parse_mac_address(dut, responder_nmi_mac,
1027 responder_nmi_mac_addr);
1028 size += NAN_MAC_ADDR_LEN;
1029 memcpy(cfg_debug.debug_cmd_data, responder_nmi_mac_addr,
1030 NAN_MAC_ADDR_LEN);
1031 sigma_dut_print(dut, DUT_MSG_INFO,
1032 "%s: RESPONDER NMI MAC: "MAC_ADDR_STR,
1033 __func__,
1034 MAC_ADDR_ARRAY(responder_nmi_mac_addr));
1035 sigma_dut_print(dut, DUT_MSG_INFO,
1036 "%s: Schedule Update: cmd size = %d",
1037 __func__, size);
1038 }
1039 } else if (strcasecmp(schedule_update_type, "NDLnotify") == 0) {
1040 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NOTIFY;
1041 size = sizeof(u32);
1042 sigma_dut_print(dut, DUT_MSG_INFO,
1043 "%s: Schedule Update cmd type = %d", __func__,
1044 cfg_debug.cmd);
1045 }
1046
1047 nan_debug_command_config(0, global_interface_handle, cfg_debug, size);
1048
1049 return 0;
1050}
1051
1052
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001053int config_post_disc_attr(void)
1054{
Rakesh Sunki107356c2017-03-30 14:47:55 -07001055 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001056 NanConfigRequest configReq;
1057
1058 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001059
1060 /* Configure Post disc attr */
1061 /* Make these defines and use correct enum */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001062 configReq.num_config_discovery_attr = 1;
1063 configReq.discovery_attr_val[0].type = 4; /* Further Nan discovery */
1064 configReq.discovery_attr_val[0].role = 0;
1065 configReq.discovery_attr_val[0].transmit_freq = 1;
1066 configReq.discovery_attr_val[0].duration = 0;
1067 configReq.discovery_attr_val[0].avail_interval_bitmap = 0x00000008;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001068
Rakesh Sunki107356c2017-03-30 14:47:55 -07001069 ret = nan_config_request(0, global_interface_handle, &configReq);
1070 if (ret != WIFI_SUCCESS) {
1071 sigma_dut_print(global_dut, DUT_MSG_INFO,
1072 "NAN config request failed while configuring post discovery attribute");
1073 }
1074
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001075 return 0;
1076}
1077
1078
1079int sigma_nan_publish_request(struct sigma_dut *dut, struct sigma_conn *conn,
1080 struct sigma_cmd *cmd)
1081{
1082 const char *publish_type = get_param(cmd, "PublishType");
1083 const char *service_name = get_param(cmd, "ServiceName");
1084 const char *disc_range = get_param(cmd, "DiscoveryRange");
1085 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
1086 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
1087 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
1088 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001089 const char *ndp_enable = get_param(cmd, "DataPathFlag");
1090 const char *ndp_type = get_param(cmd, "DataPathType");
1091 const char *data_path_security = get_param(cmd, "datapathsecurity");
Rakesh Sunki48060402017-03-30 14:47:55 -07001092 const char *range_required = get_param(cmd, "rangerequired");
Rakesh Sunkie6f66832017-05-16 15:22:48 -07001093 const char *awake_dw_interval = get_param(cmd, "awakeDWint");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001094 NanPublishRequest req;
Rakesh Sunkie6f66832017-05-16 15:22:48 -07001095 NanConfigRequest config_req;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001096 int filter_len_rx = 0, filter_len_tx = 0;
1097 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
1098 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -07001099 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001100
1101 memset(&req, 0, sizeof(NanPublishRequest));
Rakesh Sunkie6f66832017-05-16 15:22:48 -07001102 memset(&config_req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001103 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -07001104 req.period = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001105 req.publish_match_indicator = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001106 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
1107 req.tx_type = NAN_TX_TYPE_BROADCAST;
1108 req.publish_count = 0;
Rakesh Sunki0a0eea82017-03-30 14:47:55 -07001109 req.service_responder_policy = NAN_SERVICE_ACCEPT_POLICY_ALL;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001110
Rakesh Sunki42363682017-05-16 15:00:42 -07001111 if (global_publish_service_name_len &&
1112 service_name &&
1113 strcasecmp((char *) global_publish_service_name,
1114 service_name) == 0 &&
1115 global_publish_id) {
1116 req.publish_id = global_publish_id;
1117 sigma_dut_print(dut, DUT_MSG_INFO,
1118 "%s: updating publish_id = %d in publish request",
1119 __func__, req.publish_id);
1120 }
1121
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001122 if (service_name) {
1123 strlcpy((char *) req.service_name, service_name,
Rakesh Sunki42363682017-05-16 15:00:42 -07001124 sizeof(req.service_name));
1125 req.service_name_len = strlen((char *) req.service_name);
1126 strlcpy((char *) global_publish_service_name, service_name,
1127 sizeof(global_publish_service_name));
1128 global_publish_service_name_len =
1129 strlen((char *) global_publish_service_name);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001130 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001131
1132 if (publish_type) {
1133 if (strcasecmp(publish_type, "Solicited") == 0) {
1134 req.publish_type = NAN_PUBLISH_TYPE_SOLICITED;
Rakesh Sunki62644ab2017-03-30 14:47:55 -07001135 } else if (strcasecmp(publish_type, "Unsolicited") == 0) {
1136 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001137 } else if (strcasecmp(publish_type, "Cancel") == 0) {
1138 NanPublishCancelRequest req;
1139
1140 memset(&req, 0, sizeof(NanPublishCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -07001141 ret = nan_publish_cancel_request(
1142 0, global_interface_handle, &req);
1143 if (ret != WIFI_SUCCESS) {
1144 send_resp(dut, conn, SIGMA_ERROR,
1145 "Unable to cancel nan publish request");
1146 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001147 return 0;
1148 }
1149 }
1150
1151 if (disc_range)
1152 req.rssi_threshold_flag = atoi(disc_range);
1153
1154 if (sdftx_dw)
1155 req.publish_count = atoi(sdftx_dw);
1156
1157 if (discrange_ltd)
1158 req.rssi_threshold_flag = atoi(discrange_ltd);
1159
1160 memset(input_rx, 0, sizeof(input_rx));
1161 memset(input_tx, 0, sizeof(input_tx));
1162 if (rx_match_filter) {
1163 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
1164 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
1165 filter_len_rx);
1166 }
1167 if (tx_match_filter) {
1168 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
1169 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
1170 filter_len_tx);
1171 }
1172
1173 if (is_fam == 1) {
1174 config_post_disc_attr();
Rakesh Sunkif680e0f2017-03-30 14:47:55 -07001175 /*
1176 * 8-bit bitmap which allows the Host to associate this publish
1177 * with a particular Post-NAN Connectivity attribute which has
1178 * been sent down in a NanConfigureRequest/NanEnableRequest
1179 * message. If the DE fails to find a configured Post-NAN
1180 * connectivity attributes referenced by the bitmap, the DE will
1181 * return an error code to the Host. If the Publish is
1182 * configured to use a Post-NAN Connectivity attribute and the
1183 * Host does not refresh the Post-NAN Connectivity attribute the
1184 * Publish will be canceled and the Host will be sent a
1185 * PublishTerminatedIndication message.
1186 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001187 req.connmap = 0x10;
1188 }
1189
1190 if (tx_match_filter) {
1191 req.tx_match_filter_len = filter_len_tx;
1192 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
1193 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
1194 }
1195
1196 if (rx_match_filter) {
1197 req.rx_match_filter_len = filter_len_rx;
1198 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
1199 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
1200 }
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001201
1202 if (service_name) {
1203 strlcpy((char *) req.service_name, service_name,
1204 strlen(service_name) + 1);
1205 req.service_name_len = strlen(service_name);
1206 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001207
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001208 if (ndp_enable) {
1209 if (strcasecmp(ndp_enable, "enable") == 0)
1210 req.sdea_params.config_nan_data_path = 1;
1211 else
1212 req.sdea_params.config_nan_data_path = 0;
1213
1214 if (ndp_type)
1215 req.sdea_params.ndp_type = atoi(ndp_type);
1216
1217 if (data_path_security) {
1218 if (strcasecmp(data_path_security, "secure") == 0) {
1219 req.sdea_params.security_cfg =
1220 NAN_DP_CONFIG_SECURITY;
1221 } else if (strcasecmp(data_path_security, "open") ==
1222 0) {
1223 req.sdea_params.security_cfg =
1224 NAN_DP_CONFIG_NO_SECURITY;
1225 }
1226 }
1227
1228 if (dut->nan_pmk_len == NAN_PMK_INFO_LEN) {
1229 memcpy(&req.key_info.body.pmk_info.pmk[0],
1230 &dut->nan_pmk[0], NAN_PMK_INFO_LEN);
1231 req.key_info.body.pmk_info.pmk_len = NAN_PMK_INFO_LEN;
1232 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
1233 __func__, req.key_info.body.pmk_info.pmk_len);
1234 }
1235 }
Rakesh Sunki48060402017-03-30 14:47:55 -07001236 if (range_required && strcasecmp(range_required, "enable") == 0) {
1237 req.sdea_params.ranging_state = NAN_RANGING_ENABLE;
1238 req.sdea_params.range_report = NAN_ENABLE_RANGE_REPORT;
1239 }
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001240
Rakesh Sunkie6f66832017-05-16 15:22:48 -07001241 if (awake_dw_interval) {
1242 int input_dw_interval_val = atoi(awake_dw_interval);
1243 int awake_dw_int = 0;
1244
1245 if (input_dw_interval_val > NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL) {
1246 sigma_dut_print(dut, DUT_MSG_INFO,
1247 "%s: input active dw interval = %d overwritting dw interval to Max allowed dw interval 16",
1248 __func__, input_dw_interval_val);
1249 input_dw_interval_val =
1250 NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL;
1251 }
1252 sigma_dut_print(dut, DUT_MSG_INFO,
1253 "%s: input active DW interval = %d",
1254 __func__, input_dw_interval_val);
1255 /*
1256 * Indicates the interval for Sync beacons and SDF's in 2.4 GHz
1257 * or 5 GHz band. Valid values of DW Interval are: 1, 2, 3, 4,
1258 * and 5; 0 is reserved. The SDF includes in OTA when enabled.
1259 * The publish/subscribe period. values don't override the
1260 * device level configurations.
1261 * input_dw_interval_val is provided by the user are in the
1262 * format 2^n-1 = 1/2/4/8/16. Internal implementation expects n
1263 * to be passed to indicate the awake_dw_interval.
1264 */
1265 if (input_dw_interval_val == 1 ||
1266 input_dw_interval_val % 2 == 0) {
1267 while (input_dw_interval_val > 0) {
1268 input_dw_interval_val >>= 1;
1269 awake_dw_int++;
1270 }
1271 }
1272 sigma_dut_print(dut, DUT_MSG_INFO,
1273 "%s:converted active DW interval = %d",
1274 __func__, awake_dw_int);
1275 config_req.config_dw.config_2dot4g_dw_band = 1;
1276 config_req.config_dw.dw_2dot4g_interval_val = awake_dw_int;
1277 config_req.config_dw.config_5g_dw_band = 1;
1278 config_req.config_dw.dw_5g_interval_val = awake_dw_int;
1279 ret = nan_config_request(0, global_interface_handle,
1280 &config_req);
1281 if (ret != WIFI_SUCCESS) {
1282 sigma_dut_print(dut, DUT_MSG_ERROR,
1283 "%s:NAN config request failed",
1284 __func__);
1285 return -2;
1286 }
1287 }
1288
Rakesh Sunki107356c2017-03-30 14:47:55 -07001289 ret = nan_publish_request(0, global_interface_handle, &req);
1290 if (ret != WIFI_SUCCESS)
1291 send_resp(dut, conn, SIGMA_ERROR, "Unable to publish");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001292
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001293 if (ndp_enable)
1294 dut->ndp_enable = 1;
1295
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001296 return 0;
1297}
1298
1299
1300static int nan_further_availability_rx(struct sigma_dut *dut,
1301 struct sigma_conn *conn,
1302 struct sigma_cmd *cmd)
1303{
1304 const char *master_pref = get_param(cmd, "MasterPref");
1305 const char *rand_fac = get_param(cmd, "RandFactor");
1306 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001307 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001308 struct timespec abstime;
1309
1310 NanEnableRequest req;
1311
1312 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001313 req.cluster_low = 0;
1314 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001315 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001316
1317 if (master_pref)
1318 req.master_pref = strtoul(master_pref, NULL, 0);
1319
1320 if (rand_fac) {
1321 int rand_fac_val = strtoul(rand_fac, NULL, 0);
1322
1323 req.config_random_factor_force = 1;
1324 req.random_factor_force_val = rand_fac_val;
1325 }
1326
1327 if (hop_count) {
1328 int hop_count_val = strtoul(hop_count, NULL, 0);
1329
1330 req.config_hop_count_force = 1;
1331 req.hop_count_force_val = hop_count_val;
1332 }
1333
Rakesh Sunki107356c2017-03-30 14:47:55 -07001334 ret = nan_enable_request(0, global_interface_handle, &req);
1335 if (ret != WIFI_SUCCESS) {
1336 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
1337 return 0;
1338 }
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001339
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001340 abstime.tv_sec = 4;
1341 abstime.tv_nsec = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001342 wait(abstime);
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001343
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001344 return 0;
1345}
1346
1347
1348static int nan_further_availability_tx(struct sigma_dut *dut,
1349 struct sigma_conn *conn,
1350 struct sigma_cmd *cmd)
1351{
1352 const char *master_pref = get_param(cmd, "MasterPref");
1353 const char *rand_fac = get_param(cmd, "RandFactor");
1354 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001355 wifi_error ret;
1356
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001357 NanEnableRequest req;
1358 NanConfigRequest configReq;
1359
1360 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361 req.cluster_low = 0;
1362 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001363 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001364
1365 if (master_pref)
1366 req.master_pref = strtoul(master_pref, NULL, 0);
1367
1368 if (rand_fac) {
1369 int rand_fac_val = strtoul(rand_fac, NULL, 0);
1370
1371 req.config_random_factor_force = 1;
1372 req.random_factor_force_val = rand_fac_val;
1373 }
1374
1375 if (hop_count) {
1376 int hop_count_val = strtoul(hop_count, NULL, 0);
1377
1378 req.config_hop_count_force = 1;
1379 req.hop_count_force_val = hop_count_val;
1380 }
1381
Rakesh Sunki107356c2017-03-30 14:47:55 -07001382 ret = nan_enable_request(0, global_interface_handle, &req);
1383 if (ret != WIFI_SUCCESS) {
1384 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
1385 return 0;
1386 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001387
1388 /* Start the config of fam */
1389
1390 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001391
1392 configReq.config_fam = 1;
1393 configReq.fam_val.numchans = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001394 configReq.fam_val.famchan[0].entry_control = 0;
1395 configReq.fam_val.famchan[0].class_val = 81;
1396 configReq.fam_val.famchan[0].channel = 6;
1397 configReq.fam_val.famchan[0].mapid = 0;
1398 configReq.fam_val.famchan[0].avail_interval_bitmap = 0x7ffffffe;
1399
Rakesh Sunki107356c2017-03-30 14:47:55 -07001400 ret = nan_config_request(0, global_interface_handle, &configReq);
1401 if (ret != WIFI_SUCCESS)
1402 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001403
1404 return 0;
1405}
1406
1407
1408int sigma_nan_transmit_followup(struct sigma_dut *dut,
1409 struct sigma_conn *conn,
1410 struct sigma_cmd *cmd)
1411{
1412 const char *mac = get_param(cmd, "mac");
1413 const char *requestor_id = get_param(cmd, "RemoteInstanceId");
1414 const char *local_id = get_param(cmd, "LocalInstanceId");
1415 const char *service_name = get_param(cmd, "servicename");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001416 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001417 NanTransmitFollowupRequest req;
1418
1419 memset(&req, 0, sizeof(NanTransmitFollowupRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001420 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001421 req.addr[0] = 0xFF;
1422 req.addr[1] = 0xFF;
1423 req.addr[2] = 0xFF;
1424 req.addr[3] = 0xFF;
1425 req.addr[4] = 0xFF;
1426 req.addr[5] = 0xFF;
1427 req.priority = NAN_TX_PRIORITY_NORMAL;
1428 req.dw_or_faw = 0;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001429
1430 if (service_name)
1431 req.service_specific_info_len = strlen(service_name);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001432
1433 if (requestor_id) {
1434 /* int requestor_id_val = atoi(requestor_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001435 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001436 }
1437 if (local_id) {
1438 /* int local_id_val = atoi(local_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001439 req.publish_subscribe_id = global_header_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001440 }
1441
1442 if (mac == NULL) {
1443 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid MAC Address");
1444 return -1;
1445 }
1446 nan_parse_mac_address(dut, mac, req.addr);
1447
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001448 if (requestor_id)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001449 req.requestor_instance_id = strtoul(requestor_id, NULL, 0);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001450
Rakesh Sunki107356c2017-03-30 14:47:55 -07001451 ret = nan_transmit_followup_request(0, global_interface_handle, &req);
1452 if (ret != WIFI_SUCCESS) {
1453 send_resp(dut, conn, SIGMA_ERROR,
1454 "Unable to complete nan transmit followup");
1455 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001456
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001457 return 0;
1458}
1459
Rakesh Sunki107356c2017-03-30 14:47:55 -07001460
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001461/* NotifyResponse invoked to notify the status of the Request */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001462void nan_notify_response(transaction_id id, NanResponseMsg *rsp_data)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001463{
1464 sigma_dut_print(global_dut, DUT_MSG_INFO,
Rakesh Sunkifdbd60b2017-03-30 14:47:55 -07001465 "%s: status %d response_type %d",
1466 __func__, rsp_data->status, rsp_data->response_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001467 if (rsp_data->response_type == NAN_RESPONSE_STATS &&
1468 rsp_data->body.stats_response.stats_type ==
1469 NAN_STATS_ID_DE_TIMING_SYNC) {
1470 NanSyncStats *pSyncStats;
1471
1472 sigma_dut_print(global_dut, DUT_MSG_INFO,
1473 "%s: stats_type %d", __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001474 rsp_data->body.stats_response.stats_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001475 pSyncStats = &rsp_data->body.stats_response.data.sync_stats;
1476 memcpy(&global_nan_sync_stats, pSyncStats,
1477 sizeof(NanSyncStats));
1478 pthread_cond_signal(&gCondition);
Rakesh Sunki4d5912d2017-03-30 14:47:55 -07001479 } else if (rsp_data->response_type == NAN_RESPONSE_PUBLISH) {
1480 sigma_dut_print(global_dut, DUT_MSG_INFO,
1481 "%s: publish_id %d\n",
1482 __func__,
1483 rsp_data->body.publish_response.publish_id);
1484 global_publish_id = rsp_data->body.publish_response.publish_id;
1485 } else if (rsp_data->response_type == NAN_RESPONSE_SUBSCRIBE) {
1486 sigma_dut_print(global_dut, DUT_MSG_INFO,
1487 "%s: subscribe_id %d\n",
1488 __func__,
1489 rsp_data->body.subscribe_response.subscribe_id);
1490 global_subscribe_id =
1491 rsp_data->body.subscribe_response.subscribe_id;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001492 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001493}
1494
1495
1496/* Events Callback */
1497void nan_event_publish_replied(NanPublishRepliedInd *event)
1498{
1499 sigma_dut_print(global_dut, DUT_MSG_INFO,
1500 "%s: handle %d " MAC_ADDR_STR " rssi:%d",
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001501 __func__, event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001502 MAC_ADDR_ARRAY(event->addr), event->rssi_value);
1503 event_anyresponse = 1;
1504 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001505 "EventName,Replied,RemoteInstanceID %d,mac," MAC_ADDR_STR,
1506 (event->requestor_instance_id >> 24),
1507 MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001508}
1509
1510
1511/* Events Callback */
1512void nan_event_publish_terminated(NanPublishTerminatedInd *event)
1513{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001514 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: publish_id %d reason %d",
1515 __func__, event->publish_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001516}
1517
1518
1519/* Events Callback */
1520void nan_event_match(NanMatchInd *event)
1521{
1522 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001523 "%s: Pub/Sub Id %d remote_requestor_id %08x "
1524 MAC_ADDR_STR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001525 " rssi:%d",
1526 __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001527 event->publish_subscribe_id,
1528 event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001529 MAC_ADDR_ARRAY(event->addr),
1530 event->rssi_value);
1531 event_anyresponse = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001532 global_header_handle = event->publish_subscribe_id;
1533 global_match_handle = event->requestor_instance_id;
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001534 memcpy(global_peer_mac_addr, event->addr, sizeof(global_peer_mac_addr));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001535
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001536 /* memset(event_resp_buf, 0, sizeof(event_resp_buf)); */
1537 /* global_pub_sub_handle = event->header.handle; */
1538 /* Print the SSI */
1539 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing SSI:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001540 nan_hex_dump(global_dut, event->service_specific_info,
1541 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001542 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1543 "EventName,DiscoveryResult,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001544 MAC_ADDR_STR " ", (event->requestor_instance_id >> 24),
1545 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001546
1547 /* Print the match filter */
1548 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing sdf match filter:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001549 nan_hex_dump(global_dut, event->sdf_match_filter,
1550 event->sdf_match_filter_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551
1552 /* Print the conn_capability */
1553 sigma_dut_print(global_dut, DUT_MSG_INFO,
1554 "Printing PostConnectivity Capability");
1555 if (event->is_conn_capability_valid) {
1556 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfd supported:%s",
1557 event->conn_capability.is_wfd_supported ?
1558 "yes" : "no");
1559 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfds supported:%s",
1560 (event->conn_capability.is_wfds_supported ?
1561 "yes" : "no"));
1562 sigma_dut_print(global_dut, DUT_MSG_INFO, "TDLS supported:%s",
1563 (event->conn_capability.is_tdls_supported ?
1564 "yes" : "no"));
1565 sigma_dut_print(global_dut, DUT_MSG_INFO, "IBSS supported:%s",
1566 (event->conn_capability.is_ibss_supported ?
1567 "yes" : "no"));
1568 sigma_dut_print(global_dut, DUT_MSG_INFO, "Mesh supported:%s",
1569 (event->conn_capability.is_mesh_supported ?
1570 "yes" : "no"));
1571 sigma_dut_print(global_dut, DUT_MSG_INFO, "Infra Field:%d",
1572 event->conn_capability.wlan_infra_field);
1573 } else {
1574 sigma_dut_print(global_dut, DUT_MSG_INFO,
1575 "PostConnectivity Capability not present");
1576 }
1577
1578 /* Print the discovery_attr */
1579 sigma_dut_print(global_dut, DUT_MSG_INFO,
1580 "Printing PostDiscovery Attribute");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001581 if (event->num_rx_discovery_attr) {
1582 int idx;
1583
1584 for (idx = 0; idx < event->num_rx_discovery_attr; idx++) {
1585 sigma_dut_print(global_dut, DUT_MSG_INFO,
1586 "PostDiscovery Attribute - %d", idx);
1587 sigma_dut_print(global_dut, DUT_MSG_INFO,
1588 "Conn Type:%d Device Role:%d"
1589 MAC_ADDR_STR,
1590 event->discovery_attr[idx].type,
1591 event->discovery_attr[idx].role,
1592 MAC_ADDR_ARRAY(event->discovery_attr[idx].addr));
1593 sigma_dut_print(global_dut, DUT_MSG_INFO,
1594 "Duration:%d MapId:%d "
1595 "avail_interval_bitmap:%04x",
1596 event->discovery_attr[idx].duration,
1597 event->discovery_attr[idx].mapid,
1598 event->discovery_attr[idx].avail_interval_bitmap);
1599 sigma_dut_print(global_dut, DUT_MSG_INFO,
1600 "Printing Mesh Id:");
1601 nan_hex_dump(global_dut,
1602 event->discovery_attr[idx].mesh_id,
1603 event->discovery_attr[idx].mesh_id_len);
1604 sigma_dut_print(global_dut, DUT_MSG_INFO,
1605 "Printing Infrastructure Ssid:");
1606 nan_hex_dump(global_dut,
1607 event->discovery_attr[idx].infrastructure_ssid_val,
1608 event->discovery_attr[idx].infrastructure_ssid_len);
1609 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001610 } else {
1611 sigma_dut_print(global_dut, DUT_MSG_INFO,
1612 "PostDiscovery attribute not present");
1613 }
1614
1615 /* Print the fam */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001616 if (event->num_chans) {
1617 nan_print_further_availability_chan(global_dut,
1618 event->num_chans,
1619 &event->famchan[0]);
1620 } else {
1621 sigma_dut_print(global_dut, DUT_MSG_INFO,
1622 "Further Availability Map not present");
1623 }
1624 if (event->cluster_attribute_len) {
1625 sigma_dut_print(global_dut, DUT_MSG_INFO,
1626 "Printing Cluster Attribute:");
1627 nan_hex_dump(global_dut, event->cluster_attribute,
1628 event->cluster_attribute_len);
1629 } else {
1630 sigma_dut_print(global_dut, DUT_MSG_INFO,
1631 "Cluster Attribute not present");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001632 }
1633}
1634
1635
1636/* Events Callback */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001637void nan_event_match_expired(NanMatchExpiredInd *event)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001638{
1639 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001640 "%s: publish_subscribe_id %d match_handle %08x",
1641 __func__, event->publish_subscribe_id,
1642 event->requestor_instance_id);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001643}
1644
1645
1646/* Events Callback */
1647void nan_event_subscribe_terminated(NanSubscribeTerminatedInd *event)
1648{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001649 sigma_dut_print(global_dut, DUT_MSG_INFO,
1650 "%s: Subscribe Id %d reason %d",
1651 __func__, event->subscribe_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001652}
1653
1654
1655/* Events Callback */
1656void nan_event_followup(NanFollowupInd *event)
1657{
1658 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001659 "%s: Publish/Subscribe Id %d match_handle 0x%08x dw_or_faw %d "
1660 MAC_ADDR_STR, __func__, event->publish_subscribe_id,
1661 event->requestor_instance_id, event->dw_or_faw,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001662 MAC_ADDR_ARRAY(event->addr));
1663
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001664 global_match_handle = event->publish_subscribe_id;
1665 global_header_handle = event->requestor_instance_id;
1666 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Printing SSI", __func__);
1667 nan_hex_dump(global_dut, event->service_specific_info,
1668 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001669 event_anyresponse = 1;
1670 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1671 "EventName,FollowUp,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001672 MAC_ADDR_STR " ", event->requestor_instance_id >> 24,
1673 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001674}
1675
1676
1677/* Events Callback */
1678void nan_event_disceng_event(NanDiscEngEventInd *event)
1679{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001680 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: event_type %d",
1681 __func__, event->event_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001682
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001683 if (event->event_type == NAN_EVENT_ID_JOINED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001684 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Joined cluster "
1685 MAC_ADDR_STR,
1686 __func__,
1687 MAC_ADDR_ARRAY(event->data.cluster.addr));
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001688 /* To ensure sta_get_events to get the events
1689 * only after joining the NAN cluster. */
1690 pthread_cond_signal(&gCondition);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001691 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001692 if (event->event_type == NAN_EVENT_ID_STARTED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001693 sigma_dut_print(global_dut, DUT_MSG_INFO,
1694 "%s: Started cluster " MAC_ADDR_STR,
1695 __func__,
1696 MAC_ADDR_ARRAY(event->data.cluster.addr));
1697 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001698 if (event->event_type == NAN_EVENT_ID_DISC_MAC_ADDR) {
1699 sigma_dut_print(global_dut, DUT_MSG_INFO,
1700 "%s: Discovery Mac Address "
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001701 MAC_ADDR_STR,
1702 __func__,
1703 MAC_ADDR_ARRAY(event->data.mac_addr.addr));
1704 memcpy(global_nan_mac_addr, event->data.mac_addr.addr,
1705 sizeof(global_nan_mac_addr));
1706 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001707}
1708
1709
1710/* Events Callback */
1711void nan_event_disabled(NanDisabledInd *event)
1712{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001713 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: reason %d",
1714 __func__, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001715 /* pthread_cond_signal(&gCondition); */
1716}
1717
1718
Rakesh Sunki4c086672017-03-30 14:47:55 -07001719/* Events callback */
1720static void ndp_event_data_indication(NanDataPathRequestInd *event)
1721{
1722 sigma_dut_print(global_dut, DUT_MSG_INFO,
1723 "%s: Service Instance Id: %d Peer Discovery MAC ADDR "
1724 MAC_ADDR_STR
1725 " NDP Instance Id: %d App Info len %d App Info %s",
1726 __func__,
1727 event->service_instance_id,
1728 MAC_ADDR_ARRAY(event->peer_disc_mac_addr),
1729 event->ndp_instance_id,
1730 event->app_info.ndp_app_info_len,
1731 event->app_info.ndp_app_info);
1732
1733 global_ndp_instance_id = event->ndp_instance_id;
1734}
1735
1736
1737/* Events callback */
1738static void ndp_event_data_confirm(NanDataPathConfirmInd *event)
1739{
1740 sigma_dut_print(global_dut, DUT_MSG_INFO,
1741 "Received NDP Confirm Indication");
1742
1743 global_ndp_instance_id = event->ndp_instance_id;
1744 if (system("ifconfig nan0 up") != 0) {
1745 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1746 "Failed to set nan interface up");
1747 return;
1748 }
1749 if (system("ip -6 route add fe80::/64 dev nan0 table local") != 0) {
1750 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1751 "Failed to run:ip -6 route replace fe80::/64 dev nan0 table local");
1752 return;
1753 }
1754}
1755
1756
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001757void * my_thread_function(void *ptr)
1758{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001759 wifi_event_loop(global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001760 pthread_exit(0);
1761 return (void *) NULL;
1762}
1763
1764
1765static NanCallbackHandler callbackHandler = {
1766 .NotifyResponse = nan_notify_response,
1767 .EventPublishReplied = nan_event_publish_replied,
1768 .EventPublishTerminated = nan_event_publish_terminated,
1769 .EventMatch = nan_event_match,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001770 .EventMatchExpired = nan_event_match_expired,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001771 .EventSubscribeTerminated = nan_event_subscribe_terminated,
1772 .EventFollowup = nan_event_followup,
1773 .EventDiscEngEvent = nan_event_disceng_event,
1774 .EventDisabled = nan_event_disabled,
Rakesh Sunki4c086672017-03-30 14:47:55 -07001775 .EventDataRequest = ndp_event_data_indication,
1776 .EventDataConfirm = ndp_event_data_confirm,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001777};
1778
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001779
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001780void nan_init(struct sigma_dut *dut)
1781{
1782 pthread_t thread1; /* thread variables */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001783 wifi_error err = wifi_initialize(&global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001784
1785 if (err) {
1786 printf("wifi hal initialize failed\n");
1787 return;
1788 }
1789
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001790 global_interface_handle = wifi_get_iface_handle(global_wifi_handle,
1791 (char *) "wlan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001792 /* create threads 1 */
1793 pthread_create(&thread1, NULL, &my_thread_function, NULL);
1794
1795 pthread_mutex_init(&gMutex, NULL);
1796 pthread_cond_init(&gCondition, NULL);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001797 if (global_interface_handle)
1798 nan_register_handler(global_interface_handle, callbackHandler);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001799}
1800
1801
1802void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1803 struct sigma_cmd *cmd)
1804{
1805 sigma_dut_print(dut, DUT_MSG_INFO, "NAN sta_reset_default");
1806
1807 if (nan_state == 0) {
1808 nan_init(dut);
1809 nan_state = 1;
1810 }
1811 is_fam = 0;
1812 event_anyresponse = 0;
1813 global_dut = dut;
Rakesh Sunki7d37f412017-03-30 14:47:55 -07001814 memset(&dut->nan_pmk[0], 0, NAN_PMK_INFO_LEN);
1815 dut->nan_pmk_len = 0;
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001816 dut->sta_channel = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001817 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001818 memset(&global_nan_sync_stats, 0, sizeof(global_nan_sync_stats));
Rakesh Sunki42363682017-05-16 15:00:42 -07001819 memset(global_publish_service_name, 0,
1820 sizeof(global_publish_service_name));
1821 global_publish_service_name_len = 0;
1822 global_publish_id = 0;
Rakesh Sunki0262cb52017-05-17 14:22:05 -07001823 global_subscribe_id = 0;
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001824
Rakesh Sunki8a630b82017-03-30 14:47:55 -07001825 sigma_nan_data_end(dut, cmd);
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001826 nan_data_interface_delete(0, global_interface_handle, (char *) "nan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001827 sigma_nan_disable(dut, conn, cmd);
1828}
1829
1830
1831int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1832 struct sigma_cmd *cmd)
1833{
1834 const char *program = get_param(cmd, "Prog");
1835 const char *nan_op = get_param(cmd, "NANOp");
1836 const char *method_type = get_param(cmd, "MethodType");
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001837 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001838 char resp_buf[100];
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001839 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001840
1841 if (program == NULL)
1842 return -1;
1843
1844 if (strcasecmp(program, "NAN") != 0) {
1845 send_resp(dut, conn, SIGMA_ERROR,
1846 "ErrorCode,Unsupported program");
1847 return 0;
1848 }
1849
1850 if (nan_op) {
1851 /*
1852 * NANOp has been specified.
1853 * We will build a nan_enable or nan_disable command.
1854 */
1855 if (strcasecmp(nan_op, "On") == 0) {
1856 if (sigma_nan_enable(dut, conn, cmd) == 0) {
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001857 ret = nan_data_interface_create(
1858 0, global_interface_handle,
1859 (char *) "nan0");
1860 if (ret != WIFI_SUCCESS) {
1861 sigma_dut_print(
1862 global_dut, DUT_MSG_ERROR,
1863 "Unable to create NAN data interface");
1864 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001865 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1866 MAC_ADDR_STR,
1867 MAC_ADDR_ARRAY(global_nan_mac_addr));
1868 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1869 } else {
1870 send_resp(dut, conn, SIGMA_ERROR,
1871 "NAN_ENABLE_FAILED");
1872 return -1;
1873 }
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001874
1875 if (band && strcasecmp(band, "24g") == 0) {
1876 sigma_dut_print(dut, DUT_MSG_INFO,
1877 "%s: Setting band to 2G Only",
1878 __func__);
1879 sigma_ndp_configure_band(
1880 dut, conn, cmd,
1881 NAN_DATA_PATH_SUPPORTED_BAND_2G);
1882 } else if (band && dut->sta_channel > 12) {
1883 sigma_ndp_configure_band(
1884 dut, conn, cmd,
1885 NAN_DATA_PATH_SUPPORT_DUAL_BAND);
1886 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001887 } else if (strcasecmp(nan_op, "Off") == 0) {
1888 sigma_nan_disable(dut, conn, cmd);
Rakesh Sunki42363682017-05-16 15:00:42 -07001889 memset(global_publish_service_name, 0,
1890 sizeof(global_publish_service_name));
1891 global_publish_service_name_len = 0;
1892 global_publish_id = 0;
Rakesh Sunki0262cb52017-05-17 14:22:05 -07001893 global_subscribe_id = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001894 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1895 }
1896 }
1897 if (nan_state && nan_op == NULL) {
1898 if (method_type) {
1899 if (strcasecmp(method_type, "Publish") == 0) {
1900 sigma_nan_publish_request(dut, conn, cmd);
1901 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1902 }
1903 if (strcasecmp(method_type, "Subscribe") == 0) {
1904 sigma_nan_subscribe_request(dut, conn, cmd);
1905 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1906 }
1907 if (strcasecmp(method_type, "Followup") == 0) {
1908 sigma_nan_transmit_followup(dut, conn, cmd);
1909 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1910 }
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001911 if (strcasecmp(method_type, "DataRequest") == 0) {
1912 sigma_nan_data_request(dut, conn, cmd);
1913 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1914 }
Rakesh Sunkia5cc2842017-03-30 14:47:55 -07001915 if (strcasecmp(method_type, "DataResponse") == 0) {
1916 sigma_dut_print(dut, DUT_MSG_INFO,
1917 "%s: method_type is DataResponse",
1918 __func__);
1919 sigma_nan_data_response(dut, conn, cmd);
1920 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1921 }
Rakesh Sunki8a630b82017-03-30 14:47:55 -07001922 if (strcasecmp(method_type, "DataEnd") == 0) {
1923 sigma_nan_data_end(dut, cmd);
1924 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1925 }
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -07001926 if (strcasecmp(method_type, "rangerequest") == 0) {
1927 sigma_dut_print(dut, DUT_MSG_INFO,
1928 "%s: method_type is rangerequest",
1929 __func__);
1930 sigma_nan_range_request(dut, cmd);
1931 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1932 }
1933 if (strcasecmp(method_type, "cancelrange") == 0) {
1934 sigma_dut_print(dut, DUT_MSG_INFO,
1935 "%s: method_type is cancelrange",
1936 __func__);
1937 sigma_nan_cancel_range(dut, cmd);
1938 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1939 }
Rakesh Sunkib2b65162017-03-30 14:47:55 -07001940 if (strcasecmp(method_type, "SchedUpdate") == 0) {
1941 sigma_dut_print(dut, DUT_MSG_INFO,
1942 "%s: method_type is SchedUpdate",
1943 __func__);
1944 sigma_nan_schedule_update(dut, cmd);
1945 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1946 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001947 } else {
1948 sigma_nan_config_enable(dut, conn, cmd);
1949 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1950 MAC_ADDR_STR,
1951 MAC_ADDR_ARRAY(global_nan_mac_addr));
1952 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1953 }
1954 }
1955
1956 return 0;
1957}
1958
1959
1960int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1961 struct sigma_cmd *cmd)
1962{
1963
1964 const char *program = get_param(cmd, "Program");
1965 const char *parameter = get_param(cmd, "Parameter");
1966 char resp_buf[100];
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001967 NanStatsRequest req;
1968 struct timespec abstime;
1969 u64 master_rank;
1970 u8 master_pref;
1971 u8 random_factor;
1972 u8 hop_count;
1973 u32 beacon_transmit_time;
1974 u32 ndp_channel_freq;
1975 u32 ndp_channel_freq2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001976
1977 if (program == NULL) {
1978 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Program Name");
1979 return -1;
1980 }
1981 if (strcasecmp(program, "NAN") != 0) {
1982 send_resp(dut, conn, SIGMA_ERROR,
1983 "ErrorCode,Unsupported program");
1984 return 0;
1985 }
1986
1987 if (parameter == NULL) {
1988 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Parameter");
1989 return -1;
1990 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001991
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001992 memset(&req, 0, sizeof(NanStatsRequest));
1993 req.stats_type = (NanStatsType) NAN_STATS_ID_DE_TIMING_SYNC;
1994 nan_stats_request(0, global_interface_handle, &req);
1995 /*
1996 * To ensure sta_get_events to get the events
1997 * only after joining the NAN cluster
1998 */
1999 abstime.tv_sec = 4;
2000 abstime.tv_nsec = 0;
2001 wait(abstime);
2002
2003 master_rank = global_nan_sync_stats.myRank;
2004 master_pref = (global_nan_sync_stats.myRank & 0xFF00000000000000) >> 56;
2005 random_factor = (global_nan_sync_stats.myRank & 0x00FF000000000000) >>
2006 48;
2007 hop_count = global_nan_sync_stats.currAmHopCount;
2008 beacon_transmit_time = global_nan_sync_stats.currAmBTT;
2009 ndp_channel_freq = global_nan_sync_stats.ndpChannelFreq;
2010 ndp_channel_freq2 = global_nan_sync_stats.ndpChannelFreq2;
2011
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002012 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002013 "%s: NanStatsRequest Master_pref:%02x, Random_factor:%02x, hop_count:%02x beacon_transmit_time:%d ndp_channel_freq:%d ndp_channel_freq2:%d",
2014 __func__, master_pref, random_factor,
2015 hop_count, beacon_transmit_time,
2016 ndp_channel_freq, ndp_channel_freq2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002017
2018 if (strcasecmp(parameter, "MasterPref") == 0) {
2019 snprintf(resp_buf, sizeof(resp_buf), "MasterPref,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002020 master_pref);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002021 } else if (strcasecmp(parameter, "MasterRank") == 0) {
2022 snprintf(resp_buf, sizeof(resp_buf), "MasterRank,0x%lx",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002023 master_rank);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002024 } else if (strcasecmp(parameter, "RandFactor") == 0) {
2025 snprintf(resp_buf, sizeof(resp_buf), "RandFactor,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002026 random_factor);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002027 } else if (strcasecmp(parameter, "HopCount") == 0) {
2028 snprintf(resp_buf, sizeof(resp_buf), "HopCount,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002029 hop_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002030 } else if (strcasecmp(parameter, "BeaconTransTime") == 0) {
2031 snprintf(resp_buf, sizeof(resp_buf), "BeaconTransTime 0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002032 beacon_transmit_time);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002033 } else if (strcasecmp(parameter, "NANStatus") == 0) {
2034 if (nan_state == 1)
2035 snprintf(resp_buf, sizeof(resp_buf), "On");
2036 else
2037 snprintf(resp_buf, sizeof(resp_buf), "Off");
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002038 } else if (strcasecmp(parameter, "NDPChannel") == 0) {
2039 if (ndp_channel_freq != 0 && ndp_channel_freq2 != 0) {
2040 snprintf(resp_buf, sizeof(resp_buf),
2041 "ndpchannel,%d,ndpchannel,%d",
2042 freq_to_channel(ndp_channel_freq),
2043 freq_to_channel(ndp_channel_freq2));
2044 } else if (ndp_channel_freq != 0) {
2045 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
2046 freq_to_channel(ndp_channel_freq));
2047 } else if (ndp_channel_freq2 != 0) {
2048 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
2049 freq_to_channel(ndp_channel_freq2));
2050 } else {
2051 sigma_dut_print(dut, DUT_MSG_ERROR,
2052 "%s: No Negotiated NDP Channels", __func__);
2053 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002054 } else {
2055 send_resp(dut, conn, SIGMA_ERROR, "Invalid Parameter");
2056 return 0;
2057 }
2058
2059 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
2060 return 0;
2061}
2062
2063
2064int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
2065 struct sigma_cmd *cmd)
2066{
2067 const char *action = get_param(cmd, "Action");
2068
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07002069 if (!action)
2070 return 0;
2071
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002072 /* Check action for start, stop and get events. */
2073 if (strcasecmp(action, "Start") == 0) {
2074 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
2075 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
2076 } else if (strcasecmp(action, "Stop") == 0) {
2077 event_anyresponse = 0;
2078 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
2079 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
2080 } else if (strcasecmp(action, "Get") == 0) {
2081 if (event_anyresponse == 1) {
2082 send_resp(dut, conn, SIGMA_COMPLETE,
2083 global_event_resp_buf);
2084 } else {
2085 send_resp(dut, conn, SIGMA_COMPLETE, "EventList,NONE");
2086 }
2087 }
2088 return 0;
2089}
Rakesh Sunki4b75f962017-03-30 14:47:55 -07002090
2091#else /* #if NAN_CERT_VERSION */
2092
2093int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
2094 struct sigma_conn *conn,
2095 struct sigma_cmd *cmd)
2096{
2097 return 1;
2098}
2099
2100
2101int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
2102 struct sigma_cmd *cmd)
2103{
2104 return 0;
2105
2106}
2107
2108
2109void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
2110 struct sigma_cmd *cmd)
2111{
2112 return;
2113}
2114
2115
2116int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
2117 struct sigma_cmd *cmd)
2118{
2119 return 0;
2120}
2121
2122
2123int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
2124 struct sigma_cmd *cmd)
2125{
2126 return 0;
2127}
2128
2129#endif /* #if NAN_CERT_VERSION */