From cee7d66b1d2f353ebb42ae6eabbcd1d34626c630 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Wed, 24 Nov 2010 15:19:50 +0200 Subject: [PATCH] hostapd: Start removing struct hostapd_driver_ops abstraction Commit bf65bc638fe438b96f2986580ad167d5e276ef4c started the path to add this new abstraction for driver operations in AP mode to allow wpa_supplicant to control AP mode operations. At that point, the extra abstraction was needed, but it is not needed anymore since hostapd and wpa_supplicant share the same struct wpa_driver_ops. Start removing the unneeded abstraction by converting send_mgmt_frame() to an inline function, hostapd_drv_send_mlme(). This is similar to the design that is used in wpa_supplicant and that was used in hostapd in the past (hostapd_send_mgmt_frame() inline function). --- src/ap/ap_drv_ops.c | 10 ---------- src/ap/ap_drv_ops.h | 11 +++++++++++ src/ap/beacon.c | 3 ++- src/ap/hostapd.h | 2 -- src/ap/ieee802_11.c | 13 +++++++------ src/ap/sta_info.c | 3 ++- src/ap/wmm.c | 3 ++- src/ap/wpa_auth_glue.c | 2 +- 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c index 0ac5289d4..c65af9215 100644 --- a/src/ap/ap_drv_ops.c +++ b/src/ap/ap_drv_ops.c @@ -157,15 +157,6 @@ static int hostapd_set_ap_wps_ie(struct hostapd_data *hapd) } -static int hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, - size_t len) -{ - if (hapd->driver == NULL || hapd->driver->send_mlme == NULL) - return 0; - return hapd->driver->send_mlme(hapd->drv_priv, msg, len); -} - - static int hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data, size_t data_len, int encrypt) { @@ -476,7 +467,6 @@ static int hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled) void hostapd_set_driver_ops(struct hostapd_driver_ops *ops) { ops->set_ap_wps_ie = hostapd_set_ap_wps_ie; - ops->send_mgmt_frame = hostapd_send_mgmt_frame; ops->send_eapol = hostapd_send_eapol; ops->set_authorized = hostapd_set_authorized; ops->set_key = hostapd_set_key; diff --git a/src/ap/ap_drv_ops.h b/src/ap/ap_drv_ops.h index d8f9ddcb8..68869a0d9 100644 --- a/src/ap/ap_drv_ops.h +++ b/src/ap/ap_drv_ops.h @@ -66,4 +66,15 @@ struct wpa_scan_results * hostapd_driver_get_scan_results( int hostapd_driver_set_noa(struct hostapd_data *hapd, u8 count, int start, int duration); + +#include "drivers/driver.h" + +static inline int hostapd_drv_send_mlme(struct hostapd_data *hapd, + const void *msg, size_t len) +{ + if (hapd->driver == NULL || hapd->driver->send_mlme == NULL) + return 0; + return hapd->driver->send_mlme(hapd->drv_priv, msg, len); +} + #endif /* AP_DRV_OPS */ diff --git a/src/ap/beacon.c b/src/ap/beacon.c index 17cb541e1..0bc9079a9 100644 --- a/src/ap/beacon.c +++ b/src/ap/beacon.c @@ -31,6 +31,7 @@ #include "ap_config.h" #include "sta_info.h" #include "p2p_hostapd.h" +#include "ap_drv_ops.h" #include "beacon.h" @@ -375,7 +376,7 @@ void handle_probe_req(struct hostapd_data *hapd, pos = hostapd_eid_p2p_manage(hapd, pos); #endif /* CONFIG_P2P_MANAGER */ - if (hapd->drv.send_mgmt_frame(hapd, resp, pos - (u8 *) resp) < 0) + if (hostapd_drv_send_mlme(hapd, resp, pos - (u8 *) resp) < 0) perror("handle_probe_req: send"); os_free(resp); diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index a4ae8dc8a..e0450d927 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -51,8 +51,6 @@ struct hostapd_frame_info { struct hostapd_driver_ops { int (*set_ap_wps_ie)(struct hostapd_data *hapd); - int (*send_mgmt_frame)(struct hostapd_data *hapd, const void *msg, - size_t len); int (*send_eapol)(struct hostapd_data *hapd, const u8 *addr, const u8 *data, size_t data_len, int encrypt); int (*set_authorized)(struct hostapd_data *hapd, struct sta_info *sta, diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c index 4a98ddebb..c7604160b 100644 --- a/src/ap/ieee802_11.c +++ b/src/ap/ieee802_11.c @@ -39,6 +39,7 @@ #include "ap_config.h" #include "ap_mlme.h" #include "p2p_hostapd.h" +#include "ap_drv_ops.h" #include "ieee802_11.h" @@ -284,7 +285,7 @@ static void send_auth_reply(struct hostapd_data *hapd, " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)", MAC2STR(dst), auth_alg, auth_transaction, resp, (unsigned long) ies_len); - if (hapd->drv.send_mgmt_frame(hapd, reply, rlen) < 0) + if (hostapd_drv_send_mlme(hapd, reply, rlen) < 0) perror("send_auth_reply: send"); os_free(buf); @@ -809,7 +810,7 @@ static void send_deauth(struct hostapd_data *hapd, const u8 *addr, send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth); reply.u.deauth.reason_code = host_to_le16(reason_code); - if (hapd->drv.send_mgmt_frame(hapd, &reply, send_len) < 0) + if (hostapd_drv_send_mlme(hapd, &reply, send_len) < 0) wpa_printf(MSG_INFO, "Failed to send deauth: %s", strerror(errno)); } @@ -912,7 +913,7 @@ static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta, send_len += p - reply->u.assoc_resp.variable; - if (hapd->drv.send_mgmt_frame(hapd, reply, send_len) < 0) + if (hostapd_drv_send_mlme(hapd, reply, send_len) < 0) wpa_printf(MSG_INFO, "Failed to send assoc resp: %s", strerror(errno)); } @@ -1222,7 +1223,7 @@ void ieee802_11_send_sa_query_req(struct hostapd_data *hapd, os_memcpy(mgmt.u.action.u.sa_query_req.trans_id, trans_id, WLAN_SA_QUERY_TR_ID_LEN); end = mgmt.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN; - if (hapd->drv.send_mgmt_frame(hapd, &mgmt, end - (u8 *) &mgmt) < 0) + if (hostapd_drv_send_mlme(hapd, &mgmt, end - (u8 *) &mgmt) < 0) perror("ieee802_11_send_sa_query_req: send"); } @@ -1262,7 +1263,7 @@ static void hostapd_sa_query_request(struct hostapd_data *hapd, mgmt->u.action.u.sa_query_req.trans_id, WLAN_SA_QUERY_TR_ID_LEN); end = resp.u.action.u.sa_query_req.trans_id + WLAN_SA_QUERY_TR_ID_LEN; - if (hapd->drv.send_mgmt_frame(hapd, &resp, end - (u8 *) &resp) < 0) + if (hostapd_drv_send_mlme(hapd, &resp, end - (u8 *) &resp) < 0) perror("hostapd_sa_query_request: send"); } @@ -1433,7 +1434,7 @@ static void handle_action(struct hostapd_data *hapd, os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); resp->u.action.category |= 0x80; - hapd->drv.send_mgmt_frame(hapd, resp, len); + hostapd_drv_send_mlme(hapd, resp, len); os_free(resp); } } diff --git a/src/ap/sta_info.c b/src/ap/sta_info.c index 80cdb625a..928b5489d 100644 --- a/src/ap/sta_info.c +++ b/src/ap/sta_info.c @@ -32,6 +32,7 @@ #include "ap_mlme.h" #include "vlan_init.h" #include "p2p_hostapd.h" +#include "ap_drv_ops.h" #include "sta_info.h" static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, @@ -335,7 +336,7 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx) ETH_ALEN); os_memcpy(hdr.IEEE80211_SA_FROMDS, hapd->own_addr, ETH_ALEN); - if (hapd->drv.send_mgmt_frame(hapd, &hdr, sizeof(hdr)) < 0) + if (hostapd_drv_send_mlme(hapd, &hdr, sizeof(hdr)) < 0) perror("ap_handle_timer: send"); #endif /* CONFIG_NATIVE_WINDOWS */ } else if (sta->timeout_next != STA_REMOVE) { diff --git a/src/ap/wmm.c b/src/ap/wmm.c index 36681309c..7e9e5ba3b 100644 --- a/src/ap/wmm.c +++ b/src/ap/wmm.c @@ -23,6 +23,7 @@ #include "ieee802_11.h" #include "sta_info.h" #include "ap_config.h" +#include "ap_drv_ops.h" #include "wmm.h" @@ -150,7 +151,7 @@ static void wmm_send_action(struct hostapd_data *hapd, const u8 *addr, os_memcpy(t, tspec, sizeof(struct wmm_tspec_element)); len = ((u8 *) (t + 1)) - buf; - if (hapd->drv.send_mgmt_frame(hapd, m, len) < 0) + if (hostapd_drv_send_mlme(hapd, m, len) < 0) perror("wmm_send_action: send"); } diff --git a/src/ap/wpa_auth_glue.c b/src/ap/wpa_auth_glue.c index afa13a698..ed43d90a3 100644 --- a/src/ap/wpa_auth_glue.c +++ b/src/ap/wpa_auth_glue.c @@ -396,7 +396,7 @@ static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst, os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN); os_memcpy(&m->u, data, data_len); - res = hapd->drv.send_mgmt_frame(hapd, (u8 *) m, mlen); + res = hostapd_drv_send_mlme(hapd, (u8 *) m, mlen); os_free(m); return res; }