blob: 8934e7f5e7675c582564efd24fc537c1660b9531 [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.
Peng Xu8863ec72018-08-06 11:50:37 -07004 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005 * All Rights Reserved.
6 * Licensed under the Clear BSD license. See README for more details.
7 */
8
9#include "sigma_dut.h"
10#include <sys/stat.h>
11#include "wpa_ctrl.h"
12#include "wpa_helpers.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
Peng Xu47d709b2019-06-04 18:14:02 -070017#if ((NAN_MAJOR_VERSION > 2) || \
18 (NAN_MAJOR_VERSION == 2 && \
19 (NAN_MINOR_VERSION >= 1 || NAN_MICRO_VERSION >= 1))) && \
20 NAN_CERT_VERSION >= 5
21#define NAN_NEW_CERT_VERSION
22#endif
23
Jouni Malinencd4e3c32015-10-29 12:39:56 +020024pthread_cond_t gCondition;
25pthread_mutex_t gMutex;
Rakesh Sunkid51e8982017-03-30 14:47:55 -070026static NanSyncStats global_nan_sync_stats;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020027static int nan_state = 0;
28static int event_anyresponse = 0;
29static int is_fam = 0;
30
Rakesh Sunki4c086672017-03-30 14:47:55 -070031static uint16_t global_ndp_instance_id = 0;
Rakesh Sunki4d5912d2017-03-30 14:47:55 -070032static uint16_t global_publish_id = 0;
33static uint16_t global_subscribe_id = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020034uint16_t global_header_handle = 0;
35uint32_t global_match_handle = 0;
36
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -070037#define DEFAULT_SVC "QNanCluster"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020038#define MAC_ADDR_ARRAY(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
39#define MAC_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
40#ifndef ETH_ALEN
41#define ETH_ALEN 6
42#endif
43
Peng Xu47d709b2019-06-04 18:14:02 -070044static const u8 nan_wfa_oui[] = { 0x50, 0x6f, 0x9a };
45/* TLV header length = tag (1 byte) + length (2 bytes) */
46#define WLAN_NAN_TLV_HEADER_SIZE (1 + 2)
47#define NAN_INTF_ID_LEN 8
48
Jouni Malinencd4e3c32015-10-29 12:39:56 +020049struct sigma_dut *global_dut = NULL;
50static char global_nan_mac_addr[ETH_ALEN];
Rakesh Sunki14cfcd22017-03-30 14:47:55 -070051static char global_peer_mac_addr[ETH_ALEN];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020052static char global_event_resp_buf[1024];
Rakesh Sunki42363682017-05-16 15:00:42 -070053static u8 global_publish_service_name[NAN_MAX_SERVICE_NAME_LEN];
54static u32 global_publish_service_name_len = 0;
Rakesh Sunki74f4f992017-08-16 15:21:52 -070055static u8 global_subscribe_service_name[NAN_MAX_SERVICE_NAME_LEN];
56static u32 global_subscribe_service_name_len = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020057
58static int nan_further_availability_tx(struct sigma_dut *dut,
59 struct sigma_conn *conn,
60 struct sigma_cmd *cmd);
61static int nan_further_availability_rx(struct sigma_dut *dut,
62 struct sigma_conn *conn,
63 struct sigma_cmd *cmd);
64
Peng Xu47d709b2019-06-04 18:14:02 -070065enum wlan_nan_tlv_type {
66 NAN_TLV_TYPE_IPV6_LINK_LOCAL = 0x00,
67 NAN_TLV_TYPE_SERVICE_INFO = 0x01,
68 NAN_TLV_TYPE_RSVD_START = 0x02,
69 NAN_TLV_TYPE_RSVD_START_END = 0xFF
70};
71
72enum wlan_nan_service_protocol_type {
73 NAN_TLV_SERVICE_PROTO_TYPE_RSVD1 = 0x00,
74 NAN_TLV_SERVICE_PROTO_TYPE_BONJOUR = 0x01,
75 NAN_TLV_SERVICE_PROTO_TYPE_GENERIC = 0x02,
76 NAN_TLV_SERVICE_PROTO_RSVD2_START = 0x03,
77 NAN_TLV_SERVICE_PROTO_TYPE_RSVD2_END = 0xFF
78};
79
80enum wlan_nan_generic_service_proto_sub_attr {
81 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TRANS_PORT = 0x00,
82 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TRANS_PROTO = 0x01,
83 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_SERVICE_NAME = 0x02,
84 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TEXTINFO = 0x04,
85 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_UUID = 0x05,
86 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_BLOB = 0x06,
87 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_RSVD1_START = 0x07,
88 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_RSVD1_END = 0xDC,
89 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_VENDOR_SPEC_INFO= 0xDD,
90 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_RSVD2_START = 0xDE,
91 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_RSVD2_END = 0xFF
92};
93
Jouni Malinencd4e3c32015-10-29 12:39:56 +020094
95void nan_hex_dump(struct sigma_dut *dut, uint8_t *data, size_t len)
96{
97 char buf[512];
98 uint16_t index;
99 uint8_t *ptr;
100 int pos;
101
102 memset(buf, 0, sizeof(buf));
103 ptr = data;
104 pos = 0;
105 for (index = 0; index < len; index++) {
Peng Xu6734e232017-10-04 10:10:33 -0700106 pos += snprintf(&(buf[pos]), sizeof(buf) - pos,
107 "%02x ", *ptr++);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200108 if (pos > 508)
109 break;
110 }
111 sigma_dut_print(dut, DUT_MSG_INFO, "HEXDUMP len=[%d]", (int) len);
112 sigma_dut_print(dut, DUT_MSG_INFO, "buf:%s", buf);
113}
114
115
116int nan_parse_hex(unsigned char c)
117{
118 if (c >= '0' && c <= '9')
119 return c - '0';
120 if (c >= 'a' && c <= 'f')
121 return c - 'a' + 10;
122 if (c >= 'A' && c <= 'F')
123 return c - 'A' + 10;
124 return 0;
125}
126
127
128int nan_parse_token(const char *tokenIn, u8 *tokenOut, int *filterLen)
129{
130 int total_len = 0, len = 0;
131 char *saveptr = NULL;
132
133 tokenIn = strtok_r((char *) tokenIn, ":", &saveptr);
134 while (tokenIn != NULL) {
135 len = strlen(tokenIn);
136 if (len == 1 && *tokenIn == '*')
137 len = 0;
138 tokenOut[total_len++] = (u8) len;
139 if (len != 0)
140 memcpy((u8 *) tokenOut + total_len, tokenIn, len);
141 total_len += len;
142 tokenIn = strtok_r(NULL, ":", &saveptr);
143 }
144 *filterLen = total_len;
145 return 0;
146}
147
148
149int nan_parse_mac_address(struct sigma_dut *dut, const char *arg, u8 *addr)
150{
151 if (strlen(arg) != 17) {
152 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid mac address %s",
153 arg);
154 sigma_dut_print(dut, DUT_MSG_ERROR,
155 "expected format xx:xx:xx:xx:xx:xx");
156 return -1;
157 }
158
159 addr[0] = nan_parse_hex(arg[0]) << 4 | nan_parse_hex(arg[1]);
160 addr[1] = nan_parse_hex(arg[3]) << 4 | nan_parse_hex(arg[4]);
161 addr[2] = nan_parse_hex(arg[6]) << 4 | nan_parse_hex(arg[7]);
162 addr[3] = nan_parse_hex(arg[9]) << 4 | nan_parse_hex(arg[10]);
163 addr[4] = nan_parse_hex(arg[12]) << 4 | nan_parse_hex(arg[13]);
164 addr[5] = nan_parse_hex(arg[15]) << 4 | nan_parse_hex(arg[16]);
165
166 return 0;
167}
168
169
170int nan_parse_mac_address_list(struct sigma_dut *dut, const char *input,
171 u8 *output, u16 max_addr_allowed)
172{
173 /*
174 * Reads a list of mac address separated by space. Each MAC address
175 * should have the format of aa:bb:cc:dd:ee:ff.
176 */
177 char *saveptr;
178 char *token;
179 int i = 0;
180
181 for (i = 0; i < max_addr_allowed; i++) {
182 token = strtok_r((i == 0) ? (char *) input : NULL,
183 " ", &saveptr);
184 if (token) {
185 nan_parse_mac_address(dut, token, output);
186 output += NAN_MAC_ADDR_LEN;
187 } else
188 break;
189 }
190
191 sigma_dut_print(dut, DUT_MSG_INFO, "Num MacAddress:%d", i);
192
193 return i;
194}
195
196
197int nan_parse_hex_string(struct sigma_dut *dut, const char *input,
198 u8 *output, int *outputlen)
199{
200 int i = 0;
201 int j = 0;
202
203 for (i = 0; i < (int) strlen(input) && j < *outputlen; i += 2) {
204 output[j] = nan_parse_hex(input[i]);
205 if (i + 1 < (int) strlen(input)) {
206 output[j] = ((output[j] << 4) |
207 nan_parse_hex(input[i + 1]));
208 }
209 j++;
210 }
211 *outputlen = j;
212 sigma_dut_print(dut, DUT_MSG_INFO, "Input:%s inputlen:%d outputlen:%d",
213 input, (int) strlen(input), (int) *outputlen);
214 return 0;
215}
216
217
Peng Xu47d709b2019-06-04 18:14:02 -0700218static size_t nan_build_ipv6_link_local_tlv(u8 *p_frame,
219 const u8 *p_ipv6_intf_addr)
220{
221 /* fill attribute ID */
222 *p_frame++ = NAN_TLV_TYPE_IPV6_LINK_LOCAL;
223
224 /* Fill the length */
225 *p_frame++ = NAN_INTF_ID_LEN & 0xFF;
226 *p_frame++ = NAN_INTF_ID_LEN >> 8;
227
228 /* only the lower 8 bytes is needed */
229 memcpy(p_frame, &p_ipv6_intf_addr[NAN_INTF_ID_LEN], NAN_INTF_ID_LEN);
230
231 return NAN_INTF_ID_LEN + WLAN_NAN_TLV_HEADER_SIZE;
232}
233
234
235static size_t nan_build_service_info_tlv_sub_attr(
236 u8 *p_frame, const u8 *sub_attr, const u16 sub_attr_len,
237 enum wlan_nan_generic_service_proto_sub_attr sub_attr_id)
238{
239 /* Fill Service Subattibute ID */
240 *p_frame++ = (u8) sub_attr_id;
241
242 /* Fill the length */
243 *p_frame++ = sub_attr_len & 0xFF;
244 *p_frame++ = sub_attr_len >> 8;
245
246 /* Fill the value */
247 memcpy(p_frame, sub_attr, sub_attr_len);
248
249 return sub_attr_len + WLAN_NAN_TLV_HEADER_SIZE;
250}
251
252
253static size_t nan_build_service_info_tlv(u8 *p_frame,
254 const NdpIpTransParams *p_ndp_attr)
255{
256 u16 tlv_len = 0, len = 0;
257 u8 *p_offset_len;
258
259 if (p_ndp_attr->trans_port_present || p_ndp_attr->trans_proto_present) {
260 /* fill attribute ID */
261 *p_frame++ = NAN_TLV_TYPE_SERVICE_INFO;
262
263 p_offset_len = p_frame;
264 p_frame += 2;
265
266 /* Fill WFA Specific OUI */
267 memcpy(p_frame, nan_wfa_oui, sizeof(nan_wfa_oui));
268 p_frame += sizeof(nan_wfa_oui);
269 tlv_len += sizeof(nan_wfa_oui);
270
271 /* Fill Service protocol Type */
272 *p_frame++ = NAN_TLV_SERVICE_PROTO_TYPE_GENERIC;
273 tlv_len += 1;
274
275 if (p_ndp_attr->trans_port_present) {
276 len = nan_build_service_info_tlv_sub_attr(
277 p_frame,
278 (const u8 *) &p_ndp_attr->transport_port,
279 sizeof(p_ndp_attr->transport_port),
280 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TRANS_PORT);
281 p_frame += len;
282 tlv_len += len;
283 }
284
285 if (p_ndp_attr->trans_proto_present) {
286 len = nan_build_service_info_tlv_sub_attr(
287 p_frame,
288 (const u8 *) &p_ndp_attr->transport_protocol,
289 sizeof(p_ndp_attr->transport_protocol),
290 NAN_GENERIC_SERVICE_PROTO_SUB_ATTR_ID_TRANS_PROTO);
291 p_frame += len;
292 tlv_len += len;
293 }
294
295 /* Fill the length */
296 *p_offset_len++ = tlv_len & 0xFF;
297 *p_offset_len = tlv_len >> 8;
298
299 tlv_len += WLAN_NAN_TLV_HEADER_SIZE;
300 }
301
302 return tlv_len;
303}
304
305
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200306int wait(struct timespec abstime)
307{
308 struct timeval now;
309
310 gettimeofday(&now, NULL);
311
312 abstime.tv_sec += now.tv_sec;
313 if (((abstime.tv_nsec + now.tv_usec * 1000) > 1000 * 1000 * 1000) ||
314 (abstime.tv_nsec + now.tv_usec * 1000 < 0)) {
315 abstime.tv_sec += 1;
316 abstime.tv_nsec += now.tv_usec * 1000;
317 abstime.tv_nsec -= 1000 * 1000 * 1000;
318 } else {
319 abstime.tv_nsec += now.tv_usec * 1000;
320 }
321
322 return pthread_cond_timedwait(&gCondition, &gMutex, &abstime);
323}
324
325
326int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
327 struct sigma_conn *conn,
328 struct sigma_cmd *cmd)
329{
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700330 const char *oper_chan = get_param(cmd, "oper_chn");
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700331 const char *pmk = get_param(cmd, "PMK");
Peng Xu47d709b2019-06-04 18:14:02 -0700332#ifdef NAN_NEW_CERT_VERSION
Peng Xu57d7ead2018-08-06 11:53:47 -0700333 const char *ndpe = get_param(cmd, "NDPE");
334 const char *trans_proto = get_param(cmd, "TransProtoType");
335 const char *ndp_attr = get_param(cmd, "ndpAttr");
336#endif
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200337
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700338 if (oper_chan) {
339 sigma_dut_print(dut, DUT_MSG_INFO, "Operating Channel: %s",
340 oper_chan);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700341 dut->sta_channel = atoi(oper_chan);
Rakesh Sunki8dd1d882017-03-30 14:47:55 -0700342 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200343
Rakesh Sunki7d37f412017-03-30 14:47:55 -0700344 if (pmk) {
345 int pmk_len;
346
347 sigma_dut_print(dut, DUT_MSG_INFO, "%s given string pmk: %s",
348 __func__, pmk);
349 memset(dut->nan_pmk, 0, NAN_PMK_INFO_LEN);
350 dut->nan_pmk_len = 0;
351 pmk_len = NAN_PMK_INFO_LEN;
352 nan_parse_hex_string(dut, &pmk[2], &dut->nan_pmk[0], &pmk_len);
353 dut->nan_pmk_len = pmk_len;
354 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
355 __func__, dut->nan_pmk_len);
356 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex pmk", __func__);
357 nan_hex_dump(dut, &dut->nan_pmk[0], dut->nan_pmk_len);
358 }
359
Peng Xu47d709b2019-06-04 18:14:02 -0700360#ifdef NAN_NEW_CERT_VERSION
Peng Xu57d7ead2018-08-06 11:53:47 -0700361 if (ndpe) {
362 NanConfigRequest req;
363 wifi_error ret;
364
365 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s: NDPE: %s",
366 __func__, ndpe);
367 memset(&req, 0, sizeof(NanConfigRequest));
368 dut->ndpe = strcasecmp(ndpe, "Enable") == 0;
369 req.config_ndpe_attr = 1;
370 req.use_ndpe_attr = dut->ndpe;
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530371 ret = nan_config_request(0, dut->wifi_hal_iface_handle, &req);
Peng Xu57d7ead2018-08-06 11:53:47 -0700372 if (ret != WIFI_SUCCESS) {
373 send_resp(dut, conn, SIGMA_ERROR,
374 "NAN config request failed");
375 return 0;
376 }
377 }
378
379 if (trans_proto) {
380 sigma_dut_print(dut, DUT_MSG_INFO, "%s: Transport protocol: %s",
381 __func__, trans_proto);
382 if (strcasecmp(trans_proto, "TCP") == 0) {
383 dut->trans_proto = TRANSPORT_PROTO_TYPE_TCP;
384 } else if (strcasecmp(trans_proto, "UDP") == 0) {
385 dut->trans_proto = TRANSPORT_PROTO_TYPE_UDP;
386 } else {
387 sigma_dut_print(dut, DUT_MSG_ERROR,
388 "%s: Invalid protocol %s, set to TCP",
389 __func__, trans_proto);
390 dut->trans_proto = TRANSPORT_PROTO_TYPE_TCP;
391 }
392 }
393
394 if (dut->ndpe && ndp_attr) {
395 NanDebugParams cfg_debug;
396 int ndp_attr_val;
397 int ret, size;
398
399 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s: NDP Attr: %s",
400 __func__, ndp_attr);
401
402 memset(&cfg_debug, 0, sizeof(NanDebugParams));
403 cfg_debug.cmd = NAN_TEST_MODE_CMD_ENABLE_NDP;
404 if (strcasecmp(ndp_attr, "Absent") == 0)
405 ndp_attr_val = NAN_NDP_ATTR_ABSENT;
406 else
407 ndp_attr_val = NAN_NDP_ATTR_PRESENT;
408 memcpy(cfg_debug.debug_cmd_data, &ndp_attr_val, sizeof(int));
409 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530410 ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Peng Xu57d7ead2018-08-06 11:53:47 -0700411 cfg_debug, size);
412 if (ret != WIFI_SUCCESS) {
413 send_resp(dut, conn, SIGMA_ERROR,
414 "NAN config ndpAttr failed");
415 return 0;
416 }
417 }
418#endif
419
Rakesh Sunki14bff1d2017-03-30 14:47:55 -0700420 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200421 return 0;
422}
423
424
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700425void nan_print_further_availability_chan(struct sigma_dut *dut,
426 u8 num_chans,
427 NanFurtherAvailabilityChannel *fachan)
428{
429 int idx;
430
431 sigma_dut_print(dut, DUT_MSG_INFO,
432 "********Printing FurtherAvailabilityChan Info******");
433 sigma_dut_print(dut, DUT_MSG_INFO, "Numchans:%d", num_chans);
434 for (idx = 0; idx < num_chans; idx++) {
435 sigma_dut_print(dut, DUT_MSG_INFO,
436 "[%d]: NanAvailDuration:%d class_val:%02x channel:%d",
437 idx, fachan->entry_control,
438 fachan->class_val, fachan->channel);
439 sigma_dut_print(dut, DUT_MSG_INFO,
440 "[%d]: mapid:%d Availability bitmap:%08x",
441 idx, fachan->mapid,
442 fachan->avail_interval_bitmap);
443 }
444 sigma_dut_print(dut, DUT_MSG_INFO,
445 "*********************Done**********************");
446}
447
448
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200449int sigma_nan_enable(struct sigma_dut *dut, struct sigma_conn *conn,
450 struct sigma_cmd *cmd)
451{
452 const char *master_pref = get_param(cmd, "MasterPref");
453 const char *rand_fac = get_param(cmd, "RandFactor");
454 const char *hop_count = get_param(cmd, "HopCount");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200455 const char *sdftx_band = get_param(cmd, "SDFTxBand");
456 const char *oper_chan = get_param(cmd, "oper_chn");
457 const char *further_avail_ind = get_param(cmd, "FurtherAvailInd");
458 const char *band = get_param(cmd, "Band");
459 const char *only_5g = get_param(cmd, "5GOnly");
Rakesh Sunki38dd72e2017-03-30 14:47:55 -0700460 const char *nan_availability = get_param(cmd, "NANAvailability");
Peng Xu47d709b2019-06-04 18:14:02 -0700461#ifdef NAN_NEW_CERT_VERSION
Peng Xu8863ec72018-08-06 11:50:37 -0700462 const char *ndpe = get_param(cmd, "NDPE");
463#endif
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200464 struct timespec abstime;
465 NanEnableRequest req;
466
467 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200468 req.cluster_low = 0;
469 req.cluster_high = 0xFFFF;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700470 req.master_pref = 100;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200471
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700472 /* This is a debug hack to beacon in channel 11 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200473 if (oper_chan) {
474 req.config_2dot4g_support = 1;
475 req.support_2dot4g_val = 111;
476 }
477
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200478 if (master_pref) {
479 int master_pref_val = strtoul(master_pref, NULL, 0);
480
481 req.master_pref = master_pref_val;
482 }
483
484 if (rand_fac) {
485 int rand_fac_val = strtoul(rand_fac, NULL, 0);
486
487 req.config_random_factor_force = 1;
488 req.random_factor_force_val = rand_fac_val;
489 }
490
491 if (hop_count) {
492 int hop_count_val = strtoul(hop_count, NULL, 0);
493
494 req.config_hop_count_force = 1;
495 req.hop_count_force_val = hop_count_val;
496 }
497
498 if (sdftx_band) {
499 if (strcasecmp(sdftx_band, "5G") == 0) {
500 req.config_2dot4g_support = 1;
501 req.support_2dot4g_val = 0;
502 }
503 }
504
Peng Xu47d709b2019-06-04 18:14:02 -0700505#ifdef NAN_NEW_CERT_VERSION
Peng Xu8863ec72018-08-06 11:50:37 -0700506 if (ndpe) {
507 if (strcasecmp(ndpe, "Enable") == 0) {
508 dut->ndpe = 1;
509 req.config_ndpe_attr = 1;
510 req.use_ndpe_attr = 1;
511 } else {
512 dut->ndpe = 0;
513 req.config_ndpe_attr = 1;
514 req.use_ndpe_attr = 0;
515 }
516 req.config_disc_mac_addr_randomization = 1;
517 req.disc_mac_addr_rand_interval_sec = 0;
518 }
519#endif
520
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700521 sigma_dut_print(dut, DUT_MSG_INFO,
522 "%s: Setting dual band 2.4 GHz and 5 GHz by default",
523 __func__);
524 /* Enable 2.4 GHz support */
525 req.config_2dot4g_support = 1;
526 req.support_2dot4g_val = 1;
527 req.config_2dot4g_beacons = 1;
528 req.beacon_2dot4g_val = 1;
529 req.config_2dot4g_sdf = 1;
530 req.sdf_2dot4g_val = 1;
531
532 /* Enable 5 GHz support */
533 req.config_support_5g = 1;
534 req.support_5g_val = 1;
535 req.config_5g_beacons = 1;
536 req.beacon_5g_val = 1;
537 req.config_5g_sdf = 1;
538 req.sdf_5g_val = 1;
539
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200540 if (band) {
541 if (strcasecmp(band, "24G") == 0) {
542 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunki47a276a2017-03-30 14:47:55 -0700543 "Band 2.4 GHz selected, disable 5 GHz");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200544 /* Disable 5G support */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700545 req.config_support_5g = 1;
546 req.support_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200547 req.config_5g_beacons = 1;
548 req.beacon_5g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700549 req.config_5g_sdf = 1;
550 req.sdf_5g_val = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200551 }
552 }
553
554 if (further_avail_ind) {
555 sigma_dut_print(dut, DUT_MSG_INFO, "FAM Test Enabled");
556 if (strcasecmp(further_avail_ind, "tx") == 0) {
557 is_fam = 1;
558 nan_further_availability_tx(dut, conn, cmd);
559 return 0;
560 } else if (strcasecmp(further_avail_ind, "rx") == 0) {
561 nan_further_availability_rx(dut, conn, cmd);
562 return 0;
563 }
564 }
565
566 if (only_5g && atoi(only_5g)) {
567 sigma_dut_print(dut, DUT_MSG_INFO, "5GHz only enabled");
568 req.config_2dot4g_support = 1;
569 req.support_2dot4g_val = 1;
570 req.config_2dot4g_beacons = 1;
571 req.beacon_2dot4g_val = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700572 req.config_2dot4g_sdf = 1;
573 req.sdf_2dot4g_val = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200574 }
575
Ajit Vaishyac2ae9612020-02-28 00:09:07 +0530576 if (if_nametoindex(NAN_AWARE_IFACE))
577 run_system_wrapper(dut, "ifconfig %s up", NAN_AWARE_IFACE);
578
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530579 nan_enable_request(0, dut->wifi_hal_iface_handle, &req);
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700580
Rakesh Sunki38dd72e2017-03-30 14:47:55 -0700581 if (nan_availability) {
582 int cmd_len, size;
583 NanDebugParams cfg_debug;
584
585 sigma_dut_print(dut, DUT_MSG_INFO,
586 "%s given string nan_availability: %s",
587 __func__, nan_availability);
588 memset(&cfg_debug, 0, sizeof(NanDebugParams));
589 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_AVAILABILITY;
590 size = NAN_MAX_DEBUG_MESSAGE_DATA_LEN;
591 nan_parse_hex_string(dut, &nan_availability[2],
592 &cfg_debug.debug_cmd_data[0], &size);
593 sigma_dut_print(dut, DUT_MSG_INFO, "%s:hex nan_availability",
594 __func__);
595 nan_hex_dump(dut, &cfg_debug.debug_cmd_data[0], size);
596 cmd_len = size + sizeof(u32);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530597 nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunki38dd72e2017-03-30 14:47:55 -0700598 cfg_debug, cmd_len);
599 }
600
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700601 /* To ensure sta_get_events to get the events
602 * only after joining the NAN cluster. */
603 abstime.tv_sec = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200604 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700605 wait(abstime);
606
607 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200608}
609
610
611int sigma_nan_disable(struct sigma_dut *dut, struct sigma_conn *conn,
612 struct sigma_cmd *cmd)
613{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200614 struct timespec abstime;
615
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530616 nan_disable_request(0, dut->wifi_hal_iface_handle);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200617
618 abstime.tv_sec = 4;
619 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700620 wait(abstime);
621
622 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200623}
624
625
626int sigma_nan_config_enable(struct sigma_dut *dut, struct sigma_conn *conn,
627 struct sigma_cmd *cmd)
628{
629 const char *master_pref = get_param(cmd, "MasterPref");
630 const char *rand_fac = get_param(cmd, "RandFactor");
631 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -0700632 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200633 struct timespec abstime;
634 NanConfigRequest req;
635
636 memset(&req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200637 req.config_rssi_proximity = 1;
638 req.rssi_proximity = 70;
639
640 if (master_pref) {
641 int master_pref_val = strtoul(master_pref, NULL, 0);
642
643 req.config_master_pref = 1;
644 req.master_pref = master_pref_val;
645 }
646
647 if (rand_fac) {
648 int rand_fac_val = strtoul(rand_fac, NULL, 0);
649
650 req.config_random_factor_force = 1;
651 req.random_factor_force_val = rand_fac_val;
652 }
653
654 if (hop_count) {
655 int hop_count_val = strtoul(hop_count, NULL, 0);
656
657 req.config_hop_count_force = 1;
658 req.hop_count_force_val = hop_count_val;
659 }
660
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530661 ret = nan_config_request(0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunki107356c2017-03-30 14:47:55 -0700662 if (ret != WIFI_SUCCESS)
663 send_resp(dut, conn, SIGMA_ERROR, "NAN config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200664
665 abstime.tv_sec = 4;
666 abstime.tv_nsec = 0;
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700667 wait(abstime);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200668
Kantesh Mundaragi116be192016-10-19 17:10:52 -0700669 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200670}
671
672
673static int sigma_nan_subscribe_request(struct sigma_dut *dut,
674 struct sigma_conn *conn,
675 struct sigma_cmd *cmd)
676{
677 const char *subscribe_type = get_param(cmd, "SubscribeType");
678 const char *service_name = get_param(cmd, "ServiceName");
679 const char *disc_range = get_param(cmd, "DiscoveryRange");
680 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
681 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
682 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
683 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
684 const char *include_bit = get_param(cmd, "IncludeBit");
685 const char *mac = get_param(cmd, "MAC");
686 const char *srf_type = get_param(cmd, "SRFType");
Rakesh Sunkiff76d8c2017-06-06 12:29:34 -0700687#if NAN_CERT_VERSION >= 3
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700688 const char *awake_dw_interval = get_param(cmd, "awakeDWint");
Rakesh Sunkiff76d8c2017-06-06 12:29:34 -0700689#endif
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200690 NanSubscribeRequest req;
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700691 NanConfigRequest config_req;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200692 int filter_len_rx = 0, filter_len_tx = 0;
693 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
694 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -0700695 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200696
697 memset(&req, 0, sizeof(NanSubscribeRequest));
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700698 memset(&config_req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200699 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -0700700 req.period = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200701 req.subscribe_type = 1;
702 req.serviceResponseFilter = 1; /* MAC */
703 req.serviceResponseInclude = 0;
704 req.ssiRequiredForMatchIndication = 0;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -0700705 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200706 req.subscribe_count = 0;
707
Rakesh Sunki74f4f992017-08-16 15:21:52 -0700708 if (global_subscribe_service_name_len &&
709 service_name &&
710 strcasecmp((char *) global_subscribe_service_name,
711 service_name) == 0 &&
712 global_subscribe_id) {
713 req.subscribe_id = global_subscribe_id;
714 sigma_dut_print(dut, DUT_MSG_INFO,
715 "%s: updating subscribe_id = %d in subscribe request",
716 __func__, req.subscribe_id);
717 }
718
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200719 if (subscribe_type) {
720 if (strcasecmp(subscribe_type, "Active") == 0) {
721 req.subscribe_type = 1;
722 } else if (strcasecmp(subscribe_type, "Passive") == 0) {
723 req.subscribe_type = 0;
724 } else if (strcasecmp(subscribe_type, "Cancel") == 0) {
725 NanSubscribeCancelRequest req;
726
727 memset(&req, 0, sizeof(NanSubscribeCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -0700728 ret = nan_subscribe_cancel_request(
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530729 0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunki107356c2017-03-30 14:47:55 -0700730 if (ret != WIFI_SUCCESS) {
731 send_resp(dut, conn, SIGMA_ERROR,
732 "NAN subscribe cancel request failed");
733 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200734 return 0;
735 }
736 }
737
738 if (disc_range)
739 req.rssi_threshold_flag = atoi(disc_range);
740
741 if (sdftx_dw)
742 req.subscribe_count = atoi(sdftx_dw);
743
744 /* Check this once again if config can be called here (TBD) */
745 if (discrange_ltd)
746 req.rssi_threshold_flag = atoi(discrange_ltd);
747
748 if (include_bit) {
749 int include_bit_val = atoi(include_bit);
750
751 req.serviceResponseInclude = include_bit_val;
752 sigma_dut_print(dut, DUT_MSG_INFO, "Includebit set %d",
753 req.serviceResponseInclude);
754 }
755
756 if (srf_type) {
757 int srf_type_val = atoi(srf_type);
758
759 if (srf_type_val == 1)
760 req.serviceResponseFilter = 0; /* Bloom */
761 else
762 req.serviceResponseFilter = 1; /* MAC */
763 req.useServiceResponseFilter = 1;
764 sigma_dut_print(dut, DUT_MSG_INFO, "srfFilter %d",
765 req.serviceResponseFilter);
766 }
767
768 if (mac) {
769 sigma_dut_print(dut, DUT_MSG_INFO, "MAC_ADDR List %s", mac);
770 req.num_intf_addr_present = nan_parse_mac_address_list(
771 dut, mac, &req.intf_addr[0][0],
772 NAN_MAX_SUBSCRIBE_MAX_ADDRESS);
773 }
774
775 memset(input_rx, 0, sizeof(input_rx));
776 memset(input_tx, 0, sizeof(input_tx));
777 if (rx_match_filter) {
778 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
779 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
780 filter_len_rx);
781 }
782 if (tx_match_filter) {
783 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
784 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
785 filter_len_tx);
786 }
787
788 if (tx_match_filter) {
789 req.tx_match_filter_len = filter_len_tx;
790 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
791 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
792 }
793 if (rx_match_filter) {
794 req.rx_match_filter_len = filter_len_rx;
795 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
796 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
797 }
798
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700799 if (service_name) {
800 strlcpy((char *) req.service_name, service_name,
801 strlen(service_name) + 1);
802 req.service_name_len = strlen(service_name);
Rakesh Sunki74f4f992017-08-16 15:21:52 -0700803 strlcpy((char *) global_subscribe_service_name, service_name,
804 sizeof(global_subscribe_service_name));
805 global_subscribe_service_name_len =
806 strlen((char *) global_subscribe_service_name);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -0700807 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200808
Rakesh Sunkiff76d8c2017-06-06 12:29:34 -0700809#if NAN_CERT_VERSION >= 3
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700810 if (awake_dw_interval) {
811 int input_dw_interval_val = atoi(awake_dw_interval);
812 int awake_dw_int = 0;
813
814 if (input_dw_interval_val > NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL) {
815 sigma_dut_print(dut, DUT_MSG_INFO,
816 "%s: input active dw interval = %d overwritting dw interval to Max allowed dw interval 16",
817 __func__, input_dw_interval_val);
818 input_dw_interval_val =
819 NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL;
820 }
821 sigma_dut_print(dut, DUT_MSG_INFO,
822 "%s: input active DW interval = %d",
823 __func__, input_dw_interval_val);
824 /*
825 * Indicates the interval for Sync beacons and SDF's in 2.4 GHz
826 * or 5 GHz band. Valid values of DW Interval are: 1, 2, 3, 4,
827 * and 5; 0 is reserved. The SDF includes in OTA when enabled.
828 * The publish/subscribe period values don't override the device
829 * level configurations.
830 * input_dw_interval_val is provided by the user are in the
831 * format 2^n-1 = 1/2/4/8/16. Internal implementation expects n
832 * to be passed to indicate the awake_dw_interval.
833 */
834 if (input_dw_interval_val == 1 ||
835 input_dw_interval_val % 2 == 0) {
836 while (input_dw_interval_val > 0) {
837 input_dw_interval_val >>= 1;
838 awake_dw_int++;
839 }
840 }
841 sigma_dut_print(dut, DUT_MSG_INFO,
842 "%s:converted active DW interval = %d",
843 __func__, awake_dw_int);
844 config_req.config_dw.config_2dot4g_dw_band = 1;
845 config_req.config_dw.dw_2dot4g_interval_val = awake_dw_int;
846 config_req.config_dw.config_5g_dw_band = 1;
847 config_req.config_dw.dw_5g_interval_val = awake_dw_int;
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530848 ret = nan_config_request(0, dut->wifi_hal_iface_handle,
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700849 &config_req);
850 if (ret != WIFI_SUCCESS) {
851 sigma_dut_print(dut, DUT_MSG_ERROR,
852 "%s:NAN config request failed",
853 __func__);
854 return -2;
855 }
856 }
Rakesh Sunkiff76d8c2017-06-06 12:29:34 -0700857#endif
Rakesh Sunkie6f66832017-05-16 15:22:48 -0700858
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530859 ret = nan_subscribe_request(0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunki107356c2017-03-30 14:47:55 -0700860 if (ret != WIFI_SUCCESS) {
861 send_resp(dut, conn, SIGMA_ERROR,
862 "NAN subscribe request failed");
863 }
864
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200865 return 0;
866}
867
868
Rakesh Sunkid7344c02017-03-30 14:47:55 -0700869static int sigma_ndp_configure_band(struct sigma_dut *dut,
870 struct sigma_conn *conn,
871 struct sigma_cmd *cmd,
872 NdpSupportedBand band_config_val)
873{
874 wifi_error ret;
875 NanDebugParams cfg_debug;
876 int size;
877
878 memset(&cfg_debug, 0, sizeof(NanDebugParams));
879 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SUPPORTED_BANDS;
880 memcpy(cfg_debug.debug_cmd_data, &band_config_val, sizeof(int));
881 sigma_dut_print(dut, DUT_MSG_INFO, "%s:setting debug cmd=0x%x",
882 __func__, cfg_debug.cmd);
883 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530884 ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, cfg_debug,
Rakesh Sunkid7344c02017-03-30 14:47:55 -0700885 size);
886 if (ret != WIFI_SUCCESS)
887 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
888
889 return 0;
890}
891
892
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700893static int sigma_nan_data_request(struct sigma_dut *dut,
894 struct sigma_conn *conn,
895 struct sigma_cmd *cmd)
896{
897 const char *ndp_security = get_param(cmd, "DataPathSecurity");
898 const char *ndp_resp_mac = get_param(cmd, "RespNanMac");
899 const char *include_immutable = get_param(cmd, "includeimmutable");
900 const char *avoid_channel = get_param(cmd, "avoidchannel");
901 const char *invalid_nan_schedule = get_param(cmd, "InvalidNANSchedule");
902 const char *map_order = get_param(cmd, "maporder");
Rakesh Sunki8a4845d2017-05-16 15:27:13 -0700903#if NAN_CERT_VERSION >= 3
904 const char *qos_config = get_param(cmd, "QoS");
905#endif
Peng Xu47d709b2019-06-04 18:14:02 -0700906#ifdef NAN_NEW_CERT_VERSION
Peng Xub0c682c2018-06-27 14:36:07 -0700907 const char *ndpe_enable = get_param(cmd, "Ndpe");
908 const char *ndpe_attr = get_param(cmd, "ndpeAttr");
Peng Xu2486bbe2018-07-19 14:37:22 -0700909 const char *ndp_attr = get_param(cmd, "ndpAttr");
Peng Xu7b1b9e12018-07-19 16:24:55 -0700910 const char *tlv_list = get_param(cmd, "TLVList");
Peng Xub0c682c2018-06-27 14:36:07 -0700911#endif
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700912 wifi_error ret;
913 NanDataPathInitiatorRequest init_req;
914 NanDebugParams cfg_debug;
915 int size;
916
917 memset(&init_req, 0, sizeof(NanDataPathInitiatorRequest));
918
919 if (ndp_security) {
920 if (strcasecmp(ndp_security, "open") == 0)
921 init_req.ndp_cfg.security_cfg =
922 NAN_DP_CONFIG_NO_SECURITY;
923 else if (strcasecmp(ndp_security, "secure") == 0)
924 init_req.ndp_cfg.security_cfg = NAN_DP_CONFIG_SECURITY;
925 }
926
927 if (include_immutable) {
928 int include_immutable_val = 0;
929
930 memset(&cfg_debug, 0, sizeof(NanDebugParams));
931 cfg_debug.cmd = NAN_TEST_MODE_CMD_NDP_INCLUDE_IMMUTABLE;
932 include_immutable_val = atoi(include_immutable);
933 memcpy(cfg_debug.debug_cmd_data, &include_immutable_val,
934 sizeof(int));
935 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530936 nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700937 cfg_debug, size);
938 }
939
940 if (avoid_channel) {
941 int avoid_channel_freq = 0;
942
943 memset(&cfg_debug, 0, sizeof(NanDebugParams));
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +0200944 avoid_channel_freq = channel_to_freq(dut, atoi(avoid_channel));
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700945 cfg_debug.cmd = NAN_TEST_MODE_CMD_NDP_AVOID_CHANNEL;
946 memcpy(cfg_debug.debug_cmd_data, &avoid_channel_freq,
947 sizeof(int));
948 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530949 nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700950 cfg_debug, size);
951 }
952
953 if (invalid_nan_schedule) {
954 int invalid_nan_schedule_type = 0;
955
956 memset(&cfg_debug, 0, sizeof(NanDebugParams));
957 invalid_nan_schedule_type = atoi(invalid_nan_schedule);
958 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_TYPE;
959 memcpy(cfg_debug.debug_cmd_data,
960 &invalid_nan_schedule_type, sizeof(int));
961 size = sizeof(u32) + sizeof(int);
962 sigma_dut_print(dut, DUT_MSG_INFO,
963 "%s: invalid schedule type: cmd type = %d and command data = %d",
964 __func__, cfg_debug.cmd,
965 invalid_nan_schedule_type);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530966 nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700967 cfg_debug, size);
968 }
969
970 if (map_order) {
971 int map_order_val = 0;
972
973 memset(&cfg_debug, 0, sizeof(NanDebugParams));
974 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_AVAILABILITY_MAP_ORDER;
975 map_order_val = atoi(map_order);
976 memcpy(cfg_debug.debug_cmd_data, &map_order_val, sizeof(int));
977 size = sizeof(u32) + sizeof(int);
978 sigma_dut_print(dut, DUT_MSG_INFO,
979 "%s: map order: cmd type = %d and command data = %d",
980 __func__,
Rakesh Sunki9eaa6772017-04-04 11:37:03 -0700981 cfg_debug.cmd, map_order_val);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530982 nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunki14cfcd22017-03-30 14:47:55 -0700983 cfg_debug, size);
984 }
985
Rakesh Sunki8a4845d2017-05-16 15:27:13 -0700986#if NAN_CERT_VERSION >= 3
987 if (qos_config) {
988 u32 qos_config_val = 0;
989
990 memset(&cfg_debug, 0, sizeof(NanDebugParams));
991 cfg_debug.cmd = NAN_TEST_MODE_CMD_CONFIG_QOS;
992 qos_config_val = atoi(qos_config);
993 memcpy(cfg_debug.debug_cmd_data, &qos_config_val, sizeof(u32));
994 size = sizeof(u32) + sizeof(u32);
995 sigma_dut_print(dut, DUT_MSG_INFO,
996 "%s: qos config: cmd type = %d and command data = %d",
997 __func__, cfg_debug.cmd, qos_config_val);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +0530998 nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunki8a4845d2017-05-16 15:27:13 -0700999 cfg_debug, size);
1000 }
1001#endif
1002
Peng Xu47d709b2019-06-04 18:14:02 -07001003#ifdef NAN_NEW_CERT_VERSION
Peng Xub0c682c2018-06-27 14:36:07 -07001004 if (ndpe_enable &&
1005 strcasecmp(ndpe_enable, "Enable") == 0)
1006 dut->ndpe = 1;
1007
Peng Xu2486bbe2018-07-19 14:37:22 -07001008 if (dut->ndpe && ndp_attr) {
1009 NanDebugParams cfg_debug;
1010 int ndp_attr_val;
1011
1012 memset(&cfg_debug, 0, sizeof(NanDebugParams));
1013 cfg_debug.cmd = NAN_TEST_MODE_CMD_ENABLE_NDP;
1014 if (strcasecmp(ndp_attr, "Absent") == 0)
1015 ndp_attr_val = NAN_NDP_ATTR_ABSENT;
1016 else
1017 ndp_attr_val = NAN_NDP_ATTR_PRESENT;
1018 memcpy(cfg_debug.debug_cmd_data, &ndp_attr_val, sizeof(int));
1019 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301020 ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Peng Xu2486bbe2018-07-19 14:37:22 -07001021 cfg_debug, size);
1022 if (ret != WIFI_SUCCESS) {
1023 send_resp(dut, conn, SIGMA_ERROR,
1024 "NAN config ndpAttr failed");
1025 return 0;
1026 }
1027 }
1028
Peng Xub0c682c2018-06-27 14:36:07 -07001029 if (dut->ndpe && ndpe_attr) {
1030 NanDebugParams cfg_debug;
1031 int ndpe_attr_val;
1032
1033 memset(&cfg_debug, 0, sizeof(NanDebugParams));
1034 cfg_debug.cmd = NAN_TEST_MODE_CMD_DISABLE_NDPE;
1035 if (strcasecmp(ndpe_attr, "Absent") == 0)
1036 ndpe_attr_val = NAN_NDPE_ATTR_ABSENT;
1037 else
1038 ndpe_attr_val = NAN_NDPE_ATTR_PRESENT;
1039 memcpy(cfg_debug.debug_cmd_data, &ndpe_attr_val, sizeof(int));
1040 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301041 ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Peng Xub0c682c2018-06-27 14:36:07 -07001042 cfg_debug, size);
1043 if (ret != WIFI_SUCCESS) {
1044 send_resp(dut, conn, SIGMA_ERROR,
1045 "NAN config ndpeAttr failed");
1046 return 0;
1047 }
1048 }
1049#endif
1050
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001051 /*
1052 * Setting this flag, so that interface for ping6 command
1053 * is set appropriately in traffic_send_ping().
1054 */
1055 dut->ndp_enable = 1;
1056
1057 /*
1058 * Intended sleep after NAN data interface create
1059 * before the NAN data request
1060 */
1061 sleep(4);
1062
1063 init_req.requestor_instance_id = global_match_handle;
1064 strlcpy((char *) init_req.ndp_iface, "nan0",
1065 sizeof(init_req.ndp_iface));
1066
1067 if (ndp_resp_mac) {
1068 nan_parse_mac_address(dut, ndp_resp_mac,
1069 init_req.peer_disc_mac_addr);
1070 sigma_dut_print(
1071 dut, DUT_MSG_INFO, "PEER MAC ADDR: " MAC_ADDR_STR,
1072 MAC_ADDR_ARRAY(init_req.peer_disc_mac_addr));
1073 } else {
1074 memcpy(init_req.peer_disc_mac_addr, global_peer_mac_addr,
1075 sizeof(init_req.peer_disc_mac_addr));
1076 }
1077
1078 /* Not requesting the channel and letting FW decide */
1079 if (dut->sta_channel == 0) {
1080 init_req.channel_request_type = NAN_DP_CHANNEL_NOT_REQUESTED;
1081 init_req.channel = 0;
1082 } else {
1083 init_req.channel_request_type = NAN_DP_FORCE_CHANNEL_SETUP;
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02001084 init_req.channel = channel_to_freq(dut, dut->sta_channel);
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001085 }
1086 sigma_dut_print(dut, DUT_MSG_INFO,
1087 "%s: Initiator Request: Channel = %d Channel Request Type = %d",
1088 __func__, init_req.channel,
1089 init_req.channel_request_type);
1090
1091 if (dut->nan_pmk_len == NAN_PMK_INFO_LEN) {
Rakesh Sunki395b0152017-05-16 15:30:36 -07001092 init_req.key_info.key_type = NAN_SECURITY_KEY_INPUT_PMK;
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001093 memcpy(&init_req.key_info.body.pmk_info.pmk[0],
1094 &dut->nan_pmk[0], NAN_PMK_INFO_LEN);
1095 init_req.key_info.body.pmk_info.pmk_len = NAN_PMK_INFO_LEN;
1096 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
1097 __func__,
1098 init_req.key_info.body.pmk_info.pmk_len);
1099 }
1100
Peng Xu47d709b2019-06-04 18:14:02 -07001101#ifdef NAN_NEW_CERT_VERSION
Peng Xub0c682c2018-06-27 14:36:07 -07001102 if (dut->ndpe) {
Peng Xu47d709b2019-06-04 18:14:02 -07001103 if (dut->device_type == STA_testbed && !tlv_list) {
1104 init_req.app_info.ndp_app_info_len = 0;
1105 memset(init_req.app_info.ndp_app_info, 0,
1106 sizeof(init_req.app_info.ndp_app_info));
1107 } else {
1108 size_t addr_len = 0;
1109 u8 nan_ipv6_intf_addr[IPV6_ADDR_LEN];
1110 unsigned char nan_mac_addr[ETH_ALEN];
Peng Xub0c682c2018-06-27 14:36:07 -07001111
Peng Xu47d709b2019-06-04 18:14:02 -07001112 if (get_hwaddr("nan0", nan_mac_addr) < 0) {
1113 sigma_dut_print(dut, DUT_MSG_ERROR,
1114 "%s:get_hwaddr nan0 failed",
1115 __func__);
1116 return -1;
1117 }
1118
1119 /* store IPv6 into app_info as TLV */
1120 addr_len = convert_mac_addr_to_ipv6_linklocal(
1121 nan_mac_addr, &nan_ipv6_intf_addr[0]);
1122 init_req.app_info.ndp_app_info_len =
1123 nan_build_ipv6_link_local_tlv(
1124 init_req.app_info.ndp_app_info,
1125 &nan_ipv6_intf_addr[0]);
1126 sigma_dut_print(dut, DUT_MSG_DEBUG,
1127 "%s: Initiator Request: IPv6:",
1128 __func__);
1129 nan_hex_dump(dut, &nan_ipv6_intf_addr[0],
1130 IPV6_ADDR_LEN);
1131 }
Peng Xub0c682c2018-06-27 14:36:07 -07001132 }
1133#endif
1134
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301135 ret = nan_data_request_initiator(0, dut->wifi_hal_iface_handle,
1136 &init_req);
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07001137 if (ret != WIFI_SUCCESS) {
1138 send_resp(dut, conn, SIGMA_ERROR,
1139 "Unable to initiate nan data request");
1140 return 0;
1141 }
1142
1143 return 0;
1144}
1145
1146
Rakesh Sunkia5cc2842017-03-30 14:47:55 -07001147static int sigma_nan_data_response(struct sigma_dut *dut,
1148 struct sigma_conn *conn,
1149 struct sigma_cmd *cmd)
1150{
1151 const char *ndl_response = get_param(cmd, "NDLresponse");
1152 const char *m4_response_type = get_param(cmd, "M4ResponseType");
Peng Xu47d709b2019-06-04 18:14:02 -07001153#ifdef NAN_NEW_CERT_VERSION
Peng Xub0c682c2018-06-27 14:36:07 -07001154 const char *ndpe_attr = get_param(cmd, "ndpeAttr");
Peng Xu2486bbe2018-07-19 14:37:22 -07001155 const char *ndp_attr = get_param(cmd, "ndpAttr");
Peng Xub0c682c2018-06-27 14:36:07 -07001156#endif
Rakesh Sunkia5cc2842017-03-30 14:47:55 -07001157 wifi_error ret;
1158 NanDebugParams cfg_debug;
1159 int size;
1160
1161 if (ndl_response) {
1162 int auto_responder_mode_val = 0;
1163
1164 sigma_dut_print(dut, DUT_MSG_INFO,
1165 "%s: ndl_response = (%s) is passed",
1166 __func__, ndl_response);
1167 memset(&cfg_debug, 0, sizeof(NanDebugParams));
1168 cfg_debug.cmd = NAN_TEST_MODE_CMD_AUTO_RESPONDER_MODE;
1169 if (strcasecmp(ndl_response, "Auto") == 0) {
1170 auto_responder_mode_val = NAN_DATA_RESPONDER_MODE_AUTO;
1171 } else if (strcasecmp(ndl_response, "Reject") == 0) {
1172 auto_responder_mode_val =
1173 NAN_DATA_RESPONDER_MODE_REJECT;
1174 } else if (strcasecmp(ndl_response, "Accept") == 0) {
1175 auto_responder_mode_val =
1176 NAN_DATA_RESPONDER_MODE_ACCEPT;
1177 } else if (strcasecmp(ndl_response, "Counter") == 0) {
1178 auto_responder_mode_val =
1179 NAN_DATA_RESPONDER_MODE_COUNTER;
1180 } else {
1181 sigma_dut_print(dut, DUT_MSG_ERROR,
1182 "%s: Invalid ndl_response",
1183 __func__);
1184 return 0;
1185 }
1186 memcpy(cfg_debug.debug_cmd_data, &auto_responder_mode_val,
1187 sizeof(int));
1188 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301189 ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunkia5cc2842017-03-30 14:47:55 -07001190 cfg_debug, size);
1191 if (ret != WIFI_SUCCESS) {
1192 send_resp(dut, conn, SIGMA_ERROR,
1193 "Nan config request failed");
1194 }
1195 }
1196
1197 if (m4_response_type) {
1198 int m4_response_type_val = 0;
1199
1200 sigma_dut_print(dut, DUT_MSG_INFO,
1201 "%s: m4_response_type = (%s) is passed",
1202 __func__, m4_response_type);
1203 memset(&cfg_debug, 0, sizeof(NanDebugParams));
1204 cfg_debug.cmd = NAN_TEST_MODE_CMD_M4_RESPONSE_TYPE;
1205 if (strcasecmp(m4_response_type, "Accept") == 0)
1206 m4_response_type_val = NAN_DATA_PATH_M4_RESPONSE_ACCEPT;
1207 else if (strcasecmp(m4_response_type, "Reject") == 0)
1208 m4_response_type_val = NAN_DATA_PATH_M4_RESPONSE_REJECT;
1209 else if (strcasecmp(m4_response_type, "BadMic") == 0)
1210 m4_response_type_val = NAN_DATA_PATH_M4_RESPONSE_BADMIC;
1211
1212 memcpy(cfg_debug.debug_cmd_data, &m4_response_type_val,
1213 sizeof(int));
1214 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301215 ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunkia5cc2842017-03-30 14:47:55 -07001216 cfg_debug, size);
1217 if (ret != WIFI_SUCCESS) {
1218 send_resp(dut, conn, SIGMA_ERROR,
1219 "Nan config request failed");
1220 }
1221 }
1222
Peng Xu47d709b2019-06-04 18:14:02 -07001223#ifdef NAN_NEW_CERT_VERSION
Peng Xu2486bbe2018-07-19 14:37:22 -07001224 if (dut->ndpe && ndp_attr) {
1225 NanDebugParams cfg_debug;
1226 int ndp_attr_val;
1227
1228 memset(&cfg_debug, 0, sizeof(NanDebugParams));
1229 cfg_debug.cmd = NAN_TEST_MODE_CMD_ENABLE_NDP;
1230 if (strcasecmp(ndp_attr, "Absent") == 0)
1231 ndp_attr_val = NAN_NDP_ATTR_ABSENT;
1232 else
1233 ndp_attr_val = NAN_NDP_ATTR_PRESENT;
1234 memcpy(cfg_debug.debug_cmd_data, &ndp_attr_val, sizeof(int));
1235 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301236 ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Peng Xu2486bbe2018-07-19 14:37:22 -07001237 cfg_debug, size);
1238 if (ret != WIFI_SUCCESS) {
1239 send_resp(dut, conn, SIGMA_ERROR,
1240 "NAN config ndpAttr failed");
1241 return 0;
1242 }
1243 }
1244
Peng Xub0c682c2018-06-27 14:36:07 -07001245 if (ndpe_attr && dut->ndpe) {
1246 int ndpe_attr_val;
1247
1248 memset(&cfg_debug, 0, sizeof(NanDebugParams));
1249 cfg_debug.cmd = NAN_TEST_MODE_CMD_DISABLE_NDPE;
1250 if (strcasecmp(ndpe_attr, "Absent") == 0)
1251 ndpe_attr_val = NAN_NDPE_ATTR_ABSENT;
1252 else
1253 ndpe_attr_val = NAN_NDPE_ATTR_PRESENT;
1254 memcpy(cfg_debug.debug_cmd_data, &ndpe_attr_val, sizeof(int));
1255 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301256 ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Peng Xub0c682c2018-06-27 14:36:07 -07001257 cfg_debug, size);
1258 if (ret != WIFI_SUCCESS) {
1259 send_resp(dut, conn, SIGMA_ERROR,
1260 "NAN config ndpeAttr failed");
1261 return 0;
1262 }
1263 }
1264#endif
1265
Rakesh Sunkia5cc2842017-03-30 14:47:55 -07001266 return 0;
1267}
1268
1269
Rakesh Sunki8a630b82017-03-30 14:47:55 -07001270static int sigma_nan_data_end(struct sigma_dut *dut, struct sigma_cmd *cmd)
1271{
1272 const char *nmf_security_config = get_param(cmd, "Security");
1273 NanDataPathEndRequest req;
1274 NanDebugParams cfg_debug;
1275 int size;
1276
1277 memset(&req, 0, sizeof(NanDataPathEndRequest));
1278 memset(&cfg_debug, 0, sizeof(NanDebugParams));
1279 if (nmf_security_config) {
1280 int nmf_security_config_val = 0;
1281
1282 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_NMF_CLEAR_CONFIG;
1283 if (strcasecmp(nmf_security_config, "open") == 0)
1284 nmf_security_config_val = NAN_NMF_CLEAR_ENABLE;
1285 else if (strcasecmp(nmf_security_config, "secure") == 0)
1286 nmf_security_config_val = NAN_NMF_CLEAR_DISABLE;
1287 memcpy(cfg_debug.debug_cmd_data,
1288 &nmf_security_config_val, sizeof(int));
1289 size = sizeof(u32) + sizeof(int);
1290 sigma_dut_print(dut, DUT_MSG_INFO,
1291 "%s: nmf_security_config_val -- cmd type = %d and command data = %d",
1292 __func__, cfg_debug.cmd,
1293 nmf_security_config_val);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301294 nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunki8a630b82017-03-30 14:47:55 -07001295 cfg_debug, size);
1296 }
1297
1298 req.num_ndp_instances = 1;
1299 req.ndp_instance_id[0] = global_ndp_instance_id;
1300
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301301 nan_data_end(0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunki8a630b82017-03-30 14:47:55 -07001302 return 0;
1303}
1304
1305
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -07001306static int sigma_nan_range_request(struct sigma_dut *dut,
1307 struct sigma_cmd *cmd)
1308{
1309 const char *dest_mac = get_param(cmd, "destmac");
1310 NanSubscribeRequest req;
1311
1312 memset(&req, 0, sizeof(NanSubscribeRequest));
1313 req.period = 1;
Rakesh Sunki3834be52017-08-16 15:27:36 -07001314 req.subscribe_type = NAN_SUBSCRIBE_TYPE_PASSIVE;
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -07001315 req.serviceResponseFilter = NAN_SRF_ATTR_BLOOM_FILTER;
1316 req.serviceResponseInclude = NAN_SRF_INCLUDE_RESPOND;
1317 req.ssiRequiredForMatchIndication = NAN_SSI_NOT_REQUIRED_IN_MATCH_IND;
1318 req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS;
1319 req.subscribe_count = 0;
1320 strlcpy((char *) req.service_name, DEFAULT_SVC,
1321 NAN_MAX_SERVICE_NAME_LEN);
1322 req.service_name_len = strlen((char *) req.service_name);
1323
1324 req.subscribe_id = global_subscribe_id;
1325 req.sdea_params.ranging_state = 1;
1326 req.sdea_params.range_report = NAN_ENABLE_RANGE_REPORT;
1327 req.range_response_cfg.requestor_instance_id = global_match_handle;
1328 req.range_response_cfg.ranging_response = NAN_RANGE_REQUEST_ACCEPT;
1329 req.ranging_cfg.config_ranging_indications =
1330 NAN_RANGING_INDICATE_CONTINUOUS_MASK;
1331 if (dest_mac) {
1332 nan_parse_mac_address(dut, dest_mac,
1333 req.range_response_cfg.peer_addr);
1334 sigma_dut_print(
1335 dut, DUT_MSG_INFO, "peer mac addr: " MAC_ADDR_STR,
1336 MAC_ADDR_ARRAY(req.range_response_cfg.peer_addr));
1337 }
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301338 nan_subscribe_request(0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -07001339
1340 return 0;
1341}
1342
1343
1344static int sigma_nan_cancel_range(struct sigma_dut *dut,
1345 struct sigma_cmd *cmd)
1346{
1347 const char *dest_mac = get_param(cmd, "destmac");
1348 NanPublishRequest req;
1349
1350 memset(&req, 0, sizeof(NanPublishRequest));
1351 req.ttl = 0;
1352 req.period = 1;
1353 req.publish_match_indicator = 1;
1354 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
1355 req.tx_type = NAN_TX_TYPE_BROADCAST;
1356 req.publish_count = 0;
1357 strlcpy((char *) req.service_name, DEFAULT_SVC,
1358 NAN_MAX_SERVICE_NAME_LEN);
1359 req.service_name_len = strlen((char *) req.service_name);
1360 req.publish_id = global_publish_id;
1361 req.range_response_cfg.ranging_response = NAN_RANGE_REQUEST_CANCEL;
1362 if (dest_mac) {
1363 nan_parse_mac_address(dut, dest_mac,
1364 req.range_response_cfg.peer_addr);
1365 sigma_dut_print(
1366 dut, DUT_MSG_INFO, "peer mac addr: " MAC_ADDR_STR,
1367 MAC_ADDR_ARRAY(req.range_response_cfg.peer_addr));
1368 }
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301369 nan_publish_request(0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -07001370
1371 return 0;
1372}
1373
1374
Rakesh Sunkib2b65162017-03-30 14:47:55 -07001375static int sigma_nan_schedule_update(struct sigma_dut *dut,
1376 struct sigma_cmd *cmd)
1377{
1378 const char *schedule_update_type = get_param(cmd, "type");
1379 const char *channel_availability = get_param(cmd,
1380 "ChannelAvailability");
1381 const char *responder_nmi_mac = get_param(cmd, "ResponderNMI");
1382 NanDebugParams cfg_debug;
1383 int size = 0;
1384
1385 memset(&cfg_debug, 0, sizeof(NanDebugParams));
1386
1387 if (!schedule_update_type)
1388 return 0;
1389
1390 if (strcasecmp(schedule_update_type, "ULWnotify") == 0) {
1391 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_ULW_NOTIFY;
1392 size = sizeof(u32);
1393 sigma_dut_print(dut, DUT_MSG_INFO,
1394 "%s: Schedule Update cmd type = %d", __func__,
1395 cfg_debug.cmd);
1396 if (channel_availability) {
1397 int channel_availability_val;
1398
1399 channel_availability_val = atoi(channel_availability);
1400 size += sizeof(int);
1401 memcpy(cfg_debug.debug_cmd_data,
1402 &channel_availability_val, sizeof(int));
1403 sigma_dut_print(dut, DUT_MSG_INFO,
1404 "%s: Schedule Update cmd data = %d size = %d",
1405 __func__, channel_availability_val,
1406 size);
1407 }
1408 } else if (strcasecmp(schedule_update_type, "NDLnegotiate") == 0) {
1409 cfg_debug.cmd =
1410 NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NEGOTIATE;
1411 size = sizeof(u32);
1412 sigma_dut_print(dut, DUT_MSG_INFO,
1413 "%s: Schedule Update cmd type = %d", __func__,
1414 cfg_debug.cmd);
1415 if (responder_nmi_mac) {
1416 u8 responder_nmi_mac_addr[NAN_MAC_ADDR_LEN];
1417
1418 nan_parse_mac_address(dut, responder_nmi_mac,
1419 responder_nmi_mac_addr);
1420 size += NAN_MAC_ADDR_LEN;
1421 memcpy(cfg_debug.debug_cmd_data, responder_nmi_mac_addr,
1422 NAN_MAC_ADDR_LEN);
1423 sigma_dut_print(dut, DUT_MSG_INFO,
1424 "%s: RESPONDER NMI MAC: "MAC_ADDR_STR,
1425 __func__,
1426 MAC_ADDR_ARRAY(responder_nmi_mac_addr));
1427 sigma_dut_print(dut, DUT_MSG_INFO,
1428 "%s: Schedule Update: cmd size = %d",
1429 __func__, size);
1430 }
1431 } else if (strcasecmp(schedule_update_type, "NDLnotify") == 0) {
1432 cfg_debug.cmd = NAN_TEST_MODE_CMD_NAN_SCHED_UPDATE_NDL_NOTIFY;
1433 size = sizeof(u32);
1434 sigma_dut_print(dut, DUT_MSG_INFO,
1435 "%s: Schedule Update cmd type = %d", __func__,
1436 cfg_debug.cmd);
1437 }
1438
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301439 nan_debug_command_config(0, dut->wifi_hal_iface_handle, cfg_debug,
1440 size);
Rakesh Sunkib2b65162017-03-30 14:47:55 -07001441
1442 return 0;
1443}
1444
1445
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301446int config_post_disc_attr(struct sigma_dut *dut)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001447{
Rakesh Sunki107356c2017-03-30 14:47:55 -07001448 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001449 NanConfigRequest configReq;
1450
1451 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001452
1453 /* Configure Post disc attr */
1454 /* Make these defines and use correct enum */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001455 configReq.num_config_discovery_attr = 1;
1456 configReq.discovery_attr_val[0].type = 4; /* Further Nan discovery */
1457 configReq.discovery_attr_val[0].role = 0;
1458 configReq.discovery_attr_val[0].transmit_freq = 1;
1459 configReq.discovery_attr_val[0].duration = 0;
1460 configReq.discovery_attr_val[0].avail_interval_bitmap = 0x00000008;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001461
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301462 ret = nan_config_request(0, dut->wifi_hal_iface_handle, &configReq);
Rakesh Sunki107356c2017-03-30 14:47:55 -07001463 if (ret != WIFI_SUCCESS) {
1464 sigma_dut_print(global_dut, DUT_MSG_INFO,
1465 "NAN config request failed while configuring post discovery attribute");
1466 }
1467
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001468 return 0;
1469}
1470
1471
1472int sigma_nan_publish_request(struct sigma_dut *dut, struct sigma_conn *conn,
1473 struct sigma_cmd *cmd)
1474{
1475 const char *publish_type = get_param(cmd, "PublishType");
1476 const char *service_name = get_param(cmd, "ServiceName");
1477 const char *disc_range = get_param(cmd, "DiscoveryRange");
1478 const char *rx_match_filter = get_param(cmd, "rxMatchFilter");
1479 const char *tx_match_filter = get_param(cmd, "txMatchFilter");
1480 const char *sdftx_dw = get_param(cmd, "SDFTxDW");
1481 const char *discrange_ltd = get_param(cmd, "DiscRangeLtd");
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001482 const char *ndp_enable = get_param(cmd, "DataPathFlag");
1483 const char *ndp_type = get_param(cmd, "DataPathType");
1484 const char *data_path_security = get_param(cmd, "datapathsecurity");
Rakesh Sunki48060402017-03-30 14:47:55 -07001485 const char *range_required = get_param(cmd, "rangerequired");
Rakesh Sunki8a4845d2017-05-16 15:27:13 -07001486#if NAN_CERT_VERSION >= 3
Rakesh Sunkiff76d8c2017-06-06 12:29:34 -07001487 const char *awake_dw_interval = get_param(cmd, "awakeDWint");
Rakesh Sunki8a4845d2017-05-16 15:27:13 -07001488 const char *qos_config = get_param(cmd, "QoS");
1489#endif
Peng Xu8863ec72018-08-06 11:50:37 -07001490 const char *ndpe = get_param(cmd, "NDPE");
1491 const char *trans_proto = get_param(cmd, "TransProtoType");
Peng Xu47d709b2019-06-04 18:14:02 -07001492#ifdef NAN_NEW_CERT_VERSION
Peng Xu2486bbe2018-07-19 14:37:22 -07001493 const char *ndp_attr = get_param(cmd, "ndpAttr");
1494#endif
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001495 NanPublishRequest req;
Rakesh Sunkie6f66832017-05-16 15:22:48 -07001496 NanConfigRequest config_req;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001497 int filter_len_rx = 0, filter_len_tx = 0;
1498 u8 input_rx[NAN_MAX_MATCH_FILTER_LEN];
1499 u8 input_tx[NAN_MAX_MATCH_FILTER_LEN];
Rakesh Sunki107356c2017-03-30 14:47:55 -07001500 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001501
1502 memset(&req, 0, sizeof(NanPublishRequest));
Rakesh Sunkie6f66832017-05-16 15:22:48 -07001503 memset(&config_req, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001504 req.ttl = 0;
Rakesh Sunki4625de72017-03-30 14:47:55 -07001505 req.period = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001506 req.publish_match_indicator = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001507 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
1508 req.tx_type = NAN_TX_TYPE_BROADCAST;
1509 req.publish_count = 0;
Rakesh Sunki0a0eea82017-03-30 14:47:55 -07001510 req.service_responder_policy = NAN_SERVICE_ACCEPT_POLICY_ALL;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001511
Rakesh Sunki42363682017-05-16 15:00:42 -07001512 if (global_publish_service_name_len &&
1513 service_name &&
1514 strcasecmp((char *) global_publish_service_name,
1515 service_name) == 0 &&
1516 global_publish_id) {
1517 req.publish_id = global_publish_id;
1518 sigma_dut_print(dut, DUT_MSG_INFO,
1519 "%s: updating publish_id = %d in publish request",
1520 __func__, req.publish_id);
1521 }
1522
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001523 if (service_name) {
1524 strlcpy((char *) req.service_name, service_name,
Rakesh Sunki42363682017-05-16 15:00:42 -07001525 sizeof(req.service_name));
1526 req.service_name_len = strlen((char *) req.service_name);
1527 strlcpy((char *) global_publish_service_name, service_name,
1528 sizeof(global_publish_service_name));
1529 global_publish_service_name_len =
1530 strlen((char *) global_publish_service_name);
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001531 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001532
1533 if (publish_type) {
1534 if (strcasecmp(publish_type, "Solicited") == 0) {
1535 req.publish_type = NAN_PUBLISH_TYPE_SOLICITED;
Rakesh Sunki62644ab2017-03-30 14:47:55 -07001536 } else if (strcasecmp(publish_type, "Unsolicited") == 0) {
1537 req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001538 } else if (strcasecmp(publish_type, "Cancel") == 0) {
1539 NanPublishCancelRequest req;
1540
1541 memset(&req, 0, sizeof(NanPublishCancelRequest));
Rakesh Sunki107356c2017-03-30 14:47:55 -07001542 ret = nan_publish_cancel_request(
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301543 0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunki107356c2017-03-30 14:47:55 -07001544 if (ret != WIFI_SUCCESS) {
1545 send_resp(dut, conn, SIGMA_ERROR,
1546 "Unable to cancel nan publish request");
1547 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001548 return 0;
1549 }
1550 }
1551
1552 if (disc_range)
1553 req.rssi_threshold_flag = atoi(disc_range);
1554
1555 if (sdftx_dw)
1556 req.publish_count = atoi(sdftx_dw);
1557
1558 if (discrange_ltd)
1559 req.rssi_threshold_flag = atoi(discrange_ltd);
1560
1561 memset(input_rx, 0, sizeof(input_rx));
1562 memset(input_tx, 0, sizeof(input_tx));
1563 if (rx_match_filter) {
1564 nan_parse_token(rx_match_filter, input_rx, &filter_len_rx);
1565 sigma_dut_print(dut, DUT_MSG_INFO, "RxFilterLen %d",
1566 filter_len_rx);
1567 }
1568 if (tx_match_filter) {
1569 nan_parse_token(tx_match_filter, input_tx, &filter_len_tx);
1570 sigma_dut_print(dut, DUT_MSG_INFO, "TxFilterLen %d",
1571 filter_len_tx);
1572 }
1573
1574 if (is_fam == 1) {
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301575 config_post_disc_attr(dut);
Rakesh Sunkif680e0f2017-03-30 14:47:55 -07001576 /*
1577 * 8-bit bitmap which allows the Host to associate this publish
1578 * with a particular Post-NAN Connectivity attribute which has
1579 * been sent down in a NanConfigureRequest/NanEnableRequest
1580 * message. If the DE fails to find a configured Post-NAN
1581 * connectivity attributes referenced by the bitmap, the DE will
1582 * return an error code to the Host. If the Publish is
1583 * configured to use a Post-NAN Connectivity attribute and the
1584 * Host does not refresh the Post-NAN Connectivity attribute the
1585 * Publish will be canceled and the Host will be sent a
1586 * PublishTerminatedIndication message.
1587 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001588 req.connmap = 0x10;
1589 }
1590
1591 if (tx_match_filter) {
1592 req.tx_match_filter_len = filter_len_tx;
1593 memcpy(req.tx_match_filter, input_tx, filter_len_tx);
1594 nan_hex_dump(dut, req.tx_match_filter, filter_len_tx);
1595 }
1596
1597 if (rx_match_filter) {
1598 req.rx_match_filter_len = filter_len_rx;
1599 memcpy(req.rx_match_filter, input_rx, filter_len_rx);
1600 nan_hex_dump(dut, req.rx_match_filter, filter_len_rx);
1601 }
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001602
1603 if (service_name) {
1604 strlcpy((char *) req.service_name, service_name,
1605 strlen(service_name) + 1);
1606 req.service_name_len = strlen(service_name);
1607 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001608
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001609 if (ndp_enable) {
1610 if (strcasecmp(ndp_enable, "enable") == 0)
1611 req.sdea_params.config_nan_data_path = 1;
1612 else
1613 req.sdea_params.config_nan_data_path = 0;
1614
1615 if (ndp_type)
1616 req.sdea_params.ndp_type = atoi(ndp_type);
1617
1618 if (data_path_security) {
1619 if (strcasecmp(data_path_security, "secure") == 0) {
1620 req.sdea_params.security_cfg =
1621 NAN_DP_CONFIG_SECURITY;
1622 } else if (strcasecmp(data_path_security, "open") ==
1623 0) {
1624 req.sdea_params.security_cfg =
1625 NAN_DP_CONFIG_NO_SECURITY;
1626 }
1627 }
1628
1629 if (dut->nan_pmk_len == NAN_PMK_INFO_LEN) {
Rakesh Sunki395b0152017-05-16 15:30:36 -07001630 req.key_info.key_type = NAN_SECURITY_KEY_INPUT_PMK;
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001631 memcpy(&req.key_info.body.pmk_info.pmk[0],
1632 &dut->nan_pmk[0], NAN_PMK_INFO_LEN);
1633 req.key_info.body.pmk_info.pmk_len = NAN_PMK_INFO_LEN;
1634 sigma_dut_print(dut, DUT_MSG_INFO, "%s: pmk len = %d",
1635 __func__, req.key_info.body.pmk_info.pmk_len);
1636 }
1637 }
Rakesh Sunki48060402017-03-30 14:47:55 -07001638 if (range_required && strcasecmp(range_required, "enable") == 0) {
1639 req.sdea_params.ranging_state = NAN_RANGING_ENABLE;
1640 req.sdea_params.range_report = NAN_ENABLE_RANGE_REPORT;
1641 }
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001642
Rakesh Sunkiff76d8c2017-06-06 12:29:34 -07001643#if NAN_CERT_VERSION >= 3
Rakesh Sunkie6f66832017-05-16 15:22:48 -07001644 if (awake_dw_interval) {
1645 int input_dw_interval_val = atoi(awake_dw_interval);
1646 int awake_dw_int = 0;
1647
1648 if (input_dw_interval_val > NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL) {
1649 sigma_dut_print(dut, DUT_MSG_INFO,
1650 "%s: input active dw interval = %d overwritting dw interval to Max allowed dw interval 16",
1651 __func__, input_dw_interval_val);
1652 input_dw_interval_val =
1653 NAN_MAX_ALLOWED_DW_AWAKE_INTERVAL;
1654 }
1655 sigma_dut_print(dut, DUT_MSG_INFO,
1656 "%s: input active DW interval = %d",
1657 __func__, input_dw_interval_val);
1658 /*
1659 * Indicates the interval for Sync beacons and SDF's in 2.4 GHz
1660 * or 5 GHz band. Valid values of DW Interval are: 1, 2, 3, 4,
1661 * and 5; 0 is reserved. The SDF includes in OTA when enabled.
1662 * The publish/subscribe period. values don't override the
1663 * device level configurations.
1664 * input_dw_interval_val is provided by the user are in the
1665 * format 2^n-1 = 1/2/4/8/16. Internal implementation expects n
1666 * to be passed to indicate the awake_dw_interval.
1667 */
1668 if (input_dw_interval_val == 1 ||
1669 input_dw_interval_val % 2 == 0) {
1670 while (input_dw_interval_val > 0) {
1671 input_dw_interval_val >>= 1;
1672 awake_dw_int++;
1673 }
1674 }
1675 sigma_dut_print(dut, DUT_MSG_INFO,
1676 "%s:converted active DW interval = %d",
1677 __func__, awake_dw_int);
1678 config_req.config_dw.config_2dot4g_dw_band = 1;
1679 config_req.config_dw.dw_2dot4g_interval_val = awake_dw_int;
1680 config_req.config_dw.config_5g_dw_band = 1;
1681 config_req.config_dw.dw_5g_interval_val = awake_dw_int;
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301682 ret = nan_config_request(0, dut->wifi_hal_iface_handle,
Rakesh Sunkie6f66832017-05-16 15:22:48 -07001683 &config_req);
1684 if (ret != WIFI_SUCCESS) {
1685 sigma_dut_print(dut, DUT_MSG_ERROR,
1686 "%s:NAN config request failed",
1687 __func__);
1688 return -2;
1689 }
1690 }
1691
Rakesh Sunki8a4845d2017-05-16 15:27:13 -07001692 if (qos_config)
1693 req.sdea_params.qos_cfg = (NanQosCfgStatus) atoi(qos_config);
1694#endif
1695
Peng Xu8863ec72018-08-06 11:50:37 -07001696 if (ndpe &&
1697 strcasecmp(ndpe, "Enable") == 0)
1698 dut->ndpe = 1;
1699
1700 if (trans_proto) {
1701 if (strcasecmp(trans_proto, "TCP") == 0) {
1702 dut->trans_proto = TRANSPORT_PROTO_TYPE_TCP;
1703 } else if (strcasecmp(trans_proto, "UDP") == 0) {
1704 dut->trans_proto = TRANSPORT_PROTO_TYPE_UDP;
1705 } else {
1706 sigma_dut_print(dut, DUT_MSG_ERROR,
1707 "%s: Invalid protocol %s",
1708 __func__, trans_proto);
1709 return -1;
1710 }
1711 }
1712
Peng Xu47d709b2019-06-04 18:14:02 -07001713#ifdef NAN_NEW_CERT_VERSION
Peng Xu2486bbe2018-07-19 14:37:22 -07001714 if (dut->ndpe && ndp_attr) {
1715 NanDebugParams cfg_debug;
1716 int ndp_attr_val, size;
1717
1718 memset(&cfg_debug, 0, sizeof(NanDebugParams));
1719 cfg_debug.cmd = NAN_TEST_MODE_CMD_ENABLE_NDP;
1720 if (strcasecmp(ndp_attr, "Absent") == 0)
1721 ndp_attr_val = NAN_NDP_ATTR_ABSENT;
1722 else
1723 ndp_attr_val = NAN_NDP_ATTR_PRESENT;
1724 memcpy(cfg_debug.debug_cmd_data, &ndp_attr_val, sizeof(int));
1725 size = sizeof(u32) + sizeof(int);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301726 ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Peng Xu2486bbe2018-07-19 14:37:22 -07001727 cfg_debug, size);
1728 if (ret != WIFI_SUCCESS) {
1729 send_resp(dut, conn, SIGMA_ERROR,
1730 "NAN config ndpAttr failed");
1731 return 0;
1732 }
1733 }
1734
Peng Xu8863ec72018-08-06 11:50:37 -07001735 if (dut->ndpe) {
1736 unsigned char nan_mac_addr[ETH_ALEN];
Peng Xu47d709b2019-06-04 18:14:02 -07001737 size_t len = 0, tlv_len = 0;
Peng Xu8863ec72018-08-06 11:50:37 -07001738 NanDebugParams cfg_debug;
1739 NdpIpTransParams ndp_ip_trans_param;
Peng Xu47d709b2019-06-04 18:14:02 -07001740 u8 *p_buf;
Peng Xu8863ec72018-08-06 11:50:37 -07001741
Peng Xu47d709b2019-06-04 18:14:02 -07001742 if (get_hwaddr("nan0", nan_mac_addr) < 0) {
1743 sigma_dut_print(dut, DUT_MSG_ERROR,
1744 "%s:get_hwaddr nan0 failed", __func__);
1745 return -1;
1746 }
1747 len = convert_mac_addr_to_ipv6_linklocal(
Peng Xu8863ec72018-08-06 11:50:37 -07001748 nan_mac_addr, ndp_ip_trans_param.ipv6_intf_addr);
1749 ndp_ip_trans_param.ipv6_addr_present = 1;
1750
1751 ndp_ip_trans_param.trans_port_present = 1;
1752 ndp_ip_trans_param.transport_port = dut->trans_port;
1753
1754 ndp_ip_trans_param.trans_proto_present = 1;
1755 ndp_ip_trans_param.transport_protocol = dut->trans_proto;
1756
Peng Xu47d709b2019-06-04 18:14:02 -07001757 /* build TLV blob for cfg_debug cmd */
1758 p_buf = cfg_debug.debug_cmd_data;
1759
1760 /* put IPv6 address tlv into data buffer */
1761 len = nan_build_ipv6_link_local_tlv(
1762 p_buf, ndp_ip_trans_param.ipv6_intf_addr);
1763 tlv_len = len;
1764 p_buf += len;
1765
1766 /* put port and protocol TLV into data buffer */
1767 len = nan_build_service_info_tlv(p_buf, &ndp_ip_trans_param);
1768 tlv_len += len;
1769
Peng Xu8863ec72018-08-06 11:50:37 -07001770 cfg_debug.cmd = NAN_TEST_MODE_CMD_TRANSPORT_IP_PARAM;
1771 memcpy(cfg_debug.debug_cmd_data, &ndp_ip_trans_param,
1772 sizeof(NdpIpTransParams));
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301773 nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Peng Xu47d709b2019-06-04 18:14:02 -07001774 cfg_debug, tlv_len + sizeof(u32));
Peng Xu8863ec72018-08-06 11:50:37 -07001775 }
1776#endif
1777
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301778 ret = nan_publish_request(0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunki107356c2017-03-30 14:47:55 -07001779 if (ret != WIFI_SUCCESS)
1780 send_resp(dut, conn, SIGMA_ERROR, "Unable to publish");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001781
Rakesh Sunki1a5afb92017-03-30 14:47:55 -07001782 if (ndp_enable)
1783 dut->ndp_enable = 1;
1784
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001785 return 0;
1786}
1787
1788
1789static int nan_further_availability_rx(struct sigma_dut *dut,
1790 struct sigma_conn *conn,
1791 struct sigma_cmd *cmd)
1792{
1793 const char *master_pref = get_param(cmd, "MasterPref");
1794 const char *rand_fac = get_param(cmd, "RandFactor");
1795 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001796 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001797 struct timespec abstime;
1798
1799 NanEnableRequest req;
1800
1801 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001802 req.cluster_low = 0;
1803 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001804 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001805
1806 if (master_pref)
1807 req.master_pref = strtoul(master_pref, NULL, 0);
1808
1809 if (rand_fac) {
1810 int rand_fac_val = strtoul(rand_fac, NULL, 0);
1811
1812 req.config_random_factor_force = 1;
1813 req.random_factor_force_val = rand_fac_val;
1814 }
1815
1816 if (hop_count) {
1817 int hop_count_val = strtoul(hop_count, NULL, 0);
1818
1819 req.config_hop_count_force = 1;
1820 req.hop_count_force_val = hop_count_val;
1821 }
1822
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301823 ret = nan_enable_request(0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunki107356c2017-03-30 14:47:55 -07001824 if (ret != WIFI_SUCCESS) {
1825 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
1826 return 0;
1827 }
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001828
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001829 abstime.tv_sec = 4;
1830 abstime.tv_nsec = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001831 wait(abstime);
Kantesh Mundaragi116be192016-10-19 17:10:52 -07001832
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001833 return 0;
1834}
1835
1836
1837static int nan_further_availability_tx(struct sigma_dut *dut,
1838 struct sigma_conn *conn,
1839 struct sigma_cmd *cmd)
1840{
1841 const char *master_pref = get_param(cmd, "MasterPref");
1842 const char *rand_fac = get_param(cmd, "RandFactor");
1843 const char *hop_count = get_param(cmd, "HopCount");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001844 wifi_error ret;
1845
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001846 NanEnableRequest req;
1847 NanConfigRequest configReq;
1848
1849 memset(&req, 0, sizeof(NanEnableRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001850 req.cluster_low = 0;
1851 req.cluster_high = 0xFFFF;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001852 req.master_pref = 30;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001853
1854 if (master_pref)
1855 req.master_pref = strtoul(master_pref, NULL, 0);
1856
1857 if (rand_fac) {
1858 int rand_fac_val = strtoul(rand_fac, NULL, 0);
1859
1860 req.config_random_factor_force = 1;
1861 req.random_factor_force_val = rand_fac_val;
1862 }
1863
1864 if (hop_count) {
1865 int hop_count_val = strtoul(hop_count, NULL, 0);
1866
1867 req.config_hop_count_force = 1;
1868 req.hop_count_force_val = hop_count_val;
1869 }
1870
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301871 ret = nan_enable_request(0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunki107356c2017-03-30 14:47:55 -07001872 if (ret != WIFI_SUCCESS) {
1873 send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan");
1874 return 0;
1875 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001876
1877 /* Start the config of fam */
1878
1879 memset(&configReq, 0, sizeof(NanConfigRequest));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001880
1881 configReq.config_fam = 1;
1882 configReq.fam_val.numchans = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001883 configReq.fam_val.famchan[0].entry_control = 0;
1884 configReq.fam_val.famchan[0].class_val = 81;
1885 configReq.fam_val.famchan[0].channel = 6;
1886 configReq.fam_val.famchan[0].mapid = 0;
1887 configReq.fam_val.famchan[0].avail_interval_bitmap = 0x7ffffffe;
1888
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301889 ret = nan_config_request(0, dut->wifi_hal_iface_handle, &configReq);
Rakesh Sunki107356c2017-03-30 14:47:55 -07001890 if (ret != WIFI_SUCCESS)
1891 send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001892
1893 return 0;
1894}
1895
1896
1897int sigma_nan_transmit_followup(struct sigma_dut *dut,
1898 struct sigma_conn *conn,
1899 struct sigma_cmd *cmd)
1900{
1901 const char *mac = get_param(cmd, "mac");
1902 const char *requestor_id = get_param(cmd, "RemoteInstanceId");
1903 const char *local_id = get_param(cmd, "LocalInstanceId");
1904 const char *service_name = get_param(cmd, "servicename");
Rakesh Sunki107356c2017-03-30 14:47:55 -07001905 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001906 NanTransmitFollowupRequest req;
1907
1908 memset(&req, 0, sizeof(NanTransmitFollowupRequest));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001909 req.requestor_instance_id = global_match_handle;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001910 req.addr[0] = 0xFF;
1911 req.addr[1] = 0xFF;
1912 req.addr[2] = 0xFF;
1913 req.addr[3] = 0xFF;
1914 req.addr[4] = 0xFF;
1915 req.addr[5] = 0xFF;
1916 req.priority = NAN_TX_PRIORITY_NORMAL;
1917 req.dw_or_faw = 0;
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07001918
1919 if (service_name)
1920 req.service_specific_info_len = strlen(service_name);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001921
1922 if (requestor_id) {
1923 /* int requestor_id_val = atoi(requestor_id); */
Rakesh Sunkifa417332017-08-16 15:41:32 -07001924 if (global_match_handle != 0) {
1925 req.requestor_instance_id = global_match_handle;
1926 } else {
1927 u32 requestor_id_val = atoi(requestor_id);
1928 requestor_id_val =
1929 (requestor_id_val << 24) | 0x0000FFFF;
1930 req.requestor_instance_id = requestor_id_val;
1931 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001932 }
1933 if (local_id) {
1934 /* int local_id_val = atoi(local_id); */
Rakesh Sunkifa417332017-08-16 15:41:32 -07001935 if (global_header_handle != 0)
1936 req.publish_subscribe_id = global_header_handle;
1937 else
1938 req.publish_subscribe_id = atoi(local_id);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001939 }
1940
1941 if (mac == NULL) {
1942 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid MAC Address");
1943 return -1;
1944 }
1945 nan_parse_mac_address(dut, mac, req.addr);
1946
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05301947 ret = nan_transmit_followup_request(0, dut->wifi_hal_iface_handle,
1948 &req);
Rakesh Sunki107356c2017-03-30 14:47:55 -07001949 if (ret != WIFI_SUCCESS) {
1950 send_resp(dut, conn, SIGMA_ERROR,
1951 "Unable to complete nan transmit followup");
1952 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001953
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001954 return 0;
1955}
1956
Rakesh Sunki107356c2017-03-30 14:47:55 -07001957
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001958/* NotifyResponse invoked to notify the status of the Request */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001959void nan_notify_response(transaction_id id, NanResponseMsg *rsp_data)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001960{
1961 sigma_dut_print(global_dut, DUT_MSG_INFO,
Rakesh Sunkifdbd60b2017-03-30 14:47:55 -07001962 "%s: status %d response_type %d",
1963 __func__, rsp_data->status, rsp_data->response_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001964 if (rsp_data->response_type == NAN_RESPONSE_STATS &&
1965 rsp_data->body.stats_response.stats_type ==
1966 NAN_STATS_ID_DE_TIMING_SYNC) {
1967 NanSyncStats *pSyncStats;
1968
1969 sigma_dut_print(global_dut, DUT_MSG_INFO,
1970 "%s: stats_type %d", __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001971 rsp_data->body.stats_response.stats_type);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07001972 pSyncStats = &rsp_data->body.stats_response.data.sync_stats;
1973 memcpy(&global_nan_sync_stats, pSyncStats,
1974 sizeof(NanSyncStats));
1975 pthread_cond_signal(&gCondition);
Rakesh Sunki4d5912d2017-03-30 14:47:55 -07001976 } else if (rsp_data->response_type == NAN_RESPONSE_PUBLISH) {
1977 sigma_dut_print(global_dut, DUT_MSG_INFO,
1978 "%s: publish_id %d\n",
1979 __func__,
1980 rsp_data->body.publish_response.publish_id);
1981 global_publish_id = rsp_data->body.publish_response.publish_id;
1982 } else if (rsp_data->response_type == NAN_RESPONSE_SUBSCRIBE) {
1983 sigma_dut_print(global_dut, DUT_MSG_INFO,
1984 "%s: subscribe_id %d\n",
1985 __func__,
1986 rsp_data->body.subscribe_response.subscribe_id);
1987 global_subscribe_id =
1988 rsp_data->body.subscribe_response.subscribe_id;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001989 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001990}
1991
1992
1993/* Events Callback */
1994void nan_event_publish_replied(NanPublishRepliedInd *event)
1995{
1996 sigma_dut_print(global_dut, DUT_MSG_INFO,
1997 "%s: handle %d " MAC_ADDR_STR " rssi:%d",
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07001998 __func__, event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001999 MAC_ADDR_ARRAY(event->addr), event->rssi_value);
2000 event_anyresponse = 1;
2001 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
Rakesh Sunkifa417332017-08-16 15:41:32 -07002002 "EventName,Replied,RemoteInstanceID,%d,LocalInstanceID,%d,mac," MAC_ADDR_STR" ",
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002003 (event->requestor_instance_id >> 24),
Rakesh Sunkifa417332017-08-16 15:41:32 -07002004 (event->requestor_instance_id & 0xFFFF),
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002005 MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002006}
2007
2008
2009/* Events Callback */
2010void nan_event_publish_terminated(NanPublishTerminatedInd *event)
2011{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002012 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: publish_id %d reason %d",
2013 __func__, event->publish_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002014}
2015
2016
2017/* Events Callback */
2018void nan_event_match(NanMatchInd *event)
2019{
2020 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002021 "%s: Pub/Sub Id %d remote_requestor_id %08x "
2022 MAC_ADDR_STR
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002023 " rssi:%d",
2024 __func__,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002025 event->publish_subscribe_id,
2026 event->requestor_instance_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002027 MAC_ADDR_ARRAY(event->addr),
2028 event->rssi_value);
2029 event_anyresponse = 1;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002030 global_header_handle = event->publish_subscribe_id;
2031 global_match_handle = event->requestor_instance_id;
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07002032 memcpy(global_peer_mac_addr, event->addr, sizeof(global_peer_mac_addr));
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002033
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002034 /* memset(event_resp_buf, 0, sizeof(event_resp_buf)); */
2035 /* global_pub_sub_handle = event->header.handle; */
2036 /* Print the SSI */
2037 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing SSI:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002038 nan_hex_dump(global_dut, event->service_specific_info,
2039 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002040 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
2041 "EventName,DiscoveryResult,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002042 MAC_ADDR_STR " ", (event->requestor_instance_id >> 24),
2043 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002044
2045 /* Print the match filter */
2046 sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing sdf match filter:");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002047 nan_hex_dump(global_dut, event->sdf_match_filter,
2048 event->sdf_match_filter_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002049
2050 /* Print the conn_capability */
2051 sigma_dut_print(global_dut, DUT_MSG_INFO,
2052 "Printing PostConnectivity Capability");
2053 if (event->is_conn_capability_valid) {
2054 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfd supported:%s",
2055 event->conn_capability.is_wfd_supported ?
2056 "yes" : "no");
2057 sigma_dut_print(global_dut, DUT_MSG_INFO, "Wfds supported:%s",
2058 (event->conn_capability.is_wfds_supported ?
2059 "yes" : "no"));
2060 sigma_dut_print(global_dut, DUT_MSG_INFO, "TDLS supported:%s",
2061 (event->conn_capability.is_tdls_supported ?
2062 "yes" : "no"));
2063 sigma_dut_print(global_dut, DUT_MSG_INFO, "IBSS supported:%s",
2064 (event->conn_capability.is_ibss_supported ?
2065 "yes" : "no"));
2066 sigma_dut_print(global_dut, DUT_MSG_INFO, "Mesh supported:%s",
2067 (event->conn_capability.is_mesh_supported ?
2068 "yes" : "no"));
2069 sigma_dut_print(global_dut, DUT_MSG_INFO, "Infra Field:%d",
2070 event->conn_capability.wlan_infra_field);
2071 } else {
2072 sigma_dut_print(global_dut, DUT_MSG_INFO,
2073 "PostConnectivity Capability not present");
2074 }
2075
2076 /* Print the discovery_attr */
2077 sigma_dut_print(global_dut, DUT_MSG_INFO,
2078 "Printing PostDiscovery Attribute");
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002079 if (event->num_rx_discovery_attr) {
2080 int idx;
2081
2082 for (idx = 0; idx < event->num_rx_discovery_attr; idx++) {
2083 sigma_dut_print(global_dut, DUT_MSG_INFO,
2084 "PostDiscovery Attribute - %d", idx);
2085 sigma_dut_print(global_dut, DUT_MSG_INFO,
2086 "Conn Type:%d Device Role:%d"
2087 MAC_ADDR_STR,
2088 event->discovery_attr[idx].type,
2089 event->discovery_attr[idx].role,
2090 MAC_ADDR_ARRAY(event->discovery_attr[idx].addr));
2091 sigma_dut_print(global_dut, DUT_MSG_INFO,
2092 "Duration:%d MapId:%d "
2093 "avail_interval_bitmap:%04x",
2094 event->discovery_attr[idx].duration,
2095 event->discovery_attr[idx].mapid,
2096 event->discovery_attr[idx].avail_interval_bitmap);
2097 sigma_dut_print(global_dut, DUT_MSG_INFO,
2098 "Printing Mesh Id:");
2099 nan_hex_dump(global_dut,
2100 event->discovery_attr[idx].mesh_id,
2101 event->discovery_attr[idx].mesh_id_len);
2102 sigma_dut_print(global_dut, DUT_MSG_INFO,
2103 "Printing Infrastructure Ssid:");
2104 nan_hex_dump(global_dut,
2105 event->discovery_attr[idx].infrastructure_ssid_val,
2106 event->discovery_attr[idx].infrastructure_ssid_len);
2107 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002108 } else {
2109 sigma_dut_print(global_dut, DUT_MSG_INFO,
2110 "PostDiscovery attribute not present");
2111 }
2112
2113 /* Print the fam */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002114 if (event->num_chans) {
2115 nan_print_further_availability_chan(global_dut,
2116 event->num_chans,
2117 &event->famchan[0]);
2118 } else {
2119 sigma_dut_print(global_dut, DUT_MSG_INFO,
2120 "Further Availability Map not present");
2121 }
2122 if (event->cluster_attribute_len) {
2123 sigma_dut_print(global_dut, DUT_MSG_INFO,
2124 "Printing Cluster Attribute:");
2125 nan_hex_dump(global_dut, event->cluster_attribute,
2126 event->cluster_attribute_len);
2127 } else {
2128 sigma_dut_print(global_dut, DUT_MSG_INFO,
2129 "Cluster Attribute not present");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 }
2131}
2132
2133
2134/* Events Callback */
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002135void nan_event_match_expired(NanMatchExpiredInd *event)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002136{
2137 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002138 "%s: publish_subscribe_id %d match_handle %08x",
2139 __func__, event->publish_subscribe_id,
2140 event->requestor_instance_id);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002141}
2142
2143
2144/* Events Callback */
2145void nan_event_subscribe_terminated(NanSubscribeTerminatedInd *event)
2146{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002147 sigma_dut_print(global_dut, DUT_MSG_INFO,
2148 "%s: Subscribe Id %d reason %d",
2149 __func__, event->subscribe_id, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002150}
2151
2152
2153/* Events Callback */
2154void nan_event_followup(NanFollowupInd *event)
2155{
2156 sigma_dut_print(global_dut, DUT_MSG_INFO,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002157 "%s: Publish/Subscribe Id %d match_handle 0x%08x dw_or_faw %d "
2158 MAC_ADDR_STR, __func__, event->publish_subscribe_id,
2159 event->requestor_instance_id, event->dw_or_faw,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002160 MAC_ADDR_ARRAY(event->addr));
2161
Rakesh Sunkifa417332017-08-16 15:41:32 -07002162 global_match_handle = event->requestor_instance_id;
2163 global_header_handle = event->publish_subscribe_id;
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002164 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Printing SSI", __func__);
2165 nan_hex_dump(global_dut, event->service_specific_info,
2166 event->service_specific_info_len);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002167 event_anyresponse = 1;
2168 snprintf(global_event_resp_buf, sizeof(global_event_resp_buf),
2169 "EventName,FollowUp,RemoteInstanceID,%d,LocalInstanceID,%d,mac,"
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002170 MAC_ADDR_STR " ", event->requestor_instance_id >> 24,
2171 event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002172}
2173
2174
2175/* Events Callback */
2176void nan_event_disceng_event(NanDiscEngEventInd *event)
2177{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002178 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: event_type %d",
2179 __func__, event->event_type);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002180
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002181 if (event->event_type == NAN_EVENT_ID_JOINED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002182 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: Joined cluster "
2183 MAC_ADDR_STR,
2184 __func__,
2185 MAC_ADDR_ARRAY(event->data.cluster.addr));
Kantesh Mundaragi116be192016-10-19 17:10:52 -07002186 /* To ensure sta_get_events to get the events
2187 * only after joining the NAN cluster. */
2188 pthread_cond_signal(&gCondition);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002189 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002190 if (event->event_type == NAN_EVENT_ID_STARTED_CLUSTER) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002191 sigma_dut_print(global_dut, DUT_MSG_INFO,
2192 "%s: Started cluster " MAC_ADDR_STR,
2193 __func__,
2194 MAC_ADDR_ARRAY(event->data.cluster.addr));
2195 }
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002196 if (event->event_type == NAN_EVENT_ID_DISC_MAC_ADDR) {
2197 sigma_dut_print(global_dut, DUT_MSG_INFO,
2198 "%s: Discovery Mac Address "
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002199 MAC_ADDR_STR,
2200 __func__,
2201 MAC_ADDR_ARRAY(event->data.mac_addr.addr));
2202 memcpy(global_nan_mac_addr, event->data.mac_addr.addr,
2203 sizeof(global_nan_mac_addr));
2204 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002205}
2206
2207
2208/* Events Callback */
2209void nan_event_disabled(NanDisabledInd *event)
2210{
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002211 sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: reason %d",
2212 __func__, event->reason);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002213 /* pthread_cond_signal(&gCondition); */
Ajit Vaishyac2ae9612020-02-28 00:09:07 +05302214 if (if_nametoindex(NAN_AWARE_IFACE))
2215 run_system_wrapper(global_dut, "ifconfig %s down",
2216 NAN_AWARE_IFACE);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002217}
2218
2219
Rakesh Sunki4c086672017-03-30 14:47:55 -07002220/* Events callback */
2221static void ndp_event_data_indication(NanDataPathRequestInd *event)
2222{
Peng Xu47d709b2019-06-04 18:14:02 -07002223 u8 *p_frame;
2224 u16 ipv6_addr_len = 0;
2225 static const u8 ipv6_intf_addr_msb[] = {
2226 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2227 };
2228
Rakesh Sunki4c086672017-03-30 14:47:55 -07002229 sigma_dut_print(global_dut, DUT_MSG_INFO,
2230 "%s: Service Instance Id: %d Peer Discovery MAC ADDR "
2231 MAC_ADDR_STR
2232 " NDP Instance Id: %d App Info len %d App Info %s",
2233 __func__,
2234 event->service_instance_id,
2235 MAC_ADDR_ARRAY(event->peer_disc_mac_addr),
2236 event->ndp_instance_id,
2237 event->app_info.ndp_app_info_len,
2238 event->app_info.ndp_app_info);
2239
2240 global_ndp_instance_id = event->ndp_instance_id;
Peng Xu47d709b2019-06-04 18:14:02 -07002241 memset(global_dut->nan_ipv6_addr, 0, sizeof(global_dut->nan_ipv6_addr));
2242 global_dut->nan_ipv6_len = 0;
2243
2244 if (event->app_info.ndp_app_info_len > 0) {
2245 p_frame = event->app_info.ndp_app_info;
2246 if (*p_frame == NAN_TLV_TYPE_IPV6_LINK_LOCAL) {
2247 p_frame++;
2248 ipv6_addr_len = *p_frame++;
2249 ipv6_addr_len |= (*p_frame++) << 8;
2250 memcpy(global_dut->nan_ipv6_addr, ipv6_intf_addr_msb,
2251 NAN_INTF_ID_LEN);
2252 global_dut->nan_ipv6_len = NAN_INTF_ID_LEN;
2253 if (ipv6_addr_len > 0 &&
2254 ipv6_addr_len <= NAN_INTF_ID_LEN) {
2255 memcpy(global_dut->nan_ipv6_addr +
2256 NAN_INTF_ID_LEN,
2257 p_frame, ipv6_addr_len);
2258 global_dut->nan_ipv6_len += ipv6_addr_len;
2259 }
2260 }
2261 }
Rakesh Sunki4c086672017-03-30 14:47:55 -07002262}
2263
2264
2265/* Events callback */
2266static void ndp_event_data_confirm(NanDataPathConfirmInd *event)
2267{
Rakesh Sunki8f8e74b2017-05-16 15:42:12 -07002268 char cmd[200];
2269 char ipv6_buf[100];
2270
Rakesh Sunki4c086672017-03-30 14:47:55 -07002271 sigma_dut_print(global_dut, DUT_MSG_INFO,
2272 "Received NDP Confirm Indication");
2273
Rakesh Sunki8f8e74b2017-05-16 15:42:12 -07002274 memset(cmd, 0, sizeof(cmd));
2275 memset(ipv6_buf, 0, sizeof(ipv6_buf));
2276
Rakesh Sunki4c086672017-03-30 14:47:55 -07002277 global_ndp_instance_id = event->ndp_instance_id;
Rakesh Sunki8f8e74b2017-05-16 15:42:12 -07002278
2279 if (event->rsp_code == NAN_DP_REQUEST_ACCEPT) {
2280 if (system("ifconfig nan0 up") != 0) {
2281 sigma_dut_print(global_dut, DUT_MSG_ERROR,
2282 "Failed to set nan interface up");
2283 return;
2284 }
Peng Xu78a3cbd2018-07-27 14:05:34 -07002285 if (system("ip -6 route replace fe80::/64 dev nan0 table local") !=
Rakesh Sunki8f8e74b2017-05-16 15:42:12 -07002286 0) {
2287 sigma_dut_print(global_dut, DUT_MSG_ERROR,
2288 "Failed to run:ip -6 route replace fe80::/64 dev nan0 table local");
2289 }
Peng Xu47d709b2019-06-04 18:14:02 -07002290
2291 if (global_dut->nan_ipv6_len > 0 &&
2292 global_dut->nan_ipv6_len >= IPV6_ADDR_LEN)
Peng Xu78a3cbd2018-07-27 14:05:34 -07002293 snprintf(ipv6_buf, sizeof(ipv6_buf),
2294 "fe80::%02x%02x:%02xff:fe%02x:%02x%02x",
Peng Xu47d709b2019-06-04 18:14:02 -07002295 global_dut->nan_ipv6_addr[8],
2296 global_dut->nan_ipv6_addr[9],
2297 global_dut->nan_ipv6_addr[10],
2298 global_dut->nan_ipv6_addr[13],
2299 global_dut->nan_ipv6_addr[14],
2300 global_dut->nan_ipv6_addr[15]);
Peng Xu78a3cbd2018-07-27 14:05:34 -07002301 else
Peng Xu78a3cbd2018-07-27 14:05:34 -07002302 convert_mac_addr_to_ipv6_lladdr(
2303 event->peer_ndi_mac_addr,
2304 ipv6_buf, sizeof(ipv6_buf));
2305
Rakesh Sunki8f8e74b2017-05-16 15:42:12 -07002306 snprintf(cmd, sizeof(cmd),
2307 "ip -6 neighbor replace %s lladdr %02x:%02x:%02x:%02x:%02x:%02x nud permanent dev nan0",
2308 ipv6_buf, event->peer_ndi_mac_addr[0],
2309 event->peer_ndi_mac_addr[1],
2310 event->peer_ndi_mac_addr[2],
2311 event->peer_ndi_mac_addr[3],
2312 event->peer_ndi_mac_addr[4],
2313 event->peer_ndi_mac_addr[5]);
2314 sigma_dut_print(global_dut, DUT_MSG_INFO,
2315 "neighbor replace cmd = %s", cmd);
2316 if (system(cmd) != 0) {
2317 sigma_dut_print(global_dut, DUT_MSG_ERROR,
2318 "Failed to run: ip -6 neighbor replace");
2319 return;
2320 }
Rakesh Sunki4c086672017-03-30 14:47:55 -07002321 }
2322}
2323
2324
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002325static NanCallbackHandler callbackHandler = {
2326 .NotifyResponse = nan_notify_response,
2327 .EventPublishReplied = nan_event_publish_replied,
2328 .EventPublishTerminated = nan_event_publish_terminated,
2329 .EventMatch = nan_event_match,
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07002330 .EventMatchExpired = nan_event_match_expired,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002331 .EventSubscribeTerminated = nan_event_subscribe_terminated,
2332 .EventFollowup = nan_event_followup,
2333 .EventDiscEngEvent = nan_event_disceng_event,
2334 .EventDisabled = nan_event_disabled,
Rakesh Sunki4c086672017-03-30 14:47:55 -07002335 .EventDataRequest = ndp_event_data_indication,
2336 .EventDataConfirm = ndp_event_data_confirm,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002337};
2338
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07002339
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002340void nan_init(struct sigma_dut *dut)
2341{
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05302342 if (wifi_hal_initialize(dut)) {
2343 sigma_dut_print(dut, DUT_MSG_ERROR,
2344 "%s - wifi hal init failed for - NAN",
2345 __func__);
2346 exit(0);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002347 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002348 pthread_mutex_init(&gMutex, NULL);
2349 pthread_cond_init(&gCondition, NULL);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05302350 if (dut->wifi_hal_iface_handle)
2351 nan_register_handler(dut->wifi_hal_iface_handle,
2352 callbackHandler);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002353}
2354
2355
2356void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
2357 struct sigma_cmd *cmd)
2358{
2359 sigma_dut_print(dut, DUT_MSG_INFO, "NAN sta_reset_default");
2360
Anurag Das2052daa2018-08-31 14:35:25 +05302361#ifdef ANDROID
2362 if (dut->nanservicediscoveryinprogress) {
2363 char *argv[5];
2364 pid_t pid;
2365
2366 argv[0] = "am";
2367 argv[1] = "broadcast";
2368 argv[2] = "-a";
2369 argv[3] = "org.codeaurora.nanservicediscovery.close";
2370 argv[4] = NULL;
2371
2372 pid = fork();
2373 if (pid == -1) {
2374 sigma_dut_print(dut, DUT_MSG_ERROR, "fork: %s",
2375 strerror(errno));
2376 } else if (pid == 0) {
2377 execv("/system/bin/am", argv);
2378 sigma_dut_print(dut, DUT_MSG_ERROR, "execv: %s",
2379 strerror(errno));
2380 exit(0);
2381 }
2382 dut->nanservicediscoveryinprogress = 0;
2383 }
2384#endif /* ANDROID */
2385
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002386 if (nan_state == 0) {
2387 nan_init(dut);
2388 nan_state = 1;
2389 }
2390 is_fam = 0;
2391 event_anyresponse = 0;
2392 global_dut = dut;
Rakesh Sunki7d37f412017-03-30 14:47:55 -07002393 memset(&dut->nan_pmk[0], 0, NAN_PMK_INFO_LEN);
2394 dut->nan_pmk_len = 0;
Rakesh Sunkid7344c02017-03-30 14:47:55 -07002395 dut->sta_channel = 0;
Peng Xu8863ec72018-08-06 11:50:37 -07002396 dut->ndpe = 0;
2397 dut->trans_proto = NAN_TRANSPORT_PROTOCOL_DEFAULT;
2398 dut->trans_port = NAN_TRANSPORT_PORT_DEFAULT;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002399 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002400 memset(&global_nan_sync_stats, 0, sizeof(global_nan_sync_stats));
Rakesh Sunki42363682017-05-16 15:00:42 -07002401 memset(global_publish_service_name, 0,
2402 sizeof(global_publish_service_name));
2403 global_publish_service_name_len = 0;
2404 global_publish_id = 0;
Rakesh Sunki0262cb52017-05-17 14:22:05 -07002405 global_subscribe_id = 0;
Rakesh Sunki7a40a202017-03-30 14:47:55 -07002406
Rakesh Sunki8a630b82017-03-30 14:47:55 -07002407 sigma_nan_data_end(dut, cmd);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05302408 nan_data_interface_delete(0, dut->wifi_hal_iface_handle,
2409 (char *) "nan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002410 sigma_nan_disable(dut, conn, cmd);
Rakesh Sunkifa417332017-08-16 15:41:32 -07002411 global_header_handle = 0;
2412 global_match_handle = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002413}
2414
2415
2416int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
2417 struct sigma_cmd *cmd)
2418{
2419 const char *program = get_param(cmd, "Prog");
2420 const char *nan_op = get_param(cmd, "NANOp");
2421 const char *method_type = get_param(cmd, "MethodType");
Rakesh Sunkid7344c02017-03-30 14:47:55 -07002422 const char *band = get_param(cmd, "band");
Anurag Das2052daa2018-08-31 14:35:25 +05302423 const char *disc_mac_addr = get_param(cmd, "DiscoveryMacAddress");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002424 char resp_buf[100];
Rakesh Sunki7a40a202017-03-30 14:47:55 -07002425 wifi_error ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002426
2427 if (program == NULL)
2428 return -1;
2429
2430 if (strcasecmp(program, "NAN") != 0) {
2431 send_resp(dut, conn, SIGMA_ERROR,
2432 "ErrorCode,Unsupported program");
2433 return 0;
2434 }
2435
2436 if (nan_op) {
Rakesh Sunkib5604ff2017-05-16 15:47:08 -07002437#if NAN_CERT_VERSION >= 3
2438 int size = 0;
2439 u32 device_type_val = 0;
2440 NanDebugParams cfg_debug;
2441
2442 memset(&cfg_debug, 0, sizeof(NanDebugParams));
2443 cfg_debug.cmd = NAN_TEST_MODE_CMD_DEVICE_TYPE;
2444 if (dut->device_type == STA_testbed)
2445 device_type_val = NAN_DEVICE_TYPE_TEST_BED;
2446 else if (dut->device_type == STA_dut)
2447 device_type_val = NAN_DEVICE_TYPE_DUT;
2448
2449 memcpy(cfg_debug.debug_cmd_data, &device_type_val, sizeof(u32));
2450 size = sizeof(u32) + sizeof(u32);
2451 sigma_dut_print(dut, DUT_MSG_INFO,
2452 "%s: Device Type: cmd type = %d and command data = %u",
2453 __func__, cfg_debug.cmd, device_type_val);
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05302454 nan_debug_command_config(0, dut->wifi_hal_iface_handle,
Rakesh Sunkib5604ff2017-05-16 15:47:08 -07002455 cfg_debug, size);
2456#endif
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002457 /*
2458 * NANOp has been specified.
2459 * We will build a nan_enable or nan_disable command.
2460 */
2461 if (strcasecmp(nan_op, "On") == 0) {
2462 if (sigma_nan_enable(dut, conn, cmd) == 0) {
Rakesh Sunki7a40a202017-03-30 14:47:55 -07002463 ret = nan_data_interface_create(
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05302464 0, dut->wifi_hal_iface_handle,
Rakesh Sunki7a40a202017-03-30 14:47:55 -07002465 (char *) "nan0");
2466 if (ret != WIFI_SUCCESS) {
2467 sigma_dut_print(
2468 global_dut, DUT_MSG_ERROR,
2469 "Unable to create NAN data interface");
2470 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002471 snprintf(resp_buf, sizeof(resp_buf), "mac,"
2472 MAC_ADDR_STR,
2473 MAC_ADDR_ARRAY(global_nan_mac_addr));
2474 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
2475 } else {
2476 send_resp(dut, conn, SIGMA_ERROR,
2477 "NAN_ENABLE_FAILED");
2478 return -1;
2479 }
Rakesh Sunkid7344c02017-03-30 14:47:55 -07002480
2481 if (band && strcasecmp(band, "24g") == 0) {
2482 sigma_dut_print(dut, DUT_MSG_INFO,
2483 "%s: Setting band to 2G Only",
2484 __func__);
2485 sigma_ndp_configure_band(
2486 dut, conn, cmd,
2487 NAN_DATA_PATH_SUPPORTED_BAND_2G);
2488 } else if (band && dut->sta_channel > 12) {
2489 sigma_ndp_configure_band(
2490 dut, conn, cmd,
2491 NAN_DATA_PATH_SUPPORT_DUAL_BAND);
2492 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002493 } else if (strcasecmp(nan_op, "Off") == 0) {
Rakesh Sunkibcf9ef32017-08-16 15:53:27 -07002494 nan_data_interface_delete(0,
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05302495 dut->wifi_hal_iface_handle, (char *) "nan0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002496 sigma_nan_disable(dut, conn, cmd);
Rakesh Sunki42363682017-05-16 15:00:42 -07002497 memset(global_publish_service_name, 0,
2498 sizeof(global_publish_service_name));
2499 global_publish_service_name_len = 0;
2500 global_publish_id = 0;
Rakesh Sunki0262cb52017-05-17 14:22:05 -07002501 global_subscribe_id = 0;
Rakesh Sunkifa417332017-08-16 15:41:32 -07002502 global_header_handle = 0;
2503 global_match_handle = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002504 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2505 }
2506 }
2507 if (nan_state && nan_op == NULL) {
2508 if (method_type) {
2509 if (strcasecmp(method_type, "Publish") == 0) {
2510 sigma_nan_publish_request(dut, conn, cmd);
2511 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2512 }
2513 if (strcasecmp(method_type, "Subscribe") == 0) {
2514 sigma_nan_subscribe_request(dut, conn, cmd);
2515 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2516 }
2517 if (strcasecmp(method_type, "Followup") == 0) {
2518 sigma_nan_transmit_followup(dut, conn, cmd);
2519 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2520 }
Rakesh Sunki14cfcd22017-03-30 14:47:55 -07002521 if (strcasecmp(method_type, "DataRequest") == 0) {
2522 sigma_nan_data_request(dut, conn, cmd);
2523 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2524 }
Rakesh Sunkia5cc2842017-03-30 14:47:55 -07002525 if (strcasecmp(method_type, "DataResponse") == 0) {
2526 sigma_dut_print(dut, DUT_MSG_INFO,
2527 "%s: method_type is DataResponse",
2528 __func__);
2529 sigma_nan_data_response(dut, conn, cmd);
2530 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2531 }
Rakesh Sunki8a630b82017-03-30 14:47:55 -07002532 if (strcasecmp(method_type, "DataEnd") == 0) {
2533 sigma_nan_data_end(dut, cmd);
2534 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2535 }
Rakesh Sunkid5e9b4d2017-03-30 14:47:55 -07002536 if (strcasecmp(method_type, "rangerequest") == 0) {
2537 sigma_dut_print(dut, DUT_MSG_INFO,
2538 "%s: method_type is rangerequest",
2539 __func__);
2540 sigma_nan_range_request(dut, cmd);
2541 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2542 }
2543 if (strcasecmp(method_type, "cancelrange") == 0) {
2544 sigma_dut_print(dut, DUT_MSG_INFO,
2545 "%s: method_type is cancelrange",
2546 __func__);
2547 sigma_nan_cancel_range(dut, cmd);
2548 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2549 }
Rakesh Sunkib2b65162017-03-30 14:47:55 -07002550 if (strcasecmp(method_type, "SchedUpdate") == 0) {
2551 sigma_dut_print(dut, DUT_MSG_INFO,
2552 "%s: method_type is SchedUpdate",
2553 __func__);
2554 sigma_nan_schedule_update(dut, cmd);
2555 send_resp(dut, conn, SIGMA_COMPLETE, "NULL");
2556 }
Anurag Das2052daa2018-08-31 14:35:25 +05302557 } else if (disc_mac_addr &&
2558 strcasecmp(disc_mac_addr, "GET") == 0) {
2559 snprintf(resp_buf, sizeof(resp_buf), "mac,"
2560 MAC_ADDR_STR,
2561 MAC_ADDR_ARRAY(global_nan_mac_addr));
2562 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002563 } else {
2564 sigma_nan_config_enable(dut, conn, cmd);
2565 snprintf(resp_buf, sizeof(resp_buf), "mac,"
2566 MAC_ADDR_STR,
2567 MAC_ADDR_ARRAY(global_nan_mac_addr));
2568 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
2569 }
2570 }
2571
2572 return 0;
2573}
2574
2575
2576int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
2577 struct sigma_cmd *cmd)
2578{
2579
2580 const char *program = get_param(cmd, "Program");
2581 const char *parameter = get_param(cmd, "Parameter");
2582 char resp_buf[100];
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002583 NanStatsRequest req;
2584 struct timespec abstime;
2585 u64 master_rank;
2586 u8 master_pref;
2587 u8 random_factor;
2588 u8 hop_count;
2589 u32 beacon_transmit_time;
2590 u32 ndp_channel_freq;
2591 u32 ndp_channel_freq2;
Rakesh Sunkia3b59662017-05-16 15:52:33 -07002592#if NAN_CERT_VERSION >= 3
2593 u32 sched_update_channel_freq;
2594#endif
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002595
2596 if (program == NULL) {
2597 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Program Name");
2598 return -1;
2599 }
2600 if (strcasecmp(program, "NAN") != 0) {
2601 send_resp(dut, conn, SIGMA_ERROR,
2602 "ErrorCode,Unsupported program");
2603 return 0;
2604 }
2605
2606 if (parameter == NULL) {
2607 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid Parameter");
2608 return -1;
2609 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002611 memset(&req, 0, sizeof(NanStatsRequest));
Rakesh Sunkia3b59662017-05-16 15:52:33 -07002612 memset(resp_buf, 0, sizeof(resp_buf));
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002613 req.stats_type = (NanStatsType) NAN_STATS_ID_DE_TIMING_SYNC;
Vinay Gannevaram2dfb1da2019-06-14 15:24:08 +05302614 nan_stats_request(0, dut->wifi_hal_iface_handle, &req);
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002615 /*
2616 * To ensure sta_get_events to get the events
2617 * only after joining the NAN cluster
2618 */
2619 abstime.tv_sec = 4;
2620 abstime.tv_nsec = 0;
2621 wait(abstime);
2622
2623 master_rank = global_nan_sync_stats.myRank;
2624 master_pref = (global_nan_sync_stats.myRank & 0xFF00000000000000) >> 56;
2625 random_factor = (global_nan_sync_stats.myRank & 0x00FF000000000000) >>
2626 48;
2627 hop_count = global_nan_sync_stats.currAmHopCount;
2628 beacon_transmit_time = global_nan_sync_stats.currAmBTT;
2629 ndp_channel_freq = global_nan_sync_stats.ndpChannelFreq;
2630 ndp_channel_freq2 = global_nan_sync_stats.ndpChannelFreq2;
Rakesh Sunkia3b59662017-05-16 15:52:33 -07002631#if NAN_CERT_VERSION >= 3
2632 sched_update_channel_freq =
2633 global_nan_sync_stats.schedUpdateChannelFreq;
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002634
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002635 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunkia3b59662017-05-16 15:52:33 -07002636 "%s: NanStatsRequest Master_pref:%02x, Random_factor:%02x, hop_count:%02x beacon_transmit_time:%d ndp_channel_freq:%d ndp_channel_freq2:%d sched_update_channel_freq:%d",
2637 __func__, master_pref, random_factor,
2638 hop_count, beacon_transmit_time,
2639 ndp_channel_freq, ndp_channel_freq2,
2640 sched_update_channel_freq);
2641#else /* #if NAN_CERT_VERSION >= 3 */
2642 sigma_dut_print(dut, DUT_MSG_INFO,
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002643 "%s: NanStatsRequest Master_pref:%02x, Random_factor:%02x, hop_count:%02x beacon_transmit_time:%d ndp_channel_freq:%d ndp_channel_freq2:%d",
2644 __func__, master_pref, random_factor,
2645 hop_count, beacon_transmit_time,
2646 ndp_channel_freq, ndp_channel_freq2);
Rakesh Sunkia3b59662017-05-16 15:52:33 -07002647#endif /* #if NAN_CERT_VERSION >= 3 */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002648
2649 if (strcasecmp(parameter, "MasterPref") == 0) {
2650 snprintf(resp_buf, sizeof(resp_buf), "MasterPref,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002651 master_pref);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002652 } else if (strcasecmp(parameter, "MasterRank") == 0) {
2653 snprintf(resp_buf, sizeof(resp_buf), "MasterRank,0x%lx",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002654 master_rank);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002655 } else if (strcasecmp(parameter, "RandFactor") == 0) {
2656 snprintf(resp_buf, sizeof(resp_buf), "RandFactor,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002657 random_factor);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002658 } else if (strcasecmp(parameter, "HopCount") == 0) {
2659 snprintf(resp_buf, sizeof(resp_buf), "HopCount,0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002660 hop_count);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002661 } else if (strcasecmp(parameter, "BeaconTransTime") == 0) {
2662 snprintf(resp_buf, sizeof(resp_buf), "BeaconTransTime 0x%x",
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002663 beacon_transmit_time);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002664 } else if (strcasecmp(parameter, "NANStatus") == 0) {
2665 if (nan_state == 1)
2666 snprintf(resp_buf, sizeof(resp_buf), "On");
2667 else
2668 snprintf(resp_buf, sizeof(resp_buf), "Off");
Rakesh Sunkid51e8982017-03-30 14:47:55 -07002669 } else if (strcasecmp(parameter, "NDPChannel") == 0) {
2670 if (ndp_channel_freq != 0 && ndp_channel_freq2 != 0) {
2671 snprintf(resp_buf, sizeof(resp_buf),
2672 "ndpchannel,%d,ndpchannel,%d",
2673 freq_to_channel(ndp_channel_freq),
2674 freq_to_channel(ndp_channel_freq2));
2675 } else if (ndp_channel_freq != 0) {
2676 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
2677 freq_to_channel(ndp_channel_freq));
2678 } else if (ndp_channel_freq2 != 0) {
2679 snprintf(resp_buf, sizeof(resp_buf), "ndpchannel,%d",
2680 freq_to_channel(ndp_channel_freq2));
2681 } else {
2682 sigma_dut_print(dut, DUT_MSG_ERROR,
2683 "%s: No Negotiated NDP Channels", __func__);
2684 }
Rakesh Sunkia3b59662017-05-16 15:52:33 -07002685#if NAN_CERT_VERSION >= 3
2686 } else if (strcasecmp(parameter, "SchedUpdateChannel") == 0) {
2687 snprintf(resp_buf, sizeof(resp_buf), "schedupdatechannel,%d",
2688 freq_to_channel(sched_update_channel_freq));
2689#endif
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002690 } else {
2691 send_resp(dut, conn, SIGMA_ERROR, "Invalid Parameter");
2692 return 0;
2693 }
2694
2695 send_resp(dut, conn, SIGMA_COMPLETE, resp_buf);
2696 return 0;
2697}
2698
2699
2700int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
2701 struct sigma_cmd *cmd)
2702{
2703 const char *action = get_param(cmd, "Action");
2704
Kantesh Mundaragi132c6d22016-10-28 16:17:50 -07002705 if (!action)
2706 return 0;
2707
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002708 /* Check action for start, stop and get events. */
2709 if (strcasecmp(action, "Start") == 0) {
2710 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
2711 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
2712 } else if (strcasecmp(action, "Stop") == 0) {
2713 event_anyresponse = 0;
2714 memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf));
2715 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
2716 } else if (strcasecmp(action, "Get") == 0) {
2717 if (event_anyresponse == 1) {
2718 send_resp(dut, conn, SIGMA_COMPLETE,
2719 global_event_resp_buf);
2720 } else {
2721 send_resp(dut, conn, SIGMA_COMPLETE, "EventList,NONE");
2722 }
2723 }
2724 return 0;
2725}
Rakesh Sunki4b75f962017-03-30 14:47:55 -07002726
2727#else /* #if NAN_CERT_VERSION */
2728
2729int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut,
2730 struct sigma_conn *conn,
2731 struct sigma_cmd *cmd)
2732{
2733 return 1;
2734}
2735
2736
2737int nan_cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
2738 struct sigma_cmd *cmd)
2739{
2740 return 0;
2741
2742}
2743
2744
2745void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
2746 struct sigma_cmd *cmd)
2747{
2748 return;
2749}
2750
2751
2752int nan_cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
2753 struct sigma_cmd *cmd)
2754{
2755 return 0;
2756}
2757
2758
2759int nan_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
2760 struct sigma_cmd *cmd)
2761{
2762 return 0;
2763}
2764
2765#endif /* #if NAN_CERT_VERSION */