cmd.c 57 KB

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