uap_cmd.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. #include "main.h"
  20. #include "11ac.h"
  21. /* This function parses security related parameters from cfg80211_ap_settings
  22. * and sets into FW understandable bss_config structure.
  23. */
  24. int mwifiex_set_secure_params(struct mwifiex_private *priv,
  25. struct mwifiex_uap_bss_param *bss_config,
  26. struct cfg80211_ap_settings *params) {
  27. int i;
  28. struct mwifiex_wep_key wep_key;
  29. if (!params->privacy) {
  30. bss_config->protocol = PROTOCOL_NO_SECURITY;
  31. bss_config->key_mgmt = KEY_MGMT_NONE;
  32. bss_config->wpa_cfg.length = 0;
  33. priv->sec_info.wep_enabled = 0;
  34. priv->sec_info.wpa_enabled = 0;
  35. priv->sec_info.wpa2_enabled = 0;
  36. return 0;
  37. }
  38. switch (params->auth_type) {
  39. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  40. bss_config->auth_mode = WLAN_AUTH_OPEN;
  41. break;
  42. case NL80211_AUTHTYPE_SHARED_KEY:
  43. bss_config->auth_mode = WLAN_AUTH_SHARED_KEY;
  44. break;
  45. case NL80211_AUTHTYPE_NETWORK_EAP:
  46. bss_config->auth_mode = WLAN_AUTH_LEAP;
  47. break;
  48. default:
  49. bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO;
  50. break;
  51. }
  52. bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
  53. for (i = 0; i < params->crypto.n_akm_suites; i++) {
  54. switch (params->crypto.akm_suites[i]) {
  55. case WLAN_AKM_SUITE_8021X:
  56. if (params->crypto.wpa_versions &
  57. NL80211_WPA_VERSION_1) {
  58. bss_config->protocol = PROTOCOL_WPA;
  59. bss_config->key_mgmt = KEY_MGMT_EAP;
  60. }
  61. if (params->crypto.wpa_versions &
  62. NL80211_WPA_VERSION_2) {
  63. bss_config->protocol |= PROTOCOL_WPA2;
  64. bss_config->key_mgmt = KEY_MGMT_EAP;
  65. }
  66. break;
  67. case WLAN_AKM_SUITE_PSK:
  68. if (params->crypto.wpa_versions &
  69. NL80211_WPA_VERSION_1) {
  70. bss_config->protocol = PROTOCOL_WPA;
  71. bss_config->key_mgmt = KEY_MGMT_PSK;
  72. }
  73. if (params->crypto.wpa_versions &
  74. NL80211_WPA_VERSION_2) {
  75. bss_config->protocol |= PROTOCOL_WPA2;
  76. bss_config->key_mgmt = KEY_MGMT_PSK;
  77. }
  78. break;
  79. default:
  80. break;
  81. }
  82. }
  83. for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) {
  84. switch (params->crypto.ciphers_pairwise[i]) {
  85. case WLAN_CIPHER_SUITE_WEP40:
  86. case WLAN_CIPHER_SUITE_WEP104:
  87. break;
  88. case WLAN_CIPHER_SUITE_TKIP:
  89. if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  90. bss_config->wpa_cfg.pairwise_cipher_wpa |=
  91. CIPHER_TKIP;
  92. if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  93. bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
  94. CIPHER_TKIP;
  95. break;
  96. case WLAN_CIPHER_SUITE_CCMP:
  97. if (params->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  98. bss_config->wpa_cfg.pairwise_cipher_wpa |=
  99. CIPHER_AES_CCMP;
  100. if (params->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  101. bss_config->wpa_cfg.pairwise_cipher_wpa2 |=
  102. CIPHER_AES_CCMP;
  103. default:
  104. break;
  105. }
  106. }
  107. switch (params->crypto.cipher_group) {
  108. case WLAN_CIPHER_SUITE_WEP40:
  109. case WLAN_CIPHER_SUITE_WEP104:
  110. if (priv->sec_info.wep_enabled) {
  111. bss_config->protocol = PROTOCOL_STATIC_WEP;
  112. bss_config->key_mgmt = KEY_MGMT_NONE;
  113. bss_config->wpa_cfg.length = 0;
  114. for (i = 0; i < NUM_WEP_KEYS; i++) {
  115. wep_key = priv->wep_key[i];
  116. bss_config->wep_cfg[i].key_index = i;
  117. if (priv->wep_key_curr_index == i)
  118. bss_config->wep_cfg[i].is_default = 1;
  119. else
  120. bss_config->wep_cfg[i].is_default = 0;
  121. bss_config->wep_cfg[i].length =
  122. wep_key.key_length;
  123. memcpy(&bss_config->wep_cfg[i].key,
  124. &wep_key.key_material,
  125. wep_key.key_length);
  126. }
  127. }
  128. break;
  129. case WLAN_CIPHER_SUITE_TKIP:
  130. bss_config->wpa_cfg.group_cipher = CIPHER_TKIP;
  131. break;
  132. case WLAN_CIPHER_SUITE_CCMP:
  133. bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP;
  134. break;
  135. default:
  136. break;
  137. }
  138. return 0;
  139. }
  140. /* This function updates 11n related parameters from IE and sets them into
  141. * bss_config structure.
  142. */
  143. void
  144. mwifiex_set_ht_params(struct mwifiex_private *priv,
  145. struct mwifiex_uap_bss_param *bss_cfg,
  146. struct cfg80211_ap_settings *params)
  147. {
  148. const u8 *ht_ie;
  149. if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
  150. return;
  151. ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
  152. params->beacon.tail_len);
  153. if (ht_ie) {
  154. memcpy(&bss_cfg->ht_cap, ht_ie + 2,
  155. sizeof(struct ieee80211_ht_cap));
  156. priv->ap_11n_enabled = 1;
  157. } else {
  158. memset(&bss_cfg->ht_cap , 0, sizeof(struct ieee80211_ht_cap));
  159. bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
  160. bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
  161. }
  162. return;
  163. }
  164. /* This function updates 11ac related parameters from IE
  165. * and sets them into bss_config structure.
  166. */
  167. void mwifiex_set_vht_params(struct mwifiex_private *priv,
  168. struct mwifiex_uap_bss_param *bss_cfg,
  169. struct cfg80211_ap_settings *params)
  170. {
  171. const u8 *vht_ie;
  172. vht_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, params->beacon.tail,
  173. params->beacon.tail_len);
  174. if (vht_ie) {
  175. memcpy(&bss_cfg->vht_cap, vht_ie + 2,
  176. sizeof(struct ieee80211_vht_cap));
  177. priv->ap_11ac_enabled = 1;
  178. } else {
  179. priv->ap_11ac_enabled = 0;
  180. }
  181. return;
  182. }
  183. /* Enable VHT only when cfg80211_ap_settings has VHT IE.
  184. * Otherwise disable VHT.
  185. */
  186. void mwifiex_set_vht_width(struct mwifiex_private *priv,
  187. enum nl80211_chan_width width,
  188. bool ap_11ac_enable)
  189. {
  190. struct mwifiex_adapter *adapter = priv->adapter;
  191. struct mwifiex_11ac_vht_cfg vht_cfg;
  192. vht_cfg.band_config = VHT_CFG_5GHZ;
  193. vht_cfg.cap_info = adapter->hw_dot_11ac_dev_cap;
  194. if (!ap_11ac_enable) {
  195. vht_cfg.mcs_tx_set = DISABLE_VHT_MCS_SET;
  196. vht_cfg.mcs_rx_set = DISABLE_VHT_MCS_SET;
  197. } else {
  198. vht_cfg.mcs_tx_set = DEFAULT_VHT_MCS_SET;
  199. vht_cfg.mcs_rx_set = DEFAULT_VHT_MCS_SET;
  200. }
  201. vht_cfg.misc_config = VHT_CAP_UAP_ONLY;
  202. if (ap_11ac_enable && width >= NL80211_CHAN_WIDTH_80)
  203. vht_cfg.misc_config |= VHT_BW_80_160_80P80;
  204. mwifiex_send_cmd_sync(priv, HostCmd_CMD_11AC_CFG,
  205. HostCmd_ACT_GEN_SET, 0, &vht_cfg);
  206. return;
  207. }
  208. /* This function finds supported rates IE from beacon parameter and sets
  209. * these rates into bss_config structure.
  210. */
  211. void
  212. mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
  213. struct cfg80211_ap_settings *params)
  214. {
  215. struct ieee_types_header *rate_ie;
  216. int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
  217. const u8 *var_pos = params->beacon.head + var_offset;
  218. int len = params->beacon.head_len - var_offset;
  219. u8 rate_len = 0;
  220. rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
  221. if (rate_ie) {
  222. memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
  223. rate_len = rate_ie->len;
  224. }
  225. rate_ie = (void *)cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
  226. params->beacon.tail,
  227. params->beacon.tail_len);
  228. if (rate_ie)
  229. memcpy(bss_cfg->rates + rate_len, rate_ie + 1, rate_ie->len);
  230. return;
  231. }
  232. /* This function initializes some of mwifiex_uap_bss_param variables.
  233. * This helps FW in ignoring invalid values. These values may or may not
  234. * be get updated to valid ones at later stage.
  235. */
  236. void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
  237. {
  238. config->bcast_ssid_ctl = 0x7F;
  239. config->radio_ctl = 0x7F;
  240. config->dtim_period = 0x7F;
  241. config->beacon_period = 0x7FFF;
  242. config->auth_mode = 0x7F;
  243. config->rts_threshold = 0x7FFF;
  244. config->frag_threshold = 0x7FFF;
  245. config->retry_limit = 0x7F;
  246. config->qos_info = 0xFF;
  247. }
  248. /* This function parses BSS related parameters from structure
  249. * and prepares TLVs specific to WPA/WPA2 security.
  250. * These TLVs are appended to command buffer.
  251. */
  252. static void
  253. mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
  254. {
  255. struct host_cmd_tlv_pwk_cipher *pwk_cipher;
  256. struct host_cmd_tlv_gwk_cipher *gwk_cipher;
  257. struct host_cmd_tlv_passphrase *passphrase;
  258. struct host_cmd_tlv_akmp *tlv_akmp;
  259. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  260. u16 cmd_size = *param_size;
  261. u8 *tlv = *tlv_buf;
  262. tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
  263. tlv_akmp->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
  264. tlv_akmp->tlv.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
  265. sizeof(struct host_cmd_tlv));
  266. tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
  267. tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
  268. cmd_size += sizeof(struct host_cmd_tlv_akmp);
  269. tlv += sizeof(struct host_cmd_tlv_akmp);
  270. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
  271. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  272. pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  273. pwk_cipher->tlv.len =
  274. cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
  275. sizeof(struct host_cmd_tlv));
  276. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
  277. pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
  278. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  279. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  280. }
  281. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
  282. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  283. pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  284. pwk_cipher->tlv.len =
  285. cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
  286. sizeof(struct host_cmd_tlv));
  287. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
  288. pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
  289. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  290. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  291. }
  292. if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
  293. gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
  294. gwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
  295. gwk_cipher->tlv.len =
  296. cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
  297. sizeof(struct host_cmd_tlv));
  298. gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
  299. cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
  300. tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
  301. }
  302. if (bss_cfg->wpa_cfg.length) {
  303. passphrase = (struct host_cmd_tlv_passphrase *)tlv;
  304. passphrase->tlv.type = cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
  305. passphrase->tlv.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
  306. memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
  307. bss_cfg->wpa_cfg.length);
  308. cmd_size += sizeof(struct host_cmd_tlv) +
  309. bss_cfg->wpa_cfg.length;
  310. tlv += sizeof(struct host_cmd_tlv) + bss_cfg->wpa_cfg.length;
  311. }
  312. *param_size = cmd_size;
  313. *tlv_buf = tlv;
  314. return;
  315. }
  316. /* This function parses WMM related parameters from cfg80211_ap_settings
  317. * structure and updates bss_config structure.
  318. */
  319. void
  320. mwifiex_set_wmm_params(struct mwifiex_private *priv,
  321. struct mwifiex_uap_bss_param *bss_cfg,
  322. struct cfg80211_ap_settings *params)
  323. {
  324. const u8 *vendor_ie;
  325. struct ieee_types_header *wmm_ie;
  326. u8 wmm_oui[] = {0x00, 0x50, 0xf2, 0x02};
  327. vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  328. WLAN_OUI_TYPE_MICROSOFT_WMM,
  329. params->beacon.tail,
  330. params->beacon.tail_len);
  331. if (vendor_ie) {
  332. wmm_ie = (struct ieee_types_header *)vendor_ie;
  333. memcpy(&bss_cfg->wmm_info, wmm_ie + 1,
  334. sizeof(bss_cfg->wmm_info));
  335. priv->wmm_enabled = 1;
  336. } else {
  337. memset(&bss_cfg->wmm_info, 0, sizeof(bss_cfg->wmm_info));
  338. memcpy(&bss_cfg->wmm_info.oui, wmm_oui, sizeof(wmm_oui));
  339. bss_cfg->wmm_info.subtype = MWIFIEX_WMM_SUBTYPE;
  340. bss_cfg->wmm_info.version = MWIFIEX_WMM_VERSION;
  341. priv->wmm_enabled = 0;
  342. }
  343. bss_cfg->qos_info = 0x00;
  344. return;
  345. }
  346. /* This function parses BSS related parameters from structure
  347. * and prepares TLVs specific to WEP encryption.
  348. * These TLVs are appended to command buffer.
  349. */
  350. static void
  351. mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
  352. {
  353. struct host_cmd_tlv_wep_key *wep_key;
  354. u16 cmd_size = *param_size;
  355. int i;
  356. u8 *tlv = *tlv_buf;
  357. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  358. for (i = 0; i < NUM_WEP_KEYS; i++) {
  359. if (bss_cfg->wep_cfg[i].length &&
  360. (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
  361. bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
  362. wep_key = (struct host_cmd_tlv_wep_key *)tlv;
  363. wep_key->tlv.type = cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
  364. wep_key->tlv.len =
  365. cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
  366. wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
  367. wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
  368. memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
  369. bss_cfg->wep_cfg[i].length);
  370. cmd_size += sizeof(struct host_cmd_tlv) + 2 +
  371. bss_cfg->wep_cfg[i].length;
  372. tlv += sizeof(struct host_cmd_tlv) + 2 +
  373. bss_cfg->wep_cfg[i].length;
  374. }
  375. }
  376. *param_size = cmd_size;
  377. *tlv_buf = tlv;
  378. return;
  379. }
  380. /* This function parses BSS related parameters from structure
  381. * and prepares TLVs. These TLVs are appended to command buffer.
  382. */
  383. static int
  384. mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
  385. {
  386. struct host_cmd_tlv_dtim_period *dtim_period;
  387. struct host_cmd_tlv_beacon_period *beacon_period;
  388. struct host_cmd_tlv_ssid *ssid;
  389. struct host_cmd_tlv_bcast_ssid *bcast_ssid;
  390. struct host_cmd_tlv_channel_band *chan_band;
  391. struct host_cmd_tlv_frag_threshold *frag_threshold;
  392. struct host_cmd_tlv_rts_threshold *rts_threshold;
  393. struct host_cmd_tlv_retry_limit *retry_limit;
  394. struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
  395. struct host_cmd_tlv_auth_type *auth_type;
  396. struct host_cmd_tlv_rates *tlv_rates;
  397. struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
  398. struct mwifiex_ie_types_htcap *htcap;
  399. struct mwifiex_ie_types_wmmcap *wmm_cap;
  400. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  401. int i;
  402. u16 cmd_size = *param_size;
  403. if (bss_cfg->ssid.ssid_len) {
  404. ssid = (struct host_cmd_tlv_ssid *)tlv;
  405. ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
  406. ssid->tlv.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
  407. memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
  408. cmd_size += sizeof(struct host_cmd_tlv) +
  409. bss_cfg->ssid.ssid_len;
  410. tlv += sizeof(struct host_cmd_tlv) + bss_cfg->ssid.ssid_len;
  411. bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
  412. bcast_ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
  413. bcast_ssid->tlv.len =
  414. cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
  415. bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
  416. cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
  417. tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
  418. }
  419. if (bss_cfg->rates[0]) {
  420. tlv_rates = (struct host_cmd_tlv_rates *)tlv;
  421. tlv_rates->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
  422. for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
  423. i++)
  424. tlv_rates->rates[i] = bss_cfg->rates[i];
  425. tlv_rates->tlv.len = cpu_to_le16(i);
  426. cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
  427. tlv += sizeof(struct host_cmd_tlv_rates) + i;
  428. }
  429. if (bss_cfg->channel &&
  430. ((bss_cfg->band_cfg == BAND_CONFIG_BG &&
  431. bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
  432. (bss_cfg->band_cfg == BAND_CONFIG_A &&
  433. bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
  434. chan_band = (struct host_cmd_tlv_channel_band *)tlv;
  435. chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
  436. chan_band->tlv.len =
  437. cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
  438. sizeof(struct host_cmd_tlv));
  439. chan_band->band_config = bss_cfg->band_cfg;
  440. chan_band->channel = bss_cfg->channel;
  441. cmd_size += sizeof(struct host_cmd_tlv_channel_band);
  442. tlv += sizeof(struct host_cmd_tlv_channel_band);
  443. }
  444. if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
  445. bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
  446. beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
  447. beacon_period->tlv.type =
  448. cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
  449. beacon_period->tlv.len =
  450. cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
  451. sizeof(struct host_cmd_tlv));
  452. beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
  453. cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
  454. tlv += sizeof(struct host_cmd_tlv_beacon_period);
  455. }
  456. if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
  457. bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
  458. dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
  459. dtim_period->tlv.type = cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
  460. dtim_period->tlv.len =
  461. cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
  462. sizeof(struct host_cmd_tlv));
  463. dtim_period->period = bss_cfg->dtim_period;
  464. cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
  465. tlv += sizeof(struct host_cmd_tlv_dtim_period);
  466. }
  467. if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
  468. rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
  469. rts_threshold->tlv.type =
  470. cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
  471. rts_threshold->tlv.len =
  472. cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
  473. sizeof(struct host_cmd_tlv));
  474. rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
  475. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  476. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  477. }
  478. if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
  479. (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
  480. frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
  481. frag_threshold->tlv.type =
  482. cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
  483. frag_threshold->tlv.len =
  484. cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
  485. sizeof(struct host_cmd_tlv));
  486. frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
  487. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  488. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  489. }
  490. if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
  491. retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
  492. retry_limit->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
  493. retry_limit->tlv.len =
  494. cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
  495. sizeof(struct host_cmd_tlv));
  496. retry_limit->limit = (u8)bss_cfg->retry_limit;
  497. cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
  498. tlv += sizeof(struct host_cmd_tlv_retry_limit);
  499. }
  500. if ((bss_cfg->protocol & PROTOCOL_WPA) ||
  501. (bss_cfg->protocol & PROTOCOL_WPA2) ||
  502. (bss_cfg->protocol & PROTOCOL_EAP))
  503. mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
  504. else
  505. mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
  506. if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
  507. (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
  508. auth_type = (struct host_cmd_tlv_auth_type *)tlv;
  509. auth_type->tlv.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
  510. auth_type->tlv.len =
  511. cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
  512. sizeof(struct host_cmd_tlv));
  513. auth_type->auth_type = (u8)bss_cfg->auth_mode;
  514. cmd_size += sizeof(struct host_cmd_tlv_auth_type);
  515. tlv += sizeof(struct host_cmd_tlv_auth_type);
  516. }
  517. if (bss_cfg->protocol) {
  518. encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
  519. encrypt_protocol->tlv.type =
  520. cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
  521. encrypt_protocol->tlv.len =
  522. cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
  523. - sizeof(struct host_cmd_tlv));
  524. encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
  525. cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
  526. tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
  527. }
  528. if (bss_cfg->ht_cap.cap_info) {
  529. htcap = (struct mwifiex_ie_types_htcap *)tlv;
  530. htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  531. htcap->header.len =
  532. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  533. htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
  534. htcap->ht_cap.ampdu_params_info =
  535. bss_cfg->ht_cap.ampdu_params_info;
  536. memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
  537. sizeof(struct ieee80211_mcs_info));
  538. htcap->ht_cap.extended_ht_cap_info =
  539. bss_cfg->ht_cap.extended_ht_cap_info;
  540. htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
  541. htcap->ht_cap.antenna_selection_info =
  542. bss_cfg->ht_cap.antenna_selection_info;
  543. cmd_size += sizeof(struct mwifiex_ie_types_htcap);
  544. tlv += sizeof(struct mwifiex_ie_types_htcap);
  545. }
  546. if (bss_cfg->wmm_info.qos_info != 0xFF) {
  547. wmm_cap = (struct mwifiex_ie_types_wmmcap *)tlv;
  548. wmm_cap->header.type = cpu_to_le16(WLAN_EID_VENDOR_SPECIFIC);
  549. wmm_cap->header.len = cpu_to_le16(sizeof(wmm_cap->wmm_info));
  550. memcpy(&wmm_cap->wmm_info, &bss_cfg->wmm_info,
  551. sizeof(wmm_cap->wmm_info));
  552. cmd_size += sizeof(struct mwifiex_ie_types_wmmcap);
  553. tlv += sizeof(struct mwifiex_ie_types_wmmcap);
  554. }
  555. if (bss_cfg->sta_ao_timer) {
  556. ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
  557. ao_timer->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
  558. ao_timer->tlv.len = cpu_to_le16(sizeof(*ao_timer) -
  559. sizeof(struct host_cmd_tlv));
  560. ao_timer->sta_ao_timer = cpu_to_le32(bss_cfg->sta_ao_timer);
  561. cmd_size += sizeof(*ao_timer);
  562. tlv += sizeof(*ao_timer);
  563. }
  564. if (bss_cfg->ps_sta_ao_timer) {
  565. ps_ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
  566. ps_ao_timer->tlv.type = cpu_to_le16(TLV_TYPE_UAP_PS_AO_TIMER);
  567. ps_ao_timer->tlv.len = cpu_to_le16(sizeof(*ps_ao_timer) -
  568. sizeof(struct host_cmd_tlv));
  569. ps_ao_timer->sta_ao_timer =
  570. cpu_to_le32(bss_cfg->ps_sta_ao_timer);
  571. cmd_size += sizeof(*ps_ao_timer);
  572. tlv += sizeof(*ps_ao_timer);
  573. }
  574. *param_size = cmd_size;
  575. return 0;
  576. }
  577. /* This function parses custom IEs from IE list and prepares command buffer */
  578. static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
  579. {
  580. struct mwifiex_ie_list *ap_ie = cmd_buf;
  581. struct host_cmd_tlv *tlv_ie = (struct host_cmd_tlv *)tlv;
  582. if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
  583. return -1;
  584. *ie_size += le16_to_cpu(ap_ie->len) + sizeof(struct host_cmd_tlv);
  585. tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
  586. tlv_ie->len = ap_ie->len;
  587. tlv += sizeof(struct host_cmd_tlv);
  588. memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
  589. return 0;
  590. }
  591. /* Parse AP config structure and prepare TLV based command structure
  592. * to be sent to FW for uAP configuration
  593. */
  594. static int
  595. mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
  596. u32 type, void *cmd_buf)
  597. {
  598. u8 *tlv;
  599. u16 cmd_size, param_size, ie_size;
  600. struct host_cmd_ds_sys_config *sys_cfg;
  601. cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
  602. cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
  603. sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
  604. sys_cfg->action = cpu_to_le16(cmd_action);
  605. tlv = sys_cfg->tlv;
  606. switch (type) {
  607. case UAP_BSS_PARAMS_I:
  608. param_size = cmd_size;
  609. if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
  610. return -1;
  611. cmd->size = cpu_to_le16(param_size);
  612. break;
  613. case UAP_CUSTOM_IE_I:
  614. ie_size = cmd_size;
  615. if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
  616. return -1;
  617. cmd->size = cpu_to_le16(ie_size);
  618. break;
  619. default:
  620. return -1;
  621. }
  622. return 0;
  623. }
  624. /* This function prepares the AP specific commands before sending them
  625. * to the firmware.
  626. * This is a generic function which calls specific command preparation
  627. * routines based upon the command number.
  628. */
  629. int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
  630. u16 cmd_action, u32 type,
  631. void *data_buf, void *cmd_buf)
  632. {
  633. struct host_cmd_ds_command *cmd = cmd_buf;
  634. switch (cmd_no) {
  635. case HostCmd_CMD_UAP_SYS_CONFIG:
  636. if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
  637. return -1;
  638. break;
  639. case HostCmd_CMD_UAP_BSS_START:
  640. case HostCmd_CMD_UAP_BSS_STOP:
  641. cmd->command = cpu_to_le16(cmd_no);
  642. cmd->size = cpu_to_le16(S_DS_GEN);
  643. break;
  644. default:
  645. dev_err(priv->adapter->dev,
  646. "PREP_CMD: unknown cmd %#x\n", cmd_no);
  647. return -1;
  648. }
  649. return 0;
  650. }