cmd.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  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 wlan_cmd_hw_spec(wlan_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 wlan_cmd_802_11_ps_mode(wlan_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. wlan_adapter *adapter = priv->adapter;
  49. lbs_deb_enter(LBS_DEB_CMD);
  50. cmd->command = cpu_to_le16(cmd_802_11_ps_mode);
  51. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
  52. S_DS_GEN);
  53. psm->action = cpu_to_le16(cmd_action);
  54. psm->multipledtim = 0;
  55. switch (cmd_action) {
  56. case cmd_subcmd_enter_ps:
  57. lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
  58. lbs_deb_cmd("locallisteninterval = %d\n",
  59. adapter->locallisteninterval);
  60. psm->locallisteninterval =
  61. cpu_to_le16(adapter->locallisteninterval);
  62. psm->nullpktinterval =
  63. cpu_to_le16(adapter->nullpktinterval);
  64. psm->multipledtim =
  65. cpu_to_le16(priv->adapter->multipledtim);
  66. break;
  67. case cmd_subcmd_exit_ps:
  68. lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
  69. break;
  70. case cmd_subcmd_sleep_confirmed:
  71. lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
  72. break;
  73. default:
  74. break;
  75. }
  76. lbs_deb_leave(LBS_DEB_CMD);
  77. return 0;
  78. }
  79. static int wlan_cmd_802_11_inactivity_timeout(wlan_private * priv,
  80. struct cmd_ds_command *cmd,
  81. u16 cmd_action, void *pdata_buf)
  82. {
  83. u16 *timeout = pdata_buf;
  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. return 0;
  94. }
  95. static int wlan_cmd_802_11_sleep_params(wlan_private * priv,
  96. struct cmd_ds_command *cmd,
  97. u16 cmd_action)
  98. {
  99. wlan_adapter *adapter = priv->adapter;
  100. struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
  101. lbs_deb_enter(LBS_DEB_CMD);
  102. cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
  103. S_DS_GEN);
  104. cmd->command = cpu_to_le16(cmd_802_11_sleep_params);
  105. if (cmd_action == cmd_act_get) {
  106. memset(&adapter->sp, 0, sizeof(struct sleep_params));
  107. memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
  108. sp->action = cpu_to_le16(cmd_action);
  109. } else if (cmd_action == cmd_act_set) {
  110. sp->action = cpu_to_le16(cmd_action);
  111. sp->error = cpu_to_le16(adapter->sp.sp_error);
  112. sp->offset = cpu_to_le16(adapter->sp.sp_offset);
  113. sp->stabletime = cpu_to_le16(adapter->sp.sp_stabletime);
  114. sp->calcontrol = (u8) adapter->sp.sp_calcontrol;
  115. sp->externalsleepclk = (u8) adapter->sp.sp_extsleepclk;
  116. sp->reserved = cpu_to_le16(adapter->sp.sp_reserved);
  117. }
  118. lbs_deb_leave(LBS_DEB_CMD);
  119. return 0;
  120. }
  121. static int wlan_cmd_802_11_set_wep(wlan_private * priv,
  122. struct cmd_ds_command *cmd,
  123. u32 cmd_act,
  124. void * pdata_buf)
  125. {
  126. struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
  127. wlan_adapter *adapter = priv->adapter;
  128. int ret = 0;
  129. struct assoc_request * assoc_req = pdata_buf;
  130. lbs_deb_enter(LBS_DEB_CMD);
  131. cmd->command = cpu_to_le16(cmd_802_11_set_wep);
  132. cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
  133. if (cmd_act == cmd_act_add) {
  134. int i;
  135. if (!assoc_req) {
  136. lbs_deb_cmd("Invalid association request!");
  137. ret = -1;
  138. goto done;
  139. }
  140. wep->action = cpu_to_le16(cmd_act_add);
  141. /* default tx key index */
  142. wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
  143. (u32)cmd_WEP_KEY_INDEX_MASK));
  144. lbs_deb_cmd("Tx key Index: %u\n", le16_to_cpu(wep->keyindex));
  145. /* Copy key types and material to host command structure */
  146. for (i = 0; i < 4; i++) {
  147. struct WLAN_802_11_KEY * pkey = &assoc_req->wep_keys[i];
  148. switch (pkey->len) {
  149. case KEY_LEN_WEP_40:
  150. wep->keytype[i] =
  151. cpu_to_le16(cmd_type_wep_40_bit);
  152. memmove(&wep->keymaterial[i], pkey->key,
  153. pkey->len);
  154. break;
  155. case KEY_LEN_WEP_104:
  156. wep->keytype[i] =
  157. cpu_to_le16(cmd_type_wep_104_bit);
  158. memmove(&wep->keymaterial[i], pkey->key,
  159. pkey->len);
  160. break;
  161. case 0:
  162. break;
  163. default:
  164. lbs_deb_cmd("Invalid WEP key %d length of %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. }
  178. ret = 0;
  179. done:
  180. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  181. return ret;
  182. }
  183. static int wlan_cmd_802_11_enable_rsn(wlan_private * priv,
  184. struct cmd_ds_command *cmd,
  185. u16 cmd_action,
  186. void * pdata_buf)
  187. {
  188. struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
  189. u32 * enable = pdata_buf;
  190. lbs_deb_enter(LBS_DEB_CMD);
  191. cmd->command = cpu_to_le16(cmd_802_11_enable_rsn);
  192. cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
  193. penableRSN->action = cpu_to_le16(cmd_action);
  194. if (cmd_action == cmd_act_set) {
  195. if (*enable)
  196. penableRSN->enable = cpu_to_le16(cmd_enable_rsn);
  197. else
  198. penableRSN->enable = cpu_to_le16(cmd_disable_rsn);
  199. }
  200. lbs_deb_leave(LBS_DEB_CMD);
  201. return 0;
  202. }
  203. static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
  204. struct WLAN_802_11_KEY * pkey)
  205. {
  206. pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
  207. if (pkey->flags & KEY_INFO_WPA_ENABLED) {
  208. pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
  209. }
  210. if (pkey->flags & KEY_INFO_WPA_UNICAST) {
  211. pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
  212. }
  213. if (pkey->flags & KEY_INFO_WPA_MCAST) {
  214. pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
  215. }
  216. pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
  217. pkeyparamset->keylen = cpu_to_le16(pkey->len);
  218. memcpy(pkeyparamset->key, pkey->key, pkey->len);
  219. pkeyparamset->length = cpu_to_le16( sizeof(pkeyparamset->keytypeid)
  220. + sizeof(pkeyparamset->keyinfo)
  221. + sizeof(pkeyparamset->keylen)
  222. + sizeof(pkeyparamset->key));
  223. }
  224. static int wlan_cmd_802_11_key_material(wlan_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 wlan_cmd_802_11_reset(wlan_private * priv,
  262. struct cmd_ds_command *cmd, int cmd_action)
  263. {
  264. struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
  265. cmd->command = cpu_to_le16(cmd_802_11_reset);
  266. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
  267. reset->action = cpu_to_le16(cmd_action);
  268. return 0;
  269. }
  270. static int wlan_cmd_802_11_get_log(wlan_private * priv,
  271. struct cmd_ds_command *cmd)
  272. {
  273. cmd->command = cpu_to_le16(cmd_802_11_get_log);
  274. cmd->size =
  275. cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
  276. return 0;
  277. }
  278. static int wlan_cmd_802_11_get_stat(wlan_private * priv,
  279. struct cmd_ds_command *cmd)
  280. {
  281. cmd->command = cpu_to_le16(cmd_802_11_get_stat);
  282. cmd->size =
  283. cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
  284. return 0;
  285. }
  286. static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
  287. struct cmd_ds_command *cmd,
  288. int cmd_action,
  289. int cmd_oid, void *pdata_buf)
  290. {
  291. struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
  292. wlan_adapter *adapter = priv->adapter;
  293. u8 ucTemp;
  294. lbs_deb_enter(LBS_DEB_CMD);
  295. lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
  296. cmd->command = cpu_to_le16(cmd_802_11_snmp_mib);
  297. cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
  298. switch (cmd_oid) {
  299. case OID_802_11_INFRASTRUCTURE_MODE:
  300. {
  301. u8 mode = (u8) (size_t) pdata_buf;
  302. pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
  303. pSNMPMIB->oid = cpu_to_le16((u16) desired_bsstype_i);
  304. pSNMPMIB->bufsize = sizeof(u8);
  305. if (mode == IW_MODE_ADHOC) {
  306. ucTemp = SNMP_MIB_VALUE_ADHOC;
  307. } else {
  308. /* Infra and Auto modes */
  309. ucTemp = SNMP_MIB_VALUE_INFRA;
  310. }
  311. memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
  312. break;
  313. }
  314. case OID_802_11D_ENABLE:
  315. {
  316. u32 ulTemp;
  317. pSNMPMIB->oid = cpu_to_le16((u16) dot11d_i);
  318. if (cmd_action == cmd_act_set) {
  319. pSNMPMIB->querytype = cmd_act_set;
  320. pSNMPMIB->bufsize = sizeof(u16);
  321. ulTemp = *(u32 *)pdata_buf;
  322. *((__le16 *)(pSNMPMIB->value)) =
  323. cpu_to_le16((u16) ulTemp);
  324. }
  325. break;
  326. }
  327. case OID_802_11_FRAGMENTATION_THRESHOLD:
  328. {
  329. u32 ulTemp;
  330. pSNMPMIB->oid = cpu_to_le16((u16) fragthresh_i);
  331. if (cmd_action == cmd_act_get) {
  332. pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
  333. } else if (cmd_action == cmd_act_set) {
  334. pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
  335. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  336. ulTemp = *((u32 *) pdata_buf);
  337. *((__le16 *)(pSNMPMIB->value)) =
  338. cpu_to_le16((u16) ulTemp);
  339. }
  340. break;
  341. }
  342. case OID_802_11_RTS_THRESHOLD:
  343. {
  344. u32 ulTemp;
  345. pSNMPMIB->oid = le16_to_cpu((u16) rtsthresh_i);
  346. if (cmd_action == cmd_act_get) {
  347. pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
  348. } else if (cmd_action == cmd_act_set) {
  349. pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
  350. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  351. ulTemp = *((u32 *)pdata_buf);
  352. *(__le16 *)(pSNMPMIB->value) =
  353. cpu_to_le16((u16) ulTemp);
  354. }
  355. break;
  356. }
  357. case OID_802_11_TX_RETRYCOUNT:
  358. pSNMPMIB->oid = cpu_to_le16((u16) short_retrylim_i);
  359. if (cmd_action == cmd_act_get) {
  360. pSNMPMIB->querytype = cpu_to_le16(cmd_act_get);
  361. } else if (cmd_action == cmd_act_set) {
  362. pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
  363. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  364. *((__le16 *)(pSNMPMIB->value)) =
  365. cpu_to_le16((u16) adapter->txretrycount);
  366. }
  367. break;
  368. default:
  369. break;
  370. }
  371. lbs_deb_cmd(
  372. "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
  373. le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
  374. le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
  375. lbs_deb_cmd(
  376. "SNMP_CMD: action=0x%x, oid=0x%x, oidsize=0x%x, value=0x%x\n",
  377. le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
  378. le16_to_cpu(pSNMPMIB->bufsize),
  379. le16_to_cpu(*(__le16 *) pSNMPMIB->value));
  380. lbs_deb_leave(LBS_DEB_CMD);
  381. return 0;
  382. }
  383. static int wlan_cmd_802_11_radio_control(wlan_private * priv,
  384. struct cmd_ds_command *cmd,
  385. int cmd_action)
  386. {
  387. wlan_adapter *adapter = priv->adapter;
  388. struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
  389. lbs_deb_enter(LBS_DEB_CMD);
  390. cmd->size =
  391. cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
  392. S_DS_GEN);
  393. cmd->command = cpu_to_le16(cmd_802_11_radio_control);
  394. pradiocontrol->action = cpu_to_le16(cmd_action);
  395. switch (adapter->preamble) {
  396. case cmd_type_short_preamble:
  397. pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
  398. break;
  399. case cmd_type_long_preamble:
  400. pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
  401. break;
  402. case cmd_type_auto_preamble:
  403. default:
  404. pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
  405. break;
  406. }
  407. if (adapter->radioon)
  408. pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
  409. else
  410. pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
  411. lbs_deb_leave(LBS_DEB_CMD);
  412. return 0;
  413. }
  414. static int wlan_cmd_802_11_rf_tx_power(wlan_private * priv,
  415. struct cmd_ds_command *cmd,
  416. u16 cmd_action, void *pdata_buf)
  417. {
  418. struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
  419. lbs_deb_enter(LBS_DEB_CMD);
  420. cmd->size =
  421. cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
  422. cmd->command = cpu_to_le16(cmd_802_11_rf_tx_power);
  423. prtp->action = cpu_to_le16(cmd_action);
  424. lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
  425. le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
  426. le16_to_cpu(prtp->action));
  427. switch (cmd_action) {
  428. case cmd_act_tx_power_opt_get:
  429. prtp->action = cpu_to_le16(cmd_act_get);
  430. prtp->currentlevel = 0;
  431. break;
  432. case cmd_act_tx_power_opt_set_high:
  433. prtp->action = cpu_to_le16(cmd_act_set);
  434. prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_high);
  435. break;
  436. case cmd_act_tx_power_opt_set_mid:
  437. prtp->action = cpu_to_le16(cmd_act_set);
  438. prtp->currentlevel = cpu_to_le16(cmd_act_tx_power_index_mid);
  439. break;
  440. case cmd_act_tx_power_opt_set_low:
  441. prtp->action = cpu_to_le16(cmd_act_set);
  442. prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
  443. break;
  444. }
  445. lbs_deb_leave(LBS_DEB_CMD);
  446. return 0;
  447. }
  448. static int wlan_cmd_802_11_rf_antenna(wlan_private * priv,
  449. struct cmd_ds_command *cmd,
  450. u16 cmd_action, void *pdata_buf)
  451. {
  452. struct cmd_ds_802_11_rf_antenna *rant = &cmd->params.rant;
  453. cmd->command = cpu_to_le16(cmd_802_11_rf_antenna);
  454. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_antenna) +
  455. S_DS_GEN);
  456. rant->action = cpu_to_le16(cmd_action);
  457. if ((cmd_action == cmd_act_set_rx) || (cmd_action == cmd_act_set_tx)) {
  458. rant->antennamode = cpu_to_le16((u16) (*(u32 *) pdata_buf));
  459. }
  460. return 0;
  461. }
  462. static int wlan_cmd_802_11_rate_adapt_rateset(wlan_private * priv,
  463. struct cmd_ds_command *cmd,
  464. u16 cmd_action)
  465. {
  466. struct cmd_ds_802_11_rate_adapt_rateset
  467. *rateadapt = &cmd->params.rateset;
  468. wlan_adapter *adapter = priv->adapter;
  469. cmd->size =
  470. cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
  471. + S_DS_GEN);
  472. cmd->command = cpu_to_le16(cmd_802_11_rate_adapt_rateset);
  473. lbs_deb_enter(LBS_DEB_CMD);
  474. rateadapt->action = cpu_to_le16(cmd_action);
  475. rateadapt->enablehwauto = cpu_to_le16(adapter->enablehwauto);
  476. rateadapt->bitmap = cpu_to_le16(adapter->ratebitmap);
  477. lbs_deb_leave(LBS_DEB_CMD);
  478. return 0;
  479. }
  480. static int wlan_cmd_802_11_data_rate(wlan_private * priv,
  481. struct cmd_ds_command *cmd,
  482. u16 cmd_action)
  483. {
  484. struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
  485. wlan_adapter *adapter = priv->adapter;
  486. lbs_deb_enter(LBS_DEB_CMD);
  487. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
  488. S_DS_GEN);
  489. cmd->command = cpu_to_le16(cmd_802_11_data_rate);
  490. memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
  491. pdatarate->action = cpu_to_le16(cmd_action);
  492. if (cmd_action == cmd_act_set_tx_fix_rate) {
  493. pdatarate->datarate[0] = libertas_data_rate_to_index(adapter->datarate);
  494. lbs_deb_cmd("Setting FW for fixed rate 0x%02X\n",
  495. adapter->datarate);
  496. } else if (cmd_action == cmd_act_set_tx_auto) {
  497. lbs_deb_cmd("Setting FW for AUTO rate\n");
  498. }
  499. lbs_deb_leave(LBS_DEB_CMD);
  500. return 0;
  501. }
  502. static int wlan_cmd_mac_multicast_adr(wlan_private * priv,
  503. struct cmd_ds_command *cmd,
  504. u16 cmd_action)
  505. {
  506. struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
  507. wlan_adapter *adapter = priv->adapter;
  508. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
  509. S_DS_GEN);
  510. cmd->command = cpu_to_le16(cmd_mac_multicast_adr);
  511. pMCastAdr->action = cpu_to_le16(cmd_action);
  512. pMCastAdr->nr_of_adrs =
  513. cpu_to_le16((u16) adapter->nr_of_multicastmacaddr);
  514. memcpy(pMCastAdr->maclist, adapter->multicastlist,
  515. adapter->nr_of_multicastmacaddr * ETH_ALEN);
  516. return 0;
  517. }
  518. static int wlan_cmd_802_11_rf_channel(wlan_private * priv,
  519. struct cmd_ds_command *cmd,
  520. int option, void *pdata_buf)
  521. {
  522. struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
  523. cmd->command = cpu_to_le16(cmd_802_11_rf_channel);
  524. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
  525. S_DS_GEN);
  526. if (option == cmd_opt_802_11_rf_channel_set) {
  527. rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
  528. }
  529. rfchan->action = cpu_to_le16(option);
  530. return 0;
  531. }
  532. static int wlan_cmd_802_11_rssi(wlan_private * priv,
  533. struct cmd_ds_command *cmd)
  534. {
  535. wlan_adapter *adapter = priv->adapter;
  536. cmd->command = cpu_to_le16(cmd_802_11_rssi);
  537. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
  538. cmd->params.rssi.N = cpu_to_le16(priv->adapter->bcn_avg_factor);
  539. /* reset Beacon SNR/NF/RSSI values */
  540. adapter->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
  541. adapter->SNR[TYPE_BEACON][TYPE_AVG] = 0;
  542. adapter->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
  543. adapter->NF[TYPE_BEACON][TYPE_AVG] = 0;
  544. adapter->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
  545. adapter->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
  546. return 0;
  547. }
  548. static int wlan_cmd_reg_access(wlan_private * priv,
  549. struct cmd_ds_command *cmdptr,
  550. u8 cmd_action, void *pdata_buf)
  551. {
  552. struct wlan_offset_value *offval;
  553. lbs_deb_enter(LBS_DEB_CMD);
  554. offval = (struct wlan_offset_value *)pdata_buf;
  555. switch (cmdptr->command) {
  556. case cmd_mac_reg_access:
  557. {
  558. struct cmd_ds_mac_reg_access *macreg;
  559. cmdptr->size =
  560. cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
  561. + S_DS_GEN);
  562. macreg =
  563. (struct cmd_ds_mac_reg_access *)&cmdptr->params.
  564. macreg;
  565. macreg->action = cpu_to_le16(cmd_action);
  566. macreg->offset = cpu_to_le16((u16) offval->offset);
  567. macreg->value = cpu_to_le32(offval->value);
  568. break;
  569. }
  570. case cmd_bbp_reg_access:
  571. {
  572. struct cmd_ds_bbp_reg_access *bbpreg;
  573. cmdptr->size =
  574. cpu_to_le16(sizeof
  575. (struct cmd_ds_bbp_reg_access)
  576. + S_DS_GEN);
  577. bbpreg =
  578. (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
  579. bbpreg;
  580. bbpreg->action = cpu_to_le16(cmd_action);
  581. bbpreg->offset = cpu_to_le16((u16) offval->offset);
  582. bbpreg->value = (u8) offval->value;
  583. break;
  584. }
  585. case cmd_rf_reg_access:
  586. {
  587. struct cmd_ds_rf_reg_access *rfreg;
  588. cmdptr->size =
  589. cpu_to_le16(sizeof
  590. (struct cmd_ds_rf_reg_access) +
  591. S_DS_GEN);
  592. rfreg =
  593. (struct cmd_ds_rf_reg_access *)&cmdptr->params.
  594. rfreg;
  595. rfreg->action = cpu_to_le16(cmd_action);
  596. rfreg->offset = cpu_to_le16((u16) offval->offset);
  597. rfreg->value = (u8) offval->value;
  598. break;
  599. }
  600. default:
  601. break;
  602. }
  603. lbs_deb_leave(LBS_DEB_CMD);
  604. return 0;
  605. }
  606. static int wlan_cmd_802_11_mac_address(wlan_private * priv,
  607. struct cmd_ds_command *cmd,
  608. u16 cmd_action)
  609. {
  610. wlan_adapter *adapter = priv->adapter;
  611. cmd->command = cpu_to_le16(cmd_802_11_mac_address);
  612. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
  613. S_DS_GEN);
  614. cmd->result = 0;
  615. cmd->params.macadd.action = cpu_to_le16(cmd_action);
  616. if (cmd_action == cmd_act_set) {
  617. memcpy(cmd->params.macadd.macadd,
  618. adapter->current_addr, ETH_ALEN);
  619. lbs_dbg_hex("SET_CMD: MAC ADDRESS-", adapter->current_addr, 6);
  620. }
  621. return 0;
  622. }
  623. static int wlan_cmd_802_11_eeprom_access(wlan_private * priv,
  624. struct cmd_ds_command *cmd,
  625. int cmd_action, void *pdata_buf)
  626. {
  627. struct wlan_ioctl_regrdwr *ea = pdata_buf;
  628. lbs_deb_enter(LBS_DEB_CMD);
  629. cmd->command = cpu_to_le16(cmd_802_11_eeprom_access);
  630. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
  631. S_DS_GEN);
  632. cmd->result = 0;
  633. cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
  634. cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
  635. cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
  636. cmd->params.rdeeprom.value = 0;
  637. return 0;
  638. }
  639. static int wlan_cmd_bt_access(wlan_private * priv,
  640. struct cmd_ds_command *cmd,
  641. u16 cmd_action, void *pdata_buf)
  642. {
  643. struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
  644. lbs_deb_cmd("BT CMD(%d)\n", cmd_action);
  645. cmd->command = cpu_to_le16(cmd_bt_access);
  646. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
  647. cmd->result = 0;
  648. bt_access->action = cpu_to_le16(cmd_action);
  649. switch (cmd_action) {
  650. case cmd_act_bt_access_add:
  651. memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
  652. lbs_dbg_hex("BT_ADD: blinded mac address-", bt_access->addr1, 6);
  653. break;
  654. case cmd_act_bt_access_del:
  655. memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
  656. lbs_dbg_hex("BT_DEL: blinded mac address-", bt_access->addr1, 6);
  657. break;
  658. case cmd_act_bt_access_list:
  659. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  660. break;
  661. case cmd_act_bt_access_reset:
  662. break;
  663. case cmd_act_bt_access_set_invert:
  664. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  665. break;
  666. case cmd_act_bt_access_get_invert:
  667. break;
  668. default:
  669. break;
  670. }
  671. return 0;
  672. }
  673. static int wlan_cmd_fwt_access(wlan_private * priv,
  674. struct cmd_ds_command *cmd,
  675. u16 cmd_action, void *pdata_buf)
  676. {
  677. struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
  678. lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
  679. cmd->command = cpu_to_le16(cmd_fwt_access);
  680. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
  681. cmd->result = 0;
  682. if (pdata_buf)
  683. memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
  684. else
  685. memset(fwt_access, 0, sizeof(*fwt_access));
  686. fwt_access->action = cpu_to_le16(cmd_action);
  687. return 0;
  688. }
  689. static int wlan_cmd_mesh_access(wlan_private * priv,
  690. struct cmd_ds_command *cmd,
  691. u16 cmd_action, void *pdata_buf)
  692. {
  693. struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
  694. lbs_deb_cmd("FWT CMD(%d)\n", cmd_action);
  695. cmd->command = cpu_to_le16(cmd_mesh_access);
  696. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
  697. cmd->result = 0;
  698. if (pdata_buf)
  699. memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
  700. else
  701. memset(mesh_access, 0, sizeof(*mesh_access));
  702. mesh_access->action = cpu_to_le16(cmd_action);
  703. return 0;
  704. }
  705. void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
  706. {
  707. unsigned long flags;
  708. struct cmd_ds_command *cmdptr;
  709. lbs_deb_enter(LBS_DEB_CMD);
  710. if (!cmdnode) {
  711. lbs_deb_cmd("QUEUE_CMD: cmdnode is NULL\n");
  712. goto done;
  713. }
  714. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  715. if (!cmdptr) {
  716. lbs_deb_cmd("QUEUE_CMD: cmdptr is NULL\n");
  717. goto done;
  718. }
  719. /* Exit_PS command needs to be queued in the header always. */
  720. if (cmdptr->command == cmd_802_11_ps_mode) {
  721. struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
  722. if (psm->action == cpu_to_le16(cmd_subcmd_exit_ps)) {
  723. if (adapter->psstate != PS_STATE_FULL_POWER)
  724. addtail = 0;
  725. }
  726. }
  727. spin_lock_irqsave(&adapter->driver_lock, flags);
  728. if (addtail)
  729. list_add_tail((struct list_head *)cmdnode,
  730. &adapter->cmdpendingq);
  731. else
  732. list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
  733. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  734. lbs_deb_cmd("QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
  735. cmdnode,
  736. le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
  737. done:
  738. lbs_deb_leave(LBS_DEB_CMD);
  739. }
  740. /*
  741. * TODO: Fix the issue when DownloadcommandToStation is being called the
  742. * second time when the command timesout. All the cmdptr->xxx are in little
  743. * endian and therefore all the comparissions will fail.
  744. * For now - we are not performing the endian conversion the second time - but
  745. * for PS and DEEP_SLEEP we need to worry
  746. */
  747. static int DownloadcommandToStation(wlan_private * priv,
  748. struct cmd_ctrl_node *cmdnode)
  749. {
  750. unsigned long flags;
  751. struct cmd_ds_command *cmdptr;
  752. wlan_adapter *adapter = priv->adapter;
  753. int ret = 0;
  754. u16 cmdsize;
  755. u16 command;
  756. lbs_deb_enter(LBS_DEB_CMD);
  757. if (!adapter || !cmdnode) {
  758. lbs_deb_cmd("DNLD_CMD: adapter = %p, cmdnode = %p\n",
  759. adapter, cmdnode);
  760. if (cmdnode) {
  761. spin_lock_irqsave(&adapter->driver_lock, flags);
  762. __libertas_cleanup_and_insert_cmd(priv, cmdnode);
  763. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  764. }
  765. ret = -1;
  766. goto done;
  767. }
  768. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  769. spin_lock_irqsave(&adapter->driver_lock, flags);
  770. if (!cmdptr || !cmdptr->size) {
  771. lbs_deb_cmd("DNLD_CMD: cmdptr is Null or cmd size is Zero, "
  772. "Not sending\n");
  773. __libertas_cleanup_and_insert_cmd(priv, cmdnode);
  774. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  775. ret = -1;
  776. goto done;
  777. }
  778. adapter->cur_cmd = cmdnode;
  779. adapter->cur_cmd_retcode = 0;
  780. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  781. lbs_deb_cmd("DNLD_CMD:: Before download, size of cmd = %d\n",
  782. le16_to_cpu(cmdptr->size));
  783. cmdsize = cmdptr->size;
  784. command = cpu_to_le16(cmdptr->command);
  785. cmdnode->cmdwaitqwoken = 0;
  786. cmdsize = cpu_to_le16(cmdsize);
  787. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
  788. if (ret != 0) {
  789. lbs_deb_cmd("DNLD_CMD: Host to Card failed\n");
  790. spin_lock_irqsave(&adapter->driver_lock, flags);
  791. __libertas_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
  792. adapter->cur_cmd = NULL;
  793. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  794. ret = -1;
  795. goto done;
  796. }
  797. lbs_deb_cmd("DNLD_CMD: Sent command 0x%x @ %lu\n", command, jiffies);
  798. lbs_dbg_hex("DNLD_CMD: command", cmdnode->bufvirtualaddr, cmdsize);
  799. /* Setup the timer after transmit command */
  800. if (command == cmd_802_11_scan || command == cmd_802_11_authenticate
  801. || command == cmd_802_11_associate)
  802. mod_timer(&adapter->command_timer, jiffies + (10*HZ));
  803. else
  804. mod_timer(&adapter->command_timer, jiffies + (5*HZ));
  805. ret = 0;
  806. done:
  807. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  808. return ret;
  809. }
  810. static int wlan_cmd_mac_control(wlan_private * priv,
  811. struct cmd_ds_command *cmd)
  812. {
  813. struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
  814. lbs_deb_enter(LBS_DEB_CMD);
  815. cmd->command = cpu_to_le16(cmd_mac_control);
  816. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
  817. mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
  818. lbs_deb_cmd("wlan_cmd_mac_control(): action=0x%X size=%d\n",
  819. le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
  820. lbs_deb_leave(LBS_DEB_CMD);
  821. return 0;
  822. }
  823. /**
  824. * This function inserts command node to cmdfreeq
  825. * after cleans it. Requires adapter->driver_lock held.
  826. */
  827. void __libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
  828. {
  829. wlan_adapter *adapter = priv->adapter;
  830. if (!ptempcmd)
  831. goto done;
  832. cleanup_cmdnode(ptempcmd);
  833. list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
  834. done:
  835. return;
  836. }
  837. void libertas_cleanup_and_insert_cmd(wlan_private * priv, struct cmd_ctrl_node *ptempcmd)
  838. {
  839. unsigned long flags;
  840. spin_lock_irqsave(&priv->adapter->driver_lock, flags);
  841. __libertas_cleanup_and_insert_cmd(priv, ptempcmd);
  842. spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
  843. }
  844. int libertas_set_radio_control(wlan_private * priv)
  845. {
  846. int ret = 0;
  847. lbs_deb_enter(LBS_DEB_CMD);
  848. ret = libertas_prepare_and_send_command(priv,
  849. cmd_802_11_radio_control,
  850. cmd_act_set,
  851. cmd_option_waitforrsp, 0, NULL);
  852. lbs_deb_cmd("RADIO_SET: on or off: 0x%X, preamble = 0x%X\n",
  853. priv->adapter->radioon, priv->adapter->preamble);
  854. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  855. return ret;
  856. }
  857. int libertas_set_mac_packet_filter(wlan_private * priv)
  858. {
  859. int ret = 0;
  860. lbs_deb_enter(LBS_DEB_CMD);
  861. lbs_deb_cmd("libertas_set_mac_packet_filter value = %x\n",
  862. priv->adapter->currentpacketfilter);
  863. /* Send MAC control command to station */
  864. ret = libertas_prepare_and_send_command(priv,
  865. cmd_mac_control, 0, 0, 0, NULL);
  866. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  867. return ret;
  868. }
  869. /**
  870. * @brief This function prepare the command before send to firmware.
  871. *
  872. * @param priv A pointer to wlan_private structure
  873. * @param cmd_no command number
  874. * @param cmd_action command action: GET or SET
  875. * @param wait_option wait option: wait response or not
  876. * @param cmd_oid cmd oid: treated as sub command
  877. * @param pdata_buf A pointer to informaion buffer
  878. * @return 0 or -1
  879. */
  880. int libertas_prepare_and_send_command(wlan_private * priv,
  881. u16 cmd_no,
  882. u16 cmd_action,
  883. u16 wait_option, u32 cmd_oid, void *pdata_buf)
  884. {
  885. int ret = 0;
  886. wlan_adapter *adapter = priv->adapter;
  887. struct cmd_ctrl_node *cmdnode;
  888. struct cmd_ds_command *cmdptr;
  889. unsigned long flags;
  890. lbs_deb_enter(LBS_DEB_CMD);
  891. if (!adapter) {
  892. lbs_deb_cmd("PREP_CMD: adapter is Null\n");
  893. ret = -1;
  894. goto done;
  895. }
  896. if (adapter->surpriseremoved) {
  897. lbs_deb_cmd("PREP_CMD: Card is Removed\n");
  898. ret = -1;
  899. goto done;
  900. }
  901. cmdnode = libertas_get_free_cmd_ctrl_node(priv);
  902. if (cmdnode == NULL) {
  903. lbs_deb_cmd("PREP_CMD: No free cmdnode\n");
  904. /* Wake up main thread to execute next command */
  905. wake_up_interruptible(&priv->mainthread.waitq);
  906. ret = -1;
  907. goto done;
  908. }
  909. libertas_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
  910. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  911. lbs_deb_cmd("PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
  912. cmdptr, cmd_no);
  913. if (!cmdptr) {
  914. lbs_deb_cmd("PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
  915. libertas_cleanup_and_insert_cmd(priv, cmdnode);
  916. ret = -1;
  917. goto done;
  918. }
  919. /* Set sequence number, command and INT option */
  920. adapter->seqnum++;
  921. cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
  922. cmdptr->command = cpu_to_le16(cmd_no);
  923. cmdptr->result = 0;
  924. switch (cmd_no) {
  925. case cmd_get_hw_spec:
  926. ret = wlan_cmd_hw_spec(priv, cmdptr);
  927. break;
  928. case cmd_802_11_ps_mode:
  929. ret = wlan_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
  930. break;
  931. case cmd_802_11_scan:
  932. ret = libertas_cmd_80211_scan(priv, cmdptr, pdata_buf);
  933. break;
  934. case cmd_mac_control:
  935. ret = wlan_cmd_mac_control(priv, cmdptr);
  936. break;
  937. case cmd_802_11_associate:
  938. case cmd_802_11_reassociate:
  939. ret = libertas_cmd_80211_associate(priv, cmdptr, pdata_buf);
  940. break;
  941. case cmd_802_11_deauthenticate:
  942. ret = libertas_cmd_80211_deauthenticate(priv, cmdptr);
  943. break;
  944. case cmd_802_11_set_wep:
  945. ret = wlan_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
  946. break;
  947. case cmd_802_11_ad_hoc_start:
  948. ret = libertas_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
  949. break;
  950. case cmd_code_dnld:
  951. break;
  952. case cmd_802_11_reset:
  953. ret = wlan_cmd_802_11_reset(priv, cmdptr, cmd_action);
  954. break;
  955. case cmd_802_11_get_log:
  956. ret = wlan_cmd_802_11_get_log(priv, cmdptr);
  957. break;
  958. case cmd_802_11_authenticate:
  959. ret = libertas_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
  960. break;
  961. case cmd_802_11_get_stat:
  962. ret = wlan_cmd_802_11_get_stat(priv, cmdptr);
  963. break;
  964. case cmd_802_11_snmp_mib:
  965. ret = wlan_cmd_802_11_snmp_mib(priv, cmdptr,
  966. cmd_action, cmd_oid, pdata_buf);
  967. break;
  968. case cmd_mac_reg_access:
  969. case cmd_bbp_reg_access:
  970. case cmd_rf_reg_access:
  971. ret = wlan_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
  972. break;
  973. case cmd_802_11_rf_channel:
  974. ret = wlan_cmd_802_11_rf_channel(priv, cmdptr,
  975. cmd_action, pdata_buf);
  976. break;
  977. case cmd_802_11_rf_tx_power:
  978. ret = wlan_cmd_802_11_rf_tx_power(priv, cmdptr,
  979. cmd_action, pdata_buf);
  980. break;
  981. case cmd_802_11_radio_control:
  982. ret = wlan_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
  983. break;
  984. case cmd_802_11_rf_antenna:
  985. ret = wlan_cmd_802_11_rf_antenna(priv, cmdptr,
  986. cmd_action, pdata_buf);
  987. break;
  988. case cmd_802_11_data_rate:
  989. ret = wlan_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
  990. break;
  991. case cmd_802_11_rate_adapt_rateset:
  992. ret = wlan_cmd_802_11_rate_adapt_rateset(priv,
  993. cmdptr, cmd_action);
  994. break;
  995. case cmd_mac_multicast_adr:
  996. ret = wlan_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
  997. break;
  998. case cmd_802_11_ad_hoc_join:
  999. ret = libertas_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
  1000. break;
  1001. case cmd_802_11_rssi:
  1002. ret = wlan_cmd_802_11_rssi(priv, cmdptr);
  1003. break;
  1004. case cmd_802_11_ad_hoc_stop:
  1005. ret = libertas_cmd_80211_ad_hoc_stop(priv, cmdptr);
  1006. break;
  1007. case cmd_802_11_enable_rsn:
  1008. ret = wlan_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
  1009. pdata_buf);
  1010. break;
  1011. case cmd_802_11_key_material:
  1012. ret = wlan_cmd_802_11_key_material(priv, cmdptr, cmd_action,
  1013. cmd_oid, pdata_buf);
  1014. break;
  1015. case cmd_802_11_pairwise_tsc:
  1016. break;
  1017. case cmd_802_11_group_tsc:
  1018. break;
  1019. case cmd_802_11_mac_address:
  1020. ret = wlan_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
  1021. break;
  1022. case cmd_802_11_eeprom_access:
  1023. ret = wlan_cmd_802_11_eeprom_access(priv, cmdptr,
  1024. cmd_action, pdata_buf);
  1025. break;
  1026. case cmd_802_11_set_afc:
  1027. case cmd_802_11_get_afc:
  1028. cmdptr->command = cpu_to_le16(cmd_no);
  1029. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
  1030. S_DS_GEN);
  1031. memmove(&cmdptr->params.afc,
  1032. pdata_buf, sizeof(struct cmd_ds_802_11_afc));
  1033. ret = 0;
  1034. goto done;
  1035. case cmd_802_11d_domain_info:
  1036. ret = libertas_cmd_802_11d_domain_info(priv, cmdptr,
  1037. cmd_no, cmd_action);
  1038. break;
  1039. case cmd_802_11_sleep_params:
  1040. ret = wlan_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
  1041. break;
  1042. case cmd_802_11_inactivity_timeout:
  1043. ret = wlan_cmd_802_11_inactivity_timeout(priv, cmdptr,
  1044. cmd_action, pdata_buf);
  1045. libertas_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
  1046. break;
  1047. case cmd_802_11_tpc_cfg:
  1048. cmdptr->command = cpu_to_le16(cmd_802_11_tpc_cfg);
  1049. cmdptr->size =
  1050. cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
  1051. S_DS_GEN);
  1052. memmove(&cmdptr->params.tpccfg,
  1053. pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
  1054. ret = 0;
  1055. break;
  1056. case cmd_802_11_led_gpio_ctrl:
  1057. {
  1058. struct mrvlietypes_ledgpio *gpio =
  1059. (struct mrvlietypes_ledgpio*)
  1060. cmdptr->params.ledgpio.data;
  1061. memmove(&cmdptr->params.ledgpio,
  1062. pdata_buf,
  1063. sizeof(struct cmd_ds_802_11_led_ctrl));
  1064. cmdptr->command =
  1065. cpu_to_le16(cmd_802_11_led_gpio_ctrl);
  1066. #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
  1067. cmdptr->size =
  1068. cpu_to_le16(gpio->header.len + S_DS_GEN +
  1069. ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
  1070. gpio->header.len = cpu_to_le16(gpio->header.len);
  1071. ret = 0;
  1072. break;
  1073. }
  1074. case cmd_802_11_pwr_cfg:
  1075. cmdptr->command = cpu_to_le16(cmd_802_11_pwr_cfg);
  1076. cmdptr->size =
  1077. cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
  1078. S_DS_GEN);
  1079. memmove(&cmdptr->params.pwrcfg, pdata_buf,
  1080. sizeof(struct cmd_ds_802_11_pwr_cfg));
  1081. ret = 0;
  1082. break;
  1083. case cmd_bt_access:
  1084. ret = wlan_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
  1085. break;
  1086. case cmd_fwt_access:
  1087. ret = wlan_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
  1088. break;
  1089. case cmd_mesh_access:
  1090. ret = wlan_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
  1091. break;
  1092. case cmd_get_tsf:
  1093. cmdptr->command = cpu_to_le16(cmd_get_tsf);
  1094. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
  1095. S_DS_GEN);
  1096. ret = 0;
  1097. break;
  1098. case cmd_802_11_tx_rate_query:
  1099. cmdptr->command = cpu_to_le16(cmd_802_11_tx_rate_query);
  1100. cmdptr->size = cpu_to_le16(sizeof(struct cmd_tx_rate_query) +
  1101. S_DS_GEN);
  1102. adapter->txrate = 0;
  1103. ret = 0;
  1104. break;
  1105. default:
  1106. lbs_deb_cmd("PREP_CMD: unknown command- %#x\n", cmd_no);
  1107. ret = -1;
  1108. break;
  1109. }
  1110. /* return error, since the command preparation failed */
  1111. if (ret != 0) {
  1112. lbs_deb_cmd("PREP_CMD: command preparation failed\n");
  1113. libertas_cleanup_and_insert_cmd(priv, cmdnode);
  1114. ret = -1;
  1115. goto done;
  1116. }
  1117. cmdnode->cmdwaitqwoken = 0;
  1118. libertas_queue_cmd(adapter, cmdnode, 1);
  1119. adapter->nr_cmd_pending++;
  1120. wake_up_interruptible(&priv->mainthread.waitq);
  1121. if (wait_option & cmd_option_waitforrsp) {
  1122. lbs_deb_cmd("PREP_CMD: Wait for CMD response\n");
  1123. might_sleep();
  1124. wait_event_interruptible(cmdnode->cmdwait_q,
  1125. cmdnode->cmdwaitqwoken);
  1126. }
  1127. spin_lock_irqsave(&adapter->driver_lock, flags);
  1128. if (adapter->cur_cmd_retcode) {
  1129. lbs_deb_cmd("PREP_CMD: command failed with return code=%d\n",
  1130. adapter->cur_cmd_retcode);
  1131. adapter->cur_cmd_retcode = 0;
  1132. ret = -1;
  1133. }
  1134. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1135. done:
  1136. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  1137. return ret;
  1138. }
  1139. EXPORT_SYMBOL_GPL(libertas_prepare_and_send_command);
  1140. /**
  1141. * @brief This function allocates the command buffer and link
  1142. * it to command free queue.
  1143. *
  1144. * @param priv A pointer to wlan_private structure
  1145. * @return 0 or -1
  1146. */
  1147. int libertas_allocate_cmd_buffer(wlan_private * priv)
  1148. {
  1149. int ret = 0;
  1150. u32 ulbufsize;
  1151. u32 i;
  1152. struct cmd_ctrl_node *tempcmd_array;
  1153. u8 *ptempvirtualaddr;
  1154. wlan_adapter *adapter = priv->adapter;
  1155. lbs_deb_enter(LBS_DEB_CMD);
  1156. /* Allocate and initialize cmdCtrlNode */
  1157. ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
  1158. if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
  1159. lbs_deb_cmd(
  1160. "ALLOC_CMD_BUF: failed to allocate tempcmd_array\n");
  1161. ret = -1;
  1162. goto done;
  1163. }
  1164. adapter->cmd_array = tempcmd_array;
  1165. /* Allocate and initialize command buffers */
  1166. ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
  1167. for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
  1168. if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
  1169. lbs_deb_cmd(
  1170. "ALLOC_CMD_BUF: ptempvirtualaddr: out of memory\n");
  1171. ret = -1;
  1172. goto done;
  1173. }
  1174. /* Update command buffer virtual */
  1175. tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
  1176. }
  1177. for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
  1178. init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
  1179. libertas_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
  1180. }
  1181. ret = 0;
  1182. done:
  1183. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  1184. return ret;
  1185. }
  1186. /**
  1187. * @brief This function frees the command buffer.
  1188. *
  1189. * @param priv A pointer to wlan_private structure
  1190. * @return 0 or -1
  1191. */
  1192. int libertas_free_cmd_buffer(wlan_private * priv)
  1193. {
  1194. u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
  1195. unsigned int i;
  1196. struct cmd_ctrl_node *tempcmd_array;
  1197. wlan_adapter *adapter = priv->adapter;
  1198. lbs_deb_enter(LBS_DEB_CMD);
  1199. /* need to check if cmd array is allocated or not */
  1200. if (adapter->cmd_array == NULL) {
  1201. lbs_deb_cmd("FREE_CMD_BUF: cmd_array is Null\n");
  1202. goto done;
  1203. }
  1204. tempcmd_array = adapter->cmd_array;
  1205. /* Release shared memory buffers */
  1206. ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
  1207. for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
  1208. if (tempcmd_array[i].bufvirtualaddr) {
  1209. lbs_deb_cmd("Free all the array\n");
  1210. kfree(tempcmd_array[i].bufvirtualaddr);
  1211. tempcmd_array[i].bufvirtualaddr = NULL;
  1212. }
  1213. }
  1214. /* Release cmd_ctrl_node */
  1215. if (adapter->cmd_array) {
  1216. lbs_deb_cmd("Free cmd_array\n");
  1217. kfree(adapter->cmd_array);
  1218. adapter->cmd_array = NULL;
  1219. }
  1220. done:
  1221. lbs_deb_leave(LBS_DEB_CMD);
  1222. return 0;
  1223. }
  1224. /**
  1225. * @brief This function gets a free command node if available in
  1226. * command free queue.
  1227. *
  1228. * @param priv A pointer to wlan_private structure
  1229. * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
  1230. */
  1231. struct cmd_ctrl_node *libertas_get_free_cmd_ctrl_node(wlan_private * priv)
  1232. {
  1233. struct cmd_ctrl_node *tempnode;
  1234. wlan_adapter *adapter = priv->adapter;
  1235. unsigned long flags;
  1236. if (!adapter)
  1237. return NULL;
  1238. spin_lock_irqsave(&adapter->driver_lock, flags);
  1239. if (!list_empty(&adapter->cmdfreeq)) {
  1240. tempnode = (struct cmd_ctrl_node *)adapter->cmdfreeq.next;
  1241. list_del((struct list_head *)tempnode);
  1242. } else {
  1243. lbs_deb_cmd("GET_CMD_NODE: cmd_ctrl_node is not available\n");
  1244. tempnode = NULL;
  1245. }
  1246. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1247. if (tempnode) {
  1248. /*
  1249. lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode available\n");
  1250. lbs_pr_debug(3, "GET_CMD_NODE: cmdCtrlNode Address = %p\n",
  1251. tempnode);
  1252. */
  1253. cleanup_cmdnode(tempnode);
  1254. }
  1255. return tempnode;
  1256. }
  1257. /**
  1258. * @brief This function cleans command node.
  1259. *
  1260. * @param ptempnode A pointer to cmdCtrlNode structure
  1261. * @return n/a
  1262. */
  1263. static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
  1264. {
  1265. if (!ptempnode)
  1266. return;
  1267. ptempnode->cmdwaitqwoken = 1;
  1268. wake_up_interruptible(&ptempnode->cmdwait_q);
  1269. ptempnode->status = 0;
  1270. ptempnode->cmd_oid = (u32) 0;
  1271. ptempnode->wait_option = 0;
  1272. ptempnode->pdata_buf = NULL;
  1273. if (ptempnode->bufvirtualaddr != NULL)
  1274. memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
  1275. return;
  1276. }
  1277. /**
  1278. * @brief This function initializes the command node.
  1279. *
  1280. * @param priv A pointer to wlan_private structure
  1281. * @param ptempnode A pointer to cmd_ctrl_node structure
  1282. * @param cmd_oid cmd oid: treated as sub command
  1283. * @param wait_option wait option: wait response or not
  1284. * @param pdata_buf A pointer to informaion buffer
  1285. * @return 0 or -1
  1286. */
  1287. void libertas_set_cmd_ctrl_node(wlan_private * priv,
  1288. struct cmd_ctrl_node *ptempnode,
  1289. u32 cmd_oid, u16 wait_option, void *pdata_buf)
  1290. {
  1291. lbs_deb_enter(LBS_DEB_CMD);
  1292. if (!ptempnode)
  1293. return;
  1294. ptempnode->cmd_oid = cmd_oid;
  1295. ptempnode->wait_option = wait_option;
  1296. ptempnode->pdata_buf = pdata_buf;
  1297. lbs_deb_leave(LBS_DEB_CMD);
  1298. }
  1299. /**
  1300. * @brief This function executes next command in command
  1301. * pending queue. It will put fimware back to PS mode
  1302. * if applicable.
  1303. *
  1304. * @param priv A pointer to wlan_private structure
  1305. * @return 0 or -1
  1306. */
  1307. int libertas_execute_next_command(wlan_private * priv)
  1308. {
  1309. wlan_adapter *adapter = priv->adapter;
  1310. struct cmd_ctrl_node *cmdnode = NULL;
  1311. struct cmd_ds_command *cmdptr;
  1312. unsigned long flags;
  1313. int ret = 0;
  1314. lbs_deb_enter(LBS_DEB_CMD);
  1315. spin_lock_irqsave(&adapter->driver_lock, flags);
  1316. if (adapter->cur_cmd) {
  1317. lbs_pr_alert( "EXEC_NEXT_CMD: there is command in processing!\n");
  1318. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1319. ret = -1;
  1320. goto done;
  1321. }
  1322. if (!list_empty(&adapter->cmdpendingq)) {
  1323. cmdnode = (struct cmd_ctrl_node *)
  1324. adapter->cmdpendingq.next;
  1325. }
  1326. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1327. if (cmdnode) {
  1328. lbs_deb_cmd(
  1329. "EXEC_NEXT_CMD: Got next command from cmdpendingq\n");
  1330. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  1331. if (is_command_allowed_in_ps(cmdptr->command)) {
  1332. if ((adapter->psstate == PS_STATE_SLEEP) ||
  1333. (adapter->psstate == PS_STATE_PRE_SLEEP)) {
  1334. lbs_deb_cmd(
  1335. "EXEC_NEXT_CMD: Cannot send cmd 0x%x in psstate %d\n",
  1336. le16_to_cpu(cmdptr->command),
  1337. adapter->psstate);
  1338. ret = -1;
  1339. goto done;
  1340. }
  1341. lbs_deb_cmd("EXEC_NEXT_CMD: OK to send command "
  1342. "0x%x in psstate %d\n",
  1343. le16_to_cpu(cmdptr->command),
  1344. adapter->psstate);
  1345. } else if (adapter->psstate != PS_STATE_FULL_POWER) {
  1346. /*
  1347. * 1. Non-PS command:
  1348. * Queue it. set needtowakeup to TRUE if current state
  1349. * is SLEEP, otherwise call libertas_ps_wakeup to send Exit_PS.
  1350. * 2. PS command but not Exit_PS:
  1351. * Ignore it.
  1352. * 3. PS command Exit_PS:
  1353. * Set needtowakeup to TRUE if current state is SLEEP,
  1354. * otherwise send this command down to firmware
  1355. * immediately.
  1356. */
  1357. if (cmdptr->command !=
  1358. cpu_to_le16(cmd_802_11_ps_mode)) {
  1359. /* Prepare to send Exit PS,
  1360. * this non PS command will be sent later */
  1361. if ((adapter->psstate == PS_STATE_SLEEP)
  1362. || (adapter->psstate == PS_STATE_PRE_SLEEP)
  1363. ) {
  1364. /* w/ new scheme, it will not reach here.
  1365. since it is blocked in main_thread. */
  1366. adapter->needtowakeup = 1;
  1367. } else
  1368. libertas_ps_wakeup(priv, 0);
  1369. ret = 0;
  1370. goto done;
  1371. } else {
  1372. /*
  1373. * PS command. Ignore it if it is not Exit_PS.
  1374. * otherwise send it down immediately.
  1375. */
  1376. struct cmd_ds_802_11_ps_mode *psm =
  1377. &cmdptr->params.psmode;
  1378. lbs_deb_cmd(
  1379. "EXEC_NEXT_CMD: PS cmd- action=0x%x\n",
  1380. psm->action);
  1381. if (psm->action !=
  1382. cpu_to_le16(cmd_subcmd_exit_ps)) {
  1383. lbs_deb_cmd(
  1384. "EXEC_NEXT_CMD: Ignore Enter PS cmd\n");
  1385. list_del((struct list_head *)cmdnode);
  1386. libertas_cleanup_and_insert_cmd(priv, cmdnode);
  1387. ret = 0;
  1388. goto done;
  1389. }
  1390. if ((adapter->psstate == PS_STATE_SLEEP) ||
  1391. (adapter->psstate == PS_STATE_PRE_SLEEP)) {
  1392. lbs_deb_cmd(
  1393. "EXEC_NEXT_CMD: Ignore ExitPS cmd in sleep\n");
  1394. list_del((struct list_head *)cmdnode);
  1395. libertas_cleanup_and_insert_cmd(priv, cmdnode);
  1396. adapter->needtowakeup = 1;
  1397. ret = 0;
  1398. goto done;
  1399. }
  1400. lbs_deb_cmd(
  1401. "EXEC_NEXT_CMD: Sending Exit_PS down...\n");
  1402. }
  1403. }
  1404. list_del((struct list_head *)cmdnode);
  1405. lbs_deb_cmd("EXEC_NEXT_CMD: Sending 0x%04X command\n",
  1406. le16_to_cpu(cmdptr->command));
  1407. DownloadcommandToStation(priv, cmdnode);
  1408. } else {
  1409. /*
  1410. * check if in power save mode, if yes, put the device back
  1411. * to PS mode
  1412. */
  1413. if ((adapter->psmode != wlan802_11powermodecam) &&
  1414. (adapter->psstate == PS_STATE_FULL_POWER) &&
  1415. (adapter->connect_status == libertas_connected)) {
  1416. if (adapter->secinfo.WPAenabled ||
  1417. adapter->secinfo.WPA2enabled) {
  1418. /* check for valid WPA group keys */
  1419. if (adapter->wpa_mcast_key.len ||
  1420. adapter->wpa_unicast_key.len) {
  1421. lbs_deb_cmd(
  1422. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1423. " go back to PS_SLEEP");
  1424. libertas_ps_sleep(priv, 0);
  1425. }
  1426. } else {
  1427. lbs_deb_cmd(
  1428. "EXEC_NEXT_CMD: command PendQ is empty,"
  1429. " go back to PS_SLEEP");
  1430. libertas_ps_sleep(priv, 0);
  1431. }
  1432. }
  1433. }
  1434. ret = 0;
  1435. done:
  1436. lbs_deb_leave(LBS_DEB_CMD);
  1437. return ret;
  1438. }
  1439. void libertas_send_iwevcustom_event(wlan_private * priv, s8 * str)
  1440. {
  1441. union iwreq_data iwrq;
  1442. u8 buf[50];
  1443. lbs_deb_enter(LBS_DEB_CMD);
  1444. memset(&iwrq, 0, sizeof(union iwreq_data));
  1445. memset(buf, 0, sizeof(buf));
  1446. snprintf(buf, sizeof(buf) - 1, "%s", str);
  1447. iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
  1448. /* Send Event to upper layer */
  1449. lbs_deb_cmd("Event Indication string = %s\n", (char *)buf);
  1450. lbs_deb_cmd("Event Indication String length = %d\n", iwrq.data.length);
  1451. lbs_deb_cmd("Sending wireless event IWEVCUSTOM for %s\n", str);
  1452. wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
  1453. lbs_deb_leave(LBS_DEB_CMD);
  1454. }
  1455. static int sendconfirmsleep(wlan_private * priv, u8 * cmdptr, u16 size)
  1456. {
  1457. unsigned long flags;
  1458. wlan_adapter *adapter = priv->adapter;
  1459. int ret = 0;
  1460. lbs_deb_enter(LBS_DEB_CMD);
  1461. lbs_deb_cmd("SEND_SLEEPC_CMD: Before download, size of cmd = %d\n",
  1462. size);
  1463. lbs_dbg_hex("SEND_SLEEPC_CMD: Sleep confirm command", cmdptr, size);
  1464. ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
  1465. priv->dnld_sent = DNLD_RES_RECEIVED;
  1466. spin_lock_irqsave(&adapter->driver_lock, flags);
  1467. if (adapter->intcounter || adapter->currenttxskb)
  1468. lbs_deb_cmd("SEND_SLEEPC_CMD: intcounter=%d currenttxskb=%p\n",
  1469. adapter->intcounter, adapter->currenttxskb);
  1470. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1471. if (ret) {
  1472. lbs_pr_alert(
  1473. "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
  1474. } else {
  1475. spin_lock_irqsave(&adapter->driver_lock, flags);
  1476. if (!adapter->intcounter) {
  1477. adapter->psstate = PS_STATE_SLEEP;
  1478. } else {
  1479. lbs_deb_cmd("SEND_SLEEPC_CMD: After sent,IntC=%d\n",
  1480. adapter->intcounter);
  1481. }
  1482. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1483. lbs_deb_cmd("SEND_SLEEPC_CMD: Sent Confirm Sleep command\n");
  1484. lbs_deb_cmd("+");
  1485. }
  1486. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  1487. return ret;
  1488. }
  1489. void libertas_ps_sleep(wlan_private * priv, int wait_option)
  1490. {
  1491. lbs_deb_enter(LBS_DEB_CMD);
  1492. /*
  1493. * PS is currently supported only in Infrastructure mode
  1494. * Remove this check if it is to be supported in IBSS mode also
  1495. */
  1496. libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
  1497. cmd_subcmd_enter_ps, wait_option, 0, NULL);
  1498. lbs_deb_leave(LBS_DEB_CMD);
  1499. }
  1500. /**
  1501. * @brief This function sends Eixt_PS command to firmware.
  1502. *
  1503. * @param priv A pointer to wlan_private structure
  1504. * @param wait_option wait response or not
  1505. * @return n/a
  1506. */
  1507. void libertas_ps_wakeup(wlan_private * priv, int wait_option)
  1508. {
  1509. __le32 Localpsmode;
  1510. lbs_deb_enter(LBS_DEB_CMD);
  1511. Localpsmode = cpu_to_le32(wlan802_11powermodecam);
  1512. lbs_deb_cmd("Exit_PS: Localpsmode = %d\n", wlan802_11powermodecam);
  1513. libertas_prepare_and_send_command(priv, cmd_802_11_ps_mode,
  1514. cmd_subcmd_exit_ps,
  1515. wait_option, 0, &Localpsmode);
  1516. lbs_deb_leave(LBS_DEB_CMD);
  1517. }
  1518. /**
  1519. * @brief This function checks condition and prepares to
  1520. * send sleep confirm command to firmware if ok.
  1521. *
  1522. * @param priv A pointer to wlan_private structure
  1523. * @param psmode Power Saving mode
  1524. * @return n/a
  1525. */
  1526. void libertas_ps_confirm_sleep(wlan_private * priv, u16 psmode)
  1527. {
  1528. unsigned long flags =0;
  1529. wlan_adapter *adapter = priv->adapter;
  1530. u8 allowed = 1;
  1531. lbs_deb_enter(LBS_DEB_CMD);
  1532. if (priv->dnld_sent) {
  1533. allowed = 0;
  1534. lbs_deb_cmd("D");
  1535. }
  1536. spin_lock_irqsave(&adapter->driver_lock, flags);
  1537. if (adapter->cur_cmd) {
  1538. allowed = 0;
  1539. lbs_deb_cmd("C");
  1540. }
  1541. if (adapter->intcounter > 0) {
  1542. allowed = 0;
  1543. lbs_deb_cmd("I%d", adapter->intcounter);
  1544. }
  1545. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1546. if (allowed) {
  1547. lbs_deb_cmd("Sending libertas_ps_confirm_sleep\n");
  1548. sendconfirmsleep(priv, (u8 *) & adapter->libertas_ps_confirm_sleep,
  1549. sizeof(struct PS_CMD_ConfirmSleep));
  1550. } else {
  1551. lbs_deb_cmd("Sleep Confirm has been delayed\n");
  1552. }
  1553. lbs_deb_leave(LBS_DEB_CMD);
  1554. }