cmd.c 49 KB

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