cmd.c 58 KB

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