aboutsummaryrefslogtreecommitdiff
path: root/contrib/hostapd/driver.h
blob: 365deda48a2a87fd7cac5fca11a486bfa3f81212 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#ifndef DRIVER_H
#define DRIVER_H

struct driver_ops {
	const char *name;		/* as appears in the config file */

	int (*init)(struct hostapd_data *hapd);
	void (*deinit)(void *priv);

	int (*wireless_event_init)(void *priv);
	void (*wireless_event_deinit)(void *priv);

	/**
	 * set_8021x - enable/disable 802.1x support
	 * @priv: driver private data
	 * @enabled: 1 = enable, 0 = disable
	 *
	 * Returns: 0 on success, -1 on failure
	 *
	 * Configure the kernel driver to enable/disable 802.1x support.
	 * This may be an empty function if 802.1x support is always enabled.
	 */
	int (*set_ieee8021x)(void *priv, int enabled);

	/**
	 * set_privacy - enable/disable privacy
	 * @priv: driver private data
	 * @enabled: 1 = privacy enabled, 0 = disabled
	 *
	 * Return: 0 on success, -1 on failure
	 *
	 * Configure privacy.
	 */
	int (*set_privacy)(void *priv, int enabled);

	int (*set_encryption)(void *priv, const char *alg, u8 *addr,
			      int idx, u8 *key, size_t key_len);
	int (*get_seqnum)(void *priv, u8 *addr, int idx, u8 *seq);
	int (*flush)(void *priv);
	int (*set_generic_elem)(void *priv, const u8 *elem, size_t elem_len);

	int (*read_sta_data)(void *priv, struct hostap_sta_driver_data *data,
			     u8 *addr);
	int (*send_eapol)(void *priv, u8 *addr, u8 *data, size_t data_len,
			  int encrypt);
	int (*set_sta_authorized)(void *driver, u8 *addr, int authorized);
	int (*sta_deauth)(void *priv, u8 *addr, int reason);
	int (*sta_disassoc)(void *priv, u8 *addr, int reason);
	int (*sta_remove)(void *priv, u8 *addr);
	int (*get_ssid)(void *priv, u8 *buf, int len);
	int (*set_ssid)(void *priv, u8 *buf, int len);
	int (*send_mgmt_frame)(void *priv, const void *msg, size_t len,
			       int flags);
	int (*set_assoc_ap)(void *priv, u8 *addr);
	int (*sta_add)(void *priv, u8 *addr, u16 aid, u16 capability,
		       u8 tx_supp_rates);
	int (*get_inact_sec)(void *priv, u8 *addr);
	int (*sta_clear_stats)(void *priv, u8 *addr);
};

static inline int
hostapd_driver_init(struct hostapd_data *hapd)
{
	if (hapd->driver == NULL || hapd->driver->init == NULL)
		return -1;
	return hapd->driver->init(hapd);
}

static inline void
hostapd_driver_deinit(struct hostapd_data *hapd)
{
	if (hapd->driver == NULL || hapd->driver->deinit == NULL)
		return;
	hapd->driver->deinit(hapd->driver);
}

static inline int
hostapd_wireless_event_init(struct hostapd_data *hapd)
{
	if (hapd->driver == NULL ||
	    hapd->driver->wireless_event_init == NULL)
		return 0;
	return hapd->driver->wireless_event_init(hapd->driver);
}

static inline void
hostapd_wireless_event_deinit(struct hostapd_data *hapd)
{
	if (hapd->driver == NULL ||
	    hapd->driver->wireless_event_deinit == NULL)
		return;
	hapd->driver->wireless_event_deinit(hapd->driver);
}

static inline int
hostapd_set_ieee8021x(struct hostapd_data *hapd, int enabled)
{
	if (hapd->driver == NULL || hapd->driver->set_ieee8021x == NULL)
		return 0;
	return hapd->driver->set_ieee8021x(hapd->driver, enabled);
}

static inline int
hostapd_set_privacy(struct hostapd_data *hapd, int enabled)
{
	if (hapd->driver == NULL || hapd->driver->set_privacy == NULL)
		return 0;
	return hapd->driver->set_privacy(hapd->driver, enabled);
}

static inline int
hostapd_set_encryption(struct hostapd_data *hapd, const char *alg, u8 *addr,
		       int idx, u8 *key, size_t key_len)
{
	if (hapd->driver == NULL || hapd->driver->set_encryption == NULL)
		return 0;
	return hapd->driver->set_encryption(hapd->driver, alg, addr, idx, key,
					    key_len);
}

