[PATCH] driver_bsd.c: Reduce code duplication (DELKEY)
Masashi Honma
honma
Wed Jan 27 21:52:07 PST 2010
Hello.
This patch reduces code duplication between hostapd and wpa_supplicant
about IEEE80211_IOC_DELKEY. This is a preparation for AP mode
wpa_supplicant. This is a patch to
http://lists.shmoo.com/pipermail/hostap/2010-January/021030.html.
--- driver_bsd.c.bak 2010-01-28 14:47:09.000000000 +0900
+++ driver_bsd.c 2010-01-28 14:47:11.000000000 +0900
@@ -192,6 +192,26 @@
return 0;
}
+static int
+bsd_del_key(int s, const char *ifname, const u8 *addr, int key_idx)
+{
+ struct ieee80211req_del_key wk;
+
+ os_memset(&wk, 0, sizeof(wk));
+ if (addr == NULL) {
+ wpa_printf(MSG_DEBUG, "%s: key_idx=%d", __func__, key_idx);
+ wk.idk_keyix = key_idx;
+ } else {
+ wpa_printf(MSG_DEBUG, "%s: addr=" MACSTR, __func__,
+ MAC2STR(addr));
+ os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
+ wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */
+ }
+
+ return bsd_set80211var(s, ifname, IEEE80211_IOC_DELKEY, &wk,
+ sizeof(wk));
+}
+
#ifdef HOSTAPD
@@ -439,26 +459,6 @@
}
static int
-bsd_del_key(void *priv, const u8 *addr, int key_idx)
-{
- struct bsd_driver_data *drv = priv;
- struct ieee80211req_del_key wk;
-
- wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
- __func__, ether_sprintf(addr), key_idx);
-
- memset(&wk, 0, sizeof(wk));
- if (addr != NULL) {
- memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
- wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE; /* XXX */
- } else {
- wk.idk_keyix = key_idx;
- }
-
- return set80211var(drv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
-}
-
-static int
bsd_set_key(const char *ifname, void *priv, enum wpa_alg alg,
const u8 *addr, int key_idx, int set_tx, const u8 *seq,
size_t seq_len, const u8 *key, size_t key_len)
@@ -468,7 +468,7 @@
u_int8_t cipher;
if (alg == WPA_ALG_NONE)
- return bsd_del_key(drv, addr, key_idx);
+ return bsd_del_key(drv->ioctl_sock, drv->iface, addr, key_idx);
wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
__func__, alg, ether_sprintf(addr), key_idx);
@@ -1054,29 +1054,6 @@
}
static int
-wpa_driver_bsd_del_key(struct wpa_driver_bsd_data *drv, int key_idx,
- const unsigned char *addr)
-{
- struct ieee80211req_del_key wk;
-
- os_memset(&wk, 0, sizeof(wk));
- if (addr != NULL &&
- bcmp(addr, "\xff\xff\xff\xff\xff\xff", IEEE80211_ADDR_LEN) != 0) {
- struct ether_addr ea;
-
- os_memcpy(&ea, addr, IEEE80211_ADDR_LEN);
- wpa_printf(MSG_DEBUG, "%s: addr=%s keyidx=%d",
- __func__, ether_ntoa(&ea), key_idx);
- os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
- wk.idk_keyix = (uint8_t) IEEE80211_KEYIX_NONE;
- } else {
- wpa_printf(MSG_DEBUG, "%s: keyidx=%d", __func__, key_idx);
- wk.idk_keyix = key_idx;
- }
- return set80211var(drv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
-}
-
-static int
wpa_driver_bsd_set_key(const char *ifname, void *priv, enum wpa_alg alg,
const unsigned char *addr, int key_idx, int set_tx,
const u8 *seq, size_t seq_len,
@@ -1089,7 +1066,10 @@
u_int8_t cipher;
if (alg == WPA_ALG_NONE)
- return wpa_driver_bsd_del_key(drv, key_idx, addr);
+ return bsd_del_key(drv->sock, drv->ifname,
+ os_memcmp(addr, "\xff\xff\xff\xff\xff\xff",
+ IEEE80211_ADDR_LEN) == 0 ? NULL : addr,
+ key_idx);
switch (alg) {
case WPA_ALG_WEP:
Regards,
Masashi Honma.
More information about the Hostap
mailing list