uap_cmd.c 22 KB

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