cmd.c 54 KB

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