cmd.c 54 KB

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