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