uap_cmd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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 updates 11n related parameters from IE and sets them into
  112. * bss_config structure.
  113. */
  114. void
  115. mwifiex_set_ht_params(struct mwifiex_private *priv,
  116. struct mwifiex_uap_bss_param *bss_cfg,
  117. struct cfg80211_ap_settings *params)
  118. {
  119. const u8 *ht_ie;
  120. if (!ISSUPP_11NENABLED(priv->adapter->fw_cap_info))
  121. return;
  122. ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, params->beacon.tail,
  123. params->beacon.tail_len);
  124. if (ht_ie) {
  125. memcpy(&bss_cfg->ht_cap, ht_ie + 2,
  126. sizeof(struct ieee80211_ht_cap));
  127. } else {
  128. memset(&bss_cfg->ht_cap , 0, sizeof(struct ieee80211_ht_cap));
  129. bss_cfg->ht_cap.cap_info = cpu_to_le16(MWIFIEX_DEF_HT_CAP);
  130. bss_cfg->ht_cap.ampdu_params_info = MWIFIEX_DEF_AMPDU;
  131. }
  132. return;
  133. }
  134. /* This function initializes some of mwifiex_uap_bss_param variables.
  135. * This helps FW in ignoring invalid values. These values may or may not
  136. * be get updated to valid ones at later stage.
  137. */
  138. void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config)
  139. {
  140. config->bcast_ssid_ctl = 0x7F;
  141. config->radio_ctl = 0x7F;
  142. config->dtim_period = 0x7F;
  143. config->beacon_period = 0x7FFF;
  144. config->auth_mode = 0x7F;
  145. config->rts_threshold = 0x7FFF;
  146. config->frag_threshold = 0x7FFF;
  147. config->retry_limit = 0x7F;
  148. }
  149. /* This function parses BSS related parameters from structure
  150. * and prepares TLVs specific to WPA/WPA2 security.
  151. * These TLVs are appended to command buffer.
  152. */
  153. static void
  154. mwifiex_uap_bss_wpa(u8 **tlv_buf, void *cmd_buf, u16 *param_size)
  155. {
  156. struct host_cmd_tlv_pwk_cipher *pwk_cipher;
  157. struct host_cmd_tlv_gwk_cipher *gwk_cipher;
  158. struct host_cmd_tlv_passphrase *passphrase;
  159. struct host_cmd_tlv_akmp *tlv_akmp;
  160. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  161. u16 cmd_size = *param_size;
  162. u8 *tlv = *tlv_buf;
  163. tlv_akmp = (struct host_cmd_tlv_akmp *)tlv;
  164. tlv_akmp->tlv.type = cpu_to_le16(TLV_TYPE_UAP_AKMP);
  165. tlv_akmp->tlv.len = cpu_to_le16(sizeof(struct host_cmd_tlv_akmp) -
  166. sizeof(struct host_cmd_tlv));
  167. tlv_akmp->key_mgmt_operation = cpu_to_le16(bss_cfg->key_mgmt_operation);
  168. tlv_akmp->key_mgmt = cpu_to_le16(bss_cfg->key_mgmt);
  169. cmd_size += sizeof(struct host_cmd_tlv_akmp);
  170. tlv += sizeof(struct host_cmd_tlv_akmp);
  171. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa & VALID_CIPHER_BITMAP) {
  172. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  173. pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  174. pwk_cipher->tlv.len =
  175. cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
  176. sizeof(struct host_cmd_tlv));
  177. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA);
  178. pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa;
  179. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  180. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  181. }
  182. if (bss_cfg->wpa_cfg.pairwise_cipher_wpa2 & VALID_CIPHER_BITMAP) {
  183. pwk_cipher = (struct host_cmd_tlv_pwk_cipher *)tlv;
  184. pwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_PWK_CIPHER);
  185. pwk_cipher->tlv.len =
  186. cpu_to_le16(sizeof(struct host_cmd_tlv_pwk_cipher) -
  187. sizeof(struct host_cmd_tlv));
  188. pwk_cipher->proto = cpu_to_le16(PROTOCOL_WPA2);
  189. pwk_cipher->cipher = bss_cfg->wpa_cfg.pairwise_cipher_wpa2;
  190. cmd_size += sizeof(struct host_cmd_tlv_pwk_cipher);
  191. tlv += sizeof(struct host_cmd_tlv_pwk_cipher);
  192. }
  193. if (bss_cfg->wpa_cfg.group_cipher & VALID_CIPHER_BITMAP) {
  194. gwk_cipher = (struct host_cmd_tlv_gwk_cipher *)tlv;
  195. gwk_cipher->tlv.type = cpu_to_le16(TLV_TYPE_GWK_CIPHER);
  196. gwk_cipher->tlv.len =
  197. cpu_to_le16(sizeof(struct host_cmd_tlv_gwk_cipher) -
  198. sizeof(struct host_cmd_tlv));
  199. gwk_cipher->cipher = bss_cfg->wpa_cfg.group_cipher;
  200. cmd_size += sizeof(struct host_cmd_tlv_gwk_cipher);
  201. tlv += sizeof(struct host_cmd_tlv_gwk_cipher);
  202. }
  203. if (bss_cfg->wpa_cfg.length) {
  204. passphrase = (struct host_cmd_tlv_passphrase *)tlv;
  205. passphrase->tlv.type = cpu_to_le16(TLV_TYPE_UAP_WPA_PASSPHRASE);
  206. passphrase->tlv.len = cpu_to_le16(bss_cfg->wpa_cfg.length);
  207. memcpy(passphrase->passphrase, bss_cfg->wpa_cfg.passphrase,
  208. bss_cfg->wpa_cfg.length);
  209. cmd_size += sizeof(struct host_cmd_tlv) +
  210. bss_cfg->wpa_cfg.length;
  211. tlv += sizeof(struct host_cmd_tlv) + bss_cfg->wpa_cfg.length;
  212. }
  213. *param_size = cmd_size;
  214. *tlv_buf = tlv;
  215. return;
  216. }
  217. /* This function parses BSS related parameters from structure
  218. * and prepares TLVs. These TLVs are appended to command buffer.
  219. */
  220. static int
  221. mwifiex_uap_bss_param_prepare(u8 *tlv, void *cmd_buf, u16 *param_size)
  222. {
  223. struct host_cmd_tlv_dtim_period *dtim_period;
  224. struct host_cmd_tlv_beacon_period *beacon_period;
  225. struct host_cmd_tlv_ssid *ssid;
  226. struct host_cmd_tlv_bcast_ssid *bcast_ssid;
  227. struct host_cmd_tlv_channel_band *chan_band;
  228. struct host_cmd_tlv_frag_threshold *frag_threshold;
  229. struct host_cmd_tlv_rts_threshold *rts_threshold;
  230. struct host_cmd_tlv_retry_limit *retry_limit;
  231. struct host_cmd_tlv_encrypt_protocol *encrypt_protocol;
  232. struct host_cmd_tlv_auth_type *auth_type;
  233. struct mwifiex_ie_types_htcap *htcap;
  234. struct mwifiex_uap_bss_param *bss_cfg = cmd_buf;
  235. u16 cmd_size = *param_size;
  236. if (bss_cfg->ssid.ssid_len) {
  237. ssid = (struct host_cmd_tlv_ssid *)tlv;
  238. ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_SSID);
  239. ssid->tlv.len = cpu_to_le16((u16)bss_cfg->ssid.ssid_len);
  240. memcpy(ssid->ssid, bss_cfg->ssid.ssid, bss_cfg->ssid.ssid_len);
  241. cmd_size += sizeof(struct host_cmd_tlv) +
  242. bss_cfg->ssid.ssid_len;
  243. tlv += sizeof(struct host_cmd_tlv) + bss_cfg->ssid.ssid_len;
  244. bcast_ssid = (struct host_cmd_tlv_bcast_ssid *)tlv;
  245. bcast_ssid->tlv.type = cpu_to_le16(TLV_TYPE_UAP_BCAST_SSID);
  246. bcast_ssid->tlv.len =
  247. cpu_to_le16(sizeof(bcast_ssid->bcast_ctl));
  248. bcast_ssid->bcast_ctl = bss_cfg->bcast_ssid_ctl;
  249. cmd_size += sizeof(struct host_cmd_tlv_bcast_ssid);
  250. tlv += sizeof(struct host_cmd_tlv_bcast_ssid);
  251. }
  252. if (bss_cfg->channel && bss_cfg->channel <= MAX_CHANNEL_BAND_BG) {
  253. chan_band = (struct host_cmd_tlv_channel_band *)tlv;
  254. chan_band->tlv.type = cpu_to_le16(TLV_TYPE_CHANNELBANDLIST);
  255. chan_band->tlv.len =
  256. cpu_to_le16(sizeof(struct host_cmd_tlv_channel_band) -
  257. sizeof(struct host_cmd_tlv));
  258. chan_band->band_config = bss_cfg->band_cfg;
  259. chan_band->channel = bss_cfg->channel;
  260. cmd_size += sizeof(struct host_cmd_tlv_channel_band);
  261. tlv += sizeof(struct host_cmd_tlv_channel_band);
  262. }
  263. if (bss_cfg->beacon_period >= MIN_BEACON_PERIOD &&
  264. bss_cfg->beacon_period <= MAX_BEACON_PERIOD) {
  265. beacon_period = (struct host_cmd_tlv_beacon_period *)tlv;
  266. beacon_period->tlv.type =
  267. cpu_to_le16(TLV_TYPE_UAP_BEACON_PERIOD);
  268. beacon_period->tlv.len =
  269. cpu_to_le16(sizeof(struct host_cmd_tlv_beacon_period) -
  270. sizeof(struct host_cmd_tlv));
  271. beacon_period->period = cpu_to_le16(bss_cfg->beacon_period);
  272. cmd_size += sizeof(struct host_cmd_tlv_beacon_period);
  273. tlv += sizeof(struct host_cmd_tlv_beacon_period);
  274. }
  275. if (bss_cfg->dtim_period >= MIN_DTIM_PERIOD &&
  276. bss_cfg->dtim_period <= MAX_DTIM_PERIOD) {
  277. dtim_period = (struct host_cmd_tlv_dtim_period *)tlv;
  278. dtim_period->tlv.type = cpu_to_le16(TLV_TYPE_UAP_DTIM_PERIOD);
  279. dtim_period->tlv.len =
  280. cpu_to_le16(sizeof(struct host_cmd_tlv_dtim_period) -
  281. sizeof(struct host_cmd_tlv));
  282. dtim_period->period = bss_cfg->dtim_period;
  283. cmd_size += sizeof(struct host_cmd_tlv_dtim_period);
  284. tlv += sizeof(struct host_cmd_tlv_dtim_period);
  285. }
  286. if (bss_cfg->rts_threshold <= MWIFIEX_RTS_MAX_VALUE) {
  287. rts_threshold = (struct host_cmd_tlv_rts_threshold *)tlv;
  288. rts_threshold->tlv.type =
  289. cpu_to_le16(TLV_TYPE_UAP_RTS_THRESHOLD);
  290. rts_threshold->tlv.len =
  291. cpu_to_le16(sizeof(struct host_cmd_tlv_rts_threshold) -
  292. sizeof(struct host_cmd_tlv));
  293. rts_threshold->rts_thr = cpu_to_le16(bss_cfg->rts_threshold);
  294. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  295. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  296. }
  297. if ((bss_cfg->frag_threshold >= MWIFIEX_FRAG_MIN_VALUE) &&
  298. (bss_cfg->frag_threshold <= MWIFIEX_FRAG_MAX_VALUE)) {
  299. frag_threshold = (struct host_cmd_tlv_frag_threshold *)tlv;
  300. frag_threshold->tlv.type =
  301. cpu_to_le16(TLV_TYPE_UAP_FRAG_THRESHOLD);
  302. frag_threshold->tlv.len =
  303. cpu_to_le16(sizeof(struct host_cmd_tlv_frag_threshold) -
  304. sizeof(struct host_cmd_tlv));
  305. frag_threshold->frag_thr = cpu_to_le16(bss_cfg->frag_threshold);
  306. cmd_size += sizeof(struct host_cmd_tlv_frag_threshold);
  307. tlv += sizeof(struct host_cmd_tlv_frag_threshold);
  308. }
  309. if (bss_cfg->retry_limit <= MWIFIEX_RETRY_LIMIT) {
  310. retry_limit = (struct host_cmd_tlv_retry_limit *)tlv;
  311. retry_limit->tlv.type = cpu_to_le16(TLV_TYPE_UAP_RETRY_LIMIT);
  312. retry_limit->tlv.len =
  313. cpu_to_le16(sizeof(struct host_cmd_tlv_retry_limit) -
  314. sizeof(struct host_cmd_tlv));
  315. retry_limit->limit = (u8)bss_cfg->retry_limit;
  316. cmd_size += sizeof(struct host_cmd_tlv_retry_limit);
  317. tlv += sizeof(struct host_cmd_tlv_retry_limit);
  318. }
  319. if ((bss_cfg->protocol & PROTOCOL_WPA) ||
  320. (bss_cfg->protocol & PROTOCOL_WPA2) ||
  321. (bss_cfg->protocol & PROTOCOL_EAP))
  322. mwifiex_uap_bss_wpa(&tlv, cmd_buf, &cmd_size);
  323. if ((bss_cfg->auth_mode <= WLAN_AUTH_SHARED_KEY) ||
  324. (bss_cfg->auth_mode == MWIFIEX_AUTH_MODE_AUTO)) {
  325. auth_type = (struct host_cmd_tlv_auth_type *)tlv;
  326. auth_type->tlv.type = cpu_to_le16(TLV_TYPE_AUTH_TYPE);
  327. auth_type->tlv.len =
  328. cpu_to_le16(sizeof(struct host_cmd_tlv_auth_type) -
  329. sizeof(struct host_cmd_tlv));
  330. auth_type->auth_type = (u8)bss_cfg->auth_mode;
  331. cmd_size += sizeof(struct host_cmd_tlv_auth_type);
  332. tlv += sizeof(struct host_cmd_tlv_auth_type);
  333. }
  334. if (bss_cfg->protocol) {
  335. encrypt_protocol = (struct host_cmd_tlv_encrypt_protocol *)tlv;
  336. encrypt_protocol->tlv.type =
  337. cpu_to_le16(TLV_TYPE_UAP_ENCRY_PROTOCOL);
  338. encrypt_protocol->tlv.len =
  339. cpu_to_le16(sizeof(struct host_cmd_tlv_encrypt_protocol)
  340. - sizeof(struct host_cmd_tlv));
  341. encrypt_protocol->proto = cpu_to_le16(bss_cfg->protocol);
  342. cmd_size += sizeof(struct host_cmd_tlv_encrypt_protocol);
  343. tlv += sizeof(struct host_cmd_tlv_encrypt_protocol);
  344. }
  345. if (bss_cfg->ht_cap.cap_info) {
  346. htcap = (struct mwifiex_ie_types_htcap *)tlv;
  347. htcap->header.type = cpu_to_le16(WLAN_EID_HT_CAPABILITY);
  348. htcap->header.len =
  349. cpu_to_le16(sizeof(struct ieee80211_ht_cap));
  350. htcap->ht_cap.cap_info = bss_cfg->ht_cap.cap_info;
  351. htcap->ht_cap.ampdu_params_info =
  352. bss_cfg->ht_cap.ampdu_params_info;
  353. memcpy(&htcap->ht_cap.mcs, &bss_cfg->ht_cap.mcs,
  354. sizeof(struct ieee80211_mcs_info));
  355. htcap->ht_cap.extended_ht_cap_info =
  356. bss_cfg->ht_cap.extended_ht_cap_info;
  357. htcap->ht_cap.tx_BF_cap_info = bss_cfg->ht_cap.tx_BF_cap_info;
  358. htcap->ht_cap.antenna_selection_info =
  359. bss_cfg->ht_cap.antenna_selection_info;
  360. cmd_size += sizeof(struct mwifiex_ie_types_htcap);
  361. tlv += sizeof(struct mwifiex_ie_types_htcap);
  362. }
  363. *param_size = cmd_size;
  364. return 0;
  365. }
  366. /* This function parses custom IEs from IE list and prepares command buffer */
  367. static int mwifiex_uap_custom_ie_prepare(u8 *tlv, void *cmd_buf, u16 *ie_size)
  368. {
  369. struct mwifiex_ie_list *ap_ie = cmd_buf;
  370. struct host_cmd_tlv *tlv_ie = (struct host_cmd_tlv *)tlv;
  371. if (!ap_ie || !ap_ie->len || !ap_ie->ie_list)
  372. return -1;
  373. *ie_size += le16_to_cpu(ap_ie->len) + sizeof(struct host_cmd_tlv);
  374. tlv_ie->type = cpu_to_le16(TLV_TYPE_MGMT_IE);
  375. tlv_ie->len = ap_ie->len;
  376. tlv += sizeof(struct host_cmd_tlv);
  377. memcpy(tlv, ap_ie->ie_list, le16_to_cpu(ap_ie->len));
  378. return 0;
  379. }
  380. /* Parse AP config structure and prepare TLV based command structure
  381. * to be sent to FW for uAP configuration
  382. */
  383. static int
  384. mwifiex_cmd_uap_sys_config(struct host_cmd_ds_command *cmd, u16 cmd_action,
  385. u32 type, void *cmd_buf)
  386. {
  387. u8 *tlv;
  388. u16 cmd_size, param_size, ie_size;
  389. struct host_cmd_ds_sys_config *sys_cfg;
  390. cmd->command = cpu_to_le16(HostCmd_CMD_UAP_SYS_CONFIG);
  391. cmd_size = (u16)(sizeof(struct host_cmd_ds_sys_config) + S_DS_GEN);
  392. sys_cfg = (struct host_cmd_ds_sys_config *)&cmd->params.uap_sys_config;
  393. sys_cfg->action = cpu_to_le16(cmd_action);
  394. tlv = sys_cfg->tlv;
  395. switch (type) {
  396. case UAP_BSS_PARAMS_I:
  397. param_size = cmd_size;
  398. if (mwifiex_uap_bss_param_prepare(tlv, cmd_buf, &param_size))
  399. return -1;
  400. cmd->size = cpu_to_le16(param_size);
  401. break;
  402. case UAP_CUSTOM_IE_I:
  403. ie_size = cmd_size;
  404. if (mwifiex_uap_custom_ie_prepare(tlv, cmd_buf, &ie_size))
  405. return -1;
  406. cmd->size = cpu_to_le16(ie_size);
  407. break;
  408. default:
  409. return -1;
  410. }
  411. return 0;
  412. }
  413. /* This function prepares the AP specific commands before sending them
  414. * to the firmware.
  415. * This is a generic function which calls specific command preparation
  416. * routines based upon the command number.
  417. */
  418. int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, u16 cmd_no,
  419. u16 cmd_action, u32 type,
  420. void *data_buf, void *cmd_buf)
  421. {
  422. struct host_cmd_ds_command *cmd = cmd_buf;
  423. switch (cmd_no) {
  424. case HostCmd_CMD_UAP_SYS_CONFIG:
  425. if (mwifiex_cmd_uap_sys_config(cmd, cmd_action, type, data_buf))
  426. return -1;
  427. break;
  428. case HostCmd_CMD_UAP_BSS_START:
  429. case HostCmd_CMD_UAP_BSS_STOP:
  430. cmd->command = cpu_to_le16(cmd_no);
  431. cmd->size = cpu_to_le16(S_DS_GEN);
  432. break;
  433. default:
  434. dev_err(priv->adapter->dev,
  435. "PREP_CMD: unknown cmd %#x\n", cmd_no);
  436. return -1;
  437. }
  438. return 0;
  439. }