uap_cmd.c 14 KB

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