Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright (c) 2002,2003 Oliver Kurth
0004  *       (c) 2003,2004 Joerg Albert <joerg.albert@gmx.de>
0005  *       (c) 2007 Guido Guenther <agx@sigxcpu.org>
0006  *
0007  * This driver was based on information from the Sourceforge driver
0008  * released and maintained by Atmel:
0009  *
0010  *  http://sourceforge.net/projects/atmelwlandriver/
0011  *
0012  * Although the code was completely re-written,
0013  * it would have been impossible without Atmel's decision to
0014  * release an Open Source driver (unfortunately the firmware was
0015  * kept binary only). Thanks for that decision to Atmel!
0016  */
0017 
0018 #ifndef _AT76_USB_H
0019 #define _AT76_USB_H
0020 
0021 /* Board types */
0022 enum board_type {
0023     BOARD_503_ISL3861 = 1,
0024     BOARD_503_ISL3863 = 2,
0025     BOARD_503 = 3,
0026     BOARD_503_ACC = 4,
0027     BOARD_505 = 5,
0028     BOARD_505_2958 = 6,
0029     BOARD_505A = 7,
0030     BOARD_505AMX = 8
0031 };
0032 
0033 #define CMD_STATUS_IDLE             0x00
0034 #define CMD_STATUS_COMPLETE         0x01
0035 #define CMD_STATUS_UNKNOWN          0x02
0036 #define CMD_STATUS_INVALID_PARAMETER        0x03
0037 #define CMD_STATUS_FUNCTION_NOT_SUPPORTED   0x04
0038 #define CMD_STATUS_TIME_OUT         0x07
0039 #define CMD_STATUS_IN_PROGRESS          0x08
0040 #define CMD_STATUS_HOST_FAILURE         0xff
0041 #define CMD_STATUS_SCAN_FAILED          0xf0
0042 
0043 /* answers to get op mode */
0044 #define OPMODE_NONE             0x00
0045 #define OPMODE_NORMAL_NIC_WITH_FLASH        0x01
0046 #define OPMODE_HW_CONFIG_MODE           0x02
0047 #define OPMODE_DFU_MODE_WITH_FLASH      0x03
0048 #define OPMODE_NORMAL_NIC_WITHOUT_FLASH     0x04
0049 
0050 #define CMD_SET_MIB     0x01
0051 #define CMD_GET_MIB     0x02
0052 #define CMD_SCAN        0x03
0053 #define CMD_JOIN        0x04
0054 #define CMD_START_IBSS      0x05
0055 #define CMD_RADIO_ON        0x06
0056 #define CMD_RADIO_OFF       0x07
0057 #define CMD_STARTUP     0x0B
0058 
0059 #define MIB_LOCAL       0x01
0060 #define MIB_MAC_ADDR        0x02
0061 #define MIB_MAC         0x03
0062 #define MIB_MAC_MGMT        0x05
0063 #define MIB_MAC_WEP     0x06
0064 #define MIB_PHY         0x07
0065 #define MIB_FW_VERSION      0x08
0066 #define MIB_MDOMAIN     0x09
0067 
0068 #define ADHOC_MODE      1
0069 #define INFRASTRUCTURE_MODE 2
0070 
0071 /* values for struct mib_local, field preamble_type */
0072 #define PREAMBLE_TYPE_LONG  0
0073 #define PREAMBLE_TYPE_SHORT 1
0074 #define PREAMBLE_TYPE_AUTO  2
0075 
0076 /* values for tx_rate */
0077 #define TX_RATE_1MBIT       0
0078 #define TX_RATE_2MBIT       1
0079 #define TX_RATE_5_5MBIT     2
0080 #define TX_RATE_11MBIT      3
0081 #define TX_RATE_AUTO        4
0082 
0083 /* power management modes */
0084 #define AT76_PM_OFF     1
0085 #define AT76_PM_ON      2
0086 #define AT76_PM_SMART       3
0087 
0088 struct hwcfg_r505 {
0089     u8 cr39_values[14];
0090     u8 reserved1[14];
0091     u8 bb_cr[14];
0092     u8 pidvid[4];
0093     u8 mac_addr[ETH_ALEN];
0094     u8 regulatory_domain;
0095     u8 reserved2[14];
0096     u8 cr15_values[14];
0097     u8 reserved3[3];
0098 } __packed;
0099 
0100 struct hwcfg_rfmd {
0101     u8 cr20_values[14];
0102     u8 cr21_values[14];
0103     u8 bb_cr[14];
0104     u8 pidvid[4];
0105     u8 mac_addr[ETH_ALEN];
0106     u8 regulatory_domain;
0107     u8 low_power_values[14];
0108     u8 normal_power_values[14];
0109     u8 reserved1[3];
0110 } __packed;
0111 
0112 struct hwcfg_intersil {
0113     u8 mac_addr[ETH_ALEN];
0114     u8 cr31_values[14];
0115     u8 cr58_values[14];
0116     u8 pidvid[4];
0117     u8 regulatory_domain;
0118     u8 reserved[1];
0119 } __packed;
0120 
0121 union at76_hwcfg {
0122     struct hwcfg_intersil i;
0123     struct hwcfg_rfmd r3;
0124     struct hwcfg_r505 r5;
0125 };
0126 
0127 #define WEP_SMALL_KEY_LEN   (40 / 8)
0128 #define WEP_LARGE_KEY_LEN   (104 / 8)
0129 #define WEP_KEYS        (4)
0130 
0131 struct at76_card_config {
0132     u8 exclude_unencrypted;
0133     u8 promiscuous_mode;
0134     u8 short_retry_limit;
0135     u8 encryption_type;
0136     __le16 rts_threshold;
0137     __le16 fragmentation_threshold; /* 256..2346 */
0138     u8 basic_rate_set[4];
0139     u8 auto_rate_fallback;  /* 0,1 */
0140     u8 channel;
0141     u8 privacy_invoked;
0142     u8 wep_default_key_id;  /* 0..3 */
0143     u8 current_ssid[32];
0144     u8 wep_default_key_value[4][WEP_LARGE_KEY_LEN];
0145     u8 ssid_len;
0146     u8 short_preamble;
0147     __le16 beacon_period;
0148 } __packed;
0149 
0150 struct at76_command {
0151     u8 cmd;
0152     u8 reserved;
0153     __le16 size;
0154     u8 data[];
0155 } __packed;
0156 
0157 /* Length of Atmel-specific Rx header before 802.11 frame */
0158 #define AT76_RX_HDRLEN offsetof(struct at76_rx_buffer, packet)
0159 
0160 struct at76_rx_buffer {
0161     __le16 wlength;
0162     u8 rx_rate;
0163     u8 newbss;
0164     u8 fragmentation;
0165     u8 rssi;
0166     u8 link_quality;
0167     u8 noise_level;
0168     __le32 rx_time;
0169     u8 packet[IEEE80211_MAX_FRAG_THRESHOLD];
0170 } __packed;
0171 
0172 /* Length of Atmel-specific Tx header before 802.11 frame */
0173 #define AT76_TX_HDRLEN offsetof(struct at76_tx_buffer, packet)
0174 
0175 struct at76_tx_buffer {
0176     __le16 wlength;
0177     u8 tx_rate;
0178     u8 padding;
0179     u8 reserved[4];
0180     u8 packet[IEEE80211_MAX_FRAG_THRESHOLD];
0181 } __packed;
0182 
0183 /* defines for scan_type below */
0184 #define SCAN_TYPE_ACTIVE    0
0185 #define SCAN_TYPE_PASSIVE   1
0186 
0187 struct at76_req_scan {
0188     u8 bssid[ETH_ALEN];
0189     u8 essid[32];
0190     u8 scan_type;
0191     u8 channel;
0192     __le16 probe_delay;
0193     __le16 min_channel_time;
0194     __le16 max_channel_time;
0195     u8 essid_size;
0196     u8 international_scan;
0197 } __packed;
0198 
0199 struct at76_req_ibss {
0200     u8 bssid[ETH_ALEN];
0201     u8 essid[32];
0202     u8 bss_type;
0203     u8 channel;
0204     u8 essid_size;
0205     u8 reserved[3];
0206 } __packed;
0207 
0208 struct at76_req_join {
0209     u8 bssid[ETH_ALEN];
0210     u8 essid[32];
0211     u8 bss_type;
0212     u8 channel;
0213     __le16 timeout;
0214     u8 essid_size;
0215     u8 reserved;
0216 } __packed;
0217 
0218 struct mib_local {
0219     u16 reserved0;
0220     u8 beacon_enable;
0221     u8 txautorate_fallback;
0222     u8 reserved1;
0223     u8 ssid_size;
0224     u8 promiscuous_mode;
0225     u16 reserved2;
0226     u8 preamble_type;
0227     u16 reserved3;
0228 } __packed;
0229 
0230 struct mib_mac_addr {
0231     u8 mac_addr[ETH_ALEN];
0232     u8 res[2];      /* ??? */
0233     u8 group_addr[4][ETH_ALEN];
0234     u8 group_addr_status[4];
0235 } __packed;
0236 
0237 struct mib_mac {
0238     __le32 max_tx_msdu_lifetime;
0239     __le32 max_rx_lifetime;
0240     __le16 frag_threshold;
0241     __le16 rts_threshold;
0242     __le16 cwmin;
0243     __le16 cwmax;
0244     u8 short_retry_time;
0245     u8 long_retry_time;
0246     u8 scan_type;       /* active or passive */
0247     u8 scan_channel;
0248     __le16 probe_delay; /* delay before ProbeReq in active scan, RO */
0249     __le16 min_channel_time;
0250     __le16 max_channel_time;
0251     __le16 listen_interval;
0252     u8 desired_ssid[32];
0253     u8 desired_bssid[ETH_ALEN];
0254     u8 desired_bsstype; /* ad-hoc or infrastructure */
0255     u8 reserved2;
0256 } __packed;
0257 
0258 struct mib_mac_mgmt {
0259     __le16 beacon_period;
0260     __le16 CFP_max_duration;
0261     __le16 medium_occupancy_limit;
0262     __le16 station_id;  /* assoc id */
0263     __le16 ATIM_window;
0264     u8 CFP_mode;
0265     u8 privacy_option_implemented;
0266     u8 DTIM_period;
0267     u8 CFP_period;
0268     u8 current_bssid[ETH_ALEN];
0269     u8 current_essid[32];
0270     u8 current_bss_type;
0271     u8 power_mgmt_mode;
0272     /* rfmd and 505 */
0273     u8 ibss_change;
0274     u8 res;
0275     u8 multi_domain_capability_implemented;
0276     u8 multi_domain_capability_enabled;
0277     u8 country_string[IEEE80211_COUNTRY_STRING_LEN];
0278     u8 reserved[3];
0279 } __packed;
0280 
0281 struct mib_mac_wep {
0282     u8 privacy_invoked; /* 0 disable encr., 1 enable encr */
0283     u8 wep_default_key_id;
0284     u8 wep_key_mapping_len;
0285     u8 exclude_unencrypted;
0286     __le32 wep_icv_error_count;
0287     __le32 wep_excluded_count;
0288     u8 wep_default_keyvalue[WEP_KEYS][WEP_LARGE_KEY_LEN];
0289     u8 encryption_level;    /* 1 for 40bit, 2 for 104bit encryption */
0290 } __packed;
0291 
0292 struct mib_phy {
0293     __le32 ed_threshold;
0294 
0295     __le16 slot_time;
0296     __le16 sifs_time;
0297     __le16 preamble_length;
0298     __le16 plcp_header_length;
0299     __le16 mpdu_max_length;
0300     __le16 cca_mode_supported;
0301 
0302     u8 operation_rate_set[4];
0303     u8 channel_id;
0304     u8 current_cca_mode;
0305     u8 phy_type;
0306     u8 current_reg_domain;
0307 } __packed;
0308 
0309 struct mib_fw_version {
0310     u8 major;
0311     u8 minor;
0312     u8 patch;
0313     u8 build;
0314 } __packed;
0315 
0316 struct mib_mdomain {
0317     u8 tx_powerlevel[14];
0318     u8 channel_list[14];    /* 0 for invalid channels */
0319 } __packed;
0320 
0321 struct set_mib_buffer {
0322     u8 type;
0323     u8 size;
0324     u8 index;
0325     u8 reserved;
0326     union {
0327         u8 byte;
0328         __le16 word;
0329         u8 addr[ETH_ALEN];
0330         struct mib_mac_wep wep_mib;
0331     } data;
0332 } __packed;
0333 
0334 struct at76_fw_header {
0335     __le32 crc;     /* CRC32 of the whole image */
0336     __le32 board_type;  /* firmware compatibility code */
0337     u8 build;       /* firmware build number */
0338     u8 patch;       /* firmware patch level */
0339     u8 minor;       /* firmware minor version */
0340     u8 major;       /* firmware major version */
0341     __le32 str_offset;  /* offset of the copyright string */
0342     __le32 int_fw_offset;   /* internal firmware image offset */
0343     __le32 int_fw_len;  /* internal firmware image length */
0344     __le32 ext_fw_offset;   /* external firmware image offset */
0345     __le32 ext_fw_len;  /* external firmware image length */
0346 } __packed;
0347 
0348 /* a description of a regulatory domain and the allowed channels */
0349 struct reg_domain {
0350     u16 code;
0351     char const *name;
0352     u32 channel_map;    /* if bit N is set, channel (N+1) is allowed */
0353 };
0354 
0355 /* Data for one loaded firmware file */
0356 struct fwentry {
0357     const char *const fwname;
0358     const struct firmware *fw;
0359     int extfw_size;
0360     int intfw_size;
0361     /* pointer to loaded firmware, no need to free */
0362     u8 *extfw;      /* external firmware, extfw_size bytes long */
0363     u8 *intfw;      /* internal firmware, intfw_size bytes long */
0364     enum board_type board_type; /* board type */
0365     struct mib_fw_version fw_version;
0366     int loaded;     /* Loaded and parsed successfully */
0367 };
0368 
0369 struct at76_priv {
0370     struct usb_device *udev;    /* USB device pointer */
0371 
0372     struct sk_buff *rx_skb; /* skbuff for receiving data */
0373     struct sk_buff *tx_skb; /* skbuff for transmitting data */
0374     void *bulk_out_buffer;  /* buffer for sending data */
0375 
0376     struct urb *tx_urb; /* URB for sending data */
0377     struct urb *rx_urb; /* URB for receiving data */
0378 
0379     unsigned int tx_pipe;   /* bulk out pipe */
0380     unsigned int rx_pipe;   /* bulk in pipe */
0381 
0382     struct mutex mtx;   /* locks this structure */
0383 
0384     /* work queues */
0385     struct work_struct work_set_promisc;
0386     struct work_struct work_submit_rx;
0387     struct work_struct work_join_bssid;
0388     struct delayed_work dwork_hw_scan;
0389 
0390     struct tasklet_struct rx_tasklet;
0391 
0392     /* the WEP stuff */
0393     int wep_enabled;    /* 1 if WEP is enabled */
0394     int wep_key_id;     /* key id to be used */
0395     u8 wep_keys[WEP_KEYS][WEP_LARGE_KEY_LEN];   /* WEP keys */
0396     u8 wep_keys_len[WEP_KEYS];  /* length of WEP keys */
0397 
0398     int channel;
0399     int iw_mode;
0400     u8 bssid[ETH_ALEN];
0401     u8 essid[IW_ESSID_MAX_SIZE];
0402     int essid_size;
0403     int radio_on;
0404     int promisc;
0405 
0406     int preamble_type;  /* 0 - long, 1 - short, 2 - auto */
0407     int auth_mode;      /* authentication type: 0 open, 1 shared key */
0408     int txrate;     /* 0,1,2,3 = 1,2,5.5,11 Mbps, 4 is auto */
0409     int frag_threshold; /* threshold for fragmentation of tx packets */
0410     int rts_threshold;  /* threshold for RTS mechanism */
0411     int short_retry_limit;
0412 
0413     int scan_min_time;  /* scan min channel time */
0414     int scan_max_time;  /* scan max channel time */
0415     int scan_mode;      /* SCAN_TYPE_ACTIVE, SCAN_TYPE_PASSIVE */
0416     int scan_need_any;  /* if set, need to scan for any ESSID */
0417     bool scanning;      /* if set, the scan is running */
0418 
0419     u16 assoc_id;       /* current association ID, if associated */
0420 
0421     u8 pm_mode;     /* power management mode */
0422     u32 pm_period;      /* power management period in microseconds */
0423 
0424     struct reg_domain const *domain;    /* reg domain description */
0425 
0426     /* These fields contain HW config provided by the device (not all of
0427      * these fields are used by all board types) */
0428     u8 mac_addr[ETH_ALEN];
0429     u8 regulatory_domain;
0430 
0431     struct at76_card_config card_config;
0432 
0433     enum board_type board_type;
0434     struct mib_fw_version fw_version;
0435 
0436     unsigned int device_unplugged:1;
0437     unsigned int netdev_registered:1;
0438     struct set_mib_buffer mib_buf;  /* global buffer for set_mib calls */
0439 
0440     int beacon_period;  /* period of mgmt beacons, Kus */
0441 
0442     struct ieee80211_hw *hw;
0443     int mac80211_registered;
0444 };
0445 
0446 #define AT76_SUPPORTED_FILTERS 0
0447 
0448 #define SCAN_POLL_INTERVAL  (HZ / 4)
0449 
0450 #define CMD_COMPLETION_TIMEOUT  (5 * HZ)
0451 
0452 #define DEF_RTS_THRESHOLD   1536
0453 #define DEF_FRAG_THRESHOLD  1536
0454 #define DEF_SHORT_RETRY_LIMIT   8
0455 #define DEF_CHANNEL     10
0456 #define DEF_SCAN_MIN_TIME   10
0457 #define DEF_SCAN_MAX_TIME   120
0458 
0459 /* the max padding size for tx in bytes (see calc_padding) */
0460 #define MAX_PADDING_SIZE    53
0461 
0462 #endif              /* _AT76_USB_H */