cmd.c 50 KB

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