From 8d9365a973025976a15e5e7adb26a6f791957b7c Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Thu, 7 Mar 2019 21:20:28 +0100 Subject: [PATCH 1/2] core,wifi-p2p: Fix Wi-Fi P2P device type The device type was set to the GType rather than a new value in the NMDeviceType enum. Add the corresponding enum entry, fix the device type and set the routing priority to the same value as generic devices. --- libnm-core/nm-dbus-interface.h | 2 ++ libnm/nm-device.c | 3 +++ src/devices/nm-device.c | 1 + src/devices/wifi/nm-device-wifi-p2p.c | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libnm-core/nm-dbus-interface.h b/libnm-core/nm-dbus-interface.h index 4a9442d051..038d2c9ee0 100644 --- a/libnm-core/nm-dbus-interface.h +++ b/libnm-core/nm-dbus-interface.h @@ -222,6 +222,7 @@ typedef enum { * @NM_DEVICE_TYPE_WPAN: a IEEE 802.15.4 (WPAN) MAC Layer Device * @NM_DEVICE_TYPE_6LOWPAN: 6LoWPAN interface * @NM_DEVICE_TYPE_WIREGUARD: a WireGuard interface + * @NM_DEVICE_TYPE_WIFI_P2P: an 802.11 Wi-Fi P2P device (Since: 1.16) * * #NMDeviceType values indicate the type of hardware represented by a * device object. @@ -257,6 +258,7 @@ typedef enum { NM_DEVICE_TYPE_WPAN = 27, NM_DEVICE_TYPE_6LOWPAN = 28, NM_DEVICE_TYPE_WIREGUARD = 29, + NM_DEVICE_TYPE_WIFI_P2P = 30, } NMDeviceType; /** diff --git a/libnm/nm-device.c b/libnm/nm-device.c index 65bffe7565..db73797dd2 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -294,6 +294,7 @@ coerce_type (NMDeviceType type) case NM_DEVICE_TYPE_WPAN: case NM_DEVICE_TYPE_6LOWPAN: case NM_DEVICE_TYPE_WIREGUARD: + case NM_DEVICE_TYPE_WIFI_P2P: return type; } return NM_DEVICE_TYPE_UNKNOWN; @@ -1427,6 +1428,8 @@ get_type_name (NMDevice *device) return _("6LoWPAN"); case NM_DEVICE_TYPE_WIREGUARD: return _("WireGuard"); + case NM_DEVICE_TYPE_WIFI_P2P: + return _("Wi-Fi P2P"); case NM_DEVICE_TYPE_GENERIC: case NM_DEVICE_TYPE_UNUSED1: case NM_DEVICE_TYPE_UNUSED2: diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index d5f7847f92..6cabee270b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -2114,6 +2114,7 @@ nm_device_get_route_metric_default (NMDeviceType device_type) return 800; case NM_DEVICE_TYPE_WPAN: return 850; + case NM_DEVICE_TYPE_WIFI_P2P: case NM_DEVICE_TYPE_GENERIC: return 950; case NM_DEVICE_TYPE_UNKNOWN: diff --git a/src/devices/wifi/nm-device-wifi-p2p.c b/src/devices/wifi/nm-device-wifi-p2p.c index 62e23ee931..8381ebc769 100644 --- a/src/devices/wifi/nm-device-wifi-p2p.c +++ b/src/devices/wifi/nm-device-wifi-p2p.c @@ -1241,7 +1241,7 @@ nm_device_wifi_p2p_new (const char *iface) return g_object_new (NM_TYPE_DEVICE_WIFI_P2P, NM_DEVICE_IFACE, iface, NM_DEVICE_TYPE_DESC, "802.11 Wi-Fi P2P", - NM_DEVICE_DEVICE_TYPE, NM_TYPE_DEVICE_WIFI_P2P, + NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_WIFI_P2P, NM_DEVICE_LINK_TYPE, NM_LINK_TYPE_WIFI, NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WLAN, NULL); From a6a185ba00c6218d9b1ace6e3bd6b57347198246 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Thu, 7 Mar 2019 21:31:47 +0100 Subject: [PATCH 2/2] libnm: Fix reporting of unknown device types nm_device_get_device_type would report the device type as it was send on DBus, while fetching the property would mean that only a known device types is reported. Make both results consistent by coercing in nm_device_get_device_type rather than when setting the property. --- libnm/nm-device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnm/nm-device.c b/libnm/nm-device.c index db73797dd2..5965cb3b8f 100644 --- a/libnm/nm-device.c +++ b/libnm/nm-device.c @@ -356,7 +356,7 @@ get_property (GObject *object, switch (prop_id) { case PROP_DEVICE_TYPE: - g_value_set_enum (value, coerce_type (nm_device_get_device_type (device))); + g_value_set_enum (value, nm_device_get_device_type (device)); break; case PROP_UDI: g_value_set_string (value, nm_device_get_udi (device)); @@ -937,7 +937,7 @@ nm_device_get_device_type (NMDevice *self) { g_return_val_if_fail (NM_IS_DEVICE (self), NM_DEVICE_TYPE_UNKNOWN); - return NM_DEVICE_GET_PRIVATE (self)->device_type; + return coerce_type (NM_DEVICE_GET_PRIVATE (self)->device_type); } /**