0001
0002
0003
0004
0005
0006
0007
0008 #include "main.h"
0009 #include "11ac.h"
0010 #include "11n.h"
0011
0012
0013
0014
0015 int mwifiex_set_secure_params(struct mwifiex_private *priv,
0016 struct mwifiex_uap_bss_param *bss_config,
0017 struct cfg80211_ap_settings *params) {
0018 int i;
0019 struct mwifiex_wep_key wep_key;
0020
0021 if (!params->privacy) {
0022 bss_config->protocol = PROTOCOL_NO_SECURITY;
0023 bss_config->key_mgmt = KEY_MGMT_NONE;
0024 bss_config->wpa_cfg.length = 0;
0025 priv->sec_info.wep_enabled = 0;
0026 priv->sec_info.wpa_enabled = 0;
0027 priv->sec_info.wpa2_enabled = 0;
0028
0029 return 0;
0030 }
0031
0032 switch (params->auth_type) {
0033 case NL80211_AUTHTYPE_OPEN_SYSTEM:
0034 bss_config->auth_mode = WLAN_AUTH_OPEN;
0035 break;
0036 case NL80211_AUTHTYPE_SHARED_KEY:
0037 bss_config->auth_mode = WLAN_AUTH_SHARED_KEY;
0038 break;
0039 case NL80211_AUTHTYPE_NETWORK_EAP:
0040 bss_config->auth_mode = WLAN_AUTH_LEAP;
0041 break;
0042 default:
0043 bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO;
0044 break;
0045 }
0046
0047 bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
0048
0049 for (i = 0; i < params->crypto.n_akm_suites; i++) {
0050 switch (params->crypto.akm_suites[i]) {
0051 case WLAN_AKM_SUITE_8021X:
0052 if (params->crypto.wpa_versions &
0053 NL80211_WPA_VERSION_1) {
0054 bss_config->protocol = PROTOCOL_WPA;
0055 bss_config->key_mgmt = KEY_MGMT_EAP;
0056 }
0057 if (params->crypto.wpa_versions &
0058 NL80211_WPA_VERSION_2) {
0059 bss_config->protocol |= PROTOCOL_WPA2;
0060 bss_config->key_mgmt = KEY_MGMT_EAP;
0061 }
0062 break;
0063 case WLAN_AKM_SUITE_PSK:
0064 if (params->crypto.wpa_versions &
0065 NL80211_WPA_VERSION_1) {
0066 bss_config->protocol = PROTOCOL_WPA;
0067 bss_config->key_mgmt = KEY_MGMT_PSK;
0068 }
0069 if (params->crypto.wpa_versions &
0070 NL80211_WPA_VERSION_2) {
0071 bss_config->protocol |= PROTOCOL_WPA2;
0072 bss_config->key_mgmt = KEY_MGMT_PSK;
0073 }
0074 break;
0075 default:
0076 break;
0077 }
0078 }
0079 for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) {
0080 switch (params->crypto.ciphers_pairwise[i]) {
0081 case WLAN_CIPHER_SUITE_WEP40:
0082 case WLAN_CIPHER_SUITE_WEP104:
0083 break;
0084 case WLAN_CIPHER_SUITE_TKIP:
0085 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
0086 bss_config->wpa_cfg.pairwise_cipher_wpa |=
0087 CIPHER_TKIP;
0088 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
0089 bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
0090 CIPHER_TKIP;
0091 break;
0092 case WLAN_CIPHER_SUITE_CCMP:
0093 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
0094 bss_config->wpa_cfg.pairwise_cipher_wpa |=
0095 CIPHER_AES_CCMP;
0096 if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
0097 bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
0098 CIPHER_AES_CCMP;
0099 break;
0100 default:
0101 break;
0102 }
0103 }
0104
0105 switch (params->crypto.cipher_group) {
0106 case WLAN_CIPHER_SUITE_WEP40:
0107 case WLAN_CIPHER_SUITE_WEP104:
0108 if (priv->sec_info.wep_enabled) {
0109 bss_config->protocol = PROTOCOL_STATIC_WEP;
0110 bss_config->key_mgmt = KEY_MGMT_NONE;
0111 bss_config->wpa_cfg.length = 0;
0112
0113 for (i = 0; i < NUM_WEP_KEYS; i++) {
0114 wep_key = priv->wep_key[i];
0115 bss_config->wep_cfg[i].key_index = i;
0116
0117 if (priv->wep_key_curr_index == i)
0118 bss_config->wep_cfg[i].is_default = 1;
0119 else
0120 bss_config->wep_cfg[i].is_default = 0;
0121
0122 bss_config->wep_cfg[i].length =
0123 wep_key.key_length;
0124 memcpy(&bss_config->wep_cfg[i].key,
0125 &wep_key.key_material,
0126 wep_key.key_length);
0127 }
0128 }
0129 break;
0130 case WLAN_CIPHER_SUITE_TKIP:
0131 bss_config->wpa_cfg.group_cipher = CIPHER_TKIP;
0132 break;
0133 case WLAN_CIPHER_SUITE_CCMP:
0134 bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP;
0135 break;
0136 default:
0137 break;
0138 }
0139
0140 return 0;
0141 }
0142
0143
0144
0145
0146 void
0147 mwifiex_set_ht_params(struct mwifiex_private *priv,
0148 struct mwifiex_uap_bss_param *bss_cfg,
0149 struct cfg80211_ap_settings *params)
0150 {
0151 const u8 *ht_ie;
0152
0153 if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
0154 return;
0155
0156 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
0157 params->beacon.tail_len);
0158 if (ht_ie) {
0159 memcpy(&bss_cfg->ht_cap, ht_ie + 2,
0160 sizeof(struct ieee80211_ht_cap));
0161 priv->ap_11n_enabled = 1;
0162 } else {
0163 memset(&bss_cfg->ht_cap, 0, sizeof(struct ieee80211_ht_cap));
0164 bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
0165 bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
0166 }
0167
0168 return;
0169 }
0170
0171
0172
0173
0174 void mwifiex_set_vht_params(struct mwifiex_private *priv,
0175 struct mwifiex_uap_bss_param *bss_cfg,
0176 struct cfg80211_ap_settings *params)
0177 {
0178 const u8 *vht_ie;
0179
0180 vht_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, params->beacon.tail,
0181 params->beacon.tail_len);
0182 if (vht_ie) {
0183 memcpy(&bss_cfg->vht_cap, vht_ie + 2,
0184 sizeof(struct ieee80211_vht_cap));
0185 priv->ap_11ac_enabled = 1;
0186 } else {
0187 priv->ap_11ac_enabled = 0;
0188 }
0189
0190 return;
0191 }
0192
0193
0194
0195
0196 void mwifiex_set_tpc_params(struct mwifiex_private *priv,
0197 struct mwifiex_uap_bss_param *bss_cfg,
0198 struct cfg80211_ap_settings *params)
0199 {
0200 const u8 *tpc_ie;
0201
0202 tpc_ie = cfg80211_find_ie(WLAN_EID_TPC_REQUEST, params->beacon.tail,
0203 params->beacon.tail_len);
0204 if (tpc_ie)
0205 bss_cfg->power_constraint = *(tpc_ie + 2);
0206 else
0207 bss_cfg->power_constraint = 0;
0208 }
0209
0210
0211
0212
0213 void mwifiex_set_vht_width(struct mwifiex_private *priv,
0214 enum nl80211_chan_width width,
0215 bool ap_11ac_enable)
0216 {
0217 struct mwifiex_adapter *adapter = priv->adapter;
0218 struct mwifiex_11ac_vht_cfg vht_cfg;
0219
0220 vht_cfg.band_config = VHT_CFG_5GHZ;
0221 vht_cfg.cap_info = adapter->hw_dot_11ac_dev_cap;
0222
0223 if (!ap_11ac_enable) {
0224 vht_cfg.mcs_tx_set = DISABLE_VHT_MCS_SET;
0225 vht_cfg.mcs_rx_set = DISABLE_VHT_MCS_SET;
0226 } else {
0227 vht_cfg.mcs_tx_set = DEFAULT_VHT_MCS_SET;
0228 vht_cfg.mcs_rx_set = DEFAULT_VHT_MCS_SET;
0229 }
0230
0231 vht_cfg.misc_config = VHT_CAP_UAP_ONLY;
0232
0233 if (ap_11ac_enable && width >= NL80211_CHAN_WIDTH_80)
0234 vht_cfg.misc_config |= VHT_BW_80_160_80P80;
0235
0236 mwifiex_send_cmd(priv, HostCmd_CMD_11AC_CFG,
0237 HostCmd_ACT_GEN_SET, 0, &vht_cfg, true);
0238
0239 return;
0240 }
0241
0242
0243
0244
0245 void
0246 mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
0247 struct cfg80211_ap_settings *params)
0248 {
0249 struct ieee_types_header *rate_ie;
0250 int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
0251 const u8 *var_pos = params->beacon.head + var_offset;
0252 int len = params->beacon.head_len - var_offset;
0253 u8 rate_len = 0;
0254
0255 rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
0256 if (rate_ie) {
0257 if (rate_ie->len > MWIFIEX_SUPPORTED_RATES)
0258 return;
0259 memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
0260 rate_len = rate_ie->len;
0261 }
0262
0263 rate_ie = (void *)cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
0264 params->beacon.tail,
0265 params->beacon.tail_len);
0266 if (rate_ie) {
0267 if (rate_ie->len > MWIFIEX_SUPPORTED_RATES - rate_len)
0268 return;
0269 memcpy(bss_cfg->rates + rate_len, rate_ie + 1, rate_ie->len);
0270 }
0271
0272 return;
0273 }
0274
0275
0276
0277
0278
0279 void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
0280 {
0281 config->bcast_ssid_ctl = 0x7F;
0282 config->radio_ctl = 0x7F;
0283 config->dtim_period = 0x7F;
0284 config->beacon_period = 0x7FFF;
0285 config->auth_mode = 0x7F;
0286 config->rts_threshold = 0x7FFF;
0287 config->frag_threshold = 0x7FFF;
0288 config->retry_limit = 0x7F;
0289 config->qos_info = 0xFF;
0290 }
0291
0292
0293
0294
0295
0296 static void
0297 mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
0298 {
0299 struct host_cmd_tlv_pwk_cipher *pwk_cipher;
0300 struct host_cmd_tlv_gwk_cipher *gwk_cipher;
0301 struct host_cmd_tlv_passphrase *passphrase;
0302 struct host_cmd_tlv_akmp *tlv_akmp;
0303 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
0304 u16 cmd_size = *param_size;
0305 u8 *tlv = *tlv_buf;
0306
0307 tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
0308 tlv_akmp->header.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
0309 tlv_akmp->header.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
0310 sizeof(struct mwifiex_ie_types_header));
0311 tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
0312 tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
0313 cmd_size += sizeof(struct host_cmd_tlv_akmp);
0314 tlv += sizeof(struct host_cmd_tlv_akmp);
0315
0316 if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
0317 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
0318 pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
0319 pwk_cipher->header.len =
0320 cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
0321 sizeof(struct mwifiex_ie_types_header));
0322 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
0323 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
0324 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
0325 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
0326 }
0327
0328 if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
0329 pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
0330 pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
0331 pwk_cipher->header.len =
0332 cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
0333 sizeof(struct mwifiex_ie_types_header));
0334 pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
0335 pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
0336 cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
0337 tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
0338 }
0339
0340 if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
0341 gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
0342 gwk_cipher->header.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
0343 gwk_cipher->header.len =
0344 cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
0345 sizeof(struct mwifiex_ie_types_header));
0346 gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
0347 cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
0348 tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
0349 }
0350
0351 if (bss_cfg->wpa_cfg.length) {
0352 passphrase = (struct host_cmd_tlv_passphrase *)tlv;
0353 passphrase->header.type =
0354 cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
0355 passphrase->header.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
0356 memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
0357 bss_cfg->wpa_cfg.length);
0358 cmd_size += sizeof(struct mwifiex_ie_types_header) +
0359 bss_cfg->wpa_cfg.length;
0360 tlv += sizeof(struct mwifiex_ie_types_header) +
0361 bss_cfg->wpa_cfg.length;
0362 }
0363
0364 *param_size = cmd_size;
0365 *tlv_buf = tlv;
0366
0367 return;
0368 }
0369
0370
0371
0372
0373 void
0374 mwifiex_set_wmm_params(struct mwifiex_private *priv,
0375 struct mwifiex_uap_bss_param *bss_cfg,
0376 struct cfg80211_ap_settings *params)
0377 {
0378 const u8 *vendor_ie;
0379 const u8 *wmm_ie;
0380 static const u8 wmm_oui[] = {0x00, 0x50, 0xf2, 0x02};
0381
0382 vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
0383 WLAN_OUI_TYPE_MICROSOFT_WMM,
0384 params->beacon.tail,
0385 params->beacon.tail_len);
0386 if (vendor_ie) {
0387 wmm_ie = vendor_ie;
0388 if (*(wmm_ie + 1) > sizeof(struct mwifiex_types_wmm_info))
0389 return;
0390 memcpy(&bss_cfg->wmm_info, wmm_ie +
0391 sizeof(struct ieee_types_header), *(wmm_ie + 1));
0392 priv->wmm_enabled = 1;
0393 } else {
0394 memset(&bss_cfg->wmm_info, 0, sizeof(bss_cfg->wmm_info));
0395 memcpy(&bss_cfg->wmm_info.oui, wmm_oui, sizeof(wmm_oui));
0396 bss_cfg->wmm_info.subtype = MWIFIEX_WMM_SUBTYPE;
0397 bss_cfg->wmm_info.version = MWIFIEX_WMM_VERSION;
0398 priv->wmm_enabled = 0;
0399 }
0400
0401 bss_cfg->qos_info = 0x00;
0402 return;
0403 }
0404
0405
0406
0407
0408 static void
0409 mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
0410 {
0411 struct host_cmd_tlv_wep_key *wep_key;
0412 u16 cmd_size = *param_size;
0413 int i;
0414 u8 *tlv = *tlv_buf;
0415 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
0416
0417 for (i = 0; i < NUM_WEP_KEYS; i++) {
0418 if (bss_cfg->wep_cfg[i].length &&
0419 (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
0420 bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
0421 wep_key = (struct host_cmd_tlv_wep_key *)tlv;
0422 wep_key->header.type =
0423 cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
0424 wep_key->header.len =
0425 cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
0426 wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
0427 wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
0428 memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
0429 bss_cfg->wep_cfg[i].length);
0430 cmd_size += sizeof(struct mwifiex_ie_types_header) + 2 +
0431 bss_cfg->wep_cfg[i].length;
0432 tlv += sizeof(struct mwifiex_ie_types_header) + 2 +
0433 bss_cfg->wep_cfg[i].length;
0434 }
0435 }
0436
0437 *param_size = cmd_size;
0438 *tlv_buf = tlv;
0439
0440 return;
0441 }
0442
0443
0444
0445 void mwifiex_config_uap_11d(struct mwifiex_private *priv,
0446 struct cfg80211_beacon_data *beacon_data)
0447 {
0448 enum state_11d_t state_11d;
0449 const u8 *country_ie;
0450
0451 country_ie = cfg80211_find_ie(WLAN_EID_COUNTRY, beacon_data->tail,
0452 beacon_data->tail_len);
0453 if (country_ie) {
0454
0455 state_11d = ENABLE_11D;
0456 if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
0457 HostCmd_ACT_GEN_SET, DOT11D_I,
0458 &state_11d, true)) {
0459 mwifiex_dbg(priv->adapter, ERROR,
0460 "11D: failed to enable 11D\n");
0461 }
0462 }
0463 }
0464
0465
0466
0467
0468 static int
0469 mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
0470 {
0471 struct host_cmd_tlv_dtim_period *dtim_period;
0472 struct host_cmd_tlv_beacon_period *beacon_period;
0473 struct host_cmd_tlv_ssid *ssid;
0474 struct host_cmd_tlv_bcast_ssid *bcast_ssid;
0475 struct host_cmd_tlv_channel_band *chan_band;
0476 struct host_cmd_tlv_frag_threshold *frag_threshold;
0477 struct host_cmd_tlv_rts_threshold *rts_threshold;
0478 struct host_cmd_tlv_retry_limit *retry_limit;
0479 struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
0480 struct host_cmd_tlv_auth_type *auth_type;
0481 struct host_cmd_tlv_rates *tlv_rates;
0482 struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
0483 struct host_cmd_tlv_power_constraint *pwr_ct;
0484 struct mwifiex_ie_types_htcap *htcap;
0485 struct mwifiex_ie_types_wmmcap *wmm_cap;
0486 struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
0487 int i;
0488 u16 cmd_size = *param_size;
0489
0490 if (bss_cfg->ssid.ssid_len) {
0491 ssid = (struct host_cmd_tlv_ssid *)tlv;
0492 ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
0493 ssid->header.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
0494 memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
0495 cmd_size += sizeof(struct mwifiex_ie_types_header) +
0496 bss_cfg->ssid.ssid_len;
0497 tlv += sizeof(struct mwifiex_ie_types_header) +
0498 bss_cfg->ssid.ssid_len;
0499
0500 bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
0501 bcast_ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
0502 bcast_ssid->header.len =
0503 cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
0504 bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
0505 cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
0506 tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
0507 }
0508 if (bss_cfg->rates[0]) {
0509 tlv_rates = (struct host_cmd_tlv_rates *)tlv;
0510 tlv_rates->header.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
0511
0512 for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
0513 i++)
0514 tlv_rates->rates[i] = bss_cfg->rates[i];
0515
0516 tlv_rates->header.len = cpu_to_le16(i);
0517 cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
0518 tlv += sizeof(struct host_cmd_tlv_rates) + i;
0519 }
0520 if (bss_cfg->channel &&
0521 (((bss_cfg->band_cfg & BIT(0)) == BAND_CONFIG_BG &&
0522 bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
0523 ((bss_cfg->band_cfg & BIT(0)) == BAND_CONFIG_A &&
0524 bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
0525 chan_band = (struct host_cmd_tlv_channel_band *)tlv;
0526 chan_band->header.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
0527 chan_band->header.len =
0528 cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
0529 sizeof(struct mwifiex_ie_types_header));
0530 chan_band->band_config = bss_cfg->band_cfg;
0531 chan_band->channel = bss_cfg->channel;
0532 cmd_size += sizeof(struct host_cmd_tlv_channel_band);
0533 tlv += sizeof(struct host_cmd_tlv_channel_band);
0534 }
0535 if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
0536 bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
0537 beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
0538 beacon_period->header.type =
0539 cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
0540 beacon_period->header.len =
0541 cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
0542 sizeof(struct mwifiex_ie_types_header));
0543 beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
0544 cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
0545 tlv += sizeof(struct host_cmd_tlv_beacon_period);
0546 }
0547 if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
0548 bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
0549 dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
0550 dtim_period->header.type =
0551 cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
0552 dtim_period->header.len =
0553 cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
0554 sizeof(struct mwifiex_ie_types_header));
0555 dtim_period->period = bss_cfg->dtim_period;
0556 cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
0557 tlv += sizeof(struct host_cmd_tlv_dtim_period);
0558 }
0559 if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
0560 rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
0561 rts_threshold->header.type =
0562 cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
0563 rts_threshold->header.len =
0564 cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
0565 sizeof(struct mwifiex_ie_types_header));
0566 rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
0567 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
0568 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
0569 }
0570 if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
0571 (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
0572 frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
0573 frag_threshold->header.type =
0574 cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
0575 frag_threshold->header.len =
0576 cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
0577 sizeof(struct mwifiex_ie_types_header));
0578 frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
0579 cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
0580 tlv += sizeof(struct host_cmd_tlv_frag_threshold);
0581 }
0582 if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
0583 retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
0584 retry_limit->header.type =
0585 cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
0586 retry_limit->header.len =
0587 cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
0588 sizeof(struct mwifiex_ie_types_header));
0589 retry_limit->limit = (u8)bss_cfg->retry_limit;
0590 cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
0591 tlv += sizeof(struct host_cmd_tlv_retry_limit);
0592 }
0593 if ((bss_cfg->protocol & PROTOCOL_WPA) ||
0594 (bss_cfg->protocol & PROTOCOL_WPA2) ||
0595 (bss_cfg->protocol & PROTOCOL_EAP))
0596 mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
0597 else
0598 mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
0599
0600 if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
0601 (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
0602 auth_type = (struct host_cmd_tlv_auth_type *)tlv;
0603 auth_type->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
0604 auth_type->header.len =
0605 cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
0606 sizeof(struct mwifiex_ie_types_header));
0607 auth_type->auth_type = (u8)bss_cfg->auth_mode;
0608 cmd_size += sizeof(struct host_cmd_tlv_auth_type);
0609 tlv += sizeof(struct host_cmd_tlv_auth_type);
0610 }
0611 if (bss_cfg->protocol) {
0612 encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
0613 encrypt_protocol->header.type =
0614 cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
0615 encrypt_protocol->header.len =
0616 cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
0617 - sizeof(struct mwifiex_ie_types_header));
0618 encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
0619 cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
0620 tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
0621 }
0622
0623 if (bss_cfg->ht_cap.cap_info) {
0624 htcap = (struct mwifiex_ie_types_htcap *)tlv;
0625 htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
0626 htcap->header.len =
0627 cpu_to_le16(sizeof(struct ieee80211_ht_cap));
0628 htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
0629 htcap->ht_cap.ampdu_params_info =
0630 bss_cfg->ht_cap.ampdu_params_info;
0631 memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
0632 sizeof(struct ieee80211_mcs_info));
0633 htcap->ht_cap.extended_ht_cap_info =
0634 bss_cfg->ht_cap.extended_ht_cap_info;
0635 htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
0636 htcap->ht_cap.antenna_selection_info =
0637 bss_cfg->ht_cap.antenna_selection_info;
0638 cmd_size += sizeof(struct mwifiex_ie_types_htcap);
0639 tlv += sizeof(struct mwifiex_ie_types_htcap);
0640 }
0641
0642 if (bss_cfg->wmm_info.qos_info != 0xFF) {
0643 wmm_cap = (struct mwifiex_ie_types_wmmcap *)tlv;
0644 wmm_cap->header.type = cpu_to_le16(WLAN_EID_VENDOR_SPECIFIC);
0645 wmm_cap->header.len = cpu_to_le16(sizeof(wmm_cap->wmm_info));
0646 memcpy(&wmm_cap->wmm_info, &bss_cfg->wmm_info,
0647 sizeof(wmm_cap->wmm_info));
0648 cmd_size += sizeof(struct mwifiex_ie_types_wmmcap);
0649 tlv += sizeof(struct mwifiex_ie_types_wmmcap);
0650 }
0651
0652 if (bss_cfg->sta_ao_timer) {
0653 ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
0654 ao_timer->header.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
0655 ao_timer->header.len = cpu_to_le16(sizeof(*ao_timer) -
0656 sizeof(struct mwifiex_ie_types_header));
0657 ao_timer->sta_ao_timer = cpu_to_le32(bss_cfg->sta_ao_timer);
0658 cmd_size += sizeof(*ao_timer);
0659 tlv += sizeof(*ao_timer);
0660 }
0661
0662 if (bss_cfg->power_constraint) {
0663 pwr_ct = (void *)tlv;
0664 pwr_ct->header.type = cpu_to_le16(TLV_TYPE_PWR_CONSTRAINT);
0665 pwr_ct->header.len = cpu_to_le16(sizeof(u8));
0666 pwr_ct->constraint = bss_cfg->power_constraint;
0667 cmd_size += sizeof(*pwr_ct);
0668 tlv += sizeof(*pwr_ct);
0669 }
0670
0671 if (bss_cfg->ps_sta_ao_timer) {
0672 ps_ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
0673 ps_ao_timer->header.type =
0674 cpu_to_le16(TLV_TYPE_UAP_PS_AO_TIMER);
0675 ps_ao_timer->header.len = cpu_to_le16(sizeof(*ps_ao_timer) -
0676 sizeof(struct mwifiex_ie_types_header));
0677 ps_ao_timer->sta_ao_timer =
0678 cpu_to_le32(bss_cfg->ps_sta_ao_timer);
0679 cmd_size += sizeof(*ps_ao_timer);
0680 tlv += sizeof(*ps_ao_timer);
0681 }
0682
0683 *param_size = cmd_size;
0684
0685 return 0;
0686 }
0687
0688
0689 static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
0690 {
0691 struct mwifiex_ie_list *ap_ie = cmd_buf;
0692 struct mwifiex_ie_types_header *tlv_ie = (void *)tlv;
0693
0694 if (!ap_ie || !ap_ie->len)
0695 return -1;
0696
0697 *ie_size += le16_to_cpu(ap_ie->len) +
0698 sizeof(struct mwifiex_ie_types_header);
0699
0700 tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
0701 tlv_ie->len = ap_ie->len;
0702 tlv += sizeof(struct mwifiex_ie_types_header);
0703
0704 memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
0705
0706 return 0;
0707 }
0708
0709
0710
0711
0712 static int
0713 mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
0714 u32 type, void *cmd_buf)
0715 {
0716 u8 *tlv;
0717 u16 cmd_size, param_size, ie_size;
0718 struct host_cmd_ds_sys_config *sys_cfg;
0719
0720 cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
0721 cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
0722 sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
0723 sys_cfg->action = cpu_to_le16(cmd_action);
0724 tlv = sys_cfg->tlv;
0725
0726 switch (type) {
0727 case UAP_BSS_PARAMS_I:
0728 param_size = cmd_size;
0729 if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, ¶m_size))
0730 return -1;
0731 cmd->size = cpu_to_le16(param_size);
0732 break;
0733 case UAP_CUSTOM_IE_I:
0734 ie_size = cmd_size;
0735 if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
0736 return -1;
0737 cmd->size = cpu_to_le16(ie_size);
0738 break;
0739 default:
0740 return -1;
0741 }
0742
0743 return 0;
0744 }
0745
0746
0747
0748
0749 static int mwifiex_cmd_uap_sta_deauth(struct mwifiex_private *priv,
0750 struct host_cmd_ds_command *cmd, u8 *mac)
0751 {
0752 struct host_cmd_ds_sta_deauth *sta_deauth = &cmd->params.sta_deauth;
0753
0754 cmd->command = cpu_to_le16(HostCmd_CMD_UAP_STA_DEAUTH);
0755 memcpy(sta_deauth->mac, mac, ETH_ALEN);
0756 sta_deauth->reason = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
0757
0758 cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_sta_deauth) +
0759 S_DS_GEN);
0760 return 0;
0761 }
0762
0763
0764
0765
0766
0767
0768 int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
0769 u16 cmd_action, u32 type,
0770 void *data_buf, void *cmd_buf)
0771 {
0772 struct host_cmd_ds_command *cmd = cmd_buf;
0773
0774 switch (cmd_no) {
0775 case HostCmd_CMD_UAP_SYS_CONFIG:
0776 if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
0777 return -1;
0778 break;
0779 case HostCmd_CMD_UAP_BSS_START:
0780 case HostCmd_CMD_UAP_BSS_STOP:
0781 case HOST_CMD_APCMD_SYS_RESET:
0782 case HOST_CMD_APCMD_STA_LIST:
0783 cmd->command = cpu_to_le16(cmd_no);
0784 cmd->size = cpu_to_le16(S_DS_GEN);
0785 break;
0786 case HostCmd_CMD_UAP_STA_DEAUTH:
0787 if (mwifiex_cmd_uap_sta_deauth(priv, cmd, data_buf))
0788 return -1;
0789 break;
0790 case HostCmd_CMD_CHAN_REPORT_REQUEST:
0791 if (mwifiex_cmd_issue_chan_report_request(priv, cmd_buf,
0792 data_buf))
0793 return -1;
0794 break;
0795 default:
0796 mwifiex_dbg(priv->adapter, ERROR,
0797 "PREP_CMD: unknown cmd %#x\n", cmd_no);
0798 return -1;
0799 }
0800
0801 return 0;
0802 }
0803
0804 void mwifiex_uap_set_channel(struct mwifiex_private *priv,
0805 struct mwifiex_uap_bss_param *bss_cfg,
0806 struct cfg80211_chan_def chandef)
0807 {
0808 u8 config_bands = 0, old_bands = priv->adapter->config_bands;
0809
0810 priv->bss_chandef = chandef;
0811
0812 bss_cfg->channel = ieee80211_frequency_to_channel(
0813 chandef.chan->center_freq);
0814
0815
0816 if (chandef.chan->band == NL80211_BAND_2GHZ) {
0817 bss_cfg->band_cfg = BAND_CONFIG_BG;
0818 config_bands = BAND_B | BAND_G;
0819
0820 if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
0821 config_bands |= BAND_GN;
0822 } else {
0823 bss_cfg->band_cfg = BAND_CONFIG_A;
0824 config_bands = BAND_A;
0825
0826 if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
0827 config_bands |= BAND_AN;
0828
0829 if (chandef.width > NL80211_CHAN_WIDTH_40)
0830 config_bands |= BAND_AAC;
0831 }
0832
0833 switch (chandef.width) {
0834 case NL80211_CHAN_WIDTH_5:
0835 case NL80211_CHAN_WIDTH_10:
0836 case NL80211_CHAN_WIDTH_20_NOHT:
0837 case NL80211_CHAN_WIDTH_20:
0838 break;
0839 case NL80211_CHAN_WIDTH_40:
0840 if (chandef.center_freq1 < chandef.chan->center_freq)
0841 bss_cfg->band_cfg |= MWIFIEX_SEC_CHAN_BELOW;
0842 else
0843 bss_cfg->band_cfg |= MWIFIEX_SEC_CHAN_ABOVE;
0844 break;
0845 case NL80211_CHAN_WIDTH_80:
0846 case NL80211_CHAN_WIDTH_80P80:
0847 case NL80211_CHAN_WIDTH_160:
0848 bss_cfg->band_cfg |=
0849 mwifiex_get_sec_chan_offset(bss_cfg->channel) << 4;
0850 break;
0851 default:
0852 mwifiex_dbg(priv->adapter,
0853 WARN, "Unknown channel width: %d\n",
0854 chandef.width);
0855 break;
0856 }
0857
0858 priv->adapter->config_bands = config_bands;
0859
0860 if (old_bands != config_bands) {
0861 mwifiex_send_domain_info_cmd_fw(priv->adapter->wiphy);
0862 mwifiex_dnld_txpwr_table(priv);
0863 }
0864 }
0865
0866 int mwifiex_config_start_uap(struct mwifiex_private *priv,
0867 struct mwifiex_uap_bss_param *bss_cfg)
0868 {
0869 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
0870 HostCmd_ACT_GEN_SET,
0871 UAP_BSS_PARAMS_I, bss_cfg, true)) {
0872 mwifiex_dbg(priv->adapter, ERROR,
0873 "Failed to set AP configuration\n");
0874 return -1;
0875 }
0876
0877 if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_START,
0878 HostCmd_ACT_GEN_SET, 0, NULL, true)) {
0879 mwifiex_dbg(priv->adapter, ERROR,
0880 "Failed to start the BSS\n");
0881 return -1;
0882 }
0883
0884 if (priv->sec_info.wep_enabled)
0885 priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
0886 else
0887 priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
0888
0889 if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
0890 HostCmd_ACT_GEN_SET, 0,
0891 &priv->curr_pkt_filter, true))
0892 return -1;
0893
0894 return 0;
0895 }