2005-12-31 Dan Williams <dcbw@redhat.com>

* refactor NMDevice into a GObject-based framework with separate
		objects for wired and wireless.  The following files are no
		longer used but should stick around for a bit so we don't
		loose code through the cracks:
			NetworkManagerDevice.c
			NetworkManagerDevice.h
			NetworkManagerWireless.c
			NetworkManagerWireless.h

	The intent here is to allow each device type to manage its own
	connection & activation life-cycle, ie to allow wireless devices
	to interface with wpa_supplicant, etc.  There's a fair bit of
	encapsulation breakage right now that should gradually get pulled
	back into each device, along with things like periodic property
	updates and link probing.


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1244 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2005-12-31 08:21:24 +00:00
parent d717e1ad88
commit 4ed4b491fa
50 changed files with 5874 additions and 181 deletions

View File

@@ -1,3 +1,21 @@
2005-12-31 Dan Williams <dcbw@redhat.com>
* refactor NMDevice into a GObject-based framework with separate
objects for wired and wireless. The following files are no
longer used but should stick around for a bit so we don't
loose code through the cracks:
NetworkManagerDevice.c
NetworkManagerDevice.h
NetworkManagerWireless.c
NetworkManagerWireless.h
The intent here is to allow each device type to manage its own
connection & activation life-cycle, ie to allow wireless devices
to interface with wpa_supplicant, etc. There's a fair bit of
encapsulation breakage right now that should gradually get pulled
back into each device, along with things like periodic property
updates and link probing.
2005-12-29 Dan Williams <dcbw@redhat.com> 2005-12-29 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h * include/NetworkManager.h

View File

@@ -11,6 +11,13 @@ INCLUDES = -I${top_srcdir} \
bin_PROGRAMS = NetworkManager bin_PROGRAMS = NetworkManager
NetworkManager_SOURCES = \ NetworkManager_SOURCES = \
nm-device.c \
nm-device.h \
nm-device-private.h \
nm-device-802-3-ethernet.c \
nm-device-802-3-ethernet.h \
nm-device-802-11-wireless.c \
nm-device-802-11-wireless.h \
NetworkManagerAP.c \ NetworkManagerAP.c \
NetworkManagerAP.h \ NetworkManagerAP.h \
NetworkManagerAPList.c \ NetworkManagerAPList.c \
@@ -28,9 +35,6 @@ NetworkManager_SOURCES = \
nm-dbus-net.h \ nm-dbus-net.h \
nm-dbus-nmi.c \ nm-dbus-nmi.c \
nm-dbus-nmi.h \ nm-dbus-nmi.h \
NetworkManagerDevice.c \
NetworkManagerDevice.h \
NetworkManagerDevicePrivate.h \
nm-ip4-config.c \ nm-ip4-config.c \
nm-ip4-config.h \ nm-ip4-config.h \
NetworkManager.c \ NetworkManager.c \
@@ -39,8 +43,6 @@ NetworkManager_SOURCES = \
NetworkManagerPolicy.h \ NetworkManagerPolicy.h \
NetworkManagerUtils.c \ NetworkManagerUtils.c \
NetworkManagerUtils.h \ NetworkManagerUtils.h \
NetworkManagerWireless.c \
NetworkManagerWireless.h \
NetworkManagerSystem.c \ NetworkManagerSystem.c \
NetworkManagerSystem.h \ NetworkManagerSystem.h \
nm-netlink-monitor.c \ nm-netlink-monitor.c \

View File

@@ -36,9 +36,10 @@
#include "NetworkManager.h" #include "NetworkManager.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "NetworkManagerPolicy.h" #include "NetworkManagerPolicy.h"
#include "NetworkManagerWireless.h"
#include "NetworkManagerDbus.h" #include "NetworkManagerDbus.h"
#include "NetworkManagerAP.h" #include "NetworkManagerAP.h"
#include "NetworkManagerAPList.h" #include "NetworkManagerAPList.h"
@@ -143,7 +144,7 @@ NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi, cons
{ {
/* If we couldn't add the device to our list, free its data. */ /* If we couldn't add the device to our list, free its data. */
nm_warning ("could not acquire device list mutex." ); nm_warning ("could not acquire device list mutex." );
nm_device_unref (dev); g_object_unref (G_OBJECT (dev));
dev = NULL; dev = NULL;
} }
} else nm_warning ("could not allocate device data." ); } else nm_warning ("could not allocate device data." );
@@ -168,7 +169,7 @@ void nm_remove_device (NMData *data, NMDevice *dev)
nm_device_worker_thread_stop (dev); nm_device_worker_thread_stop (dev);
nm_dbus_schedule_device_status_change_signal (data, dev, NULL, DEVICE_REMOVED); nm_dbus_schedule_device_status_change_signal (data, dev, NULL, DEVICE_REMOVED);
nm_device_unref (dev); g_object_unref (G_OBJECT (dev));
/* Remove the device entry from the device list and free its data */ /* Remove the device entry from the device list and free its data */
data->dev_list = g_slist_remove (data->dev_list, dev); data->dev_list = g_slist_remove (data->dev_list, dev);
@@ -442,7 +443,7 @@ static void device_stop_and_free (NMDevice *dev, gpointer user_data)
nm_device_set_removed (dev, TRUE); nm_device_set_removed (dev, TRUE);
nm_device_deactivate (dev); nm_device_deactivate (dev);
nm_device_unref (dev); g_object_unref (G_OBJECT (dev));
} }
@@ -555,7 +556,7 @@ static gboolean nm_poll_and_update_wireless_link_state (NMData *data)
{ {
if ((dev = (NMDevice *)(elt->data))) if ((dev = (NMDevice *)(elt->data)))
{ {
nm_device_ref (dev); g_object_ref (G_OBJECT (dev));
copy = g_slist_append (copy, dev); copy = g_slist_append (copy, dev);
} }
} }
@@ -568,10 +569,11 @@ static gboolean nm_poll_and_update_wireless_link_state (NMData *data)
{ {
if (nm_device_is_802_11_wireless (dev) && !nm_device_is_activating (dev)) if (nm_device_is_802_11_wireless (dev) && !nm_device_is_activating (dev))
{ {
nm_device_set_link_active (dev, nm_device_probe_link_state (dev)); NMDevice80211Wireless *wdev = NM_DEVICE_802_11_WIRELESS (dev);
nm_device_update_signal_strength (dev); nm_device_set_active_link (dev, nm_device_probe_link_state (dev));
nm_device_802_11_wireless_update_signal_strength (wdev);
} }
nm_device_unref (dev); g_object_unref (G_OBJECT (dev));
} }
} }
@@ -598,7 +600,7 @@ static void nm_device_link_activated (NmNetlinkMonitor *monitor, const gchar *in
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__)) if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{ {
if ((dev = nm_get_device_by_iface (data, interface_name))) if ((dev = nm_get_device_by_iface (data, interface_name)))
nm_device_ref (dev); g_object_ref (G_OBJECT (dev));
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__); nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
} }
@@ -607,10 +609,10 @@ static void nm_device_link_activated (NmNetlinkMonitor *monitor, const gchar *in
{ {
if (nm_device_is_802_3_ethernet (dev) && !nm_device_has_active_link (dev)) if (nm_device_is_802_3_ethernet (dev) && !nm_device_has_active_link (dev))
{ {
nm_device_set_link_active (dev, TRUE); nm_device_set_active_link (dev, TRUE);
nm_policy_schedule_device_change_check (data); nm_policy_schedule_device_change_check (data);
} }
nm_device_unref (dev); g_object_unref (G_OBJECT (dev));
} }
} }
@@ -621,15 +623,15 @@ static void nm_device_link_deactivated (NmNetlinkMonitor *monitor, const gchar *
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__)) if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{ {
if ((dev = nm_get_device_by_iface (data, interface_name))) if ((dev = nm_get_device_by_iface (data, interface_name)))
nm_device_ref (dev); g_object_ref (G_OBJECT (dev));
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__); nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
} }
if (dev) if (dev)
{ {
if (nm_device_is_802_3_ethernet (dev)) if (nm_device_is_802_3_ethernet (dev))
nm_device_set_link_active (dev, FALSE); nm_device_set_active_link (dev, FALSE);
nm_device_unref (dev); g_object_unref (G_OBJECT (dev));
} }
} }

View File

