cmd.c 53 KB

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