Remove direct driver calls from accounting.c
[libeap.git] / hostapd / ap_drv_ops.c
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 #include "includes.h"
16
17 #include "common.h"
18 #include "hostapd.h"
19 #include "sta_info.h"
20 #include "driver_i.h"
21
22
23 static int hostapd_set_ap_wps_ie(struct hostapd_data *hapd,
24                                  const struct wpabuf *beacon,
25                                  const struct wpabuf *proberesp)
26 {
27         if (hapd->driver == NULL || hapd->driver->set_ap_wps_ie == NULL)
28                 return 0;
29         return hapd->driver->set_ap_wps_ie(hapd->conf->iface, hapd->drv_priv,
30                                            beacon, proberesp);
31 }
32
33
34 static int hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg,
35                            size_t len)
36 {
37         if (hapd->driver == NULL || hapd->driver->send_mlme == NULL)
38                 return 0;
39         return hapd->driver->send_mlme(hapd->drv_priv, msg, len);
40 }
41
42
43 static int hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr,
44                               const u8 *data, size_t data_len, int encrypt)
45 {
46         if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
47                 return 0;
48         return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
49                                              data_len, encrypt,
50                                              hapd->own_addr);
51 }
52
53
54 static int hostapd_set_authorized(struct hostapd_data *hapd,
55                                   struct sta_info *sta, int authorized)
56 {
57         if (authorized) {
58                 return hostapd_sta_set_flags(hapd, sta->addr,
59                                              hostapd_sta_flags_to_drv(
60                                                      sta->flags),
61                                              WPA_STA_AUTHORIZED, ~0);
62         }
63
64         return hostapd_sta_set_flags(hapd, sta->addr,
65                                      hostapd_sta_flags_to_drv(sta->flags),
66                                      0, ~WPA_STA_AUTHORIZED);
67 }
68
69
70 static int hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
71                            wpa_alg alg, const u8 *addr, int key_idx,
72                            int set_tx, const u8 *seq, size_t seq_len,
73                            const u8 *key, size_t key_len)
74 {
75         if (hapd->driver == NULL || hapd->driver->set_key == NULL)
76                 return 0;
77         return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
78                                      key_idx, set_tx, seq, seq_len, key,
79                                      key_len);
80 }
81
82
83 static int hostapd_read_sta_data(struct hostapd_data *hapd,
84                                  struct hostap_sta_driver_data *data,
85                                  const u8 *addr)
86 {
87         if (hapd->driver == NULL || hapd->driver->read_sta_data == NULL)
88                 return -1;
89         return hapd->driver->read_sta_data(hapd->drv_priv, data, addr);
90 }
91
92
93 static int hostapd_sta_clear_stats(struct hostapd_data *hapd, const u8 *addr)
94 {
95         if (hapd->driver == NULL || hapd->driver->sta_clear_stats == NULL)
96                 return 0;
97         return hapd->driver->sta_clear_stats(hapd->drv_priv, addr);
98 }
99
100
101 void hostapd_set_driver_ops(struct hostapd_driver_ops *ops)
102 {
103         ops->set_ap_wps_ie = hostapd_set_ap_wps_ie;
104         ops->send_mgmt_frame = hostapd_send_mgmt_frame;
105         ops->send_eapol = hostapd_send_eapol;
106         ops->set_authorized = hostapd_set_authorized;
107         ops->set_key = hostapd_set_key;
108         ops->read_sta_data = hostapd_read_sta_data;
109         ops->sta_clear_stats = hostapd_sta_clear_stats;
110 }