hostapd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * hostapd / Initialization and configuration
  3. * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef HOSTAPD_H
  9. #define HOSTAPD_H
  10. #include "common/defs.h"
  11. #include "ap_config.h"
  12. struct wpa_driver_ops;
  13. struct wpa_ctrl_dst;
  14. struct radius_server_data;
  15. struct upnp_wps_device_sm;
  16. struct hostapd_data;
  17. struct sta_info;
  18. struct hostap_sta_driver_data;
  19. struct ieee80211_ht_capabilities;
  20. struct full_dynamic_vlan;
  21. enum wps_event;
  22. union wps_event_data;
  23. struct hostapd_iface;
  24. struct hostapd_dynamic_iface;
  25. struct hapd_interfaces {
  26. int (*reload_config)(struct hostapd_iface *iface);
  27. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  28. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  29. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  30. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  31. int (*cb)(struct hostapd_iface *iface,
  32. void *ctx), void *ctx);
  33. int (*driver_init)(struct hostapd_iface *iface);
  34. size_t count;
  35. size_t count_dynamic;
  36. int global_ctrl_sock;
  37. char *global_iface_path;
  38. char *global_iface_name;
  39. gid_t ctrl_iface_group;
  40. struct hostapd_iface **iface;
  41. struct hostapd_dynamic_iface **dynamic_iface;
  42. };
  43. enum hostapd_chan_status {
  44. HOSTAPD_CHAN_VALID = 0, /* channel is ready */
  45. HOSTAPD_CHAN_INVALID = 1, /* no usable channel found */
  46. HOSTAPD_CHAN_ACS = 2, /* ACS work being performed */
  47. };
  48. struct hostapd_probereq_cb {
  49. int (*cb)(void *ctx, const u8 *sa, const u8 *da, const u8 *bssid,
  50. const u8 *ie, size_t ie_len, int ssi_signal);
  51. void *ctx;
  52. };
  53. #define HOSTAPD_RATE_BASIC 0x00000001
  54. struct hostapd_rate_data {
  55. int rate; /* rate in 100 kbps */
  56. int flags; /* HOSTAPD_RATE_ flags */
  57. };
  58. struct hostapd_frame_info {
  59. u32 channel;
  60. u32 datarate;
  61. int ssi_signal; /* dBm */
  62. };
  63. enum wps_status {
  64. WPS_STATUS_SUCCESS = 1,
  65. WPS_STATUS_FAILURE
  66. };
  67. enum pbc_status {
  68. WPS_PBC_STATUS_DISABLE,
  69. WPS_PBC_STATUS_ACTIVE,
  70. WPS_PBC_STATUS_TIMEOUT,
  71. WPS_PBC_STATUS_OVERLAP
  72. };
  73. struct wps_stat {
  74. enum wps_status status;
  75. enum wps_error_indication failure_reason;
  76. enum pbc_status pbc_status;
  77. u8 peer_addr[ETH_ALEN];
  78. };
  79. /**
  80. * struct hostapd_data - hostapd per-BSS data structure
  81. */
  82. struct hostapd_data {
  83. struct hostapd_iface *iface;
  84. struct hostapd_config *iconf;
  85. struct hostapd_bss_config *conf;
  86. u8 own_addr[ETH_ALEN];
  87. int num_sta; /* number of entries in sta_list */
  88. struct sta_info *sta_list; /* STA info list head */
  89. #define STA_HASH_SIZE 256
  90. #define STA_HASH(sta) (sta[5])
  91. struct sta_info *sta_hash[STA_HASH_SIZE];
  92. /*
  93. * Bitfield for indicating which AIDs are allocated. Only AID values
  94. * 1-2007 are used and as such, the bit at index 0 corresponds to AID
  95. * 1.
  96. */
  97. #define AID_WORDS ((2008 + 31) / 32)
  98. u32 sta_aid[AID_WORDS];
  99. const struct wpa_driver_ops *driver;
  100. void *drv_priv;
  101. void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
  102. struct sta_info *sta, int reassoc);
  103. void *msg_ctx; /* ctx for wpa_msg() calls */
  104. void *msg_ctx_parent; /* parent interface ctx for wpa_msg() calls */
  105. struct radius_client_data *radius;
  106. u32 acct_session_id_hi, acct_session_id_lo;
  107. struct radius_das_data *radius_das;
  108. struct iapp_data *iapp;
  109. struct hostapd_cached_radius_acl *acl_cache;
  110. struct hostapd_acl_query_data *acl_queries;
  111. struct wpa_authenticator *wpa_auth;
  112. struct eapol_authenticator *eapol_auth;
  113. struct rsn_preauth_interface *preauth_iface;
  114. time_t michael_mic_failure;
  115. int michael_mic_failures;
  116. int tkip_countermeasures;
  117. int ctrl_sock;
  118. struct wpa_ctrl_dst *ctrl_dst;
  119. void *ssl_ctx;
  120. void *eap_sim_db_priv;
  121. struct radius_server_data *radius_srv;
  122. int parameter_set_count;
  123. /* Time Advertisement */
  124. u8 time_update_counter;
  125. struct wpabuf *time_adv;
  126. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  127. struct full_dynamic_vlan *full_dynamic_vlan;
  128. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  129. struct l2_packet_data *l2;
  130. struct wps_context *wps;
  131. int beacon_set_done;
  132. struct wpabuf *wps_beacon_ie;
  133. struct wpabuf *wps_probe_resp_ie;
  134. #ifdef CONFIG_WPS
  135. unsigned int ap_pin_failures;
  136. unsigned int ap_pin_failures_consecutive;
  137. struct upnp_wps_device_sm *wps_upnp;
  138. unsigned int ap_pin_lockout_time;
  139. struct wps_stat wps_stats;
  140. #endif /* CONFIG_WPS */
  141. struct hostapd_probereq_cb *probereq_cb;
  142. size_t num_probereq_cb;
  143. void (*public_action_cb)(void *ctx, const u8 *buf, size_t len,
  144. int freq);
  145. void *public_action_cb_ctx;
  146. void (*public_action_cb2)(void *ctx, const u8 *buf, size_t len,
  147. int freq);
  148. void *public_action_cb2_ctx;
  149. int (*vendor_action_cb)(void *ctx, const u8 *buf, size_t len,
  150. int freq);
  151. void *vendor_action_cb_ctx;
  152. void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr,
  153. const u8 *uuid_e);
  154. void *wps_reg_success_cb_ctx;
  155. void (*wps_event_cb)(void *ctx, enum wps_event event,
  156. union wps_event_data *data);
  157. void *wps_event_cb_ctx;
  158. void (*sta_authorized_cb)(void *ctx, const u8 *mac_addr,
  159. int authorized, const u8 *p2p_dev_addr);
  160. void *sta_authorized_cb_ctx;
  161. void (*setup_complete_cb)(void *ctx);
  162. void *setup_complete_cb_ctx;
  163. void (*new_psk_cb)(void *ctx, const u8 *mac_addr,
  164. const u8 *p2p_dev_addr, const u8 *psk,
  165. size_t psk_len);
  166. void *new_psk_cb_ctx;
  167. #ifdef CONFIG_P2P
  168. struct p2p_data *p2p;
  169. struct p2p_group *p2p_group;
  170. struct wpabuf *p2p_beacon_ie;
  171. struct wpabuf *p2p_probe_resp_ie;
  172. /* Number of non-P2P association stations */
  173. int num_sta_no_p2p;
  174. /* Periodic NoA (used only when no non-P2P clients in the group) */
  175. int noa_enabled;
  176. int noa_start;
  177. int noa_duration;
  178. #endif /* CONFIG_P2P */
  179. #ifdef CONFIG_INTERWORKING
  180. size_t gas_frag_limit;
  181. #endif /* CONFIG_INTERWORKING */
  182. #ifdef CONFIG_SQLITE
  183. struct hostapd_eap_user tmp_eap_user;
  184. #endif /* CONFIG_SQLITE */
  185. #ifdef CONFIG_SAE
  186. /** Key used for generating SAE anti-clogging tokens */
  187. u8 sae_token_key[8];
  188. os_time_t last_sae_token_key_update;
  189. #endif /* CONFIG_SAE */
  190. };
  191. /**
  192. * struct hostapd_iface - hostapd per-interface data structure
  193. */
  194. struct hostapd_iface {
  195. struct hapd_interfaces *interfaces;
  196. void *owner;
  197. char *config_fname;
  198. struct hostapd_config *conf;
  199. char phy[16]; /* Name of the PHY (radio) */
  200. enum hostapd_iface_state {
  201. HAPD_IFACE_UNINITIALIZED,
  202. HAPD_IFACE_DISABLED,
  203. HAPD_IFACE_COUNTRY_UPDATE,
  204. HAPD_IFACE_ACS,
  205. HAPD_IFACE_HT_SCAN,
  206. HAPD_IFACE_DFS,
  207. HAPD_IFACE_ENABLED
  208. } state;
  209. size_t num_bss;
  210. struct hostapd_data **bss;
  211. unsigned int wait_channel_update:1;
  212. unsigned int cac_started:1;
  213. int num_ap; /* number of entries in ap_list */
  214. struct ap_info *ap_list; /* AP info list head */
  215. struct ap_info *ap_hash[STA_HASH_SIZE];
  216. unsigned int drv_flags;
  217. /*
  218. * A bitmap of supported protocols for probe response offload. See
  219. * struct wpa_driver_capa in driver.h
  220. */
  221. unsigned int probe_resp_offloads;
  222. /* extended capabilities supported by the driver */
  223. const u8 *extended_capa, *extended_capa_mask;
  224. unsigned int extended_capa_len;
  225. unsigned int drv_max_acl_mac_addrs;
  226. struct hostapd_hw_modes *hw_features;
  227. int num_hw_features;
  228. struct hostapd_hw_modes *current_mode;
  229. /* Rates that are currently used (i.e., filtered copy of
  230. * current_mode->channels */
  231. int num_rates;
  232. struct hostapd_rate_data *current_rates;
  233. int *basic_rates;
  234. int freq;
  235. u16 hw_flags;
  236. /* Number of associated Non-ERP stations (i.e., stations using 802.11b
  237. * in 802.11g BSS) */
  238. int num_sta_non_erp;
  239. /* Number of associated stations that do not support Short Slot Time */
  240. int num_sta_no_short_slot_time;
  241. /* Number of associated stations that do not support Short Preamble */
  242. int num_sta_no_short_preamble;
  243. int olbc; /* Overlapping Legacy BSS Condition */
  244. /* Number of HT associated stations that do not support greenfield */
  245. int num_sta_ht_no_gf;
  246. /* Number of associated non-HT stations */
  247. int num_sta_no_ht;
  248. /* Number of HT associated stations 20 MHz */
  249. int num_sta_ht_20mhz;
  250. /* Overlapping BSS information */
  251. int olbc_ht;
  252. u16 ht_op_mode;
  253. /* surveying helpers */
  254. /* number of channels surveyed */
  255. unsigned int chans_surveyed;
  256. /* lowest observed noise floor in dBm */
  257. s8 lowest_nf;
  258. #ifdef CONFIG_ACS
  259. unsigned int acs_num_completed_scans;
  260. #endif /* CONFIG_ACS */
  261. void (*scan_cb)(struct hostapd_iface *iface);
  262. };
  263. /**
  264. * struct hostapd_dynamic_iface - hostapd per dynamically allocated
  265. * or added interface data structure
  266. */
  267. struct hostapd_dynamic_iface {
  268. char parent[IFNAMSIZ + 1];
  269. char iface[IFNAMSIZ + 1];
  270. unsigned int usage;
  271. };
  272. /* hostapd.c */
  273. int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
  274. int (*cb)(struct hostapd_iface *iface,
  275. void *ctx), void *ctx);
  276. int hostapd_reload_config(struct hostapd_iface *iface);
  277. struct hostapd_data *
  278. hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
  279. struct hostapd_config *conf,
  280. struct hostapd_bss_config *bss);
  281. int hostapd_setup_interface(struct hostapd_iface *iface);
  282. int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
  283. void hostapd_interface_deinit(struct hostapd_iface *iface);
  284. void hostapd_interface_free(struct hostapd_iface *iface);
  285. struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
  286. const char *config_file);
  287. struct hostapd_iface *
  288. hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
  289. const char *config_fname, int debug);
  290. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  291. int reassoc);
  292. void hostapd_interface_deinit_free(struct hostapd_iface *iface);
  293. int hostapd_enable_iface(struct hostapd_iface *hapd_iface);
  294. int hostapd_reload_iface(struct hostapd_iface *hapd_iface);
  295. int hostapd_disable_iface(struct hostapd_iface *hapd_iface);
  296. int hostapd_add_iface(struct hapd_interfaces *ifaces, char *buf);
  297. int hostapd_remove_iface(struct hapd_interfaces *ifaces, char *buf);
  298. void hostapd_channel_list_updated(struct hostapd_iface *iface);
  299. void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s);
  300. const char * hostapd_state_text(enum hostapd_iface_state s);
  301. /* utils.c */
  302. int hostapd_register_probereq_cb(struct hostapd_data *hapd,
  303. int (*cb)(void *ctx, const u8 *sa,
  304. const u8 *da, const u8 *bssid,
  305. const u8 *ie, size_t ie_len,
  306. int ssi_signal),
  307. void *ctx);
  308. void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
  309. /* drv_callbacks.c (TODO: move to somewhere else?) */
  310. int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
  311. const u8 *ie, size_t ielen, int reassoc);
  312. void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
  313. void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr);
  314. void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
  315. const u8 *addr, int reason_code);
  316. int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
  317. const u8 *bssid, const u8 *ie, size_t ie_len,
  318. int ssi_signal);
  319. void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
  320. int offset);
  321. const struct hostapd_eap_user *
  322. hostapd_get_eap_user(struct hostapd_data *hapd, const u8 *identity,
  323. size_t identity_len, int phase2);
  324. #endif /* HOSTAPD_H */