wl1271_cmd.c 17 KB

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