cmd.c 53 KB

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