cmd.c 58 KB

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