cmd.c 56 KB

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