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) \ |
Hante Meuleman | 7d74703 | 2013-06-18 13:29:22 +0200 | [diff] [blame] | 104 | BRCMF_ENUM_DEF(ACTION_FRAME_RX, 75) \ |
Hante Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 105 | BRCMF_ENUM_DEF(TDLS_PEER_EVENT, 92) \ |
Franky Lin | 4cd0ea4 | 2013-09-25 13:05:40 +0200 | [diff] [blame] | 106 | BRCMF_ENUM_DEF(BCMC_CREDIT_SUPPORT, 127) \ |
| 107 | BRCMF_ENUM_DEF(PSTA_PRIMARY_INTF_IND, 128) |
Arend van Spriel | dc5cbdf | 2012-12-05 15:25:56 +0100 | [diff] [blame] | 108 | |
| 109 | #define BRCMF_ENUM_DEF(id, val) \ |
| 110 | BRCMF_E_##id = (val), |
| 111 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 112 | /* firmware event codes sent by the dongle */ |
| 113 | enum brcmf_fweh_event_code { |
Arend van Spriel | dc5cbdf | 2012-12-05 15:25:56 +0100 | [diff] [blame] | 114 | BRCMF_FWEH_EVENT_ENUM_DEFLIST |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 115 | BRCMF_E_LAST |
| 116 | }; |
Arend van Spriel | dc5cbdf | 2012-12-05 15:25:56 +0100 | [diff] [blame] | 117 | #undef BRCMF_ENUM_DEF |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 118 | |
Arend van Spriel | 5af47fb | 2013-09-25 13:05:44 +0200 | [diff] [blame] | 119 | #define BRCMF_EVENTING_MASK_LEN DIV_ROUND_UP(BRCMF_E_LAST, 8) |
Franky Lin | 4cd0ea4 | 2013-09-25 13:05:40 +0200 | [diff] [blame] | 120 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 121 | /* 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 Spriel | 01376a0 | 2013-11-29 12:25:23 +0100 | [diff] [blame] | 126 | /* 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 Meuleman | 70b7d94 | 2014-07-30 13:20:07 +0200 | [diff] [blame] | 159 | #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 Spriel | 01376a0 | 2013-11-29 12:25:23 +0100 | [diff] [blame] | 163 | /* 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 Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 176 | /** |
| 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 | */ |
| 200 | struct 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 Spriel | 01376a0 | 2013-11-29 12:25:23 +0100 | [diff] [blame] | 214 | struct brcmf_if_event { |
| 215 | u8 ifidx; |
| 216 | u8 action; |
| 217 | u8 flags; |
| 218 | u8 bssidx; |
| 219 | u8 role; |
| 220 | }; |
| 221 | |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 222 | typedef 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 | */ |
| 234 | struct brcmf_fweh_info { |
| 235 | struct work_struct event_work; |
Luis R. Rodriguez | f241b24 | 2012-11-29 12:45:09 -0800 | [diff] [blame] | 236 | spinlock_t evt_q_lock; |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 237 | 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 | |
| 243 | void brcmf_fweh_attach(struct brcmf_pub *drvr); |
| 244 | void brcmf_fweh_detach(struct brcmf_pub *drvr); |
| 245 | int 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)); |
| 249 | void brcmf_fweh_unregister(struct brcmf_pub *drvr, |
| 250 | enum brcmf_fweh_event_code code); |
| 251 | int brcmf_fweh_activate_events(struct brcmf_if *ifp); |
| 252 | void brcmf_fweh_process_event(struct brcmf_pub *drvr, |
Arend van Spriel | deb09280 | 2013-04-05 10:57:54 +0200 | [diff] [blame] | 253 | struct brcmf_event *event_packet); |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 254 | |
| 255 | static inline void brcmf_fweh_process_skb(struct brcmf_pub *drvr, |
Arend van Spriel | deb09280 | 2013-04-05 10:57:54 +0200 | [diff] [blame] | 256 | struct sk_buff *skb) |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 257 | { |
| 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 Spriel | deb09280 | 2013-04-05 10:57:54 +0200 | [diff] [blame] | 279 | brcmf_fweh_process_event(drvr, event_packet); |
Arend van Spriel | 5c36b99 | 2012-11-14 18:46:05 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | #endif /* FWEH_H_ */ |