blob: 250a811253bd10f6b8b9b2a1b3bdf84cfd8fd52d [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;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020027uint16_t global_header_handle = 0;
28uint32_t global_match_handle = 0;
29
30#define MAC_ADDR_ARRAY(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
31#define MAC_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
32#ifndef ETH_ALEN
33#define ETH_ALEN 6
34#endif
35
36struct sigma_dut *global_dut = NULL;
37static char global_nan_mac_addr[ETH_ALEN];
38static char global_event_resp_buf[1024];
39
40static int nan_further_availability_tx(struct sigma_dut *dut,
41 struct sigma_conn *conn,
42 struct sigma_cmd *cmd);
43static int nan_further_availability_rx(struct sigma_dut *dut,
44 struct sigma_conn *conn,
45 struct sigma_cmd *cmd);
46
47
48void nan_hex_dump(struct sigma_dut *dut, uint8_t *data, size_t len)
49{
50 char buf[512];
51 uint16_t index;
52 uint8_t *ptr;
53 int pos;
54
55 memset(buf, 0, sizeof(buf));
56 ptr = data;
57 pos = 0;
58 for (index = 0; index < len; index++) {
59 pos += sprintf(&(buf[pos]), "%02x ", *ptr++);
60 if (pos > 508)
61 break;
62 }
63 sigma_dut_print(dut, DUT_MSG_INFO, "HEXDUMP len=[%d]", (int) len);
64 sigma_dut_print(dut, DUT_MSG_INFO, "buf:%s", buf);
65}
66
67
68int nan_parse_hex(unsigned char c)
69{
70 if (c >= '0' && c <= '9')
71 return c - '0';
72 if (c >= 'a' && c <= 'f')
73 return c - 'a' + 10;
74 if (c >= 'A' && c <= 'F')
75 return c - 'A' + 10;
76 return 0;
77}
78
79
80int nan_parse_token(const char *tokenIn, u8 *tokenOut, int *filterLen)
81{
82 int total_len = 0, len = 0;
83 char *saveptr = NULL;
84
85 tokenIn = strtok_r((char *) tokenIn, ":", &saveptr);
86 while (tokenIn != NULL) {
87 len = strlen(tokenIn);
88 if (len == 1 && *tokenIn == '*')
89 len = 0;
90 tokenOut[total_len++] = (u8) len;
91 if (len != 0)
92 memcpy((u8 *) tokenOut + total_len, tokenIn, len);
93 total_len += len;
94 tokenIn = strtok_r(NULL, ":", &saveptr);
95 }
96 *filterLen = total_len;
97 return 0;
98}
99
100
101int nan_parse_mac_address(struct sigma_dut *dut, const char *arg, u8 *addr)
102{
103 if (strlen(arg) != 17) {
104 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid mac address %s",
105 arg);
106 sigma_dut_print(dut, DUT_MSG_ERROR,
107 "expected format xx:xx:xx:xx:xx:xx");
108 return -1;
109 }
110
111 addr[0] = nan_parse_hex(arg[0]) << 4 | nan_parse_hex(arg[1]);
112 addr[1] = nan_parse_hex(arg[3]) << 4 | nan_parse_hex(arg[4]);
113 addr[2] = nan_parse_hex(arg[6]) << 4 | nan_parse_hex(arg[7]);
114 addr[3] = nan_parse_hex(arg[9]) << 4 | nan_parse_hex(arg[10]);
115 addr[4] = nan_parse_hex(arg[12]) << 4 | nan_parse_hex(arg[13]);
116 addr[5] = nan_parse_hex(arg[15]) << 4 | nan_parse_hex(arg[16]);
117
118 return 0;
119}
120
121
122int nan_parse_mac_address_list(struct sigma_dut *dut, const char *input,
123 u8 *output, u16 max_addr_allowed)
124{
125 /*
126 * Reads a list of mac address separated by space. Each MAC address
127 * should have the format of aa:bb:cc:dd:ee:ff.
128 */
129 char *saveptr;
130 char *token;
131 int i = 0;
132
133 for (i = 0; i < max_addr_allowed; i++) {
134 token = strtok_r((i == 0) ? (char *) input : NULL,
135 " ", &saveptr);
136 if (token) {
137 nan_parse_mac_address(dut, token, output);
138 output += NAN_MAC_ADDR_LEN;
139 } else
140 break;
141 }
142
143 sigma_dut_print(dut, DUT_MSG_INFO, "Num MacAddress:%d", i);
144
145 return i;
146}
147
148
149int nan_parse_hex_string(struct sigma_dut *dut, const char *input,
150 u8 *output, int *outputlen)
151{
152 int i = 0;
153 int j = 0;
154
155 for (i = 0; i < (int) strlen(input) && j < *outputlen; i += 2) {
156 output[j] = nan_parse_hex(input[i]);
157 if (i + 1 < (int) strlen(input)) {
158 output[j] = ((output[j] << 4) |
159 nan_parse_hex(input[i + 1]));
160 }
161 j++;
162 }
163 *outputlen = j;
164 sigma_dut_print(dut, DUT_MSG_INFO, "Input:%s inputlen:%d outputlen:%d",
165 input, (int) strlen(input), (int) *outputlen);
166 return 0;
167}
168
169
170int wait(struct timespec abstime)
171{
172 struct timeval now;
173
174 gettimeofday(&now, NULL);
175
176 abstime.tv_sec += now.tv_sec;
177 if (((abstime.tv_nsec + now.tv_usec * 1000) > 1000 * 1000 * 1000) ||
178 (abstime.tv_nsec + now.tv_usec * 1000 < 0)) {
179 abstime.tv_sec += 1;
180 abstime.tv_nsec += now.tv_usec * 1000;
181 abstime.tv_nsec -= 1000 * 1000 * 1000;
182 } else {
183 abstime.tv_nsec += now.tv_usec * 1000;
184 }
185
186 return pthread_cond_timedwait(&gCondition, &gMutex, &abstime);
187}
188
189
190int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
191 struct sigma_conn *conn,
192 struct sigma_cmd *cmd)
193{
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700194 const char *oper_chan = get_param(cmd, "oper_chn");
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700195 const char *pmk = get_param(cmd, "PMK");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700197 if (oper_chan) {
198 sigma_dut_print(dut, DUT_MSG_INFO, "Operating Channel: %s",
199 oper_chan);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700200 dut->sta_channel = atoi(oper_chan);
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700201 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200202
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700203 if (pmk) {
204 int pmk_len;
205
206 sigma_dut_print(dut, DUT_MSG_INFO, "%s given string pmk: %s",
207 __func__, pmk);
208 memset(dut->nan_pmk, 0, NAN_PMK_INFO_LEN);
209 dut->nan_pmk_len = 0;
210 pmk_len = NAN_PMK_INFO_LEN;
211 nan_parse_hex_string(dut, &pmk[2], &dut->nan_pmk[0], &pmk_len);
212 dut->nan_pmk_len = pmk_len;
213 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
214 __func__, dut->nan_pmk_len);
215 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex pmk", __func__);
216 nan_hex_dump(dut, &dut->nan_pmk[0], dut->nan_pmk_len);
217 }
218
Rakesh Sunki14bff1d2017-03-30 14:47:55 -0700219 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200220 return 0;
221}
222
223
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700224void nan_print_further_availability_chan(struct sigma_dut *dut,
225 u8 num_chans,
226 NanFurtherAvailabilityChannel *fachan)
227{
228 int idx;
229
230 sigma_dut_print(dut, DUT_MSG_INFO,
231 "********Printing FurtherAvailabilityChan Info******");
232 sigma_dut_print(dut, DUT_MSG_INFO, "Numchans:%d", num_chans);
233 for (idx = 0; idx < num_chans; idx++) {
234 sigma_dut_print(dut, DUT_MSG_INFO,
235 "[%d]: NanAvailDuration:%d class_val:%02x channel:%d",
236 idx, fachan->entry_control,
237 fachan->class_val, fachan->channel);
238 sigma_dut_print(dut, DUT_MSG_INFO,
239 "[%d]: mapid:%d Availability bitmap:%08x",
240 idx, fachan->mapid,
241 fachan->avail_interval_bitmap);
242 }
243 sigma_dut_print(dut, DUT_MSG_INFO,
244 "*********************Done**********************");
245}
246
247
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200248int sigma_nan_enable(struct sigma_dut *dut, struct sigma_conn *conn,
249 struct sigma_cmd *cmd)
250{
251 const char *master_pref = get_param(cmd, "MasterPref");
252 const char *rand_fac = get_param(cmd, "RandFactor");
253 const char *hop_count = get_param(cmd, "HopCount");
254 const char *high_tsf = get_param(cmd, "HighTSF");
255 const char *sdftx_band = get_param(cmd, "SDFTxBand");
256 const char *oper_chan = get_param(cmd, "oper_chn");
257 const char *further_avail_ind = get_param(cmd, "FurtherAvailInd");
258 const char *band = get_param(cmd, "Band");
259 const char *only_5g = get_param(cmd, "5GOnly");
260 struct timespec abstime;
261 NanEnableRequest req;
262
263 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200264 req.cluster_low = 0;
265 req.cluster_high = 0xFFFF;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700266 req.master_pref = 100;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200267
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700268 /* This is a debug hack to beacon in channel 11 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200269 if (oper_chan) {
270 req.config_2dot4g_support = 1;
271 req.support_2dot4g_val = 111;
272 }
273
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200274 if (master_pref) {
275 int master_pref_val = strtoul(master_pref, NULL, 0);
276
277 req.master_pref = master_pref_val;
278 }
279
280 if (rand_fac) {
281 int rand_fac_val = strtoul(rand_fac, NULL, 0);
282
283 req.config_random_factor_force = 1;
284 req.random_factor_force_val = rand_fac_val;
285 }
286
287 if (hop_count) {
288 int hop_count_val = strtoul(hop_count, NULL, 0);
289
290 req.config_hop_count_force = 1;
291 req.hop_count_force_val = hop_count_val;
292 }
293
294 if (sdftx_band) {
295 if (strcasecmp(sdftx_band, "5G") == 0) {
296 req.config_2dot4g_support = 1;
297 req.support_2dot4g_val = 0;
298 }
299 }
300
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700301 sigma_dut_print(dut, DUT_MSG_INFO,
302 "%s: Setting dual band 2.4 GHz and 5 GHz by default",
303 __func__);
304 /* Enable 2.4 GHz support */
305 req.config_2dot4g_support = 1;
306 req.support_2dot4g_val = 1;
307 req.config_2dot4g_beacons = 1;
308 req.beacon_2dot4g_val = 1;
309 req.config_2dot4g_sdf = 1;
310 req.sdf_2dot4g_val = 1;
311
312 /* Enable 5 GHz support */
313 req.config_support_5g = 1;
314 req.support_5g_val = 1;
315 req.config_5g_beacons = 1;
316 req.beacon_5g_val = 1;
317 req.config_5g_sdf = 1;
318 req.sdf_5g_val = 1;
319
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200320 if (band) {
321 if (strcasecmp(band, "24G") == 0) {
322 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700323 "Band 2.4 GHz selected, disable 5 GHz");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200324 /* Disable 5G support */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700325 req.config_support_5g = 1;
326 req.support_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200327 req.config_5g_beacons = 1;
328 req.beacon_5g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700329 req.config_5g_sdf = 1;
330 req.sdf_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200331 }
332 }
333
334 if (further_avail_ind) {
335 sigma_dut_print(dut, DUT_MSG_INFO, "FAM Test Enabled");
336 if (strcasecmp(further_avail_ind, "tx") == 0) {
337 is_fam = 1;
338 nan_further_availability_tx(dut, conn, cmd);
339 return 0;
340 } else if (strcasecmp(further_avail_ind, "rx") == 0) {
341 nan_further_availability_rx(dut, conn, cmd);
342 return 0;
343 }
344 }
345
346 if (only_5g && atoi(only_5g)) {
347 sigma_dut_print(dut, DUT_MSG_INFO, "5GHz only enabled");
348 req.config_2dot4g_support = 1;
349 req.support_2dot4g_val = 1;
350 req.config_2dot4g_beacons = 1;
351 req.beacon_2dot4g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700352 req.config_2dot4g_sdf = 1;
353 req.sdf_2dot4g_val = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200354 }
355
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700356 nan_enable_request(0, global_interface_handle, &req);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700357
358 /* To ensure sta_get_events to get the events
359 * only after joining the NAN cluster. */
360 abstime.tv_sec = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200361 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700362 wait(abstime);
363
364 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200365}
366
367
368int sigma_nan_disable(struct sigma_dut *dut, struct sigma_conn *conn,
369 struct sigma_cmd *cmd)
370{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200371 struct timespec abstime;
372
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700373 nan_disable_request(0, global_interface_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200374
375 abstime.tv_sec = 4;
376 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700377 wait(abstime);
378
379 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200380}
381
382
383int sigma_nan_config_enable(struct sigma_dut *dut, struct sigma_conn *conn,
384 struct sigma_cmd *cmd)
385{
386 const char *master_pref = get_param(cmd, "MasterPref");
387 const char *rand_fac = get_param(cmd, "RandFactor");
388 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700389 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200390 struct timespec abstime;
391 NanConfigRequest req;
392
393 memset(&req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200394 req.config_rssi_proximity = 1;
395 req.rssi_proximity = 70;
396
397 if (master_pref) {
398 int master_pref_val = strtoul(master_pref, NULL, 0);
399
400 req.config_master_pref = 1;
401 req.master_pref = master_pref_val;
402 }
403
404 if (rand_fac) {
405 int rand_fac_val = strtoul(rand_fac, NULL, 0);
406
407 req.config_random_factor_force = 1;
408 req.random_factor_force_val = rand_fac_val;
409 }
410
411 if (hop_count) {
412 int hop_count_val = strtoul(hop_count, NULL, 0);
413
414 req.config_hop_count_force = 1;
415 req.hop_count_force_val = hop_count_val;
416 }
417
Rakesh Sunki107356c2017-03-30 14:47:55 -0700418 ret = nan_config_request(0, global_interface_handle, &req);
419 if (ret != WIFI_SUCCESS)
420 send_resp(dut, conn, SIGMA_ERROR, "NAN config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200421
422 abstime.tv_sec = 4;
423 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700424 wait(abstime);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200425
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700426 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200427}
428
429
430static int sigma_nan_subscribe_request(struct sigma_dut *dut,
431 struct sigma_conn *conn,
432 struct sigma_cmd *cmd)
433{
434 const char *subscribe_type = get_param(cmd, "SubscribeType");
435 const char *service_name = get_param(cmd, "ServiceName");
436 const char *disc_range = get_param(cmd, "DiscoveryRange");
437 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
438 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
439 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
440 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
441 const char *include_bit = get_param(cmd, "IncludeBit");
442 const char *mac = get_param(cmd, "MAC");
443 const char *srf_type = get_param(cmd, "SRFType");
444 NanSubscribeRequest req;
445 int filter_len_rx = 0, filter_len_tx = 0;
446 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
447 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -0700448 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200449
450 memset(&req, 0, sizeof(NanSubscribeRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200451 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -0700452 req.period = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200453 req.subscribe_type = 1;
454 req.serviceResponseFilter = 1; /* MAC */
455 req.serviceResponseInclude = 0;
456 req.ssiRequiredForMatchIndication = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700457 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200458 req.subscribe_count = 0;
459
460 if (subscribe_type) {
461 if (strcasecmp(subscribe_type, "Active") == 0) {
462 req.subscribe_type = 1;
463 } else if (strcasecmp(subscribe_type, "Passive") == 0) {
464 req.subscribe_type = 0;
465 } else if (strcasecmp(subscribe_type, "Cancel") == 0) {
466 NanSubscribeCancelRequest req;
467
468 memset(&req, 0, sizeof(NanSubscribeCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -0700469 ret = nan_subscribe_cancel_request(
470 0, global_interface_handle, &req);
471 if (ret != WIFI_SUCCESS) {
472 send_resp(dut, conn, SIGMA_ERROR,
473 "NAN subscribe cancel request failed");
474 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200475 return 0;
476 }
477 }
478
479 if (disc_range)
480 req.rssi_threshold_flag = atoi(disc_range);
481
482 if (sdftx_dw)
483 req.subscribe_count = atoi(sdftx_dw);
484
485 /* Check this once again if config can be called here (TBD) */
486 if (discrange_ltd)
487 req.rssi_threshold_flag = atoi(discrange_ltd);
488
489 if (include_bit) {
490 int include_bit_val = atoi(include_bit);
491
492 req.serviceResponseInclude = include_bit_val;
493 sigma_dut_print(dut, DUT_MSG_INFO, "Includebit set %d",
494 req.serviceResponseInclude);
495 }
496
497 if (srf_type) {
498 int srf_type_val = atoi(srf_type);
499
500 if (srf_type_val == 1)
501 req.serviceResponseFilter = 0; /* Bloom */
502 else
503 req.serviceResponseFilter = 1; /* MAC */
504 req.useServiceResponseFilter = 1;
505 sigma_dut_print(dut, DUT_MSG_INFO, "srfFilter %d",
506 req.serviceResponseFilter);
507 }
508
509 if (mac) {
510 sigma_dut_print(dut, DUT_MSG_INFO, "MAC_ADDR List %s", mac);
511 req.num_intf_addr_present = nan_parse_mac_address_list(
512 dut, mac, &req.intf_addr[0][0],
513 NAN_MAX_SUBSCRIBE_MAX_ADDRESS);
514 }
515
516 memset(input_rx, 0, sizeof(input_rx));
517 memset(input_tx, 0, sizeof(input_tx));
518 if (rx_match_filter) {
519 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
520 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
521 filter_len_rx);
522 }
523 if (tx_match_filter) {
524 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
525 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
526 filter_len_tx);
527 }
528
529 if (tx_match_filter) {
530 req.tx_match_filter_len = filter_len_tx;
531 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
532 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
533 }
534 if (rx_match_filter) {
535 req.rx_match_filter_len = filter_len_rx;
536 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
537 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
538 }
539
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700540 if (service_name) {
541 strlcpy((char *) req.service_name, service_name,
542 strlen(service_name) + 1);
543 req.service_name_len = strlen(service_name);
544 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200545
Rakesh Sunki107356c2017-03-30 14:47:55 -0700546 ret = nan_subscribe_request(0, global_interface_handle, &req);
547 if (ret != WIFI_SUCCESS) {
548 send_resp(dut, conn, SIGMA_ERROR,
549 "NAN subscribe request failed");
550 }
551
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200552 return 0;
553}
554
555
Rakesh Sunkid7344c02017-03-30 14:47:55 -0700556static int sigma_ndp_configure_band(struct sigma_dut *dut,
557 struct sigma_conn *conn,
558 struct sigma_cmd *cmd,
559 NdpSupportedBand band_config_val)
560{
561 wifi_error ret;
562 NanDebugParams cfg_debug;
563 int size;
564
565 memset(&cfg_debug, 0, sizeof(NanDebugParams));
566 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SUPPORTED_BANDS;
567 memcpy(cfg_debug.debug_cmd_data, &band_config_val, sizeof(int));
568 sigma_dut_print(dut, DUT_MSG_INFO, "%s:setting debug cmd=0x%x",
569 __func__, cfg_debug.cmd);
570 size = sizeof(u32) + sizeof(int);
571 ret = nan_debug_command_config(0, global_interface_handle, cfg_debug,
572 size);
573 if (ret != WIFI_SUCCESS)
574 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
575
576 return 0;
577}
578
579
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200580int config_post_disc_attr(void)
581{
Rakesh Sunki107356c2017-03-30 14:47:55 -0700582 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200583 NanConfigRequest configReq;
584
585 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200586
587 /* Configure Post disc attr */
588 /* Make these defines and use correct enum */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700589 configReq.num_config_discovery_attr = 1;
590 configReq.discovery_attr_val[0].type = 4; /* Further Nan discovery */
591 configReq.discovery_attr_val[0].role = 0;
592 configReq.discovery_attr_val[0].transmit_freq = 1;
593 configReq.discovery_attr_val[0].duration = 0;
594 configReq.discovery_attr_val[0].avail_interval_bitmap = 0x00000008;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200595
Rakesh Sunki107356c2017-03-30 14:47:55 -0700596 ret = nan_config_request(0, global_interface_handle, &configReq);
597 if (ret != WIFI_SUCCESS) {
598 sigma_dut_print(global_dut, DUT_MSG_INFO,
599 "NAN config request failed while configuring post discovery attribute");
600 }
601
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200602 return 0;
603}
604
605
606int sigma_nan_publish_request(struct sigma_dut *dut, struct sigma_conn *conn,
607 struct sigma_cmd *cmd)
608{
609 const char *publish_type = get_param(cmd, "PublishType");
610 const char *service_name = get_param(cmd, "ServiceName");
611 const char *disc_range = get_param(cmd, "DiscoveryRange");
612 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
613 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
614 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
615 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
616 NanPublishRequest req;
617 int filter_len_rx = 0, filter_len_tx = 0;
618 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
619 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -0700620 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200621
622 memset(&req, 0, sizeof(NanPublishRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200623 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -0700624 req.period = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700625 req.publish_match_indicator = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200626 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
627 req.tx_type = NAN_TX_TYPE_BROADCAST;
628 req.publish_count = 0;
Rakesh Sunki0a0eea82017-03-30 14:47:55 -0700629 req.service_responder_policy = NAN_SERVICE_ACCEPT_POLICY_ALL;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700630
631 if (service_name) {
632 strlcpy((char *) req.service_name, service_name,
633 strlen(service_name) + 1);
634 req.service_name_len = strlen(service_name);
635 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200636
637 if (publish_type) {
638 if (strcasecmp(publish_type, "Solicited") == 0) {
639 req.publish_type = NAN_PUBLISH_TYPE_SOLICITED;
640 } else if (strcasecmp(publish_type, "Cancel") == 0) {
641 NanPublishCancelRequest req;
642
643 memset(&req, 0, sizeof(NanPublishCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -0700644 ret = nan_publish_cancel_request(
645 0, global_interface_handle, &req);
646 if (ret != WIFI_SUCCESS) {
647 send_resp(dut, conn, SIGMA_ERROR,
648 "Unable to cancel nan publish request");
649 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200650 return 0;
651 }
652 }
653
654 if (disc_range)
655 req.rssi_threshold_flag = atoi(disc_range);
656
657 if (sdftx_dw)
658 req.publish_count = atoi(sdftx_dw);
659
660 if (discrange_ltd)
661 req.rssi_threshold_flag = atoi(discrange_ltd);
662
663 memset(input_rx, 0, sizeof(input_rx));
664 memset(input_tx, 0, sizeof(input_tx));
665 if (rx_match_filter) {
666 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
667 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
668 filter_len_rx);
669 }
670 if (tx_match_filter) {
671 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
672 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
673 filter_len_tx);
674 }
675
676 if (is_fam == 1) {
677 config_post_disc_attr();
678 /* TODO: Add comments regarding this step */
679 req.connmap = 0x10;
680 }
681
682 if (tx_match_filter) {
683 req.tx_match_filter_len = filter_len_tx;
684 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
685 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
686 }
687
688 if (rx_match_filter) {
689 req.rx_match_filter_len = filter_len_rx;
690 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
691 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
692 }
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700693
694 if (service_name) {
695 strlcpy((char *) req.service_name, service_name,
696 strlen(service_name) + 1);
697 req.service_name_len = strlen(service_name);
698 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200699
Rakesh Sunki107356c2017-03-30 14:47:55 -0700700 ret = nan_publish_request(0, global_interface_handle, &req);
701 if (ret != WIFI_SUCCESS)
702 send_resp(dut, conn, SIGMA_ERROR, "Unable to publish");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200703
704 return 0;
705}
706
707
708static int nan_further_availability_rx(struct sigma_dut *dut,
709 struct sigma_conn *conn,
710 struct sigma_cmd *cmd)
711{
712 const char *master_pref = get_param(cmd, "MasterPref");
713 const char *rand_fac = get_param(cmd, "RandFactor");
714 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700715 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200716 struct timespec abstime;
717
718 NanEnableRequest req;
719
720 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200721 req.cluster_low = 0;
722 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200723 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200724
725 if (master_pref)
726 req.master_pref = strtoul(master_pref, NULL, 0);
727
728 if (rand_fac) {
729 int rand_fac_val = strtoul(rand_fac, NULL, 0);
730
731 req.config_random_factor_force = 1;
732 req.random_factor_force_val = rand_fac_val;
733 }
734
735 if (hop_count) {
736 int hop_count_val = strtoul(hop_count, NULL, 0);
737
738 req.config_hop_count_force = 1;
739 req.hop_count_force_val = hop_count_val;
740 }
741
Rakesh Sunki107356c2017-03-30 14:47:55 -0700742 ret = nan_enable_request(0, global_interface_handle, &req);
743 if (ret != WIFI_SUCCESS) {
744 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
745 return 0;
746 }
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700747
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200748 abstime.tv_sec = 4;
749 abstime.tv_nsec = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200750 wait(abstime);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700751
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200752 return 0;
753}
754
755
756static int nan_further_availability_tx(struct sigma_dut *dut,
757 struct sigma_conn *conn,
758 struct sigma_cmd *cmd)
759{
760 const char *master_pref = get_param(cmd, "MasterPref");
761 const char *rand_fac = get_param(cmd, "RandFactor");
762 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700763 wifi_error ret;
764
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200765 NanEnableRequest req;
766 NanConfigRequest configReq;
767
768 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200769 req.cluster_low = 0;
770 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200771 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200772
773 if (master_pref)
774 req.master_pref = strtoul(master_pref, NULL, 0);
775
776 if (rand_fac) {
777 int rand_fac_val = strtoul(rand_fac, NULL, 0);
778
779 req.config_random_factor_force = 1;
780 req.random_factor_force_val = rand_fac_val;
781 }
782
783 if (hop_count) {
784 int hop_count_val = strtoul(hop_count, NULL, 0);
785
786 req.config_hop_count_force = 1;
787 req.hop_count_force_val = hop_count_val;
788 }
789
Rakesh Sunki107356c2017-03-30 14:47:55 -0700790 ret = nan_enable_request(0, global_interface_handle, &req);
791 if (ret != WIFI_SUCCESS) {
792 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
793 return 0;
794 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200795
796 /* Start the config of fam */
797
798 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200799
800 configReq.config_fam = 1;
801 configReq.fam_val.numchans = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700802 configReq.fam_val.famchan[0].entry_control = 0;
803 configReq.fam_val.famchan[0].class_val = 81;
804 configReq.fam_val.famchan[0].channel = 6;
805 configReq.fam_val.famchan[0].mapid = 0;
806 configReq.fam_val.famchan[0].avail_interval_bitmap = 0x7ffffffe;
807
Rakesh Sunki107356c2017-03-30 14:47:55 -0700808 ret = nan_config_request(0, global_interface_handle, &configReq);
809 if (ret != WIFI_SUCCESS)
810 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200811
812 return 0;
813}
814
815
816int sigma_nan_transmit_followup(struct sigma_dut *dut,
817 struct sigma_conn *conn,
818 struct sigma_cmd *cmd)
819{
820 const char *mac = get_param(cmd, "mac");
821 const char *requestor_id = get_param(cmd, "RemoteInstanceId");
822 const char *local_id = get_param(cmd, "LocalInstanceId");
823 const char *service_name = get_param(cmd, "servicename");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700824 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200825 NanTransmitFollowupRequest req;
826
827 memset(&req, 0, sizeof(NanTransmitFollowupRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700828 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200829 req.addr[0] = 0xFF;
830 req.addr[1] = 0xFF;
831 req.addr[2] = 0xFF;
832 req.addr[3] = 0xFF;
833 req.addr[4] = 0xFF;
834 req.addr[5] = 0xFF;
835 req.priority = NAN_TX_PRIORITY_NORMAL;
836 req.dw_or_faw = 0;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700837
838 if (service_name)
839 req.service_specific_info_len = strlen(service_name);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200840
841 if (requestor_id) {
842 /* int requestor_id_val = atoi(requestor_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700843 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200844 }
845 if (local_id) {
846 /* int local_id_val = atoi(local_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700847 req.publish_subscribe_id = global_header_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200848 }
849
850 if (mac == NULL) {
851 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid MAC Address");
852 return -1;
853 }
854 nan_parse_mac_address(dut, mac, req.addr);
855
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200856 if (requestor_id)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700857 req.requestor_instance_id = strtoul(requestor_id, NULL, 0);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200858
Rakesh Sunki107356c2017-03-30 14:47:55 -0700859 ret = nan_transmit_followup_request(0, global_interface_handle, &req);
860 if (ret != WIFI_SUCCESS) {
861 send_resp(dut, conn, SIGMA_ERROR,
862 "Unable to complete nan transmit followup");
863 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700864
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200865 return 0;
866}
867
Rakesh Sunki107356c2017-03-30 14:47:55 -0700868
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200869/* NotifyResponse invoked to notify the status of the Request */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700870void nan_notify_response(transaction_id id, NanResponseMsg *rsp_data)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200871{
872 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700873 "%s: status %d value %d response_type %d",
874 __func__,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200875 rsp_data->status, rsp_data->value,
876 rsp_data->response_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -0700877 if (rsp_data->response_type == NAN_RESPONSE_STATS &&
878 rsp_data->body.stats_response.stats_type ==
879 NAN_STATS_ID_DE_TIMING_SYNC) {
880 NanSyncStats *pSyncStats;
881
882 sigma_dut_print(global_dut, DUT_MSG_INFO,
883 "%s: stats_type %d", __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700884 rsp_data->body.stats_response.stats_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -0700885 pSyncStats = &rsp_data->body.stats_response.data.sync_stats;
886 memcpy(&global_nan_sync_stats, pSyncStats,
887 sizeof(NanSyncStats));
888 pthread_cond_signal(&gCondition);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200889 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200890}
891
892
893/* Events Callback */
894void nan_event_publish_replied(NanPublishRepliedInd *event)
895{
896 sigma_dut_print(global_dut, DUT_MSG_INFO,
897 "%s: handle %d " MAC_ADDR_STR " rssi:%d",
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700898 __func__, event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200899 MAC_ADDR_ARRAY(event->addr), event->rssi_value);
900 event_anyresponse = 1;
901 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700902 "EventName,Replied,RemoteInstanceID %d,mac," MAC_ADDR_STR,
903 (event->requestor_instance_id >> 24),
904 MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200905}
906
907
908/* Events Callback */
909void nan_event_publish_terminated(NanPublishTerminatedInd *event)
910{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700911 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: publish_id %d reason %d",
912 __func__, event->publish_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200913}
914
915
916/* Events Callback */
917void nan_event_match(NanMatchInd *event)
918{
919 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700920 "%s: Pub/Sub Id %d remote_requestor_id %08x "
921 MAC_ADDR_STR
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200922 " rssi:%d",
923 __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700924 event->publish_subscribe_id,
925 event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200926 MAC_ADDR_ARRAY(event->addr),
927 event->rssi_value);
928 event_anyresponse = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700929 global_header_handle = event->publish_subscribe_id;
930 global_match_handle = event->requestor_instance_id;
931
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200932 /* memset(event_resp_buf, 0, sizeof(event_resp_buf)); */
933 /* global_pub_sub_handle = event->header.handle; */
934 /* Print the SSI */
935 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing SSI:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700936 nan_hex_dump(global_dut, event->service_specific_info,
937 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200938 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
939 "EventName,DiscoveryResult,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700940 MAC_ADDR_STR " ", (event->requestor_instance_id >> 24),
941 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200942
943 /* Print the match filter */
944 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing sdf match filter:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700945 nan_hex_dump(global_dut, event->sdf_match_filter,
946 event->sdf_match_filter_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200947
948 /* Print the conn_capability */
949 sigma_dut_print(global_dut, DUT_MSG_INFO,
950 "Printing PostConnectivity Capability");
951 if (event->is_conn_capability_valid) {
952 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfd supported:%s",
953 event->conn_capability.is_wfd_supported ?
954 "yes" : "no");
955 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfds supported:%s",
956 (event->conn_capability.is_wfds_supported ?
957 "yes" : "no"));
958 sigma_dut_print(global_dut, DUT_MSG_INFO, "TDLS supported:%s",
959 (event->conn_capability.is_tdls_supported ?
960 "yes" : "no"));
961 sigma_dut_print(global_dut, DUT_MSG_INFO, "IBSS supported:%s",
962 (event->conn_capability.is_ibss_supported ?
963 "yes" : "no"));
964 sigma_dut_print(global_dut, DUT_MSG_INFO, "Mesh supported:%s",
965 (event->conn_capability.is_mesh_supported ?
966 "yes" : "no"));
967 sigma_dut_print(global_dut, DUT_MSG_INFO, "Infra Field:%d",
968 event->conn_capability.wlan_infra_field);
969 } else {
970 sigma_dut_print(global_dut, DUT_MSG_INFO,
971 "PostConnectivity Capability not present");
972 }
973
974 /* Print the discovery_attr */
975 sigma_dut_print(global_dut, DUT_MSG_INFO,
976 "Printing PostDiscovery Attribute");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700977 if (event->num_rx_discovery_attr) {
978 int idx;
979
980 for (idx = 0; idx < event->num_rx_discovery_attr; idx++) {
981 sigma_dut_print(global_dut, DUT_MSG_INFO,
982 "PostDiscovery Attribute - %d", idx);
983 sigma_dut_print(global_dut, DUT_MSG_INFO,
984 "Conn Type:%d Device Role:%d"
985 MAC_ADDR_STR,
986 event->discovery_attr[idx].type,
987 event->discovery_attr[idx].role,
988 MAC_ADDR_ARRAY(event->discovery_attr[idx].addr));
989 sigma_dut_print(global_dut, DUT_MSG_INFO,
990 "Duration:%d MapId:%d "
991 "avail_interval_bitmap:%04x",
992 event->discovery_attr[idx].duration,
993 event->discovery_attr[idx].mapid,
994 event->discovery_attr[idx].avail_interval_bitmap);
995 sigma_dut_print(global_dut, DUT_MSG_INFO,
996 "Printing Mesh Id:");
997 nan_hex_dump(global_dut,
998 event->discovery_attr[idx].mesh_id,
999 event->discovery_attr[idx].mesh_id_len);
1000 sigma_dut_print(global_dut, DUT_MSG_INFO,
1001 "Printing Infrastructure Ssid:");
1002 nan_hex_dump(global_dut,
1003 event->discovery_attr[idx].infrastructure_ssid_val,
1004 event->discovery_attr[idx].infrastructure_ssid_len);
1005 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001006 } else {
1007 sigma_dut_print(global_dut, DUT_MSG_INFO,
1008 "PostDiscovery attribute not present");
1009 }
1010
1011 /* Print the fam */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001012 if (event->num_chans) {
1013 nan_print_further_availability_chan(global_dut,
1014 event->num_chans,
1015 &event->famchan[0]);
1016 } else {
1017 sigma_dut_print(global_dut, DUT_MSG_INFO,
1018 "Further Availability Map not present");
1019 }
1020 if (event->cluster_attribute_len) {
1021 sigma_dut_print(global_dut, DUT_MSG_INFO,
1022 "Printing Cluster Attribute:");
1023 nan_hex_dump(global_dut, event->cluster_attribute,
1024 event->cluster_attribute_len);
1025 } else {
1026 sigma_dut_print(global_dut, DUT_MSG_INFO,
1027 "Cluster Attribute not present");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001028 }
1029}
1030
1031
1032/* Events Callback */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001033void nan_event_match_expired(NanMatchExpiredInd *event)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001034{
1035 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001036 "%s: publish_subscribe_id %d match_handle %08x",
1037 __func__, event->publish_subscribe_id,
1038 event->requestor_instance_id);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001039}
1040
1041
1042/* Events Callback */
1043void nan_event_subscribe_terminated(NanSubscribeTerminatedInd *event)
1044{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001045 sigma_dut_print(global_dut, DUT_MSG_INFO,
1046 "%s: Subscribe Id %d reason %d",
1047 __func__, event->subscribe_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048}
1049
1050
1051/* Events Callback */
1052void nan_event_followup(NanFollowupInd *event)
1053{
1054 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001055 "%s: Publish/Subscribe Id %d match_handle 0x%08x dw_or_faw %d "
1056 MAC_ADDR_STR, __func__, event->publish_subscribe_id,
1057 event->requestor_instance_id, event->dw_or_faw,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001058 MAC_ADDR_ARRAY(event->addr));
1059
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001060 global_match_handle = event->publish_subscribe_id;
1061 global_header_handle = event->requestor_instance_id;
1062 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Printing SSI", __func__);
1063 nan_hex_dump(global_dut, event->service_specific_info,
1064 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001065 event_anyresponse = 1;
1066 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1067 "EventName,FollowUp,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001068 MAC_ADDR_STR " ", event->requestor_instance_id >> 24,
1069 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001070}
1071
1072
1073/* Events Callback */
1074void nan_event_disceng_event(NanDiscEngEventInd *event)
1075{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001076 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: event_type %d",
1077 __func__, event->event_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001078
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001079 if (event->event_type == NAN_EVENT_ID_JOINED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001080 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Joined cluster "
1081 MAC_ADDR_STR,
1082 __func__,
1083 MAC_ADDR_ARRAY(event->data.cluster.addr));
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001084 /* To ensure sta_get_events to get the events
1085 * only after joining the NAN cluster. */
1086 pthread_cond_signal(&gCondition);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001087 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001088 if (event->event_type == NAN_EVENT_ID_STARTED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001089 sigma_dut_print(global_dut, DUT_MSG_INFO,
1090 "%s: Started cluster " MAC_ADDR_STR,
1091 __func__,
1092 MAC_ADDR_ARRAY(event->data.cluster.addr));
1093 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001094 if (event->event_type == NAN_EVENT_ID_DISC_MAC_ADDR) {
1095 sigma_dut_print(global_dut, DUT_MSG_INFO,
1096 "%s: Discovery Mac Address "
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001097 MAC_ADDR_STR,
1098 __func__,
1099 MAC_ADDR_ARRAY(event->data.mac_addr.addr));
1100 memcpy(global_nan_mac_addr, event->data.mac_addr.addr,
1101 sizeof(global_nan_mac_addr));
1102 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001103}
1104
1105
1106/* Events Callback */
1107void nan_event_disabled(NanDisabledInd *event)
1108{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001109 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: reason %d",
1110 __func__, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001111 /* pthread_cond_signal(&gCondition); */
1112}
1113
1114
Rakesh Sunki4c086672017-03-30 14:47:55 -07001115/* Events callback */
1116static void ndp_event_data_indication(NanDataPathRequestInd *event)
1117{
1118 sigma_dut_print(global_dut, DUT_MSG_INFO,
1119 "%s: Service Instance Id: %d Peer Discovery MAC ADDR "
1120 MAC_ADDR_STR
1121 " NDP Instance Id: %d App Info len %d App Info %s",
1122 __func__,
1123 event->service_instance_id,
1124 MAC_ADDR_ARRAY(event->peer_disc_mac_addr),
1125 event->ndp_instance_id,
1126 event->app_info.ndp_app_info_len,
1127 event->app_info.ndp_app_info);
1128
1129 global_ndp_instance_id = event->ndp_instance_id;
1130}
1131
1132
1133/* Events callback */
1134static void ndp_event_data_confirm(NanDataPathConfirmInd *event)
1135{
1136 sigma_dut_print(global_dut, DUT_MSG_INFO,
1137 "Received NDP Confirm Indication");
1138
1139 global_ndp_instance_id = event->ndp_instance_id;
1140 if (system("ifconfig nan0 up") != 0) {
1141 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1142 "Failed to set nan interface up");
1143 return;
1144 }
1145 if (system("ip -6 route add fe80::/64 dev nan0 table local") != 0) {
1146 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1147 "Failed to run:ip -6 route replace fe80::/64 dev nan0 table local");
1148 return;
1149 }
1150}
1151
1152
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001153void * my_thread_function(void *ptr)
1154{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001155 wifi_event_loop(global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001156 pthread_exit(0);
1157 return (void *) NULL;
1158}
1159
1160
1161static NanCallbackHandler callbackHandler = {
1162 .NotifyResponse = nan_notify_response,
1163 .EventPublishReplied = nan_event_publish_replied,
1164 .EventPublishTerminated = nan_event_publish_terminated,
1165 .EventMatch = nan_event_match,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001166 .EventMatchExpired = nan_event_match_expired,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001167 .EventSubscribeTerminated = nan_event_subscribe_terminated,
1168 .EventFollowup = nan_event_followup,
1169 .EventDiscEngEvent = nan_event_disceng_event,
1170 .EventDisabled = nan_event_disabled,
Rakesh Sunki4c086672017-03-30 14:47:55 -07001171 .EventDataRequest = ndp_event_data_indication,
1172 .EventDataConfirm = ndp_event_data_confirm,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001173};
1174
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001175
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001176void nan_init(struct sigma_dut *dut)
1177{
1178 pthread_t thread1; /* thread variables */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001179 wifi_error err = wifi_initialize(&global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001180
1181 if (err) {
1182 printf("wifi hal initialize failed\n");
1183 return;
1184 }
1185
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001186 global_interface_handle = wifi_get_iface_handle(global_wifi_handle,
1187 (char *) "wlan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001188 /* create threads 1 */
1189 pthread_create(&thread1, NULL, &my_thread_function, NULL);
1190
1191 pthread_mutex_init(&gMutex, NULL);
1192 pthread_cond_init(&gCondition, NULL);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001193 if (global_interface_handle)
1194 nan_register_handler(global_interface_handle, callbackHandler);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001195}
1196
1197
1198void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1199 struct sigma_cmd *cmd)
1200{
1201 sigma_dut_print(dut, DUT_MSG_INFO, "NAN sta_reset_default");
1202
1203 if (nan_state == 0) {
1204 nan_init(dut);
1205 nan_state = 1;
1206 }
1207 is_fam = 0;
1208 event_anyresponse = 0;
1209 global_dut = dut;
Rakesh Sunki7d37f412017-03-30 14:47:55 -07001210 memset(&dut->nan_pmk[0], 0, NAN_PMK_INFO_LEN);
1211 dut->nan_pmk_len = 0;
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001212 dut->sta_channel = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001213 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001214 memset(&global_nan_sync_stats, 0, sizeof(global_nan_sync_stats));
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001215
1216 nan_data_interface_delete(0, global_interface_handle, (char *) "nan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001217 sigma_nan_disable(dut, conn, cmd);
1218}
1219
1220
1221int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1222 struct sigma_cmd *cmd)
1223{
1224 const char *program = get_param(cmd, "Prog");
1225 const char *nan_op = get_param(cmd, "NANOp");
1226 const char *method_type = get_param(cmd, "MethodType");
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001227 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001228 char resp_buf[100];
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001229 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001230
1231 if (program == NULL)
1232 return -1;
1233
1234 if (strcasecmp(program, "NAN") != 0) {
1235 send_resp(dut, conn, SIGMA_ERROR,
1236 "ErrorCode,Unsupported program");
1237 return 0;
1238 }
1239
1240 if (nan_op) {
1241 /*
1242 * NANOp has been specified.
1243 * We will build a nan_enable or nan_disable command.
1244 */
1245 if (strcasecmp(nan_op, "On") == 0) {
1246 if (sigma_nan_enable(dut, conn, cmd) == 0) {
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001247 ret = nan_data_interface_create(
1248 0, global_interface_handle,
1249 (char *) "nan0");
1250 if (ret != WIFI_SUCCESS) {
1251 sigma_dut_print(
1252 global_dut, DUT_MSG_ERROR,
1253 "Unable to create NAN data interface");
1254 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001255 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1256 MAC_ADDR_STR,
1257 MAC_ADDR_ARRAY(global_nan_mac_addr));
1258 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1259 } else {
1260 send_resp(dut, conn, SIGMA_ERROR,
1261 "NAN_ENABLE_FAILED");
1262 return -1;
1263 }
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001264
1265 if (band && strcasecmp(band, "24g") == 0) {
1266 sigma_dut_print(dut, DUT_MSG_INFO,
1267 "%s: Setting band to 2G Only",
1268 __func__);
1269 sigma_ndp_configure_band(
1270 dut, conn, cmd,
1271 NAN_DATA_PATH_SUPPORTED_BAND_2G);
1272 } else if (band && dut->sta_channel > 12) {
1273 sigma_ndp_configure_band(
1274 dut, conn, cmd,
1275 NAN_DATA_PATH_SUPPORT_DUAL_BAND);
1276 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001277 } else if (strcasecmp(nan_op, "Off") == 0) {
1278 sigma_nan_disable(dut, conn, cmd);
1279 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1280 }
1281 }
1282 if (nan_state && nan_op == NULL) {
1283 if (method_type) {
1284 if (strcasecmp(method_type, "Publish") == 0) {
1285 sigma_nan_publish_request(dut, conn, cmd);
1286 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1287 }
1288 if (strcasecmp(method_type, "Subscribe") == 0) {
1289 sigma_nan_subscribe_request(dut, conn, cmd);
1290 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1291 }
1292 if (strcasecmp(method_type, "Followup") == 0) {
1293 sigma_nan_transmit_followup(dut, conn, cmd);
1294 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1295 }
1296 } else {
1297 sigma_nan_config_enable(dut, conn, cmd);
1298 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1299 MAC_ADDR_STR,
1300 MAC_ADDR_ARRAY(global_nan_mac_addr));
1301 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1302 }
1303 }
1304
1305 return 0;
1306}
1307
1308
1309int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1310 struct sigma_cmd *cmd)
1311{
1312
1313 const char *program = get_param(cmd, "Program");
1314 const char *parameter = get_param(cmd, "Parameter");
1315 char resp_buf[100];
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001316 NanStatsRequest req;
1317 struct timespec abstime;
1318 u64 master_rank;
1319 u8 master_pref;
1320 u8 random_factor;
1321 u8 hop_count;
1322 u32 beacon_transmit_time;
1323 u32 ndp_channel_freq;
1324 u32 ndp_channel_freq2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001325
1326 if (program == NULL) {
1327 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Program Name");
1328 return -1;
1329 }
1330 if (strcasecmp(program, "NAN") != 0) {
1331 send_resp(dut, conn, SIGMA_ERROR,
1332 "ErrorCode,Unsupported program");
1333 return 0;
1334 }
1335
1336 if (parameter == NULL) {
1337 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Parameter");
1338 return -1;
1339 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001340
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001341 memset(&req, 0, sizeof(NanStatsRequest));
1342 req.stats_type = (NanStatsType) NAN_STATS_ID_DE_TIMING_SYNC;
1343 nan_stats_request(0, global_interface_handle, &req);
1344 /*
1345 * To ensure sta_get_events to get the events
1346 * only after joining the NAN cluster
1347 */
1348 abstime.tv_sec = 4;
1349 abstime.tv_nsec = 0;
1350 wait(abstime);
1351
1352 master_rank = global_nan_sync_stats.myRank;
1353 master_pref = (global_nan_sync_stats.myRank & 0xFF00000000000000) >> 56;
1354 random_factor = (global_nan_sync_stats.myRank & 0x00FF000000000000) >>
1355 48;
1356 hop_count = global_nan_sync_stats.currAmHopCount;
1357 beacon_transmit_time = global_nan_sync_stats.currAmBTT;
1358 ndp_channel_freq = global_nan_sync_stats.ndpChannelFreq;
1359 ndp_channel_freq2 = global_nan_sync_stats.ndpChannelFreq2;
1360
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001361 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001362 "%s: NanStatsRequest Master_pref:%02x, Random_factor:%02x, hop_count:%02x beacon_transmit_time:%d ndp_channel_freq:%d ndp_channel_freq2:%d",
1363 __func__, master_pref, random_factor,
1364 hop_count, beacon_transmit_time,
1365 ndp_channel_freq, ndp_channel_freq2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001366
1367 if (strcasecmp(parameter, "MasterPref") == 0) {
1368 snprintf(resp_buf, sizeof(resp_buf), "MasterPref,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001369 master_pref);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001370 } else if (strcasecmp(parameter, "MasterRank") == 0) {
1371 snprintf(resp_buf, sizeof(resp_buf), "MasterRank,0x%lx",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001372 master_rank);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001373 } else if (strcasecmp(parameter, "RandFactor") == 0) {
1374 snprintf(resp_buf, sizeof(resp_buf), "RandFactor,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001375 random_factor);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001376 } else if (strcasecmp(parameter, "HopCount") == 0) {
1377 snprintf(resp_buf, sizeof(resp_buf), "HopCount,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001378 hop_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001379 } else if (strcasecmp(parameter, "BeaconTransTime") == 0) {
1380 snprintf(resp_buf, sizeof(resp_buf), "BeaconTransTime 0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001381 beacon_transmit_time);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001382 } else if (strcasecmp(parameter, "NANStatus") == 0) {
1383 if (nan_state == 1)
1384 snprintf(resp_buf, sizeof(resp_buf), "On");
1385 else
1386 snprintf(resp_buf, sizeof(resp_buf), "Off");
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001387 } else if (strcasecmp(parameter, "NDPChannel") == 0) {
1388 if (ndp_channel_freq != 0 && ndp_channel_freq2 != 0) {
1389 snprintf(resp_buf, sizeof(resp_buf),
1390 "ndpchannel,%d,ndpchannel,%d",
1391 freq_to_channel(ndp_channel_freq),
1392 freq_to_channel(ndp_channel_freq2));
1393 } else if (ndp_channel_freq != 0) {
1394 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1395 freq_to_channel(ndp_channel_freq));
1396 } else if (ndp_channel_freq2 != 0) {
1397 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1398 freq_to_channel(ndp_channel_freq2));
1399 } else {
1400 sigma_dut_print(dut, DUT_MSG_ERROR,
1401 "%s: No Negotiated NDP Channels", __func__);
1402 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001403 } else {
1404 send_resp(dut, conn, SIGMA_ERROR, "Invalid Parameter");
1405 return 0;
1406 }
1407
1408 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1409 return 0;
1410}
1411
1412
1413int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1414 struct sigma_cmd *cmd)
1415{
1416 const char *action = get_param(cmd, "Action");
1417
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001418 if (!action)
1419 return 0;
1420
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001421 /* Check action for start, stop and get events. */
1422 if (strcasecmp(action, "Start") == 0) {
1423 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1424 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1425 } else if (strcasecmp(action, "Stop") == 0) {
1426 event_anyresponse = 0;
1427 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1428 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1429 } else if (strcasecmp(action, "Get") == 0) {
1430 if (event_anyresponse == 1) {
1431 send_resp(dut, conn, SIGMA_COMPLETE,
1432 global_event_resp_buf);
1433 } else {
1434 send_resp(dut, conn, SIGMA_COMPLETE, "EventList,NONE");
1435 }
1436 }
1437 return 0;
1438}
Rakesh Sunki4b75f962017-03-30 14:47:55 -07001439
1440#else /* #if NAN_CERT_VERSION */
1441
1442int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
1443 struct sigma_conn *conn,
1444 struct sigma_cmd *cmd)
1445{
1446 return 1;
1447}
1448
1449
1450int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1451 struct sigma_cmd *cmd)
1452{
1453 return 0;
1454
1455}
1456
1457
1458void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1459 struct sigma_cmd *cmd)
1460{
1461 return;
1462}
1463
1464
1465int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1466 struct sigma_cmd *cmd)
1467{
1468 return 0;
1469}
1470
1471
1472int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1473 struct sigma_cmd *cmd)
1474{
1475 return 0;
1476}
1477
1478#endif /* #if NAN_CERT_VERSION */