cmd.c 52 KB

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