blob: 9ab4ff6d834414a9e973ed0f9f1759eddc437a3d [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;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020021static int nan_state = 0;
22static int event_anyresponse = 0;
23static int is_fam = 0;
24
25uint16_t global_header_handle = 0;
26uint32_t global_match_handle = 0;
27
28#define MAC_ADDR_ARRAY(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
29#define MAC_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
30#ifndef ETH_ALEN
31#define ETH_ALEN 6
32#endif
33
34struct sigma_dut *global_dut = NULL;
35static char global_nan_mac_addr[ETH_ALEN];
36static char global_event_resp_buf[1024];
37
38static int nan_further_availability_tx(struct sigma_dut *dut,
39 struct sigma_conn *conn,
40 struct sigma_cmd *cmd);
41static int nan_further_availability_rx(struct sigma_dut *dut,
42 struct sigma_conn *conn,
43 struct sigma_cmd *cmd);
44
45
46void nan_hex_dump(struct sigma_dut *dut, uint8_t *data, size_t len)
47{
48 char buf[512];
49 uint16_t index;
50 uint8_t *ptr;
51 int pos;
52
53 memset(buf, 0, sizeof(buf));
54 ptr = data;
55 pos = 0;
56 for (index = 0; index < len; index++) {
57 pos += sprintf(&(buf[pos]), "%02x ", *ptr++);
58 if (pos > 508)
59 break;
60 }
61 sigma_dut_print(dut, DUT_MSG_INFO, "HEXDUMP len=[%d]", (int) len);
62 sigma_dut_print(dut, DUT_MSG_INFO, "buf:%s", buf);
63}
64
65
66int nan_parse_hex(unsigned char c)
67{
68 if (c >= '0' && c <= '9')
69 return c - '0';
70 if (c >= 'a' && c <= 'f')
71 return c - 'a' + 10;
72 if (c >= 'A' && c <= 'F')
73 return c - 'A' + 10;
74 return 0;
75}
76
77
78int nan_parse_token(const char *tokenIn, u8 *tokenOut, int *filterLen)
79{
80 int total_len = 0, len = 0;
81 char *saveptr = NULL;
82
83 tokenIn = strtok_r((char *) tokenIn, ":", &saveptr);
84 while (tokenIn != NULL) {
85 len = strlen(tokenIn);
86 if (len == 1 && *tokenIn == '*')
87 len = 0;
88 tokenOut[total_len++] = (u8) len;
89 if (len != 0)
90 memcpy((u8 *) tokenOut + total_len, tokenIn, len);
91 total_len += len;
92 tokenIn = strtok_r(NULL, ":", &saveptr);
93 }
94 *filterLen = total_len;
95 return 0;
96}
97
98
99int nan_parse_mac_address(struct sigma_dut *dut, const char *arg, u8 *addr)
100{
101 if (strlen(arg) != 17) {
102 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid mac address %s",
103 arg);
104 sigma_dut_print(dut, DUT_MSG_ERROR,
105 "expected format xx:xx:xx:xx:xx:xx");
106 return -1;
107 }
108
109 addr[0] = nan_parse_hex(arg[0]) << 4 | nan_parse_hex(arg[1]);
110 addr[1] = nan_parse_hex(arg[3]) << 4 | nan_parse_hex(arg[4]);
111 addr[2] = nan_parse_hex(arg[6]) << 4 | nan_parse_hex(arg[7]);
112 addr[3] = nan_parse_hex(arg[9]) << 4 | nan_parse_hex(arg[10]);
113 addr[4] = nan_parse_hex(arg[12]) << 4 | nan_parse_hex(arg[13]);
114 addr[5] = nan_parse_hex(arg[15]) << 4 | nan_parse_hex(arg[16]);
115
116 return 0;
117}
118
119
120int nan_parse_mac_address_list(struct sigma_dut *dut, const char *input,
121 u8 *output, u16 max_addr_allowed)
122{
123 /*
124 * Reads a list of mac address separated by space. Each MAC address
125 * should have the format of aa:bb:cc:dd:ee:ff.
126 */
127 char *saveptr;
128 char *token;
129 int i = 0;
130
131 for (i = 0; i < max_addr_allowed; i++) {
132 token = strtok_r((i == 0) ? (char *) input : NULL,
133 " ", &saveptr);
134 if (token) {
135 nan_parse_mac_address(dut, token, output);
136 output += NAN_MAC_ADDR_LEN;
137 } else
138 break;
139 }
140
141 sigma_dut_print(dut, DUT_MSG_INFO, "Num MacAddress:%d", i);
142
143 return i;
144}
145
146
147int nan_parse_hex_string(struct sigma_dut *dut, const char *input,
148 u8 *output, int *outputlen)
149{
150 int i = 0;
151 int j = 0;
152
153 for (i = 0; i < (int) strlen(input) && j < *outputlen; i += 2) {
154 output[j] = nan_parse_hex(input[i]);
155 if (i + 1 < (int) strlen(input)) {
156 output[j] = ((output[j] << 4) |
157 nan_parse_hex(input[i + 1]));
158 }
159 j++;
160 }
161 *outputlen = j;
162 sigma_dut_print(dut, DUT_MSG_INFO, "Input:%s inputlen:%d outputlen:%d",
163 input, (int) strlen(input), (int) *outputlen);
164 return 0;
165}
166
167
168int wait(struct timespec abstime)
169{
170 struct timeval now;
171
172 gettimeofday(&now, NULL);
173
174 abstime.tv_sec += now.tv_sec;
175 if (((abstime.tv_nsec + now.tv_usec * 1000) > 1000 * 1000 * 1000) ||
176 (abstime.tv_nsec + now.tv_usec * 1000 < 0)) {
177 abstime.tv_sec += 1;
178 abstime.tv_nsec += now.tv_usec * 1000;
179 abstime.tv_nsec -= 1000 * 1000 * 1000;
180 } else {
181 abstime.tv_nsec += now.tv_usec * 1000;
182 }
183
184 return pthread_cond_timedwait(&gCondition, &gMutex, &abstime);
185}
186
187
188int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
189 struct sigma_conn *conn,
190 struct sigma_cmd *cmd)
191{
192 const char *oper_chan = get_param(cmd, "oper_chan");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200193
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700194 if (oper_chan)
195 dut->sta_channel = atoi(oper_chan);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197 return 0;
198}
199
200
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700201void nan_print_further_availability_chan(struct sigma_dut *dut,
202 u8 num_chans,
203 NanFurtherAvailabilityChannel *fachan)
204{
205 int idx;
206
207 sigma_dut_print(dut, DUT_MSG_INFO,
208 "********Printing FurtherAvailabilityChan Info******");
209 sigma_dut_print(dut, DUT_MSG_INFO, "Numchans:%d", num_chans);
210 for (idx = 0; idx < num_chans; idx++) {
211 sigma_dut_print(dut, DUT_MSG_INFO,
212 "[%d]: NanAvailDuration:%d class_val:%02x channel:%d",
213 idx, fachan->entry_control,
214 fachan->class_val, fachan->channel);
215 sigma_dut_print(dut, DUT_MSG_INFO,
216 "[%d]: mapid:%d Availability bitmap:%08x",
217 idx, fachan->mapid,
218 fachan->avail_interval_bitmap);
219 }
220 sigma_dut_print(dut, DUT_MSG_INFO,
221 "*********************Done**********************");
222}
223
224
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200225int sigma_nan_enable(struct sigma_dut *dut, struct sigma_conn *conn,
226 struct sigma_cmd *cmd)
227{
228 const char *master_pref = get_param(cmd, "MasterPref");
229 const char *rand_fac = get_param(cmd, "RandFactor");
230 const char *hop_count = get_param(cmd, "HopCount");
231 const char *high_tsf = get_param(cmd, "HighTSF");
232 const char *sdftx_band = get_param(cmd, "SDFTxBand");
233 const char *oper_chan = get_param(cmd, "oper_chn");
234 const char *further_avail_ind = get_param(cmd, "FurtherAvailInd");
235 const char *band = get_param(cmd, "Band");
236 const char *only_5g = get_param(cmd, "5GOnly");
237 struct timespec abstime;
238 NanEnableRequest req;
239
240 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200241 req.cluster_low = 0;
242 req.cluster_high = 0xFFFF;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700243 req.master_pref = 100;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200244
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700245 /* This is a debug hack to beacon in channel 11 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200246 if (oper_chan) {
247 req.config_2dot4g_support = 1;
248 req.support_2dot4g_val = 111;
249 }
250
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200251 if (master_pref) {
252 int master_pref_val = strtoul(master_pref, NULL, 0);
253
254 req.master_pref = master_pref_val;
255 }
256
257 if (rand_fac) {
258 int rand_fac_val = strtoul(rand_fac, NULL, 0);
259
260 req.config_random_factor_force = 1;
261 req.random_factor_force_val = rand_fac_val;
262 }
263
264 if (hop_count) {
265 int hop_count_val = strtoul(hop_count, NULL, 0);
266
267 req.config_hop_count_force = 1;
268 req.hop_count_force_val = hop_count_val;
269 }
270
271 if (sdftx_band) {
272 if (strcasecmp(sdftx_band, "5G") == 0) {
273 req.config_2dot4g_support = 1;
274 req.support_2dot4g_val = 0;
275 }
276 }
277
278 if (band) {
279 if (strcasecmp(band, "24G") == 0) {
280 sigma_dut_print(dut, DUT_MSG_INFO,
281 "Band 2.4GHz selected");
282 /* Enable 2.4G support */
283 req.config_2dot4g_support = 1;
284 req.support_2dot4g_val = 1;
285 req.config_2dot4g_beacons = 1;
286 req.beacon_2dot4g_val = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700287 req.config_2dot4g_sdf = 1;
288 req.sdf_2dot4g_val = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200289
290 /* Disable 5G support */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700291 req.config_support_5g = 1;
292 req.support_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200293 req.config_5g_beacons = 1;
294 req.beacon_5g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700295 req.config_5g_sdf = 1;
296 req.sdf_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200297 }
298 }
299
300 if (further_avail_ind) {
301 sigma_dut_print(dut, DUT_MSG_INFO, "FAM Test Enabled");
302 if (strcasecmp(further_avail_ind, "tx") == 0) {
303 is_fam = 1;
304 nan_further_availability_tx(dut, conn, cmd);
305 return 0;
306 } else if (strcasecmp(further_avail_ind, "rx") == 0) {
307 nan_further_availability_rx(dut, conn, cmd);
308 return 0;
309 }
310 }
311
312 if (only_5g && atoi(only_5g)) {
313 sigma_dut_print(dut, DUT_MSG_INFO, "5GHz only enabled");
314 req.config_2dot4g_support = 1;
315 req.support_2dot4g_val = 1;
316 req.config_2dot4g_beacons = 1;
317 req.beacon_2dot4g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700318 req.config_2dot4g_sdf = 1;
319 req.sdf_2dot4g_val = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200320 }
321
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700322 nan_enable_request(0, global_interface_handle, &req);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700323
324 /* To ensure sta_get_events to get the events
325 * only after joining the NAN cluster. */
326 abstime.tv_sec = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200327 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700328 wait(abstime);
329
330 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200331}
332
333
334int sigma_nan_disable(struct sigma_dut *dut, struct sigma_conn *conn,
335 struct sigma_cmd *cmd)
336{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200337 struct timespec abstime;
338
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700339 nan_disable_request(0, global_interface_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200340
341 abstime.tv_sec = 4;
342 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700343 wait(abstime);
344
345 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200346}
347
348
349int sigma_nan_config_enable(struct sigma_dut *dut, struct sigma_conn *conn,
350 struct sigma_cmd *cmd)
351{
352 const char *master_pref = get_param(cmd, "MasterPref");
353 const char *rand_fac = get_param(cmd, "RandFactor");
354 const char *hop_count = get_param(cmd, "HopCount");
355 struct timespec abstime;
356 NanConfigRequest req;
357
358 memset(&req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200359 req.config_rssi_proximity = 1;
360 req.rssi_proximity = 70;
361
362 if (master_pref) {
363 int master_pref_val = strtoul(master_pref, NULL, 0);
364
365 req.config_master_pref = 1;
366 req.master_pref = master_pref_val;
367 }
368
369 if (rand_fac) {
370 int rand_fac_val = strtoul(rand_fac, NULL, 0);
371
372 req.config_random_factor_force = 1;
373 req.random_factor_force_val = rand_fac_val;
374 }
375
376 if (hop_count) {
377 int hop_count_val = strtoul(hop_count, NULL, 0);
378
379 req.config_hop_count_force = 1;
380 req.hop_count_force_val = hop_count_val;
381 }
382
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700383 nan_config_request(0, global_interface_handle, &req);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200384
385 abstime.tv_sec = 4;
386 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700387 wait(abstime);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200388
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700389 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200390}
391
392
393static int sigma_nan_subscribe_request(struct sigma_dut *dut,
394 struct sigma_conn *conn,
395 struct sigma_cmd *cmd)
396{
397 const char *subscribe_type = get_param(cmd, "SubscribeType");
398 const char *service_name = get_param(cmd, "ServiceName");
399 const char *disc_range = get_param(cmd, "DiscoveryRange");
400 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
401 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
402 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
403 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
404 const char *include_bit = get_param(cmd, "IncludeBit");
405 const char *mac = get_param(cmd, "MAC");
406 const char *srf_type = get_param(cmd, "SRFType");
407 NanSubscribeRequest req;
408 int filter_len_rx = 0, filter_len_tx = 0;
409 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
410 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
411
412 memset(&req, 0, sizeof(NanSubscribeRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200413 req.ttl = 0;
414 req.period = 1000;
415 req.subscribe_type = 1;
416 req.serviceResponseFilter = 1; /* MAC */
417 req.serviceResponseInclude = 0;
418 req.ssiRequiredForMatchIndication = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700419 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200420 req.subscribe_count = 0;
421
422 if (subscribe_type) {
423 if (strcasecmp(subscribe_type, "Active") == 0) {
424 req.subscribe_type = 1;
425 } else if (strcasecmp(subscribe_type, "Passive") == 0) {
426 req.subscribe_type = 0;
427 } else if (strcasecmp(subscribe_type, "Cancel") == 0) {
428 NanSubscribeCancelRequest req;
429
430 memset(&req, 0, sizeof(NanSubscribeCancelRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700431 nan_subscribe_cancel_request(0, global_interface_handle,
432 &req);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200433 return 0;
434 }
435 }
436
437 if (disc_range)
438 req.rssi_threshold_flag = atoi(disc_range);
439
440 if (sdftx_dw)
441 req.subscribe_count = atoi(sdftx_dw);
442
443 /* Check this once again if config can be called here (TBD) */
444 if (discrange_ltd)
445 req.rssi_threshold_flag = atoi(discrange_ltd);
446
447 if (include_bit) {
448 int include_bit_val = atoi(include_bit);
449
450 req.serviceResponseInclude = include_bit_val;
451 sigma_dut_print(dut, DUT_MSG_INFO, "Includebit set %d",
452 req.serviceResponseInclude);
453 }
454
455 if (srf_type) {
456 int srf_type_val = atoi(srf_type);
457
458 if (srf_type_val == 1)
459 req.serviceResponseFilter = 0; /* Bloom */
460 else
461 req.serviceResponseFilter = 1; /* MAC */
462 req.useServiceResponseFilter = 1;
463 sigma_dut_print(dut, DUT_MSG_INFO, "srfFilter %d",
464 req.serviceResponseFilter);
465 }
466
467 if (mac) {
468 sigma_dut_print(dut, DUT_MSG_INFO, "MAC_ADDR List %s", mac);
469 req.num_intf_addr_present = nan_parse_mac_address_list(
470 dut, mac, &req.intf_addr[0][0],
471 NAN_MAX_SUBSCRIBE_MAX_ADDRESS);
472 }
473
474 memset(input_rx, 0, sizeof(input_rx));
475 memset(input_tx, 0, sizeof(input_tx));
476 if (rx_match_filter) {
477 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
478 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
479 filter_len_rx);
480 }
481 if (tx_match_filter) {
482 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
483 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
484 filter_len_tx);
485 }
486
487 if (tx_match_filter) {
488 req.tx_match_filter_len = filter_len_tx;
489 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
490 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
491 }
492 if (rx_match_filter) {
493 req.rx_match_filter_len = filter_len_rx;
494 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
495 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
496 }
497
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700498 if (service_name) {
499 strlcpy((char *) req.service_name, service_name,
500 strlen(service_name) + 1);
501 req.service_name_len = strlen(service_name);
502 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200503
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700504 nan_subscribe_request(0, global_interface_handle, &req);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200505 return 0;
506}
507
508
509int config_post_disc_attr(void)
510{
511 NanConfigRequest configReq;
512
513 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200514
515 /* Configure Post disc attr */
516 /* Make these defines and use correct enum */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700517 configReq.num_config_discovery_attr = 1;
518 configReq.discovery_attr_val[0].type = 4; /* Further Nan discovery */
519 configReq.discovery_attr_val[0].role = 0;
520 configReq.discovery_attr_val[0].transmit_freq = 1;
521 configReq.discovery_attr_val[0].duration = 0;
522 configReq.discovery_attr_val[0].avail_interval_bitmap = 0x00000008;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200523
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700524 nan_config_request(0, global_interface_handle, &configReq);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200525 return 0;
526}
527
528
529int sigma_nan_publish_request(struct sigma_dut *dut, struct sigma_conn *conn,
530 struct sigma_cmd *cmd)
531{
532 const char *publish_type = get_param(cmd, "PublishType");
533 const char *service_name = get_param(cmd, "ServiceName");
534 const char *disc_range = get_param(cmd, "DiscoveryRange");
535 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
536 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
537 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
538 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
539 NanPublishRequest req;
540 int filter_len_rx = 0, filter_len_tx = 0;
541 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
542 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
543
544 memset(&req, 0, sizeof(NanPublishRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200545 req.ttl = 0;
546 req.period = 500;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700547 req.publish_match_indicator = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200548 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
549 req.tx_type = NAN_TX_TYPE_BROADCAST;
550 req.publish_count = 0;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700551
552 if (service_name) {
553 strlcpy((char *) req.service_name, service_name,
554 strlen(service_name) + 1);
555 req.service_name_len = strlen(service_name);
556 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200557
558 if (publish_type) {
559 if (strcasecmp(publish_type, "Solicited") == 0) {
560 req.publish_type = NAN_PUBLISH_TYPE_SOLICITED;
561 } else if (strcasecmp(publish_type, "Cancel") == 0) {
562 NanPublishCancelRequest req;
563
564 memset(&req, 0, sizeof(NanPublishCancelRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700565 nan_publish_cancel_request(0, global_interface_handle,
566 &req);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200567 return 0;
568 }
569 }
570
571 if (disc_range)
572 req.rssi_threshold_flag = atoi(disc_range);
573
574 if (sdftx_dw)
575 req.publish_count = atoi(sdftx_dw);
576
577 if (discrange_ltd)
578 req.rssi_threshold_flag = atoi(discrange_ltd);
579
580 memset(input_rx, 0, sizeof(input_rx));
581 memset(input_tx, 0, sizeof(input_tx));
582 if (rx_match_filter) {
583 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
584 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
585 filter_len_rx);
586 }
587 if (tx_match_filter) {
588 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
589 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
590 filter_len_tx);
591 }
592
593 if (is_fam == 1) {
594 config_post_disc_attr();
595 /* TODO: Add comments regarding this step */
596 req.connmap = 0x10;
597 }
598
599 if (tx_match_filter) {
600 req.tx_match_filter_len = filter_len_tx;
601 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
602 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
603 }
604
605 if (rx_match_filter) {
606 req.rx_match_filter_len = filter_len_rx;
607 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
608 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
609 }
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700610
611 if (service_name) {
612 strlcpy((char *) req.service_name, service_name,
613 strlen(service_name) + 1);
614 req.service_name_len = strlen(service_name);
615 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200616
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700617 nan_publish_request(0, global_interface_handle, &req);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200618
619 return 0;
620}
621
622
623static int nan_further_availability_rx(struct sigma_dut *dut,
624 struct sigma_conn *conn,
625 struct sigma_cmd *cmd)
626{
627 const char *master_pref = get_param(cmd, "MasterPref");
628 const char *rand_fac = get_param(cmd, "RandFactor");
629 const char *hop_count = get_param(cmd, "HopCount");
630 struct timespec abstime;
631
632 NanEnableRequest req;
633
634 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200635 req.cluster_low = 0;
636 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200637 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200638
639 if (master_pref)
640 req.master_pref = strtoul(master_pref, NULL, 0);
641
642 if (rand_fac) {
643 int rand_fac_val = strtoul(rand_fac, NULL, 0);
644
645 req.config_random_factor_force = 1;
646 req.random_factor_force_val = rand_fac_val;
647 }
648
649 if (hop_count) {
650 int hop_count_val = strtoul(hop_count, NULL, 0);
651
652 req.config_hop_count_force = 1;
653 req.hop_count_force_val = hop_count_val;
654 }
655
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700656 nan_enable_request(0, global_interface_handle, &req);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700657
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200658 abstime.tv_sec = 4;
659 abstime.tv_nsec = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200660 wait(abstime);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700661
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200662 return 0;
663}
664
665
666static int nan_further_availability_tx(struct sigma_dut *dut,
667 struct sigma_conn *conn,
668 struct sigma_cmd *cmd)
669{
670 const char *master_pref = get_param(cmd, "MasterPref");
671 const char *rand_fac = get_param(cmd, "RandFactor");
672 const char *hop_count = get_param(cmd, "HopCount");
673 NanEnableRequest req;
674 NanConfigRequest configReq;
675
676 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200677 req.cluster_low = 0;
678 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200679 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200680
681 if (master_pref)
682 req.master_pref = strtoul(master_pref, NULL, 0);
683
684 if (rand_fac) {
685 int rand_fac_val = strtoul(rand_fac, NULL, 0);
686
687 req.config_random_factor_force = 1;
688 req.random_factor_force_val = rand_fac_val;
689 }
690
691 if (hop_count) {
692 int hop_count_val = strtoul(hop_count, NULL, 0);
693
694 req.config_hop_count_force = 1;
695 req.hop_count_force_val = hop_count_val;
696 }
697
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700698 nan_enable_request(0, global_interface_handle, &req);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200699
700 /* Start the config of fam */
701
702 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200703
704 configReq.config_fam = 1;
705 configReq.fam_val.numchans = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700706 configReq.fam_val.famchan[0].entry_control = 0;
707 configReq.fam_val.famchan[0].class_val = 81;
708 configReq.fam_val.famchan[0].channel = 6;
709 configReq.fam_val.famchan[0].mapid = 0;
710 configReq.fam_val.famchan[0].avail_interval_bitmap = 0x7ffffffe;
711
712 nan_config_request(0, global_interface_handle, &configReq);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200713
714 return 0;
715}
716
717
718int sigma_nan_transmit_followup(struct sigma_dut *dut,
719 struct sigma_conn *conn,
720 struct sigma_cmd *cmd)
721{
722 const char *mac = get_param(cmd, "mac");
723 const char *requestor_id = get_param(cmd, "RemoteInstanceId");
724 const char *local_id = get_param(cmd, "LocalInstanceId");
725 const char *service_name = get_param(cmd, "servicename");
726 NanTransmitFollowupRequest req;
727
728 memset(&req, 0, sizeof(NanTransmitFollowupRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700729 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200730 req.addr[0] = 0xFF;
731 req.addr[1] = 0xFF;
732 req.addr[2] = 0xFF;
733 req.addr[3] = 0xFF;
734 req.addr[4] = 0xFF;
735 req.addr[5] = 0xFF;
736 req.priority = NAN_TX_PRIORITY_NORMAL;
737 req.dw_or_faw = 0;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700738
739 if (service_name)
740 req.service_specific_info_len = strlen(service_name);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200741
742 if (requestor_id) {
743 /* int requestor_id_val = atoi(requestor_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700744 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200745 }
746 if (local_id) {
747 /* int local_id_val = atoi(local_id); */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700748 req.publish_subscribe_id = global_header_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200749 }
750
751 if (mac == NULL) {
752 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid MAC Address");
753 return -1;
754 }
755 nan_parse_mac_address(dut, mac, req.addr);
756
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200757 if (requestor_id)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700758 req.requestor_instance_id = strtoul(requestor_id, NULL, 0);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200759
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700760
761 nan_transmit_followup_request(0, global_interface_handle, &req);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200762 return 0;
763}
764
765/* NotifyResponse invoked to notify the status of the Request */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700766void nan_notify_response(transaction_id id, NanResponseMsg *rsp_data)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200767{
768 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700769 "%s: status %d value %d response_type %d",
770 __func__,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200771 rsp_data->status, rsp_data->value,
772 rsp_data->response_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200773 if (rsp_data->response_type == NAN_RESPONSE_STATS) {
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700774 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: stats_type %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200775 __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700776 rsp_data->body.stats_response.stats_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200777 }
778#if 0
779 if (rsp_data->response_type == NAN_RESPONSE_CONFIG &&
780 rsp_data->status == 0)
781 pthread_cond_signal(&gCondition);
782#endif
783}
784
785
786/* Events Callback */
787void nan_event_publish_replied(NanPublishRepliedInd *event)
788{
789 sigma_dut_print(global_dut, DUT_MSG_INFO,
790 "%s: handle %d " MAC_ADDR_STR " rssi:%d",
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700791 __func__, event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200792 MAC_ADDR_ARRAY(event->addr), event->rssi_value);
793 event_anyresponse = 1;
794 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700795 "EventName,Replied,RemoteInstanceID %d,mac," MAC_ADDR_STR,
796 (event->requestor_instance_id >> 24),
797 MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200798}
799
800
801/* Events Callback */
802void nan_event_publish_terminated(NanPublishTerminatedInd *event)
803{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700804 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: publish_id %d reason %d",
805 __func__, event->publish_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200806}
807
808
809/* Events Callback */
810void nan_event_match(NanMatchInd *event)
811{
812 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700813 "%s: Pub/Sub Id %d remote_requestor_id %08x "
814 MAC_ADDR_STR
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200815 " rssi:%d",
816 __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700817 event->publish_subscribe_id,
818 event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200819 MAC_ADDR_ARRAY(event->addr),
820 event->rssi_value);
821 event_anyresponse = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700822 global_header_handle = event->publish_subscribe_id;
823 global_match_handle = event->requestor_instance_id;
824
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200825 /* memset(event_resp_buf, 0, sizeof(event_resp_buf)); */
826 /* global_pub_sub_handle = event->header.handle; */
827 /* Print the SSI */
828 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing SSI:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700829 nan_hex_dump(global_dut, event->service_specific_info,
830 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200831 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
832 "EventName,DiscoveryResult,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700833 MAC_ADDR_STR " ", (event->requestor_instance_id >> 24),
834 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200835
836 /* Print the match filter */
837 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing sdf match filter:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700838 nan_hex_dump(global_dut, event->sdf_match_filter,
839 event->sdf_match_filter_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200840
841 /* Print the conn_capability */
842 sigma_dut_print(global_dut, DUT_MSG_INFO,
843 "Printing PostConnectivity Capability");
844 if (event->is_conn_capability_valid) {
845 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfd supported:%s",
846 event->conn_capability.is_wfd_supported ?
847 "yes" : "no");
848 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfds supported:%s",
849 (event->conn_capability.is_wfds_supported ?
850 "yes" : "no"));
851 sigma_dut_print(global_dut, DUT_MSG_INFO, "TDLS supported:%s",
852 (event->conn_capability.is_tdls_supported ?
853 "yes" : "no"));
854 sigma_dut_print(global_dut, DUT_MSG_INFO, "IBSS supported:%s",
855 (event->conn_capability.is_ibss_supported ?
856 "yes" : "no"));
857 sigma_dut_print(global_dut, DUT_MSG_INFO, "Mesh supported:%s",
858 (event->conn_capability.is_mesh_supported ?
859 "yes" : "no"));
860 sigma_dut_print(global_dut, DUT_MSG_INFO, "Infra Field:%d",
861 event->conn_capability.wlan_infra_field);
862 } else {
863 sigma_dut_print(global_dut, DUT_MSG_INFO,
864 "PostConnectivity Capability not present");
865 }
866
867 /* Print the discovery_attr */
868 sigma_dut_print(global_dut, DUT_MSG_INFO,
869 "Printing PostDiscovery Attribute");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700870 if (event->num_rx_discovery_attr) {
871 int idx;
872
873 for (idx = 0; idx < event->num_rx_discovery_attr; idx++) {
874 sigma_dut_print(global_dut, DUT_MSG_INFO,
875 "PostDiscovery Attribute - %d", idx);
876 sigma_dut_print(global_dut, DUT_MSG_INFO,
877 "Conn Type:%d Device Role:%d"
878 MAC_ADDR_STR,
879 event->discovery_attr[idx].type,
880 event->discovery_attr[idx].role,
881 MAC_ADDR_ARRAY(event->discovery_attr[idx].addr));
882 sigma_dut_print(global_dut, DUT_MSG_INFO,
883 "Duration:%d MapId:%d "
884 "avail_interval_bitmap:%04x",
885 event->discovery_attr[idx].duration,
886 event->discovery_attr[idx].mapid,
887 event->discovery_attr[idx].avail_interval_bitmap);
888 sigma_dut_print(global_dut, DUT_MSG_INFO,
889 "Printing Mesh Id:");
890 nan_hex_dump(global_dut,
891 event->discovery_attr[idx].mesh_id,
892 event->discovery_attr[idx].mesh_id_len);
893 sigma_dut_print(global_dut, DUT_MSG_INFO,
894 "Printing Infrastructure Ssid:");
895 nan_hex_dump(global_dut,
896 event->discovery_attr[idx].infrastructure_ssid_val,
897 event->discovery_attr[idx].infrastructure_ssid_len);
898 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200899 } else {
900 sigma_dut_print(global_dut, DUT_MSG_INFO,
901 "PostDiscovery attribute not present");
902 }
903
904 /* Print the fam */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700905 if (event->num_chans) {
906 nan_print_further_availability_chan(global_dut,
907 event->num_chans,
908 &event->famchan[0]);
909 } else {
910 sigma_dut_print(global_dut, DUT_MSG_INFO,
911 "Further Availability Map not present");
912 }
913 if (event->cluster_attribute_len) {
914 sigma_dut_print(global_dut, DUT_MSG_INFO,
915 "Printing Cluster Attribute:");
916 nan_hex_dump(global_dut, event->cluster_attribute,
917 event->cluster_attribute_len);
918 } else {
919 sigma_dut_print(global_dut, DUT_MSG_INFO,
920 "Cluster Attribute not present");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200921 }
922}
923
924
925/* Events Callback */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700926void nan_event_match_expired(NanMatchExpiredInd *event)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200927{
928 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700929 "%s: publish_subscribe_id %d match_handle %08x",
930 __func__, event->publish_subscribe_id,
931 event->requestor_instance_id);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200932}
933
934
935/* Events Callback */
936void nan_event_subscribe_terminated(NanSubscribeTerminatedInd *event)
937{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700938 sigma_dut_print(global_dut, DUT_MSG_INFO,
939 "%s: Subscribe Id %d reason %d",
940 __func__, event->subscribe_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200941}
942
943
944/* Events Callback */
945void nan_event_followup(NanFollowupInd *event)
946{
947 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700948 "%s: Publish/Subscribe Id %d match_handle 0x%08x dw_or_faw %d "
949 MAC_ADDR_STR, __func__, event->publish_subscribe_id,
950 event->requestor_instance_id, event->dw_or_faw,
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200951 MAC_ADDR_ARRAY(event->addr));
952
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700953 global_match_handle = event->publish_subscribe_id;
954 global_header_handle = event->requestor_instance_id;
955 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Printing SSI", __func__);
956 nan_hex_dump(global_dut, event->service_specific_info,
957 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200958 event_anyresponse = 1;
959 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
960 "EventName,FollowUp,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700961 MAC_ADDR_STR " ", event->requestor_instance_id >> 24,
962 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200963}
964
965
966/* Events Callback */
967void nan_event_disceng_event(NanDiscEngEventInd *event)
968{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700969 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: event_type %d",
970 __func__, event->event_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200971
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700972 if (event->event_type == NAN_EVENT_ID_JOINED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200973 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Joined cluster "
974 MAC_ADDR_STR,
975 __func__,
976 MAC_ADDR_ARRAY(event->data.cluster.addr));
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700977 /* To ensure sta_get_events to get the events
978 * only after joining the NAN cluster. */
979 pthread_cond_signal(&gCondition);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200980 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700981 if (event->event_type == NAN_EVENT_ID_STARTED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200982 sigma_dut_print(global_dut, DUT_MSG_INFO,
983 "%s: Started cluster " MAC_ADDR_STR,
984 __func__,
985 MAC_ADDR_ARRAY(event->data.cluster.addr));
986 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700987 if (event->event_type == NAN_EVENT_ID_DISC_MAC_ADDR) {
988 sigma_dut_print(global_dut, DUT_MSG_INFO,
989 "%s: Discovery Mac Address "
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200990 MAC_ADDR_STR,
991 __func__,
992 MAC_ADDR_ARRAY(event->data.mac_addr.addr));
993 memcpy(global_nan_mac_addr, event->data.mac_addr.addr,
994 sizeof(global_nan_mac_addr));
995 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200996}
997
998
999/* Events Callback */
1000void nan_event_disabled(NanDisabledInd *event)
1001{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001002 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: reason %d",
1003 __func__, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001004 /* pthread_cond_signal(&gCondition); */
1005}
1006
1007
1008void * my_thread_function(void *ptr)
1009{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001010 wifi_event_loop(global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001011 pthread_exit(0);
1012 return (void *) NULL;
1013}
1014
1015
1016static NanCallbackHandler callbackHandler = {
1017 .NotifyResponse = nan_notify_response,
1018 .EventPublishReplied = nan_event_publish_replied,
1019 .EventPublishTerminated = nan_event_publish_terminated,
1020 .EventMatch = nan_event_match,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001021 .EventMatchExpired = nan_event_match_expired,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001022 .EventSubscribeTerminated = nan_event_subscribe_terminated,
1023 .EventFollowup = nan_event_followup,
1024 .EventDiscEngEvent = nan_event_disceng_event,
1025 .EventDisabled = nan_event_disabled,
1026};
1027
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001028
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001029void nan_init(struct sigma_dut *dut)
1030{
1031 pthread_t thread1; /* thread variables */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001032 wifi_error err = wifi_initialize(&global_wifi_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001033
1034 if (err) {
1035 printf("wifi hal initialize failed\n");
1036 return;
1037 }
1038
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001039 global_interface_handle = wifi_get_iface_handle(global_wifi_handle,
1040 (char *) "wlan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001041 /* create threads 1 */
1042 pthread_create(&thread1, NULL, &my_thread_function, NULL);
1043
1044 pthread_mutex_init(&gMutex, NULL);
1045 pthread_cond_init(&gCondition, NULL);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001046 if (global_interface_handle)
1047 nan_register_handler(global_interface_handle, callbackHandler);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001048}
1049
1050
1051void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1052 struct sigma_cmd *cmd)
1053{
1054 sigma_dut_print(dut, DUT_MSG_INFO, "NAN sta_reset_default");
1055
1056 if (nan_state == 0) {
1057 nan_init(dut);
1058 nan_state = 1;
1059 }
1060 is_fam = 0;
1061 event_anyresponse = 0;
1062 global_dut = dut;
1063 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1064 sigma_nan_disable(dut, conn, cmd);
1065}
1066
1067
1068int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1069 struct sigma_cmd *cmd)
1070{
1071 const char *program = get_param(cmd, "Prog");
1072 const char *nan_op = get_param(cmd, "NANOp");
1073 const char *method_type = get_param(cmd, "MethodType");
1074 char resp_buf[100];
1075
1076 if (program == NULL)
1077 return -1;
1078
1079 if (strcasecmp(program, "NAN") != 0) {
1080 send_resp(dut, conn, SIGMA_ERROR,
1081 "ErrorCode,Unsupported program");
1082 return 0;
1083 }
1084
1085 if (nan_op) {
1086 /*
1087 * NANOp has been specified.
1088 * We will build a nan_enable or nan_disable command.
1089 */
1090 if (strcasecmp(nan_op, "On") == 0) {
1091 if (sigma_nan_enable(dut, conn, cmd) == 0) {
1092 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1093 MAC_ADDR_STR,
1094 MAC_ADDR_ARRAY(global_nan_mac_addr));
1095 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1096 } else {
1097 send_resp(dut, conn, SIGMA_ERROR,
1098 "NAN_ENABLE_FAILED");
1099 return -1;
1100 }
1101 } else if (strcasecmp(nan_op, "Off") == 0) {
1102 sigma_nan_disable(dut, conn, cmd);
1103 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1104 }
1105 }
1106 if (nan_state && nan_op == NULL) {
1107 if (method_type) {
1108 if (strcasecmp(method_type, "Publish") == 0) {
1109 sigma_nan_publish_request(dut, conn, cmd);
1110 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1111 }
1112 if (strcasecmp(method_type, "Subscribe") == 0) {
1113 sigma_nan_subscribe_request(dut, conn, cmd);
1114 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1115 }
1116 if (strcasecmp(method_type, "Followup") == 0) {
1117 sigma_nan_transmit_followup(dut, conn, cmd);
1118 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
1119 }
1120 } else {
1121 sigma_nan_config_enable(dut, conn, cmd);
1122 snprintf(resp_buf, sizeof(resp_buf), "mac,"
1123 MAC_ADDR_STR,
1124 MAC_ADDR_ARRAY(global_nan_mac_addr));
1125 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1126 }
1127 }
1128
1129 return 0;
1130}
1131
1132
1133int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1134 struct sigma_cmd *cmd)
1135{
1136
1137 const char *program = get_param(cmd, "Program");
1138 const char *parameter = get_param(cmd, "Parameter");
1139 char resp_buf[100];
1140 NanStaParameter rsp;
1141
1142 if (program == NULL) {
1143 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Program Name");
1144 return -1;
1145 }
1146 if (strcasecmp(program, "NAN") != 0) {
1147 send_resp(dut, conn, SIGMA_ERROR,
1148 "ErrorCode,Unsupported program");
1149 return 0;
1150 }
1151
1152 if (parameter == NULL) {
1153 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Parameter");
1154 return -1;
1155 }
1156 memset(&rsp, 0, sizeof(NanStaParameter));
1157
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001158 nan_get_sta_parameter(0, global_interface_handle, &rsp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001159 sigma_dut_print(dut, DUT_MSG_INFO,
1160 "%s: NanStaparameter Master_pref:%02x, Random_factor:%02x, hop_count:%02x beacon_transmit_time:%d",
1161 __func__, rsp.master_pref, rsp.random_factor,
1162 rsp.hop_count, rsp.beacon_transmit_time);
1163
1164 if (strcasecmp(parameter, "MasterPref") == 0) {
1165 snprintf(resp_buf, sizeof(resp_buf), "MasterPref,0x%x",
1166 rsp.master_pref);
1167 } else if (strcasecmp(parameter, "MasterRank") == 0) {
1168 snprintf(resp_buf, sizeof(resp_buf), "MasterRank,0x%lx",
1169 rsp.master_rank);
1170 } else if (strcasecmp(parameter, "RandFactor") == 0) {
1171 snprintf(resp_buf, sizeof(resp_buf), "RandFactor,0x%x",
1172 rsp.random_factor);
1173 } else if (strcasecmp(parameter, "HopCount") == 0) {
1174 snprintf(resp_buf, sizeof(resp_buf), "HopCount,0x%x",
1175 rsp.hop_count);
1176 } else if (strcasecmp(parameter, "BeaconTransTime") == 0) {
1177 snprintf(resp_buf, sizeof(resp_buf), "BeaconTransTime 0x%x",
1178 rsp.beacon_transmit_time);
1179 } else if (strcasecmp(parameter, "NANStatus") == 0) {
1180 if (nan_state == 1)
1181 snprintf(resp_buf, sizeof(resp_buf), "On");
1182 else
1183 snprintf(resp_buf, sizeof(resp_buf), "Off");
1184 } else {
1185 send_resp(dut, conn, SIGMA_ERROR, "Invalid Parameter");
1186 return 0;
1187 }
1188
1189 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
1190 return 0;
1191}
1192
1193
1194int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1195 struct sigma_cmd *cmd)
1196{
1197 const char *action = get_param(cmd, "Action");
1198
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001199 if (!action)
1200 return 0;
1201
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001202 /* Check action for start, stop and get events. */
1203 if (strcasecmp(action, "Start") == 0) {
1204 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1205 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1206 } else if (strcasecmp(action, "Stop") == 0) {
1207 event_anyresponse = 0;
1208 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
1209 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
1210 } else if (strcasecmp(action, "Get") == 0) {
1211 if (event_anyresponse == 1) {
1212 send_resp(dut, conn, SIGMA_COMPLETE,
1213 global_event_resp_buf);
1214 } else {
1215 send_resp(dut, conn, SIGMA_COMPLETE, "EventList,NONE");
1216 }
1217 }
1218 return 0;
1219}
Rakesh Sunki4b75f962017-03-30 14:47:55 -07001220
1221#else /* #if NAN_CERT_VERSION */
1222
1223int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
1224 struct sigma_conn *conn,
1225 struct sigma_cmd *cmd)
1226{
1227 return 1;
1228}
1229
1230
1231int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
1232 struct sigma_cmd *cmd)
1233{
1234 return 0;
1235
1236}
1237
1238
1239void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
1240 struct sigma_cmd *cmd)
1241{
1242 return;
1243}
1244
1245
1246int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
1247 struct sigma_cmd *cmd)
1248{
1249 return 0;
1250}
1251
1252
1253int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
1254 struct sigma_cmd *cmd)
1255{
1256 return 0;
1257}
1258
1259#endif /* #if NAN_CERT_VERSION */