Avinash Patil | 40d0703 | 2012-05-08 18:30:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: AP specific command handling |
| 3 | * |
| 4 | * Copyright (C) 2012, 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 "main.h" |
| 21 | |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 22 | /* This function parses security related parameters from cfg80211_ap_settings |
| 23 | * and sets into FW understandable bss_config structure. |
| 24 | */ |
| 25 | int mwifiex_set_secure_params(struct mwifiex_private *priv, |
| 26 | struct mwifiex_uap_bss_param *bss_config, |
| 27 | struct cfg80211_ap_settings *params) { |
| 28 | int i; |
Avinash Patil | 9689353 | 2012-06-15 12:21:55 -0700 | [diff] [blame] | 29 | struct mwifiex_wep_key wep_key; |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 30 | |
Avinash Patil | 6ddcd46 | 2012-06-11 18:13:57 -0700 | [diff] [blame] | 31 | if (!params->privacy) { |
| 32 | bss_config->protocol = PROTOCOL_NO_SECURITY; |
| 33 | bss_config->key_mgmt = KEY_MGMT_NONE; |
| 34 | bss_config->wpa_cfg.length = 0; |
| 35 | priv->sec_info.wep_enabled = 0; |
| 36 | priv->sec_info.wpa_enabled = 0; |
| 37 | priv->sec_info.wpa2_enabled = 0; |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 42 | switch (params->auth_type) { |
| 43 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 44 | bss_config->auth_mode = WLAN_AUTH_OPEN; |
| 45 | break; |
| 46 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 47 | bss_config->auth_mode = WLAN_AUTH_SHARED_KEY; |
| 48 | break; |
| 49 | case NL80211_AUTHTYPE_NETWORK_EAP: |
| 50 | bss_config->auth_mode = WLAN_AUTH_LEAP; |
| 51 | break; |
| 52 | default: |
| 53 | bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO; |
| 54 | break; |
| 55 | } |
| 56 | |
| 57 | bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST; |
| 58 | |
| 59 | for (i = 0; i < params->crypto.n_akm_suites; i++) { |
| 60 | switch (params->crypto.akm_suites[i]) { |
| 61 | case WLAN_AKM_SUITE_8021X: |
| 62 | if (params->crypto.wpa_versions & |
| 63 | NL80211_WPA_VERSION_1) { |
| 64 | bss_config->protocol = PROTOCOL_WPA; |
| 65 | bss_config->key_mgmt = KEY_MGMT_EAP; |
| 66 | } |
| 67 | if (params->crypto.wpa_versions & |
| 68 | NL80211_WPA_VERSION_2) { |
Avinash Patil | 0fd66be | 2012-06-15 12:21:52 -0700 | [diff] [blame] | 69 | bss_config->protocol |= PROTOCOL_WPA2; |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 70 | bss_config->key_mgmt = KEY_MGMT_EAP; |
| 71 | } |
| 72 | break; |
| 73 | case WLAN_AKM_SUITE_PSK: |
| 74 | if (params->crypto.wpa_versions & |
| 75 | NL80211_WPA_VERSION_1) { |
| 76 | bss_config->protocol = PROTOCOL_WPA; |
| 77 | bss_config->key_mgmt = KEY_MGMT_PSK; |
| 78 | } |
| 79 | if (params->crypto.wpa_versions & |
| 80 | NL80211_WPA_VERSION_2) { |
Avinash Patil | 0fd66be | 2012-06-15 12:21:52 -0700 | [diff] [blame] | 81 | bss_config->protocol |= PROTOCOL_WPA2; |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 82 | bss_config->key_mgmt = KEY_MGMT_PSK; |
| 83 | } |
| 84 | break; |
| 85 | default: |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) { |
| 90 | switch (params->crypto.ciphers_pairwise[i]) { |
| 91 | case WLAN_CIPHER_SUITE_WEP40: |
| 92 | case WLAN_CIPHER_SUITE_WEP104: |
| 93 | break; |
| 94 | case WLAN_CIPHER_SUITE_TKIP: |
Avinash Patil | 0fd66be | 2012-06-15 12:21:52 -0700 | [diff] [blame] | 95 | if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1) |
| 96 | bss_config->wpa_cfg.pairwise_cipher_wpa |= |
| 97 | CIPHER_TKIP; |
| 98 | if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2) |
| 99 | bss_config->wpa_cfg.pairwise_cipher_wpa2 |= |
| 100 | CIPHER_TKIP; |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 101 | break; |
| 102 | case WLAN_CIPHER_SUITE_CCMP: |
Avinash Patil | 0fd66be | 2012-06-15 12:21:52 -0700 | [diff] [blame] | 103 | if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1) |
| 104 | bss_config->wpa_cfg.pairwise_cipher_wpa |= |
| 105 | CIPHER_AES_CCMP; |
| 106 | if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2) |
| 107 | bss_config->wpa_cfg.pairwise_cipher_wpa2 |= |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 108 | CIPHER_AES_CCMP; |
| 109 | default: |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | switch (params->crypto.cipher_group) { |
| 115 | case WLAN_CIPHER_SUITE_WEP40: |
| 116 | case WLAN_CIPHER_SUITE_WEP104: |
Avinash Patil | 9689353 | 2012-06-15 12:21:55 -0700 | [diff] [blame] | 117 | if (priv->sec_info.wep_enabled) { |
| 118 | bss_config->protocol = PROTOCOL_STATIC_WEP; |
| 119 | bss_config->key_mgmt = KEY_MGMT_NONE; |
| 120 | bss_config->wpa_cfg.length = 0; |
| 121 | |
| 122 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 123 | wep_key = priv->wep_key[i]; |
| 124 | bss_config->wep_cfg[i].key_index = i; |
| 125 | |
| 126 | if (priv->wep_key_curr_index == i) |
| 127 | bss_config->wep_cfg[i].is_default = 1; |
| 128 | else |
| 129 | bss_config->wep_cfg[i].is_default = 0; |
| 130 | |
| 131 | bss_config->wep_cfg[i].length = |
| 132 | wep_key.key_length; |
| 133 | memcpy(&bss_config->wep_cfg[i].key, |
| 134 | &wep_key.key_material, |
| 135 | wep_key.key_length); |
| 136 | } |
| 137 | } |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 138 | break; |
| 139 | case WLAN_CIPHER_SUITE_TKIP: |
| 140 | bss_config->wpa_cfg.group_cipher = CIPHER_TKIP; |
| 141 | break; |
| 142 | case WLAN_CIPHER_SUITE_CCMP: |
| 143 | bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP; |
| 144 | break; |
| 145 | default: |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
Avinash Patil | 2228125 | 2012-06-15 12:21:53 -0700 | [diff] [blame] | 152 | /* This function updates 11n related parameters from IE and sets them into |
| 153 | * bss_config structure. |
| 154 | */ |
| 155 | void |
| 156 | mwifiex_set_ht_params(struct mwifiex_private *priv, |
| 157 | struct mwifiex_uap_bss_param *bss_cfg, |
| 158 | struct cfg80211_ap_settings *params) |
| 159 | { |
| 160 | const u8 *ht_ie; |
| 161 | |
| 162 | if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info)) |
| 163 | return; |
| 164 | |
| 165 | ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail, |
| 166 | params->beacon.tail_len); |
| 167 | if (ht_ie) { |
| 168 | memcpy(&bss_cfg->ht_cap, ht_ie + 2, |
| 169 | sizeof(struct ieee80211_ht_cap)); |
| 170 | } else { |
| 171 | memset(&bss_cfg->ht_cap , 0, sizeof(struct ieee80211_ht_cap)); |
| 172 | bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP); |
| 173 | bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU; |
| 174 | } |
| 175 | |
| 176 | return; |
| 177 | } |
| 178 | |
Avinash Patil | 9b930ea | 2012-05-08 18:30:23 -0700 | [diff] [blame] | 179 | /* This function initializes some of mwifiex_uap_bss_param variables. |
| 180 | * This helps FW in ignoring invalid values. These values may or may not |
| 181 | * be get updated to valid ones at later stage. |
| 182 | */ |
| 183 | void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config) |
| 184 | { |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 185 | config->bcast_ssid_ctl = 0x7F; |
| 186 | config->radio_ctl = 0x7F; |
| 187 | config->dtim_period = 0x7F; |
| 188 | config->beacon_period = 0x7FFF; |
| 189 | config->auth_mode = 0x7F; |
Avinash Patil | 9b930ea | 2012-05-08 18:30:23 -0700 | [diff] [blame] | 190 | config->rts_threshold = 0x7FFF; |
| 191 | config->frag_threshold = 0x7FFF; |
| 192 | config->retry_limit = 0x7F; |
| 193 | } |
| 194 | |
Avinash Patil | e76268d | 2012-05-08 18:30:27 -0700 | [diff] [blame] | 195 | /* This function parses BSS related parameters from structure |
Avinash Patil | 5d66cb6 | 2012-06-15 12:21:54 -0700 | [diff] [blame] | 196 | * and prepares TLVs specific to WPA/WPA2 security. |
| 197 | * These TLVs are appended to command buffer. |
| 198 | */ |
| 199 | static void |
| 200 | mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size) |
| 201 | { |
| 202 | struct host_cmd_tlv_pwk_cipher *pwk_cipher; |
| 203 | struct host_cmd_tlv_gwk_cipher *gwk_cipher; |
| 204 | struct host_cmd_tlv_passphrase *passphrase; |
| 205 | struct host_cmd_tlv_akmp *tlv_akmp; |
| 206 | struct mwifiex_uap_bss_param *bss_cfg = cmd_buf; |
| 207 | u16 cmd_size = *param_size; |
| 208 | u8 *tlv = *tlv_buf; |
| 209 | |
| 210 | tlv_akmp = (struct host_cmd_tlv_akmp *)tlv; |
| 211 | tlv_akmp->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AKMP); |
| 212 | tlv_akmp->tlv.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) - |
| 213 | sizeof(struct host_cmd_tlv)); |
| 214 | tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation); |
| 215 | tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt); |
| 216 | cmd_size += sizeof(struct host_cmd_tlv_akmp); |
| 217 | tlv += sizeof(struct host_cmd_tlv_akmp); |
| 218 | |
| 219 | if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) { |
| 220 | pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv; |
| 221 | pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER); |
| 222 | pwk_cipher->tlv.len = |
| 223 | cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) - |
| 224 | sizeof(struct host_cmd_tlv)); |
| 225 | pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA); |
| 226 | pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa; |
| 227 | cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher); |
| 228 | tlv += sizeof(struct host_cmd_tlv_pwk_cipher); |
| 229 | } |
| 230 | |
| 231 | if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) { |
| 232 | pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv; |
| 233 | pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER); |
| 234 | pwk_cipher->tlv.len = |
| 235 | cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) - |
| 236 | sizeof(struct host_cmd_tlv)); |
| 237 | pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2); |
| 238 | pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2; |
| 239 | cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher); |
| 240 | tlv += sizeof(struct host_cmd_tlv_pwk_cipher); |
| 241 | } |
| 242 | |
| 243 | if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) { |
| 244 | gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv; |
| 245 | gwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER); |
| 246 | gwk_cipher->tlv.len = |
| 247 | cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) - |
| 248 | sizeof(struct host_cmd_tlv)); |
| 249 | gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher; |
| 250 | cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher); |
| 251 | tlv += sizeof(struct host_cmd_tlv_gwk_cipher); |
| 252 | } |
| 253 | |
| 254 | if (bss_cfg->wpa_cfg.length) { |
| 255 | passphrase = (struct host_cmd_tlv_passphrase *)tlv; |
| 256 | passphrase->tlv.type = cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE); |
| 257 | passphrase->tlv.len = cpu_to_le16(bss_cfg->wpa_cfg.length); |
| 258 | memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase, |
| 259 | bss_cfg->wpa_cfg.length); |
| 260 | cmd_size += sizeof(struct host_cmd_tlv) + |
| 261 | bss_cfg->wpa_cfg.length; |
| 262 | tlv += sizeof(struct host_cmd_tlv) + bss_cfg->wpa_cfg.length; |
| 263 | } |
| 264 | |
| 265 | *param_size = cmd_size; |
| 266 | *tlv_buf = tlv; |
| 267 | |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | /* This function parses BSS related parameters from structure |
Avinash Patil | 9689353 | 2012-06-15 12:21:55 -0700 | [diff] [blame] | 272 | * and prepares TLVs specific to WEP encryption. |
| 273 | * These TLVs are appended to command buffer. |
| 274 | */ |
| 275 | static void |
| 276 | mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size) |
| 277 | { |
| 278 | struct host_cmd_tlv_wep_key *wep_key; |
| 279 | u16 cmd_size = *param_size; |
| 280 | int i; |
| 281 | u8 *tlv = *tlv_buf; |
| 282 | struct mwifiex_uap_bss_param *bss_cfg = cmd_buf; |
| 283 | |
| 284 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 285 | if (bss_cfg->wep_cfg[i].length && |
| 286 | (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 || |
| 287 | bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) { |
| 288 | wep_key = (struct host_cmd_tlv_wep_key *)tlv; |
| 289 | wep_key->tlv.type = cpu_to_le16(TLV_TYPE_UAP_WEP_KEY); |
| 290 | wep_key->tlv.len = |
| 291 | cpu_to_le16(bss_cfg->wep_cfg[i].length + 2); |
| 292 | wep_key->key_index = bss_cfg->wep_cfg[i].key_index; |
| 293 | wep_key->is_default = bss_cfg->wep_cfg[i].is_default; |
| 294 | memcpy(wep_key->key, bss_cfg->wep_cfg[i].key, |
| 295 | bss_cfg->wep_cfg[i].length); |
| 296 | cmd_size += sizeof(struct host_cmd_tlv) + 2 + |
| 297 | bss_cfg->wep_cfg[i].length; |
| 298 | tlv += sizeof(struct host_cmd_tlv) + 2 + |
| 299 | bss_cfg->wep_cfg[i].length; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | *param_size = cmd_size; |
| 304 | *tlv_buf = tlv; |
| 305 | |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | /* This function parses BSS related parameters from structure |
Avinash Patil | e76268d | 2012-05-08 18:30:27 -0700 | [diff] [blame] | 310 | * and prepares TLVs. These TLVs are appended to command buffer. |
| 311 | */ |
| 312 | static int |
| 313 | mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size) |
Avinash Patil | 4db16a1 | 2012-05-08 18:30:20 -0700 | [diff] [blame] | 314 | { |
Avinash Patil | 12190c5 | 2012-05-08 18:30:24 -0700 | [diff] [blame] | 315 | struct host_cmd_tlv_dtim_period *dtim_period; |
| 316 | struct host_cmd_tlv_beacon_period *beacon_period; |
| 317 | struct host_cmd_tlv_ssid *ssid; |
Avinash Patil | 7a1c993 | 2012-05-29 15:39:05 -0700 | [diff] [blame] | 318 | struct host_cmd_tlv_bcast_ssid *bcast_ssid; |
Avinash Patil | 4db16a1 | 2012-05-08 18:30:20 -0700 | [diff] [blame] | 319 | struct host_cmd_tlv_channel_band *chan_band; |
Avinash Patil | 9b930ea | 2012-05-08 18:30:23 -0700 | [diff] [blame] | 320 | struct host_cmd_tlv_frag_threshold *frag_threshold; |
| 321 | struct host_cmd_tlv_rts_threshold *rts_threshold; |
| 322 | struct host_cmd_tlv_retry_limit *retry_limit; |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 323 | struct host_cmd_tlv_encrypt_protocol *encrypt_protocol; |
| 324 | struct host_cmd_tlv_auth_type *auth_type; |
Avinash Patil | 2228125 | 2012-06-15 12:21:53 -0700 | [diff] [blame] | 325 | struct mwifiex_ie_types_htcap *htcap; |
Avinash Patil | 4db16a1 | 2012-05-08 18:30:20 -0700 | [diff] [blame] | 326 | struct mwifiex_uap_bss_param *bss_cfg = cmd_buf; |
Avinash Patil | e76268d | 2012-05-08 18:30:27 -0700 | [diff] [blame] | 327 | u16 cmd_size = *param_size; |
Avinash Patil | 4db16a1 | 2012-05-08 18:30:20 -0700 | [diff] [blame] | 328 | |
Avinash Patil | 12190c5 | 2012-05-08 18:30:24 -0700 | [diff] [blame] | 329 | if (bss_cfg->ssid.ssid_len) { |
| 330 | ssid = (struct host_cmd_tlv_ssid *)tlv; |
| 331 | ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_SSID); |
| 332 | ssid->tlv.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len); |
| 333 | memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len); |
| 334 | cmd_size += sizeof(struct host_cmd_tlv) + |
| 335 | bss_cfg->ssid.ssid_len; |
| 336 | tlv += sizeof(struct host_cmd_tlv) + bss_cfg->ssid.ssid_len; |
Avinash Patil | 7a1c993 | 2012-05-29 15:39:05 -0700 | [diff] [blame] | 337 | |
| 338 | bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv; |
| 339 | bcast_ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID); |
| 340 | bcast_ssid->tlv.len = |
| 341 | cpu_to_le16(sizeof(bcast_ssid->bcast_ctl)); |
| 342 | bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl; |
| 343 | cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid); |
| 344 | tlv += sizeof(struct host_cmd_tlv_bcast_ssid); |
Avinash Patil | 12190c5 | 2012-05-08 18:30:24 -0700 | [diff] [blame] | 345 | } |
Avinash Patil | 4db16a1 | 2012-05-08 18:30:20 -0700 | [diff] [blame] | 346 | if (bss_cfg->channel && bss_cfg->channel <= MAX_CHANNEL_BAND_BG) { |
| 347 | chan_band = (struct host_cmd_tlv_channel_band *)tlv; |
| 348 | chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST); |
| 349 | chan_band->tlv.len = |
| 350 | cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) - |
| 351 | sizeof(struct host_cmd_tlv)); |
| 352 | chan_band->band_config = bss_cfg->band_cfg; |
| 353 | chan_band->channel = bss_cfg->channel; |
| 354 | cmd_size += sizeof(struct host_cmd_tlv_channel_band); |
| 355 | tlv += sizeof(struct host_cmd_tlv_channel_band); |
| 356 | } |
Avinash Patil | 12190c5 | 2012-05-08 18:30:24 -0700 | [diff] [blame] | 357 | if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD && |
| 358 | bss_cfg->beacon_period <= MAX_BEACON_PERIOD) { |
| 359 | beacon_period = (struct host_cmd_tlv_beacon_period *)tlv; |
| 360 | beacon_period->tlv.type = |
| 361 | cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD); |
| 362 | beacon_period->tlv.len = |
| 363 | cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) - |
| 364 | sizeof(struct host_cmd_tlv)); |
| 365 | beacon_period->period = cpu_to_le16(bss_cfg->beacon_period); |
| 366 | cmd_size += sizeof(struct host_cmd_tlv_beacon_period); |
| 367 | tlv += sizeof(struct host_cmd_tlv_beacon_period); |
| 368 | } |
| 369 | if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD && |
| 370 | bss_cfg->dtim_period <= MAX_DTIM_PERIOD) { |
| 371 | dtim_period = (struct host_cmd_tlv_dtim_period *)tlv; |
| 372 | dtim_period->tlv.type = cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD); |
| 373 | dtim_period->tlv.len = |
| 374 | cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) - |
| 375 | sizeof(struct host_cmd_tlv)); |
| 376 | dtim_period->period = bss_cfg->dtim_period; |
| 377 | cmd_size += sizeof(struct host_cmd_tlv_dtim_period); |
| 378 | tlv += sizeof(struct host_cmd_tlv_dtim_period); |
| 379 | } |
Avinash Patil | 9b930ea | 2012-05-08 18:30:23 -0700 | [diff] [blame] | 380 | if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) { |
| 381 | rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv; |
| 382 | rts_threshold->tlv.type = |
| 383 | cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD); |
| 384 | rts_threshold->tlv.len = |
| 385 | cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) - |
| 386 | sizeof(struct host_cmd_tlv)); |
| 387 | rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold); |
| 388 | cmd_size += sizeof(struct host_cmd_tlv_frag_threshold); |
| 389 | tlv += sizeof(struct host_cmd_tlv_frag_threshold); |
| 390 | } |
| 391 | if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) && |
| 392 | (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) { |
| 393 | frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv; |
| 394 | frag_threshold->tlv.type = |
| 395 | cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD); |
| 396 | frag_threshold->tlv.len = |
| 397 | cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) - |
| 398 | sizeof(struct host_cmd_tlv)); |
| 399 | frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold); |
| 400 | cmd_size += sizeof(struct host_cmd_tlv_frag_threshold); |
| 401 | tlv += sizeof(struct host_cmd_tlv_frag_threshold); |
| 402 | } |
| 403 | if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) { |
| 404 | retry_limit = (struct host_cmd_tlv_retry_limit *)tlv; |
| 405 | retry_limit->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT); |
| 406 | retry_limit->tlv.len = |
| 407 | cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) - |
| 408 | sizeof(struct host_cmd_tlv)); |
| 409 | retry_limit->limit = (u8)bss_cfg->retry_limit; |
| 410 | cmd_size += sizeof(struct host_cmd_tlv_retry_limit); |
| 411 | tlv += sizeof(struct host_cmd_tlv_retry_limit); |
| 412 | } |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 413 | if ((bss_cfg->protocol & PROTOCOL_WPA) || |
| 414 | (bss_cfg->protocol & PROTOCOL_WPA2) || |
Avinash Patil | 5d66cb6 | 2012-06-15 12:21:54 -0700 | [diff] [blame] | 415 | (bss_cfg->protocol & PROTOCOL_EAP)) |
| 416 | mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size); |
Avinash Patil | 9689353 | 2012-06-15 12:21:55 -0700 | [diff] [blame] | 417 | else |
| 418 | mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size); |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 419 | |
Avinash Patil | f752dcd | 2012-05-08 18:30:26 -0700 | [diff] [blame] | 420 | if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) || |
| 421 | (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) { |
| 422 | auth_type = (struct host_cmd_tlv_auth_type *)tlv; |
| 423 | auth_type->tlv.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE); |
| 424 | auth_type->tlv.len = |
| 425 | cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) - |
| 426 | sizeof(struct host_cmd_tlv)); |
| 427 | auth_type->auth_type = (u8)bss_cfg->auth_mode; |
| 428 | cmd_size += sizeof(struct host_cmd_tlv_auth_type); |
| 429 | tlv += sizeof(struct host_cmd_tlv_auth_type); |
| 430 | } |
| 431 | if (bss_cfg->protocol) { |
| 432 | encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv; |
| 433 | encrypt_protocol->tlv.type = |
| 434 | cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL); |
| 435 | encrypt_protocol->tlv.len = |
| 436 | cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol) |
| 437 | - sizeof(struct host_cmd_tlv)); |
| 438 | encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol); |
| 439 | cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol); |
| 440 | tlv += sizeof(struct host_cmd_tlv_encrypt_protocol); |
| 441 | } |
Avinash Patil | 4db16a1 | 2012-05-08 18:30:20 -0700 | [diff] [blame] | 442 | |
Avinash Patil | 2228125 | 2012-06-15 12:21:53 -0700 | [diff] [blame] | 443 | if (bss_cfg->ht_cap.cap_info) { |
| 444 | htcap = (struct mwifiex_ie_types_htcap *)tlv; |
| 445 | htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY); |
| 446 | htcap->header.len = |
| 447 | cpu_to_le16(sizeof(struct ieee80211_ht_cap)); |
| 448 | htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info; |
| 449 | htcap->ht_cap.ampdu_params_info = |
| 450 | bss_cfg->ht_cap.ampdu_params_info; |
| 451 | memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs, |
| 452 | sizeof(struct ieee80211_mcs_info)); |
| 453 | htcap->ht_cap.extended_ht_cap_info = |
| 454 | bss_cfg->ht_cap.extended_ht_cap_info; |
| 455 | htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info; |
| 456 | htcap->ht_cap.antenna_selection_info = |
| 457 | bss_cfg->ht_cap.antenna_selection_info; |
| 458 | cmd_size += sizeof(struct mwifiex_ie_types_htcap); |
| 459 | tlv += sizeof(struct mwifiex_ie_types_htcap); |
| 460 | } |
| 461 | |
Avinash Patil | e76268d | 2012-05-08 18:30:27 -0700 | [diff] [blame] | 462 | *param_size = cmd_size; |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
Avinash Patil | ede98bf | 2012-05-08 18:30:28 -0700 | [diff] [blame] | 467 | /* This function parses custom IEs from IE list and prepares command buffer */ |
| 468 | static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size) |
| 469 | { |
| 470 | struct mwifiex_ie_list *ap_ie = cmd_buf; |
| 471 | struct host_cmd_tlv *tlv_ie = (struct host_cmd_tlv *)tlv; |
| 472 | |
| 473 | if (!ap_ie || !ap_ie->len || !ap_ie->ie_list) |
| 474 | return -1; |
| 475 | |
| 476 | *ie_size += le16_to_cpu(ap_ie->len) + sizeof(struct host_cmd_tlv); |
| 477 | |
| 478 | tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE); |
| 479 | tlv_ie->len = ap_ie->len; |
| 480 | tlv += sizeof(struct host_cmd_tlv); |
| 481 | |
| 482 | memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len)); |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
Avinash Patil | e76268d | 2012-05-08 18:30:27 -0700 | [diff] [blame] | 487 | /* Parse AP config structure and prepare TLV based command structure |
| 488 | * to be sent to FW for uAP configuration |
| 489 | */ |
| 490 | static int |
| 491 | mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action, |
| 492 | u32 type, void *cmd_buf) |
| 493 | { |
| 494 | u8 *tlv; |
Avinash Patil | ede98bf | 2012-05-08 18:30:28 -0700 | [diff] [blame] | 495 | u16 cmd_size, param_size, ie_size; |
Avinash Patil | e76268d | 2012-05-08 18:30:27 -0700 | [diff] [blame] | 496 | struct host_cmd_ds_sys_config *sys_cfg; |
| 497 | |
| 498 | cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG); |
| 499 | cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN); |
| 500 | sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config; |
| 501 | sys_cfg->action = cpu_to_le16(cmd_action); |
| 502 | tlv = sys_cfg->tlv; |
| 503 | |
| 504 | switch (type) { |
| 505 | case UAP_BSS_PARAMS_I: |
| 506 | param_size = cmd_size; |
| 507 | if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, ¶m_size)) |
| 508 | return -1; |
| 509 | cmd->size = cpu_to_le16(param_size); |
| 510 | break; |
Avinash Patil | ede98bf | 2012-05-08 18:30:28 -0700 | [diff] [blame] | 511 | case UAP_CUSTOM_IE_I: |
| 512 | ie_size = cmd_size; |
| 513 | if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size)) |
| 514 | return -1; |
| 515 | cmd->size = cpu_to_le16(ie_size); |
| 516 | break; |
Avinash Patil | e76268d | 2012-05-08 18:30:27 -0700 | [diff] [blame] | 517 | default: |
| 518 | return -1; |
| 519 | } |
| 520 | |
Avinash Patil | 4db16a1 | 2012-05-08 18:30:20 -0700 | [diff] [blame] | 521 | return 0; |
| 522 | } |
| 523 | |
Avinash Patil | 40d0703 | 2012-05-08 18:30:19 -0700 | [diff] [blame] | 524 | /* This function prepares the AP specific commands before sending them |
| 525 | * to the firmware. |
| 526 | * This is a generic function which calls specific command preparation |
| 527 | * routines based upon the command number. |
| 528 | */ |
| 529 | int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no, |
Avinash Patil | e76268d | 2012-05-08 18:30:27 -0700 | [diff] [blame] | 530 | u16 cmd_action, u32 type, |
Avinash Patil | 40d0703 | 2012-05-08 18:30:19 -0700 | [diff] [blame] | 531 | void *data_buf, void *cmd_buf) |
| 532 | { |
| 533 | struct host_cmd_ds_command *cmd = cmd_buf; |
| 534 | |
| 535 | switch (cmd_no) { |
Avinash Patil | 4db16a1 | 2012-05-08 18:30:20 -0700 | [diff] [blame] | 536 | case HostCmd_CMD_UAP_SYS_CONFIG: |
Avinash Patil | e76268d | 2012-05-08 18:30:27 -0700 | [diff] [blame] | 537 | if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf)) |
Avinash Patil | 4db16a1 | 2012-05-08 18:30:20 -0700 | [diff] [blame] | 538 | return -1; |
| 539 | break; |
Avinash Patil | 40d0703 | 2012-05-08 18:30:19 -0700 | [diff] [blame] | 540 | case HostCmd_CMD_UAP_BSS_START: |
| 541 | case HostCmd_CMD_UAP_BSS_STOP: |
| 542 | cmd->command = cpu_to_le16(cmd_no); |
| 543 | cmd->size = cpu_to_le16(S_DS_GEN); |
| 544 | break; |
| 545 | default: |
| 546 | dev_err(priv->adapter->dev, |
| 547 | "PREP_CMD: unknown cmd %#x\n", cmd_no); |
| 548 | return -1; |
| 549 | } |
| 550 | |
| 551 | return 0; |
| 552 | } |