cmd.c 49 KB

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