cmd.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047
  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_reset(struct cmd_ds_command *cmd, int cmd_action)
  400. {
  401. struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
  402. lbs_deb_enter(LBS_DEB_CMD);
  403. cmd->command = cpu_to_le16(CMD_802_11_RESET);
  404. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
  405. reset->action = cpu_to_le16(cmd_action);
  406. lbs_deb_leave(LBS_DEB_CMD);
  407. return 0;
  408. }
  409. static int lbs_cmd_802_11_snmp_mib(struct lbs_private *priv,
  410. struct cmd_ds_command *cmd,
  411. int cmd_action,
  412. int cmd_oid, void *pdata_buf)
  413. {
  414. struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
  415. u8 ucTemp;
  416. lbs_deb_enter(LBS_DEB_CMD);
  417. lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
  418. cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB);
  419. cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
  420. switch (cmd_oid) {
  421. case OID_802_11_INFRASTRUCTURE_MODE:
  422. {
  423. u8 mode = (u8) (size_t) pdata_buf;
  424. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  425. pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I);
  426. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u8));
  427. if (mode == IW_MODE_ADHOC) {
  428. ucTemp = SNMP_MIB_VALUE_ADHOC;
  429. } else {
  430. /* Infra and Auto modes */
  431. ucTemp = SNMP_MIB_VALUE_INFRA;
  432. }
  433. memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
  434. break;
  435. }
  436. case OID_802_11D_ENABLE:
  437. {
  438. u32 ulTemp;
  439. pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I);
  440. if (cmd_action == CMD_ACT_SET) {
  441. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  442. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  443. ulTemp = *(u32 *)pdata_buf;
  444. *((__le16 *)(pSNMPMIB->value)) =
  445. cpu_to_le16((u16) ulTemp);
  446. }
  447. break;
  448. }
  449. case OID_802_11_FRAGMENTATION_THRESHOLD:
  450. {
  451. u32 ulTemp;
  452. pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I);
  453. if (cmd_action == CMD_ACT_GET) {
  454. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
  455. } else if (cmd_action == CMD_ACT_SET) {
  456. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  457. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  458. ulTemp = *((u32 *) pdata_buf);
  459. *((__le16 *)(pSNMPMIB->value)) =
  460. cpu_to_le16((u16) ulTemp);
  461. }
  462. break;
  463. }
  464. case OID_802_11_RTS_THRESHOLD:
  465. {
  466. u32 ulTemp;
  467. pSNMPMIB->oid = cpu_to_le16(RTSTHRESH_I);
  468. if (cmd_action == CMD_ACT_GET) {
  469. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
  470. } else if (cmd_action == CMD_ACT_SET) {
  471. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  472. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  473. ulTemp = *((u32 *)pdata_buf);
  474. *(__le16 *)(pSNMPMIB->value) =
  475. cpu_to_le16((u16) ulTemp);
  476. }
  477. break;
  478. }
  479. case OID_802_11_TX_RETRYCOUNT:
  480. pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I);
  481. if (cmd_action == CMD_ACT_GET) {
  482. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
  483. } else if (cmd_action == CMD_ACT_SET) {
  484. pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
  485. pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
  486. *((__le16 *)(pSNMPMIB->value)) =
  487. cpu_to_le16((u16) priv->txretrycount);
  488. }
  489. break;
  490. default:
  491. break;
  492. }
  493. lbs_deb_cmd(
  494. "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
  495. le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
  496. le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
  497. lbs_deb_cmd(
  498. "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
  499. le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
  500. le16_to_cpu(pSNMPMIB->bufsize),
  501. le16_to_cpu(*(__le16 *) pSNMPMIB->value));
  502. lbs_deb_leave(LBS_DEB_CMD);
  503. return 0;
  504. }
  505. static int lbs_cmd_802_11_rf_tx_power(struct cmd_ds_command *cmd,
  506. u16 cmd_action, void *pdata_buf)
  507. {
  508. struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
  509. lbs_deb_enter(LBS_DEB_CMD);
  510. cmd->size =
  511. cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
  512. cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
  513. prtp->action = cpu_to_le16(cmd_action);
  514. lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
  515. le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
  516. le16_to_cpu(prtp->action));
  517. switch (cmd_action) {
  518. case CMD_ACT_TX_POWER_OPT_GET:
  519. prtp->action = cpu_to_le16(CMD_ACT_GET);
  520. prtp->currentlevel = 0;
  521. break;
  522. case CMD_ACT_TX_POWER_OPT_SET_HIGH:
  523. prtp->action = cpu_to_le16(CMD_ACT_SET);
  524. prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH);
  525. break;
  526. case CMD_ACT_TX_POWER_OPT_SET_MID:
  527. prtp->action = cpu_to_le16(CMD_ACT_SET);
  528. prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID);
  529. break;
  530. case CMD_ACT_TX_POWER_OPT_SET_LOW:
  531. prtp->action = cpu_to_le16(CMD_ACT_SET);
  532. prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
  533. break;
  534. }
  535. lbs_deb_leave(LBS_DEB_CMD);
  536. return 0;
  537. }
  538. static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
  539. u16 cmd_action, void *pdata_buf)
  540. {
  541. struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
  542. cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
  543. cmd->size =
  544. cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
  545. S_DS_GEN);
  546. monitor->action = cpu_to_le16(cmd_action);
  547. if (cmd_action == CMD_ACT_SET) {
  548. monitor->mode =
  549. cpu_to_le16((u16) (*(u32 *) pdata_buf));
  550. }
  551. return 0;
  552. }
  553. static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
  554. {
  555. /* Bit Rate
  556. * 15:13 Reserved
  557. * 12 54 Mbps
  558. * 11 48 Mbps
  559. * 10 36 Mbps
  560. * 9 24 Mbps
  561. * 8 18 Mbps
  562. * 7 12 Mbps
  563. * 6 9 Mbps
  564. * 5 6 Mbps
  565. * 4 Reserved
  566. * 3 11 Mbps
  567. * 2 5.5 Mbps
  568. * 1 2 Mbps
  569. * 0 1 Mbps
  570. **/
  571. uint16_t ratemask;
  572. int i = lbs_data_rate_to_fw_index(rate);
  573. if (lower_rates_ok)
  574. ratemask = (0x1fef >> (12 - i));
  575. else
  576. ratemask = (1 << i);
  577. return cpu_to_le16(ratemask);
  578. }
  579. int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
  580. uint16_t cmd_action)
  581. {
  582. struct cmd_ds_802_11_rate_adapt_rateset cmd;
  583. int ret;
  584. lbs_deb_enter(LBS_DEB_CMD);
  585. if (!priv->cur_rate && !priv->enablehwauto)
  586. return -EINVAL;
  587. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  588. cmd.action = cpu_to_le16(cmd_action);
  589. cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
  590. cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
  591. ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
  592. if (!ret && cmd_action == CMD_ACT_GET) {
  593. priv->ratebitmap = le16_to_cpu(cmd.bitmap);
  594. priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
  595. }
  596. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  597. return ret;
  598. }
  599. EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
  600. /**
  601. * @brief Set the data rate
  602. *
  603. * @param priv A pointer to struct lbs_private structure
  604. * @param rate The desired data rate, or 0 to clear a locked rate
  605. *
  606. * @return 0 on success, error on failure
  607. */
  608. int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
  609. {
  610. struct cmd_ds_802_11_data_rate cmd;
  611. int ret = 0;
  612. lbs_deb_enter(LBS_DEB_CMD);
  613. memset(&cmd, 0, sizeof(cmd));
  614. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  615. if (rate > 0) {
  616. cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
  617. cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
  618. if (cmd.rates[0] == 0) {
  619. lbs_deb_cmd("DATA_RATE: invalid requested rate of"
  620. " 0x%02X\n", rate);
  621. ret = 0;
  622. goto out;
  623. }
  624. lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
  625. } else {
  626. cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
  627. lbs_deb_cmd("DATA_RATE: setting auto\n");
  628. }
  629. ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
  630. if (ret)
  631. goto out;
  632. lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
  633. /* FIXME: get actual rates FW can do if this command actually returns
  634. * all data rates supported.
  635. */
  636. priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
  637. lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
  638. out:
  639. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  640. return ret;
  641. }
  642. /**
  643. * @brief Get the radio channel
  644. *
  645. * @param priv A pointer to struct lbs_private structure
  646. *
  647. * @return The channel on success, error on failure
  648. */
  649. int lbs_get_channel(struct lbs_private *priv)
  650. {
  651. struct cmd_ds_802_11_rf_channel cmd;
  652. int ret = 0;
  653. lbs_deb_enter(LBS_DEB_CMD);
  654. memset(&cmd, 0, sizeof(cmd));
  655. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  656. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
  657. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  658. if (ret)
  659. goto out;
  660. ret = le16_to_cpu(cmd.channel);
  661. lbs_deb_cmd("current radio channel is %d\n", ret);
  662. out:
  663. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  664. return ret;
  665. }
  666. int lbs_update_channel(struct lbs_private *priv)
  667. {
  668. int ret;
  669. /* the channel in f/w could be out of sync; get the current channel */
  670. lbs_deb_enter(LBS_DEB_ASSOC);
  671. ret = lbs_get_channel(priv);
  672. if (ret > 0) {
  673. priv->curbssparams.channel = ret;
  674. ret = 0;
  675. }
  676. lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
  677. return ret;
  678. }
  679. /**
  680. * @brief Set the radio channel
  681. *
  682. * @param priv A pointer to struct lbs_private structure
  683. * @param channel The desired channel, or 0 to clear a locked channel
  684. *
  685. * @return 0 on success, error on failure
  686. */
  687. int lbs_set_channel(struct lbs_private *priv, u8 channel)
  688. {
  689. struct cmd_ds_802_11_rf_channel cmd;
  690. u8 old_channel = priv->curbssparams.channel;
  691. int ret = 0;
  692. lbs_deb_enter(LBS_DEB_CMD);
  693. memset(&cmd, 0, sizeof(cmd));
  694. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  695. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
  696. cmd.channel = cpu_to_le16(channel);
  697. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  698. if (ret)
  699. goto out;
  700. priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
  701. lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
  702. priv->curbssparams.channel);
  703. out:
  704. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  705. return ret;
  706. }
  707. static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
  708. struct cmd_ds_command *cmd)
  709. {
  710. lbs_deb_enter(LBS_DEB_CMD);
  711. cmd->command = cpu_to_le16(CMD_802_11_RSSI);
  712. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
  713. cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
  714. /* reset Beacon SNR/NF/RSSI values */
  715. priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
  716. priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
  717. priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
  718. priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
  719. priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
  720. priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
  721. lbs_deb_leave(LBS_DEB_CMD);
  722. return 0;
  723. }
  724. static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
  725. u8 cmd_action, void *pdata_buf)
  726. {
  727. struct lbs_offset_value *offval;
  728. lbs_deb_enter(LBS_DEB_CMD);
  729. offval = (struct lbs_offset_value *)pdata_buf;
  730. switch (le16_to_cpu(cmdptr->command)) {
  731. case CMD_MAC_REG_ACCESS:
  732. {
  733. struct cmd_ds_mac_reg_access *macreg;
  734. cmdptr->size =
  735. cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
  736. + S_DS_GEN);
  737. macreg =
  738. (struct cmd_ds_mac_reg_access *)&cmdptr->params.
  739. macreg;
  740. macreg->action = cpu_to_le16(cmd_action);
  741. macreg->offset = cpu_to_le16((u16) offval->offset);
  742. macreg->value = cpu_to_le32(offval->value);
  743. break;
  744. }
  745. case CMD_BBP_REG_ACCESS:
  746. {
  747. struct cmd_ds_bbp_reg_access *bbpreg;
  748. cmdptr->size =
  749. cpu_to_le16(sizeof
  750. (struct cmd_ds_bbp_reg_access)
  751. + S_DS_GEN);
  752. bbpreg =
  753. (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
  754. bbpreg;
  755. bbpreg->action = cpu_to_le16(cmd_action);
  756. bbpreg->offset = cpu_to_le16((u16) offval->offset);
  757. bbpreg->value = (u8) offval->value;
  758. break;
  759. }
  760. case CMD_RF_REG_ACCESS:
  761. {
  762. struct cmd_ds_rf_reg_access *rfreg;
  763. cmdptr->size =
  764. cpu_to_le16(sizeof
  765. (struct cmd_ds_rf_reg_access) +
  766. S_DS_GEN);
  767. rfreg =
  768. (struct cmd_ds_rf_reg_access *)&cmdptr->params.
  769. rfreg;
  770. rfreg->action = cpu_to_le16(cmd_action);
  771. rfreg->offset = cpu_to_le16((u16) offval->offset);
  772. rfreg->value = (u8) offval->value;
  773. break;
  774. }
  775. default:
  776. break;
  777. }
  778. lbs_deb_leave(LBS_DEB_CMD);
  779. return 0;
  780. }
  781. static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
  782. u16 cmd_action, void *pdata_buf)
  783. {
  784. struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
  785. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  786. cmd->command = cpu_to_le16(CMD_BT_ACCESS);
  787. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
  788. cmd->result = 0;
  789. bt_access->action = cpu_to_le16(cmd_action);
  790. switch (cmd_action) {
  791. case CMD_ACT_BT_ACCESS_ADD:
  792. memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
  793. lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
  794. break;
  795. case CMD_ACT_BT_ACCESS_DEL:
  796. memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
  797. lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
  798. break;
  799. case CMD_ACT_BT_ACCESS_LIST:
  800. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  801. break;
  802. case CMD_ACT_BT_ACCESS_RESET:
  803. break;
  804. case CMD_ACT_BT_ACCESS_SET_INVERT:
  805. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  806. break;
  807. case CMD_ACT_BT_ACCESS_GET_INVERT:
  808. break;
  809. default:
  810. break;
  811. }
  812. lbs_deb_leave(LBS_DEB_CMD);
  813. return 0;
  814. }
  815. static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
  816. u16 cmd_action, void *pdata_buf)
  817. {
  818. struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
  819. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  820. cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
  821. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
  822. cmd->result = 0;
  823. if (pdata_buf)
  824. memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
  825. else
  826. memset(fwt_access, 0, sizeof(*fwt_access));
  827. fwt_access->action = cpu_to_le16(cmd_action);
  828. lbs_deb_leave(LBS_DEB_CMD);
  829. return 0;
  830. }
  831. int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
  832. struct cmd_ds_mesh_access *cmd)
  833. {
  834. int ret;
  835. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  836. cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
  837. cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
  838. cmd->hdr.result = 0;
  839. cmd->action = cpu_to_le16(cmd_action);
  840. ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
  841. lbs_deb_leave(LBS_DEB_CMD);
  842. return ret;
  843. }
  844. int lbs_mesh_config_send(struct lbs_private *priv,
  845. struct cmd_ds_mesh_config *cmd,
  846. uint16_t action, uint16_t type)
  847. {
  848. int ret;
  849. lbs_deb_enter(LBS_DEB_CMD);
  850. cmd->hdr.command = cpu_to_le16(CMD_MESH_CONFIG);
  851. cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
  852. cmd->hdr.result = 0;
  853. cmd->type = cpu_to_le16(type);
  854. cmd->action = cpu_to_le16(action);
  855. ret = lbs_cmd_with_response(priv, CMD_MESH_CONFIG, cmd);
  856. lbs_deb_leave(LBS_DEB_CMD);
  857. return ret;
  858. }
  859. /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
  860. * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
  861. * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
  862. * lbs_mesh_config_send.
  863. */
  864. int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
  865. {
  866. struct cmd_ds_mesh_config cmd;
  867. struct mrvl_meshie *ie;
  868. memset(&cmd, 0, sizeof(cmd));
  869. cmd.channel = cpu_to_le16(chan);
  870. ie = (struct mrvl_meshie *)cmd.data;
  871. switch (action) {
  872. case CMD_ACT_MESH_CONFIG_START:
  873. ie->hdr.id = MFIE_TYPE_GENERIC;
  874. ie->val.oui[0] = 0x00;
  875. ie->val.oui[1] = 0x50;
  876. ie->val.oui[2] = 0x43;
  877. ie->val.type = MARVELL_MESH_IE_TYPE;
  878. ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
  879. ie->val.version = MARVELL_MESH_IE_VERSION;
  880. ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
  881. ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
  882. ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
  883. ie->val.mesh_id_len = priv->mesh_ssid_len;
  884. memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
  885. ie->hdr.len = sizeof(struct mrvl_meshie_val) -
  886. IW_ESSID_MAX_SIZE + priv->mesh_ssid_len;
  887. cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
  888. break;
  889. case CMD_ACT_MESH_CONFIG_STOP:
  890. break;
  891. default:
  892. return -1;
  893. }
  894. lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
  895. action, priv->mesh_tlv, chan,
  896. escape_essid(priv->mesh_ssid, priv->mesh_ssid_len));
  897. return lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
  898. }
  899. static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
  900. struct cmd_ds_command *cmd,
  901. u16 cmd_action)
  902. {
  903. struct cmd_ds_802_11_beacon_control
  904. *bcn_ctrl = &cmd->params.bcn_ctrl;
  905. lbs_deb_enter(LBS_DEB_CMD);
  906. cmd->size =
  907. cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
  908. + S_DS_GEN);
  909. cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
  910. bcn_ctrl->action = cpu_to_le16(cmd_action);
  911. bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
  912. bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
  913. lbs_deb_leave(LBS_DEB_CMD);
  914. return 0;
  915. }
  916. static void lbs_queue_cmd(struct lbs_private *priv,
  917. struct cmd_ctrl_node *cmdnode)
  918. {
  919. unsigned long flags;
  920. int addtail = 1;
  921. lbs_deb_enter(LBS_DEB_HOST);
  922. if (!cmdnode) {
  923. lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
  924. goto done;
  925. }
  926. if (!cmdnode->cmdbuf->size) {
  927. lbs_deb_host("DNLD_CMD: cmd size is zero\n");
  928. goto done;
  929. }
  930. cmdnode->result = 0;
  931. /* Exit_PS command needs to be queued in the header always. */
  932. if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
  933. struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
  934. if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  935. if (priv->psstate != PS_STATE_FULL_POWER)
  936. addtail = 0;
  937. }
  938. }
  939. spin_lock_irqsave(&priv->driver_lock, flags);
  940. if (addtail)
  941. list_add_tail(&cmdnode->list, &priv->cmdpendingq);
  942. else
  943. list_add(&cmdnode->list, &priv->cmdpendingq);
  944. spin_unlock_irqrestore(&priv->driver_lock, flags);
  945. lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
  946. le16_to_cpu(cmdnode->cmdbuf->command));
  947. done:
  948. lbs_deb_leave(LBS_DEB_HOST);
  949. }
  950. static void lbs_submit_command(struct lbs_private *priv,
  951. struct cmd_ctrl_node *cmdnode)
  952. {
  953. unsigned long flags;
  954. struct cmd_header *cmd;
  955. uint16_t cmdsize;
  956. uint16_t command;
  957. int timeo = 3 * HZ;
  958. int ret;
  959. lbs_deb_enter(LBS_DEB_HOST);
  960. cmd = cmdnode->cmdbuf;
  961. spin_lock_irqsave(&priv->driver_lock, flags);
  962. priv->cur_cmd = cmdnode;
  963. priv->cur_cmd_retcode = 0;
  964. spin_unlock_irqrestore(&priv->driver_lock, flags);
  965. cmdsize = le16_to_cpu(cmd->size);
  966. command = le16_to_cpu(cmd->command);
  967. /* These commands take longer */
  968. if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE ||
  969. command == CMD_802_11_AUTHENTICATE)
  970. timeo = 5 * HZ;
  971. lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
  972. command, le16_to_cpu(cmd->seqnum), cmdsize);
  973. lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
  974. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
  975. if (ret) {
  976. lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
  977. /* Let the timer kick in and retry, and potentially reset
  978. the whole thing if the condition persists */
  979. timeo = HZ/4;
  980. }
  981. /* Setup the timer after transmit command */
  982. mod_timer(&priv->command_timer, jiffies + timeo);
  983. lbs_deb_leave(LBS_DEB_HOST);
  984. }
  985. /**
  986. * This function inserts command node to cmdfreeq
  987. * after cleans it. Requires priv->driver_lock held.
  988. */
  989. static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  990. struct cmd_ctrl_node *cmdnode)
  991. {
  992. lbs_deb_enter(LBS_DEB_HOST);
  993. if (!cmdnode)
  994. goto out;
  995. cmdnode->callback = NULL;
  996. cmdnode->callback_arg = 0;
  997. memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
  998. list_add_tail(&cmdnode->list, &priv->cmdfreeq);
  999. out:
  1000. lbs_deb_leave(LBS_DEB_HOST);
  1001. }
  1002. static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  1003. struct cmd_ctrl_node *ptempcmd)
  1004. {
  1005. unsigned long flags;
  1006. spin_lock_irqsave(&priv->driver_lock, flags);
  1007. __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
  1008. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1009. }
  1010. void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
  1011. int result)
  1012. {
  1013. if (cmd == priv->cur_cmd)
  1014. priv->cur_cmd_retcode = result;
  1015. cmd->result = result;
  1016. cmd->cmdwaitqwoken = 1;
  1017. wake_up_interruptible(&cmd->cmdwait_q);
  1018. if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
  1019. __lbs_cleanup_and_insert_cmd(priv, cmd);
  1020. priv->cur_cmd = NULL;
  1021. }
  1022. int lbs_set_radio_control(struct lbs_private *priv)
  1023. {
  1024. int ret = 0;
  1025. struct cmd_ds_802_11_radio_control cmd;
  1026. lbs_deb_enter(LBS_DEB_CMD);
  1027. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1028. cmd.action = cpu_to_le16(CMD_ACT_SET);
  1029. switch (priv->preamble) {
  1030. case CMD_TYPE_SHORT_PREAMBLE:
  1031. cmd.control = cpu_to_le16(SET_SHORT_PREAMBLE);
  1032. break;
  1033. case CMD_TYPE_LONG_PREAMBLE:
  1034. cmd.control = cpu_to_le16(SET_LONG_PREAMBLE);
  1035. break;
  1036. case CMD_TYPE_AUTO_PREAMBLE:
  1037. default:
  1038. cmd.control = cpu_to_le16(SET_AUTO_PREAMBLE);
  1039. break;
  1040. }
  1041. if (priv->radioon)
  1042. cmd.control |= cpu_to_le16(TURN_ON_RF);
  1043. else
  1044. cmd.control &= cpu_to_le16(~TURN_ON_RF);
  1045. lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n", priv->radioon,
  1046. priv->preamble);
  1047. ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
  1048. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  1049. return ret;
  1050. }
  1051. void lbs_set_mac_control(struct lbs_private *priv)
  1052. {
  1053. struct cmd_ds_mac_control cmd;
  1054. lbs_deb_enter(LBS_DEB_CMD);
  1055. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  1056. cmd.action = cpu_to_le16(priv->mac_control);
  1057. cmd.reserved = 0;
  1058. lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
  1059. lbs_deb_leave(LBS_DEB_CMD);
  1060. }
  1061. /**
  1062. * @brief This function prepare the command before send to firmware.
  1063. *
  1064. * @param priv A pointer to struct lbs_private structure
  1065. * @param cmd_no command number
  1066. * @param cmd_action command action: GET or SET
  1067. * @param wait_option wait option: wait response or not
  1068. * @param cmd_oid cmd oid: treated as sub command
  1069. * @param pdata_buf A pointer to informaion buffer
  1070. * @return 0 or -1
  1071. */
  1072. int lbs_prepare_and_send_command(struct lbs_private *priv,
  1073. u16 cmd_no,
  1074. u16 cmd_action,
  1075. u16 wait_option, u32 cmd_oid, void *pdata_buf)
  1076. {
  1077. int ret = 0;
  1078. struct cmd_ctrl_node *cmdnode;
  1079. struct cmd_ds_command *cmdptr;
  1080. unsigned long flags;
  1081. lbs_deb_enter(LBS_DEB_HOST);
  1082. if (!priv) {
  1083. lbs_deb_host("PREP_CMD: priv is NULL\n");
  1084. ret = -1;
  1085. goto done;
  1086. }
  1087. if (priv->surpriseremoved) {
  1088. lbs_deb_host("PREP_CMD: card removed\n");
  1089. ret = -1;
  1090. goto done;
  1091. }
  1092. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1093. if (cmdnode == NULL) {
  1094. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1095. /* Wake up main thread to execute next command */
  1096. wake_up_interruptible(&priv->waitq);
  1097. ret = -1;
  1098. goto done;
  1099. }
  1100. cmdnode->callback = NULL;
  1101. cmdnode->callback_arg = (unsigned long)pdata_buf;
  1102. cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
  1103. lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
  1104. /* Set sequence number, command and INT option */
  1105. priv->seqnum++;
  1106. cmdptr->seqnum = cpu_to_le16(priv->seqnum);
  1107. cmdptr->command = cpu_to_le16(cmd_no);
  1108. cmdptr->result = 0;
  1109. switch (cmd_no) {
  1110. case CMD_802_11_PS_MODE:
  1111. ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
  1112. break;
  1113. case CMD_802_11_ASSOCIATE:
  1114. case CMD_802_11_REASSOCIATE:
  1115. ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
  1116. break;
  1117. case CMD_802_11_DEAUTHENTICATE:
  1118. ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
  1119. break;
  1120. case CMD_802_11_AD_HOC_START:
  1121. ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
  1122. break;
  1123. case CMD_802_11_RESET:
  1124. ret = lbs_cmd_802_11_reset(cmdptr, cmd_action);
  1125. break;
  1126. case CMD_802_11_AUTHENTICATE:
  1127. ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
  1128. break;
  1129. case CMD_802_11_SNMP_MIB:
  1130. ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
  1131. cmd_action, cmd_oid, pdata_buf);
  1132. break;
  1133. case CMD_MAC_REG_ACCESS:
  1134. case CMD_BBP_REG_ACCESS:
  1135. case CMD_RF_REG_ACCESS:
  1136. ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
  1137. break;
  1138. case CMD_802_11_RF_TX_POWER:
  1139. ret = lbs_cmd_802_11_rf_tx_power(cmdptr,
  1140. cmd_action, pdata_buf);
  1141. break;
  1142. case CMD_802_11_MONITOR_MODE:
  1143. ret = lbs_cmd_802_11_monitor_mode(cmdptr,
  1144. cmd_action, pdata_buf);
  1145. break;
  1146. case CMD_802_11_AD_HOC_JOIN:
  1147. ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
  1148. break;
  1149. case CMD_802_11_RSSI:
  1150. ret = lbs_cmd_802_11_rssi(priv, cmdptr);
  1151. break;
  1152. case CMD_802_11_AD_HOC_STOP:
  1153. ret = lbs_cmd_80211_ad_hoc_stop(cmdptr);
  1154. break;
  1155. case CMD_802_11_SET_AFC:
  1156. case CMD_802_11_GET_AFC:
  1157. cmdptr->command = cpu_to_le16(cmd_no);
  1158. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
  1159. S_DS_GEN);
  1160. memmove(&cmdptr->params.afc,
  1161. pdata_buf, sizeof(struct cmd_ds_802_11_afc));
  1162. ret = 0;
  1163. goto done;
  1164. case CMD_802_11D_DOMAIN_INFO:
  1165. ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
  1166. cmd_no, cmd_action);
  1167. break;
  1168. case CMD_802_11_TPC_CFG:
  1169. cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
  1170. cmdptr->size =
  1171. cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
  1172. S_DS_GEN);
  1173. memmove(&cmdptr->params.tpccfg,
  1174. pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
  1175. ret = 0;
  1176. break;
  1177. case CMD_802_11_LED_GPIO_CTRL:
  1178. {
  1179. struct mrvlietypes_ledgpio *gpio =
  1180. (struct mrvlietypes_ledgpio*)
  1181. cmdptr->params.ledgpio.data;
  1182. memmove(&cmdptr->params.ledgpio,
  1183. pdata_buf,
  1184. sizeof(struct cmd_ds_802_11_led_ctrl));
  1185. cmdptr->command =
  1186. cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
  1187. #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
  1188. cmdptr->size =
  1189. cpu_to_le16(le16_to_cpu(gpio->header.len)
  1190. + S_DS_GEN
  1191. + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
  1192. gpio->header.len = gpio->header.len;
  1193. ret = 0;
  1194. break;
  1195. }
  1196. case CMD_BT_ACCESS:
  1197. ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
  1198. break;
  1199. case CMD_FWT_ACCESS:
  1200. ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
  1201. break;
  1202. case CMD_GET_TSF:
  1203. cmdptr->command = cpu_to_le16(CMD_GET_TSF);
  1204. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
  1205. S_DS_GEN);
  1206. ret = 0;
  1207. break;
  1208. case CMD_802_11_BEACON_CTRL:
  1209. ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
  1210. break;
  1211. default:
  1212. lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
  1213. ret = -1;
  1214. break;
  1215. }
  1216. /* return error, since the command preparation failed */
  1217. if (ret != 0) {
  1218. lbs_deb_host("PREP_CMD: command preparation failed\n");
  1219. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1220. ret = -1;
  1221. goto done;
  1222. }
  1223. cmdnode->cmdwaitqwoken = 0;
  1224. lbs_queue_cmd(priv, cmdnode);
  1225. wake_up_interruptible(&priv->waitq);
  1226. if (wait_option & CMD_OPTION_WAITFORRSP) {
  1227. lbs_deb_host("PREP_CMD: wait for response\n");
  1228. might_sleep();
  1229. wait_event_interruptible(cmdnode->cmdwait_q,
  1230. cmdnode->cmdwaitqwoken);
  1231. }
  1232. spin_lock_irqsave(&priv->driver_lock, flags);
  1233. if (priv->cur_cmd_retcode) {
  1234. lbs_deb_host("PREP_CMD: command failed with return code %d\n",
  1235. priv->cur_cmd_retcode);
  1236. priv->cur_cmd_retcode = 0;
  1237. ret = -1;
  1238. }
  1239. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1240. done:
  1241. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1242. return ret;
  1243. }
  1244. /**
  1245. * @brief This function allocates the command buffer and link
  1246. * it to command free queue.
  1247. *
  1248. * @param priv A pointer to struct lbs_private structure
  1249. * @return 0 or -1
  1250. */
  1251. int lbs_allocate_cmd_buffer(struct lbs_private *priv)
  1252. {
  1253. int ret = 0;
  1254. u32 bufsize;
  1255. u32 i;
  1256. struct cmd_ctrl_node *cmdarray;
  1257. lbs_deb_enter(LBS_DEB_HOST);
  1258. /* Allocate and initialize the command array */
  1259. bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
  1260. if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
  1261. lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
  1262. ret = -1;
  1263. goto done;
  1264. }
  1265. priv->cmd_array = cmdarray;
  1266. /* Allocate and initialize each command buffer in the command array */
  1267. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1268. cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
  1269. if (!cmdarray[i].cmdbuf) {
  1270. lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
  1271. ret = -1;
  1272. goto done;
  1273. }
  1274. }
  1275. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1276. init_waitqueue_head(&cmdarray[i].cmdwait_q);
  1277. lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
  1278. }
  1279. ret = 0;
  1280. done:
  1281. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1282. return ret;
  1283. }
  1284. /**
  1285. * @brief This function frees the command buffer.
  1286. *
  1287. * @param priv A pointer to struct lbs_private structure
  1288. * @return 0 or -1
  1289. */
  1290. int lbs_free_cmd_buffer(struct lbs_private *priv)
  1291. {
  1292. struct cmd_ctrl_node *cmdarray;
  1293. unsigned int i;
  1294. lbs_deb_enter(LBS_DEB_HOST);
  1295. /* need to check if cmd array is allocated or not */
  1296. if (priv->cmd_array == NULL) {
  1297. lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
  1298. goto done;
  1299. }
  1300. cmdarray = priv->cmd_array;
  1301. /* Release shared memory buffers */
  1302. for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
  1303. if (cmdarray[i].cmdbuf) {
  1304. kfree(cmdarray[i].cmdbuf);
  1305. cmdarray[i].cmdbuf = NULL;
  1306. }
  1307. }
  1308. /* Release cmd_ctrl_node */
  1309. if (priv->cmd_array) {
  1310. kfree(priv->cmd_array);
  1311. priv->cmd_array = NULL;
  1312. }
  1313. done:
  1314. lbs_deb_leave(LBS_DEB_HOST);
  1315. return 0;
  1316. }
  1317. /**
  1318. * @brief This function gets a free command node if available in
  1319. * command free queue.
  1320. *
  1321. * @param priv A pointer to struct lbs_private structure
  1322. * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
  1323. */
  1324. static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
  1325. {
  1326. struct cmd_ctrl_node *tempnode;
  1327. unsigned long flags;
  1328. lbs_deb_enter(LBS_DEB_HOST);
  1329. if (!priv)
  1330. return NULL;
  1331. spin_lock_irqsave(&priv->driver_lock, flags);
  1332. if (!list_empty(&priv->cmdfreeq)) {
  1333. tempnode = list_first_entry(&priv->cmdfreeq,
  1334. struct cmd_ctrl_node, list);
  1335. list_del(&tempnode->list);
  1336. } else {
  1337. lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
  1338. tempnode = NULL;
  1339. }
  1340. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1341. lbs_deb_leave(LBS_DEB_HOST);
  1342. return tempnode;
  1343. }
  1344. /**
  1345. * @brief This function executes next command in command
  1346. * pending queue. It will put fimware back to PS mode
  1347. * if applicable.
  1348. *
  1349. * @param priv A pointer to struct lbs_private structure
  1350. * @return 0 or -1
  1351. */
  1352. int lbs_execute_next_command(struct lbs_private *priv)
  1353. {
  1354. struct cmd_ctrl_node *cmdnode = NULL;
  1355. struct cmd_header *cmd;
  1356. unsigned long flags;
  1357. int ret = 0;
  1358. /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1359. * only caller to us is lbs_thread() and we get even when a
  1360. * data packet is received */
  1361. lbs_deb_enter(LBS_DEB_THREAD);
  1362. spin_lock_irqsave(&priv->driver_lock, flags);
  1363. if (priv->cur_cmd) {
  1364. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1365. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1366. ret = -1;
  1367. goto done;
  1368. }
  1369. if (!list_empty(&priv->cmdpendingq)) {
  1370. cmdnode = list_first_entry(&priv->cmdpendingq,
  1371. struct cmd_ctrl_node, list);
  1372. }
  1373. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1374. if (cmdnode) {
  1375. cmd = cmdnode->cmdbuf;
  1376. if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
  1377. if ((priv->psstate == PS_STATE_SLEEP) ||
  1378. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1379. lbs_deb_host(
  1380. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1381. le16_to_cpu(cmd->command),
  1382. priv->psstate);
  1383. ret = -1;
  1384. goto done;
  1385. }
  1386. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1387. "0x%04x in psstate %d\n",
  1388. le16_to_cpu(cmd->command), priv->psstate);
  1389. } else if (priv->psstate != PS_STATE_FULL_POWER) {
  1390. /*
  1391. * 1. Non-PS command:
  1392. * Queue it. set needtowakeup to TRUE if current state
  1393. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1394. * 2. PS command but not Exit_PS:
  1395. * Ignore it.
  1396. * 3. PS command Exit_PS:
  1397. * Set needtowakeup to TRUE if current state is SLEEP,
  1398. * otherwise send this command down to firmware
  1399. * immediately.
  1400. */
  1401. if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
  1402. /* Prepare to send Exit PS,
  1403. * this non PS command will be sent later */
  1404. if ((priv->psstate == PS_STATE_SLEEP)
  1405. || (priv->psstate == PS_STATE_PRE_SLEEP)
  1406. ) {
  1407. /* w/ new scheme, it will not reach here.
  1408. since it is blocked in main_thread. */
  1409. priv->needtowakeup = 1;
  1410. } else
  1411. lbs_ps_wakeup(priv, 0);
  1412. ret = 0;
  1413. goto done;
  1414. } else {
  1415. /*
  1416. * PS command. Ignore it if it is not Exit_PS.
  1417. * otherwise send it down immediately.
  1418. */
  1419. struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
  1420. lbs_deb_host(
  1421. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1422. psm->action);
  1423. if (psm->action !=
  1424. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1425. lbs_deb_host(
  1426. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1427. list_del(&cmdnode->list);
  1428. spin_lock_irqsave(&priv->driver_lock, flags);
  1429. lbs_complete_command(priv, cmdnode, 0);
  1430. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1431. ret = 0;
  1432. goto done;
  1433. }
  1434. if ((priv->psstate == PS_STATE_SLEEP) ||
  1435. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1436. lbs_deb_host(
  1437. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1438. list_del(&cmdnode->list);
  1439. spin_lock_irqsave(&priv->driver_lock, flags);
  1440. lbs_complete_command(priv, cmdnode, 0);
  1441. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1442. priv->needtowakeup = 1;
  1443. ret = 0;
  1444. goto done;
  1445. }
  1446. lbs_deb_host(
  1447. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1448. }
  1449. }
  1450. list_del(&cmdnode->list);
  1451. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1452. le16_to_cpu(cmd->command));
  1453. lbs_submit_command(priv, cmdnode);
  1454. } else {
  1455. /*
  1456. * check if in power save mode, if yes, put the device back
  1457. * to PS mode
  1458. */
  1459. if ((priv->psmode != LBS802_11POWERMODECAM) &&
  1460. (priv->psstate == PS_STATE_FULL_POWER) &&
  1461. ((priv->connect_status == LBS_CONNECTED) ||
  1462. (priv->mesh_connect_status == LBS_CONNECTED))) {
  1463. if (priv->secinfo.WPAenabled ||
  1464. priv->secinfo.WPA2enabled) {
  1465. /* check for valid WPA group keys */
  1466. if (priv->wpa_mcast_key.len ||
  1467. priv->wpa_unicast_key.len) {
  1468. lbs_deb_host(
  1469. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1470. " go back to PS_SLEEP");
  1471. lbs_ps_sleep(priv, 0);
  1472. }
  1473. } else {
  1474. lbs_deb_host(
  1475. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1476. "go back to PS_SLEEP");
  1477. lbs_ps_sleep(priv, 0);
  1478. }
  1479. }
  1480. }
  1481. ret = 0;
  1482. done:
  1483. lbs_deb_leave(LBS_DEB_THREAD);
  1484. return ret;
  1485. }
  1486. void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
  1487. {
  1488. union iwreq_data iwrq;
  1489. u8 buf[50];
  1490. lbs_deb_enter(LBS_DEB_WEXT);
  1491. memset(&iwrq, 0, sizeof(union iwreq_data));
  1492. memset(buf, 0, sizeof(buf));
  1493. snprintf(buf, sizeof(buf) - 1, "%s", str);
  1494. iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
  1495. /* Send Event to upper layer */
  1496. lbs_deb_wext("event indication string %s\n", (char *)buf);
  1497. lbs_deb_wext("event indication length %d\n", iwrq.data.length);
  1498. lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
  1499. wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
  1500. lbs_deb_leave(LBS_DEB_WEXT);
  1501. }
  1502. static void lbs_send_confirmsleep(struct lbs_private *priv)
  1503. {
  1504. unsigned long flags;
  1505. int ret;
  1506. lbs_deb_enter(LBS_DEB_HOST);
  1507. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
  1508. sizeof(confirm_sleep));
  1509. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
  1510. sizeof(confirm_sleep));
  1511. if (ret) {
  1512. lbs_pr_alert("confirm_sleep failed\n");
  1513. goto out;
  1514. }
  1515. spin_lock_irqsave(&priv->driver_lock, flags);
  1516. /* If nothing to do, go back to sleep (?) */
  1517. if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
  1518. priv->psstate = PS_STATE_SLEEP;
  1519. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1520. out:
  1521. lbs_deb_leave(LBS_DEB_HOST);
  1522. }
  1523. void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
  1524. {
  1525. lbs_deb_enter(LBS_DEB_HOST);
  1526. /*
  1527. * PS is currently supported only in Infrastructure mode
  1528. * Remove this check if it is to be supported in IBSS mode also
  1529. */
  1530. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1531. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1532. lbs_deb_leave(LBS_DEB_HOST);
  1533. }
  1534. /**
  1535. * @brief This function sends Exit_PS command to firmware.
  1536. *
  1537. * @param priv A pointer to struct lbs_private structure
  1538. * @param wait_option wait response or not
  1539. * @return n/a
  1540. */
  1541. void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
  1542. {
  1543. __le32 Localpsmode;
  1544. lbs_deb_enter(LBS_DEB_HOST);
  1545. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1546. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1547. CMD_SUBCMD_EXIT_PS,
  1548. wait_option, 0, &Localpsmode);
  1549. lbs_deb_leave(LBS_DEB_HOST);
  1550. }
  1551. /**
  1552. * @brief This function checks condition and prepares to
  1553. * send sleep confirm command to firmware if ok.
  1554. *
  1555. * @param priv A pointer to struct lbs_private structure
  1556. * @param psmode Power Saving mode
  1557. * @return n/a
  1558. */
  1559. void lbs_ps_confirm_sleep(struct lbs_private *priv)
  1560. {
  1561. unsigned long flags =0;
  1562. int allowed = 1;
  1563. lbs_deb_enter(LBS_DEB_HOST);
  1564. if (priv->dnld_sent) {
  1565. allowed = 0;
  1566. lbs_deb_host("dnld_sent was set\n");
  1567. }
  1568. spin_lock_irqsave(&priv->driver_lock, flags);
  1569. /* In-progress command? */
  1570. if (priv->cur_cmd) {
  1571. allowed = 0;
  1572. lbs_deb_host("cur_cmd was set\n");
  1573. }
  1574. /* Pending events or command responses? */
  1575. if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
  1576. allowed = 0;
  1577. lbs_deb_host("pending events or command responses\n");
  1578. }
  1579. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1580. if (allowed) {
  1581. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1582. lbs_send_confirmsleep(priv);
  1583. } else {
  1584. lbs_deb_host("sleep confirm has been delayed\n");
  1585. }
  1586. lbs_deb_leave(LBS_DEB_HOST);
  1587. }
  1588. static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
  1589. uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
  1590. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1591. unsigned long callback_arg)
  1592. {
  1593. struct cmd_ctrl_node *cmdnode;
  1594. lbs_deb_enter(LBS_DEB_HOST);
  1595. if (priv->surpriseremoved) {
  1596. lbs_deb_host("PREP_CMD: card removed\n");
  1597. cmdnode = ERR_PTR(-ENOENT);
  1598. goto done;
  1599. }
  1600. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1601. if (cmdnode == NULL) {
  1602. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1603. /* Wake up main thread to execute next command */
  1604. wake_up_interruptible(&priv->waitq);
  1605. cmdnode = ERR_PTR(-ENOBUFS);
  1606. goto done;
  1607. }
  1608. cmdnode->callback = callback;
  1609. cmdnode->callback_arg = callback_arg;
  1610. /* Copy the incoming command to the buffer */
  1611. memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
  1612. /* Set sequence number, clean result, move to buffer */
  1613. priv->seqnum++;
  1614. cmdnode->cmdbuf->command = cpu_to_le16(command);
  1615. cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
  1616. cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
  1617. cmdnode->cmdbuf->result = 0;
  1618. lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
  1619. cmdnode->cmdwaitqwoken = 0;
  1620. lbs_queue_cmd(priv, cmdnode);
  1621. wake_up_interruptible(&priv->waitq);
  1622. done:
  1623. lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
  1624. return cmdnode;
  1625. }
  1626. void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
  1627. struct cmd_header *in_cmd, int in_cmd_size)
  1628. {
  1629. lbs_deb_enter(LBS_DEB_CMD);
  1630. __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1631. lbs_cmd_async_callback, 0);
  1632. lbs_deb_leave(LBS_DEB_CMD);
  1633. }
  1634. int __lbs_cmd(struct lbs_private *priv, uint16_t command,
  1635. struct cmd_header *in_cmd, int in_cmd_size,
  1636. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1637. unsigned long callback_arg)
  1638. {
  1639. struct cmd_ctrl_node *cmdnode;
  1640. unsigned long flags;
  1641. int ret = 0;
  1642. lbs_deb_enter(LBS_DEB_HOST);
  1643. cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1644. callback, callback_arg);
  1645. if (IS_ERR(cmdnode)) {
  1646. ret = PTR_ERR(cmdnode);
  1647. goto done;
  1648. }
  1649. might_sleep();
  1650. wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
  1651. spin_lock_irqsave(&priv->driver_lock, flags);
  1652. ret = cmdnode->result;
  1653. if (ret)
  1654. lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
  1655. command, ret);
  1656. __lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1657. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1658. done:
  1659. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1660. return ret;
  1661. }
  1662. EXPORT_SYMBOL_GPL(__lbs_cmd);