cmd.c 19 KB

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