cmd.c 55 KB

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