cmd.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227
  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. static int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
  145. struct cmd_ds_command *cmd,
  146. u16 cmd_action, void *pdata_buf)
  147. {
  148. u16 *timeout = pdata_buf;
  149. lbs_deb_enter(LBS_DEB_CMD);
  150. cmd->command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
  151. cmd->size =
  152. cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
  153. + S_DS_GEN);
  154. cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
  155. if (cmd_action)
  156. cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
  157. else
  158. cmd->params.inactivity_timeout.timeout = 0;
  159. lbs_deb_leave(LBS_DEB_CMD);
  160. return 0;
  161. }
  162. static int lbs_cmd_802_11_sleep_params(struct lbs_private *priv,
  163. struct cmd_ds_command *cmd,
  164. u16 cmd_action)
  165. {
  166. struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
  167. lbs_deb_enter(LBS_DEB_CMD);
  168. cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
  169. S_DS_GEN);
  170. cmd->command = cpu_to_le16(CMD_802_11_SLEEP_PARAMS);
  171. if (cmd_action == CMD_ACT_GET) {
  172. memset(&priv->sp, 0, sizeof(struct sleep_params));
  173. memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
  174. sp->action = cpu_to_le16(cmd_action);
  175. } else if (cmd_action == CMD_ACT_SET) {
  176. sp->action = cpu_to_le16(cmd_action);
  177. sp->error = cpu_to_le16(priv->sp.sp_error);
  178. sp->offset = cpu_to_le16(priv->sp.sp_offset);
  179. sp->stabletime = cpu_to_le16(priv->sp.sp_stabletime);
  180. sp->calcontrol = (u8) priv->sp.sp_calcontrol;
  181. sp->externalsleepclk = (u8) priv->sp.sp_extsleepclk;
  182. sp->reserved = cpu_to_le16(priv->sp.sp_reserved);
  183. }
  184. lbs_deb_leave(LBS_DEB_CMD);
  185. return 0;
  186. }
  187. static int lbs_cmd_802_11_set_wep(struct lbs_private *priv,
  188. struct cmd_ds_command *cmd,
  189. u32 cmd_act,
  190. void * pdata_buf)
  191. {
  192. struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
  193. int ret = 0;
  194. struct assoc_request * assoc_req = pdata_buf;
  195. lbs_deb_enter(LBS_DEB_CMD);
  196. cmd->command = cpu_to_le16(CMD_802_11_SET_WEP);
  197. cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
  198. if (cmd_act == CMD_ACT_ADD) {
  199. int i;
  200. if (!assoc_req) {
  201. lbs_deb_cmd("Invalid association request!\n");
  202. ret = -1;
  203. goto done;
  204. }
  205. wep->action = cpu_to_le16(CMD_ACT_ADD);
  206. /* default tx key index */
  207. wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
  208. (u32)CMD_WEP_KEY_INDEX_MASK));
  209. /* Copy key types and material to host command structure */
  210. for (i = 0; i < 4; i++) {
  211. struct enc_key * pkey = &assoc_req->wep_keys[i];
  212. switch (pkey->len) {
  213. case KEY_LEN_WEP_40:
  214. wep->keytype[i] = CMD_TYPE_WEP_40_BIT;
  215. memmove(&wep->keymaterial[i], pkey->key,
  216. pkey->len);
  217. lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
  218. break;
  219. case KEY_LEN_WEP_104:
  220. wep->keytype[i] = CMD_TYPE_WEP_104_BIT;
  221. memmove(&wep->keymaterial[i], pkey->key,
  222. pkey->len);
  223. lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
  224. break;
  225. case 0:
  226. break;
  227. default:
  228. lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
  229. i, pkey->len);
  230. ret = -1;
  231. goto done;
  232. break;
  233. }
  234. }
  235. } else if (cmd_act == CMD_ACT_REMOVE) {
  236. /* ACT_REMOVE clears _all_ WEP keys */
  237. wep->action = cpu_to_le16(CMD_ACT_REMOVE);
  238. /* default tx key index */
  239. wep->keyindex = cpu_to_le16((u16)(priv->wep_tx_keyidx &
  240. (u32)CMD_WEP_KEY_INDEX_MASK));
  241. lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
  242. }
  243. ret = 0;
  244. done:
  245. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  246. return ret;
  247. }
  248. static int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv,
  249. struct cmd_ds_command *cmd,
  250. u16 cmd_action,
  251. void * pdata_buf)
  252. {
  253. struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
  254. u32 * enable = pdata_buf;
  255. lbs_deb_enter(LBS_DEB_CMD);
  256. cmd->command = cpu_to_le16(CMD_802_11_ENABLE_RSN);
  257. cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
  258. penableRSN->action = cpu_to_le16(cmd_action);
  259. if (cmd_action == CMD_ACT_SET) {
  260. if (*enable)
  261. penableRSN->enable = cpu_to_le16(CMD_ENABLE_RSN);
  262. else
  263. penableRSN->enable = cpu_to_le16(CMD_DISABLE_RSN);
  264. lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
  265. }
  266. lbs_deb_leave(LBS_DEB_CMD);
  267. return 0;
  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_radio_control(struct lbs_private *priv,
  496. struct cmd_ds_command *cmd,
  497. int cmd_action)
  498. {
  499. struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
  500. lbs_deb_enter(LBS_DEB_CMD);
  501. cmd->size =
  502. cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
  503. S_DS_GEN);
  504. cmd->command = cpu_to_le16(CMD_802_11_RADIO_CONTROL);
  505. pradiocontrol->action = cpu_to_le16(cmd_action);
  506. switch (priv->preamble) {
  507. case CMD_TYPE_SHORT_PREAMBLE:
  508. pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
  509. break;
  510. case CMD_TYPE_LONG_PREAMBLE:
  511. pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
  512. break;
  513. case CMD_TYPE_AUTO_PREAMBLE:
  514. default:
  515. pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
  516. break;
  517. }
  518. if (priv->radioon)
  519. pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
  520. else
  521. pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
  522. lbs_deb_leave(LBS_DEB_CMD);
  523. return 0;
  524. }
  525. static int lbs_cmd_802_11_rf_tx_power(struct lbs_private *priv,
  526. struct cmd_ds_command *cmd,
  527. u16 cmd_action, void *pdata_buf)
  528. {
  529. struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
  530. lbs_deb_enter(LBS_DEB_CMD);
  531. cmd->size =
  532. cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
  533. cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
  534. prtp->action = cpu_to_le16(cmd_action);
  535. lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
  536. le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
  537. le16_to_cpu(prtp->action));
  538. switch (cmd_action) {
  539. case CMD_ACT_TX_POWER_OPT_GET:
  540. prtp->action = cpu_to_le16(CMD_ACT_GET);
  541. prtp->currentlevel = 0;
  542. break;
  543. case CMD_ACT_TX_POWER_OPT_SET_HIGH:
  544. prtp->action = cpu_to_le16(CMD_ACT_SET);
  545. prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH);
  546. break;
  547. case CMD_ACT_TX_POWER_OPT_SET_MID:
  548. prtp->action = cpu_to_le16(CMD_ACT_SET);
  549. prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID);
  550. break;
  551. case CMD_ACT_TX_POWER_OPT_SET_LOW:
  552. prtp->action = cpu_to_le16(CMD_ACT_SET);
  553. prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
  554. break;
  555. }
  556. lbs_deb_leave(LBS_DEB_CMD);
  557. return 0;
  558. }
  559. static int lbs_cmd_802_11_monitor_mode(struct lbs_private *priv,
  560. struct cmd_ds_command *cmd,
  561. u16 cmd_action, void *pdata_buf)
  562. {
  563. struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
  564. cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
  565. cmd->size =
  566. cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
  567. S_DS_GEN);
  568. monitor->action = cpu_to_le16(cmd_action);
  569. if (cmd_action == CMD_ACT_SET) {
  570. monitor->mode =
  571. cpu_to_le16((u16) (*(u32 *) pdata_buf));
  572. }
  573. return 0;
  574. }
  575. static int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
  576. struct cmd_ds_command *cmd,
  577. u16 cmd_action)
  578. {
  579. struct cmd_ds_802_11_rate_adapt_rateset
  580. *rateadapt = &cmd->params.rateset;
  581. lbs_deb_enter(LBS_DEB_CMD);
  582. cmd->size =
  583. cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
  584. + S_DS_GEN);
  585. cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
  586. rateadapt->action = cpu_to_le16(cmd_action);
  587. rateadapt->enablehwauto = cpu_to_le16(priv->enablehwauto);
  588. rateadapt->bitmap = cpu_to_le16(priv->ratebitmap);
  589. lbs_deb_leave(LBS_DEB_CMD);
  590. return 0;
  591. }
  592. /**
  593. * @brief Get the current data rate
  594. *
  595. * @param priv A pointer to struct lbs_private structure
  596. *
  597. * @return The data rate on success, error on failure
  598. */
  599. int lbs_get_data_rate(struct lbs_private *priv)
  600. {
  601. struct cmd_ds_802_11_data_rate cmd;
  602. int ret = -1;
  603. lbs_deb_enter(LBS_DEB_CMD);
  604. memset(&cmd, 0, sizeof(cmd));
  605. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  606. cmd.action = cpu_to_le16(CMD_ACT_GET_TX_RATE);
  607. ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
  608. if (ret)
  609. goto out;
  610. lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
  611. ret = (int) lbs_fw_index_to_data_rate(cmd.rates[0]);
  612. lbs_deb_cmd("DATA_RATE: current rate 0x%02x\n", ret);
  613. out:
  614. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  615. return ret;
  616. }
  617. /**
  618. * @brief Set the data rate
  619. *
  620. * @param priv A pointer to struct lbs_private structure
  621. * @param rate The desired data rate, or 0 to clear a locked rate
  622. *
  623. * @return 0 on success, error on failure
  624. */
  625. int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
  626. {
  627. struct cmd_ds_802_11_data_rate cmd;
  628. int ret = 0;
  629. lbs_deb_enter(LBS_DEB_CMD);
  630. memset(&cmd, 0, sizeof(cmd));
  631. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  632. if (rate > 0) {
  633. cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
  634. cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
  635. if (cmd.rates[0] == 0) {
  636. lbs_deb_cmd("DATA_RATE: invalid requested rate of"
  637. " 0x%02X\n", rate);
  638. ret = 0;
  639. goto out;
  640. }
  641. lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
  642. } else {
  643. cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
  644. lbs_deb_cmd("DATA_RATE: setting auto\n");
  645. }
  646. ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
  647. if (ret)
  648. goto out;
  649. lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
  650. /* FIXME: get actual rates FW can do if this command actually returns
  651. * all data rates supported.
  652. */
  653. priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
  654. lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
  655. out:
  656. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  657. return ret;
  658. }
  659. static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv,
  660. struct cmd_ds_command *cmd,
  661. u16 cmd_action)
  662. {
  663. struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
  664. lbs_deb_enter(LBS_DEB_CMD);
  665. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
  666. S_DS_GEN);
  667. cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
  668. lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
  669. pMCastAdr->action = cpu_to_le16(cmd_action);
  670. pMCastAdr->nr_of_adrs =
  671. cpu_to_le16((u16) priv->nr_of_multicastmacaddr);
  672. memcpy(pMCastAdr->maclist, priv->multicastlist,
  673. priv->nr_of_multicastmacaddr * ETH_ALEN);
  674. lbs_deb_leave(LBS_DEB_CMD);
  675. return 0;
  676. }
  677. /**
  678. * @brief Get the radio channel
  679. *
  680. * @param priv A pointer to struct lbs_private structure
  681. *
  682. * @return The channel on success, error on failure
  683. */
  684. int lbs_get_channel(struct lbs_private *priv)
  685. {
  686. struct cmd_ds_802_11_rf_channel cmd;
  687. int ret = 0;
  688. lbs_deb_enter(LBS_DEB_CMD);
  689. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  690. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
  691. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  692. if (ret)
  693. goto out;
  694. ret = le16_to_cpu(cmd.channel);
  695. lbs_deb_cmd("current radio channel is %d\n", ret);
  696. out:
  697. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  698. return ret;
  699. }
  700. /**
  701. * @brief Set the radio channel
  702. *
  703. * @param priv A pointer to struct lbs_private structure
  704. * @param channel The desired channel, or 0 to clear a locked channel
  705. *
  706. * @return 0 on success, error on failure
  707. */
  708. int lbs_set_channel(struct lbs_private *priv, u8 channel)
  709. {
  710. struct cmd_ds_802_11_rf_channel cmd;
  711. u8 old_channel = priv->curbssparams.channel;
  712. int ret = 0;
  713. lbs_deb_enter(LBS_DEB_CMD);
  714. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  715. cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
  716. cmd.channel = cpu_to_le16(channel);
  717. ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
  718. if (ret)
  719. goto out;
  720. priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
  721. lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
  722. priv->curbssparams.channel);
  723. out:
  724. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  725. return ret;
  726. }
  727. static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
  728. struct cmd_ds_command *cmd)
  729. {
  730. lbs_deb_enter(LBS_DEB_CMD);
  731. cmd->command = cpu_to_le16(CMD_802_11_RSSI);
  732. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
  733. cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
  734. /* reset Beacon SNR/NF/RSSI values */
  735. priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
  736. priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
  737. priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
  738. priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
  739. priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
  740. priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
  741. lbs_deb_leave(LBS_DEB_CMD);
  742. return 0;
  743. }
  744. static int lbs_cmd_reg_access(struct lbs_private *priv,
  745. struct cmd_ds_command *cmdptr,
  746. u8 cmd_action, void *pdata_buf)
  747. {
  748. struct lbs_offset_value *offval;
  749. lbs_deb_enter(LBS_DEB_CMD);
  750. offval = (struct lbs_offset_value *)pdata_buf;
  751. switch (le16_to_cpu(cmdptr->command)) {
  752. case CMD_MAC_REG_ACCESS:
  753. {
  754. struct cmd_ds_mac_reg_access *macreg;
  755. cmdptr->size =
  756. cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
  757. + S_DS_GEN);
  758. macreg =
  759. (struct cmd_ds_mac_reg_access *)&cmdptr->params.
  760. macreg;
  761. macreg->action = cpu_to_le16(cmd_action);
  762. macreg->offset = cpu_to_le16((u16) offval->offset);
  763. macreg->value = cpu_to_le32(offval->value);
  764. break;
  765. }
  766. case CMD_BBP_REG_ACCESS:
  767. {
  768. struct cmd_ds_bbp_reg_access *bbpreg;
  769. cmdptr->size =
  770. cpu_to_le16(sizeof
  771. (struct cmd_ds_bbp_reg_access)
  772. + S_DS_GEN);
  773. bbpreg =
  774. (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
  775. bbpreg;
  776. bbpreg->action = cpu_to_le16(cmd_action);
  777. bbpreg->offset = cpu_to_le16((u16) offval->offset);
  778. bbpreg->value = (u8) offval->value;
  779. break;
  780. }
  781. case CMD_RF_REG_ACCESS:
  782. {
  783. struct cmd_ds_rf_reg_access *rfreg;
  784. cmdptr->size =
  785. cpu_to_le16(sizeof
  786. (struct cmd_ds_rf_reg_access) +
  787. S_DS_GEN);
  788. rfreg =
  789. (struct cmd_ds_rf_reg_access *)&cmdptr->params.
  790. rfreg;
  791. rfreg->action = cpu_to_le16(cmd_action);
  792. rfreg->offset = cpu_to_le16((u16) offval->offset);
  793. rfreg->value = (u8) offval->value;
  794. break;
  795. }
  796. default:
  797. break;
  798. }
  799. lbs_deb_leave(LBS_DEB_CMD);
  800. return 0;
  801. }
  802. static int lbs_cmd_802_11_mac_address(struct lbs_private *priv,
  803. struct cmd_ds_command *cmd,
  804. u16 cmd_action)
  805. {
  806. lbs_deb_enter(LBS_DEB_CMD);
  807. cmd->command = cpu_to_le16(CMD_802_11_MAC_ADDRESS);
  808. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
  809. S_DS_GEN);
  810. cmd->result = 0;
  811. cmd->params.macadd.action = cpu_to_le16(cmd_action);
  812. if (cmd_action == CMD_ACT_SET) {
  813. memcpy(cmd->params.macadd.macadd,
  814. priv->current_addr, ETH_ALEN);
  815. lbs_deb_hex(LBS_DEB_CMD, "SET_CMD: MAC addr", priv->current_addr, 6);
  816. }
  817. lbs_deb_leave(LBS_DEB_CMD);
  818. return 0;
  819. }
  820. static int lbs_cmd_802_11_eeprom_access(struct lbs_private *priv,
  821. struct cmd_ds_command *cmd,
  822. int cmd_action, void *pdata_buf)
  823. {
  824. struct lbs_ioctl_regrdwr *ea = pdata_buf;
  825. lbs_deb_enter(LBS_DEB_CMD);
  826. cmd->command = cpu_to_le16(CMD_802_11_EEPROM_ACCESS);
  827. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
  828. S_DS_GEN);
  829. cmd->result = 0;
  830. cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
  831. cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
  832. cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
  833. cmd->params.rdeeprom.value = 0;
  834. lbs_deb_leave(LBS_DEB_CMD);
  835. return 0;
  836. }
  837. static int lbs_cmd_bt_access(struct lbs_private *priv,
  838. struct cmd_ds_command *cmd,
  839. u16 cmd_action, void *pdata_buf)
  840. {
  841. struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
  842. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  843. cmd->command = cpu_to_le16(CMD_BT_ACCESS);
  844. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
  845. cmd->result = 0;
  846. bt_access->action = cpu_to_le16(cmd_action);
  847. switch (cmd_action) {
  848. case CMD_ACT_BT_ACCESS_ADD:
  849. memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
  850. lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
  851. break;
  852. case CMD_ACT_BT_ACCESS_DEL:
  853. memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
  854. lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
  855. break;
  856. case CMD_ACT_BT_ACCESS_LIST:
  857. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  858. break;
  859. case CMD_ACT_BT_ACCESS_RESET:
  860. break;
  861. case CMD_ACT_BT_ACCESS_SET_INVERT:
  862. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  863. break;
  864. case CMD_ACT_BT_ACCESS_GET_INVERT:
  865. break;
  866. default:
  867. break;
  868. }
  869. lbs_deb_leave(LBS_DEB_CMD);
  870. return 0;
  871. }
  872. static int lbs_cmd_fwt_access(struct lbs_private *priv,
  873. struct cmd_ds_command *cmd,
  874. u16 cmd_action, void *pdata_buf)
  875. {
  876. struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
  877. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  878. cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
  879. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
  880. cmd->result = 0;
  881. if (pdata_buf)
  882. memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
  883. else
  884. memset(fwt_access, 0, sizeof(*fwt_access));
  885. fwt_access->action = cpu_to_le16(cmd_action);
  886. lbs_deb_leave(LBS_DEB_CMD);
  887. return 0;
  888. }
  889. int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
  890. struct cmd_ds_mesh_access *cmd)
  891. {
  892. int ret;
  893. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  894. cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
  895. cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
  896. cmd->hdr.result = 0;
  897. cmd->action = cpu_to_le16(cmd_action);
  898. ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
  899. lbs_deb_leave(LBS_DEB_CMD);
  900. return ret;
  901. }
  902. EXPORT_SYMBOL_GPL(lbs_mesh_access);
  903. int lbs_mesh_config(struct lbs_private *priv, uint16_t enable, uint16_t chan)
  904. {
  905. struct cmd_ds_mesh_config cmd;
  906. memset(&cmd, 0, sizeof(cmd));
  907. cmd.action = cpu_to_le16(enable);
  908. cmd.channel = cpu_to_le16(chan);
  909. cmd.type = cpu_to_le16(priv->mesh_tlv);
  910. cmd.hdr.size = cpu_to_le16(sizeof(cmd));
  911. if (enable) {
  912. cmd.length = cpu_to_le16(priv->mesh_ssid_len);
  913. memcpy(cmd.data, priv->mesh_ssid, priv->mesh_ssid_len);
  914. }
  915. lbs_deb_cmd("mesh config enable %d TLV %x channel %d SSID %s\n",
  916. enable, priv->mesh_tlv, chan,
  917. escape_essid(priv->mesh_ssid, priv->mesh_ssid_len));
  918. return lbs_cmd_with_response(priv, CMD_MESH_CONFIG, &cmd);
  919. }
  920. static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
  921. struct cmd_ds_command *cmd,
  922. u16 cmd_action)
  923. {
  924. struct cmd_ds_802_11_beacon_control
  925. *bcn_ctrl = &cmd->params.bcn_ctrl;
  926. lbs_deb_enter(LBS_DEB_CMD);
  927. cmd->size =
  928. cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
  929. + S_DS_GEN);
  930. cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
  931. bcn_ctrl->action = cpu_to_le16(cmd_action);
  932. bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
  933. bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
  934. lbs_deb_leave(LBS_DEB_CMD);
  935. return 0;
  936. }
  937. static void lbs_queue_cmd(struct lbs_private *priv,
  938. struct cmd_ctrl_node *cmdnode)
  939. {
  940. unsigned long flags;
  941. int addtail = 1;
  942. lbs_deb_enter(LBS_DEB_HOST);
  943. if (!cmdnode) {
  944. lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
  945. goto done;
  946. }
  947. if (!cmdnode->cmdbuf->size) {
  948. lbs_deb_host("DNLD_CMD: cmd size is zero\n");
  949. goto done;
  950. }
  951. cmdnode->result = 0;
  952. /* Exit_PS command needs to be queued in the header always. */
  953. if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
  954. struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
  955. if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  956. if (priv->psstate != PS_STATE_FULL_POWER)
  957. addtail = 0;
  958. }
  959. }
  960. spin_lock_irqsave(&priv->driver_lock, flags);
  961. if (addtail)
  962. list_add_tail(&cmdnode->list, &priv->cmdpendingq);
  963. else
  964. list_add(&cmdnode->list, &priv->cmdpendingq);
  965. spin_unlock_irqrestore(&priv->driver_lock, flags);
  966. lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
  967. le16_to_cpu(cmdnode->cmdbuf->command));
  968. done:
  969. lbs_deb_leave(LBS_DEB_HOST);
  970. }
  971. static int lbs_submit_command(struct lbs_private *priv,
  972. struct cmd_ctrl_node *cmdnode)
  973. {
  974. unsigned long flags;
  975. struct cmd_header *cmd;
  976. int ret = -1;
  977. u16 cmdsize;
  978. u16 command;
  979. lbs_deb_enter(LBS_DEB_HOST);
  980. cmd = cmdnode->cmdbuf;
  981. spin_lock_irqsave(&priv->driver_lock, flags);
  982. priv->cur_cmd = cmdnode;
  983. priv->cur_cmd_retcode = 0;
  984. spin_unlock_irqrestore(&priv->driver_lock, flags);
  985. cmdsize = le16_to_cpu(cmd->size);
  986. command = le16_to_cpu(cmd->command);
  987. lbs_deb_host("DNLD_CMD: command 0x%04x, seq %d, size %d, jiffies %lu\n",
  988. command, le16_to_cpu(cmd->seqnum), cmdsize, jiffies);
  989. lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
  990. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
  991. if (ret) {
  992. lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
  993. spin_lock_irqsave(&priv->driver_lock, flags);
  994. lbs_complete_command(priv, priv->cur_cmd, ret);
  995. spin_unlock_irqrestore(&priv->driver_lock, flags);
  996. goto done;
  997. }
  998. lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
  999. /* Setup the timer after transmit command */
  1000. if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
  1001. || command == CMD_802_11_ASSOCIATE)
  1002. mod_timer(&priv->command_timer, jiffies + (10*HZ));
  1003. else
  1004. mod_timer(&priv->command_timer, jiffies + (5*HZ));
  1005. ret = 0;
  1006. done:
  1007. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1008. return ret;
  1009. }
  1010. static int lbs_cmd_mac_control(struct lbs_private *priv,
  1011. struct cmd_ds_command *cmd)
  1012. {
  1013. struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
  1014. lbs_deb_enter(LBS_DEB_CMD);
  1015. cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
  1016. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
  1017. mac->action = cpu_to_le16(priv->currentpacketfilter);
  1018. lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
  1019. le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
  1020. lbs_deb_leave(LBS_DEB_CMD);
  1021. return 0;
  1022. }
  1023. /**
  1024. * This function inserts command node to cmdfreeq
  1025. * after cleans it. Requires priv->driver_lock held.
  1026. */
  1027. static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  1028. struct cmd_ctrl_node *cmdnode)
  1029. {
  1030. lbs_deb_enter(LBS_DEB_HOST);
  1031. if (!cmdnode)
  1032. goto out;
  1033. cmdnode->callback = NULL;
  1034. cmdnode->callback_arg = 0;
  1035. memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
  1036. list_add_tail(&cmdnode->list, &priv->cmdfreeq);
  1037. out:
  1038. lbs_deb_leave(LBS_DEB_HOST);
  1039. }
  1040. static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  1041. struct cmd_ctrl_node *ptempcmd)
  1042. {
  1043. unsigned long flags;
  1044. spin_lock_irqsave(&priv->driver_lock, flags);
  1045. __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
  1046. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1047. }
  1048. void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
  1049. int result)
  1050. {
  1051. if (cmd == priv->cur_cmd)
  1052. priv->cur_cmd_retcode = result;
  1053. cmd->result = result;
  1054. cmd->cmdwaitqwoken = 1;
  1055. wake_up_interruptible(&cmd->cmdwait_q);
  1056. if (!cmd->callback)
  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);
  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->callback = NULL;
  1455. ptempnode->callback_arg = (unsigned long)pdata_buf;
  1456. lbs_deb_leave(LBS_DEB_HOST);
  1457. }
  1458. /**
  1459. * @brief This function executes next command in command
  1460. * pending queue. It will put fimware back to PS mode
  1461. * if applicable.
  1462. *
  1463. * @param priv A pointer to struct lbs_private structure
  1464. * @return 0 or -1
  1465. */
  1466. int lbs_execute_next_command(struct lbs_private *priv)
  1467. {
  1468. struct cmd_ctrl_node *cmdnode = NULL;
  1469. struct cmd_header *cmd;
  1470. unsigned long flags;
  1471. int ret = 0;
  1472. // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1473. // only caller to us is lbs_thread() and we get even when a
  1474. // data packet is received
  1475. lbs_deb_enter(LBS_DEB_THREAD);
  1476. spin_lock_irqsave(&priv->driver_lock, flags);
  1477. if (priv->cur_cmd) {
  1478. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1479. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1480. ret = -1;
  1481. goto done;
  1482. }
  1483. if (!list_empty(&priv->cmdpendingq)) {
  1484. cmdnode = list_first_entry(&priv->cmdpendingq,
  1485. struct cmd_ctrl_node, list);
  1486. }
  1487. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1488. if (cmdnode) {
  1489. cmd = cmdnode->cmdbuf;
  1490. if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
  1491. if ((priv->psstate == PS_STATE_SLEEP) ||
  1492. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1493. lbs_deb_host(
  1494. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1495. le16_to_cpu(cmd->command),
  1496. priv->psstate);
  1497. ret = -1;
  1498. goto done;
  1499. }
  1500. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1501. "0x%04x in psstate %d\n",
  1502. le16_to_cpu(cmd->command), priv->psstate);
  1503. } else if (priv->psstate != PS_STATE_FULL_POWER) {
  1504. /*
  1505. * 1. Non-PS command:
  1506. * Queue it. set needtowakeup to TRUE if current state
  1507. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1508. * 2. PS command but not Exit_PS:
  1509. * Ignore it.
  1510. * 3. PS command Exit_PS:
  1511. * Set needtowakeup to TRUE if current state is SLEEP,
  1512. * otherwise send this command down to firmware
  1513. * immediately.
  1514. */
  1515. if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
  1516. /* Prepare to send Exit PS,
  1517. * this non PS command will be sent later */
  1518. if ((priv->psstate == PS_STATE_SLEEP)
  1519. || (priv->psstate == PS_STATE_PRE_SLEEP)
  1520. ) {
  1521. /* w/ new scheme, it will not reach here.
  1522. since it is blocked in main_thread. */
  1523. priv->needtowakeup = 1;
  1524. } else
  1525. lbs_ps_wakeup(priv, 0);
  1526. ret = 0;
  1527. goto done;
  1528. } else {
  1529. /*
  1530. * PS command. Ignore it if it is not Exit_PS.
  1531. * otherwise send it down immediately.
  1532. */
  1533. struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
  1534. lbs_deb_host(
  1535. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1536. psm->action);
  1537. if (psm->action !=
  1538. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1539. lbs_deb_host(
  1540. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1541. list_del(&cmdnode->list);
  1542. spin_lock_irqsave(&priv->driver_lock, flags);
  1543. lbs_complete_command(priv, cmdnode, 0);
  1544. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1545. ret = 0;
  1546. goto done;
  1547. }
  1548. if ((priv->psstate == PS_STATE_SLEEP) ||
  1549. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1550. lbs_deb_host(
  1551. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1552. list_del(&cmdnode->list);
  1553. spin_lock_irqsave(&priv->driver_lock, flags);
  1554. lbs_complete_command(priv, cmdnode, 0);
  1555. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1556. priv->needtowakeup = 1;
  1557. ret = 0;
  1558. goto done;
  1559. }
  1560. lbs_deb_host(
  1561. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1562. }
  1563. }
  1564. list_del(&cmdnode->list);
  1565. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1566. le16_to_cpu(cmd->command));
  1567. lbs_submit_command(priv, cmdnode);
  1568. } else {
  1569. /*
  1570. * check if in power save mode, if yes, put the device back
  1571. * to PS mode
  1572. */
  1573. if ((priv->psmode != LBS802_11POWERMODECAM) &&
  1574. (priv->psstate == PS_STATE_FULL_POWER) &&
  1575. ((priv->connect_status == LBS_CONNECTED) ||
  1576. (priv->mesh_connect_status == LBS_CONNECTED))) {
  1577. if (priv->secinfo.WPAenabled ||
  1578. priv->secinfo.WPA2enabled) {
  1579. /* check for valid WPA group keys */
  1580. if (priv->wpa_mcast_key.len ||
  1581. priv->wpa_unicast_key.len) {
  1582. lbs_deb_host(
  1583. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1584. " go back to PS_SLEEP");
  1585. lbs_ps_sleep(priv, 0);
  1586. }
  1587. } else {
  1588. lbs_deb_host(
  1589. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1590. "go back to PS_SLEEP");
  1591. lbs_ps_sleep(priv, 0);
  1592. }
  1593. }
  1594. }
  1595. ret = 0;
  1596. done:
  1597. lbs_deb_leave(LBS_DEB_THREAD);
  1598. return ret;
  1599. }
  1600. void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
  1601. {
  1602. union iwreq_data iwrq;
  1603. u8 buf[50];
  1604. lbs_deb_enter(LBS_DEB_WEXT);
  1605. memset(&iwrq, 0, sizeof(union iwreq_data));
  1606. memset(buf, 0, sizeof(buf));
  1607. snprintf(buf, sizeof(buf) - 1, "%s", str);
  1608. iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
  1609. /* Send Event to upper layer */
  1610. lbs_deb_wext("event indication string %s\n", (char *)buf);
  1611. lbs_deb_wext("event indication length %d\n", iwrq.data.length);
  1612. lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
  1613. wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
  1614. lbs_deb_leave(LBS_DEB_WEXT);
  1615. }
  1616. static int sendconfirmsleep(struct lbs_private *priv, u8 *cmdptr, u16 size)
  1617. {
  1618. unsigned long flags;
  1619. int ret = 0;
  1620. lbs_deb_enter(LBS_DEB_HOST);
  1621. lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
  1622. size);
  1623. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
  1624. ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
  1625. spin_lock_irqsave(&priv->driver_lock, flags);
  1626. if (priv->intcounter || priv->currenttxskb)
  1627. lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
  1628. priv->intcounter, priv->currenttxskb);
  1629. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1630. if (ret) {
  1631. lbs_pr_alert(
  1632. "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
  1633. } else {
  1634. spin_lock_irqsave(&priv->driver_lock, flags);
  1635. if (!priv->intcounter) {
  1636. priv->psstate = PS_STATE_SLEEP;
  1637. } else {
  1638. lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
  1639. priv->intcounter);
  1640. }
  1641. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1642. lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
  1643. }
  1644. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1645. return ret;
  1646. }
  1647. void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
  1648. {
  1649. lbs_deb_enter(LBS_DEB_HOST);
  1650. /*
  1651. * PS is currently supported only in Infrastructure mode
  1652. * Remove this check if it is to be supported in IBSS mode also
  1653. */
  1654. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1655. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1656. lbs_deb_leave(LBS_DEB_HOST);
  1657. }
  1658. /**
  1659. * @brief This function sends Exit_PS command to firmware.
  1660. *
  1661. * @param priv A pointer to struct lbs_private structure
  1662. * @param wait_option wait response or not
  1663. * @return n/a
  1664. */
  1665. void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
  1666. {
  1667. __le32 Localpsmode;
  1668. lbs_deb_enter(LBS_DEB_HOST);
  1669. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1670. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1671. CMD_SUBCMD_EXIT_PS,
  1672. wait_option, 0, &Localpsmode);
  1673. lbs_deb_leave(LBS_DEB_HOST);
  1674. }
  1675. /**
  1676. * @brief This function checks condition and prepares to
  1677. * send sleep confirm command to firmware if ok.
  1678. *
  1679. * @param priv A pointer to struct lbs_private structure
  1680. * @param psmode Power Saving mode
  1681. * @return n/a
  1682. */
  1683. void lbs_ps_confirm_sleep(struct lbs_private *priv, u16 psmode)
  1684. {
  1685. unsigned long flags =0;
  1686. u8 allowed = 1;
  1687. lbs_deb_enter(LBS_DEB_HOST);
  1688. if (priv->dnld_sent) {
  1689. allowed = 0;
  1690. lbs_deb_host("dnld_sent was set\n");
  1691. }
  1692. spin_lock_irqsave(&priv->driver_lock, flags);
  1693. if (priv->cur_cmd) {
  1694. allowed = 0;
  1695. lbs_deb_host("cur_cmd was set\n");
  1696. }
  1697. if (priv->intcounter > 0) {
  1698. allowed = 0;
  1699. lbs_deb_host("intcounter %d\n", priv->intcounter);
  1700. }
  1701. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1702. if (allowed) {
  1703. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1704. sendconfirmsleep(priv, (u8 *) & priv->lbs_ps_confirm_sleep,
  1705. sizeof(struct PS_CMD_ConfirmSleep));
  1706. } else {
  1707. lbs_deb_host("sleep confirm has been delayed\n");
  1708. }
  1709. lbs_deb_leave(LBS_DEB_HOST);
  1710. }
  1711. /**
  1712. * @brief Simple callback that copies response back into command
  1713. *
  1714. * @param priv A pointer to struct lbs_private structure
  1715. * @param extra A pointer to the original command structure for which
  1716. * 'resp' is a response
  1717. * @param resp A pointer to the command response
  1718. *
  1719. * @return 0 on success, error on failure
  1720. */
  1721. int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
  1722. struct cmd_header *resp)
  1723. {
  1724. struct cmd_header *buf = (void *)extra;
  1725. uint16_t copy_len;
  1726. lbs_deb_enter(LBS_DEB_CMD);
  1727. copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
  1728. lbs_deb_cmd("Copying back %u bytes; command response was %u bytes, "
  1729. "copy back buffer was %u bytes\n", copy_len,
  1730. le16_to_cpu(resp->size), le16_to_cpu(buf->size));
  1731. memcpy(buf, resp, copy_len);
  1732. lbs_deb_leave(LBS_DEB_CMD);
  1733. return 0;
  1734. }
  1735. EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
  1736. struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv, uint16_t command,
  1737. struct cmd_header *in_cmd, int in_cmd_size,
  1738. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1739. unsigned long callback_arg)
  1740. {
  1741. struct cmd_ctrl_node *cmdnode;
  1742. lbs_deb_enter(LBS_DEB_HOST);
  1743. if (priv->surpriseremoved) {
  1744. lbs_deb_host("PREP_CMD: card removed\n");
  1745. cmdnode = ERR_PTR(-ENOENT);
  1746. goto done;
  1747. }
  1748. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1749. if (cmdnode == NULL) {
  1750. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1751. /* Wake up main thread to execute next command */
  1752. wake_up_interruptible(&priv->waitq);
  1753. cmdnode = ERR_PTR(-ENOBUFS);
  1754. goto done;
  1755. }
  1756. cmdnode->callback = callback;
  1757. cmdnode->callback_arg = callback_arg;
  1758. /* Copy the incoming command to the buffer */
  1759. memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
  1760. /* Set sequence number, clean result, move to buffer */
  1761. priv->seqnum++;
  1762. cmdnode->cmdbuf->command = cpu_to_le16(command);
  1763. cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
  1764. cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
  1765. cmdnode->cmdbuf->result = 0;
  1766. lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
  1767. /* here was the big old switch() statement, which is now obsolete,
  1768. * because the caller of lbs_cmd() sets up all of *cmd for us. */
  1769. cmdnode->cmdwaitqwoken = 0;
  1770. lbs_queue_cmd(priv, cmdnode);
  1771. wake_up_interruptible(&priv->waitq);
  1772. done:
  1773. lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
  1774. return cmdnode;
  1775. }
  1776. int __lbs_cmd(struct lbs_private *priv, uint16_t command,
  1777. struct cmd_header *in_cmd, int in_cmd_size,
  1778. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1779. unsigned long callback_arg)
  1780. {
  1781. struct cmd_ctrl_node *cmdnode;
  1782. unsigned long flags;
  1783. int ret = 0;
  1784. lbs_deb_enter(LBS_DEB_HOST);
  1785. cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
  1786. callback, callback_arg);
  1787. if (IS_ERR(cmdnode)) {
  1788. ret = PTR_ERR(cmdnode);
  1789. goto done;
  1790. }
  1791. might_sleep();
  1792. wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
  1793. spin_lock_irqsave(&priv->driver_lock, flags);
  1794. ret = cmdnode->result;
  1795. if (ret)
  1796. lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
  1797. command, ret);
  1798. __lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1799. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1800. done:
  1801. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1802. return ret;
  1803. }
  1804. EXPORT_SYMBOL_GPL(__lbs_cmd);