cmd.c 54 KB

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