cmd.c 50 KB

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