mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 11:00:09 +01:00
Merge branch 'th/nm_utils_hwaddr_ntoa_len'
https://mail.gnome.org/archives/networkmanager-list/2014-May/msg00046.html Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
commit
00a6f9dcf9
5 changed files with 59 additions and 72 deletions
|
|
@ -2154,18 +2154,26 @@ char *
|
|||
nm_utils_hwaddr_ntoa_len (gconstpointer addr, gsize length)
|
||||
{
|
||||
const guint8 *in = addr;
|
||||
GString *out;
|
||||
char *out, *result;
|
||||
const char *LOOKUP = "0123456789ABCDEF";
|
||||
|
||||
g_return_val_if_fail (addr && length, g_strdup (""));
|
||||
|
||||
out = g_string_new (NULL);
|
||||
while (length--) {
|
||||
if (out->len)
|
||||
g_string_append_c (out, ':');
|
||||
g_string_append_printf (out, "%02X", *in++);
|
||||
if (!addr || !length) {
|
||||
g_return_val_if_reached (g_strdup (""));
|
||||
return g_strdup ("");
|
||||
}
|
||||
|
||||
return g_string_free (out, FALSE);
|
||||
result = out = g_malloc (length * 3);
|
||||
for (;;) {
|
||||
guint8 v = *in++;
|
||||
|
||||
*out++ = LOOKUP[v >> 4];
|
||||
*out++ = LOOKUP[v & 0x0F];
|
||||
if (--length == 0) {
|
||||
*out = 0;
|
||||
return result;
|
||||
}
|
||||
*out++ = ':';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ typedef struct {
|
|||
|
||||
NMBluezDevice *bt_device;
|
||||
|
||||
char *bdaddr;
|
||||
guint8 bdaddr[ETH_ALEN];
|
||||
char *name;
|
||||
guint32 capabilities;
|
||||
|
||||
|
|
@ -170,8 +170,6 @@ check_connection_compatible (NMDevice *device,
|
|||
NMSettingConnection *s_con;
|
||||
NMSettingBluetooth *s_bt;
|
||||
const GByteArray *array;
|
||||
char *str;
|
||||
int addr_match = FALSE;
|
||||
guint32 bt_type;
|
||||
|
||||
if (!NM_DEVICE_CLASS (nm_device_bt_parent_class)->check_connection_compatible (device, connection, error))
|
||||
|
|
@ -195,14 +193,6 @@ check_connection_compatible (NMDevice *device,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
array = nm_setting_bluetooth_get_bdaddr (s_bt);
|
||||
if (!array || (array->len != ETH_ALEN)) {
|
||||
g_set_error (error,
|
||||
NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INVALID,
|
||||
"The connection did not contain a valid Bluetooth address.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bt_type = get_connection_bt_type (connection);
|
||||
if (!(bt_type & priv->capabilities)) {
|
||||
g_set_error (error,
|
||||
|
|
@ -211,13 +201,22 @@ check_connection_compatible (NMDevice *device,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
str = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
array->data[0], array->data[1], array->data[2],
|
||||
array->data[3], array->data[4], array->data[5]);
|
||||
addr_match = !strcmp (priv->bdaddr, str);
|
||||
g_free (str);
|
||||
array = nm_setting_bluetooth_get_bdaddr (s_bt);
|
||||
if (!array || (array->len != ETH_ALEN)) {
|
||||
g_set_error (error,
|
||||
NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INVALID,
|
||||
"The connection did not contain a valid Bluetooth address.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return addr_match;
|
||||
if (memcmp (priv->bdaddr, array->data, ETH_ALEN) != 0) {
|
||||
g_set_error (error,
|
||||
NM_BT_ERROR, NM_BT_ERROR_CONNECTION_INVALID,
|
||||
"The connection did not match the device's Bluetooth address.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -249,7 +248,6 @@ complete_connection (NMDevice *device,
|
|||
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device);
|
||||
NMSettingBluetooth *s_bt;
|
||||
const GByteArray *setting_bdaddr;
|
||||
struct ether_addr *devaddr = ether_aton (priv->bdaddr);
|
||||
const char *ctype;
|
||||
gboolean is_dun = FALSE, is_pan = FALSE;
|
||||
NMSettingGsm *s_gsm;
|
||||
|
|
@ -357,7 +355,7 @@ complete_connection (NMDevice *device,
|
|||
setting_bdaddr = nm_setting_bluetooth_get_bdaddr (s_bt);
|
||||
if (setting_bdaddr) {
|
||||
/* Make sure the setting BT Address (if any) matches the device's */
|
||||
if (memcmp (setting_bdaddr->data, devaddr->ether_addr_octet, ETH_ALEN)) {
|
||||
if (memcmp (setting_bdaddr->data, priv->bdaddr, ETH_ALEN)) {
|
||||
g_set_error_literal (error,
|
||||
NM_SETTING_BLUETOOTH_ERROR,
|
||||
NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY,
|
||||
|
|
@ -369,9 +367,9 @@ complete_connection (NMDevice *device,
|
|||
const guint8 null_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
/* Lock the connection to this device by default */
|
||||
if (memcmp (devaddr->ether_addr_octet, null_mac, ETH_ALEN)) {
|
||||
if (memcmp (priv->bdaddr, null_mac, ETH_ALEN)) {
|
||||
bdaddr = g_byte_array_sized_new (ETH_ALEN);
|
||||
g_byte_array_append (bdaddr, devaddr->ether_addr_octet, ETH_ALEN);
|
||||
g_byte_array_append (bdaddr, priv->bdaddr, ETH_ALEN);
|
||||
g_object_set (G_OBJECT (s_bt), NM_SETTING_BLUETOOTH_BDADDR, bdaddr, NULL);
|
||||
g_byte_array_free (bdaddr, TRUE);
|
||||
}
|
||||
|
|
@ -1140,7 +1138,7 @@ constructed (GObject *object)
|
|||
my_hwaddr = nm_device_get_hw_address (NM_DEVICE (object), &my_hwaddr_len);
|
||||
g_assert (my_hwaddr);
|
||||
g_assert_cmpint (my_hwaddr_len, ==, ETH_ALEN);
|
||||
priv->bdaddr = nm_utils_hwaddr_ntoa (my_hwaddr, ARPHRD_ETHER);
|
||||
memcpy (priv->bdaddr, my_hwaddr, ETH_ALEN);
|
||||
|
||||
/* Watch for BT device property changes */
|
||||
g_signal_connect (priv->bt_device, "notify::" NM_BLUEZ_DEVICE_CONNECTED,
|
||||
|
|
|
|||
|
|
@ -1061,10 +1061,7 @@ set_link_status (NMDeviceWimax *self, WIMAX_API_LINK_STATUS_INFO_EX *link_status
|
|||
conv_rssi = sdk_rssi_to_dbm (link_status->RSSI);
|
||||
conv_cinr = sdk_cinr_to_db (link_status->CINR);
|
||||
conv_tx_pow = sdk_tx_pow_to_dbm (link_status->txPWR);
|
||||
new_bsid = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
link_status->bsId[0], link_status->bsId[1],
|
||||
link_status->bsId[2], link_status->bsId[3],
|
||||
link_status->bsId[4], link_status->bsId[5]);
|
||||
new_bsid = nm_utils_hwaddr_ntoa_len (link_status->bsId, 6);
|
||||
}
|
||||
|
||||
if (priv->center_freq != center_freq) {
|
||||
|
|
|
|||
|
|
@ -50,6 +50,14 @@
|
|||
#include "utils.h"
|
||||
#include "crypto.h"
|
||||
|
||||
|
||||
static void
|
||||
svSetValue_free (shvarFile *s, const char *key, char *value, gboolean verbatim)
|
||||
{
|
||||
svSetValue (s, key, value, verbatim);
|
||||
g_free (value);
|
||||
}
|
||||
|
||||
static void
|
||||
save_secret_flags (shvarFile *ifcfg,
|
||||
const char *key,
|
||||
|
|
@ -817,21 +825,15 @@ write_wireless_setting (NMConnection *connection,
|
|||
svSetValue (ifcfg, "HWADDR", NULL, FALSE);
|
||||
device_mac = nm_setting_wireless_get_mac_address (s_wireless);
|
||||
if (device_mac) {
|
||||
tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
device_mac->data[0], device_mac->data[1], device_mac->data[2],
|
||||
device_mac->data[3], device_mac->data[4], device_mac->data[5]);
|
||||
svSetValue (ifcfg, "HWADDR", tmp, FALSE);
|
||||
g_free (tmp);
|
||||
svSetValue_free (ifcfg, "HWADDR",
|
||||
nm_utils_hwaddr_ntoa_len (device_mac->data, device_mac->len), FALSE);
|
||||
}
|
||||
|
||||
svSetValue (ifcfg, "MACADDR", NULL, FALSE);
|
||||
cloned_mac = nm_setting_wireless_get_cloned_mac_address (s_wireless);
|
||||
if (cloned_mac) {
|
||||
tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
cloned_mac->data[0], cloned_mac->data[1], cloned_mac->data[2],
|
||||
cloned_mac->data[3], cloned_mac->data[4], cloned_mac->data[5]);
|
||||
svSetValue (ifcfg, "MACADDR", tmp, FALSE);
|
||||
g_free (tmp);
|
||||
svSetValue_free (ifcfg, "MACADDR",
|
||||
nm_utils_hwaddr_ntoa_len (cloned_mac->data, cloned_mac->len), FALSE);
|
||||
}
|
||||
|
||||
svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE);
|
||||
|
|
@ -933,11 +935,8 @@ write_wireless_setting (NMConnection *connection,
|
|||
svSetValue (ifcfg, "BSSID", NULL, FALSE);
|
||||
bssid = nm_setting_wireless_get_bssid (s_wireless);
|
||||
if (bssid) {
|
||||
tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
bssid->data[0], bssid->data[1], bssid->data[2],
|
||||
bssid->data[3], bssid->data[4], bssid->data[5]);
|
||||
svSetValue (ifcfg, "BSSID", tmp, FALSE);
|
||||
g_free (tmp);
|
||||
svSetValue_free (ifcfg, "BSSID",
|
||||
nm_utils_hwaddr_ntoa_len (bssid->data, bssid->len), FALSE);
|
||||
}
|
||||
|
||||
/* Ensure DEFAULTKEY and SECURITYMODE are cleared unless there's security;
|
||||
|
|
@ -1068,21 +1067,15 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||
svSetValue (ifcfg, "HWADDR", NULL, FALSE);
|
||||
device_mac = nm_setting_wired_get_mac_address (s_wired);
|
||||
if (device_mac) {
|
||||
tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
device_mac->data[0], device_mac->data[1], device_mac->data[2],
|
||||
device_mac->data[3], device_mac->data[4], device_mac->data[5]);
|
||||
svSetValue (ifcfg, "HWADDR", tmp, FALSE);
|
||||
g_free (tmp);
|
||||
svSetValue_free (ifcfg, "HWADDR",
|
||||
nm_utils_hwaddr_ntoa_len (device_mac->data, device_mac->len), FALSE);
|
||||
}
|
||||
|
||||
svSetValue (ifcfg, "MACADDR", NULL, FALSE);
|
||||
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
|
||||
if (cloned_mac) {
|
||||
tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
cloned_mac->data[0], cloned_mac->data[1], cloned_mac->data[2],
|
||||
cloned_mac->data[3], cloned_mac->data[4], cloned_mac->data[5]);
|
||||
svSetValue (ifcfg, "MACADDR", tmp, FALSE);
|
||||
g_free (tmp);
|
||||
svSetValue_free (ifcfg, "MACADDR",
|
||||
nm_utils_hwaddr_ntoa_len (cloned_mac->data, cloned_mac->len), FALSE);
|
||||
}
|
||||
|
||||
svSetValue (ifcfg, "HWADDR_BLACKLIST", NULL, FALSE);
|
||||
|
|
|
|||
|
|
@ -2292,10 +2292,7 @@ write_wireless_setting (NMConnection *connection,
|
|||
ifnet_set_data (ssid_str, "mac", NULL);
|
||||
mac = nm_setting_wireless_get_mac_address (s_wireless);
|
||||
if (mac) {
|
||||
tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
mac->data[0], mac->data[1], mac->data[2],
|
||||
mac->data[3], mac->data[4],
|
||||
mac->data[5]);
|
||||
tmp = nm_utils_hwaddr_ntoa_len (mac->data, mac->len);
|
||||
ifnet_set_data (ssid_str, "mac", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
|
@ -2324,10 +2321,7 @@ write_wireless_setting (NMConnection *connection,
|
|||
wpa_set_data (ssid_str, "bssid", NULL);
|
||||
bssid = nm_setting_wireless_get_bssid (s_wireless);
|
||||
if (bssid) {
|
||||
tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
bssid->data[0], bssid->data[1],
|
||||
bssid->data[2], bssid->data[3],
|
||||
bssid->data[4], bssid->data[5]);
|
||||
tmp = nm_utils_hwaddr_ntoa_len (bssid->data, bssid->len);
|
||||
wpa_set_data (ssid_str, "bssid", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
|
@ -2366,10 +2360,7 @@ write_wired_setting (NMConnection *connection,
|
|||
ifnet_set_data (conn_name, "mac", NULL);
|
||||
mac = nm_setting_wired_get_mac_address (s_wired);
|
||||
if (mac) {
|
||||
tmp = g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
|
||||
mac->data[0], mac->data[1], mac->data[2],
|
||||
mac->data[3], mac->data[4],
|
||||
mac->data[5]);
|
||||
tmp = nm_utils_hwaddr_ntoa_len (mac->data, mac->len);
|
||||
ifnet_set_data (conn_name, "mac", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue