linux/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.h
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2010 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#ifndef _wl_cfg80211_h_
  18#define _wl_cfg80211_h_
  19
  20#include <linux/wireless.h>
  21#include <linux/wireless.h>
  22#include <net/cfg80211.h>
  23#include <proto/ethernet.h>
  24#include <wlioctl.h>
  25
  26struct wl_conf;
  27struct wl_iface;
  28struct wl_priv;
  29struct wl_security;
  30struct wl_ibss;
  31
  32#if defined(IL_BIGENDIAN)
  33#include <bcmendian.h>
  34#define htod32(i) (bcmswap32(i))
  35#define htod16(i) (bcmswap16(i))
  36#define dtoh32(i) (bcmswap32(i))
  37#define dtoh16(i) (bcmswap16(i))
  38#define htodchanspec(i) htod16(i)
  39#define dtohchanspec(i) dtoh16(i)
  40#else
  41#define htod32(i) i
  42#define htod16(i) i
  43#define dtoh32(i) i
  44#define dtoh16(i) i
  45#define htodchanspec(i) i
  46#define dtohchanspec(i) i
  47#endif
  48
  49#define WL_DBG_NONE     0
  50#define WL_DBG_DBG      (1 << 2)
  51#define WL_DBG_INFO     (1 << 1)
  52#define WL_DBG_ERR      (1 << 0)
  53#define WL_DBG_MASK ((WL_DBG_DBG | WL_DBG_INFO | WL_DBG_ERR) << 1)
  54
  55#define WL_DBG_LEVEL 1          /* 0 invalidates all debug messages.
  56                                 default is 1 */
  57#define WL_ERR(fmt, args...)                                    \
  58do {                                                            \
  59        if (wl_dbg_level & WL_DBG_ERR) {                        \
  60                if (net_ratelimit()) {                          \
  61                        printk(KERN_ERR "ERROR @%s : " fmt,     \
  62                               __func__, ##args);               \
  63                }                                               \
  64        }                                                       \
  65} while (0)
  66
  67#define WL_INFO(fmt, args...)                                   \
  68do {                                                            \
  69        if (wl_dbg_level & WL_DBG_INFO) {                       \
  70                if (net_ratelimit()) {                          \
  71                        printk(KERN_ERR "INFO @%s : " fmt,      \
  72                               __func__, ##args);               \
  73                }                                               \
  74        }                                                       \
  75} while (0)
  76
  77#if (WL_DBG_LEVEL > 0)
  78#define WL_DBG(fmt, args...)                                    \
  79do {                                                            \
  80        if (wl_dbg_level & WL_DBG_DBG) {                        \
  81                printk(KERN_ERR "DEBUG @%s :" fmt,              \
  82                       __func__, ##args);                       \
  83        }                                                       \
  84} while (0)
  85#else                           /* !(WL_DBG_LEVEL > 0) */
  86#define WL_DBG(fmt, args...) noprintk(fmt, ##args)
  87#endif                          /* (WL_DBG_LEVEL > 0) */
  88
  89#define WL_SCAN_RETRY_MAX       3       /* used for ibss scan */
  90#define WL_NUM_SCAN_MAX         1
  91#define WL_NUM_PMKIDS_MAX       MAXPMKID        /* will be used
  92                                                 * for 2.6.33 kernel
  93                                                 * or later
  94                                                 */
  95#define WL_SCAN_BUF_MAX                 (1024 * 8)
  96#define WL_TLV_INFO_MAX                 1024
  97#define WL_BSS_INFO_MAX                 2048
  98#define WL_ASSOC_INFO_MAX       512     /*
  99                                 * needs to grab assoc info from dongle to
 100                                 * report it to cfg80211 through "connect"
 101                                 * event
 102                                 */
 103#define WL_IOCTL_LEN_MAX        1024
 104#define WL_EXTRA_BUF_MAX        2048
 105#define WL_ISCAN_BUF_MAX        2048    /*
 106                                 * the buf lengh can be WLC_IOCTL_MAXLEN (8K)
 107                                 * to reduce iteration
 108                                 */
 109#define WL_ISCAN_TIMER_INTERVAL_MS      3000
 110#define WL_SCAN_ERSULTS_LAST    (WL_SCAN_RESULTS_NO_MEM+1)
 111#define WL_AP_MAX       256     /* virtually unlimitted as long
 112                                 * as kernel memory allows
 113                                 */
 114#define WL_FILE_NAME_MAX                256
 115
 116/* dongle status */
 117enum wl_status {
 118        WL_STATUS_READY,
 119        WL_STATUS_SCANNING,
 120        WL_STATUS_SCAN_ABORTING,
 121        WL_STATUS_CONNECTING,
 122        WL_STATUS_CONNECTED
 123};
 124
 125/* wi-fi mode */
 126enum wl_mode {
 127        WL_MODE_BSS,
 128        WL_MODE_IBSS,
 129        WL_MODE_AP
 130};
 131
 132/* dongle profile list */
 133enum wl_prof_list {
 134        WL_PROF_MODE,
 135        WL_PROF_SSID,
 136        WL_PROF_SEC,
 137        WL_PROF_IBSS,
 138        WL_PROF_BAND,
 139        WL_PROF_BSSID,
 140        WL_PROF_ACT,
 141        WL_PROF_BEACONINT,
 142        WL_PROF_DTIMPERIOD
 143};
 144
 145/* dongle iscan state */
 146enum wl_iscan_state {
 147        WL_ISCAN_STATE_IDLE,
 148        WL_ISCAN_STATE_SCANING
 149};
 150
 151/* fw downloading status */
 152enum wl_fw_status {
 153        WL_FW_LOADING_DONE,
 154        WL_NVRAM_LOADING_DONE
 155};
 156
 157/* beacon / probe_response */
 158struct beacon_proberesp {
 159        __le64 timestamp;
 160        __le16 beacon_int;
 161        __le16 capab_info;
 162        u8 variable[0];
 163} __attribute__ ((packed));
 164
 165/* dongle configuration */
 166struct wl_conf {
 167        u32 mode;               /* adhoc , infrastructure or ap */
 168        u32 frag_threshold;
 169        u32 rts_threshold;
 170        u32 retry_short;
 171        u32 retry_long;
 172        s32 tx_power;
 173        struct ieee80211_channel channel;
 174};
 175
 176/* cfg80211 main event loop */
 177struct wl_event_loop {
 178        s32(*handler[WLC_E_LAST]) (struct wl_priv *wl,
 179                                     struct net_device *ndev,
 180                                     const wl_event_msg_t *e, void *data);
 181};
 182
 183/* representing interface of cfg80211 plane */
 184struct wl_iface {
 185        struct wl_priv *wl;
 186};
 187
 188struct wl_dev {
 189        void *driver_data;      /* to store cfg80211 object information */
 190};
 191
 192/* bss inform structure for cfg80211 interface */
 193struct wl_cfg80211_bss_info {
 194        u16 band;
 195        u16 channel;
 196        s16 rssi;
 197        u16 frame_len;
 198        u8 frame_buf[1];
 199};
 200
 201/* basic structure of scan request */
 202struct wl_scan_req {
 203        struct wlc_ssid ssid;
 204};
 205
 206/* basic structure of information element */
 207struct wl_ie {
 208        u16 offset;
 209        u8 buf[WL_TLV_INFO_MAX];
 210};
 211
 212/* event queue for cfg80211 main event */
 213struct wl_event_q {
 214        struct list_head eq_list;
 215        u32 etype;
 216        wl_event_msg_t emsg;
 217        s8 edata[1];
 218};
 219
 220/* security information with currently associated ap */
 221struct wl_security {
 222        u32 wpa_versions;
 223        u32 auth_type;
 224        u32 cipher_pairwise;
 225        u32 cipher_group;
 226        u32 wpa_auth;
 227};
 228
 229/* ibss information for currently joined ibss network */
 230struct wl_ibss {
 231        u8 beacon_interval;     /* in millisecond */
 232        u8 atim;                /* in millisecond */
 233        s8 join_only;
 234        u8 band;
 235        u8 channel;
 236};
 237
 238/* dongle profile */
 239struct wl_profile {
 240        u32 mode;
 241        struct wlc_ssid ssid;
 242        u8 bssid[ETH_ALEN];
 243        u16 beacon_interval;
 244        u8 dtim_period;
 245        struct wl_security sec;
 246        struct wl_ibss ibss;
 247        s32 band;
 248        bool active;
 249};
 250
 251/* dongle iscan event loop */
 252struct wl_iscan_eloop {
 253        s32(*handler[WL_SCAN_ERSULTS_LAST]) (struct wl_priv *wl);
 254};
 255
 256/* dongle iscan controller */
 257struct wl_iscan_ctrl {
 258        struct net_device *dev;
 259        struct timer_list timer;
 260        u32 timer_ms;
 261        u32 timer_on;
 262        s32 state;
 263        struct task_struct *tsk;
 264        struct semaphore sync;
 265        struct wl_iscan_eloop el;
 266        void *data;
 267        s8 ioctl_buf[WLC_IOCTL_SMLEN];
 268        s8 scan_buf[WL_ISCAN_BUF_MAX];
 269};
 270
 271/* association inform */
 272struct wl_connect_info {
 273        u8 *req_ie;
 274        s32 req_ie_len;
 275        u8 *resp_ie;
 276        s32 resp_ie_len;
 277};
 278
 279/* firmware /nvram downloading controller */
 280struct wl_fw_ctrl {
 281        const struct firmware *fw_entry;
 282        unsigned long status;
 283        u32 ptr;
 284        s8 fw_name[WL_FILE_NAME_MAX];
 285        s8 nvram_name[WL_FILE_NAME_MAX];
 286};
 287
 288/* assoc ie length */
 289struct wl_assoc_ielen {
 290        u32 req_len;
 291        u32 resp_len;
 292};
 293
 294/* wpa2 pmk list */
 295struct wl_pmk_list {
 296        pmkid_list_t pmkids;
 297        pmkid_t foo[MAXPMKID - 1];
 298};
 299
 300/* dongle private data of cfg80211 interface */
 301struct wl_priv {
 302        struct wireless_dev *wdev;      /* representing wl cfg80211 device */
 303        struct wl_conf *conf;   /* dongle configuration */
 304        struct cfg80211_scan_request *scan_request;     /* scan request
 305                                                         object */
 306        struct wl_event_loop el;        /* main event loop */
 307        struct list_head eq_list;       /* used for event queue */
 308        spinlock_t eq_lock;     /* for event queue synchronization */
 309        struct mutex usr_sync;  /* maily for dongle up/down synchronization */
 310        struct wl_scan_results *bss_list;       /* bss_list holding scanned
 311                                                 ap information */
 312        struct wl_scan_results *scan_results;
 313        struct wl_scan_req *scan_req_int;       /* scan request object for
 314                                                 internal purpose */
 315        struct wl_cfg80211_bss_info *bss_info;  /* bss information for
 316                                                 cfg80211 layer */
 317        struct wl_ie ie;        /* information element object for
 318                                         internal purpose */
 319        struct ether_addr bssid;        /* bssid of currently engaged network */
 320        struct semaphore event_sync;    /* for synchronization of main event
 321                                         thread */
 322        struct wl_profile *profile;     /* holding dongle profile */
 323        struct wl_iscan_ctrl *iscan;    /* iscan controller */
 324        struct wl_connect_info conn_info;       /* association information
 325                                                 container */
 326        struct wl_fw_ctrl *fw;  /* control firwmare / nvram paramter
 327                                 downloading */
 328        struct wl_pmk_list *pmk_list;   /* wpa2 pmk list */
 329        struct task_struct *event_tsk;  /* task of main event handler thread */
 330        unsigned long status;           /* current dongle status */
 331        void *pub;
 332        u32 channel;            /* current channel */
 333        bool iscan_on;          /* iscan on/off switch */
 334        bool iscan_kickstart;   /* indicate iscan already started */
 335        bool active_scan;       /* current scan mode */
 336        bool ibss_starter;      /* indicates this sta is ibss starter */
 337        bool link_up;           /* link/connection up flag */
 338        bool pwr_save;          /* indicate whether dongle to support
 339                                         power save mode */
 340        bool dongle_up;         /* indicate whether dongle up or not */
 341        bool roam_on;           /* on/off switch for dongle self-roaming */
 342        bool scan_tried;        /* indicates if first scan attempted */
 343        u8 *ioctl_buf;  /* ioctl buffer */
 344        u8 *extra_buf;  /* maily to grab assoc information */
 345        struct dentry *debugfsdir;
 346        u8 ci[0] __attribute__ ((__aligned__(NETDEV_ALIGN)));
 347};
 348
 349#define wl_to_dev(w) (wiphy_dev(wl->wdev->wiphy))
 350#define wl_to_wiphy(w) (w->wdev->wiphy)
 351#define wiphy_to_wl(w) ((struct wl_priv *)(wiphy_priv(w)))
 352#define wl_to_wdev(w) (w->wdev)
 353#define wdev_to_wl(w) ((struct wl_priv *)(wdev_priv(w)))
 354#define wl_to_ndev(w) (w->wdev->netdev)
 355#define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
 356#define ci_to_wl(c) (ci->wl)
 357#define wl_to_ci(w) (&w->ci)
 358#define wl_to_sr(w) (w->scan_req_int)
 359#define wl_to_ie(w) (&w->ie)
 360#define iscan_to_wl(i) ((struct wl_priv *)(i->data))
 361#define wl_to_iscan(w) (w->iscan)
 362#define wl_to_conn(w) (&w->conn_info)
 363
 364static inline struct wl_bss_info *next_bss(struct wl_scan_results *list,
 365                                           struct wl_bss_info *bss)
 366{
 367        return bss = bss ?
 368                (struct wl_bss_info *)((unsigned long)bss +
 369                                       dtoh32(bss->length)) : list->bss_info;
 370}
 371
 372#define for_each_bss(list, bss, __i)    \
 373        for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
 374
 375extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data);
 376extern void wl_cfg80211_detach(void);
 377/* event handler from dongle */
 378extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
 379                              void *data);
 380extern void wl_cfg80211_sdio_func(void *func);  /* set sdio function info */
 381extern struct sdio_func *wl_cfg80211_get_sdio_func(void);       /* set sdio function info */
 382extern s32 wl_cfg80211_up(void);        /* dongle up */
 383extern s32 wl_cfg80211_down(void);      /* dongle down */
 384extern void wl_cfg80211_dbg_level(u32 level);   /* set dongle
 385                                                         debugging level */
 386extern void *wl_cfg80211_request_fw(s8 *file_name);     /* request fw /nvram
 387                                                         downloading */
 388extern s32 wl_cfg80211_read_fw(s8 *buf, u32 size);      /* read fw
 389                                                                 image */
 390extern void wl_cfg80211_release_fw(void);       /* release fw */
 391extern s8 *wl_cfg80211_get_fwname(void);        /* get firmware name for
 392                                                 the dongle */
 393extern s8 *wl_cfg80211_get_nvramname(void);     /* get nvram name for
 394                                                 the dongle */
 395
 396#endif                          /* _wl_cfg80211_h_ */
 397