summaryrefslogtreecommitdiff
path: root/src/devices/wifi/nm-device-wifi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/wifi/nm-device-wifi.c')
-rw-r--r--src/devices/wifi/nm-device-wifi.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c
index ed78c5c762..314813f49a 100644
--- a/src/devices/wifi/nm-device-wifi.c
+++ b/src/devices/wifi/nm-device-wifi.c
@@ -114,7 +114,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
struct _NMDeviceWifiPrivate {
gboolean disposed;
- guint8 perm_hw_addr[ETH_ALEN]; /* Permanent MAC address */
+ char * perm_hw_addr; /* Permanent MAC address */
guint8 initial_hw_addr[ETH_ALEN]; /* Initial MAC address (as seen when NM starts) */
gint8 invalid_strength_counter;
@@ -839,7 +839,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
mac = nm_setting_wireless_get_mac_address (s_wireless);
- if (mac && !nm_utils_hwaddr_equal (mac->data, mac->len, priv->perm_hw_addr, ETH_ALEN))
+ if (mac && !nm_utils_hwaddr_equal (mac->data, mac->len, priv->perm_hw_addr, -1))
return FALSE;
/* Check for MAC address blacklist */
@@ -853,7 +853,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
return FALSE;
}
- if (nm_utils_hwaddr_equal (addr, ETH_ALEN, priv->perm_hw_addr, ETH_ALEN))
+ if (nm_utils_hwaddr_equal (addr, ETH_ALEN, priv->perm_hw_addr, -1))
return FALSE;
}
@@ -1131,7 +1131,7 @@ complete_connection (NMDevice *device,
setting_mac = nm_setting_wireless_get_mac_address (s_wifi);
if (setting_mac) {
/* Make sure the setting MAC (if any) matches the device's permanent MAC */
- if (!nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, priv->perm_hw_addr, ETH_ALEN)) {
+ if (!nm_utils_hwaddr_equal (setting_mac->data, setting_mac->len, priv->perm_hw_addr, -1)) {
g_set_error (error,
NM_SETTING_WIRELESS_ERROR,
NM_SETTING_WIRELESS_ERROR_INVALID_PROPERTY,
@@ -1140,14 +1140,15 @@ complete_connection (NMDevice *device,
}
} else {
GByteArray *mac;
+ guint8 perm_hw_addr[ETH_ALEN];
/* Lock the connection to this device by default if it uses a
* permanent MAC address (ie not a 'locally administered' one)
*/
- if ( !(priv->perm_hw_addr[0] & 0x02)
- && !nm_utils_hwaddr_equal (priv->perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
- mac = g_byte_array_sized_new (ETH_ALEN);
- g_byte_array_append (mac, priv->perm_hw_addr, ETH_ALEN);
+ nm_utils_hwaddr_aton (priv->perm_hw_addr, perm_hw_addr, ETH_ALEN);
+ if ( !(perm_hw_addr[0] & 0x02)
+ && !nm_utils_hwaddr_equal (perm_hw_addr, ETH_ALEN, NULL, ETH_ALEN)) {
+ mac = nm_utils_hwaddr_atoba (priv->perm_hw_addr, ETH_ALEN);
g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_MAC_ADDRESS, mac, NULL);
g_byte_array_free (mac, TRUE);
}
@@ -2561,6 +2562,8 @@ update_permanent_hw_address (NMDevice *dev)
struct ethtool_perm_addr *epaddr = NULL;
int fd, ret;
+ g_return_if_fail (priv->perm_hw_addr == NULL);
+
fd = socket (PF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
nm_log_err (LOGD_HW, "could not open control socket.");
@@ -2582,13 +2585,10 @@ update_permanent_hw_address (NMDevice *dev)
nm_log_dbg (LOGD_HW | LOGD_ETHER, "(%s): unable to read permanent MAC address (error %d)",
nm_device_get_iface (dev), errno);
/* Fall back to current address */
- memcpy (epaddr->data, nm_device_get_hw_address (dev, NULL), ETH_ALEN);
+ nm_utils_hwaddr_aton (nm_device_get_hw_address (dev), epaddr->data, ETH_ALEN);
}
- if (!nm_utils_hwaddr_equal (priv->perm_hw_addr, ETH_ALEN, epaddr->data, ETH_ALEN)) {
- memcpy (priv->perm_hw_addr, epaddr->data, ETH_ALEN);
- g_object_notify (G_OBJECT (dev), NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS);
- }
+ priv->perm_hw_addr = nm_utils_hwaddr_ntoa (epaddr->data, ETH_ALEN);
g_free (epaddr);
close (fd);
@@ -2599,17 +2599,16 @@ update_initial_hw_address (NMDevice *dev)
{
NMDeviceWifi *self = NM_DEVICE_WIFI (dev);
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
- char *mac_str;
+ const char *mac_str;
/* This sets initial MAC address from current MAC address. It should only
* be called from NMDevice constructor() to really get the initial address.
*/
- memcpy (priv->initial_hw_addr, nm_device_get_hw_address (dev, NULL), ETH_ALEN);
+ mac_str = nm_device_get_hw_address (dev);
+ nm_utils_hwaddr_aton (mac_str, priv->initial_hw_addr, ETH_ALEN);
- mac_str = nm_utils_hwaddr_ntoa (priv->initial_hw_addr, ETH_ALEN);
nm_log_dbg (LOGD_DEVICE | LOGD_ETHER, "(%s): read initial MAC address %s",
nm_device_get_iface (dev), mac_str);
- g_free (mac_str);
}
static NMActStageReturn
@@ -2703,8 +2702,12 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
if (nm_ap_get_mode (ap) == NM_802_11_MODE_INFRA)
nm_ap_set_broadcast (ap, FALSE);
- else if (nm_ap_is_hotspot (ap))
- nm_ap_set_address (ap, nm_device_get_hw_address (dev, NULL));
+ else if (nm_ap_is_hotspot (ap)) {
+ guint8 addr[ETH_ALEN];
+
+ nm_utils_hwaddr_aton (nm_device_get_hw_address (dev), addr, ETH_ALEN);
+ nm_ap_set_address (ap, addr);
+ }
priv->ap_list = g_slist_prepend (priv->ap_list, ap);
nm_ap_export_to_dbus (ap);
@@ -3309,6 +3312,17 @@ dispose (GObject *object)
}
static void
+finalize (GObject *object)
+{
+ NMDeviceWifi *self = NM_DEVICE_WIFI (object);
+ NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
+
+ g_free (priv->perm_hw_addr);
+
+ G_OBJECT_CLASS (nm_device_wifi_parent_class)->finalize (object);
+}
+
+static void
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
@@ -3319,7 +3333,7 @@ get_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_PERM_HW_ADDRESS:
- g_value_take_string (value, nm_utils_hwaddr_ntoa (priv->perm_hw_addr, ETH_ALEN));
+ g_value_set_string (value, priv->perm_hw_addr);
break;
case PROP_MODE:
g_value_set_uint (value, priv->mode);
@@ -3375,6 +3389,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->dispose = dispose;
+ object_class->finalize = finalize;
parent_class->bring_up = bring_up;
parent_class->update_permanent_hw_address = update_permanent_hw_address;