aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2010-01-03 20:17:08 (GMT)
committerJouni Malinen <j@w1.fi>2010-01-03 20:17:08 (GMT)
commit2ac9688eb884c27cb0e66470e3fd26b9d94c2999 (patch)
tree4f17d6c9739d6359836ddedc3b044b7350f549ce
parent34f2f814e08a08806e81047198bca08537bfa5bc (diff)
downloadhostap-2ac9688eb884c27cb0e66470e3fd26b9d94c2999.zip
hostap-2ac9688eb884c27cb0e66470e3fd26b9d94c2999.tar.gz
hostap-2ac9688eb884c27cb0e66470e3fd26b9d94c2999.tar.bz2
Use common driver code for Linux hwaddr get/set
-rw-r--r--src/drivers/driver_hostap.c16
-rw-r--r--src/drivers/driver_nl80211.c54
-rw-r--r--src/drivers/linux_ioctl.c43
-rw-r--r--src/drivers/linux_ioctl.h2
4 files changed, 51 insertions, 64 deletions
diff --git a/src/drivers/driver_hostap.c b/src/drivers/driver_hostap.c
index 39b17b6..64b345f 100644
--- a/src/drivers/driver_hostap.c
+++ b/src/drivers/driver_hostap.c
@@ -269,21 +269,7 @@ static int hostap_init_sockets(struct hostap_driver_data *drv, u8 *own_addr)
return -1;
}
- memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
- if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
- perror("ioctl(SIOCGIFHWADDR)");
- return -1;
- }
-
- if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
- printf("Invalid HW-addr family 0x%04x\n",
- ifr.ifr_hwaddr.sa_family);
- return -1;
- }
- os_memcpy(own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
- return 0;
+ return linux_get_ifhwaddr(drv->sock, drv->iface, own_addr);
}
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index a6e6188..58e4d28 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -18,7 +18,6 @@
#include "includes.h"
#include <sys/ioctl.h>
-#include <net/if_arp.h>
#include <net/if.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
@@ -270,50 +269,6 @@ nla_put_failure:
}
-static int get_ifhwaddr(struct wpa_driver_nl80211_data *drv,
- const char *ifname, u8 *addr)
-{
- struct ifreq ifr;
-
- os_memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
- if (ioctl(drv->ioctl_sock, SIOCGIFHWADDR, &ifr)) {
- wpa_printf(MSG_ERROR, "%s: ioctl(SIOCGIFHWADDR): %d (%s)",
- ifname, errno, strerror(errno));
- return -1;
- }
-
- if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
- wpa_printf(MSG_ERROR, "%s: Invalid HW-addr family 0x%04x",
- ifname, ifr.ifr_hwaddr.sa_family);
- return -1;
- }
- os_memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
- return 0;
-}
-
-
-static int set_ifhwaddr(struct wpa_driver_nl80211_data *drv,
- const char *ifname, const u8 *addr)
-{
- struct ifreq ifr;
-
- os_memset(&ifr, 0, sizeof(ifr));
- os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
- os_memcpy(ifr.ifr_hwaddr.sa_data, addr, ETH_ALEN);
- ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
-
- if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifr)) {
- wpa_printf(MSG_DEBUG, "%s: ioctl(SIOCSIFHWADDR): %d (%s)",
- ifname, errno, strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-
static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
{
struct wpa_driver_nl80211_data *drv = priv;
@@ -2696,7 +2651,7 @@ static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
#endif /* HOSTAPD */
if (addr && iftype != NL80211_IFTYPE_MONITOR &&
- set_ifhwaddr(drv, ifname, addr)) {
+ linux_set_ifhwaddr(drv->ioctl_sock, ifname, addr)) {
nl80211_remove_iface(drv, ifidx);
return -1;
}
@@ -4302,7 +4257,8 @@ static void *i802_init(struct hostapd_data *hapd,
goto failed;
if (params->bssid) {
- if (set_ifhwaddr(drv, drv->ifname, params->bssid))
+ if (linux_set_ifhwaddr(drv->ioctl-sock, drv->ifname,
+ params->bssid))
goto failed;
}
@@ -4327,7 +4283,7 @@ static void *i802_init(struct hostapd_data *hapd,
goto failed;
}
- if (get_ifhwaddr(drv, drv->ifname, params->own_addr))
+ if (linux_get_ifhwaddr(drv->ioctl_sock, drv->ifname, params->own_addr))
goto failed;
return drv;
@@ -4588,7 +4544,7 @@ static int wpa_driver_nl80211_alloc_interface_addr(void *priv, u8 *addr)
{
struct wpa_driver_nl80211_data *drv = priv;
- if (get_ifhwaddr(drv, drv->ifname, addr) < 0)
+ if (linux_get_ifhwaddr(drv->ioctl_sock, drv->ifname, addr) < 0)
return -1;
if (addr[0] & 0x02) {
diff --git a/src/drivers/linux_ioctl.c b/src/drivers/linux_ioctl.c
index 733bdb2..549ebb4 100644
--- a/src/drivers/linux_ioctl.c
+++ b/src/drivers/linux_ioctl.c
@@ -15,6 +15,7 @@
#include "utils/includes.h"
#include <sys/ioctl.h>
#include <net/if.h>
+#include <net/if_arp.h>
#include "utils/common.h"
#include "linux_ioctl.h"
@@ -54,3 +55,45 @@ int linux_set_iface_flags(int sock, const char *ifname, int dev_up)
return 0;
}
+
+
+int linux_get_ifhwaddr(int sock, const char *ifname, u8 *addr)
+{
+ struct ifreq ifr;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ if (ioctl(sock, SIOCGIFHWADDR, &ifr)) {
+ wpa_printf(MSG_ERROR, "Could not get interface %s hwaddr: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
+ wpa_printf(MSG_ERROR, "%s: Invalid HW-addr family 0x%04x",
+ ifname, ifr.ifr_hwaddr.sa_family);
+ return -1;
+ }
+ os_memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+
+ return 0;
+}
+
+
+int linux_set_ifhwaddr(int sock, const char *ifname, const u8 *addr)
+{
+ struct ifreq ifr;
+
+ os_memset(&ifr, 0, sizeof(ifr));
+ os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ os_memcpy(ifr.ifr_hwaddr.sa_data, addr, ETH_ALEN);
+ ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+
+ if (ioctl(sock, SIOCSIFHWADDR, &ifr)) {
+ wpa_printf(MSG_DEBUG, "Could not set interface %s hwaddr: %s",
+ ifname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/src/drivers/linux_ioctl.h b/src/drivers/linux_ioctl.h
index 8498b9a..54142f5 100644
--- a/src/drivers/linux_ioctl.h
+++ b/src/drivers/linux_ioctl.h
@@ -16,5 +16,7 @@
#define LINUX_IOCTL_H
int linux_set_iface_flags(int sock, const char *ifname, int dev_up);
+int linux_get_ifhwaddr(int sock, const char *ifname, u8 *addr);
+int linux_set_ifhwaddr(int sock, const char *ifname, const u8 *addr);
#endif /* LINUX_IOCTL_H */