Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: association and ad-hoc start/join |
| 3 | * |
| 4 | * Copyright (C) 2011, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include "decl.h" |
| 21 | #include "ioctl.h" |
| 22 | #include "util.h" |
| 23 | #include "fw.h" |
| 24 | #include "main.h" |
| 25 | #include "wmm.h" |
| 26 | #include "11n.h" |
| 27 | |
| 28 | #define CAPINFO_MASK (~(BIT(15) | BIT(14) | BIT(12) | BIT(11) | BIT(9))) |
| 29 | |
| 30 | /* |
| 31 | * Append a generic IE as a pass through TLV to a TLV buffer. |
| 32 | * |
| 33 | * This function is called from the network join command preparation routine. |
| 34 | * |
| 35 | * If the IE buffer has been setup by the application, this routine appends |
| 36 | * the buffer as a pass through TLV type to the request. |
| 37 | */ |
| 38 | static int |
| 39 | mwifiex_cmd_append_generic_ie(struct mwifiex_private *priv, u8 **buffer) |
| 40 | { |
| 41 | int ret_len = 0; |
| 42 | struct mwifiex_ie_types_header ie_header; |
| 43 | |
| 44 | /* Null Checks */ |
| 45 | if (!buffer) |
| 46 | return 0; |
| 47 | if (!(*buffer)) |
| 48 | return 0; |
| 49 | |
| 50 | /* |
| 51 | * If there is a generic ie buffer setup, append it to the return |
| 52 | * parameter buffer pointer. |
| 53 | */ |
| 54 | if (priv->gen_ie_buf_len) { |
| 55 | dev_dbg(priv->adapter->dev, "info: %s: append generic %d to %p\n", |
| 56 | __func__, priv->gen_ie_buf_len, *buffer); |
| 57 | |
| 58 | /* Wrap the generic IE buffer with a pass through TLV type */ |
| 59 | ie_header.type = cpu_to_le16(TLV_TYPE_PASSTHROUGH); |
| 60 | ie_header.len = cpu_to_le16(priv->gen_ie_buf_len); |
| 61 | memcpy(*buffer, &ie_header, sizeof(ie_header)); |
| 62 | |
| 63 | /* Increment the return size and the return buffer pointer |
| 64 | param */ |
| 65 | *buffer += sizeof(ie_header); |
| 66 | ret_len += sizeof(ie_header); |
| 67 | |
| 68 | /* Copy the generic IE buffer to the output buffer, advance |
| 69 | pointer */ |
| 70 | memcpy(*buffer, priv->gen_ie_buf, priv->gen_ie_buf_len); |
| 71 | |
| 72 | /* Increment the return size and the return buffer pointer |
| 73 | param */ |
| 74 | *buffer += priv->gen_ie_buf_len; |
| 75 | ret_len += priv->gen_ie_buf_len; |
| 76 | |
| 77 | /* Reset the generic IE buffer */ |
| 78 | priv->gen_ie_buf_len = 0; |
| 79 | } |
| 80 | |
| 81 | /* return the length appended to the buffer */ |
| 82 | return ret_len; |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | * Append TSF tracking info from the scan table for the target AP. |
| 87 | * |
| 88 | * This function is called from the network join command preparation routine. |
| 89 | * |
| 90 | * The TSF table TSF sent to the firmware contains two TSF values: |
| 91 | * - The TSF of the target AP from its previous beacon/probe response |
| 92 | * - The TSF timestamp of our local MAC at the time we observed the |
| 93 | * beacon/probe response. |
| 94 | * |
| 95 | * The firmware uses the timestamp values to set an initial TSF value |
| 96 | * in the MAC for the new association after a reassociation attempt. |
| 97 | */ |
| 98 | static int |
| 99 | mwifiex_cmd_append_tsf_tlv(struct mwifiex_private *priv, u8 **buffer, |
| 100 | struct mwifiex_bssdescriptor *bss_desc) |
| 101 | { |
| 102 | struct mwifiex_ie_types_tsf_timestamp tsf_tlv; |
Bing Zhao | 1a5b306 | 2011-05-02 11:00:45 -0700 | [diff] [blame] | 103 | __le64 tsf_val; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 104 | |
| 105 | /* Null Checks */ |
| 106 | if (buffer == NULL) |
| 107 | return 0; |
| 108 | if (*buffer == NULL) |
| 109 | return 0; |
| 110 | |
| 111 | memset(&tsf_tlv, 0x00, sizeof(struct mwifiex_ie_types_tsf_timestamp)); |
| 112 | |
| 113 | tsf_tlv.header.type = cpu_to_le16(TLV_TYPE_TSFTIMESTAMP); |
| 114 | tsf_tlv.header.len = cpu_to_le16(2 * sizeof(tsf_val)); |
| 115 | |
| 116 | memcpy(*buffer, &tsf_tlv, sizeof(tsf_tlv.header)); |
| 117 | *buffer += sizeof(tsf_tlv.header); |
| 118 | |
Bing Zhao | 1a5b306 | 2011-05-02 11:00:45 -0700 | [diff] [blame] | 119 | /* TSF at the time when beacon/probe_response was received */ |
| 120 | tsf_val = cpu_to_le64(bss_desc->network_tsf); |
| 121 | memcpy(*buffer, &tsf_val, sizeof(tsf_val)); |
| 122 | *buffer += sizeof(tsf_val); |
| 123 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 124 | memcpy(&tsf_val, bss_desc->time_stamp, sizeof(tsf_val)); |
| 125 | |
| 126 | dev_dbg(priv->adapter->dev, "info: %s: TSF offset calc: %016llx - " |
| 127 | "%016llx\n", __func__, tsf_val, bss_desc->network_tsf); |
| 128 | |
| 129 | memcpy(*buffer, &tsf_val, sizeof(tsf_val)); |
| 130 | *buffer += sizeof(tsf_val); |
| 131 | |
| 132 | return sizeof(tsf_tlv.header) + (2 * sizeof(tsf_val)); |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * This function finds out the common rates between rate1 and rate2. |
| 137 | * |
| 138 | * It will fill common rates in rate1 as output if found. |
| 139 | * |
| 140 | * NOTE: Setting the MSB of the basic rates needs to be taken |
| 141 | * care of, either before or after calling this function. |
| 142 | */ |
| 143 | static int mwifiex_get_common_rates(struct mwifiex_private *priv, u8 *rate1, |
| 144 | u32 rate1_size, u8 *rate2, u32 rate2_size) |
| 145 | { |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 146 | int ret; |
| 147 | u8 *ptr = rate1, *tmp; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 148 | u32 i, j; |
| 149 | |
Yogesh Ashok Powar | 5982b47 | 2011-08-29 13:21:10 -0700 | [diff] [blame] | 150 | tmp = kmemdup(rate1, rate1_size, GFP_KERNEL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 151 | if (!tmp) { |
| 152 | dev_err(priv->adapter->dev, "failed to alloc tmp buf\n"); |
| 153 | return -ENOMEM; |
| 154 | } |
| 155 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 156 | memset(rate1, 0, rate1_size); |
| 157 | |
| 158 | for (i = 0; rate2[i] && i < rate2_size; i++) { |
| 159 | for (j = 0; tmp[j] && j < rate1_size; j++) { |
| 160 | /* Check common rate, excluding the bit for |
| 161 | basic rate */ |
| 162 | if ((rate2[i] & 0x7F) == (tmp[j] & 0x7F)) { |
| 163 | *rate1++ = tmp[j]; |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | dev_dbg(priv->adapter->dev, "info: Tx data rate set to %#x\n", |
| 170 | priv->data_rate); |
| 171 | |
| 172 | if (!priv->is_data_rate_auto) { |
| 173 | while (*ptr) { |
| 174 | if ((*ptr & 0x7f) == priv->data_rate) { |
| 175 | ret = 0; |
| 176 | goto done; |
| 177 | } |
| 178 | ptr++; |
| 179 | } |
| 180 | dev_err(priv->adapter->dev, "previously set fixed data rate %#x" |
| 181 | " is not compatible with the network\n", |
| 182 | priv->data_rate); |
| 183 | |
| 184 | ret = -1; |
| 185 | goto done; |
| 186 | } |
| 187 | |
| 188 | ret = 0; |
| 189 | done: |
| 190 | kfree(tmp); |
| 191 | return ret; |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | * This function creates the intersection of the rates supported by a |
| 196 | * target BSS and our adapter settings for use in an assoc/join command. |
| 197 | */ |
| 198 | static int |
| 199 | mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv, |
| 200 | struct mwifiex_bssdescriptor *bss_desc, |
| 201 | u8 *out_rates, u32 *out_rates_size) |
| 202 | { |
| 203 | u8 card_rates[MWIFIEX_SUPPORTED_RATES]; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 204 | u32 card_rates_size; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 205 | |
| 206 | /* Copy AP supported rates */ |
| 207 | memcpy(out_rates, bss_desc->supported_rates, MWIFIEX_SUPPORTED_RATES); |
| 208 | /* Get the STA supported rates */ |
| 209 | card_rates_size = mwifiex_get_active_data_rates(priv, card_rates); |
| 210 | /* Get the common rates between AP and STA supported rates */ |
| 211 | if (mwifiex_get_common_rates(priv, out_rates, MWIFIEX_SUPPORTED_RATES, |
| 212 | card_rates, card_rates_size)) { |
| 213 | *out_rates_size = 0; |
| 214 | dev_err(priv->adapter->dev, "%s: cannot get common rates\n", |
| 215 | __func__); |
| 216 | return -1; |
| 217 | } |
| 218 | |
| 219 | *out_rates_size = |
| 220 | min_t(size_t, strlen(out_rates), MWIFIEX_SUPPORTED_RATES); |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 226 | * This function appends a WAPI IE. |
| 227 | * |
| 228 | * This function is called from the network join command preparation routine. |
| 229 | * |
| 230 | * If the IE buffer has been setup by the application, this routine appends |
| 231 | * the buffer as a WAPI TLV type to the request. |
| 232 | */ |
| 233 | static int |
| 234 | mwifiex_cmd_append_wapi_ie(struct mwifiex_private *priv, u8 **buffer) |
| 235 | { |
| 236 | int retLen = 0; |
| 237 | struct mwifiex_ie_types_header ie_header; |
| 238 | |
| 239 | /* Null Checks */ |
| 240 | if (buffer == NULL) |
| 241 | return 0; |
| 242 | if (*buffer == NULL) |
| 243 | return 0; |
| 244 | |
| 245 | /* |
| 246 | * If there is a wapi ie buffer setup, append it to the return |
| 247 | * parameter buffer pointer. |
| 248 | */ |
| 249 | if (priv->wapi_ie_len) { |
| 250 | dev_dbg(priv->adapter->dev, "cmd: append wapi ie %d to %p\n", |
| 251 | priv->wapi_ie_len, *buffer); |
| 252 | |
| 253 | /* Wrap the generic IE buffer with a pass through TLV type */ |
| 254 | ie_header.type = cpu_to_le16(TLV_TYPE_WAPI_IE); |
| 255 | ie_header.len = cpu_to_le16(priv->wapi_ie_len); |
| 256 | memcpy(*buffer, &ie_header, sizeof(ie_header)); |
| 257 | |
| 258 | /* Increment the return size and the return buffer pointer |
| 259 | param */ |
| 260 | *buffer += sizeof(ie_header); |
| 261 | retLen += sizeof(ie_header); |
| 262 | |
| 263 | /* Copy the wapi IE buffer to the output buffer, advance |
| 264 | pointer */ |
| 265 | memcpy(*buffer, priv->wapi_ie, priv->wapi_ie_len); |
| 266 | |
| 267 | /* Increment the return size and the return buffer pointer |
| 268 | param */ |
| 269 | *buffer += priv->wapi_ie_len; |
| 270 | retLen += priv->wapi_ie_len; |
| 271 | |
| 272 | } |
| 273 | /* return the length appended to the buffer */ |
| 274 | return retLen; |
| 275 | } |
| 276 | |
| 277 | /* |
| 278 | * This function appends rsn ie tlv for wpa/wpa2 security modes. |
| 279 | * It is called from the network join command preparation routine. |
| 280 | */ |
| 281 | static int mwifiex_append_rsn_ie_wpa_wpa2(struct mwifiex_private *priv, |
| 282 | u8 **buffer) |
| 283 | { |
| 284 | struct mwifiex_ie_types_rsn_param_set *rsn_ie_tlv; |
| 285 | int rsn_ie_len; |
| 286 | |
| 287 | if (!buffer || !(*buffer)) |
| 288 | return 0; |
| 289 | |
| 290 | rsn_ie_tlv = (struct mwifiex_ie_types_rsn_param_set *) (*buffer); |
| 291 | rsn_ie_tlv->header.type = cpu_to_le16((u16) priv->wpa_ie[0]); |
| 292 | rsn_ie_tlv->header.type = cpu_to_le16( |
| 293 | le16_to_cpu(rsn_ie_tlv->header.type) & 0x00FF); |
| 294 | rsn_ie_tlv->header.len = cpu_to_le16((u16) priv->wpa_ie[1]); |
| 295 | rsn_ie_tlv->header.len = cpu_to_le16(le16_to_cpu(rsn_ie_tlv->header.len) |
| 296 | & 0x00FF); |
| 297 | if (le16_to_cpu(rsn_ie_tlv->header.len) <= (sizeof(priv->wpa_ie) - 2)) |
| 298 | memcpy(rsn_ie_tlv->rsn_ie, &priv->wpa_ie[2], |
| 299 | le16_to_cpu(rsn_ie_tlv->header.len)); |
| 300 | else |
| 301 | return -1; |
| 302 | |
| 303 | rsn_ie_len = sizeof(rsn_ie_tlv->header) + |
| 304 | le16_to_cpu(rsn_ie_tlv->header.len); |
| 305 | *buffer += rsn_ie_len; |
| 306 | |
| 307 | return rsn_ie_len; |
| 308 | } |
| 309 | |
| 310 | /* |
| 311 | * This function prepares command for association. |
| 312 | * |
| 313 | * This sets the following parameters - |
| 314 | * - Peer MAC address |
| 315 | * - Listen interval |
| 316 | * - Beacon interval |
| 317 | * - Capability information |
| 318 | * |
| 319 | * ...and the following TLVs, as required - |
| 320 | * - SSID TLV |
| 321 | * - PHY TLV |
| 322 | * - SS TLV |
| 323 | * - Rates TLV |
| 324 | * - Authentication TLV |
| 325 | * - Channel TLV |
| 326 | * - WPA/WPA2 IE |
| 327 | * - 11n TLV |
| 328 | * - Vendor specific TLV |
| 329 | * - WMM TLV |
| 330 | * - WAPI IE |
| 331 | * - Generic IE |
| 332 | * - TSF TLV |
| 333 | * |
| 334 | * Preparation also includes - |
| 335 | * - Setting command ID and proper size |
| 336 | * - Ensuring correct endian-ness |
| 337 | */ |
| 338 | int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv, |
| 339 | struct host_cmd_ds_command *cmd, |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 340 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 341 | { |
| 342 | struct host_cmd_ds_802_11_associate *assoc = &cmd->params.associate; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 343 | struct mwifiex_ie_types_ssid_param_set *ssid_tlv; |
| 344 | struct mwifiex_ie_types_phy_param_set *phy_tlv; |
| 345 | struct mwifiex_ie_types_ss_param_set *ss_tlv; |
| 346 | struct mwifiex_ie_types_rates_param_set *rates_tlv; |
| 347 | struct mwifiex_ie_types_auth_type *auth_tlv; |
| 348 | struct mwifiex_ie_types_chan_list_param_set *chan_tlv; |
| 349 | u8 rates[MWIFIEX_SUPPORTED_RATES]; |
| 350 | u32 rates_size; |
| 351 | u16 tmp_cap; |
| 352 | u8 *pos; |
| 353 | int rsn_ie_len = 0; |
| 354 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 355 | pos = (u8 *) assoc; |
| 356 | |
| 357 | mwifiex_cfg_tx_buf(priv, bss_desc); |
| 358 | |
| 359 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_ASSOCIATE); |
| 360 | |
| 361 | /* Save so we know which BSS Desc to use in the response handler */ |
| 362 | priv->attempted_bss_desc = bss_desc; |
| 363 | |
| 364 | memcpy(assoc->peer_sta_addr, |
| 365 | bss_desc->mac_address, sizeof(assoc->peer_sta_addr)); |
| 366 | pos += sizeof(assoc->peer_sta_addr); |
| 367 | |
| 368 | /* Set the listen interval */ |
| 369 | assoc->listen_interval = cpu_to_le16(priv->listen_interval); |
| 370 | /* Set the beacon period */ |
| 371 | assoc->beacon_period = cpu_to_le16(bss_desc->beacon_period); |
| 372 | |
| 373 | pos += sizeof(assoc->cap_info_bitmap); |
| 374 | pos += sizeof(assoc->listen_interval); |
| 375 | pos += sizeof(assoc->beacon_period); |
| 376 | pos += sizeof(assoc->dtim_period); |
| 377 | |
| 378 | ssid_tlv = (struct mwifiex_ie_types_ssid_param_set *) pos; |
| 379 | ssid_tlv->header.type = cpu_to_le16(WLAN_EID_SSID); |
| 380 | ssid_tlv->header.len = cpu_to_le16((u16) bss_desc->ssid.ssid_len); |
| 381 | memcpy(ssid_tlv->ssid, bss_desc->ssid.ssid, |
| 382 | le16_to_cpu(ssid_tlv->header.len)); |
| 383 | pos += sizeof(ssid_tlv->header) + le16_to_cpu(ssid_tlv->header.len); |
| 384 | |
| 385 | phy_tlv = (struct mwifiex_ie_types_phy_param_set *) pos; |
| 386 | phy_tlv->header.type = cpu_to_le16(WLAN_EID_DS_PARAMS); |
| 387 | phy_tlv->header.len = cpu_to_le16(sizeof(phy_tlv->fh_ds.ds_param_set)); |
| 388 | memcpy(&phy_tlv->fh_ds.ds_param_set, |
| 389 | &bss_desc->phy_param_set.ds_param_set.current_chan, |
| 390 | sizeof(phy_tlv->fh_ds.ds_param_set)); |
| 391 | pos += sizeof(phy_tlv->header) + le16_to_cpu(phy_tlv->header.len); |
| 392 | |
| 393 | ss_tlv = (struct mwifiex_ie_types_ss_param_set *) pos; |
| 394 | ss_tlv->header.type = cpu_to_le16(WLAN_EID_CF_PARAMS); |
| 395 | ss_tlv->header.len = cpu_to_le16(sizeof(ss_tlv->cf_ibss.cf_param_set)); |
| 396 | pos += sizeof(ss_tlv->header) + le16_to_cpu(ss_tlv->header.len); |
| 397 | |
| 398 | /* Get the common rates supported between the driver and the BSS Desc */ |
| 399 | if (mwifiex_setup_rates_from_bssdesc |
| 400 | (priv, bss_desc, rates, &rates_size)) |
| 401 | return -1; |
| 402 | |
| 403 | /* Save the data rates into Current BSS state structure */ |
| 404 | priv->curr_bss_params.num_of_rates = rates_size; |
| 405 | memcpy(&priv->curr_bss_params.data_rates, rates, rates_size); |
| 406 | |
| 407 | /* Setup the Rates TLV in the association command */ |
| 408 | rates_tlv = (struct mwifiex_ie_types_rates_param_set *) pos; |
| 409 | rates_tlv->header.type = cpu_to_le16(WLAN_EID_SUPP_RATES); |
| 410 | rates_tlv->header.len = cpu_to_le16((u16) rates_size); |
| 411 | memcpy(rates_tlv->rates, rates, rates_size); |
| 412 | pos += sizeof(rates_tlv->header) + rates_size; |
| 413 | dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: rates size = %d\n", |
| 414 | rates_size); |
| 415 | |
Marc Yang | 203afec | 2011-03-24 20:49:39 -0700 | [diff] [blame] | 416 | /* Add the Authentication type to be used for Auth frames */ |
| 417 | auth_tlv = (struct mwifiex_ie_types_auth_type *) pos; |
| 418 | auth_tlv->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE); |
| 419 | auth_tlv->header.len = cpu_to_le16(sizeof(auth_tlv->auth_type)); |
Amitkumar Karwar | 5eb02e4 | 2012-02-24 21:36:04 -0800 | [diff] [blame^] | 420 | if (priv->sec_info.wep_enabled) |
Marc Yang | 203afec | 2011-03-24 20:49:39 -0700 | [diff] [blame] | 421 | auth_tlv->auth_type = cpu_to_le16( |
| 422 | (u16) priv->sec_info.authentication_mode); |
| 423 | else |
Marc Yang | f986b6d | 2011-03-28 17:55:42 -0700 | [diff] [blame] | 424 | auth_tlv->auth_type = cpu_to_le16(NL80211_AUTHTYPE_OPEN_SYSTEM); |
Marc Yang | 203afec | 2011-03-24 20:49:39 -0700 | [diff] [blame] | 425 | |
| 426 | pos += sizeof(auth_tlv->header) + le16_to_cpu(auth_tlv->header.len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 427 | |
| 428 | if (IS_SUPPORT_MULTI_BANDS(priv->adapter) |
| 429 | && !(ISSUPP_11NENABLED(priv->adapter->fw_cap_info) |
| 430 | && (!bss_desc->disable_11n) |
| 431 | && (priv->adapter->config_bands & BAND_GN |
| 432 | || priv->adapter->config_bands & BAND_AN) |
| 433 | && (bss_desc->bcn_ht_cap) |
| 434 | ) |
| 435 | ) { |
| 436 | /* Append a channel TLV for the channel the attempted AP was |
| 437 | found on */ |
| 438 | chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos; |
| 439 | chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); |
| 440 | chan_tlv->header.len = |
| 441 | cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set)); |
| 442 | |
| 443 | memset(chan_tlv->chan_scan_param, 0x00, |
| 444 | sizeof(struct mwifiex_chan_scan_param_set)); |
| 445 | chan_tlv->chan_scan_param[0].chan_number = |
| 446 | (bss_desc->phy_param_set.ds_param_set.current_chan); |
| 447 | dev_dbg(priv->adapter->dev, "info: Assoc: TLV Chan = %d\n", |
| 448 | chan_tlv->chan_scan_param[0].chan_number); |
| 449 | |
| 450 | chan_tlv->chan_scan_param[0].radio_type = |
| 451 | mwifiex_band_to_radio_type((u8) bss_desc->bss_band); |
| 452 | |
| 453 | dev_dbg(priv->adapter->dev, "info: Assoc: TLV Band = %d\n", |
| 454 | chan_tlv->chan_scan_param[0].radio_type); |
| 455 | pos += sizeof(chan_tlv->header) + |
| 456 | sizeof(struct mwifiex_chan_scan_param_set); |
| 457 | } |
| 458 | |
| 459 | if (!priv->wps.session_enable) { |
| 460 | if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled) |
| 461 | rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos); |
| 462 | |
| 463 | if (rsn_ie_len == -1) |
| 464 | return -1; |
| 465 | } |
| 466 | |
| 467 | if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info) |
| 468 | && (!bss_desc->disable_11n) |
| 469 | && (priv->adapter->config_bands & BAND_GN |
| 470 | || priv->adapter->config_bands & BAND_AN)) |
| 471 | mwifiex_cmd_append_11n_tlv(priv, bss_desc, &pos); |
| 472 | |
| 473 | /* Append vendor specific IE TLV */ |
| 474 | mwifiex_cmd_append_vsie_tlv(priv, MWIFIEX_VSIE_MASK_ASSOC, &pos); |
| 475 | |
| 476 | mwifiex_wmm_process_association_req(priv, &pos, &bss_desc->wmm_ie, |
| 477 | bss_desc->bcn_ht_cap); |
| 478 | if (priv->sec_info.wapi_enabled && priv->wapi_ie_len) |
| 479 | mwifiex_cmd_append_wapi_ie(priv, &pos); |
| 480 | |
| 481 | |
| 482 | mwifiex_cmd_append_generic_ie(priv, &pos); |
| 483 | |
| 484 | mwifiex_cmd_append_tsf_tlv(priv, &pos, bss_desc); |
| 485 | |
| 486 | cmd->size = cpu_to_le16((u16) (pos - (u8 *) assoc) + S_DS_GEN); |
| 487 | |
| 488 | /* Set the Capability info at last */ |
| 489 | tmp_cap = bss_desc->cap_info_bitmap; |
| 490 | |
| 491 | if (priv->adapter->config_bands == BAND_B) |
Bing Zhao | b93f85f | 2011-03-25 19:47:01 -0700 | [diff] [blame] | 492 | tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 493 | |
| 494 | tmp_cap &= CAPINFO_MASK; |
| 495 | dev_dbg(priv->adapter->dev, "info: ASSOC_CMD: tmp_cap=%4X CAPINFO_MASK=%4lX\n", |
| 496 | tmp_cap, CAPINFO_MASK); |
| 497 | assoc->cap_info_bitmap = cpu_to_le16(tmp_cap); |
| 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | /* |
| 503 | * Association firmware command response handler |
| 504 | * |
| 505 | * The response buffer for the association command has the following |
| 506 | * memory layout. |
| 507 | * |
| 508 | * For cases where an association response was not received (indicated |
| 509 | * by the CapInfo and AId field): |
| 510 | * |
| 511 | * .------------------------------------------------------------. |
| 512 | * | Header(4 * sizeof(t_u16)): Standard command response hdr | |
| 513 | * .------------------------------------------------------------. |
| 514 | * | cap_info/Error Return(t_u16): | |
| 515 | * | 0xFFFF(-1): Internal error | |
| 516 | * | 0xFFFE(-2): Authentication unhandled message | |
| 517 | * | 0xFFFD(-3): Authentication refused | |
| 518 | * | 0xFFFC(-4): Timeout waiting for AP response | |
| 519 | * .------------------------------------------------------------. |
| 520 | * | status_code(t_u16): | |
| 521 | * | If cap_info is -1: | |
| 522 | * | An internal firmware failure prevented the | |
| 523 | * | command from being processed. The status_code | |
| 524 | * | will be set to 1. | |
| 525 | * | | |
| 526 | * | If cap_info is -2: | |
| 527 | * | An authentication frame was received but was | |
| 528 | * | not handled by the firmware. IEEE Status | |
| 529 | * | code for the failure is returned. | |
| 530 | * | | |
| 531 | * | If cap_info is -3: | |
| 532 | * | An authentication frame was received and the | |
| 533 | * | status_code is the IEEE Status reported in the | |
| 534 | * | response. | |
| 535 | * | | |
| 536 | * | If cap_info is -4: | |
| 537 | * | (1) Association response timeout | |
| 538 | * | (2) Authentication response timeout | |
| 539 | * .------------------------------------------------------------. |
| 540 | * | a_id(t_u16): 0xFFFF | |
| 541 | * .------------------------------------------------------------. |
| 542 | * |
| 543 | * |
| 544 | * For cases where an association response was received, the IEEE |
| 545 | * standard association response frame is returned: |
| 546 | * |
| 547 | * .------------------------------------------------------------. |
| 548 | * | Header(4 * sizeof(t_u16)): Standard command response hdr | |
| 549 | * .------------------------------------------------------------. |
| 550 | * | cap_info(t_u16): IEEE Capability | |
| 551 | * .------------------------------------------------------------. |
| 552 | * | status_code(t_u16): IEEE Status Code | |
| 553 | * .------------------------------------------------------------. |
| 554 | * | a_id(t_u16): IEEE Association ID | |
| 555 | * .------------------------------------------------------------. |
| 556 | * | IEEE IEs(variable): Any received IEs comprising the | |
| 557 | * | remaining portion of a received | |
| 558 | * | association response frame. | |
| 559 | * .------------------------------------------------------------. |
| 560 | * |
| 561 | * For simplistic handling, the status_code field can be used to determine |
| 562 | * an association success (0) or failure (non-zero). |
| 563 | */ |
| 564 | int mwifiex_ret_802_11_associate(struct mwifiex_private *priv, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 565 | struct host_cmd_ds_command *resp) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 566 | { |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 567 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 568 | int ret = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 569 | struct ieee_types_assoc_rsp *assoc_rsp; |
| 570 | struct mwifiex_bssdescriptor *bss_desc; |
| 571 | u8 enable_data = true; |
| 572 | |
| 573 | assoc_rsp = (struct ieee_types_assoc_rsp *) &resp->params; |
| 574 | |
| 575 | priv->assoc_rsp_size = min(le16_to_cpu(resp->size) - S_DS_GEN, |
| 576 | sizeof(priv->assoc_rsp_buf)); |
| 577 | |
| 578 | memcpy(priv->assoc_rsp_buf, &resp->params, priv->assoc_rsp_size); |
| 579 | |
| 580 | if (le16_to_cpu(assoc_rsp->status_code)) { |
| 581 | priv->adapter->dbg.num_cmd_assoc_failure++; |
| 582 | dev_err(priv->adapter->dev, "ASSOC_RESP: association failed, " |
| 583 | "status code = %d, error = 0x%x, a_id = 0x%x\n", |
| 584 | le16_to_cpu(assoc_rsp->status_code), |
| 585 | le16_to_cpu(assoc_rsp->cap_info_bitmap), |
| 586 | le16_to_cpu(assoc_rsp->a_id)); |
| 587 | |
| 588 | ret = -1; |
| 589 | goto done; |
| 590 | } |
| 591 | |
| 592 | /* Send a Media Connected event, according to the Spec */ |
| 593 | priv->media_connected = true; |
| 594 | |
| 595 | priv->adapter->ps_state = PS_STATE_AWAKE; |
| 596 | priv->adapter->pps_uapsd_mode = false; |
| 597 | priv->adapter->tx_lock_flag = false; |
| 598 | |
| 599 | /* Set the attempted BSSID Index to current */ |
| 600 | bss_desc = priv->attempted_bss_desc; |
| 601 | |
| 602 | dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: %s\n", |
| 603 | bss_desc->ssid.ssid); |
| 604 | |
| 605 | /* Make a copy of current BSSID descriptor */ |
| 606 | memcpy(&priv->curr_bss_params.bss_descriptor, |
| 607 | bss_desc, sizeof(struct mwifiex_bssdescriptor)); |
| 608 | |
| 609 | /* Update curr_bss_params */ |
| 610 | priv->curr_bss_params.bss_descriptor.channel |
| 611 | = bss_desc->phy_param_set.ds_param_set.current_chan; |
| 612 | |
| 613 | priv->curr_bss_params.band = (u8) bss_desc->bss_band; |
| 614 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 615 | if (bss_desc->wmm_ie.vend_hdr.element_id == WLAN_EID_VENDOR_SPECIFIC) |
| 616 | priv->curr_bss_params.wmm_enabled = true; |
| 617 | else |
| 618 | priv->curr_bss_params.wmm_enabled = false; |
| 619 | |
| 620 | if ((priv->wmm_required || bss_desc->bcn_ht_cap) |
| 621 | && priv->curr_bss_params.wmm_enabled) |
| 622 | priv->wmm_enabled = true; |
| 623 | else |
| 624 | priv->wmm_enabled = false; |
| 625 | |
| 626 | priv->curr_bss_params.wmm_uapsd_enabled = false; |
| 627 | |
| 628 | if (priv->wmm_enabled) |
| 629 | priv->curr_bss_params.wmm_uapsd_enabled |
| 630 | = ((bss_desc->wmm_ie.qos_info_bitmap & |
| 631 | IEEE80211_WMM_IE_AP_QOSINFO_UAPSD) ? 1 : 0); |
| 632 | |
| 633 | dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: curr_pkt_filter is %#x\n", |
| 634 | priv->curr_pkt_filter); |
| 635 | if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled) |
| 636 | priv->wpa_is_gtk_set = false; |
| 637 | |
| 638 | if (priv->wmm_enabled) { |
| 639 | /* Don't re-enable carrier until we get the WMM_GET_STATUS |
| 640 | event */ |
| 641 | enable_data = false; |
| 642 | } else { |
| 643 | /* Since WMM is not enabled, setup the queues with the |
| 644 | defaults */ |
| 645 | mwifiex_wmm_setup_queue_priorities(priv, NULL); |
| 646 | mwifiex_wmm_setup_ac_downgrade(priv); |
| 647 | } |
| 648 | |
| 649 | if (enable_data) |
| 650 | dev_dbg(priv->adapter->dev, |
| 651 | "info: post association, re-enabling data flow\n"); |
| 652 | |
| 653 | /* Reset SNR/NF/RSSI values */ |
| 654 | priv->data_rssi_last = 0; |
| 655 | priv->data_nf_last = 0; |
| 656 | priv->data_rssi_avg = 0; |
| 657 | priv->data_nf_avg = 0; |
| 658 | priv->bcn_rssi_last = 0; |
| 659 | priv->bcn_nf_last = 0; |
| 660 | priv->bcn_rssi_avg = 0; |
| 661 | priv->bcn_nf_avg = 0; |
| 662 | priv->rxpd_rate = 0; |
| 663 | priv->rxpd_htinfo = 0; |
| 664 | |
| 665 | mwifiex_save_curr_bcn(priv); |
| 666 | |
| 667 | priv->adapter->dbg.num_cmd_assoc_success++; |
| 668 | |
| 669 | dev_dbg(priv->adapter->dev, "info: ASSOC_RESP: associated\n"); |
| 670 | |
| 671 | /* Add the ra_list here for infra mode as there will be only 1 ra |
| 672 | always */ |
| 673 | mwifiex_ralist_add(priv, |
| 674 | priv->curr_bss_params.bss_descriptor.mac_address); |
| 675 | |
| 676 | if (!netif_carrier_ok(priv->netdev)) |
| 677 | netif_carrier_on(priv->netdev); |
| 678 | if (netif_queue_stopped(priv->netdev)) |
| 679 | netif_wake_queue(priv->netdev); |
| 680 | |
| 681 | if (priv->sec_info.wpa_enabled || priv->sec_info.wpa2_enabled) |
| 682 | priv->scan_block = true; |
| 683 | |
| 684 | done: |
| 685 | /* Need to indicate IOCTL complete */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 686 | if (adapter->curr_cmd->wait_q_enabled) { |
| 687 | if (ret) |
| 688 | adapter->cmd_wait_q.status = -1; |
| 689 | else |
| 690 | adapter->cmd_wait_q.status = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | return ret; |
| 694 | } |
| 695 | |
| 696 | /* |
| 697 | * This function prepares command for ad-hoc start. |
| 698 | * |
| 699 | * Driver will fill up SSID, BSS mode, IBSS parameters, physical |
| 700 | * parameters, probe delay, and capability information. Firmware |
| 701 | * will fill up beacon period, basic rates and operational rates. |
| 702 | * |
| 703 | * In addition, the following TLVs are added - |
| 704 | * - Channel TLV |
| 705 | * - Vendor specific IE |
| 706 | * - WPA/WPA2 IE |
| 707 | * - HT Capabilities IE |
| 708 | * - HT Information IE |
| 709 | * |
| 710 | * Preparation also includes - |
| 711 | * - Setting command ID and proper size |
| 712 | * - Ensuring correct endian-ness |
| 713 | */ |
| 714 | int |
| 715 | mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv, |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 716 | struct host_cmd_ds_command *cmd, |
| 717 | struct mwifiex_802_11_ssid *req_ssid) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 718 | { |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 719 | int rsn_ie_len = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 720 | struct mwifiex_adapter *adapter = priv->adapter; |
| 721 | struct host_cmd_ds_802_11_ad_hoc_start *adhoc_start = |
| 722 | &cmd->params.adhoc_start; |
| 723 | struct mwifiex_bssdescriptor *bss_desc; |
| 724 | u32 cmd_append_size = 0; |
| 725 | u32 i; |
| 726 | u16 tmp_cap; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 727 | struct mwifiex_ie_types_chan_list_param_set *chan_tlv; |
Yogesh Ashok Powar | eedf15d | 2011-11-07 21:41:07 -0800 | [diff] [blame] | 728 | u8 radio_type; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 729 | |
| 730 | struct mwifiex_ie_types_htcap *ht_cap; |
| 731 | struct mwifiex_ie_types_htinfo *ht_info; |
| 732 | u8 *pos = (u8 *) adhoc_start + |
| 733 | sizeof(struct host_cmd_ds_802_11_ad_hoc_start); |
| 734 | |
| 735 | if (!adapter) |
| 736 | return -1; |
| 737 | |
| 738 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_START); |
| 739 | |
| 740 | bss_desc = &priv->curr_bss_params.bss_descriptor; |
| 741 | priv->attempted_bss_desc = bss_desc; |
| 742 | |
| 743 | /* |
| 744 | * Fill in the parameters for 2 data structures: |
| 745 | * 1. struct host_cmd_ds_802_11_ad_hoc_start command |
| 746 | * 2. bss_desc |
| 747 | * Driver will fill up SSID, bss_mode,IBSS param, Physical Param, |
| 748 | * probe delay, and Cap info. |
| 749 | * Firmware will fill up beacon period, Basic rates |
| 750 | * and operational rates. |
| 751 | */ |
| 752 | |
| 753 | memset(adhoc_start->ssid, 0, IEEE80211_MAX_SSID_LEN); |
| 754 | |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 755 | memcpy(adhoc_start->ssid, req_ssid->ssid, req_ssid->ssid_len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 756 | |
| 757 | dev_dbg(adapter->dev, "info: ADHOC_S_CMD: SSID = %s\n", |
| 758 | adhoc_start->ssid); |
| 759 | |
| 760 | memset(bss_desc->ssid.ssid, 0, IEEE80211_MAX_SSID_LEN); |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 761 | memcpy(bss_desc->ssid.ssid, req_ssid->ssid, req_ssid->ssid_len); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 762 | |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 763 | bss_desc->ssid.ssid_len = req_ssid->ssid_len; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 764 | |
| 765 | /* Set the BSS mode */ |
| 766 | adhoc_start->bss_mode = HostCmd_BSS_MODE_IBSS; |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 767 | bss_desc->bss_mode = NL80211_IFTYPE_ADHOC; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 768 | adhoc_start->beacon_period = cpu_to_le16(priv->beacon_period); |
| 769 | bss_desc->beacon_period = priv->beacon_period; |
| 770 | |
| 771 | /* Set Physical param set */ |
| 772 | /* Parameter IE Id */ |
| 773 | #define DS_PARA_IE_ID 3 |
| 774 | /* Parameter IE length */ |
| 775 | #define DS_PARA_IE_LEN 1 |
| 776 | |
| 777 | adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID; |
| 778 | adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN; |
| 779 | |
| 780 | if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211 |
| 781 | (priv, adapter->adhoc_start_band, (u16) |
| 782 | priv->adhoc_channel)) { |
| 783 | struct mwifiex_chan_freq_power *cfp; |
| 784 | cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv, |
| 785 | adapter->adhoc_start_band, FIRST_VALID_CHANNEL); |
| 786 | if (cfp) |
| 787 | priv->adhoc_channel = (u8) cfp->channel; |
| 788 | } |
| 789 | |
| 790 | if (!priv->adhoc_channel) { |
| 791 | dev_err(adapter->dev, "ADHOC_S_CMD: adhoc_channel cannot be 0\n"); |
| 792 | return -1; |
| 793 | } |
| 794 | |
| 795 | dev_dbg(adapter->dev, "info: ADHOC_S_CMD: creating ADHOC on channel %d\n", |
| 796 | priv->adhoc_channel); |
| 797 | |
| 798 | priv->curr_bss_params.bss_descriptor.channel = priv->adhoc_channel; |
| 799 | priv->curr_bss_params.band = adapter->adhoc_start_band; |
| 800 | |
| 801 | bss_desc->channel = priv->adhoc_channel; |
| 802 | adhoc_start->phy_param_set.ds_param_set.current_chan = |
| 803 | priv->adhoc_channel; |
| 804 | |
| 805 | memcpy(&bss_desc->phy_param_set, &adhoc_start->phy_param_set, |
| 806 | sizeof(union ieee_types_phy_param_set)); |
| 807 | |
| 808 | /* Set IBSS param set */ |
| 809 | /* IBSS parameter IE Id */ |
| 810 | #define IBSS_PARA_IE_ID 6 |
| 811 | /* IBSS parameter IE length */ |
| 812 | #define IBSS_PARA_IE_LEN 2 |
| 813 | |
| 814 | adhoc_start->ss_param_set.ibss_param_set.element_id = IBSS_PARA_IE_ID; |
| 815 | adhoc_start->ss_param_set.ibss_param_set.len = IBSS_PARA_IE_LEN; |
| 816 | adhoc_start->ss_param_set.ibss_param_set.atim_window |
| 817 | = cpu_to_le16(priv->atim_window); |
| 818 | memcpy(&bss_desc->ss_param_set, &adhoc_start->ss_param_set, |
| 819 | sizeof(union ieee_types_ss_param_set)); |
| 820 | |
| 821 | /* Set Capability info */ |
| 822 | bss_desc->cap_info_bitmap |= WLAN_CAPABILITY_IBSS; |
| 823 | tmp_cap = le16_to_cpu(adhoc_start->cap_info_bitmap); |
| 824 | tmp_cap &= ~WLAN_CAPABILITY_ESS; |
| 825 | tmp_cap |= WLAN_CAPABILITY_IBSS; |
| 826 | |
| 827 | /* Set up privacy in bss_desc */ |
Yogesh Ashok Powar | 2be50b8 | 2011-04-01 18:36:47 -0700 | [diff] [blame] | 828 | if (priv->sec_info.encryption_mode) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 829 | /* Ad-Hoc capability privacy on */ |
| 830 | dev_dbg(adapter->dev, |
| 831 | "info: ADHOC_S_CMD: wep_status set privacy to WEP\n"); |
| 832 | bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP; |
| 833 | tmp_cap |= WLAN_CAPABILITY_PRIVACY; |
| 834 | } else { |
| 835 | dev_dbg(adapter->dev, "info: ADHOC_S_CMD: wep_status NOT set," |
| 836 | " setting privacy to ACCEPT ALL\n"); |
| 837 | bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_ACCEPT_ALL; |
| 838 | } |
| 839 | |
Yogesh Ashok Powar | 63af633 | 2011-11-07 21:41:09 -0800 | [diff] [blame] | 840 | memset(adhoc_start->data_rate, 0, sizeof(adhoc_start->data_rate)); |
| 841 | mwifiex_get_active_data_rates(priv, adhoc_start->data_rate); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 842 | if ((adapter->adhoc_start_band & BAND_G) && |
| 843 | (priv->curr_pkt_filter & HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON)) { |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 844 | if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 845 | HostCmd_ACT_GEN_SET, 0, |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 846 | &priv->curr_pkt_filter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 847 | dev_err(adapter->dev, |
| 848 | "ADHOC_S_CMD: G Protection config failed\n"); |
| 849 | return -1; |
| 850 | } |
| 851 | } |
| 852 | /* Find the last non zero */ |
Yogesh Ashok Powar | 63af633 | 2011-11-07 21:41:09 -0800 | [diff] [blame] | 853 | for (i = 0; i < sizeof(adhoc_start->data_rate); i++) |
| 854 | if (!adhoc_start->data_rate[i]) |
| 855 | break; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 856 | |
| 857 | priv->curr_bss_params.num_of_rates = i; |
| 858 | |
| 859 | /* Copy the ad-hoc creating rates into Current BSS rate structure */ |
| 860 | memcpy(&priv->curr_bss_params.data_rates, |
Yogesh Ashok Powar | 63af633 | 2011-11-07 21:41:09 -0800 | [diff] [blame] | 861 | &adhoc_start->data_rate, priv->curr_bss_params.num_of_rates); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 862 | |
| 863 | dev_dbg(adapter->dev, "info: ADHOC_S_CMD: rates=%02x %02x %02x %02x\n", |
Yogesh Ashok Powar | 63af633 | 2011-11-07 21:41:09 -0800 | [diff] [blame] | 864 | adhoc_start->data_rate[0], adhoc_start->data_rate[1], |
| 865 | adhoc_start->data_rate[2], adhoc_start->data_rate[3]); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 866 | |
| 867 | dev_dbg(adapter->dev, "info: ADHOC_S_CMD: AD-HOC Start command is ready\n"); |
| 868 | |
| 869 | if (IS_SUPPORT_MULTI_BANDS(adapter)) { |
| 870 | /* Append a channel TLV */ |
| 871 | chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos; |
| 872 | chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); |
| 873 | chan_tlv->header.len = |
| 874 | cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set)); |
| 875 | |
| 876 | memset(chan_tlv->chan_scan_param, 0x00, |
| 877 | sizeof(struct mwifiex_chan_scan_param_set)); |
| 878 | chan_tlv->chan_scan_param[0].chan_number = |
| 879 | (u8) priv->curr_bss_params.bss_descriptor.channel; |
| 880 | |
| 881 | dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Chan = %d\n", |
| 882 | chan_tlv->chan_scan_param[0].chan_number); |
| 883 | |
| 884 | chan_tlv->chan_scan_param[0].radio_type |
| 885 | = mwifiex_band_to_radio_type(priv->curr_bss_params.band); |
| 886 | if (adapter->adhoc_start_band & BAND_GN |
| 887 | || adapter->adhoc_start_band & BAND_AN) { |
Amitkumar Karwar | 21c3ba3 | 2011-12-20 23:47:21 -0800 | [diff] [blame] | 888 | if (adapter->sec_chan_offset == |
| 889 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 890 | chan_tlv->chan_scan_param[0].radio_type |= |
Amitkumar Karwar | 21c3ba3 | 2011-12-20 23:47:21 -0800 | [diff] [blame] | 891 | (IEEE80211_HT_PARAM_CHA_SEC_ABOVE << 4); |
| 892 | else if (adapter->sec_chan_offset == |
| 893 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 894 | chan_tlv->chan_scan_param[0].radio_type |= |
Amitkumar Karwar | 21c3ba3 | 2011-12-20 23:47:21 -0800 | [diff] [blame] | 895 | (IEEE80211_HT_PARAM_CHA_SEC_BELOW << 4); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 896 | } |
| 897 | dev_dbg(adapter->dev, "info: ADHOC_S_CMD: TLV Band = %d\n", |
| 898 | chan_tlv->chan_scan_param[0].radio_type); |
| 899 | pos += sizeof(chan_tlv->header) + |
| 900 | sizeof(struct mwifiex_chan_scan_param_set); |
| 901 | cmd_append_size += |
| 902 | sizeof(chan_tlv->header) + |
| 903 | sizeof(struct mwifiex_chan_scan_param_set); |
| 904 | } |
| 905 | |
| 906 | /* Append vendor specific IE TLV */ |
| 907 | cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv, |
| 908 | MWIFIEX_VSIE_MASK_ADHOC, &pos); |
| 909 | |
| 910 | if (priv->sec_info.wpa_enabled) { |
| 911 | rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos); |
| 912 | if (rsn_ie_len == -1) |
| 913 | return -1; |
| 914 | cmd_append_size += rsn_ie_len; |
| 915 | } |
| 916 | |
| 917 | if (adapter->adhoc_11n_enabled) { |
Yogesh Ashok Powar | eedf15d | 2011-11-07 21:41:07 -0800 | [diff] [blame] | 918 | /* Fill HT CAPABILITY */ |
| 919 | ht_cap = (struct mwifiex_ie_types_htcap *) pos; |
| 920 | memset(ht_cap, 0, sizeof(struct mwifiex_ie_types_htcap)); |
| 921 | ht_cap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY); |
| 922 | ht_cap->header.len = |
| 923 | cpu_to_le16(sizeof(struct ieee80211_ht_cap)); |
| 924 | radio_type = mwifiex_band_to_radio_type( |
| 925 | priv->adapter->config_bands); |
| 926 | mwifiex_fill_cap_info(priv, radio_type, ht_cap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 927 | |
Yogesh Ashok Powar | eedf15d | 2011-11-07 21:41:07 -0800 | [diff] [blame] | 928 | pos += sizeof(struct mwifiex_ie_types_htcap); |
| 929 | cmd_append_size += |
| 930 | sizeof(struct mwifiex_ie_types_htcap); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 931 | |
Yogesh Ashok Powar | eedf15d | 2011-11-07 21:41:07 -0800 | [diff] [blame] | 932 | /* Fill HT INFORMATION */ |
| 933 | ht_info = (struct mwifiex_ie_types_htinfo *) pos; |
| 934 | memset(ht_info, 0, sizeof(struct mwifiex_ie_types_htinfo)); |
| 935 | ht_info->header.type = cpu_to_le16(WLAN_EID_HT_INFORMATION); |
| 936 | ht_info->header.len = |
| 937 | cpu_to_le16(sizeof(struct ieee80211_ht_info)); |
| 938 | |
| 939 | ht_info->ht_info.control_chan = |
| 940 | (u8) priv->curr_bss_params.bss_descriptor.channel; |
Amitkumar Karwar | 21c3ba3 | 2011-12-20 23:47:21 -0800 | [diff] [blame] | 941 | if (adapter->sec_chan_offset) { |
| 942 | ht_info->ht_info.ht_param = adapter->sec_chan_offset; |
Yogesh Ashok Powar | eedf15d | 2011-11-07 21:41:07 -0800 | [diff] [blame] | 943 | ht_info->ht_info.ht_param |= |
Marc Yang | 6d2bd91 | 2011-03-25 19:47:02 -0700 | [diff] [blame] | 944 | IEEE80211_HT_PARAM_CHAN_WIDTH_ANY; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 945 | } |
Yogesh Ashok Powar | eedf15d | 2011-11-07 21:41:07 -0800 | [diff] [blame] | 946 | ht_info->ht_info.operation_mode = |
| 947 | cpu_to_le16(IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); |
| 948 | ht_info->ht_info.basic_set[0] = 0xff; |
| 949 | pos += sizeof(struct mwifiex_ie_types_htinfo); |
| 950 | cmd_append_size += |
| 951 | sizeof(struct mwifiex_ie_types_htinfo); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | cmd->size = cpu_to_le16((u16) |
| 955 | (sizeof(struct host_cmd_ds_802_11_ad_hoc_start) |
| 956 | + S_DS_GEN + cmd_append_size)); |
| 957 | |
| 958 | if (adapter->adhoc_start_band == BAND_B) |
Bing Zhao | b93f85f | 2011-03-25 19:47:01 -0700 | [diff] [blame] | 959 | tmp_cap &= ~WLAN_CAPABILITY_SHORT_SLOT_TIME; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 960 | else |
Bing Zhao | b93f85f | 2011-03-25 19:47:01 -0700 | [diff] [blame] | 961 | tmp_cap |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 962 | |
| 963 | adhoc_start->cap_info_bitmap = cpu_to_le16(tmp_cap); |
| 964 | |
| 965 | return 0; |
| 966 | } |
| 967 | |
| 968 | /* |
| 969 | * This function prepares command for ad-hoc join. |
| 970 | * |
| 971 | * Most of the parameters are set up by copying from the target BSS descriptor |
| 972 | * from the scan response. |
| 973 | * |
| 974 | * In addition, the following TLVs are added - |
| 975 | * - Channel TLV |
| 976 | * - Vendor specific IE |
| 977 | * - WPA/WPA2 IE |
| 978 | * - 11n IE |
| 979 | * |
| 980 | * Preparation also includes - |
| 981 | * - Setting command ID and proper size |
| 982 | * - Ensuring correct endian-ness |
| 983 | */ |
| 984 | int |
| 985 | mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv, |
Amitkumar Karwar | a5ffddb | 2011-06-20 15:21:48 -0700 | [diff] [blame] | 986 | struct host_cmd_ds_command *cmd, |
| 987 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 988 | { |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 989 | int rsn_ie_len = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 990 | struct host_cmd_ds_802_11_ad_hoc_join *adhoc_join = |
| 991 | &cmd->params.adhoc_join; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 992 | struct mwifiex_ie_types_chan_list_param_set *chan_tlv; |
| 993 | u32 cmd_append_size = 0; |
| 994 | u16 tmp_cap; |
| 995 | u32 i, rates_size = 0; |
| 996 | u16 curr_pkt_filter; |
| 997 | u8 *pos = |
| 998 | (u8 *) adhoc_join + |
| 999 | sizeof(struct host_cmd_ds_802_11_ad_hoc_join); |
| 1000 | |
| 1001 | /* Use G protection */ |
| 1002 | #define USE_G_PROTECTION 0x02 |
| 1003 | if (bss_desc->erp_flags & USE_G_PROTECTION) { |
| 1004 | curr_pkt_filter = |
| 1005 | priv-> |
| 1006 | curr_pkt_filter | HostCmd_ACT_MAC_ADHOC_G_PROTECTION_ON; |
| 1007 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1008 | if (mwifiex_send_cmd_async(priv, HostCmd_CMD_MAC_CONTROL, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1009 | HostCmd_ACT_GEN_SET, 0, |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1010 | &curr_pkt_filter)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1011 | dev_err(priv->adapter->dev, |
| 1012 | "ADHOC_J_CMD: G Protection config failed\n"); |
| 1013 | return -1; |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | priv->attempted_bss_desc = bss_desc; |
| 1018 | |
| 1019 | cmd->command = cpu_to_le16(HostCmd_CMD_802_11_AD_HOC_JOIN); |
| 1020 | |
| 1021 | adhoc_join->bss_descriptor.bss_mode = HostCmd_BSS_MODE_IBSS; |
| 1022 | |
| 1023 | adhoc_join->bss_descriptor.beacon_period |
| 1024 | = cpu_to_le16(bss_desc->beacon_period); |
| 1025 | |
| 1026 | memcpy(&adhoc_join->bss_descriptor.bssid, |
| 1027 | &bss_desc->mac_address, ETH_ALEN); |
| 1028 | |
| 1029 | memcpy(&adhoc_join->bss_descriptor.ssid, |
| 1030 | &bss_desc->ssid.ssid, bss_desc->ssid.ssid_len); |
| 1031 | |
| 1032 | memcpy(&adhoc_join->bss_descriptor.phy_param_set, |
| 1033 | &bss_desc->phy_param_set, |
| 1034 | sizeof(union ieee_types_phy_param_set)); |
| 1035 | |
| 1036 | memcpy(&adhoc_join->bss_descriptor.ss_param_set, |
| 1037 | &bss_desc->ss_param_set, sizeof(union ieee_types_ss_param_set)); |
| 1038 | |
| 1039 | tmp_cap = bss_desc->cap_info_bitmap; |
| 1040 | |
| 1041 | tmp_cap &= CAPINFO_MASK; |
| 1042 | |
| 1043 | dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: tmp_cap=%4X" |
| 1044 | " CAPINFO_MASK=%4lX\n", tmp_cap, CAPINFO_MASK); |
| 1045 | |
| 1046 | /* Information on BSSID descriptor passed to FW */ |
| 1047 | dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: BSSID = %pM, SSID = %s\n", |
| 1048 | adhoc_join->bss_descriptor.bssid, |
| 1049 | adhoc_join->bss_descriptor.ssid); |
| 1050 | |
| 1051 | for (i = 0; bss_desc->supported_rates[i] && |
| 1052 | i < MWIFIEX_SUPPORTED_RATES; |
| 1053 | i++) |
| 1054 | ; |
| 1055 | rates_size = i; |
| 1056 | |
| 1057 | /* Copy Data Rates from the Rates recorded in scan response */ |
| 1058 | memset(adhoc_join->bss_descriptor.data_rates, 0, |
| 1059 | sizeof(adhoc_join->bss_descriptor.data_rates)); |
| 1060 | memcpy(adhoc_join->bss_descriptor.data_rates, |
| 1061 | bss_desc->supported_rates, rates_size); |
| 1062 | |
| 1063 | /* Copy the adhoc join rates into Current BSS state structure */ |
| 1064 | priv->curr_bss_params.num_of_rates = rates_size; |
| 1065 | memcpy(&priv->curr_bss_params.data_rates, bss_desc->supported_rates, |
| 1066 | rates_size); |
| 1067 | |
| 1068 | /* Copy the channel information */ |
| 1069 | priv->curr_bss_params.bss_descriptor.channel = bss_desc->channel; |
| 1070 | priv->curr_bss_params.band = (u8) bss_desc->bss_band; |
| 1071 | |
Amitkumar Karwar | 5eb02e4 | 2012-02-24 21:36:04 -0800 | [diff] [blame^] | 1072 | if (priv->sec_info.wep_enabled || priv->sec_info.wpa_enabled) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1073 | tmp_cap |= WLAN_CAPABILITY_PRIVACY; |
| 1074 | |
| 1075 | if (IS_SUPPORT_MULTI_BANDS(priv->adapter)) { |
| 1076 | /* Append a channel TLV */ |
| 1077 | chan_tlv = (struct mwifiex_ie_types_chan_list_param_set *) pos; |
| 1078 | chan_tlv->header.type = cpu_to_le16(TLV_TYPE_CHANLIST); |
| 1079 | chan_tlv->header.len = |
| 1080 | cpu_to_le16(sizeof(struct mwifiex_chan_scan_param_set)); |
| 1081 | |
| 1082 | memset(chan_tlv->chan_scan_param, 0x00, |
| 1083 | sizeof(struct mwifiex_chan_scan_param_set)); |
| 1084 | chan_tlv->chan_scan_param[0].chan_number = |
| 1085 | (bss_desc->phy_param_set.ds_param_set.current_chan); |
| 1086 | dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Chan = %d\n", |
| 1087 | chan_tlv->chan_scan_param[0].chan_number); |
| 1088 | |
| 1089 | chan_tlv->chan_scan_param[0].radio_type = |
| 1090 | mwifiex_band_to_radio_type((u8) bss_desc->bss_band); |
| 1091 | |
| 1092 | dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: TLV Band = %d\n", |
| 1093 | chan_tlv->chan_scan_param[0].radio_type); |
| 1094 | pos += sizeof(chan_tlv->header) + |
| 1095 | sizeof(struct mwifiex_chan_scan_param_set); |
| 1096 | cmd_append_size += sizeof(chan_tlv->header) + |
| 1097 | sizeof(struct mwifiex_chan_scan_param_set); |
| 1098 | } |
| 1099 | |
| 1100 | if (priv->sec_info.wpa_enabled) |
| 1101 | rsn_ie_len = mwifiex_append_rsn_ie_wpa_wpa2(priv, &pos); |
| 1102 | if (rsn_ie_len == -1) |
| 1103 | return -1; |
| 1104 | cmd_append_size += rsn_ie_len; |
| 1105 | |
| 1106 | if (ISSUPP_11NENABLED(priv->adapter->fw_cap_info)) |
| 1107 | cmd_append_size += mwifiex_cmd_append_11n_tlv(priv, |
| 1108 | bss_desc, &pos); |
| 1109 | |
| 1110 | /* Append vendor specific IE TLV */ |
| 1111 | cmd_append_size += mwifiex_cmd_append_vsie_tlv(priv, |
| 1112 | MWIFIEX_VSIE_MASK_ADHOC, &pos); |
| 1113 | |
| 1114 | cmd->size = cpu_to_le16((u16) |
| 1115 | (sizeof(struct host_cmd_ds_802_11_ad_hoc_join) |
| 1116 | + S_DS_GEN + cmd_append_size)); |
| 1117 | |
| 1118 | adhoc_join->bss_descriptor.cap_info_bitmap = cpu_to_le16(tmp_cap); |
| 1119 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1120 | return 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | /* |
| 1124 | * This function handles the command response of ad-hoc start and |
| 1125 | * ad-hoc join. |
| 1126 | * |
| 1127 | * The function generates a device-connected event to notify |
| 1128 | * the applications, in case of successful ad-hoc start/join, and |
| 1129 | * saves the beacon buffer. |
| 1130 | */ |
| 1131 | int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1132 | struct host_cmd_ds_command *resp) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1133 | { |
| 1134 | int ret = 0; |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1135 | struct mwifiex_adapter *adapter = priv->adapter; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1136 | struct host_cmd_ds_802_11_ad_hoc_result *adhoc_result; |
| 1137 | struct mwifiex_bssdescriptor *bss_desc; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1138 | |
| 1139 | adhoc_result = &resp->params.adhoc_result; |
| 1140 | |
| 1141 | bss_desc = priv->attempted_bss_desc; |
| 1142 | |
| 1143 | /* Join result code 0 --> SUCCESS */ |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1144 | if (le16_to_cpu(resp->result)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1145 | dev_err(priv->adapter->dev, "ADHOC_RESP: failed\n"); |
| 1146 | if (priv->media_connected) |
| 1147 | mwifiex_reset_connect_state(priv); |
| 1148 | |
| 1149 | memset(&priv->curr_bss_params.bss_descriptor, |
| 1150 | 0x00, sizeof(struct mwifiex_bssdescriptor)); |
| 1151 | |
| 1152 | ret = -1; |
| 1153 | goto done; |
| 1154 | } |
| 1155 | |
| 1156 | /* Send a Media Connected event, according to the Spec */ |
| 1157 | priv->media_connected = true; |
| 1158 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1159 | if (le16_to_cpu(resp->command) == HostCmd_CMD_802_11_AD_HOC_START) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1160 | dev_dbg(priv->adapter->dev, "info: ADHOC_S_RESP %s\n", |
| 1161 | bss_desc->ssid.ssid); |
| 1162 | |
| 1163 | /* Update the created network descriptor with the new BSSID */ |
| 1164 | memcpy(bss_desc->mac_address, |
| 1165 | adhoc_result->bssid, ETH_ALEN); |
| 1166 | |
| 1167 | priv->adhoc_state = ADHOC_STARTED; |
| 1168 | } else { |
| 1169 | /* |
| 1170 | * Now the join cmd should be successful. |
| 1171 | * If BSSID has changed use SSID to compare instead of BSSID |
| 1172 | */ |
| 1173 | dev_dbg(priv->adapter->dev, "info: ADHOC_J_RESP %s\n", |
| 1174 | bss_desc->ssid.ssid); |
| 1175 | |
| 1176 | /* |
| 1177 | * Make a copy of current BSSID descriptor, only needed for |
| 1178 | * join since the current descriptor is already being used |
| 1179 | * for adhoc start |
| 1180 | */ |
| 1181 | memcpy(&priv->curr_bss_params.bss_descriptor, |
| 1182 | bss_desc, sizeof(struct mwifiex_bssdescriptor)); |
| 1183 | |
| 1184 | priv->adhoc_state = ADHOC_JOINED; |
| 1185 | } |
| 1186 | |
| 1187 | dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: channel = %d\n", |
| 1188 | priv->adhoc_channel); |
| 1189 | dev_dbg(priv->adapter->dev, "info: ADHOC_RESP: BSSID = %pM\n", |
| 1190 | priv->curr_bss_params.bss_descriptor.mac_address); |
| 1191 | |
| 1192 | if (!netif_carrier_ok(priv->netdev)) |
| 1193 | netif_carrier_on(priv->netdev); |
| 1194 | if (netif_queue_stopped(priv->netdev)) |
| 1195 | netif_wake_queue(priv->netdev); |
| 1196 | |
| 1197 | mwifiex_save_curr_bcn(priv); |
| 1198 | |
| 1199 | done: |
| 1200 | /* Need to indicate IOCTL complete */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1201 | if (adapter->curr_cmd->wait_q_enabled) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1202 | if (ret) |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1203 | adapter->cmd_wait_q.status = -1; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1204 | else |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1205 | adapter->cmd_wait_q.status = 0; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1206 | |
| 1207 | } |
| 1208 | |
| 1209 | return ret; |
| 1210 | } |
| 1211 | |
| 1212 | /* |
| 1213 | * This function associates to a specific BSS discovered in a scan. |
| 1214 | * |
| 1215 | * It clears any past association response stored for application |
| 1216 | * retrieval and calls the command preparation routine to send the |
| 1217 | * command to firmware. |
| 1218 | */ |
| 1219 | int mwifiex_associate(struct mwifiex_private *priv, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1220 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1221 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1222 | u8 current_bssid[ETH_ALEN]; |
| 1223 | |
| 1224 | /* Return error if the adapter or table entry is not marked as infra */ |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 1225 | if ((priv->bss_mode != NL80211_IFTYPE_STATION) || |
| 1226 | (bss_desc->bss_mode != NL80211_IFTYPE_STATION)) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1227 | return -1; |
| 1228 | |
| 1229 | memcpy(¤t_bssid, |
| 1230 | &priv->curr_bss_params.bss_descriptor.mac_address, |
| 1231 | sizeof(current_bssid)); |
| 1232 | |
| 1233 | /* Clear any past association response stored for application |
| 1234 | retrieval */ |
| 1235 | priv->assoc_rsp_size = 0; |
| 1236 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1237 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_ASSOCIATE, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1238 | HostCmd_ACT_GEN_SET, 0, bss_desc); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | /* |
| 1242 | * This function starts an ad-hoc network. |
| 1243 | * |
| 1244 | * It calls the command preparation routine to send the command to firmware. |
| 1245 | */ |
| 1246 | int |
| 1247 | mwifiex_adhoc_start(struct mwifiex_private *priv, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1248 | struct mwifiex_802_11_ssid *adhoc_ssid) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1249 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1250 | dev_dbg(priv->adapter->dev, "info: Adhoc Channel = %d\n", |
| 1251 | priv->adhoc_channel); |
| 1252 | dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n", |
| 1253 | priv->curr_bss_params.bss_descriptor.channel); |
| 1254 | dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %d\n", |
| 1255 | priv->curr_bss_params.band); |
| 1256 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1257 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_START, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1258 | HostCmd_ACT_GEN_SET, 0, adhoc_ssid); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | /* |
| 1262 | * This function joins an ad-hoc network found in a previous scan. |
| 1263 | * |
| 1264 | * It calls the command preparation routine to send the command to firmware, |
| 1265 | * if already not connected to the requested SSID. |
| 1266 | */ |
| 1267 | int mwifiex_adhoc_join(struct mwifiex_private *priv, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1268 | struct mwifiex_bssdescriptor *bss_desc) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1269 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1270 | dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid =%s\n", |
| 1271 | priv->curr_bss_params.bss_descriptor.ssid.ssid); |
| 1272 | dev_dbg(priv->adapter->dev, "info: adhoc join: curr_bss ssid_len =%u\n", |
| 1273 | priv->curr_bss_params.bss_descriptor.ssid.ssid_len); |
| 1274 | dev_dbg(priv->adapter->dev, "info: adhoc join: ssid =%s\n", |
| 1275 | bss_desc->ssid.ssid); |
| 1276 | dev_dbg(priv->adapter->dev, "info: adhoc join: ssid_len =%u\n", |
| 1277 | bss_desc->ssid.ssid_len); |
| 1278 | |
| 1279 | /* Check if the requested SSID is already joined */ |
| 1280 | if (priv->curr_bss_params.bss_descriptor.ssid.ssid_len && |
| 1281 | !mwifiex_ssid_cmp(&bss_desc->ssid, |
| 1282 | &priv->curr_bss_params.bss_descriptor.ssid) && |
| 1283 | (priv->curr_bss_params.bss_descriptor.bss_mode == |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 1284 | NL80211_IFTYPE_ADHOC)) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1285 | dev_dbg(priv->adapter->dev, "info: ADHOC_J_CMD: new ad-hoc SSID" |
| 1286 | " is the same as current; not attempting to re-join\n"); |
| 1287 | return -1; |
| 1288 | } |
| 1289 | |
| 1290 | dev_dbg(priv->adapter->dev, "info: curr_bss_params.channel = %d\n", |
| 1291 | priv->curr_bss_params.bss_descriptor.channel); |
| 1292 | dev_dbg(priv->adapter->dev, "info: curr_bss_params.band = %c\n", |
| 1293 | priv->curr_bss_params.band); |
| 1294 | |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1295 | return mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_AD_HOC_JOIN, |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1296 | HostCmd_ACT_GEN_SET, 0, bss_desc); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | /* |
| 1300 | * This function deauthenticates/disconnects from infra network by sending |
| 1301 | * deauthentication request. |
| 1302 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1303 | static int mwifiex_deauthenticate_infra(struct mwifiex_private *priv, u8 *mac) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1304 | { |
| 1305 | u8 mac_address[ETH_ALEN]; |
Yogesh Ashok Powar | 270e58e | 2011-05-03 20:11:46 -0700 | [diff] [blame] | 1306 | int ret; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1307 | u8 zero_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 }; |
| 1308 | |
| 1309 | if (mac) { |
| 1310 | if (!memcmp(mac, zero_mac, sizeof(zero_mac))) |
| 1311 | memcpy((u8 *) &mac_address, |
| 1312 | (u8 *) &priv->curr_bss_params.bss_descriptor. |
| 1313 | mac_address, ETH_ALEN); |
| 1314 | else |
| 1315 | memcpy((u8 *) &mac_address, (u8 *) mac, ETH_ALEN); |
| 1316 | } else { |
| 1317 | memcpy((u8 *) &mac_address, (u8 *) &priv->curr_bss_params. |
| 1318 | bss_descriptor.mac_address, ETH_ALEN); |
| 1319 | } |
| 1320 | |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1321 | ret = mwifiex_send_cmd_sync(priv, HostCmd_CMD_802_11_DEAUTHENTICATE, |
| 1322 | HostCmd_ACT_GEN_SET, 0, &mac_address); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1323 | |
| 1324 | return ret; |
| 1325 | } |
| 1326 | |
| 1327 | /* |
| 1328 | * This function deauthenticates/disconnects from a BSS. |
| 1329 | * |
| 1330 | * In case of infra made, it sends deauthentication request, and |
| 1331 | * in case of ad-hoc mode, a stop network request is sent to the firmware. |
| 1332 | */ |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1333 | int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1334 | { |
| 1335 | int ret = 0; |
| 1336 | |
| 1337 | if (priv->media_connected) { |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 1338 | if (priv->bss_mode == NL80211_IFTYPE_STATION) { |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1339 | ret = mwifiex_deauthenticate_infra(priv, mac); |
Bing Zhao | eecd825 | 2011-03-28 17:55:41 -0700 | [diff] [blame] | 1340 | } else if (priv->bss_mode == NL80211_IFTYPE_ADHOC) { |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1341 | ret = mwifiex_send_cmd_sync(priv, |
| 1342 | HostCmd_CMD_802_11_AD_HOC_STOP, |
| 1343 | HostCmd_ACT_GEN_SET, 0, NULL); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | return ret; |
| 1348 | } |
Amitkumar Karwar | 600f5d9 | 2011-04-13 17:27:06 -0700 | [diff] [blame] | 1349 | EXPORT_SYMBOL_GPL(mwifiex_deauthenticate); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1350 | |
| 1351 | /* |
| 1352 | * This function converts band to radio type used in channel TLV. |
| 1353 | */ |
| 1354 | u8 |
| 1355 | mwifiex_band_to_radio_type(u8 band) |
| 1356 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1357 | switch (band) { |
| 1358 | case BAND_A: |
| 1359 | case BAND_AN: |
| 1360 | case BAND_A | BAND_AN: |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1361 | return HostCmd_SCAN_RADIO_TYPE_A; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1362 | case BAND_B: |
| 1363 | case BAND_G: |
| 1364 | case BAND_B | BAND_G: |
| 1365 | default: |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 1366 | return HostCmd_SCAN_RADIO_TYPE_BG; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1367 | } |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1368 | } |