cmd.c 57 KB

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