Import hostapd 0.5.8
[dragonfly/port-amd64.git] / contrib / hostapd-0.4.9 / driver.h
blobed9ecbfdbc8c3856ccbb969f145e3e85eec9cd44
1 #ifndef DRIVER_H
2 #define DRIVER_H
4 struct driver_ops {
5 const char *name; /* as appears in the config file */
7 int (*init)(struct hostapd_data *hapd);
8 void (*deinit)(void *priv);
10 int (*wireless_event_init)(void *priv);
11 void (*wireless_event_deinit)(void *priv);
13 /**
14 * set_8021x - enable/disable IEEE 802.1X support
15 * @priv: driver private data
16 * @enabled: 1 = enable, 0 = disable
18 * Returns: 0 on success, -1 on failure
20 * Configure the kernel driver to enable/disable 802.1X support.
21 * This may be an empty function if 802.1X support is always enabled.
23 int (*set_ieee8021x)(void *priv, int enabled);
25 /**
26 * set_privacy - enable/disable privacy
27 * @priv: driver private data
28 * @enabled: 1 = privacy enabled, 0 = disabled
30 * Return: 0 on success, -1 on failure
32 * Configure privacy.
34 int (*set_privacy)(void *priv, int enabled);
36 int (*set_encryption)(void *priv, const char *alg, u8 *addr,
37 int idx, u8 *key, size_t key_len);
38 int (*get_seqnum)(void *priv, u8 *addr, int idx, u8 *seq);
39 int (*flush)(void *priv);
40 int (*set_generic_elem)(void *priv, const u8 *elem, size_t elem_len);
42 int (*read_sta_data)(void *priv, struct hostap_sta_driver_data *data,
43 u8 *addr);
44 int (*send_eapol)(void *priv, u8 *addr, u8 *data, size_t data_len,
45 int encrypt);
46 int (*set_sta_authorized)(void *driver, u8 *addr, int authorized);
47 int (*sta_deauth)(void *priv, u8 *addr, int reason);
48 int (*sta_disassoc)(void *priv, u8 *addr, int reason);
49 int (*sta_remove)(void *priv, u8 *addr);
50 int (*get_ssid)(void *priv, u8 *buf, int len);
51 int (*set_ssid)(void *priv, u8 *buf, int len);
52 int (*set_countermeasures)(void *priv, int enabled);
53 int (*send_mgmt_frame)(void *priv, const void *msg, size_t len,
54 int flags);
55 int (*set_assoc_ap)(void *priv, u8 *addr);
56 int (*sta_add)(void *priv, u8 *addr, u16 aid, u16 capability,
57 u8 tx_supp_rates);
58 int (*get_inact_sec)(void *priv, u8 *addr);
59 int (*sta_clear_stats)(void *priv, u8 *addr);
62 static inline int
63 hostapd_driver_init(struct hostapd_data *hapd)
65 if (hapd->driver == NULL || hapd->driver->init == NULL)
66 return -1;
67 return hapd->driver->init(hapd);
70 static inline void
71 hostapd_driver_deinit(struct hostapd_data *hapd)
73 if (hapd->driver == NULL || hapd->driver->deinit == NULL)
74 return;
75 hapd->driver->deinit(hapd->driver);
78 static inline int
79 hostapd_wireless_event_init(struct hostapd_data *hapd)
81 if (hapd->driver == NULL ||
82 hapd->driver->wireless_event_init == NULL)
83 return 0;
84 return hapd->driver->wireless_event_init(hapd->driver);
87 static inline void
88 hostapd_wireless_event_deinit(struct hostapd_data *hapd)
90 if (hapd->driver == NULL ||
91 hapd->driver->wireless_event_deinit == NULL)
92 return;
93 hapd->driver->wireless_event_deinit(hapd->driver);
96 static inline int
97 hostapd_set_ieee8021x(struct hostapd_data *hapd, int enabled)
99 if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
100 return 0;
101 return hapd->driver->set_ieee8021x(hapd->driver, enabled);
104 static inline int
105 hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
107 if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
108 return 0;
109 return hapd->driver->set_privacy(hapd->driver, enabled);
112 static inline int
113 hostapd_set_encryption(struct hostapd_data *hapd, const char *alg, u8 *addr,
114 int idx, u8 *key, size_t key_len)
116 if (hapd->driver == NULL || hapd->driver->set_encryption == NULL)
117 return 0;
118 return hapd->driver->set_encryption(hapd->driver, alg, addr, idx, key,
119 key_len);
122 static inline int
123 hostapd_get_seqnum(struct hostapd_data *hapd, u8 *addr, int idx, u8 *seq)
125 if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
126 return 0;
127 return hapd->driver->get_seqnum(hapd->driver, addr, idx, seq);
130 static inline int
131 hostapd_flush(struct hostapd_data *hapd)
133 if (hapd->driver == NULL || hapd->driver->flush == NULL)
134 return 0;
135 return hapd->driver->flush(hapd->driver);
138 static inline int
139 hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
140 size_t elem_len)
142 if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
143 return 0;
144 return hapd->driver->set_generic_elem(hapd->driver, elem, elem_len);
147 static inline int
148 hostapd_read_sta_data(struct hostapd_data *hapd,
149 struct hostap_sta_driver_data *data, u8 *addr)
151 if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
152 return -1;
153 return hapd->driver->read_sta_data(hapd->driver, data, addr);
156 static inline int
157 hostapd_send_eapol(struct hostapd_data *hapd, u8 *addr, u8 *data,
158 size_t data_len, int encrypt)
160 if (hapd->driver == NULL || hapd->driver->send_eapol == NULL)
161 return 0;
162 return hapd->driver->send_eapol(hapd->driver, addr, data, data_len,
163 encrypt);
166 static inline int
167 hostapd_set_sta_authorized(struct hostapd_data *hapd, u8 *addr, int authorized)
169 if (hapd->driver == NULL || hapd->driver->set_sta_authorized == NULL)
170 return 0;
171 return hapd->driver->set_sta_authorized(hapd->driver, addr,
172 authorized);
175 static inline int
176 hostapd_sta_deauth(struct hostapd_data *hapd, u8 *addr, int reason)
178 if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
179 return 0;
180 return hapd->driver->sta_deauth(hapd->driver, addr, reason);
183 static inline int
184 hostapd_sta_disassoc(struct hostapd_data *hapd, u8 *addr, int reason)
186 if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
187 return 0;
188 return hapd->driver->sta_disassoc(hapd->driver, addr, reason);
191 static inline int
192 hostapd_sta_remove(struct hostapd_data *hapd, u8 *addr)
194 if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
195 return 0;
196 return hapd->driver->sta_remove(hapd->driver, addr);
199 static inline int
200 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
202 if (hapd->driver == NULL || hapd->driver->get_ssid == NULL)
203 return 0;
204 return hapd->driver->get_ssid(hapd->driver, buf, len);
207 static inline int
208 hostapd_set_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
210 if (hapd->driver == NULL || hapd->driver->set_ssid == NULL)
211 return 0;
212 return hapd->driver->set_ssid(hapd->driver, buf, len);
215 static inline int
216 hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len,
217 int flags)
219 if (hapd->driver == NULL || hapd->driver->send_mgmt_frame == NULL)
220 return 0;
221 return hapd->driver->send_mgmt_frame(hapd->driver, msg, len, flags);
224 static inline int
225 hostapd_set_assoc_ap(struct hostapd_data *hapd, u8 *addr)
227 if (hapd->driver == NULL || hapd->driver->set_assoc_ap == NULL)
228 return 0;
229 return hapd->driver->set_assoc_ap(hapd->driver, addr);
232 static inline int
233 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
235 if (hapd->driver == NULL || hapd->driver->set_countermeasures == NULL)
236 return 0;
237 return hapd->driver->set_countermeasures(hapd->driver, enabled);
240 static inline int
241 hostapd_sta_add(struct hostapd_data *hapd, u8 *addr, u16 aid, u16 capability,
242 u8 tx_supp_rates)
244 if (hapd->driver == NULL || hapd->driver->sta_add == NULL)
245 return 0;
246 return hapd->driver->sta_add(hapd->driver, addr, aid, capability,
247 tx_supp_rates);
250 static inline int
251 hostapd_get_inact_sec(struct hostapd_data *hapd, u8 *addr)
253 if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
254 return 0;
255 return hapd->driver->get_inact_sec(hapd->driver, addr);
259 void driver_register(const char *name, const struct driver_ops *ops);
260 void driver_unregister(const char *name);
261 const struct driver_ops *driver_lookup(const char *name);
263 static inline int
264 hostapd_sta_clear_stats(struct hostapd_data *hapd, u8 *addr)
266 if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
267 return 0;
268 return hapd->driver->sta_clear_stats(hapd->driver, addr);
271 #endif /* DRIVER_H */