blob: dd20b1862d44b94121076e6287e4f704c9f1daee [file] [log] [blame]
Arend van Spriel5c36b992012-11-14 18:46:05 -08001/*
2 * Copyright (c) 2012 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17
18#ifndef FWEH_H_
19#define FWEH_H_
20
Arend van Sprielb6f06f62012-11-14 18:46:14 -080021#include <asm/unaligned.h>
Arend van Spriel5c36b992012-11-14 18:46:05 -080022#include <linux/skbuff.h>
23#include <linux/if_ether.h>
24#include <linux/if.h>
25
26/* formward declarations */
27struct brcmf_pub;
28struct brcmf_if;
29struct brcmf_cfg80211_info;
30struct brcmf_event;
31
Arend van Sprieldc5cbdf2012-12-05 15:25:56 +010032/* list of firmware events */
33#define BRCMF_FWEH_EVENT_ENUM_DEFLIST \
34 BRCMF_ENUM_DEF(SET_SSID, 0) \
35 BRCMF_ENUM_DEF(JOIN, 1) \
36 BRCMF_ENUM_DEF(START, 2) \
37 BRCMF_ENUM_DEF(AUTH, 3) \
38 BRCMF_ENUM_DEF(AUTH_IND, 4) \
39 BRCMF_ENUM_DEF(DEAUTH, 5) \
40 BRCMF_ENUM_DEF(DEAUTH_IND, 6) \
41 BRCMF_ENUM_DEF(ASSOC, 7) \
42 BRCMF_ENUM_DEF(ASSOC_IND, 8) \
43 BRCMF_ENUM_DEF(REASSOC, 9) \
44 BRCMF_ENUM_DEF(REASSOC_IND, 10) \
45 BRCMF_ENUM_DEF(DISASSOC, 11) \
46 BRCMF_ENUM_DEF(DISASSOC_IND, 12) \
47 BRCMF_ENUM_DEF(QUIET_START, 13) \
48 BRCMF_ENUM_DEF(QUIET_END, 14) \
49 BRCMF_ENUM_DEF(BEACON_RX, 15) \
50 BRCMF_ENUM_DEF(LINK, 16) \
51 BRCMF_ENUM_DEF(MIC_ERROR, 17) \
52 BRCMF_ENUM_DEF(NDIS_LINK, 18) \
53 BRCMF_ENUM_DEF(ROAM, 19) \
54 BRCMF_ENUM_DEF(TXFAIL, 20) \
55 BRCMF_ENUM_DEF(PMKID_CACHE, 21) \
56 BRCMF_ENUM_DEF(RETROGRADE_TSF, 22) \
57 BRCMF_ENUM_DEF(PRUNE, 23) \
58 BRCMF_ENUM_DEF(AUTOAUTH, 24) \
59 BRCMF_ENUM_DEF(EAPOL_MSG, 25) \
60 BRCMF_ENUM_DEF(SCAN_COMPLETE, 26) \
61 BRCMF_ENUM_DEF(ADDTS_IND, 27) \
62 BRCMF_ENUM_DEF(DELTS_IND, 28) \
63 BRCMF_ENUM_DEF(BCNSENT_IND, 29) \
64 BRCMF_ENUM_DEF(BCNRX_MSG, 30) \
65 BRCMF_ENUM_DEF(BCNLOST_MSG, 31) \
66 BRCMF_ENUM_DEF(ROAM_PREP, 32) \
67 BRCMF_ENUM_DEF(PFN_NET_FOUND, 33) \
68 BRCMF_ENUM_DEF(PFN_NET_LOST, 34) \
69 BRCMF_ENUM_DEF(RESET_COMPLETE, 35) \
70 BRCMF_ENUM_DEF(JOIN_START, 36) \
71 BRCMF_ENUM_DEF(ROAM_START, 37) \
72 BRCMF_ENUM_DEF(ASSOC_START, 38) \
73 BRCMF_ENUM_DEF(IBSS_ASSOC, 39) \
74 BRCMF_ENUM_DEF(RADIO, 40) \
75 BRCMF_ENUM_DEF(PSM_WATCHDOG, 41) \
76 BRCMF_ENUM_DEF(PROBREQ_MSG, 44) \
77 BRCMF_ENUM_DEF(SCAN_CONFIRM_IND, 45) \
78 BRCMF_ENUM_DEF(PSK_SUP, 46) \
79 BRCMF_ENUM_DEF(COUNTRY_CODE_CHANGED, 47) \
80 BRCMF_ENUM_DEF(EXCEEDED_MEDIUM_TIME, 48) \
81 BRCMF_ENUM_DEF(ICV_ERROR, 49) \
82 BRCMF_ENUM_DEF(UNICAST_DECODE_ERROR, 50) \
83 BRCMF_ENUM_DEF(MULTICAST_DECODE_ERROR, 51) \
84 BRCMF_ENUM_DEF(TRACE, 52) \
85 BRCMF_ENUM_DEF(IF, 54) \
Hante Meuleman0de8aac2013-02-08 15:53:38 +010086 BRCMF_ENUM_DEF(P2P_DISC_LISTEN_COMPLETE, 55) \
Arend van Sprieldc5cbdf2012-12-05 15:25:56 +010087 BRCMF_ENUM_DEF(RSSI, 56) \
88 BRCMF_ENUM_DEF(PFN_SCAN_COMPLETE, 57) \
89 BRCMF_ENUM_DEF(EXTLOG_MSG, 58) \
90 BRCMF_ENUM_DEF(ACTION_FRAME, 59) \
91 BRCMF_ENUM_DEF(ACTION_FRAME_COMPLETE, 60) \
92 BRCMF_ENUM_DEF(PRE_ASSOC_IND, 61) \
93 BRCMF_ENUM_DEF(PRE_REASSOC_IND, 62) \
94 BRCMF_ENUM_DEF(CHANNEL_ADOPTED, 63) \
95 BRCMF_ENUM_DEF(AP_STARTED, 64) \
96 BRCMF_ENUM_DEF(DFS_AP_STOP, 65) \
97 BRCMF_ENUM_DEF(DFS_AP_RESUME, 66) \
98 BRCMF_ENUM_DEF(ESCAN_RESULT, 69) \
99 BRCMF_ENUM_DEF(ACTION_FRAME_OFF_CHAN_COMPLETE, 70) \
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100100 BRCMF_ENUM_DEF(PROBERESP_MSG, 71) \
101 BRCMF_ENUM_DEF(P2P_PROBEREQ_MSG, 72) \
Arend van Sprieldc5cbdf2012-12-05 15:25:56 +0100102 BRCMF_ENUM_DEF(DCS_REQUEST, 73) \
Hante Meuleman0de8aac2013-02-08 15:53:38 +0100103 BRCMF_ENUM_DEF(FIFO_CREDIT_MAP, 74) \
Hante Meuleman7d747032013-06-18 13:29:22 +0200104 BRCMF_ENUM_DEF(ACTION_FRAME_RX, 75) \
Hante Meuleman70b7d942014-07-30 13:20:07 +0200105 BRCMF_ENUM_DEF(TDLS_PEER_EVENT, 92) \
Franky Lin4cd0ea42013-09-25 13:05:40 +0200106 BRCMF_ENUM_DEF(BCMC_CREDIT_SUPPORT, 127) \
107 BRCMF_ENUM_DEF(PSTA_PRIMARY_INTF_IND, 128)
Arend van Sprieldc5cbdf2012-12-05 15:25:56 +0100108
109#define BRCMF_ENUM_DEF(id, val) \
110 BRCMF_E_##id = (val),
111
Arend van Spriel5c36b992012-11-14 18:46:05 -0800112/* firmware event codes sent by the dongle */
113enum brcmf_fweh_event_code {
Arend van Sprieldc5cbdf2012-12-05 15:25:56 +0100114 BRCMF_FWEH_EVENT_ENUM_DEFLIST
Arend van Spriel5c36b992012-11-14 18:46:05 -0800115 BRCMF_E_LAST
116};
Arend van Sprieldc5cbdf2012-12-05 15:25:56 +0100117#undef BRCMF_ENUM_DEF
Arend van Spriel5c36b992012-11-14 18:46:05 -0800118
Arend van Spriel5af47fb2013-09-25 13:05:44 +0200119#define BRCMF_EVENTING_MASK_LEN DIV_ROUND_UP(BRCMF_E_LAST, 8)
Franky Lin4cd0ea42013-09-25 13:05:40 +0200120
Arend van Spriel5c36b992012-11-14 18:46:05 -0800121/* flags field values in struct brcmf_event_msg */
122#define BRCMF_EVENT_MSG_LINK 0x01
123#define BRCMF_EVENT_MSG_FLUSHTXQ 0x02
124#define BRCMF_EVENT_MSG_GROUP 0x04
125
Arend van Spriel01376a02013-11-29 12:25:23 +0100126/* status field values in struct brcmf_event_msg */
127#define BRCMF_E_STATUS_SUCCESS 0
128#define BRCMF_E_STATUS_FAIL 1
129#define BRCMF_E_STATUS_TIMEOUT 2
130#define BRCMF_E_STATUS_NO_NETWORKS 3
131#define BRCMF_E_STATUS_ABORT 4
132#define BRCMF_E_STATUS_NO_ACK 5
133#define BRCMF_E_STATUS_UNSOLICITED 6
134#define BRCMF_E_STATUS_ATTEMPT 7
135#define BRCMF_E_STATUS_PARTIAL 8
136#define BRCMF_E_STATUS_NEWSCAN 9
137#define BRCMF_E_STATUS_NEWASSOC 10
138#define BRCMF_E_STATUS_11HQUIET 11
139#define BRCMF_E_STATUS_SUPPRESS 12
140#define BRCMF_E_STATUS_NOCHANS 13
141#define BRCMF_E_STATUS_CS_ABORT 15
142#define BRCMF_E_STATUS_ERROR 16
143
144/* reason field values in struct brcmf_event_msg */
145#define BRCMF_E_REASON_INITIAL_ASSOC 0
146#define BRCMF_E_REASON_LOW_RSSI 1
147#define BRCMF_E_REASON_DEAUTH 2
148#define BRCMF_E_REASON_DISASSOC 3
149#define BRCMF_E_REASON_BCNS_LOST 4
150#define BRCMF_E_REASON_MINTXRATE 9
151#define BRCMF_E_REASON_TXFAIL 10
152
153#define BRCMF_E_REASON_LINK_BSSCFG_DIS 4
154#define BRCMF_E_REASON_FAST_ROAM_FAILED 5
155#define BRCMF_E_REASON_DIRECTED_ROAM 6
156#define BRCMF_E_REASON_TSPEC_REJECTED 7
157#define BRCMF_E_REASON_BETTER_AP 8
158
Hante Meuleman70b7d942014-07-30 13:20:07 +0200159#define BRCMF_E_REASON_TDLS_PEER_DISCOVERED 0
160#define BRCMF_E_REASON_TDLS_PEER_CONNECTED 1
161#define BRCMF_E_REASON_TDLS_PEER_DISCONNECTED 2
162
Arend van Spriel01376a02013-11-29 12:25:23 +0100163/* action field values for brcmf_ifevent */
164#define BRCMF_E_IF_ADD 1
165#define BRCMF_E_IF_DEL 2
166#define BRCMF_E_IF_CHANGE 3
167
168/* flag field values for brcmf_ifevent */
169#define BRCMF_E_IF_FLAG_NOIF 1
170
171/* role field values for brcmf_ifevent */
172#define BRCMF_E_IF_ROLE_STA 0
173#define BRCMF_E_IF_ROLE_AP 1
174#define BRCMF_E_IF_ROLE_WDS 2
175
Arend van Spriel5c36b992012-11-14 18:46:05 -0800176/**
177 * definitions for event packet validation.
178 */
179#define BRCMF_EVENT_OUI_OFFSET 19
180#define BRCM_OUI "\x00\x10\x18"
181#define DOT11_OUI_LEN 3
182#define BCMILCP_BCM_SUBTYPE_EVENT 1
183
184
185/**
186 * struct brcmf_event_msg - firmware event message.
187 *
188 * @version: version information.
189 * @flags: event flags.
190 * @event_code: firmware event code.
191 * @status: status information.
192 * @reason: reason code.
193 * @auth_type: authentication type.
194 * @datalen: lenght of event data buffer.
195 * @addr: ether address.
196 * @ifname: interface name.
197 * @ifidx: interface index.
198 * @bsscfgidx: bsscfg index.
199 */
200struct brcmf_event_msg {
201 u16 version;
202 u16 flags;
203 u32 event_code;
204 u32 status;
205 u32 reason;
206 s32 auth_type;
207 u32 datalen;
208 u8 addr[ETH_ALEN];
209 char ifname[IFNAMSIZ];
210 u8 ifidx;
211 u8 bsscfgidx;
212};
213
Arend van Spriel01376a02013-11-29 12:25:23 +0100214struct brcmf_if_event {
215 u8 ifidx;
216 u8 action;
217 u8 flags;
218 u8 bssidx;
219 u8 role;
220};
221
Arend van Spriel5c36b992012-11-14 18:46:05 -0800222typedef int (*brcmf_fweh_handler_t)(struct brcmf_if *ifp,
223 const struct brcmf_event_msg *evtmsg,
224 void *data);
225
226/**
227 * struct brcmf_fweh_info - firmware event handling information.
228 *
229 * @event_work: event worker.
230 * @evt_q_lock: lock for event queue protection.
231 * @event_q: event queue.
232 * @evt_handler: registered event handlers.
233 */
234struct brcmf_fweh_info {
235 struct work_struct event_work;
Luis R. Rodriguezf241b242012-11-29 12:45:09 -0800236 spinlock_t evt_q_lock;
Arend van Spriel5c36b992012-11-14 18:46:05 -0800237 struct list_head event_q;
238 int (*evt_handler[BRCMF_E_LAST])(struct brcmf_if *ifp,
239 const struct brcmf_event_msg *evtmsg,
240 void *data);
241};
242
243void brcmf_fweh_attach(struct brcmf_pub *drvr);
244void brcmf_fweh_detach(struct brcmf_pub *drvr);
245int brcmf_fweh_register(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code,
246 int (*handler)(struct brcmf_if *ifp,
247 const struct brcmf_event_msg *evtmsg,
248 void *data));
249void brcmf_fweh_unregister(struct brcmf_pub *drvr,
250 enum brcmf_fweh_event_code code);
251int brcmf_fweh_activate_events(struct brcmf_if *ifp);
252void brcmf_fweh_process_event(struct brcmf_pub *drvr,
Arend van Sprieldeb092802013-04-05 10:57:54 +0200253 struct brcmf_event *event_packet);
Arend van Spriel5c36b992012-11-14 18:46:05 -0800254
255static inline void brcmf_fweh_process_skb(struct brcmf_pub *drvr,
Arend van Sprieldeb092802013-04-05 10:57:54 +0200256 struct sk_buff *skb)
Arend van Spriel5c36b992012-11-14 18:46:05 -0800257{
258 struct brcmf_event *event_packet;
259 u8 *data;
260 u16 usr_stype;
261
262 /* only process events when protocol matches */
263 if (skb->protocol != cpu_to_be16(ETH_P_LINK_CTL))
264 return;
265
266 /* check for BRCM oui match */
267 event_packet = (struct brcmf_event *)skb_mac_header(skb);
268 data = (u8 *)event_packet;
269 data += BRCMF_EVENT_OUI_OFFSET;
270 if (memcmp(BRCM_OUI, data, DOT11_OUI_LEN))
271 return;
272
273 /* final match on usr_subtype */
274 data += DOT11_OUI_LEN;
275 usr_stype = get_unaligned_be16(data);
276 if (usr_stype != BCMILCP_BCM_SUBTYPE_EVENT)
277 return;
278
Arend van Sprieldeb092802013-04-05 10:57:54 +0200279 brcmf_fweh_process_event(drvr, event_packet);
Arend van Spriel5c36b992012-11-14 18:46:05 -0800280}
281
282#endif /* FWEH_H_ */