sta.c 63 KB

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