@@ -22,7 +22,6 @@
#include "NetworkManagerAP.h" #include "NetworkManagerAP.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "NetworkManagerWireless.h"
#include "nm-ap-security.h" #include "nm-ap-security.h"
#include <wireless.h> #include <wireless.h>
@@ -85,6 +84,7 @@ NMAccessPoint * nm_ap_new (void)
ap->mode = IW_MODE_INFRA; ap->mode = IW_MODE_INFRA;
ap->refcount = 1; ap->refcount = 1;
ap->capabilities = NM_802_11_CAP_PROTO_NONE;
return ap; return ap;
} }
@@ -203,12 +203,20 @@ void nm_ap_set_essid (NMAccessPoint *ap, const char * essid)
guint32 nm_ap_get_capabilities (NMAccessPoint *ap) guint32 nm_ap_get_capabilities (NMAccessPoint *ap)
{ {
g_return_val_if_fail (ap != NULL, -1); g_return_val_if_fail (ap != NULL, NM_802_11_CAP_NONE);
return ap->capabilities; return ap->capabilities;
} }
void nm_ap_set_capabilities (NMAccessPoint *ap, guint32 capabilities)
{
g_return_if_fail (ap != NULL);
ap->capabilities = capabilities;
}
/* /*
* Get/set functions for encrypted flag * Get/set functions for encrypted flag
* *
@@ -222,16 +230,6 @@ gboolean nm_ap_get_encrypted (const NMAccessPoint *ap)
|| (ap->capabilities & NM_802_11_CAP_PROTO_WPA2)); || (ap->capabilities & NM_802_11_CAP_PROTO_WPA2));
} }
void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean privacy)
{
#define ALL_WEP (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP104 | NM_802_11_CAP_CIPHER_WEP40)
g_return_if_fail (ap != NULL);
if (privacy)
ap->capabilities |= ALL_WEP;
else
ap->capabilities &= ~ALL_WEP;
}
/* /*
* Accessorts for AP security info * Accessorts for AP security info
@@ -544,41 +542,72 @@ gboolean nm_ap_has_manufacturer_default_essid (NMAccessPoint *ap)
} }
static void set_capabilities_from_cipher (NMAccessPoint *ap, int cipher) static guint32 add_capabilities_from_cipher (guint32 caps, int cipher)
{ {
if (cipher & IW_AUTH_CIPHER_WEP40) if (cipher & IW_AUTH_CIPHER_WEP40)
ap->capabilities |= NM_802_11_CAP_CIPHER_WEP40; {
caps |= (NM_802_11_CAP_PROTO_WEP & NM_802_11_CAP_CIPHER_WEP40);
caps &= ~NM_802_11_CAP_PROTO_NONE;
}
if (cipher & IW_AUTH_CIPHER_WEP104) if (cipher & IW_AUTH_CIPHER_WEP104)
ap->capabilities |= NM_802_11_CAP_CIPHER_WEP104; {
caps |= (NM_802_11_CAP_PROTO_WEP & NM_802_11_CAP_CIPHER_WEP104);
caps &= ~NM_802_11_CAP_PROTO_NONE;
}
if (cipher & IW_AUTH_CIPHER_TKIP) if (cipher & IW_AUTH_CIPHER_TKIP)
ap->capabilities |= NM_802_11_CAP_CIPHER_TKIP; {
caps |= NM_802_11_CAP_CIPHER_TKIP;
caps &= ~NM_802_11_CAP_PROTO_NONE;
}
if (cipher & IW_AUTH_CIPHER_CCMP) if (cipher & IW_AUTH_CIPHER_CCMP)
ap->capabilities |= NM_802_11_CAP_CIPHER_CCMP; {
caps |= NM_802_11_CAP_CIPHER_CCMP;
caps &= ~NM_802_11_CAP_PROTO_NONE;
}
return caps;
} }
void nm_ap_set_capabilities_from_wpa_ie (NMAccessPoint *ap, const guint8 *wpa_ie, guint32 length) void nm_ap_add_capabilities_from_ie (NMAccessPoint *ap, const guint8 *wpa_ie, guint32 length)
{ {
wpa_ie_data * cap_data; wpa_ie_data * cap_data;
guint32 caps;
g_return_if_fail (ap != NULL); g_return_if_fail (ap != NULL);
if (!(cap_data = wpa_parse_wpa_ie (wpa_ie, length))) if (!(cap_data = wpa_parse_wpa_ie (wpa_ie, length)))
return; return;
ap->capabilities = NM_802_11_CAP_NONE; caps = nm_ap_get_capabilities (ap);
if (cap_data->proto & IW_AUTH_WPA_VERSION_WPA) if (cap_data->proto & IW_AUTH_WPA_VERSION_WPA)
ap->capabilities |= NM_802_11_CAP_PROTO_WPA; {
caps |= NM_802_11_CAP_PROTO_WPA;
caps &= ~NM_802_11_CAP_PROTO_NONE;
}
if (cap_data->proto & IW_AUTH_WPA_VERSION_WPA2) if (cap_data->proto & IW_AUTH_WPA_VERSION_WPA2)
ap->capabilities |= NM_802_11_CAP_PROTO_WPA2; {
caps |= NM_802_11_CAP_PROTO_WPA2;
caps &= ~NM_802_11_CAP_PROTO_NONE;
}
set_capabilities_from_cipher (ap, cap_data->pairwise_cipher); caps = add_capabilities_from_cipher (caps, cap_data->pairwise_cipher);
set_capabilities_from_cipher (ap, cap_data->group_cipher); caps = add_capabilities_from_cipher (caps, cap_data->group_cipher);
if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_802_1X) if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_802_1X)
ap->capabilities |= NM_802_11_CAP_KEY_MGMT_802_1X; caps |= NM_802_11_CAP_KEY_MGMT_802_1X;
if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_PSK) if (cap_data->key_mgmt & IW_AUTH_KEY_MGMT_PSK)
ap->capabilities |= NM_802_11_CAP_KEY_MGMT_PSK; caps |= NM_802_11_CAP_KEY_MGMT_PSK;
nm_ap_set_capabilities (ap, caps);
} }
void nm_ap_add_capabilities_for_wep (NMAccessPoint *ap)
{
guint32 caps;
g_return_if_fail (ap != NULL);
ap->capabilities |= (NM_802_11_CAP_PROTO_WEP | NM_802_11_CAP_CIPHER_WEP40 | NM_802_11_CAP_CIPHER_WEP104);
ap->capabilities &= ~NM_802_11_CAP_PROTO_NONE;
}

View File

@@ -44,9 +44,9 @@ char * nm_ap_get_essid (const NMAccessPoint *ap);
void nm_ap_set_essid (NMAccessPoint *ap, const char *essid); void nm_ap_set_essid (NMAccessPoint *ap, const char *essid);
guint32 nm_ap_get_capabilities (NMAccessPoint *ap); guint32 nm_ap_get_capabilities (NMAccessPoint *ap);
void nm_ap_set_capabilities (NMAccessPoint *ap, guint32 capabilities);
gboolean nm_ap_get_encrypted (const NMAccessPoint *ap); gboolean nm_ap_get_encrypted (const NMAccessPoint *ap);
void nm_ap_set_encrypted (NMAccessPoint *ap, gboolean privacy);
NMAPSecurity * nm_ap_get_security (const NMAccessPoint *ap); NMAPSecurity * nm_ap_get_security (const NMAccessPoint *ap);
void nm_ap_set_security (NMAccessPoint *ap, NMAPSecurity *security); void nm_ap_set_security (NMAccessPoint *ap, NMAPSecurity *security);
@@ -87,7 +87,8 @@ void nm_ap_set_user_created (NMAccessPoint *ap, gboolean user_created);
GSList * nm_ap_get_user_addresses (const NMAccessPoint *ap); GSList * nm_ap_get_user_addresses (const NMAccessPoint *ap);
void nm_ap_set_user_addresses (NMAccessPoint *ap, GSList *list); void nm_ap_set_user_addresses (NMAccessPoint *ap, GSList *list);
void nm_ap_set_capabilities_from_wpa_ie (NMAccessPoint *ap, const guint8 *wpa_ie, guint32 length); void nm_ap_add_capabilities_from_ie (NMAccessPoint *ap, const guint8 *wpa_ie, guint32 length);
void nm_ap_add_capabilities_for_wep (NMAccessPoint *ap);
/* /*
* NOTE: * NOTE:

View File

@@ -457,8 +457,8 @@ gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *me
const GTimeVal *merge_ap_seen = nm_ap_get_last_seen (merge_ap); const GTimeVal *merge_ap_seen = nm_ap_get_last_seen (merge_ap);
nm_ap_set_encrypted (list_ap_addr, nm_ap_get_encrypted (merge_ap)); nm_ap_set_capabilities (list_ap_addr, nm_ap_get_capabilities (merge_ap));
if (nm_ap_get_strength (merge_ap) != nm_ap_get_strength (list_ap_addr)) if (nm_ap_get_strength (merge_ap) != nm_ap_get_strength (list_ap_addr))
{ {
nm_ap_set_strength (list_ap_addr, nm_ap_get_strength (merge_ap)); nm_ap_set_strength (list_ap_addr, nm_ap_get_strength (merge_ap));
*strength_changed = TRUE; *strength_changed = TRUE;
@@ -480,7 +480,7 @@ gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *me
const GTimeVal *merge_ap_seen = nm_ap_get_last_seen (merge_ap); const GTimeVal *merge_ap_seen = nm_ap_get_last_seen (merge_ap);
const GTimeVal *list_ap_essid_seen = nm_ap_get_last_seen (list_ap_essid); const GTimeVal *list_ap_essid_seen = nm_ap_get_last_seen (list_ap_essid);
nm_ap_set_encrypted (list_ap_essid, nm_ap_get_encrypted (merge_ap)); nm_ap_set_capabilities (list_ap_essid, nm_ap_get_capabilities (merge_ap));
if (!((list_ap_essid_seen->tv_sec == merge_ap_seen->tv_sec) if (!((list_ap_essid_seen->tv_sec == merge_ap_seen->tv_sec)
&& (nm_ap_get_strength (list_ap_essid) >= nm_ap_get_strength (merge_ap)))) && (nm_ap_get_strength (list_ap_essid) >= nm_ap_get_strength (merge_ap))))
@@ -600,7 +600,7 @@ void nm_ap_list_copy_essids_by_address (NMAccessPointList *dest, NMAccessPointLi
* may result in undesired behavior. * may result in undesired behavior.
* *
*/ */
void nm_ap_list_diff (NMData *data, NMDevice *dev, NMAccessPointList *old, NMAccessPointList *new) void nm_ap_list_diff (NMData *data, NMDevice80211Wireless *dev, NMAccessPointList *old, NMAccessPointList *new)
{ {
NMAPListIter *iter; NMAPListIter *iter;
NMAccessPoint *old_ap; NMAccessPoint *old_ap;

View File

@@ -24,8 +24,10 @@
#include <glib.h> #include <glib.h>
#include "NetworkManager.h" #include "NetworkManager.h"
#include "NetworkManagerDevice.h" #include "NetworkManagerMain.h"
#include "NetworkManagerAP.h"
#include "nm-device.h"
#include "nm-device-802-11-wireless.h"
typedef struct NMAccessPointList NMAccessPointList; typedef struct NMAccessPointList NMAccessPointList;
typedef struct NMAPListIter NMAPListIter; typedef struct NMAPListIter NMAPListIter;
@@ -49,7 +51,7 @@ void nm_ap_list_copy_properties (NMAccessPointList *dest, NMAccessPointList
void nm_ap_list_copy_essids_by_address (NMAccessPointList *dest, NMAccessPointList *source); void nm_ap_list_copy_essids_by_address (NMAccessPointList *dest, NMAccessPointList *source);
void nm_ap_list_copy_one_essid_by_address (NMAccessPoint *ap, NMAccessPointList *search_list); void nm_ap_list_copy_one_essid_by_address (NMAccessPoint *ap, NMAccessPointList *search_list);
void nm_ap_list_diff (NMData *data, NMDevice *dev, NMAccessPointList *old, NMAccessPointList *new); void nm_ap_list_diff (NMData *data, NMDevice80211Wireless *dev, NMAccessPointList *old, NMAccessPointList *new);
gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *merge_ap, gboolean *new, gboolean *strength_changed); gboolean nm_ap_list_merge_scanned_ap (NMAccessPointList *list, NMAccessPoint *merge_ap, gboolean *new, gboolean *strength_changed);
NMNetworkType nm_ap_list_get_type (NMAccessPointList *list); NMNetworkType nm_ap_list_get_type (NMAccessPointList *list);

View File

@@ -30,13 +30,12 @@
#include "NetworkManager.h" #include "NetworkManager.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "NetworkManagerDbus.h" #include "NetworkManagerDbus.h"
#include "NetworkManagerDbusUtils.h" #include "NetworkManagerDbusUtils.h"
#include "NetworkManagerAP.h" #include "NetworkManagerAP.h"
#include "NetworkManagerAPList.h" #include "NetworkManagerAPList.h"
#include "NetworkManagerPolicy.h" #include "NetworkManagerPolicy.h"
#include "NetworkManagerWireless.h"
#include "nm-dbus-nm.h" #include "nm-dbus-nm.h"
#include "nm-dbus-device.h" #include "nm-dbus-device.h"
#include "nm-dbus-net.h" #include "nm-dbus-net.h"
@@ -251,7 +250,7 @@ static gboolean nm_dbus_signal_device_status_change (gpointer user_data)
dbus_message_unref (message); dbus_message_unref (message);
nm_device_unref (cb_data->dev); g_object_unref (G_OBJECT (cb_data->dev));
g_free (cb_data); g_free (cb_data);
return FALSE; return FALSE;
@@ -267,7 +266,7 @@ void nm_dbus_schedule_device_status_change_signal (NMData *data, NMDevice *dev,
g_return_if_fail (dev != NULL); g_return_if_fail (dev != NULL);
cb_data = g_malloc0 (sizeof (NMStatusChangeData)); cb_data = g_malloc0 (sizeof (NMStatusChangeData));
nm_device_ref (dev); g_object_ref (G_OBJECT (dev));
cb_data->data = data; cb_data->data = data;
cb_data->dev = dev; cb_data->dev = dev;
if (ap) if (ap)
@@ -351,7 +350,7 @@ void nm_dbus_signal_state_change (DBusConnection *connection, NMData *data)
* Notifies the bus that a new wireless network has come into range * Notifies the bus that a new wireless network has come into range
* *
*/ */
void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, NMNetworkStatus status, gint strength) void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice80211Wireless *dev, NMAccessPoint *ap, NMNetworkStatus status, gint strength)
{ {
DBusMessage * message; DBusMessage * message;
char * dev_path = NULL; char * dev_path = NULL;
@@ -362,10 +361,10 @@ void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevic
g_return_if_fail (dev != NULL); g_return_if_fail (dev != NULL);
g_return_if_fail (ap != NULL); g_return_if_fail (ap != NULL);
if (!(dev_path = nm_dbus_get_object_path_for_device (dev))) if (!(dev_path = nm_dbus_get_object_path_for_device (NM_DEVICE (dev))))
goto out; goto out;
if (!(net_path = nm_dbus_get_object_path_for_network (dev, ap))) if (!(net_path = nm_dbus_get_object_path_for_network (NM_DEVICE (dev), ap)))
goto out; goto out;
switch (status) switch (status)
@@ -410,7 +409,7 @@ out:
} }
void nm_dbus_signal_device_strength_change (DBusConnection *connection, NMDevice *dev, gint strength) void nm_dbus_signal_device_strength_change (DBusConnection *connection, NMDevice80211Wireless *dev, gint strength)
{ {
DBusMessage * message; DBusMessage * message;
char * dev_path = NULL; char * dev_path = NULL;
@@ -418,7 +417,7 @@ void nm_dbus_signal_device_strength_change (DBusConnection *connection, NMDevice
g_return_if_fail (connection != NULL); g_return_if_fail (connection != NULL);
g_return_if_fail (dev != NULL); g_return_if_fail (dev != NULL);
if (!(dev_path = nm_dbus_get_object_path_for_device (dev))) if (!(dev_path = nm_dbus_get_object_path_for_device (NM_DEVICE (dev))))
goto out; goto out;
if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, "DeviceStrengthChanged"))) if (!(message = dbus_message_new_signal (NM_DBUS_PATH, NM_DBUS_INTERFACE, "DeviceStrengthChanged")))
@@ -494,7 +493,7 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus
} }
else if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "UserInterfaceActivated")) else if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "UserInterfaceActivated"))
{ {
nm_wireless_set_scan_interval (data, NULL, NM_WIRELESS_SCAN_INTERVAL_ACTIVE); nm_device_802_11_wireless_set_scan_interval (data, NULL, NM_WIRELESS_SCAN_INTERVAL_ACTIVE);
handled = TRUE; handled = TRUE;
} }
} }

