blob: dce49180c5a76eb4ada797acb6a396078a371026 [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 */
63void hdd_set_dot11p_config(hdd_context_t *hdd_ctx)
64{
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 */
198static int hdd_ocb_validate_config(hdd_adapter_t *adapter,
199 struct sir_ocb_config *config)
200{
201 int i;
202 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
203
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 */
231static int hdd_ocb_register_sta(hdd_adapter_t *adapter)
232{
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};
235 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
236 hdd_station_ctx_t *pHddStaCtx = WLAN_HDD_GET_STATION_CTX_PTR(adapter);
237 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
Leo Changfdb45c32016-10-28 11:09:23 -0700242 qdf_status = cdp_peer_register_ocb_peer(soc, hdd_ctx->pcds_context,
243 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
Naveen Rawatac027cb2017-04-27 15:02:42 -0700272 if (pHddStaCtx->conn_info.staId[0] != HDD_WLAN_INVALID_STA_ID &&
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800273 pHddStaCtx->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
277 pHddStaCtx->conn_info.staId[0] = peer_id;
Anurag Chouhanc5548422016-02-24 18:33:27 +0530278 qdf_copy_macaddr(&pHddStaCtx->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 */
386static int hdd_ocb_set_config_req(hdd_adapter_t *adapter,
387 struct sir_ocb_config *config)
388{
389 int rc;
Jeff Johnson7af334b2017-02-01 13:03:43 -0800390 QDF_STATUS status;
391 hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
392 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
Srinivas Girigowda6598eea2017-07-06 19:26:19 -0700412 hdd_info("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 Johnson441e1f72017-02-07 08:50:49 -0800472 hdd_context_t *hdd_ctx;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800473 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
474 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 Johnson441e1f72017-02-07 08:50:49 -0800481 hdd_ctx = WLAN_HDD_GET_CTX(pAdapter);
482 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++) {
510 wlan_hdd_release_intf_addr(adapter->pHddCtx,
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 {
542 mac_addr = wlan_hdd_get_intf_addr(adapter->pHddCtx);
543 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{
775 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
776 struct net_device *dev = wdev->netdev;
777 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
778 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 */
803 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_MAX,
804 data,
805 data_len, qca_wlan_vendor_ocb_set_config_policy)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700806 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800807 return -EINVAL;
808 }
809
810 /* Get the number of channels in the schedule */
811 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_COUNT]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700812 hdd_err("CHANNEL_COUNT is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800813 return -EINVAL;
814 }
815 channel_count = nla_get_u32(
816 tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_COUNT]);
817
818 /* Get the size of the channel schedule */
819 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_SCHEDULE_SIZE]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700820 hdd_err("SCHEDULE_SIZE is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800821 return -EINVAL;
822 }
823 schedule_size = nla_get_u32(
824 tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_SCHEDULE_SIZE]);
825
826 /* Get the ndl chan array and the ndl active state array. */
SaidiReddy Yenuga3db38772017-03-28 15:18:56 +0530827 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_CHANNEL_ARRAY]) {
828 hdd_err("NDL_CHANNEL_ARRAY is not present");
829 return -EINVAL;
830 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800831 ndl_chan_list =
832 tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_CHANNEL_ARRAY];
833 ndl_chan_list_len = (ndl_chan_list ? nla_len(ndl_chan_list) : 0);
834
SaidiReddy Yenuga3db38772017-03-28 15:18:56 +0530835 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_ACTIVE_STATE_ARRAY]) {
836 hdd_err("NDL_ACTIVE_STATE_ARRAY is not present");
837 return -EINVAL;
838 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800839 ndl_active_state_list =
840 tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_ACTIVE_STATE_ARRAY];
841 ndl_active_state_list_len = (ndl_active_state_list ?
842 nla_len(ndl_active_state_list) : 0);
843
844 /* Get the flags */
845 if (tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_FLAGS])
846 flags = nla_get_u32(tb[
847 QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_FLAGS]);
848
849 config = hdd_ocb_config_new(channel_count, schedule_size,
850 ndl_chan_list_len,
851 ndl_active_state_list_len);
852 if (config == NULL) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700853 hdd_err("Failed to allocate memory!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800854 return -ENOMEM;
855 }
856
857 config->channel_count = channel_count;
858 config->schedule_size = schedule_size;
859 config->flags = flags;
860
861 /* Read the channel array */
SaidiReddy Yenuga3db38772017-03-28 15:18:56 +0530862 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_ARRAY]) {
863 hdd_err("CHANNEL_ARRAY is not present");
864 return -EINVAL;
865 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800866 channel_array = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_ARRAY];
867 if (!channel_array) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700868 hdd_err("No channel present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800869 goto fail;
870 }
871 if (nla_len(channel_array) != channel_count *
872 sizeof(struct wlan_hdd_ocb_config_channel)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700873 hdd_err("CHANNEL_ARRAY is not the correct size");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800874 goto fail;
875 }
876 wlan_hdd_ocb_config_channel_to_sir_ocb_config_channel(
877 config->channels, nla_data(channel_array), channel_count);
878
879 /* Identify the vdev interface */
880 config->session_id = adapter->sessionId;
881
882 /* Release all the mac addresses used for OCB */
883 for (i = 0; i < adapter->ocb_mac_addr_count; i++) {
884 wlan_hdd_release_intf_addr(adapter->pHddCtx,
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800885 adapter->ocb_mac_address[i].bytes);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800886 }
887 adapter->ocb_mac_addr_count = 0;
888
889 /*
890 * Setup locally administered mac addresses for each channel.
891 * First channel uses the adapter's address.
892 */
893 for (i = 0; i < config->channel_count; i++) {
894 if (i == 0) {
Anurag Chouhanc5548422016-02-24 18:33:27 +0530895 qdf_copy_macaddr(&config->channels[i].mac_address,
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800896 &adapter->macAddressCurrent);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800897 } else {
898 mac_addr = wlan_hdd_get_intf_addr(adapter->pHddCtx);
899 if (mac_addr == NULL) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700900 hdd_err("Cannot obtain mac address");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800901 goto fail;
902 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530903 qdf_mem_copy(config->channels[i].mac_address.bytes,
Anurag Chouhan6d760662016-02-20 16:05:43 +0530904 mac_addr, QDF_MAC_ADDR_SIZE);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800905 /* Save the mac address to release later */
Anurag Chouhanc5548422016-02-24 18:33:27 +0530906 qdf_copy_macaddr(&adapter->ocb_mac_address[
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800907 adapter->ocb_mac_addr_count],
Srinivas Girigowda117e7fb2015-11-16 12:33:45 -0800908 &config->channels[i].mac_address);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800909 adapter->ocb_mac_addr_count++;
910 }
911 }
912
913 /* Read the schedule array */
914 sched_array = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_SCHEDULE_ARRAY];
915 if (!sched_array) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700916 hdd_err("No channel present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800917 goto fail;
918 }
919 if (nla_len(sched_array) != schedule_size * sizeof(*config->schedule)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -0700920 hdd_err("SCHEDULE_ARRAY is not the correct size");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800921 goto fail;
922 }
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530923 qdf_mem_copy(config->schedule, nla_data(sched_array),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800924 nla_len(sched_array));
925
926 /* Copy the NDL chan array */
927 if (ndl_chan_list_len) {
928 config->dcc_ndl_chan_list_len = ndl_chan_list_len;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530929 qdf_mem_copy(config->dcc_ndl_chan_list, nla_data(ndl_chan_list),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800930 nla_len(ndl_chan_list));
931 }
932
933 /* Copy the NDL active state array */
934 if (ndl_active_state_list_len) {
935 config->dcc_ndl_active_state_list_len =
936 ndl_active_state_list_len;
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530937 qdf_mem_copy(config->dcc_ndl_active_state_list,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800938 nla_data(ndl_active_state_list),
939 nla_len(ndl_active_state_list));
940 }
941
942 rc = hdd_ocb_set_config_req(adapter, config);
943 if (rc)
Jeff Johnson5f735d52016-07-06 15:14:45 -0700944 hdd_err("Error while setting OCB config: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800945
946fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +0530947 qdf_mem_free(config);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800948 return rc;
949}
950
951/**
952 * wlan_hdd_cfg80211_ocb_set_config() - Interface for set config command
953 * @wiphy: pointer to the wiphy
954 * @wdev: pointer to the wdev
955 * @data: The netlink data
956 * @data_len: The length of the netlink data in bytes
957 *
958 * Return: 0 on success.
959 */
960int wlan_hdd_cfg80211_ocb_set_config(struct wiphy *wiphy,
961 struct wireless_dev *wdev,
962 const void *data,
963 int data_len)
964{
965 int ret;
966
967 cds_ssr_protect(__func__);
968 ret = __wlan_hdd_cfg80211_ocb_set_config(wiphy, wdev, data, data_len);
969 cds_ssr_unprotect(__func__);
970
971 return ret;
972}
973
974/**
975 * __wlan_hdd_cfg80211_ocb_set_utc_time() - Interface for set UTC time command
976 * @wiphy: pointer to the wiphy
977 * @wdev: pointer to the wdev
978 * @data: The netlink data
979 * @data_len: The length of the netlink data in bytes
980 *
981 * Return: 0 on success.
982 */
983static int __wlan_hdd_cfg80211_ocb_set_utc_time(struct wiphy *wiphy,
984 struct wireless_dev *wdev,
985 const void *data,
986 int data_len)
987{
988 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
989 struct net_device *dev = wdev->netdev;
990 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
991 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_MAX + 1];
992 struct nlattr *utc_attr;
993 struct nlattr *time_error_attr;
994 struct sir_ocb_utc *utc;
995 int rc = -EINVAL;
996
Jeff Johnson1f61b612016-02-12 16:28:33 -0800997 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -0800998
Abhishek Singh23edd1c2016-05-05 11:56:06 +0530999 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001000 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001001
Krunal Sonibe766b02016-03-10 13:00:44 -08001002 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001003 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001004 return -EINVAL;
1005 }
1006
1007 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001008 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001009 return -EINVAL;
1010 }
1011
1012 /* Parse the netlink message */
1013 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_MAX,
1014 data,
1015 data_len, qca_wlan_vendor_ocb_set_utc_time_policy)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001016 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001017 return -EINVAL;
1018 }
1019
1020 /* Read the UTC time */
1021 utc_attr = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_VALUE];
1022 if (!utc_attr) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001023 hdd_err("UTC_TIME is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001024 return -EINVAL;
1025 }
1026 if (nla_len(utc_attr) != SIZE_UTC_TIME) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001027 hdd_err("UTC_TIME is not the correct size");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001028 return -EINVAL;
1029 }
1030
1031 /* Read the time error */
1032 time_error_attr = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_ERROR];
1033 if (!time_error_attr) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001034 hdd_err("UTC_TIME is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001035 return -EINVAL;
1036 }
1037 if (nla_len(time_error_attr) != SIZE_UTC_TIME_ERROR) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001038 hdd_err("UTC_TIME is not the correct size");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001039 return -EINVAL;
1040 }
1041
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301042 utc = qdf_mem_malloc(sizeof(*utc));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001043 if (!utc) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001044 hdd_err("qdf_mem_malloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001045 return -ENOMEM;
1046 }
1047 utc->vdev_id = adapter->sessionId;
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301048 qdf_mem_copy(utc->utc_time, nla_data(utc_attr), SIZE_UTC_TIME);
1049 qdf_mem_copy(utc->time_error, nla_data(time_error_attr),
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001050 SIZE_UTC_TIME_ERROR);
1051
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301052 if (sme_ocb_set_utc_time(hdd_ctx->hHal, utc) != QDF_STATUS_SUCCESS) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001053 hdd_err("Error while setting UTC time");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001054 rc = -EINVAL;
1055 } else {
1056 rc = 0;
1057 }
1058
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301059 qdf_mem_free(utc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001060 return rc;
1061}
1062
1063/**
1064 * wlan_hdd_cfg80211_ocb_set_utc_time() - Interface for the set UTC time command
1065 * @wiphy: pointer to the wiphy
1066 * @wdev: pointer to the wdev
1067 * @data: The netlink data
1068 * @data_len: The length of the netlink data in bytes
1069 *
1070 * Return: 0 on success.
1071 */
1072int wlan_hdd_cfg80211_ocb_set_utc_time(struct wiphy *wiphy,
1073 struct wireless_dev *wdev,
1074 const void *data,
1075 int data_len)
1076{
1077 int ret;
1078
1079 cds_ssr_protect(__func__);
1080 ret = __wlan_hdd_cfg80211_ocb_set_utc_time(wiphy, wdev, data, data_len);
1081 cds_ssr_unprotect(__func__);
1082
1083 return ret;
1084}
1085
1086/**
1087 * __wlan_hdd_cfg80211_ocb_start_timing_advert() - Interface for start TA cmd
1088 * @wiphy: pointer to the wiphy
1089 * @wdev: pointer to the wdev
1090 * @data: The netlink data
1091 * @data_len: The length of the netlink data in bytes
1092 *
1093 * Return: 0 on success.
1094 */
1095static int
1096__wlan_hdd_cfg80211_ocb_start_timing_advert(struct wiphy *wiphy,
1097 struct wireless_dev *wdev,
1098 const void *data,
1099 int data_len)
1100{
1101 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1102 struct net_device *dev = wdev->netdev;
1103 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001104 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_MAX + 1];
1105 struct sir_ocb_timing_advert *timing_advert;
1106 int rc = -EINVAL;
1107
Jeff Johnson1f61b612016-02-12 16:28:33 -08001108 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001109
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301110 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001111 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001112
Krunal Sonibe766b02016-03-10 13:00:44 -08001113 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001114 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001115 return -EINVAL;
1116 }
1117
1118 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001119 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001120 return -EINVAL;
1121 }
1122
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301123 timing_advert = qdf_mem_malloc(sizeof(*timing_advert));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001124 if (!timing_advert) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001125 hdd_err("qdf_mem_malloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001126 return -ENOMEM;
1127 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001128 timing_advert->vdev_id = adapter->sessionId;
1129
1130 /* Parse the netlink message */
1131 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_MAX,
1132 data,
1133 data_len,
1134 qca_wlan_vendor_ocb_start_timing_advert_policy)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001135 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001136 goto fail;
1137 }
1138
1139 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_CHANNEL_FREQ]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001140 hdd_err("CHANNEL_FREQ is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001141 goto fail;
1142 }
1143 timing_advert->chan_freq = nla_get_u32(
1144 tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_CHANNEL_FREQ]);
1145
1146 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_REPEAT_RATE]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001147 hdd_err("REPEAT_RATE is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001148 goto fail;
1149 }
1150 timing_advert->repeat_rate = nla_get_u32(
1151 tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_REPEAT_RATE]);
1152
1153 timing_advert->template_length =
Naveen Rawatb4d37622015-11-13 16:15:25 -08001154 sme_ocb_gen_timing_advert_frame(hdd_ctx->hHal,
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001155 *(tSirMacAddr *)&adapter->macAddressCurrent.bytes,
1156 &timing_advert->template_value,
1157 &timing_advert->timestamp_offset,
1158 &timing_advert->time_value_offset);
1159 if (timing_advert->template_length <= 0) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001160 hdd_err("Error while generating the TA frame");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001161 goto fail;
1162 }
1163
1164 if (sme_ocb_start_timing_advert(hdd_ctx->hHal, timing_advert) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301165 QDF_STATUS_SUCCESS) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001166 hdd_err("Error while starting timing advert");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001167 rc = -EINVAL;
1168 } else {
1169 rc = 0;
1170 }
1171
1172fail:
1173 if (timing_advert->template_value)
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301174 qdf_mem_free(timing_advert->template_value);
1175 qdf_mem_free(timing_advert);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001176 return rc;
1177}
1178
1179/**
1180 * wlan_hdd_cfg80211_ocb_start_timing_advert() - Interface for the start TA cmd
1181 * @wiphy: pointer to the wiphy
1182 * @wdev: pointer to the wdev
1183 * @data: The netlink data
1184 * @data_len: The length of the netlink data in bytes
1185 *
1186 * Return: 0 on success.
1187 */
1188int wlan_hdd_cfg80211_ocb_start_timing_advert(struct wiphy *wiphy,
1189 struct wireless_dev *wdev,
1190 const void *data,
1191 int data_len)
1192{
1193 int ret;
1194
1195 cds_ssr_protect(__func__);
1196 ret = __wlan_hdd_cfg80211_ocb_start_timing_advert(wiphy, wdev,
1197 data, data_len);
1198 cds_ssr_unprotect(__func__);
1199
1200 return ret;
1201}
1202
1203/**
1204 * __wlan_hdd_cfg80211_ocb_stop_timing_advert() - Interface for the stop TA cmd
1205 * @wiphy: pointer to the wiphy
1206 * @wdev: pointer to the wdev
1207 * @data: The netlink data
1208 * @data_len: The length of the netlink data in bytes
1209 *
1210 * Return: 0 on success.
1211 */
1212static int
1213__wlan_hdd_cfg80211_ocb_stop_timing_advert(struct wiphy *wiphy,
1214 struct wireless_dev *wdev,
1215 const void *data,
1216 int data_len)
1217{
1218 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1219 struct net_device *dev = wdev->netdev;
1220 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1221 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_MAX + 1];
1222 struct sir_ocb_timing_advert *timing_advert;
1223 int rc = -EINVAL;
1224
Jeff Johnson1f61b612016-02-12 16:28:33 -08001225 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001226
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301227 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001228 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001229
Krunal Sonibe766b02016-03-10 13:00:44 -08001230 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001231 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001232 return -EINVAL;
1233 }
1234
1235 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001236 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001237 return -EINVAL;
1238 }
1239
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301240 timing_advert = qdf_mem_malloc(sizeof(*timing_advert));
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001241 if (!timing_advert) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001242 hdd_err("qdf_mem_malloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001243 return -ENOMEM;
1244 }
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001245 timing_advert->vdev_id = adapter->sessionId;
1246
1247 /* Parse the netlink message */
1248 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_MAX,
1249 data,
1250 data_len,
1251 qca_wlan_vendor_ocb_stop_timing_advert_policy)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001252 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001253 goto fail;
1254 }
1255
1256 if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_CHANNEL_FREQ]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001257 hdd_err("CHANNEL_FREQ is not present");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001258 goto fail;
1259 }
1260 timing_advert->chan_freq = nla_get_u32(
1261 tb[QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_CHANNEL_FREQ]);
1262
1263 if (sme_ocb_stop_timing_advert(hdd_ctx->hHal, timing_advert) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301264 QDF_STATUS_SUCCESS) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001265 hdd_err("Error while stopping timing advert");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001266 rc = -EINVAL;
1267 } else {
1268 rc = 0;
1269 }
1270
1271fail:
Anurag Chouhan600c3a02016-03-01 10:33:54 +05301272 qdf_mem_free(timing_advert);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001273 return rc;
1274}
1275
1276/**
1277 * wlan_hdd_cfg80211_ocb_stop_timing_advert() - Interface for the stop TA cmd
1278 * @wiphy: pointer to the wiphy
1279 * @wdev: pointer to the wdev
1280 * @data: The netlink data
1281 * @data_len: The length of the netlink data in bytes
1282 *
1283 * Return: 0 on success.
1284 */
1285int wlan_hdd_cfg80211_ocb_stop_timing_advert(struct wiphy *wiphy,
1286 struct wireless_dev *wdev,
1287 const void *data,
1288 int data_len)
1289{
1290 int ret;
1291
1292 cds_ssr_protect(__func__);
1293 ret = __wlan_hdd_cfg80211_ocb_stop_timing_advert(wiphy, wdev,
1294 data, data_len);
1295 cds_ssr_unprotect(__func__);
1296
1297 return ret;
1298}
1299
Jeff Johnson7af334b2017-02-01 13:03:43 -08001300struct hdd_ocb_get_tsf_timer_priv {
1301 struct sir_ocb_get_tsf_timer_response response;
1302 int status;
1303};
1304
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001305/**
1306 * hdd_ocb_get_tsf_timer_callback() - Callback to get TSF command
1307 * @context_ptr: request context
1308 * @response_ptr: response data
1309 */
1310static void hdd_ocb_get_tsf_timer_callback(void *context_ptr,
1311 void *response_ptr)
1312{
Jeff Johnson7af334b2017-02-01 13:03:43 -08001313 struct hdd_request *hdd_request;
1314 struct hdd_ocb_get_tsf_timer_priv *priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001315 struct sir_ocb_get_tsf_timer_response *response = response_ptr;
1316
Jeff Johnson7af334b2017-02-01 13:03:43 -08001317 hdd_request = hdd_request_get(context_ptr);
1318 if (!hdd_request) {
1319 hdd_err("Obsolete request");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001320 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001321 }
Jeff Johnson7af334b2017-02-01 13:03:43 -08001322
1323 if (response) {
1324 priv->response = *response;
1325 priv->status = 0;
1326 } else {
1327 priv->status = -EINVAL;
1328 }
1329 hdd_request_complete(hdd_request);
1330 hdd_request_put(hdd_request);
1331}
1332
1333static int
1334hdd_ocb_get_tsf_timer_reply(struct wiphy *wiphy,
1335 struct sir_ocb_get_tsf_timer_response *response)
1336{
1337 uint32_t nl_buf_len;
1338 struct sk_buff *nl_resp;
1339 int rc;
1340
1341 /* Allocate the buffer for the response. */
1342 nl_buf_len = NLMSG_HDRLEN;
1343 nl_buf_len += 2 * (NLA_HDRLEN + sizeof(uint32_t));
1344 nl_resp = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, nl_buf_len);
1345 if (!nl_resp) {
1346 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
1347 return -ENOMEM;
1348 }
1349
1350 /* Populate the response. */
1351 rc = nla_put_u32(nl_resp,
1352 QCA_WLAN_VENDOR_ATTR_OCB_GET_TSF_RESP_TIMER_HIGH,
1353 response->timer_high);
1354 if (rc)
1355 goto end;
1356 rc = nla_put_u32(nl_resp,
1357 QCA_WLAN_VENDOR_ATTR_OCB_GET_TSF_RESP_TIMER_LOW,
1358 response->timer_low);
1359 if (rc)
1360 goto end;
1361
1362 /* Send the response. */
1363 rc = cfg80211_vendor_cmd_reply(nl_resp);
1364 nl_resp = NULL;
1365 if (rc) {
1366 hdd_err("cfg80211_vendor_cmd_reply failed: %d", rc);
1367 goto end;
1368 }
1369end:
1370 if (nl_resp)
1371 kfree_skb(nl_resp);
1372
1373 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001374}
1375
1376/**
1377 * __wlan_hdd_cfg80211_ocb_get_tsf_timer() - Interface for get TSF timer cmd
1378 * @wiphy: pointer to the wiphy
1379 * @wdev: pointer to the wdev
1380 * @data: The netlink data
1381 * @data_len: The length of the netlink data in bytes
1382 *
1383 * Return: 0 on success.
1384 */
1385static int
1386__wlan_hdd_cfg80211_ocb_get_tsf_timer(struct wiphy *wiphy,
1387 struct wireless_dev *wdev,
1388 const void *data,
1389 int data_len)
1390{
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001391 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1392 struct net_device *dev = wdev->netdev;
1393 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
Jeff Johnson7af334b2017-02-01 13:03:43 -08001394 int rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001395 struct sir_ocb_get_tsf_timer request = {0};
Jeff Johnson7af334b2017-02-01 13:03:43 -08001396 QDF_STATUS status;
1397 void *cookie;
1398 struct hdd_request *hdd_request;
1399 struct hdd_ocb_get_tsf_timer_priv *priv;
1400 static const struct hdd_request_params params = {
1401 .priv_size = sizeof(*priv),
1402 .timeout_ms = WLAN_WAIT_TIME_OCB_CMD,
1403 };
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001404
Jeff Johnson1f61b612016-02-12 16:28:33 -08001405 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001406
Jeff Johnson7af334b2017-02-01 13:03:43 -08001407 rc = wlan_hdd_validate_context(hdd_ctx);
1408 if (rc)
1409 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001410
Krunal Sonibe766b02016-03-10 13:00:44 -08001411 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001412 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001413 return -EINVAL;
1414 }
1415
1416 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001417 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001418 return -EINVAL;
1419 }
1420
Jeff Johnson7af334b2017-02-01 13:03:43 -08001421 hdd_request = hdd_request_alloc(&params);
1422 if (!hdd_request) {
1423 hdd_err("Request allocation failure");
1424 return -ENOMEM;
1425 }
1426 cookie = hdd_request_cookie(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001427
1428 request.vdev_id = adapter->sessionId;
1429 /* Call the SME function */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001430 status = sme_ocb_get_tsf_timer(hdd_ctx->hHal, cookie,
1431 hdd_ocb_get_tsf_timer_callback,
1432 &request);
1433 if (QDF_IS_STATUS_ERROR(status)) {
1434 hdd_err("Error calling SME function.");
1435 rc = qdf_status_to_os_return(status);
1436 goto end;
1437 }
1438
1439 rc = hdd_request_wait_for_response(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001440 if (rc) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001441 hdd_err("Operation timed out");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001442 goto end;
1443 }
1444
Jeff Johnson7af334b2017-02-01 13:03:43 -08001445 priv = hdd_request_priv(hdd_request);
1446 rc = priv->status;
1447 if (rc) {
1448 hdd_err("Operation failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001449 goto end;
1450 }
1451
Jeff Johnson5f735d52016-07-06 15:14:45 -07001452 hdd_err("Got TSF timer response, high=%d, low=%d",
Jeff Johnson7af334b2017-02-01 13:03:43 -08001453 priv->response.timer_high,
1454 priv->response.timer_low);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001455
1456 /* Send the response. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001457 rc = hdd_ocb_get_tsf_timer_reply(wiphy, &priv->response);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001458 if (rc) {
Jeff Johnson7af334b2017-02-01 13:03:43 -08001459 hdd_err("hdd_ocb_get_tsf_timer_reply failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001460 goto end;
1461 }
1462
Jeff Johnson7af334b2017-02-01 13:03:43 -08001463 /* fall through */
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001464end:
Jeff Johnson7af334b2017-02-01 13:03:43 -08001465 hdd_request_put(hdd_request);
1466
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001467 return rc;
1468}
1469
1470/**
1471 * wlan_hdd_cfg80211_ocb_get_tsf_timer() - Interface for get TSF timer cmd
1472 * @wiphy: pointer to the wiphy
1473 * @wdev: pointer to the wdev
1474 * @data: The netlink data
1475 * @data_len: The length of the netlink data in bytes
1476 *
1477 * Return: 0 on success.
1478 */
1479int wlan_hdd_cfg80211_ocb_get_tsf_timer(struct wiphy *wiphy,
1480 struct wireless_dev *wdev,
1481 const void *data,
1482 int data_len)
1483{
1484 int ret;
1485
1486 cds_ssr_protect(__func__);
1487 ret = __wlan_hdd_cfg80211_ocb_get_tsf_timer(wiphy, wdev,
1488 data, data_len);
1489 cds_ssr_unprotect(__func__);
1490
1491 return ret;
1492}
1493
Jeff Johnson7af334b2017-02-01 13:03:43 -08001494struct hdd_dcc_stats_priv {
1495 struct sir_dcc_get_stats_response *response;
1496 int status;
1497};
1498
1499static void hdd_dcc_get_stats_dealloc(void *context_ptr)
1500{
1501 struct hdd_dcc_stats_priv *priv = context_ptr;
1502
1503 qdf_mem_free(priv->response);
1504 priv->response = NULL;
1505}
1506
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001507/**
1508 * hdd_dcc_get_stats_callback() - Callback to get stats command
1509 * @context_ptr: request context
1510 * @response_ptr: response data
1511 */
1512static void hdd_dcc_get_stats_callback(void *context_ptr, void *response_ptr)
1513{
Jeff Johnson7af334b2017-02-01 13:03:43 -08001514 struct hdd_request *hdd_request;
1515 struct hdd_dcc_stats_priv *priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001516 struct sir_dcc_get_stats_response *response = response_ptr;
1517 struct sir_dcc_get_stats_response *hdd_resp;
1518
Jeff Johnson7af334b2017-02-01 13:03:43 -08001519 hdd_request = hdd_request_get(context_ptr);
1520 if (!hdd_request) {
1521 hdd_err("Obsolete request");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001522 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001523 }
Jeff Johnson7af334b2017-02-01 13:03:43 -08001524
1525 priv = hdd_request_priv(hdd_request);
1526 if (!response) {
1527 priv->status = -EINVAL;
1528 goto end;
1529 }
1530
1531 priv->response = qdf_mem_malloc(sizeof(*response) +
1532 response->channel_stats_array_len);
1533 if (!priv->response) {
1534 priv->status = -ENOMEM;
1535 goto end;
1536 }
1537
1538 hdd_resp = priv->response;
1539 *hdd_resp = *response;
1540 hdd_resp->channel_stats_array = (void *)hdd_resp + sizeof(*hdd_resp);
1541 qdf_mem_copy(hdd_resp->channel_stats_array,
1542 response->channel_stats_array,
1543 response->channel_stats_array_len);
1544 priv->status = 0;
1545
1546end:
1547 hdd_request_complete(hdd_request);
1548 hdd_request_put(hdd_request);
1549}
1550
1551static int
1552hdd_dcc_get_stats_send_reply(struct wiphy *wiphy,
1553 struct sir_dcc_get_stats_response *response)
1554{
1555 uint32_t nl_buf_len;
1556 struct sk_buff *nl_resp;
1557 int rc;
1558
1559 /* Allocate the buffer for the response. */
1560 nl_buf_len = NLMSG_HDRLEN;
1561 nl_buf_len += NLA_HDRLEN + sizeof(uint32_t);
1562 nl_buf_len += NLA_HDRLEN + response->channel_stats_array_len;
1563 nl_resp = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, nl_buf_len);
1564 if (!nl_resp) {
1565 hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed");
1566 return -ENOMEM;
1567 }
1568
1569 /* Populate the response. */
1570 rc = nla_put_u32(nl_resp,
1571 QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_CHANNEL_COUNT,
1572 response->num_channels);
1573 if (rc)
1574 goto end;
1575 rc = nla_put(nl_resp,
1576 QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_STATS_ARRAY,
1577 response->channel_stats_array_len,
1578 response->channel_stats_array);
1579 if (rc)
1580 goto end;
1581
1582 /* Send the response. */
1583 rc = cfg80211_vendor_cmd_reply(nl_resp);
1584 nl_resp = NULL;
1585 if (rc) {
1586 hdd_err("cfg80211_vendor_cmd_reply failed: %d", rc);
1587 goto end;
1588 }
1589end:
1590 if (nl_resp)
1591 kfree_skb(nl_resp);
1592
1593 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001594}
1595
1596/**
1597 * __wlan_hdd_cfg80211_dcc_get_stats() - Interface for get dcc stats
1598 * @wiphy: pointer to the wiphy
1599 * @wdev: pointer to the wdev
1600 * @data: The netlink data
1601 * @data_len: The length of the netlink data in bytes
1602 *
1603 * Return: 0 on success.
1604 */
1605static int __wlan_hdd_cfg80211_dcc_get_stats(struct wiphy *wiphy,
1606 struct wireless_dev *wdev,
1607 const void *data,
1608 int data_len)
1609{
1610 uint32_t channel_count = 0;
1611 uint32_t request_array_len = 0;
1612 void *request_array = 0;
1613 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1614 struct net_device *dev = wdev->netdev;
1615 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1616 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_MAX + 1];
Jeff Johnson7af334b2017-02-01 13:03:43 -08001617 int rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001618 struct sir_dcc_get_stats request = {0};
Jeff Johnson7af334b2017-02-01 13:03:43 -08001619 QDF_STATUS status;
1620 void *cookie;
1621 struct hdd_request *hdd_request;
1622 struct hdd_dcc_stats_priv *priv;
1623 static const struct hdd_request_params params = {
1624 .priv_size = sizeof(*priv),
1625 .timeout_ms = WLAN_WAIT_TIME_OCB_CMD,
1626 .dealloc = hdd_dcc_get_stats_dealloc,
1627 };
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001628
Jeff Johnson1f61b612016-02-12 16:28:33 -08001629 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001630
Jeff Johnson7af334b2017-02-01 13:03:43 -08001631 rc = wlan_hdd_validate_context(hdd_ctx);
1632 if (rc)
1633 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001634
Krunal Sonibe766b02016-03-10 13:00:44 -08001635 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001636 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001637 return -EINVAL;
1638 }
1639
1640 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001641 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001642 return -EINVAL;
1643 }
1644
1645 /* Parse the netlink message */
1646 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_MAX,
1647 data,
1648 data_len,
1649 qca_wlan_vendor_dcc_get_stats)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001650 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001651 return -EINVAL;
1652 }
1653
1654 /* Validate all the parameters are present */
1655 if (!tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_CHANNEL_COUNT] ||
1656 !tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001657 hdd_err("Parameters are not present.");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001658 return -EINVAL;
1659 }
1660
1661 channel_count = nla_get_u32(
1662 tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_CHANNEL_COUNT]);
1663 request_array_len = nla_len(
1664 tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY]);
1665 request_array = nla_data(
1666 tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY]);
1667
Jeff Johnson7af334b2017-02-01 13:03:43 -08001668 hdd_request = hdd_request_alloc(&params);
1669 if (!hdd_request) {
1670 hdd_err("Request allocation failure");
1671 return -ENOMEM;
1672 }
1673 cookie = hdd_request_cookie(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001674
1675 request.vdev_id = adapter->sessionId;
1676 request.channel_count = channel_count;
1677 request.request_array_len = request_array_len;
1678 request.request_array = request_array;
1679
1680 /* Call the SME function. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001681 status = sme_dcc_get_stats(hdd_ctx->hHal, cookie,
1682 hdd_dcc_get_stats_callback,
1683 &request);
1684 if (QDF_IS_STATUS_ERROR(status)) {
1685 hdd_err("Error calling SME function.");
1686 rc = qdf_status_to_os_return(status);
1687 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001688 }
1689
1690 /* Wait for the function to complete. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001691 rc = hdd_request_wait_for_response(hdd_request);
1692 if (rc) {
1693 hdd_err("Operation timed out");
1694 goto end;
1695 }
1696
1697 priv = hdd_request_priv(hdd_request);
1698 rc = priv->status;
1699 if (rc) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001700 hdd_err("Operation failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001701 goto end;
1702 }
1703
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001704 /* Send the response. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001705 rc = hdd_dcc_get_stats_send_reply(wiphy, priv->response);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001706 if (rc) {
Jeff Johnson7af334b2017-02-01 13:03:43 -08001707 hdd_err("hdd_dcc_get_stats_send_reply failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001708 goto end;
1709 }
1710
1711 /* fall through */
1712end:
Jeff Johnson7af334b2017-02-01 13:03:43 -08001713 hdd_request_put(hdd_request);
1714
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001715 return rc;
1716}
1717
1718/**
1719 * wlan_hdd_cfg80211_dcc_get_stats() - Interface for get dcc stats
1720 * @wiphy: pointer to the wiphy
1721 * @wdev: pointer to the wdev
1722 * @data: The netlink data
1723 * @data_len: The length of the netlink data in bytes
1724 *
1725 * Return: 0 on success.
1726 */
1727int wlan_hdd_cfg80211_dcc_get_stats(struct wiphy *wiphy,
1728 struct wireless_dev *wdev,
1729 const void *data,
1730 int data_len)
1731{
1732 int ret;
1733
1734 cds_ssr_protect(__func__);
1735 ret = __wlan_hdd_cfg80211_dcc_get_stats(wiphy, wdev,
1736 data, data_len);
1737 cds_ssr_unprotect(__func__);
1738
1739 return ret;
1740}
1741
1742/**
1743 * __wlan_hdd_cfg80211_dcc_clear_stats() - Interface for clear dcc stats cmd
1744 * @wiphy: pointer to the wiphy
1745 * @wdev: pointer to the wdev
1746 * @data: The netlink data
1747 * @data_len: The length of the netlink data in bytes
1748 *
1749 * Return: 0 on success.
1750 */
1751static int __wlan_hdd_cfg80211_dcc_clear_stats(struct wiphy *wiphy,
1752 struct wireless_dev *wdev,
1753 const void *data,
1754 int data_len)
1755{
1756 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1757 struct net_device *dev = wdev->netdev;
1758 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1759 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_MAX + 1];
1760
Jeff Johnson1f61b612016-02-12 16:28:33 -08001761 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001762
Abhishek Singh23edd1c2016-05-05 11:56:06 +05301763 if (wlan_hdd_validate_context(hdd_ctx))
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001764 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001765
Krunal Sonibe766b02016-03-10 13:00:44 -08001766 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001767 hdd_err("Device not in OCB mode!");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001768 return -EINVAL;
1769 }
1770
1771 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001772 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001773 return -EINVAL;
1774 }
1775
1776 /* Parse the netlink message */
1777 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_MAX,
1778 data,
1779 data_len,
1780 qca_wlan_vendor_dcc_clear_stats)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001781 hdd_err("Invalid ATTR");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001782 return -EINVAL;
1783 }
1784
1785 /* Verify that the parameter is present */
1786 if (!tb[QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_BITMAP]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001787 hdd_err("Parameters are not present.");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001788 return -EINVAL;
1789 }
1790
1791 /* Call the SME function */
1792 if (sme_dcc_clear_stats(hdd_ctx->hHal, adapter->sessionId,
1793 nla_get_u32(
1794 tb[QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_BITMAP])) !=
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05301795 QDF_STATUS_SUCCESS) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001796 hdd_err("Error calling SME function.");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001797 return -EINVAL;
1798 }
1799
1800 return 0;
1801}
1802
1803/**
1804 * wlan_hdd_cfg80211_dcc_clear_stats() - Interface for clear dcc stats cmd
1805 * @wiphy: pointer to the wiphy
1806 * @wdev: pointer to the wdev
1807 * @data: The netlink data
1808 * @data_len: The length of the netlink data in bytes
1809 *
1810 * Return: 0 on success.
1811 */
1812int wlan_hdd_cfg80211_dcc_clear_stats(struct wiphy *wiphy,
1813 struct wireless_dev *wdev,
1814 const void *data,
1815 int data_len)
1816{
1817 int ret;
1818
1819 cds_ssr_protect(__func__);
1820 ret = __wlan_hdd_cfg80211_dcc_clear_stats(wiphy, wdev,
1821 data, data_len);
1822 cds_ssr_unprotect(__func__);
1823
1824 return ret;
1825}
1826
Jeff Johnson7af334b2017-02-01 13:03:43 -08001827struct hdd_dcc_update_ndl_priv {
1828 int status;
1829};
1830
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001831/**
1832 * hdd_dcc_update_ndl_callback() - Callback to update NDL command
1833 * @context_ptr: request context
1834 * @response_ptr: response data
1835 */
1836static void hdd_dcc_update_ndl_callback(void *context_ptr, void *response_ptr)
1837{
Jeff Johnson7af334b2017-02-01 13:03:43 -08001838 struct hdd_request *hdd_request;
1839 struct hdd_dcc_update_ndl_priv *priv;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001840 struct sir_dcc_update_ndl_response *response = response_ptr;
1841
Jeff Johnson7af334b2017-02-01 13:03:43 -08001842 hdd_request = hdd_request_get(context_ptr);
1843 if (!hdd_request) {
1844 hdd_err("Obsolete request");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001845 return;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001846 }
Jeff Johnson7af334b2017-02-01 13:03:43 -08001847 priv = hdd_request_priv(hdd_request);
1848 if (response && (0 == response->status)) {
1849 priv->status = 0;
1850 } else {
1851 priv->status = -EINVAL;
1852 }
1853 hdd_request_complete(hdd_request);
1854 hdd_request_put(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001855}
1856
1857/**
1858 * __wlan_hdd_cfg80211_dcc_update_ndl() - Interface for update dcc cmd
1859 * @wiphy: pointer to the wiphy
1860 * @wdev: pointer to the wdev
1861 * @data: The netlink data
1862 * @data_len: The length of the netlink data in bytes
1863 *
1864 * Return: 0 on success.
1865 */
1866static int __wlan_hdd_cfg80211_dcc_update_ndl(struct wiphy *wiphy,
1867 struct wireless_dev *wdev,
1868 const void *data,
1869 int data_len)
1870{
1871 hdd_context_t *hdd_ctx = wiphy_priv(wiphy);
1872 struct net_device *dev = wdev->netdev;
1873 hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
1874 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_MAX + 1];
1875 struct sir_dcc_update_ndl request;
1876 uint32_t channel_count;
1877 uint32_t ndl_channel_array_len;
1878 void *ndl_channel_array;
1879 uint32_t ndl_active_state_array_len;
1880 void *ndl_active_state_array;
Jeff Johnson7af334b2017-02-01 13:03:43 -08001881 int rc;
1882 QDF_STATUS status;
1883 void *cookie;
1884 struct hdd_request *hdd_request;
1885 struct hdd_dcc_update_ndl_priv *priv;
1886 static const struct hdd_request_params params = {
1887 .priv_size = sizeof(*priv),
1888 .timeout_ms = WLAN_WAIT_TIME_OCB_CMD,
1889 };
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001890
Jeff Johnson1f61b612016-02-12 16:28:33 -08001891 ENTER_DEV(dev);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001892
Jeff Johnson7af334b2017-02-01 13:03:43 -08001893 rc = wlan_hdd_validate_context(hdd_ctx);
1894 if (rc)
1895 return rc;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001896
Krunal Sonibe766b02016-03-10 13:00:44 -08001897 if (adapter->device_mode != QDF_OCB_MODE) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001898 hdd_err("Device not in OCB mode!");
Jeff Johnson7af334b2017-02-01 13:03:43 -08001899 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001900 }
1901
1902 if (!wma_is_vdev_up(adapter->sessionId)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001903 hdd_err("The device has not been started");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001904 return -EINVAL;
1905 }
1906
1907 /* Parse the netlink message */
1908 if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_MAX,
1909 data,
1910 data_len,
1911 qca_wlan_vendor_dcc_update_ndl)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001912 hdd_err("Invalid ATTR");
Jeff Johnson7af334b2017-02-01 13:03:43 -08001913 return -EINVAL;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001914 }
1915
1916 /* Verify that the parameter is present */
1917 if (!tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_COUNT] ||
1918 !tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY] ||
1919 !tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY]) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001920 hdd_err("Parameters are not present.");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001921 return -EINVAL;
1922 }
1923
1924 channel_count = nla_get_u32(
1925 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_COUNT]);
1926 ndl_channel_array_len = nla_len(
1927 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY]);
1928 ndl_channel_array = nla_data(
1929 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY]);
1930 ndl_active_state_array_len = nla_len(
1931 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY]);
1932 ndl_active_state_array = nla_data(
1933 tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY]);
1934
Jeff Johnson7af334b2017-02-01 13:03:43 -08001935 hdd_request = hdd_request_alloc(&params);
1936 if (!hdd_request) {
1937 hdd_err("Request allocation failure");
1938 return -ENOMEM;
1939 }
1940 cookie = hdd_request_cookie(hdd_request);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001941
1942 /* Copy the parameters to the request structure. */
1943 request.vdev_id = adapter->sessionId;
1944 request.channel_count = channel_count;
1945 request.dcc_ndl_chan_list_len = ndl_channel_array_len;
1946 request.dcc_ndl_chan_list = ndl_channel_array;
1947 request.dcc_ndl_active_state_list_len = ndl_active_state_array_len;
1948 request.dcc_ndl_active_state_list = ndl_active_state_array;
1949
1950 /* Call the SME function */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001951 status = sme_dcc_update_ndl(hdd_ctx->hHal, cookie,
1952 hdd_dcc_update_ndl_callback,
1953 &request);
1954 if (QDF_IS_STATUS_ERROR(status)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001955 hdd_err("Error calling SME function.");
Jeff Johnson7af334b2017-02-01 13:03:43 -08001956 rc = qdf_status_to_os_return(status);
1957 goto end;
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001958 }
1959
1960 /* Wait for the function to complete. */
Jeff Johnson7af334b2017-02-01 13:03:43 -08001961 rc = hdd_request_wait_for_response(hdd_request);
1962 if (rc) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07001963 hdd_err("Operation timed out");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001964 goto end;
1965 }
1966
Jeff Johnson7af334b2017-02-01 13:03:43 -08001967 priv = hdd_request_priv(hdd_request);
1968 rc = priv->status;
1969 if (rc) {
1970 hdd_err("Operation failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001971 goto end;
1972 }
1973
1974 /* fall through */
1975end:
Jeff Johnson7af334b2017-02-01 13:03:43 -08001976 hdd_request_put(hdd_request);
1977
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08001978 return rc;
1979}
1980
1981/**
1982 * wlan_hdd_cfg80211_dcc_update_ndl() - Interface for update dcc cmd
1983 * @wiphy: pointer to the wiphy
1984 * @wdev: pointer to the wdev
1985 * @data: The netlink data
1986 * @data_len: The length of the netlink data in bytes
1987 *
1988 * Return: 0 on success.
1989 */
1990int wlan_hdd_cfg80211_dcc_update_ndl(struct wiphy *wiphy,
1991 struct wireless_dev *wdev,
1992 const void *data,
1993 int data_len)
1994{
1995 int ret;
1996
1997 cds_ssr_protect(__func__);
1998 ret = __wlan_hdd_cfg80211_dcc_update_ndl(wiphy, wdev,
1999 data, data_len);
2000 cds_ssr_unprotect(__func__);
2001
2002 return ret;
2003}
2004
2005/**
2006 * wlan_hdd_dcc_stats_event_callback() - Callback to get stats event
2007 * @context_ptr: request context
2008 * @response_ptr: response data
2009 */
2010static void wlan_hdd_dcc_stats_event_callback(void *context_ptr,
2011 void *response_ptr)
2012{
2013 hdd_context_t *hdd_ctx = (hdd_context_t *)context_ptr;
2014 struct sir_dcc_get_stats_response *resp = response_ptr;
2015 struct sk_buff *vendor_event;
2016
2017 ENTER();
2018
2019 vendor_event =
2020 cfg80211_vendor_event_alloc(hdd_ctx->wiphy,
2021 NULL, sizeof(uint32_t) + resp->channel_stats_array_len +
2022 NLMSG_HDRLEN,
2023 QCA_NL80211_VENDOR_SUBCMD_DCC_STATS_EVENT_INDEX,
2024 GFP_KERNEL);
2025
2026 if (!vendor_event) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07002027 hdd_err("cfg80211_vendor_event_alloc failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002028 return;
2029 }
2030
2031 if (nla_put_u32(vendor_event,
2032 QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_CHANNEL_COUNT,
2033 resp->num_channels) ||
2034 nla_put(vendor_event,
2035 QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_STATS_ARRAY,
2036 resp->channel_stats_array_len,
2037 resp->channel_stats_array)) {
Jeff Johnson5f735d52016-07-06 15:14:45 -07002038 hdd_err("nla put failed");
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002039 kfree_skb(vendor_event);
2040 return;
2041 }
2042
2043 cfg80211_vendor_event(vendor_event, GFP_KERNEL);
2044}
2045
2046/**
2047 * wlan_hdd_dcc_register_for_dcc_stats_event() - Register for dcc stats events
2048 * @hdd_ctx: hdd context
2049 */
2050void wlan_hdd_dcc_register_for_dcc_stats_event(hdd_context_t *hdd_ctx)
2051{
2052 int rc;
2053
2054 rc = sme_register_for_dcc_stats_event(hdd_ctx->hHal, hdd_ctx,
Arun Khandavalli4b55da72016-07-19 19:55:01 +05302055 wlan_hdd_dcc_stats_event_callback);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002056 if (rc)
Jeff Johnson5f735d52016-07-06 15:14:45 -07002057 hdd_err("Register callback failed: %d", rc);
Prakash Dhavali7090c5f2015-11-02 17:55:19 -08002058}