hostapd_driver_ops reduction
[mech_eap.git] / src / ap / ap_drv_ops.h
1 /*
2  * hostapd - Driver operations
3  * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #ifndef AP_DRV_OPS
16 #define AP_DRV_OPS
17
18 enum wpa_driver_if_type;
19 struct wpa_bss_params;
20 struct wpa_driver_scan_params;
21
22 void hostapd_set_driver_ops(struct hostapd_driver_ops *ops);
23 int hostapd_set_privacy(struct hostapd_data *hapd, int enabled);
24 int hostapd_set_generic_elem(struct hostapd_data *hapd, const u8 *elem,
25                              size_t elem_len);
26 int hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len);
27 int hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len);
28 int hostapd_if_add(struct hostapd_data *hapd, enum wpa_driver_if_type type,
29                    const char *ifname, const u8 *addr, void *bss_ctx,
30                    void **drv_priv, char *force_ifname, u8 *if_addr);
31 int hostapd_if_remove(struct hostapd_data *hapd, enum wpa_driver_if_type type,
32                       const char *ifname);
33 int hostapd_set_ieee8021x(struct hostapd_data *hapd,
34                           struct wpa_bss_params *params);
35 int hostapd_get_seqnum(const char *ifname, struct hostapd_data *hapd,
36                        const u8 *addr, int idx, u8 *seq);
37 int hostapd_flush(struct hostapd_data *hapd);
38 int hostapd_set_freq(struct hostapd_data *hapd, int mode, int freq,
39                      int channel, int ht_enabled, int sec_channel_offset);
40 int hostapd_set_rts(struct hostapd_data *hapd, int rts);
41 int hostapd_set_frag(struct hostapd_data *hapd, int frag);
42 int hostapd_sta_set_flags(struct hostapd_data *hapd, u8 *addr,
43                           int total_flags, int flags_or, int flags_and);
44 int hostapd_set_rate_sets(struct hostapd_data *hapd, int *supp_rates,
45                           int *basic_rates, int mode);
46 int hostapd_set_country(struct hostapd_data *hapd, const char *country);
47 int hostapd_set_cts_protect(struct hostapd_data *hapd, int value);
48 int hostapd_set_preamble(struct hostapd_data *hapd, int value);
49 int hostapd_set_short_slot_time(struct hostapd_data *hapd, int value);
50 int hostapd_set_tx_queue_params(struct hostapd_data *hapd, int queue, int aifs,
51                                 int cw_min, int cw_max, int burst_time);
52 int hostapd_valid_bss_mask(struct hostapd_data *hapd, const u8 *addr,
53                            const u8 *mask);
54 struct hostapd_hw_modes *
55 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
56                             u16 *flags);
57 int hostapd_driver_commit(struct hostapd_data *hapd);
58 int hostapd_set_ht_params(struct hostapd_data *hapd,
59                           const u8 *ht_capab, size_t ht_capab_len,
60                           const u8 *ht_oper, size_t ht_oper_len);
61 int hostapd_drv_none(struct hostapd_data *hapd);
62 int hostapd_driver_scan(struct hostapd_data *hapd,
63                         struct wpa_driver_scan_params *params);
64 struct wpa_scan_results * hostapd_driver_get_scan_results(
65         struct hostapd_data *hapd);
66 int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start,
67                            int duration);
68
69
70 #include "drivers/driver.h"
71
72 static inline int hostapd_drv_send_mlme(struct hostapd_data *hapd,
73                                         const void *msg, size_t len)
74 {
75         if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
76                 return 0;
77         return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
78 }
79
80 static inline int hostapd_drv_set_countermeasures(struct hostapd_data *hapd,
81                                                   int enabled)
82 {
83         if (hapd->driver == NULL ||
84             hapd->driver->hapd_set_countermeasures == NULL)
85                 return 0;
86         return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
87 }
88
89 static inline int hostapd_drv_set_sta_vlan(const char *ifname,
90                                            struct hostapd_data *hapd,
91                                            const u8 *addr, int vlan_id)
92 {
93         if (hapd->driver == NULL || hapd->driver->set_sta_vlan == NULL)
94                 return 0;
95         return hapd->driver->set_sta_vlan(hapd->drv_priv, addr, ifname,
96                                           vlan_id);
97 }
98
99 static inline int hostapd_drv_get_inact_sec(struct hostapd_data *hapd,
100                                             const u8 *addr)
101 {
102         if (hapd->driver == NULL || hapd->driver->get_inact_sec == NULL)
103                 return 0;
104         return hapd->driver->get_inact_sec(hapd->drv_priv, addr);
105 }
106
107 static inline int hostapd_drv_sta_deauth(struct hostapd_data *hapd,
108                                          const u8 *addr, int reason)
109 {
110         if (hapd->driver == NULL || hapd->driver->sta_deauth == NULL)
111                 return 0;
112         return hapd->driver->sta_deauth(hapd->drv_priv, hapd->own_addr, addr,
113                                         reason);
114 }
115
116 static inline int hostapd_drv_sta_disassoc(struct hostapd_data *hapd,
117                                            const u8 *addr, int reason)
118 {
119         if (hapd->driver == NULL || hapd->driver->sta_disassoc == NULL)
120                 return 0;
121         return hapd->driver->sta_disassoc(hapd->drv_priv, hapd->own_addr, addr,
122                                           reason);
123 }
124
125 static inline int hostapd_drv_sta_remove(struct hostapd_data *hapd,
126                                          const u8 *addr)
127 {
128         if (hapd->driver == NULL || hapd->driver->sta_remove == NULL)
129                 return 0;
130         return hapd->driver->sta_remove(hapd->drv_priv, addr);
131 }
132
133 static inline int hostapd_drv_hapd_send_eapol(struct hostapd_data *hapd,
134                                               const u8 *addr, const u8 *data,
135                                               size_t data_len, int encrypt)
136 {
137         if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
138                 return 0;
139         return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
140                                              data_len, encrypt,
141                                              hapd->own_addr);
142 }
143
144 static inline int hostapd_drv_set_key(const char *ifname,
145                                       struct hostapd_data *hapd,
146                                       enum wpa_alg alg, const u8 *addr,
147                                       int key_idx, int set_tx,
148                                       const u8 *seq, size_t seq_len,
149                                       const u8 *key, size_t key_len)
150 {
151         if (hapd->driver == NULL || hapd->driver->set_key == NULL)
152                 return 0;
153         return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
154                                      key_idx, set_tx, seq, seq_len, key,
155                                      key_len);
156 }
157
158 static inline int hostapd_drv_read_sta_data(
159         struct hostapd_data *hapd, struct hostap_sta_driver_data *data,
160         const u8 *addr)
161 {
162         if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
163                 return -1;
164         return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
165 }
166
167 static inline int hostapd_drv_sta_clear_stats(struct hostapd_data *hapd,
168                                               const u8 *addr)
169 {
170         if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
171                 return 0;
172         return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
173 }
174
175 static inline int hostapd_drv_set_beacon(struct hostapd_data *hapd,
176                                          const u8 *head, size_t head_len,
177                                          const u8 *tail, size_t tail_len,
178                                          int dtim_period, int beacon_int)
179 {
180         if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
181                 return 0;
182         return hapd->driver->set_beacon(hapd->drv_priv,
183                                         head, head_len, tail, tail_len,
184                                         dtim_period, beacon_int);
185 }
186
187 static inline int hostapd_drv_set_radius_acl_auth(struct hostapd_data *hapd,
188                                                   const u8 *mac, int accepted,
189                                                   u32 session_timeout)
190 {
191         if (hapd->driver == NULL || hapd->driver->set_radius_acl_auth == NULL)
192                 return 0;
193         return hapd->driver->set_radius_acl_auth(hapd->drv_priv, mac, accepted,
194                                                  session_timeout);
195 }
196
197 static inline int hostapd_drv_set_radius_acl_expire(struct hostapd_data *hapd,
198                                                     const u8 *mac)
199 {
200         if (hapd->driver == NULL ||
201             hapd->driver->set_radius_acl_expire == NULL)
202                 return 0;
203         return hapd->driver->set_radius_acl_expire(hapd->drv_priv, mac);
204 }
205
206 #endif /* AP_DRV_OPS */