mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2025-01-18 02:44:03 -05:00
driver_bsd.c: Reduce code duplication (MLME)
This patch reduces code duplication between hostapd and wpa_supplicant about IEEE80211_IOC_MLME. This is a preparation for AP mode wpa_supplicant.
This commit is contained in:
parent
cbdecd2b0d
commit
fa6b8afe6f
@ -212,6 +212,20 @@ bsd_del_key(int s, const char *ifname, const u8 *addr, int key_idx)
|
|||||||
sizeof(wk));
|
sizeof(wk));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
bsd_send_mlme_param(int s, const char *ifname, const u8 op, const u16 reason,
|
||||||
|
const u8 *addr)
|
||||||
|
{
|
||||||
|
struct ieee80211req_mlme mlme;
|
||||||
|
|
||||||
|
os_memset(&mlme, 0, sizeof(mlme));
|
||||||
|
mlme.im_op = op;
|
||||||
|
mlme.im_reason = reason;
|
||||||
|
os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
|
||||||
|
return bsd_set80211var(s, ifname, IEEE80211_IOC_MLME, &mlme,
|
||||||
|
sizeof(mlme));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef HOSTAPD
|
#ifdef HOSTAPD
|
||||||
|
|
||||||
@ -432,18 +446,10 @@ static int
|
|||||||
bsd_set_sta_authorized(void *priv, const u8 *addr, int authorized)
|
bsd_set_sta_authorized(void *priv, const u8 *addr, int authorized)
|
||||||
{
|
{
|
||||||
struct bsd_driver_data *drv = priv;
|
struct bsd_driver_data *drv = priv;
|
||||||
struct ieee80211req_mlme mlme;
|
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
|
return bsd_send_mlme_param(drv->ioctl_sock, drv->iface, authorized ?
|
||||||
__func__, ether_sprintf(addr), authorized);
|
IEEE80211_MLME_AUTHORIZE :
|
||||||
|
IEEE80211_MLME_UNAUTHORIZE, 0, addr);
|
||||||
if (authorized)
|
|
||||||
mlme.im_op = IEEE80211_MLME_AUTHORIZE;
|
|
||||||
else
|
|
||||||
mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
|
|
||||||
mlme.im_reason = 0;
|
|
||||||
memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
|
|
||||||
return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -592,15 +598,9 @@ static int
|
|||||||
bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, int reason_code)
|
bsd_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, int reason_code)
|
||||||
{
|
{
|
||||||
struct bsd_driver_data *drv = priv;
|
struct bsd_driver_data *drv = priv;
|
||||||
struct ieee80211req_mlme mlme;
|
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
|
return bsd_send_mlme_param(drv->ioctl_sock, drv->iface,
|
||||||
__func__, ether_sprintf(addr), reason_code);
|
IEEE80211_MLME_DEAUTH, reason_code, addr);
|
||||||
|
|
||||||
mlme.im_op = IEEE80211_MLME_DEAUTH;
|
|
||||||
mlme.im_reason = reason_code;
|
|
||||||
memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
|
|
||||||
return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -608,15 +608,9 @@ bsd_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
|
|||||||
int reason_code)
|
int reason_code)
|
||||||
{
|
{
|
||||||
struct bsd_driver_data *drv = priv;
|
struct bsd_driver_data *drv = priv;
|
||||||
struct ieee80211req_mlme mlme;
|
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
|
return bsd_send_mlme_param(drv->ioctl_sock, drv->iface,
|
||||||
__func__, ether_sprintf(addr), reason_code);
|
IEEE80211_MLME_DISASSOC, reason_code, addr);
|
||||||
|
|
||||||
mlme.im_op = IEEE80211_MLME_DISASSOC;
|
|
||||||
mlme.im_reason = reason_code;
|
|
||||||
memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
|
|
||||||
return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1182,28 +1176,18 @@ static int
|
|||||||
wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code)
|
wpa_driver_bsd_deauthenticate(void *priv, const u8 *addr, int reason_code)
|
||||||
{
|
{
|
||||||
struct wpa_driver_bsd_data *drv = priv;
|
struct wpa_driver_bsd_data *drv = priv;
|
||||||
struct ieee80211req_mlme mlme;
|
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "%s", __func__);
|
return bsd_send_mlme_param(drv->sock, drv->ifname,
|
||||||
os_memset(&mlme, 0, sizeof(mlme));
|
IEEE80211_MLME_DEAUTH, reason_code, addr);
|
||||||
mlme.im_op = IEEE80211_MLME_DEAUTH;
|
|
||||||
mlme.im_reason = reason_code;
|
|
||||||
os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
|
|
||||||
return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
wpa_driver_bsd_disassociate(void *priv, const u8 *addr, int reason_code)
|
wpa_driver_bsd_disassociate(void *priv, const u8 *addr, int reason_code)
|
||||||
{
|
{
|
||||||
struct wpa_driver_bsd_data *drv = priv;
|
struct wpa_driver_bsd_data *drv = priv;
|
||||||
struct ieee80211req_mlme mlme;
|
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "%s", __func__);
|
return bsd_send_mlme_param(drv->sock, drv->ifname,
|
||||||
os_memset(&mlme, 0, sizeof(mlme));
|
IEEE80211_MLME_DISASSOC, reason_code, addr);
|
||||||
mlme.im_op = IEEE80211_MLME_DISASSOC;
|
|
||||||
mlme.im_reason = reason_code;
|
|
||||||
os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
|
|
||||||
return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user