cmd.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001
  1. /**
  2. * This file contains the handling of command.
  3. * It prepares command and sends it to firmware when it is ready.
  4. */
  5. #include <net/iw_handler.h>
  6. #include "host.h"
  7. #include "hostcmd.h"
  8. #include "decl.h"
  9. #include "defs.h"
  10. #include "dev.h"
  11. #include "assoc.h"
  12. #include "wext.h"
  13. #include "cmd.h"
  14. static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
  15. /**
  16. * @brief Simple callback that copies response back into command
  17. *
  18. * @param priv A pointer to struct lbs_private structure
  19. * @param extra A pointer to the original command structure for which
  20. * 'resp' is a response
  21. * @param resp A pointer to the command response
  22. *
  23. * @return 0 on success, error on failure
  24. */
  25. int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
  26. struct cmd_header *resp)
  27. {
  28. struct cmd_header *buf = (void *)extra;
  29. uint16_t copy_len;
  30. copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
  31. memcpy(buf, resp, copy_len);
  32. return 0;
  33. }
  34. EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
  35. /**
  36. * @brief Simple callback that ignores the result. Use this if
  37. * you just want to send a command to the hardware, but don't
  38. * care for the result.
  39. *
  40. * @param priv ignored
  41. * @param extra ignored
  42. * @param resp ignored
  43. *
  44. * @return 0 for success
  45. */
  46. static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
  47. struct cmd_header *resp)
  48. {
  49. return 0;
  50. }
  51. /**
  52. * @brief Checks whether a command is allowed in Power Save mode
  53. *
  54. * @param command the command ID
  55. * @return 1 if allowed, 0 if not allowed
  56. */
  57. static u8 is_command_allowed_in_ps(u16 cmd)
  58. {
  59. switch (cmd) {
  60. case CMD_802_11_RSSI:
  61. return 1;
  62. default:
  63. break;
  64. }
  65. return 0;
  66. }
  67. /**
  68. * @brief Updates the hardware details like MAC address and regulatory region
  69. *
  70. * @param priv A pointer to struct lbs_private structure
  71. *
  72. * @return 0 on success, error on failure
  73. */
  74. int lbs_update_hw_spec(struct lbs_private *priv)
  75. {
  76. struct cmd_ds_get_hw_spec cmd;
  77. int ret = -1;
  78. u32 i;
  79. DECLARE_MAC_BUF(mac);
  80. lbs_deb_enter(LBS_DEB_CMD);
  81. memset(&cmd, 0, sizeof(cmd));
  82. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  83. memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
  84. ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
  85. if (ret)
  86. goto out;
  87. priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
  88. /* The firmware release is in an interesting format: the patch
  89. * level is in the most significant nibble ... so fix that: */
  90. priv->fwrelease = le32_to_cpu(cmd.fwrelease);
  91. priv->fwrelease = (priv->fwrelease << 8) |
  92. (priv->fwrelease >> 24 & 0xff);
  93. /* Some firmware capabilities:
  94. * CF card firmware 5.0.16p0: cap 0x00000303
  95. * USB dongle firmware 5.110.17p2: cap 0x00000303
  96. */
  97. printk("libertas: %s, fw %u.%u.%up%u, cap 0x%08x\n",
  98. print_mac(mac, cmd.permanentaddr),
  99. priv->fwrelease >> 24 & 0xff,
  100. priv->fwrelease >> 16 & 0xff,
  101. priv->fwrelease >> 8 & 0xff,
  102. priv->fwrelease & 0xff,
  103. priv->fwcapinfo);
  104. lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
  105. cmd.hwifversion, cmd.version);
  106. /* Clamp region code to 8-bit since FW spec indicates that it should
  107. * only ever be 8-bit, even though the field size is 16-bit. Some firmware
  108. * returns non-zero high 8 bits here.
  109. */
  110. priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
  111. for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
  112. /* use the region code to search for the index */
  113. if (priv->regioncode == lbs_region_code_to_index[i])
  114. break;
  115. }
  116. /* if it's unidentified region code, use the default (USA) */
  117. if (i >= MRVDRV_MAX_REGION_CODE) {
  118. priv->regioncode = 0x10;
  119. lbs_pr_info("unidentified region code; using the default (USA)\n");
  120. }
  121. if (priv->current_addr[0] == 0xff)
  122. memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
  123. memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
  124. if (priv->mesh_dev)
  125. memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
  126. if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
  127. ret = -1;
  128. goto out;
  129. }
  130. if (lbs_set_universaltable(priv, 0)) {
  131. ret = -1;
  132. goto out;
  133. }
  134. out:
  135. lbs_deb_leave(LBS_DEB_CMD);
  136. return ret;
  137. }
  138. int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria)
  139. {
  140. struct cmd_ds_host_sleep cmd_config;
  141. int ret;
  142. cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
  143. cmd_config.criteria = cpu_to_le32(criteria);
  144. cmd_config.gpio = priv->wol_gpio;
  145. cmd_config.gap = priv->wol_gap;
  146. ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
  147. if (!ret) {
  148. lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
  149. priv->wol_criteria = criteria;
  150. } else {
  151. lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
  152. }
  153. return ret;
  154. }
  155. EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
  156. static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
  157. u16 cmd_action)
  158. {
  159. struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
  160. lbs_deb_enter(LBS_DEB_CMD);
  161. cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
  162. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
  163. S_DS_GEN);
  164. psm->action = cpu_to_le16(cmd_action);
  165. psm->multipledtim = 0;
  166. switch (cmd_action) {
  167. case CMD_SUBCMD_ENTER_PS:
  168. lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
  169. psm->locallisteninterval = 0;
  170. psm->nullpktinterval = 0;
  171. psm->multipledtim =
  172. cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
  173. break;
  174. case CMD_SUBCMD_EXIT_PS:
  175. lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
  176. break;
  177. case CMD_SUBCMD_SLEEP_CONFIRMED:
  178. lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
  179. break;
  180. default:
  181. break;
  182. }
  183. lbs_deb_leave(LBS_DEB_CMD);
  184. return 0;
  185. }
  186. int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
  187. uint16_t cmd_action, uint16_t *timeout)
  188. {
  189. struct cmd_ds_802_11_inactivity_timeout cmd;
  190. int ret;
  191. lbs_deb_enter(LBS_DEB_CMD);
  192. cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
  193. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  194. cmd.action = cpu_to_le16(cmd_action);
  195. if (cmd_action == CMD_ACT_SET)
  196. cmd.timeout = cpu_to_le16(*timeout);
  197. else
  198. cmd.timeout = 0;
  199. ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
  200. if (!ret)
  201. *timeout = le16_to_cpu(cmd.timeout);
  202. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  203. return 0;
  204. }
  205. int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
  206. struct sleep_params *sp)
  207. {
  208. struct cmd_ds_802_11_sleep_params cmd;
  209. int ret;
  210. lbs_deb_enter(LBS_DEB_CMD);
  211. if (cmd_action == CMD_ACT_GET) {
  212. memset(&cmd, 0, sizeof(cmd));
  213. } else {
  214. cmd.error = cpu_to_le16(sp->sp_error);
  215. cmd.offset = cpu_to_le16(sp->sp_offset);
  216. cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
  217. cmd.calcontrol = sp->sp_calcontrol;
  218. cmd.externalsleepclk = sp->sp_extsleepclk;
  219. cmd.reserved = cpu_to_le16(sp->sp_reserved);
  220. }
  221. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  222. cmd.action = cpu_to_le16(cmd_action);
  223. ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
  224. if (!ret) {
  225. lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
  226. "calcontrol 0x%x extsleepclk 0x%x\n",
  227. le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
  228. le16_to_cpu(cmd.stabletime), cmd.calcontrol,
  229. cmd.externalsleepclk);
  230. sp->sp_error = le16_to_cpu(cmd.error);
  231. sp->sp_offset = le16_to_cpu(cmd.offset);
  232. sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
  233. sp->sp_calcontrol = cmd.calcontrol;
  234. sp->sp_extsleepclk = cmd.externalsleepclk;
  235. sp->sp_reserved = le16_to_cpu(cmd.reserved);
  236. }
  237. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  238. return 0;
  239. }
  240. int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
  241. struct assoc_request *assoc)
  242. {
  243. struct cmd_ds_802_11_set_wep cmd;
  244. int ret = 0;
  245. lbs_deb_enter(LBS_DEB_CMD);
  246. cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
  247. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  248. cmd.action = cpu_to_le16(cmd_action);
  249. if (cmd_action == CMD_ACT_ADD) {
  250. int i;
  251. /* default tx key index */
  252. cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
  253. CMD_WEP_KEY_INDEX_MASK);
  254. /* Copy key types and material to host command structure */
  255. for (i = 0; i < 4; i++) {
  256. struct enc_key *pkey = &assoc->wep_keys[i];
  257. switch (pkey->len) {
  258. case KEY_LEN_WEP_40:
  259. cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
  260. memmove(cmd.keymaterial[i], pkey->key, pkey->len);
  261. lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
  262. break;
  263. case KEY_LEN_WEP_104:
  264. cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
  265. memmove(cmd.keymaterial[i], pkey->key, pkey->len);
  266. lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
  267. break;
  268. case 0:
  269. break;
  270. default:
  271. lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
  272. i, pkey->len);
  273. ret = -1;
  274. goto done;
  275. break;
  276. }
  277. }
  278. } else if (cmd_action == CMD_ACT_REMOVE) {
  279. /* ACT_REMOVE clears _all_ WEP keys */
  280. /* default tx key index */
  281. cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
  282. CMD_WEP_KEY_INDEX_MASK);
  283. lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
  284. }
  285. ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
  286. done:
  287. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  288. return ret;
  289. }
  290. int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
  291. uint16_t *enable)
  292. {
  293. struct cmd_ds_802_11_enable_rsn cmd;
  294. int ret;
  295. lbs_deb_enter(LBS_DEB_CMD);
  296. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  297. cmd.action = cpu_to_le16(cmd_action);
  298. if (cmd_action == CMD_ACT_SET) {
  299. if (*enable)
  300. cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
  301. else
  302. cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
  303. lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
  304. }
  305. ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
  306. if (!ret && cmd_action == CMD_ACT_GET)
  307. *enable = le16_to_cpu(cmd.enable);
  308. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  309. return ret;
  310. }
  311. static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
  312. struct enc_key *key)
  313. {
  314. lbs_deb_enter(LBS_DEB_CMD);
  315. if (key->flags & KEY_INFO_WPA_ENABLED)
  316. keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
  317. if (key->flags & KEY_INFO_WPA_UNICAST)
  318. keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
  319. if (key->flags & KEY_INFO_WPA_MCAST)
  320. keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
  321. keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  322. keyparam->keytypeid = cpu_to_le16(key->type);
  323. keyparam->keylen = cpu_to_le16(key->len);
  324. memcpy(keyparam->key, key->key, key->len);
  325. /* Length field doesn't include the {type,length} header */
  326. keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
  327. lbs_deb_leave(LBS_DEB_CMD);
  328. }
  329. int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
  330. struct assoc_request *assoc)
  331. {
  332. struct cmd_ds_802_11_key_material cmd;
  333. int ret = 0;
  334. int index = 0;
  335. lbs_deb_enter(LBS_DEB_CMD);
  336. cmd.action = cpu_to_le16(cmd_action);
  337. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  338. if (cmd_action == CMD_ACT_GET) {
  339. cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
  340. } else {
  341. memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
  342. if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
  343. set_one_wpa_key(&cmd.keyParamSet[index],
  344. &assoc->wpa_unicast_key);
  345. index++;
  346. }
  347. if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
  348. set_one_wpa_key(&cmd.keyParamSet[index],
  349. &assoc->wpa_mcast_key);
  350. index++;
  351. }
  352. /* The common header and as many keys as we included */
  353. cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
  354. keyParamSet[index]));
  355. }
  356. ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
  357. /* Copy the returned key to driver private data */
  358. if (!ret && cmd_action == CMD_ACT_GET) {
  359. void *buf_ptr = cmd.keyParamSet;
  360. void *resp_end = &(&cmd)[1];
  361. while (buf_ptr < resp_end) {
  362. struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
  363. struct enc_key *key;
  364. uint16_t param_set_len = le16_to_cpu(keyparam->length);
  365. uint16_t key_len = le16_to_cpu(keyparam->keylen);
  366. uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
  367. uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
  368. void *end;
  369. end = (void *)keyparam + sizeof(keyparam->type)
  370. + sizeof(keyparam->length) + param_set_len;
  371. /* Make sure we don't access past the end of the IEs */
  372. if (end > resp_end)
  373. break;
  374. if (key_flags & KEY_INFO_WPA_UNICAST)
  375. key = &priv->wpa_unicast_key;
  376. else if (key_flags & KEY_INFO_WPA_MCAST)
  377. key = &priv->wpa_mcast_key;
  378. else
  379. break;
  380. /* Copy returned key into driver */
  381. memset(key, 0, sizeof(struct enc_key));
  382. if (key_len > sizeof(key->key))
  383. break;
  384. key->type = key_type;
  385. key->flags = key_flags;
  386. key->len = key_len;
  387. memcpy(key->key, keyparam->key, key->len);
  388. buf_ptr = end + 1;
  389. }
  390. }
  391. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  392. return ret;
  393. }
  394. static int lbs_cmd_802_11_reset(struct cmd_ds_command *cmd, int cmd_action)
  395. {
  396. struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
  397. lbs_deb_enter(LBS_DEB_CMD);
  398. cmd->command = cpu_to_le16(CMD_802_11_RESET);
  399. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
  400. reset->action = cpu_to_le16(cmd_action);
  401. lbs_deb_leave(LBS_DEB_CMD);
  402. return 0;
  403. }
  404. static int lbs_cmd_802_11_snmp_mib(struct lbs_private *priv,
  405. struct cmd_ds_command *cmd,
  406. int cmd_action,
  407. int cmd_oid, void *pdata_buf)
  408. {
  409. struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
  410. u8 ucTemp;
  411. lbs_deb_enter(LBS_DEB_CMD);
  412. lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
  413. cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB);
  414. cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
  415. switch (cmd_oid) {
  416. case OID_802_11_INFRASTRUCTURE_MODE:
  417. {
  418. u8 mode = (u8) (size_t) pdata_buf;
  419. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  420. pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I);
  421. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u8));
  422. if (mode == IW_MODE_ADHOC) {
  423. ucTemp = SNMP_MIB_VALUE_ADHOC;
  424. } else {
  425. /* Infra and Auto modes */
  426. ucTemp = SNMP_MIB_VALUE_INFRA;
  427. }
  428. memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
  429. break;
  430. }
  431. case OID_802_11D_ENABLE:
  432. {
  433. u32 ulTemp;
  434. pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I);
  435. if (cmd_action == CMD_ACT_SET) {
  436. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  437. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  438. ulTemp = *(u32 *)pdata_buf;
  439. *((__le16 *)(pSNMPMIB->value)) =
  440. cpu_to_le16((u16) ulTemp);
  441. }
  442. break;
  443. }
  444. case OID_802_11_FRAGMENTATION_THRESHOLD:
  445. {
  446. u32 ulTemp;
  447. pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I);
  448. if (cmd_action == CMD_ACT_GET) {
  449. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
  450. } else if (cmd_action == CMD_ACT_SET) {
  451. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  452. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  453. ulTemp = *((u32 *) pdata_buf);
  454. *((__le16 *)(pSNMPMIB->value)) =
  455. cpu_to_le16((u16) ulTemp);
  456. }
  457. break;
  458. }
  459. case OID_802_11_RTS_THRESHOLD:
  460. {
  461. u32 ulTemp;
  462. pSNMPMIB->oid = cpu_to_le16(RTSTHRESH_I);
  463. if (cmd_action == CMD_ACT_GET) {
  464. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
  465. } else if (cmd_action == CMD_ACT_SET) {
  466. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  467. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  468. ulTemp = *((u32 *)pdata_buf);
  469. *(__le16 *)(pSNMPMIB->value) =
  470. cpu_to_le16((u16) ulTemp);
  471. }
  472. break;
  473. }
  474. case OID_802_11_TX_RETRYCOUNT:
  475. pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I);
  476. if (cmd_action == CMD_ACT_GET) {
  477. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
  478. } else if (cmd_action == CMD_ACT_SET) {
  479. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  480. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  481. *((__le16 *)(pSNMPMIB->value)) =
  482. cpu_to_le16((u16) priv->txretrycount);
  483. }
  484. break;
  485. default:
  486. break;
  487. }
  488. lbs_deb_cmd(
  489. "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
  490. le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
  491. le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
  492. lbs_deb_cmd(
  493. "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
  494. le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
  495. le16_to_cpu(pSNMPMIB->bufsize),
  496. le16_to_cpu(*(__le16 *) pSNMPMIB->value));
  497. lbs_deb_leave(LBS_DEB_CMD);
  498. return 0;
  499. }
  500. static int lbs_cmd_802_11_rf_tx_power(struct cmd_ds_command *cmd,
  501. u16 cmd_action, void *pdata_buf)
  502. {
  503. struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
  504. lbs_deb_enter(LBS_DEB_CMD);
  505. cmd->size =
  506. cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
  507. cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
  508. prtp->action = cpu_to_le16(cmd_action);
  509. lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
  510. le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
  511. le16_to_cpu(prtp->action));
  512. switch (cmd_action) {
  513. case CMD_ACT_TX_POWER_OPT_GET:
  514. prtp->action = cpu_to_le16(CMD_ACT_GET);
  515. prtp->currentlevel = 0;
  516. break;
  517. case CMD_ACT_TX_POWER_OPT_SET_HIGH:
  518. prtp->action = cpu_to_le16(CMD_ACT_SET);
  519. prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH);
  520. break;
  521. case CMD_ACT_TX_POWER_OPT_SET_MID:
  522. prtp->action = cpu_to_le16(CMD_ACT_SET);
  523. prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID);
  524. break;
  525. case CMD_ACT_TX_POWER_OPT_SET_LOW:
  526. prtp->action = cpu_to_le16(CMD_ACT_SET);
  527. prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
  528. break;
  529. }
  530. lbs_deb_leave(LBS_DEB_CMD);
  531. return 0;
  532. }
  533. static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
  534. u16 cmd_action, void *pdata_buf)
  535. {
  536. struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
  537. cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
  538. cmd->size =
  539. cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
  540. S_DS_GEN);
  541. monitor->action = cpu_to_le16(cmd_action);
  542. if (cmd_action == CMD_ACT_SET) {
  543. monitor->mode =
  544. cpu_to_le16((u16) (*(u32 *) pdata_buf));
  545. }
  546. return 0;
  547. }
  548. static int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
  549. struct cmd_ds_command *cmd,
  550. u16 cmd_action)
  551. {
  552. struct cmd_ds_802_11_rate_adapt_rateset
  553. *rateadapt = &cmd->params.rateset;
  554. lbs_deb_enter(LBS_DEB_CMD);
  555. cmd->size =
  556. cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
  557. + S_DS_GEN);
  558. cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
  559. rateadapt->action = cpu_to_le16(cmd_action);
  560. rateadapt->enablehwauto = cpu_to_le16(priv->enablehwauto);
  561. rateadapt->bitmap = cpu_to_le16(priv->ratebitmap);
  562. lbs_deb_leave(LBS_DEB_CMD);
  563. return 0;
  564. }
  565. /**
  566. * @brief Get the current data rate
  567. *
  568. * @param priv A pointer to struct lbs_private structure
  569. *
  570. * @return The data rate on success, error on failure
  571. */
  572. int lbs_get_data_rate(struct lbs_private *priv)
  573. {
  574. struct cmd_ds_802_11_data_rate cmd;
  575. int ret = -1;
  576. lbs_deb_enter(LBS_DEB_CMD);
  577. memset(&cmd, 0, sizeof(cmd));
  578. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  579. cmd.action = cpu_to_le16(CMD_ACT_GET_TX_RATE);
  580. ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
  581. if (ret)
  582. goto out;
  583. lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
  584. ret = (int) lbs_fw_index_to_data_rate(cmd.rates[0]);
  585. lbs_deb_cmd("DATA_RATE: current rate 0x%02x\n", ret);
  586. out:
  587. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  588. return ret;
  589. }
  590. /**
  591. * @brief Set the data rate
  592. *
  593. * @param priv A pointer to struct lbs_private structure
  594. * @param rate The desired data rate, or 0 to clear a locked rate
  595. *
  596. * @return 0 on success, error on failure
  597. */
  598. int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
  599. {
  600. struct cmd_ds_802_11_data_rate cmd;
  601. int ret = 0;
  602. lbs_deb_enter(LBS_DEB_CMD);
  603. memset(&cmd, 0, sizeof(cmd));
  604. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  605. if (rate > 0) {
  606. cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
  607. cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
  608. if (cmd.rates[0] == 0) {
  609. lbs_deb_cmd("DATA_RATE: invalid requested rate of"
  610. " 0x%02X\n", rate);
  611. ret = 0;
  612. goto out;
  613. }
  614. lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
  615. } else {
  616. cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
  617. lbs_deb_cmd("DATA_RATE: setting auto\n");
  618. }
  619. ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
  620. if (ret)
  621. goto out;
  622. lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
  623. /* FIXME: get actual rates FW can do if this command actually returns
  624. * all data rates supported.
  625. */
  626. priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
  627. lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
  628. out:
  629. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  630. return ret;
  631. }
  632. static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv,
  633. struct cmd_ds_command *cmd,
  634. u16 cmd_action)
  635. {
  636. struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
  637. lbs_deb_enter(LBS_DEB_CMD);
  638. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
  639. S_DS_GEN);
  640. cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
  641. lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
  642. pMCastAdr->action = cpu_to_le16(cmd_action);
  643. pMCastAdr->nr_of_adrs =
  644. cpu_to_le16((u16) priv->nr_of_multicastmacaddr);
  645. memcpy(pMCastAdr->maclist, priv->multicastlist,
  646. priv->nr_of_multicastmacaddr * ETH_ALEN);
  647. lbs_deb_leave(LBS_DEB_CMD);
  648. return 0;
  649. }
  650. /**
  651. * @brief Get the radio channel
  652. *
  653. * @param priv A pointer to struct lbs_private structure
  654. *
  655. * @return The channel on success, error on failure
  656. */
  657. int lbs_get_channel(struct lbs_private *priv)
  658. {
  659. struct cmd_ds_802_11_rf_channel cmd;
  660. int ret = 0;
  661. lbs_deb_enter(LBS_DEB_CMD);
  662. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  663. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
  664. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  665. if (ret)
  666. goto out;
  667. ret = le16_to_cpu(cmd.channel);
  668. lbs_deb_cmd("current radio channel is %d\n", ret);
  669. out:
  670. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  671. return ret;
  672. }
  673. /**
  674. * @brief Set the radio channel
  675. *
  676. * @param priv A pointer to struct lbs_private structure
  677. * @param channel The desired channel, or 0 to clear a locked channel
  678. *
  679. * @return 0 on success, error on failure
  680. */
  681. int lbs_set_channel(struct lbs_private *priv, u8 channel)
  682. {
  683. struct cmd_ds_802_11_rf_channel cmd;
  684. u8 old_channel = priv->curbssparams.channel;
  685. int ret = 0;
  686. lbs_deb_enter(LBS_DEB_CMD);
  687. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  688. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
  689. cmd.channel = cpu_to_le16(channel);
  690. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  691. if (ret)
  692. goto out;
  693. priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
  694. lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
  695. priv->curbssparams.channel);
  696. out:
  697. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  698. return ret;
  699. }
  700. static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
  701. struct cmd_ds_command *cmd)
  702. {
  703. lbs_deb_enter(LBS_DEB_CMD);
  704. cmd->command = cpu_to_le16(CMD_802_11_RSSI);
  705. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
  706. cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
  707. /* reset Beacon SNR/NF/RSSI values */
  708. priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
  709. priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
  710. priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
  711. priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
  712. priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
  713. priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
  714. lbs_deb_leave(LBS_DEB_CMD);
  715. return 0;
  716. }
  717. static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
  718. u8 cmd_action, void *pdata_buf)
  719. {
  720. struct lbs_offset_value *offval;
  721. lbs_deb_enter(LBS_DEB_CMD);
  722. offval = (struct lbs_offset_value *)pdata_buf;
  723. switch (le16_to_cpu(cmdptr->command)) {
  724. case CMD_MAC_REG_ACCESS:
  725. {
  726. struct cmd_ds_mac_reg_access *macreg;
  727. cmdptr->size =
  728. cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
  729. + S_DS_GEN);
  730. macreg =
  731. (struct cmd_ds_mac_reg_access *)&cmdptr->params.
  732. macreg;
  733. macreg->action = cpu_to_le16(cmd_action);
  734. macreg->offset = cpu_to_le16((u16) offval->offset);
  735. macreg->value = cpu_to_le32(offval->value);
  736. break;
  737. }
  738. case CMD_BBP_REG_ACCESS:
  739. {
  740. struct cmd_ds_bbp_reg_access *bbpreg;
  741. cmdptr->size =
  742. cpu_to_le16(sizeof
  743. (struct cmd_ds_bbp_reg_access)
  744. + S_DS_GEN);
  745. bbpreg =
  746. (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
  747. bbpreg;
  748. bbpreg->action = cpu_to_le16(cmd_action);
  749. bbpreg->offset = cpu_to_le16((u16) offval->offset);
  750. bbpreg->value = (u8) offval->value;
  751. break;
  752. }
  753. case CMD_RF_REG_ACCESS:
  754. {
  755. struct cmd_ds_rf_reg_access *rfreg;
  756. cmdptr->size =
  757. cpu_to_le16(sizeof
  758. (struct cmd_ds_rf_reg_access) +
  759. S_DS_GEN);
  760. rfreg =
  761. (struct cmd_ds_rf_reg_access *)&cmdptr->params.
  762. rfreg;
  763. rfreg->action = cpu_to_le16(cmd_action);
  764. rfreg->offset = cpu_to_le16((u16) offval->offset);
  765. rfreg->value = (u8) offval->value;
  766. break;
  767. }
  768. default:
  769. break;
  770. }
  771. lbs_deb_leave(LBS_DEB_CMD);
  772. return 0;
  773. }
  774. static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
  775. u16 cmd_action, void *pdata_buf)
  776. {
  777. struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
  778. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  779. cmd->command = cpu_to_le16(CMD_BT_ACCESS);
  780. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
  781. cmd->result = 0;
  782. bt_access->action = cpu_to_le16(cmd_action);
  783. switch (cmd_action) {
  784. case CMD_ACT_BT_ACCESS_ADD:
  785. memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
  786. lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
  787. break;
  788. case CMD_ACT_BT_ACCESS_DEL:
  789. memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
  790. lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
  791. break;
  792. case CMD_ACT_BT_ACCESS_LIST:
  793. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  794. break;
  795. case CMD_ACT_BT_ACCESS_RESET:
  796. break;
  797. case CMD_ACT_BT_ACCESS_SET_INVERT:
  798. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  799. break;
  800. case CMD_ACT_BT_ACCESS_GET_INVERT:
  801. break;
  802. default:
  803. break;
  804. }
  805. lbs_deb_leave(LBS_DEB_CMD);
  806. return 0;
  807. }
  808. static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
  809. u16 cmd_action, void *pdata_buf)
  810. {
  811. struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
  812. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  813. cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
  814. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
  815. cmd->result = 0;
  816. if (pdata_buf)
  817. memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
  818. else
  819. memset(fwt_access, 0, sizeof(*fwt_access));
  820. fwt_access->action = cpu_to_le16(cmd_action);
  821. lbs_deb_leave(LBS_DEB_CMD);
  822. return 0;
  823. }
  824. int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
  825. struct cmd_ds_mesh_access *cmd)
  826. {
  827. int ret;
  828. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  829. cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
  830. cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
  831. cmd->hdr.result = 0;
  832. cmd->action = cpu_to_le16(cmd_action);
  833. ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
  834. lbs_deb_leave(LBS_DEB_CMD);
  835. return ret;
  836. }
  837. int lbs_mesh_config(struct lbs_private *priv, uint16_t enable, uint16_t chan)
  838. {
  839. struct cmd_ds_mesh_config cmd;
  840. memset(&cmd, 0, sizeof(cmd));
  841. cmd.action = cpu_to_le16(enable);
  842. cmd.channel = cpu_to_le16(chan);
  843. cmd.type = cpu_to_le16(priv->mesh_tlv);
  844. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  845. if (enable) {
  846. cmd.length = cpu_to_le16(priv->mesh_ssid_len);
  847. memcpy(cmd.data, priv->mesh_ssid, priv->mesh_ssid_len);
  848. }
  849. lbs_deb_cmd("mesh config enable %d TLV %x channel %d SSID %s\n",
  850. enable, priv->mesh_tlv, chan,
  851. escape_essid(priv->mesh_ssid, priv->mesh_ssid_len));
  852. return lbs_cmd_with_response(priv, CMD_MESH_CONFIG, &cmd);
  853. }
  854. static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
  855. struct cmd_ds_command *cmd,
  856. u16 cmd_action)
  857. {
  858. struct cmd_ds_802_11_beacon_control
  859. *bcn_ctrl = &cmd->params.bcn_ctrl;
  860. lbs_deb_enter(LBS_DEB_CMD);
  861. cmd->size =
  862. cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
  863. + S_DS_GEN);
  864. cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
  865. bcn_ctrl->action = cpu_to_le16(cmd_action);
  866. bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
  867. bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
  868. lbs_deb_leave(LBS_DEB_CMD);
  869. return 0;
  870. }
  871. static void lbs_queue_cmd(struct lbs_private *priv,
  872. struct cmd_ctrl_node *cmdnode)
  873. {
  874. unsigned long flags;
  875. int addtail = 1;
  876. lbs_deb_enter(LBS_DEB_HOST);
  877. if (!cmdnode) {
  878. lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
  879. goto done;
  880. }
  881. if (!cmdnode->cmdbuf->size) {
  882. lbs_deb_host("DNLD_CMD: cmd size is zero\n");
  883. goto done;
  884. }
  885. cmdnode->result = 0;
  886. /* Exit_PS command needs to be queued in the header always. */
  887. if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
  888. struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
  889. if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  890. if (priv->psstate != PS_STATE_FULL_POWER)
  891. addtail = 0;
  892. }
  893. }
  894. spin_lock_irqsave(&priv->driver_lock, flags);
  895. if (addtail)
  896. list_add_tail(&cmdnode->list, &priv->cmdpendingq);
  897. else
  898. list_add(&cmdnode->list, &priv->cmdpendingq);
  899. spin_unlock_irqrestore(&priv->driver_lock, flags);
  900. lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
  901. le16_to_cpu(cmdnode->cmdbuf->command));
  902. done:
  903. lbs_deb_leave(LBS_DEB_HOST);
  904. }
  905. static void lbs_submit_command(struct lbs_private *priv,
  906. struct cmd_ctrl_node *cmdnode)
  907. {
  908. unsigned long flags;
  909. struct cmd_header *cmd;
  910. uint16_t cmdsize;
  911. uint16_t command;
  912. int timeo = 5 * HZ;
  913. int ret;
  914. lbs_deb_enter(LBS_DEB_HOST);
  915. cmd = cmdnode->cmdbuf;
  916. spin_lock_irqsave(&priv->driver_lock, flags);
  917. priv->cur_cmd = cmdnode;
  918. priv->cur_cmd_retcode = 0;
  919. spin_unlock_irqrestore(&priv->driver_lock, flags);
  920. cmdsize = le16_to_cpu(cmd->size);
  921. command = le16_to_cpu(cmd->command);
  922. /* These commands take longer */
  923. if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE ||
  924. command == CMD_802_11_AUTHENTICATE)
  925. timeo = 10 * HZ;
  926. lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
  927. command, le16_to_cpu(cmd->seqnum), cmdsize);
  928. lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
  929. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
  930. if (ret) {
  931. lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
  932. /* Let the timer kick in and retry, and potentially reset
  933. the whole thing if the condition persists */
  934. timeo = HZ;
  935. }
  936. /* Setup the timer after transmit command */
  937. mod_timer(&priv->command_timer, jiffies + timeo);
  938. lbs_deb_leave(LBS_DEB_HOST);
  939. }
  940. /**
  941. * This function inserts command node to cmdfreeq
  942. * after cleans it. Requires priv->driver_lock held.
  943. */
  944. static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  945. struct cmd_ctrl_node *cmdnode)
  946. {
  947. lbs_deb_enter(LBS_DEB_HOST);
  948. if (!cmdnode)
  949. goto out;
  950. cmdnode->callback = NULL;
  951. cmdnode->callback_arg = 0;
  952. memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
  953. list_add_tail(&cmdnode->list, &priv->cmdfreeq);
  954. out:
  955. lbs_deb_leave(LBS_DEB_HOST);
  956. }
  957. static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  958. struct cmd_ctrl_node *ptempcmd)
  959. {
  960. unsigned long flags;
  961. spin_lock_irqsave(&priv->driver_lock, flags);
  962. __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
  963. spin_unlock_irqrestore(&priv->driver_lock, flags);
  964. }
  965. void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
  966. int result)
  967. {
  968. if (cmd == priv->cur_cmd)
  969. priv->cur_cmd_retcode = result;
  970. cmd->result = result;
  971. cmd->cmdwaitqwoken = 1;
  972. wake_up_interruptible(&cmd->cmdwait_q);
  973. if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
  974. __lbs_cleanup_and_insert_cmd(priv, cmd);
  975. priv->cur_cmd = NULL;
  976. }
  977. int lbs_set_radio_control(struct lbs_private *priv)
  978. {
  979. int ret = 0;
  980. struct cmd_ds_802_11_radio_control cmd;
  981. lbs_deb_enter(LBS_DEB_CMD);
  982. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  983. cmd.action = cpu_to_le16(CMD_ACT_SET);
  984. switch (priv->preamble) {
  985. case CMD_TYPE_SHORT_PREAMBLE:
  986. cmd.control = cpu_to_le16(SET_SHORT_PREAMBLE);
  987. break;
  988. case CMD_TYPE_LONG_PREAMBLE:
  989. cmd.control = cpu_to_le16(SET_LONG_PREAMBLE);
  990. break;
  991. case CMD_TYPE_AUTO_PREAMBLE:
  992. default:
  993. cmd.control = cpu_to_le16(SET_AUTO_PREAMBLE);
  994. break;
  995. }
  996. if (priv->radioon)
  997. cmd.control |= cpu_to_le16(TURN_ON_RF);
  998. else
  999. cmd.control &= cpu_to_le16(~TURN_ON_RF);
  1000. lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n", priv->radioon,
  1001. priv->preamble);
  1002. ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
  1003. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  1004. return ret;
  1005. }
  1006. void lbs_set_mac_control(struct lbs_private *priv)
  1007. {
  1008. struct cmd_ds_mac_control cmd;
  1009. lbs_deb_enter(LBS_DEB_CMD);
  1010. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1011. cmd.action = cpu_to_le16(priv->mac_control);
  1012. cmd.reserved = 0;
  1013. lbs_cmd_async(priv, CMD_MAC_CONTROL,
  1014. &cmd.hdr, sizeof(cmd));
  1015. lbs_deb_leave(LBS_DEB_CMD);
  1016. }
  1017. /**
  1018. * @brief This function prepare the command before send to firmware.
  1019. *
  1020. * @param priv A pointer to struct lbs_private structure
  1021. * @param cmd_no command number
  1022. * @param cmd_action command action: GET or SET
  1023. * @param wait_option wait option: wait response or not
  1024. * @param cmd_oid cmd oid: treated as sub command
  1025. * @param pdata_buf A pointer to informaion buffer
  1026. * @return 0 or -1
  1027. */
  1028. int lbs_prepare_and_send_command(struct lbs_private *priv,
  1029. u16 cmd_no,
  1030. u16 cmd_action,
  1031. u16 wait_option, u32 cmd_oid, void *pdata_buf)
  1032. {
  1033. int ret = 0;
  1034. struct cmd_ctrl_node *cmdnode;
  1035. struct cmd_ds_command *cmdptr;
  1036. unsigned long flags;
  1037. lbs_deb_enter(LBS_DEB_HOST);
  1038. if (!priv) {
  1039. lbs_deb_host("PREP_CMD: priv is NULL\n");
  1040. ret = -1;
  1041. goto done;
  1042. }
  1043. if (priv->surpriseremoved) {
  1044. lbs_deb_host("PREP_CMD: card removed\n");
  1045. ret = -1;
  1046. goto done;
  1047. }
  1048. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1049. if (cmdnode == NULL) {
  1050. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1051. /* Wake up main thread to execute next command */
  1052. wake_up_interruptible(&priv->waitq);
  1053. ret = -1;
  1054. goto done;
  1055. }
  1056. cmdnode->callback = NULL;
  1057. cmdnode->callback_arg = (unsigned long)pdata_buf;
  1058. cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
  1059. lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
  1060. /* Set sequence number, command and INT option */
  1061. priv->seqnum++;
  1062. cmdptr->seqnum = cpu_to_le16(priv->seqnum);
  1063. cmdptr->command = cpu_to_le16(cmd_no);
  1064. cmdptr->result = 0;
  1065. switch (cmd_no) {
  1066. case CMD_802_11_PS_MODE:
  1067. ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
  1068. break;
  1069. case CMD_802_11_ASSOCIATE:
  1070. case CMD_802_11_REASSOCIATE:
  1071. ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
  1072. break;
  1073. case CMD_802_11_DEAUTHENTICATE:
  1074. ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
  1075. break;
  1076. case CMD_802_11_AD_HOC_START:
  1077. ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
  1078. break;
  1079. case CMD_802_11_RESET:
  1080. ret = lbs_cmd_802_11_reset(cmdptr, cmd_action);
  1081. break;
  1082. case CMD_802_11_AUTHENTICATE:
  1083. ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
  1084. break;
  1085. case CMD_802_11_SNMP_MIB:
  1086. ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
  1087. cmd_action, cmd_oid, pdata_buf);
  1088. break;
  1089. case CMD_MAC_REG_ACCESS:
  1090. case CMD_BBP_REG_ACCESS:
  1091. case CMD_RF_REG_ACCESS:
  1092. ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
  1093. break;
  1094. case CMD_802_11_RF_TX_POWER:
  1095. ret = lbs_cmd_802_11_rf_tx_power(cmdptr,
  1096. cmd_action, pdata_buf);
  1097. break;
  1098. case CMD_802_11_RATE_ADAPT_RATESET:
  1099. ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
  1100. cmdptr, cmd_action);
  1101. break;
  1102. case CMD_MAC_MULTICAST_ADR:
  1103. ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
  1104. break;
  1105. case CMD_802_11_MONITOR_MODE:
  1106. ret = lbs_cmd_802_11_monitor_mode(cmdptr,
  1107. cmd_action, pdata_buf);
  1108. break;
  1109. case CMD_802_11_AD_HOC_JOIN:
  1110. ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
  1111. break;
  1112. case CMD_802_11_RSSI:
  1113. ret = lbs_cmd_802_11_rssi(priv, cmdptr);
  1114. break;
  1115. case CMD_802_11_AD_HOC_STOP:
  1116. ret = lbs_cmd_80211_ad_hoc_stop(cmdptr);
  1117. break;
  1118. case CMD_802_11_SET_AFC:
  1119. case CMD_802_11_GET_AFC:
  1120. cmdptr->command = cpu_to_le16(cmd_no);
  1121. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
  1122. S_DS_GEN);
  1123. memmove(&cmdptr->params.afc,
  1124. pdata_buf, sizeof(struct cmd_ds_802_11_afc));
  1125. ret = 0;
  1126. goto done;
  1127. case CMD_802_11D_DOMAIN_INFO:
  1128. ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
  1129. cmd_no, cmd_action);
  1130. break;
  1131. case CMD_802_11_TPC_CFG:
  1132. cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
  1133. cmdptr->size =
  1134. cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
  1135. S_DS_GEN);
  1136. memmove(&cmdptr->params.tpccfg,
  1137. pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
  1138. ret = 0;
  1139. break;
  1140. case CMD_802_11_LED_GPIO_CTRL:
  1141. {
  1142. struct mrvlietypes_ledgpio *gpio =
  1143. (struct mrvlietypes_ledgpio*)
  1144. cmdptr->params.ledgpio.data;
  1145. memmove(&cmdptr->params.ledgpio,
  1146. pdata_buf,
  1147. sizeof(struct cmd_ds_802_11_led_ctrl));
  1148. cmdptr->command =
  1149. cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
  1150. #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
  1151. cmdptr->size =
  1152. cpu_to_le16(le16_to_cpu(gpio->header.len)
  1153. + S_DS_GEN
  1154. + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
  1155. gpio->header.len = gpio->header.len;
  1156. ret = 0;
  1157. break;
  1158. }
  1159. case CMD_BT_ACCESS:
  1160. ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
  1161. break;
  1162. case CMD_FWT_ACCESS:
  1163. ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
  1164. break;
  1165. case CMD_GET_TSF:
  1166. cmdptr->command = cpu_to_le16(CMD_GET_TSF);
  1167. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
  1168. S_DS_GEN);
  1169. ret = 0;
  1170. break;
  1171. case CMD_802_11_BEACON_CTRL:
  1172. ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
  1173. break;
  1174. default:
  1175. lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
  1176. ret = -1;
  1177. break;
  1178. }
  1179. /* return error, since the command preparation failed */
  1180. if (ret != 0) {
  1181. lbs_deb_host("PREP_CMD: command preparation failed\n");
  1182. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1183. ret = -1;
  1184. goto done;
  1185. }
  1186. cmdnode->cmdwaitqwoken = 0;
  1187. lbs_queue_cmd(priv, cmdnode);
  1188. wake_up_interruptible(&priv->waitq);
  1189. if (wait_option & CMD_OPTION_WAITFORRSP) {
  1190. lbs_deb_host("PREP_CMD: wait for response\n");
  1191. might_sleep();
  1192. wait_event_interruptible(cmdnode->cmdwait_q,
  1193. cmdnode->cmdwaitqwoken);
  1194. }
  1195. spin_lock_irqsave(&priv->driver_lock, flags);
  1196. if (priv->cur_cmd_retcode) {
  1197. lbs_deb_host("PREP_CMD: command failed with return code %d\n",
  1198. priv->cur_cmd_retcode);
  1199. priv->cur_cmd_retcode = 0;
  1200. ret = -1;
  1201. }
  1202. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1203. done:
  1204. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1205. return ret;
  1206. }
  1207. /**
  1208. * @brief This function allocates the command buffer and link
  1209. * it to command free queue.
  1210. *
  1211. * @param priv A pointer to struct lbs_private structure
  1212. * @return 0 or -1
  1213. */
  1214. int lbs_allocate_cmd_buffer(struct lbs_private *priv)
  1215. {
  1216. int ret = 0;
  1217. u32 bufsize;
  1218. u32 i;
  1219. struct cmd_ctrl_node *cmdarray;
  1220. lbs_deb_enter(LBS_DEB_HOST);
  1221. /* Allocate and initialize the command array */
  1222. bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
  1223. if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
  1224. lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
  1225. ret = -1;
  1226. goto done;
  1227. }
  1228. priv->cmd_array = cmdarray;
  1229. /* Allocate and initialize each command buffer in the command array */
  1230. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1231. cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
  1232. if (!cmdarray[i].cmdbuf) {
  1233. lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
  1234. ret = -1;
  1235. goto done;
  1236. }
  1237. }
  1238. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1239. init_waitqueue_head(&cmdarray[i].cmdwait_q);
  1240. lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
  1241. }
  1242. ret = 0;
  1243. done:
  1244. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1245. return ret;
  1246. }
  1247. /**
  1248. * @brief This function frees the command buffer.
  1249. *
  1250. * @param priv A pointer to struct lbs_private structure
  1251. * @return 0 or -1
  1252. */
  1253. int lbs_free_cmd_buffer(struct lbs_private *priv)
  1254. {
  1255. struct cmd_ctrl_node *cmdarray;
  1256. unsigned int i;
  1257. lbs_deb_enter(LBS_DEB_HOST);
  1258. /* need to check if cmd array is allocated or not */
  1259. if (priv->cmd_array == NULL) {
  1260. lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
  1261. goto done;
  1262. }
  1263. cmdarray = priv->cmd_array;
  1264. /* Release shared memory buffers */
  1265. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1266. if (cmdarray[i].cmdbuf) {
  1267. kfree(cmdarray[i].cmdbuf);
  1268. cmdarray[i].cmdbuf = NULL;
  1269. }
  1270. }
  1271. /* Release cmd_ctrl_node */
  1272. if (priv->cmd_array) {
  1273. kfree(priv->cmd_array);
  1274. priv->cmd_array = NULL;
  1275. }
  1276. done:
  1277. lbs_deb_leave(LBS_DEB_HOST);
  1278. return 0;
  1279. }
  1280. /**
  1281. * @brief This function gets a free command node if available in
  1282. * command free queue.
  1283. *
  1284. * @param priv A pointer to struct lbs_private structure
  1285. * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
  1286. */
  1287. static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
  1288. {
  1289. struct cmd_ctrl_node *tempnode;
  1290. unsigned long flags;
  1291. lbs_deb_enter(LBS_DEB_HOST);
  1292. if (!priv)
  1293. return NULL;
  1294. spin_lock_irqsave(&priv->driver_lock, flags);
  1295. if (!list_empty(&priv->cmdfreeq)) {
  1296. tempnode = list_first_entry(&priv->cmdfreeq,
  1297. struct cmd_ctrl_node, list);
  1298. list_del(&tempnode->list);
  1299. } else {
  1300. lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
  1301. tempnode = NULL;
  1302. }
  1303. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1304. lbs_deb_leave(LBS_DEB_HOST);
  1305. return tempnode;
  1306. }
  1307. /**
  1308. * @brief This function executes next command in command
  1309. * pending queue. It will put fimware back to PS mode
  1310. * if applicable.
  1311. *
  1312. * @param priv A pointer to struct lbs_private structure
  1313. * @return 0 or -1
  1314. */
  1315. int lbs_execute_next_command(struct lbs_private *priv)
  1316. {
  1317. struct cmd_ctrl_node *cmdnode = NULL;
  1318. struct cmd_header *cmd;
  1319. unsigned long flags;
  1320. int ret = 0;
  1321. /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1322. * only caller to us is lbs_thread() and we get even when a
  1323. * data packet is received */
  1324. lbs_deb_enter(LBS_DEB_THREAD);
  1325. spin_lock_irqsave(&priv->driver_lock, flags);
  1326. if (priv->cur_cmd) {
  1327. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1328. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1329. ret = -1;
  1330. goto done;
  1331. }
  1332. if (!list_empty(&priv->cmdpendingq)) {
  1333. cmdnode = list_first_entry(&priv->cmdpendingq,
  1334. struct cmd_ctrl_node, list);
  1335. }
  1336. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1337. if (cmdnode) {
  1338. cmd = cmdnode->cmdbuf;
  1339. if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
  1340. if ((priv->psstate == PS_STATE_SLEEP) ||
  1341. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1342. lbs_deb_host(
  1343. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1344. le16_to_cpu(cmd->command),
  1345. priv->psstate);
  1346. ret = -1;
  1347. goto done;
  1348. }
  1349. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1350. "0x%04x in psstate %d\n",
  1351. le16_to_cpu(cmd->command), priv->psstate);
  1352. } else if (priv->psstate != PS_STATE_FULL_POWER) {
  1353. /*
  1354. * 1. Non-PS command:
  1355. * Queue it. set needtowakeup to TRUE if current state
  1356. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1357. * 2. PS command but not Exit_PS:
  1358. * Ignore it.
  1359. * 3. PS command Exit_PS:
  1360. * Set needtowakeup to TRUE if current state is SLEEP,
  1361. * otherwise send this command down to firmware
  1362. * immediately.
  1363. */
  1364. if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
  1365. /* Prepare to send Exit PS,
  1366. * this non PS command will be sent later */
  1367. if ((priv->psstate == PS_STATE_SLEEP)
  1368. || (priv->psstate == PS_STATE_PRE_SLEEP)
  1369. ) {
  1370. /* w/ new scheme, it will not reach here.
  1371. since it is blocked in main_thread. */
  1372. priv->needtowakeup = 1;
  1373. } else
  1374. lbs_ps_wakeup(priv, 0);
  1375. ret = 0;
  1376. goto done;
  1377. } else {
  1378. /*
  1379. * PS command. Ignore it if it is not Exit_PS.
  1380. * otherwise send it down immediately.
  1381. */
  1382. struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
  1383. lbs_deb_host(
  1384. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1385. psm->action);
  1386. if (psm->action !=
  1387. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1388. lbs_deb_host(
  1389. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1390. list_del(&cmdnode->list);
  1391. spin_lock_irqsave(&priv->driver_lock, flags);
  1392. lbs_complete_command(priv, cmdnode, 0);
  1393. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1394. ret = 0;
  1395. goto done;
  1396. }
  1397. if ((priv->psstate == PS_STATE_SLEEP) ||
  1398. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1399. lbs_deb_host(
  1400. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1401. list_del(&cmdnode->list);
  1402. spin_lock_irqsave(&priv->driver_lock, flags);
  1403. lbs_complete_command(priv, cmdnode, 0);
  1404. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1405. priv->needtowakeup = 1;
  1406. ret = 0;
  1407. goto done;
  1408. }
  1409. lbs_deb_host(
  1410. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1411. }
  1412. }
  1413. list_del(&cmdnode->list);
  1414. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1415. le16_to_cpu(cmd->command));
  1416. lbs_submit_command(priv, cmdnode);
  1417. } else {
  1418. /*
  1419. * check if in power save mode, if yes, put the device back
  1420. * to PS mode
  1421. */
  1422. if ((priv->psmode != LBS802_11POWERMODECAM) &&
  1423. (priv->psstate == PS_STATE_FULL_POWER) &&
  1424. ((priv->connect_status == LBS_CONNECTED) ||
  1425. (priv->mesh_connect_status == LBS_CONNECTED))) {
  1426. if (priv->secinfo.WPAenabled ||
  1427. priv->secinfo.WPA2enabled) {
  1428. /* check for valid WPA group keys */
  1429. if (priv->wpa_mcast_key.len ||
  1430. priv->wpa_unicast_key.len) {
  1431. lbs_deb_host(
  1432. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1433. " go back to PS_SLEEP");
  1434. lbs_ps_sleep(priv, 0);
  1435. }
  1436. } else {
  1437. lbs_deb_host(
  1438. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1439. "go back to PS_SLEEP");
  1440. lbs_ps_sleep(priv, 0);
  1441. }
  1442. }
  1443. }
  1444. ret = 0;
  1445. done:
  1446. lbs_deb_leave(LBS_DEB_THREAD);
  1447. return ret;
  1448. }
  1449. void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
  1450. {
  1451. union iwreq_data iwrq;
  1452. u8 buf[50];
  1453. lbs_deb_enter(LBS_DEB_WEXT);
  1454. memset(&iwrq, 0, sizeof(union iwreq_data));
  1455. memset(buf, 0, sizeof(buf));
  1456. snprintf(buf, sizeof(buf) - 1, "%s", str);
  1457. iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
  1458. /* Send Event to upper layer */
  1459. lbs_deb_wext("event indication string %s\n", (char *)buf);
  1460. lbs_deb_wext("event indication length %d\n", iwrq.data.length);
  1461. lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
  1462. wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
  1463. lbs_deb_leave(LBS_DEB_WEXT);
  1464. }
  1465. static void lbs_send_confirmsleep(struct lbs_private *priv)
  1466. {
  1467. unsigned long flags;
  1468. int ret;
  1469. lbs_deb_enter(LBS_DEB_HOST);
  1470. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
  1471. sizeof(confirm_sleep));
  1472. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
  1473. sizeof(confirm_sleep));
  1474. if (ret) {
  1475. lbs_pr_alert("confirm_sleep failed\n");
  1476. } else {
  1477. spin_lock_irqsave(&priv->driver_lock, flags);
  1478. if (!priv->intcounter)
  1479. priv->psstate = PS_STATE_SLEEP;
  1480. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1481. }
  1482. lbs_deb_leave(LBS_DEB_HOST);
  1483. }
  1484. void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
  1485. {
  1486. lbs_deb_enter(LBS_DEB_HOST);
  1487. /*
  1488. * PS is currently supported only in Infrastructure mode
  1489. * Remove this check if it is to be supported in IBSS mode also
  1490. */
  1491. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1492. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1493. lbs_deb_leave(LBS_DEB_HOST);
  1494. }
  1495. /**
  1496. * @brief This function sends Exit_PS command to firmware.
  1497. *
  1498. * @param priv A pointer to struct lbs_private structure
  1499. * @param wait_option wait response or not
  1500. * @return n/a
  1501. */
  1502. void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
  1503. {
  1504. __le32 Localpsmode;
  1505. lbs_deb_enter(LBS_DEB_HOST);
  1506. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1507. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1508. CMD_SUBCMD_EXIT_PS,
  1509. wait_option, 0, &Localpsmode);
  1510. lbs_deb_leave(LBS_DEB_HOST);
  1511. }
  1512. /**
  1513. * @brief This function checks condition and prepares to
  1514. * send sleep confirm command to firmware if ok.
  1515. *
  1516. * @param priv A pointer to struct lbs_private structure
  1517. * @param psmode Power Saving mode
  1518. * @return n/a
  1519. */
  1520. void lbs_ps_confirm_sleep(struct lbs_private *priv)
  1521. {
  1522. unsigned long flags =0;
  1523. int allowed = 1;
  1524. lbs_deb_enter(LBS_DEB_HOST);
  1525. if (priv->dnld_sent) {
  1526. allowed = 0;
  1527. lbs_deb_host("dnld_sent was set\n");
  1528. }
  1529. spin_lock_irqsave(&priv->driver_lock, flags);
  1530. if (priv->cur_cmd) {
  1531. allowed = 0;
  1532. lbs_deb_host("cur_cmd was set\n");
  1533. }
  1534. if (priv->intcounter > 0) {
  1535. allowed = 0;
  1536. lbs_deb_host("intcounter %d\n", priv->intcounter);
  1537. }
  1538. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1539. if (allowed) {
  1540. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1541. lbs_send_confirmsleep(priv);
  1542. } else {
  1543. lbs_deb_host("sleep confirm has been delayed\n");
  1544. }
  1545. lbs_deb_leave(LBS_DEB_HOST);
  1546. }
  1547. static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
  1548. uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
  1549. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1550. unsigned long callback_arg)
  1551. {
  1552. struct cmd_ctrl_node *cmdnode;
  1553. lbs_deb_enter(LBS_DEB_HOST);
  1554. if (priv->surpriseremoved) {
  1555. lbs_deb_host("PREP_CMD: card removed\n");
  1556. cmdnode = ERR_PTR(-ENOENT);
  1557. goto done;
  1558. }
  1559. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1560. if (cmdnode == NULL) {
  1561. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1562. /* Wake up main thread to execute next command */
  1563. wake_up_interruptible(&priv->waitq);
  1564. cmdnode = ERR_PTR(-ENOBUFS);
  1565. goto done;
  1566. }
  1567. cmdnode->callback = callback;
  1568. cmdnode->callback_arg = callback_arg;
  1569. /* Copy the incoming command to the buffer */
  1570. memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
  1571. /* Set sequence number, clean result, move to buffer */
  1572. priv->seqnum++;
  1573. cmdnode->cmdbuf->command = cpu_to_le16(command);
  1574. cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
  1575. cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
  1576. cmdnode->cmdbuf->result = 0;
  1577. lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
  1578. cmdnode->cmdwaitqwoken = 0;
  1579. lbs_queue_cmd(priv, cmdnode);
  1580. wake_up_interruptible(&priv->waitq);
  1581. done:
  1582. lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
  1583. return cmdnode;
  1584. }
  1585. void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
  1586. struct cmd_header *in_cmd, int in_cmd_size)
  1587. {
  1588. lbs_deb_enter(LBS_DEB_CMD);
  1589. __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1590. lbs_cmd_async_callback, 0);
  1591. lbs_deb_leave(LBS_DEB_CMD);
  1592. }
  1593. int __lbs_cmd(struct lbs_private *priv, uint16_t command,
  1594. struct cmd_header *in_cmd, int in_cmd_size,
  1595. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1596. unsigned long callback_arg)
  1597. {
  1598. struct cmd_ctrl_node *cmdnode;
  1599. unsigned long flags;
  1600. int ret = 0;
  1601. lbs_deb_enter(LBS_DEB_HOST);
  1602. cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1603. callback, callback_arg);
  1604. if (IS_ERR(cmdnode)) {
  1605. ret = PTR_ERR(cmdnode);
  1606. goto done;
  1607. }
  1608. might_sleep();
  1609. wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
  1610. spin_lock_irqsave(&priv->driver_lock, flags);
  1611. ret = cmdnode->result;
  1612. if (ret)
  1613. lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
  1614. command, ret);
  1615. __lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1616. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1617. done:
  1618. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1619. return ret;
  1620. }
  1621. EXPORT_SYMBOL_GPL(__lbs_cmd);