static inline int
hostapd_get_seqnum(struct hostapd_data *hapd, u8 *addr, int idx, u8 *seq)
{
	if (hapd->driver == NULL || hapd->driver->get_seqnum == NULL)
		return 0;
	return hapd->driver->get_seqnum(hapd->driver, addr, idx, seq);
}

static inline int
hostapd_flush(struct hostapd_data *hapd)
{
	if (hapd->driver == NULL || hapd->driver->flush == NULL)
		return 0;
	return hapd->driver->flush(hapd->driver);
}

static inline int
hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
			 size_t elem_len)
{
	if (hapd->driver == NULL || hapd->driver->set_generic_elem == NULL)
		return 0;
	return hapd->driver->set_generic_elem(hapd->driver, elem, elem_len);
}

static inline int
hostapd_read_sta_data(struct hostapd_data *hapd,
		      struct hostap_sta_driver_data *data, u8 *addr)
{
	if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
		return -1;
	return hapd->driver->read_sta_data(hapd->driver, data, addr);
}

static inline int
hostapd_send_eapol(struct hostapd_data *hapd, u8 *addr, u8 *data,
		   size_t data_len, int encrypt)
{
	if (hapd->driver == NULL || hapd->driver->send_eapol == NULL)
		return 0;
	return hapd->driver->send_eapol(hapd->driver, addr, data, data_len,
					encrypt);
}

static inline int
hostapd_set_sta_authorized(struct hostapd_data *hapd, u8 *addr, int authorized)
{
	if (hapd->driver == NULL || hapd->driver->set_sta_authorized == NULL)
		return 0;
	return hapd->driver->set_sta_authorized(hapd->driver, addr,
						authorized);
}

static inline int
hostapd_sta_deauth(struct hostapd_data *hapd, u8 *addr, int reason)
{
	if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
		return 0;
	return hapd->driver->sta_deauth(hapd->driver, addr, reason);
}

static inline int
hostapd_sta_disassoc(struct hostapd_data *hapd, u8 *addr, int reason)
{
	if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
		return 0;
	return hapd->driver->sta_disassoc(hapd->driver, addr, reason);
}

static inline int
hostapd_sta_remove(struct hostapd_data *hapd, u8 *addr)
{
	if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
		return 0;
	return hapd->driver->sta_remove(hapd->driver, addr);
}

static inline int
hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
{
	if (hapd->driver == NULL || hapd->driver->get_ssid == NULL)
		return 0;
	return hapd->driver->get_ssid(hapd->driver, buf, len);
}

static inline int
hostapd_set_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
{
	if (hapd->driver == NULL || hapd->driver->set_ssid == NULL)
		return 0;
	return hapd->driver->set_ssid(hapd->driver, buf, len);
}

static inline int
hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len,
			int flags)
{
	if (hapd->driver == NULL || hapd->driver->send_mgmt_frame == NULL)
		return 0;
	return hapd->driver->send_mgmt_frame(hapd->driver, msg, len, flags);
}

static inline int
hostapd_set_assoc_ap(struct hostapd_data *hapd, u8 *addr)
{
	if (hapd->driver == NULL || hapd->driver->set_assoc_ap == NULL)
		return 0;
	return hapd->driver->set_assoc_ap(hapd->driver, addr);
}

static inline int
hostapd_sta_add(struct hostapd_data *hapd, u8 *addr, u16 aid, u16 capability,
		u8 tx_supp_rates)
{
	if (hapd->driver == NULL || hapd->driver->sta_add == NULL)
		return 0;
	return hapd->driver->sta_add(hapd->driver, addr, aid, capability,
				     tx_supp_rates);
}

static inline int
hostapd_get_inact_sec(struct hostapd_data *hapd, u8 *addr)
{
	if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
		return 0;
	return hapd->driver->get_inact_sec(hapd->driver, addr);
}


void driver_register(const char *name, const struct driver_ops *ops);
void driver_unregister(const char *name);
const struct driver_ops *driver_lookup(const char *name);

static inline int
hostapd_sta_clear_stats(struct hostapd_data *hapd, u8 *addr)
{
	if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
		return 0;
	return hapd->driver->sta_clear_stats(hapd->driver, addr);
}

#endif /* DRIVER_H */