core: add generic way of getting device hardware addresses
This commit is contained in:
@@ -82,6 +82,7 @@ typedef struct {
|
|||||||
int brfd;
|
int brfd;
|
||||||
int nas_ifindex;
|
int nas_ifindex;
|
||||||
char * nas_ifname;
|
char * nas_ifname;
|
||||||
|
guint8 nas_hw_addr[ETH_ALEN];
|
||||||
} NMDeviceAdslPrivate;
|
} NMDeviceAdslPrivate;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -233,6 +234,7 @@ static void
|
|||||||
set_nas_iface (NMDeviceAdsl *self, int idx, const char *name)
|
set_nas_iface (NMDeviceAdsl *self, int idx, const char *name)
|
||||||
{
|
{
|
||||||
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self);
|
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (self);
|
||||||
|
gsize addrlen;
|
||||||
|
|
||||||
g_return_if_fail (name != NULL);
|
g_return_if_fail (name != NULL);
|
||||||
|
|
||||||
@@ -245,6 +247,13 @@ set_nas_iface (NMDeviceAdsl *self, int idx, const char *name)
|
|||||||
|
|
||||||
g_warn_if_fail (priv->nas_ifname == NULL);
|
g_warn_if_fail (priv->nas_ifname == NULL);
|
||||||
priv->nas_ifname = g_strdup (name);
|
priv->nas_ifname = g_strdup (name);
|
||||||
|
|
||||||
|
/* Update NAS interface's MAC address */
|
||||||
|
addrlen = nm_device_read_hwaddr (NM_DEVICE (self),
|
||||||
|
priv->nas_hw_addr,
|
||||||
|
sizeof (priv->nas_hw_addr),
|
||||||
|
NULL);
|
||||||
|
g_warn_if_fail (addrlen == sizeof (priv->nas_hw_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -591,10 +600,20 @@ deactivate (NMDevice *device)
|
|||||||
priv->nas_ifindex = -1;
|
priv->nas_ifindex = -1;
|
||||||
g_free (priv->nas_ifname);
|
g_free (priv->nas_ifname);
|
||||||
priv->nas_ifname = NULL;
|
priv->nas_ifname = NULL;
|
||||||
|
memset (priv->nas_hw_addr, 0, sizeof (priv->nas_hw_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************/
|
/**************************************************************/
|
||||||
|
|
||||||
|
static const guint8 *
|
||||||
|
get_hw_address (NMDevice *device, guint *out_len)
|
||||||
|
{
|
||||||
|
NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device);
|
||||||
|
|
||||||
|
*out_len = priv->nas_ifname ? sizeof (priv->nas_hw_addr) : 0;
|
||||||
|
return priv->nas_hw_addr;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_carrier (NMDeviceAdsl *self, const gboolean carrier)
|
set_carrier (NMDeviceAdsl *self, const gboolean carrier)
|
||||||
{
|
{
|
||||||
@@ -818,6 +837,7 @@ nm_device_adsl_class_init (NMDeviceAdslClass *klass)
|
|||||||
parent_class->get_best_auto_connection = get_best_auto_connection;
|
parent_class->get_best_auto_connection = get_best_auto_connection;
|
||||||
parent_class->complete_connection = complete_connection;
|
parent_class->complete_connection = complete_connection;
|
||||||
|
|
||||||
|
parent_class->get_hw_address = get_hw_address;
|
||||||
parent_class->act_stage2_config = act_stage2_config;
|
parent_class->act_stage2_config = act_stage2_config;
|
||||||
parent_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
|
parent_class->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
|
||||||
parent_class->deactivate = deactivate;
|
parent_class->deactivate = deactivate;
|
||||||
|
@@ -63,6 +63,7 @@ typedef struct {
|
|||||||
guint mm_watch_id;
|
guint mm_watch_id;
|
||||||
gboolean mm_running;
|
gboolean mm_running;
|
||||||
|
|
||||||
|
guint8 hw_addr[ETH_ALEN]; /* binary representation of bdaddr */
|
||||||
char *bdaddr;
|
char *bdaddr;
|
||||||
char *name;
|
char *name;
|
||||||
guint32 capabilities;
|
guint32 capabilities;
|
||||||
@@ -117,14 +118,6 @@ guint32 nm_device_bt_get_capabilities (NMDeviceBt *self)
|
|||||||
return NM_DEVICE_BT_GET_PRIVATE (self)->capabilities;
|
return NM_DEVICE_BT_GET_PRIVATE (self)->capabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *nm_device_bt_get_hw_address (NMDeviceBt *self)
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (self != NULL, NULL);
|
|
||||||
g_return_val_if_fail (NM_IS_DEVICE_BT (self), NULL);
|
|
||||||
|
|
||||||
return NM_DEVICE_BT_GET_PRIVATE (self)->bdaddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static guint32
|
static guint32
|
||||||
get_connection_bt_type (NMConnection *connection)
|
get_connection_bt_type (NMConnection *connection)
|
||||||
{
|
{
|
||||||
@@ -401,6 +394,15 @@ get_generic_capabilities (NMDevice *dev)
|
|||||||
return NM_DEVICE_CAP_NM_SUPPORTED;
|
return NM_DEVICE_CAP_NM_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const guint8 *
|
||||||
|
get_hw_address (NMDevice *device, guint *out_len)
|
||||||
|
{
|
||||||
|
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
|
||||||
|
|
||||||
|
*out_len = sizeof (priv->hw_addr);
|
||||||
|
return priv->hw_addr;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
hwaddr_matches (NMDevice *device,
|
hwaddr_matches (NMDevice *device,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
@@ -1231,6 +1233,8 @@ set_property (GObject *object, guint prop_id,
|
|||||||
case PROP_HW_ADDRESS:
|
case PROP_HW_ADDRESS:
|
||||||
/* Construct only */
|
/* Construct only */
|
||||||
priv->bdaddr = g_ascii_strup (g_value_get_string (value), -1);
|
priv->bdaddr = g_ascii_strup (g_value_get_string (value), -1);
|
||||||
|
if (!nm_utils_hwaddr_aton (priv->bdaddr, ARPHRD_ETHER, &priv->hw_addr))
|
||||||
|
nm_log_err (LOGD_HW, "Failed to convert BT address '%s'", priv->bdaddr);
|
||||||
break;
|
break;
|
||||||
case PROP_BT_NAME:
|
case PROP_BT_NAME:
|
||||||
/* Construct only */
|
/* Construct only */
|
||||||
@@ -1326,6 +1330,7 @@ nm_device_bt_class_init (NMDeviceBtClass *klass)
|
|||||||
device_class->check_connection_available = check_connection_available;
|
device_class->check_connection_available = check_connection_available;
|
||||||
device_class->complete_connection = complete_connection;
|
device_class->complete_connection = complete_connection;
|
||||||
device_class->hwaddr_matches = hwaddr_matches;
|
device_class->hwaddr_matches = hwaddr_matches;
|
||||||
|
device_class->get_hw_address = get_hw_address;
|
||||||
device_class->is_available = is_available;
|
device_class->is_available = is_available;
|
||||||
|
|
||||||
device_class->state_changed = device_state_changed;
|
device_class->state_changed = device_state_changed;
|
||||||
|
@@ -65,8 +65,6 @@ NMDevice *nm_device_bt_new (const char *udi,
|
|||||||
|
|
||||||
guint32 nm_device_bt_get_capabilities (NMDeviceBt *device);
|
guint32 nm_device_bt_get_capabilities (NMDeviceBt *device);
|
||||||
|
|
||||||
const char *nm_device_bt_get_hw_address (NMDeviceBt *device);
|
|
||||||
|
|
||||||
gboolean nm_device_bt_modem_added (NMDeviceBt *device,
|
gboolean nm_device_bt_modem_added (NMDeviceBt *device,
|
||||||
NMModem *modem,
|
NMModem *modem,
|
||||||
const char *driver);
|
const char *driver);
|
||||||
|
@@ -315,6 +315,14 @@ update_hw_address (NMDevice *dev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const guint8 *
|
||||||
|
get_hw_address (NMDevice *device, guint *out_len)
|
||||||
|
{
|
||||||
|
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
|
||||||
|
|
||||||
|
*out_len = sizeof (priv->hw_addr);
|
||||||
|
return priv->hw_addr;
|
||||||
|
}
|
||||||
|
|
||||||
static NMActStageReturn
|
static NMActStageReturn
|
||||||
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
|
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
|
||||||
@@ -505,6 +513,7 @@ nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *klass)
|
|||||||
parent_class->bring_up = bring_up;
|
parent_class->bring_up = bring_up;
|
||||||
parent_class->take_down = take_down;
|
parent_class->take_down = take_down;
|
||||||
parent_class->update_hw_address = update_hw_address;
|
parent_class->update_hw_address = update_hw_address;
|
||||||
|
parent_class->get_hw_address = get_hw_address;
|
||||||
parent_class->check_connection_compatible = check_connection_compatible;
|
parent_class->check_connection_compatible = check_connection_compatible;
|
||||||
parent_class->complete_connection = complete_connection;
|
parent_class->complete_connection = complete_connection;
|
||||||
|
|
||||||
@@ -616,15 +625,16 @@ static gboolean
|
|||||||
is_companion (NMDeviceOlpcMesh *self, NMDevice *other)
|
is_companion (NMDeviceOlpcMesh *self, NMDevice *other)
|
||||||
{
|
{
|
||||||
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
|
NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self);
|
||||||
struct ether_addr their_addr;
|
const guint8 *their_addr;
|
||||||
|
guint their_addr_len = 0;
|
||||||
NMManager *manager;
|
NMManager *manager;
|
||||||
|
|
||||||
if (!NM_IS_DEVICE_WIFI (other))
|
if (!NM_IS_DEVICE_WIFI (other))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
nm_device_wifi_get_address (NM_DEVICE_WIFI (other), &their_addr);
|
their_addr = nm_device_get_hw_address (other, &their_addr_len);
|
||||||
|
if ( (their_addr_len != ETH_ALEN)
|
||||||
if (memcmp (priv->hw_addr, their_addr.ether_addr_octet, ETH_ALEN) != 0)
|
|| (memcmp (priv->hw_addr, their_addr, ETH_ALEN) != 0))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
priv->companion = other;
|
priv->companion = other;
|
||||||
|
@@ -172,6 +172,15 @@ update_hw_address (NMDevice *dev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const guint8 *
|
||||||
|
get_hw_address (NMDevice *device, guint *out_len)
|
||||||
|
{
|
||||||
|
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device);
|
||||||
|
|
||||||
|
*out_len = priv->hw_addr_len;
|
||||||
|
return priv->hw_addr;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
can_interrupt_activation (NMDevice *dev)
|
can_interrupt_activation (NMDevice *dev)
|
||||||
{
|
{
|
||||||
@@ -724,6 +733,7 @@ nm_device_vlan_class_init (NMDeviceVlanClass *klass)
|
|||||||
|
|
||||||
parent_class->get_generic_capabilities = get_generic_capabilities;
|
parent_class->get_generic_capabilities = get_generic_capabilities;
|
||||||
parent_class->update_hw_address = update_hw_address;
|
parent_class->update_hw_address = update_hw_address;
|
||||||
|
parent_class->get_hw_address = get_hw_address;
|
||||||
parent_class->hw_bring_up = hw_bring_up;
|
parent_class->hw_bring_up = hw_bring_up;
|
||||||
parent_class->can_interrupt_activation = can_interrupt_activation;
|
parent_class->can_interrupt_activation = can_interrupt_activation;
|
||||||
parent_class->is_available = is_available;
|
parent_class->is_available = is_available;
|
||||||
|
@@ -1460,25 +1460,6 @@ get_best_auto_connection (NMDevice *dev,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* nm_device_wifi_get_address
|
|
||||||
*
|
|
||||||
* Get a device's hardware address
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
nm_device_wifi_get_address (NMDeviceWifi *self,
|
|
||||||
struct ether_addr *addr)
|
|
||||||
{
|
|
||||||
NMDeviceWifiPrivate *priv;
|
|
||||||
|
|
||||||
g_return_if_fail (self != NULL);
|
|
||||||
g_return_if_fail (addr != NULL);
|
|
||||||
|
|
||||||
priv = NM_DEVICE_WIFI_GET_PRIVATE (self);
|
|
||||||
memcpy (addr, &priv->hw_addr, sizeof (struct ether_addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ap_list_dump (NMDeviceWifi *self)
|
ap_list_dump (NMDeviceWifi *self)
|
||||||
{
|
{
|
||||||
@@ -2936,6 +2917,15 @@ update_initial_hw_address (NMDevice *dev)
|
|||||||
g_free (mac_str);
|
g_free (mac_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const guint8 *
|
||||||
|
get_hw_address (NMDevice *device, guint *out_len)
|
||||||
|
{
|
||||||
|
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
|
||||||
|
|
||||||
|
*out_len = ETH_ALEN;
|
||||||
|
return priv->hw_addr;
|
||||||
|
}
|
||||||
|
|
||||||
static NMActStageReturn
|
static NMActStageReturn
|
||||||
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
|
act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason)
|
||||||
{
|
{
|
||||||
@@ -3761,6 +3751,7 @@ nm_device_wifi_class_init (NMDeviceWifiClass *klass)
|
|||||||
parent_class->bring_up = bring_up;
|
parent_class->bring_up = bring_up;
|
||||||
parent_class->take_down = take_down;
|
parent_class->take_down = take_down;
|
||||||
parent_class->update_hw_address = update_hw_address;
|
parent_class->update_hw_address = update_hw_address;
|
||||||
|
parent_class->get_hw_address = get_hw_address;
|
||||||
parent_class->update_permanent_hw_address = update_permanent_hw_address;
|
parent_class->update_permanent_hw_address = update_permanent_hw_address;
|
||||||
parent_class->update_initial_hw_address = update_initial_hw_address;
|
parent_class->update_initial_hw_address = update_initial_hw_address;
|
||||||
parent_class->get_best_auto_connection = get_best_auto_connection;
|
parent_class->get_best_auto_connection = get_best_auto_connection;
|
||||||
|
@@ -94,8 +94,6 @@ NMDevice *nm_device_wifi_new (const char *udi,
|
|||||||
const char *iface,
|
const char *iface,
|
||||||
const char *driver);
|
const char *driver);
|
||||||
|
|
||||||
void nm_device_wifi_get_address (NMDeviceWifi *dev, struct ether_addr *addr);
|
|
||||||
|
|
||||||
NMAccessPoint * nm_device_wifi_get_activation_ap (NMDeviceWifi *self);
|
NMAccessPoint * nm_device_wifi_get_activation_ap (NMDeviceWifi *self);
|
||||||
|
|
||||||
RfKillState nm_device_wifi_get_ipw_rfkill_state (NMDeviceWifi *self);
|
RfKillState nm_device_wifi_get_ipw_rfkill_state (NMDeviceWifi *self);
|
||||||
|
@@ -387,6 +387,15 @@ update_hw_address (NMDevice *dev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const guint8 *
|
||||||
|
get_hw_address (NMDevice *dev, guint *out_len)
|
||||||
|
{
|
||||||
|
NMDeviceWiredPrivate *priv = NM_DEVICE_WIRED_GET_PRIVATE (dev);
|
||||||
|
|
||||||
|
*out_len = priv->hw_addr_len;
|
||||||
|
return priv->hw_addr;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
can_interrupt_activation (NMDevice *dev)
|
can_interrupt_activation (NMDevice *dev)
|
||||||
{
|
{
|
||||||
@@ -472,6 +481,7 @@ nm_device_wired_class_init (NMDeviceWiredClass *klass)
|
|||||||
parent_class->hw_bring_up = hw_bring_up;
|
parent_class->hw_bring_up = hw_bring_up;
|
||||||
parent_class->can_interrupt_activation = can_interrupt_activation;
|
parent_class->can_interrupt_activation = can_interrupt_activation;
|
||||||
parent_class->update_hw_address = update_hw_address;
|
parent_class->update_hw_address = update_hw_address;
|
||||||
|
parent_class->get_hw_address = get_hw_address;
|
||||||
parent_class->is_available = is_available;
|
parent_class->is_available = is_available;
|
||||||
parent_class->connection_match_config = connection_match_config;
|
parent_class->connection_match_config = connection_match_config;
|
||||||
}
|
}
|
||||||
|
@@ -611,6 +611,18 @@ nm_device_set_ip_iface (NMDevice *self, const char *iface)
|
|||||||
g_free (old_ip_iface);
|
g_free (old_ip_iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const guint8 *
|
||||||
|
nm_device_get_hw_address (NMDevice *dev, guint *out_len)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (dev != NULL, NULL);
|
||||||
|
g_return_val_if_fail (NM_IS_DEVICE (dev), NULL);
|
||||||
|
g_return_val_if_fail (out_len != NULL, NULL);
|
||||||
|
g_return_val_if_fail (*out_len == 0, NULL);
|
||||||
|
|
||||||
|
if (NM_DEVICE_GET_CLASS (dev)->get_hw_address)
|
||||||
|
return NM_DEVICE_GET_CLASS (dev)->get_hw_address (dev, out_len);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get/set functions for driver
|
* Get/set functions for driver
|
||||||
|
@@ -112,6 +112,7 @@ typedef struct {
|
|||||||
void (* update_hw_address) (NMDevice *self);
|
void (* update_hw_address) (NMDevice *self);
|
||||||
void (* update_permanent_hw_address) (NMDevice *self);
|
void (* update_permanent_hw_address) (NMDevice *self);
|
||||||
void (* update_initial_hw_address) (NMDevice *self);
|
void (* update_initial_hw_address) (NMDevice *self);
|
||||||
|
const guint8 * (* get_hw_address) (NMDevice *self, guint *out_len);
|
||||||
|
|
||||||
guint32 (* get_type_capabilities) (NMDevice *self);
|
guint32 (* get_type_capabilities) (NMDevice *self);
|
||||||
guint32 (* get_generic_capabilities) (NMDevice *self);
|
guint32 (* get_generic_capabilities) (NMDevice *self);
|
||||||
@@ -212,6 +213,8 @@ NMDeviceType nm_device_get_device_type (NMDevice *dev);
|
|||||||
|
|
||||||
int nm_device_get_priority (NMDevice *dev);
|
int nm_device_get_priority (NMDevice *dev);
|
||||||
|
|
||||||
|
const guint8 * nm_device_get_hw_address (NMDevice *dev, guint *out_len);
|
||||||
|
|
||||||
NMDHCP4Config * nm_device_get_dhcp4_config (NMDevice *dev);
|
NMDHCP4Config * nm_device_get_dhcp4_config (NMDevice *dev);
|
||||||
NMDHCP6Config * nm_device_get_dhcp6_config (NMDevice *dev);
|
NMDHCP6Config * nm_device_get_dhcp6_config (NMDevice *dev);
|
||||||
|
|
||||||
|
@@ -370,6 +370,15 @@ update_hw_address (NMDevice *dev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const guint8 *
|
||||||
|
get_hw_address (NMDevice *device, guint *out_len)
|
||||||
|
{
|
||||||
|
NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (device);
|
||||||
|
|
||||||
|
*out_len = sizeof (priv->hw_addr);
|
||||||
|
return priv->hw_addr;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
hwaddr_matches (NMDevice *device,
|
hwaddr_matches (NMDevice *device,
|
||||||
NMConnection *connection,
|
NMConnection *connection,
|
||||||
@@ -1477,6 +1486,7 @@ nm_device_wimax_class_init (NMDeviceWimaxClass *klass)
|
|||||||
device_class->take_down = take_down;
|
device_class->take_down = take_down;
|
||||||
device_class->hw_bring_up = hw_bring_up;
|
device_class->hw_bring_up = hw_bring_up;
|
||||||
device_class->update_hw_address = update_hw_address;
|
device_class->update_hw_address = update_hw_address;
|
||||||
|
device_class->get_hw_address = get_hw_address;
|
||||||
device_class->check_connection_compatible = check_connection_compatible;
|
device_class->check_connection_compatible = check_connection_compatible;
|
||||||
device_class->check_connection_available = check_connection_available;
|
device_class->check_connection_available = check_connection_available;
|
||||||
device_class->complete_connection = complete_connection;
|
device_class->complete_connection = complete_connection;
|
||||||
|
Reference in New Issue
Block a user