uap_cmd.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. /*
  2. * Marvell Wireless LAN device driver: AP specific command handling
  3. *
  4. * Copyright (C) 2012-2014, 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. u16 cap_info;
  150. if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
  151. return;
  152. ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
  153. params->beacon.tail_len);
  154. if (ht_ie) {
  155. memcpy(&bss_cfg->ht_cap, ht_ie + 2,
  156. sizeof(struct ieee80211_ht_cap));
  157. cap_info = le16_to_cpu(bss_cfg->ht_cap.cap_info);
  158. memset(&bss_cfg->ht_cap.mcs, 0,
  159. priv->adapter->number_of_antenna);
  160. switch (GET_RXSTBC(cap_info)) {
  161. case MWIFIEX_RX_STBC1:
  162. /* HT_CAP 1X1 mode */
  163. bss_cfg->ht_cap.mcs.rx_mask[0] = 0xff;
  164. break;
  165. case MWIFIEX_RX_STBC12: /* fall through */
  166. case MWIFIEX_RX_STBC123:
  167. /* HT_CAP 2X2 mode */
  168. bss_cfg->ht_cap.mcs.rx_mask[0] = 0xff;
  169. bss_cfg->ht_cap.mcs.rx_mask[1] = 0xff;
  170. break;
  171. default:
  172. mwifiex_dbg(priv->adapter, WARN,
  173. "Unsupported RX-STBC, default to 2x2\n");
  174. bss_cfg->ht_cap.mcs.rx_mask[0] = 0xff;
  175. bss_cfg->ht_cap.mcs.rx_mask[1] = 0xff;
  176. break;
  177. }
  178. priv->ap_11n_enabled = 1;
  179. } else {
  180. memset(&bss_cfg->ht_cap , 0, sizeof(struct ieee80211_ht_cap));
  181. bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
  182. bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
  183. }
  184. return;
  185. }
  186. /* This function updates 11ac related parameters from IE
  187. * and sets them into bss_config structure.
  188. */
  189. void mwifiex_set_vht_params(struct mwifiex_private *priv,
  190. struct mwifiex_uap_bss_param *bss_cfg,
  191. struct cfg80211_ap_settings *params)
  192. {
  193. const u8 *vht_ie;
  194. vht_ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, params->beacon.tail,
  195. params->beacon.tail_len);
  196. if (vht_ie) {
  197. memcpy(&bss_cfg->vht_cap, vht_ie + 2,
  198. sizeof(struct ieee80211_vht_cap));
  199. priv->ap_11ac_enabled = 1;
  200. } else {
  201. priv->ap_11ac_enabled = 0;
  202. }
  203. return;
  204. }
  205. /* This function updates 11ac related parameters from IE
  206. * and sets them into bss_config structure.
  207. */
  208. void mwifiex_set_tpc_params(struct mwifiex_private *priv,
  209. struct mwifiex_uap_bss_param *bss_cfg,
  210. struct cfg80211_ap_settings *params)
  211. {
  212. const u8 *tpc_ie;
  213. tpc_ie = cfg80211_find_ie(WLAN_EID_TPC_REQUEST, params->beacon.tail,
  214. params->beacon.tail_len);
  215. if (tpc_ie)
  216. bss_cfg->power_constraint = *(tpc_ie + 2);
  217. else
  218. bss_cfg->power_constraint = 0;
  219. }
  220. /* Enable VHT only when cfg80211_ap_settings has VHT IE.
  221. * Otherwise disable VHT.
  222. */
  223. void mwifiex_set_vht_width(struct mwifiex_private *priv,
  224. enum nl80211_chan_width width,
  225. bool ap_11ac_enable)
  226. {
  227. struct mwifiex_adapter *adapter = priv->adapter;
  228. struct mwifiex_11ac_vht_cfg vht_cfg;
  229. vht_cfg.band_config = VHT_CFG_5GHZ;
  230. vht_cfg.cap_info = adapter->hw_dot_11ac_dev_cap;
  231. if (!ap_11ac_enable) {
  232. vht_cfg.mcs_tx_set = DISABLE_VHT_MCS_SET;
  233. vht_cfg.mcs_rx_set = DISABLE_VHT_MCS_SET;
  234. } else {
  235. vht_cfg.mcs_tx_set = DEFAULT_VHT_MCS_SET;
  236. vht_cfg.mcs_rx_set = DEFAULT_VHT_MCS_SET;
  237. }
  238. vht_cfg.misc_config = VHT_CAP_UAP_ONLY;
  239. if (ap_11ac_enable && width >= NL80211_CHAN_WIDTH_80)
  240. vht_cfg.misc_config |= VHT_BW_80_160_80P80;
  241. mwifiex_send_cmd(priv, HostCmd_CMD_11AC_CFG,
  242. HostCmd_ACT_GEN_SET, 0, &vht_cfg, true);
  243. return;
  244. }
  245. /* This function finds supported rates IE from beacon parameter and sets
  246. * these rates into bss_config structure.
  247. */
  248. void
  249. mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
  250. struct cfg80211_ap_settings *params)
  251. {
  252. struct ieee_types_header *rate_ie;
  253. int var_offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
  254. const u8 *var_pos = params->beacon.head + var_offset;
  255. int len = params->beacon.head_len - var_offset;
  256. u8 rate_len = 0;
  257. rate_ie = (void *)cfg80211_find_ie(WLAN_EID_SUPP_RATES, var_pos, len);
  258. if (rate_ie) {
  259. memcpy(bss_cfg->rates, rate_ie + 1, rate_ie->len);
  260. rate_len = rate_ie->len;
  261. }
  262. rate_ie = (void *)cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
  263. params->beacon.tail,
  264. params->beacon.tail_len);
  265. if (rate_ie)
  266. memcpy(bss_cfg->rates + rate_len, rate_ie + 1, rate_ie->len);
  267. return;
  268. }
  269. /* This function initializes some of mwifiex_uap_bss_param variables.
  270. * This helps FW in ignoring invalid values. These values may or may not
  271. * be get updated to valid ones at later stage.
  272. */
  273. void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
  274. {
  275. config->bcast_ssid_ctl = 0x7F;
  276. config->radio_ctl = 0x7F;
  277. config->dtim_period = 0x7F;
  278. config->beacon_period = 0x7FFF;
  279. config->auth_mode = 0x7F;
  280. config->rts_threshold = 0x7FFF;
  281. config->frag_threshold = 0x7FFF;
  282. config->retry_limit = 0x7F;
  283. config->qos_info = 0xFF;
  284. }
  285. /* This function parses BSS related parameters from structure
  286. * and prepares TLVs specific to WPA/WPA2 security.
  287. * These TLVs are appended to command buffer.
  288. */
  289. static void
  290. mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
  291. {
  292. struct host_cmd_tlv_pwk_cipher *pwk_cipher;
  293. struct host_cmd_tlv_gwk_cipher *gwk_cipher;
  294. struct host_cmd_tlv_passphrase *passphrase;
  295. struct host_cmd_tlv_akmp *tlv_akmp;
  296. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  297. u16 cmd_size = *param_size;
  298. u8 *tlv = *tlv_buf;
  299. tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
  300. tlv_akmp->header.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
  301. tlv_akmp->header.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
  302. sizeof(struct mwifiex_ie_types_header));
  303. tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
  304. tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
  305. cmd_size += sizeof(struct host_cmd_tlv_akmp);
  306. tlv += sizeof(struct host_cmd_tlv_akmp);
  307. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
  308. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  309. pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  310. pwk_cipher->header.len =
  311. cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
  312. sizeof(struct mwifiex_ie_types_header));
  313. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
  314. pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
  315. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  316. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  317. }
  318. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
  319. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  320. pwk_cipher->header.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  321. pwk_cipher->header.len =
  322. cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
  323. sizeof(struct mwifiex_ie_types_header));
  324. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
  325. pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
  326. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  327. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  328. }
  329. if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
  330. gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
  331. gwk_cipher->header.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
  332. gwk_cipher->header.len =
  333. cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
  334. sizeof(struct mwifiex_ie_types_header));
  335. gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
  336. cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
  337. tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
  338. }
  339. if (bss_cfg->wpa_cfg.length) {
  340. passphrase = (struct host_cmd_tlv_passphrase *)tlv;
  341. passphrase->header.type =
  342. cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
  343. passphrase->header.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
  344. memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
  345. bss_cfg->wpa_cfg.length);
  346. cmd_size += sizeof(struct mwifiex_ie_types_header) +
  347. bss_cfg->wpa_cfg.length;
  348. tlv += sizeof(struct mwifiex_ie_types_header) +
  349. bss_cfg->wpa_cfg.length;
  350. }
  351. *param_size = cmd_size;
  352. *tlv_buf = tlv;
  353. return;
  354. }
  355. /* This function parses WMM related parameters from cfg80211_ap_settings
  356. * structure and updates bss_config structure.
  357. */
  358. void
  359. mwifiex_set_wmm_params(struct mwifiex_private *priv,
  360. struct mwifiex_uap_bss_param *bss_cfg,
  361. struct cfg80211_ap_settings *params)
  362. {
  363. const u8 *vendor_ie;
  364. struct ieee_types_header *wmm_ie;
  365. u8 wmm_oui[] = {0x00, 0x50, 0xf2, 0x02};
  366. vendor_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
  367. WLAN_OUI_TYPE_MICROSOFT_WMM,
  368. params->beacon.tail,
  369. params->beacon.tail_len);
  370. if (vendor_ie) {
  371. wmm_ie = (struct ieee_types_header *)vendor_ie;
  372. memcpy(&bss_cfg->wmm_info, wmm_ie + 1,
  373. sizeof(bss_cfg->wmm_info));
  374. priv->wmm_enabled = 1;
  375. } else {
  376. memset(&bss_cfg->wmm_info, 0, sizeof(bss_cfg->wmm_info));
  377. memcpy(&bss_cfg->wmm_info.oui, wmm_oui, sizeof(wmm_oui));
  378. bss_cfg->wmm_info.subtype = MWIFIEX_WMM_SUBTYPE;
  379. bss_cfg->wmm_info.version = MWIFIEX_WMM_VERSION;
  380. priv->wmm_enabled = 0;
  381. }
  382. bss_cfg->qos_info = 0x00;
  383. return;
  384. }
  385. /* This function parses BSS related parameters from structure
  386. * and prepares TLVs specific to WEP encryption.
  387. * These TLVs are appended to command buffer.
  388. */
  389. static void
  390. mwifiex_uap_bss_wep(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
  391. {
  392. struct host_cmd_tlv_wep_key *wep_key;
  393. u16 cmd_size = *param_size;
  394. int i;
  395. u8 *tlv = *tlv_buf;
  396. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  397. for (i = 0; i < NUM_WEP_KEYS; i++) {
  398. if (bss_cfg->wep_cfg[i].length &&
  399. (bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP40 ||
  400. bss_cfg->wep_cfg[i].length == WLAN_KEY_LEN_WEP104)) {
  401. wep_key = (struct host_cmd_tlv_wep_key *)tlv;
  402. wep_key->header.type =
  403. cpu_to_le16(TLV_TYPE_UAP_WEP_KEY);
  404. wep_key->header.len =
  405. cpu_to_le16(bss_cfg->wep_cfg[i].length + 2);
  406. wep_key->key_index = bss_cfg->wep_cfg[i].key_index;
  407. wep_key->is_default = bss_cfg->wep_cfg[i].is_default;
  408. memcpy(wep_key->key, bss_cfg->wep_cfg[i].key,
  409. bss_cfg->wep_cfg[i].length);
  410. cmd_size += sizeof(struct mwifiex_ie_types_header) + 2 +
  411. bss_cfg->wep_cfg[i].length;
  412. tlv += sizeof(struct mwifiex_ie_types_header) + 2 +
  413. bss_cfg->wep_cfg[i].length;
  414. }
  415. }
  416. *param_size = cmd_size;
  417. *tlv_buf = tlv;
  418. return;
  419. }
  420. /* This function parses BSS related parameters from structure
  421. * and prepares TLVs. These TLVs are appended to command buffer.
  422. */
  423. static int
  424. mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
  425. {
  426. struct host_cmd_tlv_dtim_period *dtim_period;
  427. struct host_cmd_tlv_beacon_period *beacon_period;
  428. struct host_cmd_tlv_ssid *ssid;
  429. struct host_cmd_tlv_bcast_ssid *bcast_ssid;
  430. struct host_cmd_tlv_channel_band *chan_band;
  431. struct host_cmd_tlv_frag_threshold *frag_threshold;
  432. struct host_cmd_tlv_rts_threshold *rts_threshold;
  433. struct host_cmd_tlv_retry_limit *retry_limit;
  434. struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
  435. struct host_cmd_tlv_auth_type *auth_type;
  436. struct host_cmd_tlv_rates *tlv_rates;
  437. struct host_cmd_tlv_ageout_timer *ao_timer, *ps_ao_timer;
  438. struct host_cmd_tlv_power_constraint *pwr_ct;
  439. struct mwifiex_ie_types_htcap *htcap;
  440. struct mwifiex_ie_types_wmmcap *wmm_cap;
  441. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  442. int i;
  443. u16 cmd_size = *param_size;
  444. if (bss_cfg->ssid.ssid_len) {
  445. ssid = (struct host_cmd_tlv_ssid *)tlv;
  446. ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
  447. ssid->header.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
  448. memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
  449. cmd_size += sizeof(struct mwifiex_ie_types_header) +
  450. bss_cfg->ssid.ssid_len;
  451. tlv += sizeof(struct mwifiex_ie_types_header) +
  452. bss_cfg->ssid.ssid_len;
  453. bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
  454. bcast_ssid->header.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
  455. bcast_ssid->header.len =
  456. cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
  457. bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
  458. cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
  459. tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
  460. }
  461. if (bss_cfg->rates[0]) {
  462. tlv_rates = (struct host_cmd_tlv_rates *)tlv;
  463. tlv_rates->header.type = cpu_to_le16(TLV_TYPE_UAP_RATES);
  464. for (i = 0; i < MWIFIEX_SUPPORTED_RATES && bss_cfg->rates[i];
  465. i++)
  466. tlv_rates->rates[i] = bss_cfg->rates[i];
  467. tlv_rates->header.len = cpu_to_le16(i);
  468. cmd_size += sizeof(struct host_cmd_tlv_rates) + i;
  469. tlv += sizeof(struct host_cmd_tlv_rates) + i;
  470. }
  471. if (bss_cfg->channel &&
  472. ((bss_cfg->band_cfg == BAND_CONFIG_BG &&
  473. bss_cfg->channel <= MAX_CHANNEL_BAND_BG) ||
  474. (bss_cfg->band_cfg == BAND_CONFIG_A &&
  475. bss_cfg->channel <= MAX_CHANNEL_BAND_A))) {
  476. chan_band = (struct host_cmd_tlv_channel_band *)tlv;
  477. chan_band->header.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
  478. chan_band->header.len =
  479. cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
  480. sizeof(struct mwifiex_ie_types_header));
  481. chan_band->band_config = bss_cfg->band_cfg;
  482. chan_band->channel = bss_cfg->channel;
  483. cmd_size += sizeof(struct host_cmd_tlv_channel_band);
  484. tlv += sizeof(struct host_cmd_tlv_channel_band);
  485. }
  486. if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
  487. bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
  488. beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
  489. beacon_period->header.type =
  490. cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
  491. beacon_period->header.len =
  492. cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
  493. sizeof(struct mwifiex_ie_types_header));
  494. beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
  495. cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
  496. tlv += sizeof(struct host_cmd_tlv_beacon_period);
  497. }
  498. if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
  499. bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
  500. dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
  501. dtim_period->header.type =
  502. cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
  503. dtim_period->header.len =
  504. cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
  505. sizeof(struct mwifiex_ie_types_header));
  506. dtim_period->period = bss_cfg->dtim_period;
  507. cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
  508. tlv += sizeof(struct host_cmd_tlv_dtim_period);
  509. }
  510. if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
  511. rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
  512. rts_threshold->header.type =
  513. cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
  514. rts_threshold->header.len =
  515. cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
  516. sizeof(struct mwifiex_ie_types_header));
  517. rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
  518. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  519. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  520. }
  521. if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
  522. (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
  523. frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
  524. frag_threshold->header.type =
  525. cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
  526. frag_threshold->header.len =
  527. cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
  528. sizeof(struct mwifiex_ie_types_header));
  529. frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
  530. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  531. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  532. }
  533. if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
  534. retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
  535. retry_limit->header.type =
  536. cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
  537. retry_limit->header.len =
  538. cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
  539. sizeof(struct mwifiex_ie_types_header));
  540. retry_limit->limit = (u8)bss_cfg->retry_limit;
  541. cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
  542. tlv += sizeof(struct host_cmd_tlv_retry_limit);
  543. }
  544. if ((bss_cfg->protocol & PROTOCOL_WPA) ||
  545. (bss_cfg->protocol & PROTOCOL_WPA2) ||
  546. (bss_cfg->protocol & PROTOCOL_EAP))
  547. mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
  548. else
  549. mwifiex_uap_bss_wep(&tlv, cmd_buf, &cmd_size);
  550. if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
  551. (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
  552. auth_type = (struct host_cmd_tlv_auth_type *)tlv;
  553. auth_type->header.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
  554. auth_type->header.len =
  555. cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
  556. sizeof(struct mwifiex_ie_types_header));
  557. auth_type->auth_type = (u8)bss_cfg->auth_mode;
  558. cmd_size += sizeof(struct host_cmd_tlv_auth_type);
  559. tlv += sizeof(struct host_cmd_tlv_auth_type);
  560. }
  561. if (bss_cfg->protocol) {
  562. encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
  563. encrypt_protocol->header.type =
  564. cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
  565. encrypt_protocol->header.len =
  566. cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
  567. - sizeof(struct mwifiex_ie_types_header));
  568. encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
  569. cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
  570. tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
  571. }
  572. if (bss_cfg->ht_cap.cap_info) {
  573. htcap = (struct mwifiex_ie_types_htcap *)tlv;
  574. htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  575. htcap->header.len =
  576. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  577. htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
  578. htcap->ht_cap.ampdu_params_info =
  579. bss_cfg->ht_cap.ampdu_params_info;
  580. memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
  581. sizeof(struct ieee80211_mcs_info));
  582. htcap->ht_cap.extended_ht_cap_info =
  583. bss_cfg->ht_cap.extended_ht_cap_info;
  584. htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
  585. htcap->ht_cap.antenna_selection_info =
  586. bss_cfg->ht_cap.antenna_selection_info;
  587. cmd_size += sizeof(struct mwifiex_ie_types_htcap);
  588. tlv += sizeof(struct mwifiex_ie_types_htcap);
  589. }
  590. if (bss_cfg->wmm_info.qos_info != 0xFF) {
  591. wmm_cap = (struct mwifiex_ie_types_wmmcap *)tlv;
  592. wmm_cap->header.type = cpu_to_le16(WLAN_EID_VENDOR_SPECIFIC);
  593. wmm_cap->header.len = cpu_to_le16(sizeof(wmm_cap->wmm_info));
  594. memcpy(&wmm_cap->wmm_info, &bss_cfg->wmm_info,
  595. sizeof(wmm_cap->wmm_info));
  596. cmd_size += sizeof(struct mwifiex_ie_types_wmmcap);
  597. tlv += sizeof(struct mwifiex_ie_types_wmmcap);
  598. }
  599. if (bss_cfg->sta_ao_timer) {
  600. ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
  601. ao_timer->header.type = cpu_to_le16(TLV_TYPE_UAP_AO_TIMER);
  602. ao_timer->header.len = cpu_to_le16(sizeof(*ao_timer) -
  603. sizeof(struct mwifiex_ie_types_header));
  604. ao_timer->sta_ao_timer = cpu_to_le32(bss_cfg->sta_ao_timer);
  605. cmd_size += sizeof(*ao_timer);
  606. tlv += sizeof(*ao_timer);
  607. }
  608. if (bss_cfg->power_constraint) {
  609. pwr_ct = (void *)tlv;
  610. pwr_ct->header.type = cpu_to_le16(TLV_TYPE_PWR_CONSTRAINT);
  611. pwr_ct->header.len = cpu_to_le16(sizeof(u8));
  612. pwr_ct->constraint = bss_cfg->power_constraint;
  613. cmd_size += sizeof(*pwr_ct);
  614. tlv += sizeof(*pwr_ct);
  615. }
  616. if (bss_cfg->ps_sta_ao_timer) {
  617. ps_ao_timer = (struct host_cmd_tlv_ageout_timer *)tlv;
  618. ps_ao_timer->header.type =
  619. cpu_to_le16(TLV_TYPE_UAP_PS_AO_TIMER);
  620. ps_ao_timer->header.len = cpu_to_le16(sizeof(*ps_ao_timer) -
  621. sizeof(struct mwifiex_ie_types_header));
  622. ps_ao_timer->sta_ao_timer =
  623. cpu_to_le32(bss_cfg->ps_sta_ao_timer);
  624. cmd_size += sizeof(*ps_ao_timer);
  625. tlv += sizeof(*ps_ao_timer);
  626. }
  627. *param_size = cmd_size;
  628. return 0;
  629. }
  630. /* This function parses custom IEs from IE list and prepares command buffer */
  631. static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
  632. {
  633. struct mwifiex_ie_list *ap_ie = cmd_buf;
  634. struct mwifiex_ie_types_header *tlv_ie = (void *)tlv;
  635. if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
  636. return -1;
  637. *ie_size += le16_to_cpu(ap_ie->len) +
  638. sizeof(struct mwifiex_ie_types_header);
  639. tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
  640. tlv_ie->len = ap_ie->len;
  641. tlv += sizeof(struct mwifiex_ie_types_header);
  642. memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
  643. return 0;
  644. }
  645. /* Parse AP config structure and prepare TLV based command structure
  646. * to be sent to FW for uAP configuration
  647. */
  648. static int
  649. mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
  650. u32 type, void *cmd_buf)
  651. {
  652. u8 *tlv;
  653. u16 cmd_size, param_size, ie_size;
  654. struct host_cmd_ds_sys_config *sys_cfg;
  655. cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
  656. cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
  657. sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
  658. sys_cfg->action = cpu_to_le16(cmd_action);
  659. tlv = sys_cfg->tlv;
  660. switch (type) {
  661. case UAP_BSS_PARAMS_I:
  662. param_size = cmd_size;
  663. if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
  664. return -1;
  665. cmd->size = cpu_to_le16(param_size);
  666. break;
  667. case UAP_CUSTOM_IE_I:
  668. ie_size = cmd_size;
  669. if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
  670. return -1;
  671. cmd->size = cpu_to_le16(ie_size);
  672. break;
  673. default:
  674. return -1;
  675. }
  676. return 0;
  677. }
  678. /* This function prepares AP specific deauth command with mac supplied in
  679. * function parameter.
  680. */
  681. static int mwifiex_cmd_uap_sta_deauth(struct mwifiex_private *priv,
  682. struct host_cmd_ds_command *cmd, u8 *mac)
  683. {
  684. struct host_cmd_ds_sta_deauth *sta_deauth = &cmd->params.sta_deauth;
  685. cmd->command = cpu_to_le16(HostCmd_CMD_UAP_STA_DEAUTH);
  686. memcpy(sta_deauth->mac, mac, ETH_ALEN);
  687. sta_deauth->reason = cpu_to_le16(WLAN_REASON_DEAUTH_LEAVING);
  688. cmd->size = cpu_to_le16(sizeof(struct host_cmd_ds_sta_deauth) +
  689. S_DS_GEN);
  690. return 0;
  691. }
  692. /* This function prepares the AP specific commands before sending them
  693. * to the firmware.
  694. * This is a generic function which calls specific command preparation
  695. * routines based upon the command number.
  696. */
  697. int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
  698. u16 cmd_action, u32 type,
  699. void *data_buf, void *cmd_buf)
  700. {
  701. struct host_cmd_ds_command *cmd = cmd_buf;
  702. switch (cmd_no) {
  703. case HostCmd_CMD_UAP_SYS_CONFIG:
  704. if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
  705. return -1;
  706. break;
  707. case HostCmd_CMD_UAP_BSS_START:
  708. case HostCmd_CMD_UAP_BSS_STOP:
  709. case HOST_CMD_APCMD_SYS_RESET:
  710. case HOST_CMD_APCMD_STA_LIST:
  711. cmd->command = cpu_to_le16(cmd_no);
  712. cmd->size = cpu_to_le16(S_DS_GEN);
  713. break;
  714. case HostCmd_CMD_UAP_STA_DEAUTH:
  715. if (mwifiex_cmd_uap_sta_deauth(priv, cmd, data_buf))
  716. return -1;
  717. break;
  718. case HostCmd_CMD_CHAN_REPORT_REQUEST:
  719. if (mwifiex_cmd_issue_chan_report_request(priv, cmd_buf,
  720. data_buf))
  721. return -1;
  722. break;
  723. default:
  724. mwifiex_dbg(priv->adapter, ERROR,
  725. "PREP_CMD: unknown cmd %#x\n", cmd_no);
  726. return -1;
  727. }
  728. return 0;
  729. }
  730. void mwifiex_uap_set_channel(struct mwifiex_private *priv,
  731. struct mwifiex_uap_bss_param *bss_cfg,
  732. struct cfg80211_chan_def chandef)
  733. {
  734. u8 config_bands = 0, old_bands = priv->adapter->config_bands;
  735. priv->bss_chandef = chandef;
  736. bss_cfg->channel = ieee80211_frequency_to_channel(
  737. chandef.chan->center_freq);
  738. /* Set appropriate bands */
  739. if (chandef.chan->band == IEEE80211_BAND_2GHZ) {
  740. bss_cfg->band_cfg = BAND_CONFIG_BG;
  741. config_bands = BAND_B | BAND_G;
  742. if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
  743. config_bands |= BAND_GN;
  744. } else {
  745. bss_cfg->band_cfg = BAND_CONFIG_A;
  746. config_bands = BAND_A;
  747. if (chandef.width > NL80211_CHAN_WIDTH_20_NOHT)
  748. config_bands |= BAND_AN;
  749. if (chandef.width > NL80211_CHAN_WIDTH_40)
  750. config_bands |= BAND_AAC;
  751. }
  752. priv->adapter->config_bands = config_bands;
  753. if (old_bands != config_bands) {
  754. mwifiex_send_domain_info_cmd_fw(priv->adapter->wiphy);
  755. mwifiex_dnld_txpwr_table(priv);
  756. }
  757. }
  758. int mwifiex_config_start_uap(struct mwifiex_private *priv,
  759. struct mwifiex_uap_bss_param *bss_cfg)
  760. {
  761. enum state_11d_t state_11d;
  762. if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  763. HostCmd_ACT_GEN_SET,
  764. UAP_BSS_PARAMS_I, bss_cfg, false)) {
  765. mwifiex_dbg(priv->adapter, ERROR,
  766. "Failed to set the SSID\n");
  767. return -1;
  768. }
  769. /* Send cmd to FW to enable 11D function */
  770. state_11d = ENABLE_11D;
  771. if (mwifiex_send_cmd(priv, HostCmd_CMD_802_11_SNMP_MIB,
  772. HostCmd_ACT_GEN_SET, DOT11D_I,
  773. &state_11d, true)) {
  774. mwifiex_dbg(priv->adapter, ERROR,
  775. "11D: failed to enable 11D\n");
  776. return -1;
  777. }
  778. if (mwifiex_send_cmd(priv, HostCmd_CMD_UAP_BSS_START,
  779. HostCmd_ACT_GEN_SET, 0, NULL, false)) {
  780. mwifiex_dbg(priv->adapter, ERROR,
  781. "Failed to start the BSS\n");
  782. return -1;
  783. }
  784. if (priv->sec_info.wep_enabled)
  785. priv->curr_pkt_filter |= HostCmd_ACT_MAC_WEP_ENABLE;
  786. else
  787. priv->curr_pkt_filter &= ~HostCmd_ACT_MAC_WEP_ENABLE;
  788. if (mwifiex_send_cmd(priv, HostCmd_CMD_MAC_CONTROL,
  789. HostCmd_ACT_GEN_SET, 0,
  790. &priv->curr_pkt_filter, true))
  791. return -1;
  792. return 0;
  793. }