blob: 3b3c1eacd8195a07046abe9c734104f812719173 [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 */
84void hdd_ndp_print_ini_config(hdd_context_t *hdd_ctx)
85{
Naveen Rawatba4f6612016-07-05 12:03:16 -070086 hdd_info("Name = [%s] Value = [%u]", CFG_ENABLE_NAN_DATAPATH_NAME,
Deepak Dhamdhere3385d752016-05-25 20:36:47 -070087 hdd_ctx->config->enable_nan_datapath);
Naveen Rawatba4f6612016-07-05 12:03:16 -070088 hdd_info("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 */
Deepak Dhamdhere13230d32016-05-26 00:46:53 -0700102void hdd_nan_datapath_target_config(hdd_context_t *hdd_ctx,
103 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 */
122static int hdd_close_ndi(hdd_adapter_t *adapter)
123{
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700124 int errno;
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700125 hdd_context_t *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 */
167static bool hdd_is_ndp_allowed(hdd_context_t *hdd_ctx)
168{
169 hdd_adapter_t *adapter;
170 hdd_station_ctx_t *sta_ctx;
171 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 */
212static int hdd_ndi_start_bss(hdd_adapter_t *adapter,
213 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 */
290static int hdd_get_random_nan_mac_addr(hdd_context_t *hdd_ctx,
291 struct qdf_mac_addr *mac_addr)
292{
293 hdd_adapter_t *adapter;
294 uint8_t i, attempts, max_attempt = 16;
295 struct qdf_mac_addr bcast_mac_addr = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
296
297 for (attempts = 0; attempts < max_attempt; attempts++) {
298 cds_rand_get_bytes(0, (uint8_t *)mac_addr, sizeof(*mac_addr));
299 WLAN_HDD_RESET_LOCALLY_ADMINISTERED_BIT(mac_addr->bytes);
300 /*
301 * to avoid potential conflict with FW's generated NMI mac addr,
302 * host sets LSB if 6th byte to 0
303 */
304 mac_addr->bytes[5] &= 0xFE;
305
306 if (!qdf_mem_cmp(mac_addr, &bcast_mac_addr, sizeof(*mac_addr)))
307 continue;
308
309 for (i = 0; i < QDF_MAX_CONCURRENCY_PERSONA; i++) {
310 if (!qdf_mem_cmp(hdd_ctx->config->intfMacAddr[i].bytes,
311 mac_addr, sizeof(*mac_addr)))
312 continue;
313 }
314
315 adapter = hdd_get_adapter_by_macaddr(hdd_ctx, mac_addr->bytes);
316 if (!adapter)
317 return 0;
318 }
319
320 hdd_err("unable to get non-pre-existing mac address in %d attempts",
321 max_attempt);
322
323 return -EINVAL;
324}
325
Naveen Rawat97500352017-03-22 10:07:58 -0700326#ifndef WLAN_FEATURE_NAN_CONVERGENCE
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700327/**
328 * hdd_ndi_create_req_handler() - NDI create request handler
329 * @hdd_ctx: hdd context
330 * @tb: parsed NL attribute list
331 *
332 * Return: 0 on success or error code on failure
333 */
334static int hdd_ndi_create_req_handler(hdd_context_t *hdd_ctx,
335 struct nlattr **tb)
336{
337 hdd_adapter_t *adapter;
338 char *iface_name;
339 uint16_t transaction_id;
340 int ret;
341 struct nan_datapath_ctx *ndp_ctx;
342 uint8_t op_channel =
343 hdd_ctx->config->nan_datapath_ndi_channel;
344
345 ENTER();
346
347 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700348 hdd_err("Interface name string is unavailable");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700349 return -EINVAL;
350 }
351 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
352
353 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700354 hdd_err("transaction id is unavailable");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700355 return -EINVAL;
356 }
357 transaction_id =
358 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
359
360 /* Check for an existing interface of NDI type */
361 adapter = hdd_get_adapter(hdd_ctx, QDF_NDI_MODE);
362 if (adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700363 hdd_err("Cannot support more than one NDI");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700364 return -EEXIST;
365 }
366
367 adapter = hdd_open_adapter(hdd_ctx, QDF_NDI_MODE, iface_name,
368 wlan_hdd_get_intf_addr(hdd_ctx), NET_NAME_UNKNOWN,
369 true);
370 if (!adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700371 hdd_err("hdd_open_adapter failed");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700372 return -ENOMEM;
373 }
374
375 /*
376 * Create transaction id is required to be saved since the firmware
377 * does not honor the transaction id for create request
378 */
379 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
380 ndp_ctx->ndp_create_transaction_id = transaction_id;
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700381 ndp_ctx->state = NAN_DATA_NDI_CREATING_STATE;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700382
383 /*
384 * The NAN data interface has been created at this point.
385 * Unlike traditional device modes, where the higher application
386 * layer initiates connect / join / start, the NAN data interface
387 * does not have any such formal requests. The NDI create request
388 * is responsible for starting the BSS as well.
389 */
390 if (op_channel != NAN_SOCIAL_CHANNEL_2_4GHZ ||
391 op_channel != NAN_SOCIAL_CHANNEL_5GHZ_LOWER_BAND ||
392 op_channel != NAN_SOCIAL_CHANNEL_5GHZ_UPPER_BAND) {
393 /* start NDI on the default 2.4 GHz social channel */
394 op_channel = NAN_SOCIAL_CHANNEL_2_4GHZ;
395 }
396 ret = hdd_ndi_start_bss(adapter, op_channel);
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700397 if (0 > ret) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700398 hdd_err("NDI start bss failed");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700399 /* Start BSS failed, delete the interface */
400 hdd_close_ndi(adapter);
401 }
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700402
403 EXIT();
404 return ret;
405}
406
407/**
408 * hdd_ndi_delete_req_handler() - NDI delete request handler
409 * @hdd_ctx: hdd context
410 * @tb: parsed NL attribute list
411 *
412 * Return: 0 on success or error code on failure
413 */
414static int hdd_ndi_delete_req_handler(hdd_context_t *hdd_ctx,
415 struct nlattr **tb)
416{
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700417 hdd_adapter_t *adapter;
418 char *iface_name;
419 uint16_t transaction_id;
420 struct nan_datapath_ctx *ndp_ctx;
421 int ret;
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700422 hdd_station_ctx_t *sta_ctx;
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700423
424 ENTER();
425
426 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700427 hdd_err("Interface name string is unavailable");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700428 return -EINVAL;
429 }
430
431 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
432
433 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700434 hdd_err("Transaction id is unavailable");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700435 return -EINVAL;
436 }
437
438 transaction_id =
439 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
440
441 /* Check if there is already an existing inteface with the same name */
442 adapter = hdd_get_adapter(hdd_ctx, QDF_NDI_MODE);
443 if (!adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700444 hdd_err("NAN data interface %s is not available", iface_name);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700445 return -EINVAL;
446 }
447
448 /* check if adapter is in NDI mode */
449 if (QDF_NDI_MODE != adapter->device_mode) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700450 hdd_err("Interface %s is not in NDI mode", iface_name);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700451 return -EINVAL;
452 }
453
454 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
455 if (!ndp_ctx) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700456 hdd_err("ndp_ctx is NULL");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700457 return -EINVAL;
458 }
459
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700460 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
461 if (!sta_ctx) {
462 hdd_err("sta_ctx is NULL");
463 return -EINVAL;
464 }
465
Naveen Rawatf28315c2016-06-29 18:06:02 -0700466 /* check if there are active peers on the adapter */
467 if (ndp_ctx->active_ndp_peers > 0) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700468 hdd_err("NDP peers active: %d, cannot delete NDI",
Naveen Rawatf28315c2016-06-29 18:06:02 -0700469 ndp_ctx->active_ndp_peers);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700470 return -EINVAL;
471 }
472
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700473 /*
474 * Since, the interface is being deleted, remove the
475 * broadcast id.
476 */
477 hdd_ctx->sta_to_adapter[sta_ctx->broadcast_staid] = 0;
478 sta_ctx->broadcast_staid = HDD_WLAN_INVALID_STA_ID;
479
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700480 ndp_ctx->ndp_delete_transaction_id = transaction_id;
481 ndp_ctx->state = NAN_DATA_NDI_DELETING_STATE;
482
483 /* Delete the interface */
484 ret = __wlan_hdd_del_virtual_intf(hdd_ctx->wiphy, &adapter->wdev);
485 if (ret < 0)
Naveen Rawatba4f6612016-07-05 12:03:16 -0700486 hdd_err("NDI delete request failed");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700487 else
Naveen Rawatba4f6612016-07-05 12:03:16 -0700488 hdd_err("NDI delete request successfully issued");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700489
490 return ret;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700491}
492
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700493/**
494 * hdd_ndp_initiator_req_handler() - NDP initiator request handler
495 * @hdd_ctx: hdd context
496 * @tb: parsed NL attribute list
497 *
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800498 * tb will contain following vendor attributes:
499 * QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR
500 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID
501 * QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL - optional
Ravi Joshi71e82f32017-02-09 23:15:16 -0800502 * QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL_CONFIG - optional
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800503 * QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID
504 * QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR
505 * QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO - optional
506 * QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS - optional
507 * QCA_WLAN_VENDOR_ATTR_NDP_PMK - optional
508 * QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE - optional
509 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700510 * Return: 0 on success or error code on failure
511 */
512static int hdd_ndp_initiator_req_handler(hdd_context_t *hdd_ctx,
513 struct nlattr **tb)
514{
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700515 hdd_adapter_t *adapter;
516 char *iface_name;
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -0700517 struct ndp_initiator_req req = {0};
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700518 QDF_STATUS status;
519 uint32_t ndp_qos_cfg;
520 tHalHandle hal = hdd_ctx->hHal;
521 struct nan_datapath_ctx *ndp_ctx;
522
523 ENTER();
524
525 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700526 hdd_err("Interface name string is unavailable");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700527 return -EINVAL;
528 }
529
530 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
531 /* Check for interface in NDI mode */
532 adapter = hdd_get_adapter(hdd_ctx, QDF_NDI_MODE);
533 if (!adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700534 hdd_err("NAN data interface %s not available", iface_name);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700535 return -EINVAL;
536 }
537
538 /* NAN data path coexists only with STA interface */
539 if (false == hdd_is_ndp_allowed(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700540 hdd_err("Unsupported concurrency for NAN datapath");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700541 return -EPERM;
542 }
543
544 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
545
546 if (ndp_ctx->state == NAN_DATA_NDI_DELETED_STATE ||
547 ndp_ctx->state == NAN_DATA_NDI_DELETING_STATE ||
548 ndp_ctx->state == NAN_DATA_NDI_CREATING_STATE) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700549 hdd_err("Data request not allowed in NDI current state: %d",
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700550 ndp_ctx->state);
551 return -EINVAL;
552 }
553
554 req.vdev_id = adapter->sessionId;
555
556 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700557 hdd_err("Transaction ID is unavailable");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700558 return -EINVAL;
559 }
560 req.transaction_id =
561 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
562
Naveen Rawat0a017052016-10-19 14:17:07 -0700563 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL])
564 req.channel =
565 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL]);
566
Ravi Joshi71e82f32017-02-09 23:15:16 -0800567 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL_CONFIG])
Naveen Rawat0a017052016-10-19 14:17:07 -0700568 req.channel_cfg =
569 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_CHANNEL_CONFIG]);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700570
571 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700572 hdd_err("NDP service instance ID is unavailable");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700573 return -EINVAL;
574 }
575 req.service_instance_id =
Naveen Rawat19da3d12016-08-16 12:39:38 -0700576 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID]);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700577
578 qdf_mem_copy(req.self_ndi_mac_addr.bytes,
579 adapter->macAddressCurrent.bytes, QDF_MAC_ADDR_SIZE);
580
581 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700582 hdd_err("NDI peer discovery mac addr is unavailable");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700583 return -EINVAL;
584 }
585 qdf_mem_copy(req.peer_discovery_mac_addr.bytes,
586 nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR]),
587 QDF_MAC_ADDR_SIZE);
588
Naveen Rawat90ae3082016-06-29 18:22:59 -0700589 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]) {
590 req.ndp_info.ndp_app_info_len =
591 nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]);
592 req.ndp_info.ndp_app_info =
593 nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700594 }
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700595
596 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS]) {
597 /* at present ndp config stores 4 bytes QOS info only */
598 req.ndp_config.ndp_cfg_len = 4;
599 req.ndp_config.ndp_cfg = (uint8_t *)&ndp_qos_cfg;
600 ndp_qos_cfg =
601 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS]);
602 }
603
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800604 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE] &&
605 !tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]) {
606 hdd_err("PMK cannot be absent when CSID is present.");
607 return -EINVAL;
608 }
609
610 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]) {
611 req.pmk.pmk = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]);
612 req.pmk.pmk_len = nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]);
613 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD,
614 QDF_TRACE_LEVEL_DEBUG,
615 req.pmk.pmk, req.pmk.pmk_len);
616 }
617
618 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE]) {
619 req.ncs_sk_type =
620 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE]);
621
622 }
623
Ravi Joshi71e82f32017-02-09 23:15:16 -0800624 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",
625 req.vdev_id, req.transaction_id, req.channel, req.channel_cfg,
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700626 req.service_instance_id, req.ndp_info.ndp_app_info_len,
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800627 req.ncs_sk_type, req.peer_discovery_mac_addr.bytes);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700628 status = sme_ndp_initiator_req_handler(hal, &req);
629 if (status != QDF_STATUS_SUCCESS) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700630 hdd_err("sme_ndp_initiator_req_handler failed, status: %d",
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -0700631 status);
632 return -ECOMM;
633 }
634 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700635 return 0;
636}
637
638/**
639 * hdd_ndp_responder_req_handler() - NDP responder request handler
640 * @hdd_ctx: hdd context
641 * @tb: parsed NL attribute list
642 *
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800643 * tb includes following vendor attributes:
644 * QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR
645 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID
646 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID
647 * QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE
648 * QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO - optional
649 * QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS - optional
650 * QCA_WLAN_VENDOR_ATTR_NDP_PMK - optional
651 * QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE - optional
652 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700653 * Return: 0 on success or error code on failure
654 */
655static int hdd_ndp_responder_req_handler(hdd_context_t *hdd_ctx,
656 struct nlattr **tb)
657{
Abhishek Singh4fef7472016-06-06 11:36:03 -0700658 hdd_adapter_t *adapter;
659 char *iface_name;
660 struct ndp_responder_req req = {0};
661 QDF_STATUS status;
662 int ret = 0;
663 struct nan_datapath_ctx *ndp_ctx;
664 uint32_t ndp_qos_cfg;
665
666 ENTER();
667
668 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700669 hdd_err("Interface name string is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700670 return -EINVAL;
671 }
672
673 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
674 /* Check if there is already an existing NAN interface */
675 adapter = hdd_get_adapter(hdd_ctx, QDF_NDI_MODE);
676 if (!adapter) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700677 hdd_err("NAN data interface %s not available", iface_name);
Abhishek Singh4fef7472016-06-06 11:36:03 -0700678 return -EINVAL;
679 }
680
681 if (QDF_NDI_MODE != adapter->device_mode) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700682 hdd_err("Interface %s not in NDI mode", iface_name);
Abhishek Singh4fef7472016-06-06 11:36:03 -0700683 return -EINVAL;
684 }
685
686 /* NAN data path coexists only with STA interface */
687 if (!hdd_is_ndp_allowed(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700688 hdd_err("Unsupported concurrency for NAN datapath");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700689 return -EINVAL;
690 }
691
692 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
693
694 if (ndp_ctx->state == NAN_DATA_NDI_DELETED_STATE ||
695 ndp_ctx->state == NAN_DATA_NDI_DELETING_STATE ||
696 ndp_ctx->state == NAN_DATA_NDI_CREATING_STATE) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700697 hdd_err("Data request not allowed in current NDI state: %d",
Abhishek Singh4fef7472016-06-06 11:36:03 -0700698 ndp_ctx->state);
699 return -EAGAIN;
700 }
701
702 req.vdev_id = adapter->sessionId;
703
704 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700705 hdd_err("Transaction ID is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700706 return -EINVAL;
707 }
708 req.transaction_id =
709 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
710
711 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700712 hdd_err("Instance ID is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700713 return -EINVAL;
714 }
715 req.ndp_instance_id =
716 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID]);
717
718 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700719 hdd_err("ndp_rsp is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700720 return -EINVAL;
721 }
722 req.ndp_rsp = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE]);
723
724 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]) {
725 req.ndp_info.ndp_app_info_len =
726 nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]);
727 if (req.ndp_info.ndp_app_info_len) {
728 req.ndp_info.ndp_app_info =
729 nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO]);
730 }
731 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700732 hdd_info("NDP app info is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700733 }
734 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS]) {
735 /* at present ndp config stores 4 bytes QOS info only */
736 req.ndp_config.ndp_cfg_len = 4;
737 ndp_qos_cfg =
738 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS]);
739 req.ndp_config.ndp_cfg = (uint8_t *)&ndp_qos_cfg;
740 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700741 hdd_info("NDP config data is unavailable");
Abhishek Singh4fef7472016-06-06 11:36:03 -0700742 }
743
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800744 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE] &&
745 !tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]) {
746 hdd_err("PMK cannot be absent when CSID is present.");
747 return -EINVAL;
748 }
749
750 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]) {
751 req.pmk.pmk = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]);
752 req.pmk.pmk_len = nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_PMK]);
753 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD,
754 QDF_TRACE_LEVEL_DEBUG,
755 req.pmk.pmk, req.pmk.pmk_len);
756 }
757
758 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE]) {
759 req.ncs_sk_type =
760 nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE]);
761
762 }
763
764 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 -0700765 req.vdev_id, req.transaction_id, req.ndp_rsp,
Naveen Rawat4f3983e2016-11-29 16:12:09 -0800766 req.ndp_instance_id, req.ndp_info.ndp_app_info_len,
767 req.ncs_sk_type);
Abhishek Singh4fef7472016-06-06 11:36:03 -0700768
769 status = sme_ndp_responder_req_handler(hdd_ctx->hHal, &req);
770 if (status != QDF_STATUS_SUCCESS) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700771 hdd_err("sme_ndp_initiator_req_handler failed, status: %d",
Abhishek Singh4fef7472016-06-06 11:36:03 -0700772 status);
773 ret = -EINVAL;
774 }
775
776 EXIT();
777 return ret;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700778}
779
780/**
781 * hdd_ndp_end_req_handler() - NDP end request handler
782 * @hdd_ctx: hdd context
783 * @tb: parsed NL attribute list
784 *
785 * Return: 0 on success or error code on failure
786 */
Naveen Rawatf28315c2016-06-29 18:06:02 -0700787static int hdd_ndp_end_req_handler(hdd_context_t *hdd_ctx, struct nlattr **tb)
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700788{
Naveen Rawatf28315c2016-06-29 18:06:02 -0700789 struct ndp_end_req req = {0};
790 QDF_STATUS status;
791 tHalHandle hal = hdd_ctx->hHal;
792
793 ENTER();
794
795 /* NAN data path coexists only with STA interface */
796 if (!hdd_is_ndp_allowed(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700797 hdd_err("Unsupported concurrency for NAN datapath");
Naveen Rawatf28315c2016-06-29 18:06:02 -0700798 return -EINVAL;
799 }
800
801 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700802 hdd_err("Transaction ID is unavailable");
Naveen Rawatf28315c2016-06-29 18:06:02 -0700803 return -EINVAL;
804 }
805 req.transaction_id =
806 nla_get_u16(tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
807
808 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700809 hdd_err("NDP instance ID array is unavailable");
Naveen Rawatf28315c2016-06-29 18:06:02 -0700810 return -EINVAL;
811 }
812
813 req.num_ndp_instances =
814 nla_len(tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY]) /
815 sizeof(uint32_t);
816 if (0 >= req.num_ndp_instances) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700817 hdd_err("Num NDP instances is 0");
Naveen Rawatf28315c2016-06-29 18:06:02 -0700818 return -EINVAL;
819 }
820 req.ndp_ids = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY]);
821
Naveen Rawatba4f6612016-07-05 12:03:16 -0700822 hdd_info("sending ndp_end_req to SME, transaction_id: %d",
Naveen Rawatf28315c2016-06-29 18:06:02 -0700823 req.transaction_id);
824
825 status = sme_ndp_end_req_handler(hal, &req);
826 if (status != QDF_STATUS_SUCCESS) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700827 hdd_err("sme_ndp_end_req_handler failed, status: %d",
Naveen Rawatf28315c2016-06-29 18:06:02 -0700828 status);
829 return -ECOMM;
830 }
831 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700832 return 0;
833}
834
835/**
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700836 * hdd_ndp_iface_create_rsp_handler() - NDP iface create response handler
837 * @adapter: pointer to adapter context
838 * @rsp_params: response parameters
839 *
840 * The function is expected to send a response back to the user space
841 * even if the creation of BSS has failed
842 *
843 * Following vendor event is sent to cfg80211:
844 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
845 * QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_CREATE (4 bytes)
846 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
Rakesh Sunkid92d1082017-01-04 15:14:28 -0800847 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700848 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE
849 *
850 * Return: none
851 */
852static void hdd_ndp_iface_create_rsp_handler(hdd_adapter_t *adapter,
853 void *rsp_params)
854{
855 struct sk_buff *vendor_event;
856 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
857 struct ndi_create_rsp *ndi_rsp = (struct ndi_create_rsp *)rsp_params;
858 uint32_t data_len = (3 * sizeof(uint32_t)) + sizeof(uint16_t) +
859 NLMSG_HDRLEN + (4 * NLA_HDRLEN);
860 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700861 bool create_fail = false;
862 uint8_t create_transaction_id = 0;
Naveen Rawate21103f2016-07-08 14:18:00 -0700863 uint32_t create_status = NDP_RSP_STATUS_ERROR;
864 uint32_t create_reason = NDP_NAN_DATA_IFACE_CREATE_FAILED;
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700865 hdd_station_ctx_t *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
866 struct qdf_mac_addr bc_mac_addr = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
867 tCsrRoamInfo roam_info = {0};
868 tSirBssDescription tmp_bss_descp = {0};
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700869
870 ENTER();
871
872 if (wlan_hdd_validate_context(hdd_ctx))
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700873 /* No way the driver can send response back to user space */
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700874 return;
875
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700876 if (ndi_rsp) {
877 create_status = ndi_rsp->status;
Naveen Rawate21103f2016-07-08 14:18:00 -0700878 create_reason = ndi_rsp->reason;
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700879 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700880 hdd_err("Invalid ndi create response");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700881 create_fail = true;
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700882 }
883
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700884 if (ndp_ctx) {
885 create_transaction_id = ndp_ctx->ndp_create_transaction_id;
886 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700887 hdd_err("ndp_ctx is NULL");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700888 create_fail = true;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700889 }
890
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700891 if (!sta_ctx) {
892 hdd_err("sta_ctx is NULL");
893 create_fail = true;
894 }
895
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700896 /* notify response to the upper layer */
897 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
898 NULL,
899 data_len,
900 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
901 cds_get_gfp_flags());
902
903 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700904 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700905 create_fail = true;
906 goto close_ndi;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700907 }
908
909 /* Sub vendor command */
910 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
911 QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_CREATE)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700912 hdd_err("QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD put fail");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700913 goto nla_put_failure;
914 }
915
916 /* Transaction id */
917 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700918 create_transaction_id)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700919 hdd_err("VENDOR_ATTR_NDP_TRANSACTION_ID put fail");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700920 goto nla_put_failure;
921 }
922
923 /* Status code */
Rakesh Sunkid92d1082017-01-04 15:14:28 -0800924 if (nla_put_u32(vendor_event,
925 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700926 create_status)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700927 hdd_err("VENDOR_ATTR_NDP_DRV_RETURN_TYPE put fail");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700928 goto nla_put_failure;
929 }
930
931 /* Status return value */
932 if (nla_put_u32(vendor_event,
Naveen Rawat8d63a592016-06-29 18:30:59 -0700933 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
Naveen Rawate21103f2016-07-08 14:18:00 -0700934 create_reason)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700935 hdd_err("VENDOR_ATTR_NDP_DRV_RETURN_VALUE put fail");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700936 goto nla_put_failure;
937 }
938
Naveen Rawatba4f6612016-07-05 12:03:16 -0700939 hdd_info("sub command: %d, value: %d",
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700940 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
941 QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_CREATE);
Naveen Rawatba4f6612016-07-05 12:03:16 -0700942 hdd_info("create transaction id: %d, value: %d",
943 QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID, create_transaction_id);
944 hdd_info("status code: %d, value: %d",
Rakesh Sunkid92d1082017-01-04 15:14:28 -0800945 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
946 create_status);
Naveen Rawatba4f6612016-07-05 12:03:16 -0700947 hdd_info("Return value: %d, value: %d",
Naveen Rawate21103f2016-07-08 14:18:00 -0700948 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE, create_reason);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700949
950 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
951
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700952 if (!create_fail && ndi_rsp->status == QDF_STATUS_SUCCESS) {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700953 hdd_err("NDI interface successfully created");
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700954 ndp_ctx->ndp_create_transaction_id = 0;
955 ndp_ctx->state = NAN_DATA_NDI_CREATED_STATE;
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -0700956 wlan_hdd_netif_queue_control(adapter,
957 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
958 WLAN_CONTROL_PATH);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700959 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -0700960 hdd_err("NDI interface creation failed with reason %d",
Naveen Rawate21103f2016-07-08 14:18:00 -0700961 create_reason);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700962 }
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700963
964 /* Something went wrong while starting the BSS */
965 if (create_fail)
966 goto close_ndi;
967
Rakesh Sunkicf1c9ab2016-08-25 14:11:25 -0700968 sta_ctx->broadcast_staid = ndi_rsp->sta_id;
969 hdd_save_peer(sta_ctx, sta_ctx->broadcast_staid, &bc_mac_addr);
970 hdd_roam_register_sta(adapter, &roam_info,
971 sta_ctx->broadcast_staid,
972 &bc_mac_addr, &tmp_bss_descp);
973 hdd_ctx->sta_to_adapter[sta_ctx->broadcast_staid] = adapter;
974
975
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700976 EXIT();
977 return;
978
979nla_put_failure:
980 kfree_skb(vendor_event);
Deepak Dhamdhere616d9c52016-06-01 12:39:51 -0700981close_ndi:
982 hdd_close_ndi(adapter);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -0700983 return;
984}
985
986/**
987 * hdd_ndp_iface_delete_rsp_handler() - NDP iface delete response handler
988 * @adapter: pointer to adapter context
989 * @rsp_params: response parameters
990 *
991 * Return: none
992 */
993static void hdd_ndp_iface_delete_rsp_handler(hdd_adapter_t *adapter,
994 void *rsp_params)
995{
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700996 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
997 struct ndi_delete_rsp *ndi_rsp = rsp_params;
Naveen Rawat8d63a592016-06-29 18:30:59 -0700998 struct nan_datapath_ctx *ndp_ctx;
Deepak Dhamdhere13983f22016-05-31 19:06:09 -0700999
1000 if (wlan_hdd_validate_context(hdd_ctx))
1001 return;
1002
1003 if (!ndi_rsp) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001004 hdd_err("Invalid ndi delete response");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001005 return;
1006 }
1007
Naveen Rawat8d63a592016-06-29 18:30:59 -07001008 if (ndi_rsp->status == NDP_RSP_STATUS_SUCCESS)
Naveen Rawatba4f6612016-07-05 12:03:16 -07001009 hdd_err("NDI BSS successfully stopped");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001010 else
Naveen Rawatba4f6612016-07-05 12:03:16 -07001011 hdd_err("NDI BSS stop failed with reason %d", ndi_rsp->reason);
Naveen Rawat8d63a592016-06-29 18:30:59 -07001012
1013 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
1014 ndp_ctx->ndi_delete_rsp_reason = ndi_rsp->reason;
1015 ndp_ctx->ndi_delete_rsp_status = ndi_rsp->status;
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -07001016 wlan_hdd_netif_queue_control(adapter,
1017 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
1018 WLAN_CONTROL_PATH);
Naveen Rawat8d63a592016-06-29 18:30:59 -07001019
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001020 complete(&adapter->disconnect_comp_var);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001021 return;
1022}
1023
1024/**
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001025 * hdd_ndp_session_end_handler() - NDI session termination handler
1026 * @adapter: pointer to adapter context
1027 *
1028 * Following vendor event is sent to cfg80211:
1029 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1030 * QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_DELETE (4 bytes)
1031 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001032 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001033 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE (4 bytes)
1034 *
1035 * Return: none
1036 */
1037void hdd_ndp_session_end_handler(hdd_adapter_t *adapter)
1038{
1039 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1040 struct sk_buff *vendor_event;
1041 struct nan_datapath_ctx *ndp_ctx;
1042 uint32_t data_len = sizeof(uint32_t) * (3 + sizeof(uint16_t)) +
1043 (NLA_HDRLEN * 4) + NLMSG_HDRLEN;
1044
1045 ENTER();
1046
1047 if (wlan_hdd_validate_context(hdd_ctx))
1048 return;
1049
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001050 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
1051 if (!ndp_ctx) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001052 hdd_err("ndp context is NULL");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001053 return;
1054 }
1055
1056 /*
1057 * The virtual adapters are stopped and closed even during
1058 * driver unload or stop, the service layer is not required
1059 * to be informed in that case (response is not expected)
1060 */
1061 if (NAN_DATA_NDI_DELETING_STATE != ndp_ctx->state) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001062 hdd_err("NDI interface %s deleted", adapter->dev->name);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001063 return;
1064 }
1065
1066 /* notify response to the upper layer */
1067 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
1068 NULL,
1069 data_len,
1070 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1071 GFP_KERNEL);
1072
1073 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001074 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001075 return;
1076 }
1077
1078 /* Sub vendor command goes first */
1079 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1080 QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_DELETE)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001081 hdd_err("VENDOR_ATTR_NDP_SUBCMD put fail");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001082 goto failure;
1083 }
1084
1085 /* Transaction id */
1086 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1087 ndp_ctx->ndp_delete_transaction_id)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001088 hdd_err("VENDOR_ATTR_NDP_TRANSACTION_ID put fail");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001089 goto failure;
1090 }
1091
1092 /* Status code */
1093 if (nla_put_u32(vendor_event,
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001094 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001095 ndp_ctx->ndi_delete_rsp_status)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001096 hdd_err("VENDOR_ATTR_NDP_DRV_RETURN_TYPE put fail");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001097 goto failure;
1098 }
1099
1100 /* Status return value */
1101 if (nla_put_u32(vendor_event,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001102 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
1103 ndp_ctx->ndi_delete_rsp_reason)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001104 hdd_err("VENDOR_ATTR_NDP_DRV_RETURN_VALUE put fail");
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001105 goto failure;
1106 }
1107
Naveen Rawatba4f6612016-07-05 12:03:16 -07001108 hdd_info("sub command: %d, value: %d", QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001109 QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_DELETE);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001110 hdd_info("delete transaction id: %d, value: %d",
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001111 QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1112 ndp_ctx->ndp_delete_transaction_id);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001113 hdd_info("status code: %d, value: %d",
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001114 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001115 ndp_ctx->ndi_delete_rsp_status);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001116 hdd_info("Return value: %d, value: %d",
Naveen Rawat8d63a592016-06-29 18:30:59 -07001117 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
1118 ndp_ctx->ndi_delete_rsp_reason);
Deepak Dhamdhere13983f22016-05-31 19:06:09 -07001119
1120 ndp_ctx->ndp_delete_transaction_id = 0;
1121 ndp_ctx->state = NAN_DATA_NDI_DELETED_STATE;
1122
1123 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1124
1125 EXIT();
1126 return;
1127
1128failure:
1129 kfree_skb(vendor_event);
1130}
1131
1132
1133/**
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001134 * hdd_ndp_initiator_rsp_handler() - NDP initiator response handler
1135 * @adapter: pointer to adapter context
1136 * @rsp_params: response parameters
1137 *
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001138 * Following vendor event is sent to cfg80211:
1139 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1140 * QCA_WLAN_VENDOR_ATTR_NDP_INITIATOR_RESPONSE (4 bytes)
1141 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
1142 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID (4 bytes)
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001143 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001144 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE (4 bytes)
1145 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001146 * Return: none
1147 */
1148static void hdd_ndp_initiator_rsp_handler(hdd_adapter_t *adapter,
1149 void *rsp_params)
1150{
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001151 struct sk_buff *vendor_event;
1152 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1153 struct ndp_initiator_rsp *rsp = rsp_params;
1154 uint32_t data_len = (4 * sizeof(uint32_t)) + (1 * sizeof(uint16_t)) +
1155 NLMSG_HDRLEN + (5 * NLA_HDRLEN);
1156
1157 ENTER();
1158
1159 if (!rsp) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001160 hdd_err("Invalid NDP Initator response");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001161 return;
1162 }
1163
1164 if (0 != wlan_hdd_validate_context(hdd_ctx))
1165 return;
1166
1167 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy, NULL,
1168 data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1169 GFP_KERNEL);
1170 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001171 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001172 return;
1173 }
1174
1175 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1176 QCA_WLAN_VENDOR_ATTR_NDP_INITIATOR_RESPONSE))
1177 goto ndp_initiator_rsp_nla_failed;
1178
1179 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1180 rsp->transaction_id))
1181 goto ndp_initiator_rsp_nla_failed;
1182
1183 if (nla_put_u32(vendor_event,
1184 QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID,
1185 rsp->ndp_instance_id))
1186 goto ndp_initiator_rsp_nla_failed;
1187
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001188 if (nla_put_u32(vendor_event,
1189 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001190 rsp->status))
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001191 goto ndp_initiator_rsp_nla_failed;
1192
1193 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001194 rsp->reason))
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001195 goto ndp_initiator_rsp_nla_failed;
1196
Naveen Rawatba4f6612016-07-05 12:03:16 -07001197 hdd_info("NDP Initiator rsp sent, tid:%d, instance id:%d, status:%d, reason: %d",
Naveen Rawat8d63a592016-06-29 18:30:59 -07001198 rsp->transaction_id, rsp->ndp_instance_id, rsp->status,
1199 rsp->reason);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001200 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1201 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001202 return;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001203ndp_initiator_rsp_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001204 hdd_err("nla_put api failed");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001205 kfree_skb(vendor_event);
1206 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001207}
1208
1209/**
1210 * hdd_ndp_new_peer_ind_handler() - NDP new peer indication handler
1211 * @adapter: pointer to adapter context
1212 * @ind_params: indication parameters
1213 *
1214 * Return: none
1215 */
1216static void hdd_ndp_new_peer_ind_handler(hdd_adapter_t *adapter,
1217 void *ind_params)
1218{
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001219 struct sme_ndp_peer_ind *new_peer_ind = ind_params;
1220 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1221 tSirBssDescription tmp_bss_descp = {0};
1222 tCsrRoamInfo roam_info = {0};
1223 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
1224 hdd_station_ctx_t *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1225
1226 ENTER();
1227
1228 if (NULL == ind_params) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001229 hdd_err("Invalid new NDP peer params");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001230 return;
1231 }
Naveen Rawatba4f6612016-07-05 12:03:16 -07001232 hdd_info("session_id: %d, peer_mac: %pM, sta_id: %d",
Naveen Rawatf28315c2016-06-29 18:06:02 -07001233 new_peer_ind->session_id, new_peer_ind->peer_mac_addr.bytes,
1234 new_peer_ind->sta_id);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001235
1236 /* save peer in ndp ctx */
1237 if (false == hdd_save_peer(sta_ctx, new_peer_ind->sta_id,
1238 &new_peer_ind->peer_mac_addr)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001239 hdd_err("Ndp peer table full. cannot save new peer");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001240 return;
1241 }
1242
1243 /* this function is called for each new peer */
1244 ndp_ctx->active_ndp_peers++;
Naveen Rawatba4f6612016-07-05 12:03:16 -07001245 hdd_info("vdev_id: %d, num_peers: %d", adapter->sessionId,
1246 ndp_ctx->active_ndp_peers);
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -07001247
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001248 hdd_roam_register_sta(adapter, &roam_info, new_peer_ind->sta_id,
1249 &new_peer_ind->peer_mac_addr, &tmp_bss_descp);
1250 hdd_ctx->sta_to_adapter[new_peer_ind->sta_id] = adapter;
1251 /* perform following steps for first new peer ind */
1252 if (ndp_ctx->active_ndp_peers == 1) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001253 hdd_info("Set ctx connection state to connected");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001254 sta_ctx->conn_info.connState = eConnectionState_NdiConnected;
1255 hdd_wmm_connect(adapter, &roam_info, eCSR_BSS_TYPE_NDI);
Deepak Dhamdhere5872c8c2016-06-02 15:51:47 -07001256 wlan_hdd_netif_queue_control(adapter,
1257 WLAN_WAKE_ALL_NETIF_QUEUE, WLAN_CONTROL_PATH);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001258 }
1259 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001260}
1261
1262/**
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001263 * hdd_ndp_peer_departed_ind_handler() - Handle NDP peer departed indication
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001264 * @adapter: pointer to adapter context
1265 * @ind_params: indication parameters
1266 *
1267 * Return: none
1268 */
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001269static void hdd_ndp_peer_departed_ind_handler(hdd_adapter_t *adapter,
1270 void *ind_params)
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001271{
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001272 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1273 struct sme_ndp_peer_ind *peer_ind = ind_params;
1274 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
1275 hdd_station_ctx_t *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1276
1277 hdd_roam_deregister_sta(adapter, peer_ind->sta_id);
1278 hdd_delete_peer(sta_ctx, peer_ind->sta_id);
1279 hdd_ctx->sta_to_adapter[peer_ind->sta_id] = 0;
1280
1281 if (--ndp_ctx->active_ndp_peers == 0) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001282 hdd_info("No more ndp peers.");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001283 sta_ctx->conn_info.connState = eConnectionState_NdiDisconnected;
1284 hdd_conn_set_connection_state(adapter,
1285 eConnectionState_NdiDisconnected);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001286 hdd_info("Stop netif tx queues.");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001287 wlan_hdd_netif_queue_control(adapter, WLAN_STOP_ALL_NETIF_QUEUE,
1288 WLAN_CONTROL_PATH);
1289 }
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001290}
1291
1292/**
1293 * hdd_ndp_confirm_ind_handler() - NDP confirm indication handler
1294 * @adapter: pointer to adapter context
1295 * @ind_params: indication parameters
1296 *
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001297 * Following vendor event is sent to cfg80211:
1298 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1299 * QCA_WLAN_VENDOR_ATTR_NDP_CONFIRM_IND (4 bytes)
1300 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID (4 bytes)
1301 * QCA_WLAN_VENDOR_ATTR_NDP_NDI_MAC_ADDR (6 bytes)
1302 * QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR (IFNAMSIZ)
1303 * QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO (ndp_app_info_len size)
1304 * QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE (4 bytes)
1305 * QCA_WLAN_VENDOR_ATTR_NDP_RETURN_VALUE (4 bytes)
1306 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001307 * Return: none
1308 */
1309static void hdd_ndp_confirm_ind_handler(hdd_adapter_t *adapter,
1310 void *ind_params)
1311{
Naveen Rawatf28315c2016-06-29 18:06:02 -07001312 int idx;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001313 uint32_t ndp_qos_config = 0;
1314 struct ndp_confirm_event *ndp_confirm = ind_params;
1315 struct sk_buff *vendor_event;
1316 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1317 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
Naveen Rawatf28315c2016-06-29 18:06:02 -07001318 hdd_station_ctx_t *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001319 uint32_t data_len;
1320
1321 ENTER();
1322 if (!ndp_confirm) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001323 hdd_err("Invalid NDP Initator response");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001324 return;
1325 }
1326
1327 if (0 != wlan_hdd_validate_context(hdd_ctx))
1328 return;
1329
Naveen Rawatf28315c2016-06-29 18:06:02 -07001330 /* ndp_confirm is called each time user generated ndp req succeeds */
1331 idx = hdd_get_peer_idx(sta_ctx, &ndp_confirm->peer_ndi_mac_addr);
1332 if (idx == INVALID_PEER_IDX)
Naveen Rawatba4f6612016-07-05 12:03:16 -07001333 hdd_err("can't find addr: %pM in vdev_id: %d, peer table.",
Naveen Rawatf28315c2016-06-29 18:06:02 -07001334 &ndp_confirm->peer_ndi_mac_addr, adapter->sessionId);
Naveen Rawat460be782016-06-29 18:26:22 -07001335 else if (ndp_confirm->rsp_code == NDP_RESPONSE_ACCEPT)
Naveen Rawatf28315c2016-06-29 18:06:02 -07001336 ndp_ctx->active_ndp_sessions[idx]++;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001337
1338 data_len = (4 * sizeof(uint32_t)) + QDF_MAC_ADDR_SIZE + IFNAMSIZ +
Naveen Rawat90ae3082016-06-29 18:22:59 -07001339 + NLMSG_HDRLEN + (7 * NLA_HDRLEN) +
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001340 ndp_confirm->ndp_info.ndp_app_info_len;
1341
Naveen Rawat8d63a592016-06-29 18:30:59 -07001342 if (ndp_confirm->ndp_info.ndp_app_info_len)
1343 data_len += NLA_HDRLEN + ndp_confirm->ndp_info.ndp_app_info_len;
1344
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001345 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy, NULL,
1346 data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1347 GFP_KERNEL);
1348 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001349 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001350 return;
1351 }
1352
1353 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1354 QCA_WLAN_VENDOR_ATTR_NDP_CONFIRM_IND))
1355 goto ndp_confirm_nla_failed;
1356
1357 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID,
1358 ndp_confirm->ndp_instance_id))
1359 goto ndp_confirm_nla_failed;
1360
1361 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_NDI_MAC_ADDR,
1362 QDF_MAC_ADDR_SIZE, ndp_confirm->peer_ndi_mac_addr.bytes))
1363 goto ndp_confirm_nla_failed;
1364
1365 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR,
1366 IFNAMSIZ, adapter->dev->name))
1367 goto ndp_confirm_nla_failed;
1368
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001369 if (ndp_confirm->ndp_info.ndp_app_info_len && nla_put(vendor_event,
Naveen Rawat8d63a592016-06-29 18:30:59 -07001370 QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO,
1371 ndp_confirm->ndp_info.ndp_app_info_len,
1372 ndp_confirm->ndp_info.ndp_app_info))
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001373 goto ndp_confirm_nla_failed;
1374
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001375 if (nla_put_u32(vendor_event,
1376 QCA_WLAN_VENDOR_ATTR_NDP_RESPONSE_CODE,
1377 ndp_confirm->rsp_code))
1378 goto ndp_confirm_nla_failed;
1379
Naveen Rawat8d63a592016-06-29 18:30:59 -07001380 if (nla_put_u32(vendor_event,
1381 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
1382 ndp_confirm->reason_code))
1383 goto ndp_confirm_nla_failed;
1384
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001385 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001386 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 -07001387 ndp_confirm->ndp_instance_id,
1388 ndp_confirm->peer_ndi_mac_addr.bytes,
Naveen Rawat460be782016-06-29 18:26:22 -07001389 ndp_qos_config, ndp_confirm->rsp_code,
1390 ndp_confirm->reason_code);
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001391
Naveen Rawatba4f6612016-07-05 12:03:16 -07001392 hdd_info("NDP confim, ndp app info dump");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001393 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
1394 ndp_confirm->ndp_info.ndp_app_info,
1395 ndp_confirm->ndp_info.ndp_app_info_len);
1396 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001397 return;
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001398ndp_confirm_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001399 hdd_err("nla_put api failed");
Deepak Dhamdhere0f076bd2016-06-02 11:29:21 -07001400 kfree_skb(vendor_event);
1401 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001402}
1403
1404/**
1405 * hdd_ndp_indication_handler() - NDP indication handler
1406 * @adapter: pointer to adapter context
1407 * @ind_params: indication parameters
1408 *
Abhishek Singh4fef7472016-06-06 11:36:03 -07001409 * Following vendor event is sent to cfg80211:
1410 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1411 * QCA_WLAN_VENDOR_ATTR_NDP_REQUEST_IND (4 bytes)
1412 * QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR (IFNAMSIZ)
Naveen Rawat19da3d12016-08-16 12:39:38 -07001413 * QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID (4 bytes)
Abhishek Singh4fef7472016-06-06 11:36:03 -07001414 * QCA_WLAN_VENDOR_ATTR_NDP_NDI_MAC_ADDR (6 bytes)
1415 * QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR (6 bytes)
1416 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID (4 bytes)
1417 * QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO (ndp_app_info_len size)
1418 * QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS (4 bytes)
Naveen Rawat4f3983e2016-11-29 16:12:09 -08001419 * QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE(4 bytes)
1420 * QCA_WLAN_VENDOR_ATTR_NDP_SCID(scid_len in size)
Abhishek Singh4fef7472016-06-06 11:36:03 -07001421 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001422 * Return: none
1423 */
1424static void hdd_ndp_indication_handler(hdd_adapter_t *adapter,
1425 void *ind_params)
1426{
Abhishek Singh4fef7472016-06-06 11:36:03 -07001427 struct sk_buff *vendor_event;
1428 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1429 struct ndp_indication_event *event = ind_params;
1430 uint32_t ndp_qos_config;
1431 struct nan_datapath_ctx *ndp_ctx;
1432 uint16_t data_len;
1433
1434 ENTER();
1435 if (!ind_params) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001436 hdd_err("Invalid NDP Indication");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001437 return;
1438 }
1439
1440 if (0 != wlan_hdd_validate_context(hdd_ctx))
1441 return;
1442
1443 /* Handle only if adapter is in NDI mode */
1444 if (QDF_NDI_MODE != adapter->device_mode) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001445 hdd_err("Adapter is not in NDI mode");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001446 return;
1447 }
1448
Naveen Rawatba4f6612016-07-05 12:03:16 -07001449 hdd_info("NDP Indication, policy: %d", event->policy);
Abhishek Singh4fef7472016-06-06 11:36:03 -07001450
1451 /* Policy check */
1452 if (!WLAN_HDD_IS_NDP_ENABLED(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001453 hdd_err("NAN datapath is not suported");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001454 return;
1455 }
1456
1457 /* NAN data path coexists only with STA interface */
1458 if (!hdd_is_ndp_allowed(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001459 hdd_err("Unsupported concurrency for NAN datapath");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001460 return;
1461 }
1462
1463 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
1464
1465 /* check if we are in middle of deleting/creating the interface */
1466 if (ndp_ctx->state == NAN_DATA_NDI_DELETED_STATE ||
1467 ndp_ctx->state == NAN_DATA_NDI_DELETING_STATE ||
1468 ndp_ctx->state == NAN_DATA_NDI_CREATING_STATE) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001469 hdd_err("Data request not allowed in current NDI state: %d",
Abhishek Singh4fef7472016-06-06 11:36:03 -07001470 ndp_ctx->state);
1471 return;
1472 }
1473
Naveen Rawat4f3983e2016-11-29 16:12:09 -08001474 data_len = (5 * sizeof(uint32_t)) + (2 * QDF_MAC_ADDR_SIZE) + IFNAMSIZ +
1475 event->ndp_info.ndp_app_info_len + event->scid.scid_len +
1476 (10 * NLA_HDRLEN) + NLMSG_HDRLEN;
Abhishek Singh4fef7472016-06-06 11:36:03 -07001477
1478 /* notify response to the upper layer */
1479 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
1480 NULL, data_len,
1481 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1482 GFP_KERNEL);
1483 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001484 hdd_err("cfg80211_vendor_event_alloc failed");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001485 return;
1486 }
1487
1488 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1489 QCA_WLAN_VENDOR_ATTR_NDP_REQUEST_IND))
1490 goto ndp_indication_nla_failed;
1491
1492 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR,
1493 IFNAMSIZ, adapter->dev->name))
1494 goto ndp_indication_nla_failed;
1495
Naveen Rawat19da3d12016-08-16 12:39:38 -07001496 if (nla_put_u32(vendor_event,
Abhishek Singh4fef7472016-06-06 11:36:03 -07001497 QCA_WLAN_VENDOR_ATTR_NDP_SERVICE_INSTANCE_ID,
1498 event->service_instance_id))
1499 goto ndp_indication_nla_failed;
1500
1501 if (nla_put(vendor_event,
1502 QCA_WLAN_VENDOR_ATTR_NDP_NDI_MAC_ADDR,
1503 QDF_MAC_ADDR_SIZE, event->peer_mac_addr.bytes))
1504 goto ndp_indication_nla_failed;
1505
1506 if (nla_put(vendor_event,
Jeff Johnson03294f12016-12-09 17:10:24 -08001507 QCA_WLAN_VENDOR_ATTR_NDP_PEER_DISCOVERY_MAC_ADDR,
Abhishek Singh4fef7472016-06-06 11:36:03 -07001508 QDF_MAC_ADDR_SIZE, event->peer_discovery_mac_addr.bytes))
1509 goto ndp_indication_nla_failed;
1510
1511 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID,
1512 event->ndp_instance_id))
1513 goto ndp_indication_nla_failed;
1514
1515 if (event->ndp_info.ndp_app_info_len)
1516 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_APP_INFO,
1517 event->ndp_info.ndp_app_info_len,
1518 event->ndp_info.ndp_app_info))
1519 goto ndp_indication_nla_failed;
1520
1521 if (event->ndp_config.ndp_cfg_len) {
1522 ndp_qos_config = *((uint32_t *)event->ndp_config.ndp_cfg);
1523 /* at present ndp config stores 4 bytes QOS info only */
1524 if (nla_put_u32(vendor_event,
1525 QCA_WLAN_VENDOR_ATTR_NDP_CONFIG_QOS,
1526 ndp_qos_config))
1527 goto ndp_indication_nla_failed;
1528 }
1529
Naveen Rawat4f3983e2016-11-29 16:12:09 -08001530 if (event->scid.scid_len) {
1531 if (nla_put_u32(vendor_event,
1532 QCA_WLAN_VENDOR_ATTR_NDP_NCS_SK_TYPE,
1533 event->ncs_sk_type))
1534 goto ndp_indication_nla_failed;
1535
1536 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SCID,
1537 event->scid.scid_len,
1538 event->scid.scid))
1539 goto ndp_indication_nla_failed;
1540
1541 hdd_info("csid: %d, scid_len: %d",
1542 event->ncs_sk_type, event->scid.scid_len);
1543
1544 QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_DEBUG,
1545 event->scid.scid, event->scid.scid_len);
1546 }
1547
Abhishek Singh4fef7472016-06-06 11:36:03 -07001548 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1549 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001550 return;
Abhishek Singh4fef7472016-06-06 11:36:03 -07001551ndp_indication_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001552 hdd_err("nla_put api failed");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001553 kfree_skb(vendor_event);
1554 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001555}
1556
1557/**
1558 * hdd_ndp_responder_rsp_handler() - NDP responder response handler
1559 * @adapter: pointer to adapter context
1560 * @rsp_params: response parameters
1561 *
Abhishek Singh4fef7472016-06-06 11:36:03 -07001562 * Following vendor event is sent to cfg80211:
1563 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1564 * QCA_WLAN_VENDOR_ATTR_NDP_RESPONDER_RESPONSE (4 bytes)
1565 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001566 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
1567 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE (4 bytes)
Abhishek Singh4fef7472016-06-06 11:36:03 -07001568 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001569 * Return: none
1570 */
1571static void hdd_ndp_responder_rsp_handler(hdd_adapter_t *adapter,
1572 void *rsp_params)
1573{
Abhishek Singh4fef7472016-06-06 11:36:03 -07001574 struct sk_buff *vendor_event;
1575 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1576 struct ndp_responder_rsp_event *rsp = rsp_params;
1577 uint16_t data_len;
1578
1579 ENTER();
1580 if (!rsp) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001581 hdd_err("Invalid NDP Responder response");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001582 return;
1583 }
1584
1585 if (0 != wlan_hdd_validate_context(hdd_ctx))
1586 return;
1587
Naveen Rawatba4f6612016-07-05 12:03:16 -07001588 hdd_info("NDP Responder,vdev id %d transaction_id %d status code: %d reason %d",
Abhishek Singh4fef7472016-06-06 11:36:03 -07001589 rsp->vdev_id, rsp->transaction_id,
1590 rsp->status, rsp->reason);
1591
1592 data_len = 3 * sizeof(uint32_t) + sizeof(uint16_t) +
1593 4 * NLA_HDRLEN + NLMSG_HDRLEN;
1594 /* notify response to the upper layer */
1595 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
1596 NULL, data_len,
1597 QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1598 GFP_KERNEL);
1599 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001600 hdd_err("cfg80211_vendor_event_alloc failed");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001601 return;
1602 }
1603
1604 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1605 QCA_WLAN_VENDOR_ATTR_NDP_RESPONDER_RESPONSE))
1606 goto ndp_responder_rsp_nla_failed;
1607
1608 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1609 rsp->transaction_id))
1610 goto ndp_responder_rsp_nla_failed;
1611
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001612 if (nla_put_u32(vendor_event,
1613 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Abhishek Singh4fef7472016-06-06 11:36:03 -07001614 rsp->status))
1615 goto ndp_responder_rsp_nla_failed;
1616
1617 if (nla_put_u32(vendor_event,
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001618 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
Abhishek Singh4fef7472016-06-06 11:36:03 -07001619 rsp->reason))
1620 goto ndp_responder_rsp_nla_failed;
1621
1622 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1623 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001624 return;
Abhishek Singh4fef7472016-06-06 11:36:03 -07001625ndp_responder_rsp_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001626 hdd_err("nla_put api failed");
Abhishek Singh4fef7472016-06-06 11:36:03 -07001627 kfree_skb(vendor_event);
1628 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001629}
1630
1631/**
1632 * hdd_ndp_end_rsp_handler() - NDP end response handler
1633 * @adapter: pointer to adapter context
1634 * @rsp_params: response parameters
1635 *
Naveen Rawatf28315c2016-06-29 18:06:02 -07001636 * Following vendor event is sent to cfg80211:
1637 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1638 * QCA_WLAN_VENDOR_ATTR_NDP_END_RESPONSE(4 bytest)
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001639 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE (4 bytes)
Naveen Rawatf28315c2016-06-29 18:06:02 -07001640 * QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE (4 bytes)
1641 * QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID (2 bytes)
1642 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001643 * Return: none
1644 */
Naveen Rawatf28315c2016-06-29 18:06:02 -07001645static void hdd_ndp_end_rsp_handler(hdd_adapter_t *adapter, void *rsp_params)
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001646{
Naveen Rawatf28315c2016-06-29 18:06:02 -07001647 struct sk_buff *vendor_event;
1648 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1649 struct ndp_end_rsp_event *rsp = rsp_params;
Rakesh Sunkiae936b62016-07-28 16:01:45 -07001650 uint32_t data_len;
Naveen Rawatf28315c2016-06-29 18:06:02 -07001651
1652 ENTER();
1653
1654 if (!rsp) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001655 hdd_err("Invalid ndp end response");
Naveen Rawatf28315c2016-06-29 18:06:02 -07001656 return;
1657 }
1658
1659 if (0 != wlan_hdd_validate_context(hdd_ctx))
1660 return;
1661
Naveen Rawatf28315c2016-06-29 18:06:02 -07001662 data_len = NLMSG_HDRLEN + (4 * NLA_HDRLEN) + (3 * sizeof(uint32_t)) +
1663 sizeof(uint16_t);
1664
1665 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy, NULL,
1666 data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1667 GFP_KERNEL);
1668 if (!vendor_event) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001669 hdd_err("cfg80211_vendor_event_alloc failed");
Naveen Rawatf28315c2016-06-29 18:06:02 -07001670 return;
1671 }
1672
1673 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1674 QCA_WLAN_VENDOR_ATTR_NDP_END_RESPONSE))
1675 goto ndp_end_rsp_nla_failed;
1676
Rakesh Sunkid92d1082017-01-04 15:14:28 -08001677 if (nla_put_u32(vendor_event,
1678 QCA_WLAN_VENDOR_ATTR_NDP_DRV_RESPONSE_STATUS_TYPE,
Naveen Rawatf28315c2016-06-29 18:06:02 -07001679 rsp->status))
1680 goto ndp_end_rsp_nla_failed;
1681
1682 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_DRV_RETURN_VALUE,
1683 rsp->reason))
1684 goto ndp_end_rsp_nla_failed;
1685
1686 if (nla_put_u16(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID,
1687 rsp->transaction_id))
1688 goto ndp_end_rsp_nla_failed;
1689
Naveen Rawatba4f6612016-07-05 12:03:16 -07001690 hdd_info("NDP End rsp sent, transaction id: %d, status: %d, reason: %d",
Naveen Rawatf28315c2016-06-29 18:06:02 -07001691 rsp->transaction_id, rsp->status, rsp->reason);
1692 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1693 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001694 return;
Naveen Rawatf28315c2016-06-29 18:06:02 -07001695
1696ndp_end_rsp_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001697 hdd_err("nla_put api failed");
Naveen Rawatf28315c2016-06-29 18:06:02 -07001698 kfree_skb(vendor_event);
1699 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001700}
1701
1702/**
1703 * hdd_ndp_end_ind_handler() - NDP end indication handler
1704 * @adapter: pointer to adapter context
1705 * @ind_params: indication parameters
1706 *
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001707 * Following vendor event is sent to cfg80211:
1708 * QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD =
1709 * QCA_WLAN_VENDOR_ATTR_NDP_END_IND (4 bytes)
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001710 * QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY (4 * num of NDP Instances)
1711 *
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001712 * Return: none
1713 */
1714static void hdd_ndp_end_ind_handler(hdd_adapter_t *adapter,
1715 void *ind_params)
1716{
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001717 struct sk_buff *vendor_event;
1718 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
1719 struct ndp_end_indication_event *end_ind = ind_params;
1720 uint32_t data_len, i;
1721 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
1722 hdd_station_ctx_t *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
1723 uint32_t *ndp_instance_array;
Naveen Rawate21103f2016-07-08 14:18:00 -07001724 hdd_adapter_t *ndi_adapter;
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001725
1726 ENTER();
1727
1728 if (!end_ind) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001729 hdd_err("Invalid ndp end indication");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001730 return;
1731 }
1732
1733 if (0 != wlan_hdd_validate_context(hdd_ctx))
1734 return;
1735
1736 ndp_instance_array = qdf_mem_malloc(end_ind->num_ndp_ids *
1737 sizeof(*ndp_instance_array));
1738 if (!ndp_instance_array) {
1739 hdd_err("Failed to allocate ndp_instance_array");
1740 return;
1741 }
1742 for (i = 0; i < end_ind->num_ndp_ids; i++) {
1743 int idx;
1744
1745 ndp_instance_array[i] = end_ind->ndp_map[i].ndp_instance_id;
Naveen Rawate21103f2016-07-08 14:18:00 -07001746 ndi_adapter = hdd_get_adapter_by_vdev(hdd_ctx,
1747 end_ind->ndp_map[i].vdev_id);
1748 if (ndi_adapter == NULL) {
1749 hdd_err("Adapter not found for vdev_id: %d",
1750 end_ind->ndp_map[i].vdev_id);
1751 continue;
1752 }
1753 ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(ndi_adapter);
Govind Singhb8475942016-08-12 11:07:09 +05301754 if (!ndp_ctx) {
1755 hdd_err("ndp_ctx is NULL for vdev id: %d",
1756 end_ind->ndp_map[i].vdev_id);
1757 continue;
1758 }
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001759 idx = hdd_get_peer_idx(sta_ctx,
1760 &end_ind->ndp_map[i].peer_ndi_mac_addr);
1761 if (idx == INVALID_PEER_IDX) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001762 hdd_err("can't find addr: %pM in sta_ctx.",
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001763 &end_ind->ndp_map[i].peer_ndi_mac_addr);
1764 continue;
1765 }
1766 /* save the value of active sessions on each peer */
1767 ndp_ctx->active_ndp_sessions[idx] =
1768 end_ind->ndp_map[i].num_active_ndp_sessions;
1769 }
1770
Naveen Rawat90ae3082016-06-29 18:22:59 -07001771 data_len = (sizeof(uint32_t)) + NLMSG_HDRLEN + (2 * NLA_HDRLEN) +
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001772 end_ind->num_ndp_ids * sizeof(*ndp_instance_array);
1773
1774 vendor_event = cfg80211_vendor_event_alloc(hdd_ctx->wiphy, NULL,
1775 data_len, QCA_NL80211_VENDOR_SUBCMD_NDP_INDEX,
1776 GFP_KERNEL);
1777 if (!vendor_event) {
SaidiReddy Yenuga466b3ce2017-05-02 18:50:25 +05301778 qdf_mem_free(ndp_instance_array);
Naveen Rawatba4f6612016-07-05 12:03:16 -07001779 hdd_err("cfg80211_vendor_event_alloc failed");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001780 return;
1781 }
1782
1783 if (nla_put_u32(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD,
1784 QCA_WLAN_VENDOR_ATTR_NDP_END_IND))
1785 goto ndp_end_ind_nla_failed;
1786
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001787 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NDP_INSTANCE_ID_ARRAY,
1788 end_ind->num_ndp_ids * sizeof(*ndp_instance_array),
1789 ndp_instance_array))
1790 goto ndp_end_ind_nla_failed;
1791
1792 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
1793 qdf_mem_free(ndp_instance_array);
1794 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001795 return;
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001796
1797ndp_end_ind_nla_failed:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001798 hdd_err("nla_put api failed");
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001799 kfree_skb(vendor_event);
1800 qdf_mem_free(ndp_instance_array);
1801 EXIT();
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001802}
1803
1804/**
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001805 * hdd_ndp_event_handler() - ndp response and indication handler
1806 * @adapter: adapter context
1807 * @roam_info: pointer to roam_info structure
1808 * @roam_id: roam id as indicated by SME
1809 * @roam_status: roam status
1810 * @roam_result: roam result
1811 *
1812 * Return: none
1813 */
1814void hdd_ndp_event_handler(hdd_adapter_t *adapter,
1815 tCsrRoamInfo *roam_info, uint32_t roam_id, eRoamCmdStatus roam_status,
1816 eCsrRoamResult roam_result)
1817{
1818 if (roam_status == eCSR_ROAM_NDP_STATUS_UPDATE) {
1819 switch (roam_result) {
Naveen Rawat8d63a592016-06-29 18:30:59 -07001820 case eCSR_ROAM_RESULT_NDI_CREATE_RSP:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001821 hdd_ndp_iface_create_rsp_handler(adapter,
1822 &roam_info->ndp.ndi_create_params);
1823 break;
Naveen Rawat8d63a592016-06-29 18:30:59 -07001824 case eCSR_ROAM_RESULT_NDI_DELETE_RSP:
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001825 hdd_ndp_iface_delete_rsp_handler(adapter,
1826 &roam_info->ndp.ndi_delete_params);
1827 break;
1828 case eCSR_ROAM_RESULT_NDP_INITIATOR_RSP:
1829 hdd_ndp_initiator_rsp_handler(adapter,
1830 &roam_info->ndp.ndp_init_rsp_params);
1831 break;
1832 case eCSR_ROAM_RESULT_NDP_NEW_PEER_IND:
1833 hdd_ndp_new_peer_ind_handler(adapter,
1834 &roam_info->ndp.ndp_peer_ind_params);
1835 break;
1836 case eCSR_ROAM_RESULT_NDP_CONFIRM_IND:
1837 hdd_ndp_confirm_ind_handler(adapter,
1838 &roam_info->ndp.ndp_confirm_params);
1839 break;
1840 case eCSR_ROAM_RESULT_NDP_INDICATION:
1841 hdd_ndp_indication_handler(adapter,
1842 &roam_info->ndp.ndp_indication_params);
1843 break;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001844 case eCSR_ROAM_RESULT_NDP_RESPONDER_RSP:
1845 hdd_ndp_responder_rsp_handler(adapter,
1846 &roam_info->ndp.ndp_responder_rsp_params);
1847 break;
1848 case eCSR_ROAM_RESULT_NDP_END_RSP:
1849 hdd_ndp_end_rsp_handler(adapter,
Naveen Rawatf28315c2016-06-29 18:06:02 -07001850 roam_info->ndp.ndp_end_rsp_params);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001851 break;
1852 case eCSR_ROAM_RESULT_NDP_PEER_DEPARTED_IND:
1853 hdd_ndp_peer_departed_ind_handler(adapter,
1854 &roam_info->ndp.ndp_peer_ind_params);
1855 break;
1856 case eCSR_ROAM_RESULT_NDP_END_IND:
1857 hdd_ndp_end_ind_handler(adapter,
Deepak Dhamdherea6d2f4c2016-06-04 00:24:52 -07001858 roam_info->ndp.ndp_end_ind_params);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001859 break;
1860 default:
Naveen Rawatba4f6612016-07-05 12:03:16 -07001861 hdd_err("Unknown NDP response event from SME %d",
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001862 roam_result);
1863 break;
1864 }
1865 }
1866}
Naveen Rawat97500352017-03-22 10:07:58 -07001867#else
1868void hdd_ndp_event_handler(hdd_adapter_t *adapter,
1869 tCsrRoamInfo *roam_info, uint32_t roam_id, eRoamCmdStatus roam_status,
1870 eCsrRoamResult roam_result)
1871{
Naveen Rawatcb5c5402017-03-22 10:12:19 -07001872 bool success;
1873 struct wlan_objmgr_psoc *psoc = wlan_vdev_get_psoc(adapter->hdd_vdev);
1874
1875 if (roam_status == eCSR_ROAM_NDP_STATUS_UPDATE) {
1876 switch (roam_result) {
1877 case eCSR_ROAM_RESULT_NDI_CREATE_RSP:
1878 success = (roam_info->ndp.ndi_create_params.status ==
1879 NAN_DATAPATH_RSP_STATUS_SUCCESS);
1880 hdd_debug("posting ndi create status: %d to umac",
1881 success);
1882 os_if_nan_post_ndi_create_rsp(psoc, adapter->sessionId,
1883 success);
1884 return;
1885 case eCSR_ROAM_RESULT_NDI_DELETE_RSP:
1886 success = (roam_info->ndp.ndi_create_params.status ==
1887 NAN_DATAPATH_RSP_STATUS_SUCCESS);
1888 hdd_debug("posting ndi delete status: %d to umac",
1889 success);
1890 os_if_nan_post_ndi_delete_rsp(psoc, adapter->sessionId,
1891 success);
1892 return;
1893 default:
1894 hdd_err("in correct roam_result: %d", roam_result);
1895 return;
1896 }
1897 } else {
1898 hdd_err("in correct roam_status: %d", roam_status);
1899 return;
1900 }
Naveen Rawat97500352017-03-22 10:07:58 -07001901}
1902#endif
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001903
1904/**
1905 * __wlan_hdd_cfg80211_process_ndp_cmds() - handle NDP request
1906 * @wiphy: pointer to wireless wiphy structure.
1907 * @wdev: pointer to wireless_dev structure.
1908 * @data: Pointer to the data to be passed via vendor interface
1909 * @data_len:Length of the data to be passed
1910 *
1911 * This function is invoked to handle vendor command
1912 *
1913 * Return: 0 on success, negative errno on failure
1914 */
Naveen Rawat63de5422017-03-22 11:03:56 -07001915#ifdef WLAN_FEATURE_NAN_CONVERGENCE
1916static int __wlan_hdd_cfg80211_process_ndp_cmd(struct wiphy *wiphy,
1917 struct wireless_dev *wdev, const void *data, int data_len)
1918{
1919 int ret_val;
1920 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1921
1922 ENTER();
1923
1924 ret_val = wlan_hdd_validate_context(hdd_ctx);
1925 if (ret_val)
1926 return ret_val;
1927
1928 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
1929 hdd_err("Command not allowed in FTM mode");
1930 return -EPERM;
1931 }
1932
1933 if (!WLAN_HDD_IS_NDP_ENABLED(hdd_ctx)) {
1934 hdd_err("NAN datapath is not enabled");
1935 return -EPERM;
1936 }
1937 /* NAN data path coexists only with STA interface */
1938 if (false == hdd_is_ndp_allowed(hdd_ctx)) {
1939 hdd_err("Unsupported concurrency for NAN datapath");
1940 return -EPERM;
1941 }
1942
1943 /* NAN data path coexists only with STA interface */
1944 if (false == hdd_is_ndp_allowed(hdd_ctx)) {
1945 hdd_err("Unsupported concurrency for NAN datapath");
1946 return -EPERM;
1947 }
1948
1949 return os_if_nan_process_ndp_cmd(hdd_ctx->hdd_psoc,
1950 data, data_len);
1951}
1952#else
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001953static int __wlan_hdd_cfg80211_process_ndp_cmd(struct wiphy *wiphy,
1954 struct wireless_dev *wdev, const void *data, int data_len)
1955{
1956 uint32_t ndp_cmd_type;
1957 uint16_t transaction_id;
1958 int ret_val;
1959 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1960 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_NDP_PARAMS_MAX + 1];
1961 char *iface_name;
1962
1963 ENTER();
1964
1965 ret_val = wlan_hdd_validate_context(hdd_ctx);
1966 if (ret_val)
1967 return ret_val;
1968
1969 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001970 hdd_err("Command not allowed in FTM mode");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001971 return -EPERM;
1972 }
Deepak Dhamdhere7e6016f2016-06-01 09:37:37 -07001973 if (!WLAN_HDD_IS_NDP_ENABLED(hdd_ctx)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001974 hdd_err("NAN datapath is not enabled");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001975 return -EPERM;
1976 }
1977 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_NDP_PARAMS_MAX,
1978 data, data_len,
1979 qca_wlan_vendor_ndp_policy)) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001980 hdd_err("Invalid NDP vendor command attributes");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001981 return -EINVAL;
1982 }
1983
1984 /* Parse and fetch NDP Command Type*/
1985 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001986 hdd_err("NAN datapath cmd type failed");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001987 return -EINVAL;
1988 }
1989 ndp_cmd_type = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_NDP_SUBCMD]);
1990
1991 if (!tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07001992 hdd_err("attr transaction id failed");
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07001993 return -EINVAL;
1994 }
1995 transaction_id = nla_get_u16(
1996 tb[QCA_WLAN_VENDOR_ATTR_NDP_TRANSACTION_ID]);
1997
Naveen Rawatf28315c2016-06-29 18:06:02 -07001998 if (tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]) {
1999 iface_name = nla_data(tb[QCA_WLAN_VENDOR_ATTR_NDP_IFACE_STR]);
Naveen Rawatba4f6612016-07-05 12:03:16 -07002000 hdd_err("Transaction Id: %d NDP Cmd: %d iface_name: %s",
Naveen Rawatf28315c2016-06-29 18:06:02 -07002001 transaction_id, ndp_cmd_type, iface_name);
2002 } else {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002003 hdd_err("Transaction Id: %d NDP Cmd: %d iface_name: unspecified",
Naveen Rawatf28315c2016-06-29 18:06:02 -07002004 transaction_id, ndp_cmd_type);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002005 }
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002006
2007 switch (ndp_cmd_type) {
2008 case QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_CREATE:
2009 ret_val = hdd_ndi_create_req_handler(hdd_ctx, tb);
2010 break;
2011 case QCA_WLAN_VENDOR_ATTR_NDP_INTERFACE_DELETE:
2012 ret_val = hdd_ndi_delete_req_handler(hdd_ctx, tb);
2013 break;
2014 case QCA_WLAN_VENDOR_ATTR_NDP_INITIATOR_REQUEST:
2015 ret_val = hdd_ndp_initiator_req_handler(hdd_ctx, tb);
2016 break;
2017 case QCA_WLAN_VENDOR_ATTR_NDP_RESPONDER_REQUEST:
2018 ret_val = hdd_ndp_responder_req_handler(hdd_ctx, tb);
2019 break;
2020 case QCA_WLAN_VENDOR_ATTR_NDP_END_REQUEST:
2021 ret_val = hdd_ndp_end_req_handler(hdd_ctx, tb);
2022 break;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002023 default:
Naveen Rawatba4f6612016-07-05 12:03:16 -07002024 hdd_err("Unrecognized NDP vendor cmd %d", ndp_cmd_type);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002025 ret_val = -EINVAL;
2026 break;
2027 }
2028
2029 return ret_val;
2030}
Naveen Rawat63de5422017-03-22 11:03:56 -07002031#endif
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002032
2033/**
2034 * wlan_hdd_cfg80211_process_ndp_cmd() - handle NDP request
2035 * @wiphy: pointer to wireless wiphy structure.
2036 * @wdev: pointer to wireless_dev structure.
2037 * @data: Pointer to the data to be passed via vendor interface
2038 * @data_len:Length of the data to be passed
2039 *
2040 * This function is called to send a NAN request to
2041 * firmware. This is an SSR-protected wrapper function.
2042 *
2043 * Return: 0 on success, negative errno on failure
2044 */
2045int wlan_hdd_cfg80211_process_ndp_cmd(struct wiphy *wiphy,
2046 struct wireless_dev *wdev, const void *data, int data_len)
2047{
2048 int ret;
2049
2050 cds_ssr_protect(__func__);
2051 ret = __wlan_hdd_cfg80211_process_ndp_cmd(wiphy, wdev, data, data_len);
2052 cds_ssr_unprotect(__func__);
2053
2054 return ret;
2055}
2056
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002057#ifndef WLAN_FEATURE_NAN_CONVERGENCE
2058static int update_ndi_state(struct hdd_adapter_s *adapter, uint32_t state)
2059{
2060 struct nan_datapath_ctx *ndp_ctx = WLAN_HDD_GET_NDP_CTX_PTR(adapter);
2061
2062 ndp_ctx->state = state;
2063 return 0;
2064}
2065#else
2066static int update_ndi_state(struct hdd_adapter_s *adapter, uint32_t state)
2067{
2068 return os_if_nan_set_ndi_state(adapter->hdd_vdev, state);
2069}
2070#endif
2071
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002072/**
2073 * hdd_init_nan_data_mode() - initialize nan data mode
2074 * @adapter: adapter context
2075 *
2076 * Returns: 0 on success negative error code on error
2077 */
2078int hdd_init_nan_data_mode(struct hdd_adapter_s *adapter)
2079{
2080 struct net_device *wlan_dev = adapter->dev;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002081 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
2082 QDF_STATUS status;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002083 int32_t ret_val = 0;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002084
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002085 sme_set_curr_device_mode(hdd_ctx->hHal, adapter->device_mode);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002086
Dustin Brownd28772b2017-03-17 14:16:07 -07002087 ret_val = hdd_vdev_create(adapter);
2088 if (ret_val) {
2089 hdd_err("failed to create vdev: %d", ret_val);
2090 return ret_val;
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002091 }
2092
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002093 /* Register wireless extensions */
2094 ret_val = hdd_register_wext(wlan_dev);
2095 if (0 > ret_val) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002096 hdd_err("Wext registration failed with status code %d",
2097 ret_val);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002098 ret_val = -EAGAIN;
2099 goto error_register_wext;
2100 }
2101
2102 status = hdd_init_tx_rx(adapter);
2103 if (QDF_STATUS_SUCCESS != status) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002104 hdd_err("hdd_init_tx_rx() init failed, status %d", status);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002105 ret_val = -EAGAIN;
2106 goto error_init_txrx;
2107 }
2108
2109 set_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
2110
2111 status = hdd_wmm_adapter_init(adapter);
2112 if (QDF_STATUS_SUCCESS != status) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002113 hdd_err("hdd_wmm_adapter_init() failed, status %d", status);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002114 ret_val = -EAGAIN;
2115 goto error_wmm_init;
2116 }
2117
2118 set_bit(WMM_INIT_DONE, &adapter->event_flags);
2119
2120 ret_val = wma_cli_set_command((int)adapter->sessionId,
2121 (int)WMI_PDEV_PARAM_BURST_ENABLE,
2122 (int)hdd_ctx->config->enableSifsBurst,
2123 PDEV_CMD);
2124 if (0 != ret_val) {
Naveen Rawatba4f6612016-07-05 12:03:16 -07002125 hdd_err("WMI_PDEV_PARAM_BURST_ENABLE set failed %d", ret_val);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002126 }
2127
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002128 update_ndi_state(adapter, NAN_DATA_NDI_CREATING_STATE);
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002129 return ret_val;
2130
2131error_wmm_init:
2132 clear_bit(INIT_TX_RX_SUCCESS, &adapter->event_flags);
2133 hdd_deinit_tx_rx(adapter);
2134
2135error_init_txrx:
2136 hdd_unregister_wext(wlan_dev);
2137
2138error_register_wext:
Dustin Brownd28772b2017-03-17 14:16:07 -07002139 QDF_BUG(!hdd_vdev_destroy(adapter));
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002140
Deepak Dhamdhere5cdce842016-05-31 10:39:12 -07002141 return ret_val;
2142}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002143
2144#ifdef WLAN_FEATURE_NAN_CONVERGENCE
2145struct wlan_objmgr_vdev *hdd_ndi_open(char *iface_name)
2146{
2147 hdd_adapter_t *adapter;
Naveen Rawat5a6f8402017-07-03 16:00:11 -07002148 struct qdf_mac_addr ndi_mac_addr;
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002149 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2150
2151 ENTER();
Naveen Rawat5a6f8402017-07-03 16:00:11 -07002152
2153 if (hdd_get_random_nan_mac_addr(hdd_ctx, &ndi_mac_addr)) {
2154 hdd_err("get random mac address failed");
2155 return NULL;
2156 }
2157
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002158 adapter = hdd_open_adapter(hdd_ctx, QDF_NDI_MODE, iface_name,
Naveen Rawat5a6f8402017-07-03 16:00:11 -07002159 ndi_mac_addr.bytes, NET_NAME_UNKNOWN, true);
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002160 if (!adapter) {
2161 hdd_err("hdd_open_adapter failed");
2162 return NULL;
2163 }
2164
2165 EXIT();
2166 return adapter->hdd_vdev;
2167}
2168
2169int hdd_ndi_start(uint8_t vdev_id)
2170{
2171 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2172 uint8_t op_channel = hdd_ctx->config->nan_datapath_ndi_channel;
2173 hdd_adapter_t *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2174
2175 ENTER();
2176 /*
2177 * The NAN data interface has been created at this point.
2178 * Unlike traditional device modes, where the higher application
2179 * layer initiates connect / join / start, the NAN data
2180 * interface does not have any such formal requests. The NDI
2181 * create request is responsible for starting the BSS as well.
2182 */
2183 if (op_channel != NAN_SOCIAL_CHANNEL_2_4GHZ ||
2184 op_channel != NAN_SOCIAL_CHANNEL_5GHZ_LOWER_BAND ||
2185 op_channel != NAN_SOCIAL_CHANNEL_5GHZ_UPPER_BAND) {
2186 /* start NDI on the default 2.4 GHz social channel */
2187 op_channel = NAN_SOCIAL_CHANNEL_2_4GHZ;
2188 }
2189 if (hdd_ndi_start_bss(adapter, op_channel)) {
2190 hdd_err("NDI start bss failed");
2191 /* Start BSS failed, delete the interface */
2192 hdd_close_ndi(adapter);
2193 EXIT();
2194 return -EINVAL;
2195 }
2196
2197 return 0;
2198}
2199
2200int hdd_ndi_delete(uint8_t vdev_id, char *iface_name, uint16_t transaction_id)
2201{
2202 int ret;
2203 hdd_adapter_t *adapter;
2204 hdd_station_ctx_t *sta_ctx;
2205 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2206
Naveen Rawatc4b045c2017-06-30 16:11:42 -07002207 /* check if adapter by vdev_id is valid NDI */
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002208 adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2209 if (!adapter || !WLAN_HDD_IS_NDI(adapter)) {
2210 hdd_err("NAN data interface %s is not available", iface_name);
2211 return -EINVAL;
2212 }
2213
2214 sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2215 if (!sta_ctx) {
2216 hdd_err("sta_ctx is NULL");
2217 return -EINVAL;
2218 }
2219
2220 /* Since, the interface is being deleted, remove the broadcast id. */
2221 hdd_ctx->sta_to_adapter[sta_ctx->broadcast_staid] = 0;
2222 sta_ctx->broadcast_staid = HDD_WLAN_INVALID_STA_ID;
2223
2224 os_if_nan_set_ndp_delete_transaction_id(adapter->hdd_vdev,
2225 transaction_id);
2226 os_if_nan_set_ndi_state(adapter->hdd_vdev, NAN_DATA_NDI_DELETING_STATE);
2227
2228 /* Delete the interface */
2229 ret = __wlan_hdd_del_virtual_intf(hdd_ctx->wiphy, &adapter->wdev);
2230 if (ret)
2231 hdd_err("NDI delete request failed");
2232 else
2233 hdd_err("NDI delete request successfully issued");
2234
2235 return ret;
2236}
2237
2238void hdd_ndi_drv_ndi_create_rsp_handler(uint8_t vdev_id,
2239 struct nan_datapath_inf_create_rsp *ndi_rsp)
2240{
2241 tCsrRoamInfo roam_info = {0};
2242 tSirBssDescription tmp_bss_descp = {0};
2243 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2244 hdd_adapter_t *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2245 struct qdf_mac_addr bc_mac_addr = QDF_MAC_ADDR_BROADCAST_INITIALIZER;
2246 hdd_station_ctx_t *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2247
2248 if (ndi_rsp->status == QDF_STATUS_SUCCESS) {
2249 hdd_alert("NDI interface successfully created");
2250 os_if_nan_set_ndp_create_transaction_id(adapter->hdd_vdev, 0);
2251 os_if_nan_set_ndi_state(adapter->hdd_vdev,
2252 NAN_DATA_NDI_CREATED_STATE);
2253 wlan_hdd_netif_queue_control(adapter,
2254 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
2255 WLAN_CONTROL_PATH);
2256 } else {
2257 hdd_alert("NDI interface creation failed with reason %d",
2258 ndi_rsp->reason /* create_reason */);
2259 }
2260
2261 sta_ctx->broadcast_staid = ndi_rsp->sta_id;
2262 hdd_save_peer(sta_ctx, sta_ctx->broadcast_staid, &bc_mac_addr);
2263 hdd_roam_register_sta(adapter, &roam_info,
2264 sta_ctx->broadcast_staid,
2265 &bc_mac_addr, &tmp_bss_descp);
2266 hdd_ctx->sta_to_adapter[sta_ctx->broadcast_staid] = adapter;
2267}
2268
2269void hdd_ndi_close(uint8_t vdev_id)
2270{
2271 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2272 hdd_adapter_t *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2273 hdd_close_ndi(adapter);
2274}
2275
2276void hdd_ndi_drv_ndi_delete_rsp_handler(uint8_t vdev_id)
2277{
2278 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2279 hdd_adapter_t *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2280
2281 wlan_hdd_netif_queue_control(adapter,
2282 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
2283 WLAN_CONTROL_PATH);
2284
2285 complete(&adapter->disconnect_comp_var);
2286}
2287
2288void hdd_ndp_session_end_handler(hdd_adapter_t *adapter)
2289{
2290 os_if_nan_ndi_session_end(adapter->hdd_vdev);
2291}
2292
Naveen Rawat37f62c82017-03-26 22:24:43 -07002293int hdd_ndp_get_peer_idx(uint8_t vdev_id, struct qdf_mac_addr *addr)
2294{
2295 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2296 hdd_adapter_t *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2297 hdd_station_ctx_t *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2298 return hdd_get_peer_idx(sta_ctx, addr);
2299}
2300
2301/**
2302 * hdd_ndp_new_peer_handler() - NDP new peer indication handler
2303 * @adapter: pointer to adapter context
2304 * @ind_params: indication parameters
2305 *
2306 * Return: none
2307 */
2308int hdd_ndp_new_peer_handler(uint8_t vdev_id, uint16_t sta_id,
2309 struct qdf_mac_addr *peer_mac_addr, bool fist_peer)
2310{
2311 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2312 hdd_adapter_t *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2313 tSirBssDescription tmp_bss_descp = {0};
2314 tCsrRoamInfo roam_info = {0};
2315 hdd_station_ctx_t *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2316
2317 ENTER();
2318 /* save peer in ndp ctx */
2319 if (false == hdd_save_peer(sta_ctx, sta_id, peer_mac_addr)) {
2320 hdd_err("Ndp peer table full. cannot save new peer");
2321 return -EPERM;
2322 }
2323
2324 /* this function is called for each new peer */
2325 hdd_roam_register_sta(adapter, &roam_info, sta_id,
2326 peer_mac_addr, &tmp_bss_descp);
2327 hdd_ctx->sta_to_adapter[sta_id] = adapter;
2328 /* perform following steps for first new peer ind */
2329 if (fist_peer) {
2330 hdd_info("Set ctx connection state to connected");
2331 sta_ctx->conn_info.connState = eConnectionState_NdiConnected;
2332 hdd_wmm_connect(adapter, &roam_info, eCSR_BSS_TYPE_NDI);
2333 wlan_hdd_netif_queue_control(adapter,
2334 WLAN_WAKE_ALL_NETIF_QUEUE, WLAN_CONTROL_PATH);
2335 }
2336 EXIT();
2337 return 0;
2338}
2339
Naveen Rawatb3143ea2017-03-26 22:25:46 -07002340
2341/**
2342 * hdd_ndp_peer_departed_handler() - Handle NDP peer departed indication
2343 * @adapter: pointer to adapter context
2344 * @ind_params: indication parameters
2345 *
2346 * Return: none
2347 */
2348void hdd_ndp_peer_departed_handler(uint8_t vdev_id, uint16_t sta_id,
2349 struct qdf_mac_addr *peer_mac_addr, bool last_peer)
2350{
2351 hdd_context_t *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
2352 hdd_adapter_t *adapter = hdd_get_adapter_by_vdev(hdd_ctx, vdev_id);
2353 hdd_station_ctx_t *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
2354
2355 ENTER();
2356 hdd_roam_deregister_sta(adapter, sta_id);
2357 hdd_delete_peer(sta_ctx, sta_id);
2358 hdd_ctx->sta_to_adapter[sta_id] = NULL;
2359
2360 if (last_peer) {
2361 hdd_info("No more ndp peers.");
2362 sta_ctx->conn_info.connState = eConnectionState_NdiDisconnected;
2363 hdd_conn_set_connection_state(adapter,
2364 eConnectionState_NdiDisconnected);
2365 hdd_info("Stop netif tx queues.");
2366 wlan_hdd_netif_queue_control(adapter, WLAN_STOP_ALL_NETIF_QUEUE,
2367 WLAN_CONTROL_PATH);
2368 }
2369 EXIT();
2370}
Naveen Rawatcb5c5402017-03-22 10:12:19 -07002371#endif