cmd.c 49 KB

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