1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file is part of wl12xx
5 * Copyright (C) 2012 Texas Instruments. All rights reserved.
8 #include <net/genetlink.h>
12 #include "../wlcore/cmd.h"
13 #include "../wlcore/debug.h"
14 #include "../wlcore/vendor_cmd.h"
16 int wl18xx_wait_for_event(struct wl1271
*wl
, enum wlcore_wait_event event
,
22 case WLCORE_EVENT_PEER_REMOVE_COMPLETE
:
23 local_event
= PEER_REMOVE_COMPLETE_EVENT_ID
;
26 case WLCORE_EVENT_DFS_CONFIG_COMPLETE
:
27 local_event
= DFS_CHANNELS_CONFIG_COMPLETE_EVENT
;
31 /* event not implemented */
34 return wlcore_cmd_wait_for_event_or_timeout(wl
, local_event
, timeout
);
37 static const char *wl18xx_radar_type_decode(u8 radar_type
)
40 case RADAR_TYPE_REGULAR
:
42 case RADAR_TYPE_CHIRP
:
50 static int wlcore_smart_config_sync_event(struct wl1271
*wl
, u8 sync_channel
,
54 enum nl80211_band band
;
57 if (sync_band
== WLCORE_BAND_5GHZ
)
58 band
= NL80211_BAND_5GHZ
;
60 band
= NL80211_BAND_2GHZ
;
62 freq
= ieee80211_channel_to_frequency(sync_channel
, band
);
64 wl1271_debug(DEBUG_EVENT
,
65 "SMART_CONFIG_SYNC_EVENT_ID, freq: %d (chan: %d band %d)",
66 freq
, sync_channel
, sync_band
);
67 skb
= cfg80211_vendor_event_alloc(wl
->hw
->wiphy
, NULL
, 20,
68 WLCORE_VENDOR_EVENT_SC_SYNC
,
71 if (nla_put_u32(skb
, WLCORE_VENDOR_ATTR_FREQ
, freq
)) {
75 cfg80211_vendor_event(skb
, GFP_KERNEL
);
79 static int wlcore_smart_config_decode_event(struct wl1271
*wl
,
80 u8 ssid_len
, u8
*ssid
,
85 wl1271_debug(DEBUG_EVENT
, "SMART_CONFIG_DECODE_EVENT_ID");
86 wl1271_dump_ascii(DEBUG_EVENT
, "SSID:", ssid
, ssid_len
);
88 skb
= cfg80211_vendor_event_alloc(wl
->hw
->wiphy
, NULL
,
89 ssid_len
+ pwd_len
+ 20,
90 WLCORE_VENDOR_EVENT_SC_DECODE
,
93 if (nla_put(skb
, WLCORE_VENDOR_ATTR_SSID
, ssid_len
, ssid
) ||
94 nla_put(skb
, WLCORE_VENDOR_ATTR_PSK
, pwd_len
, pwd
)) {
98 cfg80211_vendor_event(skb
, GFP_KERNEL
);
102 static void wlcore_event_time_sync(struct wl1271
*wl
,
103 u16 tsf_high_msb
, u16 tsf_high_lsb
,
104 u16 tsf_low_msb
, u16 tsf_low_lsb
)
109 clock_high
= (tsf_high_msb
<< 16) | tsf_high_lsb
;
110 clock_low
= (tsf_low_msb
<< 16) | tsf_low_lsb
;
112 wl1271_info("TIME_SYNC_EVENT_ID: clock_high %u, clock low %u",
113 clock_high
, clock_low
);
116 int wl18xx_process_mailbox_events(struct wl1271
*wl
)
118 struct wl18xx_event_mailbox
*mbox
= wl
->mbox
;
121 vector
= le32_to_cpu(mbox
->events_vector
);
122 wl1271_debug(DEBUG_EVENT
, "MBOX vector: 0x%x", vector
);
124 if (vector
& SCAN_COMPLETE_EVENT_ID
) {
125 wl1271_debug(DEBUG_EVENT
, "scan results: %d",
126 mbox
->number_of_scan_results
);
129 wl18xx_scan_completed(wl
, wl
->scan_wlvif
);
132 if (vector
& TIME_SYNC_EVENT_ID
)
133 wlcore_event_time_sync(wl
,
134 mbox
->time_sync_tsf_high_msb
,
135 mbox
->time_sync_tsf_high_lsb
,
136 mbox
->time_sync_tsf_low_msb
,
137 mbox
->time_sync_tsf_low_lsb
);
139 if (vector
& RADAR_DETECTED_EVENT_ID
) {
140 wl1271_info("radar event: channel %d type %s",
142 wl18xx_radar_type_decode(mbox
->radar_type
));
144 if (!wl
->radar_debug_mode
)
145 ieee80211_radar_detected(wl
->hw
);
148 if (vector
& PERIODIC_SCAN_REPORT_EVENT_ID
) {
149 wl1271_debug(DEBUG_EVENT
,
150 "PERIODIC_SCAN_REPORT_EVENT (results %d)",
151 mbox
->number_of_sched_scan_results
);
153 wlcore_scan_sched_scan_results(wl
);
156 if (vector
& PERIODIC_SCAN_COMPLETE_EVENT_ID
)
157 wlcore_event_sched_scan_completed(wl
, 1);
159 if (vector
& RSSI_SNR_TRIGGER_0_EVENT_ID
)
160 wlcore_event_rssi_trigger(wl
, mbox
->rssi_snr_trigger_metric
);
162 if (vector
& BA_SESSION_RX_CONSTRAINT_EVENT_ID
)
163 wlcore_event_ba_rx_constraint(wl
,
164 le16_to_cpu(mbox
->rx_ba_role_id_bitmap
),
165 le16_to_cpu(mbox
->rx_ba_allowed_bitmap
));
167 if (vector
& BSS_LOSS_EVENT_ID
)
168 wlcore_event_beacon_loss(wl
,
169 le16_to_cpu(mbox
->bss_loss_bitmap
));
171 if (vector
& CHANNEL_SWITCH_COMPLETE_EVENT_ID
)
172 wlcore_event_channel_switch(wl
,
173 le16_to_cpu(mbox
->channel_switch_role_id_bitmap
),
176 if (vector
& DUMMY_PACKET_EVENT_ID
)
177 wlcore_event_dummy_packet(wl
);
180 * "TX retries exceeded" has a different meaning according to mode.
181 * In AP mode the offending station is disconnected.
183 if (vector
& MAX_TX_FAILURE_EVENT_ID
)
184 wlcore_event_max_tx_failure(wl
,
185 le16_to_cpu(mbox
->tx_retry_exceeded_bitmap
));
187 if (vector
& INACTIVE_STA_EVENT_ID
)
188 wlcore_event_inactive_sta(wl
,
189 le16_to_cpu(mbox
->inactive_sta_bitmap
));
191 if (vector
& REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID
)
192 wlcore_event_roc_complete(wl
);
194 if (vector
& SMART_CONFIG_SYNC_EVENT_ID
)
195 wlcore_smart_config_sync_event(wl
, mbox
->sc_sync_channel
,
198 if (vector
& SMART_CONFIG_DECODE_EVENT_ID
)
199 wlcore_smart_config_decode_event(wl
,
204 if (vector
& FW_LOGGER_INDICATION
)
205 wlcore_event_fw_logger(wl
);
207 if (vector
& RX_BA_WIN_SIZE_CHANGE_EVENT_ID
) {
208 struct wl12xx_vif
*wlvif
;
209 struct ieee80211_vif
*vif
;
210 struct ieee80211_sta
*sta
;
211 u8 link_id
= mbox
->rx_ba_link_id
;
212 u8 win_size
= mbox
->rx_ba_win_size
;
215 wlvif
= wl
->links
[link_id
].wlvif
;
216 vif
= wl12xx_wlvif_to_vif(wlvif
);
218 /* Update RX aggregation window size and call
219 * MAC routine to stop active RX aggregations for this link
221 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
)
222 addr
= vif
->bss_conf
.bssid
;
224 addr
= wl
->links
[link_id
].addr
;
226 sta
= ieee80211_find_sta(vif
, addr
);
228 sta
->max_rx_aggregation_subframes
= win_size
;
229 ieee80211_stop_rx_ba_session(vif
,
230 wl
->links
[link_id
].ba_bitmap
,