wl1271_cmd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. ret = -EIO;
  84. }
  85. wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
  86. WL1271_ACX_INTR_CMD_COMPLETE);
  87. out:
  88. return ret;
  89. }
  90. int wl1271_cmd_general_parms(struct wl1271 *wl)
  91. {
  92. struct wl1271_general_parms_cmd *gen_parms;
  93. int ret;
  94. if (!wl->nvs)
  95. return -ENODEV;
  96. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  97. if (!gen_parms)
  98. return -ENOMEM;
  99. gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  100. memcpy(&gen_parms->general_params, &wl->nvs->general_params,
  101. sizeof(struct wl1271_ini_general_params));
  102. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
  103. if (ret < 0)
  104. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  105. kfree(gen_parms);
  106. return ret;
  107. }
  108. int wl1271_cmd_radio_parms(struct wl1271 *wl)
  109. {
  110. struct wl1271_radio_parms_cmd *radio_parms;
  111. struct wl1271_ini_general_params *gp = &wl->nvs->general_params;
  112. int ret;
  113. if (!wl->nvs)
  114. return -ENODEV;
  115. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  116. if (!radio_parms)
  117. return -ENOMEM;
  118. radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
  119. /* 2.4GHz parameters */
  120. memcpy(&radio_parms->static_params_2, &wl->nvs->stat_radio_params_2,
  121. sizeof(struct wl1271_ini_band_params_2));
  122. memcpy(&radio_parms->dyn_params_2,
  123. &wl->nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
  124. sizeof(struct wl1271_ini_fem_params_2));
  125. /* 5GHz parameters */
  126. memcpy(&radio_parms->static_params_5,
  127. &wl->nvs->stat_radio_params_5,
  128. sizeof(struct wl1271_ini_band_params_5));
  129. memcpy(&radio_parms->dyn_params_5,
  130. &wl->nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
  131. sizeof(struct wl1271_ini_fem_params_5));
  132. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
  133. radio_parms, sizeof(*radio_parms));
  134. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  135. if (ret < 0)
  136. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  137. kfree(radio_parms);
  138. return ret;
  139. }
  140. /*
  141. * Poll the mailbox event field until any of the bits in the mask is set or a
  142. * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
  143. */
  144. static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
  145. {
  146. u32 events_vector, event;
  147. unsigned long timeout;
  148. timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
  149. do {
  150. if (time_after(jiffies, timeout))
  151. return -ETIMEDOUT;
  152. msleep(1);
  153. /* read from both event fields */
  154. wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
  155. sizeof(events_vector), false);
  156. event = events_vector & mask;
  157. wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
  158. sizeof(events_vector), false);
  159. event |= events_vector & mask;
  160. } while (!event);
  161. return 0;
  162. }
  163. int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
  164. {
  165. struct wl1271_cmd_join *join;
  166. int ret, i;
  167. u8 *bssid;
  168. join = kzalloc(sizeof(*join), GFP_KERNEL);
  169. if (!join) {
  170. ret = -ENOMEM;
  171. goto out;
  172. }
  173. wl1271_debug(DEBUG_CMD, "cmd join");
  174. /* Reverse order BSSID */
  175. bssid = (u8 *) &join->bssid_lsb;
  176. for (i = 0; i < ETH_ALEN; i++)
  177. bssid[i] = wl->bssid[ETH_ALEN - i - 1];
  178. join->rx_config_options = cpu_to_le32(wl->rx_config);
  179. join->rx_filter_options = cpu_to_le32(wl->rx_filter);
  180. join->bss_type = bss_type;
  181. join->basic_rate_set = cpu_to_le32(wl->basic_rate_set);
  182. if (wl->band == IEEE80211_BAND_5GHZ)
  183. join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
  184. join->beacon_interval = cpu_to_le16(wl->beacon_int);
  185. join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
  186. join->channel = wl->channel;
  187. join->ssid_len = wl->ssid_len;
  188. memcpy(join->ssid, wl->ssid, wl->ssid_len);
  189. join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
  190. /* reset TX security counters */
  191. wl->tx_security_last_seq = 0;
  192. wl->tx_security_seq = 0;
  193. ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
  194. if (ret < 0) {
  195. wl1271_error("failed to initiate cmd join");
  196. goto out_free;
  197. }
  198. ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
  199. if (ret < 0)
  200. wl1271_error("cmd join event completion error");
  201. out_free:
  202. kfree(join);
  203. out:
  204. return ret;
  205. }
  206. /**
  207. * send test command to firmware
  208. *
  209. * @wl: wl struct
  210. * @buf: buffer containing the command, with all headers, must work with dma
  211. * @len: length of the buffer
  212. * @answer: is answer needed
  213. */
  214. int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
  215. {
  216. int ret;
  217. size_t res_len = 0;
  218. wl1271_debug(DEBUG_CMD, "cmd test");
  219. if (answer)
  220. res_len = buf_len;
  221. ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
  222. if (ret < 0) {
  223. wl1271_warning("TEST command failed");
  224. return ret;
  225. }
  226. return ret;
  227. }
  228. /**
  229. * read acx from firmware
  230. *
  231. * @wl: wl struct
  232. * @id: acx id
  233. * @buf: buffer for the response, including all headers, must work with dma
  234. * @len: lenght of buf
  235. */
  236. int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
  237. {
  238. struct acx_header *acx = buf;
  239. int ret;
  240. wl1271_debug(DEBUG_CMD, "cmd interrogate");
  241. acx->id = cpu_to_le16(id);
  242. /* payload length, does not include any headers */
  243. acx->len = cpu_to_le16(len - sizeof(*acx));
  244. ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
  245. if (ret < 0)
  246. wl1271_error("INTERROGATE command failed");
  247. return ret;
  248. }
  249. /**
  250. * write acx value to firmware
  251. *
  252. * @wl: wl struct
  253. * @id: acx id
  254. * @buf: buffer containing acx, including all headers, must work with dma
  255. * @len: length of buf
  256. */
  257. int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
  258. {
  259. struct acx_header *acx = buf;
  260. int ret;
  261. wl1271_debug(DEBUG_CMD, "cmd configure");
  262. acx->id = cpu_to_le16(id);
  263. /* payload length, does not include any headers */
  264. acx->len = cpu_to_le16(len - sizeof(*acx));
  265. ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
  266. if (ret < 0) {
  267. wl1271_warning("CONFIGURE command NOK");
  268. return ret;
  269. }
  270. return 0;
  271. }
  272. int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
  273. {
  274. struct cmd_enabledisable_path *cmd;
  275. int ret;
  276. u16 cmd_rx, cmd_tx;
  277. wl1271_debug(DEBUG_CMD, "cmd data path");
  278. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  279. if (!cmd) {
  280. ret = -ENOMEM;
  281. goto out;
  282. }
  283. /* the channel here is only used for calibration, so hardcoded to 1 */
  284. cmd->channel = 1;
  285. if (enable) {
  286. cmd_rx = CMD_ENABLE_RX;
  287. cmd_tx = CMD_ENABLE_TX;
  288. } else {
  289. cmd_rx = CMD_DISABLE_RX;
  290. cmd_tx = CMD_DISABLE_TX;
  291. }
  292. ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
  293. if (ret < 0) {
  294. wl1271_error("rx %s cmd for channel %d failed",
  295. enable ? "start" : "stop", cmd->channel);
  296. goto out;
  297. }
  298. wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
  299. enable ? "start" : "stop", cmd->channel);
  300. ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
  301. if (ret < 0) {
  302. wl1271_error("tx %s cmd for channel %d failed",
  303. enable ? "start" : "stop", cmd->channel);
  304. goto out;
  305. }
  306. wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
  307. enable ? "start" : "stop", cmd->channel);
  308. out:
  309. kfree(cmd);
  310. return ret;
  311. }
  312. int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send)
  313. {
  314. struct wl1271_cmd_ps_params *ps_params = NULL;
  315. int ret = 0;
  316. /* FIXME: this should be in ps.c */
  317. ret = wl1271_acx_wake_up_conditions(wl);
  318. if (ret < 0) {
  319. wl1271_error("couldn't set wake up conditions");
  320. goto out;
  321. }
  322. wl1271_debug(DEBUG_CMD, "cmd set ps mode");
  323. ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
  324. if (!ps_params) {
  325. ret = -ENOMEM;
  326. goto out;
  327. }
  328. ps_params->ps_mode = ps_mode;
  329. ps_params->send_null_data = send;
  330. ps_params->retries = 5;
  331. ps_params->hang_over_period = 1;
  332. ps_params->null_data_rate = cpu_to_le32(wl->basic_rate_set);
  333. ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
  334. sizeof(*ps_params), 0);
  335. if (ret < 0) {
  336. wl1271_error("cmd set_ps_mode failed");
  337. goto out;
  338. }
  339. out:
  340. kfree(ps_params);
  341. return ret;
  342. }
  343. int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
  344. size_t len)
  345. {
  346. struct cmd_read_write_memory *cmd;
  347. int ret = 0;
  348. wl1271_debug(DEBUG_CMD, "cmd read memory");
  349. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  350. if (!cmd) {
  351. ret = -ENOMEM;
  352. goto out;
  353. }
  354. WARN_ON(len > MAX_READ_SIZE);
  355. len = min_t(size_t, len, MAX_READ_SIZE);
  356. cmd->addr = cpu_to_le32(addr);
  357. cmd->size = cpu_to_le32(len);
  358. ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
  359. sizeof(*cmd));
  360. if (ret < 0) {
  361. wl1271_error("read memory command failed: %d", ret);
  362. goto out;
  363. }
  364. /* the read command got in */
  365. memcpy(answer, cmd->value, len);
  366. out:
  367. kfree(cmd);
  368. return ret;
  369. }
  370. int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
  371. void *buf, size_t buf_len, int index, u32 rates)
  372. {
  373. struct wl1271_cmd_template_set *cmd;
  374. int ret = 0;
  375. wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
  376. WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
  377. buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
  378. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  379. if (!cmd) {
  380. ret = -ENOMEM;
  381. goto out;
  382. }
  383. cmd->len = cpu_to_le16(buf_len);
  384. cmd->template_type = template_id;
  385. cmd->enabled_rates = cpu_to_le32(rates);
  386. cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit;
  387. cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit;
  388. cmd->index = index;
  389. if (buf)
  390. memcpy(cmd->template_data, buf, buf_len);
  391. ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
  392. if (ret < 0) {
  393. wl1271_warning("cmd set_template failed: %d", ret);
  394. goto out_free;
  395. }
  396. out_free:
  397. kfree(cmd);
  398. out:
  399. return ret;
  400. }
  401. int wl1271_cmd_build_null_data(struct wl1271 *wl)
  402. {
  403. struct sk_buff *skb = NULL;
  404. int size;
  405. void *ptr;
  406. int ret = -ENOMEM;
  407. if (wl->bss_type == BSS_TYPE_IBSS) {
  408. size = sizeof(struct wl12xx_null_data_template);
  409. ptr = NULL;
  410. } else {
  411. skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
  412. if (!skb)
  413. goto out;
  414. size = skb->len;
  415. ptr = skb->data;
  416. }
  417. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
  418. WL1271_RATE_AUTOMATIC);
  419. out:
  420. dev_kfree_skb(skb);
  421. if (ret)
  422. wl1271_warning("cmd buld null data failed %d", ret);
  423. return ret;
  424. }
  425. int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
  426. {
  427. struct sk_buff *skb = NULL;
  428. int ret = -ENOMEM;
  429. skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
  430. if (!skb)
  431. goto out;
  432. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
  433. skb->data, skb->len,
  434. CMD_TEMPL_KLV_IDX_NULL_DATA,
  435. WL1271_RATE_AUTOMATIC);
  436. out:
  437. dev_kfree_skb(skb);
  438. if (ret)
  439. wl1271_warning("cmd build klv null data failed %d", ret);
  440. return ret;
  441. }
  442. int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
  443. {
  444. struct sk_buff *skb;
  445. int ret = 0;
  446. skb = ieee80211_pspoll_get(wl->hw, wl->vif);
  447. if (!skb)
  448. goto out;
  449. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
  450. skb->len, 0, wl->basic_rate_set);
  451. out:
  452. dev_kfree_skb(skb);
  453. return ret;
  454. }
  455. int wl1271_cmd_build_probe_req(struct wl1271 *wl,
  456. const u8 *ssid, size_t ssid_len,
  457. const u8 *ie, size_t ie_len, u8 band)
  458. {
  459. struct sk_buff *skb;
  460. int ret;
  461. skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
  462. ie, ie_len);
  463. if (!skb) {
  464. ret = -ENOMEM;
  465. goto out;
  466. }
  467. wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
  468. if (band == IEEE80211_BAND_2GHZ)
  469. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
  470. skb->data, skb->len, 0,
  471. wl->conf.tx.basic_rate);
  472. else
  473. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  474. skb->data, skb->len, 0,
  475. wl->conf.tx.basic_rate_5);
  476. out:
  477. dev_kfree_skb(skb);
  478. return ret;
  479. }
  480. int wl1271_build_qos_null_data(struct wl1271 *wl)
  481. {
  482. struct ieee80211_qos_hdr template;
  483. memset(&template, 0, sizeof(template));
  484. memcpy(template.addr1, wl->bssid, ETH_ALEN);
  485. memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
  486. memcpy(template.addr3, wl->bssid, ETH_ALEN);
  487. template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  488. IEEE80211_STYPE_QOS_NULLFUNC |
  489. IEEE80211_FCTL_TODS);
  490. /* FIXME: not sure what priority to use here */
  491. template.qos_ctrl = cpu_to_le16(0);
  492. return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
  493. sizeof(template), 0,
  494. WL1271_RATE_AUTOMATIC);
  495. }
  496. int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
  497. {
  498. struct wl1271_cmd_set_keys *cmd;
  499. int ret = 0;
  500. wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
  501. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  502. if (!cmd) {
  503. ret = -ENOMEM;
  504. goto out;
  505. }
  506. cmd->id = id;
  507. cmd->key_action = cpu_to_le16(KEY_SET_ID);
  508. cmd->key_type = KEY_WEP;
  509. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  510. if (ret < 0) {
  511. wl1271_warning("cmd set_default_wep_key failed: %d", ret);
  512. goto out;
  513. }
  514. out:
  515. kfree(cmd);
  516. return ret;
  517. }
  518. int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
  519. u8 key_size, const u8 *key, const u8 *addr,
  520. u32 tx_seq_32, u16 tx_seq_16)
  521. {
  522. struct wl1271_cmd_set_keys *cmd;
  523. int ret = 0;
  524. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  525. if (!cmd) {
  526. ret = -ENOMEM;
  527. goto out;
  528. }
  529. if (key_type != KEY_WEP)
  530. memcpy(cmd->addr, addr, ETH_ALEN);
  531. cmd->key_action = cpu_to_le16(action);
  532. cmd->key_size = key_size;
  533. cmd->key_type = key_type;
  534. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  535. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  536. /* we have only one SSID profile */
  537. cmd->ssid_profile = 0;
  538. cmd->id = id;
  539. if (key_type == KEY_TKIP) {
  540. /*
  541. * We get the key in the following form:
  542. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  543. * but the target is expecting:
  544. * TKIP - RX MIC - TX MIC
  545. */
  546. memcpy(cmd->key, key, 16);
  547. memcpy(cmd->key + 16, key + 24, 8);
  548. memcpy(cmd->key + 24, key + 16, 8);
  549. } else {
  550. memcpy(cmd->key, key, key_size);
  551. }
  552. wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
  553. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  554. if (ret < 0) {
  555. wl1271_warning("could not set keys");
  556. goto out;
  557. }
  558. out:
  559. kfree(cmd);
  560. return ret;
  561. }
  562. int wl1271_cmd_disconnect(struct wl1271 *wl)
  563. {
  564. struct wl1271_cmd_disconnect *cmd;
  565. int ret = 0;
  566. wl1271_debug(DEBUG_CMD, "cmd disconnect");
  567. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  568. if (!cmd) {
  569. ret = -ENOMEM;
  570. goto out;
  571. }
  572. cmd->rx_config_options = cpu_to_le32(wl->rx_config);
  573. cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
  574. /* disconnect reason is not used in immediate disconnections */
  575. cmd->type = DISCONNECT_IMMEDIATE;
  576. ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
  577. if (ret < 0) {
  578. wl1271_error("failed to send disconnect command");
  579. goto out_free;
  580. }
  581. ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
  582. if (ret < 0)
  583. wl1271_error("cmd disconnect event completion error");
  584. out_free:
  585. kfree(cmd);
  586. out:
  587. return ret;
  588. }