blob: 47ab647d06ac40517ad7964c475f805d09379165 [file] [log] [blame]
Ravi Joshia063dd92016-05-25 16:43:13 -07001/*
Selvaraj, Sridhar0672a122016-12-29 16:11:48 +05302 * Copyright (c) 2016-2017 The Linux Foundation. All rights reserved.
Ravi Joshia063dd92016-05-25 16:43:13 -07003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for
7 * any purpose with or without fee is hereby granted, provided that the
8 * above copyright notice and this permission notice appear in all
9 * copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
12 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
13 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
14 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
15 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
16 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
17 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18 * PERFORMANCE OF THIS SOFTWARE.
19 */
20
21/**
22 * DOC: wlan_hdd_nan_datapath.c
23 *
24 * WLAN Host Device Driver nan datapath API implementation
25 */
Deepak Dhamdhere13983f22016-05-31 19:06:09 -070026#include <wlan_hdd_includes.h>
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070027#include <linux/if.h>
28#include <linux/netdevice.h>
29#include <linux/skbuff.h>
30#include <linux/etherdevice.h>
31#include "wlan_hdd_includes.h"
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070032#include "wlan_hdd_p2p.h"
33#include "wma_api.h"
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -070034#include "wlan_hdd_assoc.h"
35#include "sme_nan_datapath.h"
Rajeev Kumar699debf2017-01-06 14:17:00 -080036#include "wlan_hdd_object_manager.h"
Sandeep Puligillafdd201e2017-02-02 18:43:46 -080037#include <qca_vendor.h>
Naveen Rawat63de5422017-03-22 11:03:56 -070038#include "os_if_nan.h"
Naveen Rawatcb5c5402017-03-22 10:12:19 -070039#include "wlan_nan_api.h"
40#include "nan_public_structs.h"
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070041
Naveen Rawat97500352017-03-22 10:07:58 -070042#ifndef WLAN_FEATURE_NAN_CONVERGENCE
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070043/* NLA policy */
44static const struct nla_policy
45qca_wlan_vendor_ndp_policy[QCA_WLAN_VENDOR_ATTR_NDP_PARAMS_MAX + 1] = {
46 [QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD] = { .type = NLA_U32 },
47 [QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID] = { .type = NLA_U16 },
Jeff Johnson438ff422017-06-15 14:56:45 -070048 [QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR] = { .type = NLA_NUL_STRING,
49 .len = IFNAMSIZ - 1 },
Naveen Rawat19da3d12016-08-16 12:39:38 -070050 [QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID] = { .type = NLA_U32 },
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -070051 [QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL] = { .type = NLA_U32 },
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070052 [QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR] = {
Naveen Rawatf28315c2016-06-29 18:06:02 -070053 .type = NLA_BINARY,
54 .len = QDF_MAC_ADDR_SIZE },
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070055 [QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_SECURITY] = { .type = NLA_U16 },
56 [QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS] = { .type = NLA_BINARY,
57 .len = NDP_QOS_INFO_LEN },
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070058 [QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO] = { .type = NLA_BINARY,
59 .len = NDP_APP_INFO_LEN },
60 [QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID] = { .type = NLA_U32 },
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -070061 [QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE] = { .type = NLA_U16 },
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070062 [QCA_WLAN_VENDOR_ATTR_NDP_NDI_MAC_ADDR] = { .type = NLA_BINARY,
63 .len = QDF_MAC_ADDR_SIZE },
Naveen Rawatf28315c2016-06-29 18:06:02 -070064 [QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY] = { .type = NLA_BINARY,
65 .len = NDP_NUM_INSTANCE_ID },
Naveen Rawat0a017052016-10-19 14:17:07 -070066 [QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL_CONFIG] = { .type = NLA_U32 },
Naveen Rawat4f3983e2016-11-29 16:12:09 -080067 [QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE] = { .type = NLA_U32 },
68 [QCA_WLAN_VENDOR_ATTR_NDP_PMK] = { .type = NLA_BINARY,
69 .len = NDP_PMK_LEN },
70 [QCA_WLAN_VENDOR_ATTR_NDP_SCID] = { .type = NLA_BINARY,
71 .len = NDP_SCID_BUF_LEN },
Rakesh Sunkid92d1082017-01-04 15:14:28 -080072 [QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE] = { .type =
73 NLA_U32 },
74 [QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE] = { .type = NLA_U32 },
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -070075};
Naveen Rawat97500352017-03-22 10:07:58 -070076#endif
Deepak Dhamdhere3385d752016-05-25 20:36:47 -070077
78/**
79 * hdd_ndp_print_ini_config()- Print nan datapath specific INI configuration
80 * @hdd_ctx: handle to hdd context
81 *
82 * Return: None
83 */
Jeff Johnson88dc4f92017-08-28 11:51:34 -070084void hdd_ndp_print_ini_config(struct hdd_context *hdd_ctx)
Deepak Dhamdhere3385d752016-05-25 20:36:47 -070085{
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -070086 hdd_debug("Name = [%s] Value = [%u]", CFG_ENABLE_NAN_DATAPATH_NAME,
Deepak Dhamdhere3385d752016-05-25 20:36:47 -070087 hdd_ctx->config->enable_nan_datapath);
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -070088 hdd_debug("Name = [%s] Value = [%u]", CFG_ENABLE_NAN_NDI_CHANNEL_NAME,
Deepak Dhamdhere3385d752016-05-25 20:36:47 -070089 hdd_ctx->config->nan_datapath_ndi_channel);
90}
Deepak Dhamdhere13230d32016-05-26 00:46:53 -070091
92/**
93 * hdd_nan_datapath_target_config() - Configure NAN datapath features
94 * @hdd_ctx: Pointer to HDD context
95 * @cfg: Pointer to target device capability information
96 *
Deepak Dhamdhere13983f22016-05-31 19:06:09 -070097 * NAN datapath functionality is enabled if it is enabled in
98 * .ini file and also supported on target device.
Deepak Dhamdhere13230d32016-05-26 00:46:53 -070099 *
100 * Return: None
101 */
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700102void hdd_nan_datapath_target_config(struct hdd_context *hdd_ctx,
Deepak Dhamdhere13230d32016-05-26 00:46:53 -0700103 struct wma_tgt_cfg *cfg)
104{
Deepak Dhamdhere7e6016f2016-06-01 09:37:37 -0700105 hdd_ctx->nan_datapath_enabled =
106 hdd_ctx->config->enable_nan_datapath &&
107 cfg->nan_datapath_enabled;
Naveen Rawatcb5c5402017-03-22 10:12:19 -0700108 hdd_info("enable_nan_datapath: final: %d, host: %d, fw: %d",
109 hdd_ctx->nan_datapath_enabled,
110 hdd_ctx->config->enable_nan_datapath,
111 cfg->nan_datapath_enabled);
Deepak Dhamdhere13230d32016-05-26 00:46:53 -0700112}
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700113
114/**
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700115 * hdd_close_ndi() - close NAN Data interface
116 * @adapter: adapter context
117 *
118 * Close the adapter if start BSS fails
119 *
120 * Returns: 0 on success, negative error code otherwise
121 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -0700122static int hdd_close_ndi(struct hdd_adapter *adapter)
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700123{
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700124 int errno;
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700125 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700126
127 ENTER();
128
129 /* check if the adapter is in NAN Data mode */
130 if (QDF_NDI_MODE != adapter->device_mode) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700131 hdd_err("Interface is not in NDI mode");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700132 return -EINVAL;
133 }
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -0700134 wlan_hdd_netif_queue_control(adapter,
Himanshu Agarwal865201d2017-04-12 15:45:31 +0530135 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -0700136 WLAN_CONTROL_PATH);
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700137
138#ifdef WLAN_OPEN_SOURCE
139 cancel_work_sync(&adapter->ipv4NotifierWorkQueue);
140#endif
141 hdd_deregister_tx_flow_control(adapter);
142
143#ifdef WLAN_NS_OFFLOAD
144#ifdef WLAN_OPEN_SOURCE
145 cancel_work_sync(&adapter->ipv6NotifierWorkQueue);
146#endif
147#endif
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700148 errno = hdd_vdev_destroy(adapter);
149 if (errno)
150 hdd_err("failed to destroy vdev: %d", errno);
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700151
152 /* We are good to close the adapter */
153 hdd_close_adapter(hdd_ctx, adapter, true);
154
155 EXIT();
156 return 0;
157}
158
159/**
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700160 * hdd_is_ndp_allowed() - Indicates if NDP is allowed
161 * @hdd_ctx: hdd context
162 *
163 * NDP is not allowed with any other role active except STA.
164 *
165 * Return: true if allowed, false otherwise
166 */
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700167static bool hdd_is_ndp_allowed(struct hdd_context *hdd_ctx)
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700168{
Jeff Johnson8cb9df12017-08-29 14:28:45 -0700169 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -0700170 struct hdd_station_ctx *sta_ctx;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700171 QDF_STATUS status;
172 hdd_adapter_list_node_t *curr = NULL, *next = NULL;
173
174 status = hdd_get_front_adapter(hdd_ctx, &curr);
175 while (QDF_STATUS_SUCCESS == status) {
176 adapter = curr->pAdapter;
177 if (!adapter)
178 goto next_adapter;
179
180 switch (adapter->device_mode) {
181 case QDF_P2P_GO_MODE:
182 case QDF_SAP_MODE:
183 if (test_bit(SOFTAP_BSS_STARTED,
184 &adapter->event_flags))
185 return false;
186 break;
187 case QDF_P2P_CLIENT_MODE:
188 case QDF_IBSS_MODE:
189 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
190 if (hdd_conn_is_connected(sta_ctx) ||
191 hdd_is_connecting(sta_ctx))
192 return false;
193 break;
194 default:
195 break;
196 }
197next_adapter:
198 status = hdd_get_next_adapter(hdd_ctx, curr, &next);
199 curr = next;
200 }
201
202 return true;
203}
204
205/**
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700206 * hdd_ndi_start_bss() - Start BSS on NAN data interface
207 * @adapter: adapter context
208 * @operating_channel: channel on which the BSS to be started
209 *
210 * Return: 0 on success, error value on failure
211 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -0700212static int hdd_ndi_start_bss(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700213 uint8_t operating_channel)
214{
215 int ret;
216 uint32_t roam_id;
217 hdd_wext_state_t *wext_state =
Deepak Dhamdhere8360d4c2016-06-01 13:24:31 -0700218 WLAN_HDD_GET_WEXT_STATE_PTR(adapter);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700219 tCsrRoamProfile *roam_profile = &wext_state->roamProfile;
220
221 ENTER();
222
223 if (!roam_profile) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700224 hdd_err("No valid roam profile");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700225 return -EINVAL;
226 }
227
228 if (HDD_WMM_USER_MODE_NO_QOS ==
229 (WLAN_HDD_GET_CTX(adapter))->config->WmmMode) {
230 /* QoS not enabled in cfg file*/
231 roam_profile->uapsd_mask = 0;
232 } else {
233 /* QoS enabled, update uapsd mask from cfg file*/
234 roam_profile->uapsd_mask =
235 (WLAN_HDD_GET_CTX(adapter))->config->UapsdMask;
236 }
237
238 roam_profile->csrPersona = adapter->device_mode;
239
240 roam_profile->ChannelInfo.numOfChannels = 1;
241 if (operating_channel) {
242 roam_profile->ChannelInfo.ChannelList = &operating_channel;
243 } else {
244 roam_profile->ChannelInfo.ChannelList[0] =
245 NAN_SOCIAL_CHANNEL_2_4GHZ;
246 }
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700247
248 roam_profile->SSIDs.numOfSSIDs = 1;
249 roam_profile->SSIDs.SSIDList->SSID.length = 0;
250
251 roam_profile->phyMode = eCSR_DOT11_MODE_11ac;
252 roam_profile->BSSType = eCSR_BSS_TYPE_NDI;
253 roam_profile->BSSIDs.numOfBSSIDs = 1;
254 qdf_mem_copy((void *)(roam_profile->BSSIDs.bssid),
255 &adapter->macAddressCurrent.bytes[0],
256 QDF_MAC_ADDR_SIZE);
257
258 roam_profile->AuthType.numEntries = 1;
259 roam_profile->AuthType.authType[0] = eCSR_AUTH_TYPE_OPEN_SYSTEM;
260 roam_profile->EncryptionType.numEntries = 1;
261 roam_profile->EncryptionType.encryptionType[0] = eCSR_ENCRYPT_TYPE_NONE;
262
263 ret = sme_roam_connect(WLAN_HDD_GET_HAL_CTX(adapter),
264 adapter->sessionId, roam_profile, &roam_id);
265 if (QDF_STATUS_SUCCESS != ret) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700266 hdd_err("NDI sme_RoamConnect session %d failed with status %d -> NotConnected",
267 adapter->sessionId, ret);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700268 /* change back to NotConnected */
269 hdd_conn_set_connection_state(adapter,
270 eConnectionState_NotConnected);
271 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700272 hdd_info("sme_RoamConnect issued successfully for NDI");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700273 }
274
275 roam_profile->ChannelInfo.ChannelList = NULL;
276 roam_profile->ChannelInfo.numOfChannels = 0;
277
278 EXIT();
279
280 return ret;
281}
282
Naveen Rawat5a6f8402017-07-03 16:00:11 -0700283/**
284 * hdd_get_random_nan_mac_addr() - generate random non pre-existent mac address
285 * @hdd_ctx: hdd context pointer
286 * @mac_addr: mac address buffer to populate
287 *
288 * Return: status of operation
289 */
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700290static int hdd_get_random_nan_mac_addr(struct hdd_context *hdd_ctx,
Naveen Rawat5a6f8402017-07-03 16:00:11 -0700291 struct qdf_mac_addr *mac_addr)
292{
Jeff Johnson8cb9df12017-08-29 14:28:45 -0700293 struct hdd_adapter *adapter;
Naveen Rawat5a6f8402017-07-03 16:00:11 -0700294 uint8_t i, attempts, max_attempt = 16;
Naveen Rawat5a6f8402017-07-03 16:00:11 -0700295
296 for (attempts = 0; attempts < max_attempt; attempts++) {
297 cds_rand_get_bytes(0, (uint8_t *)mac_addr, sizeof(*mac_addr));
Ravi Joshi04a1c992017-06-11 19:47:54 -0700298
299 /*
300 * Reset multicast bit (bit-0) and set locally-administered bit
301 */
302 mac_addr->bytes[0] = 0x2;
303
Naveen Rawat5a6f8402017-07-03 16:00:11 -0700304 /*
305 * to avoid potential conflict with FW's generated NMI mac addr,
306 * host sets LSB if 6th byte to 0
307 */
308 mac_addr->bytes[5] &= 0xFE;
309
Naveen Rawat5a6f8402017-07-03 16:00:11 -0700310 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
311 if (!qdf_mem_cmp(hdd_ctx->config->intfMacAddr[i].bytes,
312 mac_addr, sizeof(*mac_addr)))
313 continue;
314 }
315
316 adapter = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr->bytes);
317 if (!adapter)
318 return 0;
319 }
320
321 hdd_err("unable to get non-pre-existing mac address in %d attempts",
322 max_attempt);
323
324 return -EINVAL;
325}
326
Naveen Rawat97500352017-03-22 10:07:58 -0700327#ifndef WLAN_FEATURE_NAN_CONVERGENCE
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700328/**
329 * hdd_ndi_create_req_handler() - NDI create request handler
330 * @hdd_ctx: hdd context
331 * @tb: parsed NL attribute list
332 *
333 * Return: 0 on success or error code on failure
334 */
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700335static int hdd_ndi_create_req_handler(struct hdd_context *hdd_ctx,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700336 struct nlattr **tb)
337{
Jeff Johnson8cb9df12017-08-29 14:28:45 -0700338 struct hdd_adapter *adapter;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700339 char *iface_name;
340 uint16_t transaction_id;
341 int ret;
342 struct nan_datapath_ctx *ndp_ctx;
343 uint8_t op_channel =
344 hdd_ctx->config->nan_datapath_ndi_channel;
Ravi Joshi9771d432017-06-26 13:58:12 -0700345 struct qdf_mac_addr random_ndi_mac;
346 uint8_t *ndi_mac_addr;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700347
348 ENTER();
349
350 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700351 hdd_err("Interface name string is unavailable");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700352 return -EINVAL;
353 }
354 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
355
356 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700357 hdd_err("transaction id is unavailable");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700358 return -EINVAL;
359 }
360 transaction_id =
361 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
362
363 /* Check for an existing interface of NDI type */
364 adapter = hdd_get_adapter(hdd_ctx, QDF_NDI_MODE);
365 if (adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700366 hdd_err("Cannot support more than one NDI");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700367 return -EEXIST;
368 }
369
Ravi Joshi9771d432017-06-26 13:58:12 -0700370 if (hdd_ctx->config->is_ndi_mac_randomized) {
371 if (hdd_get_random_nan_mac_addr(hdd_ctx, &random_ndi_mac)) {
372 hdd_err("get random mac address failed");
373 return -EINVAL;
374 }
375 ndi_mac_addr = &random_ndi_mac.bytes[0];
376 } else {
377 ndi_mac_addr = wlan_hdd_get_intf_addr(hdd_ctx);
378 if (!ndi_mac_addr) {
379 hdd_err("get intf address failed");
380 return -EINVAL;
381 }
382 }
383
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700384 adapter = hdd_open_adapter(hdd_ctx, QDF_NDI_MODE, iface_name,
Ravi Joshi9771d432017-06-26 13:58:12 -0700385 ndi_mac_addr, NET_NAME_UNKNOWN, true);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700386 if (!adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700387 hdd_err("hdd_open_adapter failed");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700388 return -ENOMEM;
389 }
390
391 /*
392 * Create transaction id is required to be saved since the firmware
393 * does not honor the transaction id for create request
394 */
395 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
396 ndp_ctx->ndp_create_transaction_id = transaction_id;
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700397 ndp_ctx->state = NAN_DATA_NDI_CREATING_STATE;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700398
399 /*
400 * The NAN data interface has been created at this point.
401 * Unlike traditional device modes, where the higher application
402 * layer initiates connect / join / start, the NAN data interface
403 * does not have any such formal requests. The NDI create request
404 * is responsible for starting the BSS as well.
405 */
406 if (op_channel != NAN_SOCIAL_CHANNEL_2_4GHZ ||
407 op_channel != NAN_SOCIAL_CHANNEL_5GHZ_LOWER_BAND ||
408 op_channel != NAN_SOCIAL_CHANNEL_5GHZ_UPPER_BAND) {
409 /* start NDI on the default 2.4 GHz social channel */
410 op_channel = NAN_SOCIAL_CHANNEL_2_4GHZ;
411 }
412 ret = hdd_ndi_start_bss(adapter, op_channel);
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700413 if (0 > ret) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700414 hdd_err("NDI start bss failed");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700415 /* Start BSS failed, delete the interface */
416 hdd_close_ndi(adapter);
417 }
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700418
419 EXIT();
420 return ret;
421}
422
423/**
424 * hdd_ndi_delete_req_handler() - NDI delete request handler
425 * @hdd_ctx: hdd context
426 * @tb: parsed NL attribute list
427 *
428 * Return: 0 on success or error code on failure
429 */
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700430static int hdd_ndi_delete_req_handler(struct hdd_context *hdd_ctx,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700431 struct nlattr **tb)
432{
Jeff Johnson8cb9df12017-08-29 14:28:45 -0700433 struct hdd_adapter *adapter;
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700434 char *iface_name;
435 uint16_t transaction_id;
436 struct nan_datapath_ctx *ndp_ctx;
437 int ret;
Jeff Johnson40dae4e2017-08-29 14:00:25 -0700438 struct hdd_station_ctx *sta_ctx;
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700439
440 ENTER();
441
442 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700443 hdd_err("Interface name string is unavailable");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700444 return -EINVAL;
445 }
446
447 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
448
449 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700450 hdd_err("Transaction id is unavailable");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700451 return -EINVAL;
452 }
453
454 transaction_id =
455 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
456
457 /* Check if there is already an existing inteface with the same name */
458 adapter = hdd_get_adapter(hdd_ctx, QDF_NDI_MODE);
459 if (!adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700460 hdd_err("NAN data interface %s is not available", iface_name);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700461 return -EINVAL;
462 }
463
464 /* check if adapter is in NDI mode */
465 if (QDF_NDI_MODE != adapter->device_mode) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700466 hdd_err("Interface %s is not in NDI mode", iface_name);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700467 return -EINVAL;
468 }
469
470 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
471 if (!ndp_ctx) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700472 hdd_err("ndp_ctx is NULL");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700473 return -EINVAL;
474 }
475
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700476 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
477 if (!sta_ctx) {
478 hdd_err("sta_ctx is NULL");
479 return -EINVAL;
480 }
481
Naveen Rawatf28315c2016-06-29 18:06:02 -0700482 /* check if there are active peers on the adapter */
483 if (ndp_ctx->active_ndp_peers > 0) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700484 hdd_err("NDP peers active: %d, cannot delete NDI",
Naveen Rawatf28315c2016-06-29 18:06:02 -0700485 ndp_ctx->active_ndp_peers);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700486 return -EINVAL;
487 }
488
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700489 /*
490 * Since, the interface is being deleted, remove the
491 * broadcast id.
492 */
493 hdd_ctx->sta_to_adapter[sta_ctx->broadcast_staid] = 0;
494 sta_ctx->broadcast_staid = HDD_WLAN_INVALID_STA_ID;
495
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700496 ndp_ctx->ndp_delete_transaction_id = transaction_id;
497 ndp_ctx->state = NAN_DATA_NDI_DELETING_STATE;
498
499 /* Delete the interface */
500 ret = __wlan_hdd_del_virtual_intf(hdd_ctx->wiphy, &adapter->wdev);
501 if (ret < 0)
Naveen Rawatba4f6612016-07-05 12:03:16 -0700502 hdd_err("NDI delete request failed");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700503 else
Naveen Rawatba4f6612016-07-05 12:03:16 -0700504 hdd_err("NDI delete request successfully issued");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700505
506 return ret;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700507}
508
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700509/**
510 * hdd_ndp_initiator_req_handler() - NDP initiator request handler
511 * @hdd_ctx: hdd context
512 * @tb: parsed NL attribute list
513 *
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800514 * tb will contain following vendor attributes:
515 * QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR
516 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID
517 * QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL - optional
Ravi Joshi71e82f32017-02-09 23:15:16 -0800518 * QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL_CONFIG - optional
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800519 * QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID
520 * QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR
521 * QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO - optional
522 * QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS - optional
523 * QCA_WLAN_VENDOR_ATTR_NDP_PMK - optional
524 * QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE - optional
525 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700526 * Return: 0 on success or error code on failure
527 */
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700528static int hdd_ndp_initiator_req_handler(struct hdd_context *hdd_ctx,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700529 struct nlattr **tb)
530{
Jeff Johnson8cb9df12017-08-29 14:28:45 -0700531 struct hdd_adapter *adapter;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700532 char *iface_name;
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -0700533 struct ndp_initiator_req req = {0};
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700534 QDF_STATUS status;
535 uint32_t ndp_qos_cfg;
536 tHalHandle hal = hdd_ctx->hHal;
537 struct nan_datapath_ctx *ndp_ctx;
538
539 ENTER();
540
541 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700542 hdd_err("Interface name string is unavailable");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700543 return -EINVAL;
544 }
545
546 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
547 /* Check for interface in NDI mode */
548 adapter = hdd_get_adapter(hdd_ctx, QDF_NDI_MODE);
549 if (!adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700550 hdd_err("NAN data interface %s not available", iface_name);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700551 return -EINVAL;
552 }
553
554 /* NAN data path coexists only with STA interface */
555 if (false == hdd_is_ndp_allowed(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700556 hdd_err("Unsupported concurrency for NAN datapath");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700557 return -EPERM;
558 }
559
560 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
561
562 if (ndp_ctx->state == NAN_DATA_NDI_DELETED_STATE ||
563 ndp_ctx->state == NAN_DATA_NDI_DELETING_STATE ||
564 ndp_ctx->state == NAN_DATA_NDI_CREATING_STATE) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700565 hdd_err("Data request not allowed in NDI current state: %d",
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700566 ndp_ctx->state);
567 return -EINVAL;
568 }
569
570 req.vdev_id = adapter->sessionId;
571
572 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700573 hdd_err("Transaction ID is unavailable");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700574 return -EINVAL;
575 }
576 req.transaction_id =
577 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
578
Naveen Rawat0a017052016-10-19 14:17:07 -0700579 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL])
580 req.channel =
581 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL]);
582
Ravi Joshi71e82f32017-02-09 23:15:16 -0800583 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL_CONFIG])
Naveen Rawat0a017052016-10-19 14:17:07 -0700584 req.channel_cfg =
585 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL_CONFIG]);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700586
587 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700588 hdd_err("NDP service instance ID is unavailable");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700589 return -EINVAL;
590 }
591 req.service_instance_id =
Naveen Rawat19da3d12016-08-16 12:39:38 -0700592 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID]);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700593
594 qdf_mem_copy(req.self_ndi_mac_addr.bytes,
595 adapter->macAddressCurrent.bytes, QDF_MAC_ADDR_SIZE);
596
597 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700598 hdd_err("NDI peer discovery mac addr is unavailable");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700599 return -EINVAL;
600 }
601 qdf_mem_copy(req.peer_discovery_mac_addr.bytes,
602 nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR]),
603 QDF_MAC_ADDR_SIZE);
604
Naveen Rawat90ae3082016-06-29 18:22:59 -0700605 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]) {
606 req.ndp_info.ndp_app_info_len =
607 nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]);
608 req.ndp_info.ndp_app_info =
609 nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700610 }
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700611
612 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS]) {
613 /* at present ndp config stores 4 bytes QOS info only */
614 req.ndp_config.ndp_cfg_len = 4;
615 req.ndp_config.ndp_cfg = (uint8_t *)&ndp_qos_cfg;
616 ndp_qos_cfg =
617 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS]);
618 }
619
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800620 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE] &&
621 !tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]) {
622 hdd_err("PMK cannot be absent when CSID is present.");
623 return -EINVAL;
624 }
625
626 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]) {
627 req.pmk.pmk = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]);
628 req.pmk.pmk_len = nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]);
629 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD,
630 QDF_TRACE_LEVEL_DEBUG,
631 req.pmk.pmk, req.pmk.pmk_len);
632 }
633
634 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE]) {
635 req.ncs_sk_type =
636 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE]);
637
638 }
639
Ravi Joshi71e82f32017-02-09 23:15:16 -0800640 hdd_info("vdev_id: %d, transaction_id: %d, channel: %d, channel_cfg: %d, service_instance_id: %d, ndp_app_info_len: %d, csid: %d, peer_discovery_mac_addr: %pM",
641 req.vdev_id, req.transaction_id, req.channel, req.channel_cfg,
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700642 req.service_instance_id, req.ndp_info.ndp_app_info_len,
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800643 req.ncs_sk_type, req.peer_discovery_mac_addr.bytes);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700644 status = sme_ndp_initiator_req_handler(hal, &req);
645 if (status != QDF_STATUS_SUCCESS) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700646 hdd_err("sme_ndp_initiator_req_handler failed, status: %d",
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700647 status);
648 return -ECOMM;
649 }
650 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700651 return 0;
652}
653
654/**
655 * hdd_ndp_responder_req_handler() - NDP responder request handler
656 * @hdd_ctx: hdd context
657 * @tb: parsed NL attribute list
658 *
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800659 * tb includes following vendor attributes:
660 * QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR
661 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID
662 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID
663 * QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE
664 * QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO - optional
665 * QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS - optional
666 * QCA_WLAN_VENDOR_ATTR_NDP_PMK - optional
667 * QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE - optional
668 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700669 * Return: 0 on success or error code on failure
670 */
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700671static int hdd_ndp_responder_req_handler(struct hdd_context *hdd_ctx,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700672 struct nlattr **tb)
673{
Jeff Johnson8cb9df12017-08-29 14:28:45 -0700674 struct hdd_adapter *adapter;
Abhishek Singh4fef7472016-06-06 11:36:03 -0700675 char *iface_name;
676 struct ndp_responder_req req = {0};
677 QDF_STATUS status;
678 int ret = 0;
679 struct nan_datapath_ctx *ndp_ctx;
680 uint32_t ndp_qos_cfg;
681
682 ENTER();
683
684 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700685 hdd_err("Interface name string is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700686 return -EINVAL;
687 }
688
689 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
690 /* Check if there is already an existing NAN interface */
691 adapter = hdd_get_adapter(hdd_ctx, QDF_NDI_MODE);
692 if (!adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700693 hdd_err("NAN data interface %s not available", iface_name);
Abhishek Singh4fef7472016-06-06 11:36:03 -0700694 return -EINVAL;
695 }
696
697 if (QDF_NDI_MODE != adapter->device_mode) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700698 hdd_err("Interface %s not in NDI mode", iface_name);
Abhishek Singh4fef7472016-06-06 11:36:03 -0700699 return -EINVAL;
700 }
701
702 /* NAN data path coexists only with STA interface */
703 if (!hdd_is_ndp_allowed(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700704 hdd_err("Unsupported concurrency for NAN datapath");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700705 return -EINVAL;
706 }
707
708 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
709
710 if (ndp_ctx->state == NAN_DATA_NDI_DELETED_STATE ||
711 ndp_ctx->state == NAN_DATA_NDI_DELETING_STATE ||
712 ndp_ctx->state == NAN_DATA_NDI_CREATING_STATE) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700713 hdd_err("Data request not allowed in current NDI state: %d",
Abhishek Singh4fef7472016-06-06 11:36:03 -0700714 ndp_ctx->state);
715 return -EAGAIN;
716 }
717
718 req.vdev_id = adapter->sessionId;
719
720 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700721 hdd_err("Transaction ID is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700722 return -EINVAL;
723 }
724 req.transaction_id =
725 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
726
727 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700728 hdd_err("Instance ID is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700729 return -EINVAL;
730 }
731 req.ndp_instance_id =
732 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID]);
733
734 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700735 hdd_err("ndp_rsp is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700736 return -EINVAL;
737 }
738 req.ndp_rsp = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE]);
739
740 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]) {
741 req.ndp_info.ndp_app_info_len =
742 nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]);
743 if (req.ndp_info.ndp_app_info_len) {
744 req.ndp_info.ndp_app_info =
745 nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]);
746 }
747 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700748 hdd_info("NDP app info is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700749 }
750 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS]) {
751 /* at present ndp config stores 4 bytes QOS info only */
752 req.ndp_config.ndp_cfg_len = 4;
753 ndp_qos_cfg =
754 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS]);
755 req.ndp_config.ndp_cfg = (uint8_t *)&ndp_qos_cfg;
756 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700757 hdd_info("NDP config data is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700758 }
759
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800760 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE] &&
761 !tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]) {
762 hdd_err("PMK cannot be absent when CSID is present.");
763 return -EINVAL;
764 }
765
766 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]) {
767 req.pmk.pmk = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]);
768 req.pmk.pmk_len = nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]);
769 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD,
770 QDF_TRACE_LEVEL_DEBUG,
771 req.pmk.pmk, req.pmk.pmk_len);
772 }
773
774 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE]) {
775 req.ncs_sk_type =
776 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE]);
777
778 }
779
780 hdd_info("vdev_id: %d, transaction_id: %d, ndp_rsp %d, ndp_instance_id: %d, ndp_app_info_len: %d, csid: %d",
Abhishek Singh4fef7472016-06-06 11:36:03 -0700781 req.vdev_id, req.transaction_id, req.ndp_rsp,
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800782 req.ndp_instance_id, req.ndp_info.ndp_app_info_len,
783 req.ncs_sk_type);
Abhishek Singh4fef7472016-06-06 11:36:03 -0700784
785 status = sme_ndp_responder_req_handler(hdd_ctx->hHal, &req);
786 if (status != QDF_STATUS_SUCCESS) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700787 hdd_err("sme_ndp_initiator_req_handler failed, status: %d",
Abhishek Singh4fef7472016-06-06 11:36:03 -0700788 status);
789 ret = -EINVAL;
790 }
791
792 EXIT();
793 return ret;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700794}
795
796/**
797 * hdd_ndp_end_req_handler() - NDP end request handler
798 * @hdd_ctx: hdd context
799 * @tb: parsed NL attribute list
800 *
801 * Return: 0 on success or error code on failure
802 */
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700803static int hdd_ndp_end_req_handler(struct hdd_context *hdd_ctx, struct nlattr **tb)
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700804{
Naveen Rawatf28315c2016-06-29 18:06:02 -0700805 struct ndp_end_req req = {0};
806 QDF_STATUS status;
807 tHalHandle hal = hdd_ctx->hHal;
808
809 ENTER();
810
811 /* NAN data path coexists only with STA interface */
812 if (!hdd_is_ndp_allowed(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700813 hdd_err("Unsupported concurrency for NAN datapath");
Naveen Rawatf28315c2016-06-29 18:06:02 -0700814 return -EINVAL;
815 }
816
817 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700818 hdd_err("Transaction ID is unavailable");
Naveen Rawatf28315c2016-06-29 18:06:02 -0700819 return -EINVAL;
820 }
821 req.transaction_id =
822 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
823
824 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700825 hdd_err("NDP instance ID array is unavailable");
Naveen Rawatf28315c2016-06-29 18:06:02 -0700826 return -EINVAL;
827 }
828
829 req.num_ndp_instances =
830 nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY]) /
831 sizeof(uint32_t);
832 if (0 >= req.num_ndp_instances) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700833 hdd_err("Num NDP instances is 0");
Naveen Rawatf28315c2016-06-29 18:06:02 -0700834 return -EINVAL;
835 }
836 req.ndp_ids = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY]);
837
Naveen Rawatba4f6612016-07-05 12:03:16 -0700838 hdd_info("sending ndp_end_req to SME, transaction_id: %d",
Naveen Rawatf28315c2016-06-29 18:06:02 -0700839 req.transaction_id);
840
841 status = sme_ndp_end_req_handler(hal, &req);
842 if (status != QDF_STATUS_SUCCESS) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700843 hdd_err("sme_ndp_end_req_handler failed, status: %d",
Naveen Rawatf28315c2016-06-29 18:06:02 -0700844 status);
845 return -ECOMM;
846 }
847 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700848 return 0;
849}
850
851/**
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700852 * hdd_ndp_iface_create_rsp_handler() - NDP iface create response handler
853 * @adapter: pointer to adapter context
854 * @rsp_params: response parameters
855 *
856 * The function is expected to send a response back to the user space
857 * even if the creation of BSS has failed
858 *
859 * Following vendor event is sent to cfg80211:
860 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
861 * QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_CREATE (4 bytes)
862 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
Rakesh Sunkid92d1082017-01-04 15:14:28 -0800863 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700864 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE
865 *
866 * Return: none
867 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -0700868static void hdd_ndp_iface_create_rsp_handler(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700869 void *rsp_params)
870{
871 struct sk_buff *vendor_event;
Jeff Johnson88dc4f92017-08-28 11:51:34 -0700872 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700873 struct ndi_create_rsp *ndi_rsp = (struct ndi_create_rsp *)rsp_params;
874 uint32_t data_len = (3 * sizeof(uint32_t)) + sizeof(uint16_t) +
875 NLMSG_HDRLEN + (4 * NLA_HDRLEN);
876 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700877 bool create_fail = false;
878 uint8_t create_transaction_id = 0;
Naveen Rawate21103f2016-07-08 14:18:00 -0700879 uint32_t create_status = NDP_RSP_STATUS_ERROR;
880 uint32_t create_reason = NDP_NAN_DATA_IFACE_CREATE_FAILED;
Jeff Johnson40dae4e2017-08-29 14:00:25 -0700881 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700882 struct qdf_mac_addr bc_mac_addr = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Kapil Guptaffa26022017-08-16 12:20:09 +0530883 tCsrRoamInfo *roam_info;
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700884 tSirBssDescription tmp_bss_descp = {0};
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700885
886 ENTER();
887
Kapil Guptaffa26022017-08-16 12:20:09 +0530888 roam_info = qdf_mem_malloc(sizeof(*roam_info));
889 if (!roam_info) {
890 hdd_err("failed to allocate memory");
891 return;
892 }
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700893 if (wlan_hdd_validate_context(hdd_ctx))
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700894 /* No way the driver can send response back to user space */
Kapil Guptaffa26022017-08-16 12:20:09 +0530895 qdf_mem_free(roam_info);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700896 return;
897
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700898 if (ndi_rsp) {
899 create_status = ndi_rsp->status;
Naveen Rawate21103f2016-07-08 14:18:00 -0700900 create_reason = ndi_rsp->reason;
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700901 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700902 hdd_err("Invalid ndi create response");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700903 create_fail = true;
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700904 }
905
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700906 if (ndp_ctx) {
907 create_transaction_id = ndp_ctx->ndp_create_transaction_id;
908 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700909 hdd_err("ndp_ctx is NULL");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700910 create_fail = true;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700911 }
912
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700913 if (!sta_ctx) {
914 hdd_err("sta_ctx is NULL");
915 create_fail = true;
916 }
917
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700918 /* notify response to the upper layer */
919 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
920 NULL,
921 data_len,
922 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
923 cds_get_gfp_flags());
924
925 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700926 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700927 create_fail = true;
928 goto close_ndi;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700929 }
930
931 /* Sub vendor command */
932 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
933 QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_CREATE)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700934 hdd_err("QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD put fail");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700935 goto nla_put_failure;
936 }
937
938 /* Transaction id */
939 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700940 create_transaction_id)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700941 hdd_err("VENDOR_ATTR_NDP_TRANSACTION_ID put fail");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700942 goto nla_put_failure;
943 }
944
945 /* Status code */
Rakesh Sunkid92d1082017-01-04 15:14:28 -0800946 if (nla_put_u32(vendor_event,
947 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700948 create_status)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700949 hdd_err("VENDOR_ATTR_NDP_DRV_RETURN_TYPE put fail");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700950 goto nla_put_failure;
951 }
952
953 /* Status return value */
954 if (nla_put_u32(vendor_event,
Naveen Rawat8d63a592016-06-29 18:30:59 -0700955 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
Naveen Rawate21103f2016-07-08 14:18:00 -0700956 create_reason)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700957 hdd_err("VENDOR_ATTR_NDP_DRV_RETURN_VALUE put fail");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700958 goto nla_put_failure;
959 }
960
Naveen Rawatba4f6612016-07-05 12:03:16 -0700961 hdd_info("sub command: %d, value: %d",
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700962 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
963 QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_CREATE);
Naveen Rawatba4f6612016-07-05 12:03:16 -0700964 hdd_info("create transaction id: %d, value: %d",
965 QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID, create_transaction_id);
966 hdd_info("status code: %d, value: %d",
Rakesh Sunkid92d1082017-01-04 15:14:28 -0800967 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
968 create_status);
Naveen Rawatba4f6612016-07-05 12:03:16 -0700969 hdd_info("Return value: %d, value: %d",
Naveen Rawate21103f2016-07-08 14:18:00 -0700970 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE, create_reason);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700971
972 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
973
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700974 if (!create_fail && ndi_rsp->status == QDF_STATUS_SUCCESS) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700975 hdd_err("NDI interface successfully created");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700976 ndp_ctx->ndp_create_transaction_id = 0;
977 ndp_ctx->state = NAN_DATA_NDI_CREATED_STATE;
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -0700978 wlan_hdd_netif_queue_control(adapter,
979 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
980 WLAN_CONTROL_PATH);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700981 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700982 hdd_err("NDI interface creation failed with reason %d",
Naveen Rawate21103f2016-07-08 14:18:00 -0700983 create_reason);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700984 }
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700985
986 /* Something went wrong while starting the BSS */
987 if (create_fail)
988 goto close_ndi;
989
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700990 sta_ctx->broadcast_staid = ndi_rsp->sta_id;
991 hdd_save_peer(sta_ctx, sta_ctx->broadcast_staid, &bc_mac_addr);
Kapil Guptaffa26022017-08-16 12:20:09 +0530992 hdd_roam_register_sta(adapter, roam_info,
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700993 sta_ctx->broadcast_staid,
994 &bc_mac_addr, &tmp_bss_descp);
995 hdd_ctx->sta_to_adapter[sta_ctx->broadcast_staid] = adapter;
996
Kapil Guptaffa26022017-08-16 12:20:09 +0530997 qdf_mem_free(roam_info);
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700998
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700999 EXIT();
1000 return;
1001
1002nla_put_failure:
1003 kfree_skb(vendor_event);
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -07001004close_ndi:
1005 hdd_close_ndi(adapter);
Kapil Guptaffa26022017-08-16 12:20:09 +05301006 qdf_mem_free(roam_info);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001007}
1008
1009/**
1010 * hdd_ndp_iface_delete_rsp_handler() - NDP iface delete response handler
1011 * @adapter: pointer to adapter context
1012 * @rsp_params: response parameters
1013 *
1014 * Return: none
1015 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001016static void hdd_ndp_iface_delete_rsp_handler(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001017 void *rsp_params)
1018{
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001019 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001020 struct ndi_delete_rsp *ndi_rsp = rsp_params;
Naveen Rawat8d63a592016-06-29 18:30:59 -07001021 struct nan_datapath_ctx *ndp_ctx;
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001022
1023 if (wlan_hdd_validate_context(hdd_ctx))
1024 return;
1025
1026 if (!ndi_rsp) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001027 hdd_err("Invalid ndi delete response");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001028 return;
1029 }
1030
Naveen Rawat8d63a592016-06-29 18:30:59 -07001031 if (ndi_rsp->status == NDP_RSP_STATUS_SUCCESS)
Naveen Rawatba4f6612016-07-05 12:03:16 -07001032 hdd_err("NDI BSS successfully stopped");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001033 else
Naveen Rawatba4f6612016-07-05 12:03:16 -07001034 hdd_err("NDI BSS stop failed with reason %d", ndi_rsp->reason);
Naveen Rawat8d63a592016-06-29 18:30:59 -07001035
1036 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
1037 ndp_ctx->ndi_delete_rsp_reason = ndi_rsp->reason;
1038 ndp_ctx->ndi_delete_rsp_status = ndi_rsp->status;
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -07001039 wlan_hdd_netif_queue_control(adapter,
1040 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
1041 WLAN_CONTROL_PATH);
Naveen Rawat8d63a592016-06-29 18:30:59 -07001042
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001043 complete(&adapter->disconnect_comp_var);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001044}
1045
1046/**
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001047 * hdd_ndp_session_end_handler() - NDI session termination handler
1048 * @adapter: pointer to adapter context
1049 *
1050 * Following vendor event is sent to cfg80211:
1051 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1052 * QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_DELETE (4 bytes)
1053 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001054 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001055 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE (4 bytes)
1056 *
1057 * Return: none
1058 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001059void hdd_ndp_session_end_handler(struct hdd_adapter *adapter)
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001060{
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001061 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001062 struct sk_buff *vendor_event;
1063 struct nan_datapath_ctx *ndp_ctx;
1064 uint32_t data_len = sizeof(uint32_t) * (3 + sizeof(uint16_t)) +
1065 (NLA_HDRLEN * 4) + NLMSG_HDRLEN;
1066
1067 ENTER();
1068
1069 if (wlan_hdd_validate_context(hdd_ctx))
1070 return;
1071
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001072 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
1073 if (!ndp_ctx) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001074 hdd_err("ndp context is NULL");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001075 return;
1076 }
1077
1078 /*
1079 * The virtual adapters are stopped and closed even during
1080 * driver unload or stop, the service layer is not required
1081 * to be informed in that case (response is not expected)
1082 */
1083 if (NAN_DATA_NDI_DELETING_STATE != ndp_ctx->state) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001084 hdd_err("NDI interface %s deleted", adapter->dev->name);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001085 return;
1086 }
1087
1088 /* notify response to the upper layer */
1089 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
1090 NULL,
1091 data_len,
1092 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1093 GFP_KERNEL);
1094
1095 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001096 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001097 return;
1098 }
1099
1100 /* Sub vendor command goes first */
1101 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1102 QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_DELETE)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001103 hdd_err("VENDOR_ATTR_NDP_SUBCMD put fail");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001104 goto failure;
1105 }
1106
1107 /* Transaction id */
1108 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1109 ndp_ctx->ndp_delete_transaction_id)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001110 hdd_err("VENDOR_ATTR_NDP_TRANSACTION_ID put fail");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001111 goto failure;
1112 }
1113
1114 /* Status code */
1115 if (nla_put_u32(vendor_event,
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001116 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001117 ndp_ctx->ndi_delete_rsp_status)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001118 hdd_err("VENDOR_ATTR_NDP_DRV_RETURN_TYPE put fail");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001119 goto failure;
1120 }
1121
1122 /* Status return value */
1123 if (nla_put_u32(vendor_event,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001124 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
1125 ndp_ctx->ndi_delete_rsp_reason)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001126 hdd_err("VENDOR_ATTR_NDP_DRV_RETURN_VALUE put fail");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001127 goto failure;
1128 }
1129
Naveen Rawatba4f6612016-07-05 12:03:16 -07001130 hdd_info("sub command: %d, value: %d", QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001131 QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_DELETE);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001132 hdd_info("delete transaction id: %d, value: %d",
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001133 QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1134 ndp_ctx->ndp_delete_transaction_id);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001135 hdd_info("status code: %d, value: %d",
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001136 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001137 ndp_ctx->ndi_delete_rsp_status);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001138 hdd_info("Return value: %d, value: %d",
Naveen Rawat8d63a592016-06-29 18:30:59 -07001139 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
1140 ndp_ctx->ndi_delete_rsp_reason);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001141
1142 ndp_ctx->ndp_delete_transaction_id = 0;
1143 ndp_ctx->state = NAN_DATA_NDI_DELETED_STATE;
1144
1145 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1146
1147 EXIT();
1148 return;
1149
1150failure:
1151 kfree_skb(vendor_event);
1152}
1153
1154
1155/**
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001156 * hdd_ndp_initiator_rsp_handler() - NDP initiator response handler
1157 * @adapter: pointer to adapter context
1158 * @rsp_params: response parameters
1159 *
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001160 * Following vendor event is sent to cfg80211:
1161 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1162 * QCA_WLAN_VENDOR_ATTR_NDP_INITIATOR_RESPONSE (4 bytes)
1163 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
1164 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID (4 bytes)
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001165 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001166 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE (4 bytes)
1167 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001168 * Return: none
1169 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001170static void hdd_ndp_initiator_rsp_handler(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001171 void *rsp_params)
1172{
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001173 struct sk_buff *vendor_event;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001174 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001175 struct ndp_initiator_rsp *rsp = rsp_params;
1176 uint32_t data_len = (4 * sizeof(uint32_t)) + (1 * sizeof(uint16_t)) +
1177 NLMSG_HDRLEN + (5 * NLA_HDRLEN);
1178
1179 ENTER();
1180
1181 if (!rsp) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001182 hdd_err("Invalid NDP Initator response");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001183 return;
1184 }
1185
1186 if (0 != wlan_hdd_validate_context(hdd_ctx))
1187 return;
1188
1189 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy, NULL,
1190 data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1191 GFP_KERNEL);
1192 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001193 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001194 return;
1195 }
1196
1197 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1198 QCA_WLAN_VENDOR_ATTR_NDP_INITIATOR_RESPONSE))
1199 goto ndp_initiator_rsp_nla_failed;
1200
1201 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1202 rsp->transaction_id))
1203 goto ndp_initiator_rsp_nla_failed;
1204
1205 if (nla_put_u32(vendor_event,
1206 QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID,
1207 rsp->ndp_instance_id))
1208 goto ndp_initiator_rsp_nla_failed;
1209
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001210 if (nla_put_u32(vendor_event,
1211 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001212 rsp->status))
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001213 goto ndp_initiator_rsp_nla_failed;
1214
1215 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001216 rsp->reason))
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001217 goto ndp_initiator_rsp_nla_failed;
1218
Naveen Rawatba4f6612016-07-05 12:03:16 -07001219 hdd_info("NDP Initiator rsp sent, tid:%d, instance id:%d, status:%d, reason: %d",
Naveen Rawat8d63a592016-06-29 18:30:59 -07001220 rsp->transaction_id, rsp->ndp_instance_id, rsp->status,
1221 rsp->reason);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001222 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1223 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001224 return;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001225ndp_initiator_rsp_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001226 hdd_err("nla_put api failed");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001227 kfree_skb(vendor_event);
1228 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001229}
1230
1231/**
1232 * hdd_ndp_new_peer_ind_handler() - NDP new peer indication handler
1233 * @adapter: pointer to adapter context
1234 * @ind_params: indication parameters
1235 *
1236 * Return: none
1237 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001238static void hdd_ndp_new_peer_ind_handler(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001239 void *ind_params)
1240{
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001241 struct sme_ndp_peer_ind *new_peer_ind = ind_params;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001242 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001243 tSirBssDescription tmp_bss_descp = {0};
Kapil Guptaffa26022017-08-16 12:20:09 +05301244 tCsrRoamInfo *roam_info;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001245 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
Jeff Johnson40dae4e2017-08-29 14:00:25 -07001246 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001247
1248 ENTER();
1249
Kapil Guptaffa26022017-08-16 12:20:09 +05301250 roam_info = qdf_mem_malloc(sizeof(*roam_info));
1251 if (!roam_info) {
1252 hdd_err("failed to allocate memory");
1253 return;
1254 }
1255
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001256 if (NULL == ind_params) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001257 hdd_err("Invalid new NDP peer params");
Kapil Guptaffa26022017-08-16 12:20:09 +05301258 goto free;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001259 }
Naveen Rawatba4f6612016-07-05 12:03:16 -07001260 hdd_info("session_id: %d, peer_mac: %pM, sta_id: %d",
Naveen Rawatf28315c2016-06-29 18:06:02 -07001261 new_peer_ind->session_id, new_peer_ind->peer_mac_addr.bytes,
1262 new_peer_ind->sta_id);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001263
1264 /* save peer in ndp ctx */
1265 if (false == hdd_save_peer(sta_ctx, new_peer_ind->sta_id,
1266 &new_peer_ind->peer_mac_addr)) {
Kapil Guptaffa26022017-08-16 12:20:09 +05301267 hdd_warn("Ndp peer table full. cannot save new peer");
1268 goto free;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001269 }
1270
1271 /* this function is called for each new peer */
1272 ndp_ctx->active_ndp_peers++;
Naveen Rawatba4f6612016-07-05 12:03:16 -07001273 hdd_info("vdev_id: %d, num_peers: %d", adapter->sessionId,
1274 ndp_ctx->active_ndp_peers);
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -07001275
Kapil Guptaffa26022017-08-16 12:20:09 +05301276 hdd_roam_register_sta(adapter, roam_info, new_peer_ind->sta_id,
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001277 &new_peer_ind->peer_mac_addr, &tmp_bss_descp);
1278 hdd_ctx->sta_to_adapter[new_peer_ind->sta_id] = adapter;
1279 /* perform following steps for first new peer ind */
1280 if (ndp_ctx->active_ndp_peers == 1) {
Varun Reddy Yeturu9e0032c2017-07-12 18:39:59 -07001281 hdd_conn_set_connection_state(adapter,
1282 eConnectionState_NdiConnected);
Kapil Guptaffa26022017-08-16 12:20:09 +05301283 hdd_wmm_connect(adapter, roam_info, eCSR_BSS_TYPE_NDI);
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -07001284 wlan_hdd_netif_queue_control(adapter,
1285 WLAN_WAKE_ALL_NETIF_QUEUE, WLAN_CONTROL_PATH);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001286 }
Kapil Guptaffa26022017-08-16 12:20:09 +05301287free:
1288 qdf_mem_free(roam_info);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001289 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001290}
1291
1292/**
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001293 * hdd_ndp_peer_departed_ind_handler() - Handle NDP peer departed indication
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001294 * @adapter: pointer to adapter context
1295 * @ind_params: indication parameters
1296 *
1297 * Return: none
1298 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001299static void hdd_ndp_peer_departed_ind_handler(struct hdd_adapter *adapter,
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001300 void *ind_params)
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001301{
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001302 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001303 struct sme_ndp_peer_ind *peer_ind = ind_params;
1304 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
Jeff Johnson40dae4e2017-08-29 14:00:25 -07001305 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001306
1307 hdd_roam_deregister_sta(adapter, peer_ind->sta_id);
1308 hdd_delete_peer(sta_ctx, peer_ind->sta_id);
1309 hdd_ctx->sta_to_adapter[peer_ind->sta_id] = 0;
1310
1311 if (--ndp_ctx->active_ndp_peers == 0) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001312 hdd_info("No more ndp peers.");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001313 hdd_conn_set_connection_state(adapter,
1314 eConnectionState_NdiDisconnected);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001315 hdd_info("Stop netif tx queues.");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001316 wlan_hdd_netif_queue_control(adapter, WLAN_STOP_ALL_NETIF_QUEUE,
1317 WLAN_CONTROL_PATH);
1318 }
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001319}
1320
1321/**
1322 * hdd_ndp_confirm_ind_handler() - NDP confirm indication handler
1323 * @adapter: pointer to adapter context
1324 * @ind_params: indication parameters
1325 *
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001326 * Following vendor event is sent to cfg80211:
1327 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1328 * QCA_WLAN_VENDOR_ATTR_NDP_CONFIRM_IND (4 bytes)
1329 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID (4 bytes)
1330 * QCA_WLAN_VENDOR_ATTR_NDP_NDI_MAC_ADDR (6 bytes)
1331 * QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR (IFNAMSIZ)
1332 * QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO (ndp_app_info_len size)
1333 * QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE (4 bytes)
1334 * QCA_WLAN_VENDOR_ATTR_NDP_RETURN_VALUE (4 bytes)
1335 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001336 * Return: none
1337 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001338static void hdd_ndp_confirm_ind_handler(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001339 void *ind_params)
1340{
Naveen Rawatf28315c2016-06-29 18:06:02 -07001341 int idx;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001342 uint32_t ndp_qos_config = 0;
1343 struct ndp_confirm_event *ndp_confirm = ind_params;
1344 struct sk_buff *vendor_event;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001345 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001346 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
Jeff Johnson40dae4e2017-08-29 14:00:25 -07001347 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001348 uint32_t data_len;
1349
1350 ENTER();
1351 if (!ndp_confirm) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001352 hdd_err("Invalid NDP Initator response");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001353 return;
1354 }
1355
1356 if (0 != wlan_hdd_validate_context(hdd_ctx))
1357 return;
1358
Naveen Rawatf28315c2016-06-29 18:06:02 -07001359 /* ndp_confirm is called each time user generated ndp req succeeds */
1360 idx = hdd_get_peer_idx(sta_ctx, &ndp_confirm->peer_ndi_mac_addr);
1361 if (idx == INVALID_PEER_IDX)
Naveen Rawatba4f6612016-07-05 12:03:16 -07001362 hdd_err("can't find addr: %pM in vdev_id: %d, peer table.",
Naveen Rawatf28315c2016-06-29 18:06:02 -07001363 &ndp_confirm->peer_ndi_mac_addr, adapter->sessionId);
Naveen Rawat460be782016-06-29 18:26:22 -07001364 else if (ndp_confirm->rsp_code == NDP_RESPONSE_ACCEPT)
Naveen Rawatf28315c2016-06-29 18:06:02 -07001365 ndp_ctx->active_ndp_sessions[idx]++;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001366
1367 data_len = (4 * sizeof(uint32_t)) + QDF_MAC_ADDR_SIZE + IFNAMSIZ +
Naveen Rawat90ae3082016-06-29 18:22:59 -07001368 + NLMSG_HDRLEN + (7 * NLA_HDRLEN) +
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001369 ndp_confirm->ndp_info.ndp_app_info_len;
1370
Naveen Rawat8d63a592016-06-29 18:30:59 -07001371 if (ndp_confirm->ndp_info.ndp_app_info_len)
1372 data_len += NLA_HDRLEN + ndp_confirm->ndp_info.ndp_app_info_len;
1373
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001374 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy, NULL,
1375 data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1376 GFP_KERNEL);
1377 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001378 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001379 return;
1380 }
1381
1382 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1383 QCA_WLAN_VENDOR_ATTR_NDP_CONFIRM_IND))
1384 goto ndp_confirm_nla_failed;
1385
1386 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID,
1387 ndp_confirm->ndp_instance_id))
1388 goto ndp_confirm_nla_failed;
1389
1390 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_NDI_MAC_ADDR,
1391 QDF_MAC_ADDR_SIZE, ndp_confirm->peer_ndi_mac_addr.bytes))
1392 goto ndp_confirm_nla_failed;
1393
1394 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR,
1395 IFNAMSIZ, adapter->dev->name))
1396 goto ndp_confirm_nla_failed;
1397
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001398 if (ndp_confirm->ndp_info.ndp_app_info_len && nla_put(vendor_event,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001399 QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO,
1400 ndp_confirm->ndp_info.ndp_app_info_len,
1401 ndp_confirm->ndp_info.ndp_app_info))
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001402 goto ndp_confirm_nla_failed;
1403
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001404 if (nla_put_u32(vendor_event,
1405 QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE,
1406 ndp_confirm->rsp_code))
1407 goto ndp_confirm_nla_failed;
1408
Naveen Rawat8d63a592016-06-29 18:30:59 -07001409 if (nla_put_u32(vendor_event,
1410 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
1411 ndp_confirm->reason_code))
1412 goto ndp_confirm_nla_failed;
1413
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001414 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001415 hdd_info("NDP confim sent, ndp instance id: %d, peer addr: %pM, ndp_cfg: %d, rsp_code: %d, reason_code: %d",
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001416 ndp_confirm->ndp_instance_id,
1417 ndp_confirm->peer_ndi_mac_addr.bytes,
Naveen Rawat460be782016-06-29 18:26:22 -07001418 ndp_qos_config, ndp_confirm->rsp_code,
1419 ndp_confirm->reason_code);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001420
Naveen Rawatba4f6612016-07-05 12:03:16 -07001421 hdd_info("NDP confim, ndp app info dump");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001422 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
1423 ndp_confirm->ndp_info.ndp_app_info,
1424 ndp_confirm->ndp_info.ndp_app_info_len);
1425 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001426 return;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001427ndp_confirm_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001428 hdd_err("nla_put api failed");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001429 kfree_skb(vendor_event);
1430 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001431}
1432
1433/**
1434 * hdd_ndp_indication_handler() - NDP indication handler
1435 * @adapter: pointer to adapter context
1436 * @ind_params: indication parameters
1437 *
Abhishek Singh4fef7472016-06-06 11:36:03 -07001438 * Following vendor event is sent to cfg80211:
1439 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1440 * QCA_WLAN_VENDOR_ATTR_NDP_REQUEST_IND (4 bytes)
1441 * QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR (IFNAMSIZ)
Naveen Rawat19da3d12016-08-16 12:39:38 -07001442 * QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID (4 bytes)
Abhishek Singh4fef7472016-06-06 11:36:03 -07001443 * QCA_WLAN_VENDOR_ATTR_NDP_NDI_MAC_ADDR (6 bytes)
1444 * QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR (6 bytes)
1445 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID (4 bytes)
1446 * QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO (ndp_app_info_len size)
1447 * QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS (4 bytes)
Naveen Rawat4f3983e2016-11-29 16:12:09 -08001448 * QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE(4 bytes)
1449 * QCA_WLAN_VENDOR_ATTR_NDP_SCID(scid_len in size)
Abhishek Singh4fef7472016-06-06 11:36:03 -07001450 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001451 * Return: none
1452 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001453static void hdd_ndp_indication_handler(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001454 void *ind_params)
1455{
Abhishek Singh4fef7472016-06-06 11:36:03 -07001456 struct sk_buff *vendor_event;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001457 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Abhishek Singh4fef7472016-06-06 11:36:03 -07001458 struct ndp_indication_event *event = ind_params;
1459 uint32_t ndp_qos_config;
1460 struct nan_datapath_ctx *ndp_ctx;
1461 uint16_t data_len;
1462
1463 ENTER();
1464 if (!ind_params) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001465 hdd_err("Invalid NDP Indication");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001466 return;
1467 }
1468
1469 if (0 != wlan_hdd_validate_context(hdd_ctx))
1470 return;
1471
1472 /* Handle only if adapter is in NDI mode */
1473 if (QDF_NDI_MODE != adapter->device_mode) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001474 hdd_err("Adapter is not in NDI mode");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001475 return;
1476 }
1477
Naveen Rawatba4f6612016-07-05 12:03:16 -07001478 hdd_info("NDP Indication, policy: %d", event->policy);
Abhishek Singh4fef7472016-06-06 11:36:03 -07001479
1480 /* Policy check */
1481 if (!WLAN_HDD_IS_NDP_ENABLED(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001482 hdd_err("NAN datapath is not suported");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001483 return;
1484 }
1485
1486 /* NAN data path coexists only with STA interface */
1487 if (!hdd_is_ndp_allowed(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001488 hdd_err("Unsupported concurrency for NAN datapath");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001489 return;
1490 }
1491
1492 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
1493
1494 /* check if we are in middle of deleting/creating the interface */
1495 if (ndp_ctx->state == NAN_DATA_NDI_DELETED_STATE ||
1496 ndp_ctx->state == NAN_DATA_NDI_DELETING_STATE ||
1497 ndp_ctx->state == NAN_DATA_NDI_CREATING_STATE) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001498 hdd_err("Data request not allowed in current NDI state: %d",
Abhishek Singh4fef7472016-06-06 11:36:03 -07001499 ndp_ctx->state);
1500 return;
1501 }
1502
Naveen Rawat4f3983e2016-11-29 16:12:09 -08001503 data_len = (5 * sizeof(uint32_t)) + (2 * QDF_MAC_ADDR_SIZE) + IFNAMSIZ +
1504 event->ndp_info.ndp_app_info_len + event->scid.scid_len +
1505 (10 * NLA_HDRLEN) + NLMSG_HDRLEN;
Abhishek Singh4fef7472016-06-06 11:36:03 -07001506
1507 /* notify response to the upper layer */
1508 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
1509 NULL, data_len,
1510 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1511 GFP_KERNEL);
1512 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001513 hdd_err("cfg80211_vendor_event_alloc failed");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001514 return;
1515 }
1516
1517 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1518 QCA_WLAN_VENDOR_ATTR_NDP_REQUEST_IND))
1519 goto ndp_indication_nla_failed;
1520
1521 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR,
1522 IFNAMSIZ, adapter->dev->name))
1523 goto ndp_indication_nla_failed;
1524
Naveen Rawat19da3d12016-08-16 12:39:38 -07001525 if (nla_put_u32(vendor_event,
Abhishek Singh4fef7472016-06-06 11:36:03 -07001526 QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID,
1527 event->service_instance_id))
1528 goto ndp_indication_nla_failed;
1529
1530 if (nla_put(vendor_event,
1531 QCA_WLAN_VENDOR_ATTR_NDP_NDI_MAC_ADDR,
1532 QDF_MAC_ADDR_SIZE, event->peer_mac_addr.bytes))
1533 goto ndp_indication_nla_failed;
1534
1535 if (nla_put(vendor_event,
Jeff Johnson03294f12016-12-09 17:10:24 -08001536 QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR,
Abhishek Singh4fef7472016-06-06 11:36:03 -07001537 QDF_MAC_ADDR_SIZE, event->peer_discovery_mac_addr.bytes))
1538 goto ndp_indication_nla_failed;
1539
1540 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID,
1541 event->ndp_instance_id))
1542 goto ndp_indication_nla_failed;
1543
1544 if (event->ndp_info.ndp_app_info_len)
1545 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO,
1546 event->ndp_info.ndp_app_info_len,
1547 event->ndp_info.ndp_app_info))
1548 goto ndp_indication_nla_failed;
1549
1550 if (event->ndp_config.ndp_cfg_len) {
1551 ndp_qos_config = *((uint32_t *)event->ndp_config.ndp_cfg);
1552 /* at present ndp config stores 4 bytes QOS info only */
1553 if (nla_put_u32(vendor_event,
1554 QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS,
1555 ndp_qos_config))
1556 goto ndp_indication_nla_failed;
1557 }
1558
Naveen Rawat4f3983e2016-11-29 16:12:09 -08001559 if (event->scid.scid_len) {
1560 if (nla_put_u32(vendor_event,
1561 QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE,
1562 event->ncs_sk_type))
1563 goto ndp_indication_nla_failed;
1564
1565 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SCID,
1566 event->scid.scid_len,
1567 event->scid.scid))
1568 goto ndp_indication_nla_failed;
1569
1570 hdd_info("csid: %d, scid_len: %d",
1571 event->ncs_sk_type, event->scid.scid_len);
1572
1573 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
1574 event->scid.scid, event->scid.scid_len);
1575 }
1576
Abhishek Singh4fef7472016-06-06 11:36:03 -07001577 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1578 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001579 return;
Abhishek Singh4fef7472016-06-06 11:36:03 -07001580ndp_indication_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001581 hdd_err("nla_put api failed");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001582 kfree_skb(vendor_event);
1583 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001584}
1585
1586/**
1587 * hdd_ndp_responder_rsp_handler() - NDP responder response handler
1588 * @adapter: pointer to adapter context
1589 * @rsp_params: response parameters
1590 *
Abhishek Singh4fef7472016-06-06 11:36:03 -07001591 * Following vendor event is sent to cfg80211:
1592 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1593 * QCA_WLAN_VENDOR_ATTR_NDP_RESPONDER_RESPONSE (4 bytes)
1594 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001595 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
1596 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE (4 bytes)
Abhishek Singh4fef7472016-06-06 11:36:03 -07001597 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001598 * Return: none
1599 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001600static void hdd_ndp_responder_rsp_handler(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001601 void *rsp_params)
1602{
Abhishek Singh4fef7472016-06-06 11:36:03 -07001603 struct sk_buff *vendor_event;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001604 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Abhishek Singh4fef7472016-06-06 11:36:03 -07001605 struct ndp_responder_rsp_event *rsp = rsp_params;
1606 uint16_t data_len;
1607
1608 ENTER();
1609 if (!rsp) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001610 hdd_err("Invalid NDP Responder response");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001611 return;
1612 }
1613
1614 if (0 != wlan_hdd_validate_context(hdd_ctx))
1615 return;
1616
Naveen Rawatba4f6612016-07-05 12:03:16 -07001617 hdd_info("NDP Responder,vdev id %d transaction_id %d status code: %d reason %d",
Abhishek Singh4fef7472016-06-06 11:36:03 -07001618 rsp->vdev_id, rsp->transaction_id,
1619 rsp->status, rsp->reason);
1620
1621 data_len = 3 * sizeof(uint32_t) + sizeof(uint16_t) +
1622 4 * NLA_HDRLEN + NLMSG_HDRLEN;
1623 /* notify response to the upper layer */
1624 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
1625 NULL, data_len,
1626 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1627 GFP_KERNEL);
1628 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001629 hdd_err("cfg80211_vendor_event_alloc failed");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001630 return;
1631 }
1632
1633 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1634 QCA_WLAN_VENDOR_ATTR_NDP_RESPONDER_RESPONSE))
1635 goto ndp_responder_rsp_nla_failed;
1636
1637 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1638 rsp->transaction_id))
1639 goto ndp_responder_rsp_nla_failed;
1640
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001641 if (nla_put_u32(vendor_event,
1642 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Abhishek Singh4fef7472016-06-06 11:36:03 -07001643 rsp->status))
1644 goto ndp_responder_rsp_nla_failed;
1645
1646 if (nla_put_u32(vendor_event,
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001647 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
Abhishek Singh4fef7472016-06-06 11:36:03 -07001648 rsp->reason))
1649 goto ndp_responder_rsp_nla_failed;
1650
1651 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1652 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001653 return;
Abhishek Singh4fef7472016-06-06 11:36:03 -07001654ndp_responder_rsp_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001655 hdd_err("nla_put api failed");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001656 kfree_skb(vendor_event);
1657 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001658}
1659
1660/**
1661 * hdd_ndp_end_rsp_handler() - NDP end response handler
1662 * @adapter: pointer to adapter context
1663 * @rsp_params: response parameters
1664 *
Naveen Rawatf28315c2016-06-29 18:06:02 -07001665 * Following vendor event is sent to cfg80211:
1666 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1667 * QCA_WLAN_VENDOR_ATTR_NDP_END_RESPONSE(4 bytest)
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001668 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
Naveen Rawatf28315c2016-06-29 18:06:02 -07001669 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE (4 bytes)
1670 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
1671 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001672 * Return: none
1673 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001674static void hdd_ndp_end_rsp_handler(struct hdd_adapter *adapter, void *rsp_params)
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001675{
Naveen Rawatf28315c2016-06-29 18:06:02 -07001676 struct sk_buff *vendor_event;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001677 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Naveen Rawatf28315c2016-06-29 18:06:02 -07001678 struct ndp_end_rsp_event *rsp = rsp_params;
Rakesh Sunkiae936b62016-07-28 16:01:45 -07001679 uint32_t data_len;
Naveen Rawatf28315c2016-06-29 18:06:02 -07001680
1681 ENTER();
1682
1683 if (!rsp) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001684 hdd_err("Invalid ndp end response");
Naveen Rawatf28315c2016-06-29 18:06:02 -07001685 return;
1686 }
1687
1688 if (0 != wlan_hdd_validate_context(hdd_ctx))
1689 return;
1690
Naveen Rawatf28315c2016-06-29 18:06:02 -07001691 data_len = NLMSG_HDRLEN + (4 * NLA_HDRLEN) + (3 * sizeof(uint32_t)) +
1692 sizeof(uint16_t);
1693
1694 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy, NULL,
1695 data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1696 GFP_KERNEL);
1697 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001698 hdd_err("cfg80211_vendor_event_alloc failed");
Naveen Rawatf28315c2016-06-29 18:06:02 -07001699 return;
1700 }
1701
1702 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1703 QCA_WLAN_VENDOR_ATTR_NDP_END_RESPONSE))
1704 goto ndp_end_rsp_nla_failed;
1705
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001706 if (nla_put_u32(vendor_event,
1707 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Naveen Rawatf28315c2016-06-29 18:06:02 -07001708 rsp->status))
1709 goto ndp_end_rsp_nla_failed;
1710
1711 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
1712 rsp->reason))
1713 goto ndp_end_rsp_nla_failed;
1714
1715 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1716 rsp->transaction_id))
1717 goto ndp_end_rsp_nla_failed;
1718
Naveen Rawatba4f6612016-07-05 12:03:16 -07001719 hdd_info("NDP End rsp sent, transaction id: %d, status: %d, reason: %d",
Naveen Rawatf28315c2016-06-29 18:06:02 -07001720 rsp->transaction_id, rsp->status, rsp->reason);
1721 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1722 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001723 return;
Naveen Rawatf28315c2016-06-29 18:06:02 -07001724
1725ndp_end_rsp_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001726 hdd_err("nla_put api failed");
Naveen Rawatf28315c2016-06-29 18:06:02 -07001727 kfree_skb(vendor_event);
1728 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001729}
1730
1731/**
1732 * hdd_ndp_end_ind_handler() - NDP end indication handler
1733 * @adapter: pointer to adapter context
1734 * @ind_params: indication parameters
1735 *
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001736 * Following vendor event is sent to cfg80211:
1737 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1738 * QCA_WLAN_VENDOR_ATTR_NDP_END_IND (4 bytes)
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001739 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY (4 * num of NDP Instances)
1740 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001741 * Return: none
1742 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001743static void hdd_ndp_end_ind_handler(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001744 void *ind_params)
1745{
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001746 struct sk_buff *vendor_event;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001747 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001748 struct ndp_end_indication_event *end_ind = ind_params;
1749 uint32_t data_len, i;
1750 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
Jeff Johnson40dae4e2017-08-29 14:00:25 -07001751 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001752 uint32_t *ndp_instance_array;
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001753 struct hdd_adapter *ndi_adapter;
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001754
1755 ENTER();
1756
1757 if (!end_ind) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001758 hdd_err("Invalid ndp end indication");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001759 return;
1760 }
1761
1762 if (0 != wlan_hdd_validate_context(hdd_ctx))
1763 return;
1764
1765 ndp_instance_array = qdf_mem_malloc(end_ind->num_ndp_ids *
1766 sizeof(*ndp_instance_array));
1767 if (!ndp_instance_array) {
1768 hdd_err("Failed to allocate ndp_instance_array");
1769 return;
1770 }
1771 for (i = 0; i < end_ind->num_ndp_ids; i++) {
1772 int idx;
1773
1774 ndp_instance_array[i] = end_ind->ndp_map[i].ndp_instance_id;
Naveen Rawate21103f2016-07-08 14:18:00 -07001775 ndi_adapter = hdd_get_adapter_by_vdev(hdd_ctx,
1776 end_ind->ndp_map[i].vdev_id);
1777 if (ndi_adapter == NULL) {
1778 hdd_err("Adapter not found for vdev_id: %d",
1779 end_ind->ndp_map[i].vdev_id);
1780 continue;
1781 }
1782 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(ndi_adapter);
Govind Singhb8475942016-08-12 11:07:09 +05301783 if (!ndp_ctx) {
1784 hdd_err("ndp_ctx is NULL for vdev id: %d",
1785 end_ind->ndp_map[i].vdev_id);
1786 continue;
1787 }
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001788 idx = hdd_get_peer_idx(sta_ctx,
1789 &end_ind->ndp_map[i].peer_ndi_mac_addr);
1790 if (idx == INVALID_PEER_IDX) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001791 hdd_err("can't find addr: %pM in sta_ctx.",
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001792 &end_ind->ndp_map[i].peer_ndi_mac_addr);
1793 continue;
1794 }
1795 /* save the value of active sessions on each peer */
1796 ndp_ctx->active_ndp_sessions[idx] =
1797 end_ind->ndp_map[i].num_active_ndp_sessions;
1798 }
1799
Naveen Rawat90ae3082016-06-29 18:22:59 -07001800 data_len = (sizeof(uint32_t)) + NLMSG_HDRLEN + (2 * NLA_HDRLEN) +
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001801 end_ind->num_ndp_ids * sizeof(*ndp_instance_array);
1802
1803 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy, NULL,
1804 data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1805 GFP_KERNEL);
1806 if (!vendor_event) {
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05301807 qdf_mem_free(ndp_instance_array);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001808 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001809 return;
1810 }
1811
1812 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1813 QCA_WLAN_VENDOR_ATTR_NDP_END_IND))
1814 goto ndp_end_ind_nla_failed;
1815
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001816 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY,
1817 end_ind->num_ndp_ids * sizeof(*ndp_instance_array),
1818 ndp_instance_array))
1819 goto ndp_end_ind_nla_failed;
1820
1821 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1822 qdf_mem_free(ndp_instance_array);
1823 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001824 return;
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001825
1826ndp_end_ind_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001827 hdd_err("nla_put api failed");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001828 kfree_skb(vendor_event);
1829 qdf_mem_free(ndp_instance_array);
1830 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001831}
1832
1833/**
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001834 * hdd_ndp_event_handler() - ndp response and indication handler
1835 * @adapter: adapter context
1836 * @roam_info: pointer to roam_info structure
1837 * @roam_id: roam id as indicated by SME
1838 * @roam_status: roam status
1839 * @roam_result: roam result
1840 *
1841 * Return: none
1842 */
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001843void hdd_ndp_event_handler(struct hdd_adapter *adapter,
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001844 tCsrRoamInfo *roam_info, uint32_t roam_id, eRoamCmdStatus roam_status,
1845 eCsrRoamResult roam_result)
1846{
1847 if (roam_status == eCSR_ROAM_NDP_STATUS_UPDATE) {
1848 switch (roam_result) {
Naveen Rawat8d63a592016-06-29 18:30:59 -07001849 case eCSR_ROAM_RESULT_NDI_CREATE_RSP:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001850 hdd_ndp_iface_create_rsp_handler(adapter,
1851 &roam_info->ndp.ndi_create_params);
1852 break;
Naveen Rawat8d63a592016-06-29 18:30:59 -07001853 case eCSR_ROAM_RESULT_NDI_DELETE_RSP:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001854 hdd_ndp_iface_delete_rsp_handler(adapter,
1855 &roam_info->ndp.ndi_delete_params);
1856 break;
1857 case eCSR_ROAM_RESULT_NDP_INITIATOR_RSP:
1858 hdd_ndp_initiator_rsp_handler(adapter,
1859 &roam_info->ndp.ndp_init_rsp_params);
1860 break;
1861 case eCSR_ROAM_RESULT_NDP_NEW_PEER_IND:
1862 hdd_ndp_new_peer_ind_handler(adapter,
1863 &roam_info->ndp.ndp_peer_ind_params);
1864 break;
1865 case eCSR_ROAM_RESULT_NDP_CONFIRM_IND:
1866 hdd_ndp_confirm_ind_handler(adapter,
1867 &roam_info->ndp.ndp_confirm_params);
1868 break;
1869 case eCSR_ROAM_RESULT_NDP_INDICATION:
1870 hdd_ndp_indication_handler(adapter,
1871 &roam_info->ndp.ndp_indication_params);
1872 break;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001873 case eCSR_ROAM_RESULT_NDP_RESPONDER_RSP:
1874 hdd_ndp_responder_rsp_handler(adapter,
1875 &roam_info->ndp.ndp_responder_rsp_params);
1876 break;
1877 case eCSR_ROAM_RESULT_NDP_END_RSP:
1878 hdd_ndp_end_rsp_handler(adapter,
Naveen Rawatf28315c2016-06-29 18:06:02 -07001879 roam_info->ndp.ndp_end_rsp_params);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001880 break;
1881 case eCSR_ROAM_RESULT_NDP_PEER_DEPARTED_IND:
1882 hdd_ndp_peer_departed_ind_handler(adapter,
1883 &roam_info->ndp.ndp_peer_ind_params);
1884 break;
1885 case eCSR_ROAM_RESULT_NDP_END_IND:
1886 hdd_ndp_end_ind_handler(adapter,
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001887 roam_info->ndp.ndp_end_ind_params);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001888 break;
1889 default:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001890 hdd_err("Unknown NDP response event from SME %d",
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001891 roam_result);
1892 break;
1893 }
1894 }
1895}
Naveen Rawat97500352017-03-22 10:07:58 -07001896#else
Jeff Johnson8cb9df12017-08-29 14:28:45 -07001897void hdd_ndp_event_handler(struct hdd_adapter *adapter,
Naveen Rawat97500352017-03-22 10:07:58 -07001898 tCsrRoamInfo *roam_info, uint32_t roam_id, eRoamCmdStatus roam_status,
1899 eCsrRoamResult roam_result)
1900{
Naveen Rawatcb5c5402017-03-22 10:12:19 -07001901 bool success;
1902 struct wlan_objmgr_psoc *psoc = wlan_vdev_get_psoc(adapter->hdd_vdev);
1903
1904 if (roam_status == eCSR_ROAM_NDP_STATUS_UPDATE) {
1905 switch (roam_result) {
1906 case eCSR_ROAM_RESULT_NDI_CREATE_RSP:
1907 success = (roam_info->ndp.ndi_create_params.status ==
1908 NAN_DATAPATH_RSP_STATUS_SUCCESS);
1909 hdd_debug("posting ndi create status: %d to umac",
1910 success);
1911 os_if_nan_post_ndi_create_rsp(psoc, adapter->sessionId,
1912 success);
1913 return;
1914 case eCSR_ROAM_RESULT_NDI_DELETE_RSP:
1915 success = (roam_info->ndp.ndi_create_params.status ==
1916 NAN_DATAPATH_RSP_STATUS_SUCCESS);
1917 hdd_debug("posting ndi delete status: %d to umac",
1918 success);
1919 os_if_nan_post_ndi_delete_rsp(psoc, adapter->sessionId,
1920 success);
1921 return;
1922 default:
1923 hdd_err("in correct roam_result: %d", roam_result);
1924 return;
1925 }
1926 } else {
1927 hdd_err("in correct roam_status: %d", roam_status);
1928 return;
1929 }
Naveen Rawat97500352017-03-22 10:07:58 -07001930}
1931#endif
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001932
1933/**
1934 * __wlan_hdd_cfg80211_process_ndp_cmds() - handle NDP request
1935 * @wiphy: pointer to wireless wiphy structure.
1936 * @wdev: pointer to wireless_dev structure.
1937 * @data: Pointer to the data to be passed via vendor interface
1938 * @data_len:Length of the data to be passed
1939 *
1940 * This function is invoked to handle vendor command
1941 *
1942 * Return: 0 on success, negative errno on failure
1943 */
Naveen Rawat63de5422017-03-22 11:03:56 -07001944#ifdef WLAN_FEATURE_NAN_CONVERGENCE
1945static int __wlan_hdd_cfg80211_process_ndp_cmd(struct wiphy *wiphy,
1946 struct wireless_dev *wdev, const void *data, int data_len)
1947{
1948 int ret_val;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001949 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Naveen Rawat63de5422017-03-22 11:03:56 -07001950
1951 ENTER();
1952
1953 ret_val = wlan_hdd_validate_context(hdd_ctx);
1954 if (ret_val)
1955 return ret_val;
1956
1957 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
1958 hdd_err("Command not allowed in FTM mode");
1959 return -EPERM;
1960 }
1961
1962 if (!WLAN_HDD_IS_NDP_ENABLED(hdd_ctx)) {
1963 hdd_err("NAN datapath is not enabled");
1964 return -EPERM;
1965 }
1966 /* NAN data path coexists only with STA interface */
1967 if (false == hdd_is_ndp_allowed(hdd_ctx)) {
1968 hdd_err("Unsupported concurrency for NAN datapath");
1969 return -EPERM;
1970 }
1971
1972 /* NAN data path coexists only with STA interface */
1973 if (false == hdd_is_ndp_allowed(hdd_ctx)) {
1974 hdd_err("Unsupported concurrency for NAN datapath");
1975 return -EPERM;
1976 }
1977
1978 return os_if_nan_process_ndp_cmd(hdd_ctx->hdd_psoc,
1979 data, data_len);
1980}
1981#else
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001982static int __wlan_hdd_cfg80211_process_ndp_cmd(struct wiphy *wiphy,
1983 struct wireless_dev *wdev, const void *data, int data_len)
1984{
1985 uint32_t ndp_cmd_type;
1986 uint16_t transaction_id;
1987 int ret_val;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07001988 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001989 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_NDP_PARAMS_MAX + 1];
1990 char *iface_name;
1991
1992 ENTER();
1993
1994 ret_val = wlan_hdd_validate_context(hdd_ctx);
1995 if (ret_val)
1996 return ret_val;
1997
1998 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001999 hdd_err("Command not allowed in FTM mode");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002000 return -EPERM;
2001 }
Deepak Dhamdhere7e6016f2016-06-01 09:37:37 -07002002 if (!WLAN_HDD_IS_NDP_ENABLED(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002003 hdd_err("NAN datapath is not enabled");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002004 return -EPERM;
2005 }
Dustin Brown3fb15042017-08-15 15:54:49 -07002006 if (hdd_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_NDP_PARAMS_MAX,
2007 data, data_len, qca_wlan_vendor_ndp_policy)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002008 hdd_err("Invalid NDP vendor command attributes");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002009 return -EINVAL;
2010 }
2011
2012 /* Parse and fetch NDP Command Type*/
2013 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002014 hdd_err("NAN datapath cmd type failed");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002015 return -EINVAL;
2016 }
2017 ndp_cmd_type = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD]);
2018
2019 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002020 hdd_err("attr transaction id failed");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002021 return -EINVAL;
2022 }
2023 transaction_id = nla_get_u16(
2024 tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
2025
Naveen Rawatf28315c2016-06-29 18:06:02 -07002026 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
2027 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002028 hdd_debug("Transaction Id: %d NDP Cmd: %d iface_name: %s",
Naveen Rawatf28315c2016-06-29 18:06:02 -07002029 transaction_id, ndp_cmd_type, iface_name);
2030 } else {
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07002031 hdd_debug("Transaction Id: %d NDP Cmd: %d iface_name: unspecified",
Naveen Rawatf28315c2016-06-29 18:06:02 -07002032 transaction_id, ndp_cmd_type);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002033 }
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002034
2035 switch (ndp_cmd_type) {
2036 case QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_CREATE:
2037 ret_val = hdd_ndi_create_req_handler(hdd_ctx, tb);
2038 break;
2039 case QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_DELETE:
2040 ret_val = hdd_ndi_delete_req_handler(hdd_ctx, tb);
2041 break;
2042 case QCA_WLAN_VENDOR_ATTR_NDP_INITIATOR_REQUEST:
2043 ret_val = hdd_ndp_initiator_req_handler(hdd_ctx, tb);
2044 break;
2045 case QCA_WLAN_VENDOR_ATTR_NDP_RESPONDER_REQUEST:
2046 ret_val = hdd_ndp_responder_req_handler(hdd_ctx, tb);
2047 break;
2048 case QCA_WLAN_VENDOR_ATTR_NDP_END_REQUEST:
2049 ret_val = hdd_ndp_end_req_handler(hdd_ctx, tb);
2050 break;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002051 default:
Naveen Rawatba4f6612016-07-05 12:03:16 -07002052 hdd_err("Unrecognized NDP vendor cmd %d", ndp_cmd_type);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002053 ret_val = -EINVAL;
2054 break;
2055 }
2056
2057 return ret_val;
2058}
Naveen Rawat63de5422017-03-22 11:03:56 -07002059#endif
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002060
2061/**
2062 * wlan_hdd_cfg80211_process_ndp_cmd() - handle NDP request
2063 * @wiphy: pointer to wireless wiphy structure.
2064 * @wdev: pointer to wireless_dev structure.
2065 * @data: Pointer to the data to be passed via vendor interface
2066 * @data_len:Length of the data to be passed
2067 *
2068 * This function is called to send a NAN request to
2069 * firmware. This is an SSR-protected wrapper function.
2070 *
2071 * Return: 0 on success, negative errno on failure
2072 */
2073int wlan_hdd_cfg80211_process_ndp_cmd(struct wiphy *wiphy,
2074 struct wireless_dev *wdev, const void *data, int data_len)
2075{
2076 int ret;
2077
2078 cds_ssr_protect(__func__);
2079 ret = __wlan_hdd_cfg80211_process_ndp_cmd(wiphy, wdev, data, data_len);
2080 cds_ssr_unprotect(__func__);
2081
2082 return ret;
2083}
2084
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002085#ifndef WLAN_FEATURE_NAN_CONVERGENCE
Jeff Johnson85b5c112017-08-11 15:15:23 -07002086static int update_ndi_state(struct hdd_adapter *adapter, uint32_t state)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002087{
2088 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
2089
2090 ndp_ctx->state = state;
2091 return 0;
2092}
2093#else
Jeff Johnson85b5c112017-08-11 15:15:23 -07002094static int update_ndi_state(struct hdd_adapter *adapter, uint32_t state)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002095{
2096 return os_if_nan_set_ndi_state(adapter->hdd_vdev, state);
2097}
2098#endif
2099
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002100/**
2101 * hdd_init_nan_data_mode() - initialize nan data mode
2102 * @adapter: adapter context
2103 *
2104 * Returns: 0 on success negative error code on error
2105 */
Jeff Johnson85b5c112017-08-11 15:15:23 -07002106int hdd_init_nan_data_mode(struct hdd_adapter *adapter)
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002107{
2108 struct net_device *wlan_dev = adapter->dev;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002109 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002110 QDF_STATUS status;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002111 int32_t ret_val = 0;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002112
Dustin Brownd28772b2017-03-17 14:16:07 -07002113 ret_val = hdd_vdev_create(adapter);
2114 if (ret_val) {
2115 hdd_err("failed to create vdev: %d", ret_val);
2116 return ret_val;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002117 }
2118
Ravi Joshi8eb65f92017-07-20 16:30:19 -07002119 /* Configure self HT/VHT capabilities */
2120 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
2121 sme_set_pdev_ht_vht_ies(hdd_ctx->hHal, hdd_ctx->config->enable2x2);
2122 sme_set_vdev_ies_per_band(hdd_ctx->hHal, adapter->sessionId);
2123
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002124 /* Register wireless extensions */
2125 ret_val = hdd_register_wext(wlan_dev);
2126 if (0 > ret_val) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002127 hdd_err("Wext registration failed with status code %d",
2128 ret_val);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002129 ret_val = -EAGAIN;
2130 goto error_register_wext;
2131 }
2132
2133 status = hdd_init_tx_rx(adapter);
2134 if (QDF_STATUS_SUCCESS != status) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002135 hdd_err("hdd_init_tx_rx() init failed, status %d", status);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002136 ret_val = -EAGAIN;
2137 goto error_init_txrx;
2138 }
2139
2140 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
2141
2142 status = hdd_wmm_adapter_init(adapter);
2143 if (QDF_STATUS_SUCCESS != status) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002144 hdd_err("hdd_wmm_adapter_init() failed, status %d", status);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002145 ret_val = -EAGAIN;
2146 goto error_wmm_init;
2147 }
2148
2149 set_bit(WMM_INIT_DONE, &adapter->event_flags);
2150
2151 ret_val = wma_cli_set_command((int)adapter->sessionId,
2152 (int)WMI_PDEV_PARAM_BURST_ENABLE,
2153 (int)hdd_ctx->config->enableSifsBurst,
2154 PDEV_CMD);
Arunk Khandavalli15664e42017-06-29 15:56:14 +05302155 if (0 != ret_val)
Naveen Rawatba4f6612016-07-05 12:03:16 -07002156 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Arunk Khandavalli15664e42017-06-29 15:56:14 +05302157
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002158
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002159 update_ndi_state(adapter, NAN_DATA_NDI_CREATING_STATE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002160 return ret_val;
2161
2162error_wmm_init:
2163 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
2164 hdd_deinit_tx_rx(adapter);
2165
2166error_init_txrx:
2167 hdd_unregister_wext(wlan_dev);
2168
2169error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07002170 QDF_BUG(!hdd_vdev_destroy(adapter));
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002171
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002172 return ret_val;
2173}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002174
2175#ifdef WLAN_FEATURE_NAN_CONVERGENCE
2176struct wlan_objmgr_vdev *hdd_ndi_open(char *iface_name)
2177{
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002178 struct hdd_adapter *adapter;
Ravi Joshi9771d432017-06-26 13:58:12 -07002179 struct qdf_mac_addr random_ndi_mac;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002180 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Ravi Joshi9771d432017-06-26 13:58:12 -07002181 uint8_t *ndi_mac_addr;
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002182
2183 ENTER();
Naveen Rawat5a6f8402017-07-03 16:00:11 -07002184
Ravi Joshi9771d432017-06-26 13:58:12 -07002185 if (hdd_ctx->config->is_ndi_mac_randomized) {
2186 if (hdd_get_random_nan_mac_addr(hdd_ctx, &random_ndi_mac)) {
2187 hdd_err("get random mac address failed");
2188 return NULL;
2189 }
2190 ndi_mac_addr = &random_ndi_mac.bytes[0];
2191 } else {
2192 ndi_mac_addr = wlan_hdd_get_intf_addr(hdd_ctx);
2193 if (!ndi_mac_addr) {
2194 hdd_err("get intf address failed");
2195 return NULL;
2196 }
Naveen Rawat5a6f8402017-07-03 16:00:11 -07002197 }
2198
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002199 adapter = hdd_open_adapter(hdd_ctx, QDF_NDI_MODE, iface_name,
Ravi Joshi9771d432017-06-26 13:58:12 -07002200 ndi_mac_addr, NET_NAME_UNKNOWN, true);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002201 if (!adapter) {
2202 hdd_err("hdd_open_adapter failed");
2203 return NULL;
2204 }
2205
2206 EXIT();
2207 return adapter->hdd_vdev;
2208}
2209
2210int hdd_ndi_start(uint8_t vdev_id)
2211{
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002212 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002213 uint8_t op_channel = hdd_ctx->config->nan_datapath_ndi_channel;
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002214 struct hdd_adapter *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002215
2216 ENTER();
2217 /*
2218 * The NAN data interface has been created at this point.
2219 * Unlike traditional device modes, where the higher application
2220 * layer initiates connect / join / start, the NAN data
2221 * interface does not have any such formal requests. The NDI
2222 * create request is responsible for starting the BSS as well.
2223 */
2224 if (op_channel != NAN_SOCIAL_CHANNEL_2_4GHZ ||
2225 op_channel != NAN_SOCIAL_CHANNEL_5GHZ_LOWER_BAND ||
2226 op_channel != NAN_SOCIAL_CHANNEL_5GHZ_UPPER_BAND) {
2227 /* start NDI on the default 2.4 GHz social channel */
2228 op_channel = NAN_SOCIAL_CHANNEL_2_4GHZ;
2229 }
2230 if (hdd_ndi_start_bss(adapter, op_channel)) {
2231 hdd_err("NDI start bss failed");
2232 /* Start BSS failed, delete the interface */
2233 hdd_close_ndi(adapter);
2234 EXIT();
2235 return -EINVAL;
2236 }
2237
2238 return 0;
2239}
2240
2241int hdd_ndi_delete(uint8_t vdev_id, char *iface_name, uint16_t transaction_id)
2242{
2243 int ret;
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002244 struct hdd_adapter *adapter;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002245 struct hdd_station_ctx *sta_ctx;
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002246 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002247
Naveen Rawatc4b045c2017-06-30 16:11:42 -07002248 /* check if adapter by vdev_id is valid NDI */
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002249 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2250 if (!adapter || !WLAN_HDD_IS_NDI(adapter)) {
2251 hdd_err("NAN data interface %s is not available", iface_name);
2252 return -EINVAL;
2253 }
2254
2255 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2256 if (!sta_ctx) {
2257 hdd_err("sta_ctx is NULL");
2258 return -EINVAL;
2259 }
2260
2261 /* Since, the interface is being deleted, remove the broadcast id. */
2262 hdd_ctx->sta_to_adapter[sta_ctx->broadcast_staid] = 0;
2263 sta_ctx->broadcast_staid = HDD_WLAN_INVALID_STA_ID;
2264
2265 os_if_nan_set_ndp_delete_transaction_id(adapter->hdd_vdev,
2266 transaction_id);
2267 os_if_nan_set_ndi_state(adapter->hdd_vdev, NAN_DATA_NDI_DELETING_STATE);
2268
2269 /* Delete the interface */
2270 ret = __wlan_hdd_del_virtual_intf(hdd_ctx->wiphy, &adapter->wdev);
2271 if (ret)
2272 hdd_err("NDI delete request failed");
2273 else
2274 hdd_err("NDI delete request successfully issued");
2275
2276 return ret;
2277}
2278
2279void hdd_ndi_drv_ndi_create_rsp_handler(uint8_t vdev_id,
2280 struct nan_datapath_inf_create_rsp *ndi_rsp)
2281{
2282 tCsrRoamInfo roam_info = {0};
2283 tSirBssDescription tmp_bss_descp = {0};
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002284 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002285 struct hdd_adapter *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002286 struct qdf_mac_addr bc_mac_addr = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002287 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002288
2289 if (ndi_rsp->status == QDF_STATUS_SUCCESS) {
2290 hdd_alert("NDI interface successfully created");
2291 os_if_nan_set_ndp_create_transaction_id(adapter->hdd_vdev, 0);
2292 os_if_nan_set_ndi_state(adapter->hdd_vdev,
2293 NAN_DATA_NDI_CREATED_STATE);
2294 wlan_hdd_netif_queue_control(adapter,
2295 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2296 WLAN_CONTROL_PATH);
2297 } else {
2298 hdd_alert("NDI interface creation failed with reason %d",
2299 ndi_rsp->reason /* create_reason */);
2300 }
2301
2302 sta_ctx->broadcast_staid = ndi_rsp->sta_id;
2303 hdd_save_peer(sta_ctx, sta_ctx->broadcast_staid, &bc_mac_addr);
2304 hdd_roam_register_sta(adapter, &roam_info,
2305 sta_ctx->broadcast_staid,
2306 &bc_mac_addr, &tmp_bss_descp);
2307 hdd_ctx->sta_to_adapter[sta_ctx->broadcast_staid] = adapter;
2308}
2309
2310void hdd_ndi_close(uint8_t vdev_id)
2311{
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002312 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002313 struct hdd_adapter *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002314 hdd_close_ndi(adapter);
2315}
2316
2317void hdd_ndi_drv_ndi_delete_rsp_handler(uint8_t vdev_id)
2318{
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002319 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002320 struct hdd_adapter *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002321
2322 wlan_hdd_netif_queue_control(adapter,
2323 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2324 WLAN_CONTROL_PATH);
2325
2326 complete(&adapter->disconnect_comp_var);
2327}
2328
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002329void hdd_ndp_session_end_handler(struct hdd_adapter *adapter)
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002330{
2331 os_if_nan_ndi_session_end(adapter->hdd_vdev);
2332}
2333
Naveen Rawat37f62c82017-03-26 22:24:43 -07002334int hdd_ndp_get_peer_idx(uint8_t vdev_id, struct qdf_mac_addr *addr)
2335{
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002336 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002337 struct hdd_adapter *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002338 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Naveen Rawat37f62c82017-03-26 22:24:43 -07002339 return hdd_get_peer_idx(sta_ctx, addr);
2340}
2341
2342/**
2343 * hdd_ndp_new_peer_handler() - NDP new peer indication handler
2344 * @adapter: pointer to adapter context
2345 * @ind_params: indication parameters
2346 *
2347 * Return: none
2348 */
2349int hdd_ndp_new_peer_handler(uint8_t vdev_id, uint16_t sta_id,
2350 struct qdf_mac_addr *peer_mac_addr, bool fist_peer)
2351{
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002352 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002353 struct hdd_adapter *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Naveen Rawat37f62c82017-03-26 22:24:43 -07002354 tSirBssDescription tmp_bss_descp = {0};
2355 tCsrRoamInfo roam_info = {0};
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002356 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Naveen Rawat37f62c82017-03-26 22:24:43 -07002357
2358 ENTER();
2359 /* save peer in ndp ctx */
2360 if (false == hdd_save_peer(sta_ctx, sta_id, peer_mac_addr)) {
2361 hdd_err("Ndp peer table full. cannot save new peer");
2362 return -EPERM;
2363 }
2364
2365 /* this function is called for each new peer */
2366 hdd_roam_register_sta(adapter, &roam_info, sta_id,
2367 peer_mac_addr, &tmp_bss_descp);
2368 hdd_ctx->sta_to_adapter[sta_id] = adapter;
2369 /* perform following steps for first new peer ind */
2370 if (fist_peer) {
2371 hdd_info("Set ctx connection state to connected");
2372 sta_ctx->conn_info.connState = eConnectionState_NdiConnected;
2373 hdd_wmm_connect(adapter, &roam_info, eCSR_BSS_TYPE_NDI);
2374 wlan_hdd_netif_queue_control(adapter,
2375 WLAN_WAKE_ALL_NETIF_QUEUE, WLAN_CONTROL_PATH);
2376 }
2377 EXIT();
2378 return 0;
2379}
2380
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002381
2382/**
2383 * hdd_ndp_peer_departed_handler() - Handle NDP peer departed indication
2384 * @adapter: pointer to adapter context
2385 * @ind_params: indication parameters
2386 *
2387 * Return: none
2388 */
2389void hdd_ndp_peer_departed_handler(uint8_t vdev_id, uint16_t sta_id,
2390 struct qdf_mac_addr *peer_mac_addr, bool last_peer)
2391{
Jeff Johnson88dc4f92017-08-28 11:51:34 -07002392 struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
Jeff Johnson8cb9df12017-08-29 14:28:45 -07002393 struct hdd_adapter *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
Jeff Johnson40dae4e2017-08-29 14:00:25 -07002394 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002395
2396 ENTER();
2397 hdd_roam_deregister_sta(adapter, sta_id);
2398 hdd_delete_peer(sta_ctx, sta_id);
2399 hdd_ctx->sta_to_adapter[sta_id] = NULL;
2400
2401 if (last_peer) {
2402 hdd_info("No more ndp peers.");
2403 sta_ctx->conn_info.connState = eConnectionState_NdiDisconnected;
2404 hdd_conn_set_connection_state(adapter,
2405 eConnectionState_NdiDisconnected);
2406 hdd_info("Stop netif tx queues.");
2407 wlan_hdd_netif_queue_control(adapter, WLAN_STOP_ALL_NETIF_QUEUE,
2408 WLAN_CONTROL_PATH);
2409 }
2410 EXIT();
2411}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002412#endif