blob: d3551e3dca357646b00f9e668743f3881044e63c [file] [log] [blame]
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001/*
Jeff Johnson441e1f72017-02-07 08:50:49 -08002 * Copyright (c) 2011-2017 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 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_ocb.c
30 *
31 * WLAN Host Device Driver 802.11p OCB implementation
32 */
33
34#include "cds_sched.h"
35#include "wlan_hdd_assoc.h"
36#include "wlan_hdd_main.h"
37#include "wlan_hdd_ocb.h"
38#include "wlan_hdd_trace.h"
Jeff Johnson7af334b2017-02-01 13:03:43 -080039#include "wlan_hdd_request_manager.h"
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080040#include "wlan_tgt_def_config.h"
41#include "sch_api.h"
42#include "wma_api.h"
Leo Changfdb45c32016-10-28 11:09:23 -070043#include <cdp_txrx_cmn.h>
Manjunathappa Prakash3454fd62016-04-01 08:52:06 -070044#include <cdp_txrx_peer_ops.h>
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -080045#include <cdp_txrx_handle.h>
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080046/* Structure definitions for WLAN_SET_DOT11P_CHANNEL_SCHED */
47#define AIFSN_MIN (2)
48#define AIFSN_MAX (15)
49#define CW_MIN (1)
50#define CW_MAX (10)
51
52/* Maximum time(ms) to wait for OCB operations */
53#define WLAN_WAIT_TIME_OCB_CMD 1500
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080054
55/**
56 * hdd_set_dot11p_config() - Set 802.11p config flag
57 * @hdd_ctx: HDD Context pointer
58 *
59 * TODO-OCB: This has been temporarily added to ensure this paramter
60 * is set in CSR when we init the channel list. This should be removed
61 * once the 5.9 GHz channels are added to the regulatory domain.
62 */
Jeff Johnson7106aba2017-08-28 11:49:07 -070063void hdd_set_dot11p_config(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080064{
65 sme_set_dot11p_config(hdd_ctx->hHal,
66 hdd_ctx->config->dot11p_mode !=
67 WLAN_HDD_11P_DISABLED);
68}
69
70/**
71 * dot11p_validate_qos_params() - Check if QoS parameters are valid
72 * @qos_params: Array of QoS parameters
73 *
74 * Return: 0 on success. error code on failure.
75 */
76static int dot11p_validate_qos_params(struct sir_qos_params qos_params[])
77{
78 int i;
79
80 for (i = 0; i < MAX_NUM_AC; i++) {
81 if ((!qos_params[i].aifsn) && (!qos_params[i].cwmin)
82 && (!qos_params[i].cwmax))
83 continue;
84
85 /* Validate AIFSN */
86 if ((qos_params[i].aifsn < AIFSN_MIN)
87 || (qos_params[i].aifsn > AIFSN_MAX)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -070088 hdd_err("Invalid QoS parameter aifsn %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080089 qos_params[i].aifsn);
90 return -EINVAL;
91 }
92
93 /* Validate CWMin */
94 if ((qos_params[i].cwmin < CW_MIN)
95 || (qos_params[i].cwmin > CW_MAX)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -070096 hdd_err("Invalid QoS parameter cwmin %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -080097 qos_params[i].cwmin);
98 return -EINVAL;
99 }
100
101 /* Validate CWMax */
102 if ((qos_params[i].cwmax < CW_MIN)
103 || (qos_params[i].cwmax > CW_MAX)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700104 hdd_err("Invalid QoS parameter cwmax %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800105 qos_params[i].cwmax);
106 return -EINVAL;
107 }
108 }
109
110 return 0;
111}
112
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800113/**
114 * dot11p_validate_channel() - validates a DSRC channel
115 * @center_freq: the channel's center frequency
116 * @bandwidth: the channel's bandwidth
117 * @tx_power: transmit power
118 * @reg_power: (output) the max tx power from the regulatory domain
119 * @antenna_max: (output) the max antenna gain from the regulatory domain
120 *
121 * Return: 0 if the channel is valid, error code otherwise.
122 */
123static int dot11p_validate_channel(struct wiphy *wiphy,
124 uint32_t channel_freq, uint32_t bandwidth,
125 uint32_t tx_power, uint8_t *reg_power,
126 uint8_t *antenna_max)
127{
128 int band_idx, channel_idx;
129 struct ieee80211_supported_band *current_band;
130 struct ieee80211_channel *current_channel;
131
Srinivas Girigowda5da651b2017-08-04 11:22:54 -0700132 for (band_idx = 0; band_idx < HDD_NUM_NL80211_BANDS; band_idx++) {
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800133 current_band = wiphy->bands[band_idx];
134 if (!current_band)
135 continue;
136
137 for (channel_idx = 0; channel_idx < current_band->n_channels;
138 channel_idx++) {
139 current_channel = &current_band->channels[channel_idx];
140
141 if (channel_freq == current_channel->center_freq) {
142 if (current_channel->flags &
143 IEEE80211_CHAN_DISABLED)
144 return -EINVAL;
145
146 if (reg_power)
147 *reg_power =
148 current_channel->max_reg_power;
149 if (antenna_max)
150 *antenna_max =
151 current_channel->
152 max_antenna_gain;
153
154 switch (bandwidth) {
155 case 0:
156 if (current_channel->flags &
157 IEEE80211_CHAN_NO_10MHZ)
158 bandwidth = 5;
159 else if (current_channel->flags &
160 IEEE80211_CHAN_NO_20MHZ)
161 bandwidth = 10;
162 else
163 bandwidth = 20;
164 break;
165 case 5:
166 break;
167 case 10:
168 if (current_channel->flags &
169 IEEE80211_CHAN_NO_10MHZ)
170 return -EINVAL;
171 break;
172 case 20:
173 if (current_channel->flags &
174 IEEE80211_CHAN_NO_20MHZ)
175 return -EINVAL;
176 break;
177 default:
178 return -EINVAL;
179 }
180
181 if (tx_power > current_channel->max_power)
182 return -EINVAL;
183
184 return 0;
185 }
186 }
187 }
188
Amar Singhalfda6eda2015-11-02 15:08:59 -0800189 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800190}
191
192/**
193 * hdd_ocb_validate_config() - Validates the config data
194 * @config: configuration to be validated
195 *
196 * Return: 0 on success.
197 */
Jeff Johnson7a1688a2017-08-29 14:27:19 -0700198static int hdd_ocb_validate_config(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800199 struct sir_ocb_config *config)
200{
201 int i;
Jeff Johnson7106aba2017-08-28 11:49:07 -0700202 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800203
204 for (i = 0; i < config->channel_count; i++) {
205 if (dot11p_validate_channel(hdd_ctx->wiphy,
206 config->channels[i].chan_freq,
207 config->channels[i].bandwidth,
208 config->channels[i].max_pwr,
209 &config->channels[i].reg_pwr,
210 &config->channels[i].antenna_max)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700211 hdd_err("Invalid channel frequency %d",
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800212 config->channels[i].chan_freq);
213 return -EINVAL;
214 }
215 if (dot11p_validate_qos_params(config->channels[i].qos_params))
216 return -EINVAL;
217 }
218
219 return 0;
220}
221
222/**
223 * hdd_ocb_register_sta() - Register station with Transport Layer
224 * @adapter: Pointer to HDD Adapter
225 *
226 * This function should be invoked in the OCB Set Schedule callback
227 * to enable the data path in the TL by calling RegisterSTAClient
228 *
229 * Return: 0 on success. -1 on failure.
230 */
Jeff Johnson7a1688a2017-08-29 14:27:19 -0700231static int hdd_ocb_register_sta(struct hdd_adapter *adapter)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800232{
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530233 QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800234 struct ol_txrx_desc_type sta_desc = {0};
Jeff Johnson7106aba2017-08-28 11:49:07 -0700235 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnsond377dce2017-10-04 10:32:42 -0700236 struct hdd_station_ctx *sta_ctx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800237 uint8_t peer_id;
Dhanashri Atre182b0272016-02-17 15:35:07 -0800238 struct ol_txrx_ops txrx_ops;
Leo Changfdb45c32016-10-28 11:09:23 -0700239 void *soc = cds_get_context(QDF_MODULE_ID_SOC);
240 void *pdev = cds_get_context(QDF_MODULE_ID_TXRX);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800241
Jeff Johnson382bce02017-09-01 14:21:07 -0700242 qdf_status = cdp_peer_register_ocb_peer(soc,
Leo Changfdb45c32016-10-28 11:09:23 -0700243 adapter->macAddressCurrent.bytes,
244 &peer_id);
Anurag Chouhanfb54ab02016-02-18 18:00:46 +0530245 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700246 hdd_err("Error registering OCB Self Peer!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800247 return -EINVAL;
248 }
249
250 hdd_ctx->sta_to_adapter[peer_id] = adapter;
251
252 sta_desc.sta_id = peer_id;
253 sta_desc.is_qos_enabled = 1;
254
Dhanashri Atre182b0272016-02-17 15:35:07 -0800255 /* Register the vdev transmit and receive functions */
256 qdf_mem_zero(&txrx_ops, sizeof(txrx_ops));
257 txrx_ops.rx.rx = hdd_rx_packet_cbk;
Leo Changfdb45c32016-10-28 11:09:23 -0700258 cdp_vdev_register(soc,
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800259 (struct cdp_vdev *)cdp_get_vdev_from_vdev_id(soc,
260 (struct cdp_pdev *)pdev, adapter->sessionId),
261 adapter, &txrx_ops);
Dhanashri Atre168d2b42016-02-22 14:43:06 -0800262 adapter->tx_fn = txrx_ops.tx.tx;
Dhanashri Atre182b0272016-02-17 15:35:07 -0800263
Venkata Sharath Chandra Manchala0d44d452016-11-23 17:48:15 -0800264 qdf_status = cdp_peer_register(soc,
265 (struct cdp_pdev *)pdev, &sta_desc);
Dhanashri Atre50141c52016-04-07 13:15:29 -0700266 if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700267 hdd_err("Failed to register. Status= %d [0x%08X]",
Dhanashri Atre50141c52016-04-07 13:15:29 -0700268 qdf_status, qdf_status);
269 return -EINVAL;
270 }
271
Jeff Johnsond377dce2017-10-04 10:32:42 -0700272 if (sta_ctx->conn_info.staId[0] != HDD_WLAN_INVALID_STA_ID &&
273 sta_ctx->conn_info.staId[0] != peer_id) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700274 hdd_err("The ID for the OCB station has changed.");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800275 }
276
Jeff Johnsond377dce2017-10-04 10:32:42 -0700277 sta_ctx->conn_info.staId[0] = peer_id;
278 qdf_copy_macaddr(&sta_ctx->conn_info.peerMacAddress[0],
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800279 &adapter->macAddressCurrent);
280
281 return 0;
282}
283
284/**
285 * hdd_ocb_config_new() - Creates a new OCB configuration
286 * @num_channels: the number of channels
287 * @num_schedule: the schedule size
288 * @ndl_chan_list_len: length in bytes of the NDL chan blob
289 * @ndl_active_state_list_len: length in bytes of the active state blob
290 *
291 * Return: A pointer to the OCB configuration struct, NULL on failure.
292 */
Jeff Johnson929ad032016-10-19 07:34:42 -0700293static
294struct sir_ocb_config *hdd_ocb_config_new(uint32_t num_channels,
295 uint32_t num_schedule,
296 uint32_t ndl_chan_list_len,
297 uint32_t ndl_active_state_list_len)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800298{
299 struct sir_ocb_config *ret = 0;
300 uint32_t len;
301 void *cursor;
302
303 if (num_channels > CFG_TGT_NUM_OCB_CHANNELS ||
304 num_schedule > CFG_TGT_NUM_OCB_SCHEDULES)
305 return NULL;
306
307 len = sizeof(*ret) +
308 num_channels * sizeof(struct sir_ocb_config_channel) +
309 num_schedule * sizeof(struct sir_ocb_config_sched) +
310 ndl_chan_list_len +
311 ndl_active_state_list_len;
312
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530313 cursor = qdf_mem_malloc(len);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800314 if (!cursor)
315 goto fail;
316
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800317 ret = cursor;
318 cursor += sizeof(*ret);
319
320 ret->channel_count = num_channels;
321 ret->channels = cursor;
322 cursor += num_channels * sizeof(*ret->channels);
323
324 ret->schedule_size = num_schedule;
325 ret->schedule = cursor;
326 cursor += num_schedule * sizeof(*ret->schedule);
327
328 ret->dcc_ndl_chan_list = cursor;
329 cursor += ndl_chan_list_len;
330
331 ret->dcc_ndl_active_state_list = cursor;
332 cursor += ndl_active_state_list_len;
333
334 return ret;
335
336fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530337 qdf_mem_free(ret);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800338 return NULL;
339}
340
Jeff Johnson7af334b2017-02-01 13:03:43 -0800341struct hdd_ocb_set_config_priv {
342 int status;
343};
344
345
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800346/**
347 * hdd_ocb_set_config_callback() - OCB set config callback function
348 * @context_ptr: OCB call context
349 * @response_ptr: Pointer to response structure
350 *
351 * This function is registered as a callback with the lower layers
352 * and is used to respond with the status of a OCB set config command.
353 */
354static void hdd_ocb_set_config_callback(void *context_ptr, void *response_ptr)
355{
Jeff Johnson7af334b2017-02-01 13:03:43 -0800356 struct hdd_request *hdd_request;
357 struct hdd_ocb_set_config_priv *priv;
358 struct sir_ocb_set_config_response *response = response_ptr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800359
Jeff Johnson7af334b2017-02-01 13:03:43 -0800360 hdd_request = hdd_request_get(context_ptr);
361 if (!hdd_request) {
362 hdd_err("Obsolete request");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800363 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800364 }
Jeff Johnson7af334b2017-02-01 13:03:43 -0800365 priv = hdd_request_priv(hdd_request);
366
367 if (response && response->status)
Srinivas Girigowdaaaea4102017-03-25 11:02:52 -0700368 hdd_warn("Operation failed: %d", response->status);
Jeff Johnson7af334b2017-02-01 13:03:43 -0800369
370 if (response && (0 == response->status))
371 priv->status = 0;
372 else
373 priv->status = -EINVAL;
374
375 hdd_request_complete(hdd_request);
376 hdd_request_put(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800377}
378
379/**
380 * hdd_ocb_set_config_req() - Send an OCB set config request
381 * @adapter: a pointer to the adapter
382 * @config: a pointer to the OCB configuration
383 *
384 * Return: 0 on success.
385 */
Jeff Johnson7a1688a2017-08-29 14:27:19 -0700386static int hdd_ocb_set_config_req(struct hdd_adapter *adapter,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800387 struct sir_ocb_config *config)
388{
389 int rc;
Jeff Johnson7af334b2017-02-01 13:03:43 -0800390 QDF_STATUS status;
Jeff Johnson7106aba2017-08-28 11:49:07 -0700391 struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson7af334b2017-02-01 13:03:43 -0800392 void *cookie;
393 struct hdd_request *hdd_request;
394 struct hdd_ocb_set_config_priv *priv;
395 static const struct hdd_request_params params = {
396 .priv_size = sizeof(*priv),
397 .timeout_ms = WLAN_WAIT_TIME_OCB_CMD,
398 };
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800399
400 if (hdd_ocb_validate_config(adapter, config)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700401 hdd_err("The configuration is invalid");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800402 return -EINVAL;
403 }
404
Jeff Johnson7af334b2017-02-01 13:03:43 -0800405 hdd_request = hdd_request_alloc(&params);
406 if (!hdd_request) {
407 hdd_err("Request allocation failure");
408 return -ENOMEM;
409 }
410 cookie = hdd_request_cookie(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800411
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -0700412 hdd_debug("Disabling queues");
Himanshu Agarwal865201d2017-04-12 15:45:31 +0530413 wlan_hdd_netif_queue_control(adapter,
414 WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER,
415 WLAN_CONTROL_PATH);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800416
417 /* Call the SME API to set the config */
Jeff Johnson7af334b2017-02-01 13:03:43 -0800418 status = sme_ocb_set_config(hdd_ctx->hHal, cookie,
419 hdd_ocb_set_config_callback, config);
420 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700421 hdd_err("Error calling SME function.");
Jeff Johnson7af334b2017-02-01 13:03:43 -0800422 rc = qdf_status_to_os_return(status);
423 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800424 }
425
426 /* Wait for the function to complete. */
Jeff Johnson7af334b2017-02-01 13:03:43 -0800427 rc = hdd_request_wait_for_response(hdd_request);
428 if (rc) {
429 hdd_err("Operation timed out");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800430 goto end;
431 }
432
Jeff Johnson7af334b2017-02-01 13:03:43 -0800433 priv = hdd_request_priv(hdd_request);
434 rc = priv->status;
435 if (rc) {
436 hdd_err("Operation failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800437 goto end;
438 }
439
Jeff Johnson7af334b2017-02-01 13:03:43 -0800440 /*
441 * OCB set config command successful.
442 * Open the TX data path
443 */
444 if (!hdd_ocb_register_sta(adapter))
445 wlan_hdd_netif_queue_control(adapter,
446 WLAN_START_ALL_NETIF_QUEUE_N_CARRIER,
447 WLAN_CONTROL_PATH);
448
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800449 /* fall through */
450end:
Jeff Johnson7af334b2017-02-01 13:03:43 -0800451 hdd_request_put(hdd_request);
452
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800453 return rc;
454}
455
456/**
457 * __iw_set_dot11p_channel_sched() - Handler for WLAN_SET_DOT11P_CHANNEL_SCHED
458 * ioctl
459 * @dev: Pointer to net_device structure
460 * @iw_request_info: IW Request Info
461 * @wrqu: IW Request Userspace Data Pointer
462 * @extra: IW Request Kernel Data Pointer
463 *
464 * Return: 0 on success
465 */
466static int __iw_set_dot11p_channel_sched(struct net_device *dev,
467 struct iw_request_info *info,
468 union iwreq_data *wrqu, char *extra)
469{
Jeff Johnson441e1f72017-02-07 08:50:49 -0800470 int rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800471 struct dot11p_channel_sched *sched;
Jeff Johnson7106aba2017-08-28 11:49:07 -0700472 struct hdd_context *hdd_ctx;
Jeff Johnson7a1688a2017-08-29 14:27:19 -0700473 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800474 struct sir_ocb_config *config = NULL;
475 uint8_t *mac_addr;
476 int i, j;
477 struct sir_ocb_config_channel *curr_chan;
478
Jeff Johnson6ee91ee2016-02-11 18:55:30 -0800479 ENTER_DEV(dev);
480
Jeff Johnson382bce02017-09-01 14:21:07 -0700481 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
Jeff Johnson441e1f72017-02-07 08:50:49 -0800482 rc = wlan_hdd_validate_context(hdd_ctx);
483 if (0 != rc)
484 return rc;
485
486 rc = hdd_check_private_wext_control(hdd_ctx, info);
487 if (0 != rc)
488 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800489
Krunal Sonibe766b02016-03-10 13:00:44 -0800490 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700491 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800492 return -EINVAL;
493 }
494
495 sched = (struct dot11p_channel_sched *)extra;
496
497 /* Scheduled slots same as num channels for compatibility */
498 config = hdd_ocb_config_new(sched->num_channels, sched->num_channels,
499 0, 0);
500 if (config == NULL) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700501 hdd_err("Failed to allocate memory!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800502 return -ENOMEM;
503 }
504
505 /* Identify the vdev interface */
506 config->session_id = adapter->sessionId;
507
508 /* Release all the mac addresses used for OCB */
509 for (i = 0; i < adapter->ocb_mac_addr_count; i++) {
Jeff Johnson399c6272017-08-30 10:51:00 -0700510 wlan_hdd_release_intf_addr(hdd_ctx,
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800511 adapter->ocb_mac_address[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800512 }
513 adapter->ocb_mac_addr_count = 0;
514
515 config->channel_count = 0;
516 for (i = 0; i < sched->num_channels; i++) {
517 if (0 == sched->channels[i].channel_freq)
518 continue;
519
520 curr_chan = &(config->channels[config->channel_count]);
521
522 curr_chan->chan_freq = sched->channels[i].channel_freq;
523 /*
524 * tx_power is divided by 2 because ocb_channel.tx_power is
525 * in half dB increments and sir_ocb_config_channel.max_pwr
526 * is in 1 dB increments.
527 */
528 curr_chan->max_pwr = sched->channels[i].tx_power / 2;
529 curr_chan->bandwidth = sched->channels[i].channel_bandwidth;
530 /* assume 10 as default if not provided */
531 if (curr_chan->bandwidth == 0)
532 curr_chan->bandwidth = 10;
533
534 /*
535 * Setup locally administered mac addresses for each channel.
536 * First channel uses the adapter's address.
537 */
538 if (i == 0) {
Anurag Chouhanc5548422016-02-24 18:33:27 +0530539 qdf_copy_macaddr(&curr_chan->mac_address,
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800540 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800541 } else {
Jeff Johnson399c6272017-08-30 10:51:00 -0700542 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800543 if (mac_addr == NULL) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700544 hdd_err("Cannot obtain mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800545 rc = -EINVAL;
546 goto fail;
547 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530548 qdf_mem_copy(config->channels[
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800549 config->channel_count].mac_address.bytes,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800550 mac_addr, sizeof(tSirMacAddr));
551 /* Save the mac address to release later */
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530552 qdf_mem_copy(adapter->ocb_mac_address[
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800553 adapter->ocb_mac_addr_count].bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530554 mac_addr, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800555 adapter->ocb_mac_addr_count++;
556 }
557
558 for (j = 0; j < MAX_NUM_AC; j++) {
559 curr_chan->qos_params[j].aifsn =
560 sched->channels[i].qos_params[j].aifsn;
561 curr_chan->qos_params[j].cwmin =
562 sched->channels[i].qos_params[j].cwmin;
563 curr_chan->qos_params[j].cwmax =
564 sched->channels[i].qos_params[j].cwmax;
565 }
566
567 config->channel_count++;
568 }
569
570 /*
571 * Scheduled slots same as num channels for compatibility with
572 * legacy use.
573 */
574 for (i = 0; i < sched->num_channels; i++) {
575 config->schedule[i].chan_freq = sched->channels[i].channel_freq;
576 config->schedule[i].guard_interval =
577 sched->channels[i].start_guard_interval;
578 config->schedule[i].total_duration =
579 sched->channels[i].duration;
580 }
581
582 rc = hdd_ocb_set_config_req(adapter, config);
583 if (rc) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700584 hdd_err("Error while setting OCB config");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800585 goto fail;
586 }
587
588 rc = 0;
589
590fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530591 qdf_mem_free(config);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800592 return rc;
593}
594
595/**
596 * iw_set_dot11p_channel_sched() - IOCTL interface for setting channel schedule
597 * @dev: Pointer to net_device structure
598 * @iw_request_info: IW Request Info
599 * @wrqu: IW Request Userspace Data Pointer
600 * @extra: IW Request Kernel Data Pointer
601 *
602 * Return: 0 on success.
603 */
604int iw_set_dot11p_channel_sched(struct net_device *dev,
605 struct iw_request_info *info,
606 union iwreq_data *wrqu, char *extra)
607{
608 int ret;
609
610 cds_ssr_protect(__func__);
611 ret = __iw_set_dot11p_channel_sched(dev, info, wrqu, extra);
612 cds_ssr_unprotect(__func__);
613
614 return ret;
615}
616
617static const struct nla_policy qca_wlan_vendor_ocb_set_config_policy[
618 QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_MAX + 1] = {
619 [QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_COUNT] = {
620 .type = NLA_U32
621 },
622 [QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_SCHEDULE_SIZE] = {
623 .type = NLA_U32
624 },
625 [QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_ARRAY] = {
626 .type = NLA_BINARY
627 },
628 [QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_SCHEDULE_ARRAY] = {
629 .type = NLA_BINARY
630 },
631 [QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_CHANNEL_ARRAY] = {
632 .type = NLA_BINARY
633 },
634 [QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_ACTIVE_STATE_ARRAY] = {
635 .type = NLA_BINARY
636 },
637 [QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_FLAGS] = {
638 .type = NLA_U32
639 },
640};
641
642static const struct nla_policy qca_wlan_vendor_ocb_set_utc_time_policy[
643 QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_MAX + 1] = {
644 [QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_VALUE] = {
645 .type = NLA_BINARY, .len = SIZE_UTC_TIME
646 },
647 [QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_ERROR] = {
648 .type = NLA_BINARY, .len = SIZE_UTC_TIME_ERROR
649 },
650};
651
652static const struct nla_policy qca_wlan_vendor_ocb_start_timing_advert_policy[
653 QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_MAX + 1] = {
654 [QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_CHANNEL_FREQ] = {
655 .type = NLA_U32
656 },
657 [QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_REPEAT_RATE] = {
658 .type = NLA_U32
659 },
660};
661
662static const struct nla_policy qca_wlan_vendor_ocb_stop_timing_advert_policy[
663 QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_MAX + 1] = {
664 [QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_CHANNEL_FREQ] = {
665 .type = NLA_U32
666 },
667};
668
669static const struct nla_policy qca_wlan_vendor_ocb_get_tsf_timer_resp[] = {
670 [QCA_WLAN_VENDOR_ATTR_OCB_GET_TSF_RESP_TIMER_HIGH] = {
671 .type = NLA_U32
672 },
673 [QCA_WLAN_VENDOR_ATTR_OCB_GET_TSF_RESP_TIMER_LOW] = {
674 .type = NLA_U32
675 },
676};
677
678static const struct nla_policy qca_wlan_vendor_dcc_get_stats[] = {
679 [QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_CHANNEL_COUNT] = {
680 .type = NLA_U32
681 },
682 [QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY] = {
683 .type = NLA_BINARY
684 },
685};
686
687static const struct nla_policy qca_wlan_vendor_dcc_get_stats_resp[] = {
688 [QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_CHANNEL_COUNT] = {
689 .type = NLA_U32
690 },
691 [QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_STATS_ARRAY] = {
692 .type = NLA_BINARY
693 },
694};
695
696static const struct nla_policy qca_wlan_vendor_dcc_clear_stats[] = {
697 [QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_BITMAP] = {
698 .type = NLA_U32
699 },
700};
701
702static const struct nla_policy qca_wlan_vendor_dcc_update_ndl[
703 QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_MAX + 1] = {
704 [QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_COUNT] = {
705 .type = NLA_U32
706 },
707 [QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY] = {
708 .type = NLA_BINARY
709 },
710 [QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY] = {
711 .type = NLA_BINARY
712 },
713};
714
715/**
716 * struct wlan_hdd_ocb_config_channel
717 * @chan_freq: frequency of the channel
718 * @bandwidth: bandwidth of the channel, either 10 or 20 MHz
719 * @mac_address: MAC address assigned to this channel
720 * @qos_params: QoS parameters
721 * @max_pwr: maximum transmit power of the channel (1/2 dBm)
722 * @min_pwr: minimum transmit power of the channel (1/2 dBm)
723 */
724struct wlan_hdd_ocb_config_channel {
725 uint32_t chan_freq;
726 uint32_t bandwidth;
727 uint16_t flags;
728 uint8_t reserved[4];
729 struct sir_qos_params qos_params[MAX_NUM_AC];
730 uint32_t max_pwr;
731 uint32_t min_pwr;
732};
733
734static void wlan_hdd_ocb_config_channel_to_sir_ocb_config_channel(
735 struct sir_ocb_config_channel *dest,
736 struct wlan_hdd_ocb_config_channel *src,
737 uint32_t channel_count)
738{
739 uint32_t i;
740
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530741 qdf_mem_zero(dest, channel_count * sizeof(*dest));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800742
743 for (i = 0; i < channel_count; i++) {
744 dest[i].chan_freq = src[i].chan_freq;
745 dest[i].bandwidth = src[i].bandwidth;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530746 qdf_mem_copy(dest[i].qos_params, src[i].qos_params,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800747 sizeof(dest[i].qos_params));
748 /*
749 * max_pwr and min_pwr are divided by 2 because
750 * wlan_hdd_ocb_config_channel.max_pwr and min_pwr
751 * are in 1/2 dB increments and
752 * sir_ocb_config_channel.max_pwr and min_pwr are in
753 * 1 dB increments.
754 */
755 dest[i].max_pwr = src[i].max_pwr / 2;
756 dest[i].min_pwr = (src[i].min_pwr + 1) / 2;
757 dest[i].flags = src[i].flags;
758 }
759}
760
761/**
762 * __wlan_hdd_cfg80211_ocb_set_config() - Interface for set config command
763 * @wiphy: pointer to the wiphy
764 * @wdev: pointer to the wdev
765 * @data: The netlink data
766 * @data_len: The length of the netlink data in bytes
767 *
768 * Return: 0 on success.
769 */
770static int __wlan_hdd_cfg80211_ocb_set_config(struct wiphy *wiphy,
771 struct wireless_dev *wdev,
772 const void *data,
773 int data_len)
774{
Jeff Johnson7106aba2017-08-28 11:49:07 -0700775 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800776 struct net_device *dev = wdev->netdev;
Jeff Johnson7a1688a2017-08-29 14:27:19 -0700777 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800778 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_MAX + 1];
779 struct nlattr *channel_array;
780 struct nlattr *sched_array;
781 struct nlattr *ndl_chan_list;
782 uint32_t ndl_chan_list_len;
783 struct nlattr *ndl_active_state_list;
784 uint32_t ndl_active_state_list_len;
785 uint32_t flags = 0;
786 int i;
Jeff Johnson929ad032016-10-19 07:34:42 -0700787 uint32_t channel_count, schedule_size;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800788 struct sir_ocb_config *config;
789 int rc = -EINVAL;
790 uint8_t *mac_addr;
791
Jeff Johnson1f61b612016-02-12 16:28:33 -0800792 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800793
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530794 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800795 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800796
Krunal Sonibe766b02016-03-10 13:00:44 -0800797 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700798 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800799 return -EINVAL;
800 }
801
802 /* Parse the netlink message */
Dustin Brown3fb15042017-08-15 15:54:49 -0700803 if (hdd_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_MAX, data,
804 data_len, qca_wlan_vendor_ocb_set_config_policy)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700805 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800806 return -EINVAL;
807 }
808
809 /* Get the number of channels in the schedule */
810 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_COUNT]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700811 hdd_err("CHANNEL_COUNT is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800812 return -EINVAL;
813 }
814 channel_count = nla_get_u32(
815 tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_COUNT]);
816
817 /* Get the size of the channel schedule */
818 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_SCHEDULE_SIZE]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700819 hdd_err("SCHEDULE_SIZE is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800820 return -EINVAL;
821 }
822 schedule_size = nla_get_u32(
823 tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_SCHEDULE_SIZE]);
824
825 /* Get the ndl chan array and the ndl active state array. */
SaidiReddy Yenuga3db38772017-03-28 15:18:56 +0530826 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_CHANNEL_ARRAY]) {
827 hdd_err("NDL_CHANNEL_ARRAY is not present");
828 return -EINVAL;
829 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800830 ndl_chan_list =
831 tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_CHANNEL_ARRAY];
832 ndl_chan_list_len = (ndl_chan_list ? nla_len(ndl_chan_list) : 0);
833
SaidiReddy Yenuga3db38772017-03-28 15:18:56 +0530834 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_ACTIVE_STATE_ARRAY]) {
835 hdd_err("NDL_ACTIVE_STATE_ARRAY is not present");
836 return -EINVAL;
837 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800838 ndl_active_state_list =
839 tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_ACTIVE_STATE_ARRAY];
840 ndl_active_state_list_len = (ndl_active_state_list ?
841 nla_len(ndl_active_state_list) : 0);
842
843 /* Get the flags */
844 if (tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_FLAGS])
845 flags = nla_get_u32(tb[
846 QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_FLAGS]);
847
848 config = hdd_ocb_config_new(channel_count, schedule_size,
849 ndl_chan_list_len,
850 ndl_active_state_list_len);
851 if (config == NULL) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700852 hdd_err("Failed to allocate memory!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800853 return -ENOMEM;
854 }
855
856 config->channel_count = channel_count;
857 config->schedule_size = schedule_size;
858 config->flags = flags;
859
860 /* Read the channel array */
861 channel_array = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_ARRAY];
862 if (!channel_array) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700863 hdd_err("No channel present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800864 goto fail;
865 }
866 if (nla_len(channel_array) != channel_count *
867 sizeof(struct wlan_hdd_ocb_config_channel)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700868 hdd_err("CHANNEL_ARRAY is not the correct size");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869 goto fail;
870 }
871 wlan_hdd_ocb_config_channel_to_sir_ocb_config_channel(
872 config->channels, nla_data(channel_array), channel_count);
873
874 /* Identify the vdev interface */
875 config->session_id = adapter->sessionId;
876
877 /* Release all the mac addresses used for OCB */
878 for (i = 0; i < adapter->ocb_mac_addr_count; i++) {
Jeff Johnson399c6272017-08-30 10:51:00 -0700879 wlan_hdd_release_intf_addr(hdd_ctx,
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800880 adapter->ocb_mac_address[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800881 }
882 adapter->ocb_mac_addr_count = 0;
883
884 /*
885 * Setup locally administered mac addresses for each channel.
886 * First channel uses the adapter's address.
887 */
888 for (i = 0; i < config->channel_count; i++) {
889 if (i == 0) {
Anurag Chouhanc5548422016-02-24 18:33:27 +0530890 qdf_copy_macaddr(&config->channels[i].mac_address,
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800891 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800892 } else {
Jeff Johnson399c6272017-08-30 10:51:00 -0700893 mac_addr = wlan_hdd_get_intf_addr(hdd_ctx);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800894 if (mac_addr == NULL) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700895 hdd_err("Cannot obtain mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800896 goto fail;
897 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530898 qdf_mem_copy(config->channels[i].mac_address.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530899 mac_addr, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800900 /* Save the mac address to release later */
Anurag Chouhanc5548422016-02-24 18:33:27 +0530901 qdf_copy_macaddr(&adapter->ocb_mac_address[
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800902 adapter->ocb_mac_addr_count],
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800903 &config->channels[i].mac_address);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800904 adapter->ocb_mac_addr_count++;
905 }
906 }
907
908 /* Read the schedule array */
909 sched_array = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_SCHEDULE_ARRAY];
910 if (!sched_array) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700911 hdd_err("No channel present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800912 goto fail;
913 }
914 if (nla_len(sched_array) != schedule_size * sizeof(*config->schedule)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700915 hdd_err("SCHEDULE_ARRAY is not the correct size");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800916 goto fail;
917 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530918 qdf_mem_copy(config->schedule, nla_data(sched_array),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800919 nla_len(sched_array));
920
921 /* Copy the NDL chan array */
922 if (ndl_chan_list_len) {
923 config->dcc_ndl_chan_list_len = ndl_chan_list_len;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530924 qdf_mem_copy(config->dcc_ndl_chan_list, nla_data(ndl_chan_list),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800925 nla_len(ndl_chan_list));
926 }
927
928 /* Copy the NDL active state array */
929 if (ndl_active_state_list_len) {
930 config->dcc_ndl_active_state_list_len =
931 ndl_active_state_list_len;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530932 qdf_mem_copy(config->dcc_ndl_active_state_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800933 nla_data(ndl_active_state_list),
934 nla_len(ndl_active_state_list));
935 }
936
937 rc = hdd_ocb_set_config_req(adapter, config);
938 if (rc)
Jeff Johnson5f735d52016-07-06 15:14:45 -0700939 hdd_err("Error while setting OCB config: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800940
941fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530942 qdf_mem_free(config);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800943 return rc;
944}
945
946/**
947 * wlan_hdd_cfg80211_ocb_set_config() - Interface for set config command
948 * @wiphy: pointer to the wiphy
949 * @wdev: pointer to the wdev
950 * @data: The netlink data
951 * @data_len: The length of the netlink data in bytes
952 *
953 * Return: 0 on success.
954 */
955int wlan_hdd_cfg80211_ocb_set_config(struct wiphy *wiphy,
956 struct wireless_dev *wdev,
957 const void *data,
958 int data_len)
959{
960 int ret;
961
962 cds_ssr_protect(__func__);
963 ret = __wlan_hdd_cfg80211_ocb_set_config(wiphy, wdev, data, data_len);
964 cds_ssr_unprotect(__func__);
965
966 return ret;
967}
968
969/**
970 * __wlan_hdd_cfg80211_ocb_set_utc_time() - Interface for set UTC time command
971 * @wiphy: pointer to the wiphy
972 * @wdev: pointer to the wdev
973 * @data: The netlink data
974 * @data_len: The length of the netlink data in bytes
975 *
976 * Return: 0 on success.
977 */
978static int __wlan_hdd_cfg80211_ocb_set_utc_time(struct wiphy *wiphy,
979 struct wireless_dev *wdev,
980 const void *data,
981 int data_len)
982{
Jeff Johnson7106aba2017-08-28 11:49:07 -0700983 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800984 struct net_device *dev = wdev->netdev;
Jeff Johnson7a1688a2017-08-29 14:27:19 -0700985 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800986 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_MAX + 1];
987 struct nlattr *utc_attr;
988 struct nlattr *time_error_attr;
989 struct sir_ocb_utc *utc;
990 int rc = -EINVAL;
991
Jeff Johnson1f61b612016-02-12 16:28:33 -0800992 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800993
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530994 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800995 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800996
Krunal Sonibe766b02016-03-10 13:00:44 -0800997 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700998 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800999 return -EINVAL;
1000 }
1001
1002 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001003 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001004 return -EINVAL;
1005 }
1006
1007 /* Parse the netlink message */
Dustin Brown3fb15042017-08-15 15:54:49 -07001008 if (hdd_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_MAX, data,
1009 data_len, qca_wlan_vendor_ocb_set_utc_time_policy)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001010 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001011 return -EINVAL;
1012 }
1013
1014 /* Read the UTC time */
1015 utc_attr = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_VALUE];
1016 if (!utc_attr) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001017 hdd_err("UTC_TIME is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001018 return -EINVAL;
1019 }
1020 if (nla_len(utc_attr) != SIZE_UTC_TIME) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001021 hdd_err("UTC_TIME is not the correct size");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001022 return -EINVAL;
1023 }
1024
1025 /* Read the time error */
1026 time_error_attr = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_ERROR];
1027 if (!time_error_attr) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001028 hdd_err("UTC_TIME is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001029 return -EINVAL;
1030 }
1031 if (nla_len(time_error_attr) != SIZE_UTC_TIME_ERROR) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001032 hdd_err("UTC_TIME is not the correct size");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001033 return -EINVAL;
1034 }
1035
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301036 utc = qdf_mem_malloc(sizeof(*utc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001037 if (!utc) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001038 hdd_err("qdf_mem_malloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001039 return -ENOMEM;
1040 }
1041 utc->vdev_id = adapter->sessionId;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301042 qdf_mem_copy(utc->utc_time, nla_data(utc_attr), SIZE_UTC_TIME);
1043 qdf_mem_copy(utc->time_error, nla_data(time_error_attr),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001044 SIZE_UTC_TIME_ERROR);
1045
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301046 if (sme_ocb_set_utc_time(hdd_ctx->hHal, utc) != QDF_STATUS_SUCCESS) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001047 hdd_err("Error while setting UTC time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001048 rc = -EINVAL;
1049 } else {
1050 rc = 0;
1051 }
1052
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301053 qdf_mem_free(utc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 return rc;
1055}
1056
1057/**
1058 * wlan_hdd_cfg80211_ocb_set_utc_time() - Interface for the set UTC time command
1059 * @wiphy: pointer to the wiphy
1060 * @wdev: pointer to the wdev
1061 * @data: The netlink data
1062 * @data_len: The length of the netlink data in bytes
1063 *
1064 * Return: 0 on success.
1065 */
1066int wlan_hdd_cfg80211_ocb_set_utc_time(struct wiphy *wiphy,
1067 struct wireless_dev *wdev,
1068 const void *data,
1069 int data_len)
1070{
1071 int ret;
1072
1073 cds_ssr_protect(__func__);
1074 ret = __wlan_hdd_cfg80211_ocb_set_utc_time(wiphy, wdev, data, data_len);
1075 cds_ssr_unprotect(__func__);
1076
1077 return ret;
1078}
1079
1080/**
1081 * __wlan_hdd_cfg80211_ocb_start_timing_advert() - Interface for start TA cmd
1082 * @wiphy: pointer to the wiphy
1083 * @wdev: pointer to the wdev
1084 * @data: The netlink data
1085 * @data_len: The length of the netlink data in bytes
1086 *
1087 * Return: 0 on success.
1088 */
1089static int
1090__wlan_hdd_cfg80211_ocb_start_timing_advert(struct wiphy *wiphy,
1091 struct wireless_dev *wdev,
1092 const void *data,
1093 int data_len)
1094{
Jeff Johnson7106aba2017-08-28 11:49:07 -07001095 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001096 struct net_device *dev = wdev->netdev;
Jeff Johnson7a1688a2017-08-29 14:27:19 -07001097 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001098 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_MAX + 1];
1099 struct sir_ocb_timing_advert *timing_advert;
1100 int rc = -EINVAL;
1101
Jeff Johnson1f61b612016-02-12 16:28:33 -08001102 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001103
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301104 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001105 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001106
Krunal Sonibe766b02016-03-10 13:00:44 -08001107 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001108 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109 return -EINVAL;
1110 }
1111
1112 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001113 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001114 return -EINVAL;
1115 }
1116
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301117 timing_advert = qdf_mem_malloc(sizeof(*timing_advert));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001118 if (!timing_advert) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001119 hdd_err("qdf_mem_malloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001120 return -ENOMEM;
1121 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001122 timing_advert->vdev_id = adapter->sessionId;
1123
1124 /* Parse the netlink message */
Dustin Brown3fb15042017-08-15 15:54:49 -07001125 if (hdd_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_MAX,
1126 data, data_len,
1127 qca_wlan_vendor_ocb_start_timing_advert_policy)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001128 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001129 goto fail;
1130 }
1131
1132 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_CHANNEL_FREQ]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001133 hdd_err("CHANNEL_FREQ is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001134 goto fail;
1135 }
1136 timing_advert->chan_freq = nla_get_u32(
1137 tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_CHANNEL_FREQ]);
1138
1139 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_REPEAT_RATE]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001140 hdd_err("REPEAT_RATE is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141 goto fail;
1142 }
1143 timing_advert->repeat_rate = nla_get_u32(
1144 tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_REPEAT_RATE]);
1145
1146 timing_advert->template_length =
Naveen Rawatb4d37622015-11-13 16:15:25 -08001147 sme_ocb_gen_timing_advert_frame(hdd_ctx->hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148 *(tSirMacAddr *)&adapter->macAddressCurrent.bytes,
1149 &timing_advert->template_value,
1150 &timing_advert->timestamp_offset,
1151 &timing_advert->time_value_offset);
1152 if (timing_advert->template_length <= 0) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001153 hdd_err("Error while generating the TA frame");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001154 goto fail;
1155 }
1156
1157 if (sme_ocb_start_timing_advert(hdd_ctx->hHal, timing_advert) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301158 QDF_STATUS_SUCCESS) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001159 hdd_err("Error while starting timing advert");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001160 rc = -EINVAL;
1161 } else {
1162 rc = 0;
1163 }
1164
1165fail:
1166 if (timing_advert->template_value)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301167 qdf_mem_free(timing_advert->template_value);
1168 qdf_mem_free(timing_advert);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001169 return rc;
1170}
1171
1172/**
1173 * wlan_hdd_cfg80211_ocb_start_timing_advert() - Interface for the start TA cmd
1174 * @wiphy: pointer to the wiphy
1175 * @wdev: pointer to the wdev
1176 * @data: The netlink data
1177 * @data_len: The length of the netlink data in bytes
1178 *
1179 * Return: 0 on success.
1180 */
1181int wlan_hdd_cfg80211_ocb_start_timing_advert(struct wiphy *wiphy,
1182 struct wireless_dev *wdev,
1183 const void *data,
1184 int data_len)
1185{
1186 int ret;
1187
1188 cds_ssr_protect(__func__);
1189 ret = __wlan_hdd_cfg80211_ocb_start_timing_advert(wiphy, wdev,
1190 data, data_len);
1191 cds_ssr_unprotect(__func__);
1192
1193 return ret;
1194}
1195
1196/**
1197 * __wlan_hdd_cfg80211_ocb_stop_timing_advert() - Interface for the stop TA cmd
1198 * @wiphy: pointer to the wiphy
1199 * @wdev: pointer to the wdev
1200 * @data: The netlink data
1201 * @data_len: The length of the netlink data in bytes
1202 *
1203 * Return: 0 on success.
1204 */
1205static int
1206__wlan_hdd_cfg80211_ocb_stop_timing_advert(struct wiphy *wiphy,
1207 struct wireless_dev *wdev,
1208 const void *data,
1209 int data_len)
1210{
Jeff Johnson7106aba2017-08-28 11:49:07 -07001211 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001212 struct net_device *dev = wdev->netdev;
Jeff Johnson7a1688a2017-08-29 14:27:19 -07001213 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001214 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_MAX + 1];
1215 struct sir_ocb_timing_advert *timing_advert;
1216 int rc = -EINVAL;
1217
Jeff Johnson1f61b612016-02-12 16:28:33 -08001218 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001219
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301220 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001221 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001222
Krunal Sonibe766b02016-03-10 13:00:44 -08001223 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001224 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001225 return -EINVAL;
1226 }
1227
1228 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001229 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001230 return -EINVAL;
1231 }
1232
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301233 timing_advert = qdf_mem_malloc(sizeof(*timing_advert));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001234 if (!timing_advert) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001235 hdd_err("qdf_mem_malloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001236 return -ENOMEM;
1237 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001238 timing_advert->vdev_id = adapter->sessionId;
1239
1240 /* Parse the netlink message */
Dustin Brown3fb15042017-08-15 15:54:49 -07001241 if (hdd_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_MAX,
1242 data, data_len,
1243 qca_wlan_vendor_ocb_stop_timing_advert_policy)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001244 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001245 goto fail;
1246 }
1247
1248 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_CHANNEL_FREQ]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001249 hdd_err("CHANNEL_FREQ is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001250 goto fail;
1251 }
1252 timing_advert->chan_freq = nla_get_u32(
1253 tb[QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_CHANNEL_FREQ]);
1254
1255 if (sme_ocb_stop_timing_advert(hdd_ctx->hHal, timing_advert) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301256 QDF_STATUS_SUCCESS) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001257 hdd_err("Error while stopping timing advert");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001258 rc = -EINVAL;
1259 } else {
1260 rc = 0;
1261 }
1262
1263fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301264 qdf_mem_free(timing_advert);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001265 return rc;
1266}
1267
1268/**
1269 * wlan_hdd_cfg80211_ocb_stop_timing_advert() - Interface for the stop TA cmd
1270 * @wiphy: pointer to the wiphy
1271 * @wdev: pointer to the wdev
1272 * @data: The netlink data
1273 * @data_len: The length of the netlink data in bytes
1274 *
1275 * Return: 0 on success.
1276 */
1277int wlan_hdd_cfg80211_ocb_stop_timing_advert(struct wiphy *wiphy,
1278 struct wireless_dev *wdev,
1279 const void *data,
1280 int data_len)
1281{
1282 int ret;
1283
1284 cds_ssr_protect(__func__);
1285 ret = __wlan_hdd_cfg80211_ocb_stop_timing_advert(wiphy, wdev,
1286 data, data_len);
1287 cds_ssr_unprotect(__func__);
1288
1289 return ret;
1290}
1291
Jeff Johnson7af334b2017-02-01 13:03:43 -08001292struct hdd_ocb_get_tsf_timer_priv {
1293 struct sir_ocb_get_tsf_timer_response response;
1294 int status;
1295};
1296
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001297/**
1298 * hdd_ocb_get_tsf_timer_callback() - Callback to get TSF command
1299 * @context_ptr: request context
1300 * @response_ptr: response data
1301 */
1302static void hdd_ocb_get_tsf_timer_callback(void *context_ptr,
1303 void *response_ptr)
1304{
Jeff Johnson7af334b2017-02-01 13:03:43 -08001305 struct hdd_request *hdd_request;
1306 struct hdd_ocb_get_tsf_timer_priv *priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001307 struct sir_ocb_get_tsf_timer_response *response = response_ptr;
1308
Jeff Johnson7af334b2017-02-01 13:03:43 -08001309 hdd_request = hdd_request_get(context_ptr);
1310 if (!hdd_request) {
1311 hdd_err("Obsolete request");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001312 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001313 }
Jeff Johnson7af334b2017-02-01 13:03:43 -08001314
1315 if (response) {
1316 priv->response = *response;
1317 priv->status = 0;
1318 } else {
1319 priv->status = -EINVAL;
1320 }
1321 hdd_request_complete(hdd_request);
1322 hdd_request_put(hdd_request);
1323}
1324
1325static int
1326hdd_ocb_get_tsf_timer_reply(struct wiphy *wiphy,
1327 struct sir_ocb_get_tsf_timer_response *response)
1328{
1329 uint32_t nl_buf_len;
1330 struct sk_buff *nl_resp;
1331 int rc;
1332
1333 /* Allocate the buffer for the response. */
1334 nl_buf_len = NLMSG_HDRLEN;
1335 nl_buf_len += 2 * (NLA_HDRLEN + sizeof(uint32_t));
1336 nl_resp = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, nl_buf_len);
1337 if (!nl_resp) {
1338 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
1339 return -ENOMEM;
1340 }
1341
1342 /* Populate the response. */
1343 rc = nla_put_u32(nl_resp,
1344 QCA_WLAN_VENDOR_ATTR_OCB_GET_TSF_RESP_TIMER_HIGH,
1345 response->timer_high);
1346 if (rc)
1347 goto end;
1348 rc = nla_put_u32(nl_resp,
1349 QCA_WLAN_VENDOR_ATTR_OCB_GET_TSF_RESP_TIMER_LOW,
1350 response->timer_low);
1351 if (rc)
1352 goto end;
1353
1354 /* Send the response. */
1355 rc = cfg80211_vendor_cmd_reply(nl_resp);
1356 nl_resp = NULL;
1357 if (rc) {
1358 hdd_err("cfg80211_vendor_cmd_reply failed: %d", rc);
1359 goto end;
1360 }
1361end:
1362 if (nl_resp)
1363 kfree_skb(nl_resp);
1364
1365 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001366}
1367
1368/**
1369 * __wlan_hdd_cfg80211_ocb_get_tsf_timer() - Interface for get TSF timer cmd
1370 * @wiphy: pointer to the wiphy
1371 * @wdev: pointer to the wdev
1372 * @data: The netlink data
1373 * @data_len: The length of the netlink data in bytes
1374 *
1375 * Return: 0 on success.
1376 */
1377static int
1378__wlan_hdd_cfg80211_ocb_get_tsf_timer(struct wiphy *wiphy,
1379 struct wireless_dev *wdev,
1380 const void *data,
1381 int data_len)
1382{
Jeff Johnson7106aba2017-08-28 11:49:07 -07001383 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001384 struct net_device *dev = wdev->netdev;
Jeff Johnson7a1688a2017-08-29 14:27:19 -07001385 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson7af334b2017-02-01 13:03:43 -08001386 int rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001387 struct sir_ocb_get_tsf_timer request = {0};
Jeff Johnson7af334b2017-02-01 13:03:43 -08001388 QDF_STATUS status;
1389 void *cookie;
1390 struct hdd_request *hdd_request;
1391 struct hdd_ocb_get_tsf_timer_priv *priv;
1392 static const struct hdd_request_params params = {
1393 .priv_size = sizeof(*priv),
1394 .timeout_ms = WLAN_WAIT_TIME_OCB_CMD,
1395 };
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001396
Jeff Johnson1f61b612016-02-12 16:28:33 -08001397 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001398
Jeff Johnson7af334b2017-02-01 13:03:43 -08001399 rc = wlan_hdd_validate_context(hdd_ctx);
1400 if (rc)
1401 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001402
Krunal Sonibe766b02016-03-10 13:00:44 -08001403 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001404 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001405 return -EINVAL;
1406 }
1407
1408 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001409 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001410 return -EINVAL;
1411 }
1412
Jeff Johnson7af334b2017-02-01 13:03:43 -08001413 hdd_request = hdd_request_alloc(&params);
1414 if (!hdd_request) {
1415 hdd_err("Request allocation failure");
1416 return -ENOMEM;
1417 }
1418 cookie = hdd_request_cookie(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001419
1420 request.vdev_id = adapter->sessionId;
1421 /* Call the SME function */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001422 status = sme_ocb_get_tsf_timer(hdd_ctx->hHal, cookie,
1423 hdd_ocb_get_tsf_timer_callback,
1424 &request);
1425 if (QDF_IS_STATUS_ERROR(status)) {
1426 hdd_err("Error calling SME function.");
1427 rc = qdf_status_to_os_return(status);
1428 goto end;
1429 }
1430
1431 rc = hdd_request_wait_for_response(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001432 if (rc) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001433 hdd_err("Operation timed out");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001434 goto end;
1435 }
1436
Jeff Johnson7af334b2017-02-01 13:03:43 -08001437 priv = hdd_request_priv(hdd_request);
1438 rc = priv->status;
1439 if (rc) {
1440 hdd_err("Operation failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001441 goto end;
1442 }
1443
Varun Reddy Yeturu8a5d3d42017-08-02 13:03:27 -07001444 hdd_debug("Got TSF timer response, high=%d, low=%d",
Jeff Johnson7af334b2017-02-01 13:03:43 -08001445 priv->response.timer_high,
1446 priv->response.timer_low);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001447
1448 /* Send the response. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001449 rc = hdd_ocb_get_tsf_timer_reply(wiphy, &priv->response);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001450 if (rc) {
Jeff Johnson7af334b2017-02-01 13:03:43 -08001451 hdd_err("hdd_ocb_get_tsf_timer_reply failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001452 goto end;
1453 }
1454
Jeff Johnson7af334b2017-02-01 13:03:43 -08001455 /* fall through */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001456end:
Jeff Johnson7af334b2017-02-01 13:03:43 -08001457 hdd_request_put(hdd_request);
1458
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001459 return rc;
1460}
1461
1462/**
1463 * wlan_hdd_cfg80211_ocb_get_tsf_timer() - Interface for get TSF timer cmd
1464 * @wiphy: pointer to the wiphy
1465 * @wdev: pointer to the wdev
1466 * @data: The netlink data
1467 * @data_len: The length of the netlink data in bytes
1468 *
1469 * Return: 0 on success.
1470 */
1471int wlan_hdd_cfg80211_ocb_get_tsf_timer(struct wiphy *wiphy,
1472 struct wireless_dev *wdev,
1473 const void *data,
1474 int data_len)
1475{
1476 int ret;
1477
1478 cds_ssr_protect(__func__);
1479 ret = __wlan_hdd_cfg80211_ocb_get_tsf_timer(wiphy, wdev,
1480 data, data_len);
1481 cds_ssr_unprotect(__func__);
1482
1483 return ret;
1484}
1485
Jeff Johnson7af334b2017-02-01 13:03:43 -08001486struct hdd_dcc_stats_priv {
1487 struct sir_dcc_get_stats_response *response;
1488 int status;
1489};
1490
1491static void hdd_dcc_get_stats_dealloc(void *context_ptr)
1492{
1493 struct hdd_dcc_stats_priv *priv = context_ptr;
1494
1495 qdf_mem_free(priv->response);
1496 priv->response = NULL;
1497}
1498
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001499/**
1500 * hdd_dcc_get_stats_callback() - Callback to get stats command
1501 * @context_ptr: request context
1502 * @response_ptr: response data
1503 */
1504static void hdd_dcc_get_stats_callback(void *context_ptr, void *response_ptr)
1505{
Jeff Johnson7af334b2017-02-01 13:03:43 -08001506 struct hdd_request *hdd_request;
1507 struct hdd_dcc_stats_priv *priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001508 struct sir_dcc_get_stats_response *response = response_ptr;
1509 struct sir_dcc_get_stats_response *hdd_resp;
1510
Jeff Johnson7af334b2017-02-01 13:03:43 -08001511 hdd_request = hdd_request_get(context_ptr);
1512 if (!hdd_request) {
1513 hdd_err("Obsolete request");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001514 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001515 }
Jeff Johnson7af334b2017-02-01 13:03:43 -08001516
1517 priv = hdd_request_priv(hdd_request);
1518 if (!response) {
1519 priv->status = -EINVAL;
1520 goto end;
1521 }
1522
1523 priv->response = qdf_mem_malloc(sizeof(*response) +
1524 response->channel_stats_array_len);
1525 if (!priv->response) {
1526 priv->status = -ENOMEM;
1527 goto end;
1528 }
1529
1530 hdd_resp = priv->response;
1531 *hdd_resp = *response;
1532 hdd_resp->channel_stats_array = (void *)hdd_resp + sizeof(*hdd_resp);
1533 qdf_mem_copy(hdd_resp->channel_stats_array,
1534 response->channel_stats_array,
1535 response->channel_stats_array_len);
1536 priv->status = 0;
1537
1538end:
1539 hdd_request_complete(hdd_request);
1540 hdd_request_put(hdd_request);
1541}
1542
1543static int
1544hdd_dcc_get_stats_send_reply(struct wiphy *wiphy,
1545 struct sir_dcc_get_stats_response *response)
1546{
1547 uint32_t nl_buf_len;
1548 struct sk_buff *nl_resp;
1549 int rc;
1550
1551 /* Allocate the buffer for the response. */
1552 nl_buf_len = NLMSG_HDRLEN;
1553 nl_buf_len += NLA_HDRLEN + sizeof(uint32_t);
1554 nl_buf_len += NLA_HDRLEN + response->channel_stats_array_len;
1555 nl_resp = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, nl_buf_len);
1556 if (!nl_resp) {
1557 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
1558 return -ENOMEM;
1559 }
1560
1561 /* Populate the response. */
1562 rc = nla_put_u32(nl_resp,
1563 QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_CHANNEL_COUNT,
1564 response->num_channels);
1565 if (rc)
1566 goto end;
1567 rc = nla_put(nl_resp,
1568 QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_STATS_ARRAY,
1569 response->channel_stats_array_len,
1570 response->channel_stats_array);
1571 if (rc)
1572 goto end;
1573
1574 /* Send the response. */
1575 rc = cfg80211_vendor_cmd_reply(nl_resp);
1576 nl_resp = NULL;
1577 if (rc) {
1578 hdd_err("cfg80211_vendor_cmd_reply failed: %d", rc);
1579 goto end;
1580 }
1581end:
1582 if (nl_resp)
1583 kfree_skb(nl_resp);
1584
1585 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001586}
1587
1588/**
1589 * __wlan_hdd_cfg80211_dcc_get_stats() - Interface for get dcc stats
1590 * @wiphy: pointer to the wiphy
1591 * @wdev: pointer to the wdev
1592 * @data: The netlink data
1593 * @data_len: The length of the netlink data in bytes
1594 *
1595 * Return: 0 on success.
1596 */
1597static int __wlan_hdd_cfg80211_dcc_get_stats(struct wiphy *wiphy,
1598 struct wireless_dev *wdev,
1599 const void *data,
1600 int data_len)
1601{
1602 uint32_t channel_count = 0;
1603 uint32_t request_array_len = 0;
1604 void *request_array = 0;
Jeff Johnson7106aba2017-08-28 11:49:07 -07001605 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001606 struct net_device *dev = wdev->netdev;
Jeff Johnson7a1688a2017-08-29 14:27:19 -07001607 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001608 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_MAX + 1];
Jeff Johnson7af334b2017-02-01 13:03:43 -08001609 int rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001610 struct sir_dcc_get_stats request = {0};
Jeff Johnson7af334b2017-02-01 13:03:43 -08001611 QDF_STATUS status;
1612 void *cookie;
1613 struct hdd_request *hdd_request;
1614 struct hdd_dcc_stats_priv *priv;
1615 static const struct hdd_request_params params = {
1616 .priv_size = sizeof(*priv),
1617 .timeout_ms = WLAN_WAIT_TIME_OCB_CMD,
1618 .dealloc = hdd_dcc_get_stats_dealloc,
1619 };
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001620
Jeff Johnson1f61b612016-02-12 16:28:33 -08001621 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001622
Jeff Johnson7af334b2017-02-01 13:03:43 -08001623 rc = wlan_hdd_validate_context(hdd_ctx);
1624 if (rc)
1625 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001626
Krunal Sonibe766b02016-03-10 13:00:44 -08001627 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001628 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001629 return -EINVAL;
1630 }
1631
1632 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001633 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634 return -EINVAL;
1635 }
1636
1637 /* Parse the netlink message */
Dustin Brown3fb15042017-08-15 15:54:49 -07001638 if (hdd_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_MAX, data,
1639 data_len, qca_wlan_vendor_dcc_get_stats)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001640 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001641 return -EINVAL;
1642 }
1643
1644 /* Validate all the parameters are present */
1645 if (!tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_CHANNEL_COUNT] ||
1646 !tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001647 hdd_err("Parameters are not present.");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001648 return -EINVAL;
1649 }
1650
1651 channel_count = nla_get_u32(
1652 tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_CHANNEL_COUNT]);
1653 request_array_len = nla_len(
1654 tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY]);
1655 request_array = nla_data(
1656 tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY]);
1657
Jeff Johnson7af334b2017-02-01 13:03:43 -08001658 hdd_request = hdd_request_alloc(&params);
1659 if (!hdd_request) {
1660 hdd_err("Request allocation failure");
1661 return -ENOMEM;
1662 }
1663 cookie = hdd_request_cookie(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001664
1665 request.vdev_id = adapter->sessionId;
1666 request.channel_count = channel_count;
1667 request.request_array_len = request_array_len;
1668 request.request_array = request_array;
1669
1670 /* Call the SME function. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001671 status = sme_dcc_get_stats(hdd_ctx->hHal, cookie,
1672 hdd_dcc_get_stats_callback,
1673 &request);
1674 if (QDF_IS_STATUS_ERROR(status)) {
1675 hdd_err("Error calling SME function.");
1676 rc = qdf_status_to_os_return(status);
1677 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001678 }
1679
1680 /* Wait for the function to complete. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001681 rc = hdd_request_wait_for_response(hdd_request);
1682 if (rc) {
1683 hdd_err("Operation timed out");
1684 goto end;
1685 }
1686
1687 priv = hdd_request_priv(hdd_request);
1688 rc = priv->status;
1689 if (rc) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001690 hdd_err("Operation failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001691 goto end;
1692 }
1693
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001694 /* Send the response. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001695 rc = hdd_dcc_get_stats_send_reply(wiphy, priv->response);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001696 if (rc) {
Jeff Johnson7af334b2017-02-01 13:03:43 -08001697 hdd_err("hdd_dcc_get_stats_send_reply failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001698 goto end;
1699 }
1700
1701 /* fall through */
1702end:
Jeff Johnson7af334b2017-02-01 13:03:43 -08001703 hdd_request_put(hdd_request);
1704
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001705 return rc;
1706}
1707
1708/**
1709 * wlan_hdd_cfg80211_dcc_get_stats() - Interface for get dcc stats
1710 * @wiphy: pointer to the wiphy
1711 * @wdev: pointer to the wdev
1712 * @data: The netlink data
1713 * @data_len: The length of the netlink data in bytes
1714 *
1715 * Return: 0 on success.
1716 */
1717int wlan_hdd_cfg80211_dcc_get_stats(struct wiphy *wiphy,
1718 struct wireless_dev *wdev,
1719 const void *data,
1720 int data_len)
1721{
1722 int ret;
1723
1724 cds_ssr_protect(__func__);
1725 ret = __wlan_hdd_cfg80211_dcc_get_stats(wiphy, wdev,
1726 data, data_len);
1727 cds_ssr_unprotect(__func__);
1728
1729 return ret;
1730}
1731
1732/**
1733 * __wlan_hdd_cfg80211_dcc_clear_stats() - Interface for clear dcc stats cmd
1734 * @wiphy: pointer to the wiphy
1735 * @wdev: pointer to the wdev
1736 * @data: The netlink data
1737 * @data_len: The length of the netlink data in bytes
1738 *
1739 * Return: 0 on success.
1740 */
1741static int __wlan_hdd_cfg80211_dcc_clear_stats(struct wiphy *wiphy,
1742 struct wireless_dev *wdev,
1743 const void *data,
1744 int data_len)
1745{
Jeff Johnson7106aba2017-08-28 11:49:07 -07001746 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001747 struct net_device *dev = wdev->netdev;
Jeff Johnson7a1688a2017-08-29 14:27:19 -07001748 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001749 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_MAX + 1];
1750
Jeff Johnson1f61b612016-02-12 16:28:33 -08001751 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001752
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301753 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001754 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001755
Krunal Sonibe766b02016-03-10 13:00:44 -08001756 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001757 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001758 return -EINVAL;
1759 }
1760
1761 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001762 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001763 return -EINVAL;
1764 }
1765
1766 /* Parse the netlink message */
Dustin Brown3fb15042017-08-15 15:54:49 -07001767 if (hdd_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_MAX, data,
1768 data_len, qca_wlan_vendor_dcc_clear_stats)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001769 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001770 return -EINVAL;
1771 }
1772
1773 /* Verify that the parameter is present */
1774 if (!tb[QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_BITMAP]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001775 hdd_err("Parameters are not present.");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001776 return -EINVAL;
1777 }
1778
1779 /* Call the SME function */
1780 if (sme_dcc_clear_stats(hdd_ctx->hHal, adapter->sessionId,
1781 nla_get_u32(
1782 tb[QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_BITMAP])) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301783 QDF_STATUS_SUCCESS) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001784 hdd_err("Error calling SME function.");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001785 return -EINVAL;
1786 }
1787
1788 return 0;
1789}
1790
1791/**
1792 * wlan_hdd_cfg80211_dcc_clear_stats() - Interface for clear dcc stats cmd
1793 * @wiphy: pointer to the wiphy
1794 * @wdev: pointer to the wdev
1795 * @data: The netlink data
1796 * @data_len: The length of the netlink data in bytes
1797 *
1798 * Return: 0 on success.
1799 */
1800int wlan_hdd_cfg80211_dcc_clear_stats(struct wiphy *wiphy,
1801 struct wireless_dev *wdev,
1802 const void *data,
1803 int data_len)
1804{
1805 int ret;
1806
1807 cds_ssr_protect(__func__);
1808 ret = __wlan_hdd_cfg80211_dcc_clear_stats(wiphy, wdev,
1809 data, data_len);
1810 cds_ssr_unprotect(__func__);
1811
1812 return ret;
1813}
1814
Jeff Johnson7af334b2017-02-01 13:03:43 -08001815struct hdd_dcc_update_ndl_priv {
1816 int status;
1817};
1818
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001819/**
1820 * hdd_dcc_update_ndl_callback() - Callback to update NDL command
1821 * @context_ptr: request context
1822 * @response_ptr: response data
1823 */
1824static void hdd_dcc_update_ndl_callback(void *context_ptr, void *response_ptr)
1825{
Jeff Johnson7af334b2017-02-01 13:03:43 -08001826 struct hdd_request *hdd_request;
1827 struct hdd_dcc_update_ndl_priv *priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001828 struct sir_dcc_update_ndl_response *response = response_ptr;
1829
Jeff Johnson7af334b2017-02-01 13:03:43 -08001830 hdd_request = hdd_request_get(context_ptr);
1831 if (!hdd_request) {
1832 hdd_err("Obsolete request");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001833 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001834 }
Jeff Johnson7af334b2017-02-01 13:03:43 -08001835 priv = hdd_request_priv(hdd_request);
1836 if (response && (0 == response->status)) {
1837 priv->status = 0;
1838 } else {
1839 priv->status = -EINVAL;
1840 }
1841 hdd_request_complete(hdd_request);
1842 hdd_request_put(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001843}
1844
1845/**
1846 * __wlan_hdd_cfg80211_dcc_update_ndl() - Interface for update dcc cmd
1847 * @wiphy: pointer to the wiphy
1848 * @wdev: pointer to the wdev
1849 * @data: The netlink data
1850 * @data_len: The length of the netlink data in bytes
1851 *
1852 * Return: 0 on success.
1853 */
1854static int __wlan_hdd_cfg80211_dcc_update_ndl(struct wiphy *wiphy,
1855 struct wireless_dev *wdev,
1856 const void *data,
1857 int data_len)
1858{
Jeff Johnson7106aba2017-08-28 11:49:07 -07001859 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001860 struct net_device *dev = wdev->netdev;
Jeff Johnson7a1688a2017-08-29 14:27:19 -07001861 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001862 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_MAX + 1];
1863 struct sir_dcc_update_ndl request;
1864 uint32_t channel_count;
1865 uint32_t ndl_channel_array_len;
1866 void *ndl_channel_array;
1867 uint32_t ndl_active_state_array_len;
1868 void *ndl_active_state_array;
Jeff Johnson7af334b2017-02-01 13:03:43 -08001869 int rc;
1870 QDF_STATUS status;
1871 void *cookie;
1872 struct hdd_request *hdd_request;
1873 struct hdd_dcc_update_ndl_priv *priv;
1874 static const struct hdd_request_params params = {
1875 .priv_size = sizeof(*priv),
1876 .timeout_ms = WLAN_WAIT_TIME_OCB_CMD,
1877 };
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001878
Jeff Johnson1f61b612016-02-12 16:28:33 -08001879 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001880
Jeff Johnson7af334b2017-02-01 13:03:43 -08001881 rc = wlan_hdd_validate_context(hdd_ctx);
1882 if (rc)
1883 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001884
Krunal Sonibe766b02016-03-10 13:00:44 -08001885 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001886 hdd_err("Device not in OCB mode!");
Jeff Johnson7af334b2017-02-01 13:03:43 -08001887 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001888 }
1889
1890 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001891 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001892 return -EINVAL;
1893 }
1894
1895 /* Parse the netlink message */
Dustin Brown3fb15042017-08-15 15:54:49 -07001896 if (hdd_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_MAX, data,
1897 data_len, qca_wlan_vendor_dcc_update_ndl)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001898 hdd_err("Invalid ATTR");
Jeff Johnson7af334b2017-02-01 13:03:43 -08001899 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900 }
1901
1902 /* Verify that the parameter is present */
1903 if (!tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_COUNT] ||
1904 !tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY] ||
1905 !tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001906 hdd_err("Parameters are not present.");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001907 return -EINVAL;
1908 }
1909
1910 channel_count = nla_get_u32(
1911 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_COUNT]);
1912 ndl_channel_array_len = nla_len(
1913 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY]);
1914 ndl_channel_array = nla_data(
1915 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY]);
1916 ndl_active_state_array_len = nla_len(
1917 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY]);
1918 ndl_active_state_array = nla_data(
1919 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY]);
1920
Jeff Johnson7af334b2017-02-01 13:03:43 -08001921 hdd_request = hdd_request_alloc(&params);
1922 if (!hdd_request) {
1923 hdd_err("Request allocation failure");
1924 return -ENOMEM;
1925 }
1926 cookie = hdd_request_cookie(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001927
1928 /* Copy the parameters to the request structure. */
1929 request.vdev_id = adapter->sessionId;
1930 request.channel_count = channel_count;
1931 request.dcc_ndl_chan_list_len = ndl_channel_array_len;
1932 request.dcc_ndl_chan_list = ndl_channel_array;
1933 request.dcc_ndl_active_state_list_len = ndl_active_state_array_len;
1934 request.dcc_ndl_active_state_list = ndl_active_state_array;
1935
1936 /* Call the SME function */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001937 status = sme_dcc_update_ndl(hdd_ctx->hHal, cookie,
1938 hdd_dcc_update_ndl_callback,
1939 &request);
1940 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001941 hdd_err("Error calling SME function.");
Jeff Johnson7af334b2017-02-01 13:03:43 -08001942 rc = qdf_status_to_os_return(status);
1943 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001944 }
1945
1946 /* Wait for the function to complete. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001947 rc = hdd_request_wait_for_response(hdd_request);
1948 if (rc) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001949 hdd_err("Operation timed out");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001950 goto end;
1951 }
1952
Jeff Johnson7af334b2017-02-01 13:03:43 -08001953 priv = hdd_request_priv(hdd_request);
1954 rc = priv->status;
1955 if (rc) {
1956 hdd_err("Operation failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001957 goto end;
1958 }
1959
1960 /* fall through */
1961end:
Jeff Johnson7af334b2017-02-01 13:03:43 -08001962 hdd_request_put(hdd_request);
1963
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001964 return rc;
1965}
1966
1967/**
1968 * wlan_hdd_cfg80211_dcc_update_ndl() - Interface for update dcc cmd
1969 * @wiphy: pointer to the wiphy
1970 * @wdev: pointer to the wdev
1971 * @data: The netlink data
1972 * @data_len: The length of the netlink data in bytes
1973 *
1974 * Return: 0 on success.
1975 */
1976int wlan_hdd_cfg80211_dcc_update_ndl(struct wiphy *wiphy,
1977 struct wireless_dev *wdev,
1978 const void *data,
1979 int data_len)
1980{
1981 int ret;
1982
1983 cds_ssr_protect(__func__);
1984 ret = __wlan_hdd_cfg80211_dcc_update_ndl(wiphy, wdev,
1985 data, data_len);
1986 cds_ssr_unprotect(__func__);
1987
1988 return ret;
1989}
1990
1991/**
1992 * wlan_hdd_dcc_stats_event_callback() - Callback to get stats event
1993 * @context_ptr: request context
1994 * @response_ptr: response data
1995 */
1996static void wlan_hdd_dcc_stats_event_callback(void *context_ptr,
1997 void *response_ptr)
1998{
Jeff Johnson7106aba2017-08-28 11:49:07 -07001999 struct hdd_context *hdd_ctx = (struct hdd_context *)context_ptr;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002000 struct sir_dcc_get_stats_response *resp = response_ptr;
2001 struct sk_buff *vendor_event;
2002
2003 ENTER();
2004
2005 vendor_event =
2006 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
2007 NULL, sizeof(uint32_t) + resp->channel_stats_array_len +
2008 NLMSG_HDRLEN,
2009 QCA_NL80211_VENDOR_SUBCMD_DCC_STATS_EVENT_INDEX,
2010 GFP_KERNEL);
2011
2012 if (!vendor_event) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07002013 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002014 return;
2015 }
2016
2017 if (nla_put_u32(vendor_event,
2018 QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_CHANNEL_COUNT,
2019 resp->num_channels) ||
2020 nla_put(vendor_event,
2021 QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_STATS_ARRAY,
2022 resp->channel_stats_array_len,
2023 resp->channel_stats_array)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07002024 hdd_err("nla put failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002025 kfree_skb(vendor_event);
2026 return;
2027 }
2028
2029 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
2030}
2031
2032/**
2033 * wlan_hdd_dcc_register_for_dcc_stats_event() - Register for dcc stats events
2034 * @hdd_ctx: hdd context
2035 */
Jeff Johnson7106aba2017-08-28 11:49:07 -07002036void wlan_hdd_dcc_register_for_dcc_stats_event(struct hdd_context *hdd_ctx)
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002037{
2038 int rc;
2039
2040 rc = sme_register_for_dcc_stats_event(hdd_ctx->hHal, hdd_ctx,
Arun Khandavalli4b55da72016-07-19 19:55:01 +05302041 wlan_hdd_dcc_stats_event_callback);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002042 if (rc)
Jeff Johnson5f735d52016-07-06 15:14:45 -07002043 hdd_err("Register callback failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002044}