cmd.c 57 KB

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