cmd.c 55 KB

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