2 * This file is part of wl1271
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
30 #include "wl12xx_80211.h"
32 void wlcore_event_rssi_trigger(struct wl1271 *wl, s8 *metric_arr)
34 struct wl12xx_vif *wlvif;
35 struct ieee80211_vif *vif;
36 enum nl80211_cqm_rssi_threshold_event event;
37 s8 metric = metric_arr[0];
39 wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
41 /* TODO: check actual multi-role support */
42 wl12xx_for_each_wlvif_sta(wl, wlvif) {
43 if (metric <= wlvif->rssi_thold)
44 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
46 event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
48 vif = wl12xx_wlvif_to_vif(wlvif);
49 if (event != wlvif->last_rssi_event)
50 ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
51 wlvif->last_rssi_event = event;
54 EXPORT_SYMBOL_GPL(wlcore_event_rssi_trigger);
56 static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
58 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
60 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
61 u8 hlid = wlvif->sta.hlid;
62 if (!wl->links[hlid].ba_bitmap)
64 ieee80211_stop_rx_ba_session(vif, wl->links[hlid].ba_bitmap,
68 struct wl1271_link *lnk;
69 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
71 lnk = &wl->links[hlid];
75 ieee80211_stop_rx_ba_session(vif,
82 void wlcore_event_soft_gemini_sense(struct wl1271 *wl, u8 enable)
84 struct wl12xx_vif *wlvif;
87 set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
89 clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
90 wl12xx_for_each_wlvif_sta(wl, wlvif) {
91 wl1271_recalc_rx_streaming(wl, wlvif);
95 EXPORT_SYMBOL_GPL(wlcore_event_soft_gemini_sense);
97 void wlcore_event_sched_scan_completed(struct wl1271 *wl,
100 wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT (status 0x%0x)",
104 ieee80211_sched_scan_stopped(wl->hw);
105 wl->sched_vif = NULL;
108 EXPORT_SYMBOL_GPL(wlcore_event_sched_scan_completed);
110 void wlcore_event_ba_rx_constraint(struct wl1271 *wl,
111 unsigned long roles_bitmap,
112 unsigned long allowed_bitmap)
114 struct wl12xx_vif *wlvif;
116 wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx allowed=0x%lx",
117 __func__, roles_bitmap, allowed_bitmap);
119 wl12xx_for_each_wlvif(wl, wlvif) {
120 if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
121 !test_bit(wlvif->role_id , &roles_bitmap))
124 wlvif->ba_allowed = !!test_bit(wlvif->role_id,
126 if (!wlvif->ba_allowed)
127 wl1271_stop_ba_event(wl, wlvif);
130 EXPORT_SYMBOL_GPL(wlcore_event_ba_rx_constraint);
132 void wlcore_event_channel_switch(struct wl1271 *wl,
133 unsigned long roles_bitmap,
136 struct wl12xx_vif *wlvif;
137 struct ieee80211_vif *vif;
139 wl1271_debug(DEBUG_EVENT, "%s: roles=0x%lx success=%d",
140 __func__, roles_bitmap, success);
142 wl12xx_for_each_wlvif_sta(wl, wlvif) {
143 if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
144 !test_bit(wlvif->role_id , &roles_bitmap))
147 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
151 vif = wl12xx_wlvif_to_vif(wlvif);
153 ieee80211_chswitch_done(vif, success);
154 cancel_delayed_work(&wlvif->channel_switch_work);
157 EXPORT_SYMBOL_GPL(wlcore_event_channel_switch);
159 void wlcore_event_dummy_packet(struct wl1271 *wl)
162 wl1271_info("Got DUMMY_PACKET event in PLT mode. FW bug, ignoring.");
166 wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
167 wl1271_tx_dummy_packet(wl);
169 EXPORT_SYMBOL_GPL(wlcore_event_dummy_packet);
171 static void wlcore_disconnect_sta(struct wl1271 *wl, unsigned long sta_bitmap)
173 u32 num_packets = wl->conf.tx.max_tx_retries;
174 struct wl12xx_vif *wlvif;
175 struct ieee80211_vif *vif;
176 struct ieee80211_sta *sta;
180 for_each_set_bit(h, &sta_bitmap, wl->num_links) {
182 /* find the ap vif connected to this sta */
183 wl12xx_for_each_wlvif_ap(wl, wlvif) {
184 if (!test_bit(h, wlvif->ap.sta_hlid_map))
192 vif = wl12xx_wlvif_to_vif(wlvif);
193 addr = wl->links[h].addr;
196 sta = ieee80211_find_sta(vif, addr);
198 wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
199 ieee80211_report_low_ack(sta, num_packets);
205 void wlcore_event_max_tx_failure(struct wl1271 *wl, unsigned long sta_bitmap)
207 wl1271_debug(DEBUG_EVENT, "MAX_TX_FAILURE_EVENT_ID");
208 wlcore_disconnect_sta(wl, sta_bitmap);
210 EXPORT_SYMBOL_GPL(wlcore_event_max_tx_failure);
212 void wlcore_event_inactive_sta(struct wl1271 *wl, unsigned long sta_bitmap)
214 wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
215 wlcore_disconnect_sta(wl, sta_bitmap);
217 EXPORT_SYMBOL_GPL(wlcore_event_inactive_sta);
219 void wlcore_event_roc_complete(struct wl1271 *wl)
221 wl1271_debug(DEBUG_EVENT, "REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID");
223 ieee80211_ready_on_channel(wl->hw);
225 EXPORT_SYMBOL_GPL(wlcore_event_roc_complete);
227 void wlcore_event_beacon_loss(struct wl1271 *wl, unsigned long roles_bitmap)
230 * We are HW_MONITOR device. On beacon loss - queue
231 * connection loss work. Cancel it on REGAINED event.
233 struct wl12xx_vif *wlvif;
234 struct ieee80211_vif *vif;
235 int delay = wl->conf.conn.synch_fail_thold *
236 wl->conf.conn.bss_lose_timeout;
238 wl1271_info("Beacon loss detected. roles:0x%lx", roles_bitmap);
240 wl12xx_for_each_wlvif_sta(wl, wlvif) {
241 if (wlvif->role_id == WL12XX_INVALID_ROLE_ID ||
242 !test_bit(wlvif->role_id , &roles_bitmap))
245 vif = wl12xx_wlvif_to_vif(wlvif);
247 /* don't attempt roaming in case of p2p */
249 ieee80211_connection_loss(vif);
254 * if the work is already queued, it should take place.
255 * We don't want to delay the connection loss
256 * indication any more.
258 ieee80211_queue_delayed_work(wl->hw,
259 &wlvif->connection_loss_work,
260 msecs_to_jiffies(delay));
262 ieee80211_cqm_rssi_notify(
264 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
268 EXPORT_SYMBOL_GPL(wlcore_event_beacon_loss);
270 int wl1271_event_unmask(struct wl1271 *wl)
274 wl1271_debug(DEBUG_EVENT, "unmasking event_mask 0x%x", wl->event_mask);
275 ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
282 int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
286 wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
291 /* first we read the mbox descriptor */
292 ret = wlcore_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
293 wl->mbox_size, false);
297 /* process the descriptor */
298 ret = wl->ops->process_mailbox_events(wl);
303 * TODO: we just need this because one bit is in a different
304 * place. Is there any better way?
306 ret = wl->ops->ack_event(wl);