uap_cmd.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. switch (params->auth_type) {
  28. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  29. bss_config->auth_mode = WLAN_AUTH_OPEN;
  30. break;
  31. case NL80211_AUTHTYPE_SHARED_KEY:
  32. bss_config->auth_mode = WLAN_AUTH_SHARED_KEY;
  33. break;
  34. case NL80211_AUTHTYPE_NETWORK_EAP:
  35. bss_config->auth_mode = WLAN_AUTH_LEAP;
  36. break;
  37. default:
  38. bss_config->auth_mode = MWIFIEX_AUTH_MODE_AUTO;
  39. break;
  40. }
  41. bss_config->key_mgmt_operation |= KEY_MGMT_ON_HOST;
  42. for (i = 0; i < params->crypto.n_akm_suites; i++) {
  43. switch (params->crypto.akm_suites[i]) {
  44. case WLAN_AKM_SUITE_8021X:
  45. if (params->crypto.wpa_versions &
  46. NL80211_WPA_VERSION_1) {
  47. bss_config->protocol = PROTOCOL_WPA;
  48. bss_config->key_mgmt = KEY_MGMT_EAP;
  49. }
  50. if (params->crypto.wpa_versions &
  51. NL80211_WPA_VERSION_2) {
  52. bss_config->protocol = PROTOCOL_WPA2;
  53. bss_config->key_mgmt = KEY_MGMT_EAP;
  54. }
  55. break;
  56. case WLAN_AKM_SUITE_PSK:
  57. if (params->crypto.wpa_versions &
  58. NL80211_WPA_VERSION_1) {
  59. bss_config->protocol = PROTOCOL_WPA;
  60. bss_config->key_mgmt = KEY_MGMT_PSK;
  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_PSK;
  66. }
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. for (i = 0; i < params->crypto.n_ciphers_pairwise; i++) {
  73. switch (params->crypto.ciphers_pairwise[i]) {
  74. case WLAN_CIPHER_SUITE_WEP40:
  75. case WLAN_CIPHER_SUITE_WEP104:
  76. break;
  77. case WLAN_CIPHER_SUITE_TKIP:
  78. bss_config->wpa_cfg.pairwise_cipher_wpa = CIPHER_TKIP;
  79. break;
  80. case WLAN_CIPHER_SUITE_CCMP:
  81. bss_config->wpa_cfg.pairwise_cipher_wpa2 =
  82. CIPHER_AES_CCMP;
  83. default:
  84. break;
  85. }
  86. }
  87. switch (params->crypto.cipher_group) {
  88. case WLAN_CIPHER_SUITE_WEP40:
  89. case WLAN_CIPHER_SUITE_WEP104:
  90. break;
  91. case WLAN_CIPHER_SUITE_TKIP:
  92. bss_config->wpa_cfg.group_cipher = CIPHER_TKIP;
  93. break;
  94. case WLAN_CIPHER_SUITE_CCMP:
  95. bss_config->wpa_cfg.group_cipher = CIPHER_AES_CCMP;
  96. break;
  97. default:
  98. break;
  99. }
  100. return 0;
  101. }
  102. /* This function initializes some of mwifiex_uap_bss_param variables.
  103. * This helps FW in ignoring invalid values. These values may or may not
  104. * be get updated to valid ones at later stage.
  105. */
  106. void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
  107. {
  108. config->bcast_ssid_ctl = 0x7F;
  109. config->radio_ctl = 0x7F;
  110. config->dtim_period = 0x7F;
  111. config->beacon_period = 0x7FFF;
  112. config->auth_mode = 0x7F;
  113. config->rts_threshold = 0x7FFF;
  114. config->frag_threshold = 0x7FFF;
  115. config->retry_limit = 0x7F;
  116. }
  117. /* This function parses BSS related parameters from structure
  118. * and prepares TLVs. These TLVs are appended to command buffer.
  119. */
  120. static int
  121. mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
  122. {
  123. struct host_cmd_tlv_dtim_period *dtim_period;
  124. struct host_cmd_tlv_beacon_period *beacon_period;
  125. struct host_cmd_tlv_ssid *ssid;
  126. struct host_cmd_tlv_bcast_ssid *bcast_ssid;
  127. struct host_cmd_tlv_channel_band *chan_band;
  128. struct host_cmd_tlv_frag_threshold *frag_threshold;
  129. struct host_cmd_tlv_rts_threshold *rts_threshold;
  130. struct host_cmd_tlv_retry_limit *retry_limit;
  131. struct host_cmd_tlv_pwk_cipher *pwk_cipher;
  132. struct host_cmd_tlv_gwk_cipher *gwk_cipher;
  133. struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
  134. struct host_cmd_tlv_auth_type *auth_type;
  135. struct host_cmd_tlv_passphrase *passphrase;
  136. struct host_cmd_tlv_akmp *tlv_akmp;
  137. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  138. u16 cmd_size = *param_size;
  139. if (bss_cfg->ssid.ssid_len) {
  140. ssid = (struct host_cmd_tlv_ssid *)tlv;
  141. ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
  142. ssid->tlv.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
  143. memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
  144. cmd_size += sizeof(struct host_cmd_tlv) +
  145. bss_cfg->ssid.ssid_len;
  146. tlv += sizeof(struct host_cmd_tlv) + bss_cfg->ssid.ssid_len;
  147. bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
  148. bcast_ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
  149. bcast_ssid->tlv.len =
  150. cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
  151. bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
  152. cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
  153. tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
  154. }
  155. if (bss_cfg->channel && bss_cfg->channel <= MAX_CHANNEL_BAND_BG) {
  156. chan_band = (struct host_cmd_tlv_channel_band *)tlv;
  157. chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
  158. chan_band->tlv.len =
  159. cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
  160. sizeof(struct host_cmd_tlv));
  161. chan_band->band_config = bss_cfg->band_cfg;
  162. chan_band->channel = bss_cfg->channel;
  163. cmd_size += sizeof(struct host_cmd_tlv_channel_band);
  164. tlv += sizeof(struct host_cmd_tlv_channel_band);
  165. }
  166. if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
  167. bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
  168. beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
  169. beacon_period->tlv.type =
  170. cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
  171. beacon_period->tlv.len =
  172. cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
  173. sizeof(struct host_cmd_tlv));
  174. beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
  175. cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
  176. tlv += sizeof(struct host_cmd_tlv_beacon_period);
  177. }
  178. if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
  179. bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
  180. dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
  181. dtim_period->tlv.type = cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
  182. dtim_period->tlv.len =
  183. cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
  184. sizeof(struct host_cmd_tlv));
  185. dtim_period->period = bss_cfg->dtim_period;
  186. cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
  187. tlv += sizeof(struct host_cmd_tlv_dtim_period);
  188. }
  189. if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
  190. rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
  191. rts_threshold->tlv.type =
  192. cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
  193. rts_threshold->tlv.len =
  194. cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
  195. sizeof(struct host_cmd_tlv));
  196. rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
  197. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  198. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  199. }
  200. if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
  201. (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
  202. frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
  203. frag_threshold->tlv.type =
  204. cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
  205. frag_threshold->tlv.len =
  206. cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
  207. sizeof(struct host_cmd_tlv));
  208. frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
  209. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  210. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  211. }
  212. if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
  213. retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
  214. retry_limit->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
  215. retry_limit->tlv.len =
  216. cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
  217. sizeof(struct host_cmd_tlv));
  218. retry_limit->limit = (u8)bss_cfg->retry_limit;
  219. cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
  220. tlv += sizeof(struct host_cmd_tlv_retry_limit);
  221. }
  222. if ((bss_cfg->protocol & PROTOCOL_WPA) ||
  223. (bss_cfg->protocol & PROTOCOL_WPA2) ||
  224. (bss_cfg->protocol & PROTOCOL_EAP)) {
  225. tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
  226. tlv_akmp->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
  227. tlv_akmp->tlv.len =
  228. cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
  229. sizeof(struct host_cmd_tlv));
  230. tlv_akmp->key_mgmt_operation =
  231. cpu_to_le16(bss_cfg->key_mgmt_operation);
  232. tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
  233. cmd_size += sizeof(struct host_cmd_tlv_akmp);
  234. tlv += sizeof(struct host_cmd_tlv_akmp);
  235. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa &
  236. VALID_CIPHER_BITMAP) {
  237. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  238. pwk_cipher->tlv.type =
  239. cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  240. pwk_cipher->tlv.len = cpu_to_le16(
  241. sizeof(struct host_cmd_tlv_pwk_cipher) -
  242. sizeof(struct host_cmd_tlv));
  243. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
  244. pwk_cipher->cipher =
  245. bss_cfg->wpa_cfg.pairwise_cipher_wpa;
  246. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  247. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  248. }
  249. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 &
  250. VALID_CIPHER_BITMAP) {
  251. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  252. pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  253. pwk_cipher->tlv.len = cpu_to_le16(
  254. sizeof(struct host_cmd_tlv_pwk_cipher) -
  255. sizeof(struct host_cmd_tlv));
  256. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
  257. pwk_cipher->cipher =
  258. bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
  259. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  260. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  261. }
  262. if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
  263. gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
  264. gwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
  265. gwk_cipher->tlv.len = cpu_to_le16(
  266. sizeof(struct host_cmd_tlv_gwk_cipher) -
  267. sizeof(struct host_cmd_tlv));
  268. gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
  269. cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
  270. tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
  271. }
  272. if (bss_cfg->wpa_cfg.length) {
  273. passphrase = (struct host_cmd_tlv_passphrase *)tlv;
  274. passphrase->tlv.type =
  275. cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
  276. passphrase->tlv.len =
  277. cpu_to_le16(bss_cfg->wpa_cfg.length);
  278. memcpy(passphrase->passphrase,
  279. bss_cfg->wpa_cfg.passphrase,
  280. bss_cfg->wpa_cfg.length);
  281. cmd_size += sizeof(struct host_cmd_tlv) +
  282. bss_cfg->wpa_cfg.length;
  283. tlv += sizeof(struct host_cmd_tlv) +
  284. bss_cfg->wpa_cfg.length;
  285. }
  286. }
  287. if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
  288. (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
  289. auth_type = (struct host_cmd_tlv_auth_type *)tlv;
  290. auth_type->tlv.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
  291. auth_type->tlv.len =
  292. cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
  293. sizeof(struct host_cmd_tlv));
  294. auth_type->auth_type = (u8)bss_cfg->auth_mode;
  295. cmd_size += sizeof(struct host_cmd_tlv_auth_type);
  296. tlv += sizeof(struct host_cmd_tlv_auth_type);
  297. }
  298. if (bss_cfg->protocol) {
  299. encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
  300. encrypt_protocol->tlv.type =
  301. cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
  302. encrypt_protocol->tlv.len =
  303. cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
  304. - sizeof(struct host_cmd_tlv));
  305. encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
  306. cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
  307. tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
  308. }
  309. *param_size = cmd_size;
  310. return 0;
  311. }
  312. /* This function parses custom IEs from IE list and prepares command buffer */
  313. static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
  314. {
  315. struct mwifiex_ie_list *ap_ie = cmd_buf;
  316. struct host_cmd_tlv *tlv_ie = (struct host_cmd_tlv *)tlv;
  317. if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
  318. return -1;
  319. *ie_size += le16_to_cpu(ap_ie->len) + sizeof(struct host_cmd_tlv);
  320. tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
  321. tlv_ie->len = ap_ie->len;
  322. tlv += sizeof(struct host_cmd_tlv);
  323. memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
  324. return 0;
  325. }
  326. /* Parse AP config structure and prepare TLV based command structure
  327. * to be sent to FW for uAP configuration
  328. */
  329. static int
  330. mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
  331. u32 type, void *cmd_buf)
  332. {
  333. u8 *tlv;
  334. u16 cmd_size, param_size, ie_size;
  335. struct host_cmd_ds_sys_config *sys_cfg;
  336. cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
  337. cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
  338. sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
  339. sys_cfg->action = cpu_to_le16(cmd_action);
  340. tlv = sys_cfg->tlv;
  341. switch (type) {
  342. case UAP_BSS_PARAMS_I:
  343. param_size = cmd_size;
  344. if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
  345. return -1;
  346. cmd->size = cpu_to_le16(param_size);
  347. break;
  348. case UAP_CUSTOM_IE_I:
  349. ie_size = cmd_size;
  350. if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
  351. return -1;
  352. cmd->size = cpu_to_le16(ie_size);
  353. break;
  354. default:
  355. return -1;
  356. }
  357. return 0;
  358. }
  359. /* This function prepares the AP specific commands before sending them
  360. * to the firmware.
  361. * This is a generic function which calls specific command preparation
  362. * routines based upon the command number.
  363. */
  364. int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
  365. u16 cmd_action, u32 type,
  366. void *data_buf, void *cmd_buf)
  367. {
  368. struct host_cmd_ds_command *cmd = cmd_buf;
  369. switch (cmd_no) {
  370. case HostCmd_CMD_UAP_SYS_CONFIG:
  371. if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
  372. return -1;
  373. break;
  374. case HostCmd_CMD_UAP_BSS_START:
  375. case HostCmd_CMD_UAP_BSS_STOP:
  376. cmd->command = cpu_to_le16(cmd_no);
  377. cmd->size = cpu_to_le16(S_DS_GEN);
  378. break;
  379. default:
  380. dev_err(priv->adapter->dev,
  381. "PREP_CMD: unknown cmd %#x\n", cmd_no);
  382. return -1;
  383. }
  384. return 0;
  385. }
  386. /* This function sets the RF channel for AP.
  387. *
  388. * This function populates channel information in AP config structure
  389. * and sends command to configure channel information in AP.
  390. */
  391. int mwifiex_uap_set_channel(struct mwifiex_private *priv, int channel)
  392. {
  393. struct mwifiex_uap_bss_param *bss_cfg;
  394. struct wiphy *wiphy = priv->wdev->wiphy;
  395. bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
  396. if (!bss_cfg)
  397. return -ENOMEM;
  398. mwifiex_set_sys_config_invalid_data(bss_cfg);
  399. bss_cfg->band_cfg = BAND_CONFIG_MANUAL;
  400. bss_cfg->channel = channel;
  401. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  402. HostCmd_ACT_GEN_SET,
  403. UAP_BSS_PARAMS_I, bss_cfg)) {
  404. wiphy_err(wiphy, "Failed to set the uAP channel\n");
  405. kfree(bss_cfg);
  406. return -1;
  407. }
  408. kfree(bss_cfg);
  409. return 0;
  410. }