cmd.c 57 KB

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