cmd.c 49 KB

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