#ifndef HOSTAPD_H
#define HOSTAPD_H

#include "common.h"
#include "ap.h"
#include "../driver/modules/hostap_wlan.h"


struct ieee80211_hdr {
	u16 frame_control;
	u16 duration_id;
	u8 addr1[6];
	u8 addr2[6];
	u8 addr3[6];
	u16 seq_ctrl;
	/* followed by 'u8 addr4[6];' if ToDS and FromDS is set in data frame
	 */
} __attribute__ ((packed));

#define IEEE80211_DA_FROMDS addr1
#define IEEE80211_BSSID_FROMDS addr2
#define IEEE80211_SA_FROMDS addr3

#define IEEE80211_HDRLEN (sizeof(struct ieee80211_hdr))

#define IEEE80211_FC(type, stype) host_to_le16((type << 2) | (stype << 4))

/* MTU to be set for the wlan#ap device; this is mainly needed for IEEE 802.1X
 * frames that might be longer than normal default MTU and they are not
 * fragmented */
#define HOSTAPD_MTU 2290

extern unsigned char rfc1042_header[6];

typedef struct hostapd_data {
	int sock; /* raw packet socket for driver access */
	int ioctl_sock; /* socket for ioctl() use */
	u8 own_addr[6];
	char iface[IFNAMSIZ + 1];

	int num_sta; /* number of entries in sta_list */
	struct sta_info *sta_list; /* STA info list head */
	struct sta_info *sta_hash[STA_HASH_SIZE];

	/* pointers to STA info; based on allocated AID or NULL if AID free
	 * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
	 * and so on
	 */
	struct sta_info *sta_aid[MAX_AID_TABLE_SIZE];

	enum { HOSTAPD_DEBUG_NO = 0, HOSTAPD_DEBUG_MINIMAL = 1,
	       HOSTAPD_DEBUG_MSGDUMPS = 2 };

	int debug; /* debug verbosity level */
	char *dump_log_name; /* file name for state dump (SIGUSR1) */

	int ieee802_1x; /* use IEEE 802.1X */
	int minimal_eap; /* test version of EAP authentication that only
			  * requires EAP Response-Identity and authorizes any
			  * station */
	struct in_addr own_ip_addr;
	struct in_addr auth_server_addr; /* address of the RADIUS server used
					  * as the Authentication Server */
	int auth_server_port;
	u8 *auth_server_shared_secret;
	size_t auth_server_shared_secret_len;
	char ssid[33];
	int ssid_len;
	char *eap_req_id_text; /* optional displayable message sent with
				* EAP Request-Identity */

	u8 *default_wep_key;
	size_t default_wep_key_len;
	u8 default_wep_key_idx;
	int individual_wep_key_len;

	int auth_serv_sock; /* socket for RADIUS messages */

	u8 next_radius_identifier;
} hostapd;


struct sta_info* ap_get_sta(hostapd *hapd, u8 *sta);
struct sta_info* ap_get_sta_radius_identifier(hostapd *hapd,
					      u8 radius_identifier);
int hostapd_ioctl(hostapd *hapd, struct prism2_hostapd_param *param);
int hostapd_set_encryption(hostapd *hapd, const char *alg, u8 *addr,
			   int idx, u8 *key, size_t key_len);

#endif /* HOSTAPD_H */
