uap_cmd.c 29 KB

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