cmd.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232
  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 struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
  15. static void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
  16. struct cmd_ctrl_node *ptempnode,
  17. void *pdata_buf);
  18. /**
  19. * @brief Checks whether a command is allowed in Power Save mode
  20. *
  21. * @param command the command ID
  22. * @return 1 if allowed, 0 if not allowed
  23. */
  24. static u8 is_command_allowed_in_ps(u16 cmd)
  25. {
  26. switch (cmd) {
  27. case CMD_802_11_RSSI:
  28. return 1;
  29. default:
  30. break;
  31. }
  32. return 0;
  33. }
  34. /**
  35. * @brief Updates the hardware details like MAC address and regulatory region
  36. *
  37. * @param priv A pointer to struct lbs_private structure
  38. *
  39. * @return 0 on success, error on failure
  40. */
  41. int lbs_update_hw_spec(struct lbs_private *priv)
  42. {
  43. struct cmd_ds_get_hw_spec cmd;
  44. int ret = -1;
  45. u32 i;
  46. DECLARE_MAC_BUF(mac);
  47. lbs_deb_enter(LBS_DEB_CMD);
  48. memset(&cmd, 0, sizeof(cmd));
  49. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  50. memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
  51. ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
  52. if (ret)
  53. goto out;
  54. priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
  55. memcpy(priv->fwreleasenumber, cmd.fwreleasenumber, 4);
  56. lbs_deb_cmd("GET_HW_SPEC: firmware release %u.%u.%up%u\n",
  57. priv->fwreleasenumber[2], priv->fwreleasenumber[1],
  58. priv->fwreleasenumber[0], priv->fwreleasenumber[3]);
  59. lbs_deb_cmd("GET_HW_SPEC: MAC addr %s\n",
  60. print_mac(mac, cmd.permanentaddr));
  61. lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
  62. cmd.hwifversion, cmd.version);
  63. /* Clamp region code to 8-bit since FW spec indicates that it should
  64. * only ever be 8-bit, even though the field size is 16-bit. Some firmware
  65. * returns non-zero high 8 bits here.
  66. */
  67. priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
  68. for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
  69. /* use the region code to search for the index */
  70. if (priv->regioncode == lbs_region_code_to_index[i])
  71. break;
  72. }
  73. /* if it's unidentified region code, use the default (USA) */
  74. if (i >= MRVDRV_MAX_REGION_CODE) {
  75. priv->regioncode = 0x10;
  76. lbs_pr_info("unidentified region code; using the default (USA)\n");
  77. }
  78. if (priv->current_addr[0] == 0xff)
  79. memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
  80. memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
  81. if (priv->mesh_dev)
  82. memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
  83. if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
  84. ret = -1;
  85. goto out;
  86. }
  87. if (lbs_set_universaltable(priv, 0)) {
  88. ret = -1;
  89. goto out;
  90. }
  91. out:
  92. lbs_deb_leave(LBS_DEB_CMD);
  93. return ret;
  94. }
  95. int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria)
  96. {
  97. struct cmd_ds_host_sleep cmd_config;
  98. int ret;
  99. cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
  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(*cmd));
  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. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  911. if (enable) {
  912. cmd.length = cpu_to_le16(priv->mesh_ssid_len);
  913. memcpy(cmd.data, priv->mesh_ssid, priv->mesh_ssid_len);
  914. }
  915. lbs_deb_cmd("mesh config enable %d TLV %x channel %d SSID %s\n",
  916. enable, priv->mesh_tlv, chan,
  917. escape_essid(priv->mesh_ssid, priv->mesh_ssid_len));
  918. return lbs_cmd_with_response(priv, CMD_MESH_CONFIG, &cmd);
  919. }
  920. static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
  921. struct cmd_ds_command *cmd,
  922. u16 cmd_action)
  923. {
  924. struct cmd_ds_802_11_beacon_control
  925. *bcn_ctrl = &cmd->params.bcn_ctrl;
  926. lbs_deb_enter(LBS_DEB_CMD);
  927. cmd->size =
  928. cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
  929. + S_DS_GEN);
  930. cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
  931. bcn_ctrl->action = cpu_to_le16(cmd_action);
  932. bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
  933. bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
  934. lbs_deb_leave(LBS_DEB_CMD);
  935. return 0;
  936. }
  937. /*
  938. * Note: NEVER use lbs_queue_cmd() with addtail==0 other than for
  939. * the command timer, because it does not account for queued commands.
  940. */
  941. void lbs_queue_cmd(struct lbs_private *priv,
  942. struct cmd_ctrl_node *cmdnode,
  943. u8 addtail)
  944. {
  945. unsigned long flags;
  946. lbs_deb_enter(LBS_DEB_HOST);
  947. if (!cmdnode) {
  948. lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
  949. goto done;
  950. }
  951. if (!cmdnode->cmdbuf->size) {
  952. lbs_deb_host("DNLD_CMD: cmd size is zero\n");
  953. goto done;
  954. }
  955. cmdnode->result = 0;
  956. /* Exit_PS command needs to be queued in the header always. */
  957. if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
  958. struct cmd_ds_802_11_ps_mode *psm = (void *) cmdnode->cmdbuf;
  959. if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  960. if (priv->psstate != PS_STATE_FULL_POWER)
  961. addtail = 0;
  962. }
  963. }
  964. spin_lock_irqsave(&priv->driver_lock, flags);
  965. if (addtail)
  966. list_add_tail(&cmdnode->list, &priv->cmdpendingq);
  967. else
  968. list_add(&cmdnode->list, &priv->cmdpendingq);
  969. spin_unlock_irqrestore(&priv->driver_lock, flags);
  970. lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
  971. le16_to_cpu(cmdnode->cmdbuf->command));
  972. done:
  973. lbs_deb_leave(LBS_DEB_HOST);
  974. }
  975. static int lbs_submit_command(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. cmd = cmdnode->cmdbuf;
  985. spin_lock_irqsave(&priv->driver_lock, flags);
  986. priv->cur_cmd = cmdnode;
  987. priv->cur_cmd_retcode = 0;
  988. spin_unlock_irqrestore(&priv->driver_lock, flags);
  989. cmdsize = le16_to_cpu(cmd->size);
  990. command = le16_to_cpu(cmd->command);
  991. lbs_deb_host("DNLD_CMD: command 0x%04x, seq %d, size %d, jiffies %lu\n",
  992. command, le16_to_cpu(cmd->seqnum), cmdsize, jiffies);
  993. lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
  994. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
  995. if (ret) {
  996. lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
  997. spin_lock_irqsave(&priv->driver_lock, flags);
  998. lbs_complete_command(priv, priv->cur_cmd, ret);
  999. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1000. goto done;
  1001. }
  1002. lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
  1003. /* Setup the timer after transmit command */
  1004. if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
  1005. || command == CMD_802_11_ASSOCIATE)
  1006. mod_timer(&priv->command_timer, jiffies + (10*HZ));
  1007. else
  1008. mod_timer(&priv->command_timer, jiffies + (5*HZ));
  1009. ret = 0;
  1010. done:
  1011. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1012. return ret;
  1013. }
  1014. static int lbs_cmd_mac_control(struct lbs_private *priv,
  1015. struct cmd_ds_command *cmd)
  1016. {
  1017. struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
  1018. lbs_deb_enter(LBS_DEB_CMD);
  1019. cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
  1020. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
  1021. mac->action = cpu_to_le16(priv->currentpacketfilter);
  1022. lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
  1023. le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
  1024. lbs_deb_leave(LBS_DEB_CMD);
  1025. return 0;
  1026. }
  1027. /**
  1028. * This function inserts command node to cmdfreeq
  1029. * after cleans it. Requires priv->driver_lock held.
  1030. */
  1031. static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  1032. struct cmd_ctrl_node *cmdnode)
  1033. {
  1034. lbs_deb_enter(LBS_DEB_HOST);
  1035. if (!cmdnode)
  1036. goto out;
  1037. cmdnode->callback = NULL;
  1038. cmdnode->callback_arg = 0;
  1039. memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
  1040. list_add_tail(&cmdnode->list, &priv->cmdfreeq);
  1041. out:
  1042. lbs_deb_leave(LBS_DEB_HOST);
  1043. }
  1044. static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  1045. struct cmd_ctrl_node *ptempcmd)
  1046. {
  1047. unsigned long flags;
  1048. spin_lock_irqsave(&priv->driver_lock, flags);
  1049. __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
  1050. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1051. }
  1052. void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
  1053. int result)
  1054. {
  1055. if (cmd == priv->cur_cmd)
  1056. priv->cur_cmd_retcode = result;
  1057. cmd->result = result;
  1058. cmd->cmdwaitqwoken = 1;
  1059. wake_up_interruptible(&cmd->cmdwait_q);
  1060. if (!cmd->callback)
  1061. __lbs_cleanup_and_insert_cmd(priv, cmd);
  1062. priv->cur_cmd = NULL;
  1063. }
  1064. int lbs_set_radio_control(struct lbs_private *priv)
  1065. {
  1066. int ret = 0;
  1067. lbs_deb_enter(LBS_DEB_CMD);
  1068. ret = lbs_prepare_and_send_command(priv,
  1069. CMD_802_11_RADIO_CONTROL,
  1070. CMD_ACT_SET,
  1071. CMD_OPTION_WAITFORRSP, 0, NULL);
  1072. lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
  1073. priv->radioon, priv->preamble);
  1074. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  1075. return ret;
  1076. }
  1077. int lbs_set_mac_packet_filter(struct lbs_private *priv)
  1078. {
  1079. int ret = 0;
  1080. lbs_deb_enter(LBS_DEB_CMD);
  1081. /* Send MAC control command to station */
  1082. ret = lbs_prepare_and_send_command(priv,
  1083. CMD_MAC_CONTROL, 0, 0, 0, NULL);
  1084. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  1085. return ret;
  1086. }
  1087. /**
  1088. * @brief This function prepare the command before send to firmware.
  1089. *
  1090. * @param priv A pointer to struct lbs_private structure
  1091. * @param cmd_no command number
  1092. * @param cmd_action command action: GET or SET
  1093. * @param wait_option wait option: wait response or not
  1094. * @param cmd_oid cmd oid: treated as sub command
  1095. * @param pdata_buf A pointer to informaion buffer
  1096. * @return 0 or -1
  1097. */
  1098. int lbs_prepare_and_send_command(struct lbs_private *priv,
  1099. u16 cmd_no,
  1100. u16 cmd_action,
  1101. u16 wait_option, u32 cmd_oid, void *pdata_buf)
  1102. {
  1103. int ret = 0;
  1104. struct cmd_ctrl_node *cmdnode;
  1105. struct cmd_ds_command *cmdptr;
  1106. unsigned long flags;
  1107. lbs_deb_enter(LBS_DEB_HOST);
  1108. if (!priv) {
  1109. lbs_deb_host("PREP_CMD: priv is NULL\n");
  1110. ret = -1;
  1111. goto done;
  1112. }
  1113. if (priv->surpriseremoved) {
  1114. lbs_deb_host("PREP_CMD: card removed\n");
  1115. ret = -1;
  1116. goto done;
  1117. }
  1118. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1119. if (cmdnode == NULL) {
  1120. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1121. /* Wake up main thread to execute next command */
  1122. wake_up_interruptible(&priv->waitq);
  1123. ret = -1;
  1124. goto done;
  1125. }
  1126. lbs_set_cmd_ctrl_node(priv, cmdnode, pdata_buf);
  1127. cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
  1128. lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
  1129. /* Set sequence number, command and INT option */
  1130. priv->seqnum++;
  1131. cmdptr->seqnum = cpu_to_le16(priv->seqnum);
  1132. cmdptr->command = cpu_to_le16(cmd_no);
  1133. cmdptr->result = 0;
  1134. switch (cmd_no) {
  1135. case CMD_802_11_PS_MODE:
  1136. ret = lbs_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
  1137. break;
  1138. case CMD_802_11_SCAN:
  1139. ret = lbs_cmd_80211_scan(priv, cmdptr, pdata_buf);
  1140. break;
  1141. case CMD_MAC_CONTROL:
  1142. ret = lbs_cmd_mac_control(priv, cmdptr);
  1143. break;
  1144. case CMD_802_11_ASSOCIATE:
  1145. case CMD_802_11_REASSOCIATE:
  1146. ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
  1147. break;
  1148. case CMD_802_11_DEAUTHENTICATE:
  1149. ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
  1150. break;
  1151. case CMD_802_11_SET_WEP:
  1152. ret = lbs_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
  1153. break;
  1154. case CMD_802_11_AD_HOC_START:
  1155. ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
  1156. break;
  1157. case CMD_CODE_DNLD:
  1158. break;
  1159. case CMD_802_11_RESET:
  1160. ret = lbs_cmd_802_11_reset(priv, cmdptr, cmd_action);
  1161. break;
  1162. case CMD_802_11_GET_LOG:
  1163. ret = lbs_cmd_802_11_get_log(priv, cmdptr);
  1164. break;
  1165. case CMD_802_11_AUTHENTICATE:
  1166. ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
  1167. break;
  1168. case CMD_802_11_GET_STAT:
  1169. ret = lbs_cmd_802_11_get_stat(priv, cmdptr);
  1170. break;
  1171. case CMD_802_11_SNMP_MIB:
  1172. ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
  1173. cmd_action, cmd_oid, pdata_buf);
  1174. break;
  1175. case CMD_MAC_REG_ACCESS:
  1176. case CMD_BBP_REG_ACCESS:
  1177. case CMD_RF_REG_ACCESS:
  1178. ret = lbs_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
  1179. break;
  1180. case CMD_802_11_RF_TX_POWER:
  1181. ret = lbs_cmd_802_11_rf_tx_power(priv, cmdptr,
  1182. cmd_action, pdata_buf);
  1183. break;
  1184. case CMD_802_11_RADIO_CONTROL:
  1185. ret = lbs_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
  1186. break;
  1187. case CMD_802_11_RATE_ADAPT_RATESET:
  1188. ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
  1189. cmdptr, cmd_action);
  1190. break;
  1191. case CMD_MAC_MULTICAST_ADR:
  1192. ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
  1193. break;
  1194. case CMD_802_11_MONITOR_MODE:
  1195. ret = lbs_cmd_802_11_monitor_mode(priv, cmdptr,
  1196. cmd_action, pdata_buf);
  1197. break;
  1198. case CMD_802_11_AD_HOC_JOIN:
  1199. ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
  1200. break;
  1201. case CMD_802_11_RSSI:
  1202. ret = lbs_cmd_802_11_rssi(priv, cmdptr);
  1203. break;
  1204. case CMD_802_11_AD_HOC_STOP:
  1205. ret = lbs_cmd_80211_ad_hoc_stop(priv, cmdptr);
  1206. break;
  1207. case CMD_802_11_ENABLE_RSN:
  1208. ret = lbs_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
  1209. pdata_buf);
  1210. break;
  1211. case CMD_802_11_KEY_MATERIAL:
  1212. ret = lbs_cmd_802_11_key_material(priv, cmdptr, cmd_action,
  1213. cmd_oid, pdata_buf);
  1214. break;
  1215. case CMD_802_11_PAIRWISE_TSC:
  1216. break;
  1217. case CMD_802_11_GROUP_TSC:
  1218. break;
  1219. case CMD_802_11_MAC_ADDRESS:
  1220. ret = lbs_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
  1221. break;
  1222. case CMD_802_11_EEPROM_ACCESS:
  1223. ret = lbs_cmd_802_11_eeprom_access(priv, cmdptr,
  1224. cmd_action, pdata_buf);
  1225. break;
  1226. case CMD_802_11_SET_AFC:
  1227. case CMD_802_11_GET_AFC:
  1228. cmdptr->command = cpu_to_le16(cmd_no);
  1229. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
  1230. S_DS_GEN);
  1231. memmove(&cmdptr->params.afc,
  1232. pdata_buf, sizeof(struct cmd_ds_802_11_afc));
  1233. ret = 0;
  1234. goto done;
  1235. case CMD_802_11D_DOMAIN_INFO:
  1236. ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
  1237. cmd_no, cmd_action);
  1238. break;
  1239. case CMD_802_11_SLEEP_PARAMS:
  1240. ret = lbs_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
  1241. break;
  1242. case CMD_802_11_INACTIVITY_TIMEOUT:
  1243. ret = lbs_cmd_802_11_inactivity_timeout(priv, cmdptr,
  1244. cmd_action, pdata_buf);
  1245. lbs_set_cmd_ctrl_node(priv, cmdnode, pdata_buf);
  1246. break;
  1247. case CMD_802_11_TPC_CFG:
  1248. cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
  1249. cmdptr->size =
  1250. cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
  1251. S_DS_GEN);
  1252. memmove(&cmdptr->params.tpccfg,
  1253. pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
  1254. ret = 0;
  1255. break;
  1256. case CMD_802_11_LED_GPIO_CTRL:
  1257. {
  1258. struct mrvlietypes_ledgpio *gpio =
  1259. (struct mrvlietypes_ledgpio*)
  1260. cmdptr->params.ledgpio.data;
  1261. memmove(&cmdptr->params.ledgpio,
  1262. pdata_buf,
  1263. sizeof(struct cmd_ds_802_11_led_ctrl));
  1264. cmdptr->command =
  1265. cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
  1266. #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
  1267. cmdptr->size =
  1268. cpu_to_le16(le16_to_cpu(gpio->header.len)
  1269. + S_DS_GEN
  1270. + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
  1271. gpio->header.len = gpio->header.len;
  1272. ret = 0;
  1273. break;
  1274. }
  1275. case CMD_802_11_SUBSCRIBE_EVENT:
  1276. lbs_cmd_802_11_subscribe_event(priv, cmdptr,
  1277. cmd_action, pdata_buf);
  1278. break;
  1279. case CMD_802_11_PWR_CFG:
  1280. cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG);
  1281. cmdptr->size =
  1282. cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
  1283. S_DS_GEN);
  1284. memmove(&cmdptr->params.pwrcfg, pdata_buf,
  1285. sizeof(struct cmd_ds_802_11_pwr_cfg));
  1286. ret = 0;
  1287. break;
  1288. case CMD_BT_ACCESS:
  1289. ret = lbs_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
  1290. break;
  1291. case CMD_FWT_ACCESS:
  1292. ret = lbs_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
  1293. break;
  1294. case CMD_GET_TSF:
  1295. cmdptr->command = cpu_to_le16(CMD_GET_TSF);
  1296. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
  1297. S_DS_GEN);
  1298. ret = 0;
  1299. break;
  1300. case CMD_802_11_BEACON_CTRL:
  1301. ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
  1302. break;
  1303. default:
  1304. lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
  1305. ret = -1;
  1306. break;
  1307. }
  1308. /* return error, since the command preparation failed */
  1309. if (ret != 0) {
  1310. lbs_deb_host("PREP_CMD: command preparation failed\n");
  1311. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1312. ret = -1;
  1313. goto done;
  1314. }
  1315. cmdnode->cmdwaitqwoken = 0;
  1316. lbs_queue_cmd(priv, cmdnode, 1);
  1317. wake_up_interruptible(&priv->waitq);
  1318. if (wait_option & CMD_OPTION_WAITFORRSP) {
  1319. lbs_deb_host("PREP_CMD: wait for response\n");
  1320. might_sleep();
  1321. wait_event_interruptible(cmdnode->cmdwait_q,
  1322. cmdnode->cmdwaitqwoken);
  1323. }
  1324. spin_lock_irqsave(&priv->driver_lock, flags);
  1325. if (priv->cur_cmd_retcode) {
  1326. lbs_deb_host("PREP_CMD: command failed with return code %d\n",
  1327. priv->cur_cmd_retcode);
  1328. priv->cur_cmd_retcode = 0;
  1329. ret = -1;
  1330. }
  1331. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1332. done:
  1333. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1334. return ret;
  1335. }
  1336. EXPORT_SYMBOL_GPL(lbs_prepare_and_send_command);
  1337. /**
  1338. * @brief This function allocates the command buffer and link
  1339. * it to command free queue.
  1340. *
  1341. * @param priv A pointer to struct lbs_private structure
  1342. * @return 0 or -1
  1343. */
  1344. int lbs_allocate_cmd_buffer(struct lbs_private *priv)
  1345. {
  1346. int ret = 0;
  1347. u32 bufsize;
  1348. u32 i;
  1349. struct cmd_ctrl_node *cmdarray;
  1350. lbs_deb_enter(LBS_DEB_HOST);
  1351. /* Allocate and initialize the command array */
  1352. bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
  1353. if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
  1354. lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
  1355. ret = -1;
  1356. goto done;
  1357. }
  1358. priv->cmd_array = cmdarray;
  1359. /* Allocate and initialize each command buffer in the command array */
  1360. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1361. cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
  1362. if (!cmdarray[i].cmdbuf) {
  1363. lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
  1364. ret = -1;
  1365. goto done;
  1366. }
  1367. }
  1368. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1369. init_waitqueue_head(&cmdarray[i].cmdwait_q);
  1370. lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
  1371. }
  1372. ret = 0;
  1373. done:
  1374. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1375. return ret;
  1376. }
  1377. /**
  1378. * @brief This function frees the command buffer.
  1379. *
  1380. * @param priv A pointer to struct lbs_private structure
  1381. * @return 0 or -1
  1382. */
  1383. int lbs_free_cmd_buffer(struct lbs_private *priv)
  1384. {
  1385. struct cmd_ctrl_node *cmdarray;
  1386. unsigned int i;
  1387. lbs_deb_enter(LBS_DEB_HOST);
  1388. /* need to check if cmd array is allocated or not */
  1389. if (priv->cmd_array == NULL) {
  1390. lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
  1391. goto done;
  1392. }
  1393. cmdarray = priv->cmd_array;
  1394. /* Release shared memory buffers */
  1395. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1396. if (cmdarray[i].cmdbuf) {
  1397. kfree(cmdarray[i].cmdbuf);
  1398. cmdarray[i].cmdbuf = NULL;
  1399. }
  1400. }
  1401. /* Release cmd_ctrl_node */
  1402. if (priv->cmd_array) {
  1403. kfree(priv->cmd_array);
  1404. priv->cmd_array = NULL;
  1405. }
  1406. done:
  1407. lbs_deb_leave(LBS_DEB_HOST);
  1408. return 0;
  1409. }
  1410. /**
  1411. * @brief This function gets a free command node if available in
  1412. * command free queue.
  1413. *
  1414. * @param priv A pointer to struct lbs_private structure
  1415. * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
  1416. */
  1417. static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
  1418. {
  1419. struct cmd_ctrl_node *tempnode;
  1420. unsigned long flags;
  1421. lbs_deb_enter(LBS_DEB_HOST);
  1422. if (!priv)
  1423. return NULL;
  1424. spin_lock_irqsave(&priv->driver_lock, flags);
  1425. if (!list_empty(&priv->cmdfreeq)) {
  1426. tempnode = list_first_entry(&priv->cmdfreeq,
  1427. struct cmd_ctrl_node, list);
  1428. list_del(&tempnode->list);
  1429. } else {
  1430. lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
  1431. tempnode = NULL;
  1432. }
  1433. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1434. lbs_deb_leave(LBS_DEB_HOST);
  1435. return tempnode;
  1436. }
  1437. /**
  1438. * @brief This function cleans command node.
  1439. *
  1440. * @param ptempnode A pointer to cmdCtrlNode structure
  1441. * @return n/a
  1442. */
  1443. /**
  1444. * @brief This function initializes the command node.
  1445. *
  1446. * @param priv A pointer to struct lbs_private structure
  1447. * @param ptempnode A pointer to cmd_ctrl_node structure
  1448. * @param pdata_buf A pointer to informaion buffer
  1449. * @return 0 or -1
  1450. */
  1451. static void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
  1452. struct cmd_ctrl_node *ptempnode,
  1453. void *pdata_buf)
  1454. {
  1455. lbs_deb_enter(LBS_DEB_HOST);
  1456. if (!ptempnode)
  1457. return;
  1458. ptempnode->callback = NULL;
  1459. ptempnode->callback_arg = (unsigned long)pdata_buf;
  1460. lbs_deb_leave(LBS_DEB_HOST);
  1461. }
  1462. /**
  1463. * @brief This function executes next command in command
  1464. * pending queue. It will put fimware back to PS mode
  1465. * if applicable.
  1466. *
  1467. * @param priv A pointer to struct lbs_private structure
  1468. * @return 0 or -1
  1469. */
  1470. int lbs_execute_next_command(struct lbs_private *priv)
  1471. {
  1472. struct cmd_ctrl_node *cmdnode = NULL;
  1473. struct cmd_header *cmd;
  1474. unsigned long flags;
  1475. int ret = 0;
  1476. // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1477. // only caller to us is lbs_thread() and we get even when a
  1478. // data packet is received
  1479. lbs_deb_enter(LBS_DEB_THREAD);
  1480. spin_lock_irqsave(&priv->driver_lock, flags);
  1481. if (priv->cur_cmd) {
  1482. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1483. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1484. ret = -1;
  1485. goto done;
  1486. }
  1487. if (!list_empty(&priv->cmdpendingq)) {
  1488. cmdnode = list_first_entry(&priv->cmdpendingq,
  1489. struct cmd_ctrl_node, list);
  1490. }
  1491. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1492. if (cmdnode) {
  1493. cmd = cmdnode->cmdbuf;
  1494. if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
  1495. if ((priv->psstate == PS_STATE_SLEEP) ||
  1496. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1497. lbs_deb_host(
  1498. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1499. le16_to_cpu(cmd->command),
  1500. priv->psstate);
  1501. ret = -1;
  1502. goto done;
  1503. }
  1504. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1505. "0x%04x in psstate %d\n",
  1506. le16_to_cpu(cmd->command), priv->psstate);
  1507. } else if (priv->psstate != PS_STATE_FULL_POWER) {
  1508. /*
  1509. * 1. Non-PS command:
  1510. * Queue it. set needtowakeup to TRUE if current state
  1511. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1512. * 2. PS command but not Exit_PS:
  1513. * Ignore it.
  1514. * 3. PS command Exit_PS:
  1515. * Set needtowakeup to TRUE if current state is SLEEP,
  1516. * otherwise send this command down to firmware
  1517. * immediately.
  1518. */
  1519. if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
  1520. /* Prepare to send Exit PS,
  1521. * this non PS command will be sent later */
  1522. if ((priv->psstate == PS_STATE_SLEEP)
  1523. || (priv->psstate == PS_STATE_PRE_SLEEP)
  1524. ) {
  1525. /* w/ new scheme, it will not reach here.
  1526. since it is blocked in main_thread. */
  1527. priv->needtowakeup = 1;
  1528. } else
  1529. lbs_ps_wakeup(priv, 0);
  1530. ret = 0;
  1531. goto done;
  1532. } else {
  1533. /*
  1534. * PS command. Ignore it if it is not Exit_PS.
  1535. * otherwise send it down immediately.
  1536. */
  1537. struct cmd_ds_802_11_ps_mode *psm = (void *)cmd;
  1538. lbs_deb_host(
  1539. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1540. psm->action);
  1541. if (psm->action !=
  1542. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1543. lbs_deb_host(
  1544. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1545. list_del(&cmdnode->list);
  1546. spin_lock_irqsave(&priv->driver_lock, flags);
  1547. lbs_complete_command(priv, cmdnode, 0);
  1548. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1549. ret = 0;
  1550. goto done;
  1551. }
  1552. if ((priv->psstate == PS_STATE_SLEEP) ||
  1553. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1554. lbs_deb_host(
  1555. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1556. list_del(&cmdnode->list);
  1557. spin_lock_irqsave(&priv->driver_lock, flags);
  1558. lbs_complete_command(priv, cmdnode, 0);
  1559. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1560. priv->needtowakeup = 1;
  1561. ret = 0;
  1562. goto done;
  1563. }
  1564. lbs_deb_host(
  1565. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1566. }
  1567. }
  1568. list_del(&cmdnode->list);
  1569. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1570. le16_to_cpu(cmd->command));
  1571. lbs_submit_command(priv, cmdnode);
  1572. } else {
  1573. /*
  1574. * check if in power save mode, if yes, put the device back
  1575. * to PS mode
  1576. */
  1577. if ((priv->psmode != LBS802_11POWERMODECAM) &&
  1578. (priv->psstate == PS_STATE_FULL_POWER) &&
  1579. ((priv->connect_status == LBS_CONNECTED) ||
  1580. (priv->mesh_connect_status == LBS_CONNECTED))) {
  1581. if (priv->secinfo.WPAenabled ||
  1582. priv->secinfo.WPA2enabled) {
  1583. /* check for valid WPA group keys */
  1584. if (priv->wpa_mcast_key.len ||
  1585. priv->wpa_unicast_key.len) {
  1586. lbs_deb_host(
  1587. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1588. " go back to PS_SLEEP");
  1589. lbs_ps_sleep(priv, 0);
  1590. }
  1591. } else {
  1592. lbs_deb_host(
  1593. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1594. "go back to PS_SLEEP");
  1595. lbs_ps_sleep(priv, 0);
  1596. }
  1597. }
  1598. }
  1599. ret = 0;
  1600. done:
  1601. lbs_deb_leave(LBS_DEB_THREAD);
  1602. return ret;
  1603. }
  1604. void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
  1605. {
  1606. union iwreq_data iwrq;
  1607. u8 buf[50];
  1608. lbs_deb_enter(LBS_DEB_WEXT);
  1609. memset(&iwrq, 0, sizeof(union iwreq_data));
  1610. memset(buf, 0, sizeof(buf));
  1611. snprintf(buf, sizeof(buf) - 1, "%s", str);
  1612. iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
  1613. /* Send Event to upper layer */
  1614. lbs_deb_wext("event indication string %s\n", (char *)buf);
  1615. lbs_deb_wext("event indication length %d\n", iwrq.data.length);
  1616. lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
  1617. wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
  1618. lbs_deb_leave(LBS_DEB_WEXT);
  1619. }
  1620. static int sendconfirmsleep(struct lbs_private *priv, u8 *cmdptr, u16 size)
  1621. {
  1622. unsigned long flags;
  1623. int ret = 0;
  1624. lbs_deb_enter(LBS_DEB_HOST);
  1625. lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
  1626. size);
  1627. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
  1628. ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
  1629. priv->dnld_sent = DNLD_RES_RECEIVED;
  1630. spin_lock_irqsave(&priv->driver_lock, flags);
  1631. if (priv->intcounter || priv->currenttxskb)
  1632. lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
  1633. priv->intcounter, priv->currenttxskb);
  1634. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1635. if (ret) {
  1636. lbs_pr_alert(
  1637. "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
  1638. } else {
  1639. spin_lock_irqsave(&priv->driver_lock, flags);
  1640. if (!priv->intcounter) {
  1641. priv->psstate = PS_STATE_SLEEP;
  1642. } else {
  1643. lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
  1644. priv->intcounter);
  1645. }
  1646. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1647. lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
  1648. }
  1649. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1650. return ret;
  1651. }
  1652. void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
  1653. {
  1654. lbs_deb_enter(LBS_DEB_HOST);
  1655. /*
  1656. * PS is currently supported only in Infrastructure mode
  1657. * Remove this check if it is to be supported in IBSS mode also
  1658. */
  1659. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1660. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1661. lbs_deb_leave(LBS_DEB_HOST);
  1662. }
  1663. /**
  1664. * @brief This function sends Exit_PS command to firmware.
  1665. *
  1666. * @param priv A pointer to struct lbs_private structure
  1667. * @param wait_option wait response or not
  1668. * @return n/a
  1669. */
  1670. void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
  1671. {
  1672. __le32 Localpsmode;
  1673. lbs_deb_enter(LBS_DEB_HOST);
  1674. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1675. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1676. CMD_SUBCMD_EXIT_PS,
  1677. wait_option, 0, &Localpsmode);
  1678. lbs_deb_leave(LBS_DEB_HOST);
  1679. }
  1680. /**
  1681. * @brief This function checks condition and prepares to
  1682. * send sleep confirm command to firmware if ok.
  1683. *
  1684. * @param priv A pointer to struct lbs_private structure
  1685. * @param psmode Power Saving mode
  1686. * @return n/a
  1687. */
  1688. void lbs_ps_confirm_sleep(struct lbs_private *priv, u16 psmode)
  1689. {
  1690. unsigned long flags =0;
  1691. u8 allowed = 1;
  1692. lbs_deb_enter(LBS_DEB_HOST);
  1693. if (priv->dnld_sent) {
  1694. allowed = 0;
  1695. lbs_deb_host("dnld_sent was set\n");
  1696. }
  1697. spin_lock_irqsave(&priv->driver_lock, flags);
  1698. if (priv->cur_cmd) {
  1699. allowed = 0;
  1700. lbs_deb_host("cur_cmd was set\n");
  1701. }
  1702. if (priv->intcounter > 0) {
  1703. allowed = 0;
  1704. lbs_deb_host("intcounter %d\n", priv->intcounter);
  1705. }
  1706. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1707. if (allowed) {
  1708. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1709. sendconfirmsleep(priv, (u8 *) & priv->lbs_ps_confirm_sleep,
  1710. sizeof(struct PS_CMD_ConfirmSleep));
  1711. } else {
  1712. lbs_deb_host("sleep confirm has been delayed\n");
  1713. }
  1714. lbs_deb_leave(LBS_DEB_HOST);
  1715. }
  1716. /**
  1717. * @brief Simple callback that copies response back into command
  1718. *
  1719. * @param priv A pointer to struct lbs_private structure
  1720. * @param extra A pointer to the original command structure for which
  1721. * 'resp' is a response
  1722. * @param resp A pointer to the command response
  1723. *
  1724. * @return 0 on success, error on failure
  1725. */
  1726. int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
  1727. struct cmd_header *resp)
  1728. {
  1729. struct cmd_header *buf = (void *)extra;
  1730. uint16_t copy_len;
  1731. lbs_deb_enter(LBS_DEB_CMD);
  1732. copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
  1733. lbs_deb_cmd("Copying back %u bytes; command response was %u bytes, "
  1734. "copy back buffer was %u bytes\n", copy_len,
  1735. le16_to_cpu(resp->size), le16_to_cpu(buf->size));
  1736. memcpy(buf, resp, copy_len);
  1737. lbs_deb_leave(LBS_DEB_CMD);
  1738. return 0;
  1739. }
  1740. EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
  1741. struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv, uint16_t command,
  1742. struct cmd_header *in_cmd, int in_cmd_size,
  1743. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1744. unsigned long callback_arg)
  1745. {
  1746. struct cmd_ctrl_node *cmdnode;
  1747. lbs_deb_enter(LBS_DEB_HOST);
  1748. if (priv->surpriseremoved) {
  1749. lbs_deb_host("PREP_CMD: card removed\n");
  1750. cmdnode = ERR_PTR(-ENOENT);
  1751. goto done;
  1752. }
  1753. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1754. if (cmdnode == NULL) {
  1755. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1756. /* Wake up main thread to execute next command */
  1757. wake_up_interruptible(&priv->waitq);
  1758. cmdnode = ERR_PTR(-ENOBUFS);
  1759. goto done;
  1760. }
  1761. cmdnode->callback = callback;
  1762. cmdnode->callback_arg = callback_arg;
  1763. /* Copy the incoming command to the buffer */
  1764. memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
  1765. /* Set sequence number, clean result, move to buffer */
  1766. priv->seqnum++;
  1767. cmdnode->cmdbuf->command = cpu_to_le16(command);
  1768. cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
  1769. cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
  1770. cmdnode->cmdbuf->result = 0;
  1771. lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
  1772. /* here was the big old switch() statement, which is now obsolete,
  1773. * because the caller of lbs_cmd() sets up all of *cmd for us. */
  1774. cmdnode->cmdwaitqwoken = 0;
  1775. lbs_queue_cmd(priv, cmdnode, 1);
  1776. wake_up_interruptible(&priv->waitq);
  1777. done:
  1778. lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
  1779. return cmdnode;
  1780. }
  1781. int __lbs_cmd(struct lbs_private *priv, uint16_t command,
  1782. struct cmd_header *in_cmd, int in_cmd_size,
  1783. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1784. unsigned long callback_arg)
  1785. {
  1786. struct cmd_ctrl_node *cmdnode;
  1787. unsigned long flags;
  1788. int ret = 0;
  1789. lbs_deb_enter(LBS_DEB_HOST);
  1790. cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1791. callback, callback_arg);
  1792. if (IS_ERR(cmdnode)) {
  1793. ret = PTR_ERR(cmdnode);
  1794. goto done;
  1795. }
  1796. might_sleep();
  1797. wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
  1798. spin_lock_irqsave(&priv->driver_lock, flags);
  1799. ret = cmdnode->result;
  1800. if (ret)
  1801. lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
  1802. command, ret);
  1803. __lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1804. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1805. done:
  1806. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1807. return ret;
  1808. }
  1809. EXPORT_SYMBOL_GPL(__lbs_cmd);