cmd.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004
  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->wait_option = 0;
  1348. ptempnode->pdata_buf = NULL;
  1349. if (ptempnode->bufvirtualaddr != NULL)
  1350. memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
  1351. lbs_deb_leave(LBS_DEB_HOST);
  1352. }
  1353. /**
  1354. * @brief This function initializes the command node.
  1355. *
  1356. * @param priv A pointer to struct lbs_private structure
  1357. * @param ptempnode A pointer to cmd_ctrl_node structure
  1358. * @param wait_option wait option: wait response or not
  1359. * @param pdata_buf A pointer to informaion buffer
  1360. * @return 0 or -1
  1361. */
  1362. void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
  1363. struct cmd_ctrl_node *ptempnode,
  1364. u16 wait_option, void *pdata_buf)
  1365. {
  1366. lbs_deb_enter(LBS_DEB_HOST);
  1367. if (!ptempnode)
  1368. return;
  1369. ptempnode->wait_option = wait_option;
  1370. ptempnode->pdata_buf = pdata_buf;
  1371. lbs_deb_leave(LBS_DEB_HOST);
  1372. }
  1373. /**
  1374. * @brief This function executes next command in command
  1375. * pending queue. It will put fimware back to PS mode
  1376. * if applicable.
  1377. *
  1378. * @param priv A pointer to struct lbs_private structure
  1379. * @return 0 or -1
  1380. */
  1381. int lbs_execute_next_command(struct lbs_private *priv)
  1382. {
  1383. struct lbs_adapter *adapter = priv->adapter;
  1384. struct cmd_ctrl_node *cmdnode = NULL;
  1385. struct cmd_ds_command *cmdptr;
  1386. unsigned long flags;
  1387. int ret = 0;
  1388. // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
  1389. // only caller to us is lbs_thread() and we get even when a
  1390. // data packet is received
  1391. lbs_deb_enter(LBS_DEB_THREAD);
  1392. spin_lock_irqsave(&adapter->driver_lock, flags);
  1393. if (adapter->cur_cmd) {
  1394. lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
  1395. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1396. ret = -1;
  1397. goto done;
  1398. }
  1399. if (!list_empty(&adapter->cmdpendingq)) {
  1400. cmdnode = (struct cmd_ctrl_node *)
  1401. adapter->cmdpendingq.next;
  1402. }
  1403. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1404. if (cmdnode) {
  1405. cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
  1406. if (is_command_allowed_in_ps(cmdptr->command)) {
  1407. if ((adapter->psstate == PS_STATE_SLEEP) ||
  1408. (adapter->psstate == PS_STATE_PRE_SLEEP)) {
  1409. lbs_deb_host(
  1410. "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
  1411. le16_to_cpu(cmdptr->command),
  1412. adapter->psstate);
  1413. ret = -1;
  1414. goto done;
  1415. }
  1416. lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
  1417. "0x%04x in psstate %d\n",
  1418. le16_to_cpu(cmdptr->command),
  1419. adapter->psstate);
  1420. } else if (adapter->psstate != PS_STATE_FULL_POWER) {
  1421. /*
  1422. * 1. Non-PS command:
  1423. * Queue it. set needtowakeup to TRUE if current state
  1424. * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
  1425. * 2. PS command but not Exit_PS:
  1426. * Ignore it.
  1427. * 3. PS command Exit_PS:
  1428. * Set needtowakeup to TRUE if current state is SLEEP,
  1429. * otherwise send this command down to firmware
  1430. * immediately.
  1431. */
  1432. if (cmdptr->command !=
  1433. cpu_to_le16(CMD_802_11_PS_MODE)) {
  1434. /* Prepare to send Exit PS,
  1435. * this non PS command will be sent later */
  1436. if ((adapter->psstate == PS_STATE_SLEEP)
  1437. || (adapter->psstate == PS_STATE_PRE_SLEEP)
  1438. ) {
  1439. /* w/ new scheme, it will not reach here.
  1440. since it is blocked in main_thread. */
  1441. adapter->needtowakeup = 1;
  1442. } else
  1443. lbs_ps_wakeup(priv, 0);
  1444. ret = 0;
  1445. goto done;
  1446. } else {
  1447. /*
  1448. * PS command. Ignore it if it is not Exit_PS.
  1449. * otherwise send it down immediately.
  1450. */
  1451. struct cmd_ds_802_11_ps_mode *psm =
  1452. &cmdptr->params.psmode;
  1453. lbs_deb_host(
  1454. "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
  1455. psm->action);
  1456. if (psm->action !=
  1457. cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
  1458. lbs_deb_host(
  1459. "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
  1460. list_del((struct list_head *)cmdnode);
  1461. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1462. ret = 0;
  1463. goto done;
  1464. }
  1465. if ((adapter->psstate == PS_STATE_SLEEP) ||
  1466. (adapter->psstate == PS_STATE_PRE_SLEEP)) {
  1467. lbs_deb_host(
  1468. "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
  1469. list_del((struct list_head *)cmdnode);
  1470. lbs_cleanup_and_insert_cmd(priv, cmdnode);
  1471. adapter->needtowakeup = 1;
  1472. ret = 0;
  1473. goto done;
  1474. }
  1475. lbs_deb_host(
  1476. "EXEC_NEXT_CMD: sending EXIT_PS\n");
  1477. }
  1478. }
  1479. list_del((struct list_head *)cmdnode);
  1480. lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
  1481. le16_to_cpu(cmdptr->command));
  1482. DownloadcommandToStation(priv, cmdnode);
  1483. } else {
  1484. /*
  1485. * check if in power save mode, if yes, put the device back
  1486. * to PS mode
  1487. */
  1488. if ((adapter->psmode != LBS802_11POWERMODECAM) &&
  1489. (adapter->psstate == PS_STATE_FULL_POWER) &&
  1490. ((adapter->connect_status == LBS_CONNECTED) ||
  1491. (adapter->mesh_connect_status == LBS_CONNECTED))) {
  1492. if (adapter->secinfo.WPAenabled ||
  1493. adapter->secinfo.WPA2enabled) {
  1494. /* check for valid WPA group keys */
  1495. if (adapter->wpa_mcast_key.len ||
  1496. adapter->wpa_unicast_key.len) {
  1497. lbs_deb_host(
  1498. "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
  1499. " go back to PS_SLEEP");
  1500. lbs_ps_sleep(priv, 0);
  1501. }
  1502. } else {
  1503. lbs_deb_host(
  1504. "EXEC_NEXT_CMD: cmdpendingq empty, "
  1505. "go back to PS_SLEEP");
  1506. lbs_ps_sleep(priv, 0);
  1507. }
  1508. }
  1509. }
  1510. ret = 0;
  1511. done:
  1512. lbs_deb_leave(LBS_DEB_THREAD);
  1513. return ret;
  1514. }
  1515. void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
  1516. {
  1517. union iwreq_data iwrq;
  1518. u8 buf[50];
  1519. lbs_deb_enter(LBS_DEB_WEXT);
  1520. memset(&iwrq, 0, sizeof(union iwreq_data));
  1521. memset(buf, 0, sizeof(buf));
  1522. snprintf(buf, sizeof(buf) - 1, "%s", str);
  1523. iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
  1524. /* Send Event to upper layer */
  1525. lbs_deb_wext("event indication string %s\n", (char *)buf);
  1526. lbs_deb_wext("event indication length %d\n", iwrq.data.length);
  1527. lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
  1528. wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
  1529. lbs_deb_leave(LBS_DEB_WEXT);
  1530. }
  1531. static int sendconfirmsleep(struct lbs_private *priv, u8 *cmdptr, u16 size)
  1532. {
  1533. unsigned long flags;
  1534. struct lbs_adapter *adapter = priv->adapter;
  1535. int ret = 0;
  1536. lbs_deb_enter(LBS_DEB_HOST);
  1537. lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
  1538. size);
  1539. lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
  1540. ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
  1541. priv->dnld_sent = DNLD_RES_RECEIVED;
  1542. spin_lock_irqsave(&adapter->driver_lock, flags);
  1543. if (adapter->intcounter || adapter->currenttxskb)
  1544. lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
  1545. adapter->intcounter, adapter->currenttxskb);
  1546. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1547. if (ret) {
  1548. lbs_pr_alert(
  1549. "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
  1550. } else {
  1551. spin_lock_irqsave(&adapter->driver_lock, flags);
  1552. if (!adapter->intcounter) {
  1553. adapter->psstate = PS_STATE_SLEEP;
  1554. } else {
  1555. lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
  1556. adapter->intcounter);
  1557. }
  1558. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1559. lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
  1560. }
  1561. lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
  1562. return ret;
  1563. }
  1564. void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
  1565. {
  1566. lbs_deb_enter(LBS_DEB_HOST);
  1567. /*
  1568. * PS is currently supported only in Infrastructure mode
  1569. * Remove this check if it is to be supported in IBSS mode also
  1570. */
  1571. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1572. CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
  1573. lbs_deb_leave(LBS_DEB_HOST);
  1574. }
  1575. /**
  1576. * @brief This function sends Exit_PS command to firmware.
  1577. *
  1578. * @param priv A pointer to struct lbs_private structure
  1579. * @param wait_option wait response or not
  1580. * @return n/a
  1581. */
  1582. void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
  1583. {
  1584. __le32 Localpsmode;
  1585. lbs_deb_enter(LBS_DEB_HOST);
  1586. Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
  1587. lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
  1588. CMD_SUBCMD_EXIT_PS,
  1589. wait_option, 0, &Localpsmode);
  1590. lbs_deb_leave(LBS_DEB_HOST);
  1591. }
  1592. /**
  1593. * @brief This function checks condition and prepares to
  1594. * send sleep confirm command to firmware if ok.
  1595. *
  1596. * @param priv A pointer to struct lbs_private structure
  1597. * @param psmode Power Saving mode
  1598. * @return n/a
  1599. */
  1600. void lbs_ps_confirm_sleep(struct lbs_private *priv, u16 psmode)
  1601. {
  1602. unsigned long flags =0;
  1603. struct lbs_adapter *adapter = priv->adapter;
  1604. u8 allowed = 1;
  1605. lbs_deb_enter(LBS_DEB_HOST);
  1606. if (priv->dnld_sent) {
  1607. allowed = 0;
  1608. lbs_deb_host("dnld_sent was set");
  1609. }
  1610. spin_lock_irqsave(&adapter->driver_lock, flags);
  1611. if (adapter->cur_cmd) {
  1612. allowed = 0;
  1613. lbs_deb_host("cur_cmd was set");
  1614. }
  1615. if (adapter->intcounter > 0) {
  1616. allowed = 0;
  1617. lbs_deb_host("intcounter %d", adapter->intcounter);
  1618. }
  1619. spin_unlock_irqrestore(&adapter->driver_lock, flags);
  1620. if (allowed) {
  1621. lbs_deb_host("sending lbs_ps_confirm_sleep\n");
  1622. sendconfirmsleep(priv, (u8 *) & adapter->lbs_ps_confirm_sleep,
  1623. sizeof(struct PS_CMD_ConfirmSleep));
  1624. } else {
  1625. lbs_deb_host("sleep confirm has been delayed\n");
  1626. }
  1627. lbs_deb_leave(LBS_DEB_HOST);
  1628. }