View File

@@ -26,6 +26,9 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#include "NetworkManager.h" #include "NetworkManager.h"
#include "NetworkManagerMain.h"
#include "nm-device.h"
#include "nm-device-802-11-wireless.h"
#include "NetworkManagerAPList.h" #include "NetworkManagerAPList.h"
@@ -51,7 +54,6 @@ static inline gboolean message_is_error (DBusMessage *msg)
return (dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_ERROR); return (dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_ERROR);
} }
DBusConnection *nm_dbus_init (NMData *data); DBusConnection *nm_dbus_init (NMData *data);
gboolean nm_dbus_is_info_daemon_running (DBusConnection *connection); gboolean nm_dbus_is_info_daemon_running (DBusConnection *connection);
@@ -64,8 +66,8 @@ void nm_dbus_schedule_device_status_change_signal (NMData *data, NMDevice *dev
void nm_dbus_signal_state_change (DBusConnection *connection, NMData *data); void nm_dbus_signal_state_change (DBusConnection *connection, NMData *data);
void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice *dev, NMAccessPoint *ap, NMNetworkStatus status, gint strength); void nm_dbus_signal_wireless_network_change (DBusConnection *connection, NMDevice80211Wireless *dev, NMAccessPoint *ap, NMNetworkStatus status, gint strength);
void nm_dbus_signal_device_strength_change (DBusConnection *connection, NMDevice *dev, gint strength); void nm_dbus_signal_device_strength_change (DBusConnection *connection, NMDevice80211Wireless *dev, gint strength);
NMDevice * nm_dbus_get_device_from_object_path (NMData *data, const char *path); NMDevice * nm_dbus_get_device_from_object_path (NMData *data, const char *path);

View File

@@ -27,7 +27,8 @@
#include <dbus/dbus-glib-lowlevel.h> #include <dbus/dbus-glib-lowlevel.h>
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib.h>
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "NetworkManagerMain.h"
typedef struct NMDbusCBData typedef struct NMDbusCBData
{ {

View File

@@ -857,6 +857,20 @@ guint32 nm_device_get_capabilities (NMDevice *dev)
} }
/*
* Accessor for type-specific device capabilities
*/
guint32 nm_device_get_type_capabilities (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, NM_DEVICE_CAP_NONE);
if (dev->type == DEVICE_TYPE_802_11_WIRELESS)
return dev->options.wireless.capabilities;
return NM_DEVICE_CAP_NONE;
}
/* /*
* Get/set functions for link_active * Get/set functions for link_active
*/ */
@@ -3700,7 +3714,7 @@ static void nm_device_fake_ap_list (NMDevice *dev)
{{0x12, 0x34, 0x56, 0x78, 0x90, 0xab}}, {{0x12, 0x34, 0x56, 0x78, 0x90, 0xab}},
{{0xcd, 0xef, 0x12, 0x34, 0x56, 0x78}}, {{0xcd, 0xef, 0x12, 0x34, 0x56, 0x78}},
{{0x90, 0xab, 0xcd, 0xef, 0x12, 0x34}} }; {{0x90, 0xab, 0xcd, 0xef, 0x12, 0x34}} };
guint8 fake_qualities[NUM_FAKE_APS] = { 150, 26, 200, 100 }; guint8 fake_qualities[NUM_FAKE_APS] = { 45, 26, 12, 93 };
double fake_freqs[NUM_FAKE_APS] = { 3.1416, 4.1416, 5.1415, 6.1415 }; double fake_freqs[NUM_FAKE_APS] = { 3.1416, 4.1416, 5.1415, 6.1415 };
gboolean fake_enc[NUM_FAKE_APS] = { FALSE, TRUE, FALSE, TRUE }; gboolean fake_enc[NUM_FAKE_APS] = { FALSE, TRUE, FALSE, TRUE };
@@ -3718,9 +3732,7 @@ static void nm_device_fake_ap_list (NMDevice *dev)
nm_ap_set_essid (nm_ap, fake_essids[i]); nm_ap_set_essid (nm_ap, fake_essids[i]);
if (fake_enc[i]) if (fake_enc[i])
nm_ap_set_encrypted (nm_ap, FALSE); nm_ap_add_capabilities_for_wep (nm_ap);
else
nm_ap_set_encrypted (nm_ap, TRUE);
nm_ap_set_address (nm_ap, (const struct ether_addr *)(&fake_addrs[i])); nm_ap_set_address (nm_ap, (const struct ether_addr *)(&fake_addrs[i]));
nm_ap_set_strength (nm_ap, fake_qualities[i]); nm_ap_set_strength (nm_ap, fake_qualities[i]);
@@ -4497,7 +4509,7 @@ static gboolean process_scan_results (NMDevice *dev, const guint8 *res_buf, guin
break; break;
case SIOCGIWENCODE: case SIOCGIWENCODE:
if (!(iwe->u.data.flags & IW_ENCODE_DISABLED)) if (!(iwe->u.data.flags & IW_ENCODE_DISABLED))
nm_ap_set_encrypted (ap, TRUE); nm_ap_add_capabilities_for_wep (ap);
break; break;
#if 0 #if 0
case SIOCGIWRATE: case SIOCGIWRATE:
@@ -4539,10 +4551,10 @@ static gboolean process_scan_results (NMDevice *dev, const guint8 *res_buf, guin
case WPA_GENERIC_INFO_ELEM: case WPA_GENERIC_INFO_ELEM:
if ((ielen < 2 + 4) || (memcmp (&gpos[2], "\x00\x50\xf2\x01", 4) != 0)) if ((ielen < 2 + 4) || (memcmp (&gpos[2], "\x00\x50\xf2\x01", 4) != 0))
break; break;
nm_ap_set_capabilities_from_wpa_ie (ap, (const guint8 *)gpos, ielen); nm_ap_add_capabilities_from_ie (ap, (const guint8 *)gpos, ielen);
break; break;
case WPA_RSN_INFO_ELEM: case WPA_RSN_INFO_ELEM:
nm_ap_set_capabilities_from_wpa_ie (ap, (const guint8 *)gpos, ielen); nm_ap_add_capabilities_from_ie (ap, (const guint8 *)gpos, ielen);
break; break;
} }
gpos += ielen; gpos += ielen;
@@ -4571,9 +4583,9 @@ static gboolean process_scan_results (NMDevice *dev, const guint8 *res_buf, guin
ie_buf = g_malloc0 (bytes); ie_buf = g_malloc0 (bytes);
hexstr2bin (spos, ie_buf, bytes); hexstr2bin (spos, ie_buf, bytes);
if (strncmp (custom, "wpa_ie=", 7) == 0) if (strncmp (custom, "wpa_ie=", 7) == 0)
nm_ap_set_capabilities_from_wpa_ie (ap, (const guint8 *)ie_buf, bytes); nm_ap_add_capabilities_from_ie (ap, (const guint8 *)ie_buf, bytes);
else if (strncmp (custom, "rsn_ie=", 7) == 0) else if (strncmp (custom, "rsn_ie=", 7) == 0)
nm_ap_set_capabilities_from_wpa_ie (ap, (const guint8 *)ie_buf, bytes); nm_ap_add_capabilities_from_ie (ap, (const guint8 *)ie_buf, bytes);
g_free (ie_buf); g_free (ie_buf);
} }
break; break;

View File

@@ -60,6 +60,7 @@ const char * nm_device_get_driver (NMDevice *dev);
NMDeviceType nm_device_get_type (NMDevice *dev); NMDeviceType nm_device_get_type (NMDevice *dev);
guint32 nm_device_get_capabilities (NMDevice *dev); guint32 nm_device_get_capabilities (NMDevice *dev);
guint32 nm_device_get_type_capabilities (NMDevice *dev);
gboolean nm_device_is_802_11_wireless (NMDevice *dev); gboolean nm_device_is_802_11_wireless (NMDevice *dev);
gboolean nm_device_is_802_3_ethernet (NMDevice *dev); gboolean nm_device_is_802_3_ethernet (NMDevice *dev);

View File

@@ -30,6 +30,7 @@
#include "NetworkManagerAP.h" #include "NetworkManagerAP.h"
#include "nm-netlink-monitor.h" #include "nm-netlink-monitor.h"
#include "nm-named-manager.h" #include "nm-named-manager.h"
#include "nm-device.h"
typedef enum NMIntState typedef enum NMIntState
@@ -92,14 +93,14 @@ typedef struct NMData
} NMData; } NMData;
struct NMDevice * nm_get_active_device (NMData *data); NMDevice * nm_get_active_device (NMData *data);
struct NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi, const char *iface, NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi, const char *iface,
gboolean test_device, NMDeviceType test_device_type); gboolean test_device, NMDeviceType test_device_type);
void nm_add_initial_devices (NMData *data); void nm_add_initial_devices (NMData *data);
void nm_remove_device (NMData *data, struct NMDevice *dev); void nm_remove_device (NMData *data, NMDevice *dev);
void nm_schedule_state_change_signal_broadcast (NMData *data); void nm_schedule_state_change_signal_broadcast (NMData *data);

View File

