sta.c 63 KB

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