Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 1 | /* |
| 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 Spriel | b6f06f6 | 2012-11-14 18:46:14 -0800 | [diff] [blame] | 21 | #include <asm/unaligned.h> |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 22 | #include <linux/skbuff.h> |
| 23 | #include <linux/if_ether.h> |
| 24 | #include <linux/if.h> |
| 25 | |
| 26 | /* formward declarations */ |
| 27 | struct brcmf_pub; |
| 28 | struct brcmf_if; |
| 29 | struct brcmf_cfg80211_info; |
| 30 | struct brcmf_event; |
| 31 | |
Arend van Spriel | dc5cbdf | 2012-12-05 15:25:56 +0100 | [diff] [blame] | 32 | /* 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 Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 86 | BRCMF_ENUM_DEF(P2P_DISC_LISTEN_COMPLETE, 55) \ |
Arend van Spriel | dc5cbdf | 2012-12-05 15:25:56 +0100 | [diff] [blame] | 87 | 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 Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 100 | BRCMF_ENUM_DEF(PROBERESP_MSG, 71) \ |
| 101 | BRCMF_ENUM_DEF(P2P_PROBEREQ_MSG, 72) \ |
Arend van Spriel | dc5cbdf | 2012-12-05 15:25:56 +0100 | [diff] [blame] | 102 | BRCMF_ENUM_DEF(DCS_REQUEST, 73) \ |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 103 | BRCMF_ENUM_DEF(FIFO_CREDIT_MAP, 74) \ |
| 104 | BRCMF_ENUM_DEF(ACTION_FRAME_RX, 75) |
Arend van Spriel | dc5cbdf | 2012-12-05 15:25:56 +0100 | [diff] [blame] | 105 | |
| 106 | #define BRCMF_ENUM_DEF(id, val) \ |
| 107 | BRCMF_E_##id = (val), |
| 108 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 109 | /* firmware event codes sent by the dongle */ |
| 110 | enum brcmf_fweh_event_code { |
Arend van Spriel | dc5cbdf | 2012-12-05 15:25:56 +0100 | [diff] [blame] | 111 | BRCMF_FWEH_EVENT_ENUM_DEFLIST |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 112 | BRCMF_E_LAST |
| 113 | }; |
Arend van Spriel | dc5cbdf | 2012-12-05 15:25:56 +0100 | [diff] [blame] | 114 | #undef BRCMF_ENUM_DEF |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 115 | |
| 116 | /* flags field values in struct brcmf_event_msg */ |
| 117 | #define BRCMF_EVENT_MSG_LINK 0x01 |
| 118 | #define BRCMF_EVENT_MSG_FLUSHTXQ 0x02 |
| 119 | #define BRCMF_EVENT_MSG_GROUP 0x04 |
| 120 | |
| 121 | /** |
| 122 | * definitions for event packet validation. |
| 123 | */ |
| 124 | #define BRCMF_EVENT_OUI_OFFSET 19 |
| 125 | #define BRCM_OUI "\x00\x10\x18" |
| 126 | #define DOT11_OUI_LEN 3 |
| 127 | #define BCMILCP_BCM_SUBTYPE_EVENT 1 |
| 128 | |
| 129 | |
| 130 | /** |
| 131 | * struct brcmf_event_msg - firmware event message. |
| 132 | * |
| 133 | * @version: version information. |
| 134 | * @flags: event flags. |
| 135 | * @event_code: firmware event code. |
| 136 | * @status: status information. |
| 137 | * @reason: reason code. |
| 138 | * @auth_type: authentication type. |
| 139 | * @datalen: lenght of event data buffer. |
| 140 | * @addr: ether address. |
| 141 | * @ifname: interface name. |
| 142 | * @ifidx: interface index. |
| 143 | * @bsscfgidx: bsscfg index. |
| 144 | */ |
| 145 | struct brcmf_event_msg { |
| 146 | u16 version; |
| 147 | u16 flags; |
| 148 | u32 event_code; |
| 149 | u32 status; |
| 150 | u32 reason; |
| 151 | s32 auth_type; |
| 152 | u32 datalen; |
| 153 | u8 addr[ETH_ALEN]; |
| 154 | char ifname[IFNAMSIZ]; |
| 155 | u8 ifidx; |
| 156 | u8 bsscfgidx; |
| 157 | }; |
| 158 | |
| 159 | typedef int (*brcmf_fweh_handler_t)(struct brcmf_if *ifp, |
| 160 | const struct brcmf_event_msg *evtmsg, |
| 161 | void *data); |
| 162 | |
| 163 | /** |
| 164 | * struct brcmf_fweh_info - firmware event handling information. |
| 165 | * |
| 166 | * @event_work: event worker. |
| 167 | * @evt_q_lock: lock for event queue protection. |
| 168 | * @event_q: event queue. |
| 169 | * @evt_handler: registered event handlers. |
| 170 | */ |
| 171 | struct brcmf_fweh_info { |
| 172 | struct work_struct event_work; |
Luis R. Rodriguez | f241b24 | 2012-11-29 12:45:09 -0800 | [diff] [blame] | 173 | spinlock_t evt_q_lock; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 174 | struct list_head event_q; |
| 175 | int (*evt_handler[BRCMF_E_LAST])(struct brcmf_if *ifp, |
| 176 | const struct brcmf_event_msg *evtmsg, |
| 177 | void *data); |
| 178 | }; |
| 179 | |
| 180 | void brcmf_fweh_attach(struct brcmf_pub *drvr); |
| 181 | void brcmf_fweh_detach(struct brcmf_pub *drvr); |
| 182 | int brcmf_fweh_register(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code, |
| 183 | int (*handler)(struct brcmf_if *ifp, |
| 184 | const struct brcmf_event_msg *evtmsg, |
| 185 | void *data)); |
| 186 | void brcmf_fweh_unregister(struct brcmf_pub *drvr, |
| 187 | enum brcmf_fweh_event_code code); |
| 188 | int brcmf_fweh_activate_events(struct brcmf_if *ifp); |
| 189 | void brcmf_fweh_process_event(struct brcmf_pub *drvr, |
Arend van Spriel | deb09280 | 2013-04-05 10:57:54 +0200 | [diff] [blame^] | 190 | struct brcmf_event *event_packet); |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 191 | |
| 192 | static inline void brcmf_fweh_process_skb(struct brcmf_pub *drvr, |
Arend van Spriel | deb09280 | 2013-04-05 10:57:54 +0200 | [diff] [blame^] | 193 | struct sk_buff *skb) |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 194 | { |
| 195 | struct brcmf_event *event_packet; |
| 196 | u8 *data; |
| 197 | u16 usr_stype; |
| 198 | |
| 199 | /* only process events when protocol matches */ |
| 200 | if (skb->protocol != cpu_to_be16(ETH_P_LINK_CTL)) |
| 201 | return; |
| 202 | |
| 203 | /* check for BRCM oui match */ |
| 204 | event_packet = (struct brcmf_event *)skb_mac_header(skb); |
| 205 | data = (u8 *)event_packet; |
| 206 | data += BRCMF_EVENT_OUI_OFFSET; |
| 207 | if (memcmp(BRCM_OUI, data, DOT11_OUI_LEN)) |
| 208 | return; |
| 209 | |
| 210 | /* final match on usr_subtype */ |
| 211 | data += DOT11_OUI_LEN; |
| 212 | usr_stype = get_unaligned_be16(data); |
| 213 | if (usr_stype != BCMILCP_BCM_SUBTYPE_EVENT) |
| 214 | return; |
| 215 | |
Arend van Spriel | deb09280 | 2013-04-05 10:57:54 +0200 | [diff] [blame^] | 216 | brcmf_fweh_process_event(drvr, event_packet); |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | #endif /* FWEH_H_ */ |