uap_cmd.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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_channel_band *chan_band;
  127. struct host_cmd_tlv_frag_threshold *frag_threshold;
  128. struct host_cmd_tlv_rts_threshold *rts_threshold;
  129. struct host_cmd_tlv_retry_limit *retry_limit;
  130. struct host_cmd_tlv_pwk_cipher *pwk_cipher;
  131. struct host_cmd_tlv_gwk_cipher *gwk_cipher;
  132. struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
  133. struct host_cmd_tlv_auth_type *auth_type;
  134. struct host_cmd_tlv_passphrase *passphrase;
  135. struct host_cmd_tlv_akmp *tlv_akmp;
  136. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  137. u16 cmd_size = *param_size;
  138. if (bss_cfg->ssid.ssid_len) {
  139. ssid = (struct host_cmd_tlv_ssid *)tlv;
  140. ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
  141. ssid->tlv.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
  142. memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
  143. cmd_size += sizeof(struct host_cmd_tlv) +
  144. bss_cfg->ssid.ssid_len;
  145. tlv += sizeof(struct host_cmd_tlv) + bss_cfg->ssid.ssid_len;
  146. }
  147. if (bss_cfg->channel && bss_cfg->channel <= MAX_CHANNEL_BAND_BG) {
  148. chan_band = (struct host_cmd_tlv_channel_band *)tlv;
  149. chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
  150. chan_band->tlv.len =
  151. cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
  152. sizeof(struct host_cmd_tlv));
  153. chan_band->band_config = bss_cfg->band_cfg;
  154. chan_band->channel = bss_cfg->channel;
  155. cmd_size += sizeof(struct host_cmd_tlv_channel_band);
  156. tlv += sizeof(struct host_cmd_tlv_channel_band);
  157. }
  158. if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
  159. bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
  160. beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
  161. beacon_period->tlv.type =
  162. cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
  163. beacon_period->tlv.len =
  164. cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
  165. sizeof(struct host_cmd_tlv));
  166. beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
  167. cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
  168. tlv += sizeof(struct host_cmd_tlv_beacon_period);
  169. }
  170. if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
  171. bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
  172. dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
  173. dtim_period->tlv.type = cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
  174. dtim_period->tlv.len =
  175. cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
  176. sizeof(struct host_cmd_tlv));
  177. dtim_period->period = bss_cfg->dtim_period;
  178. cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
  179. tlv += sizeof(struct host_cmd_tlv_dtim_period);
  180. }
  181. if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
  182. rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
  183. rts_threshold->tlv.type =
  184. cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
  185. rts_threshold->tlv.len =
  186. cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
  187. sizeof(struct host_cmd_tlv));
  188. rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
  189. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  190. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  191. }
  192. if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
  193. (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
  194. frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
  195. frag_threshold->tlv.type =
  196. cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
  197. frag_threshold->tlv.len =
  198. cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
  199. sizeof(struct host_cmd_tlv));
  200. frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
  201. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  202. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  203. }
  204. if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
  205. retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
  206. retry_limit->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
  207. retry_limit->tlv.len =
  208. cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
  209. sizeof(struct host_cmd_tlv));
  210. retry_limit->limit = (u8)bss_cfg->retry_limit;
  211. cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
  212. tlv += sizeof(struct host_cmd_tlv_retry_limit);
  213. }
  214. if ((bss_cfg->protocol & PROTOCOL_WPA) ||
  215. (bss_cfg->protocol & PROTOCOL_WPA2) ||
  216. (bss_cfg->protocol & PROTOCOL_EAP)) {
  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 =
  220. cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
  221. sizeof(struct host_cmd_tlv));
  222. tlv_akmp->key_mgmt_operation =
  223. cpu_to_le16(bss_cfg->key_mgmt_operation);
  224. tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
  225. cmd_size += sizeof(struct host_cmd_tlv_akmp);
  226. tlv += sizeof(struct host_cmd_tlv_akmp);
  227. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa &
  228. VALID_CIPHER_BITMAP) {
  229. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  230. pwk_cipher->tlv.type =
  231. cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  232. pwk_cipher->tlv.len = cpu_to_le16(
  233. sizeof(struct host_cmd_tlv_pwk_cipher) -
  234. sizeof(struct host_cmd_tlv));
  235. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
  236. pwk_cipher->cipher =
  237. bss_cfg->wpa_cfg.pairwise_cipher_wpa;
  238. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  239. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  240. }
  241. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 &
  242. VALID_CIPHER_BITMAP) {
  243. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  244. pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  245. pwk_cipher->tlv.len = cpu_to_le16(
  246. sizeof(struct host_cmd_tlv_pwk_cipher) -
  247. sizeof(struct host_cmd_tlv));
  248. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
  249. pwk_cipher->cipher =
  250. bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
  251. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  252. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  253. }
  254. if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
  255. gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
  256. gwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
  257. gwk_cipher->tlv.len = cpu_to_le16(
  258. sizeof(struct host_cmd_tlv_gwk_cipher) -
  259. sizeof(struct host_cmd_tlv));
  260. gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
  261. cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
  262. tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
  263. }
  264. if (bss_cfg->wpa_cfg.length) {
  265. passphrase = (struct host_cmd_tlv_passphrase *)tlv;
  266. passphrase->tlv.type =
  267. cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
  268. passphrase->tlv.len =
  269. cpu_to_le16(bss_cfg->wpa_cfg.length);
  270. memcpy(passphrase->passphrase,
  271. bss_cfg->wpa_cfg.passphrase,
  272. bss_cfg->wpa_cfg.length);
  273. cmd_size += sizeof(struct host_cmd_tlv) +
  274. bss_cfg->wpa_cfg.length;
  275. tlv += sizeof(struct host_cmd_tlv) +
  276. bss_cfg->wpa_cfg.length;
  277. }
  278. }
  279. if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
  280. (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
  281. auth_type = (struct host_cmd_tlv_auth_type *)tlv;
  282. auth_type->tlv.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
  283. auth_type->tlv.len =
  284. cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
  285. sizeof(struct host_cmd_tlv));
  286. auth_type->auth_type = (u8)bss_cfg->auth_mode;
  287. cmd_size += sizeof(struct host_cmd_tlv_auth_type);
  288. tlv += sizeof(struct host_cmd_tlv_auth_type);
  289. }
  290. if (bss_cfg->protocol) {
  291. encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
  292. encrypt_protocol->tlv.type =
  293. cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
  294. encrypt_protocol->tlv.len =
  295. cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
  296. - sizeof(struct host_cmd_tlv));
  297. encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
  298. cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
  299. tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
  300. }
  301. *param_size = cmd_size;
  302. return 0;
  303. }
  304. /* This function parses custom IEs from IE list and prepares command buffer */
  305. static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
  306. {
  307. struct mwifiex_ie_list *ap_ie = cmd_buf;
  308. struct host_cmd_tlv *tlv_ie = (struct host_cmd_tlv *)tlv;
  309. if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
  310. return -1;
  311. *ie_size += le16_to_cpu(ap_ie->len) + sizeof(struct host_cmd_tlv);
  312. tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
  313. tlv_ie->len = ap_ie->len;
  314. tlv += sizeof(struct host_cmd_tlv);
  315. memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
  316. return 0;
  317. }
  318. /* Parse AP config structure and prepare TLV based command structure
  319. * to be sent to FW for uAP configuration
  320. */
  321. static int
  322. mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
  323. u32 type, void *cmd_buf)
  324. {
  325. u8 *tlv;
  326. u16 cmd_size, param_size, ie_size;
  327. struct host_cmd_ds_sys_config *sys_cfg;
  328. cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
  329. cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
  330. sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
  331. sys_cfg->action = cpu_to_le16(cmd_action);
  332. tlv = sys_cfg->tlv;
  333. switch (type) {
  334. case UAP_BSS_PARAMS_I:
  335. param_size = cmd_size;
  336. if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
  337. return -1;
  338. cmd->size = cpu_to_le16(param_size);
  339. break;
  340. case UAP_CUSTOM_IE_I:
  341. ie_size = cmd_size;
  342. if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
  343. return -1;
  344. cmd->size = cpu_to_le16(ie_size);
  345. break;
  346. default:
  347. return -1;
  348. }
  349. return 0;
  350. }
  351. /* This function prepares the AP specific commands before sending them
  352. * to the firmware.
  353. * This is a generic function which calls specific command preparation
  354. * routines based upon the command number.
  355. */
  356. int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
  357. u16 cmd_action, u32 type,
  358. void *data_buf, void *cmd_buf)
  359. {
  360. struct host_cmd_ds_command *cmd = cmd_buf;
  361. switch (cmd_no) {
  362. case HostCmd_CMD_UAP_SYS_CONFIG:
  363. if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
  364. return -1;
  365. break;
  366. case HostCmd_CMD_UAP_BSS_START:
  367. case HostCmd_CMD_UAP_BSS_STOP:
  368. cmd->command = cpu_to_le16(cmd_no);
  369. cmd->size = cpu_to_le16(S_DS_GEN);
  370. break;
  371. default:
  372. dev_err(priv->adapter->dev,
  373. "PREP_CMD: unknown cmd %#x\n", cmd_no);
  374. return -1;
  375. }
  376. return 0;
  377. }
  378. /* This function sets the RF channel for AP.
  379. *
  380. * This function populates channel information in AP config structure
  381. * and sends command to configure channel information in AP.
  382. */
  383. int mwifiex_uap_set_channel(struct mwifiex_private *priv, int channel)
  384. {
  385. struct mwifiex_uap_bss_param *bss_cfg;
  386. struct wiphy *wiphy = priv->wdev->wiphy;
  387. bss_cfg = kzalloc(sizeof(struct mwifiex_uap_bss_param), GFP_KERNEL);
  388. if (!bss_cfg)
  389. return -ENOMEM;
  390. bss_cfg->band_cfg = BAND_CONFIG_MANUAL;
  391. bss_cfg->channel = channel;
  392. if (mwifiex_send_cmd_async(priv, HostCmd_CMD_UAP_SYS_CONFIG,
  393. HostCmd_ACT_GEN_SET,
  394. UAP_BSS_PARAMS_I, bss_cfg)) {
  395. wiphy_err(wiphy, "Failed to set the uAP channel\n");
  396. kfree(bss_cfg);
  397. return -1;
  398. }
  399. kfree(bss_cfg);
  400. return 0;
  401. }