blob: 9fe3aee14dc5a4b15c3d412b582753d1c3f676b6 [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnson1aa29092016-01-11 15:24:59 -08002 * Copyright (c) 2012-2016 The Linux Foundation. All rights reserved.
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/**
23 * DOC: wlan_hdd_nan.c
24 *
25 * WLAN Host Device Driver NAN API implementation
26 */
27
Jeff Johnson1aa29092016-01-11 15:24:59 -080028/* denote that this file does not allow legacy hddLog */
29#define HDD_DISALLOW_LEGACY_HDDLOG 1
30
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080031#include <linux/version.h>
32#include <linux/module.h>
33#include <linux/kernel.h>
34#include <net/cfg80211.h>
35#include <ani_global.h>
36#include "sme_api.h"
37#include "nan_api.h"
38#include "wlan_hdd_main.h"
39#include "wlan_hdd_nan.h"
40
41/**
42 * __wlan_hdd_cfg80211_nan_request() - cfg80211 NAN request handler
43 * @wiphy: driver's wiphy struct
44 * @wdev: wireless device to which the request is targeted
45 * @data: actual request data (netlink-encapsulated)
46 * @data_len: length of @data
47 *
48 * This is called when userspace needs to send a nan request to
49 * firmware. The wlan host driver simply de-encapsulates the
50 * request from the netlink payload and then forwards it to
51 * firmware via SME.
52 *
53 * Return: 0 on success, negative errno on failure
54 */
55static int __wlan_hdd_cfg80211_nan_request(struct wiphy *wiphy,
56 struct wireless_dev *wdev,
57 const void *data,
58 int data_len)
59{
60 tNanRequestReq nan_req;
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053061 QDF_STATUS status;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080062 int ret_val;
63 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
64
65 ENTER();
66
67 ret_val = wlan_hdd_validate_context(hdd_ctx);
68 if (ret_val)
69 return ret_val;
70
Peng Xuf5d60c82015-10-02 17:17:03 -070071 if (CDF_GLOBAL_FTM_MODE == hdd_get_conparam()) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080072 hdd_err("Command not allowed in FTM mode");
73 return -EPERM;
74 }
75
76 if (!hdd_ctx->config->enable_nan_support) {
77 hdd_err("NaN support is not enabled in INI");
78 return -EPERM;
79 }
80
81 nan_req.request_data_len = data_len;
82 nan_req.request_data = data;
83
84 status = sme_nan_request(&nan_req);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +053085 if (QDF_STATUS_SUCCESS != status) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080086 ret_val = -EINVAL;
87 }
88 return ret_val;
89}
90
91/**
92 * wlan_hdd_cfg80211_nan_request() - handle NAN request
93 * @wiphy: pointer to wireless wiphy structure.
94 * @wdev: pointer to wireless_dev structure.
95 * @data: Pointer to the data to be passed via vendor interface
96 * @data_len:Length of the data to be passed
97 *
98 * This function is called by userspace to send a NAN request to
99 * firmware. This is an SSR-protected wrapper function.
100 *
101 * Return: 0 on success, negative errno on failure
102 */
103int wlan_hdd_cfg80211_nan_request(struct wiphy *wiphy,
104 struct wireless_dev *wdev,
105 const void *data,
106 int data_len)
107
108{
109 int ret;
110
111 cds_ssr_protect(__func__);
112 ret = __wlan_hdd_cfg80211_nan_request(wiphy, wdev, data, data_len);
113 cds_ssr_unprotect(__func__);
114
115 return ret;
116}
117
118/**
119 * wlan_hdd_cfg80211_nan_callback() - cfg80211 NAN event handler
120 * @ctx: global HDD context
121 * @msg: NAN event message
122 *
123 * This is a callback function and it gets called when we need to report
124 * a nan event to userspace. The wlan host driver simply encapsulates the
125 * event into a netlink payload and then forwards it to userspace via a
126 * cfg80211 vendor event.
127 *
128 * Return: nothing
129 */
130static void wlan_hdd_cfg80211_nan_callback(void *ctx, tSirNanEvent *msg)
131{
132 hdd_context_t *hdd_ctx = ctx;
133 struct sk_buff *vendor_event;
134 int status;
135
136 if (NULL == msg) {
Jeff Johnson1aa29092016-01-11 15:24:59 -0800137 hdd_err("msg received here is null");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800138 return;
139 }
140
141 status = wlan_hdd_validate_context(hdd_ctx);
142 if (0 != status) {
Jeff Johnson1aa29092016-01-11 15:24:59 -0800143 hdd_err("HDD context is not valid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800144 return;
145 }
146
147 vendor_event =
148 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
149 NULL,
150 msg->event_data_len + NLMSG_HDRLEN,
151 QCA_NL80211_VENDOR_SUBCMD_NAN_INDEX,
152 GFP_KERNEL);
153
154 if (!vendor_event) {
Jeff Johnson1aa29092016-01-11 15:24:59 -0800155 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800156 return;
157 }
158 if (nla_put(vendor_event, QCA_WLAN_VENDOR_ATTR_NAN,
159 msg->event_data_len, msg->event_data)) {
Jeff Johnson1aa29092016-01-11 15:24:59 -0800160 hdd_err("QCA_WLAN_VENDOR_ATTR_NAN put fail");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800161 kfree_skb(vendor_event);
162 return;
163 }
164 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
165}
166
167/**
168 * wlan_hdd_nan_is_supported() - HDD NAN support query function
169 *
170 * This function is called to determine if NAN is supported by the
171 * driver and by the firmware.
172 *
173 * Return: true if NAN is supported by the driver and firmware
174 */
175bool wlan_hdd_nan_is_supported(void)
176{
177 return sme_is_feature_supported_by_fw(NAN);
178}
179
180/**
181 * wlan_hdd_nan_init() - HDD NAN initialization function
182 * @hdd_ctx: Global HDD context
183 *
184 * This function is called to initialize the HDD NAN feature. Currently
185 * the only operation required is to register a callback with SME.
186 *
187 * Return: void
188 */
189void wlan_hdd_nan_init(hdd_context_t *hdd_ctx)
190{
191 sme_nan_register_callback(hdd_ctx->hHal,
192 wlan_hdd_cfg80211_nan_callback);
193}