sta.c 64 KB

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