cmd.c 49 KB

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