linux/drivers/net/wireless/brcm80211/brcmfmac/fweh.h
<<
>>
Prefs
   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
  21#include <asm/unaligned.h>
  22#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
  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) \
  86        BRCMF_ENUM_DEF(P2P_DISC_LISTEN_COMPLETE, 55) \
  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) \
 100        BRCMF_ENUM_DEF(PROBERESP_MSG, 71) \
 101        BRCMF_ENUM_DEF(P2P_PROBEREQ_MSG, 72) \
 102        BRCMF_ENUM_DEF(DCS_REQUEST, 73) \
 103        BRCMF_ENUM_DEF(FIFO_CREDIT_MAP, 74) \
 104        BRCMF_ENUM_DEF(ACTION_FRAME_RX, 75) \
 105        BRCMF_ENUM_DEF(BCMC_CREDIT_SUPPORT, 127) \
 106        BRCMF_ENUM_DEF(PSTA_PRIMARY_INTF_IND, 128)
 107
 108#define BRCMF_ENUM_DEF(id, val) \
 109        BRCMF_E_##id = (val),
 110
 111/* firmware event codes sent by the dongle */
 112enum brcmf_fweh_event_code {
 113        BRCMF_FWEH_EVENT_ENUM_DEFLIST
 114        BRCMF_E_LAST
 115};
 116#undef BRCMF_ENUM_DEF
 117
 118#define BRCMF_EVENTING_MASK_LEN         DIV_ROUND_UP(BRCMF_E_LAST, 8)
 119
 120/* flags field values in struct brcmf_event_msg */
 121#define BRCMF_EVENT_MSG_LINK            0x01
 122#define BRCMF_EVENT_MSG_FLUSHTXQ        0x02
 123#define BRCMF_EVENT_MSG_GROUP           0x04
 124
 125/* status field values in struct brcmf_event_msg */
 126#define BRCMF_E_STATUS_SUCCESS                  0
 127#define BRCMF_E_STATUS_FAIL                     1
 128#define BRCMF_E_STATUS_TIMEOUT                  2
 129#define BRCMF_E_STATUS_NO_NETWORKS              3
 130#define BRCMF_E_STATUS_ABORT                    4
 131#define BRCMF_E_STATUS_NO_ACK                   5
 132#define BRCMF_E_STATUS_UNSOLICITED              6
 133#define BRCMF_E_STATUS_ATTEMPT                  7
 134#define BRCMF_E_STATUS_PARTIAL                  8
 135#define BRCMF_E_STATUS_NEWSCAN                  9
 136#define BRCMF_E_STATUS_NEWASSOC                 10
 137#define BRCMF_E_STATUS_11HQUIET                 11
 138#define BRCMF_E_STATUS_SUPPRESS                 12
 139#define BRCMF_E_STATUS_NOCHANS                  13
 140#define BRCMF_E_STATUS_CS_ABORT                 15
 141#define BRCMF_E_STATUS_ERROR                    16
 142
 143/* reason field values in struct brcmf_event_msg */
 144#define BRCMF_E_REASON_INITIAL_ASSOC            0
 145#define BRCMF_E_REASON_LOW_RSSI                 1
 146#define BRCMF_E_REASON_DEAUTH                   2
 147#define BRCMF_E_REASON_DISASSOC                 3
 148#define BRCMF_E_REASON_BCNS_LOST                4
 149#define BRCMF_E_REASON_MINTXRATE                9
 150#define BRCMF_E_REASON_TXFAIL                   10
 151
 152#define BRCMF_E_REASON_LINK_BSSCFG_DIS          4
 153#define BRCMF_E_REASON_FAST_ROAM_FAILED         5
 154#define BRCMF_E_REASON_DIRECTED_ROAM            6
 155#define BRCMF_E_REASON_TSPEC_REJECTED           7
 156#define BRCMF_E_REASON_BETTER_AP                8
 157
 158/* action field values for brcmf_ifevent */
 159#define BRCMF_E_IF_ADD                          1
 160#define BRCMF_E_IF_DEL                          2
 161#define BRCMF_E_IF_CHANGE                       3
 162
 163/* flag field values for brcmf_ifevent */
 164#define BRCMF_E_IF_FLAG_NOIF                    1
 165
 166/* role field values for brcmf_ifevent */
 167#define BRCMF_E_IF_ROLE_STA                     0
 168#define BRCMF_E_IF_ROLE_AP                      1
 169#define BRCMF_E_IF_ROLE_WDS                     2
 170
 171/**
 172 * definitions for event packet validation.
 173 */
 174#define BRCMF_EVENT_OUI_OFFSET          19
 175#define BRCM_OUI                        "\x00\x10\x18"
 176#define DOT11_OUI_LEN                   3
 177#define BCMILCP_BCM_SUBTYPE_EVENT       1
 178
 179
 180/**
 181 * struct brcmf_event_msg - firmware event message.
 182 *
 183 * @version: version information.
 184 * @flags: event flags.
 185 * @event_code: firmware event code.
 186 * @status: status information.
 187 * @reason: reason code.
 188 * @auth_type: authentication type.
 189 * @datalen: lenght of event data buffer.
 190 * @addr: ether address.
 191 * @ifname: interface name.
 192 * @ifidx: interface index.
 193 * @bsscfgidx: bsscfg index.
 194 */
 195struct brcmf_event_msg {
 196        u16 version;
 197        u16 flags;
 198        u32 event_code;
 199        u32 status;
 200        u32 reason;
 201        s32 auth_type;
 202        u32 datalen;
 203        u8 addr[ETH_ALEN];
 204        char ifname[IFNAMSIZ];
 205        u8 ifidx;
 206        u8 bsscfgidx;
 207};
 208
 209struct brcmf_if_event {
 210        u8 ifidx;
 211        u8 action;
 212        u8 flags;
 213        u8 bssidx;
 214        u8 role;
 215};
 216
 217typedef int (*brcmf_fweh_handler_t)(struct brcmf_if *ifp,
 218                                    const struct brcmf_event_msg *evtmsg,
 219                                    void *data);
 220
 221/**
 222 * struct brcmf_fweh_info - firmware event handling information.
 223 *
 224 * @event_work: event worker.
 225 * @evt_q_lock: lock for event queue protection.
 226 * @event_q: event queue.
 227 * @evt_handler: registered event handlers.
 228 */
 229struct brcmf_fweh_info {
 230        struct work_struct event_work;
 231        spinlock_t evt_q_lock;
 232        struct list_head event_q;
 233        int (*evt_handler[BRCMF_E_LAST])(struct brcmf_if *ifp,
 234                                         const struct brcmf_event_msg *evtmsg,
 235                                         void *data);
 236};
 237
 238void brcmf_fweh_attach(struct brcmf_pub *drvr);
 239void brcmf_fweh_detach(struct brcmf_pub *drvr);
 240int brcmf_fweh_register(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code,
 241                        int (*handler)(struct brcmf_if *ifp,
 242                                       const struct brcmf_event_msg *evtmsg,
 243                                       void *data));
 244void brcmf_fweh_unregister(struct brcmf_pub *drvr,
 245                           enum brcmf_fweh_event_code code);
 246int brcmf_fweh_activate_events(struct brcmf_if *ifp);
 247void brcmf_fweh_process_event(struct brcmf_pub *drvr,
 248                              struct brcmf_event *event_packet);
 249
 250static inline void brcmf_fweh_process_skb(struct brcmf_pub *drvr,
 251                                          struct sk_buff *skb)
 252{
 253        struct brcmf_event *event_packet;
 254        u8 *data;
 255        u16 usr_stype;
 256
 257        /* only process events when protocol matches */
 258        if (skb->protocol != cpu_to_be16(ETH_P_LINK_CTL))
 259                return;
 260
 261        /* check for BRCM oui match */
 262        event_packet = (struct brcmf_event *)skb_mac_header(skb);
 263        data = (u8 *)event_packet;
 264        data += BRCMF_EVENT_OUI_OFFSET;
 265        if (memcmp(BRCM_OUI, data, DOT11_OUI_LEN))
 266                return;
 267
 268        /* final match on usr_subtype */
 269        data += DOT11_OUI_LEN;
 270        usr_stype = get_unaligned_be16(data);
 271        if (usr_stype != BCMILCP_BCM_SUBTYPE_EVENT)
 272                return;
 273
 274        brcmf_fweh_process_event(drvr, event_packet);
 275}
 276
 277#endif /* FWEH_H_ */
 278