2007-03-02 Tambet Ingo <tambet@ximian.com>
* libnm-glib/nm-device-802-11-wireless.c (nm_device_802_11_wireless_get_capabilities): Implement. * libnm-glib/nm-device.c (nm_device_get_capabilities): Implement. * src/nm-device-802-11-wireless.c: Add "WirelessCapabilities" property. * src/named-manager/nm-named-manager.c (remove_one_zone_from_named): Unref the reply only if it's not NULL. Not sure why this started happening right now. * src/nm-manager.c (device_stop_and_free): Remove. No need to have different code paths for when devices get removed on shutdown or when a device is just removed. (finalize): Don't use a g_slist_foreach() when removing devices, the list data gets freed so any signal from a device (disconnected for instance) would invoke NMState update which would crash. (nm_manager_remove_device): Bring the device down when it gets removed. * src/NetworkManagerPolicy.c (nm_policy_auto_get_best_device): Remove the unused dev_type. * src/nm-hal-manager.c (create_device_and_add_to_list): Don't keep the reference to the added device, NMManager will own it (if it wants). * test/nm-tool.c: Rewrite using libnm-glib. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2417 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
26
ChangeLog
26
ChangeLog
@@ -1,5 +1,31 @@
|
||||
2007-03-02 Tambet Ingo <tambet@ximian.com>
|
||||
|
||||
* libnm-glib/nm-device-802-11-wireless.c
|
||||
(nm_device_802_11_wireless_get_capabilities): Implement.
|
||||
|
||||
* libnm-glib/nm-device.c (nm_device_get_capabilities): Implement.
|
||||
|
||||
* src/nm-device-802-11-wireless.c: Add "WirelessCapabilities" property.
|
||||
|
||||
* src/named-manager/nm-named-manager.c (remove_one_zone_from_named): Unref the
|
||||
reply only if it's not NULL. Not sure why this started happening right now.
|
||||
|
||||
* src/nm-manager.c (device_stop_and_free): Remove. No need to have different
|
||||
code paths for when devices get removed on shutdown or when a device is just
|
||||
removed.
|
||||
(finalize): Don't use a g_slist_foreach() when removing devices, the list data
|
||||
gets freed so any signal from a device (disconnected for instance) would invoke
|
||||
NMState update which would crash.
|
||||
(nm_manager_remove_device): Bring the device down when it gets removed.
|
||||
|
||||
* src/NetworkManagerPolicy.c (nm_policy_auto_get_best_device): Remove
|
||||
the unused dev_type.
|
||||
|
||||
* src/nm-hal-manager.c (create_device_and_add_to_list): Don't keep the
|
||||
reference to the added device, NMManager will own it (if it wants).
|
||||
|
||||
* test/nm-tool.c: Rewrite using libnm-glib.
|
||||
|
||||
* libnm-glib/nm-device-802-11-wireless.c: Cache networks (bssids) list.
|
||||
We get signalled when it changes.
|
||||
|
||||
|
@@ -18,6 +18,7 @@
|
||||
<property name="Mode" type="i" access="read"/>
|
||||
<property name="Bitrate" type="i" access="read"/>
|
||||
<property name="ActiveNetwork" type="o" access="read"/>
|
||||
<property name="WirelessCapabilities" type="u" access="read"/>
|
||||
|
||||
<signal name="NetworkAdded">
|
||||
<arg name="network" type="o"/>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<property name="Udi" type="s" access="read"/>
|
||||
<property name="Interface" type="s" access="read"/>
|
||||
<property name="Driver" type="s" access="read"/>
|
||||
<property name="Capabilities" type="i" access="read"/>
|
||||
<property name="Capabilities" type="u" access="read"/>
|
||||
<property name="Ip4Address" type="i" access="read"/>
|
||||
<property name="State" type="u" access="read"/>
|
||||
<property name="Ip4Config" type="o" access="read"/>
|
||||
|
@@ -161,6 +161,23 @@ nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *device)
|
||||
return bitrate;
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_device_802_11_wireless_get_capabilities (NMDevice80211Wireless *device)
|
||||
{
|
||||
guint32 caps = 0;
|
||||
GValue value = {0,};
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE (device), 0);
|
||||
|
||||
if (nm_dbus_get_property (DBUS_G_PROXY (device),
|
||||
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
|
||||
"WirelessCapabilities",
|
||||
&value))
|
||||
caps = g_value_get_uint (&value);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
static NMAccessPoint *
|
||||
get_network (NMDevice80211Wireless *device, const char *path, gboolean create_if_not_found)
|
||||
{
|
||||
|
@@ -31,6 +31,7 @@ NMDevice80211Wireless *nm_device_802_11_wireless_new (DBusGConnection *c
|
||||
char *nm_device_802_11_wireless_get_hw_address (NMDevice80211Wireless *device);
|
||||
int nm_device_802_11_wireless_get_mode (NMDevice80211Wireless *device);
|
||||
int nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *device);
|
||||
guint32 nm_device_802_11_wireless_get_capabilities (NMDevice80211Wireless *device);
|
||||
NMAccessPoint *nm_device_802_11_wireless_get_active_network (NMDevice80211Wireless *device);
|
||||
|
||||
GSList *nm_device_802_11_wireless_get_networks (NMDevice80211Wireless *device);
|
||||
|
@@ -160,6 +160,23 @@ nm_device_get_driver (NMDevice *device)
|
||||
return driver;
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_device_get_capabilities (NMDevice *device)
|
||||
{
|
||||
guint32 caps = 0;
|
||||
GValue value = {0,};
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE (device), 0);
|
||||
|
||||
if (nm_dbus_get_property (DBUS_G_PROXY (device),
|
||||
NM_DBUS_INTERFACE_DEVICE,
|
||||
"Capabilities",
|
||||
&value))
|
||||
caps = g_value_get_uint (&value);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
guint32
|
||||
nm_device_get_ip4_address (NMDevice *device)
|
||||
{
|
||||
|
@@ -34,6 +34,7 @@ void nm_device_deactivate (NMDevice *device);
|
||||
char *nm_device_get_iface (NMDevice *device);
|
||||
char *nm_device_get_udi (NMDevice *device);
|
||||
char *nm_device_get_driver (NMDevice *device);
|
||||
guint32 nm_device_get_capabilities (NMDevice *device);
|
||||
guint32 nm_device_get_ip4_address (NMDevice *device);
|
||||
NMIP4Config *nm_device_get_ip4_config (NMDevice *device);
|
||||
NMDeviceState nm_device_get_state (NMDevice *device);
|
||||
|
@@ -80,13 +80,11 @@ static NMDevice * nm_policy_auto_get_best_device (NMPolicy *policy, NMAccessPoin
|
||||
return NULL;
|
||||
|
||||
for (elt = nm_manager_get_devices (policy->manager); elt; elt = elt->next) {
|
||||
guint dev_type;
|
||||
gboolean link_active;
|
||||
guint prio = 0;
|
||||
NMDevice * dev = (NMDevice *)(elt->data);
|
||||
guint32 caps;
|
||||
|
||||
dev_type = nm_device_get_device_type (dev);
|
||||
link_active = nm_device_has_active_link (dev);
|
||||
caps = nm_device_get_capabilities (dev);
|
||||
|
||||
|
@@ -498,7 +498,9 @@ remove_one_zone_from_named (NMNamedManager *mgr, const char *zone)
|
||||
out:
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
if (reply)
|
||||
dbus_message_unref (reply);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@@ -79,6 +79,7 @@ enum {
|
||||
PROP_MODE,
|
||||
PROP_BITRATE,
|
||||
PROP_ACTIVE_NETWORK,
|
||||
PROP_CAPABILITIES,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
@@ -3048,6 +3049,7 @@ get_property (GObject *object, guint prop_id,
|
||||
GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMDevice80211Wireless *device = NM_DEVICE_802_11_WIRELESS (object);
|
||||
NMDevice80211WirelessPrivate *priv = NM_DEVICE_802_11_WIRELESS_GET_PRIVATE (device);
|
||||
struct ether_addr hw_addr;
|
||||
char hw_addr_buf[20];
|
||||
NMAccessPoint *ap;
|
||||
@@ -3066,6 +3068,9 @@ get_property (GObject *object, guint prop_id,
|
||||
case PROP_BITRATE:
|
||||
g_value_set_int (value, nm_device_802_11_wireless_get_bitrate (device));
|
||||
break;
|
||||
case PROP_CAPABILITIES:
|
||||
g_value_set_uint (value, priv->capabilities);
|
||||
break;
|
||||
case PROP_ACTIVE_NETWORK:
|
||||
req = nm_device_get_act_request (NM_DEVICE (device));
|
||||
if (req && (ap = nm_act_request_get_ap (req))) {
|
||||
@@ -3140,6 +3145,13 @@ nm_device_802_11_wireless_class_init (NMDevice80211WirelessClass *klass)
|
||||
"Currently active network",
|
||||
G_TYPE_OBJECT,
|
||||
G_PARAM_READABLE));
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_CAPABILITIES,
|
||||
g_param_spec_uint (NM_DEVICE_802_11_WIRELESS_CAPABILITIES,
|
||||
"Wireless Capabilities",
|
||||
"Wireless Capabilities",
|
||||
0, G_MAXUINT32, NM_802_11_CAP_NONE,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
/* Signals */
|
||||
signals[NETWORK_ADDED] =
|
||||
|
@@ -47,6 +47,7 @@ G_BEGIN_DECLS
|
||||
#define NM_DEVICE_802_11_WIRELESS_MODE "mode"
|
||||
#define NM_DEVICE_802_11_WIRELESS_BITRATE "bitrate"
|
||||
#define NM_DEVICE_802_11_WIRELESS_ACTIVE_NETWORK "active-network"
|
||||
#define NM_DEVICE_802_11_WIRELESS_CAPABILITIES "wireless-capabilities"
|
||||
|
||||
#ifndef NM_DEVICE_802_11_WIRELESS_DEFINED
|
||||
#define NM_DEVICE_802_11_WIRELESS_DEFINED
|
||||
|
@@ -130,6 +130,7 @@ create_device_and_add_to_list (NMHalManager *manager, const char *udi, const cha
|
||||
nm_device_get_iface (dev));
|
||||
|
||||
nm_manager_add_device (manager->nm_manager, dev);
|
||||
g_object_unref (dev);
|
||||
}
|
||||
|
||||
return dev;
|
||||
|
@@ -53,24 +53,14 @@ nm_manager_init (NMManager *manager)
|
||||
priv->sleeping = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
device_stop_and_free (gpointer data, gpointer user_data)
|
||||
{
|
||||
NMDevice *device = NM_DEVICE (data);
|
||||
|
||||
nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device));
|
||||
g_object_unref (device);
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (object);
|
||||
NMManager *manager = NM_MANAGER (object);
|
||||
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
|
||||
|
||||
g_slist_foreach (priv->devices,
|
||||
device_stop_and_free,
|
||||
NULL);
|
||||
g_slist_free (priv->devices);
|
||||
while (g_slist_length (priv->devices))
|
||||
nm_manager_remove_device (manager, NM_DEVICE (priv->devices->data));
|
||||
|
||||
G_OBJECT_CLASS (nm_manager_parent_class)->finalize (object);
|
||||
}
|
||||
@@ -283,6 +273,7 @@ nm_manager_remove_device (NMManager *manager, NMDevice *device)
|
||||
|
||||
g_signal_handlers_disconnect_by_func (device, manager_device_state_changed, manager);
|
||||
|
||||
nm_device_bring_down (device, FALSE);
|
||||
manager_device_removed (manager, device);
|
||||
g_object_unref (device);
|
||||
break;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
SUBDIRS=test-common libnm-util
|
||||
|
||||
INCLUDES = -I${top_srcdir} \
|
||||
-I${top_srcdir}/libnm-glib \
|
||||
-I${top_srcdir}/gnome/libnm_glib \
|
||||
-I${top_srcdir}/utils \
|
||||
-I${top_srcdir}/include
|
||||
@@ -23,7 +24,7 @@ noinst_PROGRAMS = nm-tool \
|
||||
|
||||
nm_tool_SOURCES = nm-tool.c
|
||||
nm_tool_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \
|
||||
$(top_builddir)/utils/libnmutils.la
|
||||
$(top_builddir)/libnm-glib/libnm-glib.la
|
||||
|
||||
nm_online_SOURCES = nm-online.c
|
||||
nm_online_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \
|
||||
|
476
test/nm-tool.c
476
test/nm-tool.c
@@ -28,40 +28,27 @@
|
||||
|
||||
#include <iwlib.h>
|
||||
|
||||
#include "NetworkManager.h"
|
||||
#include "nm-utils.h"
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <nm-client.h>
|
||||
#include <nm-device.h>
|
||||
#include <nm-device-802-3-ethernet.h>
|
||||
#include <nm-device-802-11-wireless.h>
|
||||
|
||||
|
||||
static gboolean get_nm_state (DBusConnection *connection)
|
||||
|
||||
static gboolean
|
||||
get_nm_state (NMClient *client)
|
||||
{
|
||||
dbus_uint32_t uint32_state;
|
||||
char * state_string = NULL;
|
||||
NMState state;
|
||||
char *state_string;
|
||||
gboolean success = TRUE;
|
||||
DBusMessage * message = NULL;
|
||||
DBusMessage * reply = NULL;
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state")))
|
||||
{
|
||||
fprintf (stderr, "get_nm_state(): couldn't create new dbus message.\n");
|
||||
return FALSE;
|
||||
}
|
||||
state = nm_client_get_state (client);
|
||||
|
||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, NULL);
|
||||
dbus_message_unref (message);
|
||||
if (!reply)
|
||||
{
|
||||
fprintf (stderr, "get_nm_state(): didn't get a reply from NetworkManager.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &uint32_state, DBUS_TYPE_INVALID))
|
||||
{
|
||||
fprintf (stderr, "get_nm_state(): unexpected reply from NetworkManager.\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch ((NMState) uint32_state)
|
||||
{
|
||||
switch (state) {
|
||||
case NM_STATE_ASLEEP:
|
||||
state_string = "asleep";
|
||||
break;
|
||||
@@ -84,12 +71,14 @@ static gboolean get_nm_state (DBusConnection *connection)
|
||||
success = FALSE;
|
||||
break;
|
||||
}
|
||||
|
||||
printf ("State: %s\n\n", state_string);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
static void print_string (const char *label, const char *data)
|
||||
static void
|
||||
print_string (const char *label, const char *data)
|
||||
{
|
||||
#define SPACING 18
|
||||
int label_len = 0;
|
||||
@@ -110,223 +99,118 @@ static void print_string (const char *label, const char *data)
|
||||
}
|
||||
|
||||
|
||||
static void detail_network (DBusConnection *connection, const char *path, const char *active_path)
|
||||
static void
|
||||
detail_network (gpointer data, gpointer user_data)
|
||||
{
|
||||
DBusMessage * message = NULL;
|
||||
DBusMessage * reply = NULL;
|
||||
const char * op = NULL;
|
||||
const char * essid = NULL;
|
||||
const char * hw_addr = NULL;
|
||||
dbus_int32_t strength = -1;
|
||||
double freq = 0;
|
||||
dbus_int32_t rate = 0;
|
||||
dbus_int32_t capabilities = NM_802_11_CAP_NONE;
|
||||
dbus_uint32_t mode = 0;
|
||||
gboolean broadcast = TRUE;
|
||||
NMAccessPoint *ap = NM_ACCESS_POINT (data);
|
||||
const char *active_bssid = (const char *) user_data;
|
||||
GString *str;
|
||||
gboolean active = FALSE;
|
||||
guint32 capabilities;
|
||||
char *essid;
|
||||
char *tmp;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
capabilities = nm_access_point_get_capabilities (ap);
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICE, "getProperties")))
|
||||
{
|
||||
fprintf (stderr, "detail_network(): couldn't create new dbus message.\n");
|
||||
return;
|
||||
if (active_bssid) {
|
||||
char *current_bssid = nm_access_point_get_hw_address (ap);
|
||||
if (current_bssid && !strcmp (current_bssid, active_bssid))
|
||||
active = TRUE;
|
||||
|
||||
g_free (current_bssid);
|
||||
}
|
||||
|
||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, NULL);
|
||||
dbus_message_unref (message);
|
||||
if (!reply)
|
||||
{
|
||||
fprintf (stderr, "detail_network(): didn't get a reply from NetworkManager for device %s.\n", path);
|
||||
return;
|
||||
}
|
||||
str = g_string_new (NULL);
|
||||
g_string_append_printf (str,
|
||||
"%s Mode, Freq %.3f MHz, Rate %d Mb/s, Strength %d",
|
||||
(nm_access_point_get_mode (ap) == IW_MODE_INFRA) ? "Infrastructure" : "Ad-Hoc",
|
||||
nm_access_point_get_frequency (ap) / 1000000000,
|
||||
nm_access_point_get_rate (ap) / 1024,
|
||||
nm_access_point_get_strength (ap));
|
||||
|
||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &op,
|
||||
DBUS_TYPE_STRING, &essid,
|
||||
DBUS_TYPE_STRING, &hw_addr,
|
||||
DBUS_TYPE_INT32, &strength,
|
||||
DBUS_TYPE_DOUBLE, &freq,
|
||||
DBUS_TYPE_INT32, &rate,
|
||||
DBUS_TYPE_INT32, &mode,
|
||||
DBUS_TYPE_INT32, &capabilities,
|
||||
DBUS_TYPE_BOOLEAN, &broadcast,
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
char *temp = NULL;
|
||||
char *temp_essid = NULL;
|
||||
float flt_freq = freq / 1000000000;
|
||||
gboolean active = (active_path && !strcmp (active_path, path)) ? TRUE : FALSE;
|
||||
GString *enc_string = g_string_new (NULL);
|
||||
if (nm_access_point_is_encrypted (ap))
|
||||
g_string_append (str, ", Encrypted: ");
|
||||
|
||||
if (capabilities & NM_802_11_CAP_PROTO_WEP)
|
||||
enc_string = g_string_append (enc_string, "WEP");
|
||||
g_string_append (str, " WEP");
|
||||
if (capabilities & NM_802_11_CAP_PROTO_WPA)
|
||||
{
|
||||
if (enc_string->str && (strlen (enc_string->str) > 0))
|
||||
enc_string = g_string_append_c (enc_string, ' ');
|
||||
enc_string = g_string_append (enc_string, "WPA");
|
||||
}
|
||||
g_string_append (str, " WPA");
|
||||
if (capabilities & NM_802_11_CAP_PROTO_WPA2)
|
||||
{
|
||||
if (enc_string->str && (strlen (enc_string->str) > 0))
|
||||
enc_string = g_string_append_c (enc_string, ' ');
|
||||
enc_string = g_string_append (enc_string, "WPA2");
|
||||
}
|
||||
g_string_append (str, " WPA2");
|
||||
if (capabilities & NM_802_11_CAP_KEY_MGMT_802_1X)
|
||||
{
|
||||
if (enc_string->str && (strlen (enc_string->str) > 0))
|
||||
enc_string = g_string_append_c (enc_string, ' ');
|
||||
enc_string = g_string_append (enc_string, "Enterprise");
|
||||
}
|
||||
if (enc_string->str && (strlen (enc_string->str) > 0))
|
||||
{
|
||||
enc_string = g_string_prepend (enc_string, ", Encrypted (");
|
||||
enc_string = g_string_append (enc_string, ")");
|
||||
g_string_append (str, " Enterprise");
|
||||
|
||||
/* FIXME: broadcast/hidden */
|
||||
|
||||
essid = nm_access_point_get_essid (ap);
|
||||
tmp = g_strdup_printf (" %s%s", active ? "*" : "", essid);
|
||||
g_free (essid);
|
||||
|
||||
print_string (tmp, str->str);
|
||||
|
||||
g_string_free (str, TRUE);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
temp = g_strdup_printf ("%s Mode, Freq %.3f MHz, Rate %d Mb/s, Strength %d%%%s%s",
|
||||
(mode == IW_MODE_INFRA) ? "Infrastructure" : "Ad-Hoc",
|
||||
flt_freq,
|
||||
rate / 1024,
|
||||
strength,
|
||||
(enc_string && strlen (enc_string->str)) ? enc_string->str : "",
|
||||
!broadcast ? ", Hidden" : "");
|
||||
temp_essid = g_strdup_printf (" %s%s", active ? "*" : "", essid);
|
||||
print_string (temp_essid, temp);
|
||||
g_string_free (enc_string, TRUE);
|
||||
g_free (temp_essid);
|
||||
g_free (temp);
|
||||
}
|
||||
else
|
||||
fprintf (stderr, "detail_network(): unexpected reply from NetworkManager for device %s.\n", path);
|
||||
static gchar *
|
||||
ip4_address_as_string (guint32 ip)
|
||||
{
|
||||
struct in_addr tmp_addr;
|
||||
gchar *ip_string;
|
||||
|
||||
dbus_message_unref (reply);
|
||||
tmp_addr.s_addr = ip;
|
||||
ip_string = inet_ntoa (tmp_addr);
|
||||
|
||||
return g_strdup (ip_string);
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
get_driver_name (DBusConnection *connection, const char *path)
|
||||
static void
|
||||
detail_device (gpointer data, gpointer user_data)
|
||||
{
|
||||
DBusMessage * message;
|
||||
DBusMessage * reply;
|
||||
char * driver = NULL;
|
||||
DBusError error;
|
||||
NMDevice *device = NM_DEVICE (data);
|
||||
char *tmp;
|
||||
NMDeviceState state;
|
||||
int caps;
|
||||
int speed;
|
||||
GArray *array;
|
||||
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
state = nm_device_get_state (device);
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICE, "getDriver")))
|
||||
{
|
||||
nm_warning ("%s(): Couldn't allocate the dbus message", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dbus_error_init (&error);
|
||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
||||
dbus_message_unref (message);
|
||||
if (dbus_error_is_set (&error))
|
||||
dbus_error_free (&error);
|
||||
else if (reply)
|
||||
{
|
||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &driver, DBUS_TYPE_INVALID))
|
||||
driver = g_strdup (driver);
|
||||
dbus_message_unref (reply);
|
||||
}
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
|
||||
static void detail_device (DBusConnection *connection, const char *path)
|
||||
{
|
||||
DBusMessage * message = NULL;
|
||||
DBusMessage * reply = NULL;
|
||||
char * op = NULL;
|
||||
const char * iface = NULL;
|
||||
dbus_uint32_t type = 0;
|
||||
const char * udi = NULL;
|
||||
dbus_bool_t active = FALSE;
|
||||
const char * ip4_address = NULL;
|
||||
const char * broadcast = NULL;
|
||||
const char * subnetmask = NULL;
|
||||
const char * hw_addr = NULL;
|
||||
const char * route = NULL;
|
||||
const char * primary_dns = NULL;
|
||||
const char * secondary_dns = NULL;
|
||||
dbus_uint32_t mode = 0;
|
||||
dbus_int32_t strength = -1;
|
||||
char * active_network_path = NULL;
|
||||
dbus_bool_t link_active = FALSE;
|
||||
dbus_int32_t speed = 0;
|
||||
dbus_uint32_t caps = NM_DEVICE_CAP_NONE;
|
||||
dbus_uint32_t type_caps = NM_DEVICE_CAP_NONE;
|
||||
char ** networks = NULL;
|
||||
int num_networks = 0;
|
||||
NMActStage act_stage = NM_ACT_STAGE_UNKNOWN;
|
||||
|
||||
g_return_if_fail (connection != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE_DEVICE, "getProperties")))
|
||||
{
|
||||
fprintf (stderr, "detail_device(): couldn't create new dbus message.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, NULL);
|
||||
dbus_message_unref (message);
|
||||
if (!reply)
|
||||
{
|
||||
fprintf (stderr, "detail_device(): didn't get a reply from NetworkManager for device %s.\n", path);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &op,
|
||||
DBUS_TYPE_STRING, &iface,
|
||||
DBUS_TYPE_UINT32, &type,
|
||||
DBUS_TYPE_STRING, &udi,
|
||||
DBUS_TYPE_BOOLEAN,&active,
|
||||
DBUS_TYPE_UINT32, &act_stage,
|
||||
DBUS_TYPE_STRING, &ip4_address,
|
||||
DBUS_TYPE_STRING, &subnetmask,
|
||||
DBUS_TYPE_STRING, &broadcast,
|
||||
DBUS_TYPE_STRING, &hw_addr,
|
||||
DBUS_TYPE_STRING, &route,
|
||||
DBUS_TYPE_STRING, &primary_dns,
|
||||
DBUS_TYPE_STRING, &secondary_dns,
|
||||
DBUS_TYPE_INT32, &mode,
|
||||
DBUS_TYPE_INT32, &strength,
|
||||
DBUS_TYPE_BOOLEAN,&link_active,
|
||||
DBUS_TYPE_INT32, &speed,
|
||||
DBUS_TYPE_UINT32, &caps,
|
||||
DBUS_TYPE_UINT32, &type_caps,
|
||||
DBUS_TYPE_STRING, &active_network_path,
|
||||
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &networks, &num_networks,
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
char * driver;
|
||||
|
||||
printf ("- Device: %s ----------------------------------------------------------------\n", iface);
|
||||
tmp = nm_device_get_iface (device);
|
||||
printf ("- Device: %s ----------------------------------------------------------------\n", tmp);
|
||||
g_free (tmp);
|
||||
|
||||
/* General information */
|
||||
print_string ("NM Path", op);
|
||||
if (type == DEVICE_TYPE_802_11_WIRELESS)
|
||||
print_string ("Type", "802.11 Wireless");
|
||||
else if (type == DEVICE_TYPE_802_3_ETHERNET)
|
||||
if (NM_IS_DEVICE_802_3_ETHERNET (device))
|
||||
print_string ("Type", "Wired");
|
||||
else if (NM_IS_DEVICE_802_11_WIRELESS (device))
|
||||
print_string ("Type", "802.11 Wireless");
|
||||
|
||||
if ((driver = get_driver_name (connection, path)))
|
||||
print_string ("Driver", driver);
|
||||
else
|
||||
tmp = nm_device_get_driver (device);
|
||||
if (tmp) {
|
||||
print_string ("Driver", tmp);
|
||||
g_free (tmp);
|
||||
} else
|
||||
print_string ("Driver", "(unknown)");
|
||||
|
||||
if (active)
|
||||
if (state == NM_DEVICE_STATE_ACTIVATED)
|
||||
print_string ("Active", "yes");
|
||||
else
|
||||
print_string ("Active", "no");
|
||||
|
||||
print_string ("HW Address", hw_addr);
|
||||
tmp = NULL;
|
||||
if (NM_IS_DEVICE_802_3_ETHERNET (device))
|
||||
tmp = nm_device_802_3_ethernet_get_hw_address (NM_DEVICE_802_3_ETHERNET (device));
|
||||
else if (NM_IS_DEVICE_802_11_WIRELESS (device))
|
||||
tmp = nm_device_802_11_wireless_get_hw_address (NM_DEVICE_802_11_WIRELESS (device));
|
||||
|
||||
if (tmp) {
|
||||
print_string ("HW Address", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
/* Capabilities */
|
||||
caps = nm_device_get_capabilities (device);
|
||||
printf ("\n Capabilities:\n");
|
||||
if (caps & NM_DEVICE_CAP_NM_SUPPORTED)
|
||||
print_string (" Supported", "yes");
|
||||
@@ -335,8 +219,13 @@ static void detail_device (DBusConnection *connection, const char *path)
|
||||
if (caps & NM_DEVICE_CAP_CARRIER_DETECT)
|
||||
print_string (" Carrier Detect", "yes");
|
||||
|
||||
if (speed)
|
||||
{
|
||||
speed = 0;
|
||||
if (NM_IS_DEVICE_802_3_ETHERNET (device))
|
||||
speed = nm_device_802_3_ethernet_get_speed (NM_DEVICE_802_3_ETHERNET (device));
|
||||
else if (NM_IS_DEVICE_802_11_WIRELESS (device))
|
||||
speed = nm_device_802_11_wireless_get_bitrate (NM_DEVICE_802_11_WIRELESS (device));
|
||||
|
||||
if (speed) {
|
||||
char *speed_string;
|
||||
|
||||
speed_string = g_strdup_printf ("%d Mb/s", speed);
|
||||
@@ -345,140 +234,121 @@ static void detail_device (DBusConnection *connection, const char *path)
|
||||
}
|
||||
|
||||
/* Wireless specific information */
|
||||
if (type == DEVICE_TYPE_802_11_WIRELESS)
|
||||
{
|
||||
int i;
|
||||
if ((NM_IS_DEVICE_802_11_WIRELESS (device))) {
|
||||
guint32 wireless_caps;
|
||||
NMAccessPoint *active_ap;
|
||||
char *active_bssid;
|
||||
GSList *networks;
|
||||
|
||||
printf ("\n Wireless Settings\n");
|
||||
|
||||
if (caps & NM_DEVICE_CAP_WIRELESS_SCAN)
|
||||
print_string (" Scanning", "yes");
|
||||
|
||||
if (type_caps & NM_802_11_CAP_PROTO_WEP)
|
||||
wireless_caps = nm_device_802_11_wireless_get_capabilities (NM_DEVICE_802_11_WIRELESS (device));
|
||||
|
||||
if (wireless_caps & NM_802_11_CAP_PROTO_WEP)
|
||||
print_string (" WEP Encryption", "yes");
|
||||
if (type_caps & NM_802_11_CAP_PROTO_WPA)
|
||||
if (wireless_caps & NM_802_11_CAP_PROTO_WPA)
|
||||
print_string (" WPA Encryption", "yes");
|
||||
if (type_caps & NM_802_11_CAP_PROTO_WPA2)
|
||||
if (wireless_caps & NM_802_11_CAP_PROTO_WPA2)
|
||||
print_string (" WPA2 Encryption", "yes");
|
||||
|
||||
/*
|
||||
printf ("\n Wireless Settings\n");
|
||||
if (mode == IW_MODE_INFRA)
|
||||
print_string (" Mode", "Infrastructure");
|
||||
else if (mode == IW_MODE_ADHOC)
|
||||
print_string (" Mode", "Ad-Hoc");
|
||||
str_strength = g_strdup_printf ("%d%%", strength);
|
||||
print_string (" Strength", str_strength);
|
||||
g_free (str_strength);
|
||||
*/
|
||||
active_ap = nm_device_802_11_wireless_get_active_network (NM_DEVICE_802_11_WIRELESS (device));
|
||||
active_bssid = active_ap ? nm_access_point_get_hw_address (active_ap) : NULL;
|
||||
|
||||
printf ("\n Wireless Networks (* = Current Network)\n");
|
||||
for (i = 0; i < num_networks; i++)
|
||||
detail_network (connection, networks[i], active_network_path);
|
||||
}
|
||||
else if (type == DEVICE_TYPE_802_3_ETHERNET)
|
||||
{
|
||||
printf ("\n Wireless Networks%s\n", active_ap ? "(* = Current Network)" : "");
|
||||
|
||||
networks = nm_device_802_11_wireless_get_networks (NM_DEVICE_802_11_WIRELESS (device));
|
||||
g_slist_foreach (networks, detail_network, active_bssid);
|
||||
g_free (active_bssid);
|
||||
g_slist_free (networks);
|
||||
} else if (NM_IS_DEVICE_802_3_ETHERNET (device)) {
|
||||
printf ("\n Wired Settings\n");
|
||||
/* FIXME */
|
||||
#if 0
|
||||
if (link_active)
|
||||
print_string (" Hardware Link", "yes");
|
||||
else
|
||||
print_string (" Hardware Link", "no");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* IP Setup info */
|
||||
if (active)
|
||||
{
|
||||
if (state == NM_DEVICE_STATE_ACTIVATED) {
|
||||
NMIP4Config *cfg = nm_device_get_ip4_config (device);
|
||||
|
||||
printf ("\n IP Settings:\n");
|
||||
print_string (" IP Address", ip4_address);
|
||||
print_string (" Subnet Mask", subnetmask);
|
||||
print_string (" Broadcast", broadcast);
|
||||
print_string (" Gateway", route);
|
||||
print_string (" Primary DNS", primary_dns);
|
||||
print_string (" Secondary DNS", secondary_dns);
|
||||
}
|
||||
|
||||
tmp = ip4_address_as_string (nm_ip4_config_get_address (cfg));
|
||||
print_string (" IP Address", tmp);
|
||||
g_free (tmp);
|
||||
|
||||
printf ("\n\n");
|
||||
dbus_free_string_array (networks);
|
||||
}
|
||||
else
|
||||
fprintf (stderr, "detail_device(): unexpected reply from NetworkManager for device %s.\n", path);
|
||||
tmp = ip4_address_as_string (nm_ip4_config_get_netmask (cfg));
|
||||
print_string (" Subnet Mask", tmp);
|
||||
g_free (tmp);
|
||||
|
||||
dbus_message_unref (reply);
|
||||
}
|
||||
tmp = ip4_address_as_string (nm_ip4_config_get_broadcast (cfg));
|
||||
print_string (" Broadcast", tmp);
|
||||
g_free (tmp);
|
||||
|
||||
tmp = ip4_address_as_string (nm_ip4_config_get_gateway (cfg));
|
||||
print_string (" Gateway", tmp);
|
||||
g_free (tmp);
|
||||
|
||||
static void print_devices (DBusConnection *connection)
|
||||
{
|
||||
DBusMessage * message = NULL;
|
||||
DBusMessage * reply = NULL;
|
||||
DBusError error;
|
||||
char ** paths = NULL;
|
||||
int num = -1;
|
||||
array = nm_ip4_config_get_nameservers (cfg);
|
||||
if (array) {
|
||||
int i;
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDevices")))
|
||||
{
|
||||
fprintf (stderr, "print_devices(): couldn't create new dbus message.\n");
|
||||
return;
|
||||
for (i = 0; i < array->len; i++) {
|
||||
tmp = ip4_address_as_string (g_array_index (array, guint32, i));
|
||||
print_string (" DNS", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
dbus_error_init (&error);
|
||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
||||
dbus_message_unref (message);
|
||||
if (!reply)
|
||||
{
|
||||
fprintf (stderr, "print_devices(): didn't get a reply from NetworkManager.\n");
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
if (dbus_error_has_name (&error, NM_DBUS_NO_DEVICES_ERROR))
|
||||
fprintf (stderr, "There are no available network devices.\n");
|
||||
}
|
||||
else
|
||||
fprintf (stderr, "print_devices(): NetworkManager returned an error: '%s'\n", error.message);
|
||||
return;
|
||||
g_array_free (array, TRUE);
|
||||
}
|
||||
|
||||
if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH, &paths, &num, DBUS_TYPE_INVALID))
|
||||
{
|
||||
fprintf (stderr, "print_devices(): unexpected reply from NetworkManager.\n");
|
||||
dbus_message_unref (reply);
|
||||
return;
|
||||
g_object_unref (cfg);
|
||||
}
|
||||
|
||||
for (i = 0; i < num; i++)
|
||||
detail_device (connection, paths[i]);
|
||||
|
||||
dbus_free_string_array (paths);
|
||||
dbus_message_unref (reply);
|
||||
printf ("\n\n");
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
static void
|
||||
print_devices (NMClient *client)
|
||||
{
|
||||
DBusConnection *connection;
|
||||
DBusError error;
|
||||
GSList *devices;
|
||||
|
||||
devices = nm_client_get_devices (client);
|
||||
g_slist_foreach (devices, detail_device, NULL);
|
||||
g_slist_free (devices);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
NMClient *client;
|
||||
|
||||
g_type_init ();
|
||||
|
||||
dbus_error_init (&error);
|
||||
connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
|
||||
if (connection == NULL)
|
||||
{
|
||||
fprintf (stderr, "Error connecting to system bus: %s\n", error.message);
|
||||
dbus_error_free (&error);
|
||||
return 1;
|
||||
client = nm_client_new ();
|
||||
if (!client) {
|
||||
exit (1);
|
||||
}
|
||||
|
||||
printf ("\nNetworkManager Tool\n\n");
|
||||
|
||||
if (!get_nm_state (connection))
|
||||
{
|
||||
if (!get_nm_state (client)) {
|
||||
fprintf (stderr, "\n\nNetworkManager appears not to be running (could not get its state).\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
print_devices (connection);
|
||||
print_devices (client);
|
||||
|
||||
g_object_unref (client);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user