Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Sigma Control API DUT (NAN functionality) |
Rakesh Sunki | 4b75f96 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Qualcomm Atheros, Inc. |
Peng Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 4 | * Copyright (c) 2018, The Linux Foundation |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 5 | * 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 Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 13 | #include "nan_cert.h" |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 14 | |
Rakesh Sunki | 4b75f96 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 15 | #if NAN_CERT_VERSION >= 2 |
| 16 | |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 17 | #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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 24 | pthread_cond_t gCondition; |
| 25 | pthread_mutex_t gMutex; |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 26 | static NanSyncStats global_nan_sync_stats; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 27 | static int nan_state = 0; |
| 28 | static int event_anyresponse = 0; |
| 29 | static int is_fam = 0; |
| 30 | |
Rakesh Sunki | 4c08667 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 31 | static uint16_t global_ndp_instance_id = 0; |
Rakesh Sunki | 4d5912d | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 32 | static uint16_t global_publish_id = 0; |
| 33 | static uint16_t global_subscribe_id = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 34 | uint16_t global_header_handle = 0; |
| 35 | uint32_t global_match_handle = 0; |
| 36 | |
Rakesh Sunki | d5e9b4d | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 37 | #define DEFAULT_SVC "QNanCluster" |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 38 | #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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 44 | static 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 49 | struct sigma_dut *global_dut = NULL; |
| 50 | static char global_nan_mac_addr[ETH_ALEN]; |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 51 | static char global_peer_mac_addr[ETH_ALEN]; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 52 | static char global_event_resp_buf[1024]; |
Rakesh Sunki | 4236368 | 2017-05-16 15:00:42 -0700 | [diff] [blame] | 53 | static u8 global_publish_service_name[NAN_MAX_SERVICE_NAME_LEN]; |
| 54 | static u32 global_publish_service_name_len = 0; |
Rakesh Sunki | 74f4f99 | 2017-08-16 15:21:52 -0700 | [diff] [blame] | 55 | static u8 global_subscribe_service_name[NAN_MAX_SERVICE_NAME_LEN]; |
| 56 | static u32 global_subscribe_service_name_len = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 57 | |
| 58 | static int nan_further_availability_tx(struct sigma_dut *dut, |
| 59 | struct sigma_conn *conn, |
| 60 | struct sigma_cmd *cmd); |
| 61 | static int nan_further_availability_rx(struct sigma_dut *dut, |
| 62 | struct sigma_conn *conn, |
| 63 | struct sigma_cmd *cmd); |
| 64 | |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 65 | enum 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 | |
| 72 | enum 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 | |
| 80 | enum 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 94 | |
| 95 | void 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 Xu | 6734e23 | 2017-10-04 10:10:33 -0700 | [diff] [blame] | 106 | pos += snprintf(&(buf[pos]), sizeof(buf) - pos, |
| 107 | "%02x ", *ptr++); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 108 | 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 | |
| 116 | int 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 | |
| 128 | int 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 | |
| 149 | int 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 | |
| 170 | int 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 | |
| 197 | int 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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 218 | static 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 | |
| 235 | static 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 | |
| 253 | static 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 306 | int 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 | |
| 326 | int nan_cmd_sta_preset_testparameters(struct sigma_dut *dut, |
| 327 | struct sigma_conn *conn, |
| 328 | struct sigma_cmd *cmd) |
| 329 | { |
Rakesh Sunki | 8dd1d88 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 330 | const char *oper_chan = get_param(cmd, "oper_chn"); |
Rakesh Sunki | 7d37f41 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 331 | const char *pmk = get_param(cmd, "PMK"); |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 332 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | 57d7ead | 2018-08-06 11:53:47 -0700 | [diff] [blame] | 333 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 337 | |
Rakesh Sunki | 8dd1d88 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 338 | if (oper_chan) { |
| 339 | sigma_dut_print(dut, DUT_MSG_INFO, "Operating Channel: %s", |
| 340 | oper_chan); |
Kantesh Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 341 | dut->sta_channel = atoi(oper_chan); |
Rakesh Sunki | 8dd1d88 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 342 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 343 | |
Rakesh Sunki | 7d37f41 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 344 | 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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 360 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | 57d7ead | 2018-08-06 11:53:47 -0700 | [diff] [blame] | 361 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 371 | ret = nan_config_request(0, dut->wifi_hal_iface_handle, &req); |
Peng Xu | 57d7ead | 2018-08-06 11:53:47 -0700 | [diff] [blame] | 372 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 410 | ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Peng Xu | 57d7ead | 2018-08-06 11:53:47 -0700 | [diff] [blame] | 411 | 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 Sunki | 14bff1d | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 420 | send_resp(dut, conn, SIGMA_COMPLETE, NULL); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 425 | void 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 449 | int 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 455 | 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 Sunki | 38dd72e | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 460 | const char *nan_availability = get_param(cmd, "NANAvailability"); |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 461 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 462 | const char *ndpe = get_param(cmd, "NDPE"); |
| 463 | #endif |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 464 | struct timespec abstime; |
| 465 | NanEnableRequest req; |
| 466 | |
| 467 | memset(&req, 0, sizeof(NanEnableRequest)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 468 | req.cluster_low = 0; |
| 469 | req.cluster_high = 0xFFFF; |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 470 | req.master_pref = 100; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 471 | |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 472 | /* This is a debug hack to beacon in channel 11 */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 473 | if (oper_chan) { |
| 474 | req.config_2dot4g_support = 1; |
| 475 | req.support_2dot4g_val = 111; |
| 476 | } |
| 477 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 478 | 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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 505 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 506 | 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 Sunki | 47a276a | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 521 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 540 | if (band) { |
| 541 | if (strcasecmp(band, "24G") == 0) { |
| 542 | sigma_dut_print(dut, DUT_MSG_INFO, |
Rakesh Sunki | 47a276a | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 543 | "Band 2.4 GHz selected, disable 5 GHz"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 544 | /* Disable 5G support */ |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 545 | req.config_support_5g = 1; |
| 546 | req.support_5g_val = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 547 | req.config_5g_beacons = 1; |
| 548 | req.beacon_5g_val = 0; |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 549 | req.config_5g_sdf = 1; |
| 550 | req.sdf_5g_val = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 551 | } |
| 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 Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 572 | req.config_2dot4g_sdf = 1; |
| 573 | req.sdf_2dot4g_val = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 574 | } |
| 575 | |
Ajit Vaishya | c2ae961 | 2020-02-28 00:09:07 +0530 | [diff] [blame] | 576 | if (if_nametoindex(NAN_AWARE_IFACE)) |
| 577 | run_system_wrapper(dut, "ifconfig %s up", NAN_AWARE_IFACE); |
| 578 | |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 579 | nan_enable_request(0, dut->wifi_hal_iface_handle, &req); |
Kantesh Mundaragi | 116be19 | 2016-10-19 17:10:52 -0700 | [diff] [blame] | 580 | |
Rakesh Sunki | 38dd72e | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 581 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 597 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | 38dd72e | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 598 | cfg_debug, cmd_len); |
| 599 | } |
| 600 | |
Kantesh Mundaragi | 116be19 | 2016-10-19 17:10:52 -0700 | [diff] [blame] | 601 | /* To ensure sta_get_events to get the events |
| 602 | * only after joining the NAN cluster. */ |
| 603 | abstime.tv_sec = 30; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 604 | abstime.tv_nsec = 0; |
Kantesh Mundaragi | 116be19 | 2016-10-19 17:10:52 -0700 | [diff] [blame] | 605 | wait(abstime); |
| 606 | |
| 607 | return 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | |
| 611 | int sigma_nan_disable(struct sigma_dut *dut, struct sigma_conn *conn, |
| 612 | struct sigma_cmd *cmd) |
| 613 | { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 614 | struct timespec abstime; |
| 615 | |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 616 | nan_disable_request(0, dut->wifi_hal_iface_handle); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 617 | |
| 618 | abstime.tv_sec = 4; |
| 619 | abstime.tv_nsec = 0; |
Kantesh Mundaragi | 116be19 | 2016-10-19 17:10:52 -0700 | [diff] [blame] | 620 | wait(abstime); |
| 621 | |
| 622 | return 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | |
| 626 | int 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 Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 632 | wifi_error ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 633 | struct timespec abstime; |
| 634 | NanConfigRequest req; |
| 635 | |
| 636 | memset(&req, 0, sizeof(NanConfigRequest)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 637 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 661 | ret = nan_config_request(0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 662 | if (ret != WIFI_SUCCESS) |
| 663 | send_resp(dut, conn, SIGMA_ERROR, "NAN config request failed"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 664 | |
| 665 | abstime.tv_sec = 4; |
| 666 | abstime.tv_nsec = 0; |
Kantesh Mundaragi | 116be19 | 2016-10-19 17:10:52 -0700 | [diff] [blame] | 667 | wait(abstime); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 668 | |
Kantesh Mundaragi | 116be19 | 2016-10-19 17:10:52 -0700 | [diff] [blame] | 669 | return 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | |
| 673 | static 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 Sunki | ff76d8c | 2017-06-06 12:29:34 -0700 | [diff] [blame] | 687 | #if NAN_CERT_VERSION >= 3 |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 688 | const char *awake_dw_interval = get_param(cmd, "awakeDWint"); |
Rakesh Sunki | ff76d8c | 2017-06-06 12:29:34 -0700 | [diff] [blame] | 689 | #endif |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 690 | NanSubscribeRequest req; |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 691 | NanConfigRequest config_req; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 692 | 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 Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 695 | wifi_error ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 696 | |
| 697 | memset(&req, 0, sizeof(NanSubscribeRequest)); |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 698 | memset(&config_req, 0, sizeof(NanConfigRequest)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 699 | req.ttl = 0; |
Rakesh Sunki | 4625de7 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 700 | req.period = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 701 | req.subscribe_type = 1; |
| 702 | req.serviceResponseFilter = 1; /* MAC */ |
| 703 | req.serviceResponseInclude = 0; |
| 704 | req.ssiRequiredForMatchIndication = 0; |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 705 | req.subscribe_match_indicator = NAN_MATCH_ALG_MATCH_CONTINUOUS; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 706 | req.subscribe_count = 0; |
| 707 | |
Rakesh Sunki | 74f4f99 | 2017-08-16 15:21:52 -0700 | [diff] [blame] | 708 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 719 | 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 Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 728 | ret = nan_subscribe_cancel_request( |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 729 | 0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 730 | if (ret != WIFI_SUCCESS) { |
| 731 | send_resp(dut, conn, SIGMA_ERROR, |
| 732 | "NAN subscribe cancel request failed"); |
| 733 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 734 | 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 Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 799 | if (service_name) { |
| 800 | strlcpy((char *) req.service_name, service_name, |
| 801 | strlen(service_name) + 1); |
| 802 | req.service_name_len = strlen(service_name); |
Rakesh Sunki | 74f4f99 | 2017-08-16 15:21:52 -0700 | [diff] [blame] | 803 | 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 Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 807 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 808 | |
Rakesh Sunki | ff76d8c | 2017-06-06 12:29:34 -0700 | [diff] [blame] | 809 | #if NAN_CERT_VERSION >= 3 |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 810 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 848 | ret = nan_config_request(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 849 | &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 Sunki | ff76d8c | 2017-06-06 12:29:34 -0700 | [diff] [blame] | 857 | #endif |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 858 | |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 859 | ret = nan_subscribe_request(0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 860 | if (ret != WIFI_SUCCESS) { |
| 861 | send_resp(dut, conn, SIGMA_ERROR, |
| 862 | "NAN subscribe request failed"); |
| 863 | } |
| 864 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | |
Rakesh Sunki | d7344c0 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 869 | static 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 884 | ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, cfg_debug, |
Rakesh Sunki | d7344c0 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 885 | 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 Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 893 | static 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 Sunki | 8a4845d | 2017-05-16 15:27:13 -0700 | [diff] [blame] | 903 | #if NAN_CERT_VERSION >= 3 |
| 904 | const char *qos_config = get_param(cmd, "QoS"); |
| 905 | #endif |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 906 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 907 | const char *ndpe_enable = get_param(cmd, "Ndpe"); |
| 908 | const char *ndpe_attr = get_param(cmd, "ndpeAttr"); |
Peng Xu | 2486bbe | 2018-07-19 14:37:22 -0700 | [diff] [blame] | 909 | const char *ndp_attr = get_param(cmd, "ndpAttr"); |
Peng Xu | 7b1b9e1 | 2018-07-19 16:24:55 -0700 | [diff] [blame] | 910 | const char *tlv_list = get_param(cmd, "TLVList"); |
Peng Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 911 | #endif |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 912 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 936 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 937 | 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 Lazar | 093569f | 2018-11-13 14:08:17 +0200 | [diff] [blame] | 944 | avoid_channel_freq = channel_to_freq(dut, atoi(avoid_channel)); |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 945 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 949 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 950 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 966 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 967 | 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 Sunki | 9eaa677 | 2017-04-04 11:37:03 -0700 | [diff] [blame] | 981 | cfg_debug.cmd, map_order_val); |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 982 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 983 | cfg_debug, size); |
| 984 | } |
| 985 | |
Rakesh Sunki | 8a4845d | 2017-05-16 15:27:13 -0700 | [diff] [blame] | 986 | #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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 998 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | 8a4845d | 2017-05-16 15:27:13 -0700 | [diff] [blame] | 999 | cfg_debug, size); |
| 1000 | } |
| 1001 | #endif |
| 1002 | |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1003 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1004 | if (ndpe_enable && |
| 1005 | strcasecmp(ndpe_enable, "Enable") == 0) |
| 1006 | dut->ndpe = 1; |
| 1007 | |
Peng Xu | 2486bbe | 2018-07-19 14:37:22 -0700 | [diff] [blame] | 1008 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1020 | ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Peng Xu | 2486bbe | 2018-07-19 14:37:22 -0700 | [diff] [blame] | 1021 | 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 Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1029 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1041 | ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Peng Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1042 | 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 Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1051 | /* |
| 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 Lazar | 093569f | 2018-11-13 14:08:17 +0200 | [diff] [blame] | 1084 | init_req.channel = channel_to_freq(dut, dut->sta_channel); |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1085 | } |
| 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 Sunki | 395b015 | 2017-05-16 15:30:36 -0700 | [diff] [blame] | 1092 | init_req.key_info.key_type = NAN_SECURITY_KEY_INPUT_PMK; |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1093 | 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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1101 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1102 | if (dut->ndpe) { |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1103 | 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 Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1111 | |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1112 | 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 Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1132 | } |
| 1133 | #endif |
| 1134 | |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1135 | ret = nan_data_request_initiator(0, dut->wifi_hal_iface_handle, |
| 1136 | &init_req); |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1137 | 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 Sunki | a5cc284 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1147 | static 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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1153 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1154 | const char *ndpe_attr = get_param(cmd, "ndpeAttr"); |
Peng Xu | 2486bbe | 2018-07-19 14:37:22 -0700 | [diff] [blame] | 1155 | const char *ndp_attr = get_param(cmd, "ndpAttr"); |
Peng Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1156 | #endif |
Rakesh Sunki | a5cc284 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1157 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1189 | ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | a5cc284 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1190 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1215 | ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | a5cc284 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1216 | cfg_debug, size); |
| 1217 | if (ret != WIFI_SUCCESS) { |
| 1218 | send_resp(dut, conn, SIGMA_ERROR, |
| 1219 | "Nan config request failed"); |
| 1220 | } |
| 1221 | } |
| 1222 | |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1223 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | 2486bbe | 2018-07-19 14:37:22 -0700 | [diff] [blame] | 1224 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1236 | ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Peng Xu | 2486bbe | 2018-07-19 14:37:22 -0700 | [diff] [blame] | 1237 | 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 Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1245 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1256 | ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Peng Xu | b0c682c | 2018-06-27 14:36:07 -0700 | [diff] [blame] | 1257 | 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 Sunki | a5cc284 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | |
Rakesh Sunki | 8a630b8 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1270 | static 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1294 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | 8a630b8 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1295 | cfg_debug, size); |
| 1296 | } |
| 1297 | |
| 1298 | req.num_ndp_instances = 1; |
| 1299 | req.ndp_instance_id[0] = global_ndp_instance_id; |
| 1300 | |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1301 | nan_data_end(0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | 8a630b8 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1302 | return 0; |
| 1303 | } |
| 1304 | |
| 1305 | |
Rakesh Sunki | d5e9b4d | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1306 | static 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 Sunki | 3834be5 | 2017-08-16 15:27:36 -0700 | [diff] [blame] | 1314 | req.subscribe_type = NAN_SUBSCRIBE_TYPE_PASSIVE; |
Rakesh Sunki | d5e9b4d | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1315 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1338 | nan_subscribe_request(0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | d5e9b4d | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1339 | |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | |
| 1344 | static 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1369 | nan_publish_request(0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | d5e9b4d | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1370 | |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
| 1374 | |
Rakesh Sunki | b2b6516 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1375 | static 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1439 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, cfg_debug, |
| 1440 | size); |
Rakesh Sunki | b2b6516 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1441 | |
| 1442 | return 0; |
| 1443 | } |
| 1444 | |
| 1445 | |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1446 | int config_post_disc_attr(struct sigma_dut *dut) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1447 | { |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1448 | wifi_error ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1449 | NanConfigRequest configReq; |
| 1450 | |
| 1451 | memset(&configReq, 0, sizeof(NanConfigRequest)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1452 | |
| 1453 | /* Configure Post disc attr */ |
| 1454 | /* Make these defines and use correct enum */ |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 1455 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1461 | |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1462 | ret = nan_config_request(0, dut->wifi_hal_iface_handle, &configReq); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1463 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1468 | return 0; |
| 1469 | } |
| 1470 | |
| 1471 | |
| 1472 | int 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 Sunki | 1a5afb9 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1482 | 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 Sunki | 4806040 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1485 | const char *range_required = get_param(cmd, "rangerequired"); |
Rakesh Sunki | 8a4845d | 2017-05-16 15:27:13 -0700 | [diff] [blame] | 1486 | #if NAN_CERT_VERSION >= 3 |
Rakesh Sunki | ff76d8c | 2017-06-06 12:29:34 -0700 | [diff] [blame] | 1487 | const char *awake_dw_interval = get_param(cmd, "awakeDWint"); |
Rakesh Sunki | 8a4845d | 2017-05-16 15:27:13 -0700 | [diff] [blame] | 1488 | const char *qos_config = get_param(cmd, "QoS"); |
| 1489 | #endif |
Peng Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 1490 | const char *ndpe = get_param(cmd, "NDPE"); |
| 1491 | const char *trans_proto = get_param(cmd, "TransProtoType"); |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1492 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | 2486bbe | 2018-07-19 14:37:22 -0700 | [diff] [blame] | 1493 | const char *ndp_attr = get_param(cmd, "ndpAttr"); |
| 1494 | #endif |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1495 | NanPublishRequest req; |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 1496 | NanConfigRequest config_req; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1497 | 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 Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1500 | wifi_error ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1501 | |
| 1502 | memset(&req, 0, sizeof(NanPublishRequest)); |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 1503 | memset(&config_req, 0, sizeof(NanConfigRequest)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1504 | req.ttl = 0; |
Rakesh Sunki | 4625de7 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1505 | req.period = 1; |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 1506 | req.publish_match_indicator = 1; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1507 | req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED; |
| 1508 | req.tx_type = NAN_TX_TYPE_BROADCAST; |
| 1509 | req.publish_count = 0; |
Rakesh Sunki | 0a0eea8 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1510 | req.service_responder_policy = NAN_SERVICE_ACCEPT_POLICY_ALL; |
Kantesh Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 1511 | |
Rakesh Sunki | 4236368 | 2017-05-16 15:00:42 -0700 | [diff] [blame] | 1512 | 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 Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 1523 | if (service_name) { |
| 1524 | strlcpy((char *) req.service_name, service_name, |
Rakesh Sunki | 4236368 | 2017-05-16 15:00:42 -0700 | [diff] [blame] | 1525 | 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 Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 1531 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1532 | |
| 1533 | if (publish_type) { |
| 1534 | if (strcasecmp(publish_type, "Solicited") == 0) { |
| 1535 | req.publish_type = NAN_PUBLISH_TYPE_SOLICITED; |
Rakesh Sunki | 62644ab | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1536 | } else if (strcasecmp(publish_type, "Unsolicited") == 0) { |
| 1537 | req.publish_type = NAN_PUBLISH_TYPE_UNSOLICITED; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1538 | } else if (strcasecmp(publish_type, "Cancel") == 0) { |
| 1539 | NanPublishCancelRequest req; |
| 1540 | |
| 1541 | memset(&req, 0, sizeof(NanPublishCancelRequest)); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1542 | ret = nan_publish_cancel_request( |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1543 | 0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1544 | if (ret != WIFI_SUCCESS) { |
| 1545 | send_resp(dut, conn, SIGMA_ERROR, |
| 1546 | "Unable to cancel nan publish request"); |
| 1547 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1548 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1575 | config_post_disc_attr(dut); |
Rakesh Sunki | f680e0f | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1576 | /* |
| 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1588 | 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 Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 1602 | |
| 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1608 | |
Rakesh Sunki | 1a5afb9 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1609 | 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 Sunki | 395b015 | 2017-05-16 15:30:36 -0700 | [diff] [blame] | 1630 | req.key_info.key_type = NAN_SECURITY_KEY_INPUT_PMK; |
Rakesh Sunki | 1a5afb9 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1631 | 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 Sunki | 4806040 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1638 | 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 Sunki | 1a5afb9 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1642 | |
Rakesh Sunki | ff76d8c | 2017-06-06 12:29:34 -0700 | [diff] [blame] | 1643 | #if NAN_CERT_VERSION >= 3 |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 1644 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1682 | ret = nan_config_request(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | e6f6683 | 2017-05-16 15:22:48 -0700 | [diff] [blame] | 1683 | &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 Sunki | 8a4845d | 2017-05-16 15:27:13 -0700 | [diff] [blame] | 1692 | if (qos_config) |
| 1693 | req.sdea_params.qos_cfg = (NanQosCfgStatus) atoi(qos_config); |
| 1694 | #endif |
| 1695 | |
Peng Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 1696 | 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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1713 | #ifdef NAN_NEW_CERT_VERSION |
Peng Xu | 2486bbe | 2018-07-19 14:37:22 -0700 | [diff] [blame] | 1714 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1726 | ret = nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Peng Xu | 2486bbe | 2018-07-19 14:37:22 -0700 | [diff] [blame] | 1727 | 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 Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 1735 | if (dut->ndpe) { |
| 1736 | unsigned char nan_mac_addr[ETH_ALEN]; |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1737 | size_t len = 0, tlv_len = 0; |
Peng Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 1738 | NanDebugParams cfg_debug; |
| 1739 | NdpIpTransParams ndp_ip_trans_param; |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1740 | u8 *p_buf; |
Peng Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 1741 | |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1742 | 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 Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 1748 | 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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1757 | /* 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 Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 1770 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1773 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 1774 | cfg_debug, tlv_len + sizeof(u32)); |
Peng Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 1775 | } |
| 1776 | #endif |
| 1777 | |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1778 | ret = nan_publish_request(0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1779 | if (ret != WIFI_SUCCESS) |
| 1780 | send_resp(dut, conn, SIGMA_ERROR, "Unable to publish"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1781 | |
Rakesh Sunki | 1a5afb9 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1782 | if (ndp_enable) |
| 1783 | dut->ndp_enable = 1; |
| 1784 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1785 | return 0; |
| 1786 | } |
| 1787 | |
| 1788 | |
| 1789 | static 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 Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1796 | wifi_error ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1797 | struct timespec abstime; |
| 1798 | |
| 1799 | NanEnableRequest req; |
| 1800 | |
| 1801 | memset(&req, 0, sizeof(NanEnableRequest)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1802 | req.cluster_low = 0; |
| 1803 | req.cluster_high = 0xFFFF; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1804 | req.master_pref = 30; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1805 | |
| 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1823 | ret = nan_enable_request(0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1824 | if (ret != WIFI_SUCCESS) { |
| 1825 | send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan"); |
| 1826 | return 0; |
| 1827 | } |
Kantesh Mundaragi | 116be19 | 2016-10-19 17:10:52 -0700 | [diff] [blame] | 1828 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1829 | abstime.tv_sec = 4; |
| 1830 | abstime.tv_nsec = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1831 | wait(abstime); |
Kantesh Mundaragi | 116be19 | 2016-10-19 17:10:52 -0700 | [diff] [blame] | 1832 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1833 | return 0; |
| 1834 | } |
| 1835 | |
| 1836 | |
| 1837 | static 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 Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1844 | wifi_error ret; |
| 1845 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1846 | NanEnableRequest req; |
| 1847 | NanConfigRequest configReq; |
| 1848 | |
| 1849 | memset(&req, 0, sizeof(NanEnableRequest)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1850 | req.cluster_low = 0; |
| 1851 | req.cluster_high = 0xFFFF; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1852 | req.master_pref = 30; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1853 | |
| 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1871 | ret = nan_enable_request(0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1872 | if (ret != WIFI_SUCCESS) { |
| 1873 | send_resp(dut, conn, SIGMA_ERROR, "Unable to enable nan"); |
| 1874 | return 0; |
| 1875 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1876 | |
| 1877 | /* Start the config of fam */ |
| 1878 | |
| 1879 | memset(&configReq, 0, sizeof(NanConfigRequest)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1880 | |
| 1881 | configReq.config_fam = 1; |
| 1882 | configReq.fam_val.numchans = 1; |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 1883 | 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1889 | ret = nan_config_request(0, dut->wifi_hal_iface_handle, &configReq); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1890 | if (ret != WIFI_SUCCESS) |
| 1891 | send_resp(dut, conn, SIGMA_ERROR, "Nan config request failed"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1892 | |
| 1893 | return 0; |
| 1894 | } |
| 1895 | |
| 1896 | |
| 1897 | int 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 Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1905 | wifi_error ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1906 | NanTransmitFollowupRequest req; |
| 1907 | |
| 1908 | memset(&req, 0, sizeof(NanTransmitFollowupRequest)); |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 1909 | req.requestor_instance_id = global_match_handle; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1910 | 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 Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 1918 | |
| 1919 | if (service_name) |
| 1920 | req.service_specific_info_len = strlen(service_name); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1921 | |
| 1922 | if (requestor_id) { |
| 1923 | /* int requestor_id_val = atoi(requestor_id); */ |
Rakesh Sunki | fa41733 | 2017-08-16 15:41:32 -0700 | [diff] [blame] | 1924 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1932 | } |
| 1933 | if (local_id) { |
| 1934 | /* int local_id_val = atoi(local_id); */ |
Rakesh Sunki | fa41733 | 2017-08-16 15:41:32 -0700 | [diff] [blame] | 1935 | if (global_header_handle != 0) |
| 1936 | req.publish_subscribe_id = global_header_handle; |
| 1937 | else |
| 1938 | req.publish_subscribe_id = atoi(local_id); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1939 | } |
| 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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 1947 | ret = nan_transmit_followup_request(0, dut->wifi_hal_iface_handle, |
| 1948 | &req); |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1949 | if (ret != WIFI_SUCCESS) { |
| 1950 | send_resp(dut, conn, SIGMA_ERROR, |
| 1951 | "Unable to complete nan transmit followup"); |
| 1952 | } |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 1953 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1954 | return 0; |
| 1955 | } |
| 1956 | |
Rakesh Sunki | 107356c | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1957 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1958 | /* NotifyResponse invoked to notify the status of the Request */ |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 1959 | void nan_notify_response(transaction_id id, NanResponseMsg *rsp_data) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1960 | { |
| 1961 | sigma_dut_print(global_dut, DUT_MSG_INFO, |
Rakesh Sunki | fdbd60b | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1962 | "%s: status %d response_type %d", |
| 1963 | __func__, rsp_data->status, rsp_data->response_type); |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1964 | 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 Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 1971 | rsp_data->body.stats_response.stats_type); |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1972 | 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 Sunki | 4d5912d | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 1976 | } 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1989 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | |
| 1993 | /* Events Callback */ |
| 1994 | void 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 Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 1998 | __func__, event->requestor_instance_id, |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 1999 | MAC_ADDR_ARRAY(event->addr), event->rssi_value); |
| 2000 | event_anyresponse = 1; |
| 2001 | snprintf(global_event_resp_buf, sizeof(global_event_resp_buf), |
Rakesh Sunki | fa41733 | 2017-08-16 15:41:32 -0700 | [diff] [blame] | 2002 | "EventName,Replied,RemoteInstanceID,%d,LocalInstanceID,%d,mac," MAC_ADDR_STR" ", |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2003 | (event->requestor_instance_id >> 24), |
Rakesh Sunki | fa41733 | 2017-08-16 15:41:32 -0700 | [diff] [blame] | 2004 | (event->requestor_instance_id & 0xFFFF), |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2005 | MAC_ADDR_ARRAY(event->addr)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | |
| 2009 | /* Events Callback */ |
| 2010 | void nan_event_publish_terminated(NanPublishTerminatedInd *event) |
| 2011 | { |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2012 | sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: publish_id %d reason %d", |
| 2013 | __func__, event->publish_id, event->reason); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | |
| 2017 | /* Events Callback */ |
| 2018 | void nan_event_match(NanMatchInd *event) |
| 2019 | { |
| 2020 | sigma_dut_print(global_dut, DUT_MSG_INFO, |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2021 | "%s: Pub/Sub Id %d remote_requestor_id %08x " |
| 2022 | MAC_ADDR_STR |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2023 | " rssi:%d", |
| 2024 | __func__, |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2025 | event->publish_subscribe_id, |
| 2026 | event->requestor_instance_id, |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2027 | MAC_ADDR_ARRAY(event->addr), |
| 2028 | event->rssi_value); |
| 2029 | event_anyresponse = 1; |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2030 | global_header_handle = event->publish_subscribe_id; |
| 2031 | global_match_handle = event->requestor_instance_id; |
Rakesh Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2032 | memcpy(global_peer_mac_addr, event->addr, sizeof(global_peer_mac_addr)); |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2033 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2034 | /* 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 Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2038 | nan_hex_dump(global_dut, event->service_specific_info, |
| 2039 | event->service_specific_info_len); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2040 | snprintf(global_event_resp_buf, sizeof(global_event_resp_buf), |
| 2041 | "EventName,DiscoveryResult,RemoteInstanceID,%d,LocalInstanceID,%d,mac," |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2042 | MAC_ADDR_STR " ", (event->requestor_instance_id >> 24), |
| 2043 | event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2044 | |
| 2045 | /* Print the match filter */ |
| 2046 | sigma_dut_print(global_dut, DUT_MSG_INFO, "Printing sdf match filter:"); |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2047 | nan_hex_dump(global_dut, event->sdf_match_filter, |
| 2048 | event->sdf_match_filter_len); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2049 | |
| 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 Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2079 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2108 | } else { |
| 2109 | sigma_dut_print(global_dut, DUT_MSG_INFO, |
| 2110 | "PostDiscovery attribute not present"); |
| 2111 | } |
| 2112 | |
| 2113 | /* Print the fam */ |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2114 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | |
| 2134 | /* Events Callback */ |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2135 | void nan_event_match_expired(NanMatchExpiredInd *event) |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2136 | { |
| 2137 | sigma_dut_print(global_dut, DUT_MSG_INFO, |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2138 | "%s: publish_subscribe_id %d match_handle %08x", |
| 2139 | __func__, event->publish_subscribe_id, |
| 2140 | event->requestor_instance_id); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | |
| 2144 | /* Events Callback */ |
| 2145 | void nan_event_subscribe_terminated(NanSubscribeTerminatedInd *event) |
| 2146 | { |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2147 | sigma_dut_print(global_dut, DUT_MSG_INFO, |
| 2148 | "%s: Subscribe Id %d reason %d", |
| 2149 | __func__, event->subscribe_id, event->reason); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | |
| 2153 | /* Events Callback */ |
| 2154 | void nan_event_followup(NanFollowupInd *event) |
| 2155 | { |
| 2156 | sigma_dut_print(global_dut, DUT_MSG_INFO, |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2157 | "%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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2160 | MAC_ADDR_ARRAY(event->addr)); |
| 2161 | |
Rakesh Sunki | fa41733 | 2017-08-16 15:41:32 -0700 | [diff] [blame] | 2162 | global_match_handle = event->requestor_instance_id; |
| 2163 | global_header_handle = event->publish_subscribe_id; |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2164 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2167 | event_anyresponse = 1; |
| 2168 | snprintf(global_event_resp_buf, sizeof(global_event_resp_buf), |
| 2169 | "EventName,FollowUp,RemoteInstanceID,%d,LocalInstanceID,%d,mac," |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2170 | MAC_ADDR_STR " ", event->requestor_instance_id >> 24, |
| 2171 | event->publish_subscribe_id, MAC_ADDR_ARRAY(event->addr)); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | |
| 2175 | /* Events Callback */ |
| 2176 | void nan_event_disceng_event(NanDiscEngEventInd *event) |
| 2177 | { |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2178 | sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: event_type %d", |
| 2179 | __func__, event->event_type); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2180 | |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2181 | if (event->event_type == NAN_EVENT_ID_JOINED_CLUSTER) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2182 | 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 Mundaragi | 116be19 | 2016-10-19 17:10:52 -0700 | [diff] [blame] | 2186 | /* To ensure sta_get_events to get the events |
| 2187 | * only after joining the NAN cluster. */ |
| 2188 | pthread_cond_signal(&gCondition); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2189 | } |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2190 | if (event->event_type == NAN_EVENT_ID_STARTED_CLUSTER) { |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2191 | 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 Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2196 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2199 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | |
| 2208 | /* Events Callback */ |
| 2209 | void nan_event_disabled(NanDisabledInd *event) |
| 2210 | { |
Amarnath Hullur Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2211 | sigma_dut_print(global_dut, DUT_MSG_INFO, "%s: reason %d", |
| 2212 | __func__, event->reason); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2213 | /* pthread_cond_signal(&gCondition); */ |
Ajit Vaishya | c2ae961 | 2020-02-28 00:09:07 +0530 | [diff] [blame] | 2214 | if (if_nametoindex(NAN_AWARE_IFACE)) |
| 2215 | run_system_wrapper(global_dut, "ifconfig %s down", |
| 2216 | NAN_AWARE_IFACE); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | |
Rakesh Sunki | 4c08667 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2220 | /* Events callback */ |
| 2221 | static void ndp_event_data_indication(NanDataPathRequestInd *event) |
| 2222 | { |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 2223 | 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 Sunki | 4c08667 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2229 | 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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 2241 | 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 Sunki | 4c08667 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | |
| 2265 | /* Events callback */ |
| 2266 | static void ndp_event_data_confirm(NanDataPathConfirmInd *event) |
| 2267 | { |
Rakesh Sunki | 8f8e74b | 2017-05-16 15:42:12 -0700 | [diff] [blame] | 2268 | char cmd[200]; |
| 2269 | char ipv6_buf[100]; |
| 2270 | |
Rakesh Sunki | 4c08667 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2271 | sigma_dut_print(global_dut, DUT_MSG_INFO, |
| 2272 | "Received NDP Confirm Indication"); |
| 2273 | |
Rakesh Sunki | 8f8e74b | 2017-05-16 15:42:12 -0700 | [diff] [blame] | 2274 | memset(cmd, 0, sizeof(cmd)); |
| 2275 | memset(ipv6_buf, 0, sizeof(ipv6_buf)); |
| 2276 | |
Rakesh Sunki | 4c08667 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2277 | global_ndp_instance_id = event->ndp_instance_id; |
Rakesh Sunki | 8f8e74b | 2017-05-16 15:42:12 -0700 | [diff] [blame] | 2278 | |
| 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 Xu | 78a3cbd | 2018-07-27 14:05:34 -0700 | [diff] [blame] | 2285 | if (system("ip -6 route replace fe80::/64 dev nan0 table local") != |
Rakesh Sunki | 8f8e74b | 2017-05-16 15:42:12 -0700 | [diff] [blame] | 2286 | 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 Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 2290 | |
| 2291 | if (global_dut->nan_ipv6_len > 0 && |
| 2292 | global_dut->nan_ipv6_len >= IPV6_ADDR_LEN) |
Peng Xu | 78a3cbd | 2018-07-27 14:05:34 -0700 | [diff] [blame] | 2293 | snprintf(ipv6_buf, sizeof(ipv6_buf), |
| 2294 | "fe80::%02x%02x:%02xff:fe%02x:%02x%02x", |
Peng Xu | 47d709b | 2019-06-04 18:14:02 -0700 | [diff] [blame] | 2295 | 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 Xu | 78a3cbd | 2018-07-27 14:05:34 -0700 | [diff] [blame] | 2301 | else |
Peng Xu | 78a3cbd | 2018-07-27 14:05:34 -0700 | [diff] [blame] | 2302 | convert_mac_addr_to_ipv6_lladdr( |
| 2303 | event->peer_ndi_mac_addr, |
| 2304 | ipv6_buf, sizeof(ipv6_buf)); |
| 2305 | |
Rakesh Sunki | 8f8e74b | 2017-05-16 15:42:12 -0700 | [diff] [blame] | 2306 | 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 Sunki | 4c08667 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2325 | static 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 Subramanyam | 1854ec6 | 2016-08-11 19:29:35 -0700 | [diff] [blame] | 2330 | .EventMatchExpired = nan_event_match_expired, |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2331 | .EventSubscribeTerminated = nan_event_subscribe_terminated, |
| 2332 | .EventFollowup = nan_event_followup, |
| 2333 | .EventDiscEngEvent = nan_event_disceng_event, |
| 2334 | .EventDisabled = nan_event_disabled, |
Rakesh Sunki | 4c08667 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2335 | .EventDataRequest = ndp_event_data_indication, |
| 2336 | .EventDataConfirm = ndp_event_data_confirm, |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2337 | }; |
| 2338 | |
Kantesh Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 2339 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2340 | void nan_init(struct sigma_dut *dut) |
| 2341 | { |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 2342 | 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2347 | } |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2348 | pthread_mutex_init(&gMutex, NULL); |
| 2349 | pthread_cond_init(&gCondition, NULL); |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 2350 | if (dut->wifi_hal_iface_handle) |
| 2351 | nan_register_handler(dut->wifi_hal_iface_handle, |
| 2352 | callbackHandler); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | |
| 2356 | void 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 Das | 2052daa | 2018-08-31 14:35:25 +0530 | [diff] [blame] | 2361 | #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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2386 | 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 Sunki | 7d37f41 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2393 | memset(&dut->nan_pmk[0], 0, NAN_PMK_INFO_LEN); |
| 2394 | dut->nan_pmk_len = 0; |
Rakesh Sunki | d7344c0 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2395 | dut->sta_channel = 0; |
Peng Xu | 8863ec7 | 2018-08-06 11:50:37 -0700 | [diff] [blame] | 2396 | dut->ndpe = 0; |
| 2397 | dut->trans_proto = NAN_TRANSPORT_PROTOCOL_DEFAULT; |
| 2398 | dut->trans_port = NAN_TRANSPORT_PORT_DEFAULT; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2399 | memset(global_event_resp_buf, 0, sizeof(global_event_resp_buf)); |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2400 | memset(&global_nan_sync_stats, 0, sizeof(global_nan_sync_stats)); |
Rakesh Sunki | 4236368 | 2017-05-16 15:00:42 -0700 | [diff] [blame] | 2401 | 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 Sunki | 0262cb5 | 2017-05-17 14:22:05 -0700 | [diff] [blame] | 2405 | global_subscribe_id = 0; |
Rakesh Sunki | 7a40a20 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2406 | |
Rakesh Sunki | 8a630b8 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2407 | sigma_nan_data_end(dut, cmd); |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 2408 | nan_data_interface_delete(0, dut->wifi_hal_iface_handle, |
| 2409 | (char *) "nan0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2410 | sigma_nan_disable(dut, conn, cmd); |
Rakesh Sunki | fa41733 | 2017-08-16 15:41:32 -0700 | [diff] [blame] | 2411 | global_header_handle = 0; |
| 2412 | global_match_handle = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | |
| 2416 | int 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 Sunki | d7344c0 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2422 | const char *band = get_param(cmd, "band"); |
Anurag Das | 2052daa | 2018-08-31 14:35:25 +0530 | [diff] [blame] | 2423 | const char *disc_mac_addr = get_param(cmd, "DiscoveryMacAddress"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2424 | char resp_buf[100]; |
Rakesh Sunki | 7a40a20 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2425 | wifi_error ret; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2426 | |
| 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 Sunki | b5604ff | 2017-05-16 15:47:08 -0700 | [diff] [blame] | 2437 | #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 Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 2454 | nan_debug_command_config(0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | b5604ff | 2017-05-16 15:47:08 -0700 | [diff] [blame] | 2455 | cfg_debug, size); |
| 2456 | #endif |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2457 | /* |
| 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 Sunki | 7a40a20 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2463 | ret = nan_data_interface_create( |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 2464 | 0, dut->wifi_hal_iface_handle, |
Rakesh Sunki | 7a40a20 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2465 | (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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2471 | 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 Sunki | d7344c0 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2480 | |
| 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2493 | } else if (strcasecmp(nan_op, "Off") == 0) { |
Rakesh Sunki | bcf9ef3 | 2017-08-16 15:53:27 -0700 | [diff] [blame] | 2494 | nan_data_interface_delete(0, |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 2495 | dut->wifi_hal_iface_handle, (char *) "nan0"); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2496 | sigma_nan_disable(dut, conn, cmd); |
Rakesh Sunki | 4236368 | 2017-05-16 15:00:42 -0700 | [diff] [blame] | 2497 | 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 Sunki | 0262cb5 | 2017-05-17 14:22:05 -0700 | [diff] [blame] | 2501 | global_subscribe_id = 0; |
Rakesh Sunki | fa41733 | 2017-08-16 15:41:32 -0700 | [diff] [blame] | 2502 | global_header_handle = 0; |
| 2503 | global_match_handle = 0; |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2504 | 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 Sunki | 14cfcd2 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2521 | if (strcasecmp(method_type, "DataRequest") == 0) { |
| 2522 | sigma_nan_data_request(dut, conn, cmd); |
| 2523 | send_resp(dut, conn, SIGMA_COMPLETE, "NULL"); |
| 2524 | } |
Rakesh Sunki | a5cc284 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2525 | 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 Sunki | 8a630b8 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2532 | if (strcasecmp(method_type, "DataEnd") == 0) { |
| 2533 | sigma_nan_data_end(dut, cmd); |
| 2534 | send_resp(dut, conn, SIGMA_COMPLETE, "NULL"); |
| 2535 | } |
Rakesh Sunki | d5e9b4d | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2536 | 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 Sunki | b2b6516 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2550 | 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 Das | 2052daa | 2018-08-31 14:35:25 +0530 | [diff] [blame] | 2557 | } 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2563 | } 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 | |
| 2576 | int 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 Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2583 | 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 Sunki | a3b5966 | 2017-05-16 15:52:33 -0700 | [diff] [blame] | 2592 | #if NAN_CERT_VERSION >= 3 |
| 2593 | u32 sched_update_channel_freq; |
| 2594 | #endif |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2595 | |
| 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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2610 | |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2611 | memset(&req, 0, sizeof(NanStatsRequest)); |
Rakesh Sunki | a3b5966 | 2017-05-16 15:52:33 -0700 | [diff] [blame] | 2612 | memset(resp_buf, 0, sizeof(resp_buf)); |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2613 | req.stats_type = (NanStatsType) NAN_STATS_ID_DE_TIMING_SYNC; |
Vinay Gannevaram | 2dfb1da | 2019-06-14 15:24:08 +0530 | [diff] [blame] | 2614 | nan_stats_request(0, dut->wifi_hal_iface_handle, &req); |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2615 | /* |
| 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 Sunki | a3b5966 | 2017-05-16 15:52:33 -0700 | [diff] [blame] | 2631 | #if NAN_CERT_VERSION >= 3 |
| 2632 | sched_update_channel_freq = |
| 2633 | global_nan_sync_stats.schedUpdateChannelFreq; |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2634 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2635 | sigma_dut_print(dut, DUT_MSG_INFO, |
Rakesh Sunki | a3b5966 | 2017-05-16 15:52:33 -0700 | [diff] [blame] | 2636 | "%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 Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2643 | "%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 Sunki | a3b5966 | 2017-05-16 15:52:33 -0700 | [diff] [blame] | 2647 | #endif /* #if NAN_CERT_VERSION >= 3 */ |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2648 | |
| 2649 | if (strcasecmp(parameter, "MasterPref") == 0) { |
| 2650 | snprintf(resp_buf, sizeof(resp_buf), "MasterPref,0x%x", |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2651 | master_pref); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2652 | } else if (strcasecmp(parameter, "MasterRank") == 0) { |
| 2653 | snprintf(resp_buf, sizeof(resp_buf), "MasterRank,0x%lx", |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2654 | master_rank); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2655 | } else if (strcasecmp(parameter, "RandFactor") == 0) { |
| 2656 | snprintf(resp_buf, sizeof(resp_buf), "RandFactor,0x%x", |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2657 | random_factor); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2658 | } else if (strcasecmp(parameter, "HopCount") == 0) { |
| 2659 | snprintf(resp_buf, sizeof(resp_buf), "HopCount,0x%x", |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2660 | hop_count); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2661 | } else if (strcasecmp(parameter, "BeaconTransTime") == 0) { |
| 2662 | snprintf(resp_buf, sizeof(resp_buf), "BeaconTransTime 0x%x", |
Rakesh Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2663 | beacon_transmit_time); |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2664 | } 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 Sunki | d51e898 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2669 | } 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 Sunki | a3b5966 | 2017-05-16 15:52:33 -0700 | [diff] [blame] | 2685 | #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 Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2690 | } 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 | |
| 2700 | int 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 Mundaragi | 132c6d2 | 2016-10-28 16:17:50 -0700 | [diff] [blame] | 2705 | if (!action) |
| 2706 | return 0; |
| 2707 | |
Jouni Malinen | cd4e3c3 | 2015-10-29 12:39:56 +0200 | [diff] [blame] | 2708 | /* 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 Sunki | 4b75f96 | 2017-03-30 14:47:55 -0700 | [diff] [blame] | 2726 | |
| 2727 | #else /* #if NAN_CERT_VERSION */ |
| 2728 | |
| 2729 | int 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 | |
| 2737 | int 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 | |
| 2745 | void nan_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn, |
| 2746 | struct sigma_cmd *cmd) |
| 2747 | { |
| 2748 | return; |
| 2749 | } |
| 2750 | |
| 2751 | |
| 2752 | int 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 | |
| 2759 | int 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 */ |