Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Jeff Johnson | 441e1f7 | 2017-02-07 08:50:49 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011-2017 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 3 | * |
| 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 Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 39 | #include "wlan_hdd_request_manager.h" |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 40 | #include "wlan_tgt_def_config.h" |
| 41 | #include "sch_api.h" |
| 42 | #include "wma_api.h" |
Leo Chang | fdb45c3 | 2016-10-28 11:09:23 -0700 | [diff] [blame] | 43 | #include <cdp_txrx_cmn.h> |
Manjunathappa Prakash | 3454fd6 | 2016-04-01 08:52:06 -0700 | [diff] [blame] | 44 | #include <cdp_txrx_peer_ops.h> |
Venkata Sharath Chandra Manchala | 0d44d45 | 2016-11-23 17:48:15 -0800 | [diff] [blame] | 45 | #include <cdp_txrx_handle.h> |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 46 | /* 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 Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 54 | |
| 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 | */ |
| 63 | void 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 | */ |
| 76 | static 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 Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 88 | hdd_err("Invalid QoS parameter aifsn %d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 89 | 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 Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 96 | hdd_err("Invalid QoS parameter cwmin %d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 97 | 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 Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 104 | hdd_err("Invalid QoS parameter cwmax %d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 105 | qos_params[i].cwmax); |
| 106 | return -EINVAL; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 113 | /** |
| 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 | */ |
| 123 | static 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 | |
Dustin Brown | a30892e | 2016-10-12 17:28:36 -0700 | [diff] [blame] | 132 | for (band_idx = 0; band_idx < NUM_NL80211_BANDS; band_idx++) { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 133 | 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 = ¤t_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 Singhal | fda6eda | 2015-11-02 15:08:59 -0800 | [diff] [blame] | 189 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /** |
| 193 | * hdd_ocb_validate_config() - Validates the config data |
| 194 | * @config: configuration to be validated |
| 195 | * |
| 196 | * Return: 0 on success. |
| 197 | */ |
| 198 | static 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 Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 211 | hdd_err("Invalid channel frequency %d", |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 212 | 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 | */ |
| 231 | static int hdd_ocb_register_sta(hdd_adapter_t *adapter) |
| 232 | { |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 233 | QDF_STATUS qdf_status = QDF_STATUS_E_FAILURE; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 234 | 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 Atre | 182b027 | 2016-02-17 15:35:07 -0800 | [diff] [blame] | 238 | struct ol_txrx_ops txrx_ops; |
Leo Chang | fdb45c3 | 2016-10-28 11:09:23 -0700 | [diff] [blame] | 239 | void *soc = cds_get_context(QDF_MODULE_ID_SOC); |
| 240 | void *pdev = cds_get_context(QDF_MODULE_ID_TXRX); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 241 | |
Leo Chang | fdb45c3 | 2016-10-28 11:09:23 -0700 | [diff] [blame] | 242 | qdf_status = cdp_peer_register_ocb_peer(soc, hdd_ctx->pcds_context, |
| 243 | adapter->macAddressCurrent.bytes, |
| 244 | &peer_id); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 245 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 246 | hdd_err("Error registering OCB Self Peer!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 247 | 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 Atre | 182b027 | 2016-02-17 15:35:07 -0800 | [diff] [blame] | 255 | /* 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 Chang | fdb45c3 | 2016-10-28 11:09:23 -0700 | [diff] [blame] | 258 | cdp_vdev_register(soc, |
Venkata Sharath Chandra Manchala | 0d44d45 | 2016-11-23 17:48:15 -0800 | [diff] [blame] | 259 | (struct cdp_vdev *)cdp_get_vdev_from_vdev_id(soc, |
| 260 | (struct cdp_pdev *)pdev, adapter->sessionId), |
| 261 | adapter, &txrx_ops); |
Dhanashri Atre | 168d2b4 | 2016-02-22 14:43:06 -0800 | [diff] [blame] | 262 | adapter->tx_fn = txrx_ops.tx.tx; |
Dhanashri Atre | 182b027 | 2016-02-17 15:35:07 -0800 | [diff] [blame] | 263 | |
Venkata Sharath Chandra Manchala | 0d44d45 | 2016-11-23 17:48:15 -0800 | [diff] [blame] | 264 | qdf_status = cdp_peer_register(soc, |
| 265 | (struct cdp_pdev *)pdev, &sta_desc); |
Dhanashri Atre | 50141c5 | 2016-04-07 13:15:29 -0700 | [diff] [blame] | 266 | if (!QDF_IS_STATUS_SUCCESS(qdf_status)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 267 | hdd_err("Failed to register. Status= %d [0x%08X]", |
Dhanashri Atre | 50141c5 | 2016-04-07 13:15:29 -0700 | [diff] [blame] | 268 | qdf_status, qdf_status); |
| 269 | return -EINVAL; |
| 270 | } |
| 271 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 272 | if (pHddStaCtx->conn_info.staId[0] != 0 && |
| 273 | pHddStaCtx->conn_info.staId[0] != peer_id) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 274 | hdd_err("The ID for the OCB station has changed."); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | pHddStaCtx->conn_info.staId[0] = peer_id; |
Anurag Chouhan | c554842 | 2016-02-24 18:33:27 +0530 | [diff] [blame] | 278 | qdf_copy_macaddr(&pHddStaCtx->conn_info.peerMacAddress[0], |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 279 | &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 Johnson | 929ad03 | 2016-10-19 07:34:42 -0700 | [diff] [blame] | 293 | static |
| 294 | struct 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 Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 298 | { |
| 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 Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 313 | cursor = qdf_mem_malloc(len); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 314 | if (!cursor) |
| 315 | goto fail; |
| 316 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 317 | 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 | |
| 336 | fail: |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 337 | qdf_mem_free(ret); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 338 | return NULL; |
| 339 | } |
| 340 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 341 | struct hdd_ocb_set_config_priv { |
| 342 | int status; |
| 343 | }; |
| 344 | |
| 345 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 346 | /** |
| 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 | */ |
| 354 | static void hdd_ocb_set_config_callback(void *context_ptr, void *response_ptr) |
| 355 | { |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 356 | struct hdd_request *hdd_request; |
| 357 | struct hdd_ocb_set_config_priv *priv; |
| 358 | struct sir_ocb_set_config_response *response = response_ptr; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 359 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 360 | hdd_request = hdd_request_get(context_ptr); |
| 361 | if (!hdd_request) { |
| 362 | hdd_err("Obsolete request"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 363 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 364 | } |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 365 | priv = hdd_request_priv(hdd_request); |
| 366 | |
| 367 | if (response && response->status) |
Srinivas Girigowda | aaea410 | 2017-03-25 11:02:52 -0700 | [diff] [blame] | 368 | hdd_warn("Operation failed: %d", response->status); |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 369 | |
| 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 Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 377 | } |
| 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 | */ |
| 386 | static int hdd_ocb_set_config_req(hdd_adapter_t *adapter, |
| 387 | struct sir_ocb_config *config) |
| 388 | { |
| 389 | int rc; |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 390 | 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 Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 399 | |
| 400 | if (hdd_ocb_validate_config(adapter, config)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 401 | hdd_err("The configuration is invalid"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 402 | return -EINVAL; |
| 403 | } |
| 404 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 405 | hdd_request = hdd_request_alloc(¶ms); |
| 406 | if (!hdd_request) { |
| 407 | hdd_err("Request allocation failure"); |
| 408 | return -ENOMEM; |
| 409 | } |
| 410 | cookie = hdd_request_cookie(hdd_request); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 411 | |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 412 | hdd_notice("Disabling queues"); |
Himanshu Agarwal | 865201d | 2017-04-12 15:45:31 +0530 | [diff] [blame^] | 413 | wlan_hdd_netif_queue_control(adapter, |
| 414 | WLAN_STOP_ALL_NETIF_QUEUE_N_CARRIER, |
| 415 | WLAN_CONTROL_PATH); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 416 | |
| 417 | /* Call the SME API to set the config */ |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 418 | status = sme_ocb_set_config(hdd_ctx->hHal, cookie, |
| 419 | hdd_ocb_set_config_callback, config); |
| 420 | if (QDF_IS_STATUS_ERROR(status)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 421 | hdd_err("Error calling SME function."); |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 422 | rc = qdf_status_to_os_return(status); |
| 423 | goto end; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /* Wait for the function to complete. */ |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 427 | rc = hdd_request_wait_for_response(hdd_request); |
| 428 | if (rc) { |
| 429 | hdd_err("Operation timed out"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 430 | goto end; |
| 431 | } |
| 432 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 433 | priv = hdd_request_priv(hdd_request); |
| 434 | rc = priv->status; |
| 435 | if (rc) { |
| 436 | hdd_err("Operation failed: %d", rc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 437 | goto end; |
| 438 | } |
| 439 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 440 | /* |
| 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 Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 449 | /* fall through */ |
| 450 | end: |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 451 | hdd_request_put(hdd_request); |
| 452 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 453 | 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 | */ |
| 466 | static 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 Johnson | 441e1f7 | 2017-02-07 08:50:49 -0800 | [diff] [blame] | 470 | int rc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 471 | struct dot11p_channel_sched *sched; |
Jeff Johnson | 441e1f7 | 2017-02-07 08:50:49 -0800 | [diff] [blame] | 472 | hdd_context_t *hdd_ctx; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 473 | 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 Johnson | 6ee91ee | 2016-02-11 18:55:30 -0800 | [diff] [blame] | 479 | ENTER_DEV(dev); |
| 480 | |
Jeff Johnson | 441e1f7 | 2017-02-07 08:50:49 -0800 | [diff] [blame] | 481 | 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 Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 489 | |
Krunal Soni | be766b0 | 2016-03-10 13:00:44 -0800 | [diff] [blame] | 490 | if (adapter->device_mode != QDF_OCB_MODE) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 491 | hdd_err("Device not in OCB mode!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 492 | 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 Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 501 | hdd_err("Failed to allocate memory!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 502 | 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 Girigowda | 117e7fb | 2015-11-16 12:33:45 -0800 | [diff] [blame] | 511 | adapter->ocb_mac_address[i].bytes); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 512 | } |
| 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 Chouhan | c554842 | 2016-02-24 18:33:27 +0530 | [diff] [blame] | 539 | qdf_copy_macaddr(&curr_chan->mac_address, |
Srinivas Girigowda | 117e7fb | 2015-11-16 12:33:45 -0800 | [diff] [blame] | 540 | &adapter->macAddressCurrent); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 541 | } else { |
| 542 | mac_addr = wlan_hdd_get_intf_addr(adapter->pHddCtx); |
| 543 | if (mac_addr == NULL) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 544 | hdd_err("Cannot obtain mac address"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 545 | rc = -EINVAL; |
| 546 | goto fail; |
| 547 | } |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 548 | qdf_mem_copy(config->channels[ |
Srinivas Girigowda | 117e7fb | 2015-11-16 12:33:45 -0800 | [diff] [blame] | 549 | config->channel_count].mac_address.bytes, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 550 | mac_addr, sizeof(tSirMacAddr)); |
| 551 | /* Save the mac address to release later */ |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 552 | qdf_mem_copy(adapter->ocb_mac_address[ |
Srinivas Girigowda | 117e7fb | 2015-11-16 12:33:45 -0800 | [diff] [blame] | 553 | adapter->ocb_mac_addr_count].bytes, |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 554 | mac_addr, QDF_MAC_ADDR_SIZE); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 555 | 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 Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 584 | hdd_err("Error while setting OCB config"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 585 | goto fail; |
| 586 | } |
| 587 | |
| 588 | rc = 0; |
| 589 | |
| 590 | fail: |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 591 | qdf_mem_free(config); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 592 | 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 | */ |
| 604 | int 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 | |
| 617 | static 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 | |
| 642 | static 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 | |
| 652 | static 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 | |
| 662 | static 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 | |
| 669 | static 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 | |
| 678 | static 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 | |
| 687 | static 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 | |
| 696 | static 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 | |
| 702 | static 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 | */ |
| 724 | struct 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 | |
| 734 | static 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 Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 741 | qdf_mem_zero(dest, channel_count * sizeof(*dest)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 742 | |
| 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 Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 746 | qdf_mem_copy(dest[i].qos_params, src[i].qos_params, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 747 | 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 | */ |
| 770 | static 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 Johnson | 929ad03 | 2016-10-19 07:34:42 -0700 | [diff] [blame] | 787 | uint32_t channel_count, schedule_size; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 788 | struct sir_ocb_config *config; |
| 789 | int rc = -EINVAL; |
| 790 | uint8_t *mac_addr; |
| 791 | |
Jeff Johnson | 1f61b61 | 2016-02-12 16:28:33 -0800 | [diff] [blame] | 792 | ENTER_DEV(dev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 793 | |
Abhishek Singh | 23edd1c | 2016-05-05 11:56:06 +0530 | [diff] [blame] | 794 | if (wlan_hdd_validate_context(hdd_ctx)) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 795 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 796 | |
Krunal Soni | be766b0 | 2016-03-10 13:00:44 -0800 | [diff] [blame] | 797 | if (adapter->device_mode != QDF_OCB_MODE) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 798 | hdd_err("Device not in OCB mode!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 799 | 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 Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 806 | hdd_err("Invalid ATTR"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 807 | 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 Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 812 | hdd_err("CHANNEL_COUNT is not present"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 813 | 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 Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 820 | hdd_err("SCHEDULE_SIZE is not present"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 821 | 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. */ |
| 827 | ndl_chan_list = |
| 828 | tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_CHANNEL_ARRAY]; |
| 829 | ndl_chan_list_len = (ndl_chan_list ? nla_len(ndl_chan_list) : 0); |
| 830 | |
| 831 | ndl_active_state_list = |
| 832 | tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_NDL_ACTIVE_STATE_ARRAY]; |
| 833 | ndl_active_state_list_len = (ndl_active_state_list ? |
| 834 | nla_len(ndl_active_state_list) : 0); |
| 835 | |
| 836 | /* Get the flags */ |
| 837 | if (tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_FLAGS]) |
| 838 | flags = nla_get_u32(tb[ |
| 839 | QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_FLAGS]); |
| 840 | |
| 841 | config = hdd_ocb_config_new(channel_count, schedule_size, |
| 842 | ndl_chan_list_len, |
| 843 | ndl_active_state_list_len); |
| 844 | if (config == NULL) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 845 | hdd_err("Failed to allocate memory!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 846 | return -ENOMEM; |
| 847 | } |
| 848 | |
| 849 | config->channel_count = channel_count; |
| 850 | config->schedule_size = schedule_size; |
| 851 | config->flags = flags; |
| 852 | |
| 853 | /* Read the channel array */ |
| 854 | channel_array = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_CHANNEL_ARRAY]; |
| 855 | if (!channel_array) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 856 | hdd_err("No channel present"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 857 | goto fail; |
| 858 | } |
| 859 | if (nla_len(channel_array) != channel_count * |
| 860 | sizeof(struct wlan_hdd_ocb_config_channel)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 861 | hdd_err("CHANNEL_ARRAY is not the correct size"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 862 | goto fail; |
| 863 | } |
| 864 | wlan_hdd_ocb_config_channel_to_sir_ocb_config_channel( |
| 865 | config->channels, nla_data(channel_array), channel_count); |
| 866 | |
| 867 | /* Identify the vdev interface */ |
| 868 | config->session_id = adapter->sessionId; |
| 869 | |
| 870 | /* Release all the mac addresses used for OCB */ |
| 871 | for (i = 0; i < adapter->ocb_mac_addr_count; i++) { |
| 872 | wlan_hdd_release_intf_addr(adapter->pHddCtx, |
Srinivas Girigowda | 117e7fb | 2015-11-16 12:33:45 -0800 | [diff] [blame] | 873 | adapter->ocb_mac_address[i].bytes); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 874 | } |
| 875 | adapter->ocb_mac_addr_count = 0; |
| 876 | |
| 877 | /* |
| 878 | * Setup locally administered mac addresses for each channel. |
| 879 | * First channel uses the adapter's address. |
| 880 | */ |
| 881 | for (i = 0; i < config->channel_count; i++) { |
| 882 | if (i == 0) { |
Anurag Chouhan | c554842 | 2016-02-24 18:33:27 +0530 | [diff] [blame] | 883 | qdf_copy_macaddr(&config->channels[i].mac_address, |
Srinivas Girigowda | 117e7fb | 2015-11-16 12:33:45 -0800 | [diff] [blame] | 884 | &adapter->macAddressCurrent); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 885 | } else { |
| 886 | mac_addr = wlan_hdd_get_intf_addr(adapter->pHddCtx); |
| 887 | if (mac_addr == NULL) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 888 | hdd_err("Cannot obtain mac address"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 889 | goto fail; |
| 890 | } |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 891 | qdf_mem_copy(config->channels[i].mac_address.bytes, |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 892 | mac_addr, QDF_MAC_ADDR_SIZE); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 893 | /* Save the mac address to release later */ |
Anurag Chouhan | c554842 | 2016-02-24 18:33:27 +0530 | [diff] [blame] | 894 | qdf_copy_macaddr(&adapter->ocb_mac_address[ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 895 | adapter->ocb_mac_addr_count], |
Srinivas Girigowda | 117e7fb | 2015-11-16 12:33:45 -0800 | [diff] [blame] | 896 | &config->channels[i].mac_address); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 897 | adapter->ocb_mac_addr_count++; |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | /* Read the schedule array */ |
| 902 | sched_array = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_CONFIG_SCHEDULE_ARRAY]; |
| 903 | if (!sched_array) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 904 | hdd_err("No channel present"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 905 | goto fail; |
| 906 | } |
| 907 | if (nla_len(sched_array) != schedule_size * sizeof(*config->schedule)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 908 | hdd_err("SCHEDULE_ARRAY is not the correct size"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 909 | goto fail; |
| 910 | } |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 911 | qdf_mem_copy(config->schedule, nla_data(sched_array), |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 912 | nla_len(sched_array)); |
| 913 | |
| 914 | /* Copy the NDL chan array */ |
| 915 | if (ndl_chan_list_len) { |
| 916 | config->dcc_ndl_chan_list_len = ndl_chan_list_len; |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 917 | qdf_mem_copy(config->dcc_ndl_chan_list, nla_data(ndl_chan_list), |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 918 | nla_len(ndl_chan_list)); |
| 919 | } |
| 920 | |
| 921 | /* Copy the NDL active state array */ |
| 922 | if (ndl_active_state_list_len) { |
| 923 | config->dcc_ndl_active_state_list_len = |
| 924 | ndl_active_state_list_len; |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 925 | qdf_mem_copy(config->dcc_ndl_active_state_list, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 926 | nla_data(ndl_active_state_list), |
| 927 | nla_len(ndl_active_state_list)); |
| 928 | } |
| 929 | |
| 930 | rc = hdd_ocb_set_config_req(adapter, config); |
| 931 | if (rc) |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 932 | hdd_err("Error while setting OCB config: %d", rc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 933 | |
| 934 | fail: |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 935 | qdf_mem_free(config); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 936 | return rc; |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * wlan_hdd_cfg80211_ocb_set_config() - Interface for set config command |
| 941 | * @wiphy: pointer to the wiphy |
| 942 | * @wdev: pointer to the wdev |
| 943 | * @data: The netlink data |
| 944 | * @data_len: The length of the netlink data in bytes |
| 945 | * |
| 946 | * Return: 0 on success. |
| 947 | */ |
| 948 | int wlan_hdd_cfg80211_ocb_set_config(struct wiphy *wiphy, |
| 949 | struct wireless_dev *wdev, |
| 950 | const void *data, |
| 951 | int data_len) |
| 952 | { |
| 953 | int ret; |
| 954 | |
| 955 | cds_ssr_protect(__func__); |
| 956 | ret = __wlan_hdd_cfg80211_ocb_set_config(wiphy, wdev, data, data_len); |
| 957 | cds_ssr_unprotect(__func__); |
| 958 | |
| 959 | return ret; |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * __wlan_hdd_cfg80211_ocb_set_utc_time() - Interface for set UTC time command |
| 964 | * @wiphy: pointer to the wiphy |
| 965 | * @wdev: pointer to the wdev |
| 966 | * @data: The netlink data |
| 967 | * @data_len: The length of the netlink data in bytes |
| 968 | * |
| 969 | * Return: 0 on success. |
| 970 | */ |
| 971 | static int __wlan_hdd_cfg80211_ocb_set_utc_time(struct wiphy *wiphy, |
| 972 | struct wireless_dev *wdev, |
| 973 | const void *data, |
| 974 | int data_len) |
| 975 | { |
| 976 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
| 977 | struct net_device *dev = wdev->netdev; |
| 978 | hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 979 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_MAX + 1]; |
| 980 | struct nlattr *utc_attr; |
| 981 | struct nlattr *time_error_attr; |
| 982 | struct sir_ocb_utc *utc; |
| 983 | int rc = -EINVAL; |
| 984 | |
Jeff Johnson | 1f61b61 | 2016-02-12 16:28:33 -0800 | [diff] [blame] | 985 | ENTER_DEV(dev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 986 | |
Abhishek Singh | 23edd1c | 2016-05-05 11:56:06 +0530 | [diff] [blame] | 987 | if (wlan_hdd_validate_context(hdd_ctx)) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 988 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 989 | |
Krunal Soni | be766b0 | 2016-03-10 13:00:44 -0800 | [diff] [blame] | 990 | if (adapter->device_mode != QDF_OCB_MODE) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 991 | hdd_err("Device not in OCB mode!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 992 | return -EINVAL; |
| 993 | } |
| 994 | |
| 995 | if (!wma_is_vdev_up(adapter->sessionId)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 996 | hdd_err("The device has not been started"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 997 | return -EINVAL; |
| 998 | } |
| 999 | |
| 1000 | /* Parse the netlink message */ |
| 1001 | if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_MAX, |
| 1002 | data, |
| 1003 | data_len, qca_wlan_vendor_ocb_set_utc_time_policy)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1004 | hdd_err("Invalid ATTR"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1005 | return -EINVAL; |
| 1006 | } |
| 1007 | |
| 1008 | /* Read the UTC time */ |
| 1009 | utc_attr = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_VALUE]; |
| 1010 | if (!utc_attr) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1011 | hdd_err("UTC_TIME is not present"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1012 | return -EINVAL; |
| 1013 | } |
| 1014 | if (nla_len(utc_attr) != SIZE_UTC_TIME) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1015 | hdd_err("UTC_TIME is not the correct size"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1016 | return -EINVAL; |
| 1017 | } |
| 1018 | |
| 1019 | /* Read the time error */ |
| 1020 | time_error_attr = tb[QCA_WLAN_VENDOR_ATTR_OCB_SET_UTC_TIME_ERROR]; |
| 1021 | if (!time_error_attr) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1022 | hdd_err("UTC_TIME is not present"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1023 | return -EINVAL; |
| 1024 | } |
| 1025 | if (nla_len(time_error_attr) != SIZE_UTC_TIME_ERROR) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1026 | hdd_err("UTC_TIME is not the correct size"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1027 | return -EINVAL; |
| 1028 | } |
| 1029 | |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1030 | utc = qdf_mem_malloc(sizeof(*utc)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1031 | if (!utc) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1032 | hdd_err("qdf_mem_malloc failed"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1033 | return -ENOMEM; |
| 1034 | } |
| 1035 | utc->vdev_id = adapter->sessionId; |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1036 | qdf_mem_copy(utc->utc_time, nla_data(utc_attr), SIZE_UTC_TIME); |
| 1037 | qdf_mem_copy(utc->time_error, nla_data(time_error_attr), |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1038 | SIZE_UTC_TIME_ERROR); |
| 1039 | |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1040 | if (sme_ocb_set_utc_time(hdd_ctx->hHal, utc) != QDF_STATUS_SUCCESS) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1041 | hdd_err("Error while setting UTC time"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1042 | rc = -EINVAL; |
| 1043 | } else { |
| 1044 | rc = 0; |
| 1045 | } |
| 1046 | |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1047 | qdf_mem_free(utc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1048 | return rc; |
| 1049 | } |
| 1050 | |
| 1051 | /** |
| 1052 | * wlan_hdd_cfg80211_ocb_set_utc_time() - Interface for the set UTC time command |
| 1053 | * @wiphy: pointer to the wiphy |
| 1054 | * @wdev: pointer to the wdev |
| 1055 | * @data: The netlink data |
| 1056 | * @data_len: The length of the netlink data in bytes |
| 1057 | * |
| 1058 | * Return: 0 on success. |
| 1059 | */ |
| 1060 | int wlan_hdd_cfg80211_ocb_set_utc_time(struct wiphy *wiphy, |
| 1061 | struct wireless_dev *wdev, |
| 1062 | const void *data, |
| 1063 | int data_len) |
| 1064 | { |
| 1065 | int ret; |
| 1066 | |
| 1067 | cds_ssr_protect(__func__); |
| 1068 | ret = __wlan_hdd_cfg80211_ocb_set_utc_time(wiphy, wdev, data, data_len); |
| 1069 | cds_ssr_unprotect(__func__); |
| 1070 | |
| 1071 | return ret; |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * __wlan_hdd_cfg80211_ocb_start_timing_advert() - Interface for start TA cmd |
| 1076 | * @wiphy: pointer to the wiphy |
| 1077 | * @wdev: pointer to the wdev |
| 1078 | * @data: The netlink data |
| 1079 | * @data_len: The length of the netlink data in bytes |
| 1080 | * |
| 1081 | * Return: 0 on success. |
| 1082 | */ |
| 1083 | static int |
| 1084 | __wlan_hdd_cfg80211_ocb_start_timing_advert(struct wiphy *wiphy, |
| 1085 | struct wireless_dev *wdev, |
| 1086 | const void *data, |
| 1087 | int data_len) |
| 1088 | { |
| 1089 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
| 1090 | struct net_device *dev = wdev->netdev; |
| 1091 | hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1092 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_MAX + 1]; |
| 1093 | struct sir_ocb_timing_advert *timing_advert; |
| 1094 | int rc = -EINVAL; |
| 1095 | |
Jeff Johnson | 1f61b61 | 2016-02-12 16:28:33 -0800 | [diff] [blame] | 1096 | ENTER_DEV(dev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1097 | |
Abhishek Singh | 23edd1c | 2016-05-05 11:56:06 +0530 | [diff] [blame] | 1098 | if (wlan_hdd_validate_context(hdd_ctx)) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1099 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1100 | |
Krunal Soni | be766b0 | 2016-03-10 13:00:44 -0800 | [diff] [blame] | 1101 | if (adapter->device_mode != QDF_OCB_MODE) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1102 | hdd_err("Device not in OCB mode!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1103 | return -EINVAL; |
| 1104 | } |
| 1105 | |
| 1106 | if (!wma_is_vdev_up(adapter->sessionId)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1107 | hdd_err("The device has not been started"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1108 | return -EINVAL; |
| 1109 | } |
| 1110 | |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1111 | timing_advert = qdf_mem_malloc(sizeof(*timing_advert)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1112 | if (!timing_advert) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1113 | hdd_err("qdf_mem_malloc failed"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1114 | return -ENOMEM; |
| 1115 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1116 | timing_advert->vdev_id = adapter->sessionId; |
| 1117 | |
| 1118 | /* Parse the netlink message */ |
| 1119 | if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_MAX, |
| 1120 | data, |
| 1121 | data_len, |
| 1122 | qca_wlan_vendor_ocb_start_timing_advert_policy)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1123 | hdd_err("Invalid ATTR"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1124 | goto fail; |
| 1125 | } |
| 1126 | |
| 1127 | if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_CHANNEL_FREQ]) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1128 | hdd_err("CHANNEL_FREQ is not present"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1129 | goto fail; |
| 1130 | } |
| 1131 | timing_advert->chan_freq = nla_get_u32( |
| 1132 | tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_CHANNEL_FREQ]); |
| 1133 | |
| 1134 | if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_REPEAT_RATE]) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1135 | hdd_err("REPEAT_RATE is not present"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1136 | goto fail; |
| 1137 | } |
| 1138 | timing_advert->repeat_rate = nla_get_u32( |
| 1139 | tb[QCA_WLAN_VENDOR_ATTR_OCB_START_TIMING_ADVERT_REPEAT_RATE]); |
| 1140 | |
| 1141 | timing_advert->template_length = |
Naveen Rawat | b4d3762 | 2015-11-13 16:15:25 -0800 | [diff] [blame] | 1142 | sme_ocb_gen_timing_advert_frame(hdd_ctx->hHal, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1143 | *(tSirMacAddr *)&adapter->macAddressCurrent.bytes, |
| 1144 | &timing_advert->template_value, |
| 1145 | &timing_advert->timestamp_offset, |
| 1146 | &timing_advert->time_value_offset); |
| 1147 | if (timing_advert->template_length <= 0) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1148 | hdd_err("Error while generating the TA frame"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1149 | goto fail; |
| 1150 | } |
| 1151 | |
| 1152 | if (sme_ocb_start_timing_advert(hdd_ctx->hHal, timing_advert) != |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1153 | QDF_STATUS_SUCCESS) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1154 | hdd_err("Error while starting timing advert"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1155 | rc = -EINVAL; |
| 1156 | } else { |
| 1157 | rc = 0; |
| 1158 | } |
| 1159 | |
| 1160 | fail: |
| 1161 | if (timing_advert->template_value) |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1162 | qdf_mem_free(timing_advert->template_value); |
| 1163 | qdf_mem_free(timing_advert); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1164 | return rc; |
| 1165 | } |
| 1166 | |
| 1167 | /** |
| 1168 | * wlan_hdd_cfg80211_ocb_start_timing_advert() - Interface for the start TA cmd |
| 1169 | * @wiphy: pointer to the wiphy |
| 1170 | * @wdev: pointer to the wdev |
| 1171 | * @data: The netlink data |
| 1172 | * @data_len: The length of the netlink data in bytes |
| 1173 | * |
| 1174 | * Return: 0 on success. |
| 1175 | */ |
| 1176 | int wlan_hdd_cfg80211_ocb_start_timing_advert(struct wiphy *wiphy, |
| 1177 | struct wireless_dev *wdev, |
| 1178 | const void *data, |
| 1179 | int data_len) |
| 1180 | { |
| 1181 | int ret; |
| 1182 | |
| 1183 | cds_ssr_protect(__func__); |
| 1184 | ret = __wlan_hdd_cfg80211_ocb_start_timing_advert(wiphy, wdev, |
| 1185 | data, data_len); |
| 1186 | cds_ssr_unprotect(__func__); |
| 1187 | |
| 1188 | return ret; |
| 1189 | } |
| 1190 | |
| 1191 | /** |
| 1192 | * __wlan_hdd_cfg80211_ocb_stop_timing_advert() - Interface for the stop TA cmd |
| 1193 | * @wiphy: pointer to the wiphy |
| 1194 | * @wdev: pointer to the wdev |
| 1195 | * @data: The netlink data |
| 1196 | * @data_len: The length of the netlink data in bytes |
| 1197 | * |
| 1198 | * Return: 0 on success. |
| 1199 | */ |
| 1200 | static int |
| 1201 | __wlan_hdd_cfg80211_ocb_stop_timing_advert(struct wiphy *wiphy, |
| 1202 | struct wireless_dev *wdev, |
| 1203 | const void *data, |
| 1204 | int data_len) |
| 1205 | { |
| 1206 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
| 1207 | struct net_device *dev = wdev->netdev; |
| 1208 | hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 1209 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_MAX + 1]; |
| 1210 | struct sir_ocb_timing_advert *timing_advert; |
| 1211 | int rc = -EINVAL; |
| 1212 | |
Jeff Johnson | 1f61b61 | 2016-02-12 16:28:33 -0800 | [diff] [blame] | 1213 | ENTER_DEV(dev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1214 | |
Abhishek Singh | 23edd1c | 2016-05-05 11:56:06 +0530 | [diff] [blame] | 1215 | if (wlan_hdd_validate_context(hdd_ctx)) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1216 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1217 | |
Krunal Soni | be766b0 | 2016-03-10 13:00:44 -0800 | [diff] [blame] | 1218 | if (adapter->device_mode != QDF_OCB_MODE) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1219 | hdd_err("Device not in OCB mode!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1220 | return -EINVAL; |
| 1221 | } |
| 1222 | |
| 1223 | if (!wma_is_vdev_up(adapter->sessionId)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1224 | hdd_err("The device has not been started"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1225 | return -EINVAL; |
| 1226 | } |
| 1227 | |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1228 | timing_advert = qdf_mem_malloc(sizeof(*timing_advert)); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1229 | if (!timing_advert) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1230 | hdd_err("qdf_mem_malloc failed"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1231 | return -ENOMEM; |
| 1232 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1233 | timing_advert->vdev_id = adapter->sessionId; |
| 1234 | |
| 1235 | /* Parse the netlink message */ |
| 1236 | if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_MAX, |
| 1237 | data, |
| 1238 | data_len, |
| 1239 | qca_wlan_vendor_ocb_stop_timing_advert_policy)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1240 | hdd_err("Invalid ATTR"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1241 | goto fail; |
| 1242 | } |
| 1243 | |
| 1244 | if (!tb[QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_CHANNEL_FREQ]) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1245 | hdd_err("CHANNEL_FREQ is not present"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1246 | goto fail; |
| 1247 | } |
| 1248 | timing_advert->chan_freq = nla_get_u32( |
| 1249 | tb[QCA_WLAN_VENDOR_ATTR_OCB_STOP_TIMING_ADVERT_CHANNEL_FREQ]); |
| 1250 | |
| 1251 | if (sme_ocb_stop_timing_advert(hdd_ctx->hHal, timing_advert) != |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1252 | QDF_STATUS_SUCCESS) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1253 | hdd_err("Error while stopping timing advert"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1254 | rc = -EINVAL; |
| 1255 | } else { |
| 1256 | rc = 0; |
| 1257 | } |
| 1258 | |
| 1259 | fail: |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 1260 | qdf_mem_free(timing_advert); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1261 | return rc; |
| 1262 | } |
| 1263 | |
| 1264 | /** |
| 1265 | * wlan_hdd_cfg80211_ocb_stop_timing_advert() - Interface for the stop TA cmd |
| 1266 | * @wiphy: pointer to the wiphy |
| 1267 | * @wdev: pointer to the wdev |
| 1268 | * @data: The netlink data |
| 1269 | * @data_len: The length of the netlink data in bytes |
| 1270 | * |
| 1271 | * Return: 0 on success. |
| 1272 | */ |
| 1273 | int wlan_hdd_cfg80211_ocb_stop_timing_advert(struct wiphy *wiphy, |
| 1274 | struct wireless_dev *wdev, |
| 1275 | const void *data, |
| 1276 | int data_len) |
| 1277 | { |
| 1278 | int ret; |
| 1279 | |
| 1280 | cds_ssr_protect(__func__); |
| 1281 | ret = __wlan_hdd_cfg80211_ocb_stop_timing_advert(wiphy, wdev, |
| 1282 | data, data_len); |
| 1283 | cds_ssr_unprotect(__func__); |
| 1284 | |
| 1285 | return ret; |
| 1286 | } |
| 1287 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1288 | struct hdd_ocb_get_tsf_timer_priv { |
| 1289 | struct sir_ocb_get_tsf_timer_response response; |
| 1290 | int status; |
| 1291 | }; |
| 1292 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1293 | /** |
| 1294 | * hdd_ocb_get_tsf_timer_callback() - Callback to get TSF command |
| 1295 | * @context_ptr: request context |
| 1296 | * @response_ptr: response data |
| 1297 | */ |
| 1298 | static void hdd_ocb_get_tsf_timer_callback(void *context_ptr, |
| 1299 | void *response_ptr) |
| 1300 | { |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1301 | struct hdd_request *hdd_request; |
| 1302 | struct hdd_ocb_get_tsf_timer_priv *priv; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1303 | struct sir_ocb_get_tsf_timer_response *response = response_ptr; |
| 1304 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1305 | hdd_request = hdd_request_get(context_ptr); |
| 1306 | if (!hdd_request) { |
| 1307 | hdd_err("Obsolete request"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1308 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1309 | } |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1310 | |
| 1311 | if (response) { |
| 1312 | priv->response = *response; |
| 1313 | priv->status = 0; |
| 1314 | } else { |
| 1315 | priv->status = -EINVAL; |
| 1316 | } |
| 1317 | hdd_request_complete(hdd_request); |
| 1318 | hdd_request_put(hdd_request); |
| 1319 | } |
| 1320 | |
| 1321 | static int |
| 1322 | hdd_ocb_get_tsf_timer_reply(struct wiphy *wiphy, |
| 1323 | struct sir_ocb_get_tsf_timer_response *response) |
| 1324 | { |
| 1325 | uint32_t nl_buf_len; |
| 1326 | struct sk_buff *nl_resp; |
| 1327 | int rc; |
| 1328 | |
| 1329 | /* Allocate the buffer for the response. */ |
| 1330 | nl_buf_len = NLMSG_HDRLEN; |
| 1331 | nl_buf_len += 2 * (NLA_HDRLEN + sizeof(uint32_t)); |
| 1332 | nl_resp = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, nl_buf_len); |
| 1333 | if (!nl_resp) { |
| 1334 | hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed"); |
| 1335 | return -ENOMEM; |
| 1336 | } |
| 1337 | |
| 1338 | /* Populate the response. */ |
| 1339 | rc = nla_put_u32(nl_resp, |
| 1340 | QCA_WLAN_VENDOR_ATTR_OCB_GET_TSF_RESP_TIMER_HIGH, |
| 1341 | response->timer_high); |
| 1342 | if (rc) |
| 1343 | goto end; |
| 1344 | rc = nla_put_u32(nl_resp, |
| 1345 | QCA_WLAN_VENDOR_ATTR_OCB_GET_TSF_RESP_TIMER_LOW, |
| 1346 | response->timer_low); |
| 1347 | if (rc) |
| 1348 | goto end; |
| 1349 | |
| 1350 | /* Send the response. */ |
| 1351 | rc = cfg80211_vendor_cmd_reply(nl_resp); |
| 1352 | nl_resp = NULL; |
| 1353 | if (rc) { |
| 1354 | hdd_err("cfg80211_vendor_cmd_reply failed: %d", rc); |
| 1355 | goto end; |
| 1356 | } |
| 1357 | end: |
| 1358 | if (nl_resp) |
| 1359 | kfree_skb(nl_resp); |
| 1360 | |
| 1361 | return rc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | /** |
| 1365 | * __wlan_hdd_cfg80211_ocb_get_tsf_timer() - Interface for get TSF timer cmd |
| 1366 | * @wiphy: pointer to the wiphy |
| 1367 | * @wdev: pointer to the wdev |
| 1368 | * @data: The netlink data |
| 1369 | * @data_len: The length of the netlink data in bytes |
| 1370 | * |
| 1371 | * Return: 0 on success. |
| 1372 | */ |
| 1373 | static int |
| 1374 | __wlan_hdd_cfg80211_ocb_get_tsf_timer(struct wiphy *wiphy, |
| 1375 | struct wireless_dev *wdev, |
| 1376 | const void *data, |
| 1377 | int data_len) |
| 1378 | { |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1379 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
| 1380 | struct net_device *dev = wdev->netdev; |
| 1381 | hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev); |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1382 | int rc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1383 | struct sir_ocb_get_tsf_timer request = {0}; |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1384 | QDF_STATUS status; |
| 1385 | void *cookie; |
| 1386 | struct hdd_request *hdd_request; |
| 1387 | struct hdd_ocb_get_tsf_timer_priv *priv; |
| 1388 | static const struct hdd_request_params params = { |
| 1389 | .priv_size = sizeof(*priv), |
| 1390 | .timeout_ms = WLAN_WAIT_TIME_OCB_CMD, |
| 1391 | }; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1392 | |
Jeff Johnson | 1f61b61 | 2016-02-12 16:28:33 -0800 | [diff] [blame] | 1393 | ENTER_DEV(dev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1394 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1395 | rc = wlan_hdd_validate_context(hdd_ctx); |
| 1396 | if (rc) |
| 1397 | return rc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1398 | |
Krunal Soni | be766b0 | 2016-03-10 13:00:44 -0800 | [diff] [blame] | 1399 | if (adapter->device_mode != QDF_OCB_MODE) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1400 | hdd_err("Device not in OCB mode!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1401 | return -EINVAL; |
| 1402 | } |
| 1403 | |
| 1404 | if (!wma_is_vdev_up(adapter->sessionId)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1405 | hdd_err("The device has not been started"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1406 | return -EINVAL; |
| 1407 | } |
| 1408 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1409 | hdd_request = hdd_request_alloc(¶ms); |
| 1410 | if (!hdd_request) { |
| 1411 | hdd_err("Request allocation failure"); |
| 1412 | return -ENOMEM; |
| 1413 | } |
| 1414 | cookie = hdd_request_cookie(hdd_request); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1415 | |
| 1416 | request.vdev_id = adapter->sessionId; |
| 1417 | /* Call the SME function */ |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1418 | status = sme_ocb_get_tsf_timer(hdd_ctx->hHal, cookie, |
| 1419 | hdd_ocb_get_tsf_timer_callback, |
| 1420 | &request); |
| 1421 | if (QDF_IS_STATUS_ERROR(status)) { |
| 1422 | hdd_err("Error calling SME function."); |
| 1423 | rc = qdf_status_to_os_return(status); |
| 1424 | goto end; |
| 1425 | } |
| 1426 | |
| 1427 | rc = hdd_request_wait_for_response(hdd_request); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1428 | if (rc) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1429 | hdd_err("Operation timed out"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1430 | goto end; |
| 1431 | } |
| 1432 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1433 | priv = hdd_request_priv(hdd_request); |
| 1434 | rc = priv->status; |
| 1435 | if (rc) { |
| 1436 | hdd_err("Operation failed: %d", rc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1437 | goto end; |
| 1438 | } |
| 1439 | |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1440 | hdd_err("Got TSF timer response, high=%d, low=%d", |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1441 | priv->response.timer_high, |
| 1442 | priv->response.timer_low); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1443 | |
| 1444 | /* Send the response. */ |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1445 | rc = hdd_ocb_get_tsf_timer_reply(wiphy, &priv->response); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1446 | if (rc) { |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1447 | hdd_err("hdd_ocb_get_tsf_timer_reply failed: %d", rc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1448 | goto end; |
| 1449 | } |
| 1450 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1451 | /* fall through */ |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1452 | end: |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1453 | hdd_request_put(hdd_request); |
| 1454 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1455 | return rc; |
| 1456 | } |
| 1457 | |
| 1458 | /** |
| 1459 | * wlan_hdd_cfg80211_ocb_get_tsf_timer() - Interface for get TSF timer cmd |
| 1460 | * @wiphy: pointer to the wiphy |
| 1461 | * @wdev: pointer to the wdev |
| 1462 | * @data: The netlink data |
| 1463 | * @data_len: The length of the netlink data in bytes |
| 1464 | * |
| 1465 | * Return: 0 on success. |
| 1466 | */ |
| 1467 | int wlan_hdd_cfg80211_ocb_get_tsf_timer(struct wiphy *wiphy, |
| 1468 | struct wireless_dev *wdev, |
| 1469 | const void *data, |
| 1470 | int data_len) |
| 1471 | { |
| 1472 | int ret; |
| 1473 | |
| 1474 | cds_ssr_protect(__func__); |
| 1475 | ret = __wlan_hdd_cfg80211_ocb_get_tsf_timer(wiphy, wdev, |
| 1476 | data, data_len); |
| 1477 | cds_ssr_unprotect(__func__); |
| 1478 | |
| 1479 | return ret; |
| 1480 | } |
| 1481 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1482 | struct hdd_dcc_stats_priv { |
| 1483 | struct sir_dcc_get_stats_response *response; |
| 1484 | int status; |
| 1485 | }; |
| 1486 | |
| 1487 | static void hdd_dcc_get_stats_dealloc(void *context_ptr) |
| 1488 | { |
| 1489 | struct hdd_dcc_stats_priv *priv = context_ptr; |
| 1490 | |
| 1491 | qdf_mem_free(priv->response); |
| 1492 | priv->response = NULL; |
| 1493 | } |
| 1494 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1495 | /** |
| 1496 | * hdd_dcc_get_stats_callback() - Callback to get stats command |
| 1497 | * @context_ptr: request context |
| 1498 | * @response_ptr: response data |
| 1499 | */ |
| 1500 | static void hdd_dcc_get_stats_callback(void *context_ptr, void *response_ptr) |
| 1501 | { |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1502 | struct hdd_request *hdd_request; |
| 1503 | struct hdd_dcc_stats_priv *priv; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1504 | struct sir_dcc_get_stats_response *response = response_ptr; |
| 1505 | struct sir_dcc_get_stats_response *hdd_resp; |
| 1506 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1507 | hdd_request = hdd_request_get(context_ptr); |
| 1508 | if (!hdd_request) { |
| 1509 | hdd_err("Obsolete request"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1510 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1511 | } |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1512 | |
| 1513 | priv = hdd_request_priv(hdd_request); |
| 1514 | if (!response) { |
| 1515 | priv->status = -EINVAL; |
| 1516 | goto end; |
| 1517 | } |
| 1518 | |
| 1519 | priv->response = qdf_mem_malloc(sizeof(*response) + |
| 1520 | response->channel_stats_array_len); |
| 1521 | if (!priv->response) { |
| 1522 | priv->status = -ENOMEM; |
| 1523 | goto end; |
| 1524 | } |
| 1525 | |
| 1526 | hdd_resp = priv->response; |
| 1527 | *hdd_resp = *response; |
| 1528 | hdd_resp->channel_stats_array = (void *)hdd_resp + sizeof(*hdd_resp); |
| 1529 | qdf_mem_copy(hdd_resp->channel_stats_array, |
| 1530 | response->channel_stats_array, |
| 1531 | response->channel_stats_array_len); |
| 1532 | priv->status = 0; |
| 1533 | |
| 1534 | end: |
| 1535 | hdd_request_complete(hdd_request); |
| 1536 | hdd_request_put(hdd_request); |
| 1537 | } |
| 1538 | |
| 1539 | static int |
| 1540 | hdd_dcc_get_stats_send_reply(struct wiphy *wiphy, |
| 1541 | struct sir_dcc_get_stats_response *response) |
| 1542 | { |
| 1543 | uint32_t nl_buf_len; |
| 1544 | struct sk_buff *nl_resp; |
| 1545 | int rc; |
| 1546 | |
| 1547 | /* Allocate the buffer for the response. */ |
| 1548 | nl_buf_len = NLMSG_HDRLEN; |
| 1549 | nl_buf_len += NLA_HDRLEN + sizeof(uint32_t); |
| 1550 | nl_buf_len += NLA_HDRLEN + response->channel_stats_array_len; |
| 1551 | nl_resp = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, nl_buf_len); |
| 1552 | if (!nl_resp) { |
| 1553 | hdd_err("cfg80211_vendor_cmd_alloc_reply_skb failed"); |
| 1554 | return -ENOMEM; |
| 1555 | } |
| 1556 | |
| 1557 | /* Populate the response. */ |
| 1558 | rc = nla_put_u32(nl_resp, |
| 1559 | QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_CHANNEL_COUNT, |
| 1560 | response->num_channels); |
| 1561 | if (rc) |
| 1562 | goto end; |
| 1563 | rc = nla_put(nl_resp, |
| 1564 | QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_STATS_ARRAY, |
| 1565 | response->channel_stats_array_len, |
| 1566 | response->channel_stats_array); |
| 1567 | if (rc) |
| 1568 | goto end; |
| 1569 | |
| 1570 | /* Send the response. */ |
| 1571 | rc = cfg80211_vendor_cmd_reply(nl_resp); |
| 1572 | nl_resp = NULL; |
| 1573 | if (rc) { |
| 1574 | hdd_err("cfg80211_vendor_cmd_reply failed: %d", rc); |
| 1575 | goto end; |
| 1576 | } |
| 1577 | end: |
| 1578 | if (nl_resp) |
| 1579 | kfree_skb(nl_resp); |
| 1580 | |
| 1581 | return rc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | /** |
| 1585 | * __wlan_hdd_cfg80211_dcc_get_stats() - Interface for get dcc stats |
| 1586 | * @wiphy: pointer to the wiphy |
| 1587 | * @wdev: pointer to the wdev |
| 1588 | * @data: The netlink data |
| 1589 | * @data_len: The length of the netlink data in bytes |
| 1590 | * |
| 1591 | * Return: 0 on success. |
| 1592 | */ |
| 1593 | static int __wlan_hdd_cfg80211_dcc_get_stats(struct wiphy *wiphy, |
| 1594 | struct wireless_dev *wdev, |
| 1595 | const void *data, |
| 1596 | int data_len) |
| 1597 | { |
| 1598 | uint32_t channel_count = 0; |
| 1599 | uint32_t request_array_len = 0; |
| 1600 | void *request_array = 0; |
| 1601 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
| 1602 | struct net_device *dev = wdev->netdev; |
| 1603 | hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 1604 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_MAX + 1]; |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1605 | int rc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1606 | struct sir_dcc_get_stats request = {0}; |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1607 | QDF_STATUS status; |
| 1608 | void *cookie; |
| 1609 | struct hdd_request *hdd_request; |
| 1610 | struct hdd_dcc_stats_priv *priv; |
| 1611 | static const struct hdd_request_params params = { |
| 1612 | .priv_size = sizeof(*priv), |
| 1613 | .timeout_ms = WLAN_WAIT_TIME_OCB_CMD, |
| 1614 | .dealloc = hdd_dcc_get_stats_dealloc, |
| 1615 | }; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1616 | |
Jeff Johnson | 1f61b61 | 2016-02-12 16:28:33 -0800 | [diff] [blame] | 1617 | ENTER_DEV(dev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1618 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1619 | rc = wlan_hdd_validate_context(hdd_ctx); |
| 1620 | if (rc) |
| 1621 | return rc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1622 | |
Krunal Soni | be766b0 | 2016-03-10 13:00:44 -0800 | [diff] [blame] | 1623 | if (adapter->device_mode != QDF_OCB_MODE) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1624 | hdd_err("Device not in OCB mode!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1625 | return -EINVAL; |
| 1626 | } |
| 1627 | |
| 1628 | if (!wma_is_vdev_up(adapter->sessionId)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1629 | hdd_err("The device has not been started"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1630 | return -EINVAL; |
| 1631 | } |
| 1632 | |
| 1633 | /* Parse the netlink message */ |
| 1634 | if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_MAX, |
| 1635 | data, |
| 1636 | data_len, |
| 1637 | qca_wlan_vendor_dcc_get_stats)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1638 | hdd_err("Invalid ATTR"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1639 | return -EINVAL; |
| 1640 | } |
| 1641 | |
| 1642 | /* Validate all the parameters are present */ |
| 1643 | if (!tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_CHANNEL_COUNT] || |
| 1644 | !tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY]) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1645 | hdd_err("Parameters are not present."); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1646 | return -EINVAL; |
| 1647 | } |
| 1648 | |
| 1649 | channel_count = nla_get_u32( |
| 1650 | tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_CHANNEL_COUNT]); |
| 1651 | request_array_len = nla_len( |
| 1652 | tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY]); |
| 1653 | request_array = nla_data( |
| 1654 | tb[QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_REQUEST_ARRAY]); |
| 1655 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1656 | hdd_request = hdd_request_alloc(¶ms); |
| 1657 | if (!hdd_request) { |
| 1658 | hdd_err("Request allocation failure"); |
| 1659 | return -ENOMEM; |
| 1660 | } |
| 1661 | cookie = hdd_request_cookie(hdd_request); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1662 | |
| 1663 | request.vdev_id = adapter->sessionId; |
| 1664 | request.channel_count = channel_count; |
| 1665 | request.request_array_len = request_array_len; |
| 1666 | request.request_array = request_array; |
| 1667 | |
| 1668 | /* Call the SME function. */ |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1669 | status = sme_dcc_get_stats(hdd_ctx->hHal, cookie, |
| 1670 | hdd_dcc_get_stats_callback, |
| 1671 | &request); |
| 1672 | if (QDF_IS_STATUS_ERROR(status)) { |
| 1673 | hdd_err("Error calling SME function."); |
| 1674 | rc = qdf_status_to_os_return(status); |
| 1675 | goto end; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | /* Wait for the function to complete. */ |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1679 | rc = hdd_request_wait_for_response(hdd_request); |
| 1680 | if (rc) { |
| 1681 | hdd_err("Operation timed out"); |
| 1682 | goto end; |
| 1683 | } |
| 1684 | |
| 1685 | priv = hdd_request_priv(hdd_request); |
| 1686 | rc = priv->status; |
| 1687 | if (rc) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1688 | hdd_err("Operation failed: %d", rc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1689 | goto end; |
| 1690 | } |
| 1691 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1692 | /* Send the response. */ |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1693 | rc = hdd_dcc_get_stats_send_reply(wiphy, priv->response); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1694 | if (rc) { |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1695 | hdd_err("hdd_dcc_get_stats_send_reply failed: %d", rc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1696 | goto end; |
| 1697 | } |
| 1698 | |
| 1699 | /* fall through */ |
| 1700 | end: |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1701 | hdd_request_put(hdd_request); |
| 1702 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1703 | return rc; |
| 1704 | } |
| 1705 | |
| 1706 | /** |
| 1707 | * wlan_hdd_cfg80211_dcc_get_stats() - Interface for get dcc stats |
| 1708 | * @wiphy: pointer to the wiphy |
| 1709 | * @wdev: pointer to the wdev |
| 1710 | * @data: The netlink data |
| 1711 | * @data_len: The length of the netlink data in bytes |
| 1712 | * |
| 1713 | * Return: 0 on success. |
| 1714 | */ |
| 1715 | int wlan_hdd_cfg80211_dcc_get_stats(struct wiphy *wiphy, |
| 1716 | struct wireless_dev *wdev, |
| 1717 | const void *data, |
| 1718 | int data_len) |
| 1719 | { |
| 1720 | int ret; |
| 1721 | |
| 1722 | cds_ssr_protect(__func__); |
| 1723 | ret = __wlan_hdd_cfg80211_dcc_get_stats(wiphy, wdev, |
| 1724 | data, data_len); |
| 1725 | cds_ssr_unprotect(__func__); |
| 1726 | |
| 1727 | return ret; |
| 1728 | } |
| 1729 | |
| 1730 | /** |
| 1731 | * __wlan_hdd_cfg80211_dcc_clear_stats() - Interface for clear dcc stats cmd |
| 1732 | * @wiphy: pointer to the wiphy |
| 1733 | * @wdev: pointer to the wdev |
| 1734 | * @data: The netlink data |
| 1735 | * @data_len: The length of the netlink data in bytes |
| 1736 | * |
| 1737 | * Return: 0 on success. |
| 1738 | */ |
| 1739 | static int __wlan_hdd_cfg80211_dcc_clear_stats(struct wiphy *wiphy, |
| 1740 | struct wireless_dev *wdev, |
| 1741 | const void *data, |
| 1742 | int data_len) |
| 1743 | { |
| 1744 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
| 1745 | struct net_device *dev = wdev->netdev; |
| 1746 | hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 1747 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_MAX + 1]; |
| 1748 | |
Jeff Johnson | 1f61b61 | 2016-02-12 16:28:33 -0800 | [diff] [blame] | 1749 | ENTER_DEV(dev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1750 | |
Abhishek Singh | 23edd1c | 2016-05-05 11:56:06 +0530 | [diff] [blame] | 1751 | if (wlan_hdd_validate_context(hdd_ctx)) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1752 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1753 | |
Krunal Soni | be766b0 | 2016-03-10 13:00:44 -0800 | [diff] [blame] | 1754 | if (adapter->device_mode != QDF_OCB_MODE) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1755 | hdd_err("Device not in OCB mode!"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1756 | return -EINVAL; |
| 1757 | } |
| 1758 | |
| 1759 | if (!wma_is_vdev_up(adapter->sessionId)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1760 | hdd_err("The device has not been started"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1761 | return -EINVAL; |
| 1762 | } |
| 1763 | |
| 1764 | /* Parse the netlink message */ |
| 1765 | if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_MAX, |
| 1766 | data, |
| 1767 | data_len, |
| 1768 | qca_wlan_vendor_dcc_clear_stats)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1769 | hdd_err("Invalid ATTR"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1770 | return -EINVAL; |
| 1771 | } |
| 1772 | |
| 1773 | /* Verify that the parameter is present */ |
| 1774 | if (!tb[QCA_WLAN_VENDOR_ATTR_DCC_CLEAR_STATS_BITMAP]) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1775 | hdd_err("Parameters are not present."); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1776 | 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 Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 1783 | QDF_STATUS_SUCCESS) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1784 | hdd_err("Error calling SME function."); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1785 | 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 | */ |
| 1800 | int 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 Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1815 | struct hdd_dcc_update_ndl_priv { |
| 1816 | int status; |
| 1817 | }; |
| 1818 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1819 | /** |
| 1820 | * hdd_dcc_update_ndl_callback() - Callback to update NDL command |
| 1821 | * @context_ptr: request context |
| 1822 | * @response_ptr: response data |
| 1823 | */ |
| 1824 | static void hdd_dcc_update_ndl_callback(void *context_ptr, void *response_ptr) |
| 1825 | { |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1826 | struct hdd_request *hdd_request; |
| 1827 | struct hdd_dcc_update_ndl_priv *priv; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1828 | struct sir_dcc_update_ndl_response *response = response_ptr; |
| 1829 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1830 | hdd_request = hdd_request_get(context_ptr); |
| 1831 | if (!hdd_request) { |
| 1832 | hdd_err("Obsolete request"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1833 | return; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1834 | } |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1835 | 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 Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1843 | } |
| 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 | */ |
| 1854 | static int __wlan_hdd_cfg80211_dcc_update_ndl(struct wiphy *wiphy, |
| 1855 | struct wireless_dev *wdev, |
| 1856 | const void *data, |
| 1857 | int data_len) |
| 1858 | { |
| 1859 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
| 1860 | struct net_device *dev = wdev->netdev; |
| 1861 | hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 1862 | 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 Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1869 | 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 Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1878 | |
Jeff Johnson | 1f61b61 | 2016-02-12 16:28:33 -0800 | [diff] [blame] | 1879 | ENTER_DEV(dev); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1880 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1881 | rc = wlan_hdd_validate_context(hdd_ctx); |
| 1882 | if (rc) |
| 1883 | return rc; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1884 | |
Krunal Soni | be766b0 | 2016-03-10 13:00:44 -0800 | [diff] [blame] | 1885 | if (adapter->device_mode != QDF_OCB_MODE) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1886 | hdd_err("Device not in OCB mode!"); |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1887 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | if (!wma_is_vdev_up(adapter->sessionId)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1891 | hdd_err("The device has not been started"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1892 | return -EINVAL; |
| 1893 | } |
| 1894 | |
| 1895 | /* Parse the netlink message */ |
| 1896 | if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_MAX, |
| 1897 | data, |
| 1898 | data_len, |
| 1899 | qca_wlan_vendor_dcc_update_ndl)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1900 | hdd_err("Invalid ATTR"); |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1901 | return -EINVAL; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | /* Verify that the parameter is present */ |
| 1905 | if (!tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_COUNT] || |
| 1906 | !tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY] || |
| 1907 | !tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY]) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1908 | hdd_err("Parameters are not present."); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1909 | return -EINVAL; |
| 1910 | } |
| 1911 | |
| 1912 | channel_count = nla_get_u32( |
| 1913 | tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_COUNT]); |
| 1914 | ndl_channel_array_len = nla_len( |
| 1915 | tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY]); |
| 1916 | ndl_channel_array = nla_data( |
| 1917 | tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_CHANNEL_ARRAY]); |
| 1918 | ndl_active_state_array_len = nla_len( |
| 1919 | tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY]); |
| 1920 | ndl_active_state_array = nla_data( |
| 1921 | tb[QCA_WLAN_VENDOR_ATTR_DCC_UPDATE_NDL_ACTIVE_STATE_ARRAY]); |
| 1922 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1923 | hdd_request = hdd_request_alloc(¶ms); |
| 1924 | if (!hdd_request) { |
| 1925 | hdd_err("Request allocation failure"); |
| 1926 | return -ENOMEM; |
| 1927 | } |
| 1928 | cookie = hdd_request_cookie(hdd_request); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1929 | |
| 1930 | /* Copy the parameters to the request structure. */ |
| 1931 | request.vdev_id = adapter->sessionId; |
| 1932 | request.channel_count = channel_count; |
| 1933 | request.dcc_ndl_chan_list_len = ndl_channel_array_len; |
| 1934 | request.dcc_ndl_chan_list = ndl_channel_array; |
| 1935 | request.dcc_ndl_active_state_list_len = ndl_active_state_array_len; |
| 1936 | request.dcc_ndl_active_state_list = ndl_active_state_array; |
| 1937 | |
| 1938 | /* Call the SME function */ |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1939 | status = sme_dcc_update_ndl(hdd_ctx->hHal, cookie, |
| 1940 | hdd_dcc_update_ndl_callback, |
| 1941 | &request); |
| 1942 | if (QDF_IS_STATUS_ERROR(status)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1943 | hdd_err("Error calling SME function."); |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1944 | rc = qdf_status_to_os_return(status); |
| 1945 | goto end; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | /* Wait for the function to complete. */ |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1949 | rc = hdd_request_wait_for_response(hdd_request); |
| 1950 | if (rc) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 1951 | hdd_err("Operation timed out"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1952 | goto end; |
| 1953 | } |
| 1954 | |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1955 | priv = hdd_request_priv(hdd_request); |
| 1956 | rc = priv->status; |
| 1957 | if (rc) { |
| 1958 | hdd_err("Operation failed: %d", rc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1959 | goto end; |
| 1960 | } |
| 1961 | |
| 1962 | /* fall through */ |
| 1963 | end: |
Jeff Johnson | 7af334b | 2017-02-01 13:03:43 -0800 | [diff] [blame] | 1964 | hdd_request_put(hdd_request); |
| 1965 | |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1966 | return rc; |
| 1967 | } |
| 1968 | |
| 1969 | /** |
| 1970 | * wlan_hdd_cfg80211_dcc_update_ndl() - Interface for update dcc cmd |
| 1971 | * @wiphy: pointer to the wiphy |
| 1972 | * @wdev: pointer to the wdev |
| 1973 | * @data: The netlink data |
| 1974 | * @data_len: The length of the netlink data in bytes |
| 1975 | * |
| 1976 | * Return: 0 on success. |
| 1977 | */ |
| 1978 | int wlan_hdd_cfg80211_dcc_update_ndl(struct wiphy *wiphy, |
| 1979 | struct wireless_dev *wdev, |
| 1980 | const void *data, |
| 1981 | int data_len) |
| 1982 | { |
| 1983 | int ret; |
| 1984 | |
| 1985 | cds_ssr_protect(__func__); |
| 1986 | ret = __wlan_hdd_cfg80211_dcc_update_ndl(wiphy, wdev, |
| 1987 | data, data_len); |
| 1988 | cds_ssr_unprotect(__func__); |
| 1989 | |
| 1990 | return ret; |
| 1991 | } |
| 1992 | |
| 1993 | /** |
| 1994 | * wlan_hdd_dcc_stats_event_callback() - Callback to get stats event |
| 1995 | * @context_ptr: request context |
| 1996 | * @response_ptr: response data |
| 1997 | */ |
| 1998 | static void wlan_hdd_dcc_stats_event_callback(void *context_ptr, |
| 1999 | void *response_ptr) |
| 2000 | { |
| 2001 | hdd_context_t *hdd_ctx = (hdd_context_t *)context_ptr; |
| 2002 | struct sir_dcc_get_stats_response *resp = response_ptr; |
| 2003 | struct sk_buff *vendor_event; |
| 2004 | |
| 2005 | ENTER(); |
| 2006 | |
| 2007 | vendor_event = |
| 2008 | cfg80211_vendor_event_alloc(hdd_ctx->wiphy, |
| 2009 | NULL, sizeof(uint32_t) + resp->channel_stats_array_len + |
| 2010 | NLMSG_HDRLEN, |
| 2011 | QCA_NL80211_VENDOR_SUBCMD_DCC_STATS_EVENT_INDEX, |
| 2012 | GFP_KERNEL); |
| 2013 | |
| 2014 | if (!vendor_event) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 2015 | hdd_err("cfg80211_vendor_event_alloc failed"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2016 | return; |
| 2017 | } |
| 2018 | |
| 2019 | if (nla_put_u32(vendor_event, |
| 2020 | QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_CHANNEL_COUNT, |
| 2021 | resp->num_channels) || |
| 2022 | nla_put(vendor_event, |
| 2023 | QCA_WLAN_VENDOR_ATTR_DCC_GET_STATS_RESP_STATS_ARRAY, |
| 2024 | resp->channel_stats_array_len, |
| 2025 | resp->channel_stats_array)) { |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 2026 | hdd_err("nla put failed"); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2027 | kfree_skb(vendor_event); |
| 2028 | return; |
| 2029 | } |
| 2030 | |
| 2031 | cfg80211_vendor_event(vendor_event, GFP_KERNEL); |
| 2032 | } |
| 2033 | |
| 2034 | /** |
| 2035 | * wlan_hdd_dcc_register_for_dcc_stats_event() - Register for dcc stats events |
| 2036 | * @hdd_ctx: hdd context |
| 2037 | */ |
| 2038 | void wlan_hdd_dcc_register_for_dcc_stats_event(hdd_context_t *hdd_ctx) |
| 2039 | { |
| 2040 | int rc; |
| 2041 | |
| 2042 | rc = sme_register_for_dcc_stats_event(hdd_ctx->hHal, hdd_ctx, |
Arun Khandavalli | 4b55da7 | 2016-07-19 19:55:01 +0530 | [diff] [blame] | 2043 | wlan_hdd_dcc_stats_event_callback); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2044 | if (rc) |
Jeff Johnson | 5f735d5 | 2016-07-06 15:14:45 -0700 | [diff] [blame] | 2045 | hdd_err("Register callback failed: %d", rc); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 2046 | } |