sta.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403
  1. /*
  2. * Mac80211 STA API for ST-Ericsson CW1200 drivers
  3. *
  4. * Copyright (c) 2010, ST-Ericsson
  5. * Author: Dmitry Tarnyagin <dmitry.tarnyagin@lockless.no>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/vmalloc.h>
  12. #include <linux/sched.h>
  13. #include <linux/firmware.h>
  14. #include <linux/module.h>
  15. #include <linux/etherdevice.h>
  16. #include "cw1200.h"
  17. #include "sta.h"
  18. #include "fwio.h"
  19. #include "bh.h"
  20. #include "debug.h"
  21. #ifndef ERP_INFO_BYTE_OFFSET
  22. #define ERP_INFO_BYTE_OFFSET 2
  23. #endif
  24. static void cw1200_do_join(struct cw1200_common *priv);
  25. static void cw1200_do_unjoin(struct cw1200_common *priv);
  26. static int cw1200_upload_beacon(struct cw1200_common *priv);
  27. static int cw1200_upload_pspoll(struct cw1200_common *priv);
  28. static int cw1200_upload_null(struct cw1200_common *priv);
  29. static int cw1200_upload_qosnull(struct cw1200_common *priv);
  30. static int cw1200_start_ap(struct cw1200_common *priv);
  31. static int cw1200_update_beaconing(struct cw1200_common *priv);
  32. static int cw1200_enable_beaconing(struct cw1200_common *priv,
  33. bool enable);
  34. static void __cw1200_sta_notify(struct ieee80211_hw *dev,
  35. struct ieee80211_vif *vif,
  36. enum sta_notify_cmd notify_cmd,
  37. int link_id);
  38. static int __cw1200_flush(struct cw1200_common *priv, bool drop);
  39. static inline void __cw1200_free_event_queue(struct list_head *list)
  40. {
  41. struct cw1200_wsm_event *event, *tmp;
  42. list_for_each_entry_safe(event, tmp, list, link) {
  43. list_del(&event->link);
  44. kfree(event);
  45. }
  46. }
  47. /* ******************************************************************** */
  48. /* STA API */
  49. int cw1200_start(struct ieee80211_hw *dev)
  50. {
  51. struct cw1200_common *priv = dev->priv;
  52. int ret = 0;
  53. cw1200_pm_stay_awake(&priv->pm_state, HZ);
  54. mutex_lock(&priv->conf_mutex);
  55. /* default EDCA */
  56. WSM_EDCA_SET(&priv->edca, 0, 0x0002, 0x0003, 0x0007, 47, 0xc8, false);
  57. WSM_EDCA_SET(&priv->edca, 1, 0x0002, 0x0007, 0x000f, 94, 0xc8, false);
  58. WSM_EDCA_SET(&priv->edca, 2, 0x0003, 0x000f, 0x03ff, 0, 0xc8, false);
  59. WSM_EDCA_SET(&priv->edca, 3, 0x0007, 0x000f, 0x03ff, 0, 0xc8, false);
  60. ret = wsm_set_edca_params(priv, &priv->edca);
  61. if (ret)
  62. goto out;
  63. ret = cw1200_set_uapsd_param(priv, &priv->edca);
  64. if (ret)
  65. goto out;
  66. priv->setbssparams_done = false;
  67. memcpy(priv->mac_addr, dev->wiphy->perm_addr, ETH_ALEN);
  68. priv->mode = NL80211_IFTYPE_MONITOR;
  69. priv->wep_default_key_id = -1;
  70. priv->cqm_beacon_loss_count = 10;
  71. ret = cw1200_setup_mac(priv);
  72. if (ret)
  73. goto out;
  74. out:
  75. mutex_unlock(&priv->conf_mutex);
  76. return ret;
  77. }
  78. void cw1200_stop(struct ieee80211_hw *dev)
  79. {
  80. struct cw1200_common *priv = dev->priv;
  81. LIST_HEAD(list);
  82. int i;
  83. wsm_lock_tx(priv);
  84. while (down_trylock(&priv->scan.lock)) {
  85. /* Scan is in progress. Force it to stop. */
  86. priv->scan.req = NULL;
  87. schedule();
  88. }
  89. up(&priv->scan.lock);
  90. cancel_delayed_work_sync(&priv->scan.probe_work);
  91. cancel_delayed_work_sync(&priv->scan.timeout);
  92. cancel_delayed_work_sync(&priv->clear_recent_scan_work);
  93. cancel_delayed_work_sync(&priv->join_timeout);
  94. cw1200_cqm_bssloss_sm(priv, 0, 0, 0);
  95. cancel_work_sync(&priv->unjoin_work);
  96. cancel_delayed_work_sync(&priv->link_id_gc_work);
  97. flush_workqueue(priv->workqueue);
  98. del_timer_sync(&priv->mcast_timeout);
  99. mutex_lock(&priv->conf_mutex);
  100. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  101. priv->listening = false;
  102. spin_lock(&priv->event_queue_lock);
  103. list_splice_init(&priv->event_queue, &list);
  104. spin_unlock(&priv->event_queue_lock);
  105. __cw1200_free_event_queue(&list);
  106. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  107. priv->join_pending = false;
  108. for (i = 0; i < 4; i++)
  109. cw1200_queue_clear(&priv->tx_queue[i]);
  110. mutex_unlock(&priv->conf_mutex);
  111. tx_policy_clean(priv);
  112. /* HACK! */
  113. if (atomic_xchg(&priv->tx_lock, 1) != 1)
  114. pr_debug("[STA] TX is force-unlocked due to stop request.\n");
  115. wsm_unlock_tx(priv);
  116. atomic_xchg(&priv->tx_lock, 0); /* for recovery to work */
  117. }
  118. static int cw1200_bssloss_mitigation = 1;
  119. module_param(cw1200_bssloss_mitigation, int, 0644);
  120. MODULE_PARM_DESC(cw1200_bssloss_mitigation, "BSS Loss mitigation. 0 == disabled, 1 == enabled (default)");
  121. void __cw1200_cqm_bssloss_sm(struct cw1200_common *priv,
  122. int init, int good, int bad)
  123. {
  124. int tx = 0;
  125. priv->delayed_link_loss = 0;
  126. cancel_work_sync(&priv->bss_params_work);
  127. pr_debug("[STA] CQM BSSLOSS_SM: state: %d init %d good %d bad: %d txlock: %d uj: %d\n",
  128. priv->bss_loss_state,
  129. init, good, bad,
  130. atomic_read(&priv->tx_lock),
  131. priv->delayed_unjoin);
  132. /* If we have a pending unjoin */
  133. if (priv->delayed_unjoin)
  134. return;
  135. if (init) {
  136. queue_delayed_work(priv->workqueue,
  137. &priv->bss_loss_work,
  138. HZ);
  139. priv->bss_loss_state = 0;
  140. /* Skip the confimration procedure in P2P case */
  141. if (!priv->vif->p2p && !atomic_read(&priv->tx_lock))
  142. tx = 1;
  143. } else if (good) {
  144. cancel_delayed_work_sync(&priv->bss_loss_work);
  145. priv->bss_loss_state = 0;
  146. queue_work(priv->workqueue, &priv->bss_params_work);
  147. } else if (bad) {
  148. /* XXX Should we just keep going until we time out? */
  149. if (priv->bss_loss_state < 3)
  150. tx = 1;
  151. } else {
  152. cancel_delayed_work_sync(&priv->bss_loss_work);
  153. priv->bss_loss_state = 0;
  154. }
  155. /* Bypass mitigation if it's disabled */
  156. if (!cw1200_bssloss_mitigation)
  157. tx = 0;
  158. /* Spit out a NULL packet to our AP if necessary */
  159. if (tx) {
  160. struct sk_buff *skb;
  161. priv->bss_loss_state++;
  162. skb = ieee80211_nullfunc_get(priv->hw, priv->vif);
  163. WARN_ON(!skb);
  164. if (skb)
  165. cw1200_tx(priv->hw, NULL, skb);
  166. }
  167. }
  168. int cw1200_add_interface(struct ieee80211_hw *dev,
  169. struct ieee80211_vif *vif)
  170. {
  171. int ret;
  172. struct cw1200_common *priv = dev->priv;
  173. /* __le32 auto_calibration_mode = __cpu_to_le32(1); */
  174. vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
  175. IEEE80211_VIF_SUPPORTS_UAPSD |
  176. IEEE80211_VIF_SUPPORTS_CQM_RSSI;
  177. mutex_lock(&priv->conf_mutex);
  178. if (priv->mode != NL80211_IFTYPE_MONITOR) {
  179. mutex_unlock(&priv->conf_mutex);
  180. return -EOPNOTSUPP;
  181. }
  182. switch (vif->type) {
  183. case NL80211_IFTYPE_STATION:
  184. case NL80211_IFTYPE_ADHOC:
  185. case NL80211_IFTYPE_MESH_POINT:
  186. case NL80211_IFTYPE_AP:
  187. priv->mode = vif->type;
  188. break;
  189. default:
  190. mutex_unlock(&priv->conf_mutex);
  191. return -EOPNOTSUPP;
  192. }
  193. priv->vif = vif;
  194. memcpy(priv->mac_addr, vif->addr, ETH_ALEN);
  195. ret = cw1200_setup_mac(priv);
  196. /* Enable auto-calibration */
  197. /* Exception in subsequent channel switch; disabled.
  198. * wsm_write_mib(priv, WSM_MIB_ID_SET_AUTO_CALIBRATION_MODE,
  199. * &auto_calibration_mode, sizeof(auto_calibration_mode));
  200. */
  201. mutex_unlock(&priv->conf_mutex);
  202. return ret;
  203. }
  204. void cw1200_remove_interface(struct ieee80211_hw *dev,
  205. struct ieee80211_vif *vif)
  206. {
  207. struct cw1200_common *priv = dev->priv;
  208. struct wsm_reset reset = {
  209. .reset_statistics = true,
  210. };
  211. int i;
  212. mutex_lock(&priv->conf_mutex);
  213. switch (priv->join_status) {
  214. case CW1200_JOIN_STATUS_JOINING:
  215. case CW1200_JOIN_STATUS_PRE_STA:
  216. case CW1200_JOIN_STATUS_STA:
  217. case CW1200_JOIN_STATUS_IBSS:
  218. wsm_lock_tx(priv);
  219. if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0)
  220. wsm_unlock_tx(priv);
  221. break;
  222. case CW1200_JOIN_STATUS_AP:
  223. for (i = 0; priv->link_id_map; ++i) {
  224. if (priv->link_id_map & BIT(i)) {
  225. reset.link_id = i;
  226. wsm_reset(priv, &reset);
  227. priv->link_id_map &= ~BIT(i);
  228. }
  229. }
  230. memset(priv->link_id_db, 0, sizeof(priv->link_id_db));
  231. priv->sta_asleep_mask = 0;
  232. priv->enable_beacon = false;
  233. priv->tx_multicast = false;
  234. priv->aid0_bit_set = false;
  235. priv->buffered_multicasts = false;
  236. priv->pspoll_mask = 0;
  237. reset.link_id = 0;
  238. wsm_reset(priv, &reset);
  239. break;
  240. case CW1200_JOIN_STATUS_MONITOR:
  241. cw1200_update_listening(priv, false);
  242. break;
  243. default:
  244. break;
  245. }
  246. priv->vif = NULL;
  247. priv->mode = NL80211_IFTYPE_MONITOR;
  248. eth_zero_addr(priv->mac_addr);
  249. memset(&priv->p2p_ps_modeinfo, 0, sizeof(priv->p2p_ps_modeinfo));
  250. cw1200_free_keys(priv);
  251. cw1200_setup_mac(priv);
  252. priv->listening = false;
  253. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  254. if (!__cw1200_flush(priv, true))
  255. wsm_unlock_tx(priv);
  256. mutex_unlock(&priv->conf_mutex);
  257. }
  258. int cw1200_change_interface(struct ieee80211_hw *dev,
  259. struct ieee80211_vif *vif,
  260. enum nl80211_iftype new_type,
  261. bool p2p)
  262. {
  263. int ret = 0;
  264. pr_debug("change_interface new: %d (%d), old: %d (%d)\n", new_type,
  265. p2p, vif->type, vif->p2p);
  266. if (new_type != vif->type || vif->p2p != p2p) {
  267. cw1200_remove_interface(dev, vif);
  268. vif->type = new_type;
  269. vif->p2p = p2p;
  270. ret = cw1200_add_interface(dev, vif);
  271. }
  272. return ret;
  273. }
  274. int cw1200_config(struct ieee80211_hw *dev, u32 changed)
  275. {
  276. int ret = 0;
  277. struct cw1200_common *priv = dev->priv;
  278. struct ieee80211_conf *conf = &dev->conf;
  279. pr_debug("CONFIG CHANGED: %08x\n", changed);
  280. down(&priv->scan.lock);
  281. mutex_lock(&priv->conf_mutex);
  282. /* TODO: IEEE80211_CONF_CHANGE_QOS */
  283. /* TODO: IEEE80211_CONF_CHANGE_LISTEN_INTERVAL */
  284. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  285. priv->output_power = conf->power_level;
  286. pr_debug("[STA] TX power: %d\n", priv->output_power);
  287. wsm_set_output_power(priv, priv->output_power * 10);
  288. }
  289. if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) &&
  290. (priv->channel != conf->chandef.chan)) {
  291. struct ieee80211_channel *ch = conf->chandef.chan;
  292. struct wsm_switch_channel channel = {
  293. .channel_number = ch->hw_value,
  294. };
  295. pr_debug("[STA] Freq %d (wsm ch: %d).\n",
  296. ch->center_freq, ch->hw_value);
  297. /* __cw1200_flush() implicitly locks tx, if successful */
  298. if (!__cw1200_flush(priv, false)) {
  299. if (!wsm_switch_channel(priv, &channel)) {
  300. ret = wait_event_timeout(priv->channel_switch_done,
  301. !priv->channel_switch_in_progress,
  302. 3 * HZ);
  303. if (ret) {
  304. /* Already unlocks if successful */
  305. priv->channel = ch;
  306. ret = 0;
  307. } else {
  308. ret = -ETIMEDOUT;
  309. }
  310. } else {
  311. /* Unlock if switch channel fails */
  312. wsm_unlock_tx(priv);
  313. }
  314. }
  315. }
  316. if (changed & IEEE80211_CONF_CHANGE_PS) {
  317. if (!(conf->flags & IEEE80211_CONF_PS))
  318. priv->powersave_mode.mode = WSM_PSM_ACTIVE;
  319. else if (conf->dynamic_ps_timeout <= 0)
  320. priv->powersave_mode.mode = WSM_PSM_PS;
  321. else
  322. priv->powersave_mode.mode = WSM_PSM_FAST_PS;
  323. /* Firmware requires that value for this 1-byte field must
  324. * be specified in units of 500us. Values above the 128ms
  325. * threshold are not supported.
  326. */
  327. if (conf->dynamic_ps_timeout >= 0x80)
  328. priv->powersave_mode.fast_psm_idle_period = 0xFF;
  329. else
  330. priv->powersave_mode.fast_psm_idle_period =
  331. conf->dynamic_ps_timeout << 1;
  332. if (priv->join_status == CW1200_JOIN_STATUS_STA &&
  333. priv->bss_params.aid)
  334. cw1200_set_pm(priv, &priv->powersave_mode);
  335. }
  336. if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
  337. /* TBD: It looks like it's transparent
  338. * there's a monitor interface present -- use this
  339. * to determine for example whether to calculate
  340. * timestamps for packets or not, do not use instead
  341. * of filter flags!
  342. */
  343. }
  344. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  345. struct wsm_operational_mode mode = {
  346. .power_mode = cw1200_power_mode,
  347. .disable_more_flag_usage = true,
  348. };
  349. wsm_lock_tx(priv);
  350. /* Disable p2p-dev mode forced by TX request */
  351. if ((priv->join_status == CW1200_JOIN_STATUS_MONITOR) &&
  352. (conf->flags & IEEE80211_CONF_IDLE) &&
  353. !priv->listening) {
  354. cw1200_disable_listening(priv);
  355. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  356. }
  357. wsm_set_operational_mode(priv, &mode);
  358. wsm_unlock_tx(priv);
  359. }
  360. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
  361. pr_debug("[STA] Retry limits: %d (long), %d (short).\n",
  362. conf->long_frame_max_tx_count,
  363. conf->short_frame_max_tx_count);
  364. spin_lock_bh(&priv->tx_policy_cache.lock);
  365. priv->long_frame_max_tx_count = conf->long_frame_max_tx_count;
  366. priv->short_frame_max_tx_count =
  367. (conf->short_frame_max_tx_count < 0x0F) ?
  368. conf->short_frame_max_tx_count : 0x0F;
  369. priv->hw->max_rate_tries = priv->short_frame_max_tx_count;
  370. spin_unlock_bh(&priv->tx_policy_cache.lock);
  371. }
  372. mutex_unlock(&priv->conf_mutex);
  373. up(&priv->scan.lock);
  374. return ret;
  375. }
  376. void cw1200_update_filtering(struct cw1200_common *priv)
  377. {
  378. int ret;
  379. bool bssid_filtering = !priv->rx_filter.bssid;
  380. bool is_p2p = priv->vif && priv->vif->p2p;
  381. bool is_sta = priv->vif && NL80211_IFTYPE_STATION == priv->vif->type;
  382. static struct wsm_beacon_filter_control bf_ctrl;
  383. static struct wsm_mib_beacon_filter_table bf_tbl = {
  384. .entry[0].ie_id = WLAN_EID_VENDOR_SPECIFIC,
  385. .entry[0].flags = WSM_BEACON_FILTER_IE_HAS_CHANGED |
  386. WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
  387. WSM_BEACON_FILTER_IE_HAS_APPEARED,
  388. .entry[0].oui[0] = 0x50,
  389. .entry[0].oui[1] = 0x6F,
  390. .entry[0].oui[2] = 0x9A,
  391. .entry[1].ie_id = WLAN_EID_HT_OPERATION,
  392. .entry[1].flags = WSM_BEACON_FILTER_IE_HAS_CHANGED |
  393. WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
  394. WSM_BEACON_FILTER_IE_HAS_APPEARED,
  395. .entry[2].ie_id = WLAN_EID_ERP_INFO,
  396. .entry[2].flags = WSM_BEACON_FILTER_IE_HAS_CHANGED |
  397. WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT |
  398. WSM_BEACON_FILTER_IE_HAS_APPEARED,
  399. };
  400. if (priv->join_status == CW1200_JOIN_STATUS_PASSIVE)
  401. return;
  402. else if (priv->join_status == CW1200_JOIN_STATUS_MONITOR)
  403. bssid_filtering = false;
  404. if (priv->disable_beacon_filter) {
  405. bf_ctrl.enabled = 0;
  406. bf_ctrl.bcn_count = 1;
  407. bf_tbl.num = __cpu_to_le32(0);
  408. } else if (is_p2p || !is_sta) {
  409. bf_ctrl.enabled = WSM_BEACON_FILTER_ENABLE |
  410. WSM_BEACON_FILTER_AUTO_ERP;
  411. bf_ctrl.bcn_count = 0;
  412. bf_tbl.num = __cpu_to_le32(2);
  413. } else {
  414. bf_ctrl.enabled = WSM_BEACON_FILTER_ENABLE;
  415. bf_ctrl.bcn_count = 0;
  416. bf_tbl.num = __cpu_to_le32(3);
  417. }
  418. /* When acting as p2p client being connected to p2p GO, in order to
  419. * receive frames from a different p2p device, turn off bssid filter.
  420. *
  421. * WARNING: FW dependency!
  422. * This can only be used with FW WSM371 and its successors.
  423. * In that FW version even with bssid filter turned off,
  424. * device will block most of the unwanted frames.
  425. */
  426. if (is_p2p)
  427. bssid_filtering = false;
  428. ret = wsm_set_rx_filter(priv, &priv->rx_filter);
  429. if (!ret)
  430. ret = wsm_set_beacon_filter_table(priv, &bf_tbl);
  431. if (!ret)
  432. ret = wsm_beacon_filter_control(priv, &bf_ctrl);
  433. if (!ret)
  434. ret = wsm_set_bssid_filtering(priv, bssid_filtering);
  435. if (!ret)
  436. ret = wsm_set_multicast_filter(priv, &priv->multicast_filter);
  437. if (ret)
  438. wiphy_err(priv->hw->wiphy,
  439. "Update filtering failed: %d.\n", ret);
  440. return;
  441. }
  442. void cw1200_update_filtering_work(struct work_struct *work)
  443. {
  444. struct cw1200_common *priv =
  445. container_of(work, struct cw1200_common,
  446. update_filtering_work);
  447. cw1200_update_filtering(priv);
  448. }
  449. void cw1200_set_beacon_wakeup_period_work(struct work_struct *work)
  450. {
  451. struct cw1200_common *priv =
  452. container_of(work, struct cw1200_common,
  453. set_beacon_wakeup_period_work);
  454. wsm_set_beacon_wakeup_period(priv,
  455. priv->beacon_int * priv->join_dtim_period >
  456. MAX_BEACON_SKIP_TIME_MS ? 1 :
  457. priv->join_dtim_period, 0);
  458. }
  459. u64 cw1200_prepare_multicast(struct ieee80211_hw *hw,
  460. struct netdev_hw_addr_list *mc_list)
  461. {
  462. static u8 broadcast_ipv6[ETH_ALEN] = {
  463. 0x33, 0x33, 0x00, 0x00, 0x00, 0x01
  464. };
  465. static u8 broadcast_ipv4[ETH_ALEN] = {
  466. 0x01, 0x00, 0x5e, 0x00, 0x00, 0x01
  467. };
  468. struct cw1200_common *priv = hw->priv;
  469. struct netdev_hw_addr *ha;
  470. int count = 0;
  471. /* Disable multicast filtering */
  472. priv->has_multicast_subscription = false;
  473. memset(&priv->multicast_filter, 0x00, sizeof(priv->multicast_filter));
  474. if (netdev_hw_addr_list_count(mc_list) > WSM_MAX_GRP_ADDRTABLE_ENTRIES)
  475. return 0;
  476. /* Enable if requested */
  477. netdev_hw_addr_list_for_each(ha, mc_list) {
  478. pr_debug("[STA] multicast: %pM\n", ha->addr);
  479. memcpy(&priv->multicast_filter.macaddrs[count],
  480. ha->addr, ETH_ALEN);
  481. if (!ether_addr_equal(ha->addr, broadcast_ipv4) &&
  482. !ether_addr_equal(ha->addr, broadcast_ipv6))
  483. priv->has_multicast_subscription = true;
  484. count++;
  485. }
  486. if (count) {
  487. priv->multicast_filter.enable = __cpu_to_le32(1);
  488. priv->multicast_filter.num_addrs = __cpu_to_le32(count);
  489. }
  490. return netdev_hw_addr_list_count(mc_list);
  491. }
  492. void cw1200_configure_filter(struct ieee80211_hw *dev,
  493. unsigned int changed_flags,
  494. unsigned int *total_flags,
  495. u64 multicast)
  496. {
  497. struct cw1200_common *priv = dev->priv;
  498. bool listening = !!(*total_flags &
  499. (FIF_PROMISC_IN_BSS |
  500. FIF_OTHER_BSS |
  501. FIF_BCN_PRBRESP_PROMISC |
  502. FIF_PROBE_REQ));
  503. *total_flags &= FIF_PROMISC_IN_BSS |
  504. FIF_OTHER_BSS |
  505. FIF_FCSFAIL |
  506. FIF_BCN_PRBRESP_PROMISC |
  507. FIF_PROBE_REQ;
  508. down(&priv->scan.lock);
  509. mutex_lock(&priv->conf_mutex);
  510. priv->rx_filter.promiscuous = (*total_flags & FIF_PROMISC_IN_BSS)
  511. ? 1 : 0;
  512. priv->rx_filter.bssid = (*total_flags & (FIF_OTHER_BSS |
  513. FIF_PROBE_REQ)) ? 1 : 0;
  514. priv->rx_filter.fcs = (*total_flags & FIF_FCSFAIL) ? 1 : 0;
  515. priv->disable_beacon_filter = !(*total_flags &
  516. (FIF_BCN_PRBRESP_PROMISC |
  517. FIF_PROMISC_IN_BSS |
  518. FIF_PROBE_REQ));
  519. if (priv->listening != listening) {
  520. priv->listening = listening;
  521. wsm_lock_tx(priv);
  522. cw1200_update_listening(priv, listening);
  523. wsm_unlock_tx(priv);
  524. }
  525. cw1200_update_filtering(priv);
  526. mutex_unlock(&priv->conf_mutex);
  527. up(&priv->scan.lock);
  528. }
  529. int cw1200_conf_tx(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
  530. u16 queue, const struct ieee80211_tx_queue_params *params)
  531. {
  532. struct cw1200_common *priv = dev->priv;
  533. int ret = 0;
  534. /* To prevent re-applying PM request OID again and again*/
  535. bool old_uapsd_flags;
  536. mutex_lock(&priv->conf_mutex);
  537. if (queue < dev->queues) {
  538. old_uapsd_flags = le16_to_cpu(priv->uapsd_info.uapsd_flags);
  539. WSM_TX_QUEUE_SET(&priv->tx_queue_params, queue, 0, 0, 0);
  540. ret = wsm_set_tx_queue_params(priv,
  541. &priv->tx_queue_params.params[queue], queue);
  542. if (ret) {
  543. ret = -EINVAL;
  544. goto out;
  545. }
  546. WSM_EDCA_SET(&priv->edca, queue, params->aifs,
  547. params->cw_min, params->cw_max,
  548. params->txop, 0xc8,
  549. params->uapsd);
  550. ret = wsm_set_edca_params(priv, &priv->edca);
  551. if (ret) {
  552. ret = -EINVAL;
  553. goto out;
  554. }
  555. if (priv->mode == NL80211_IFTYPE_STATION) {
  556. ret = cw1200_set_uapsd_param(priv, &priv->edca);
  557. if (!ret && priv->setbssparams_done &&
  558. (priv->join_status == CW1200_JOIN_STATUS_STA) &&
  559. (old_uapsd_flags != le16_to_cpu(priv->uapsd_info.uapsd_flags)))
  560. ret = cw1200_set_pm(priv, &priv->powersave_mode);
  561. }
  562. } else {
  563. ret = -EINVAL;
  564. }
  565. out:
  566. mutex_unlock(&priv->conf_mutex);
  567. return ret;
  568. }
  569. int cw1200_get_stats(struct ieee80211_hw *dev,
  570. struct ieee80211_low_level_stats *stats)
  571. {
  572. struct cw1200_common *priv = dev->priv;
  573. memcpy(stats, &priv->stats, sizeof(*stats));
  574. return 0;
  575. }
  576. int cw1200_set_pm(struct cw1200_common *priv, const struct wsm_set_pm *arg)
  577. {
  578. struct wsm_set_pm pm = *arg;
  579. if (priv->uapsd_info.uapsd_flags != 0)
  580. pm.mode &= ~WSM_PSM_FAST_PS_FLAG;
  581. if (memcmp(&pm, &priv->firmware_ps_mode,
  582. sizeof(struct wsm_set_pm))) {
  583. priv->firmware_ps_mode = pm;
  584. return wsm_set_pm(priv, &pm);
  585. } else {
  586. return 0;
  587. }
  588. }
  589. int cw1200_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
  590. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  591. struct ieee80211_key_conf *key)
  592. {
  593. int ret = -EOPNOTSUPP;
  594. struct cw1200_common *priv = dev->priv;
  595. struct ieee80211_key_seq seq;
  596. mutex_lock(&priv->conf_mutex);
  597. if (cmd == SET_KEY) {
  598. u8 *peer_addr = NULL;
  599. int pairwise = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) ?
  600. 1 : 0;
  601. int idx = cw1200_alloc_key(priv);
  602. struct wsm_add_key *wsm_key = &priv->keys[idx];
  603. if (idx < 0) {
  604. ret = -EINVAL;
  605. goto finally;
  606. }
  607. if (sta)
  608. peer_addr = sta->addr;
  609. key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE |
  610. IEEE80211_KEY_FLAG_RESERVE_TAILROOM;
  611. switch (key->cipher) {
  612. case WLAN_CIPHER_SUITE_WEP40:
  613. case WLAN_CIPHER_SUITE_WEP104:
  614. if (key->keylen > 16) {
  615. cw1200_free_key(priv, idx);
  616. ret = -EINVAL;
  617. goto finally;
  618. }
  619. if (pairwise) {
  620. wsm_key->type = WSM_KEY_TYPE_WEP_PAIRWISE;
  621. memcpy(wsm_key->wep_pairwise.peer,
  622. peer_addr, ETH_ALEN);
  623. memcpy(wsm_key->wep_pairwise.keydata,
  624. &key->key[0], key->keylen);
  625. wsm_key->wep_pairwise.keylen = key->keylen;
  626. } else {
  627. wsm_key->type = WSM_KEY_TYPE_WEP_DEFAULT;
  628. memcpy(wsm_key->wep_group.keydata,
  629. &key->key[0], key->keylen);
  630. wsm_key->wep_group.keylen = key->keylen;
  631. wsm_key->wep_group.keyid = key->keyidx;
  632. }
  633. break;
  634. case WLAN_CIPHER_SUITE_TKIP:
  635. ieee80211_get_key_rx_seq(key, 0, &seq);
  636. if (pairwise) {
  637. wsm_key->type = WSM_KEY_TYPE_TKIP_PAIRWISE;
  638. memcpy(wsm_key->tkip_pairwise.peer,
  639. peer_addr, ETH_ALEN);
  640. memcpy(wsm_key->tkip_pairwise.keydata,
  641. &key->key[0], 16);
  642. memcpy(wsm_key->tkip_pairwise.tx_mic_key,
  643. &key->key[16], 8);
  644. memcpy(wsm_key->tkip_pairwise.rx_mic_key,
  645. &key->key[24], 8);
  646. } else {
  647. size_t mic_offset =
  648. (priv->mode == NL80211_IFTYPE_AP) ?
  649. 16 : 24;
  650. wsm_key->type = WSM_KEY_TYPE_TKIP_GROUP;
  651. memcpy(wsm_key->tkip_group.keydata,
  652. &key->key[0], 16);
  653. memcpy(wsm_key->tkip_group.rx_mic_key,
  654. &key->key[mic_offset], 8);
  655. wsm_key->tkip_group.rx_seqnum[0] = seq.tkip.iv16 & 0xff;
  656. wsm_key->tkip_group.rx_seqnum[1] = (seq.tkip.iv16 >> 8) & 0xff;
  657. wsm_key->tkip_group.rx_seqnum[2] = seq.tkip.iv32 & 0xff;
  658. wsm_key->tkip_group.rx_seqnum[3] = (seq.tkip.iv32 >> 8) & 0xff;
  659. wsm_key->tkip_group.rx_seqnum[4] = (seq.tkip.iv32 >> 16) & 0xff;
  660. wsm_key->tkip_group.rx_seqnum[5] = (seq.tkip.iv32 >> 24) & 0xff;
  661. wsm_key->tkip_group.rx_seqnum[6] = 0;
  662. wsm_key->tkip_group.rx_seqnum[7] = 0;
  663. wsm_key->tkip_group.keyid = key->keyidx;
  664. }
  665. break;
  666. case WLAN_CIPHER_SUITE_CCMP:
  667. ieee80211_get_key_rx_seq(key, 0, &seq);
  668. if (pairwise) {
  669. wsm_key->type = WSM_KEY_TYPE_AES_PAIRWISE;
  670. memcpy(wsm_key->aes_pairwise.peer,
  671. peer_addr, ETH_ALEN);
  672. memcpy(wsm_key->aes_pairwise.keydata,
  673. &key->key[0], 16);
  674. } else {
  675. wsm_key->type = WSM_KEY_TYPE_AES_GROUP;
  676. memcpy(wsm_key->aes_group.keydata,
  677. &key->key[0], 16);
  678. wsm_key->aes_group.rx_seqnum[0] = seq.ccmp.pn[5];
  679. wsm_key->aes_group.rx_seqnum[1] = seq.ccmp.pn[4];
  680. wsm_key->aes_group.rx_seqnum[2] = seq.ccmp.pn[3];
  681. wsm_key->aes_group.rx_seqnum[3] = seq.ccmp.pn[2];
  682. wsm_key->aes_group.rx_seqnum[4] = seq.ccmp.pn[1];
  683. wsm_key->aes_group.rx_seqnum[5] = seq.ccmp.pn[0];
  684. wsm_key->aes_group.rx_seqnum[6] = 0;
  685. wsm_key->aes_group.rx_seqnum[7] = 0;
  686. wsm_key->aes_group.keyid = key->keyidx;
  687. }
  688. break;
  689. case WLAN_CIPHER_SUITE_SMS4:
  690. if (pairwise) {
  691. wsm_key->type = WSM_KEY_TYPE_WAPI_PAIRWISE;
  692. memcpy(wsm_key->wapi_pairwise.peer,
  693. peer_addr, ETH_ALEN);
  694. memcpy(wsm_key->wapi_pairwise.keydata,
  695. &key->key[0], 16);
  696. memcpy(wsm_key->wapi_pairwise.mic_key,
  697. &key->key[16], 16);
  698. wsm_key->wapi_pairwise.keyid = key->keyidx;
  699. } else {
  700. wsm_key->type = WSM_KEY_TYPE_WAPI_GROUP;
  701. memcpy(wsm_key->wapi_group.keydata,
  702. &key->key[0], 16);
  703. memcpy(wsm_key->wapi_group.mic_key,
  704. &key->key[16], 16);
  705. wsm_key->wapi_group.keyid = key->keyidx;
  706. }
  707. break;
  708. default:
  709. pr_warn("Unhandled key type %d\n", key->cipher);
  710. cw1200_free_key(priv, idx);
  711. ret = -EOPNOTSUPP;
  712. goto finally;
  713. }
  714. ret = wsm_add_key(priv, wsm_key);
  715. if (!ret)
  716. key->hw_key_idx = idx;
  717. else
  718. cw1200_free_key(priv, idx);
  719. } else if (cmd == DISABLE_KEY) {
  720. struct wsm_remove_key wsm_key = {
  721. .index = key->hw_key_idx,
  722. };
  723. if (wsm_key.index > WSM_KEY_MAX_INDEX) {
  724. ret = -EINVAL;
  725. goto finally;
  726. }
  727. cw1200_free_key(priv, wsm_key.index);
  728. ret = wsm_remove_key(priv, &wsm_key);
  729. } else {
  730. pr_warn("Unhandled key command %d\n", cmd);
  731. }
  732. finally:
  733. mutex_unlock(&priv->conf_mutex);
  734. return ret;
  735. }
  736. void cw1200_wep_key_work(struct work_struct *work)
  737. {
  738. struct cw1200_common *priv =
  739. container_of(work, struct cw1200_common, wep_key_work);
  740. u8 queue_id = cw1200_queue_get_queue_id(priv->pending_frame_id);
  741. struct cw1200_queue *queue = &priv->tx_queue[queue_id];
  742. __le32 wep_default_key_id = __cpu_to_le32(
  743. priv->wep_default_key_id);
  744. pr_debug("[STA] Setting default WEP key: %d\n",
  745. priv->wep_default_key_id);
  746. wsm_flush_tx(priv);
  747. wsm_write_mib(priv, WSM_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID,
  748. &wep_default_key_id, sizeof(wep_default_key_id));
  749. cw1200_queue_requeue(queue, priv->pending_frame_id);
  750. wsm_unlock_tx(priv);
  751. }
  752. int cw1200_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  753. {
  754. int ret = 0;
  755. __le32 val32;
  756. struct cw1200_common *priv = hw->priv;
  757. if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
  758. return 0;
  759. if (value != (u32) -1)
  760. val32 = __cpu_to_le32(value);
  761. else
  762. val32 = 0; /* disabled */
  763. if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) {
  764. /* device is down, can _not_ set threshold */
  765. ret = -ENODEV;
  766. goto out;
  767. }
  768. if (priv->rts_threshold == value)
  769. goto out;
  770. pr_debug("[STA] Setting RTS threshold: %d\n",
  771. priv->rts_threshold);
  772. /* mutex_lock(&priv->conf_mutex); */
  773. ret = wsm_write_mib(priv, WSM_MIB_ID_DOT11_RTS_THRESHOLD,
  774. &val32, sizeof(val32));
  775. if (!ret)
  776. priv->rts_threshold = value;
  777. /* mutex_unlock(&priv->conf_mutex); */
  778. out:
  779. return ret;
  780. }
  781. /* If successful, LOCKS the TX queue! */
  782. static int __cw1200_flush(struct cw1200_common *priv, bool drop)
  783. {
  784. int i, ret;
  785. for (;;) {
  786. /* TODO: correct flush handling is required when dev_stop.
  787. * Temporary workaround: 2s
  788. */
  789. if (drop) {
  790. for (i = 0; i < 4; ++i)
  791. cw1200_queue_clear(&priv->tx_queue[i]);
  792. } else {
  793. ret = wait_event_timeout(
  794. priv->tx_queue_stats.wait_link_id_empty,
  795. cw1200_queue_stats_is_empty(
  796. &priv->tx_queue_stats, -1),
  797. 2 * HZ);
  798. }
  799. if (!drop && ret <= 0) {
  800. ret = -ETIMEDOUT;
  801. break;
  802. } else {
  803. ret = 0;
  804. }
  805. wsm_lock_tx(priv);
  806. if (!cw1200_queue_stats_is_empty(&priv->tx_queue_stats, -1)) {
  807. /* Highly unlikely: WSM requeued frames. */
  808. wsm_unlock_tx(priv);
  809. continue;
  810. }
  811. break;
  812. }
  813. return ret;
  814. }
  815. void cw1200_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  816. u32 queues, bool drop)
  817. {
  818. struct cw1200_common *priv = hw->priv;
  819. switch (priv->mode) {
  820. case NL80211_IFTYPE_MONITOR:
  821. drop = true;
  822. break;
  823. case NL80211_IFTYPE_AP:
  824. if (!priv->enable_beacon)
  825. drop = true;
  826. break;
  827. }
  828. if (!__cw1200_flush(priv, drop))
  829. wsm_unlock_tx(priv);
  830. return;
  831. }
  832. /* ******************************************************************** */
  833. /* WSM callbacks */
  834. void cw1200_free_event_queue(struct cw1200_common *priv)
  835. {
  836. LIST_HEAD(list);
  837. spin_lock(&priv->event_queue_lock);
  838. list_splice_init(&priv->event_queue, &list);
  839. spin_unlock(&priv->event_queue_lock);
  840. __cw1200_free_event_queue(&list);
  841. }
  842. void cw1200_event_handler(struct work_struct *work)
  843. {
  844. struct cw1200_common *priv =
  845. container_of(work, struct cw1200_common, event_handler);
  846. struct cw1200_wsm_event *event;
  847. LIST_HEAD(list);
  848. spin_lock(&priv->event_queue_lock);
  849. list_splice_init(&priv->event_queue, &list);
  850. spin_unlock(&priv->event_queue_lock);
  851. list_for_each_entry(event, &list, link) {
  852. switch (event->evt.id) {
  853. case WSM_EVENT_ERROR:
  854. pr_err("Unhandled WSM Error from LMAC\n");
  855. break;
  856. case WSM_EVENT_BSS_LOST:
  857. pr_debug("[CQM] BSS lost.\n");
  858. cancel_work_sync(&priv->unjoin_work);
  859. if (!down_trylock(&priv->scan.lock)) {
  860. cw1200_cqm_bssloss_sm(priv, 1, 0, 0);
  861. up(&priv->scan.lock);
  862. } else {
  863. /* Scan is in progress. Delay reporting.
  864. * Scan complete will trigger bss_loss_work
  865. */
  866. priv->delayed_link_loss = 1;
  867. /* Also start a watchdog. */
  868. queue_delayed_work(priv->workqueue,
  869. &priv->bss_loss_work, 5*HZ);
  870. }
  871. break;
  872. case WSM_EVENT_BSS_REGAINED:
  873. pr_debug("[CQM] BSS regained.\n");
  874. cw1200_cqm_bssloss_sm(priv, 0, 0, 0);
  875. cancel_work_sync(&priv->unjoin_work);
  876. break;
  877. case WSM_EVENT_RADAR_DETECTED:
  878. wiphy_info(priv->hw->wiphy, "radar pulse detected\n");
  879. break;
  880. case WSM_EVENT_RCPI_RSSI:
  881. {
  882. /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
  883. * RSSI = RCPI / 2 - 110
  884. */
  885. int rcpi_rssi = (int)(event->evt.data & 0xFF);
  886. int cqm_evt;
  887. if (priv->cqm_use_rssi)
  888. rcpi_rssi = (s8)rcpi_rssi;
  889. else
  890. rcpi_rssi = rcpi_rssi / 2 - 110;
  891. cqm_evt = (rcpi_rssi <= priv->cqm_rssi_thold) ?
  892. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW :
  893. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  894. pr_debug("[CQM] RSSI event: %d.\n", rcpi_rssi);
  895. ieee80211_cqm_rssi_notify(priv->vif, cqm_evt,
  896. GFP_KERNEL);
  897. break;
  898. }
  899. case WSM_EVENT_BT_INACTIVE:
  900. pr_warn("Unhandled BT INACTIVE from LMAC\n");
  901. break;
  902. case WSM_EVENT_BT_ACTIVE:
  903. pr_warn("Unhandled BT ACTIVE from LMAC\n");
  904. break;
  905. }
  906. }
  907. __cw1200_free_event_queue(&list);
  908. }
  909. void cw1200_bss_loss_work(struct work_struct *work)
  910. {
  911. struct cw1200_common *priv =
  912. container_of(work, struct cw1200_common, bss_loss_work.work);
  913. pr_debug("[CQM] Reporting connection loss.\n");
  914. wsm_lock_tx(priv);
  915. if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0)
  916. wsm_unlock_tx(priv);
  917. }
  918. void cw1200_bss_params_work(struct work_struct *work)
  919. {
  920. struct cw1200_common *priv =
  921. container_of(work, struct cw1200_common, bss_params_work);
  922. mutex_lock(&priv->conf_mutex);
  923. priv->bss_params.reset_beacon_loss = 1;
  924. wsm_set_bss_params(priv, &priv->bss_params);
  925. priv->bss_params.reset_beacon_loss = 0;
  926. mutex_unlock(&priv->conf_mutex);
  927. }
  928. /* ******************************************************************** */
  929. /* Internal API */
  930. /* This function is called to Parse the SDD file
  931. * to extract listen_interval and PTA related information
  932. * sdd is a TLV: u8 id, u8 len, u8 data[]
  933. */
  934. static int cw1200_parse_sdd_file(struct cw1200_common *priv)
  935. {
  936. const u8 *p = priv->sdd->data;
  937. int ret = 0;
  938. while (p + 2 <= priv->sdd->data + priv->sdd->size) {
  939. if (p + p[1] + 2 > priv->sdd->data + priv->sdd->size) {
  940. pr_warn("Malformed sdd structure\n");
  941. return -1;
  942. }
  943. switch (p[0]) {
  944. case SDD_PTA_CFG_ELT_ID: {
  945. u16 v;
  946. if (p[1] < 4) {
  947. pr_warn("SDD_PTA_CFG_ELT_ID malformed\n");
  948. ret = -1;
  949. break;
  950. }
  951. v = le16_to_cpu(*((__le16 *)(p + 2)));
  952. if (!v) /* non-zero means this is enabled */
  953. break;
  954. v = le16_to_cpu(*((__le16 *)(p + 4)));
  955. priv->conf_listen_interval = (v >> 7) & 0x1F;
  956. pr_debug("PTA found; Listen Interval %d\n",
  957. priv->conf_listen_interval);
  958. break;
  959. }
  960. case SDD_REFERENCE_FREQUENCY_ELT_ID: {
  961. u16 clk = le16_to_cpu(*((__le16 *)(p + 2)));
  962. if (clk != priv->hw_refclk)
  963. pr_warn("SDD file doesn't match configured refclk (%d vs %d)\n",
  964. clk, priv->hw_refclk);
  965. break;
  966. }
  967. default:
  968. break;
  969. }
  970. p += p[1] + 2;
  971. }
  972. if (!priv->bt_present) {
  973. pr_debug("PTA element NOT found.\n");
  974. priv->conf_listen_interval = 0;
  975. }
  976. return ret;
  977. }
  978. int cw1200_setup_mac(struct cw1200_common *priv)
  979. {
  980. int ret = 0;
  981. /* NOTE: There is a bug in FW: it reports signal
  982. * as RSSI if RSSI subscription is enabled.
  983. * It's not enough to set WSM_RCPI_RSSI_USE_RSSI.
  984. *
  985. * NOTE2: RSSI based reports have been switched to RCPI, since
  986. * FW has a bug and RSSI reported values are not stable,
  987. * what can leads to signal level oscilations in user-end applications
  988. */
  989. struct wsm_rcpi_rssi_threshold threshold = {
  990. .rssiRcpiMode = WSM_RCPI_RSSI_THRESHOLD_ENABLE |
  991. WSM_RCPI_RSSI_DONT_USE_UPPER |
  992. WSM_RCPI_RSSI_DONT_USE_LOWER,
  993. .rollingAverageCount = 16,
  994. };
  995. struct wsm_configuration cfg = {
  996. .dot11StationId = &priv->mac_addr[0],
  997. };
  998. /* Remember the decission here to make sure, we will handle
  999. * the RCPI/RSSI value correctly on WSM_EVENT_RCPI_RSS
  1000. */
  1001. if (threshold.rssiRcpiMode & WSM_RCPI_RSSI_USE_RSSI)
  1002. priv->cqm_use_rssi = true;
  1003. if (!priv->sdd) {
  1004. ret = request_firmware(&priv->sdd, priv->sdd_path, priv->pdev);
  1005. if (ret) {
  1006. pr_err("Can't load sdd file %s.\n", priv->sdd_path);
  1007. return ret;
  1008. }
  1009. cw1200_parse_sdd_file(priv);
  1010. }
  1011. cfg.dpdData = priv->sdd->data;
  1012. cfg.dpdData_size = priv->sdd->size;
  1013. ret = wsm_configuration(priv, &cfg);
  1014. if (ret)
  1015. return ret;
  1016. /* Configure RSSI/SCPI reporting as RSSI. */
  1017. wsm_set_rcpi_rssi_threshold(priv, &threshold);
  1018. return 0;
  1019. }
  1020. static void cw1200_join_complete(struct cw1200_common *priv)
  1021. {
  1022. pr_debug("[STA] Join complete (%d)\n", priv->join_complete_status);
  1023. priv->join_pending = false;
  1024. if (priv->join_complete_status) {
  1025. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  1026. cw1200_update_listening(priv, priv->listening);
  1027. cw1200_do_unjoin(priv);
  1028. ieee80211_connection_loss(priv->vif);
  1029. } else {
  1030. if (priv->mode == NL80211_IFTYPE_ADHOC)
  1031. priv->join_status = CW1200_JOIN_STATUS_IBSS;
  1032. else
  1033. priv->join_status = CW1200_JOIN_STATUS_PRE_STA;
  1034. }
  1035. wsm_unlock_tx(priv); /* Clearing the lock held before do_join() */
  1036. }
  1037. void cw1200_join_complete_work(struct work_struct *work)
  1038. {
  1039. struct cw1200_common *priv =
  1040. container_of(work, struct cw1200_common, join_complete_work);
  1041. mutex_lock(&priv->conf_mutex);
  1042. cw1200_join_complete(priv);
  1043. mutex_unlock(&priv->conf_mutex);
  1044. }
  1045. void cw1200_join_complete_cb(struct cw1200_common *priv,
  1046. struct wsm_join_complete *arg)
  1047. {
  1048. pr_debug("[STA] cw1200_join_complete_cb called, status=%d.\n",
  1049. arg->status);
  1050. if (cancel_delayed_work(&priv->join_timeout)) {
  1051. priv->join_complete_status = arg->status;
  1052. queue_work(priv->workqueue, &priv->join_complete_work);
  1053. }
  1054. }
  1055. /* MUST be called with tx_lock held! It will be unlocked for us. */
  1056. static void cw1200_do_join(struct cw1200_common *priv)
  1057. {
  1058. const u8 *bssid;
  1059. struct ieee80211_bss_conf *conf = &priv->vif->bss_conf;
  1060. struct cfg80211_bss *bss = NULL;
  1061. struct wsm_protected_mgmt_policy mgmt_policy;
  1062. struct wsm_join join = {
  1063. .mode = conf->ibss_joined ?
  1064. WSM_JOIN_MODE_IBSS : WSM_JOIN_MODE_BSS,
  1065. .preamble_type = WSM_JOIN_PREAMBLE_LONG,
  1066. .probe_for_join = 1,
  1067. .atim_window = 0,
  1068. .basic_rate_set = cw1200_rate_mask_to_wsm(priv,
  1069. conf->basic_rates),
  1070. };
  1071. if (delayed_work_pending(&priv->join_timeout)) {
  1072. pr_warn("[STA] - Join request already pending, skipping..\n");
  1073. wsm_unlock_tx(priv);
  1074. return;
  1075. }
  1076. if (priv->join_status)
  1077. cw1200_do_unjoin(priv);
  1078. bssid = priv->vif->bss_conf.bssid;
  1079. bss = cfg80211_get_bss(priv->hw->wiphy, priv->channel, bssid, NULL, 0,
  1080. IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
  1081. if (!bss && !conf->ibss_joined) {
  1082. wsm_unlock_tx(priv);
  1083. return;
  1084. }
  1085. mutex_lock(&priv->conf_mutex);
  1086. /* Under the conf lock: check scan status and
  1087. * bail out if it is in progress.
  1088. */
  1089. if (atomic_read(&priv->scan.in_progress)) {
  1090. wsm_unlock_tx(priv);
  1091. goto done_put;
  1092. }
  1093. priv->join_pending = true;
  1094. /* Sanity check basic rates */
  1095. if (!join.basic_rate_set)
  1096. join.basic_rate_set = 7;
  1097. /* Sanity check beacon interval */
  1098. if (!priv->beacon_int)
  1099. priv->beacon_int = 1;
  1100. join.beacon_interval = priv->beacon_int;
  1101. /* BT Coex related changes */
  1102. if (priv->bt_present) {
  1103. if (((priv->conf_listen_interval * 100) %
  1104. priv->beacon_int) == 0)
  1105. priv->listen_interval =
  1106. ((priv->conf_listen_interval * 100) /
  1107. priv->beacon_int);
  1108. else
  1109. priv->listen_interval =
  1110. ((priv->conf_listen_interval * 100) /
  1111. priv->beacon_int + 1);
  1112. }
  1113. if (priv->hw->conf.ps_dtim_period)
  1114. priv->join_dtim_period = priv->hw->conf.ps_dtim_period;
  1115. join.dtim_period = priv->join_dtim_period;
  1116. join.channel_number = priv->channel->hw_value;
  1117. join.band = (priv->channel->band == IEEE80211_BAND_5GHZ) ?
  1118. WSM_PHY_BAND_5G : WSM_PHY_BAND_2_4G;
  1119. memcpy(join.bssid, bssid, sizeof(join.bssid));
  1120. pr_debug("[STA] Join BSSID: %pM DTIM: %d, interval: %d\n",
  1121. join.bssid,
  1122. join.dtim_period, priv->beacon_int);
  1123. if (!conf->ibss_joined) {
  1124. const u8 *ssidie;
  1125. rcu_read_lock();
  1126. ssidie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  1127. if (ssidie) {
  1128. join.ssid_len = ssidie[1];
  1129. memcpy(join.ssid, &ssidie[2], join.ssid_len);
  1130. }
  1131. rcu_read_unlock();
  1132. }
  1133. if (priv->vif->p2p) {
  1134. join.flags |= WSM_JOIN_FLAGS_P2P_GO;
  1135. join.basic_rate_set =
  1136. cw1200_rate_mask_to_wsm(priv, 0xFF0);
  1137. }
  1138. /* Enable asynchronous join calls */
  1139. if (!conf->ibss_joined) {
  1140. join.flags |= WSM_JOIN_FLAGS_FORCE;
  1141. join.flags |= WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND;
  1142. }
  1143. wsm_flush_tx(priv);
  1144. /* Stay Awake for Join and Auth Timeouts and a bit more */
  1145. cw1200_pm_stay_awake(&priv->pm_state,
  1146. CW1200_JOIN_TIMEOUT + CW1200_AUTH_TIMEOUT);
  1147. cw1200_update_listening(priv, false);
  1148. /* Turn on Block ACKs */
  1149. wsm_set_block_ack_policy(priv, priv->ba_tx_tid_mask,
  1150. priv->ba_rx_tid_mask);
  1151. /* Set up timeout */
  1152. if (join.flags & WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND) {
  1153. priv->join_status = CW1200_JOIN_STATUS_JOINING;
  1154. queue_delayed_work(priv->workqueue,
  1155. &priv->join_timeout,
  1156. CW1200_JOIN_TIMEOUT);
  1157. }
  1158. /* 802.11w protected mgmt frames */
  1159. mgmt_policy.protectedMgmtEnable = 0;
  1160. mgmt_policy.unprotectedMgmtFramesAllowed = 1;
  1161. mgmt_policy.encryptionForAuthFrame = 1;
  1162. wsm_set_protected_mgmt_policy(priv, &mgmt_policy);
  1163. /* Perform actual join */
  1164. if (wsm_join(priv, &join)) {
  1165. pr_err("[STA] cw1200_join_work: wsm_join failed!\n");
  1166. cancel_delayed_work_sync(&priv->join_timeout);
  1167. cw1200_update_listening(priv, priv->listening);
  1168. /* Tx lock still held, unjoin will clear it. */
  1169. if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0)
  1170. wsm_unlock_tx(priv);
  1171. } else {
  1172. if (!(join.flags & WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND))
  1173. cw1200_join_complete(priv); /* Will clear tx_lock */
  1174. /* Upload keys */
  1175. cw1200_upload_keys(priv);
  1176. /* Due to beacon filtering it is possible that the
  1177. * AP's beacon is not known for the mac80211 stack.
  1178. * Disable filtering temporary to make sure the stack
  1179. * receives at least one
  1180. */
  1181. priv->disable_beacon_filter = true;
  1182. }
  1183. cw1200_update_filtering(priv);
  1184. done_put:
  1185. mutex_unlock(&priv->conf_mutex);
  1186. if (bss)
  1187. cfg80211_put_bss(priv->hw->wiphy, bss);
  1188. }
  1189. void cw1200_join_timeout(struct work_struct *work)
  1190. {
  1191. struct cw1200_common *priv =
  1192. container_of(work, struct cw1200_common, join_timeout.work);
  1193. pr_debug("[WSM] Join timed out.\n");
  1194. wsm_lock_tx(priv);
  1195. if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0)
  1196. wsm_unlock_tx(priv);
  1197. }
  1198. static void cw1200_do_unjoin(struct cw1200_common *priv)
  1199. {
  1200. struct wsm_reset reset = {
  1201. .reset_statistics = true,
  1202. };
  1203. cancel_delayed_work_sync(&priv->join_timeout);
  1204. mutex_lock(&priv->conf_mutex);
  1205. priv->join_pending = false;
  1206. if (atomic_read(&priv->scan.in_progress)) {
  1207. if (priv->delayed_unjoin)
  1208. wiphy_dbg(priv->hw->wiphy, "Delayed unjoin is already scheduled.\n");
  1209. else
  1210. priv->delayed_unjoin = true;
  1211. goto done;
  1212. }
  1213. priv->delayed_link_loss = false;
  1214. if (!priv->join_status)
  1215. goto done;
  1216. if (priv->join_status == CW1200_JOIN_STATUS_AP)
  1217. goto done;
  1218. cancel_work_sync(&priv->update_filtering_work);
  1219. cancel_work_sync(&priv->set_beacon_wakeup_period_work);
  1220. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  1221. /* Unjoin is a reset. */
  1222. wsm_flush_tx(priv);
  1223. wsm_keep_alive_period(priv, 0);
  1224. wsm_reset(priv, &reset);
  1225. wsm_set_output_power(priv, priv->output_power * 10);
  1226. priv->join_dtim_period = 0;
  1227. cw1200_setup_mac(priv);
  1228. cw1200_free_event_queue(priv);
  1229. cancel_work_sync(&priv->event_handler);
  1230. cw1200_update_listening(priv, priv->listening);
  1231. cw1200_cqm_bssloss_sm(priv, 0, 0, 0);
  1232. /* Disable Block ACKs */
  1233. wsm_set_block_ack_policy(priv, 0, 0);
  1234. priv->disable_beacon_filter = false;
  1235. cw1200_update_filtering(priv);
  1236. memset(&priv->association_mode, 0,
  1237. sizeof(priv->association_mode));
  1238. memset(&priv->bss_params, 0, sizeof(priv->bss_params));
  1239. priv->setbssparams_done = false;
  1240. memset(&priv->firmware_ps_mode, 0,
  1241. sizeof(priv->firmware_ps_mode));
  1242. pr_debug("[STA] Unjoin completed.\n");
  1243. done:
  1244. mutex_unlock(&priv->conf_mutex);
  1245. }
  1246. void cw1200_unjoin_work(struct work_struct *work)
  1247. {
  1248. struct cw1200_common *priv =
  1249. container_of(work, struct cw1200_common, unjoin_work);
  1250. cw1200_do_unjoin(priv);
  1251. /* Tell the stack we're dead */
  1252. ieee80211_connection_loss(priv->vif);
  1253. wsm_unlock_tx(priv);
  1254. }
  1255. int cw1200_enable_listening(struct cw1200_common *priv)
  1256. {
  1257. struct wsm_start start = {
  1258. .mode = WSM_START_MODE_P2P_DEV,
  1259. .band = WSM_PHY_BAND_2_4G,
  1260. .beacon_interval = 100,
  1261. .dtim_period = 1,
  1262. .probe_delay = 0,
  1263. .basic_rate_set = 0x0F,
  1264. };
  1265. if (priv->channel) {
  1266. start.band = priv->channel->band == IEEE80211_BAND_5GHZ ?
  1267. WSM_PHY_BAND_5G : WSM_PHY_BAND_2_4G;
  1268. start.channel_number = priv->channel->hw_value;
  1269. } else {
  1270. start.band = WSM_PHY_BAND_2_4G;
  1271. start.channel_number = 1;
  1272. }
  1273. return wsm_start(priv, &start);
  1274. }
  1275. int cw1200_disable_listening(struct cw1200_common *priv)
  1276. {
  1277. int ret;
  1278. struct wsm_reset reset = {
  1279. .reset_statistics = true,
  1280. };
  1281. ret = wsm_reset(priv, &reset);
  1282. return ret;
  1283. }
  1284. void cw1200_update_listening(struct cw1200_common *priv, bool enabled)
  1285. {
  1286. if (enabled) {
  1287. if (priv->join_status == CW1200_JOIN_STATUS_PASSIVE) {
  1288. if (!cw1200_enable_listening(priv))
  1289. priv->join_status = CW1200_JOIN_STATUS_MONITOR;
  1290. wsm_set_probe_responder(priv, true);
  1291. }
  1292. } else {
  1293. if (priv->join_status == CW1200_JOIN_STATUS_MONITOR) {
  1294. if (!cw1200_disable_listening(priv))
  1295. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  1296. wsm_set_probe_responder(priv, false);
  1297. }
  1298. }
  1299. }
  1300. int cw1200_set_uapsd_param(struct cw1200_common *priv,
  1301. const struct wsm_edca_params *arg)
  1302. {
  1303. int ret;
  1304. u16 uapsd_flags = 0;
  1305. /* Here's the mapping AC [queue, bit]
  1306. * VO [0,3], VI [1, 2], BE [2, 1], BK [3, 0]
  1307. */
  1308. if (arg->uapsd_enable[0])
  1309. uapsd_flags |= 1 << 3;
  1310. if (arg->uapsd_enable[1])
  1311. uapsd_flags |= 1 << 2;
  1312. if (arg->uapsd_enable[2])
  1313. uapsd_flags |= 1 << 1;
  1314. if (arg->uapsd_enable[3])
  1315. uapsd_flags |= 1;
  1316. /* Currently pseudo U-APSD operation is not supported, so setting
  1317. * MinAutoTriggerInterval, MaxAutoTriggerInterval and
  1318. * AutoTriggerStep to 0
  1319. */
  1320. priv->uapsd_info.uapsd_flags = cpu_to_le16(uapsd_flags);
  1321. priv->uapsd_info.min_auto_trigger_interval = 0;
  1322. priv->uapsd_info.max_auto_trigger_interval = 0;
  1323. priv->uapsd_info.auto_trigger_step = 0;
  1324. ret = wsm_set_uapsd_info(priv, &priv->uapsd_info);
  1325. return ret;
  1326. }
  1327. /* ******************************************************************** */
  1328. /* AP API */
  1329. int cw1200_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1330. struct ieee80211_sta *sta)
  1331. {
  1332. struct cw1200_common *priv = hw->priv;
  1333. struct cw1200_sta_priv *sta_priv =
  1334. (struct cw1200_sta_priv *)&sta->drv_priv;
  1335. struct cw1200_link_entry *entry;
  1336. struct sk_buff *skb;
  1337. if (priv->mode != NL80211_IFTYPE_AP)
  1338. return 0;
  1339. sta_priv->link_id = cw1200_find_link_id(priv, sta->addr);
  1340. if (WARN_ON(!sta_priv->link_id)) {
  1341. wiphy_info(priv->hw->wiphy,
  1342. "[AP] No more link IDs available.\n");
  1343. return -ENOENT;
  1344. }
  1345. entry = &priv->link_id_db[sta_priv->link_id - 1];
  1346. spin_lock_bh(&priv->ps_state_lock);
  1347. if ((sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) ==
  1348. IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
  1349. priv->sta_asleep_mask |= BIT(sta_priv->link_id);
  1350. entry->status = CW1200_LINK_HARD;
  1351. while ((skb = skb_dequeue(&entry->rx_queue)))
  1352. ieee80211_rx_irqsafe(priv->hw, skb);
  1353. spin_unlock_bh(&priv->ps_state_lock);
  1354. return 0;
  1355. }
  1356. int cw1200_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1357. struct ieee80211_sta *sta)
  1358. {
  1359. struct cw1200_common *priv = hw->priv;
  1360. struct cw1200_sta_priv *sta_priv =
  1361. (struct cw1200_sta_priv *)&sta->drv_priv;
  1362. struct cw1200_link_entry *entry;
  1363. if (priv->mode != NL80211_IFTYPE_AP || !sta_priv->link_id)
  1364. return 0;
  1365. entry = &priv->link_id_db[sta_priv->link_id - 1];
  1366. spin_lock_bh(&priv->ps_state_lock);
  1367. entry->status = CW1200_LINK_RESERVE;
  1368. entry->timestamp = jiffies;
  1369. wsm_lock_tx_async(priv);
  1370. if (queue_work(priv->workqueue, &priv->link_id_work) <= 0)
  1371. wsm_unlock_tx(priv);
  1372. spin_unlock_bh(&priv->ps_state_lock);
  1373. flush_workqueue(priv->workqueue);
  1374. return 0;
  1375. }
  1376. static void __cw1200_sta_notify(struct ieee80211_hw *dev,
  1377. struct ieee80211_vif *vif,
  1378. enum sta_notify_cmd notify_cmd,
  1379. int link_id)
  1380. {
  1381. struct cw1200_common *priv = dev->priv;
  1382. u32 bit, prev;
  1383. /* Zero link id means "for all link IDs" */
  1384. if (link_id)
  1385. bit = BIT(link_id);
  1386. else if (WARN_ON_ONCE(notify_cmd != STA_NOTIFY_AWAKE))
  1387. bit = 0;
  1388. else
  1389. bit = priv->link_id_map;
  1390. prev = priv->sta_asleep_mask & bit;
  1391. switch (notify_cmd) {
  1392. case STA_NOTIFY_SLEEP:
  1393. if (!prev) {
  1394. if (priv->buffered_multicasts &&
  1395. !priv->sta_asleep_mask)
  1396. queue_work(priv->workqueue,
  1397. &priv->multicast_start_work);
  1398. priv->sta_asleep_mask |= bit;
  1399. }
  1400. break;
  1401. case STA_NOTIFY_AWAKE:
  1402. if (prev) {
  1403. priv->sta_asleep_mask &= ~bit;
  1404. priv->pspoll_mask &= ~bit;
  1405. if (priv->tx_multicast && link_id &&
  1406. !priv->sta_asleep_mask)
  1407. queue_work(priv->workqueue,
  1408. &priv->multicast_stop_work);
  1409. cw1200_bh_wakeup(priv);
  1410. }
  1411. break;
  1412. }
  1413. }
  1414. void cw1200_sta_notify(struct ieee80211_hw *dev,
  1415. struct ieee80211_vif *vif,
  1416. enum sta_notify_cmd notify_cmd,
  1417. struct ieee80211_sta *sta)
  1418. {
  1419. struct cw1200_common *priv = dev->priv;
  1420. struct cw1200_sta_priv *sta_priv =
  1421. (struct cw1200_sta_priv *)&sta->drv_priv;
  1422. spin_lock_bh(&priv->ps_state_lock);
  1423. __cw1200_sta_notify(dev, vif, notify_cmd, sta_priv->link_id);
  1424. spin_unlock_bh(&priv->ps_state_lock);
  1425. }
  1426. static void cw1200_ps_notify(struct cw1200_common *priv,
  1427. int link_id, bool ps)
  1428. {
  1429. if (link_id > CW1200_MAX_STA_IN_AP_MODE)
  1430. return;
  1431. pr_debug("%s for LinkId: %d. STAs asleep: %.8X\n",
  1432. ps ? "Stop" : "Start",
  1433. link_id, priv->sta_asleep_mask);
  1434. __cw1200_sta_notify(priv->hw, priv->vif,
  1435. ps ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, link_id);
  1436. }
  1437. static int cw1200_set_tim_impl(struct cw1200_common *priv, bool aid0_bit_set)
  1438. {
  1439. struct sk_buff *skb;
  1440. struct wsm_update_ie update_ie = {
  1441. .what = WSM_UPDATE_IE_BEACON,
  1442. .count = 1,
  1443. };
  1444. u16 tim_offset, tim_length;
  1445. pr_debug("[AP] mcast: %s.\n", aid0_bit_set ? "ena" : "dis");
  1446. skb = ieee80211_beacon_get_tim(priv->hw, priv->vif,
  1447. &tim_offset, &tim_length);
  1448. if (!skb) {
  1449. if (!__cw1200_flush(priv, true))
  1450. wsm_unlock_tx(priv);
  1451. return -ENOENT;
  1452. }
  1453. if (tim_offset && tim_length >= 6) {
  1454. /* Ignore DTIM count from mac80211:
  1455. * firmware handles DTIM internally.
  1456. */
  1457. skb->data[tim_offset + 2] = 0;
  1458. /* Set/reset aid0 bit */
  1459. if (aid0_bit_set)
  1460. skb->data[tim_offset + 4] |= 1;
  1461. else
  1462. skb->data[tim_offset + 4] &= ~1;
  1463. }
  1464. update_ie.ies = &skb->data[tim_offset];
  1465. update_ie.length = tim_length;
  1466. wsm_update_ie(priv, &update_ie);
  1467. dev_kfree_skb(skb);
  1468. return 0;
  1469. }
  1470. void cw1200_set_tim_work(struct work_struct *work)
  1471. {
  1472. struct cw1200_common *priv =
  1473. container_of(work, struct cw1200_common, set_tim_work);
  1474. (void)cw1200_set_tim_impl(priv, priv->aid0_bit_set);
  1475. }
  1476. int cw1200_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
  1477. bool set)
  1478. {
  1479. struct cw1200_common *priv = dev->priv;
  1480. queue_work(priv->workqueue, &priv->set_tim_work);
  1481. return 0;
  1482. }
  1483. void cw1200_set_cts_work(struct work_struct *work)
  1484. {
  1485. struct cw1200_common *priv =
  1486. container_of(work, struct cw1200_common, set_cts_work);
  1487. u8 erp_ie[3] = {WLAN_EID_ERP_INFO, 0x1, 0};
  1488. struct wsm_update_ie update_ie = {
  1489. .what = WSM_UPDATE_IE_BEACON,
  1490. .count = 1,
  1491. .ies = erp_ie,
  1492. .length = 3,
  1493. };
  1494. u32 erp_info;
  1495. __le32 use_cts_prot;
  1496. mutex_lock(&priv->conf_mutex);
  1497. erp_info = priv->erp_info;
  1498. mutex_unlock(&priv->conf_mutex);
  1499. use_cts_prot =
  1500. erp_info & WLAN_ERP_USE_PROTECTION ?
  1501. __cpu_to_le32(1) : 0;
  1502. erp_ie[ERP_INFO_BYTE_OFFSET] = erp_info;
  1503. pr_debug("[STA] ERP information 0x%x\n", erp_info);
  1504. wsm_write_mib(priv, WSM_MIB_ID_NON_ERP_PROTECTION,
  1505. &use_cts_prot, sizeof(use_cts_prot));
  1506. wsm_update_ie(priv, &update_ie);
  1507. return;
  1508. }
  1509. static int cw1200_set_btcoexinfo(struct cw1200_common *priv)
  1510. {
  1511. struct wsm_override_internal_txrate arg;
  1512. int ret = 0;
  1513. if (priv->mode == NL80211_IFTYPE_STATION) {
  1514. /* Plumb PSPOLL and NULL template */
  1515. cw1200_upload_pspoll(priv);
  1516. cw1200_upload_null(priv);
  1517. cw1200_upload_qosnull(priv);
  1518. } else {
  1519. return 0;
  1520. }
  1521. memset(&arg, 0, sizeof(struct wsm_override_internal_txrate));
  1522. if (!priv->vif->p2p) {
  1523. /* STATION mode */
  1524. if (priv->bss_params.operational_rate_set & ~0xF) {
  1525. pr_debug("[STA] STA has ERP rates\n");
  1526. /* G or BG mode */
  1527. arg.internalTxRate = (__ffs(
  1528. priv->bss_params.operational_rate_set & ~0xF));
  1529. } else {
  1530. pr_debug("[STA] STA has non ERP rates\n");
  1531. /* B only mode */
  1532. arg.internalTxRate = (__ffs(le32_to_cpu(priv->association_mode.basic_rate_set)));
  1533. }
  1534. arg.nonErpInternalTxRate = (__ffs(le32_to_cpu(priv->association_mode.basic_rate_set)));
  1535. } else {
  1536. /* P2P mode */
  1537. arg.internalTxRate = (__ffs(priv->bss_params.operational_rate_set & ~0xF));
  1538. arg.nonErpInternalTxRate = (__ffs(priv->bss_params.operational_rate_set & ~0xF));
  1539. }
  1540. pr_debug("[STA] BTCOEX_INFO MODE %d, internalTxRate : %x, nonErpInternalTxRate: %x\n",
  1541. priv->mode,
  1542. arg.internalTxRate,
  1543. arg.nonErpInternalTxRate);
  1544. ret = wsm_write_mib(priv, WSM_MIB_ID_OVERRIDE_INTERNAL_TX_RATE,
  1545. &arg, sizeof(arg));
  1546. return ret;
  1547. }
  1548. void cw1200_bss_info_changed(struct ieee80211_hw *dev,
  1549. struct ieee80211_vif *vif,
  1550. struct ieee80211_bss_conf *info,
  1551. u32 changed)
  1552. {
  1553. struct cw1200_common *priv = dev->priv;
  1554. bool do_join = false;
  1555. mutex_lock(&priv->conf_mutex);
  1556. pr_debug("BSS CHANGED: %08x\n", changed);
  1557. /* TODO: BSS_CHANGED_QOS */
  1558. /* TODO: BSS_CHANGED_TXPOWER */
  1559. if (changed & BSS_CHANGED_ARP_FILTER) {
  1560. struct wsm_mib_arp_ipv4_filter filter = {0};
  1561. int i;
  1562. pr_debug("[STA] BSS_CHANGED_ARP_FILTER cnt: %d\n",
  1563. info->arp_addr_cnt);
  1564. /* Currently only one IP address is supported by firmware.
  1565. * In case of more IPs arp filtering will be disabled.
  1566. */
  1567. if (info->arp_addr_cnt > 0 &&
  1568. info->arp_addr_cnt <= WSM_MAX_ARP_IP_ADDRTABLE_ENTRIES) {
  1569. for (i = 0; i < info->arp_addr_cnt; i++) {
  1570. filter.ipv4addrs[i] = info->arp_addr_list[i];
  1571. pr_debug("[STA] addr[%d]: 0x%X\n",
  1572. i, filter.ipv4addrs[i]);
  1573. }
  1574. filter.enable = __cpu_to_le32(1);
  1575. }
  1576. pr_debug("[STA] arp ip filter enable: %d\n",
  1577. __le32_to_cpu(filter.enable));
  1578. wsm_set_arp_ipv4_filter(priv, &filter);
  1579. }
  1580. if (changed &
  1581. (BSS_CHANGED_BEACON |
  1582. BSS_CHANGED_AP_PROBE_RESP |
  1583. BSS_CHANGED_BSSID |
  1584. BSS_CHANGED_SSID |
  1585. BSS_CHANGED_IBSS)) {
  1586. pr_debug("BSS_CHANGED_BEACON\n");
  1587. priv->beacon_int = info->beacon_int;
  1588. cw1200_update_beaconing(priv);
  1589. cw1200_upload_beacon(priv);
  1590. }
  1591. if (changed & BSS_CHANGED_BEACON_ENABLED) {
  1592. pr_debug("BSS_CHANGED_BEACON_ENABLED (%d)\n", info->enable_beacon);
  1593. if (priv->enable_beacon != info->enable_beacon) {
  1594. cw1200_enable_beaconing(priv, info->enable_beacon);
  1595. priv->enable_beacon = info->enable_beacon;
  1596. }
  1597. }
  1598. if (changed & BSS_CHANGED_BEACON_INT) {
  1599. pr_debug("CHANGED_BEACON_INT\n");
  1600. if (info->ibss_joined)
  1601. do_join = true;
  1602. else if (priv->join_status == CW1200_JOIN_STATUS_AP)
  1603. cw1200_update_beaconing(priv);
  1604. }
  1605. /* assoc/disassoc, or maybe AID changed */
  1606. if (changed & BSS_CHANGED_ASSOC) {
  1607. wsm_lock_tx(priv);
  1608. priv->wep_default_key_id = -1;
  1609. wsm_unlock_tx(priv);
  1610. }
  1611. if (changed & BSS_CHANGED_BSSID) {
  1612. pr_debug("BSS_CHANGED_BSSID\n");
  1613. do_join = true;
  1614. }
  1615. if (changed &
  1616. (BSS_CHANGED_ASSOC |
  1617. BSS_CHANGED_BSSID |
  1618. BSS_CHANGED_IBSS |
  1619. BSS_CHANGED_BASIC_RATES |
  1620. BSS_CHANGED_HT)) {
  1621. pr_debug("BSS_CHANGED_ASSOC\n");
  1622. if (info->assoc) {
  1623. if (priv->join_status < CW1200_JOIN_STATUS_PRE_STA) {
  1624. ieee80211_connection_loss(vif);
  1625. mutex_unlock(&priv->conf_mutex);
  1626. return;
  1627. } else if (priv->join_status == CW1200_JOIN_STATUS_PRE_STA) {
  1628. priv->join_status = CW1200_JOIN_STATUS_STA;
  1629. }
  1630. } else {
  1631. do_join = true;
  1632. }
  1633. if (info->assoc || info->ibss_joined) {
  1634. struct ieee80211_sta *sta = NULL;
  1635. __le32 htprot = 0;
  1636. if (info->dtim_period)
  1637. priv->join_dtim_period = info->dtim_period;
  1638. priv->beacon_int = info->beacon_int;
  1639. rcu_read_lock();
  1640. if (info->bssid && !info->ibss_joined)
  1641. sta = ieee80211_find_sta(vif, info->bssid);
  1642. if (sta) {
  1643. priv->ht_info.ht_cap = sta->ht_cap;
  1644. priv->bss_params.operational_rate_set =
  1645. cw1200_rate_mask_to_wsm(priv,
  1646. sta->supp_rates[priv->channel->band]);
  1647. priv->ht_info.channel_type = cfg80211_get_chandef_type(&dev->conf.chandef);
  1648. priv->ht_info.operation_mode = info->ht_operation_mode;
  1649. } else {
  1650. memset(&priv->ht_info, 0,
  1651. sizeof(priv->ht_info));
  1652. priv->bss_params.operational_rate_set = -1;
  1653. }
  1654. rcu_read_unlock();
  1655. /* Non Greenfield stations present */
  1656. if (priv->ht_info.operation_mode &
  1657. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)
  1658. htprot |= cpu_to_le32(WSM_NON_GREENFIELD_STA_PRESENT);
  1659. /* Set HT protection method */
  1660. htprot |= cpu_to_le32((priv->ht_info.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION) << 2);
  1661. /* TODO:
  1662. * STBC_param.dual_cts
  1663. * STBC_param.LSIG_TXOP_FILL
  1664. */
  1665. wsm_write_mib(priv, WSM_MIB_ID_SET_HT_PROTECTION,
  1666. &htprot, sizeof(htprot));
  1667. priv->association_mode.greenfield =
  1668. cw1200_ht_greenfield(&priv->ht_info);
  1669. priv->association_mode.flags =
  1670. WSM_ASSOCIATION_MODE_SNOOP_ASSOC_FRAMES |
  1671. WSM_ASSOCIATION_MODE_USE_PREAMBLE_TYPE |
  1672. WSM_ASSOCIATION_MODE_USE_HT_MODE |
  1673. WSM_ASSOCIATION_MODE_USE_BASIC_RATE_SET |
  1674. WSM_ASSOCIATION_MODE_USE_MPDU_START_SPACING;
  1675. priv->association_mode.preamble =
  1676. info->use_short_preamble ?
  1677. WSM_JOIN_PREAMBLE_SHORT :
  1678. WSM_JOIN_PREAMBLE_LONG;
  1679. priv->association_mode.basic_rate_set = __cpu_to_le32(
  1680. cw1200_rate_mask_to_wsm(priv,
  1681. info->basic_rates));
  1682. priv->association_mode.mpdu_start_spacing =
  1683. cw1200_ht_ampdu_density(&priv->ht_info);
  1684. cw1200_cqm_bssloss_sm(priv, 0, 0, 0);
  1685. cancel_work_sync(&priv->unjoin_work);
  1686. priv->bss_params.beacon_lost_count = priv->cqm_beacon_loss_count;
  1687. priv->bss_params.aid = info->aid;
  1688. if (priv->join_dtim_period < 1)
  1689. priv->join_dtim_period = 1;
  1690. pr_debug("[STA] DTIM %d, interval: %d\n",
  1691. priv->join_dtim_period, priv->beacon_int);
  1692. pr_debug("[STA] Preamble: %d, Greenfield: %d, Aid: %d, Rates: 0x%.8X, Basic: 0x%.8X\n",
  1693. priv->association_mode.preamble,
  1694. priv->association_mode.greenfield,
  1695. priv->bss_params.aid,
  1696. priv->bss_params.operational_rate_set,
  1697. priv->association_mode.basic_rate_set);
  1698. wsm_set_association_mode(priv, &priv->association_mode);
  1699. if (!info->ibss_joined) {
  1700. wsm_keep_alive_period(priv, 30 /* sec */);
  1701. wsm_set_bss_params(priv, &priv->bss_params);
  1702. priv->setbssparams_done = true;
  1703. cw1200_set_beacon_wakeup_period_work(&priv->set_beacon_wakeup_period_work);
  1704. cw1200_set_pm(priv, &priv->powersave_mode);
  1705. }
  1706. if (priv->vif->p2p) {
  1707. pr_debug("[STA] Setting p2p powersave configuration.\n");
  1708. wsm_set_p2p_ps_modeinfo(priv,
  1709. &priv->p2p_ps_modeinfo);
  1710. }
  1711. if (priv->bt_present)
  1712. cw1200_set_btcoexinfo(priv);
  1713. } else {
  1714. memset(&priv->association_mode, 0,
  1715. sizeof(priv->association_mode));
  1716. memset(&priv->bss_params, 0, sizeof(priv->bss_params));
  1717. }
  1718. }
  1719. /* ERP Protection */
  1720. if (changed & (BSS_CHANGED_ASSOC |
  1721. BSS_CHANGED_ERP_CTS_PROT |
  1722. BSS_CHANGED_ERP_PREAMBLE)) {
  1723. u32 prev_erp_info = priv->erp_info;
  1724. if (info->use_cts_prot)
  1725. priv->erp_info |= WLAN_ERP_USE_PROTECTION;
  1726. else if (!(prev_erp_info & WLAN_ERP_NON_ERP_PRESENT))
  1727. priv->erp_info &= ~WLAN_ERP_USE_PROTECTION;
  1728. if (info->use_short_preamble)
  1729. priv->erp_info |= WLAN_ERP_BARKER_PREAMBLE;
  1730. else
  1731. priv->erp_info &= ~WLAN_ERP_BARKER_PREAMBLE;
  1732. pr_debug("[STA] ERP Protection: %x\n", priv->erp_info);
  1733. if (prev_erp_info != priv->erp_info)
  1734. queue_work(priv->workqueue, &priv->set_cts_work);
  1735. }
  1736. /* ERP Slottime */
  1737. if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_SLOT)) {
  1738. __le32 slot_time = info->use_short_slot ?
  1739. __cpu_to_le32(9) : __cpu_to_le32(20);
  1740. pr_debug("[STA] Slot time: %d us.\n",
  1741. __le32_to_cpu(slot_time));
  1742. wsm_write_mib(priv, WSM_MIB_ID_DOT11_SLOT_TIME,
  1743. &slot_time, sizeof(slot_time));
  1744. }
  1745. if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_CQM)) {
  1746. struct wsm_rcpi_rssi_threshold threshold = {
  1747. .rollingAverageCount = 8,
  1748. };
  1749. pr_debug("[CQM] RSSI threshold subscribe: %d +- %d\n",
  1750. info->cqm_rssi_thold, info->cqm_rssi_hyst);
  1751. priv->cqm_rssi_thold = info->cqm_rssi_thold;
  1752. priv->cqm_rssi_hyst = info->cqm_rssi_hyst;
  1753. if (info->cqm_rssi_thold || info->cqm_rssi_hyst) {
  1754. /* RSSI subscription enabled */
  1755. /* TODO: It's not a correct way of setting threshold.
  1756. * Upper and lower must be set equal here and adjusted
  1757. * in callback. However current implementation is much
  1758. * more relaible and stable.
  1759. */
  1760. /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
  1761. * RSSI = RCPI / 2 - 110
  1762. */
  1763. if (priv->cqm_use_rssi) {
  1764. threshold.upperThreshold =
  1765. info->cqm_rssi_thold + info->cqm_rssi_hyst;
  1766. threshold.lowerThreshold =
  1767. info->cqm_rssi_thold;
  1768. threshold.rssiRcpiMode |= WSM_RCPI_RSSI_USE_RSSI;
  1769. } else {
  1770. threshold.upperThreshold = (info->cqm_rssi_thold + info->cqm_rssi_hyst + 110) * 2;
  1771. threshold.lowerThreshold = (info->cqm_rssi_thold + 110) * 2;
  1772. }
  1773. threshold.rssiRcpiMode |= WSM_RCPI_RSSI_THRESHOLD_ENABLE;
  1774. } else {
  1775. /* There is a bug in FW, see sta.c. We have to enable
  1776. * dummy subscription to get correct RSSI values.
  1777. */
  1778. threshold.rssiRcpiMode |=
  1779. WSM_RCPI_RSSI_THRESHOLD_ENABLE |
  1780. WSM_RCPI_RSSI_DONT_USE_UPPER |
  1781. WSM_RCPI_RSSI_DONT_USE_LOWER;
  1782. if (priv->cqm_use_rssi)
  1783. threshold.rssiRcpiMode |= WSM_RCPI_RSSI_USE_RSSI;
  1784. }
  1785. wsm_set_rcpi_rssi_threshold(priv, &threshold);
  1786. }
  1787. mutex_unlock(&priv->conf_mutex);
  1788. if (do_join) {
  1789. wsm_lock_tx(priv);
  1790. cw1200_do_join(priv); /* Will unlock it for us */
  1791. }
  1792. }
  1793. void cw1200_multicast_start_work(struct work_struct *work)
  1794. {
  1795. struct cw1200_common *priv =
  1796. container_of(work, struct cw1200_common, multicast_start_work);
  1797. long tmo = priv->join_dtim_period *
  1798. (priv->beacon_int + 20) * HZ / 1024;
  1799. cancel_work_sync(&priv->multicast_stop_work);
  1800. if (!priv->aid0_bit_set) {
  1801. wsm_lock_tx(priv);
  1802. cw1200_set_tim_impl(priv, true);
  1803. priv->aid0_bit_set = true;
  1804. mod_timer(&priv->mcast_timeout, jiffies + tmo);
  1805. wsm_unlock_tx(priv);
  1806. }
  1807. }
  1808. void cw1200_multicast_stop_work(struct work_struct *work)
  1809. {
  1810. struct cw1200_common *priv =
  1811. container_of(work, struct cw1200_common, multicast_stop_work);
  1812. if (priv->aid0_bit_set) {
  1813. del_timer_sync(&priv->mcast_timeout);
  1814. wsm_lock_tx(priv);
  1815. priv->aid0_bit_set = false;
  1816. cw1200_set_tim_impl(priv, false);
  1817. wsm_unlock_tx(priv);
  1818. }
  1819. }
  1820. void cw1200_mcast_timeout(unsigned long arg)
  1821. {
  1822. struct cw1200_common *priv =
  1823. (struct cw1200_common *)arg;
  1824. wiphy_warn(priv->hw->wiphy,
  1825. "Multicast delivery timeout.\n");
  1826. spin_lock_bh(&priv->ps_state_lock);
  1827. priv->tx_multicast = priv->aid0_bit_set &&
  1828. priv->buffered_multicasts;
  1829. if (priv->tx_multicast)
  1830. cw1200_bh_wakeup(priv);
  1831. spin_unlock_bh(&priv->ps_state_lock);
  1832. }
  1833. int cw1200_ampdu_action(struct ieee80211_hw *hw,
  1834. struct ieee80211_vif *vif,
  1835. enum ieee80211_ampdu_mlme_action action,
  1836. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  1837. u8 buf_size)
  1838. {
  1839. /* Aggregation is implemented fully in firmware,
  1840. * including block ack negotiation. Do not allow
  1841. * mac80211 stack to do anything: it interferes with
  1842. * the firmware.
  1843. */
  1844. /* Note that we still need this function stubbed. */
  1845. return -ENOTSUPP;
  1846. }
  1847. /* ******************************************************************** */
  1848. /* WSM callback */
  1849. void cw1200_suspend_resume(struct cw1200_common *priv,
  1850. struct wsm_suspend_resume *arg)
  1851. {
  1852. pr_debug("[AP] %s: %s\n",
  1853. arg->stop ? "stop" : "start",
  1854. arg->multicast ? "broadcast" : "unicast");
  1855. if (arg->multicast) {
  1856. bool cancel_tmo = false;
  1857. spin_lock_bh(&priv->ps_state_lock);
  1858. if (arg->stop) {
  1859. priv->tx_multicast = false;
  1860. } else {
  1861. /* Firmware sends this indication every DTIM if there
  1862. * is a STA in powersave connected. There is no reason
  1863. * to suspend, following wakeup will consume much more
  1864. * power than it could be saved.
  1865. */
  1866. cw1200_pm_stay_awake(&priv->pm_state,
  1867. priv->join_dtim_period *
  1868. (priv->beacon_int + 20) * HZ / 1024);
  1869. priv->tx_multicast = (priv->aid0_bit_set &&
  1870. priv->buffered_multicasts);
  1871. if (priv->tx_multicast) {
  1872. cancel_tmo = true;
  1873. cw1200_bh_wakeup(priv);
  1874. }
  1875. }
  1876. spin_unlock_bh(&priv->ps_state_lock);
  1877. if (cancel_tmo)
  1878. del_timer_sync(&priv->mcast_timeout);
  1879. } else {
  1880. spin_lock_bh(&priv->ps_state_lock);
  1881. cw1200_ps_notify(priv, arg->link_id, arg->stop);
  1882. spin_unlock_bh(&priv->ps_state_lock);
  1883. if (!arg->stop)
  1884. cw1200_bh_wakeup(priv);
  1885. }
  1886. return;
  1887. }
  1888. /* ******************************************************************** */
  1889. /* AP privates */
  1890. static int cw1200_upload_beacon(struct cw1200_common *priv)
  1891. {
  1892. int ret = 0;
  1893. struct ieee80211_mgmt *mgmt;
  1894. struct wsm_template_frame frame = {
  1895. .frame_type = WSM_FRAME_TYPE_BEACON,
  1896. };
  1897. u16 tim_offset;
  1898. u16 tim_len;
  1899. if (priv->mode == NL80211_IFTYPE_STATION ||
  1900. priv->mode == NL80211_IFTYPE_MONITOR ||
  1901. priv->mode == NL80211_IFTYPE_UNSPECIFIED)
  1902. goto done;
  1903. if (priv->vif->p2p)
  1904. frame.rate = WSM_TRANSMIT_RATE_6;
  1905. frame.skb = ieee80211_beacon_get_tim(priv->hw, priv->vif,
  1906. &tim_offset, &tim_len);
  1907. if (!frame.skb)
  1908. return -ENOMEM;
  1909. ret = wsm_set_template_frame(priv, &frame);
  1910. if (ret)
  1911. goto done;
  1912. /* TODO: Distill probe resp; remove TIM
  1913. * and any other beacon-specific IEs
  1914. */
  1915. mgmt = (void *)frame.skb->data;
  1916. mgmt->frame_control =
  1917. __cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1918. IEEE80211_STYPE_PROBE_RESP);
  1919. frame.frame_type = WSM_FRAME_TYPE_PROBE_RESPONSE;
  1920. if (priv->vif->p2p) {
  1921. ret = wsm_set_probe_responder(priv, true);
  1922. } else {
  1923. ret = wsm_set_template_frame(priv, &frame);
  1924. wsm_set_probe_responder(priv, false);
  1925. }
  1926. done:
  1927. dev_kfree_skb(frame.skb);
  1928. return ret;
  1929. }
  1930. static int cw1200_upload_pspoll(struct cw1200_common *priv)
  1931. {
  1932. int ret = 0;
  1933. struct wsm_template_frame frame = {
  1934. .frame_type = WSM_FRAME_TYPE_PS_POLL,
  1935. .rate = 0xFF,
  1936. };
  1937. frame.skb = ieee80211_pspoll_get(priv->hw, priv->vif);
  1938. if (!frame.skb)
  1939. return -ENOMEM;
  1940. ret = wsm_set_template_frame(priv, &frame);
  1941. dev_kfree_skb(frame.skb);
  1942. return ret;
  1943. }
  1944. static int cw1200_upload_null(struct cw1200_common *priv)
  1945. {
  1946. int ret = 0;
  1947. struct wsm_template_frame frame = {
  1948. .frame_type = WSM_FRAME_TYPE_NULL,
  1949. .rate = 0xFF,
  1950. };
  1951. frame.skb = ieee80211_nullfunc_get(priv->hw, priv->vif);
  1952. if (!frame.skb)
  1953. return -ENOMEM;
  1954. ret = wsm_set_template_frame(priv, &frame);
  1955. dev_kfree_skb(frame.skb);
  1956. return ret;
  1957. }
  1958. static int cw1200_upload_qosnull(struct cw1200_common *priv)
  1959. {
  1960. /* TODO: This needs to be implemented
  1961. struct wsm_template_frame frame = {
  1962. .frame_type = WSM_FRAME_TYPE_QOS_NULL,
  1963. .rate = 0xFF,
  1964. };
  1965. frame.skb = ieee80211_qosnullfunc_get(priv->hw, priv->vif);
  1966. if (!frame.skb)
  1967. return -ENOMEM;
  1968. ret = wsm_set_template_frame(priv, &frame);
  1969. dev_kfree_skb(frame.skb);
  1970. */
  1971. return 0;
  1972. }
  1973. static int cw1200_enable_beaconing(struct cw1200_common *priv,
  1974. bool enable)
  1975. {
  1976. struct wsm_beacon_transmit transmit = {
  1977. .enable_beaconing = enable,
  1978. };
  1979. return wsm_beacon_transmit(priv, &transmit);
  1980. }
  1981. static int cw1200_start_ap(struct cw1200_common *priv)
  1982. {
  1983. int ret;
  1984. struct ieee80211_bss_conf *conf = &priv->vif->bss_conf;
  1985. struct wsm_start start = {
  1986. .mode = priv->vif->p2p ?
  1987. WSM_START_MODE_P2P_GO : WSM_START_MODE_AP,
  1988. .band = (priv->channel->band == IEEE80211_BAND_5GHZ) ?
  1989. WSM_PHY_BAND_5G : WSM_PHY_BAND_2_4G,
  1990. .channel_number = priv->channel->hw_value,
  1991. .beacon_interval = conf->beacon_int,
  1992. .dtim_period = conf->dtim_period,
  1993. .preamble = conf->use_short_preamble ?
  1994. WSM_JOIN_PREAMBLE_SHORT :
  1995. WSM_JOIN_PREAMBLE_LONG,
  1996. .probe_delay = 100,
  1997. .basic_rate_set = cw1200_rate_mask_to_wsm(priv,
  1998. conf->basic_rates),
  1999. };
  2000. struct wsm_operational_mode mode = {
  2001. .power_mode = cw1200_power_mode,
  2002. .disable_more_flag_usage = true,
  2003. };
  2004. memset(start.ssid, 0, sizeof(start.ssid));
  2005. if (!conf->hidden_ssid) {
  2006. start.ssid_len = conf->ssid_len;
  2007. memcpy(start.ssid, conf->ssid, start.ssid_len);
  2008. }
  2009. priv->beacon_int = conf->beacon_int;
  2010. priv->join_dtim_period = conf->dtim_period;
  2011. memset(&priv->link_id_db, 0, sizeof(priv->link_id_db));
  2012. pr_debug("[AP] ch: %d(%d), bcn: %d(%d), brt: 0x%.8X, ssid: %.*s.\n",
  2013. start.channel_number, start.band,
  2014. start.beacon_interval, start.dtim_period,
  2015. start.basic_rate_set,
  2016. start.ssid_len, start.ssid);
  2017. ret = wsm_start(priv, &start);
  2018. if (!ret)
  2019. ret = cw1200_upload_keys(priv);
  2020. if (!ret && priv->vif->p2p) {
  2021. pr_debug("[AP] Setting p2p powersave configuration.\n");
  2022. wsm_set_p2p_ps_modeinfo(priv, &priv->p2p_ps_modeinfo);
  2023. }
  2024. if (!ret) {
  2025. wsm_set_block_ack_policy(priv, 0, 0);
  2026. priv->join_status = CW1200_JOIN_STATUS_AP;
  2027. cw1200_update_filtering(priv);
  2028. }
  2029. wsm_set_operational_mode(priv, &mode);
  2030. return ret;
  2031. }
  2032. static int cw1200_update_beaconing(struct cw1200_common *priv)
  2033. {
  2034. struct ieee80211_bss_conf *conf = &priv->vif->bss_conf;
  2035. struct wsm_reset reset = {
  2036. .link_id = 0,
  2037. .reset_statistics = true,
  2038. };
  2039. if (priv->mode == NL80211_IFTYPE_AP) {
  2040. /* TODO: check if changed channel, band */
  2041. if (priv->join_status != CW1200_JOIN_STATUS_AP ||
  2042. priv->beacon_int != conf->beacon_int) {
  2043. pr_debug("ap restarting\n");
  2044. wsm_lock_tx(priv);
  2045. if (priv->join_status != CW1200_JOIN_STATUS_PASSIVE)
  2046. wsm_reset(priv, &reset);
  2047. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  2048. cw1200_start_ap(priv);
  2049. wsm_unlock_tx(priv);
  2050. } else
  2051. pr_debug("ap started join_status: %d\n",
  2052. priv->join_status);
  2053. }
  2054. return 0;
  2055. }