hostap_ap.h 8.1 KB

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