blob: d7736617ea59418a898666034ee7ae4796dbaab4 [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];
Rakesh Sunki14cfcd22017-03-30 14:47:55 -070040static char global_peer_mac_addr[ETH_ALEN];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020041static char global_event_resp_buf[1024];
42
43static int nan_further_availability_tx(struct sigma_dut *dut,
44 struct sigma_conn *conn,
45 struct sigma_cmd *cmd);
46static int nan_further_availability_rx(struct sigma_dut *dut,
47 struct sigma_conn *conn,
48 struct sigma_cmd *cmd);
49
50
51void nan_hex_dump(struct sigma_dut *dut, uint8_t *data, size_t len)
52{
53 char buf[512];
54 uint16_t index;
55 uint8_t *ptr;
56 int pos;
57
58 memset(buf, 0, sizeof(buf));
59 ptr = data;
60 pos = 0;
61 for (index = 0; index < len; index++) {
62 pos += sprintf(&(buf[pos]), "%02x ", *ptr++);
63 if (pos > 508)
64 break;
65 }
66 sigma_dut_print(dut, DUT_MSG_INFO, "HEXDUMP len=[%d]", (int) len);
67 sigma_dut_print(dut, DUT_MSG_INFO, "buf:%s", buf);
68}
69
70
71int nan_parse_hex(unsigned char c)
72{
73 if (c >= '0' && c <= '9')
74 return c - '0';
75 if (c >= 'a' && c <= 'f')
76 return c - 'a' + 10;
77 if (c >= 'A' && c <= 'F')
78 return c - 'A' + 10;
79 return 0;
80}
81
82
83int nan_parse_token(const char *tokenIn, u8 *tokenOut, int *filterLen)
84{
85 int total_len = 0, len = 0;
86 char *saveptr = NULL;
87
88 tokenIn = strtok_r((char *) tokenIn, ":", &saveptr);
89 while (tokenIn != NULL) {
90 len = strlen(tokenIn);
91 if (len == 1 && *tokenIn == '*')
92 len = 0;
93 tokenOut[total_len++] = (u8) len;
94 if (len != 0)
95 memcpy((u8 *) tokenOut + total_len, tokenIn, len);
96 total_len += len;
97 tokenIn = strtok_r(NULL, ":", &saveptr);
98 }
99 *filterLen = total_len;
100 return 0;
101}
102
103
104int nan_parse_mac_address(struct sigma_dut *dut, const char *arg, u8 *addr)
105{
106 if (strlen(arg) != 17) {
107 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid mac address %s",
108 arg);
109 sigma_dut_print(dut, DUT_MSG_ERROR,
110 "expected format xx:xx:xx:xx:xx:xx");
111 return -1;
112 }
113
114 addr[0] = nan_parse_hex(arg[0]) << 4 | nan_parse_hex(arg[1]);
115 addr[1] = nan_parse_hex(arg[3]) << 4 | nan_parse_hex(arg[4]);
116 addr[2] = nan_parse_hex(arg[6]) << 4 | nan_parse_hex(arg[7]);
117 addr[3] = nan_parse_hex(arg[9]) << 4 | nan_parse_hex(arg[10]);
118 addr[4] = nan_parse_hex(arg[12]) << 4 | nan_parse_hex(arg[13]);
119 addr[5] = nan_parse_hex(arg[15]) << 4 | nan_parse_hex(arg[16]);
120
121 return 0;
122}
123
124
125int nan_parse_mac_address_list(struct sigma_dut *dut, const char *input,
126 u8 *output, u16 max_addr_allowed)
127{
128 /*
129 * Reads a list of mac address separated by space. Each MAC address
130 * should have the format of aa:bb:cc:dd:ee:ff.
131 */
132 char *saveptr;
133 char *token;
134 int i = 0;
135
136 for (i = 0; i < max_addr_allowed; i++) {
137 token = strtok_r((i == 0) ? (char *) input : NULL,
138 " ", &saveptr);
139 if (token) {
140 nan_parse_mac_address(dut, token, output);
141 output += NAN_MAC_ADDR_LEN;
142 } else
143 break;
144 }
145
146 sigma_dut_print(dut, DUT_MSG_INFO, "Num MacAddress:%d", i);
147
148 return i;
149}
150
151
152int nan_parse_hex_string(struct sigma_dut *dut, const char *input,
153 u8 *output, int *outputlen)
154{
155 int i = 0;
156 int j = 0;
157
158 for (i = 0; i < (int) strlen(input) && j < *outputlen; i += 2) {
159 output[j] = nan_parse_hex(input[i]);
160 if (i + 1 < (int) strlen(input)) {
161 output[j] = ((output[j] << 4) |
162 nan_parse_hex(input[i + 1]));
163 }
164 j++;
165 }
166 *outputlen = j;
167 sigma_dut_print(dut, DUT_MSG_INFO, "Input:%s inputlen:%d outputlen:%d",
168 input, (int) strlen(input), (int) *outputlen);
169 return 0;
170}
171
172
173int wait(struct timespec abstime)
174{
175 struct timeval now;
176
177 gettimeofday(&now, NULL);
178
179 abstime.tv_sec += now.tv_sec;
180 if (((abstime.tv_nsec + now.tv_usec * 1000) > 1000 * 1000 * 1000) ||
181 (abstime.tv_nsec + now.tv_usec * 1000 < 0)) {
182 abstime.tv_sec += 1;
183 abstime.tv_nsec += now.tv_usec * 1000;
184 abstime.tv_nsec -= 1000 * 1000 * 1000;
185 } else {
186 abstime.tv_nsec += now.tv_usec * 1000;
187 }
188
189 return pthread_cond_timedwait(&gCondition, &gMutex, &abstime);
190}
191
192
193int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
194 struct sigma_conn *conn,
195 struct sigma_cmd *cmd)
196{
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700197 const char *oper_chan = get_param(cmd, "oper_chn");
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700198 const char *pmk = get_param(cmd, "PMK");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200199
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700200 if (oper_chan) {
201 sigma_dut_print(dut, DUT_MSG_INFO, "Operating Channel: %s",
202 oper_chan);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700203 dut->sta_channel = atoi(oper_chan);
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700204 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200205
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700206 if (pmk) {
207 int pmk_len;
208
209 sigma_dut_print(dut, DUT_MSG_INFO, "%s given string pmk: %s",
210 __func__, pmk);
211 memset(dut->nan_pmk, 0, NAN_PMK_INFO_LEN);
212 dut->nan_pmk_len = 0;
213 pmk_len = NAN_PMK_INFO_LEN;
214 nan_parse_hex_string(dut, &pmk[2], &dut->nan_pmk[0], &pmk_len);
215 dut->nan_pmk_len = pmk_len;
216 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
217 __func__, dut->nan_pmk_len);
218 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex pmk", __func__);
219 nan_hex_dump(dut, &dut->nan_pmk[0], dut->nan_pmk_len);
220 }
221
Rakesh Sunki14bff1d2017-03-30 14:47:55 -0700222 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200223 return 0;
224}
225
226
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700227void nan_print_further_availability_chan(struct sigma_dut *dut,
228 u8 num_chans,
229 NanFurtherAvailabilityChannel *fachan)
230{
231 int idx;
232
233 sigma_dut_print(dut, DUT_MSG_INFO,
234 "********Printing FurtherAvailabilityChan Info******");
235 sigma_dut_print(dut, DUT_MSG_INFO, "Numchans:%d", num_chans);
236 for (idx = 0; idx < num_chans; idx++) {
237 sigma_dut_print(dut, DUT_MSG_INFO,
238 "[%d]: NanAvailDuration:%d class_val:%02x channel:%d",
239 idx, fachan->entry_control,
240 fachan->class_val, fachan->channel);
241 sigma_dut_print(dut, DUT_MSG_INFO,
242 "[%d]: mapid:%d Availability bitmap:%08x",
243 idx, fachan->mapid,
244 fachan->avail_interval_bitmap);
245 }
246 sigma_dut_print(dut, DUT_MSG_INFO,
247 "*********************Done**********************");
248}
249
250
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200251int sigma_nan_enable(struct sigma_dut *dut, struct sigma_conn *conn,
252 struct sigma_cmd *cmd)
253{
254 const char *master_pref = get_param(cmd, "MasterPref");
255 const char *rand_fac = get_param(cmd, "RandFactor");
256 const char *hop_count = get_param(cmd, "HopCount");
257 const char *high_tsf = get_param(cmd, "HighTSF");
258 const char *sdftx_band = get_param(cmd, "SDFTxBand");
259 const char *oper_chan = get_param(cmd, "oper_chn");
260 const char *further_avail_ind = get_param(cmd, "FurtherAvailInd");
261 const char *band = get_param(cmd, "Band");
262 const char *only_5g = get_param(cmd, "5GOnly");
Rakesh Sunki38dd72e2017-03-30 14:47:55 -0700263 const char *nan_availability = get_param(cmd, "NANAvailability");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200264 struct timespec abstime;
265 NanEnableRequest req;
266
267 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200268 req.cluster_low = 0;
269 req.cluster_high = 0xFFFF;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700270 req.master_pref = 100;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200271
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700272 /* This is a debug hack to beacon in channel 11 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200273 if (oper_chan) {
274 req.config_2dot4g_support = 1;
275 req.support_2dot4g_val = 111;
276 }
277
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200278 if (master_pref) {
279 int master_pref_val = strtoul(master_pref, NULL, 0);
280
281 req.master_pref = master_pref_val;
282 }
283
284 if (rand_fac) {
285 int rand_fac_val = strtoul(rand_fac, NULL, 0);
286
287 req.config_random_factor_force = 1;
288 req.random_factor_force_val = rand_fac_val;
289 }
290
291 if (hop_count) {
292 int hop_count_val = strtoul(hop_count, NULL, 0);
293
294 req.config_hop_count_force = 1;
295 req.hop_count_force_val = hop_count_val;
296 }
297
298 if (sdftx_band) {
299 if (strcasecmp(sdftx_band, "5G") == 0) {
300 req.config_2dot4g_support = 1;
301 req.support_2dot4g_val = 0;
302 }
303 }
304
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700305 sigma_dut_print(dut, DUT_MSG_INFO,
306 "%s: Setting dual band 2.4 GHz and 5 GHz by default",
307 __func__);
308 /* Enable 2.4 GHz support */
309 req.config_2dot4g_support = 1;
310 req.support_2dot4g_val = 1;
311 req.config_2dot4g_beacons = 1;
312 req.beacon_2dot4g_val = 1;
313 req.config_2dot4g_sdf = 1;
314 req.sdf_2dot4g_val = 1;
315
316 /* Enable 5 GHz support */
317 req.config_support_5g = 1;
318 req.support_5g_val = 1;
319 req.config_5g_beacons = 1;
320 req.beacon_5g_val = 1;
321 req.config_5g_sdf = 1;
322 req.sdf_5g_val = 1;
323
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200324 if (band) {
325 if (strcasecmp(band, "24G") == 0) {
326 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700327 "Band 2.4 GHz selected, disable 5 GHz");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200328 /* Disable 5G support */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700329 req.config_support_5g = 1;
330 req.support_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200331 req.config_5g_beacons = 1;
332 req.beacon_5g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700333 req.config_5g_sdf = 1;
334 req.sdf_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200335 }
336 }
337
338 if (further_avail_ind) {
339 sigma_dut_print(dut, DUT_MSG_INFO, "FAM Test Enabled");
340 if (strcasecmp(further_avail_ind, "tx") == 0) {
341 is_fam = 1;
342 nan_further_availability_tx(dut, conn, cmd);
343 return 0;
344 } else if (strcasecmp(further_avail_ind, "rx") == 0) {
345 nan_further_availability_rx(dut, conn, cmd);
346 return 0;
347 }
348 }
349
350 if (only_5g && atoi(only_5g)) {
351 sigma_dut_print(dut, DUT_MSG_INFO, "5GHz only enabled");
352 req.config_2dot4g_support = 1;
353 req.support_2dot4g_val = 1;
354 req.config_2dot4g_beacons = 1;
355 req.beacon_2dot4g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700356 req.config_2dot4g_sdf = 1;
357 req.sdf_2dot4g_val = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200358 }
359
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700360 nan_enable_request(0, global_interface_handle, &req);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700361
Rakesh Sunki38dd72e2017-03-30 14:47:55 -0700362 if (nan_availability) {
363 int cmd_len, size;
364 NanDebugParams cfg_debug;
365
366 sigma_dut_print(dut, DUT_MSG_INFO,
367 "%s given string nan_availability: %s",
368 __func__, nan_availability);
369 memset(&cfg_debug, 0, sizeof(NanDebugParams));
370 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_AVAILABILITY;
371 size = NAN_MAX_DEBUG_MESSAGE_DATA_LEN;
372 nan_parse_hex_string(dut, &nan_availability[2],
373 &cfg_debug.debug_cmd_data[0], &size);
374 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex nan_availability",
375 __func__);
376 nan_hex_dump(dut, &cfg_debug.debug_cmd_data[0], size);
377 cmd_len = size + sizeof(u32);
378 nan_debug_command_config(0, global_interface_handle,
379 cfg_debug, cmd_len);
380 }
381
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700382 /* To ensure sta_get_events to get the events
383 * only after joining the NAN cluster. */
384 abstime.tv_sec = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200385 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700386 wait(abstime);
387
388 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200389}
390
391
392int sigma_nan_disable(struct sigma_dut *dut, struct sigma_conn *conn,
393 struct sigma_cmd *cmd)
394{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200395 struct timespec abstime;
396
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700397 nan_disable_request(0, global_interface_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200398
399 abstime.tv_sec = 4;
400 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700401 wait(abstime);
402
403 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200404}
405
406
407int sigma_nan_config_enable(struct sigma_dut *dut, struct sigma_conn *conn,
408 struct sigma_cmd *cmd)
409{
410 const char *master_pref = get_param(cmd, "MasterPref");
411 const char *rand_fac = get_param(cmd, "RandFactor");
412 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700413 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200414 struct timespec abstime;
415 NanConfigRequest req;
416
417 memset(&req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200418 req.config_rssi_proximity = 1;
419 req.rssi_proximity = 70;
420
421 if (master_pref) {
422 int master_pref_val = strtoul(master_pref, NULL, 0);
423
424 req.config_master_pref = 1;
425 req.master_pref = master_pref_val;
426 }
427
428 if (rand_fac) {
429 int rand_fac_val = strtoul(rand_fac, NULL, 0);
430
431 req.config_random_factor_force = 1;
432 req.random_factor_force_val = rand_fac_val;
433 }
434
435 if (hop_count) {
436 int hop_count_val = strtoul(hop_count, NULL, 0);
437
438 req.config_hop_count_force = 1;
439 req.hop_count_force_val = hop_count_val;
440 }
441
Rakesh Sunki107356c2017-03-30 14:47:55 -0700442 ret = nan_config_request(0, global_interface_handle, &req);
443 if (ret != WIFI_SUCCESS)
444 send_resp(dut, conn, SIGMA_ERROR, "NAN config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200445
446 abstime.tv_sec = 4;
447 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700448 wait(abstime);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200449
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700450 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200451}
452
453
454static int sigma_nan_subscribe_request(struct sigma_dut *dut,
455 struct sigma_conn *conn,
456 struct sigma_cmd *cmd)
457{
458 const char *subscribe_type = get_param(cmd, "SubscribeType");
459 const char *service_name = get_param(cmd, "ServiceName");
460 const char *disc_range = get_param(cmd, "DiscoveryRange");
461 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
462 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
463 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
464 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
465 const char *include_bit = get_param(cmd, "IncludeBit");
466 const char *mac = get_param(cmd, "MAC");
467 const char *srf_type = get_param(cmd, "SRFType");
468 NanSubscribeRequest req;
469 int filter_len_rx = 0, filter_len_tx = 0;
470 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
471 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -0700472 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200473
474 memset(&req, 0, sizeof(NanSubscribeRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200475 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -0700476 req.period = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200477 req.subscribe_type = 1;
478 req.serviceResponseFilter = 1; /* MAC */
479 req.serviceResponseInclude = 0;
480 req.ssiRequiredForMatchIndication = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700481 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200482 req.subscribe_count = 0;
483
484 if (subscribe_type) {
485 if (strcasecmp(subscribe_type, "Active") == 0) {
486 req.subscribe_type = 1;
487 } else if (strcasecmp(subscribe_type, "Passive") == 0) {
488 req.subscribe_type = 0;
489 } else if (strcasecmp(subscribe_type, "Cancel") == 0) {
490 NanSubscribeCancelRequest req;
491
492 memset(&req, 0, sizeof(NanSubscribeCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -0700493 ret = nan_subscribe_cancel_request(
494 0, global_interface_handle, &req);
495 if (ret != WIFI_SUCCESS) {
496 send_resp(dut, conn, SIGMA_ERROR,
497 "NAN subscribe cancel request failed");
498 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200499 return 0;
500 }
501 }
502
503 if (disc_range)
504 req.rssi_threshold_flag = atoi(disc_range);
505
506 if (sdftx_dw)
507 req.subscribe_count = atoi(sdftx_dw);
508
509 /* Check this once again if config can be called here (TBD) */
510 if (discrange_ltd)
511 req.rssi_threshold_flag = atoi(discrange_ltd);
512
513 if (include_bit) {
514 int include_bit_val = atoi(include_bit);
515
516 req.serviceResponseInclude = include_bit_val;
517 sigma_dut_print(dut, DUT_MSG_INFO, "Includebit set %d",
518 req.serviceResponseInclude);
519 }
520
521 if (srf_type) {
522 int srf_type_val = atoi(srf_type);
523
524 if (srf_type_val == 1)
525 req.serviceResponseFilter = 0; /* Bloom */
526 else
527 req.serviceResponseFilter = 1; /* MAC */
528 req.useServiceResponseFilter = 1;
529 sigma_dut_print(dut, DUT_MSG_INFO, "srfFilter %d",
530 req.serviceResponseFilter);
531 }
532
533 if (mac) {
534 sigma_dut_print(dut, DUT_MSG_INFO, "MAC_ADDR List %s", mac);
535 req.num_intf_addr_present = nan_parse_mac_address_list(
536 dut, mac, &req.intf_addr[0][0],
537 NAN_MAX_SUBSCRIBE_MAX_ADDRESS);
538 }
539
540 memset(input_rx, 0, sizeof(input_rx));
541 memset(input_tx, 0, sizeof(input_tx));
542 if (rx_match_filter) {
543 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
544 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
545 filter_len_rx);
546 }
547 if (tx_match_filter) {
548 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
549 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
550 filter_len_tx);
551 }
552
553 if (tx_match_filter) {
554 req.tx_match_filter_len = filter_len_tx;
555 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
556 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
557 }
558 if (rx_match_filter) {
559 req.rx_match_filter_len = filter_len_rx;
560 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
561 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
562 }
563
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700564 if (service_name) {
565 strlcpy((char *) req.service_name, service_name,
566 strlen(service_name) + 1);
567 req.service_name_len = strlen(service_name);
568 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200569
Rakesh Sunki107356c2017-03-30 14:47:55 -0700570 ret = nan_subscribe_request(0, global_interface_handle, &req);
571 if (ret != WIFI_SUCCESS) {
572 send_resp(dut, conn, SIGMA_ERROR,
573 "NAN subscribe request failed");
574 }
575
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200576 return 0;
577}
578
579
Rakesh Sunkid7344c02017-03-30 14:47:55 -0700580static int sigma_ndp_configure_band(struct sigma_dut *dut,
581 struct sigma_conn *conn,
582 struct sigma_cmd *cmd,
583 NdpSupportedBand band_config_val)
584{
585 wifi_error ret;
586 NanDebugParams cfg_debug;
587 int size;
588
589 memset(&cfg_debug, 0, sizeof(NanDebugParams));
590 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SUPPORTED_BANDS;
591 memcpy(cfg_debug.debug_cmd_data, &band_config_val, sizeof(int));
592 sigma_dut_print(dut, DUT_MSG_INFO, "%s:setting debug cmd=0x%x",
593 __func__, cfg_debug.cmd);
594 size = sizeof(u32) + sizeof(int);
595 ret = nan_debug_command_config(0, global_interface_handle, cfg_debug,
596 size);
597 if (ret != WIFI_SUCCESS)
598 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
599
600 return 0;
601}
602
603
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700604static int sigma_nan_data_request(struct sigma_dut *dut,
605 struct sigma_conn *conn,
606 struct sigma_cmd *cmd)
607{
608 const char *ndp_security = get_param(cmd, "DataPathSecurity");
609 const char *ndp_resp_mac = get_param(cmd, "RespNanMac");
610 const char *include_immutable = get_param(cmd, "includeimmutable");
611 const char *avoid_channel = get_param(cmd, "avoidchannel");
612 const char *invalid_nan_schedule = get_param(cmd, "InvalidNANSchedule");
613 const char *map_order = get_param(cmd, "maporder");
614 wifi_error ret;
615 NanDataPathInitiatorRequest init_req;
616 NanDebugParams cfg_debug;
617 int size;
618
619 memset(&init_req, 0, sizeof(NanDataPathInitiatorRequest));
620
621 if (ndp_security) {
622 if (strcasecmp(ndp_security, "open") == 0)
623 init_req.ndp_cfg.security_cfg =
624 NAN_DP_CONFIG_NO_SECURITY;
625 else if (strcasecmp(ndp_security, "secure") == 0)
626 init_req.ndp_cfg.security_cfg = NAN_DP_CONFIG_SECURITY;
627 }
628
629 if (include_immutable) {
630 int include_immutable_val = 0;
631
632 memset(&cfg_debug, 0, sizeof(NanDebugParams));
633 cfg_debug.cmd = NAN_TEST_MODE_CMD_NDP_INCLUDE_IMMUTABLE;
634 include_immutable_val = atoi(include_immutable);
635 memcpy(cfg_debug.debug_cmd_data, &include_immutable_val,
636 sizeof(int));
637 size = sizeof(u32) + sizeof(int);
638 nan_debug_command_config(0, global_interface_handle,
639 cfg_debug, size);
640 }
641
642 if (avoid_channel) {
643 int avoid_channel_freq = 0;
644
645 memset(&cfg_debug, 0, sizeof(NanDebugParams));
646 avoid_channel_freq = channel_to_freq(atoi(avoid_channel));
647 cfg_debug.cmd = NAN_TEST_MODE_CMD_NDP_AVOID_CHANNEL;
648 memcpy(cfg_debug.debug_cmd_data, &avoid_channel_freq,
649 sizeof(int));
650 size = sizeof(u32) + sizeof(int);
651 nan_debug_command_config(0, global_interface_handle,
652 cfg_debug, size);
653 }
654
655 if (invalid_nan_schedule) {
656 int invalid_nan_schedule_type = 0;
657
658 memset(&cfg_debug, 0, sizeof(NanDebugParams));
659 invalid_nan_schedule_type = atoi(invalid_nan_schedule);
660 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_TYPE;
661 memcpy(cfg_debug.debug_cmd_data,
662 &invalid_nan_schedule_type, sizeof(int));
663 size = sizeof(u32) + sizeof(int);
664 sigma_dut_print(dut, DUT_MSG_INFO,
665 "%s: invalid schedule type: cmd type = %d and command data = %d",
666 __func__, cfg_debug.cmd,
667 invalid_nan_schedule_type);
668 nan_debug_command_config(0, global_interface_handle,
669 cfg_debug, size);
670 }
671
672 if (map_order) {
673 int map_order_val = 0;
674
675 memset(&cfg_debug, 0, sizeof(NanDebugParams));
676 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_AVAILABILITY_MAP_ORDER;
677 map_order_val = atoi(map_order);
678 memcpy(cfg_debug.debug_cmd_data, &map_order_val, sizeof(int));
679 size = sizeof(u32) + sizeof(int);
680 sigma_dut_print(dut, DUT_MSG_INFO,
681 "%s: map order: cmd type = %d and command data = %d",
682 __func__,
683 cfg_debug.cmd, invalid_nan_schedule_type);
684 nan_debug_command_config(0, global_interface_handle,
685 cfg_debug, size);
686 }
687
688 /*
689 * Setting this flag, so that interface for ping6 command
690 * is set appropriately in traffic_send_ping().
691 */
692 dut->ndp_enable = 1;
693
694 /*
695 * Intended sleep after NAN data interface create
696 * before the NAN data request
697 */
698 sleep(4);
699
700 init_req.requestor_instance_id = global_match_handle;
701 strlcpy((char *) init_req.ndp_iface, "nan0",
702 sizeof(init_req.ndp_iface));
703
704 if (ndp_resp_mac) {
705 nan_parse_mac_address(dut, ndp_resp_mac,
706 init_req.peer_disc_mac_addr);
707 sigma_dut_print(
708 dut, DUT_MSG_INFO, "PEER MAC ADDR: " MAC_ADDR_STR,
709 MAC_ADDR_ARRAY(init_req.peer_disc_mac_addr));
710 } else {
711 memcpy(init_req.peer_disc_mac_addr, global_peer_mac_addr,
712 sizeof(init_req.peer_disc_mac_addr));
713 }
714
715 /* Not requesting the channel and letting FW decide */
716 if (dut->sta_channel == 0) {
717 init_req.channel_request_type = NAN_DP_CHANNEL_NOT_REQUESTED;
718 init_req.channel = 0;
719 } else {
720 init_req.channel_request_type = NAN_DP_FORCE_CHANNEL_SETUP;
721 init_req.channel = channel_to_freq(dut->sta_channel);
722 }
723 sigma_dut_print(dut, DUT_MSG_INFO,
724 "%s: Initiator Request: Channel = %d Channel Request Type = %d",
725 __func__, init_req.channel,
726 init_req.channel_request_type);
727
728 if (dut->nan_pmk_len == NAN_PMK_INFO_LEN) {
729 memcpy(&init_req.key_info.body.pmk_info.pmk[0],
730 &dut->nan_pmk[0], NAN_PMK_INFO_LEN);
731 init_req.key_info.body.pmk_info.pmk_len = NAN_PMK_INFO_LEN;
732 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
733 __func__,
734 init_req.key_info.body.pmk_info.pmk_len);
735 }
736
737 ret = nan_data_request_initiator(0, global_interface_handle, &init_req);
738 if (ret != WIFI_SUCCESS) {
739 send_resp(dut, conn, SIGMA_ERROR,
740 "Unable to initiate nan data request");
741 return 0;
742 }
743
744 return 0;
745}
746
747
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200748int config_post_disc_attr(void)
749{
Rakesh Sunki107356c2017-03-30 14:47:55 -0700750 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200751 NanConfigRequest configReq;
752
753 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200754
755 /* Configure Post disc attr */
756 /* Make these defines and use correct enum */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700757 configReq.num_config_discovery_attr = 1;
758 configReq.discovery_attr_val[0].type = 4; /* Further Nan discovery */
759 configReq.discovery_attr_val[0].role = 0;
760 configReq.discovery_attr_val[0].transmit_freq = 1;
761 configReq.discovery_attr_val[0].duration = 0;
762 configReq.discovery_attr_val[0].avail_interval_bitmap = 0x00000008;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200763
Rakesh Sunki107356c2017-03-30 14:47:55 -0700764 ret = nan_config_request(0, global_interface_handle, &configReq);
765 if (ret != WIFI_SUCCESS) {
766 sigma_dut_print(global_dut, DUT_MSG_INFO,
767 "NAN config request failed while configuring post discovery attribute");
768 }
769
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200770 return 0;
771}
772
773
774int sigma_nan_publish_request(struct sigma_dut *dut, struct sigma_conn *conn,
775 struct sigma_cmd *cmd)
776{
777 const char *publish_type = get_param(cmd, "PublishType");
778 const char *service_name = get_param(cmd, "ServiceName");
779 const char *disc_range = get_param(cmd, "DiscoveryRange");
780 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
781 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
782 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
783 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
784 NanPublishRequest req;
785 int filter_len_rx = 0, filter_len_tx = 0;
786 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
787 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -0700788 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200789
790 memset(&req, 0, sizeof(NanPublishRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200791 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -0700792 req.period = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700793 req.publish_match_indicator = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200794 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
795 req.tx_type = NAN_TX_TYPE_BROADCAST;
796 req.publish_count = 0;
Rakesh Sunki0a0eea82017-03-30 14:47:55 -0700797 req.service_responder_policy = NAN_SERVICE_ACCEPT_POLICY_ALL;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700798
799 if (service_name) {
800 strlcpy((char *) req.service_name, service_name,
801 strlen(service_name) + 1);
802 req.service_name_len = strlen(service_name);
803 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200804
805 if (publish_type) {
806 if (strcasecmp(publish_type, "Solicited") == 0) {
807 req.publish_type = NAN_PUBLISH_TYPE_SOLICITED;
808 } else if (strcasecmp(publish_type, "Cancel") == 0) {
809 NanPublishCancelRequest req;
810
811 memset(&req, 0, sizeof(NanPublishCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -0700812 ret = nan_publish_cancel_request(
813 0, global_interface_handle, &req);
814 if (ret != WIFI_SUCCESS) {
815 send_resp(dut, conn, SIGMA_ERROR,
816 "Unable to cancel nan publish request");
817 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200818 return 0;
819 }
820 }
821
822 if (disc_range)
823 req.rssi_threshold_flag = atoi(disc_range);
824
825 if (sdftx_dw)
826 req.publish_count = atoi(sdftx_dw);
827
828 if (discrange_ltd)
829 req.rssi_threshold_flag = atoi(discrange_ltd);
830
831 memset(input_rx, 0, sizeof(input_rx));
832 memset(input_tx, 0, sizeof(input_tx));
833 if (rx_match_filter) {
834 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
835 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
836 filter_len_rx);
837 }
838 if (tx_match_filter) {
839 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
840 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
841 filter_len_tx);
842 }
843
844 if (is_fam == 1) {
845 config_post_disc_attr();
846 /* TODO: Add comments regarding this step */
847 req.connmap = 0x10;
848 }
849
850 if (tx_match_filter) {
851 req.tx_match_filter_len = filter_len_tx;
852 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
853 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
854 }
855
856 if (rx_match_filter) {
857 req.rx_match_filter_len = filter_len_rx;
858 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
859 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
860 }
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700861
862 if (service_name) {
863 strlcpy((char *) req.service_name, service_name,
864 strlen(service_name) + 1);
865 req.service_name_len = strlen(service_name);
866 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200867
Rakesh Sunki107356c2017-03-30 14:47:55 -0700868 ret = nan_publish_request(0, global_interface_handle, &req);
869 if (ret != WIFI_SUCCESS)
870 send_resp(dut, conn, SIGMA_ERROR, "Unable to publish");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200871
872 return 0;
873}
874
875
876static int nan_further_availability_rx(struct sigma_dut *dut,
877 struct sigma_conn *conn,
878 struct sigma_cmd *cmd)
879{
880 const char *master_pref = get_param(cmd, "MasterPref");
881 const char *rand_fac = get_param(cmd, "RandFactor");
882 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700883 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200884 struct timespec abstime;
885
886 NanEnableRequest req;
887
888 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200889 req.cluster_low = 0;
890 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200891 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200892
893 if (master_pref)
894 req.master_pref = strtoul(master_pref, NULL, 0);
895
896 if (rand_fac) {
897 int rand_fac_val = strtoul(rand_fac, NULL, 0);
898
899 req.config_random_factor_force = 1;
900 req.random_factor_force_val = rand_fac_val;
901 }
902
903 if (hop_count) {
904 int hop_count_val = strtoul(hop_count, NULL, 0);
905
906 req.config_hop_count_force = 1;
907 req.hop_count_force_val = hop_count_val;
908 }
909
Rakesh Sunki107356c2017-03-30 14:47:55 -0700910 ret = nan_enable_request(0, global_interface_handle, &req);
911 if (ret != WIFI_SUCCESS) {
912 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
913 return 0;
914 }
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700915
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200916 abstime.tv_sec = 4;
917 abstime.tv_nsec = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200918 wait(abstime);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700919
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200920 return 0;
921}
922
923
924static int nan_further_availability_tx(struct sigma_dut *dut,
925 struct sigma_conn *conn,
926 struct sigma_cmd *cmd)
927{
928 const char *master_pref = get_param(cmd, "MasterPref");
929 const char *rand_fac = get_param(cmd, "RandFactor");
930 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700931 wifi_error ret;
932
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200933 NanEnableRequest req;
934 NanConfigRequest configReq;
935
936 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200937 req.cluster_low = 0;
938 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200939 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200940
941 if (master_pref)
942 req.master_pref = strtoul(master_pref, NULL, 0);
943
944 if (rand_fac) {
945 int rand_fac_val = strtoul(rand_fac, NULL, 0);
946
947 req.config_random_factor_force = 1;
948 req.random_factor_force_val = rand_fac_val;
949 }
950
951 if (hop_count) {
952 int hop_count_val = strtoul(hop_count, NULL, 0);
953
954 req.config_hop_count_force = 1;
955 req.hop_count_force_val = hop_count_val;
956 }
957
Rakesh Sunki107356c2017-03-30 14:47:55 -0700958 ret = nan_enable_request(0, global_interface_handle, &req);
959 if (ret != WIFI_SUCCESS) {
960 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
961 return 0;
962 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200963
964 /* Start the config of fam */
965
966 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200967
968 configReq.config_fam = 1;
969 configReq.fam_val.numchans = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700970 configReq.fam_val.famchan[0].entry_control = 0;
971 configReq.fam_val.famchan[0].class_val = 81;
972 configReq.fam_val.famchan[0].channel = 6;
973 configReq.fam_val.famchan[0].mapid = 0;
974 configReq.fam_val.famchan[0].avail_interval_bitmap = 0x7ffffffe;
975
Rakesh Sunki107356c2017-03-30 14:47:55 -0700976 ret = nan_config_request(0, global_interface_handle, &configReq);
977 if (ret != WIFI_SUCCESS)
978 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200979
980 return 0;
981}
982
983
984int sigma_nan_transmit_followup(struct sigma_dut *dut,
985 struct sigma_conn *conn,
986 struct sigma_cmd *cmd)
987{
988 const char *mac = get_param(cmd, "mac");
989 const char *requestor_id = get_param(cmd, "RemoteInstanceId");
990 const char *local_id = get_param(cmd, "LocalInstanceId");
991 const char *service_name = get_param(cmd, "servicename");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700992 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200993 NanTransmitFollowupRequest req;
994
995 memset(&req, 0, sizeof(NanTransmitFollowupRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700996 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200997 req.addr[0] = 0xFF;
998 req.addr[1] = 0xFF;
999 req.addr[2] = 0xFF;
1000 req.addr[3] = 0xFF;
1001 req.addr[4] = 0xFF;
1002 req.addr[5] = 0xFF;
1003 req.priority = NAN_TX_PRIORITY_NORMAL;
1004 req.dw_or_faw = 0;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001005
1006 if (service_name)
1007 req.service_specific_info_len = strlen(service_name);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001008
1009 if (requestor_id) {
1010 /* int requestor_id_val = atoi(requestor_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001011 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001012 }
1013 if (local_id) {
1014 /* int local_id_val = atoi(local_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001015 req.publish_subscribe_id = global_header_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001016 }
1017
1018 if (mac == NULL) {
1019 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid MAC Address");
1020 return -1;
1021 }
1022 nan_parse_mac_address(dut, mac, req.addr);
1023
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001024 if (requestor_id)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001025 req.requestor_instance_id = strtoul(requestor_id, NULL, 0);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001026
Rakesh Sunki107356c2017-03-30 14:47:55 -07001027 ret = nan_transmit_followup_request(0, global_interface_handle, &req);
1028 if (ret != WIFI_SUCCESS) {
1029 send_resp(dut, conn, SIGMA_ERROR,
1030 "Unable to complete nan transmit followup");
1031 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001032
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001033 return 0;
1034}
1035
Rakesh Sunki107356c2017-03-30 14:47:55 -07001036
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001037/* NotifyResponse invoked to notify the status of the Request */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001038void nan_notify_response(transaction_id id, NanResponseMsg *rsp_data)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001039{
1040 sigma_dut_print(global_dut, DUT_MSG_INFO,
Rakesh Sunkifdbd60b2017-03-30 14:47:55 -07001041 "%s: status %d response_type %d",
1042 __func__, rsp_data->status, rsp_data->response_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001043 if (rsp_data->response_type == NAN_RESPONSE_STATS &&
1044 rsp_data->body.stats_response.stats_type ==
1045 NAN_STATS_ID_DE_TIMING_SYNC) {
1046 NanSyncStats *pSyncStats;
1047
1048 sigma_dut_print(global_dut, DUT_MSG_INFO,
1049 "%s: stats_type %d", __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001050 rsp_data->body.stats_response.stats_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001051 pSyncStats = &rsp_data->body.stats_response.data.sync_stats;
1052 memcpy(&global_nan_sync_stats, pSyncStats,
1053 sizeof(NanSyncStats));
1054 pthread_cond_signal(&gCondition);
Rakesh Sunki4d5912d2017-03-30 14:47:55 -07001055 } else if (rsp_data->response_type == NAN_RESPONSE_PUBLISH) {
1056 sigma_dut_print(global_dut, DUT_MSG_INFO,
1057 "%s: publish_id %d\n",
1058 __func__,
1059 rsp_data->body.publish_response.publish_id);
1060 global_publish_id = rsp_data->body.publish_response.publish_id;
1061 } else if (rsp_data->response_type == NAN_RESPONSE_SUBSCRIBE) {
1062 sigma_dut_print(global_dut, DUT_MSG_INFO,
1063 "%s: subscribe_id %d\n",
1064 __func__,
1065 rsp_data->body.subscribe_response.subscribe_id);
1066 global_subscribe_id =
1067 rsp_data->body.subscribe_response.subscribe_id;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001068 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001069}
1070
1071
1072/* Events Callback */
1073void nan_event_publish_replied(NanPublishRepliedInd *event)
1074{
1075 sigma_dut_print(global_dut, DUT_MSG_INFO,
1076 "%s: handle %d " MAC_ADDR_STR " rssi:%d",
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001077 __func__, event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001078 MAC_ADDR_ARRAY(event->addr), event->rssi_value);
1079 event_anyresponse = 1;
1080 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001081 "EventName,Replied,RemoteInstanceID %d,mac," MAC_ADDR_STR,
1082 (event->requestor_instance_id >> 24),
1083 MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001084}
1085
1086
1087/* Events Callback */
1088void nan_event_publish_terminated(NanPublishTerminatedInd *event)
1089{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001090 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: publish_id %d reason %d",
1091 __func__, event->publish_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001092}
1093
1094
1095/* Events Callback */
1096void nan_event_match(NanMatchInd *event)
1097{
1098 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001099 "%s: Pub/Sub Id %d remote_requestor_id %08x "
1100 MAC_ADDR_STR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001101 " rssi:%d",
1102 __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001103 event->publish_subscribe_id,
1104 event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001105 MAC_ADDR_ARRAY(event->addr),
1106 event->rssi_value);
1107 event_anyresponse = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001108 global_header_handle = event->publish_subscribe_id;
1109 global_match_handle = event->requestor_instance_id;
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001110 memcpy(global_peer_mac_addr, event->addr, sizeof(global_peer_mac_addr));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001111
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001112 /* memset(event_resp_buf, 0, sizeof(event_resp_buf)); */
1113 /* global_pub_sub_handle = event->header.handle; */
1114 /* Print the SSI */
1115 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing SSI:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001116 nan_hex_dump(global_dut, event->service_specific_info,
1117 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001118 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1119 "EventName,DiscoveryResult,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001120 MAC_ADDR_STR " ", (event->requestor_instance_id >> 24),
1121 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001122
1123 /* Print the match filter */
1124 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing sdf match filter:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001125 nan_hex_dump(global_dut, event->sdf_match_filter,
1126 event->sdf_match_filter_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001127
1128 /* Print the conn_capability */
1129 sigma_dut_print(global_dut, DUT_MSG_INFO,
1130 "Printing PostConnectivity Capability");
1131 if (event->is_conn_capability_valid) {
1132 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfd supported:%s",
1133 event->conn_capability.is_wfd_supported ?
1134 "yes" : "no");
1135 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfds supported:%s",
1136 (event->conn_capability.is_wfds_supported ?
1137 "yes" : "no"));
1138 sigma_dut_print(global_dut, DUT_MSG_INFO, "TDLS supported:%s",
1139 (event->conn_capability.is_tdls_supported ?
1140 "yes" : "no"));
1141 sigma_dut_print(global_dut, DUT_MSG_INFO, "IBSS supported:%s",
1142 (event->conn_capability.is_ibss_supported ?
1143 "yes" : "no"));
1144 sigma_dut_print(global_dut, DUT_MSG_INFO, "Mesh supported:%s",
1145 (event->conn_capability.is_mesh_supported ?
1146 "yes" : "no"));
1147 sigma_dut_print(global_dut, DUT_MSG_INFO, "Infra Field:%d",
1148 event->conn_capability.wlan_infra_field);
1149 } else {
1150 sigma_dut_print(global_dut, DUT_MSG_INFO,
1151 "PostConnectivity Capability not present");
1152 }
1153
1154 /* Print the discovery_attr */
1155 sigma_dut_print(global_dut, DUT_MSG_INFO,
1156 "Printing PostDiscovery Attribute");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001157 if (event->num_rx_discovery_attr) {
1158 int idx;
1159
1160 for (idx = 0; idx < event->num_rx_discovery_attr; idx++) {
1161 sigma_dut_print(global_dut, DUT_MSG_INFO,
1162 "PostDiscovery Attribute - %d", idx);
1163 sigma_dut_print(global_dut, DUT_MSG_INFO,
1164 "Conn Type:%d Device Role:%d"
1165 MAC_ADDR_STR,
1166 event->discovery_attr[idx].type,
1167 event->discovery_attr[idx].role,
1168 MAC_ADDR_ARRAY(event->discovery_attr[idx].addr));
1169 sigma_dut_print(global_dut, DUT_MSG_INFO,
1170 "Duration:%d MapId:%d "
1171 "avail_interval_bitmap:%04x",
1172 event->discovery_attr[idx].duration,
1173 event->discovery_attr[idx].mapid,
1174 event->discovery_attr[idx].avail_interval_bitmap);
1175 sigma_dut_print(global_dut, DUT_MSG_INFO,
1176 "Printing Mesh Id:");
1177 nan_hex_dump(global_dut,
1178 event->discovery_attr[idx].mesh_id,
1179 event->discovery_attr[idx].mesh_id_len);
1180 sigma_dut_print(global_dut, DUT_MSG_INFO,
1181 "Printing Infrastructure Ssid:");
1182 nan_hex_dump(global_dut,
1183 event->discovery_attr[idx].infrastructure_ssid_val,
1184 event->discovery_attr[idx].infrastructure_ssid_len);
1185 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001186 } else {
1187 sigma_dut_print(global_dut, DUT_MSG_INFO,
1188 "PostDiscovery attribute not present");
1189 }
1190
1191 /* Print the fam */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001192 if (event->num_chans) {
1193 nan_print_further_availability_chan(global_dut,
1194 event->num_chans,
1195 &event->famchan[0]);
1196 } else {
1197 sigma_dut_print(global_dut, DUT_MSG_INFO,
1198 "Further Availability Map not present");
1199 }
1200 if (event->cluster_attribute_len) {
1201 sigma_dut_print(global_dut, DUT_MSG_INFO,
1202 "Printing Cluster Attribute:");
1203 nan_hex_dump(global_dut, event->cluster_attribute,
1204 event->cluster_attribute_len);
1205 } else {
1206 sigma_dut_print(global_dut, DUT_MSG_INFO,
1207 "Cluster Attribute not present");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001208 }
1209}
1210
1211
1212/* Events Callback */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001213void nan_event_match_expired(NanMatchExpiredInd *event)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001214{
1215 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001216 "%s: publish_subscribe_id %d match_handle %08x",
1217 __func__, event->publish_subscribe_id,
1218 event->requestor_instance_id);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001219}
1220
1221
1222/* Events Callback */
1223void nan_event_subscribe_terminated(NanSubscribeTerminatedInd *event)
1224{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001225 sigma_dut_print(global_dut, DUT_MSG_INFO,
1226 "%s: Subscribe Id %d reason %d",
1227 __func__, event->subscribe_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001228}
1229
1230
1231/* Events Callback */
1232void nan_event_followup(NanFollowupInd *event)
1233{
1234 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001235 "%s: Publish/Subscribe Id %d match_handle 0x%08x dw_or_faw %d "
1236 MAC_ADDR_STR, __func__, event->publish_subscribe_id,
1237 event->requestor_instance_id, event->dw_or_faw,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001238 MAC_ADDR_ARRAY(event->addr));
1239
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001240 global_match_handle = event->publish_subscribe_id;
1241 global_header_handle = event->requestor_instance_id;
1242 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Printing SSI", __func__);
1243 nan_hex_dump(global_dut, event->service_specific_info,
1244 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001245 event_anyresponse = 1;
1246 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
1247 "EventName,FollowUp,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001248 MAC_ADDR_STR " ", event->requestor_instance_id >> 24,
1249 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001250}
1251
1252
1253/* Events Callback */
1254void nan_event_disceng_event(NanDiscEngEventInd *event)
1255{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001256 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: event_type %d",
1257 __func__, event->event_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001258
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001259 if (event->event_type == NAN_EVENT_ID_JOINED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001260 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Joined cluster "
1261 MAC_ADDR_STR,
1262 __func__,
1263 MAC_ADDR_ARRAY(event->data.cluster.addr));
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001264 /* To ensure sta_get_events to get the events
1265 * only after joining the NAN cluster. */
1266 pthread_cond_signal(&gCondition);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001267 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001268 if (event->event_type == NAN_EVENT_ID_STARTED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001269 sigma_dut_print(global_dut, DUT_MSG_INFO,
1270 "%s: Started cluster " MAC_ADDR_STR,
1271 __func__,
1272 MAC_ADDR_ARRAY(event->data.cluster.addr));
1273 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001274 if (event->event_type == NAN_EVENT_ID_DISC_MAC_ADDR) {
1275 sigma_dut_print(global_dut, DUT_MSG_INFO,
1276 "%s: Discovery Mac Address "
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001277 MAC_ADDR_STR,
1278 __func__,
1279 MAC_ADDR_ARRAY(event->data.mac_addr.addr));
1280 memcpy(global_nan_mac_addr, event->data.mac_addr.addr,
1281 sizeof(global_nan_mac_addr));
1282 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001283}
1284
1285
1286/* Events Callback */
1287void nan_event_disabled(NanDisabledInd *event)
1288{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001289 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: reason %d",
1290 __func__, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001291 /* pthread_cond_signal(&gCondition); */
1292}
1293
1294
Rakesh Sunki4c086672017-03-30 14:47:55 -07001295/* Events callback */
1296static void ndp_event_data_indication(NanDataPathRequestInd *event)
1297{
1298 sigma_dut_print(global_dut, DUT_MSG_INFO,
1299 "%s: Service Instance Id: %d Peer Discovery MAC ADDR "
1300 MAC_ADDR_STR
1301 " NDP Instance Id: %d App Info len %d App Info %s",
1302 __func__,
1303 event->service_instance_id,
1304 MAC_ADDR_ARRAY(event->peer_disc_mac_addr),
1305 event->ndp_instance_id,
1306 event->app_info.ndp_app_info_len,
1307 event->app_info.ndp_app_info);
1308
1309 global_ndp_instance_id = event->ndp_instance_id;
1310}
1311
1312
1313/* Events callback */
1314static void ndp_event_data_confirm(NanDataPathConfirmInd *event)
1315{
1316 sigma_dut_print(global_dut, DUT_MSG_INFO,
1317 "Received NDP Confirm Indication");
1318
1319 global_ndp_instance_id = event->ndp_instance_id;
1320 if (system("ifconfig nan0 up") != 0) {
1321 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1322 "Failed to set nan interface up");
1323 return;
1324 }
1325 if (system("ip -6 route add fe80::/64 dev nan0 table local") != 0) {
1326 sigma_dut_print(global_dut, DUT_MSG_ERROR,
1327 "Failed to run:ip -6 route replace fe80::/64 dev nan0 table local");
1328 return;
1329 }
1330}
1331
1332
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001333void * my_thread_function(void *ptr)
1334{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001335 wifi_event_loop(global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001336 pthread_exit(0);
1337 return (void *) NULL;
1338}
1339
1340
1341static NanCallbackHandler callbackHandler = {
1342 .NotifyResponse = nan_notify_response,
1343 .EventPublishReplied = nan_event_publish_replied,
1344 .EventPublishTerminated = nan_event_publish_terminated,
1345 .EventMatch = nan_event_match,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001346 .EventMatchExpired = nan_event_match_expired,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001347 .EventSubscribeTerminated = nan_event_subscribe_terminated,
1348 .EventFollowup = nan_event_followup,
1349 .EventDiscEngEvent = nan_event_disceng_event,
1350 .EventDisabled = nan_event_disabled,
Rakesh Sunki4c086672017-03-30 14:47:55 -07001351 .EventDataRequest = ndp_event_data_indication,
1352 .EventDataConfirm = ndp_event_data_confirm,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001353};
1354
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001355
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001356void nan_init(struct sigma_dut *dut)
1357{
1358 pthread_t thread1; /* thread variables */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001359 wifi_error err = wifi_initialize(&global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001360
1361 if (err) {
1362 printf("wifi hal initialize failed\n");
1363 return;
1364 }
1365
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001366 global_interface_handle = wifi_get_iface_handle(global_wifi_handle,
1367 (char *) "wlan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001368 /* create threads 1 */
1369 pthread_create(&thread1, NULL, &my_thread_function, NULL);
1370
1371 pthread_mutex_init(&gMutex, NULL);
1372 pthread_cond_init(&gCondition, NULL);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001373 if (global_interface_handle)
1374 nan_register_handler(global_interface_handle, callbackHandler);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001375}
1376
1377
1378void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1379 struct sigma_cmd *cmd)
1380{
1381 sigma_dut_print(dut, DUT_MSG_INFO, "NAN sta_reset_default");
1382
1383 if (nan_state == 0) {
1384 nan_init(dut);
1385 nan_state = 1;
1386 }
1387 is_fam = 0;
1388 event_anyresponse = 0;
1389 global_dut = dut;
Rakesh Sunki7d37f412017-03-30 14:47:55 -07001390 memset(&dut->nan_pmk[0], 0, NAN_PMK_INFO_LEN);
1391 dut->nan_pmk_len = 0;
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001392 dut->sta_channel = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001393 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001394 memset(&global_nan_sync_stats, 0, sizeof(global_nan_sync_stats));
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001395
1396 nan_data_interface_delete(0, global_interface_handle, (char *) "nan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001397 sigma_nan_disable(dut, conn, cmd);
1398}
1399
1400
1401int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1402 struct sigma_cmd *cmd)
1403{
1404 const char *program = get_param(cmd, "Prog");
1405 const char *nan_op = get_param(cmd, "NANOp");
1406 const char *method_type = get_param(cmd, "MethodType");
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001407 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001408 char resp_buf[100];
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001409 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001410
1411 if (program == NULL)
1412 return -1;
1413
1414 if (strcasecmp(program, "NAN") != 0) {
1415 send_resp(dut, conn, SIGMA_ERROR,
1416 "ErrorCode,Unsupported program");
1417 return 0;
1418 }
1419
1420 if (nan_op) {
1421 /*
1422 * NANOp has been specified.
1423 * We will build a nan_enable or nan_disable command.
1424 */
1425 if (strcasecmp(nan_op, "On") == 0) {
1426 if (sigma_nan_enable(dut, conn, cmd) == 0) {
Rakesh Sunki7a40a202017-03-30 14:47:55 -07001427 ret = nan_data_interface_create(
1428 0, global_interface_handle,
1429 (char *) "nan0");
1430 if (ret != WIFI_SUCCESS) {
1431 sigma_dut_print(
1432 global_dut, DUT_MSG_ERROR,
1433 "Unable to create NAN data interface");
1434 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001435 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1436 MAC_ADDR_STR,
1437 MAC_ADDR_ARRAY(global_nan_mac_addr));
1438 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1439 } else {
1440 send_resp(dut, conn, SIGMA_ERROR,
1441 "NAN_ENABLE_FAILED");
1442 return -1;
1443 }
Rakesh Sunkid7344c02017-03-30 14:47:55 -07001444
1445 if (band && strcasecmp(band, "24g") == 0) {
1446 sigma_dut_print(dut, DUT_MSG_INFO,
1447 "%s: Setting band to 2G Only",
1448 __func__);
1449 sigma_ndp_configure_band(
1450 dut, conn, cmd,
1451 NAN_DATA_PATH_SUPPORTED_BAND_2G);
1452 } else if (band && dut->sta_channel > 12) {
1453 sigma_ndp_configure_band(
1454 dut, conn, cmd,
1455 NAN_DATA_PATH_SUPPORT_DUAL_BAND);
1456 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001457 } else if (strcasecmp(nan_op, "Off") == 0) {
1458 sigma_nan_disable(dut, conn, cmd);
1459 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1460 }
1461 }
1462 if (nan_state && nan_op == NULL) {
1463 if (method_type) {
1464 if (strcasecmp(method_type, "Publish") == 0) {
1465 sigma_nan_publish_request(dut, conn, cmd);
1466 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1467 }
1468 if (strcasecmp(method_type, "Subscribe") == 0) {
1469 sigma_nan_subscribe_request(dut, conn, cmd);
1470 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1471 }
1472 if (strcasecmp(method_type, "Followup") == 0) {
1473 sigma_nan_transmit_followup(dut, conn, cmd);
1474 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1475 }
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001476 if (strcasecmp(method_type, "DataRequest") == 0) {
1477 sigma_nan_data_request(dut, conn, cmd);
1478 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1479 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001480 } else {
1481 sigma_nan_config_enable(dut, conn, cmd);
1482 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1483 MAC_ADDR_STR,
1484 MAC_ADDR_ARRAY(global_nan_mac_addr));
1485 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1486 }
1487 }
1488
1489 return 0;
1490}
1491
1492
1493int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1494 struct sigma_cmd *cmd)
1495{
1496
1497 const char *program = get_param(cmd, "Program");
1498 const char *parameter = get_param(cmd, "Parameter");
1499 char resp_buf[100];
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001500 NanStatsRequest req;
1501 struct timespec abstime;
1502 u64 master_rank;
1503 u8 master_pref;
1504 u8 random_factor;
1505 u8 hop_count;
1506 u32 beacon_transmit_time;
1507 u32 ndp_channel_freq;
1508 u32 ndp_channel_freq2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001509
1510 if (program == NULL) {
1511 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Program Name");
1512 return -1;
1513 }
1514 if (strcasecmp(program, "NAN") != 0) {
1515 send_resp(dut, conn, SIGMA_ERROR,
1516 "ErrorCode,Unsupported program");
1517 return 0;
1518 }
1519
1520 if (parameter == NULL) {
1521 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Parameter");
1522 return -1;
1523 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001524
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001525 memset(&req, 0, sizeof(NanStatsRequest));
1526 req.stats_type = (NanStatsType) NAN_STATS_ID_DE_TIMING_SYNC;
1527 nan_stats_request(0, global_interface_handle, &req);
1528 /*
1529 * To ensure sta_get_events to get the events
1530 * only after joining the NAN cluster
1531 */
1532 abstime.tv_sec = 4;
1533 abstime.tv_nsec = 0;
1534 wait(abstime);
1535
1536 master_rank = global_nan_sync_stats.myRank;
1537 master_pref = (global_nan_sync_stats.myRank & 0xFF00000000000000) >> 56;
1538 random_factor = (global_nan_sync_stats.myRank & 0x00FF000000000000) >>
1539 48;
1540 hop_count = global_nan_sync_stats.currAmHopCount;
1541 beacon_transmit_time = global_nan_sync_stats.currAmBTT;
1542 ndp_channel_freq = global_nan_sync_stats.ndpChannelFreq;
1543 ndp_channel_freq2 = global_nan_sync_stats.ndpChannelFreq2;
1544
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001545 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001546 "%s: NanStatsRequest Master_pref:%02x, Random_factor:%02x, hop_count:%02x beacon_transmit_time:%d ndp_channel_freq:%d ndp_channel_freq2:%d",
1547 __func__, master_pref, random_factor,
1548 hop_count, beacon_transmit_time,
1549 ndp_channel_freq, ndp_channel_freq2);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001550
1551 if (strcasecmp(parameter, "MasterPref") == 0) {
1552 snprintf(resp_buf, sizeof(resp_buf), "MasterPref,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001553 master_pref);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001554 } else if (strcasecmp(parameter, "MasterRank") == 0) {
1555 snprintf(resp_buf, sizeof(resp_buf), "MasterRank,0x%lx",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001556 master_rank);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001557 } else if (strcasecmp(parameter, "RandFactor") == 0) {
1558 snprintf(resp_buf, sizeof(resp_buf), "RandFactor,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001559 random_factor);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001560 } else if (strcasecmp(parameter, "HopCount") == 0) {
1561 snprintf(resp_buf, sizeof(resp_buf), "HopCount,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001562 hop_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001563 } else if (strcasecmp(parameter, "BeaconTransTime") == 0) {
1564 snprintf(resp_buf, sizeof(resp_buf), "BeaconTransTime 0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001565 beacon_transmit_time);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001566 } else if (strcasecmp(parameter, "NANStatus") == 0) {
1567 if (nan_state == 1)
1568 snprintf(resp_buf, sizeof(resp_buf), "On");
1569 else
1570 snprintf(resp_buf, sizeof(resp_buf), "Off");
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001571 } else if (strcasecmp(parameter, "NDPChannel") == 0) {
1572 if (ndp_channel_freq != 0 && ndp_channel_freq2 != 0) {
1573 snprintf(resp_buf, sizeof(resp_buf),
1574 "ndpchannel,%d,ndpchannel,%d",
1575 freq_to_channel(ndp_channel_freq),
1576 freq_to_channel(ndp_channel_freq2));
1577 } else if (ndp_channel_freq != 0) {
1578 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1579 freq_to_channel(ndp_channel_freq));
1580 } else if (ndp_channel_freq2 != 0) {
1581 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
1582 freq_to_channel(ndp_channel_freq2));
1583 } else {
1584 sigma_dut_print(dut, DUT_MSG_ERROR,
1585 "%s: No Negotiated NDP Channels", __func__);
1586 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001587 } else {
1588 send_resp(dut, conn, SIGMA_ERROR, "Invalid Parameter");
1589 return 0;
1590 }
1591
1592 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1593 return 0;
1594}
1595
1596
1597int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1598 struct sigma_cmd *cmd)
1599{
1600 const char *action = get_param(cmd, "Action");
1601
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001602 if (!action)
1603 return 0;
1604
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001605 /* Check action for start, stop and get events. */
1606 if (strcasecmp(action, "Start") == 0) {
1607 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1608 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1609 } else if (strcasecmp(action, "Stop") == 0) {
1610 event_anyresponse = 0;
1611 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1612 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1613 } else if (strcasecmp(action, "Get") == 0) {
1614 if (event_anyresponse == 1) {
1615 send_resp(dut, conn, SIGMA_COMPLETE,
1616 global_event_resp_buf);
1617 } else {
1618 send_resp(dut, conn, SIGMA_COMPLETE, "EventList,NONE");
1619 }
1620 }
1621 return 0;
1622}
Rakesh Sunki4b75f962017-03-30 14:47:55 -07001623
1624#else /* #if NAN_CERT_VERSION */
1625
1626int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
1627 struct sigma_conn *conn,
1628 struct sigma_cmd *cmd)
1629{
1630 return 1;
1631}
1632
1633
1634int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1635 struct sigma_cmd *cmd)
1636{
1637 return 0;
1638
1639}
1640
1641
1642void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1643 struct sigma_cmd *cmd)
1644{
1645 return;
1646}
1647
1648
1649int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1650 struct sigma_cmd *cmd)
1651{
1652 return 0;
1653}
1654
1655
1656int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1657 struct sigma_cmd *cmd)
1658{
1659 return 0;
1660}
1661
1662#endif /* #if NAN_CERT_VERSION */