cmd.c 50 KB

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