sta.c 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397
  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_OTHER_BSS |
  500. FIF_BCN_PRBRESP_PROMISC |
  501. FIF_PROBE_REQ));
  502. *total_flags &= FIF_OTHER_BSS |
  503. FIF_FCSFAIL |
  504. FIF_BCN_PRBRESP_PROMISC |
  505. FIF_PROBE_REQ;
  506. down(&priv->scan.lock);
  507. mutex_lock(&priv->conf_mutex);
  508. priv->rx_filter.promiscuous = 0;
  509. priv->rx_filter.bssid = (*total_flags & (FIF_OTHER_BSS |
  510. FIF_PROBE_REQ)) ? 1 : 0;
  511. priv->rx_filter.fcs = (*total_flags & FIF_FCSFAIL) ? 1 : 0;
  512. priv->disable_beacon_filter = !(*total_flags &
  513. (FIF_BCN_PRBRESP_PROMISC |
  514. FIF_PROBE_REQ));
  515. if (priv->listening != listening) {
  516. priv->listening = listening;
  517. wsm_lock_tx(priv);
  518. cw1200_update_listening(priv, listening);
  519. wsm_unlock_tx(priv);
  520. }
  521. cw1200_update_filtering(priv);
  522. mutex_unlock(&priv->conf_mutex);
  523. up(&priv->scan.lock);
  524. }
  525. int cw1200_conf_tx(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
  526. u16 queue, const struct ieee80211_tx_queue_params *params)
  527. {
  528. struct cw1200_common *priv = dev->priv;
  529. int ret = 0;
  530. /* To prevent re-applying PM request OID again and again*/
  531. bool old_uapsd_flags;
  532. mutex_lock(&priv->conf_mutex);
  533. if (queue < dev->queues) {
  534. old_uapsd_flags = le16_to_cpu(priv->uapsd_info.uapsd_flags);
  535. WSM_TX_QUEUE_SET(&priv->tx_queue_params, queue, 0, 0, 0);
  536. ret = wsm_set_tx_queue_params(priv,
  537. &priv->tx_queue_params.params[queue], queue);
  538. if (ret) {
  539. ret = -EINVAL;
  540. goto out;
  541. }
  542. WSM_EDCA_SET(&priv->edca, queue, params->aifs,
  543. params->cw_min, params->cw_max,
  544. params->txop, 0xc8,
  545. params->uapsd);
  546. ret = wsm_set_edca_params(priv, &priv->edca);
  547. if (ret) {
  548. ret = -EINVAL;
  549. goto out;
  550. }
  551. if (priv->mode == NL80211_IFTYPE_STATION) {
  552. ret = cw1200_set_uapsd_param(priv, &priv->edca);
  553. if (!ret && priv->setbssparams_done &&
  554. (priv->join_status == CW1200_JOIN_STATUS_STA) &&
  555. (old_uapsd_flags != le16_to_cpu(priv->uapsd_info.uapsd_flags)))
  556. ret = cw1200_set_pm(priv, &priv->powersave_mode);
  557. }
  558. } else {
  559. ret = -EINVAL;
  560. }
  561. out:
  562. mutex_unlock(&priv->conf_mutex);
  563. return ret;
  564. }
  565. int cw1200_get_stats(struct ieee80211_hw *dev,
  566. struct ieee80211_low_level_stats *stats)
  567. {
  568. struct cw1200_common *priv = dev->priv;
  569. memcpy(stats, &priv->stats, sizeof(*stats));
  570. return 0;
  571. }
  572. int cw1200_set_pm(struct cw1200_common *priv, const struct wsm_set_pm *arg)
  573. {
  574. struct wsm_set_pm pm = *arg;
  575. if (priv->uapsd_info.uapsd_flags != 0)
  576. pm.mode &= ~WSM_PSM_FAST_PS_FLAG;
  577. if (memcmp(&pm, &priv->firmware_ps_mode,
  578. sizeof(struct wsm_set_pm))) {
  579. priv->firmware_ps_mode = pm;
  580. return wsm_set_pm(priv, &pm);
  581. } else {
  582. return 0;
  583. }
  584. }
  585. int cw1200_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
  586. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  587. struct ieee80211_key_conf *key)
  588. {
  589. int ret = -EOPNOTSUPP;
  590. struct cw1200_common *priv = dev->priv;
  591. struct ieee80211_key_seq seq;
  592. mutex_lock(&priv->conf_mutex);
  593. if (cmd == SET_KEY) {
  594. u8 *peer_addr = NULL;
  595. int pairwise = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) ?
  596. 1 : 0;
  597. int idx = cw1200_alloc_key(priv);
  598. struct wsm_add_key *wsm_key = &priv->keys[idx];
  599. if (idx < 0) {
  600. ret = -EINVAL;
  601. goto finally;
  602. }
  603. if (sta)
  604. peer_addr = sta->addr;
  605. key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE |
  606. IEEE80211_KEY_FLAG_RESERVE_TAILROOM;
  607. switch (key->cipher) {
  608. case WLAN_CIPHER_SUITE_WEP40:
  609. case WLAN_CIPHER_SUITE_WEP104:
  610. if (key->keylen > 16) {
  611. cw1200_free_key(priv, idx);
  612. ret = -EINVAL;
  613. goto finally;
  614. }
  615. if (pairwise) {
  616. wsm_key->type = WSM_KEY_TYPE_WEP_PAIRWISE;
  617. memcpy(wsm_key->wep_pairwise.peer,
  618. peer_addr, ETH_ALEN);
  619. memcpy(wsm_key->wep_pairwise.keydata,
  620. &key->key[0], key->keylen);
  621. wsm_key->wep_pairwise.keylen = key->keylen;
  622. } else {
  623. wsm_key->type = WSM_KEY_TYPE_WEP_DEFAULT;
  624. memcpy(wsm_key->wep_group.keydata,
  625. &key->key[0], key->keylen);
  626. wsm_key->wep_group.keylen = key->keylen;
  627. wsm_key->wep_group.keyid = key->keyidx;
  628. }
  629. break;
  630. case WLAN_CIPHER_SUITE_TKIP:
  631. ieee80211_get_key_rx_seq(key, 0, &seq);
  632. if (pairwise) {
  633. wsm_key->type = WSM_KEY_TYPE_TKIP_PAIRWISE;
  634. memcpy(wsm_key->tkip_pairwise.peer,
  635. peer_addr, ETH_ALEN);
  636. memcpy(wsm_key->tkip_pairwise.keydata,
  637. &key->key[0], 16);
  638. memcpy(wsm_key->tkip_pairwise.tx_mic_key,
  639. &key->key[16], 8);
  640. memcpy(wsm_key->tkip_pairwise.rx_mic_key,
  641. &key->key[24], 8);
  642. } else {
  643. size_t mic_offset =
  644. (priv->mode == NL80211_IFTYPE_AP) ?
  645. 16 : 24;
  646. wsm_key->type = WSM_KEY_TYPE_TKIP_GROUP;
  647. memcpy(wsm_key->tkip_group.keydata,
  648. &key->key[0], 16);
  649. memcpy(wsm_key->tkip_group.rx_mic_key,
  650. &key->key[mic_offset], 8);
  651. wsm_key->tkip_group.rx_seqnum[0] = seq.tkip.iv16 & 0xff;
  652. wsm_key->tkip_group.rx_seqnum[1] = (seq.tkip.iv16 >> 8) & 0xff;
  653. wsm_key->tkip_group.rx_seqnum[2] = seq.tkip.iv32 & 0xff;
  654. wsm_key->tkip_group.rx_seqnum[3] = (seq.tkip.iv32 >> 8) & 0xff;
  655. wsm_key->tkip_group.rx_seqnum[4] = (seq.tkip.iv32 >> 16) & 0xff;
  656. wsm_key->tkip_group.rx_seqnum[5] = (seq.tkip.iv32 >> 24) & 0xff;
  657. wsm_key->tkip_group.rx_seqnum[6] = 0;
  658. wsm_key->tkip_group.rx_seqnum[7] = 0;
  659. wsm_key->tkip_group.keyid = key->keyidx;
  660. }
  661. break;
  662. case WLAN_CIPHER_SUITE_CCMP:
  663. ieee80211_get_key_rx_seq(key, 0, &seq);
  664. if (pairwise) {
  665. wsm_key->type = WSM_KEY_TYPE_AES_PAIRWISE;
  666. memcpy(wsm_key->aes_pairwise.peer,
  667. peer_addr, ETH_ALEN);
  668. memcpy(wsm_key->aes_pairwise.keydata,
  669. &key->key[0], 16);
  670. } else {
  671. wsm_key->type = WSM_KEY_TYPE_AES_GROUP;
  672. memcpy(wsm_key->aes_group.keydata,
  673. &key->key[0], 16);
  674. wsm_key->aes_group.rx_seqnum[0] = seq.ccmp.pn[5];
  675. wsm_key->aes_group.rx_seqnum[1] = seq.ccmp.pn[4];
  676. wsm_key->aes_group.rx_seqnum[2] = seq.ccmp.pn[3];
  677. wsm_key->aes_group.rx_seqnum[3] = seq.ccmp.pn[2];
  678. wsm_key->aes_group.rx_seqnum[4] = seq.ccmp.pn[1];
  679. wsm_key->aes_group.rx_seqnum[5] = seq.ccmp.pn[0];
  680. wsm_key->aes_group.rx_seqnum[6] = 0;
  681. wsm_key->aes_group.rx_seqnum[7] = 0;
  682. wsm_key->aes_group.keyid = key->keyidx;
  683. }
  684. break;
  685. case WLAN_CIPHER_SUITE_SMS4:
  686. if (pairwise) {
  687. wsm_key->type = WSM_KEY_TYPE_WAPI_PAIRWISE;
  688. memcpy(wsm_key->wapi_pairwise.peer,
  689. peer_addr, ETH_ALEN);
  690. memcpy(wsm_key->wapi_pairwise.keydata,
  691. &key->key[0], 16);
  692. memcpy(wsm_key->wapi_pairwise.mic_key,
  693. &key->key[16], 16);
  694. wsm_key->wapi_pairwise.keyid = key->keyidx;
  695. } else {
  696. wsm_key->type = WSM_KEY_TYPE_WAPI_GROUP;
  697. memcpy(wsm_key->wapi_group.keydata,
  698. &key->key[0], 16);
  699. memcpy(wsm_key->wapi_group.mic_key,
  700. &key->key[16], 16);
  701. wsm_key->wapi_group.keyid = key->keyidx;
  702. }
  703. break;
  704. default:
  705. pr_warn("Unhandled key type %d\n", key->cipher);
  706. cw1200_free_key(priv, idx);
  707. ret = -EOPNOTSUPP;
  708. goto finally;
  709. }
  710. ret = wsm_add_key(priv, wsm_key);
  711. if (!ret)
  712. key->hw_key_idx = idx;
  713. else
  714. cw1200_free_key(priv, idx);
  715. } else if (cmd == DISABLE_KEY) {
  716. struct wsm_remove_key wsm_key = {
  717. .index = key->hw_key_idx,
  718. };
  719. if (wsm_key.index > WSM_KEY_MAX_INDEX) {
  720. ret = -EINVAL;
  721. goto finally;
  722. }
  723. cw1200_free_key(priv, wsm_key.index);
  724. ret = wsm_remove_key(priv, &wsm_key);
  725. } else {
  726. pr_warn("Unhandled key command %d\n", cmd);
  727. }
  728. finally:
  729. mutex_unlock(&priv->conf_mutex);
  730. return ret;
  731. }
  732. void cw1200_wep_key_work(struct work_struct *work)
  733. {
  734. struct cw1200_common *priv =
  735. container_of(work, struct cw1200_common, wep_key_work);
  736. u8 queue_id = cw1200_queue_get_queue_id(priv->pending_frame_id);
  737. struct cw1200_queue *queue = &priv->tx_queue[queue_id];
  738. __le32 wep_default_key_id = __cpu_to_le32(
  739. priv->wep_default_key_id);
  740. pr_debug("[STA] Setting default WEP key: %d\n",
  741. priv->wep_default_key_id);
  742. wsm_flush_tx(priv);
  743. wsm_write_mib(priv, WSM_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID,
  744. &wep_default_key_id, sizeof(wep_default_key_id));
  745. cw1200_queue_requeue(queue, priv->pending_frame_id);
  746. wsm_unlock_tx(priv);
  747. }
  748. int cw1200_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  749. {
  750. int ret = 0;
  751. __le32 val32;
  752. struct cw1200_common *priv = hw->priv;
  753. if (priv->mode == NL80211_IFTYPE_UNSPECIFIED)
  754. return 0;
  755. if (value != (u32) -1)
  756. val32 = __cpu_to_le32(value);
  757. else
  758. val32 = 0; /* disabled */
  759. if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) {
  760. /* device is down, can _not_ set threshold */
  761. ret = -ENODEV;
  762. goto out;
  763. }
  764. if (priv->rts_threshold == value)
  765. goto out;
  766. pr_debug("[STA] Setting RTS threshold: %d\n",
  767. priv->rts_threshold);
  768. /* mutex_lock(&priv->conf_mutex); */
  769. ret = wsm_write_mib(priv, WSM_MIB_ID_DOT11_RTS_THRESHOLD,
  770. &val32, sizeof(val32));
  771. if (!ret)
  772. priv->rts_threshold = value;
  773. /* mutex_unlock(&priv->conf_mutex); */
  774. out:
  775. return ret;
  776. }
  777. /* If successful, LOCKS the TX queue! */
  778. static int __cw1200_flush(struct cw1200_common *priv, bool drop)
  779. {
  780. int i, ret;
  781. for (;;) {
  782. /* TODO: correct flush handling is required when dev_stop.
  783. * Temporary workaround: 2s
  784. */
  785. if (drop) {
  786. for (i = 0; i < 4; ++i)
  787. cw1200_queue_clear(&priv->tx_queue[i]);
  788. } else {
  789. ret = wait_event_timeout(
  790. priv->tx_queue_stats.wait_link_id_empty,
  791. cw1200_queue_stats_is_empty(
  792. &priv->tx_queue_stats, -1),
  793. 2 * HZ);
  794. }
  795. if (!drop && ret <= 0) {
  796. ret = -ETIMEDOUT;
  797. break;
  798. } else {
  799. ret = 0;
  800. }
  801. wsm_lock_tx(priv);
  802. if (!cw1200_queue_stats_is_empty(&priv->tx_queue_stats, -1)) {
  803. /* Highly unlikely: WSM requeued frames. */
  804. wsm_unlock_tx(priv);
  805. continue;
  806. }
  807. break;
  808. }
  809. return ret;
  810. }
  811. void cw1200_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  812. u32 queues, bool drop)
  813. {
  814. struct cw1200_common *priv = hw->priv;
  815. switch (priv->mode) {
  816. case NL80211_IFTYPE_MONITOR:
  817. drop = true;
  818. break;
  819. case NL80211_IFTYPE_AP:
  820. if (!priv->enable_beacon)
  821. drop = true;
  822. break;
  823. }
  824. if (!__cw1200_flush(priv, drop))
  825. wsm_unlock_tx(priv);
  826. return;
  827. }
  828. /* ******************************************************************** */
  829. /* WSM callbacks */
  830. void cw1200_free_event_queue(struct cw1200_common *priv)
  831. {
  832. LIST_HEAD(list);
  833. spin_lock(&priv->event_queue_lock);
  834. list_splice_init(&priv->event_queue, &list);
  835. spin_unlock(&priv->event_queue_lock);
  836. __cw1200_free_event_queue(&list);
  837. }
  838. void cw1200_event_handler(struct work_struct *work)
  839. {
  840. struct cw1200_common *priv =
  841. container_of(work, struct cw1200_common, event_handler);
  842. struct cw1200_wsm_event *event;
  843. LIST_HEAD(list);
  844. spin_lock(&priv->event_queue_lock);
  845. list_splice_init(&priv->event_queue, &list);
  846. spin_unlock(&priv->event_queue_lock);
  847. list_for_each_entry(event, &list, link) {
  848. switch (event->evt.id) {
  849. case WSM_EVENT_ERROR:
  850. pr_err("Unhandled WSM Error from LMAC\n");
  851. break;
  852. case WSM_EVENT_BSS_LOST:
  853. pr_debug("[CQM] BSS lost.\n");
  854. cancel_work_sync(&priv->unjoin_work);
  855. if (!down_trylock(&priv->scan.lock)) {
  856. cw1200_cqm_bssloss_sm(priv, 1, 0, 0);
  857. up(&priv->scan.lock);
  858. } else {
  859. /* Scan is in progress. Delay reporting.
  860. * Scan complete will trigger bss_loss_work
  861. */
  862. priv->delayed_link_loss = 1;
  863. /* Also start a watchdog. */
  864. queue_delayed_work(priv->workqueue,
  865. &priv->bss_loss_work, 5*HZ);
  866. }
  867. break;
  868. case WSM_EVENT_BSS_REGAINED:
  869. pr_debug("[CQM] BSS regained.\n");
  870. cw1200_cqm_bssloss_sm(priv, 0, 0, 0);
  871. cancel_work_sync(&priv->unjoin_work);
  872. break;
  873. case WSM_EVENT_RADAR_DETECTED:
  874. wiphy_info(priv->hw->wiphy, "radar pulse detected\n");
  875. break;
  876. case WSM_EVENT_RCPI_RSSI:
  877. {
  878. /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
  879. * RSSI = RCPI / 2 - 110
  880. */
  881. int rcpi_rssi = (int)(event->evt.data & 0xFF);
  882. int cqm_evt;
  883. if (priv->cqm_use_rssi)
  884. rcpi_rssi = (s8)rcpi_rssi;
  885. else
  886. rcpi_rssi = rcpi_rssi / 2 - 110;
  887. cqm_evt = (rcpi_rssi <= priv->cqm_rssi_thold) ?
  888. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW :
  889. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
  890. pr_debug("[CQM] RSSI event: %d.\n", rcpi_rssi);
  891. ieee80211_cqm_rssi_notify(priv->vif, cqm_evt,
  892. GFP_KERNEL);
  893. break;
  894. }
  895. case WSM_EVENT_BT_INACTIVE:
  896. pr_warn("Unhandled BT INACTIVE from LMAC\n");
  897. break;
  898. case WSM_EVENT_BT_ACTIVE:
  899. pr_warn("Unhandled BT ACTIVE from LMAC\n");
  900. break;
  901. }
  902. }
  903. __cw1200_free_event_queue(&list);
  904. }
  905. void cw1200_bss_loss_work(struct work_struct *work)
  906. {
  907. struct cw1200_common *priv =
  908. container_of(work, struct cw1200_common, bss_loss_work.work);
  909. pr_debug("[CQM] Reporting connection loss.\n");
  910. wsm_lock_tx(priv);
  911. if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0)
  912. wsm_unlock_tx(priv);
  913. }
  914. void cw1200_bss_params_work(struct work_struct *work)
  915. {
  916. struct cw1200_common *priv =
  917. container_of(work, struct cw1200_common, bss_params_work);
  918. mutex_lock(&priv->conf_mutex);
  919. priv->bss_params.reset_beacon_loss = 1;
  920. wsm_set_bss_params(priv, &priv->bss_params);
  921. priv->bss_params.reset_beacon_loss = 0;
  922. mutex_unlock(&priv->conf_mutex);
  923. }
  924. /* ******************************************************************** */
  925. /* Internal API */
  926. /* This function is called to Parse the SDD file
  927. * to extract listen_interval and PTA related information
  928. * sdd is a TLV: u8 id, u8 len, u8 data[]
  929. */
  930. static int cw1200_parse_sdd_file(struct cw1200_common *priv)
  931. {
  932. const u8 *p = priv->sdd->data;
  933. int ret = 0;
  934. while (p + 2 <= priv->sdd->data + priv->sdd->size) {
  935. if (p + p[1] + 2 > priv->sdd->data + priv->sdd->size) {
  936. pr_warn("Malformed sdd structure\n");
  937. return -1;
  938. }
  939. switch (p[0]) {
  940. case SDD_PTA_CFG_ELT_ID: {
  941. u16 v;
  942. if (p[1] < 4) {
  943. pr_warn("SDD_PTA_CFG_ELT_ID malformed\n");
  944. ret = -1;
  945. break;
  946. }
  947. v = le16_to_cpu(*((__le16 *)(p + 2)));
  948. if (!v) /* non-zero means this is enabled */
  949. break;
  950. v = le16_to_cpu(*((__le16 *)(p + 4)));
  951. priv->conf_listen_interval = (v >> 7) & 0x1F;
  952. pr_debug("PTA found; Listen Interval %d\n",
  953. priv->conf_listen_interval);
  954. break;
  955. }
  956. case SDD_REFERENCE_FREQUENCY_ELT_ID: {
  957. u16 clk = le16_to_cpu(*((__le16 *)(p + 2)));
  958. if (clk != priv->hw_refclk)
  959. pr_warn("SDD file doesn't match configured refclk (%d vs %d)\n",
  960. clk, priv->hw_refclk);
  961. break;
  962. }
  963. default:
  964. break;
  965. }
  966. p += p[1] + 2;
  967. }
  968. if (!priv->bt_present) {
  969. pr_debug("PTA element NOT found.\n");
  970. priv->conf_listen_interval = 0;
  971. }
  972. return ret;
  973. }
  974. int cw1200_setup_mac(struct cw1200_common *priv)
  975. {
  976. int ret = 0;
  977. /* NOTE: There is a bug in FW: it reports signal
  978. * as RSSI if RSSI subscription is enabled.
  979. * It's not enough to set WSM_RCPI_RSSI_USE_RSSI.
  980. *
  981. * NOTE2: RSSI based reports have been switched to RCPI, since
  982. * FW has a bug and RSSI reported values are not stable,
  983. * what can leads to signal level oscilations in user-end applications
  984. */
  985. struct wsm_rcpi_rssi_threshold threshold = {
  986. .rssiRcpiMode = WSM_RCPI_RSSI_THRESHOLD_ENABLE |
  987. WSM_RCPI_RSSI_DONT_USE_UPPER |
  988. WSM_RCPI_RSSI_DONT_USE_LOWER,
  989. .rollingAverageCount = 16,
  990. };
  991. struct wsm_configuration cfg = {
  992. .dot11StationId = &priv->mac_addr[0],
  993. };
  994. /* Remember the decission here to make sure, we will handle
  995. * the RCPI/RSSI value correctly on WSM_EVENT_RCPI_RSS
  996. */
  997. if (threshold.rssiRcpiMode & WSM_RCPI_RSSI_USE_RSSI)
  998. priv->cqm_use_rssi = true;
  999. if (!priv->sdd) {
  1000. ret = request_firmware(&priv->sdd, priv->sdd_path, priv->pdev);
  1001. if (ret) {
  1002. pr_err("Can't load sdd file %s.\n", priv->sdd_path);
  1003. return ret;
  1004. }
  1005. cw1200_parse_sdd_file(priv);
  1006. }
  1007. cfg.dpdData = priv->sdd->data;
  1008. cfg.dpdData_size = priv->sdd->size;
  1009. ret = wsm_configuration(priv, &cfg);
  1010. if (ret)
  1011. return ret;
  1012. /* Configure RSSI/SCPI reporting as RSSI. */
  1013. wsm_set_rcpi_rssi_threshold(priv, &threshold);
  1014. return 0;
  1015. }
  1016. static void cw1200_join_complete(struct cw1200_common *priv)
  1017. {
  1018. pr_debug("[STA] Join complete (%d)\n", priv->join_complete_status);
  1019. priv->join_pending = false;
  1020. if (priv->join_complete_status) {
  1021. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  1022. cw1200_update_listening(priv, priv->listening);
  1023. cw1200_do_unjoin(priv);
  1024. ieee80211_connection_loss(priv->vif);
  1025. } else {
  1026. if (priv->mode == NL80211_IFTYPE_ADHOC)
  1027. priv->join_status = CW1200_JOIN_STATUS_IBSS;
  1028. else
  1029. priv->join_status = CW1200_JOIN_STATUS_PRE_STA;
  1030. }
  1031. wsm_unlock_tx(priv); /* Clearing the lock held before do_join() */
  1032. }
  1033. void cw1200_join_complete_work(struct work_struct *work)
  1034. {
  1035. struct cw1200_common *priv =
  1036. container_of(work, struct cw1200_common, join_complete_work);
  1037. mutex_lock(&priv->conf_mutex);
  1038. cw1200_join_complete(priv);
  1039. mutex_unlock(&priv->conf_mutex);
  1040. }
  1041. void cw1200_join_complete_cb(struct cw1200_common *priv,
  1042. struct wsm_join_complete *arg)
  1043. {
  1044. pr_debug("[STA] cw1200_join_complete_cb called, status=%d.\n",
  1045. arg->status);
  1046. if (cancel_delayed_work(&priv->join_timeout)) {
  1047. priv->join_complete_status = arg->status;
  1048. queue_work(priv->workqueue, &priv->join_complete_work);
  1049. }
  1050. }
  1051. /* MUST be called with tx_lock held! It will be unlocked for us. */
  1052. static void cw1200_do_join(struct cw1200_common *priv)
  1053. {
  1054. const u8 *bssid;
  1055. struct ieee80211_bss_conf *conf = &priv->vif->bss_conf;
  1056. struct cfg80211_bss *bss = NULL;
  1057. struct wsm_protected_mgmt_policy mgmt_policy;
  1058. struct wsm_join join = {
  1059. .mode = conf->ibss_joined ?
  1060. WSM_JOIN_MODE_IBSS : WSM_JOIN_MODE_BSS,
  1061. .preamble_type = WSM_JOIN_PREAMBLE_LONG,
  1062. .probe_for_join = 1,
  1063. .atim_window = 0,
  1064. .basic_rate_set = cw1200_rate_mask_to_wsm(priv,
  1065. conf->basic_rates),
  1066. };
  1067. if (delayed_work_pending(&priv->join_timeout)) {
  1068. pr_warn("[STA] - Join request already pending, skipping..\n");
  1069. wsm_unlock_tx(priv);
  1070. return;
  1071. }
  1072. if (priv->join_status)
  1073. cw1200_do_unjoin(priv);
  1074. bssid = priv->vif->bss_conf.bssid;
  1075. bss = cfg80211_get_bss(priv->hw->wiphy, priv->channel, bssid, NULL, 0,
  1076. IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
  1077. if (!bss && !conf->ibss_joined) {
  1078. wsm_unlock_tx(priv);
  1079. return;
  1080. }
  1081. mutex_lock(&priv->conf_mutex);
  1082. /* Under the conf lock: check scan status and
  1083. * bail out if it is in progress.
  1084. */
  1085. if (atomic_read(&priv->scan.in_progress)) {
  1086. wsm_unlock_tx(priv);
  1087. goto done_put;
  1088. }
  1089. priv->join_pending = true;
  1090. /* Sanity check basic rates */
  1091. if (!join.basic_rate_set)
  1092. join.basic_rate_set = 7;
  1093. /* Sanity check beacon interval */
  1094. if (!priv->beacon_int)
  1095. priv->beacon_int = 1;
  1096. join.beacon_interval = priv->beacon_int;
  1097. /* BT Coex related changes */
  1098. if (priv->bt_present) {
  1099. if (((priv->conf_listen_interval * 100) %
  1100. priv->beacon_int) == 0)
  1101. priv->listen_interval =
  1102. ((priv->conf_listen_interval * 100) /
  1103. priv->beacon_int);
  1104. else
  1105. priv->listen_interval =
  1106. ((priv->conf_listen_interval * 100) /
  1107. priv->beacon_int + 1);
  1108. }
  1109. if (priv->hw->conf.ps_dtim_period)
  1110. priv->join_dtim_period = priv->hw->conf.ps_dtim_period;
  1111. join.dtim_period = priv->join_dtim_period;
  1112. join.channel_number = priv->channel->hw_value;
  1113. join.band = (priv->channel->band == IEEE80211_BAND_5GHZ) ?
  1114. WSM_PHY_BAND_5G : WSM_PHY_BAND_2_4G;
  1115. memcpy(join.bssid, bssid, sizeof(join.bssid));
  1116. pr_debug("[STA] Join BSSID: %pM DTIM: %d, interval: %d\n",
  1117. join.bssid,
  1118. join.dtim_period, priv->beacon_int);
  1119. if (!conf->ibss_joined) {
  1120. const u8 *ssidie;
  1121. rcu_read_lock();
  1122. ssidie = ieee80211_bss_get_ie(bss, WLAN_EID_SSID);
  1123. if (ssidie) {
  1124. join.ssid_len = ssidie[1];
  1125. memcpy(join.ssid, &ssidie[2], join.ssid_len);
  1126. }
  1127. rcu_read_unlock();
  1128. }
  1129. if (priv->vif->p2p) {
  1130. join.flags |= WSM_JOIN_FLAGS_P2P_GO;
  1131. join.basic_rate_set =
  1132. cw1200_rate_mask_to_wsm(priv, 0xFF0);
  1133. }
  1134. /* Enable asynchronous join calls */
  1135. if (!conf->ibss_joined) {
  1136. join.flags |= WSM_JOIN_FLAGS_FORCE;
  1137. join.flags |= WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND;
  1138. }
  1139. wsm_flush_tx(priv);
  1140. /* Stay Awake for Join and Auth Timeouts and a bit more */
  1141. cw1200_pm_stay_awake(&priv->pm_state,
  1142. CW1200_JOIN_TIMEOUT + CW1200_AUTH_TIMEOUT);
  1143. cw1200_update_listening(priv, false);
  1144. /* Turn on Block ACKs */
  1145. wsm_set_block_ack_policy(priv, priv->ba_tx_tid_mask,
  1146. priv->ba_rx_tid_mask);
  1147. /* Set up timeout */
  1148. if (join.flags & WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND) {
  1149. priv->join_status = CW1200_JOIN_STATUS_JOINING;
  1150. queue_delayed_work(priv->workqueue,
  1151. &priv->join_timeout,
  1152. CW1200_JOIN_TIMEOUT);
  1153. }
  1154. /* 802.11w protected mgmt frames */
  1155. mgmt_policy.protectedMgmtEnable = 0;
  1156. mgmt_policy.unprotectedMgmtFramesAllowed = 1;
  1157. mgmt_policy.encryptionForAuthFrame = 1;
  1158. wsm_set_protected_mgmt_policy(priv, &mgmt_policy);
  1159. /* Perform actual join */
  1160. if (wsm_join(priv, &join)) {
  1161. pr_err("[STA] cw1200_join_work: wsm_join failed!\n");
  1162. cancel_delayed_work_sync(&priv->join_timeout);
  1163. cw1200_update_listening(priv, priv->listening);
  1164. /* Tx lock still held, unjoin will clear it. */
  1165. if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0)
  1166. wsm_unlock_tx(priv);
  1167. } else {
  1168. if (!(join.flags & WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND))
  1169. cw1200_join_complete(priv); /* Will clear tx_lock */
  1170. /* Upload keys */
  1171. cw1200_upload_keys(priv);
  1172. /* Due to beacon filtering it is possible that the
  1173. * AP's beacon is not known for the mac80211 stack.
  1174. * Disable filtering temporary to make sure the stack
  1175. * receives at least one
  1176. */
  1177. priv->disable_beacon_filter = true;
  1178. }
  1179. cw1200_update_filtering(priv);
  1180. done_put:
  1181. mutex_unlock(&priv->conf_mutex);
  1182. if (bss)
  1183. cfg80211_put_bss(priv->hw->wiphy, bss);
  1184. }
  1185. void cw1200_join_timeout(struct work_struct *work)
  1186. {
  1187. struct cw1200_common *priv =
  1188. container_of(work, struct cw1200_common, join_timeout.work);
  1189. pr_debug("[WSM] Join timed out.\n");
  1190. wsm_lock_tx(priv);
  1191. if (queue_work(priv->workqueue, &priv->unjoin_work) <= 0)
  1192. wsm_unlock_tx(priv);
  1193. }
  1194. static void cw1200_do_unjoin(struct cw1200_common *priv)
  1195. {
  1196. struct wsm_reset reset = {
  1197. .reset_statistics = true,
  1198. };
  1199. cancel_delayed_work_sync(&priv->join_timeout);
  1200. mutex_lock(&priv->conf_mutex);
  1201. priv->join_pending = false;
  1202. if (atomic_read(&priv->scan.in_progress)) {
  1203. if (priv->delayed_unjoin)
  1204. wiphy_dbg(priv->hw->wiphy, "Delayed unjoin is already scheduled.\n");
  1205. else
  1206. priv->delayed_unjoin = true;
  1207. goto done;
  1208. }
  1209. priv->delayed_link_loss = false;
  1210. if (!priv->join_status)
  1211. goto done;
  1212. if (priv->join_status == CW1200_JOIN_STATUS_AP)
  1213. goto done;
  1214. cancel_work_sync(&priv->update_filtering_work);
  1215. cancel_work_sync(&priv->set_beacon_wakeup_period_work);
  1216. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  1217. /* Unjoin is a reset. */
  1218. wsm_flush_tx(priv);
  1219. wsm_keep_alive_period(priv, 0);
  1220. wsm_reset(priv, &reset);
  1221. wsm_set_output_power(priv, priv->output_power * 10);
  1222. priv->join_dtim_period = 0;
  1223. cw1200_setup_mac(priv);
  1224. cw1200_free_event_queue(priv);
  1225. cancel_work_sync(&priv->event_handler);
  1226. cw1200_update_listening(priv, priv->listening);
  1227. cw1200_cqm_bssloss_sm(priv, 0, 0, 0);
  1228. /* Disable Block ACKs */
  1229. wsm_set_block_ack_policy(priv, 0, 0);
  1230. priv->disable_beacon_filter = false;
  1231. cw1200_update_filtering(priv);
  1232. memset(&priv->association_mode, 0,
  1233. sizeof(priv->association_mode));
  1234. memset(&priv->bss_params, 0, sizeof(priv->bss_params));
  1235. priv->setbssparams_done = false;
  1236. memset(&priv->firmware_ps_mode, 0,
  1237. sizeof(priv->firmware_ps_mode));
  1238. pr_debug("[STA] Unjoin completed.\n");
  1239. done:
  1240. mutex_unlock(&priv->conf_mutex);
  1241. }
  1242. void cw1200_unjoin_work(struct work_struct *work)
  1243. {
  1244. struct cw1200_common *priv =
  1245. container_of(work, struct cw1200_common, unjoin_work);
  1246. cw1200_do_unjoin(priv);
  1247. /* Tell the stack we're dead */
  1248. ieee80211_connection_loss(priv->vif);
  1249. wsm_unlock_tx(priv);
  1250. }
  1251. int cw1200_enable_listening(struct cw1200_common *priv)
  1252. {
  1253. struct wsm_start start = {
  1254. .mode = WSM_START_MODE_P2P_DEV,
  1255. .band = WSM_PHY_BAND_2_4G,
  1256. .beacon_interval = 100,
  1257. .dtim_period = 1,
  1258. .probe_delay = 0,
  1259. .basic_rate_set = 0x0F,
  1260. };
  1261. if (priv->channel) {
  1262. start.band = priv->channel->band == IEEE80211_BAND_5GHZ ?
  1263. WSM_PHY_BAND_5G : WSM_PHY_BAND_2_4G;
  1264. start.channel_number = priv->channel->hw_value;
  1265. } else {
  1266. start.band = WSM_PHY_BAND_2_4G;
  1267. start.channel_number = 1;
  1268. }
  1269. return wsm_start(priv, &start);
  1270. }
  1271. int cw1200_disable_listening(struct cw1200_common *priv)
  1272. {
  1273. int ret;
  1274. struct wsm_reset reset = {
  1275. .reset_statistics = true,
  1276. };
  1277. ret = wsm_reset(priv, &reset);
  1278. return ret;
  1279. }
  1280. void cw1200_update_listening(struct cw1200_common *priv, bool enabled)
  1281. {
  1282. if (enabled) {
  1283. if (priv->join_status == CW1200_JOIN_STATUS_PASSIVE) {
  1284. if (!cw1200_enable_listening(priv))
  1285. priv->join_status = CW1200_JOIN_STATUS_MONITOR;
  1286. wsm_set_probe_responder(priv, true);
  1287. }
  1288. } else {
  1289. if (priv->join_status == CW1200_JOIN_STATUS_MONITOR) {
  1290. if (!cw1200_disable_listening(priv))
  1291. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  1292. wsm_set_probe_responder(priv, false);
  1293. }
  1294. }
  1295. }
  1296. int cw1200_set_uapsd_param(struct cw1200_common *priv,
  1297. const struct wsm_edca_params *arg)
  1298. {
  1299. int ret;
  1300. u16 uapsd_flags = 0;
  1301. /* Here's the mapping AC [queue, bit]
  1302. * VO [0,3], VI [1, 2], BE [2, 1], BK [3, 0]
  1303. */
  1304. if (arg->uapsd_enable[0])
  1305. uapsd_flags |= 1 << 3;
  1306. if (arg->uapsd_enable[1])
  1307. uapsd_flags |= 1 << 2;
  1308. if (arg->uapsd_enable[2])
  1309. uapsd_flags |= 1 << 1;
  1310. if (arg->uapsd_enable[3])
  1311. uapsd_flags |= 1;
  1312. /* Currently pseudo U-APSD operation is not supported, so setting
  1313. * MinAutoTriggerInterval, MaxAutoTriggerInterval and
  1314. * AutoTriggerStep to 0
  1315. */
  1316. priv->uapsd_info.uapsd_flags = cpu_to_le16(uapsd_flags);
  1317. priv->uapsd_info.min_auto_trigger_interval = 0;
  1318. priv->uapsd_info.max_auto_trigger_interval = 0;
  1319. priv->uapsd_info.auto_trigger_step = 0;
  1320. ret = wsm_set_uapsd_info(priv, &priv->uapsd_info);
  1321. return ret;
  1322. }
  1323. /* ******************************************************************** */
  1324. /* AP API */
  1325. int cw1200_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1326. struct ieee80211_sta *sta)
  1327. {
  1328. struct cw1200_common *priv = hw->priv;
  1329. struct cw1200_sta_priv *sta_priv =
  1330. (struct cw1200_sta_priv *)&sta->drv_priv;
  1331. struct cw1200_link_entry *entry;
  1332. struct sk_buff *skb;
  1333. if (priv->mode != NL80211_IFTYPE_AP)
  1334. return 0;
  1335. sta_priv->link_id = cw1200_find_link_id(priv, sta->addr);
  1336. if (WARN_ON(!sta_priv->link_id)) {
  1337. wiphy_info(priv->hw->wiphy,
  1338. "[AP] No more link IDs available.\n");
  1339. return -ENOENT;
  1340. }
  1341. entry = &priv->link_id_db[sta_priv->link_id - 1];
  1342. spin_lock_bh(&priv->ps_state_lock);
  1343. if ((sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) ==
  1344. IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
  1345. priv->sta_asleep_mask |= BIT(sta_priv->link_id);
  1346. entry->status = CW1200_LINK_HARD;
  1347. while ((skb = skb_dequeue(&entry->rx_queue)))
  1348. ieee80211_rx_irqsafe(priv->hw, skb);
  1349. spin_unlock_bh(&priv->ps_state_lock);
  1350. return 0;
  1351. }
  1352. int cw1200_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  1353. struct ieee80211_sta *sta)
  1354. {
  1355. struct cw1200_common *priv = hw->priv;
  1356. struct cw1200_sta_priv *sta_priv =
  1357. (struct cw1200_sta_priv *)&sta->drv_priv;
  1358. struct cw1200_link_entry *entry;
  1359. if (priv->mode != NL80211_IFTYPE_AP || !sta_priv->link_id)
  1360. return 0;
  1361. entry = &priv->link_id_db[sta_priv->link_id - 1];
  1362. spin_lock_bh(&priv->ps_state_lock);
  1363. entry->status = CW1200_LINK_RESERVE;
  1364. entry->timestamp = jiffies;
  1365. wsm_lock_tx_async(priv);
  1366. if (queue_work(priv->workqueue, &priv->link_id_work) <= 0)
  1367. wsm_unlock_tx(priv);
  1368. spin_unlock_bh(&priv->ps_state_lock);
  1369. flush_workqueue(priv->workqueue);
  1370. return 0;
  1371. }
  1372. static void __cw1200_sta_notify(struct ieee80211_hw *dev,
  1373. struct ieee80211_vif *vif,
  1374. enum sta_notify_cmd notify_cmd,
  1375. int link_id)
  1376. {
  1377. struct cw1200_common *priv = dev->priv;
  1378. u32 bit, prev;
  1379. /* Zero link id means "for all link IDs" */
  1380. if (link_id)
  1381. bit = BIT(link_id);
  1382. else if (WARN_ON_ONCE(notify_cmd != STA_NOTIFY_AWAKE))
  1383. bit = 0;
  1384. else
  1385. bit = priv->link_id_map;
  1386. prev = priv->sta_asleep_mask & bit;
  1387. switch (notify_cmd) {
  1388. case STA_NOTIFY_SLEEP:
  1389. if (!prev) {
  1390. if (priv->buffered_multicasts &&
  1391. !priv->sta_asleep_mask)
  1392. queue_work(priv->workqueue,
  1393. &priv->multicast_start_work);
  1394. priv->sta_asleep_mask |= bit;
  1395. }
  1396. break;
  1397. case STA_NOTIFY_AWAKE:
  1398. if (prev) {
  1399. priv->sta_asleep_mask &= ~bit;
  1400. priv->pspoll_mask &= ~bit;
  1401. if (priv->tx_multicast && link_id &&
  1402. !priv->sta_asleep_mask)
  1403. queue_work(priv->workqueue,
  1404. &priv->multicast_stop_work);
  1405. cw1200_bh_wakeup(priv);
  1406. }
  1407. break;
  1408. }
  1409. }
  1410. void cw1200_sta_notify(struct ieee80211_hw *dev,
  1411. struct ieee80211_vif *vif,
  1412. enum sta_notify_cmd notify_cmd,
  1413. struct ieee80211_sta *sta)
  1414. {
  1415. struct cw1200_common *priv = dev->priv;
  1416. struct cw1200_sta_priv *sta_priv =
  1417. (struct cw1200_sta_priv *)&sta->drv_priv;
  1418. spin_lock_bh(&priv->ps_state_lock);
  1419. __cw1200_sta_notify(dev, vif, notify_cmd, sta_priv->link_id);
  1420. spin_unlock_bh(&priv->ps_state_lock);
  1421. }
  1422. static void cw1200_ps_notify(struct cw1200_common *priv,
  1423. int link_id, bool ps)
  1424. {
  1425. if (link_id > CW1200_MAX_STA_IN_AP_MODE)
  1426. return;
  1427. pr_debug("%s for LinkId: %d. STAs asleep: %.8X\n",
  1428. ps ? "Stop" : "Start",
  1429. link_id, priv->sta_asleep_mask);
  1430. __cw1200_sta_notify(priv->hw, priv->vif,
  1431. ps ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE, link_id);
  1432. }
  1433. static int cw1200_set_tim_impl(struct cw1200_common *priv, bool aid0_bit_set)
  1434. {
  1435. struct sk_buff *skb;
  1436. struct wsm_update_ie update_ie = {
  1437. .what = WSM_UPDATE_IE_BEACON,
  1438. .count = 1,
  1439. };
  1440. u16 tim_offset, tim_length;
  1441. pr_debug("[AP] mcast: %s.\n", aid0_bit_set ? "ena" : "dis");
  1442. skb = ieee80211_beacon_get_tim(priv->hw, priv->vif,
  1443. &tim_offset, &tim_length);
  1444. if (!skb) {
  1445. if (!__cw1200_flush(priv, true))
  1446. wsm_unlock_tx(priv);
  1447. return -ENOENT;
  1448. }
  1449. if (tim_offset && tim_length >= 6) {
  1450. /* Ignore DTIM count from mac80211:
  1451. * firmware handles DTIM internally.
  1452. */
  1453. skb->data[tim_offset + 2] = 0;
  1454. /* Set/reset aid0 bit */
  1455. if (aid0_bit_set)
  1456. skb->data[tim_offset + 4] |= 1;
  1457. else
  1458. skb->data[tim_offset + 4] &= ~1;
  1459. }
  1460. update_ie.ies = &skb->data[tim_offset];
  1461. update_ie.length = tim_length;
  1462. wsm_update_ie(priv, &update_ie);
  1463. dev_kfree_skb(skb);
  1464. return 0;
  1465. }
  1466. void cw1200_set_tim_work(struct work_struct *work)
  1467. {
  1468. struct cw1200_common *priv =
  1469. container_of(work, struct cw1200_common, set_tim_work);
  1470. (void)cw1200_set_tim_impl(priv, priv->aid0_bit_set);
  1471. }
  1472. int cw1200_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
  1473. bool set)
  1474. {
  1475. struct cw1200_common *priv = dev->priv;
  1476. queue_work(priv->workqueue, &priv->set_tim_work);
  1477. return 0;
  1478. }
  1479. void cw1200_set_cts_work(struct work_struct *work)
  1480. {
  1481. struct cw1200_common *priv =
  1482. container_of(work, struct cw1200_common, set_cts_work);
  1483. u8 erp_ie[3] = {WLAN_EID_ERP_INFO, 0x1, 0};
  1484. struct wsm_update_ie update_ie = {
  1485. .what = WSM_UPDATE_IE_BEACON,
  1486. .count = 1,
  1487. .ies = erp_ie,
  1488. .length = 3,
  1489. };
  1490. u32 erp_info;
  1491. __le32 use_cts_prot;
  1492. mutex_lock(&priv->conf_mutex);
  1493. erp_info = priv->erp_info;
  1494. mutex_unlock(&priv->conf_mutex);
  1495. use_cts_prot =
  1496. erp_info & WLAN_ERP_USE_PROTECTION ?
  1497. __cpu_to_le32(1) : 0;
  1498. erp_ie[ERP_INFO_BYTE_OFFSET] = erp_info;
  1499. pr_debug("[STA] ERP information 0x%x\n", erp_info);
  1500. wsm_write_mib(priv, WSM_MIB_ID_NON_ERP_PROTECTION,
  1501. &use_cts_prot, sizeof(use_cts_prot));
  1502. wsm_update_ie(priv, &update_ie);
  1503. return;
  1504. }
  1505. static int cw1200_set_btcoexinfo(struct cw1200_common *priv)
  1506. {
  1507. struct wsm_override_internal_txrate arg;
  1508. int ret = 0;
  1509. if (priv->mode == NL80211_IFTYPE_STATION) {
  1510. /* Plumb PSPOLL and NULL template */
  1511. cw1200_upload_pspoll(priv);
  1512. cw1200_upload_null(priv);
  1513. cw1200_upload_qosnull(priv);
  1514. } else {
  1515. return 0;
  1516. }
  1517. memset(&arg, 0, sizeof(struct wsm_override_internal_txrate));
  1518. if (!priv->vif->p2p) {
  1519. /* STATION mode */
  1520. if (priv->bss_params.operational_rate_set & ~0xF) {
  1521. pr_debug("[STA] STA has ERP rates\n");
  1522. /* G or BG mode */
  1523. arg.internalTxRate = (__ffs(
  1524. priv->bss_params.operational_rate_set & ~0xF));
  1525. } else {
  1526. pr_debug("[STA] STA has non ERP rates\n");
  1527. /* B only mode */
  1528. arg.internalTxRate = (__ffs(le32_to_cpu(priv->association_mode.basic_rate_set)));
  1529. }
  1530. arg.nonErpInternalTxRate = (__ffs(le32_to_cpu(priv->association_mode.basic_rate_set)));
  1531. } else {
  1532. /* P2P mode */
  1533. arg.internalTxRate = (__ffs(priv->bss_params.operational_rate_set & ~0xF));
  1534. arg.nonErpInternalTxRate = (__ffs(priv->bss_params.operational_rate_set & ~0xF));
  1535. }
  1536. pr_debug("[STA] BTCOEX_INFO MODE %d, internalTxRate : %x, nonErpInternalTxRate: %x\n",
  1537. priv->mode,
  1538. arg.internalTxRate,
  1539. arg.nonErpInternalTxRate);
  1540. ret = wsm_write_mib(priv, WSM_MIB_ID_OVERRIDE_INTERNAL_TX_RATE,
  1541. &arg, sizeof(arg));
  1542. return ret;
  1543. }
  1544. void cw1200_bss_info_changed(struct ieee80211_hw *dev,
  1545. struct ieee80211_vif *vif,
  1546. struct ieee80211_bss_conf *info,
  1547. u32 changed)
  1548. {
  1549. struct cw1200_common *priv = dev->priv;
  1550. bool do_join = false;
  1551. mutex_lock(&priv->conf_mutex);
  1552. pr_debug("BSS CHANGED: %08x\n", changed);
  1553. /* TODO: BSS_CHANGED_QOS */
  1554. /* TODO: BSS_CHANGED_TXPOWER */
  1555. if (changed & BSS_CHANGED_ARP_FILTER) {
  1556. struct wsm_mib_arp_ipv4_filter filter = {0};
  1557. int i;
  1558. pr_debug("[STA] BSS_CHANGED_ARP_FILTER cnt: %d\n",
  1559. info->arp_addr_cnt);
  1560. /* Currently only one IP address is supported by firmware.
  1561. * In case of more IPs arp filtering will be disabled.
  1562. */
  1563. if (info->arp_addr_cnt > 0 &&
  1564. info->arp_addr_cnt <= WSM_MAX_ARP_IP_ADDRTABLE_ENTRIES) {
  1565. for (i = 0; i < info->arp_addr_cnt; i++) {
  1566. filter.ipv4addrs[i] = info->arp_addr_list[i];
  1567. pr_debug("[STA] addr[%d]: 0x%X\n",
  1568. i, filter.ipv4addrs[i]);
  1569. }
  1570. filter.enable = __cpu_to_le32(1);
  1571. }
  1572. pr_debug("[STA] arp ip filter enable: %d\n",
  1573. __le32_to_cpu(filter.enable));
  1574. wsm_set_arp_ipv4_filter(priv, &filter);
  1575. }
  1576. if (changed &
  1577. (BSS_CHANGED_BEACON |
  1578. BSS_CHANGED_AP_PROBE_RESP |
  1579. BSS_CHANGED_BSSID |
  1580. BSS_CHANGED_SSID |
  1581. BSS_CHANGED_IBSS)) {
  1582. pr_debug("BSS_CHANGED_BEACON\n");
  1583. priv->beacon_int = info->beacon_int;
  1584. cw1200_update_beaconing(priv);
  1585. cw1200_upload_beacon(priv);
  1586. }
  1587. if (changed & BSS_CHANGED_BEACON_ENABLED) {
  1588. pr_debug("BSS_CHANGED_BEACON_ENABLED (%d)\n", info->enable_beacon);
  1589. if (priv->enable_beacon != info->enable_beacon) {
  1590. cw1200_enable_beaconing(priv, info->enable_beacon);
  1591. priv->enable_beacon = info->enable_beacon;
  1592. }
  1593. }
  1594. if (changed & BSS_CHANGED_BEACON_INT) {
  1595. pr_debug("CHANGED_BEACON_INT\n");
  1596. if (info->ibss_joined)
  1597. do_join = true;
  1598. else if (priv->join_status == CW1200_JOIN_STATUS_AP)
  1599. cw1200_update_beaconing(priv);
  1600. }
  1601. /* assoc/disassoc, or maybe AID changed */
  1602. if (changed & BSS_CHANGED_ASSOC) {
  1603. wsm_lock_tx(priv);
  1604. priv->wep_default_key_id = -1;
  1605. wsm_unlock_tx(priv);
  1606. }
  1607. if (changed & BSS_CHANGED_BSSID) {
  1608. pr_debug("BSS_CHANGED_BSSID\n");
  1609. do_join = true;
  1610. }
  1611. if (changed &
  1612. (BSS_CHANGED_ASSOC |
  1613. BSS_CHANGED_BSSID |
  1614. BSS_CHANGED_IBSS |
  1615. BSS_CHANGED_BASIC_RATES |
  1616. BSS_CHANGED_HT)) {
  1617. pr_debug("BSS_CHANGED_ASSOC\n");
  1618. if (info->assoc) {
  1619. if (priv->join_status < CW1200_JOIN_STATUS_PRE_STA) {
  1620. ieee80211_connection_loss(vif);
  1621. mutex_unlock(&priv->conf_mutex);
  1622. return;
  1623. } else if (priv->join_status == CW1200_JOIN_STATUS_PRE_STA) {
  1624. priv->join_status = CW1200_JOIN_STATUS_STA;
  1625. }
  1626. } else {
  1627. do_join = true;
  1628. }
  1629. if (info->assoc || info->ibss_joined) {
  1630. struct ieee80211_sta *sta = NULL;
  1631. __le32 htprot = 0;
  1632. if (info->dtim_period)
  1633. priv->join_dtim_period = info->dtim_period;
  1634. priv->beacon_int = info->beacon_int;
  1635. rcu_read_lock();
  1636. if (info->bssid && !info->ibss_joined)
  1637. sta = ieee80211_find_sta(vif, info->bssid);
  1638. if (sta) {
  1639. priv->ht_info.ht_cap = sta->ht_cap;
  1640. priv->bss_params.operational_rate_set =
  1641. cw1200_rate_mask_to_wsm(priv,
  1642. sta->supp_rates[priv->channel->band]);
  1643. priv->ht_info.channel_type = cfg80211_get_chandef_type(&dev->conf.chandef);
  1644. priv->ht_info.operation_mode = info->ht_operation_mode;
  1645. } else {
  1646. memset(&priv->ht_info, 0,
  1647. sizeof(priv->ht_info));
  1648. priv->bss_params.operational_rate_set = -1;
  1649. }
  1650. rcu_read_unlock();
  1651. /* Non Greenfield stations present */
  1652. if (priv->ht_info.operation_mode &
  1653. IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)
  1654. htprot |= cpu_to_le32(WSM_NON_GREENFIELD_STA_PRESENT);
  1655. /* Set HT protection method */
  1656. htprot |= cpu_to_le32((priv->ht_info.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION) << 2);
  1657. /* TODO:
  1658. * STBC_param.dual_cts
  1659. * STBC_param.LSIG_TXOP_FILL
  1660. */
  1661. wsm_write_mib(priv, WSM_MIB_ID_SET_HT_PROTECTION,
  1662. &htprot, sizeof(htprot));
  1663. priv->association_mode.greenfield =
  1664. cw1200_ht_greenfield(&priv->ht_info);
  1665. priv->association_mode.flags =
  1666. WSM_ASSOCIATION_MODE_SNOOP_ASSOC_FRAMES |
  1667. WSM_ASSOCIATION_MODE_USE_PREAMBLE_TYPE |
  1668. WSM_ASSOCIATION_MODE_USE_HT_MODE |
  1669. WSM_ASSOCIATION_MODE_USE_BASIC_RATE_SET |
  1670. WSM_ASSOCIATION_MODE_USE_MPDU_START_SPACING;
  1671. priv->association_mode.preamble =
  1672. info->use_short_preamble ?
  1673. WSM_JOIN_PREAMBLE_SHORT :
  1674. WSM_JOIN_PREAMBLE_LONG;
  1675. priv->association_mode.basic_rate_set = __cpu_to_le32(
  1676. cw1200_rate_mask_to_wsm(priv,
  1677. info->basic_rates));
  1678. priv->association_mode.mpdu_start_spacing =
  1679. cw1200_ht_ampdu_density(&priv->ht_info);
  1680. cw1200_cqm_bssloss_sm(priv, 0, 0, 0);
  1681. cancel_work_sync(&priv->unjoin_work);
  1682. priv->bss_params.beacon_lost_count = priv->cqm_beacon_loss_count;
  1683. priv->bss_params.aid = info->aid;
  1684. if (priv->join_dtim_period < 1)
  1685. priv->join_dtim_period = 1;
  1686. pr_debug("[STA] DTIM %d, interval: %d\n",
  1687. priv->join_dtim_period, priv->beacon_int);
  1688. pr_debug("[STA] Preamble: %d, Greenfield: %d, Aid: %d, Rates: 0x%.8X, Basic: 0x%.8X\n",
  1689. priv->association_mode.preamble,
  1690. priv->association_mode.greenfield,
  1691. priv->bss_params.aid,
  1692. priv->bss_params.operational_rate_set,
  1693. priv->association_mode.basic_rate_set);
  1694. wsm_set_association_mode(priv, &priv->association_mode);
  1695. if (!info->ibss_joined) {
  1696. wsm_keep_alive_period(priv, 30 /* sec */);
  1697. wsm_set_bss_params(priv, &priv->bss_params);
  1698. priv->setbssparams_done = true;
  1699. cw1200_set_beacon_wakeup_period_work(&priv->set_beacon_wakeup_period_work);
  1700. cw1200_set_pm(priv, &priv->powersave_mode);
  1701. }
  1702. if (priv->vif->p2p) {
  1703. pr_debug("[STA] Setting p2p powersave configuration.\n");
  1704. wsm_set_p2p_ps_modeinfo(priv,
  1705. &priv->p2p_ps_modeinfo);
  1706. }
  1707. if (priv->bt_present)
  1708. cw1200_set_btcoexinfo(priv);
  1709. } else {
  1710. memset(&priv->association_mode, 0,
  1711. sizeof(priv->association_mode));
  1712. memset(&priv->bss_params, 0, sizeof(priv->bss_params));
  1713. }
  1714. }
  1715. /* ERP Protection */
  1716. if (changed & (BSS_CHANGED_ASSOC |
  1717. BSS_CHANGED_ERP_CTS_PROT |
  1718. BSS_CHANGED_ERP_PREAMBLE)) {
  1719. u32 prev_erp_info = priv->erp_info;
  1720. if (info->use_cts_prot)
  1721. priv->erp_info |= WLAN_ERP_USE_PROTECTION;
  1722. else if (!(prev_erp_info & WLAN_ERP_NON_ERP_PRESENT))
  1723. priv->erp_info &= ~WLAN_ERP_USE_PROTECTION;
  1724. if (info->use_short_preamble)
  1725. priv->erp_info |= WLAN_ERP_BARKER_PREAMBLE;
  1726. else
  1727. priv->erp_info &= ~WLAN_ERP_BARKER_PREAMBLE;
  1728. pr_debug("[STA] ERP Protection: %x\n", priv->erp_info);
  1729. if (prev_erp_info != priv->erp_info)
  1730. queue_work(priv->workqueue, &priv->set_cts_work);
  1731. }
  1732. /* ERP Slottime */
  1733. if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_SLOT)) {
  1734. __le32 slot_time = info->use_short_slot ?
  1735. __cpu_to_le32(9) : __cpu_to_le32(20);
  1736. pr_debug("[STA] Slot time: %d us.\n",
  1737. __le32_to_cpu(slot_time));
  1738. wsm_write_mib(priv, WSM_MIB_ID_DOT11_SLOT_TIME,
  1739. &slot_time, sizeof(slot_time));
  1740. }
  1741. if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_CQM)) {
  1742. struct wsm_rcpi_rssi_threshold threshold = {
  1743. .rollingAverageCount = 8,
  1744. };
  1745. pr_debug("[CQM] RSSI threshold subscribe: %d +- %d\n",
  1746. info->cqm_rssi_thold, info->cqm_rssi_hyst);
  1747. priv->cqm_rssi_thold = info->cqm_rssi_thold;
  1748. priv->cqm_rssi_hyst = info->cqm_rssi_hyst;
  1749. if (info->cqm_rssi_thold || info->cqm_rssi_hyst) {
  1750. /* RSSI subscription enabled */
  1751. /* TODO: It's not a correct way of setting threshold.
  1752. * Upper and lower must be set equal here and adjusted
  1753. * in callback. However current implementation is much
  1754. * more relaible and stable.
  1755. */
  1756. /* RSSI: signed Q8.0, RCPI: unsigned Q7.1
  1757. * RSSI = RCPI / 2 - 110
  1758. */
  1759. if (priv->cqm_use_rssi) {
  1760. threshold.upperThreshold =
  1761. info->cqm_rssi_thold + info->cqm_rssi_hyst;
  1762. threshold.lowerThreshold =
  1763. info->cqm_rssi_thold;
  1764. threshold.rssiRcpiMode |= WSM_RCPI_RSSI_USE_RSSI;
  1765. } else {
  1766. threshold.upperThreshold = (info->cqm_rssi_thold + info->cqm_rssi_hyst + 110) * 2;
  1767. threshold.lowerThreshold = (info->cqm_rssi_thold + 110) * 2;
  1768. }
  1769. threshold.rssiRcpiMode |= WSM_RCPI_RSSI_THRESHOLD_ENABLE;
  1770. } else {
  1771. /* There is a bug in FW, see sta.c. We have to enable
  1772. * dummy subscription to get correct RSSI values.
  1773. */
  1774. threshold.rssiRcpiMode |=
  1775. WSM_RCPI_RSSI_THRESHOLD_ENABLE |
  1776. WSM_RCPI_RSSI_DONT_USE_UPPER |
  1777. WSM_RCPI_RSSI_DONT_USE_LOWER;
  1778. if (priv->cqm_use_rssi)
  1779. threshold.rssiRcpiMode |= WSM_RCPI_RSSI_USE_RSSI;
  1780. }
  1781. wsm_set_rcpi_rssi_threshold(priv, &threshold);
  1782. }
  1783. mutex_unlock(&priv->conf_mutex);
  1784. if (do_join) {
  1785. wsm_lock_tx(priv);
  1786. cw1200_do_join(priv); /* Will unlock it for us */
  1787. }
  1788. }
  1789. void cw1200_multicast_start_work(struct work_struct *work)
  1790. {
  1791. struct cw1200_common *priv =
  1792. container_of(work, struct cw1200_common, multicast_start_work);
  1793. long tmo = priv->join_dtim_period *
  1794. (priv->beacon_int + 20) * HZ / 1024;
  1795. cancel_work_sync(&priv->multicast_stop_work);
  1796. if (!priv->aid0_bit_set) {
  1797. wsm_lock_tx(priv);
  1798. cw1200_set_tim_impl(priv, true);
  1799. priv->aid0_bit_set = true;
  1800. mod_timer(&priv->mcast_timeout, jiffies + tmo);
  1801. wsm_unlock_tx(priv);
  1802. }
  1803. }
  1804. void cw1200_multicast_stop_work(struct work_struct *work)
  1805. {
  1806. struct cw1200_common *priv =
  1807. container_of(work, struct cw1200_common, multicast_stop_work);
  1808. if (priv->aid0_bit_set) {
  1809. del_timer_sync(&priv->mcast_timeout);
  1810. wsm_lock_tx(priv);
  1811. priv->aid0_bit_set = false;
  1812. cw1200_set_tim_impl(priv, false);
  1813. wsm_unlock_tx(priv);
  1814. }
  1815. }
  1816. void cw1200_mcast_timeout(unsigned long arg)
  1817. {
  1818. struct cw1200_common *priv =
  1819. (struct cw1200_common *)arg;
  1820. wiphy_warn(priv->hw->wiphy,
  1821. "Multicast delivery timeout.\n");
  1822. spin_lock_bh(&priv->ps_state_lock);
  1823. priv->tx_multicast = priv->aid0_bit_set &&
  1824. priv->buffered_multicasts;
  1825. if (priv->tx_multicast)
  1826. cw1200_bh_wakeup(priv);
  1827. spin_unlock_bh(&priv->ps_state_lock);
  1828. }
  1829. int cw1200_ampdu_action(struct ieee80211_hw *hw,
  1830. struct ieee80211_vif *vif,
  1831. struct ieee80211_ampdu_params *params)
  1832. {
  1833. /* Aggregation is implemented fully in firmware,
  1834. * including block ack negotiation. Do not allow
  1835. * mac80211 stack to do anything: it interferes with
  1836. * the firmware.
  1837. */
  1838. /* Note that we still need this function stubbed. */
  1839. return -ENOTSUPP;
  1840. }
  1841. /* ******************************************************************** */
  1842. /* WSM callback */
  1843. void cw1200_suspend_resume(struct cw1200_common *priv,
  1844. struct wsm_suspend_resume *arg)
  1845. {
  1846. pr_debug("[AP] %s: %s\n",
  1847. arg->stop ? "stop" : "start",
  1848. arg->multicast ? "broadcast" : "unicast");
  1849. if (arg->multicast) {
  1850. bool cancel_tmo = false;
  1851. spin_lock_bh(&priv->ps_state_lock);
  1852. if (arg->stop) {
  1853. priv->tx_multicast = false;
  1854. } else {
  1855. /* Firmware sends this indication every DTIM if there
  1856. * is a STA in powersave connected. There is no reason
  1857. * to suspend, following wakeup will consume much more
  1858. * power than it could be saved.
  1859. */
  1860. cw1200_pm_stay_awake(&priv->pm_state,
  1861. priv->join_dtim_period *
  1862. (priv->beacon_int + 20) * HZ / 1024);
  1863. priv->tx_multicast = (priv->aid0_bit_set &&
  1864. priv->buffered_multicasts);
  1865. if (priv->tx_multicast) {
  1866. cancel_tmo = true;
  1867. cw1200_bh_wakeup(priv);
  1868. }
  1869. }
  1870. spin_unlock_bh(&priv->ps_state_lock);
  1871. if (cancel_tmo)
  1872. del_timer_sync(&priv->mcast_timeout);
  1873. } else {
  1874. spin_lock_bh(&priv->ps_state_lock);
  1875. cw1200_ps_notify(priv, arg->link_id, arg->stop);
  1876. spin_unlock_bh(&priv->ps_state_lock);
  1877. if (!arg->stop)
  1878. cw1200_bh_wakeup(priv);
  1879. }
  1880. return;
  1881. }
  1882. /* ******************************************************************** */
  1883. /* AP privates */
  1884. static int cw1200_upload_beacon(struct cw1200_common *priv)
  1885. {
  1886. int ret = 0;
  1887. struct ieee80211_mgmt *mgmt;
  1888. struct wsm_template_frame frame = {
  1889. .frame_type = WSM_FRAME_TYPE_BEACON,
  1890. };
  1891. u16 tim_offset;
  1892. u16 tim_len;
  1893. if (priv->mode == NL80211_IFTYPE_STATION ||
  1894. priv->mode == NL80211_IFTYPE_MONITOR ||
  1895. priv->mode == NL80211_IFTYPE_UNSPECIFIED)
  1896. goto done;
  1897. if (priv->vif->p2p)
  1898. frame.rate = WSM_TRANSMIT_RATE_6;
  1899. frame.skb = ieee80211_beacon_get_tim(priv->hw, priv->vif,
  1900. &tim_offset, &tim_len);
  1901. if (!frame.skb)
  1902. return -ENOMEM;
  1903. ret = wsm_set_template_frame(priv, &frame);
  1904. if (ret)
  1905. goto done;
  1906. /* TODO: Distill probe resp; remove TIM
  1907. * and any other beacon-specific IEs
  1908. */
  1909. mgmt = (void *)frame.skb->data;
  1910. mgmt->frame_control =
  1911. __cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1912. IEEE80211_STYPE_PROBE_RESP);
  1913. frame.frame_type = WSM_FRAME_TYPE_PROBE_RESPONSE;
  1914. if (priv->vif->p2p) {
  1915. ret = wsm_set_probe_responder(priv, true);
  1916. } else {
  1917. ret = wsm_set_template_frame(priv, &frame);
  1918. wsm_set_probe_responder(priv, false);
  1919. }
  1920. done:
  1921. dev_kfree_skb(frame.skb);
  1922. return ret;
  1923. }
  1924. static int cw1200_upload_pspoll(struct cw1200_common *priv)
  1925. {
  1926. int ret = 0;
  1927. struct wsm_template_frame frame = {
  1928. .frame_type = WSM_FRAME_TYPE_PS_POLL,
  1929. .rate = 0xFF,
  1930. };
  1931. frame.skb = ieee80211_pspoll_get(priv->hw, priv->vif);
  1932. if (!frame.skb)
  1933. return -ENOMEM;
  1934. ret = wsm_set_template_frame(priv, &frame);
  1935. dev_kfree_skb(frame.skb);
  1936. return ret;
  1937. }
  1938. static int cw1200_upload_null(struct cw1200_common *priv)
  1939. {
  1940. int ret = 0;
  1941. struct wsm_template_frame frame = {
  1942. .frame_type = WSM_FRAME_TYPE_NULL,
  1943. .rate = 0xFF,
  1944. };
  1945. frame.skb = ieee80211_nullfunc_get(priv->hw, priv->vif);
  1946. if (!frame.skb)
  1947. return -ENOMEM;
  1948. ret = wsm_set_template_frame(priv, &frame);
  1949. dev_kfree_skb(frame.skb);
  1950. return ret;
  1951. }
  1952. static int cw1200_upload_qosnull(struct cw1200_common *priv)
  1953. {
  1954. /* TODO: This needs to be implemented
  1955. struct wsm_template_frame frame = {
  1956. .frame_type = WSM_FRAME_TYPE_QOS_NULL,
  1957. .rate = 0xFF,
  1958. };
  1959. frame.skb = ieee80211_qosnullfunc_get(priv->hw, priv->vif);
  1960. if (!frame.skb)
  1961. return -ENOMEM;
  1962. ret = wsm_set_template_frame(priv, &frame);
  1963. dev_kfree_skb(frame.skb);
  1964. */
  1965. return 0;
  1966. }
  1967. static int cw1200_enable_beaconing(struct cw1200_common *priv,
  1968. bool enable)
  1969. {
  1970. struct wsm_beacon_transmit transmit = {
  1971. .enable_beaconing = enable,
  1972. };
  1973. return wsm_beacon_transmit(priv, &transmit);
  1974. }
  1975. static int cw1200_start_ap(struct cw1200_common *priv)
  1976. {
  1977. int ret;
  1978. struct ieee80211_bss_conf *conf = &priv->vif->bss_conf;
  1979. struct wsm_start start = {
  1980. .mode = priv->vif->p2p ?
  1981. WSM_START_MODE_P2P_GO : WSM_START_MODE_AP,
  1982. .band = (priv->channel->band == IEEE80211_BAND_5GHZ) ?
  1983. WSM_PHY_BAND_5G : WSM_PHY_BAND_2_4G,
  1984. .channel_number = priv->channel->hw_value,
  1985. .beacon_interval = conf->beacon_int,
  1986. .dtim_period = conf->dtim_period,
  1987. .preamble = conf->use_short_preamble ?
  1988. WSM_JOIN_PREAMBLE_SHORT :
  1989. WSM_JOIN_PREAMBLE_LONG,
  1990. .probe_delay = 100,
  1991. .basic_rate_set = cw1200_rate_mask_to_wsm(priv,
  1992. conf->basic_rates),
  1993. };
  1994. struct wsm_operational_mode mode = {
  1995. .power_mode = cw1200_power_mode,
  1996. .disable_more_flag_usage = true,
  1997. };
  1998. memset(start.ssid, 0, sizeof(start.ssid));
  1999. if (!conf->hidden_ssid) {
  2000. start.ssid_len = conf->ssid_len;
  2001. memcpy(start.ssid, conf->ssid, start.ssid_len);
  2002. }
  2003. priv->beacon_int = conf->beacon_int;
  2004. priv->join_dtim_period = conf->dtim_period;
  2005. memset(&priv->link_id_db, 0, sizeof(priv->link_id_db));
  2006. pr_debug("[AP] ch: %d(%d), bcn: %d(%d), brt: 0x%.8X, ssid: %.*s.\n",
  2007. start.channel_number, start.band,
  2008. start.beacon_interval, start.dtim_period,
  2009. start.basic_rate_set,
  2010. start.ssid_len, start.ssid);
  2011. ret = wsm_start(priv, &start);
  2012. if (!ret)
  2013. ret = cw1200_upload_keys(priv);
  2014. if (!ret && priv->vif->p2p) {
  2015. pr_debug("[AP] Setting p2p powersave configuration.\n");
  2016. wsm_set_p2p_ps_modeinfo(priv, &priv->p2p_ps_modeinfo);
  2017. }
  2018. if (!ret) {
  2019. wsm_set_block_ack_policy(priv, 0, 0);
  2020. priv->join_status = CW1200_JOIN_STATUS_AP;
  2021. cw1200_update_filtering(priv);
  2022. }
  2023. wsm_set_operational_mode(priv, &mode);
  2024. return ret;
  2025. }
  2026. static int cw1200_update_beaconing(struct cw1200_common *priv)
  2027. {
  2028. struct ieee80211_bss_conf *conf = &priv->vif->bss_conf;
  2029. struct wsm_reset reset = {
  2030. .link_id = 0,
  2031. .reset_statistics = true,
  2032. };
  2033. if (priv->mode == NL80211_IFTYPE_AP) {
  2034. /* TODO: check if changed channel, band */
  2035. if (priv->join_status != CW1200_JOIN_STATUS_AP ||
  2036. priv->beacon_int != conf->beacon_int) {
  2037. pr_debug("ap restarting\n");
  2038. wsm_lock_tx(priv);
  2039. if (priv->join_status != CW1200_JOIN_STATUS_PASSIVE)
  2040. wsm_reset(priv, &reset);
  2041. priv->join_status = CW1200_JOIN_STATUS_PASSIVE;
  2042. cw1200_start_ap(priv);
  2043. wsm_unlock_tx(priv);
  2044. } else
  2045. pr_debug("ap started join_status: %d\n",
  2046. priv->join_status);
  2047. }
  2048. return 0;
  2049. }