@@ -36,6 +36,8 @@
#include "nm-activation-request.h" #include "nm-activation-request.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-dbus-nmi.h" #include "nm-dbus-nmi.h"
#include "nm-device-802-11-wireless.h"
#include "nm-device-802-3-ethernet.h"
/* /*
@@ -61,6 +63,7 @@ static gboolean nm_policy_activation_finish (NMActRequest *req)
/* Tell NetworkManagerInfo to store the MAC address of the active device's AP */ /* Tell NetworkManagerInfo to store the MAC address of the active device's AP */
if (nm_device_is_802_11_wireless (dev)) if (nm_device_is_802_11_wireless (dev))
{ {
NMDevice80211Wireless * wdev = NM_DEVICE_802_11_WIRELESS (dev);
struct ether_addr addr; struct ether_addr addr;
NMAccessPoint * ap = nm_act_request_get_ap (req); NMAccessPoint * ap = nm_act_request_get_ap (req);
NMAccessPoint * tmp_ap; NMAccessPoint * tmp_ap;
@@ -69,7 +72,7 @@ static gboolean nm_policy_activation_finish (NMActRequest *req)
/* Cache details in the info-daemon since the connect was successful */ /* Cache details in the info-daemon since the connect was successful */
automatic = !nm_act_request_get_user_requested (req); automatic = !nm_act_request_get_user_requested (req);
nm_device_get_ap_address (dev, &addr); nm_device_802_11_wireless_get_bssid (wdev, &addr);
if (!nm_ap_get_address (ap) || !nm_ethernet_address_is_valid (nm_ap_get_address (ap))) if (!nm_ap_get_address (ap) || !nm_ethernet_address_is_valid (nm_ap_get_address (ap)))
nm_ap_set_address (ap, &addr); nm_ap_set_address (ap, &addr);
@@ -203,12 +206,12 @@ void nm_policy_schedule_activation_failed (NMActRequest *req)
*/ */
static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **ap) static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **ap)
{ {
GSList *elt; GSList * elt;
NMDevice *best_wired_dev = NULL; NMDevice8023Ethernet * best_wired_dev = NULL;
guint best_wired_prio = 0; guint best_wired_prio = 0;
NMDevice *best_wireless_dev = NULL; NMDevice80211Wireless * best_wireless_dev = NULL;
guint best_wireless_prio = 0; guint best_wireless_prio = 0;
NMDevice *highest_priority_dev = NULL; NMDevice * highest_priority_dev = NULL;
g_return_val_if_fail (data != NULL, NULL); g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (ap != NULL, NULL); g_return_val_if_fail (ap != NULL, NULL);
@@ -224,7 +227,7 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **
NMDevice * dev = (NMDevice *)(elt->data); NMDevice * dev = (NMDevice *)(elt->data);
guint32 caps; guint32 caps;
dev_type = nm_device_get_type (dev); dev_type = nm_device_get_device_type (dev);
link_active = nm_device_has_active_link (dev); link_active = nm_device_has_active_link (dev);
caps = nm_device_get_capabilities (dev); caps = nm_device_get_capabilities (dev);
@@ -246,7 +249,7 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **
if (prio > best_wired_prio) if (prio > best_wired_prio)
{ {
best_wired_dev = dev; best_wired_dev = NM_DEVICE_802_3_ETHERNET (dev);
best_wired_prio = prio; best_wired_prio = prio;
} }
} }
@@ -267,21 +270,22 @@ static NMDevice * nm_policy_auto_get_best_device (NMData *data, NMAccessPoint **
if (prio > best_wireless_prio) if (prio > best_wireless_prio)
{ {
best_wireless_dev = dev; best_wireless_dev = NM_DEVICE_802_11_WIRELESS (dev);
best_wireless_prio = prio; best_wireless_prio = prio;
} }
} }
} }
if (best_wired_dev) if (best_wired_dev)
highest_priority_dev = best_wired_dev; highest_priority_dev = NM_DEVICE (best_wired_dev);
else if (best_wireless_dev) else if (best_wireless_dev)
{ {
highest_priority_dev = best_wireless_dev; *ap = nm_device_802_11_wireless_get_best_ap (best_wireless_dev);
*ap = nm_device_get_best_ap (highest_priority_dev);
/* If the device doesn't have a "best" ap, then we can't use it */ /* If the device doesn't have a "best" ap, then we can't use it */
if (!*ap) if (!*ap)
highest_priority_dev = NULL; highest_priority_dev = NULL;
else
highest_priority_dev = NM_DEVICE (best_wireless_dev);
} }
#if 0 #if 0
@@ -619,19 +623,21 @@ static gboolean nm_policy_device_list_update_from_allowed_list (NMData *data)
NMDevice *dev = (NMDevice *)(elt->data); NMDevice *dev = (NMDevice *)(elt->data);
if (nm_device_is_802_11_wireless (dev)) if (nm_device_is_802_11_wireless (dev))
{ {
if (nm_device_get_supports_wireless_scan (dev)) NMDevice80211Wireless * wdev = NM_DEVICE_802_11_WIRELESS (dev);
if (nm_device_get_capabilities (dev) & NM_DEVICE_CAP_WIRELESS_SCAN)
{ {
/* Once we have the list, copy in any relevant information from our Allowed list and fill /* Once we have the list, copy in any relevant information from our Allowed list and fill
* in the ESSID of base stations that aren't broadcasting their ESSID, if we have their * in the ESSID of base stations that aren't broadcasting their ESSID, if we have their
* MAC address in our allowed list. * MAC address in our allowed list.
*/ */
nm_ap_list_copy_essids_by_address (nm_device_ap_list_get (dev), data->allowed_ap_list); nm_ap_list_copy_essids_by_address (nm_device_802_11_wireless_ap_list_get (wdev), data->allowed_ap_list);
nm_ap_list_copy_properties (nm_device_ap_list_get (dev), data->allowed_ap_list); nm_ap_list_copy_properties (nm_device_802_11_wireless_ap_list_get (wdev), data->allowed_ap_list);
} }
else else
nm_device_copy_allowed_to_dev_list (dev, data->allowed_ap_list); nm_device_802_11_wireless_copy_allowed_to_dev_list (wdev, data->allowed_ap_list);
nm_ap_list_remove_duplicate_essids (nm_device_ap_list_get (dev)); nm_ap_list_remove_duplicate_essids (nm_device_802_11_wireless_ap_list_get (wdev));
} }
} }

View File

@@ -23,7 +23,7 @@
#define NETWORK_MANAGER_POLICY_H #define NETWORK_MANAGER_POLICY_H
#include "NetworkManager.h" #include "NetworkManager.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "NetworkManagerDbus.h" #include "NetworkManagerDbus.h"
#include "nm-activation-request.h" #include "nm-activation-request.h"

View File

@@ -42,7 +42,7 @@
#include <glib.h> #include <glib.h>
#include <pthread.h> #include <pthread.h>
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-utils.h" #include "nm-utils.h"

View File

@@ -23,7 +23,9 @@
#define NETWORK_MANAGER_SYSTEM_H #define NETWORK_MANAGER_SYSTEM_H
#include <glib.h> #include <glib.h>
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-ip4-config.h"
#include "nm-named-manager.h"
/* Prototypes for system/distribution dependent functions, /* Prototypes for system/distribution dependent functions,

View File

@@ -36,6 +36,9 @@
#include "NetworkManager.h" #include "NetworkManager.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "nm-device.h"
#include "nm-device-802-11-wireless.h"
#include "nm-device-802-3-ethernet.h"
#include <netlink/addr.h> #include <netlink/addr.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -217,7 +220,7 @@ NMSock *nm_dev_sock_open (NMDevice *dev, SockType type, const char *func_name, c
sock->desc = desc ? g_strdup (desc) : NULL; sock->desc = desc ? g_strdup (desc) : NULL;
sock->dev = dev; sock->dev = dev;
if (sock->dev) if (sock->dev)
nm_device_ref (sock->dev); g_object_ref (G_OBJECT (sock->dev));
/* Add the sock to our global sock list for tracking */ /* Add the sock to our global sock list for tracking */
g_static_mutex_lock (&sock_list_mutex); g_static_mutex_lock (&sock_list_mutex);
@@ -244,7 +247,7 @@ void nm_dev_sock_close (NMSock *sock)
g_free (sock->func); g_free (sock->func);
g_free (sock->desc); g_free (sock->desc);
if (sock->dev) if (sock->dev)
nm_device_unref (sock->dev); g_object_unref (G_OBJECT (sock->dev));
memset (sock, 0, sizeof (NMSock)); memset (sock, 0, sizeof (NMSock));

View File

@@ -32,7 +32,7 @@
#include "NetworkManager.h" #include "NetworkManager.h"
#include "NetworkManagerMain.h" #include "NetworkManagerMain.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
typedef enum SockType typedef enum SockType
{ {

View File

@@ -30,7 +30,9 @@
#include <glib.h> #include <glib.h>
#include <unistd.h> #include <unistd.h>
#include "NetworkManager.h" #include "NetworkManager.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "NetworkManagerMain.h" #include "NetworkManagerMain.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-utils.h" #include "nm-utils.h"
@@ -210,7 +212,7 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
ARPMessage p; ARPMessage p;
struct ether_addr addr; struct ether_addr addr;
struct in_addr ip = {0}; struct in_addr ip = {0};
NMSock *sk; NMSock * sk = NULL;
int nprobes = 0; int nprobes = 0;
int nannounce = 0; int nannounce = 0;
gboolean success = FALSE; gboolean success = FALSE;
@@ -224,6 +226,13 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
memset (&saddr, 0, sizeof (saddr)); memset (&saddr, 0, sizeof (saddr));
strncpy (saddr.sa_data, nm_device_get_iface (dev), sizeof (saddr.sa_data)); strncpy (saddr.sa_data, nm_device_get_iface (dev), sizeof (saddr.sa_data));
if (nm_device_is_802_3_ethernet (dev))
nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &addr);
else if (nm_device_is_802_11_wireless (dev))
nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &addr);
else
goto out;
/* open an ARP socket */ /* open an ARP socket */
if ((sk = nm_dev_sock_open (dev, NETWORK_CONTROL, __FUNCTION__, NULL)) == NULL) if ((sk = nm_dev_sock_open (dev, NETWORK_CONTROL, __FUNCTION__, NULL)) == NULL)
{ {
@@ -238,8 +247,6 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
goto out; goto out;
} }
nm_device_get_hw_address (dev, &addr);
/* initialize pseudo random selection of IP addresses */ /* initialize pseudo random selection of IP addresses */
srandom ( (addr.ether_addr_octet[ETHER_ADDR_LEN-4] << 24) | srandom ( (addr.ether_addr_octet[ETHER_ADDR_LEN-4] << 24) |
(addr.ether_addr_octet[ETHER_ADDR_LEN-3] << 16) | (addr.ether_addr_octet[ETHER_ADDR_LEN-3] << 16) |
@@ -344,6 +351,7 @@ gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip)
} }
out: out:
nm_dev_sock_close (sk); if (sk)
nm_dev_sock_close (sk);
return success; return success;
} }

View File

@@ -1,3 +1,3 @@
#include "NetworkManagerDevice.h" #include "nm-device.h"
extern gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip); extern gboolean get_autoip (NMDevice *dev, struct in_addr *out_ip);

View File

@@ -29,7 +29,9 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "NetworkManagerDialup.h" #include "NetworkManagerDialup.h"
#include "interface_parser.h" #include "interface_parser.h"
#include "nm-utils.h" #include "nm-utils.h"
@@ -386,7 +388,10 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
struct ether_addr hw_addr; struct ether_addr hw_addr;
unsigned char eui[8]; unsigned char eui[8];
nm_device_get_hw_address(dev, &hw_addr); if (nm_device_is_802_3_ethernet (dev))
nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &hw_addr);
else if (nm_device_is_802_11_wireless (dev))
nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &hw_addr);
memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet)); memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet));
memmove(eui+5, eui+3, 3); memmove(eui+5, eui+3, 3);

View File

@@ -30,7 +30,9 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "shvar.h" #include "shvar.h"
@@ -264,7 +266,10 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
struct ether_addr hw_addr; struct ether_addr hw_addr;
unsigned char eui[8]; unsigned char eui[8];
nm_device_get_hw_address(dev, &hw_addr); if (nm_device_is_802_3_ethernet (dev))
nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &hw_addr);
else if (nm_device_is_802_11_wireless (dev))
nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &hw_addr);
memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet)); memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet));
memmove (eui+5, eui+3, 3); memmove (eui+5, eui+3, 3);

View File

@@ -25,7 +25,9 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "NetworkManagerDialup.h" #include "NetworkManagerDialup.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "shvar.h" #include "shvar.h"
@@ -319,7 +321,10 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
struct ether_addr hw_addr; struct ether_addr hw_addr;
unsigned char eui[8]; unsigned char eui[8];
nm_device_get_hw_address(dev, &hw_addr); if (nm_device_is_802_3_ethernet (dev))
nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &hw_addr);
else if (nm_device_is_802_11_wireless (dev))
nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &hw_addr);
memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet)); memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet));
memmove (eui+5, eui+3, 3); memmove (eui+5, eui+3, 3);

View File

