cmd.c 50 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(__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 lbs_cmd_hw_spec(lbs_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 lbs_cmd_802_11_ps_mode(lbs_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 lbs_cmd_802_11_inactivity_timeout(lbs_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 lbs_cmd_802_11_sleep_params(lbs_private * priv,
  93. struct cmd_ds_command *cmd,
  94. u16 cmd_action)
  95. {
  96. lbs_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 lbs_cmd_802_11_set_wep(lbs_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. lbs_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 lbs_cmd_802_11_enable_rsn(lbs_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 lbs_cmd_802_11_key_material(lbs_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 lbs_cmd_802_11_reset(lbs_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 lbs_cmd_802_11_get_log(lbs_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 lbs_cmd_802_11_get_stat(lbs_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 lbs_cmd_802_11_snmp_mib(lbs_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. lbs_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 lbs_cmd_802_11_radio_control(lbs_private * priv,
  390. struct cmd_ds_command *cmd,
  391. int cmd_action)
  392. {
  393. lbs_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 lbs_cmd_802_11_rf_tx_power(lbs_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 lbs_cmd_802_11_monitor_mode(lbs_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 lbs_cmd_802_11_rate_adapt_rateset(lbs_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. lbs_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 lbs_cmd_802_11_data_rate(lbs_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. lbs_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] = lbs_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 lbs_cmd_mac_multicast_adr(lbs_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. lbs_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 lbs_cmd_802_11_rf_channel(lbs_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 lbs_cmd_802_11_rssi(lbs_private * priv,
  546. struct cmd_ds_command *cmd)
  547. {
  548. lbs_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 lbs_cmd_reg_access(lbs_private * priv,
  564. struct cmd_ds_command *cmdptr,
  565. u8 cmd_action, void *pdata_buf)
  566. {
  567. struct lbs_offset_value *offval;
  568. lbs_deb_enter(LBS_DEB_CMD);
  569. offval = (struct lbs_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 lbs_cmd_802_11_mac_address(lbs_private * priv,
  622. struct cmd_ds_command *cmd,
  623. u16 cmd_action)
  624. {
  625. lbs_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 lbs_cmd_802_11_eeprom_access(lbs_private * priv,
  641. struct cmd_ds_command *cmd,
  642. int cmd_action, void *pdata_buf)
  643. {
  644. struct lbs_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 lbs_cmd_bt_access(lbs_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 lbs_cmd_fwt_access(lbs_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 lbs_cmd_mesh_access(lbs_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 lbs_cmd_bcn_ctrl(struct lbs_private * priv,
  727. struct cmd_ds_command *cmd,
  728. u16 cmd_action)
  729. {
  730. struct cmd_ds_802_11_beacon_control
  731. *bcn_ctrl = &cmd->params.bcn_ctrl;
  732. struct lbs_adapter *adapter = priv->adapter;
  733. lbs_deb_enter(LBS_DEB_CMD);
  734. cmd->size =
  735. cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
  736. + S_DS_GEN);
  737. cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
  738. bcn_ctrl->action = cpu_to_le16(cmd_action);
  739. bcn_ctrl->beacon_enable = cpu_to_le16(adapter->beacon_enable);
  740. bcn_ctrl->beacon_period = cpu_to_le16(adapter->beacon_period);
  741. lbs_deb_leave(LBS_DEB_CMD);
  742. return 0;
  743. }
  744. static int lbs_cmd_set_boot2_ver(lbs_private * priv,
  745. struct cmd_ds_command *cmd,
  746. u16 cmd_action, void *pdata_buf)
  747. {
  748. struct cmd_ds_set_boot2_ver *boot2_ver = &cmd->params.boot2_ver;
  749. cmd->command = cpu_to_le16(CMD_SET_BOOT2_VER);
  750. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_set_boot2_ver) + S_DS_GEN);
  751. boot2_ver->version = priv->boot2_version;
  752. return 0;
  753. }
  754. /*
  755. * Note: NEVER use lbs_queue_cmd() with addtail==0 other than for
  756. * the command timer, because it does not account for queued commands.
  757. */
  758. void lbs_queue_cmd(lbs_adapter * adapter, struct cmd_ctrl_node *cmdnode, u8 addtail)
  759. {
  760. unsigned long flags;
  761. struct cmd_ds_command *cmdptr;
  762. lbs_deb_enter(LBS_DEB_HOST);
  763. if (!cmdnode) {
  764. lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
  765. goto done;
  766. }
  767. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  768. if (!cmdptr) {
  769. lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n");
  770. goto done;
  771. }
  772. /* Exit_PS command needs to be queued in the header always. */
  773. if (cmdptr->command == CMD_802_11_PS_MODE) {
  774. struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
  775. if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  776. if (adapter->psstate != PS_STATE_FULL_POWER)
  777. addtail = 0;
  778. }
  779. }
  780. spin_lock_irqsave(&adapter->driver_lock, flags);
  781. if (addtail) {
  782. list_add_tail((struct list_head *)cmdnode,
  783. &adapter->cmdpendingq);
  784. adapter->nr_cmd_pending++;
  785. } else
  786. list_add((struct list_head *)cmdnode, &adapter->cmdpendingq);
  787. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  788. lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
  789. le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
  790. done:
  791. lbs_deb_leave(LBS_DEB_HOST);
  792. }
  793. /*
  794. * TODO: Fix the issue when DownloadcommandToStation is being called the
  795. * second time when the command times out. All the cmdptr->xxx are in little
  796. * endian and therefore all the comparissions will fail.
  797. * For now - we are not performing the endian conversion the second time - but
  798. * for PS and DEEP_SLEEP we need to worry
  799. */
  800. static int DownloadcommandToStation(lbs_private * priv,
  801. struct cmd_ctrl_node *cmdnode)
  802. {
  803. unsigned long flags;
  804. struct cmd_ds_command *cmdptr;
  805. lbs_adapter *adapter = priv->adapter;
  806. int ret = -1;
  807. u16 cmdsize;
  808. u16 command;
  809. lbs_deb_enter(LBS_DEB_HOST);
  810. if (!adapter || !cmdnode) {
  811. lbs_deb_host("DNLD_CMD: adapter or cmdmode is NULL\n");
  812. goto done;
  813. }
  814. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  815. spin_lock_irqsave(&adapter->driver_lock, flags);
  816. if (!cmdptr || !cmdptr->size) {
  817. lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n");
  818. __lbs_cleanup_and_insert_cmd(priv, cmdnode);
  819. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  820. goto done;
  821. }
  822. adapter->cur_cmd = cmdnode;
  823. adapter->cur_cmd_retcode = 0;
  824. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  825. cmdsize = cmdptr->size;
  826. command = cpu_to_le16(cmdptr->command);
  827. lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n",
  828. command, le16_to_cpu(cmdptr->size), jiffies);
  829. lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", cmdnode->bufvirtualaddr, cmdsize);
  830. cmdnode->cmdwaitqwoken = 0;
  831. cmdsize = cpu_to_le16(cmdsize);
  832. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
  833. if (ret != 0) {
  834. lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n");
  835. spin_lock_irqsave(&adapter->driver_lock, flags);
  836. adapter->cur_cmd_retcode = ret;
  837. __lbs_cleanup_and_insert_cmd(priv, adapter->cur_cmd);
  838. adapter->nr_cmd_pending--;
  839. adapter->cur_cmd = NULL;
  840. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  841. goto done;
  842. }
  843. lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
  844. /* Setup the timer after transmit command */
  845. if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
  846. || command == CMD_802_11_ASSOCIATE)
  847. mod_timer(&adapter->command_timer, jiffies + (10*HZ));
  848. else
  849. mod_timer(&adapter->command_timer, jiffies + (5*HZ));
  850. ret = 0;
  851. done:
  852. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  853. return ret;
  854. }
  855. static int lbs_cmd_mac_control(lbs_private * priv,
  856. struct cmd_ds_command *cmd)
  857. {
  858. struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
  859. lbs_deb_enter(LBS_DEB_CMD);
  860. cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
  861. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
  862. mac->action = cpu_to_le16(priv->adapter->currentpacketfilter);
  863. lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
  864. le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
  865. lbs_deb_leave(LBS_DEB_CMD);
  866. return 0;
  867. }
  868. /**
  869. * This function inserts command node to cmdfreeq
  870. * after cleans it. Requires adapter->driver_lock held.
  871. */
  872. void __lbs_cleanup_and_insert_cmd(lbs_private * priv, struct cmd_ctrl_node *ptempcmd)
  873. {
  874. lbs_adapter *adapter = priv->adapter;
  875. if (!ptempcmd)
  876. return;
  877. cleanup_cmdnode(ptempcmd);
  878. list_add_tail((struct list_head *)ptempcmd, &adapter->cmdfreeq);
  879. }
  880. static void lbs_cleanup_and_insert_cmd(lbs_private * priv, struct cmd_ctrl_node *ptempcmd)
  881. {
  882. unsigned long flags;
  883. spin_lock_irqsave(&priv->adapter->driver_lock, flags);
  884. __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
  885. spin_unlock_irqrestore(&priv->adapter->driver_lock, flags);
  886. }
  887. int lbs_set_radio_control(lbs_private * priv)
  888. {
  889. int ret = 0;
  890. lbs_deb_enter(LBS_DEB_CMD);
  891. ret = lbs_prepare_and_send_command(priv,
  892. CMD_802_11_RADIO_CONTROL,
  893. CMD_ACT_SET,
  894. CMD_OPTION_WAITFORRSP, 0, NULL);
  895. lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
  896. priv->adapter->radioon, priv->adapter->preamble);
  897. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  898. return ret;
  899. }
  900. int lbs_set_mac_packet_filter(lbs_private * priv)
  901. {
  902. int ret = 0;
  903. lbs_deb_enter(LBS_DEB_CMD);
  904. /* Send MAC control command to station */
  905. ret = lbs_prepare_and_send_command(priv,
  906. CMD_MAC_CONTROL, 0, 0, 0, NULL);
  907. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  908. return ret;
  909. }
  910. /**
  911. * @brief This function prepare the command before send to firmware.
  912. *
  913. * @param priv A pointer to lbs_private structure
  914. * @param cmd_no command number
  915. * @param cmd_action command action: GET or SET
  916. * @param wait_option wait option: wait response or not
  917. * @param cmd_oid cmd oid: treated as sub command
  918. * @param pdata_buf A pointer to informaion buffer
  919. * @return 0 or -1
  920. */
  921. int lbs_prepare_and_send_command(lbs_private * priv,
  922. u16 cmd_no,
  923. u16 cmd_action,
  924. u16 wait_option, u32 cmd_oid, void *pdata_buf)
  925. {
  926. int ret = 0;
  927. lbs_adapter *adapter = priv->adapter;
  928. struct cmd_ctrl_node *cmdnode;
  929. struct cmd_ds_command *cmdptr;
  930. unsigned long flags;
  931. lbs_deb_enter(LBS_DEB_HOST);
  932. if (!adapter) {
  933. lbs_deb_host("PREP_CMD: adapter is NULL\n");
  934. ret = -1;
  935. goto done;
  936. }
  937. if (adapter->surpriseremoved) {
  938. lbs_deb_host("PREP_CMD: card removed\n");
  939. ret = -1;
  940. goto done;
  941. }
  942. cmdnode = lbs_get_free_cmd_ctrl_node(priv);
  943. if (cmdnode == NULL) {
  944. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  945. /* Wake up main thread to execute next command */
  946. wake_up_interruptible(&priv->waitq);
  947. ret = -1;
  948. goto done;
  949. }
  950. lbs_set_cmd_ctrl_node(priv, cmdnode, cmd_oid, wait_option, pdata_buf);
  951. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  952. lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
  953. if (!cmdptr) {
  954. lbs_deb_host("PREP_CMD: cmdptr is NULL\n");
  955. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  956. ret = -1;
  957. goto done;
  958. }
  959. /* Set sequence number, command and INT option */
  960. adapter->seqnum++;
  961. cmdptr->seqnum = cpu_to_le16(adapter->seqnum);
  962. cmdptr->command = cpu_to_le16(cmd_no);
  963. cmdptr->result = 0;
  964. switch (cmd_no) {
  965. case CMD_GET_HW_SPEC:
  966. ret = lbs_cmd_hw_spec(priv, cmdptr);
  967. break;
  968. case CMD_802_11_PS_MODE:
  969. ret = lbs_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
  970. break;
  971. case CMD_802_11_SCAN:
  972. ret = lbs_cmd_80211_scan(priv, cmdptr, pdata_buf);
  973. break;
  974. case CMD_MAC_CONTROL:
  975. ret = lbs_cmd_mac_control(priv, cmdptr);
  976. break;
  977. case CMD_802_11_ASSOCIATE:
  978. case CMD_802_11_REASSOCIATE:
  979. ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
  980. break;
  981. case CMD_802_11_DEAUTHENTICATE:
  982. ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
  983. break;
  984. case CMD_802_11_SET_WEP:
  985. ret = lbs_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
  986. break;
  987. case CMD_802_11_AD_HOC_START:
  988. ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
  989. break;
  990. case CMD_CODE_DNLD:
  991. break;
  992. case CMD_802_11_RESET:
  993. ret = lbs_cmd_802_11_reset(priv, cmdptr, cmd_action);
  994. break;
  995. case CMD_802_11_GET_LOG:
  996. ret = lbs_cmd_802_11_get_log(priv, cmdptr);
  997. break;
  998. case CMD_802_11_AUTHENTICATE:
  999. ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
  1000. break;
  1001. case CMD_802_11_GET_STAT:
  1002. ret = lbs_cmd_802_11_get_stat(priv, cmdptr);
  1003. break;
  1004. case CMD_802_11_SNMP_MIB:
  1005. ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
  1006. cmd_action, cmd_oid, pdata_buf);
  1007. break;
  1008. case CMD_MAC_REG_ACCESS:
  1009. case CMD_BBP_REG_ACCESS:
  1010. case CMD_RF_REG_ACCESS:
  1011. ret = lbs_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
  1012. break;
  1013. case CMD_802_11_RF_CHANNEL:
  1014. ret = lbs_cmd_802_11_rf_channel(priv, cmdptr,
  1015. cmd_action, pdata_buf);
  1016. break;
  1017. case CMD_802_11_RF_TX_POWER:
  1018. ret = lbs_cmd_802_11_rf_tx_power(priv, cmdptr,
  1019. cmd_action, pdata_buf);
  1020. break;
  1021. case CMD_802_11_RADIO_CONTROL:
  1022. ret = lbs_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
  1023. break;
  1024. case CMD_802_11_DATA_RATE:
  1025. ret = lbs_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
  1026. break;
  1027. case CMD_802_11_RATE_ADAPT_RATESET:
  1028. ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
  1029. cmdptr, cmd_action);
  1030. break;
  1031. case CMD_MAC_MULTICAST_ADR:
  1032. ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
  1033. break;
  1034. case CMD_802_11_MONITOR_MODE:
  1035. ret = lbs_cmd_802_11_monitor_mode(priv, cmdptr,
  1036. cmd_action, pdata_buf);
  1037. break;
  1038. case CMD_802_11_AD_HOC_JOIN:
  1039. ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
  1040. break;
  1041. case CMD_802_11_RSSI:
  1042. ret = lbs_cmd_802_11_rssi(priv, cmdptr);
  1043. break;
  1044. case CMD_802_11_AD_HOC_STOP:
  1045. ret = lbs_cmd_80211_ad_hoc_stop(priv, cmdptr);
  1046. break;
  1047. case CMD_802_11_ENABLE_RSN:
  1048. ret = lbs_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
  1049. pdata_buf);
  1050. break;
  1051. case CMD_802_11_KEY_MATERIAL:
  1052. ret = lbs_cmd_802_11_key_material(priv, cmdptr, cmd_action,
  1053. cmd_oid, pdata_buf);
  1054. break;
  1055. case CMD_802_11_PAIRWISE_TSC:
  1056. break;
  1057. case CMD_802_11_GROUP_TSC:
  1058. break;
  1059. case CMD_802_11_MAC_ADDRESS:
  1060. ret = lbs_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
  1061. break;
  1062. case CMD_802_11_EEPROM_ACCESS:
  1063. ret = lbs_cmd_802_11_eeprom_access(priv, cmdptr,
  1064. cmd_action, pdata_buf);
  1065. break;
  1066. case CMD_802_11_SET_AFC:
  1067. case CMD_802_11_GET_AFC:
  1068. cmdptr->command = cpu_to_le16(cmd_no);
  1069. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
  1070. S_DS_GEN);
  1071. memmove(&cmdptr->params.afc,
  1072. pdata_buf, sizeof(struct cmd_ds_802_11_afc));
  1073. ret = 0;
  1074. goto done;
  1075. case CMD_802_11D_DOMAIN_INFO:
  1076. ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
  1077. cmd_no, cmd_action);
  1078. break;
  1079. case CMD_802_11_SLEEP_PARAMS:
  1080. ret = lbs_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
  1081. break;
  1082. case CMD_802_11_INACTIVITY_TIMEOUT:
  1083. ret = lbs_cmd_802_11_inactivity_timeout(priv, cmdptr,
  1084. cmd_action, pdata_buf);
  1085. lbs_set_cmd_ctrl_node(priv, cmdnode, 0, 0, pdata_buf);
  1086. break;
  1087. case CMD_802_11_TPC_CFG:
  1088. cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
  1089. cmdptr->size =
  1090. cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
  1091. S_DS_GEN);
  1092. memmove(&cmdptr->params.tpccfg,
  1093. pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
  1094. ret = 0;
  1095. break;
  1096. case CMD_802_11_LED_GPIO_CTRL:
  1097. {
  1098. struct mrvlietypes_ledgpio *gpio =
  1099. (struct mrvlietypes_ledgpio*)
  1100. cmdptr->params.ledgpio.data;
  1101. memmove(&cmdptr->params.ledgpio,
  1102. pdata_buf,
  1103. sizeof(struct cmd_ds_802_11_led_ctrl));
  1104. cmdptr->command =
  1105. cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
  1106. #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
  1107. cmdptr->size =
  1108. cpu_to_le16(gpio->header.len + S_DS_GEN +
  1109. ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
  1110. gpio->header.len = cpu_to_le16(gpio->header.len);
  1111. ret = 0;
  1112. break;
  1113. }
  1114. case CMD_802_11_PWR_CFG:
  1115. cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG);
  1116. cmdptr->size =
  1117. cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
  1118. S_DS_GEN);
  1119. memmove(&cmdptr->params.pwrcfg, pdata_buf,
  1120. sizeof(struct cmd_ds_802_11_pwr_cfg));
  1121. ret = 0;
  1122. break;
  1123. case CMD_BT_ACCESS:
  1124. ret = lbs_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
  1125. break;
  1126. case CMD_FWT_ACCESS:
  1127. ret = lbs_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
  1128. break;
  1129. case CMD_MESH_ACCESS:
  1130. ret = lbs_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
  1131. break;
  1132. case CMD_SET_BOOT2_VER:
  1133. ret = lbs_cmd_set_boot2_ver(priv, cmdptr, cmd_action, pdata_buf);
  1134. break;
  1135. case CMD_GET_TSF:
  1136. cmdptr->command = cpu_to_le16(CMD_GET_TSF);
  1137. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
  1138. S_DS_GEN);
  1139. ret = 0;
  1140. break;
  1141. case CMD_802_11_BEACON_CTRL:
  1142. ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
  1143. break;
  1144. default:
  1145. lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
  1146. ret = -1;
  1147. break;
  1148. }
  1149. /* return error, since the command preparation failed */
  1150. if (ret != 0) {
  1151. lbs_deb_host("PREP_CMD: command preparation failed\n");
  1152. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1153. ret = -1;
  1154. goto done;
  1155. }
  1156. cmdnode->cmdwaitqwoken = 0;
  1157. lbs_queue_cmd(adapter, cmdnode, 1);
  1158. wake_up_interruptible(&priv->waitq);
  1159. if (wait_option & CMD_OPTION_WAITFORRSP) {
  1160. lbs_deb_host("PREP_CMD: wait for response\n");
  1161. might_sleep();
  1162. wait_event_interruptible(cmdnode->cmdwait_q,
  1163. cmdnode->cmdwaitqwoken);
  1164. }
  1165. spin_lock_irqsave(&adapter->driver_lock, flags);
  1166. if (adapter->cur_cmd_retcode) {
  1167. lbs_deb_host("PREP_CMD: command failed with return code %d\n",
  1168. adapter->cur_cmd_retcode);
  1169. adapter->cur_cmd_retcode = 0;
  1170. ret = -1;
  1171. }
  1172. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1173. done:
  1174. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1175. return ret;
  1176. }
  1177. EXPORT_SYMBOL_GPL(lbs_prepare_and_send_command);
  1178. /**
  1179. * @brief This function allocates the command buffer and link
  1180. * it to command free queue.
  1181. *
  1182. * @param priv A pointer to lbs_private structure
  1183. * @return 0 or -1
  1184. */
  1185. int lbs_allocate_cmd_buffer(lbs_private * priv)
  1186. {
  1187. int ret = 0;
  1188. u32 ulbufsize;
  1189. u32 i;
  1190. struct cmd_ctrl_node *tempcmd_array;
  1191. u8 *ptempvirtualaddr;
  1192. lbs_adapter *adapter = priv->adapter;
  1193. lbs_deb_enter(LBS_DEB_HOST);
  1194. /* Allocate and initialize cmdCtrlNode */
  1195. ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
  1196. if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
  1197. lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
  1198. ret = -1;
  1199. goto done;
  1200. }
  1201. adapter->cmd_array = tempcmd_array;
  1202. /* Allocate and initialize command buffers */
  1203. ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
  1204. for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
  1205. if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
  1206. lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
  1207. ret = -1;
  1208. goto done;
  1209. }
  1210. /* Update command buffer virtual */
  1211. tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
  1212. }
  1213. for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
  1214. init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
  1215. lbs_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
  1216. }
  1217. ret = 0;
  1218. done:
  1219. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1220. return ret;
  1221. }
  1222. /**
  1223. * @brief This function frees the command buffer.
  1224. *
  1225. * @param priv A pointer to lbs_private structure
  1226. * @return 0 or -1
  1227. */
  1228. int lbs_free_cmd_buffer(lbs_private * priv)
  1229. {
  1230. u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
  1231. unsigned int i;
  1232. struct cmd_ctrl_node *tempcmd_array;
  1233. lbs_adapter *adapter = priv->adapter;
  1234. lbs_deb_enter(LBS_DEB_HOST);
  1235. /* need to check if cmd array is allocated or not */
  1236. if (adapter->cmd_array == NULL) {
  1237. lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
  1238. goto done;
  1239. }
  1240. tempcmd_array = adapter->cmd_array;
  1241. /* Release shared memory buffers */
  1242. ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
  1243. for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
  1244. if (tempcmd_array[i].bufvirtualaddr) {
  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. kfree(adapter->cmd_array);
  1252. adapter->cmd_array = NULL;
  1253. }
  1254. done:
  1255. lbs_deb_leave(LBS_DEB_HOST);
  1256. return 0;
  1257. }
  1258. /**
  1259. * @brief This function gets a free command node if available in
  1260. * command free queue.
  1261. *
  1262. * @param priv A pointer to lbs_private structure
  1263. * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
  1264. */
  1265. struct cmd_ctrl_node *lbs_get_free_cmd_ctrl_node(lbs_private * priv)
  1266. {
  1267. struct cmd_ctrl_node *tempnode;
  1268. lbs_adapter *adapter = priv->adapter;
  1269. unsigned long flags;
  1270. lbs_deb_enter(LBS_DEB_HOST);
  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_host("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. cleanup_cmdnode(tempnode);
  1284. lbs_deb_leave(LBS_DEB_HOST);
  1285. return tempnode;
  1286. }
  1287. /**
  1288. * @brief This function cleans command node.
  1289. *
  1290. * @param ptempnode A pointer to cmdCtrlNode structure
  1291. * @return n/a
  1292. */
  1293. static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
  1294. {
  1295. lbs_deb_enter(LBS_DEB_HOST);
  1296. if (!ptempnode)
  1297. return;
  1298. ptempnode->cmdwaitqwoken = 1;
  1299. wake_up_interruptible(&ptempnode->cmdwait_q);
  1300. ptempnode->status = 0;
  1301. ptempnode->cmd_oid = (u32) 0;
  1302. ptempnode->wait_option = 0;
  1303. ptempnode->pdata_buf = NULL;
  1304. if (ptempnode->bufvirtualaddr != NULL)
  1305. memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
  1306. lbs_deb_leave(LBS_DEB_HOST);
  1307. }
  1308. /**
  1309. * @brief This function initializes the command node.
  1310. *
  1311. * @param priv A pointer to lbs_private structure
  1312. * @param ptempnode A pointer to cmd_ctrl_node structure
  1313. * @param cmd_oid cmd oid: treated as sub command
  1314. * @param wait_option wait option: wait response or not
  1315. * @param pdata_buf A pointer to informaion buffer
  1316. * @return 0 or -1
  1317. */
  1318. void lbs_set_cmd_ctrl_node(lbs_private * priv,
  1319. struct cmd_ctrl_node *ptempnode,
  1320. u32 cmd_oid, u16 wait_option, void *pdata_buf)
  1321. {
  1322. lbs_deb_enter(LBS_DEB_HOST);
  1323. if (!ptempnode)
  1324. return;
  1325. ptempnode->cmd_oid = cmd_oid;
  1326. ptempnode->wait_option = wait_option;
  1327. ptempnode->pdata_buf = pdata_buf;
  1328. lbs_deb_leave(LBS_DEB_HOST);
  1329. }
  1330. /**
  1331. * @brief This function executes next command in command
  1332. * pending queue. It will put fimware back to PS mode
  1333. * if applicable.
  1334. *
  1335. * @param priv A pointer to lbs_private structure
  1336. * @return 0 or -1
  1337. */
  1338. int lbs_execute_next_command(lbs_private * priv)
  1339. {
  1340. lbs_adapter *adapter = priv->adapter;
  1341. struct cmd_ctrl_node *cmdnode = NULL;
  1342. struct cmd_ds_command *cmdptr;
  1343. unsigned long flags;
  1344. int ret = 0;
  1345. // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1346. // only caller to us is lbs_thread() and we get even when a
  1347. // data packet is received
  1348. lbs_deb_enter(LBS_DEB_THREAD);
  1349. spin_lock_irqsave(&adapter->driver_lock, flags);
  1350. if (adapter->cur_cmd) {
  1351. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1352. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1353. ret = -1;
  1354. goto done;
  1355. }
  1356. if (!list_empty(&adapter->cmdpendingq)) {
  1357. cmdnode = (struct cmd_ctrl_node *)
  1358. adapter->cmdpendingq.next;
  1359. }
  1360. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1361. if (cmdnode) {
  1362. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  1363. if (is_command_allowed_in_ps(cmdptr->command)) {
  1364. if ((adapter->psstate == PS_STATE_SLEEP) ||
  1365. (adapter->psstate == PS_STATE_PRE_SLEEP)) {
  1366. lbs_deb_host(
  1367. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1368. le16_to_cpu(cmdptr->command),
  1369. adapter->psstate);
  1370. ret = -1;
  1371. goto done;
  1372. }
  1373. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1374. "0x%04x in psstate %d\n",
  1375. le16_to_cpu(cmdptr->command),
  1376. adapter->psstate);
  1377. } else if (adapter->psstate != PS_STATE_FULL_POWER) {
  1378. /*
  1379. * 1. Non-PS command:
  1380. * Queue it. set needtowakeup to TRUE if current state
  1381. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1382. * 2. PS command but not Exit_PS:
  1383. * Ignore it.
  1384. * 3. PS command Exit_PS:
  1385. * Set needtowakeup to TRUE if current state is SLEEP,
  1386. * otherwise send this command down to firmware
  1387. * immediately.
  1388. */
  1389. if (cmdptr->command !=
  1390. cpu_to_le16(CMD_802_11_PS_MODE)) {
  1391. /* Prepare to send Exit PS,
  1392. * this non PS command will be sent later */
  1393. if ((adapter->psstate == PS_STATE_SLEEP)
  1394. || (adapter->psstate == PS_STATE_PRE_SLEEP)
  1395. ) {
  1396. /* w/ new scheme, it will not reach here.
  1397. since it is blocked in main_thread. */
  1398. adapter->needtowakeup = 1;
  1399. } else
  1400. lbs_ps_wakeup(priv, 0);
  1401. ret = 0;
  1402. goto done;
  1403. } else {
  1404. /*
  1405. * PS command. Ignore it if it is not Exit_PS.
  1406. * otherwise send it down immediately.
  1407. */
  1408. struct cmd_ds_802_11_ps_mode *psm =
  1409. &cmdptr->params.psmode;
  1410. lbs_deb_host(
  1411. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1412. psm->action);
  1413. if (psm->action !=
  1414. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1415. lbs_deb_host(
  1416. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1417. list_del((struct list_head *)cmdnode);
  1418. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1419. ret = 0;
  1420. goto done;
  1421. }
  1422. if ((adapter->psstate == PS_STATE_SLEEP) ||
  1423. (adapter->psstate == PS_STATE_PRE_SLEEP)) {
  1424. lbs_deb_host(
  1425. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1426. list_del((struct list_head *)cmdnode);
  1427. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1428. adapter->needtowakeup = 1;
  1429. ret = 0;
  1430. goto done;
  1431. }
  1432. lbs_deb_host(
  1433. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1434. }
  1435. }
  1436. list_del((struct list_head *)cmdnode);
  1437. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1438. le16_to_cpu(cmdptr->command));
  1439. DownloadcommandToStation(priv, cmdnode);
  1440. } else {
  1441. /*
  1442. * check if in power save mode, if yes, put the device back
  1443. * to PS mode
  1444. */
  1445. if ((adapter->psmode != LBS802_11POWERMODECAM) &&
  1446. (adapter->psstate == PS_STATE_FULL_POWER) &&
  1447. ((adapter->connect_status == LBS_CONNECTED) ||
  1448. (adapter->mesh_connect_status == LBS_CONNECTED))) {
  1449. if (adapter->secinfo.WPAenabled ||
  1450. adapter->secinfo.WPA2enabled) {
  1451. /* check for valid WPA group keys */
  1452. if (adapter->wpa_mcast_key.len ||
  1453. adapter->wpa_unicast_key.len) {
  1454. lbs_deb_host(
  1455. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1456. " go back to PS_SLEEP");
  1457. lbs_ps_sleep(priv, 0);
  1458. }
  1459. } else {
  1460. lbs_deb_host(
  1461. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1462. "go back to PS_SLEEP");
  1463. lbs_ps_sleep(priv, 0);
  1464. }
  1465. }
  1466. }
  1467. ret = 0;
  1468. done:
  1469. lbs_deb_leave(LBS_DEB_THREAD);
  1470. return ret;
  1471. }
  1472. void lbs_send_iwevcustom_event(lbs_private *priv, s8 *str)
  1473. {
  1474. union iwreq_data iwrq;
  1475. u8 buf[50];
  1476. lbs_deb_enter(LBS_DEB_WEXT);
  1477. memset(&iwrq, 0, sizeof(union iwreq_data));
  1478. memset(buf, 0, sizeof(buf));
  1479. snprintf(buf, sizeof(buf) - 1, "%s", str);
  1480. iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
  1481. /* Send Event to upper layer */
  1482. lbs_deb_wext("event indication string %s\n", (char *)buf);
  1483. lbs_deb_wext("event indication length %d\n", iwrq.data.length);
  1484. lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
  1485. wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
  1486. lbs_deb_leave(LBS_DEB_WEXT);
  1487. }
  1488. static int sendconfirmsleep(lbs_private *priv, u8 *cmdptr, u16 size)
  1489. {
  1490. unsigned long flags;
  1491. lbs_adapter *adapter = priv->adapter;
  1492. int ret = 0;
  1493. lbs_deb_enter(LBS_DEB_HOST);
  1494. lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
  1495. size);
  1496. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
  1497. ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
  1498. priv->dnld_sent = DNLD_RES_RECEIVED;
  1499. spin_lock_irqsave(&adapter->driver_lock, flags);
  1500. if (adapter->intcounter || adapter->currenttxskb)
  1501. lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
  1502. adapter->intcounter, adapter->currenttxskb);
  1503. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1504. if (ret) {
  1505. lbs_pr_alert(
  1506. "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
  1507. } else {
  1508. spin_lock_irqsave(&adapter->driver_lock, flags);
  1509. if (!adapter->intcounter) {
  1510. adapter->psstate = PS_STATE_SLEEP;
  1511. } else {
  1512. lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
  1513. adapter->intcounter);
  1514. }
  1515. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1516. lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
  1517. }
  1518. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1519. return ret;
  1520. }
  1521. void lbs_ps_sleep(lbs_private * priv, int wait_option)
  1522. {
  1523. lbs_deb_enter(LBS_DEB_HOST);
  1524. /*
  1525. * PS is currently supported only in Infrastructure mode
  1526. * Remove this check if it is to be supported in IBSS mode also
  1527. */
  1528. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1529. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1530. lbs_deb_leave(LBS_DEB_HOST);
  1531. }
  1532. /**
  1533. * @brief This function sends Exit_PS command to firmware.
  1534. *
  1535. * @param priv A pointer to lbs_private structure
  1536. * @param wait_option wait response or not
  1537. * @return n/a
  1538. */
  1539. void lbs_ps_wakeup(lbs_private * priv, int wait_option)
  1540. {
  1541. __le32 Localpsmode;
  1542. lbs_deb_enter(LBS_DEB_HOST);
  1543. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1544. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1545. CMD_SUBCMD_EXIT_PS,
  1546. wait_option, 0, &Localpsmode);
  1547. lbs_deb_leave(LBS_DEB_HOST);
  1548. }
  1549. /**
  1550. * @brief This function checks condition and prepares to
  1551. * send sleep confirm command to firmware if ok.
  1552. *
  1553. * @param priv A pointer to lbs_private structure
  1554. * @param psmode Power Saving mode
  1555. * @return n/a
  1556. */
  1557. void lbs_ps_confirm_sleep(lbs_private * priv, u16 psmode)
  1558. {
  1559. unsigned long flags =0;
  1560. lbs_adapter *adapter = priv->adapter;
  1561. u8 allowed = 1;
  1562. lbs_deb_enter(LBS_DEB_HOST);
  1563. if (priv->dnld_sent) {
  1564. allowed = 0;
  1565. lbs_deb_host("dnld_sent was set");
  1566. }
  1567. spin_lock_irqsave(&adapter->driver_lock, flags);
  1568. if (adapter->cur_cmd) {
  1569. allowed = 0;
  1570. lbs_deb_host("cur_cmd was set");
  1571. }
  1572. if (adapter->intcounter > 0) {
  1573. allowed = 0;
  1574. lbs_deb_host("intcounter %d", adapter->intcounter);
  1575. }
  1576. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1577. if (allowed) {
  1578. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1579. sendconfirmsleep(priv, (u8 *) & adapter->lbs_ps_confirm_sleep,
  1580. sizeof(struct PS_CMD_ConfirmSleep));
  1581. } else {
  1582. lbs_deb_host("sleep confirm has been delayed\n");
  1583. }
  1584. lbs_deb_leave(LBS_DEB_HOST);
  1585. }