Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef HOSTAP_AP_H
0003 #define HOSTAP_AP_H
0004 
0005 #include "hostap_80211.h"
0006 
0007 /* AP data structures for STAs */
0008 
0009 /* maximum number of frames to buffer per STA */
0010 #define STA_MAX_TX_BUFFER 32
0011 
0012 /* STA flags */
0013 #define WLAN_STA_AUTH BIT(0)
0014 #define WLAN_STA_ASSOC BIT(1)
0015 #define WLAN_STA_PS BIT(2)
0016 #define WLAN_STA_TIM BIT(3) /* TIM bit is on for PS stations */
0017 #define WLAN_STA_PERM BIT(4) /* permanent; do not remove entry on expiration */
0018 #define WLAN_STA_AUTHORIZED BIT(5) /* If 802.1X is used, this flag is
0019                     * controlling whether STA is authorized to
0020                     * send and receive non-IEEE 802.1X frames
0021                     */
0022 #define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
0023 
0024 #define WLAN_RATE_1M BIT(0)
0025 #define WLAN_RATE_2M BIT(1)
0026 #define WLAN_RATE_5M5 BIT(2)
0027 #define WLAN_RATE_11M BIT(3)
0028 #define WLAN_RATE_COUNT 4
0029 
0030 /* Maximum size of Supported Rates info element. IEEE 802.11 has a limit of 8,
0031  * but some pre-standard IEEE 802.11g products use longer elements. */
0032 #define WLAN_SUPP_RATES_MAX 32
0033 
0034 /* Try to increase TX rate after # successfully sent consecutive packets */
0035 #define WLAN_RATE_UPDATE_COUNT 50
0036 
0037 /* Decrease TX rate after # consecutive dropped packets */
0038 #define WLAN_RATE_DECREASE_THRESHOLD 2
0039 
0040 struct sta_info {
0041     struct list_head list;
0042     struct sta_info *hnext; /* next entry in hash table list */
0043     atomic_t users; /* number of users (do not remove if > 0) */
0044     struct proc_dir_entry *proc;
0045 
0046     u8 addr[6];
0047     u16 aid; /* STA's unique AID (1 .. 2007) or 0 if not yet assigned */
0048     u32 flags;
0049     u16 capability;
0050     u16 listen_interval; /* or beacon_int for APs */
0051     u8 supported_rates[WLAN_SUPP_RATES_MAX];
0052 
0053     unsigned long last_auth;
0054     unsigned long last_assoc;
0055     unsigned long last_rx;
0056     unsigned long last_tx;
0057     unsigned long rx_packets, tx_packets;
0058     unsigned long rx_bytes, tx_bytes;
0059     struct sk_buff_head tx_buf;
0060     /* FIX: timeout buffers with an expiry time somehow derived from
0061      * listen_interval */
0062 
0063     s8 last_rx_silence; /* Noise in dBm */
0064     s8 last_rx_signal; /* Signal strength in dBm */
0065     u8 last_rx_rate; /* TX rate in 0.1 Mbps */
0066     u8 last_rx_updated; /* IWSPY's struct iw_quality::updated */
0067 
0068     u8 tx_supp_rates; /* bit field of supported TX rates */
0069     u8 tx_rate; /* current TX rate (in 0.1 Mbps) */
0070     u8 tx_rate_idx; /* current TX rate (WLAN_RATE_*) */
0071     u8 tx_max_rate; /* max TX rate (WLAN_RATE_*) */
0072     u32 tx_count[WLAN_RATE_COUNT]; /* number of frames sent (per rate) */
0073     u32 rx_count[WLAN_RATE_COUNT]; /* number of frames received (per rate)
0074                     */
0075     u32 tx_since_last_failure;
0076     u32 tx_consecutive_exc;
0077 
0078     struct lib80211_crypt_data *crypt;
0079 
0080     int ap; /* whether this station is an AP */
0081 
0082     local_info_t *local;
0083 
0084 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
0085     union {
0086         struct {
0087             char *challenge; /* shared key authentication
0088                       * challenge */
0089         } sta;
0090         struct {
0091             int ssid_len;
0092             unsigned char ssid[MAX_SSID_LEN + 1]; /* AP's ssid */
0093             int channel;
0094             unsigned long last_beacon; /* last RX beacon time */
0095         } ap;
0096     } u;
0097 
0098     struct timer_list timer;
0099     enum { STA_NULLFUNC = 0, STA_DISASSOC, STA_DEAUTH } timeout_next;
0100 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
0101 };
0102 
0103 
0104 #define MAX_STA_COUNT 1024
0105 
0106 /* Maximum number of AIDs to use for STAs; must be 2007 or lower
0107  * (8802.11 limitation) */
0108 #define MAX_AID_TABLE_SIZE 128
0109 
0110 #define STA_HASH_SIZE 256
0111 #define STA_HASH(sta) (sta[5])
0112 
0113 
0114 /* Default value for maximum station inactivity. After AP_MAX_INACTIVITY_SEC
0115  * has passed since last received frame from the station, a nullfunc data
0116  * frame is sent to the station. If this frame is not acknowledged and no other
0117  * frames have been received, the station will be disassociated after
0118  * AP_DISASSOC_DELAY. Similarly, a the station will be deauthenticated after
0119  * AP_DEAUTH_DELAY. AP_TIMEOUT_RESOLUTION is the resolution that is used with
0120  * max inactivity timer. */
0121 #define AP_MAX_INACTIVITY_SEC (5 * 60)
0122 #define AP_DISASSOC_DELAY (HZ)
0123 #define AP_DEAUTH_DELAY (HZ)
0124 
0125 /* ap_policy: whether to accept frames to/from other APs/IBSS */
0126 typedef enum {
0127     AP_OTHER_AP_SKIP_ALL = 0,
0128     AP_OTHER_AP_SAME_SSID = 1,
0129     AP_OTHER_AP_ALL = 2,
0130     AP_OTHER_AP_EVEN_IBSS = 3
0131 } ap_policy_enum;
0132 
0133 #define PRISM2_AUTH_OPEN BIT(0)
0134 #define PRISM2_AUTH_SHARED_KEY BIT(1)
0135 
0136 
0137 /* MAC address-based restrictions */
0138 struct mac_entry {
0139     struct list_head list;
0140     u8 addr[6];
0141 };
0142 
0143 struct mac_restrictions {
0144     enum { MAC_POLICY_OPEN = 0, MAC_POLICY_ALLOW, MAC_POLICY_DENY } policy;
0145     unsigned int entries;
0146     struct list_head mac_list;
0147     spinlock_t lock;
0148 };
0149 
0150 
0151 struct add_sta_proc_data {
0152     u8 addr[ETH_ALEN];
0153     struct add_sta_proc_data *next;
0154 };
0155 
0156 
0157 typedef enum { WDS_ADD, WDS_DEL } wds_oper_type;
0158 struct wds_oper_data {
0159     wds_oper_type type;
0160     u8 addr[ETH_ALEN];
0161     struct wds_oper_data *next;
0162 };
0163 
0164 
0165 struct ap_data {
0166     int initialized; /* whether ap_data has been initialized */
0167     local_info_t *local;
0168     int bridge_packets; /* send packet to associated STAs directly to the
0169                  * wireless media instead of higher layers in the
0170                  * kernel */
0171     unsigned int bridged_unicast; /* number of unicast frames bridged on
0172                        * wireless media */
0173     unsigned int bridged_multicast; /* number of non-unicast frames
0174                      * bridged on wireless media */
0175     unsigned int tx_drop_nonassoc; /* number of unicast TX packets dropped
0176                     * because they were to an address that
0177                     * was not associated */
0178     int nullfunc_ack; /* use workaround for nullfunc frame ACKs */
0179 
0180     spinlock_t sta_table_lock;
0181     int num_sta; /* number of entries in sta_list */
0182     struct list_head sta_list; /* STA info list head */
0183     struct sta_info *sta_hash[STA_HASH_SIZE];
0184 
0185     struct proc_dir_entry *proc;
0186 
0187     ap_policy_enum ap_policy;
0188     unsigned int max_inactivity;
0189     int autom_ap_wds;
0190 
0191     struct mac_restrictions mac_restrictions; /* MAC-based auth */
0192     int last_tx_rate;
0193 
0194     struct work_struct add_sta_proc_queue;
0195     struct add_sta_proc_data *add_sta_proc_entries;
0196 
0197     struct work_struct wds_oper_queue;
0198     struct wds_oper_data *wds_oper_entries;
0199 
0200     u16 tx_callback_idx;
0201 
0202 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
0203     /* pointers to STA info; based on allocated AID or NULL if AID free
0204      * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
0205      * and so on
0206      */
0207     struct sta_info *sta_aid[MAX_AID_TABLE_SIZE];
0208 
0209     u16 tx_callback_auth, tx_callback_assoc, tx_callback_poll;
0210 
0211     /* WEP operations for generating challenges to be used with shared key
0212      * authentication */
0213     struct lib80211_crypto_ops *crypt;
0214     void *crypt_priv;
0215 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
0216 };
0217 
0218 
0219 void hostap_rx(struct net_device *dev, struct sk_buff *skb,
0220            struct hostap_80211_rx_status *rx_stats);
0221 void hostap_init_data(local_info_t *local);
0222 void hostap_init_ap_proc(local_info_t *local);
0223 void hostap_free_data(struct ap_data *ap);
0224 void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver);
0225 
0226 typedef enum {
0227     AP_TX_CONTINUE, AP_TX_DROP, AP_TX_RETRY, AP_TX_BUFFERED,
0228     AP_TX_CONTINUE_NOT_AUTHORIZED
0229 } ap_tx_ret;
0230 struct hostap_tx_data {
0231     struct sk_buff *skb;
0232     int host_encrypt;
0233     struct lib80211_crypt_data *crypt;
0234     void *sta_ptr;
0235 };
0236 ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx);
0237 void hostap_handle_sta_release(void *ptr);
0238 void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb);
0239 int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr *hdr);
0240 typedef enum {
0241     AP_RX_CONTINUE, AP_RX_DROP, AP_RX_EXIT, AP_RX_CONTINUE_NOT_AUTHORIZED
0242 } ap_rx_ret;
0243 ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
0244                    struct sk_buff *skb,
0245                    struct hostap_80211_rx_status *rx_stats,
0246                    int wds);
0247 int hostap_handle_sta_crypto(local_info_t *local, struct ieee80211_hdr *hdr,
0248                  struct lib80211_crypt_data **crypt,
0249                  void **sta_ptr);
0250 int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr);
0251 int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr);
0252 int hostap_add_sta(struct ap_data *ap, u8 *sta_addr);
0253 int hostap_update_rx_stats(struct ap_data *ap, struct ieee80211_hdr *hdr,
0254                struct hostap_80211_rx_status *rx_stats);
0255 void hostap_update_rates(local_info_t *local);
0256 void hostap_add_wds_links(local_info_t *local);
0257 void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type);
0258 
0259 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
0260 void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
0261                 int resend);
0262 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
0263 
0264 #endif /* HOSTAP_AP_H */