blob: db01778ca7c6eb8dc91bb3dada592b9c0265e63e [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
32#define MAC_ADDR_ARRAY(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
33#define MAC_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
34#ifndef ETH_ALEN
35#define ETH_ALEN 6
36#endif
37
38struct sigma_dut *global_dut = NULL;
39static char global_nan_mac_addr[ETH_ALEN];
40static char global_event_resp_buf[1024];
41
42static int nan_further_availability_tx(struct sigma_dut *dut,
43 struct sigma_conn *conn,
44 struct sigma_cmd *cmd);
45static int nan_further_availability_rx(struct sigma_dut *dut,
46 struct sigma_conn *conn,
47 struct sigma_cmd *cmd);
48
49
50void nan_hex_dump(struct sigma_dut *dut, uint8_t *data, size_t len)
51{
52 char buf[512];
53 uint16_t index;
54 uint8_t *ptr;
55 int pos;
56
57 memset(buf, 0, sizeof(buf));
58 ptr = data;
59 pos = 0;
60 for (index = 0; index < len; index++) {
61 pos += sprintf(&(buf[pos]), "%02x ", *ptr++);
62 if (pos > 508)
63 break;
64 }
65 sigma_dut_print(dut, DUT_MSG_INFO, "HEXDUMP len=[%d]", (int) len);
66 sigma_dut_print(dut, DUT_MSG_INFO, "buf:%s", buf);
67}
68
69
70int nan_parse_hex(unsigned char c)
71{
72 if (c >= '0' && c <= '9')
73 return c - '0';
74 if (c >= 'a' && c <= 'f')
75 return c - 'a' + 10;
76 if (c >= 'A' && c <= 'F')
77 return c - 'A' + 10;
78 return 0;
79}
80
81
82int nan_parse_token(const char *tokenIn, u8 *tokenOut, int *filterLen)
83{
84 int total_len = 0, len = 0;
85 char *saveptr = NULL;
86
87 tokenIn = strtok_r((char *) tokenIn, ":", &saveptr);
88 while (tokenIn != NULL) {
89 len = strlen(tokenIn);
90 if (len == 1 && *tokenIn == '*')
91 len = 0;
92 tokenOut[total_len++] = (u8) len;
93 if (len != 0)
94 memcpy((u8 *) tokenOut + total_len, tokenIn, len);
95 total_len += len;
96 tokenIn = strtok_r(NULL, ":", &saveptr);
97 }
98 *filterLen = total_len;
99 return 0;
100}
101
102
103int nan_parse_mac_address(struct sigma_dut *dut, const char *arg, u8 *addr)
104{
105 if (strlen(arg) != 17) {
106 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid mac address %s",
107 arg);
108 sigma_dut_print(dut, DUT_MSG_ERROR,
109 "expected format xx:xx:xx:xx:xx:xx");
110 return -1;
111 }
112
113 addr[0] = nan_parse_hex(arg[0]) << 4 | nan_parse_hex(arg[1]);
114 addr[1] = nan_parse_hex(arg[3]) << 4 | nan_parse_hex(arg[4]);
115 addr[2] = nan_parse_hex(arg[6]) << 4 | nan_parse_hex(arg[7]);
116 addr[3] = nan_parse_hex(arg[9]) << 4 | nan_parse_hex(arg[10]);
117 addr[4] = nan_parse_hex(arg[12]) << 4 | nan_parse_hex(arg[13]);
118 addr[5] = nan_parse_hex(arg[15]) << 4 | nan_parse_hex(arg[16]);
119
120 return 0;
121}
122
123
124int nan_parse_mac_address_list(struct sigma_dut *dut, const char *input,
125 u8 *output, u16 max_addr_allowed)
126{
127 /*
128 * Reads a list of mac address separated by space. Each MAC address
129 * should have the format of aa:bb:cc:dd:ee:ff.
130 */
131 char *saveptr;
132 char *token;
133 int i = 0;
134
135 for (i = 0; i < max_addr_allowed; i++) {
136 token = strtok_r((i == 0) ? (char *) input : NULL,
137 " ", &saveptr);
138 if (token) {
139 nan_parse_mac_address(dut, token, output);
140 output += NAN_MAC_ADDR_LEN;
141 } else
142 break;
143 }
144
145 sigma_dut_print(dut, DUT_MSG_INFO, "Num MacAddress:%d", i);
146
147 return i;
148}
149
150
151int nan_parse_hex_string(struct sigma_dut *dut, const char *input,
152 u8 *output, int *outputlen)
153{
154 int i = 0;
155 int j = 0;
156
157 for (i = 0; i < (int) strlen(input) && j < *outputlen; i += 2) {
158 output[j] = nan_parse_hex(input[i]);
159 if (i + 1 < (int) strlen(input)) {
160 output[j] = ((output[j] << 4) |
161 nan_parse_hex(input[i + 1]));
162 }
163 j++;
164 }
165 *outputlen = j;
166 sigma_dut_print(dut, DUT_MSG_INFO, "Input:%s inputlen:%d outputlen:%d",
167 input, (int) strlen(input), (int) *outputlen);
168 return 0;
169}
170
171
172int wait(struct timespec abstime)
173{
174 struct timeval now;
175
176 gettimeofday(&now, NULL);
177
178 abstime.tv_sec += now.tv_sec;
179 if (((abstime.tv_nsec + now.tv_usec * 1000) > 1000 * 1000 * 1000) ||
180 (abstime.tv_nsec + now.tv_usec * 1000 < 0)) {
181 abstime.tv_sec += 1;
182 abstime.tv_nsec += now.tv_usec * 1000;
183 abstime.tv_nsec -= 1000 * 1000 * 1000;
184 } else {
185 abstime.tv_nsec += now.tv_usec * 1000;
186 }
187
188 return pthread_cond_timedwait(&gCondition, &gMutex, &abstime);
189}
190
191
192int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
193 struct sigma_conn *conn,
194 struct sigma_cmd *cmd)
195{
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700196 const char *oper_chan = get_param(cmd, "oper_chn");
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700197 const char *pmk = get_param(cmd, "PMK");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200198
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700199 if (oper_chan) {
200 sigma_dut_print(dut, DUT_MSG_INFO, "Operating Channel: %s",
201 oper_chan);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700202 dut->sta_channel = atoi(oper_chan);
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700203 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200204
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700205 if (pmk) {
206 int pmk_len;
207
208 sigma_dut_print(dut, DUT_MSG_INFO, "%s given string pmk: %s",
209 __func__, pmk);
210 memset(dut->nan_pmk, 0, NAN_PMK_INFO_LEN);
211 dut->nan_pmk_len = 0;
212 pmk_len = NAN_PMK_INFO_LEN;
213 nan_parse_hex_string(dut, &pmk[2], &dut->nan_pmk[0], &pmk_len);
214 dut->nan_pmk_len = pmk_len;
215 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
216 __func__, dut->nan_pmk_len);
217 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex pmk", __func__);
218 nan_hex_dump(dut, &dut->nan_pmk[0], dut->nan_pmk_len);
219 }
220
Rakesh Sunki14bff1d2017-03-30 14:47:55 -0700221 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200222 return 0;
223}
224
225
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700226void nan_print_further_availability_chan(struct sigma_dut *dut,
227 u8 num_chans,
228 NanFurtherAvailabilityChannel *fachan)
229{
230 int idx;
231
232 sigma_dut_print(dut, DUT_MSG_INFO,
233 "********Printing FurtherAvailabilityChan Info******");
234 sigma_dut_print(dut, DUT_MSG_INFO, "Numchans:%d", num_chans);
235 for (idx = 0; idx < num_chans; idx++) {
236 sigma_dut_print(dut, DUT_MSG_INFO,
237 "[%d]: NanAvailDuration:%d class_val:%02x channel:%d",
238 idx, fachan->entry_control,
239 fachan->class_val, fachan->channel);
240 sigma_dut_print(dut, DUT_MSG_INFO,
241 "[%d]: mapid:%d Availability bitmap:%08x",
242 idx, fachan->mapid,
243 fachan->avail_interval_bitmap);
244 }
245 sigma_dut_print(dut, DUT_MSG_INFO,
246 "*********************Done**********************");
247}
248
249
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200250int sigma_nan_enable(struct sigma_dut *dut, struct sigma_conn *conn,
251 struct sigma_cmd *cmd)
252{
253 const char *master_pref = get_param(cmd, "MasterPref");
254 const char *rand_fac = get_param(cmd, "RandFactor");
255 const char *hop_count = get_param(cmd, "HopCount");
256 const char *high_tsf = get_param(cmd, "HighTSF");
257 const char *sdftx_band = get_param(cmd, "SDFTxBand");
258 const char *oper_chan = get_param(cmd, "oper_chn");
259 const char *further_avail_ind = get_param(cmd, "FurtherAvailInd");
260 const char *band = get_param(cmd, "Band");
261 const char *only_5g = get_param(cmd, "5GOnly");
262 struct timespec abstime;
263 NanEnableRequest req;
264
265 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200266 req.cluster_low = 0;
267 req.cluster_high = 0xFFFF;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700268 req.master_pref = 100;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200269
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700270 /* This is a debug hack to beacon in channel 11 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200271 if (oper_chan) {
272 req.config_2dot4g_support = 1;
273 req.support_2dot4g_val = 111;
274 }
275
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200276 if (master_pref) {
277 int master_pref_val = strtoul(master_pref, NULL, 0);
278
279 req.master_pref = master_pref_val;
280 }
281
282 if (rand_fac) {
283 int rand_fac_val = strtoul(rand_fac, NULL, 0);
284
285 req.config_random_factor_force = 1;
286 req.random_factor_force_val = rand_fac_val;
287 }
288
289 if (hop_count) {
290 int hop_count_val = strtoul(hop_count, NULL, 0);
291
292 req.config_hop_count_force = 1;
293 req.hop_count_force_val = hop_count_val;
294 }
295
296 if (sdftx_band) {
297 if (strcasecmp(sdftx_band, "5G") == 0) {
298 req.config_2dot4g_support = 1;
299 req.support_2dot4g_val = 0;
300 }
301 }
302
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700303 sigma_dut_print(dut, DUT_MSG_INFO,
304 "%s: Setting dual band 2.4 GHz and 5 GHz by default",
305 __func__);
306 /* Enable 2.4 GHz support */
307 req.config_2dot4g_support = 1;
308 req.support_2dot4g_val = 1;
309 req.config_2dot4g_beacons = 1;
310 req.beacon_2dot4g_val = 1;
311 req.config_2dot4g_sdf = 1;
312 req.sdf_2dot4g_val = 1;
313
314 /* Enable 5 GHz support */
315 req.config_support_5g = 1;
316 req.support_5g_val = 1;
317 req.config_5g_beacons = 1;
318 req.beacon_5g_val = 1;
319 req.config_5g_sdf = 1;
320 req.sdf_5g_val = 1;
321
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200322 if (band) {
323 if (strcasecmp(band, "24G") == 0) {
324 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700325 "Band 2.4 GHz selected, disable 5 GHz");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200326 /* Disable 5G support */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700327 req.config_support_5g = 1;
328 req.support_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200329 req.config_5g_beacons = 1;
330 req.beacon_5g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700331 req.config_5g_sdf = 1;
332 req.sdf_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200333 }
334 }
335
336 if (further_avail_ind) {
337 sigma_dut_print(dut, DUT_MSG_INFO, "FAM Test Enabled");
338 if (strcasecmp(further_avail_ind, "tx") == 0) {
339 is_fam = 1;
340 nan_further_availability_tx(dut, conn, cmd);
341 return 0;
342 } else if (strcasecmp(further_avail_ind, "rx") == 0) {
343 nan_further_availability_rx(dut, conn, cmd);
344 return 0;
345 }
346 }
347
348 if (only_5g && atoi(only_5g)) {
349 sigma_dut_print(dut, DUT_MSG_INFO, "5GHz only enabled");
350 req.config_2dot4g_support = 1;
351 req.support_2dot4g_val = 1;
352 req.config_2dot4g_beacons = 1;
353 req.beacon_2dot4g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700354 req.config_2dot4g_sdf = 1;
355 req.sdf_2dot4g_val = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200356 }
357
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700358 nan_enable_request(0, global_interface_handle, &req);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700359
360 /* To ensure sta_get_events to get the events
361 * only after joining the NAN cluster. */
362 abstime.tv_sec = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200363 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700364 wait(abstime);
365
366 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200367}
368
369
370int sigma_nan_disable(struct sigma_dut *dut, struct sigma_conn *conn,
371 struct sigma_cmd *cmd)
372{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200373 struct timespec abstime;
374
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700375 nan_disable_request(0, global_interface_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200376
377 abstime.tv_sec = 4;
378 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700379 wait(abstime);
380
381 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200382}
383
384
385int sigma_nan_config_enable(struct sigma_dut *dut, struct sigma_conn *conn,
386 struct sigma_cmd *cmd)
387{
388 const char *master_pref = get_param(cmd, "MasterPref");
389 const char *rand_fac = get_param(cmd, "RandFactor");
390 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700391 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200392 struct timespec abstime;
393 NanConfigRequest req;
394
395 memset(&req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200396 req.config_rssi_proximity = 1;
397 req.rssi_proximity = 70;
398
399 if (master_pref) {
400 int master_pref_val = strtoul(master_pref, NULL, 0);
401
402 req.config_master_pref = 1;
403 req.master_pref = master_pref_val;
404 }
405
406 if (rand_fac) {
407 int rand_fac_val = strtoul(rand_fac, NULL, 0);
408
409 req.config_random_factor_force = 1;
410 req.random_factor_force_val = rand_fac_val;
411 }
412
413 if (hop_count) {
414 int hop_count_val = strtoul(hop_count, NULL, 0);
415
416 req.config_hop_count_force = 1;
417 req.hop_count_force_val = hop_count_val;
418 }
419
Rakesh Sunki107356c2017-03-30 14:47:55 -0700420 ret = nan_config_request(0, global_interface_handle, &req);
421 if (ret != WIFI_SUCCESS)
422 send_resp(dut, conn, SIGMA_ERROR, "NAN config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200423
424 abstime.tv_sec = 4;
425 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700426 wait(abstime);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200427
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700428 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200429}
430
431
432static int sigma_nan_subscribe_request(struct sigma_dut *dut,
433 struct sigma_conn *conn,
434 struct sigma_cmd *cmd)
435{
436 const char *subscribe_type = get_param(cmd, "SubscribeType");
437 const char *service_name = get_param(cmd, "ServiceName");
438 const char *disc_range = get_param(cmd, "DiscoveryRange");
439 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
440 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
441 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
442 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
443 const char *include_bit = get_param(cmd, "IncludeBit");
444 const char *mac = get_param(cmd, "MAC");
445 const char *srf_type = get_param(cmd, "SRFType");
446 NanSubscribeRequest req;
447 int filter_len_rx = 0, filter_len_tx = 0;
448 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
449 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -0700450 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200451
452 memset(&req, 0, sizeof(NanSubscribeRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200453 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -0700454 req.period = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200455 req.subscribe_type = 1;
456 req.serviceResponseFilter = 1; /* MAC */
457 req.serviceResponseInclude = 0;
458 req.ssiRequiredForMatchIndication = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700459 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200460 req.subscribe_count = 0;
461
462 if (subscribe_type) {
463 if (strcasecmp(subscribe_type, "Active") == 0) {
464 req.subscribe_type = 1;
465 } else if (strcasecmp(subscribe_type, "Passive") == 0) {
466 req.subscribe_type = 0;
467 } else if (strcasecmp(subscribe_type, "Cancel") == 0) {
468 NanSubscribeCancelRequest req;
469
470 memset(&req, 0, sizeof(NanSubscribeCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -0700471 ret = nan_subscribe_cancel_request(
472 0, global_interface_handle, &req);
473 if (ret != WIFI_SUCCESS) {
474 send_resp(dut, conn, SIGMA_ERROR,
475 "NAN subscribe cancel request failed");
476 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200477 return 0;
478 }
479 }
480
481 if (disc_range)
482 req.rssi_threshold_flag = atoi(disc_range);
483
484 if (sdftx_dw)
485 req.subscribe_count = atoi(sdftx_dw);
486
487 /* Check this once again if config can be called here (TBD) */
488 if (discrange_ltd)
489 req.rssi_threshold_flag = atoi(discrange_ltd);
490
491 if (include_bit) {
492 int include_bit_val = atoi(include_bit);
493
494 req.serviceResponseInclude = include_bit_val;
495 sigma_dut_print(dut, DUT_MSG_INFO, "Includebit set %d",
496 req.serviceResponseInclude);
497 }
498
499 if (srf_type) {
500 int srf_type_val = atoi(srf_type);
501
502 if (srf_type_val == 1)
503 req.serviceResponseFilter = 0; /* Bloom */
504 else
505 req.serviceResponseFilter = 1; /* MAC */
506 req.useServiceResponseFilter = 1;
507 sigma_dut_print(dut, DUT_MSG_INFO, "srfFilter %d",
508 req.serviceResponseFilter);
509 }
510
511 if (mac) {
512 sigma_dut_print(dut, DUT_MSG_INFO, "MAC_ADDR List %s", mac);
513 req.num_intf_addr_present = nan_parse_mac_address_list(
514 dut, mac, &req.intf_addr[0][0],
515 NAN_MAX_SUBSCRIBE_MAX_ADDRESS);
516 }
517
518 memset(input_rx, 0, sizeof(input_rx));
519 memset(input_tx, 0, sizeof(input_tx));
520 if (rx_match_filter) {
521 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
522 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
523 filter_len_rx);
524 }
525 if (tx_match_filter) {
526 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
527 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
528 filter_len_tx);
529 }
530
531 if (tx_match_filter) {
532 req.tx_match_filter_len = filter_len_tx;
533 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
534 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
535 }
536 if (rx_match_filter) {
537 req.rx_match_filter_len = filter_len_rx;
538 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
539 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
540 }
541
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700542 if (service_name) {
543 strlcpy((char *) req.service_name, service_name,
544 strlen(service_name) + 1);
545 req.service_name_len = strlen(service_name);
546 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200547
Rakesh Sunki107356c2017-03-30 14:47:55 -0700548 ret = nan_subscribe_request(0, global_interface_handle, &req);
549 if (ret != WIFI_SUCCESS) {
550 send_resp(dut, conn, SIGMA_ERROR,
551 "NAN subscribe request failed");
552 }
553
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200554 return 0;
555}
556
557
Rakesh Sunkid7344c02017-03-30 14:47:55 -0700558static int sigma_ndp_configure_band(struct sigma_dut *dut,
559 struct sigma_conn *conn,
560 struct sigma_cmd *cmd,
561 NdpSupportedBand band_config_val)
562{
563 wifi_error ret;
564 NanDebugParams cfg_debug;
565 int size;
566
567 memset(&cfg_debug, 0, sizeof(NanDebugParams));
568 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SUPPORTED_BANDS;
569 memcpy(cfg_debug.debug_cmd_data, &band_config_val, sizeof(int));
570 sigma_dut_print(dut, DUT_MSG_INFO, "%s:setting debug cmd=0x%x",
571 __func__, cfg_debug.cmd);
572 size = sizeof(u32) + sizeof(int);
573 ret = nan_debug_command_config(0, global_interface_handle, cfg_debug,
574 size);
575 if (ret != WIFI_SUCCESS)
576 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
577
578 return 0;
579}
580
581
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200582int config_post_disc_attr(void)
583{
Rakesh Sunki107356c2017-03-30 14:47:55 -0700584 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200585 NanConfigRequest configReq;
586
587 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200588
589 /* Configure Post disc attr */
590 /* Make these defines and use correct enum */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700591 configReq.num_config_discovery_attr = 1;
592 configReq.discovery_attr_val[0].type = 4; /* Further Nan discovery */
593 configReq.discovery_attr_val[0].role = 0;
594 configReq.discovery_attr_val[0].transmit_freq = 1;
595 configReq.discovery_attr_val[0].duration = 0;
596 configReq.discovery_attr_val[0].avail_interval_bitmap = 0x00000008;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200597
Rakesh Sunki107356c2017-03-30 14:47:55 -0700598 ret = nan_config_request(0, global_interface_handle, &configReq);
599 if (ret != WIFI_SUCCESS) {
600 sigma_dut_print(global_dut, DUT_MSG_INFO,
601 "NAN config request failed while configuring post discovery attribute");
602 }
603
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200604 return 0;
605}
606
607
608int sigma_nan_publish_request(struct sigma_dut *dut, struct sigma_conn *conn,
609 struct sigma_cmd *cmd)
610{
611 const char *publish_type = get_param(cmd, "PublishType");
612 const char *service_name = get_param(cmd, "ServiceName");
613 const char *disc_range = get_param(cmd, "DiscoveryRange");
614 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
615 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
616 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
617 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
618 NanPublishRequest req;
619 int filter_len_rx = 0, filter_len_tx = 0;
620 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
621 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -0700622 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200623
624 memset(&req, 0, sizeof(NanPublishRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200625 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -0700626 req.period = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700627 req.publish_match_indicator = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200628 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
629 req.tx_type = NAN_TX_TYPE_BROADCAST;
630 req.publish_count = 0;
Rakesh Sunki0a0eea82017-03-30 14:47:55 -0700631 req.service_responder_policy = NAN_SERVICE_ACCEPT_POLICY_ALL;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700632
633 if (service_name) {
634 strlcpy((char *) req.service_name, service_name,
635 strlen(service_name) + 1);
636 req.service_name_len = strlen(service_name);
637 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200638
639 if (publish_type) {
640 if (strcasecmp(publish_type, "Solicited") == 0) {
641 req.publish_type = NAN_PUBLISH_TYPE_SOLICITED;
642 } else if (strcasecmp(publish_type, "Cancel") == 0) {
643 NanPublishCancelRequest req;
644
645 memset(&req, 0, sizeof(NanPublishCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -0700646 ret = nan_publish_cancel_request(
647 0, global_interface_handle, &req);
648 if (ret != WIFI_SUCCESS) {
649 send_resp(dut, conn, SIGMA_ERROR,
650 "Unable to cancel nan publish request");
651 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200652 return 0;
653 }
654 }
655
656 if (disc_range)
657 req.rssi_threshold_flag = atoi(disc_range);
658
659 if (sdftx_dw)
660 req.publish_count = atoi(sdftx_dw);
661
662 if (discrange_ltd)
663 req.rssi_threshold_flag = atoi(discrange_ltd);
664
665 memset(input_rx, 0, sizeof(input_rx));
666 memset(input_tx, 0, sizeof(input_tx));
667 if (rx_match_filter) {
668 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
669 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
670 filter_len_rx);
671 }
672 if (tx_match_filter) {
673 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
674 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
675 filter_len_tx);
676 }
677
678 if (is_fam == 1) {
679 config_post_disc_attr();
680 /* TODO: Add comments regarding this step */
681 req.connmap = 0x10;
682 }
683
684 if (tx_match_filter) {
685 req.tx_match_filter_len = filter_len_tx;
686 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
687 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
688 }
689
690 if (rx_match_filter) {
691 req.rx_match_filter_len = filter_len_rx;
692 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
693 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
694 }
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700695
696 if (service_name) {
697 strlcpy((char *) req.service_name, service_name,
698 strlen(service_name) + 1);
699 req.service_name_len = strlen(service_name);
700 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200701
Rakesh Sunki107356c2017-03-30 14:47:55 -0700702 ret = nan_publish_request(0, global_interface_handle, &req);
703 if (ret != WIFI_SUCCESS)
704 send_resp(dut, conn, SIGMA_ERROR, "Unable to publish");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200705
706 return 0;
707}
708
709
710static int nan_further_availability_rx(struct sigma_dut *dut,
711 struct sigma_conn *conn,
712 struct sigma_cmd *cmd)
713{
714 const char *master_pref = get_param(cmd, "MasterPref");
715 const char *rand_fac = get_param(cmd, "RandFactor");
716 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700717 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200718 struct timespec abstime;
719
720 NanEnableRequest req;
721
722 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200723 req.cluster_low = 0;
724 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200725 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200726
727 if (master_pref)
728 req.master_pref = strtoul(master_pref, NULL, 0);
729
730 if (rand_fac) {
731 int rand_fac_val = strtoul(rand_fac, NULL, 0);
732
733 req.config_random_factor_force = 1;
734 req.random_factor_force_val = rand_fac_val;
735 }
736
737 if (hop_count) {
738 int hop_count_val = strtoul(hop_count, NULL, 0);
739
740 req.config_hop_count_force = 1;
741 req.hop_count_force_val = hop_count_val;
742 }
743
Rakesh Sunki107356c2017-03-30 14:47:55 -0700744 ret = nan_enable_request(0, global_interface_handle, &req);
745 if (ret != WIFI_SUCCESS) {
746 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
747 return 0;
748 }
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700749
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200750 abstime.tv_sec = 4;
751 abstime.tv_nsec = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200752 wait(abstime);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700753
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200754 return 0;
755}
756
757
758static int nan_further_availability_tx(struct sigma_dut *dut,
759 struct sigma_conn *conn,
760 struct sigma_cmd *cmd)
761{
762 const char *master_pref = get_param(cmd, "MasterPref");
763 const char *rand_fac = get_param(cmd, "RandFactor");
764 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700765 wifi_error ret;
766
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200767 NanEnableRequest req;
768 NanConfigRequest configReq;
769
770 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200771 req.cluster_low = 0;
772 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200773 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200774
775 if (master_pref)
776 req.master_pref = strtoul(master_pref, NULL, 0);
777
778 if (rand_fac) {
779 int rand_fac_val = strtoul(rand_fac, NULL, 0);
780
781 req.config_random_factor_force = 1;
782 req.random_factor_force_val = rand_fac_val;
783 }
784
785 if (hop_count) {
786 int hop_count_val = strtoul(hop_count, NULL, 0);
787
788 req.config_hop_count_force = 1;
789 req.hop_count_force_val = hop_count_val;
790 }
791
Rakesh Sunki107356c2017-03-30 14:47:55 -0700792 ret = nan_enable_request(0, global_interface_handle, &req);
793 if (ret != WIFI_SUCCESS) {
794 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
795 return 0;
796 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200797
798 /* Start the config of fam */
799
800 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200801
802 configReq.config_fam = 1;
803 configReq.fam_val.numchans = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700804 configReq.fam_val.famchan[0].entry_control = 0;
805 configReq.fam_val.famchan[0].class_val = 81;
806 configReq.fam_val.famchan[0].channel = 6;
807 configReq.fam_val.famchan[0].mapid = 0;
808 configReq.fam_val.famchan[0].avail_interval_bitmap = 0x7ffffffe;
809
Rakesh Sunki107356c2017-03-30 14:47:55 -0700810 ret = nan_config_request(0, global_interface_handle, &configReq);
811 if (ret != WIFI_SUCCESS)
812 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200813
814 return 0;
815}
816
817
818int sigma_nan_transmit_followup(struct sigma_dut *dut,
819 struct sigma_conn *conn,
820 struct sigma_cmd *cmd)
821{
822 const char *mac = get_param(cmd, "mac");
823 const char *requestor_id = get_param(cmd, "RemoteInstanceId");
824 const char *local_id = get_param(cmd, "LocalInstanceId");
825 const char *service_name = get_param(cmd, "servicename");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700826 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200827 NanTransmitFollowupRequest req;
828
829 memset(&req, 0, sizeof(NanTransmitFollowupRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700830 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200831 req.addr[0] = 0xFF;
832 req.addr[1] = 0xFF;
833 req.addr[2] = 0xFF;
834 req.addr[3] = 0xFF;
835 req.addr[4] = 0xFF;
836 req.addr[5] = 0xFF;
837 req.priority = NAN_TX_PRIORITY_NORMAL;
838 req.dw_or_faw = 0;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700839
840 if (service_name)
841 req.service_specific_info_len = strlen(service_name);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200842
843 if (requestor_id) {
844 /* int requestor_id_val = atoi(requestor_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700845 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200846 }
847 if (local_id) {
848 /* int local_id_val = atoi(local_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700849 req.publish_subscribe_id = global_header_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200850 }
851
852 if (mac == NULL) {
853 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid MAC Address");
854 return -1;
855 }
856 nan_parse_mac_address(dut, mac, req.addr);
857
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200858 if (requestor_id)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700859 req.requestor_instance_id = strtoul(requestor_id, NULL, 0);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200860
Rakesh Sunki107356c2017-03-30 14:47:55 -0700861 ret = nan_transmit_followup_request(0, global_interface_handle, &req);
862 if (ret != WIFI_SUCCESS) {
863 send_resp(dut, conn, SIGMA_ERROR,
864 "Unable to complete nan transmit followup");
865 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700866
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200867 return 0;
868}
869
Rakesh Sunki107356c2017-03-30 14:47:55 -0700870
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200871/* NotifyResponse invoked to notify the status of the Request */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700872void nan_notify_response(transaction_id id, NanResponseMsg *rsp_data)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200873{
874 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700875 "%s: status %d value %d response_type %d",
876 __func__,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200877 rsp_data->status, rsp_data->value,
878 rsp_data->response_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -0700879 if (rsp_data->response_type == NAN_RESPONSE_STATS &&
880 rsp_data->body.stats_response.stats_type ==
881 NAN_STATS_ID_DE_TIMING_SYNC) {
882 NanSyncStats *pSyncStats;
883
884 sigma_dut_print(global_dut, DUT_MSG_INFO,
885 "%s: stats_type %d", __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700886 rsp_data->body.stats_response.stats_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -0700887 pSyncStats = &rsp_data->body.stats_response.data.sync_stats;
888 memcpy(&global_nan_sync_stats, pSyncStats,
889 sizeof(NanSyncStats));
890 pthread_cond_signal(&gCondition);
Rakesh Sunki4d5912d2017-03-30 14:47:55 -0700891 } else if (rsp_data->response_type == NAN_RESPONSE_PUBLISH) {
892 sigma_dut_print(global_dut, DUT_MSG_INFO,
893 "%s: publish_id %d\n",
894 __func__,
895 rsp_data->body.publish_response.publish_id);
896 global_publish_id = rsp_data->body.publish_response.publish_id;
897 } else if (rsp_data->response_type == NAN_RESPONSE_SUBSCRIBE) {
898 sigma_dut_print(global_dut, DUT_MSG_INFO,
899 "%s: subscribe_id %d\n",
900 __func__,
901 rsp_data->body.subscribe_response.subscribe_id);
902 global_subscribe_id =
903 rsp_data->body.subscribe_response.subscribe_id;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200904 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200905}
906
907
908/* Events Callback */
909void nan_event_publish_replied(NanPublishRepliedInd *event)
910{
911 sigma_dut_print(global_dut, DUT_MSG_INFO,
912 "%s: handle %d " MAC_ADDR_STR " rssi:%d",
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700913 __func__, event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200914 MAC_ADDR_ARRAY(event->addr), event->rssi_value);
915 event_anyresponse = 1;
916 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700917 "EventName,Replied,RemoteInstanceID %d,mac," MAC_ADDR_STR,
918 (event->requestor_instance_id >> 24),
919 MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200920}
921
922
923/* Events Callback */
924void nan_event_publish_terminated(NanPublishTerminatedInd *event)
925{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700926 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: publish_id %d reason %d",
927 __func__, event->publish_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200928}
929
930
931/* Events Callback */
932void nan_event_match(NanMatchInd *event)
933{
934 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700935 "%s: Pub/Sub Id %d remote_requestor_id %08x "
936 MAC_ADDR_STR
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200937 " rssi:%d",
938 __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700939 event->publish_subscribe_id,
940 event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200941 MAC_ADDR_ARRAY(event->addr),
942 event->rssi_value);
943 event_anyresponse = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700944 global_header_handle = event->publish_subscribe_id;
945 global_match_handle = event->requestor_instance_id;
946
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200947 /* memset(event_resp_buf, 0, sizeof(event_resp_buf)); */
948 /* global_pub_sub_handle = event->header.handle; */
949 /* Print the SSI */
950 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing SSI:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700951 nan_hex_dump(global_dut, event->service_specific_info,
952 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200953 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
954 "EventName,DiscoveryResult,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700955 MAC_ADDR_STR " ", (event->requestor_instance_id >> 24),
956 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200957
958 /* Print the match filter */
959 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing sdf match filter:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700960 nan_hex_dump(global_dut, event->sdf_match_filter,
961 event->sdf_match_filter_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962
963 /* Print the conn_capability */
964 sigma_dut_print(global_dut, DUT_MSG_INFO,
965 "Printing PostConnectivity Capability");
966 if (event->is_conn_capability_valid) {
967 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfd supported:%s",
968 event->conn_capability.is_wfd_supported ?
969 "yes" : "no");
970 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfds supported:%s",
971 (event->conn_capability.is_wfds_supported ?
972 "yes" : "no"));
973 sigma_dut_print(global_dut, DUT_MSG_INFO, "TDLS supported:%s",
974 (event->conn_capability.is_tdls_supported ?
975 "yes" : "no"));
976 sigma_dut_print(global_dut, DUT_MSG_INFO, "IBSS supported:%s",
977 (event->conn_capability.is_ibss_supported ?
978 "yes" : "no"));
979 sigma_dut_print(global_dut, DUT_MSG_INFO, "Mesh supported:%s",
980 (event->conn_capability.is_mesh_supported ?
981 "yes" : "no"));
982 sigma_dut_print(global_dut, DUT_MSG_INFO, "Infra Field:%d",
983 event->conn_capability.wlan_infra_field);
984 } else {
985 sigma_dut_print(global_dut, DUT_MSG_INFO,
986 "PostConnectivity Capability not present");
987 }
988
989 /* Print the discovery_attr */
990 sigma_dut_print(global_dut, DUT_MSG_INFO,
991 "Printing PostDiscovery Attribute");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700992 if (event->num_rx_discovery_attr) {
993 int idx;
994
995 for (idx = 0; idx < event->num_rx_discovery_attr; idx++) {
996 sigma_dut_print(global_dut, DUT_MSG_INFO,
997 "PostDiscovery Attribute - %d", idx);
998 sigma_dut_print(global_dut, DUT_MSG_INFO,
999 "Conn Type:%d Device Role:%d"
1000 MAC_ADDR_STR,
1001 event->discovery_attr[idx].type,
1002 event->discovery_attr[idx].role,
1003 MAC_ADDR_ARRAY(event->discovery_attr[idx].addr));
1004 sigma_dut_print(global_dut, DUT_MSG_INFO,
1005 "Duration:%d MapId:%d "
1006 "avail_interval_bitmap:%04x",
1007 event->discovery_attr[idx].duration,
1008 event->discovery_attr[idx].mapid,
1009 event->discovery_attr[idx].avail_interval_bitmap);
1010 sigma_dut_print(global_dut, DUT_MSG_INFO,
1011 "Printing Mesh Id:");
1012 nan_hex_dump(global_dut,
1013 event->discovery_attr[idx].mesh_id,
1014 event->discovery_attr[idx].mesh_id_len);
1015 sigma_dut_print(global_dut, DUT_MSG_INFO,
1016 "Printing Infrastructure Ssid:");
1017 nan_hex_dump(global_dut,
1018 event->discovery_attr[idx].infrastructure_ssid_val,
1019 event->discovery_attr[idx].infrastructure_ssid_len);
1020 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001021 } else {
1022 sigma_dut_print(global_dut, DUT_MSG_INFO,
1023 "PostDiscovery attribute not present");
1024 }
1025
1026 /* Print the fam */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001027 if (event->num_chans) {
1028 nan_print_further_availability_chan(global_dut,
1029 event->num_chans,
1030 &event->famchan[0]);
1031 } else {
1032 sigma_dut_print(global_dut, DUT_MSG_INFO,
1033 "Further Availability Map not present");
1034 }
1035 if (event->cluster_attribute_len) {
1036 sigma_dut_print(global_dut, DUT_MSG_INFO,
1037 "Printing Cluster Attribute:");
1038 nan_hex_dump(global_dut, event->cluster_attribute,
1039 event->cluster_attribute_len);
1040 } else {
1041 sigma_dut_print(global_dut, DUT_MSG_INFO,
1042 "Cluster Attribute not present");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001043 }
1044}
1045
1046
1047/* Events Callback */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001048void nan_event_match_expired(NanMatchExpiredInd *event)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001049{
1050 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001051 "%s: publish_subscribe_id %d match_handle %08x",
1052 __func__, event->publish_subscribe_id,
1053 event->requestor_instance_id);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001054}
1055
1056
1057/* Events Callback */
1058void nan_event_subscribe_terminated(NanSubscribeTerminatedInd *event)
1059{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001060 sigma_dut_print(global_dut, DUT_MSG_INFO,
1061 "%s: Subscribe Id %d reason %d",
1062 __func__, event->subscribe_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001063}
1064
1065
1066/* Events Callback */
1067void nan_event_followup(NanFollowupInd *event)
1068{
1069 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001070 "%s: Publish/Subscribe Id %d match_handle 0x%08x dw_or_faw %d "
1071 MAC_ADDR_STR, __func__, event->publish_subscribe_id,
1072 event->requestor_instance_id, event->dw_or_faw,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001073 MAC_ADDR_ARRAY(event->addr));
1074
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001075 global_match_handle = event->publish_subscribe_id;
1076 global_header_handle = event->requestor_instance_id;
1077 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Printing SSI", __func__);
1078 nan_hex_dump(global_dut, event->service_specific_info,
1079 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001080 event_anyresponse = 1;
1081 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1082 "EventName,FollowUp,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001083 MAC_ADDR_STR " ", event->requestor_instance_id >> 24,
1084 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001085}
1086
1087
1088/* Events Callback */
1089void nan_event_disceng_event(NanDiscEngEventInd *event)
1090{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001091 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: event_type %d",
1092 __func__, event->event_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001093
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001094 if (event->event_type == NAN_EVENT_ID_JOINED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001095 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Joined cluster "
1096 MAC_ADDR_STR,
1097 __func__,
1098 MAC_ADDR_ARRAY(event->data.cluster.addr));
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001099 /* To ensure sta_get_events to get the events
1100 * only after joining the NAN cluster. */
1101 pthread_cond_signal(&gCondition);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001102 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001103 if (event->event_type == NAN_EVENT_ID_STARTED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001104 sigma_dut_print(global_dut, DUT_MSG_INFO,
1105 "%s: Started cluster " MAC_ADDR_STR,
1106 __func__,
1107 MAC_ADDR_ARRAY(event->data.cluster.addr));
1108 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001109 if (event->event_type == NAN_EVENT_ID_DISC_MAC_ADDR) {
1110 sigma_dut_print(global_dut, DUT_MSG_INFO,
1111 "%s: Discovery Mac Address "
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001112 MAC_ADDR_STR,
1113 __func__,
1114 MAC_ADDR_ARRAY(event->data.mac_addr.addr));
1115 memcpy(global_nan_mac_addr, event->data.mac_addr.addr,
1116 sizeof(global_nan_mac_addr));
1117 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001118}
1119
1120
1121/* Events Callback */
1122void nan_event_disabled(NanDisabledInd *event)
1123{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001124 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: reason %d",
1125 __func__, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001126 /* pthread_cond_signal(&gCondition); */
1127}
1128
1129
Rakesh Sunki4c086672017-03-30 14:47:55 -07001130/* Events callback */
1131static void ndp_event_data_indication(NanDataPathRequestInd *event)
1132{
1133 sigma_dut_print(global_dut, DUT_MSG_INFO,
1134 "%s: Service Instance Id: %d Peer Discovery MAC ADDR "
1135 MAC_ADDR_STR
1136 " NDP Instance Id: %d App Info len %d App Info %s",
1137 __func__,
1138 event->service_instance_id,
1139 MAC_ADDR_ARRAY(event->peer_disc_mac_addr),
1140 event->ndp_instance_id,
1141 event->app_info.ndp_app_info_len,
1142 event->app_info.ndp_app_info);
1143
1144 global_ndp_instance_id = event->ndp_instance_id;
1145}
1146
1147
1148/* Events callback */
1149static void ndp_event_data_confirm(NanDataPathConfirmInd *event)
1150{
1151 sigma_dut_print(global_dut, DUT_MSG_INFO,
1152 "Received NDP Confirm Indication");
1153
1154 global_ndp_instance_id = event->ndp_instance_id;
1155 if (system("ifconfig nan0 up") != 0) {
1156 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1157 "Failed to set nan interface up");
1158 return;
1159 }
1160 if (system("ip -6 route add fe80::/64 dev nan0 table local") != 0) {
1161 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1162 "Failed to run:ip -6 route replace fe80::/64 dev nan0 table local");
1163 return;
1164 }
1165}
1166
1167
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001168void * my_thread_function(void *ptr)
1169{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001170 wifi_event_loop(global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001171 pthread_exit(0);
1172 return (void *) NULL;
1173}
1174
1175
1176static NanCallbackHandler callbackHandler = {
1177 .NotifyResponse = nan_notify_response,
1178 .EventPublishReplied = nan_event_publish_replied,
1179 .EventPublishTerminated = nan_event_publish_terminated,
1180 .EventMatch = nan_event_match,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001181 .EventMatchExpired = nan_event_match_expired,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001182 .EventSubscribeTerminated = nan_event_subscribe_terminated,
1183 .EventFollowup = nan_event_followup,
1184 .EventDiscEngEvent = nan_event_disceng_event,
1185 .EventDisabled = nan_event_disabled,
Rakesh Sunki4c086672017-03-30 14:47:55 -07001186 .EventDataRequest = ndp_event_data_indication,
1187 .EventDataConfirm = ndp_event_data_confirm,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001188};
1189
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001190
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001191void nan_init(struct sigma_dut *dut)
1192{
1193 pthread_t thread1; /* thread variables */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001194 wifi_error err = wifi_initialize(&global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001195
1196 if (err) {
1197 printf("wifi hal initialize failed\n");
1198 return;
1199 }
1200
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001201 global_interface_handle = wifi_get_iface_handle(global_wifi_handle,
1202 (char *) "wlan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001203 /* create threads 1 */
1204 pthread_create(&thread1, NULL, &my_thread_function, NULL);
1205
1206 pthread_mutex_init(&gMutex, NULL);
1207 pthread_cond_init(&gCondition, NULL);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001208 if (global_interface_handle)
1209 nan_register_handler(global_interface_handle, callbackHandler);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001210}
1211
1212
1213void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1214 struct sigma_cmd *cmd)
1215{
1216 sigma_dut_print(dut, DUT_MSG_INFO, "NAN sta_reset_default");
1217
1218 if (nan_state == 0) {
1219 nan_init(dut);
1220 nan_state = 1;
1221 }
1222 is_fam = 0;
1223 event_anyresponse = 0;
1224 global_dut = dut;
Rakesh Sunki7d37f412017-03-30 14:47:55 -07001225 memset(&dut->nan_pmk[0], 0, NAN_PMK_INFO_LEN);
1226 dut->nan_pmk_len = 0;
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001227 dut->sta_channel = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001228 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001229 memset(&global_nan_sync_stats, 0, sizeof(global_nan_sync_stats));
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001230
1231 nan_data_interface_delete(0, global_interface_handle, (char *) "nan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001232 sigma_nan_disable(dut, conn, cmd);
1233}
1234
1235
1236int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1237 struct sigma_cmd *cmd)
1238{
1239 const char *program = get_param(cmd, "Prog");
1240 const char *nan_op = get_param(cmd, "NANOp");
1241 const char *method_type = get_param(cmd, "MethodType");
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001242 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001243 char resp_buf[100];
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001244 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001245
1246 if (program == NULL)
1247 return -1;
1248
1249 if (strcasecmp(program, "NAN") != 0) {
1250 send_resp(dut, conn, SIGMA_ERROR,
1251 "ErrorCode,Unsupported program");
1252 return 0;
1253 }
1254
1255 if (nan_op) {
1256 /*
1257 * NANOp has been specified.
1258 * We will build a nan_enable or nan_disable command.
1259 */
1260 if (strcasecmp(nan_op, "On") == 0) {
1261 if (sigma_nan_enable(dut, conn, cmd) == 0) {
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001262 ret = nan_data_interface_create(
1263 0, global_interface_handle,
1264 (char *) "nan0");
1265 if (ret != WIFI_SUCCESS) {
1266 sigma_dut_print(
1267 global_dut, DUT_MSG_ERROR,
1268 "Unable to create NAN data interface");
1269 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001270 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1271 MAC_ADDR_STR,
1272 MAC_ADDR_ARRAY(global_nan_mac_addr));
1273 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1274 } else {
1275 send_resp(dut, conn, SIGMA_ERROR,
1276 "NAN_ENABLE_FAILED");
1277 return -1;
1278 }
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001279
1280 if (band && strcasecmp(band, "24g") == 0) {
1281 sigma_dut_print(dut, DUT_MSG_INFO,
1282 "%s: Setting band to 2G Only",
1283 __func__);
1284 sigma_ndp_configure_band(
1285 dut, conn, cmd,
1286 NAN_DATA_PATH_SUPPORTED_BAND_2G);
1287 } else if (band && dut->sta_channel > 12) {
1288 sigma_ndp_configure_band(
1289 dut, conn, cmd,
1290 NAN_DATA_PATH_SUPPORT_DUAL_BAND);
1291 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001292 } else if (strcasecmp(nan_op, "Off") == 0) {
1293 sigma_nan_disable(dut, conn, cmd);
1294 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1295 }
1296 }
1297 if (nan_state && nan_op == NULL) {
1298 if (method_type) {
1299 if (strcasecmp(method_type, "Publish") == 0) {
1300 sigma_nan_publish_request(dut, conn, cmd);
1301 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1302 }
1303 if (strcasecmp(method_type, "Subscribe") == 0) {
1304 sigma_nan_subscribe_request(dut, conn, cmd);
1305 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1306 }
1307 if (strcasecmp(method_type, "Followup") == 0) {
1308 sigma_nan_transmit_followup(dut, conn, cmd);
1309 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1310 }
1311 } else {
1312 sigma_nan_config_enable(dut, conn, cmd);
1313 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1314 MAC_ADDR_STR,
1315 MAC_ADDR_ARRAY(global_nan_mac_addr));
1316 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1317 }
1318 }
1319
1320 return 0;
1321}
1322
1323
1324int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1325 struct sigma_cmd *cmd)
1326{
1327
1328 const char *program = get_param(cmd, "Program");
1329 const char *parameter = get_param(cmd, "Parameter");
1330 char resp_buf[100];
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001331 NanStatsRequest req;
1332 struct timespec abstime;
1333 u64 master_rank;
1334 u8 master_pref;
1335 u8 random_factor;
1336 u8 hop_count;
1337 u32 beacon_transmit_time;
1338 u32 ndp_channel_freq;
1339 u32 ndp_channel_freq2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001340
1341 if (program == NULL) {
1342 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Program Name");
1343 return -1;
1344 }
1345 if (strcasecmp(program, "NAN") != 0) {
1346 send_resp(dut, conn, SIGMA_ERROR,
1347 "ErrorCode,Unsupported program");
1348 return 0;
1349 }
1350
1351 if (parameter == NULL) {
1352 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Parameter");
1353 return -1;
1354 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001355
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001356 memset(&req, 0, sizeof(NanStatsRequest));
1357 req.stats_type = (NanStatsType) NAN_STATS_ID_DE_TIMING_SYNC;
1358 nan_stats_request(0, global_interface_handle, &req);
1359 /*
1360 * To ensure sta_get_events to get the events
1361 * only after joining the NAN cluster
1362 */
1363 abstime.tv_sec = 4;
1364 abstime.tv_nsec = 0;
1365 wait(abstime);
1366
1367 master_rank = global_nan_sync_stats.myRank;
1368 master_pref = (global_nan_sync_stats.myRank & 0xFF00000000000000) >> 56;
1369 random_factor = (global_nan_sync_stats.myRank & 0x00FF000000000000) >>
1370 48;
1371 hop_count = global_nan_sync_stats.currAmHopCount;
1372 beacon_transmit_time = global_nan_sync_stats.currAmBTT;
1373 ndp_channel_freq = global_nan_sync_stats.ndpChannelFreq;
1374 ndp_channel_freq2 = global_nan_sync_stats.ndpChannelFreq2;
1375
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001376 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001377 "%s: NanStatsRequest Master_pref:%02x, Random_factor:%02x, hop_count:%02x beacon_transmit_time:%d ndp_channel_freq:%d ndp_channel_freq2:%d",
1378 __func__, master_pref, random_factor,
1379 hop_count, beacon_transmit_time,
1380 ndp_channel_freq, ndp_channel_freq2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001381
1382 if (strcasecmp(parameter, "MasterPref") == 0) {
1383 snprintf(resp_buf, sizeof(resp_buf), "MasterPref,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001384 master_pref);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001385 } else if (strcasecmp(parameter, "MasterRank") == 0) {
1386 snprintf(resp_buf, sizeof(resp_buf), "MasterRank,0x%lx",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001387 master_rank);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001388 } else if (strcasecmp(parameter, "RandFactor") == 0) {
1389 snprintf(resp_buf, sizeof(resp_buf), "RandFactor,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001390 random_factor);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001391 } else if (strcasecmp(parameter, "HopCount") == 0) {
1392 snprintf(resp_buf, sizeof(resp_buf), "HopCount,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001393 hop_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001394 } else if (strcasecmp(parameter, "BeaconTransTime") == 0) {
1395 snprintf(resp_buf, sizeof(resp_buf), "BeaconTransTime 0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001396 beacon_transmit_time);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001397 } else if (strcasecmp(parameter, "NANStatus") == 0) {
1398 if (nan_state == 1)
1399 snprintf(resp_buf, sizeof(resp_buf), "On");
1400 else
1401 snprintf(resp_buf, sizeof(resp_buf), "Off");
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001402 } else if (strcasecmp(parameter, "NDPChannel") == 0) {
1403 if (ndp_channel_freq != 0 && ndp_channel_freq2 != 0) {
1404 snprintf(resp_buf, sizeof(resp_buf),
1405 "ndpchannel,%d,ndpchannel,%d",
1406 freq_to_channel(ndp_channel_freq),
1407 freq_to_channel(ndp_channel_freq2));
1408 } else if (ndp_channel_freq != 0) {
1409 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1410 freq_to_channel(ndp_channel_freq));
1411 } else if (ndp_channel_freq2 != 0) {
1412 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1413 freq_to_channel(ndp_channel_freq2));
1414 } else {
1415 sigma_dut_print(dut, DUT_MSG_ERROR,
1416 "%s: No Negotiated NDP Channels", __func__);
1417 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001418 } else {
1419 send_resp(dut, conn, SIGMA_ERROR, "Invalid Parameter");
1420 return 0;
1421 }
1422
1423 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1424 return 0;
1425}
1426
1427
1428int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1429 struct sigma_cmd *cmd)
1430{
1431 const char *action = get_param(cmd, "Action");
1432
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001433 if (!action)
1434 return 0;
1435
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001436 /* Check action for start, stop and get events. */
1437 if (strcasecmp(action, "Start") == 0) {
1438 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1439 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1440 } else if (strcasecmp(action, "Stop") == 0) {
1441 event_anyresponse = 0;
1442 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1443 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1444 } else if (strcasecmp(action, "Get") == 0) {
1445 if (event_anyresponse == 1) {
1446 send_resp(dut, conn, SIGMA_COMPLETE,
1447 global_event_resp_buf);
1448 } else {
1449 send_resp(dut, conn, SIGMA_COMPLETE, "EventList,NONE");
1450 }
1451 }
1452 return 0;
1453}
Rakesh Sunki4b75f962017-03-30 14:47:55 -07001454
1455#else /* #if NAN_CERT_VERSION */
1456
1457int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
1458 struct sigma_conn *conn,
1459 struct sigma_cmd *cmd)
1460{
1461 return 1;
1462}
1463
1464
1465int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1466 struct sigma_cmd *cmd)
1467{
1468 return 0;
1469
1470}
1471
1472
1473void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1474 struct sigma_cmd *cmd)
1475{
1476 return;
1477}
1478
1479
1480int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1481 struct sigma_cmd *cmd)
1482{
1483 return 0;
1484}
1485
1486
1487int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1488 struct sigma_cmd *cmd)
1489{
1490 return 0;
1491}
1492
1493#endif /* #if NAN_CERT_VERSION */