cmd.c 55 KB

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