@@ -25,7 +25,9 @@
#include <signal.h> #include <signal.h>
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "nm-utils.h" #include "nm-utils.h"
/* /*
@@ -230,7 +232,10 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
struct ether_addr hw_addr; struct ether_addr hw_addr;
unsigned char eui[8]; unsigned char eui[8];
nm_device_get_hw_address (dev, &hw_addr); if (nm_device_is_802_3_ethernet (dev))
nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &hw_addr);
else if (nm_device_is_802_11_wireless (dev))
nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &hw_addr);
memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet)); memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet));
memmove (eui+5, eui+3, 3); memmove (eui+5, eui+3, 3);

View File

@@ -31,7 +31,9 @@
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
#include "NetworkManagerDialup.h" #include "NetworkManagerDialup.h"
#include "nm-utils.h" #include "nm-utils.h"
#include "shvar.h" #include "shvar.h"
@@ -315,7 +317,10 @@ void nm_system_device_add_ip6_link_address (NMDevice *dev)
struct ether_addr hw_addr; struct ether_addr hw_addr;
unsigned char eui[8]; unsigned char eui[8];
nm_device_get_hw_address (dev, &hw_addr); if (nm_device_is_802_3_ethernet (dev))
nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &hw_addr);
else if (nm_device_is_802_11_wireless (dev))
nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &hw_addr);
memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet)); memcpy (eui, &(hw_addr.ether_addr_octet), sizeof (hw_addr.ether_addr_octet));
memmove (eui+5, eui+3, 3); memmove (eui+5, eui+3, 3);

View File

@@ -21,15 +21,16 @@
#include <glib.h> #include <glib.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "nm-dhcp-manager.h" #include "nm-dhcp-manager.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "NetworkManagerPolicy.h" #include "NetworkManagerPolicy.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-activation-request.h" #include "nm-activation-request.h"
#include "nm-utils.h" #include "nm-utils.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
struct NMDHCPManager struct NMDHCPManager
@@ -173,9 +174,9 @@ guint8 nm_dhcp_manager_get_state_for_device (NMDHCPManager *manager, NMDevice *d
nm_info ("Error from dhcdbd on 'reason' request because: name '%s', message '%s'.", error.name, error.message); nm_info ("Error from dhcdbd on 'reason' request because: name '%s', message '%s'.", error.name, error.message);
dbus_error_free (&error); dbus_error_free (&error);
} }
if (reply) else if (reply)
{ {
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID)) if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID))
state = 0; state = 0;
dbus_message_unref (reply); dbus_message_unref (reply);
} }

View File

@@ -22,7 +22,7 @@
#define NM_DHCP_MANAGER_H #define NM_DHCP_MANAGER_H
#include "NetworkManagerMain.h" #include "NetworkManagerMain.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
char * get_dhcp_match_string (const char *owner); char * get_dhcp_match_string (const char *owner);

View File

@@ -24,7 +24,7 @@
#include <string.h> #include <string.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include "nm-activation-request.h" #include "nm-activation-request.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "NetworkManagerDbus.h" #include "NetworkManagerDbus.h"
#include "nm-dhcp-manager.h" #include "nm-dhcp-manager.h"
#include "nm-utils.h" #include "nm-utils.h"
@@ -62,7 +62,7 @@ NMActRequest * nm_act_request_new (NMData *data, NMDevice *dev, NMAccessPoint *a
req->refcount = 1; req->refcount = 1;
req->data = data; req->data = data;
nm_device_ref (dev); g_object_ref (G_OBJECT (dev));
req->dev = dev; req->dev = dev;
if (ap) if (ap)
@@ -90,7 +90,7 @@ void nm_act_request_unref (NMActRequest *req)
req->refcount--; req->refcount--;
if (req->refcount <= 0) if (req->refcount <= 0)
{ {
nm_device_unref (req->dev); g_object_unref (G_OBJECT (req->dev));
if (req->ap) if (req->ap)
nm_ap_unref (req->ap); nm_ap_unref (req->ap);

View File

@@ -26,7 +26,7 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include "NetworkManager.h" #include "NetworkManager.h"
#include "NetworkManagerMain.h" #include "NetworkManagerMain.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "NetworkManagerAP.h" #include "NetworkManagerAP.h"
#include "nm-ip4-config.h" #include "nm-ip4-config.h"

View File

@@ -28,7 +28,7 @@
#include "nm-ap-security-wep.h" #include "nm-ap-security-wep.h"
#include "nm-ap-security-private.h" #include "nm-ap-security-private.h"
#include "dbus-helpers.h" #include "dbus-helpers.h"
#include "NetworkManagerDevice.h" #include "nm-device-802-11-wireless.h"
#define NM_AP_SECURITY_WEP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_WEP, NMAPSecurityWEPPrivate)) #define NM_AP_SECURITY_WEP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_WEP, NMAPSecurityWEPPrivate))
@@ -112,11 +112,11 @@ real_write_wpa_supplicant_config (NMAPSecurity *instance, int fd)
} }
static int static int
real_device_setup (NMAPSecurity *instance, NMDevice * dev) real_device_setup (NMAPSecurity *instance, NMDevice80211Wireless * dev)
{ {
NMAPSecurityWEP * self = NM_AP_SECURITY_WEP (instance); NMAPSecurityWEP * self = NM_AP_SECURITY_WEP (instance);
nm_device_set_wep_enc_key (dev, nm_ap_security_get_key (instance), nm_device_802_11_wireless_set_wep_enc_key (dev, nm_ap_security_get_key (instance),
self->priv->auth_algorithm); self->priv->auth_algorithm);
return 0; return 0;
} }

View File

@@ -28,7 +28,7 @@
#include "nm-ap-security-wpa-psk.h" #include "nm-ap-security-wpa-psk.h"
#include "nm-ap-security-private.h" #include "nm-ap-security-private.h"
#include "dbus-helpers.h" #include "dbus-helpers.h"
#include "NetworkManagerDevice.h" #include "nm-device-802-11-wireless.h"
#define NM_AP_SECURITY_WPA_PSK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_WPA_PSK, NMAPSecurityWPA_PSKPrivate)) #define NM_AP_SECURITY_WPA_PSK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY_WPA_PSK, NMAPSecurityWPA_PSKPrivate))
@@ -90,7 +90,7 @@ real_write_wpa_supplicant_config (NMAPSecurity *instance, int fd)
} }
static int static int
real_device_setup (NMAPSecurity *self, NMDevice * dev) real_device_setup (NMAPSecurity *self, NMDevice80211Wireless * dev)
{ {
/* Stub; should be farmed out to wpa_supplicant eventually */ /* Stub; should be farmed out to wpa_supplicant eventually */
return 0; return 0;

View File

@@ -28,7 +28,7 @@
#include "nm-ap-security-private.h" #include "nm-ap-security-private.h"
#include "nm-ap-security-wep.h" #include "nm-ap-security-wep.h"
#include "nm-ap-security-wpa-psk.h" #include "nm-ap-security-wpa-psk.h"
#include "NetworkManagerDevice.h" #include "nm-device-802-11-wireless.h"
#define NM_AP_SECURITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY, NMAPSecurityPrivate)) #define NM_AP_SECURITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_AP_SECURITY, NMAPSecurityPrivate))
@@ -195,10 +195,10 @@ real_write_wpa_supplicant_config (NMAPSecurity *self, int fd)
} }
static int static int
real_device_setup (NMAPSecurity *self, NMDevice * dev) real_device_setup (NMAPSecurity *self, NMDevice80211Wireless * dev)
{ {
/* unencrypted */ /* unencrypted */
nm_device_set_wep_enc_key (dev, NULL, 0); nm_device_802_11_wireless_set_wep_enc_key (dev, NULL, 0);
return 0; return 0;
} }
@@ -236,7 +236,7 @@ nm_ap_security_set_description (NMAPSecurity *self, const char *desc)
} }
int int
nm_ap_security_device_setup (NMAPSecurity *self, NMDevice *dev) nm_ap_security_device_setup (NMAPSecurity *self, NMDevice80211Wireless *dev)
{ {
g_return_val_if_fail (self != NULL, -1); g_return_val_if_fail (self != NULL, -1);
g_return_val_if_fail (dev != NULL, -1); g_return_val_if_fail (dev != NULL, -1);

View File

@@ -25,6 +25,12 @@
#include <glib-object.h> #include <glib-object.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
/* Grr */
#ifndef NM_DEVICE_802_11_WIRELESS_DEFINED
#define NM_DEVICE_802_11_WIRELESS_DEFINED
typedef struct _NMDevice80211Wireless NMDevice80211Wireless;
#endif
G_BEGIN_DECLS G_BEGIN_DECLS
#define NM_TYPE_AP_SECURITY (nm_ap_security_get_type ()) #define NM_TYPE_AP_SECURITY (nm_ap_security_get_type ())
@@ -46,7 +52,6 @@ struct _NMAPSecurity
NMAPSecurityPrivate *priv; NMAPSecurityPrivate *priv;
}; };
struct NMDevice;
struct NMAccessPoint; struct NMAccessPoint;
struct _NMAPSecurityClass struct _NMAPSecurityClass
@@ -60,7 +65,7 @@ struct _NMAPSecurityClass
void (*write_wpa_supplicant_config_func)(NMAPSecurity *self, int fd); void (*write_wpa_supplicant_config_func)(NMAPSecurity *self, int fd);
int (*device_setup_func) (NMAPSecurity *self, struct NMDevice * dev); int (*device_setup_func) (NMAPSecurity *self, NMDevice80211Wireless * dev);
}; };
@@ -80,7 +85,7 @@ int nm_ap_security_serialize (NMAPSecurity *self, DBusMessageIter *iter);
void nm_ap_security_write_wpa_supplicant_config (NMAPSecurity *self, int fd); void nm_ap_security_write_wpa_supplicant_config (NMAPSecurity *self, int fd);
int nm_ap_security_device_setup (NMAPSecurity *self, struct NMDevice *dev); int nm_ap_security_device_setup (NMAPSecurity *self, NMDevice80211Wireless *dev);
const char *nm_ap_security_get_description (NMAPSecurity *self); const char *nm_ap_security_get_description (NMAPSecurity *self);

View File

