wl1271_cmd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009-2010 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/crc7.h>
  26. #include <linux/spi/spi.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/ieee80211.h>
  29. #include <linux/slab.h>
  30. #include "wl1271.h"
  31. #include "wl1271_reg.h"
  32. #include "wl1271_io.h"
  33. #include "wl1271_acx.h"
  34. #include "wl12xx_80211.h"
  35. #include "wl1271_cmd.h"
  36. #include "wl1271_event.h"
  37. #define WL1271_CMD_FAST_POLL_COUNT 50
  38. /*
  39. * send command to firmware
  40. *
  41. * @wl: wl struct
  42. * @id: command id
  43. * @buf: buffer containing the command, must work with dma
  44. * @len: length of the buffer
  45. */
  46. int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
  47. size_t res_len)
  48. {
  49. struct wl1271_cmd_header *cmd;
  50. unsigned long timeout;
  51. u32 intr;
  52. int ret = 0;
  53. u16 status;
  54. u16 poll_count = 0;
  55. cmd = buf;
  56. cmd->id = cpu_to_le16(id);
  57. cmd->status = 0;
  58. WARN_ON(len % 4 != 0);
  59. wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
  60. wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
  61. timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
  62. intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
  63. while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
  64. if (time_after(jiffies, timeout)) {
  65. wl1271_error("command complete timeout");
  66. ret = -ETIMEDOUT;
  67. goto out;
  68. }
  69. poll_count++;
  70. if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
  71. udelay(10);
  72. else
  73. msleep(1);
  74. intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
  75. }
  76. /* read back the status code of the command */
  77. if (res_len == 0)
  78. res_len = sizeof(struct wl1271_cmd_header);
  79. wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
  80. status = le16_to_cpu(cmd->status);
  81. if (status != CMD_STATUS_SUCCESS) {
  82. wl1271_error("command execute failure %d", status);
  83. ieee80211_queue_work(wl->hw, &wl->recovery_work);
  84. ret = -EIO;
  85. }
  86. wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
  87. WL1271_ACX_INTR_CMD_COMPLETE);
  88. out:
  89. return ret;
  90. }
  91. int wl1271_cmd_general_parms(struct wl1271 *wl)
  92. {
  93. struct wl1271_general_parms_cmd *gen_parms;
  94. int ret;
  95. if (!wl->nvs)
  96. return -ENODEV;
  97. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  98. if (!gen_parms)
  99. return -ENOMEM;
  100. gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  101. memcpy(&gen_parms->general_params, &wl->nvs->general_params,
  102. sizeof(struct wl1271_ini_general_params));
  103. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
  104. if (ret < 0)
  105. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  106. kfree(gen_parms);
  107. return ret;
  108. }
  109. int wl1271_cmd_radio_parms(struct wl1271 *wl)
  110. {
  111. struct wl1271_radio_parms_cmd *radio_parms;
  112. struct wl1271_ini_general_params *gp = &wl->nvs->general_params;
  113. int ret;
  114. if (!wl->nvs)
  115. return -ENODEV;
  116. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  117. if (!radio_parms)
  118. return -ENOMEM;
  119. radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
  120. /* 2.4GHz parameters */
  121. memcpy(&radio_parms->static_params_2, &wl->nvs->stat_radio_params_2,
  122. sizeof(struct wl1271_ini_band_params_2));
  123. memcpy(&radio_parms->dyn_params_2,
  124. &wl->nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
  125. sizeof(struct wl1271_ini_fem_params_2));
  126. /* 5GHz parameters */
  127. memcpy(&radio_parms->static_params_5,
  128. &wl->nvs->stat_radio_params_5,
  129. sizeof(struct wl1271_ini_band_params_5));
  130. memcpy(&radio_parms->dyn_params_5,
  131. &wl->nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
  132. sizeof(struct wl1271_ini_fem_params_5));
  133. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
  134. radio_parms, sizeof(*radio_parms));
  135. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  136. if (ret < 0)
  137. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  138. kfree(radio_parms);
  139. return ret;
  140. }
  141. /*
  142. * Poll the mailbox event field until any of the bits in the mask is set or a
  143. * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
  144. */
  145. static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
  146. {
  147. u32 events_vector, event;
  148. unsigned long timeout;
  149. timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
  150. do {
  151. if (time_after(jiffies, timeout)) {
  152. ieee80211_queue_work(wl->hw, &wl->recovery_work);
  153. return -ETIMEDOUT;
  154. }
  155. msleep(1);
  156. /* read from both event fields */
  157. wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
  158. sizeof(events_vector), false);
  159. event = events_vector & mask;
  160. wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
  161. sizeof(events_vector), false);
  162. event |= events_vector & mask;
  163. } while (!event);
  164. return 0;
  165. }
  166. int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
  167. {
  168. struct wl1271_cmd_join *join;
  169. int ret, i;
  170. u8 *bssid;
  171. join = kzalloc(sizeof(*join), GFP_KERNEL);
  172. if (!join) {
  173. ret = -ENOMEM;
  174. goto out;
  175. }
  176. wl1271_debug(DEBUG_CMD, "cmd join");
  177. /* Reverse order BSSID */
  178. bssid = (u8 *) &join->bssid_lsb;
  179. for (i = 0; i < ETH_ALEN; i++)
  180. bssid[i] = wl->bssid[ETH_ALEN - i - 1];
  181. join->rx_config_options = cpu_to_le32(wl->rx_config);
  182. join->rx_filter_options = cpu_to_le32(wl->rx_filter);
  183. join->bss_type = bss_type;
  184. join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
  185. if (wl->band == IEEE80211_BAND_5GHZ)
  186. join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
  187. join->beacon_interval = cpu_to_le16(wl->beacon_int);
  188. join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
  189. join->channel = wl->channel;
  190. join->ssid_len = wl->ssid_len;
  191. memcpy(join->ssid, wl->ssid, wl->ssid_len);
  192. join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
  193. /* reset TX security counters */
  194. wl->tx_security_last_seq = 0;
  195. wl->tx_security_seq = 0;
  196. ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
  197. if (ret < 0) {
  198. wl1271_error("failed to initiate cmd join");
  199. goto out_free;
  200. }
  201. ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
  202. if (ret < 0)
  203. wl1271_error("cmd join event completion error");
  204. out_free:
  205. kfree(join);
  206. out:
  207. return ret;
  208. }
  209. /**
  210. * send test command to firmware
  211. *
  212. * @wl: wl struct
  213. * @buf: buffer containing the command, with all headers, must work with dma
  214. * @len: length of the buffer
  215. * @answer: is answer needed
  216. */
  217. int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
  218. {
  219. int ret;
  220. size_t res_len = 0;
  221. wl1271_debug(DEBUG_CMD, "cmd test");
  222. if (answer)
  223. res_len = buf_len;
  224. ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
  225. if (ret < 0) {
  226. wl1271_warning("TEST command failed");
  227. return ret;
  228. }
  229. return ret;
  230. }
  231. /**
  232. * read acx from firmware
  233. *
  234. * @wl: wl struct
  235. * @id: acx id
  236. * @buf: buffer for the response, including all headers, must work with dma
  237. * @len: lenght of buf
  238. */
  239. int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
  240. {
  241. struct acx_header *acx = buf;
  242. int ret;
  243. wl1271_debug(DEBUG_CMD, "cmd interrogate");
  244. acx->id = cpu_to_le16(id);
  245. /* payload length, does not include any headers */
  246. acx->len = cpu_to_le16(len - sizeof(*acx));
  247. ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
  248. if (ret < 0)
  249. wl1271_error("INTERROGATE command failed");
  250. return ret;
  251. }
  252. /**
  253. * write acx value to firmware
  254. *
  255. * @wl: wl struct
  256. * @id: acx id
  257. * @buf: buffer containing acx, including all headers, must work with dma
  258. * @len: length of buf
  259. */
  260. int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
  261. {
  262. struct acx_header *acx = buf;
  263. int ret;
  264. wl1271_debug(DEBUG_CMD, "cmd configure");
  265. acx->id = cpu_to_le16(id);
  266. /* payload length, does not include any headers */
  267. acx->len = cpu_to_le16(len - sizeof(*acx));
  268. ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
  269. if (ret < 0) {
  270. wl1271_warning("CONFIGURE command NOK");
  271. return ret;
  272. }
  273. return 0;
  274. }
  275. int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
  276. {
  277. struct cmd_enabledisable_path *cmd;
  278. int ret;
  279. u16 cmd_rx, cmd_tx;
  280. wl1271_debug(DEBUG_CMD, "cmd data path");
  281. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  282. if (!cmd) {
  283. ret = -ENOMEM;
  284. goto out;
  285. }
  286. /* the channel here is only used for calibration, so hardcoded to 1 */
  287. cmd->channel = 1;
  288. if (enable) {
  289. cmd_rx = CMD_ENABLE_RX;
  290. cmd_tx = CMD_ENABLE_TX;
  291. } else {
  292. cmd_rx = CMD_DISABLE_RX;
  293. cmd_tx = CMD_DISABLE_TX;
  294. }
  295. ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
  296. if (ret < 0) {
  297. wl1271_error("rx %s cmd for channel %d failed",
  298. enable ? "start" : "stop", cmd->channel);
  299. goto out;
  300. }
  301. wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
  302. enable ? "start" : "stop", cmd->channel);
  303. ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
  304. if (ret < 0) {
  305. wl1271_error("tx %s cmd for channel %d failed",
  306. enable ? "start" : "stop", cmd->channel);
  307. goto out;
  308. }
  309. wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
  310. enable ? "start" : "stop", cmd->channel);
  311. out:
  312. kfree(cmd);
  313. return ret;
  314. }
  315. int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, u32 rates, bool send)
  316. {
  317. struct wl1271_cmd_ps_params *ps_params = NULL;
  318. int ret = 0;
  319. wl1271_debug(DEBUG_CMD, "cmd set ps mode");
  320. ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
  321. if (!ps_params) {
  322. ret = -ENOMEM;
  323. goto out;
  324. }
  325. ps_params->ps_mode = ps_mode;
  326. ps_params->send_null_data = send;
  327. ps_params->retries = 5;
  328. ps_params->hang_over_period = 1;
  329. ps_params->null_data_rate = cpu_to_le32(rates);
  330. ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
  331. sizeof(*ps_params), 0);
  332. if (ret < 0) {
  333. wl1271_error("cmd set_ps_mode failed");
  334. goto out;
  335. }
  336. out:
  337. kfree(ps_params);
  338. return ret;
  339. }
  340. int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
  341. void *buf, size_t buf_len, int index, u32 rates)
  342. {
  343. struct wl1271_cmd_template_set *cmd;
  344. int ret = 0;
  345. wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
  346. WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
  347. buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
  348. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  349. if (!cmd) {
  350. ret = -ENOMEM;
  351. goto out;
  352. }
  353. cmd->len = cpu_to_le16(buf_len);
  354. cmd->template_type = template_id;
  355. cmd->enabled_rates = cpu_to_le32(rates);
  356. cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit;
  357. cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit;
  358. cmd->index = index;
  359. if (buf)
  360. memcpy(cmd->template_data, buf, buf_len);
  361. ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
  362. if (ret < 0) {
  363. wl1271_warning("cmd set_template failed: %d", ret);
  364. goto out_free;
  365. }
  366. out_free:
  367. kfree(cmd);
  368. out:
  369. return ret;
  370. }
  371. int wl1271_cmd_build_null_data(struct wl1271 *wl)
  372. {
  373. struct sk_buff *skb = NULL;
  374. int size;
  375. void *ptr;
  376. int ret = -ENOMEM;
  377. if (wl->bss_type == BSS_TYPE_IBSS) {
  378. size = sizeof(struct wl12xx_null_data_template);
  379. ptr = NULL;
  380. } else {
  381. skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
  382. if (!skb)
  383. goto out;
  384. size = skb->len;
  385. ptr = skb->data;
  386. }
  387. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
  388. WL1271_RATE_AUTOMATIC);
  389. out:
  390. dev_kfree_skb(skb);
  391. if (ret)
  392. wl1271_warning("cmd buld null data failed %d", ret);
  393. return ret;
  394. }
  395. int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
  396. {
  397. struct sk_buff *skb = NULL;
  398. int ret = -ENOMEM;
  399. skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
  400. if (!skb)
  401. goto out;
  402. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
  403. skb->data, skb->len,
  404. CMD_TEMPL_KLV_IDX_NULL_DATA,
  405. WL1271_RATE_AUTOMATIC);
  406. out:
  407. dev_kfree_skb(skb);
  408. if (ret)
  409. wl1271_warning("cmd build klv null data failed %d", ret);
  410. return ret;
  411. }
  412. int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
  413. {
  414. struct sk_buff *skb;
  415. int ret = 0;
  416. skb = ieee80211_pspoll_get(wl->hw, wl->vif);
  417. if (!skb)
  418. goto out;
  419. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
  420. skb->len, 0, wl->basic_rate_set);
  421. out:
  422. dev_kfree_skb(skb);
  423. return ret;
  424. }
  425. int wl1271_cmd_build_probe_req(struct wl1271 *wl,
  426. const u8 *ssid, size_t ssid_len,
  427. const u8 *ie, size_t ie_len, u8 band)
  428. {
  429. struct sk_buff *skb;
  430. int ret;
  431. skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
  432. ie, ie_len);
  433. if (!skb) {
  434. ret = -ENOMEM;
  435. goto out;
  436. }
  437. wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
  438. if (band == IEEE80211_BAND_2GHZ)
  439. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
  440. skb->data, skb->len, 0,
  441. wl->conf.tx.basic_rate);
  442. else
  443. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  444. skb->data, skb->len, 0,
  445. wl->conf.tx.basic_rate_5);
  446. out:
  447. dev_kfree_skb(skb);
  448. return ret;
  449. }
  450. int wl1271_build_qos_null_data(struct wl1271 *wl)
  451. {
  452. struct ieee80211_qos_hdr template;
  453. memset(&template, 0, sizeof(template));
  454. memcpy(template.addr1, wl->bssid, ETH_ALEN);
  455. memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
  456. memcpy(template.addr3, wl->bssid, ETH_ALEN);
  457. template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  458. IEEE80211_STYPE_QOS_NULLFUNC |
  459. IEEE80211_FCTL_TODS);
  460. /* FIXME: not sure what priority to use here */
  461. template.qos_ctrl = cpu_to_le16(0);
  462. return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
  463. sizeof(template), 0,
  464. WL1271_RATE_AUTOMATIC);
  465. }
  466. int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
  467. {
  468. struct wl1271_cmd_set_keys *cmd;
  469. int ret = 0;
  470. wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
  471. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  472. if (!cmd) {
  473. ret = -ENOMEM;
  474. goto out;
  475. }
  476. cmd->id = id;
  477. cmd->key_action = cpu_to_le16(KEY_SET_ID);
  478. cmd->key_type = KEY_WEP;
  479. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  480. if (ret < 0) {
  481. wl1271_warning("cmd set_default_wep_key failed: %d", ret);
  482. goto out;
  483. }
  484. out:
  485. kfree(cmd);
  486. return ret;
  487. }
  488. int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
  489. u8 key_size, const u8 *key, const u8 *addr,
  490. u32 tx_seq_32, u16 tx_seq_16)
  491. {
  492. struct wl1271_cmd_set_keys *cmd;
  493. int ret = 0;
  494. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  495. if (!cmd) {
  496. ret = -ENOMEM;
  497. goto out;
  498. }
  499. if (key_type != KEY_WEP)
  500. memcpy(cmd->addr, addr, ETH_ALEN);
  501. cmd->key_action = cpu_to_le16(action);
  502. cmd->key_size = key_size;
  503. cmd->key_type = key_type;
  504. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  505. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  506. /* we have only one SSID profile */
  507. cmd->ssid_profile = 0;
  508. cmd->id = id;
  509. if (key_type == KEY_TKIP) {
  510. /*
  511. * We get the key in the following form:
  512. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  513. * but the target is expecting:
  514. * TKIP - RX MIC - TX MIC
  515. */
  516. memcpy(cmd->key, key, 16);
  517. memcpy(cmd->key + 16, key + 24, 8);
  518. memcpy(cmd->key + 24, key + 16, 8);
  519. } else {
  520. memcpy(cmd->key, key, key_size);
  521. }
  522. wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
  523. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  524. if (ret < 0) {
  525. wl1271_warning("could not set keys");
  526. goto out;
  527. }
  528. out:
  529. kfree(cmd);
  530. return ret;
  531. }
  532. int wl1271_cmd_disconnect(struct wl1271 *wl)
  533. {
  534. struct wl1271_cmd_disconnect *cmd;
  535. int ret = 0;
  536. wl1271_debug(DEBUG_CMD, "cmd disconnect");
  537. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  538. if (!cmd) {
  539. ret = -ENOMEM;
  540. goto out;
  541. }
  542. cmd->rx_config_options = cpu_to_le32(wl->rx_config);
  543. cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
  544. /* disconnect reason is not used in immediate disconnections */
  545. cmd->type = DISCONNECT_IMMEDIATE;
  546. ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
  547. if (ret < 0) {
  548. wl1271_error("failed to send disconnect command");
  549. goto out_free;
  550. }
  551. ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
  552. if (ret < 0)
  553. wl1271_error("cmd disconnect event completion error");
  554. out_free:
  555. kfree(cmd);
  556. out:
  557. return ret;
  558. }
  559. int wl1271_cmd_set_sta_state(struct wl1271 *wl)
  560. {
  561. struct wl1271_cmd_set_sta_state *cmd;
  562. int ret = 0;
  563. wl1271_debug(DEBUG_CMD, "cmd set sta state");
  564. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  565. if (!cmd) {
  566. ret = -ENOMEM;
  567. goto out;
  568. }
  569. cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
  570. ret = wl1271_cmd_send(wl, CMD_SET_STA_STATE, cmd, sizeof(*cmd), 0);
  571. if (ret < 0) {
  572. wl1271_error("failed to send set STA state command");
  573. goto out_free;
  574. }
  575. out_free:
  576. kfree(cmd);
  577. out:
  578. return ret;
  579. }