cmd.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152
  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. static int lbs_cmd_802_11_data_rate(struct lbs_private *priv,
  576. struct cmd_ds_command *cmd,
  577. u16 cmd_action)
  578. {
  579. struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
  580. lbs_deb_enter(LBS_DEB_CMD);
  581. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
  582. S_DS_GEN);
  583. cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE);
  584. memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
  585. pdatarate->action = cpu_to_le16(cmd_action);
  586. if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) {
  587. pdatarate->rates[0] = lbs_data_rate_to_fw_index(priv->cur_rate);
  588. lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n",
  589. priv->cur_rate);
  590. } else if (cmd_action == CMD_ACT_SET_TX_AUTO) {
  591. lbs_deb_cmd("DATA_RATE: setting auto\n");
  592. }
  593. lbs_deb_leave(LBS_DEB_CMD);
  594. return 0;
  595. }
  596. static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv,
  597. struct cmd_ds_command *cmd,
  598. u16 cmd_action)
  599. {
  600. struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
  601. lbs_deb_enter(LBS_DEB_CMD);
  602. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
  603. S_DS_GEN);
  604. cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
  605. lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
  606. pMCastAdr->action = cpu_to_le16(cmd_action);
  607. pMCastAdr->nr_of_adrs =
  608. cpu_to_le16((u16) priv->nr_of_multicastmacaddr);
  609. memcpy(pMCastAdr->maclist, priv->multicastlist,
  610. priv->nr_of_multicastmacaddr * ETH_ALEN);
  611. lbs_deb_leave(LBS_DEB_CMD);
  612. return 0;
  613. }
  614. static int lbs_cmd_802_11_rf_channel(struct lbs_private *priv,
  615. struct cmd_ds_command *cmd,
  616. int option, void *pdata_buf)
  617. {
  618. struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
  619. lbs_deb_enter(LBS_DEB_CMD);
  620. cmd->command = cpu_to_le16(CMD_802_11_RF_CHANNEL);
  621. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
  622. S_DS_GEN);
  623. if (option == CMD_OPT_802_11_RF_CHANNEL_SET) {
  624. rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
  625. }
  626. rfchan->action = cpu_to_le16(option);
  627. lbs_deb_leave(LBS_DEB_CMD);
  628. return 0;
  629. }
  630. static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
  631. struct cmd_ds_command *cmd)
  632. {
  633. lbs_deb_enter(LBS_DEB_CMD);
  634. cmd->command = cpu_to_le16(CMD_802_11_RSSI);
  635. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
  636. cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
  637. /* reset Beacon SNR/NF/RSSI values */
  638. priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
  639. priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
  640. priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
  641. priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
  642. priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
  643. priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
  644. lbs_deb_leave(LBS_DEB_CMD);
  645. return 0;
  646. }
  647. static int lbs_cmd_reg_access(struct lbs_private *priv,
  648. struct cmd_ds_command *cmdptr,
  649. u8 cmd_action, void *pdata_buf)
  650. {
  651. struct lbs_offset_value *offval;
  652. lbs_deb_enter(LBS_DEB_CMD);
  653. offval = (struct lbs_offset_value *)pdata_buf;
  654. switch (le16_to_cpu(cmdptr->command)) {
  655. case CMD_MAC_REG_ACCESS:
  656. {
  657. struct cmd_ds_mac_reg_access *macreg;
  658. cmdptr->size =
  659. cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
  660. + S_DS_GEN);
  661. macreg =
  662. (struct cmd_ds_mac_reg_access *)&cmdptr->params.
  663. macreg;
  664. macreg->action = cpu_to_le16(cmd_action);
  665. macreg->offset = cpu_to_le16((u16) offval->offset);
  666. macreg->value = cpu_to_le32(offval->value);
  667. break;
  668. }
  669. case CMD_BBP_REG_ACCESS:
  670. {
  671. struct cmd_ds_bbp_reg_access *bbpreg;
  672. cmdptr->size =
  673. cpu_to_le16(sizeof
  674. (struct cmd_ds_bbp_reg_access)
  675. + S_DS_GEN);
  676. bbpreg =
  677. (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
  678. bbpreg;
  679. bbpreg->action = cpu_to_le16(cmd_action);
  680. bbpreg->offset = cpu_to_le16((u16) offval->offset);
  681. bbpreg->value = (u8) offval->value;
  682. break;
  683. }
  684. case CMD_RF_REG_ACCESS:
  685. {
  686. struct cmd_ds_rf_reg_access *rfreg;
  687. cmdptr->size =
  688. cpu_to_le16(sizeof
  689. (struct cmd_ds_rf_reg_access) +
  690. S_DS_GEN);
  691. rfreg =
  692. (struct cmd_ds_rf_reg_access *)&cmdptr->params.
  693. rfreg;
  694. rfreg->action = cpu_to_le16(cmd_action);
  695. rfreg->offset = cpu_to_le16((u16) offval->offset);
  696. rfreg->value = (u8) offval->value;
  697. break;
  698. }
  699. default:
  700. break;
  701. }
  702. lbs_deb_leave(LBS_DEB_CMD);
  703. return 0;
  704. }
  705. static int lbs_cmd_802_11_mac_address(struct lbs_private *priv,
  706. struct cmd_ds_command *cmd,
  707. u16 cmd_action)
  708. {
  709. lbs_deb_enter(LBS_DEB_CMD);
  710. cmd->command = cpu_to_le16(CMD_802_11_MAC_ADDRESS);
  711. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
  712. S_DS_GEN);
  713. cmd->result = 0;
  714. cmd->params.macadd.action = cpu_to_le16(cmd_action);
  715. if (cmd_action == CMD_ACT_SET) {
  716. memcpy(cmd->params.macadd.macadd,
  717. priv->current_addr, ETH_ALEN);
  718. lbs_deb_hex(LBS_DEB_CMD, "SET_CMD: MAC addr", priv->current_addr, 6);
  719. }
  720. lbs_deb_leave(LBS_DEB_CMD);
  721. return 0;
  722. }
  723. static int lbs_cmd_802_11_eeprom_access(struct lbs_private *priv,
  724. struct cmd_ds_command *cmd,
  725. int cmd_action, void *pdata_buf)
  726. {
  727. struct lbs_ioctl_regrdwr *ea = pdata_buf;
  728. lbs_deb_enter(LBS_DEB_CMD);
  729. cmd->command = cpu_to_le16(CMD_802_11_EEPROM_ACCESS);
  730. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
  731. S_DS_GEN);
  732. cmd->result = 0;
  733. cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
  734. cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
  735. cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
  736. cmd->params.rdeeprom.value = 0;
  737. lbs_deb_leave(LBS_DEB_CMD);
  738. return 0;
  739. }
  740. static int lbs_cmd_bt_access(struct lbs_private *priv,
  741. struct cmd_ds_command *cmd,
  742. u16 cmd_action, void *pdata_buf)
  743. {
  744. struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
  745. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  746. cmd->command = cpu_to_le16(CMD_BT_ACCESS);
  747. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
  748. cmd->result = 0;
  749. bt_access->action = cpu_to_le16(cmd_action);
  750. switch (cmd_action) {
  751. case CMD_ACT_BT_ACCESS_ADD:
  752. memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
  753. lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
  754. break;
  755. case CMD_ACT_BT_ACCESS_DEL:
  756. memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
  757. lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
  758. break;
  759. case CMD_ACT_BT_ACCESS_LIST:
  760. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  761. break;
  762. case CMD_ACT_BT_ACCESS_RESET:
  763. break;
  764. case CMD_ACT_BT_ACCESS_SET_INVERT:
  765. bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
  766. break;
  767. case CMD_ACT_BT_ACCESS_GET_INVERT:
  768. break;
  769. default:
  770. break;
  771. }
  772. lbs_deb_leave(LBS_DEB_CMD);
  773. return 0;
  774. }
  775. static int lbs_cmd_fwt_access(struct lbs_private *priv,
  776. struct cmd_ds_command *cmd,
  777. u16 cmd_action, void *pdata_buf)
  778. {
  779. struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
  780. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  781. cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
  782. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
  783. cmd->result = 0;
  784. if (pdata_buf)
  785. memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
  786. else
  787. memset(fwt_access, 0, sizeof(*fwt_access));
  788. fwt_access->action = cpu_to_le16(cmd_action);
  789. lbs_deb_leave(LBS_DEB_CMD);
  790. return 0;
  791. }
  792. static int lbs_cmd_mesh_access(struct lbs_private *priv,
  793. struct cmd_ds_command *cmd,
  794. u16 cmd_action, void *pdata_buf)
  795. {
  796. struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
  797. lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
  798. cmd->command = cpu_to_le16(CMD_MESH_ACCESS);
  799. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
  800. cmd->result = 0;
  801. if (pdata_buf)
  802. memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
  803. else
  804. memset(mesh_access, 0, sizeof(*mesh_access));
  805. mesh_access->action = cpu_to_le16(cmd_action);
  806. lbs_deb_leave(LBS_DEB_CMD);
  807. return 0;
  808. }
  809. static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
  810. struct cmd_ds_command *cmd,
  811. u16 cmd_action)
  812. {
  813. struct cmd_ds_802_11_beacon_control
  814. *bcn_ctrl = &cmd->params.bcn_ctrl;
  815. lbs_deb_enter(LBS_DEB_CMD);
  816. cmd->size =
  817. cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
  818. + S_DS_GEN);
  819. cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
  820. bcn_ctrl->action = cpu_to_le16(cmd_action);
  821. bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
  822. bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
  823. lbs_deb_leave(LBS_DEB_CMD);
  824. return 0;
  825. }
  826. /*
  827. * Note: NEVER use lbs_queue_cmd() with addtail==0 other than for
  828. * the command timer, because it does not account for queued commands.
  829. */
  830. void lbs_queue_cmd(struct lbs_private *priv,
  831. struct cmd_ctrl_node *cmdnode,
  832. u8 addtail)
  833. {
  834. unsigned long flags;
  835. struct cmd_ds_command *cmdptr;
  836. lbs_deb_enter(LBS_DEB_HOST);
  837. if (!cmdnode) {
  838. lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
  839. goto done;
  840. }
  841. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  842. if (!cmdptr) {
  843. lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n");
  844. goto done;
  845. }
  846. /* Exit_PS command needs to be queued in the header always. */
  847. if (le16_to_cpu(cmdptr->command) == CMD_802_11_PS_MODE) {
  848. struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
  849. if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  850. if (priv->psstate != PS_STATE_FULL_POWER)
  851. addtail = 0;
  852. }
  853. }
  854. spin_lock_irqsave(&priv->driver_lock, flags);
  855. if (addtail)
  856. list_add_tail(&cmdnode->list, &priv->cmdpendingq);
  857. else
  858. list_add(&cmdnode->list, &priv->cmdpendingq);
  859. spin_unlock_irqrestore(&priv->driver_lock, flags);
  860. lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
  861. le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
  862. done:
  863. lbs_deb_leave(LBS_DEB_HOST);
  864. }
  865. /*
  866. * TODO: Fix the issue when DownloadcommandToStation is being called the
  867. * second time when the command times out. All the cmdptr->xxx are in little
  868. * endian and therefore all the comparissions will fail.
  869. * For now - we are not performing the endian conversion the second time - but
  870. * for PS and DEEP_SLEEP we need to worry
  871. */
  872. static int DownloadcommandToStation(struct lbs_private *priv,
  873. struct cmd_ctrl_node *cmdnode)
  874. {
  875. unsigned long flags;
  876. struct cmd_ds_command *cmdptr;
  877. int ret = -1;
  878. u16 cmdsize;
  879. u16 command;
  880. lbs_deb_enter(LBS_DEB_HOST);
  881. if (!priv || !cmdnode) {
  882. lbs_deb_host("DNLD_CMD: priv or cmdmode is NULL\n");
  883. goto done;
  884. }
  885. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  886. spin_lock_irqsave(&priv->driver_lock, flags);
  887. if (!cmdptr || !cmdptr->size) {
  888. lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n");
  889. __lbs_cleanup_and_insert_cmd(priv, cmdnode);
  890. spin_unlock_irqrestore(&priv->driver_lock, flags);
  891. goto done;
  892. }
  893. priv->cur_cmd = cmdnode;
  894. priv->cur_cmd_retcode = 0;
  895. spin_unlock_irqrestore(&priv->driver_lock, flags);
  896. cmdsize = le16_to_cpu(cmdptr->size);
  897. command = le16_to_cpu(cmdptr->command);
  898. lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n",
  899. command, cmdsize, jiffies);
  900. lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", cmdnode->bufvirtualaddr, cmdsize);
  901. cmdnode->cmdwaitqwoken = 0;
  902. ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
  903. if (ret != 0) {
  904. lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n");
  905. spin_lock_irqsave(&priv->driver_lock, flags);
  906. priv->cur_cmd_retcode = ret;
  907. __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
  908. priv->cur_cmd = NULL;
  909. spin_unlock_irqrestore(&priv->driver_lock, flags);
  910. goto done;
  911. }
  912. lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
  913. /* Setup the timer after transmit command */
  914. if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
  915. || command == CMD_802_11_ASSOCIATE)
  916. mod_timer(&priv->command_timer, jiffies + (10*HZ));
  917. else
  918. mod_timer(&priv->command_timer, jiffies + (5*HZ));
  919. ret = 0;
  920. done:
  921. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  922. return ret;
  923. }
  924. static int lbs_cmd_mac_control(struct lbs_private *priv,
  925. struct cmd_ds_command *cmd)
  926. {
  927. struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
  928. lbs_deb_enter(LBS_DEB_CMD);
  929. cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
  930. cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
  931. mac->action = cpu_to_le16(priv->currentpacketfilter);
  932. lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
  933. le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
  934. lbs_deb_leave(LBS_DEB_CMD);
  935. return 0;
  936. }
  937. /**
  938. * This function inserts command node to cmdfreeq
  939. * after cleans it. Requires priv->driver_lock held.
  940. */
  941. void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  942. struct cmd_ctrl_node *ptempcmd)
  943. {
  944. if (!ptempcmd)
  945. return;
  946. cleanup_cmdnode(ptempcmd);
  947. list_add_tail(&ptempcmd->list, &priv->cmdfreeq);
  948. }
  949. static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
  950. struct cmd_ctrl_node *ptempcmd)
  951. {
  952. unsigned long flags;
  953. spin_lock_irqsave(&priv->driver_lock, flags);
  954. __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
  955. spin_unlock_irqrestore(&priv->driver_lock, flags);
  956. }
  957. int lbs_set_radio_control(struct lbs_private *priv)
  958. {
  959. int ret = 0;
  960. lbs_deb_enter(LBS_DEB_CMD);
  961. ret = lbs_prepare_and_send_command(priv,
  962. CMD_802_11_RADIO_CONTROL,
  963. CMD_ACT_SET,
  964. CMD_OPTION_WAITFORRSP, 0, NULL);
  965. lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
  966. priv->radioon, priv->preamble);
  967. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  968. return ret;
  969. }
  970. int lbs_set_mac_packet_filter(struct lbs_private *priv)
  971. {
  972. int ret = 0;
  973. lbs_deb_enter(LBS_DEB_CMD);
  974. /* Send MAC control command to station */
  975. ret = lbs_prepare_and_send_command(priv,
  976. CMD_MAC_CONTROL, 0, 0, 0, NULL);
  977. lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
  978. return ret;
  979. }
  980. /**
  981. * @brief This function prepare the command before send to firmware.
  982. *
  983. * @param priv A pointer to struct lbs_private structure
  984. * @param cmd_no command number
  985. * @param cmd_action command action: GET or SET
  986. * @param wait_option wait option: wait response or not
  987. * @param cmd_oid cmd oid: treated as sub command
  988. * @param pdata_buf A pointer to informaion buffer
  989. * @return 0 or -1
  990. */
  991. int lbs_prepare_and_send_command(struct lbs_private *priv,
  992. u16 cmd_no,
  993. u16 cmd_action,
  994. u16 wait_option, u32 cmd_oid, void *pdata_buf)
  995. {
  996. int ret = 0;
  997. struct cmd_ctrl_node *cmdnode;
  998. struct cmd_ds_command *cmdptr;
  999. unsigned long flags;
  1000. lbs_deb_enter(LBS_DEB_HOST);
  1001. if (!priv) {
  1002. lbs_deb_host("PREP_CMD: priv is NULL\n");
  1003. ret = -1;
  1004. goto done;
  1005. }
  1006. if (priv->surpriseremoved) {
  1007. lbs_deb_host("PREP_CMD: card removed\n");
  1008. ret = -1;
  1009. goto done;
  1010. }
  1011. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1012. if (cmdnode == NULL) {
  1013. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1014. /* Wake up main thread to execute next command */
  1015. wake_up_interruptible(&priv->waitq);
  1016. ret = -1;
  1017. goto done;
  1018. }
  1019. lbs_set_cmd_ctrl_node(priv, cmdnode, wait_option, pdata_buf);
  1020. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  1021. lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
  1022. if (!cmdptr) {
  1023. lbs_deb_host("PREP_CMD: cmdptr is NULL\n");
  1024. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1025. ret = -1;
  1026. goto done;
  1027. }
  1028. /* Set sequence number, command and INT option */
  1029. priv->seqnum++;
  1030. cmdptr->seqnum = cpu_to_le16(priv->seqnum);
  1031. cmdptr->command = cpu_to_le16(cmd_no);
  1032. cmdptr->result = 0;
  1033. switch (cmd_no) {
  1034. case CMD_802_11_PS_MODE:
  1035. ret = lbs_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
  1036. break;
  1037. case CMD_802_11_SCAN:
  1038. ret = lbs_cmd_80211_scan(priv, cmdptr, pdata_buf);
  1039. break;
  1040. case CMD_MAC_CONTROL:
  1041. ret = lbs_cmd_mac_control(priv, cmdptr);
  1042. break;
  1043. case CMD_802_11_ASSOCIATE:
  1044. case CMD_802_11_REASSOCIATE:
  1045. ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
  1046. break;
  1047. case CMD_802_11_DEAUTHENTICATE:
  1048. ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
  1049. break;
  1050. case CMD_802_11_SET_WEP:
  1051. ret = lbs_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
  1052. break;
  1053. case CMD_802_11_AD_HOC_START:
  1054. ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
  1055. break;
  1056. case CMD_CODE_DNLD:
  1057. break;
  1058. case CMD_802_11_RESET:
  1059. ret = lbs_cmd_802_11_reset(priv, cmdptr, cmd_action);
  1060. break;
  1061. case CMD_802_11_GET_LOG:
  1062. ret = lbs_cmd_802_11_get_log(priv, cmdptr);
  1063. break;
  1064. case CMD_802_11_AUTHENTICATE:
  1065. ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
  1066. break;
  1067. case CMD_802_11_GET_STAT:
  1068. ret = lbs_cmd_802_11_get_stat(priv, cmdptr);
  1069. break;
  1070. case CMD_802_11_SNMP_MIB:
  1071. ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
  1072. cmd_action, cmd_oid, pdata_buf);
  1073. break;
  1074. case CMD_MAC_REG_ACCESS:
  1075. case CMD_BBP_REG_ACCESS:
  1076. case CMD_RF_REG_ACCESS:
  1077. ret = lbs_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
  1078. break;
  1079. case CMD_802_11_RF_CHANNEL:
  1080. ret = lbs_cmd_802_11_rf_channel(priv, cmdptr,
  1081. cmd_action, pdata_buf);
  1082. break;
  1083. case CMD_802_11_RF_TX_POWER:
  1084. ret = lbs_cmd_802_11_rf_tx_power(priv, cmdptr,
  1085. cmd_action, pdata_buf);
  1086. break;
  1087. case CMD_802_11_RADIO_CONTROL:
  1088. ret = lbs_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
  1089. break;
  1090. case CMD_802_11_DATA_RATE:
  1091. ret = lbs_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
  1092. break;
  1093. case CMD_802_11_RATE_ADAPT_RATESET:
  1094. ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
  1095. cmdptr, cmd_action);
  1096. break;
  1097. case CMD_MAC_MULTICAST_ADR:
  1098. ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
  1099. break;
  1100. case CMD_802_11_MONITOR_MODE:
  1101. ret = lbs_cmd_802_11_monitor_mode(priv, cmdptr,
  1102. cmd_action, pdata_buf);
  1103. break;
  1104. case CMD_802_11_AD_HOC_JOIN:
  1105. ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
  1106. break;
  1107. case CMD_802_11_RSSI:
  1108. ret = lbs_cmd_802_11_rssi(priv, cmdptr);
  1109. break;
  1110. case CMD_802_11_AD_HOC_STOP:
  1111. ret = lbs_cmd_80211_ad_hoc_stop(priv, cmdptr);
  1112. break;
  1113. case CMD_802_11_ENABLE_RSN:
  1114. ret = lbs_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
  1115. pdata_buf);
  1116. break;
  1117. case CMD_802_11_KEY_MATERIAL:
  1118. ret = lbs_cmd_802_11_key_material(priv, cmdptr, cmd_action,
  1119. cmd_oid, pdata_buf);
  1120. break;
  1121. case CMD_802_11_PAIRWISE_TSC:
  1122. break;
  1123. case CMD_802_11_GROUP_TSC:
  1124. break;
  1125. case CMD_802_11_MAC_ADDRESS:
  1126. ret = lbs_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
  1127. break;
  1128. case CMD_802_11_EEPROM_ACCESS:
  1129. ret = lbs_cmd_802_11_eeprom_access(priv, cmdptr,
  1130. cmd_action, pdata_buf);
  1131. break;
  1132. case CMD_802_11_SET_AFC:
  1133. case CMD_802_11_GET_AFC:
  1134. cmdptr->command = cpu_to_le16(cmd_no);
  1135. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
  1136. S_DS_GEN);
  1137. memmove(&cmdptr->params.afc,
  1138. pdata_buf, sizeof(struct cmd_ds_802_11_afc));
  1139. ret = 0;
  1140. goto done;
  1141. case CMD_802_11D_DOMAIN_INFO:
  1142. ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
  1143. cmd_no, cmd_action);
  1144. break;
  1145. case CMD_802_11_SLEEP_PARAMS:
  1146. ret = lbs_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
  1147. break;
  1148. case CMD_802_11_INACTIVITY_TIMEOUT:
  1149. ret = lbs_cmd_802_11_inactivity_timeout(priv, cmdptr,
  1150. cmd_action, pdata_buf);
  1151. lbs_set_cmd_ctrl_node(priv, cmdnode, 0, pdata_buf);
  1152. break;
  1153. case CMD_802_11_TPC_CFG:
  1154. cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
  1155. cmdptr->size =
  1156. cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
  1157. S_DS_GEN);
  1158. memmove(&cmdptr->params.tpccfg,
  1159. pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
  1160. ret = 0;
  1161. break;
  1162. case CMD_802_11_LED_GPIO_CTRL:
  1163. {
  1164. struct mrvlietypes_ledgpio *gpio =
  1165. (struct mrvlietypes_ledgpio*)
  1166. cmdptr->params.ledgpio.data;
  1167. memmove(&cmdptr->params.ledgpio,
  1168. pdata_buf,
  1169. sizeof(struct cmd_ds_802_11_led_ctrl));
  1170. cmdptr->command =
  1171. cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
  1172. #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
  1173. cmdptr->size =
  1174. cpu_to_le16(le16_to_cpu(gpio->header.len)
  1175. + S_DS_GEN
  1176. + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
  1177. gpio->header.len = gpio->header.len;
  1178. ret = 0;
  1179. break;
  1180. }
  1181. case CMD_802_11_SUBSCRIBE_EVENT:
  1182. lbs_cmd_802_11_subscribe_event(priv, cmdptr,
  1183. cmd_action, pdata_buf);
  1184. break;
  1185. case CMD_802_11_PWR_CFG:
  1186. cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG);
  1187. cmdptr->size =
  1188. cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
  1189. S_DS_GEN);
  1190. memmove(&cmdptr->params.pwrcfg, pdata_buf,
  1191. sizeof(struct cmd_ds_802_11_pwr_cfg));
  1192. ret = 0;
  1193. break;
  1194. case CMD_BT_ACCESS:
  1195. ret = lbs_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
  1196. break;
  1197. case CMD_FWT_ACCESS:
  1198. ret = lbs_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
  1199. break;
  1200. case CMD_MESH_ACCESS:
  1201. ret = lbs_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
  1202. break;
  1203. case CMD_GET_TSF:
  1204. cmdptr->command = cpu_to_le16(CMD_GET_TSF);
  1205. cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
  1206. S_DS_GEN);
  1207. ret = 0;
  1208. break;
  1209. case CMD_802_11_BEACON_CTRL:
  1210. ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
  1211. break;
  1212. default:
  1213. lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
  1214. ret = -1;
  1215. break;
  1216. }
  1217. /* return error, since the command preparation failed */
  1218. if (ret != 0) {
  1219. lbs_deb_host("PREP_CMD: command preparation failed\n");
  1220. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1221. ret = -1;
  1222. goto done;
  1223. }
  1224. cmdnode->cmdwaitqwoken = 0;
  1225. lbs_queue_cmd(priv, cmdnode, 1);
  1226. wake_up_interruptible(&priv->waitq);
  1227. if (wait_option & CMD_OPTION_WAITFORRSP) {
  1228. lbs_deb_host("PREP_CMD: wait for response\n");
  1229. might_sleep();
  1230. wait_event_interruptible(cmdnode->cmdwait_q,
  1231. cmdnode->cmdwaitqwoken);
  1232. }
  1233. spin_lock_irqsave(&priv->driver_lock, flags);
  1234. if (priv->cur_cmd_retcode) {
  1235. lbs_deb_host("PREP_CMD: command failed with return code %d\n",
  1236. priv->cur_cmd_retcode);
  1237. priv->cur_cmd_retcode = 0;
  1238. ret = -1;
  1239. }
  1240. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1241. done:
  1242. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1243. return ret;
  1244. }
  1245. EXPORT_SYMBOL_GPL(lbs_prepare_and_send_command);
  1246. /**
  1247. * @brief This function allocates the command buffer and link
  1248. * it to command free queue.
  1249. *
  1250. * @param priv A pointer to struct lbs_private structure
  1251. * @return 0 or -1
  1252. */
  1253. int lbs_allocate_cmd_buffer(struct lbs_private *priv)
  1254. {
  1255. int ret = 0;
  1256. u32 ulbufsize;
  1257. u32 i;
  1258. struct cmd_ctrl_node *tempcmd_array;
  1259. u8 *ptempvirtualaddr;
  1260. lbs_deb_enter(LBS_DEB_HOST);
  1261. /* Allocate and initialize cmdCtrlNode */
  1262. ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
  1263. if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
  1264. lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
  1265. ret = -1;
  1266. goto done;
  1267. }
  1268. priv->cmd_array = tempcmd_array;
  1269. /* Allocate and initialize command buffers */
  1270. ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
  1271. for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
  1272. if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
  1273. lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
  1274. ret = -1;
  1275. goto done;
  1276. }
  1277. /* Update command buffer virtual */
  1278. tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
  1279. }
  1280. for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
  1281. init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
  1282. lbs_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
  1283. }
  1284. ret = 0;
  1285. done:
  1286. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1287. return ret;
  1288. }
  1289. /**
  1290. * @brief This function frees the command buffer.
  1291. *
  1292. * @param priv A pointer to struct lbs_private structure
  1293. * @return 0 or -1
  1294. */
  1295. int lbs_free_cmd_buffer(struct lbs_private *priv)
  1296. {
  1297. u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
  1298. unsigned int i;
  1299. struct cmd_ctrl_node *tempcmd_array;
  1300. lbs_deb_enter(LBS_DEB_HOST);
  1301. /* need to check if cmd array is allocated or not */
  1302. if (priv->cmd_array == NULL) {
  1303. lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
  1304. goto done;
  1305. }
  1306. tempcmd_array = priv->cmd_array;
  1307. /* Release shared memory buffers */
  1308. ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
  1309. for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
  1310. if (tempcmd_array[i].bufvirtualaddr) {
  1311. kfree(tempcmd_array[i].bufvirtualaddr);
  1312. tempcmd_array[i].bufvirtualaddr = NULL;
  1313. }
  1314. }
  1315. /* Release cmd_ctrl_node */
  1316. if (priv->cmd_array) {
  1317. kfree(priv->cmd_array);
  1318. priv->cmd_array = NULL;
  1319. }
  1320. done:
  1321. lbs_deb_leave(LBS_DEB_HOST);
  1322. return 0;
  1323. }
  1324. /**
  1325. * @brief This function gets a free command node if available in
  1326. * command free queue.
  1327. *
  1328. * @param priv A pointer to struct lbs_private structure
  1329. * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
  1330. */
  1331. struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
  1332. {
  1333. struct cmd_ctrl_node *tempnode;
  1334. unsigned long flags;
  1335. lbs_deb_enter(LBS_DEB_HOST);
  1336. if (!priv)
  1337. return NULL;
  1338. spin_lock_irqsave(&priv->driver_lock, flags);
  1339. if (!list_empty(&priv->cmdfreeq)) {
  1340. tempnode = list_first_entry(&priv->cmdfreeq,
  1341. struct cmd_ctrl_node, list);
  1342. list_del(&tempnode->list);
  1343. } else {
  1344. lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
  1345. tempnode = NULL;
  1346. }
  1347. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1348. if (tempnode)
  1349. cleanup_cmdnode(tempnode);
  1350. lbs_deb_leave(LBS_DEB_HOST);
  1351. return tempnode;
  1352. }
  1353. /**
  1354. * @brief This function cleans command node.
  1355. *
  1356. * @param ptempnode A pointer to cmdCtrlNode structure
  1357. * @return n/a
  1358. */
  1359. static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
  1360. {
  1361. lbs_deb_enter(LBS_DEB_HOST);
  1362. if (!ptempnode)
  1363. return;
  1364. ptempnode->cmdwaitqwoken = 1;
  1365. wake_up_interruptible(&ptempnode->cmdwait_q);
  1366. ptempnode->wait_option = 0;
  1367. ptempnode->pdata_buf = NULL;
  1368. ptempnode->callback = NULL;
  1369. ptempnode->callback_arg = 0;
  1370. if (ptempnode->bufvirtualaddr != NULL)
  1371. memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
  1372. lbs_deb_leave(LBS_DEB_HOST);
  1373. }
  1374. /**
  1375. * @brief This function initializes the command node.
  1376. *
  1377. * @param priv A pointer to struct lbs_private structure
  1378. * @param ptempnode A pointer to cmd_ctrl_node structure
  1379. * @param wait_option wait option: wait response or not
  1380. * @param pdata_buf A pointer to informaion buffer
  1381. * @return 0 or -1
  1382. */
  1383. void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
  1384. struct cmd_ctrl_node *ptempnode,
  1385. u16 wait_option, void *pdata_buf)
  1386. {
  1387. lbs_deb_enter(LBS_DEB_HOST);
  1388. if (!ptempnode)
  1389. return;
  1390. ptempnode->wait_option = wait_option;
  1391. ptempnode->pdata_buf = pdata_buf;
  1392. ptempnode->callback = NULL;
  1393. ptempnode->callback_arg = 0;
  1394. lbs_deb_leave(LBS_DEB_HOST);
  1395. }
  1396. /**
  1397. * @brief This function executes next command in command
  1398. * pending queue. It will put fimware back to PS mode
  1399. * if applicable.
  1400. *
  1401. * @param priv A pointer to struct lbs_private structure
  1402. * @return 0 or -1
  1403. */
  1404. int lbs_execute_next_command(struct lbs_private *priv)
  1405. {
  1406. struct cmd_ctrl_node *cmdnode = NULL;
  1407. struct cmd_ds_command *cmdptr;
  1408. unsigned long flags;
  1409. int ret = 0;
  1410. // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1411. // only caller to us is lbs_thread() and we get even when a
  1412. // data packet is received
  1413. lbs_deb_enter(LBS_DEB_THREAD);
  1414. spin_lock_irqsave(&priv->driver_lock, flags);
  1415. if (priv->cur_cmd) {
  1416. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1417. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1418. ret = -1;
  1419. goto done;
  1420. }
  1421. if (!list_empty(&priv->cmdpendingq)) {
  1422. cmdnode = list_first_entry(&priv->cmdpendingq,
  1423. struct cmd_ctrl_node, list);
  1424. }
  1425. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1426. if (cmdnode) {
  1427. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  1428. if (is_command_allowed_in_ps(le16_to_cpu(cmdptr->command))) {
  1429. if ((priv->psstate == PS_STATE_SLEEP) ||
  1430. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1431. lbs_deb_host(
  1432. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1433. le16_to_cpu(cmdptr->command),
  1434. priv->psstate);
  1435. ret = -1;
  1436. goto done;
  1437. }
  1438. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1439. "0x%04x in psstate %d\n",
  1440. le16_to_cpu(cmdptr->command),
  1441. priv->psstate);
  1442. } else if (priv->psstate != PS_STATE_FULL_POWER) {
  1443. /*
  1444. * 1. Non-PS command:
  1445. * Queue it. set needtowakeup to TRUE if current state
  1446. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1447. * 2. PS command but not Exit_PS:
  1448. * Ignore it.
  1449. * 3. PS command Exit_PS:
  1450. * Set needtowakeup to TRUE if current state is SLEEP,
  1451. * otherwise send this command down to firmware
  1452. * immediately.
  1453. */
  1454. if (cmdptr->command !=
  1455. cpu_to_le16(CMD_802_11_PS_MODE)) {
  1456. /* Prepare to send Exit PS,
  1457. * this non PS command will be sent later */
  1458. if ((priv->psstate == PS_STATE_SLEEP)
  1459. || (priv->psstate == PS_STATE_PRE_SLEEP)
  1460. ) {
  1461. /* w/ new scheme, it will not reach here.
  1462. since it is blocked in main_thread. */
  1463. priv->needtowakeup = 1;
  1464. } else
  1465. lbs_ps_wakeup(priv, 0);
  1466. ret = 0;
  1467. goto done;
  1468. } else {
  1469. /*
  1470. * PS command. Ignore it if it is not Exit_PS.
  1471. * otherwise send it down immediately.
  1472. */
  1473. struct cmd_ds_802_11_ps_mode *psm =
  1474. &cmdptr->params.psmode;
  1475. lbs_deb_host(
  1476. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1477. psm->action);
  1478. if (psm->action !=
  1479. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1480. lbs_deb_host(
  1481. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1482. list_del(&cmdnode->list);
  1483. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1484. ret = 0;
  1485. goto done;
  1486. }
  1487. if ((priv->psstate == PS_STATE_SLEEP) ||
  1488. (priv->psstate == PS_STATE_PRE_SLEEP)) {
  1489. lbs_deb_host(
  1490. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1491. list_del(&cmdnode->list);
  1492. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1493. priv->needtowakeup = 1;
  1494. ret = 0;
  1495. goto done;
  1496. }
  1497. lbs_deb_host(
  1498. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1499. }
  1500. }
  1501. list_del(&cmdnode->list);
  1502. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1503. le16_to_cpu(cmdptr->command));
  1504. DownloadcommandToStation(priv, cmdnode);
  1505. } else {
  1506. /*
  1507. * check if in power save mode, if yes, put the device back
  1508. * to PS mode
  1509. */
  1510. if ((priv->psmode != LBS802_11POWERMODECAM) &&
  1511. (priv->psstate == PS_STATE_FULL_POWER) &&
  1512. ((priv->connect_status == LBS_CONNECTED) ||
  1513. (priv->mesh_connect_status == LBS_CONNECTED))) {
  1514. if (priv->secinfo.WPAenabled ||
  1515. priv->secinfo.WPA2enabled) {
  1516. /* check for valid WPA group keys */
  1517. if (priv->wpa_mcast_key.len ||
  1518. priv->wpa_unicast_key.len) {
  1519. lbs_deb_host(
  1520. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1521. " go back to PS_SLEEP");
  1522. lbs_ps_sleep(priv, 0);
  1523. }
  1524. } else {
  1525. lbs_deb_host(
  1526. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1527. "go back to PS_SLEEP");
  1528. lbs_ps_sleep(priv, 0);
  1529. }
  1530. }
  1531. }
  1532. ret = 0;
  1533. done:
  1534. lbs_deb_leave(LBS_DEB_THREAD);
  1535. return ret;
  1536. }
  1537. void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
  1538. {
  1539. union iwreq_data iwrq;
  1540. u8 buf[50];
  1541. lbs_deb_enter(LBS_DEB_WEXT);
  1542. memset(&iwrq, 0, sizeof(union iwreq_data));
  1543. memset(buf, 0, sizeof(buf));
  1544. snprintf(buf, sizeof(buf) - 1, "%s", str);
  1545. iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
  1546. /* Send Event to upper layer */
  1547. lbs_deb_wext("event indication string %s\n", (char *)buf);
  1548. lbs_deb_wext("event indication length %d\n", iwrq.data.length);
  1549. lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
  1550. wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
  1551. lbs_deb_leave(LBS_DEB_WEXT);
  1552. }
  1553. static int sendconfirmsleep(struct lbs_private *priv, u8 *cmdptr, u16 size)
  1554. {
  1555. unsigned long flags;
  1556. int ret = 0;
  1557. lbs_deb_enter(LBS_DEB_HOST);
  1558. lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
  1559. size);
  1560. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
  1561. ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
  1562. priv->dnld_sent = DNLD_RES_RECEIVED;
  1563. spin_lock_irqsave(&priv->driver_lock, flags);
  1564. if (priv->intcounter || priv->currenttxskb)
  1565. lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
  1566. priv->intcounter, priv->currenttxskb);
  1567. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1568. if (ret) {
  1569. lbs_pr_alert(
  1570. "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
  1571. } else {
  1572. spin_lock_irqsave(&priv->driver_lock, flags);
  1573. if (!priv->intcounter) {
  1574. priv->psstate = PS_STATE_SLEEP;
  1575. } else {
  1576. lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
  1577. priv->intcounter);
  1578. }
  1579. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1580. lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
  1581. }
  1582. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1583. return ret;
  1584. }
  1585. void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
  1586. {
  1587. lbs_deb_enter(LBS_DEB_HOST);
  1588. /*
  1589. * PS is currently supported only in Infrastructure mode
  1590. * Remove this check if it is to be supported in IBSS mode also
  1591. */
  1592. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1593. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1594. lbs_deb_leave(LBS_DEB_HOST);
  1595. }
  1596. /**
  1597. * @brief This function sends Exit_PS command to firmware.
  1598. *
  1599. * @param priv A pointer to struct lbs_private structure
  1600. * @param wait_option wait response or not
  1601. * @return n/a
  1602. */
  1603. void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
  1604. {
  1605. __le32 Localpsmode;
  1606. lbs_deb_enter(LBS_DEB_HOST);
  1607. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1608. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1609. CMD_SUBCMD_EXIT_PS,
  1610. wait_option, 0, &Localpsmode);
  1611. lbs_deb_leave(LBS_DEB_HOST);
  1612. }
  1613. /**
  1614. * @brief This function checks condition and prepares to
  1615. * send sleep confirm command to firmware if ok.
  1616. *
  1617. * @param priv A pointer to struct lbs_private structure
  1618. * @param psmode Power Saving mode
  1619. * @return n/a
  1620. */
  1621. void lbs_ps_confirm_sleep(struct lbs_private *priv, u16 psmode)
  1622. {
  1623. unsigned long flags =0;
  1624. u8 allowed = 1;
  1625. lbs_deb_enter(LBS_DEB_HOST);
  1626. if (priv->dnld_sent) {
  1627. allowed = 0;
  1628. lbs_deb_host("dnld_sent was set");
  1629. }
  1630. spin_lock_irqsave(&priv->driver_lock, flags);
  1631. if (priv->cur_cmd) {
  1632. allowed = 0;
  1633. lbs_deb_host("cur_cmd was set");
  1634. }
  1635. if (priv->intcounter > 0) {
  1636. allowed = 0;
  1637. lbs_deb_host("intcounter %d", priv->intcounter);
  1638. }
  1639. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1640. if (allowed) {
  1641. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1642. sendconfirmsleep(priv, (u8 *) & priv->lbs_ps_confirm_sleep,
  1643. sizeof(struct PS_CMD_ConfirmSleep));
  1644. } else {
  1645. lbs_deb_host("sleep confirm has been delayed\n");
  1646. }
  1647. lbs_deb_leave(LBS_DEB_HOST);
  1648. }
  1649. /**
  1650. * @brief Simple callback that copies response back into command
  1651. *
  1652. * @param priv A pointer to struct lbs_private structure
  1653. * @param extra A pointer to the original command structure for which
  1654. * 'resp' is a response
  1655. * @param resp A pointer to the command response
  1656. *
  1657. * @return 0 on success, error on failure
  1658. */
  1659. int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
  1660. struct cmd_header *resp)
  1661. {
  1662. struct cmd_header *buf = (void *)extra;
  1663. uint16_t copy_len;
  1664. lbs_deb_enter(LBS_DEB_CMD);
  1665. copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
  1666. lbs_deb_cmd("Copying back %u bytes; command response was %u bytes, "
  1667. "copy back buffer was %u bytes", copy_len, resp->size,
  1668. buf->size);
  1669. memcpy(buf, resp, copy_len);
  1670. lbs_deb_leave(LBS_DEB_CMD);
  1671. return 0;
  1672. }
  1673. /**
  1674. * @brief Simple way to call firmware functions
  1675. *
  1676. * @param priv A pointer to struct lbs_private structure
  1677. * @param psmode one of the many CMD_802_11_xxxx
  1678. * @param cmd pointer to the parameters structure for above command
  1679. * (this should not include the command, size, sequence
  1680. * and result fields from struct cmd_ds_gen)
  1681. * @param cmd_size size structure pointed to by cmd
  1682. * @param rsp pointer to an area where the result should be placed
  1683. * @param rsp_size pointer to the size of the rsp area. If the firmware
  1684. * returns fewer bytes, then this *rsp_size will be
  1685. * changed to the actual size.
  1686. * @return -1 in case of a higher level error, otherwise
  1687. * the result code from the firmware
  1688. */
  1689. int __lbs_cmd(struct lbs_private *priv, uint16_t command,
  1690. struct cmd_header *in_cmd, int in_cmd_size,
  1691. int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
  1692. unsigned long callback_arg)
  1693. {
  1694. struct cmd_ctrl_node *cmdnode;
  1695. struct cmd_header *send_cmd;
  1696. unsigned long flags;
  1697. int ret = 0;
  1698. lbs_deb_enter(LBS_DEB_HOST);
  1699. if (!priv) {
  1700. lbs_deb_host("PREP_CMD: priv is NULL\n");
  1701. ret = -1;
  1702. goto done;
  1703. }
  1704. if (priv->surpriseremoved) {
  1705. lbs_deb_host("PREP_CMD: card removed\n");
  1706. ret = -1;
  1707. goto done;
  1708. }
  1709. cmdnode = lbs_get_cmd_ctrl_node(priv);
  1710. if (cmdnode == NULL) {
  1711. lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
  1712. /* Wake up main thread to execute next command */
  1713. wake_up_interruptible(&priv->waitq);
  1714. ret = -1;
  1715. goto done;
  1716. }
  1717. send_cmd = (struct cmd_header *) cmdnode->bufvirtualaddr;
  1718. cmdnode->wait_option = CMD_OPTION_WAITFORRSP;
  1719. cmdnode->callback = callback;
  1720. cmdnode->callback_arg = callback_arg;
  1721. /* Copy the incoming command to the buffer */
  1722. memcpy(send_cmd, in_cmd, in_cmd_size);
  1723. /* Set sequence number, clean result, move to buffer */
  1724. priv->seqnum++;
  1725. send_cmd->command = cpu_to_le16(command);
  1726. send_cmd->size = cpu_to_le16(in_cmd_size);
  1727. send_cmd->seqnum = cpu_to_le16(priv->seqnum);
  1728. send_cmd->result = 0;
  1729. lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
  1730. /* here was the big old switch() statement, which is now obsolete,
  1731. * because the caller of lbs_cmd() sets up all of *cmd for us. */
  1732. cmdnode->cmdwaitqwoken = 0;
  1733. lbs_queue_cmd(priv, cmdnode, 1);
  1734. wake_up_interruptible(&priv->waitq);
  1735. might_sleep();
  1736. wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
  1737. spin_lock_irqsave(&priv->driver_lock, flags);
  1738. if (priv->cur_cmd_retcode) {
  1739. lbs_deb_host("PREP_CMD: command failed with return code %d\n",
  1740. priv->cur_cmd_retcode);
  1741. priv->cur_cmd_retcode = 0;
  1742. ret = -1;
  1743. }
  1744. spin_unlock_irqrestore(&priv->driver_lock, flags);
  1745. done:
  1746. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1747. return ret;
  1748. }
  1749. EXPORT_SYMBOL_GPL(__lbs_cmd);