cmd.c 52 KB

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