1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun #ifndef HOSTAP_AP_H 3*4882a593Smuzhiyun #define HOSTAP_AP_H 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun #include "hostap_80211.h" 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun /* AP data structures for STAs */ 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun /* maximum number of frames to buffer per STA */ 10*4882a593Smuzhiyun #define STA_MAX_TX_BUFFER 32 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun /* STA flags */ 13*4882a593Smuzhiyun #define WLAN_STA_AUTH BIT(0) 14*4882a593Smuzhiyun #define WLAN_STA_ASSOC BIT(1) 15*4882a593Smuzhiyun #define WLAN_STA_PS BIT(2) 16*4882a593Smuzhiyun #define WLAN_STA_TIM BIT(3) /* TIM bit is on for PS stations */ 17*4882a593Smuzhiyun #define WLAN_STA_PERM BIT(4) /* permanent; do not remove entry on expiration */ 18*4882a593Smuzhiyun #define WLAN_STA_AUTHORIZED BIT(5) /* If 802.1X is used, this flag is 19*4882a593Smuzhiyun * controlling whether STA is authorized to 20*4882a593Smuzhiyun * send and receive non-IEEE 802.1X frames 21*4882a593Smuzhiyun */ 22*4882a593Smuzhiyun #define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */ 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun #define WLAN_RATE_1M BIT(0) 25*4882a593Smuzhiyun #define WLAN_RATE_2M BIT(1) 26*4882a593Smuzhiyun #define WLAN_RATE_5M5 BIT(2) 27*4882a593Smuzhiyun #define WLAN_RATE_11M BIT(3) 28*4882a593Smuzhiyun #define WLAN_RATE_COUNT 4 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun /* Maximum size of Supported Rates info element. IEEE 802.11 has a limit of 8, 31*4882a593Smuzhiyun * but some pre-standard IEEE 802.11g products use longer elements. */ 32*4882a593Smuzhiyun #define WLAN_SUPP_RATES_MAX 32 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun /* Try to increase TX rate after # successfully sent consecutive packets */ 35*4882a593Smuzhiyun #define WLAN_RATE_UPDATE_COUNT 50 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun /* Decrease TX rate after # consecutive dropped packets */ 38*4882a593Smuzhiyun #define WLAN_RATE_DECREASE_THRESHOLD 2 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun struct sta_info { 41*4882a593Smuzhiyun struct list_head list; 42*4882a593Smuzhiyun struct sta_info *hnext; /* next entry in hash table list */ 43*4882a593Smuzhiyun atomic_t users; /* number of users (do not remove if > 0) */ 44*4882a593Smuzhiyun struct proc_dir_entry *proc; 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun u8 addr[6]; 47*4882a593Smuzhiyun u16 aid; /* STA's unique AID (1 .. 2007) or 0 if not yet assigned */ 48*4882a593Smuzhiyun u32 flags; 49*4882a593Smuzhiyun u16 capability; 50*4882a593Smuzhiyun u16 listen_interval; /* or beacon_int for APs */ 51*4882a593Smuzhiyun u8 supported_rates[WLAN_SUPP_RATES_MAX]; 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun unsigned long last_auth; 54*4882a593Smuzhiyun unsigned long last_assoc; 55*4882a593Smuzhiyun unsigned long last_rx; 56*4882a593Smuzhiyun unsigned long last_tx; 57*4882a593Smuzhiyun unsigned long rx_packets, tx_packets; 58*4882a593Smuzhiyun unsigned long rx_bytes, tx_bytes; 59*4882a593Smuzhiyun struct sk_buff_head tx_buf; 60*4882a593Smuzhiyun /* FIX: timeout buffers with an expiry time somehow derived from 61*4882a593Smuzhiyun * listen_interval */ 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun s8 last_rx_silence; /* Noise in dBm */ 64*4882a593Smuzhiyun s8 last_rx_signal; /* Signal strength in dBm */ 65*4882a593Smuzhiyun u8 last_rx_rate; /* TX rate in 0.1 Mbps */ 66*4882a593Smuzhiyun u8 last_rx_updated; /* IWSPY's struct iw_quality::updated */ 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun u8 tx_supp_rates; /* bit field of supported TX rates */ 69*4882a593Smuzhiyun u8 tx_rate; /* current TX rate (in 0.1 Mbps) */ 70*4882a593Smuzhiyun u8 tx_rate_idx; /* current TX rate (WLAN_RATE_*) */ 71*4882a593Smuzhiyun u8 tx_max_rate; /* max TX rate (WLAN_RATE_*) */ 72*4882a593Smuzhiyun u32 tx_count[WLAN_RATE_COUNT]; /* number of frames sent (per rate) */ 73*4882a593Smuzhiyun u32 rx_count[WLAN_RATE_COUNT]; /* number of frames received (per rate) 74*4882a593Smuzhiyun */ 75*4882a593Smuzhiyun u32 tx_since_last_failure; 76*4882a593Smuzhiyun u32 tx_consecutive_exc; 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun struct lib80211_crypt_data *crypt; 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun int ap; /* whether this station is an AP */ 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun local_info_t *local; 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT 85*4882a593Smuzhiyun union { 86*4882a593Smuzhiyun struct { 87*4882a593Smuzhiyun char *challenge; /* shared key authentication 88*4882a593Smuzhiyun * challenge */ 89*4882a593Smuzhiyun } sta; 90*4882a593Smuzhiyun struct { 91*4882a593Smuzhiyun int ssid_len; 92*4882a593Smuzhiyun unsigned char ssid[MAX_SSID_LEN + 1]; /* AP's ssid */ 93*4882a593Smuzhiyun int channel; 94*4882a593Smuzhiyun unsigned long last_beacon; /* last RX beacon time */ 95*4882a593Smuzhiyun } ap; 96*4882a593Smuzhiyun } u; 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun struct timer_list timer; 99*4882a593Smuzhiyun enum { STA_NULLFUNC = 0, STA_DISASSOC, STA_DEAUTH } timeout_next; 100*4882a593Smuzhiyun #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 101*4882a593Smuzhiyun }; 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun #define MAX_STA_COUNT 1024 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun /* Maximum number of AIDs to use for STAs; must be 2007 or lower 107*4882a593Smuzhiyun * (8802.11 limitation) */ 108*4882a593Smuzhiyun #define MAX_AID_TABLE_SIZE 128 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun #define STA_HASH_SIZE 256 111*4882a593Smuzhiyun #define STA_HASH(sta) (sta[5]) 112*4882a593Smuzhiyun 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun /* Default value for maximum station inactivity. After AP_MAX_INACTIVITY_SEC 115*4882a593Smuzhiyun * has passed since last received frame from the station, a nullfunc data 116*4882a593Smuzhiyun * frame is sent to the station. If this frame is not acknowledged and no other 117*4882a593Smuzhiyun * frames have been received, the station will be disassociated after 118*4882a593Smuzhiyun * AP_DISASSOC_DELAY. Similarly, a the station will be deauthenticated after 119*4882a593Smuzhiyun * AP_DEAUTH_DELAY. AP_TIMEOUT_RESOLUTION is the resolution that is used with 120*4882a593Smuzhiyun * max inactivity timer. */ 121*4882a593Smuzhiyun #define AP_MAX_INACTIVITY_SEC (5 * 60) 122*4882a593Smuzhiyun #define AP_DISASSOC_DELAY (HZ) 123*4882a593Smuzhiyun #define AP_DEAUTH_DELAY (HZ) 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun /* ap_policy: whether to accept frames to/from other APs/IBSS */ 126*4882a593Smuzhiyun typedef enum { 127*4882a593Smuzhiyun AP_OTHER_AP_SKIP_ALL = 0, 128*4882a593Smuzhiyun AP_OTHER_AP_SAME_SSID = 1, 129*4882a593Smuzhiyun AP_OTHER_AP_ALL = 2, 130*4882a593Smuzhiyun AP_OTHER_AP_EVEN_IBSS = 3 131*4882a593Smuzhiyun } ap_policy_enum; 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun #define PRISM2_AUTH_OPEN BIT(0) 134*4882a593Smuzhiyun #define PRISM2_AUTH_SHARED_KEY BIT(1) 135*4882a593Smuzhiyun 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun /* MAC address-based restrictions */ 138*4882a593Smuzhiyun struct mac_entry { 139*4882a593Smuzhiyun struct list_head list; 140*4882a593Smuzhiyun u8 addr[6]; 141*4882a593Smuzhiyun }; 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun struct mac_restrictions { 144*4882a593Smuzhiyun enum { MAC_POLICY_OPEN = 0, MAC_POLICY_ALLOW, MAC_POLICY_DENY } policy; 145*4882a593Smuzhiyun unsigned int entries; 146*4882a593Smuzhiyun struct list_head mac_list; 147*4882a593Smuzhiyun spinlock_t lock; 148*4882a593Smuzhiyun }; 149*4882a593Smuzhiyun 150*4882a593Smuzhiyun 151*4882a593Smuzhiyun struct add_sta_proc_data { 152*4882a593Smuzhiyun u8 addr[ETH_ALEN]; 153*4882a593Smuzhiyun struct add_sta_proc_data *next; 154*4882a593Smuzhiyun }; 155*4882a593Smuzhiyun 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun typedef enum { WDS_ADD, WDS_DEL } wds_oper_type; 158*4882a593Smuzhiyun struct wds_oper_data { 159*4882a593Smuzhiyun wds_oper_type type; 160*4882a593Smuzhiyun u8 addr[ETH_ALEN]; 161*4882a593Smuzhiyun struct wds_oper_data *next; 162*4882a593Smuzhiyun }; 163*4882a593Smuzhiyun 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun struct ap_data { 166*4882a593Smuzhiyun int initialized; /* whether ap_data has been initialized */ 167*4882a593Smuzhiyun local_info_t *local; 168*4882a593Smuzhiyun int bridge_packets; /* send packet to associated STAs directly to the 169*4882a593Smuzhiyun * wireless media instead of higher layers in the 170*4882a593Smuzhiyun * kernel */ 171*4882a593Smuzhiyun unsigned int bridged_unicast; /* number of unicast frames bridged on 172*4882a593Smuzhiyun * wireless media */ 173*4882a593Smuzhiyun unsigned int bridged_multicast; /* number of non-unicast frames 174*4882a593Smuzhiyun * bridged on wireless media */ 175*4882a593Smuzhiyun unsigned int tx_drop_nonassoc; /* number of unicast TX packets dropped 176*4882a593Smuzhiyun * because they were to an address that 177*4882a593Smuzhiyun * was not associated */ 178*4882a593Smuzhiyun int nullfunc_ack; /* use workaround for nullfunc frame ACKs */ 179*4882a593Smuzhiyun 180*4882a593Smuzhiyun spinlock_t sta_table_lock; 181*4882a593Smuzhiyun int num_sta; /* number of entries in sta_list */ 182*4882a593Smuzhiyun struct list_head sta_list; /* STA info list head */ 183*4882a593Smuzhiyun struct sta_info *sta_hash[STA_HASH_SIZE]; 184*4882a593Smuzhiyun 185*4882a593Smuzhiyun struct proc_dir_entry *proc; 186*4882a593Smuzhiyun 187*4882a593Smuzhiyun ap_policy_enum ap_policy; 188*4882a593Smuzhiyun unsigned int max_inactivity; 189*4882a593Smuzhiyun int autom_ap_wds; 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun struct mac_restrictions mac_restrictions; /* MAC-based auth */ 192*4882a593Smuzhiyun int last_tx_rate; 193*4882a593Smuzhiyun 194*4882a593Smuzhiyun struct work_struct add_sta_proc_queue; 195*4882a593Smuzhiyun struct add_sta_proc_data *add_sta_proc_entries; 196*4882a593Smuzhiyun 197*4882a593Smuzhiyun struct work_struct wds_oper_queue; 198*4882a593Smuzhiyun struct wds_oper_data *wds_oper_entries; 199*4882a593Smuzhiyun 200*4882a593Smuzhiyun u16 tx_callback_idx; 201*4882a593Smuzhiyun 202*4882a593Smuzhiyun #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT 203*4882a593Smuzhiyun /* pointers to STA info; based on allocated AID or NULL if AID free 204*4882a593Smuzhiyun * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1 205*4882a593Smuzhiyun * and so on 206*4882a593Smuzhiyun */ 207*4882a593Smuzhiyun struct sta_info *sta_aid[MAX_AID_TABLE_SIZE]; 208*4882a593Smuzhiyun 209*4882a593Smuzhiyun u16 tx_callback_auth, tx_callback_assoc, tx_callback_poll; 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun /* WEP operations for generating challenges to be used with shared key 212*4882a593Smuzhiyun * authentication */ 213*4882a593Smuzhiyun struct lib80211_crypto_ops *crypt; 214*4882a593Smuzhiyun void *crypt_priv; 215*4882a593Smuzhiyun #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 216*4882a593Smuzhiyun }; 217*4882a593Smuzhiyun 218*4882a593Smuzhiyun 219*4882a593Smuzhiyun void hostap_rx(struct net_device *dev, struct sk_buff *skb, 220*4882a593Smuzhiyun struct hostap_80211_rx_status *rx_stats); 221*4882a593Smuzhiyun void hostap_init_data(local_info_t *local); 222*4882a593Smuzhiyun void hostap_init_ap_proc(local_info_t *local); 223*4882a593Smuzhiyun void hostap_free_data(struct ap_data *ap); 224*4882a593Smuzhiyun void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver); 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun typedef enum { 227*4882a593Smuzhiyun AP_TX_CONTINUE, AP_TX_DROP, AP_TX_RETRY, AP_TX_BUFFERED, 228*4882a593Smuzhiyun AP_TX_CONTINUE_NOT_AUTHORIZED 229*4882a593Smuzhiyun } ap_tx_ret; 230*4882a593Smuzhiyun struct hostap_tx_data { 231*4882a593Smuzhiyun struct sk_buff *skb; 232*4882a593Smuzhiyun int host_encrypt; 233*4882a593Smuzhiyun struct lib80211_crypt_data *crypt; 234*4882a593Smuzhiyun void *sta_ptr; 235*4882a593Smuzhiyun }; 236*4882a593Smuzhiyun ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx); 237*4882a593Smuzhiyun void hostap_handle_sta_release(void *ptr); 238*4882a593Smuzhiyun void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb); 239*4882a593Smuzhiyun int hostap_update_sta_ps(local_info_t *local, struct ieee80211_hdr *hdr); 240*4882a593Smuzhiyun typedef enum { 241*4882a593Smuzhiyun AP_RX_CONTINUE, AP_RX_DROP, AP_RX_EXIT, AP_RX_CONTINUE_NOT_AUTHORIZED 242*4882a593Smuzhiyun } ap_rx_ret; 243*4882a593Smuzhiyun ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev, 244*4882a593Smuzhiyun struct sk_buff *skb, 245*4882a593Smuzhiyun struct hostap_80211_rx_status *rx_stats, 246*4882a593Smuzhiyun int wds); 247*4882a593Smuzhiyun int hostap_handle_sta_crypto(local_info_t *local, struct ieee80211_hdr *hdr, 248*4882a593Smuzhiyun struct lib80211_crypt_data **crypt, 249*4882a593Smuzhiyun void **sta_ptr); 250*4882a593Smuzhiyun int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr); 251*4882a593Smuzhiyun int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr); 252*4882a593Smuzhiyun int hostap_add_sta(struct ap_data *ap, u8 *sta_addr); 253*4882a593Smuzhiyun int hostap_update_rx_stats(struct ap_data *ap, struct ieee80211_hdr *hdr, 254*4882a593Smuzhiyun struct hostap_80211_rx_status *rx_stats); 255*4882a593Smuzhiyun void hostap_update_rates(local_info_t *local); 256*4882a593Smuzhiyun void hostap_add_wds_links(local_info_t *local); 257*4882a593Smuzhiyun void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type); 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT 260*4882a593Smuzhiyun void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap, 261*4882a593Smuzhiyun int resend); 262*4882a593Smuzhiyun #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */ 263*4882a593Smuzhiyun 264*4882a593Smuzhiyun #endif /* HOSTAP_AP_H */ 265