@@ -28,12 +28,14 @@
#include <netinet/ether.h> #include <netinet/ether.h>
#include "nm-utils.h" #include "nm-utils.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "NetworkManagerDbus.h" #include "NetworkManagerDbus.h"
#include "NetworkManagerDbusUtils.h" #include "NetworkManagerDbusUtils.h"
#include "NetworkManagerPolicy.h" #include "NetworkManagerPolicy.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "nm-dbus-device.h" #include "nm-dbus-device.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
static DBusMessage *nm_dbus_device_get_name (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) static DBusMessage *nm_dbus_device_get_name (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data)
@@ -61,11 +63,12 @@ static DBusMessage *nm_dbus_device_get_type (DBusConnection *connection, DBusMes
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL); g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
dev = data->dev; dev = data->dev;
if ((reply = dbus_message_new_method_return (message))) { if ((reply = dbus_message_new_method_return (message)))
dbus_int32_t type; {
type = nm_device_get_type (dev); dbus_int32_t type;
type = nm_device_get_device_type (dev);
dbus_message_append_args (reply, DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID); dbus_message_append_args (reply, DBUS_TYPE_INT32, &type, DBUS_TYPE_INVALID);
} }
return reply; return reply;
} }
@@ -117,9 +120,13 @@ static DBusMessage *nm_dbus_device_get_hw_address (DBusConnection *connection, D
{ {
struct ether_addr addr; struct ether_addr addr;
char char_addr[20]; char char_addr[20];
char *ptr = &char_addr[0]; char * ptr = &char_addr[0];
nm_device_get_hw_address (dev, &addr); memset (&addr, 0, sizeof (struct ether_addr));
if (nm_device_is_802_3_ethernet (dev))
nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &addr);
else if (nm_device_is_802_11_wireless (dev))
nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &addr);
memset (char_addr, 0, 20); memset (char_addr, 0, 20);
iw_ether_ntop (&addr, char_addr); iw_ether_ntop (&addr, char_addr);
dbus_message_append_args (reply, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID); dbus_message_append_args (reply, DBUS_TYPE_STRING, &ptr, DBUS_TYPE_INVALID);
@@ -136,9 +143,14 @@ static DBusMessage *nm_dbus_device_get_mode (DBusConnection *connection, DBusMes
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL); g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
dev = data->dev; dev = data->dev;
if ((reply = dbus_message_new_method_return (message))) if (!nm_device_is_802_11_wireless (dev))
{ {
dbus_int32_t mode = (dbus_int32_t) nm_device_get_mode (dev); reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeviceNotWireless",
"Wired devices cannot see wireless networks.");
}
else if ((reply = dbus_message_new_method_return (message)))
{
dbus_int32_t mode = (dbus_int32_t) nm_device_802_11_wireless_get_mode (NM_DEVICE_802_11_WIRELESS (dev));
dbus_message_append_args (reply, DBUS_TYPE_INT32, &mode, DBUS_TYPE_INVALID); dbus_message_append_args (reply, DBUS_TYPE_INT32, &mode, DBUS_TYPE_INVALID);
} }
@@ -153,12 +165,13 @@ static DBusMessage *nm_dbus_device_get_link_active (DBusConnection *connection,
g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL); g_return_val_if_fail (data && data->data && data->dev && connection && message, NULL);
dev = data->dev; dev = data->dev;
if ((reply = dbus_message_new_method_return (message))) { if ((reply = dbus_message_new_method_return (message)))
dbus_bool_t is_active; {
dbus_bool_t is_active;
is_active = nm_device_has_active_link (dev); is_active = nm_device_has_active_link (dev);
dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &is_active, DBUS_TYPE_INVALID); dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &is_active, DBUS_TYPE_INVALID);
} }
return reply; return reply;
} }
@@ -188,8 +201,8 @@ static DBusMessage *nm_dbus_device_get_active_network (DBusConnection *connectio
NMAccessPoint *tmp_ap; NMAccessPoint *tmp_ap;
char * object_path = NULL; char * object_path = NULL;
if ( (tmp_ap = nm_device_ap_list_get_ap_by_essid (dev, nm_ap_get_essid (ap))) tmp_ap = nm_device_802_11_wireless_ap_list_get_ap_by_essid (NM_DEVICE_802_11_WIRELESS (dev), nm_ap_get_essid (ap));
&& (object_path = nm_dbus_get_object_path_for_network (dev, tmp_ap))) if (tmp_ap && (object_path = nm_dbus_get_object_path_for_network (dev, tmp_ap)))
{ {
dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID); dbus_message_append_args (reply, DBUS_TYPE_OBJECT_PATH, &object_path, DBUS_TYPE_INVALID);
g_free (object_path); g_free (object_path);
@@ -234,7 +247,7 @@ static DBusMessage *nm_dbus_device_get_networks (DBusConnection *connection, DBu
dbus_message_iter_init_append (reply, &iter); dbus_message_iter_init_append (reply, &iter);
dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter_array); dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter_array);
if ((ap_list = nm_device_ap_list_get (dev))) if ((ap_list = nm_device_802_11_wireless_ap_list_get (NM_DEVICE_802_11_WIRELESS (dev))))
{ {
if ((list_iter = nm_ap_list_iter_new (ap_list))) if ((list_iter = nm_ap_list_iter_new (ap_list)))
{ {
@@ -304,7 +317,7 @@ static DBusMessage *nm_dbus_device_set_link_active (DBusConnection *connection,
dbus_error_init (&error); dbus_error_init (&error);
if (dbus_message_get_args (message, &error, DBUS_TYPE_BOOLEAN, &link, DBUS_TYPE_INVALID)) if (dbus_message_get_args (message, &error, DBUS_TYPE_BOOLEAN, &link, DBUS_TYPE_INVALID))
{ {
nm_device_set_link_active (dev, link); nm_device_set_active_link (dev, link);
nm_policy_schedule_device_change_check (data->data); nm_policy_schedule_device_change_check (data->data);
} }
} }
@@ -324,7 +337,7 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
{ {
char * op = nm_dbus_get_object_path_for_device (dev); char * op = nm_dbus_get_object_path_for_device (dev);
const char * iface = nm_device_get_iface (dev); const char * iface = nm_device_get_iface (dev);
dbus_uint32_t type = (dbus_uint32_t) nm_device_get_type (dev); dbus_uint32_t type = (dbus_uint32_t) nm_device_get_device_type (dev);
const char * udi = nm_device_get_udi (dev); const char * udi = nm_device_get_udi (dev);
gchar * ip4_address; gchar * ip4_address;
gchar * broadcast; gchar * broadcast;
@@ -340,6 +353,7 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
char * active_network_path = NULL; char * active_network_path = NULL;
dbus_bool_t link_active = (dbus_bool_t) nm_device_has_active_link (dev); dbus_bool_t link_active = (dbus_bool_t) nm_device_has_active_link (dev);
dbus_uint32_t capabilities = (dbus_uint32_t) nm_device_get_capabilities (dev); dbus_uint32_t capabilities = (dbus_uint32_t) nm_device_get_capabilities (dev);
dbus_uint32_t type_capabilities = (dbus_uint32_t) nm_device_get_type_capabilities (dev);
char ** networks = NULL; char ** networks = NULL;
int num_networks = 0; int num_networks = 0;
dbus_bool_t active = nm_device_get_act_request (dev) ? TRUE : FALSE; dbus_bool_t active = nm_device_get_act_request (dev) ? TRUE : FALSE;
@@ -351,8 +365,11 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
guint32 primary_dns_addr = 0; guint32 primary_dns_addr = 0;
guint32 secondary_dns_addr = 0; guint32 secondary_dns_addr = 0;
nm_device_get_hw_address (dev, &hw_addr);
memset (hw_addr_buf, 0, 20); memset (hw_addr_buf, 0, 20);
if (nm_device_is_802_3_ethernet (dev))
nm_device_802_3_ethernet_get_address (NM_DEVICE_802_3_ETHERNET (dev), &hw_addr);
else if (nm_device_is_802_11_wireless (dev))
nm_device_802_11_wireless_get_address (NM_DEVICE_802_11_WIRELESS (dev), &hw_addr);
iw_ether_ntop (&hw_addr, hw_addr_buf); iw_ether_ntop (&hw_addr, hw_addr_buf);
ip4config = nm_device_get_ip4_config (dev); ip4config = nm_device_get_ip4_config (dev);
@@ -379,23 +396,24 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
if (nm_device_is_802_11_wireless (dev)) if (nm_device_is_802_11_wireless (dev))
{ {
NMDevice80211Wireless * wdev = NM_DEVICE_802_11_WIRELESS (dev);
NMActRequest * req = nm_device_get_act_request (dev); NMActRequest * req = nm_device_get_act_request (dev);
NMAccessPoint * ap; NMAccessPoint * ap;
NMAccessPointList * ap_list; NMAccessPointList * ap_list;
NMAPListIter * iter; NMAPListIter * iter;
strength = (dbus_int32_t) nm_device_get_signal_strength (dev); strength = (dbus_int32_t) nm_device_802_11_wireless_get_signal_strength (wdev);
mode = (dbus_int32_t) nm_device_get_mode (dev); mode = (dbus_int32_t) nm_device_802_11_wireless_get_mode (wdev);
if (req && (ap = nm_act_request_get_ap (req))) if (req && (ap = nm_act_request_get_ap (req)))
{ {
NMAccessPoint *tmp_ap; NMAccessPoint *tmp_ap;
if ((tmp_ap = nm_device_ap_list_get_ap_by_essid (dev, nm_ap_get_essid (ap)))) if ((tmp_ap = nm_device_802_11_wireless_ap_list_get_ap_by_essid (wdev, nm_ap_get_essid (ap))))
active_network_path = nm_dbus_get_object_path_for_network (dev, tmp_ap); active_network_path = nm_dbus_get_object_path_for_network (dev, tmp_ap);
} }
ap_list = nm_device_ap_list_get (dev); ap_list = nm_device_802_11_wireless_ap_list_get (wdev);
if (ap_list && (num_networks = nm_ap_list_size (ap_list))) if (ap_list && (num_networks = nm_ap_list_size (ap_list)))
{ {
if ((iter = nm_ap_list_iter_new (ap_list))) if ((iter = nm_ap_list_iter_new (ap_list)))
@@ -436,6 +454,7 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D
DBUS_TYPE_INT32, &strength, DBUS_TYPE_INT32, &strength,
DBUS_TYPE_BOOLEAN,&link_active, DBUS_TYPE_BOOLEAN,&link_active,
DBUS_TYPE_UINT32, &capabilities, DBUS_TYPE_UINT32, &capabilities,
DBUS_TYPE_UINT32, &type_capabilities,
DBUS_TYPE_STRING, &active_network_path, DBUS_TYPE_STRING, &active_network_path,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &networks, num_networks, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &networks, num_networks,
DBUS_TYPE_INVALID); DBUS_TYPE_INVALID);

View File

@@ -19,7 +19,8 @@
* (C) Copyright 2005 Red Hat, Inc. * (C) Copyright 2005 Red Hat, Inc.
*/ */
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-device-802-11-wireless.h"
#include "NetworkManagerDbus.h" #include "NetworkManagerDbus.h"
#include "NetworkManagerAP.h" #include "NetworkManagerAP.h"
#include "NetworkManagerAPList.h" #include "NetworkManagerAPList.h"
@@ -43,7 +44,7 @@ static NMAccessPoint *nm_dbus_get_ap_from_object_path (const char *path, NMDevic
g_return_val_if_fail (path != NULL, NULL); g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (dev != NULL, NULL); g_return_val_if_fail (dev != NULL, NULL);
ap_list = nm_device_ap_list_get (dev); ap_list = nm_device_802_11_wireless_ap_list_get (NM_DEVICE_802_11_WIRELESS (dev));
if (!ap_list) if (!ap_list)
return (NULL); return (NULL);
@@ -145,7 +146,7 @@ static DBusMessage *nm_dbus_net_get_strength (DBusConnection *connection, DBusMe
NMAPListIter *iter; NMAPListIter *iter;
int best_strength = nm_ap_get_strength (data->ap); int best_strength = nm_ap_get_strength (data->ap);
if (!(ap_list = nm_device_ap_list_get (data->dev))) if (!(ap_list = nm_device_802_11_wireless_ap_list_get (NM_DEVICE_802_11_WIRELESS (data->dev))))
goto append; goto append;
if (!(iter = nm_ap_list_iter_new (ap_list))) if (!(iter = nm_ap_list_iter_new (ap_list)))
@@ -243,8 +244,8 @@ static DBusMessage *nm_dbus_net_get_properties (DBusConnection *connection, DBus
dbus_int32_t strength = nm_ap_get_strength (data->ap); dbus_int32_t strength = nm_ap_get_strength (data->ap);
double freq = nm_ap_get_freq (data->ap); double freq = nm_ap_get_freq (data->ap);
dbus_int32_t rate = nm_ap_get_rate (data->ap); dbus_int32_t rate = nm_ap_get_rate (data->ap);
dbus_bool_t enc = nm_ap_get_encrypted (data->ap);
dbus_int32_t mode = (dbus_int32_t) nm_ap_get_mode (data->ap); dbus_int32_t mode = (dbus_int32_t) nm_ap_get_mode (data->ap);
dbus_int32_t capabilities = (dbus_int32_t) nm_ap_get_capabilities (data->ap);
memset (&hw_addr_buf[0], 0, 20); memset (&hw_addr_buf[0], 0, 20);
if (nm_ap_get_address (data->ap)) if (nm_ap_get_address (data->ap))
@@ -256,8 +257,8 @@ static DBusMessage *nm_dbus_net_get_properties (DBusConnection *connection, DBus
DBUS_TYPE_INT32, &strength, DBUS_TYPE_INT32, &strength,
DBUS_TYPE_DOUBLE, &freq, DBUS_TYPE_DOUBLE, &freq,
DBUS_TYPE_INT32, &rate, DBUS_TYPE_INT32, &rate,
DBUS_TYPE_BOOLEAN,&enc,
DBUS_TYPE_INT32, &mode, DBUS_TYPE_INT32, &mode,
DBUS_TYPE_INT32, &capabilities,
DBUS_TYPE_INVALID); DBUS_TYPE_INVALID);
g_free (op); g_free (op);
} }

View File

@@ -35,6 +35,8 @@
#include "NetworkManagerSystem.h" #include "NetworkManagerSystem.h"
#include "NetworkManager.h" #include "NetworkManager.h"
#include "nm-ap-security.h" #include "nm-ap-security.h"
#include "nm-device-802-3-ethernet.h"
#include "nm-device-802-11-wireless.h"
/* /*
@@ -255,7 +257,7 @@ static DBusMessage *nm_dbus_nm_set_active_device (DBusConnection *connection, DB
} }
/* Set up the wireless-specific activation request properties */ /* Set up the wireless-specific activation request properties */
ap = nm_device_wireless_get_activation_ap (dev, essid, security); ap = nm_device_802_11_wireless_get_activation_ap (NM_DEVICE_802_11_WIRELESS (dev), essid, security);
if (security) if (security)
g_object_unref (G_OBJECT (security)); g_object_unref (G_OBJECT (security));

View File

@@ -20,7 +20,7 @@
*/ */
#include "NetworkManager.h" #include "NetworkManager.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-activation-request.h" #include "nm-activation-request.h"
#include "NetworkManagerAPList.h" #include "NetworkManagerAPList.h"
#include "NetworkManagerPolicy.h" #include "NetworkManagerPolicy.h"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,125 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2005 Red Hat, Inc.
*/
#ifndef NM_DEVICE_802_11_WIRELESS_H
#define NM_DEVICE_802_11_WIRELESS_H
#include <glib-object.h>
#include <dbus/dbus.h>
#include <net/ethernet.h>
#include "nm-device.h"
#include "NetworkManagerAP.h"
struct NMAccessPointList;
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_802_11_WIRELESS (nm_device_802_11_wireless_get_type ())
#define NM_DEVICE_802_11_WIRELESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_802_11_WIRELESS, NMDevice80211Wireless))
#define NM_DEVICE_802_11_WIRELESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_802_11_WIRELESS, NMDevice80211WirelessClass))
#define NM_IS_DEVICE_802_11_WIRELESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_802_11_WIRELESS))
#define NM_IS_DEVICE_802_11_WIRELESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_802_11_WIRELESS))
#define NM_DEVICE_802_11_WIRELESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_802_11_WIRELESS, NMDevice80211WirelessClass))
#ifndef NM_DEVICE_802_11_WIRELESS_DEFINED
#define NM_DEVICE_802_11_WIRELESS_DEFINED
typedef struct _NMDevice80211Wireless NMDevice80211Wireless;
#endif
typedef struct _NMDevice80211WirelessClass NMDevice80211WirelessClass;
typedef struct _NMDevice80211WirelessPrivate NMDevice80211WirelessPrivate;
struct _NMDevice80211Wireless
{
NMDevice parent;
/*< private >*/
NMDevice80211WirelessPrivate *priv;
};
struct _NMDevice80211WirelessClass
{
NMDeviceClass parent;
};
GType nm_device_802_11_wireless_get_type (void);
NMDevice80211Wireless * nm_device_802_11_wireless_new (void);
static inline gboolean nm_device_is_802_11_wireless (NMDevice *dev);
static inline gboolean nm_device_is_802_11_wireless (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, FALSE);
return (G_OBJECT_TYPE (dev) == NM_TYPE_DEVICE_802_11_WIRELESS);
}
void nm_device_802_11_wireless_set_essid (NMDevice80211Wireless *self,
const char *essid);
void nm_device_802_11_wireless_get_address (NMDevice80211Wireless *dev,
struct ether_addr *addr);
void nm_device_802_11_wireless_get_bssid (NMDevice80211Wireless *dev,
struct ether_addr *bssid);
NMAccessPoint * nm_device_802_11_wireless_get_best_ap (NMDevice80211Wireless *dev);
NMAccessPoint * nm_device_802_11_wireless_get_activation_ap (NMDevice80211Wireless *dev,
const char *essid,
NMAPSecurity *security);
void nm_device_802_11_wireless_set_wep_enc_key (NMDevice80211Wireless *dev,
const char *key,
int auth_method);
void nm_device_802_11_wireless_set_scan_interval (struct NMData *data,
NMDevice80211Wireless *dev,
NMWirelessScanInterval interval);
void nm_device_802_11_wireless_copy_allowed_to_dev_list (NMDevice80211Wireless *self,
struct NMAccessPointList *allowed_list);
struct NMAccessPointList * nm_device_802_11_wireless_ap_list_get (NMDevice80211Wireless *dev);
NMAccessPoint * nm_device_802_11_wireless_ap_list_get_ap_by_obj_path (NMDevice80211Wireless *dev,
const char *obj_path);
NMAccessPoint * nm_device_802_11_wireless_ap_list_get_ap_by_bssid (NMDevice80211Wireless *dev,
const struct ether_addr *bssid);
NMAccessPoint * nm_device_802_11_wireless_ap_list_get_ap_by_essid (NMDevice80211Wireless *dev,
const char *essid);
int nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *self);
gint8 nm_device_802_11_wireless_get_signal_strength (NMDevice80211Wireless *self);
void nm_device_802_11_wireless_update_signal_strength (NMDevice80211Wireless *self);
G_END_DECLS
#endif /* NM_DEVICE_802_11_WIRELESS_H */

View File

@@ -0,0 +1,349 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2005 Red Hat, Inc.
*/
#include <glib.h>
#include <glib/gi18n.h>
#include <dbus/dbus.h>
#include <netinet/in.h>
#include <string.h>
#include <net/ethernet.h>
#include <stdlib.h>
#include "nm-device-802-3-ethernet.h"
#include "nm-device-private.h"
#include "NetworkManagerMain.h"
#include "nm-activation-request.h"
#include "NetworkManagerUtils.h"
#include "nm-utils.h"
#define NM_DEVICE_802_3_ETHERNET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_802_3_ETHERNET, NMDevice8023EthernetPrivate))
struct _NMDevice8023EthernetPrivate
{
gboolean dispose_has_run;
struct ether_addr hw_addr;
};
static gboolean supports_mii_carrier_detect (NMDevice8023Ethernet *dev);
static gboolean supports_ethtool_carrier_detect (NMDevice8023Ethernet *dev);
static void
nm_device_802_3_ethernet_init (NMDevice8023Ethernet * self)
{
self->priv = NM_DEVICE_802_3_ETHERNET_GET_PRIVATE (self);
self->priv->dispose_has_run = FALSE;
memset (&(self->priv->hw_addr), 0, sizeof (struct ether_addr));
}
/*
* nm_device_get_hw_address
*
* Get a device's hardware address
*
*/
void
nm_device_802_3_ethernet_get_address (NMDevice8023Ethernet *self, struct ether_addr *addr)
{
g_return_if_fail (self != NULL);
g_return_if_fail (addr != NULL);
memcpy (addr, &(self->priv->hw_addr), sizeof (struct ether_addr));
}
static guint32
real_discover_generic_capabilities (NMDevice *dev)
{
NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (dev);
guint32 caps = NM_DEVICE_CAP_NONE;
const char * udi = NULL;
char * usb_test = NULL;
NMData * app_data;
/* cipsec devices are also explicitly unsupported at this time */
if (strstr (nm_device_get_iface (dev), "cipsec"))
return NM_DEVICE_CAP_NONE;
/* Ignore Ethernet-over-USB devices too for the moment (Red Hat #135722) */
app_data = nm_device_get_app_data (dev);
udi = nm_device_get_udi (dev);
if ( libhal_device_property_exists (app_data->hal_ctx, udi, "usb.interface.class", NULL)
&& (usb_test = libhal_device_get_property_string (app_data->hal_ctx, udi, "usb.interface.class", NULL)))
{
libhal_free_string (usb_test);
return NM_DEVICE_CAP_NONE;
}
if (supports_ethtool_carrier_detect (self) || supports_mii_carrier_detect (self))
caps |= NM_DEVICE_CAP_CARRIER_DETECT;
return caps;
}
static gboolean
real_activation_config (NMDevice *dev, NMActRequest *req)
{
NMData * data;
g_return_val_if_fail (req != NULL, FALSE);
data = nm_act_request_get_data (req);
g_assert (data);
return TRUE;
}
static gboolean
real_probe_link (NMDevice *dev)
{
NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (dev);
gboolean link = FALSE;
gchar * contents;
gchar * carrier_path;
gsize length;
guint32 caps;
if (nm_device_get_removed (dev))
return FALSE;
carrier_path = g_strdup_printf ("/sys/class/net/%s/carrier", nm_device_get_iface (dev));
if (g_file_get_contents (carrier_path, &contents, &length, NULL))
{
link = (gboolean) atoi (contents);
g_free (contents);
}
g_free (carrier_path);
/* We say that non-carrier-detect devices always have a link, because
* they never get auto-selected by NM. User has to force them on us,
* so we just hope the user knows whether or not the cable's plugged in.
*/
caps = nm_device_get_capabilities (dev);
if (!(caps & NM_DEVICE_CAP_CARRIER_DETECT))
link = TRUE;
return link;
}
static void
nm_device_802_3_ethernet_dispose (GObject *object)
{
NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (object);
NMDevice8023EthernetClass * klass = NM_DEVICE_802_3_ETHERNET_GET_CLASS (object);
NMDeviceClass * parent_class;
if (self->priv->dispose_has_run)
/* If dispose did already run, return. */
return;
/* Make sure dispose does not run twice. */
self->priv->dispose_has_run = TRUE;
/*
* In dispose, you are supposed to free all types referenced from this
* object which might themselves hold a reference to self. Generally,
* the most simple solution is to unref all members on which you own a
* reference.
*/
/* Chain up to the parent class */
parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass));
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
nm_device_802_3_ethernet_finalize (GObject *object)
{
NMDevice8023Ethernet * self = NM_DEVICE_802_3_ETHERNET (object);
NMDevice8023EthernetClass * klass = NM_DEVICE_802_3_ETHERNET_GET_CLASS (object);
NMDeviceClass * parent_class;
/* Chain up to the parent class */
parent_class = NM_DEVICE_CLASS (g_type_class_peek_parent (klass));
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
nm_device_802_3_ethernet_class_init (NMDevice8023EthernetClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
NMDeviceClass *parent_class = NM_DEVICE_CLASS (klass);
object_class->dispose = nm_device_802_3_ethernet_dispose;
object_class->finalize = nm_device_802_3_ethernet_finalize;
parent_class->activation_config = real_activation_config;
parent_class->discover_generic_capabilities = real_discover_generic_capabilities;
parent_class->probe_link = real_probe_link;
g_type_class_add_private (object_class, sizeof (NMDevice8023EthernetPrivate));
}
GType
nm_device_802_3_ethernet_get_type (void)
{
static GType type = 0;
if (type == 0)
{
static const GTypeInfo info =
{
sizeof (NMDevice8023EthernetClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) nm_device_802_3_ethernet_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (NMDevice8023Ethernet),
0, /* n_preallocs */
(GInstanceInitFunc) nm_device_802_3_ethernet_init
};
type = g_type_register_static (NM_TYPE_DEVICE,
"NMDevice8023Ethernet",
&info, 0);
}
return type;
}
/**************************************/
/* Ethtool capability detection */
/**************************************/
#include <linux/sockios.h>
#include <linux/ethtool.h>
static gboolean
supports_ethtool_carrier_detect (NMDevice8023Ethernet *self)
{
NMSock * sk;
struct ifreq ifr;
gboolean supports_ethtool = FALSE;
struct ethtool_cmd edata;
const char * iface;
g_return_val_if_fail (self != NULL, FALSE);
iface = nm_device_get_iface (NM_DEVICE (self));
if ((sk = nm_dev_sock_open (NM_DEVICE (self), DEV_GENERAL, __func__, NULL)) == NULL)
{
nm_warning ("cannot open socket on interface %s for ethtool detect; errno=%d",
iface, errno);
return FALSE;
}
strncpy (ifr.ifr_name, iface, sizeof(ifr.ifr_name) - 1);
edata.cmd = ETHTOOL_GLINK;
ifr.ifr_data = (char *) &edata;
#ifdef IOCTL_DEBUG
nm_info ("%s: About to ETHTOOL\n", iface);
#endif
if (ioctl (nm_dev_sock_get_fd (sk), SIOCETHTOOL, &ifr) == -1)
goto out;
supports_ethtool = TRUE;
out:
#ifdef IOCTL_DEBUG
nm_info ("%s: Done with ETHTOOL\n", iface);
#endif
nm_dev_sock_close (sk);
return supports_ethtool;
}
/**************************************/
/* MII capability detection */
/**************************************/
#include <linux/mii.h>
static int
mdio_read (NMDevice8023Ethernet *self, NMSock *sk, struct ifreq *ifr, int location)
{
struct mii_ioctl_data *mii;
int val = -1;
const char * iface;
g_return_val_if_fail (sk != NULL, -1);
g_return_val_if_fail (ifr != NULL, -1);
iface = nm_device_get_iface (NM_DEVICE (self));
mii = (struct mii_ioctl_data *) &(ifr->ifr_data);
mii->reg_num = location;
#ifdef IOCTL_DEBUG
nm_info ("%s: About to GET MIIREG\n", iface);
#endif
if (ioctl (nm_dev_sock_get_fd (sk), SIOCGMIIREG, ifr) >= 0)
val = mii->val_out;
#ifdef IOCTL_DEBUG
nm_info ("%s: Done with GET MIIREG\n", iface);
#endif
return val;
}
static gboolean
supports_mii_carrier_detect (NMDevice8023Ethernet *self)
{
NMSock * sk;
struct ifreq ifr;
int bmsr;
gboolean supports_mii = FALSE;
int err;
const char * iface;
g_return_val_if_fail (self != NULL, FALSE);
iface = nm_device_get_iface (NM_DEVICE (self));
if ((sk = nm_dev_sock_open (NM_DEVICE (self), DEV_GENERAL, __FUNCTION__, NULL)) == NULL)
{
nm_warning ("cannot open socket on interface %s for MII detect; errno=%d",
iface, errno);
return FALSE;
}
strncpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name) - 1);
#ifdef IOCTL_DEBUG
nm_info ("%s: About to GET MIIPHY\n", iface);
#endif
err = ioctl (nm_dev_sock_get_fd (sk), SIOCGMIIPHY, &ifr);
#ifdef IOCTL_DEBUG
nm_info ("%s: Done with GET MIIPHY\n", iface);
#endif
if (err < 0)
goto out;
/* If we can read the BMSR register, we assume that the card supports MII link detection */
bmsr = mdio_read (self, sk, &ifr, MII_BMSR);
supports_mii = (bmsr != -1) ? TRUE : FALSE;
out:
nm_dev_sock_close (sk);
return supports_mii;
}

View File

@@ -0,0 +1,77 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2005 Red Hat, Inc.
*/
#ifndef NM_DEVICE_802_3_ETHERNET_H
#define NM_DEVICE_802_3_ETHERNET_H
#include <glib-object.h>
#include <dbus/dbus.h>
#include <net/ethernet.h>
#include "nm-device.h"
G_BEGIN_DECLS
#define NM_TYPE_DEVICE_802_3_ETHERNET (nm_device_802_3_ethernet_get_type ())
#define NM_DEVICE_802_3_ETHERNET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_802_3_ETHERNET, NMDevice8023Ethernet))
#define NM_DEVICE_802_3_ETHERNET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_802_3_ETHERNET, NMDevice8023EthernetClass))
#define NM_IS_DEVICE_802_3_ETHERNET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_802_3_ETHERNET))
#define NM_IS_DEVICE_802_3_ETHERNET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE_802_3_ETHERNET))
#define NM_DEVICE_802_3_ETHERNET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_802_3_ETHERNET, NMDevice8023EthernetClass))
typedef struct _NMDevice8023Ethernet NMDevice8023Ethernet;
typedef struct _NMDevice8023EthernetClass NMDevice8023EthernetClass;
typedef struct _NMDevice8023EthernetPrivate NMDevice8023EthernetPrivate;
struct _NMDevice8023Ethernet
{
NMDevice parent;
/*< private >*/
NMDevice8023EthernetPrivate *priv;
};
struct _NMDevice8023EthernetClass
{
NMDeviceClass parent;
};
GType nm_device_802_3_ethernet_get_type (void);
NMDevice8023Ethernet * nm_device_802_3_ethernet_new (void);
static inline gboolean nm_device_is_802_3_ethernet (NMDevice *dev);
static inline gboolean nm_device_is_802_3_ethernet (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, FALSE);
return (G_OBJECT_TYPE (dev) == NM_TYPE_DEVICE_802_3_ETHERNET);
}
void nm_device_802_3_ethernet_get_address (NMDevice8023Ethernet *dev,
struct ether_addr *addr);
G_END_DECLS
#endif /* NM_DEVICE_802_3_ETHERNET_H */

38
src/nm-device-private.h Normal file
View File

@@ -0,0 +1,38 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2005 Red Hat, Inc.
*/
#ifndef NM_DEVICE_PRIVATE_H
#define NM_DEVICE_PRIVATE_H
#include "nm-device.h"
void nm_device_set_udi (NMDevice *dev,
const char *udi);
void nm_device_set_device_type (NMDevice *self,
const NMDeviceType type);
gboolean nm_device_is_activated (NMDevice *dev);
GMainContext * nm_device_get_main_context (NMDevice *dev);
#endif /* NM_DEVICE_PRIVATE_H */

1979
src/nm-device.c Normal file

File diff suppressed because it is too large Load Diff

173
src/nm-device.h Normal file
View File

@@ -0,0 +1,173 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* (C) Copyright 2005 Red Hat, Inc.
*/
#ifndef NM_DEVICE_H
#define NM_DEVICE_H
#include <glib-object.h>
#include <dbus/dbus.h>
#include <netinet/in.h>
#include "NetworkManager.h"
#include "nm-ip4-config.h"
#if 0
#define IOCTL_DEBUG
#endif
typedef enum NMWirelessScanInterval
{
NM_WIRELESS_SCAN_INTERVAL_INIT = 0,
NM_WIRELESS_SCAN_INTERVAL_ACTIVE,
NM_WIRELESS_SCAN_INTERVAL_INACTIVE
} NMWirelessScanInterval;
G_BEGIN_DECLS
#define NM_TYPE_DEVICE (nm_device_get_type ())
#define NM_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE, NMDevice))
#define NM_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE, NMDeviceClass))
#define NM_IS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE))
#define NM_IS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEVICE))
#define NM_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE, NMDeviceClass))
typedef struct _NMDevice NMDevice;
typedef struct _NMDeviceClass NMDeviceClass;
typedef struct _NMDevicePrivate NMDevicePrivate;
struct _NMDevice
{
GObject parent;
/*< private >*/
NMDevicePrivate *priv;
};
struct NMData;
struct NMActRequest;
struct _NMDeviceClass
{
GObjectClass parent;
gboolean (* is_test_device) (NMDevice *self);
const char * (* has_active_link) (NMDevice *self);
void (* set_active_link) (NMDevice *self, gboolean active);
gboolean (* probe_link) (NMDevice *self);
guint32 (* get_ip4_address) (NMDevice *self);
struct in6_addr * (* get_ip6_address) (NMDevice *self);
void (* bring_up) (NMDevice *self);
void (* bring_down) (NMDevice *self);
gboolean (* is_up) (NMDevice *self);
guint32 (* get_type_capabilities) (NMDevice *self);
guint32 (* discover_generic_capabilities) (NMDevice *self);
void (* init) (NMDevice *self);
void (* start) (NMDevice *self);
gboolean (* activation_prepare) (NMDevice *self, struct NMActRequest * req);
gboolean (* activation_config) (NMDevice *self, struct NMActRequest * req);
void (* deactivate) (NMDevice *self);
void (* cancel_activation) (NMDevice *self);
};
GType nm_device_get_type (void);
NMDevice * nm_device_new (const char *iface,
const char *udi,
gboolean test_dev,
NMDeviceType test_dev_type,
struct NMData *app_data);
void nm_device_worker_thread_stop (NMDevice *self);
const char * nm_device_get_udi (NMDevice *dev);
const char * nm_device_get_iface (NMDevice *dev);
const char * nm_device_get_driver (NMDevice *dev);
NMDeviceType nm_device_get_device_type (NMDevice *dev);
guint32 nm_device_get_capabilities (NMDevice *dev);
guint32 nm_device_get_type_capabilities (NMDevice *dev);
struct NMData * nm_device_get_app_data (NMDevice *dev);
gboolean nm_device_get_removed (NMDevice *dev);
void nm_device_set_removed (NMDevice *dev,
const gboolean removed);
gboolean nm_device_has_active_link (NMDevice *dev);
void nm_device_set_active_link (NMDevice *dev,
const gboolean active);
gboolean nm_device_probe_link_state (NMDevice *dev);
guint32 nm_device_get_ip4_address (NMDevice *dev);
void nm_device_update_ip4_address (NMDevice *dev);
struct in6_addr * nm_device_get_ip6_address (NMDevice *dev);
gboolean nm_device_get_use_dhcp (NMDevice *dev);
void nm_device_set_use_dhcp (NMDevice *dev,
gboolean use_dhcp);
NMIP4Config * nm_device_get_ip4_config (NMDevice *dev);
void nm_device_set_ip4_config (NMDevice *dev,
NMIP4Config *config);
void nm_device_bring_up (NMDevice *dev);
gboolean nm_device_bring_up_wait (NMDevice *self,
gboolean cancelable);
void nm_device_bring_down (NMDevice *dev);
gboolean nm_device_bring_down_wait (NMDevice *self,
gboolean cancelable);
gboolean nm_device_is_up (NMDevice *dev);
void * nm_device_get_system_config_data (NMDevice *dev);
struct NMActRequest * nm_device_get_act_request (NMDevice *dev);
/* Utility routines */
NMDevice * nm_get_device_by_udi (struct NMData *data,
const char *udi);
NMDevice * nm_get_device_by_iface (struct NMData *data,
const char *iface);
gboolean nm_device_is_test_device (NMDevice *dev);
gboolean nm_device_activation_start (struct NMActRequest *req);
void nm_device_activate_schedule_stage1_device_prepare (struct NMActRequest *req);
void nm_device_activate_schedule_stage2_device_config (struct NMActRequest *req);
void nm_device_activate_schedule_stage4_ip_config_get (struct NMActRequest *req);
void nm_device_activate_schedule_stage4_ip_config_timeout (struct NMActRequest *req);
void nm_device_deactivate (NMDevice *dev);
gboolean nm_device_deactivate_quickly (NMDevice *dev);
gboolean nm_device_is_activating (NMDevice *dev);
void nm_device_activation_cancel (NMDevice *dev);
gboolean nm_device_activation_should_cancel (NMDevice *self);
G_END_DECLS
#endif /* NM_DEVICE_H */

View File

@@ -22,7 +22,7 @@
#include <glib.h> #include <glib.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include "NetworkManagerMain.h" #include "NetworkManagerMain.h"
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "NetworkManagerDbus.h" #include "NetworkManagerDbus.h"
#include "NetworkManagerUtils.h" #include "NetworkManagerUtils.h"
#include "NetworkManagerVPN.h" #include "NetworkManagerVPN.h"

View File

@@ -64,7 +64,7 @@ NMVPNActRequest *nm_vpn_act_request_new (NMVPNManager *manager, NMVPNService *se
req->stage = NM_VPN_ACT_STAGE_PREPARE; req->stage = NM_VPN_ACT_STAGE_PREPARE;
req->manager = manager; req->manager = manager;
nm_device_ref (parent_dev); g_object_ref (G_OBJECT (parent_dev));
req->parent_dev = parent_dev; req->parent_dev = parent_dev;
nm_vpn_service_ref (service); nm_vpn_service_ref (service);
req->service = service; req->service = service;
@@ -95,7 +95,7 @@ void nm_vpn_act_request_unref (NMVPNActRequest *req)
req->refcount--; req->refcount--;
if (req->refcount == 0) if (req->refcount == 0)
{ {
nm_device_unref (req->parent_dev); g_object_unref (G_OBJECT (req->parent_dev));
nm_vpn_service_unref (req->service); nm_vpn_service_unref (req->service);
nm_vpn_connection_unref (req->vpn); nm_vpn_connection_unref (req->vpn);

View File

@@ -96,7 +96,7 @@ void nm_vpn_connection_unref (NMVPNConnection *connection)
g_free (connection->service_name); g_free (connection->service_name);
if (connection->parent_dev) if (connection->parent_dev)
nm_device_unref (connection->parent_dev); g_object_unref (G_OBJECT (connection->parent_dev));
if (connection->ip4_config) if (connection->ip4_config)
nm_ip4_config_unref (connection->ip4_config); nm_ip4_config_unref (connection->ip4_config);
g_free (connection->vpn_iface); g_free (connection->vpn_iface);
@@ -228,13 +228,13 @@ static void nm_vpn_connection_set_parent_device (NMVPNConnection *con, NMDevice
if (con->parent_dev) if (con->parent_dev)
{ {
nm_device_unref (con->parent_dev); g_object_unref (G_OBJECT (con->parent_dev));
con->parent_dev = NULL; con->parent_dev = NULL;
} }
if (parent_dev) if (parent_dev)
{ {
nm_device_ref (parent_dev); g_object_unref (G_OBJECT (parent_dev));
con->parent_dev = parent_dev; con->parent_dev = parent_dev;
} }
} }

View File

@@ -20,7 +20,8 @@
#ifndef NM_VPN_CONNECTION_H #ifndef NM_VPN_CONNECTION_H
#define NM_VPN_CONNECTION_H #define NM_VPN_CONNECTION_H
#include "NetworkManagerDevice.h" #include "nm-device.h"
#include "nm-named-manager.h"
typedef struct NMVPNConnection NMVPNConnection; typedef struct NMVPNConnection NMVPNConnection;

View File

@@ -20,6 +20,7 @@
#include <glib.h> #include <glib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include "nm-vpn-manager.h" #include "nm-vpn-manager.h"
#include "NetworkManager.h" #include "NetworkManager.h"