mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 02:30:08 +01:00
Move the 'carrier' property from NMDevice to NMDevice8023Ethernet; convert the libnm-glib NMDevice8023Ethernet to cached properties * introspection/nm-device-802-3-ethernet.xml - New 'Carrier' property - New 'PropertiesChanged' signal * introspection/nm-device.xml - Remove 'Carrier' property - Remove 'CarrierChanged' signal * src/nm-device-interface.c src/nm-device-interface.h - (nm_device_interface_init): remove 'carrier' property and 'carrier-changed' signal * src/nm-device.c src/nm-device.h - (nm_device_get_carrier, nm_device_set_carrier): remove - (nm_device_activate_stage5_ip_config_commit): don't bother updating the link here; wired device will handle that - (handle_dhcp_lease_change): don't bother updating link here - (get_property, nm_device_class_init): remove carrier property * src/nm-device-802-11-wireless.c - (real_update_link, nm_device_802_11_wireless_class_init): remove real_update_link(); wireless devices don't use carrier at all - (link_timeout_cb, supplicant_iface_state_cb_handler, supplicant_iface_connection_state_cb_handler, supplicant_mgr_state_cb_handler): remove anything to do with carrier * src/nm-device-802-3-ethernet.c src/nm-device-802-3-ethernet.h - (nm_device_802_3_ethernet_carrier_on, nm_device_802_3_ethernet_carrier_off, constructor): use set_carrier() instead of nm_device_set_carrier() - (device_state_changed): update link from sysfs on activation; replaces real_update_link() - (real_update_link): remove, replaced by device_state_changed() - (nm_device_802_3_ethernet_get_carrier, set_carrier): new functions - (nm_device_802_3_ethernet_get_speed): move up with other getters/setters - (real_get_generic_capabilities, real_can_interrupt_activation): use new get_carrier function - (get_property): add 'carrier' property - (nm_device_802_3_ethernet_class_init): add 'carrier' property and hook into property-changed signal helper * src/NetworkManagerPolicy.c - (device_carrier_changed): will only ever be called with a wired device - (device_added): only hook up to carrier-changed for wired devices * libnm-glib/nm-device.c libnm-glib/nm-device.h - (constructor, nm_device_class_init): remove carrier-changed signal - (device_carrier_changed_proxy): remove; unused - (nm_device_get_carrier): remove; carrier a property of wired devices * libnm-glib/nm-device-802-3-ethernet.c libnm-glib/nm-device-802-3-ethernet.h - Convert to cached properties like AP and Wireless objects - (nm_device_802_3_ethernet_get_hw_address): now returns a 'const char *' instead of a 'char *', return value should not be freed - (nm_device_802_3_ethernet_get_carrier): return current carrier status - (constructor): hook into properties-changed helper - (set_property, get_property): new functions - (nm_device_802_3_ethernet_class_init): export GObject properties * test/nm-tool.c - (detail_device): strdup the wired hardware address too since it's cached now * libnm-glib/libnm-glib-test.c - (dump_wired): strdup the wired hardware address too since it's cached now git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3428 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
318 lines
6.9 KiB
C
318 lines
6.9 KiB
C
#include <stdlib.h>
|
|
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <iwlib.h>
|
|
#include <wireless.h>
|
|
|
|
#include "nm-client.h"
|
|
#include "nm-device.h"
|
|
#include "nm-device-802-3-ethernet.h"
|
|
#include "nm-device-802-11-wireless.h"
|
|
#include "nm-utils.h"
|
|
|
|
#if 0
|
|
static gboolean
|
|
test_wireless_enabled (NMClient *client)
|
|
{
|
|
gboolean wireless;
|
|
|
|
wireless = nm_client_wireless_get_enabled (client);
|
|
g_print ("Wireless enabled? %s\n", wireless ? "yes" : "no");
|
|
|
|
nm_client_wireless_set_enabled (client, !wireless);
|
|
|
|
wireless = nm_client_wireless_get_enabled (client);
|
|
g_print ("Wireless enabled? %s\n", wireless ? "yes" : "no");
|
|
|
|
nm_client_wireless_set_enabled (client, !wireless);
|
|
|
|
return TRUE;
|
|
}
|
|
#endif
|
|
|
|
static gboolean
|
|
test_get_state (NMClient *client)
|
|
{
|
|
guint state;
|
|
|
|
state = nm_client_get_state (client);
|
|
g_print ("Current state: %d\n", state);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static gchar *
|
|
ip4_address_as_string (guint32 ip)
|
|
{
|
|
struct in_addr tmp_addr;
|
|
gchar *ip_string;
|
|
|
|
tmp_addr.s_addr = ip;
|
|
ip_string = inet_ntoa (tmp_addr);
|
|
|
|
return g_strdup (ip_string);
|
|
}
|
|
|
|
static void
|
|
dump_ip4_config (NMIP4Config *cfg)
|
|
{
|
|
char *tmp;
|
|
GArray *array;
|
|
char **ptr_array;
|
|
int i;
|
|
|
|
tmp = ip4_address_as_string (nm_ip4_config_get_address (cfg));
|
|
g_print ("IP4 address: %s\n", tmp);
|
|
g_free (tmp);
|
|
|
|
tmp = ip4_address_as_string (nm_ip4_config_get_gateway (cfg));
|
|
g_print ("IP4 gateway: %s\n", tmp);
|
|
g_free (tmp);
|
|
|
|
tmp = ip4_address_as_string (nm_ip4_config_get_netmask (cfg));
|
|
g_print ("IP4 netmask: %s\n", tmp);
|
|
g_free (tmp);
|
|
|
|
tmp = ip4_address_as_string (nm_ip4_config_get_broadcast (cfg));
|
|
g_print ("IP4 broadcast: %s\n", tmp);
|
|
g_free (tmp);
|
|
|
|
tmp = nm_ip4_config_get_hostname (cfg);
|
|
g_print ("IP4 hostname: %s\n", tmp);
|
|
g_free (tmp);
|
|
|
|
array = nm_ip4_config_get_nameservers (cfg);
|
|
if (array) {
|
|
g_print ("IP4 DNS:\n");
|
|
for (i = 0; i < array->len; i++) {
|
|
tmp = ip4_address_as_string (g_array_index (array, guint32, i));
|
|
g_print ("\t%s\n", tmp);
|
|
g_free (tmp);
|
|
}
|
|
|
|
g_array_free (array, TRUE);
|
|
}
|
|
|
|
ptr_array = nm_ip4_config_get_domains (cfg);
|
|
if (ptr_array) {
|
|
g_print ("IP4 domains:\n");
|
|
for (i = 0; ptr_array[i]; i++) {
|
|
g_print ("\t%s\n", ptr_array[i]);
|
|
}
|
|
|
|
g_strfreev (ptr_array);
|
|
}
|
|
|
|
tmp = nm_ip4_config_get_nis_domain (cfg);
|
|
g_print ("IP4 NIS domain: %s\n", tmp);
|
|
g_free (tmp);
|
|
|
|
array = nm_ip4_config_get_nis_servers (cfg);
|
|
if (array) {
|
|
g_print ("IP4 NIS servers:\n");
|
|
for (i = 0; i < array->len; i++) {
|
|
tmp = ip4_address_as_string (g_array_index (array, guint32, i));
|
|
g_print ("\t%s\n", tmp);
|
|
g_free (tmp);
|
|
}
|
|
|
|
g_array_free (array, TRUE);
|
|
}
|
|
}
|
|
|
|
static void
|
|
dump_access_point (NMAccessPoint *ap)
|
|
{
|
|
const GByteArray * ssid;
|
|
const char * str;
|
|
|
|
ssid = nm_access_point_get_ssid (ap);
|
|
g_print ("\tSsid: %s\n",
|
|
ssid ? nm_utils_escape_ssid (ssid->data, ssid->len) : "(none)");
|
|
|
|
str = nm_access_point_get_hw_address (ap);
|
|
g_print ("\tMAC Address: %s\n", str);
|
|
|
|
g_print ("\tFlags: 0x%X\n", nm_access_point_get_flags (ap));
|
|
g_print ("\tWPA Flags: 0x%X\n", nm_access_point_get_wpa_flags (ap));
|
|
g_print ("\tRSN Flags: 0x%X\n", nm_access_point_get_rsn_flags (ap));
|
|
g_print ("\tFrequency: %u\n", nm_access_point_get_frequency (ap));
|
|
|
|
g_print ("\tMode: %d\n", nm_access_point_get_mode (ap));
|
|
g_print ("\tRate: %d\n", nm_access_point_get_rate (ap));
|
|
g_print ("\tStrength: %d\n", nm_access_point_get_strength (ap));
|
|
}
|
|
|
|
static void
|
|
dump_wireless (NMDevice80211Wireless *device)
|
|
{
|
|
const char *str;
|
|
GSList *iter;
|
|
GSList *aps;
|
|
|
|
g_print ("Mode: %d\n", nm_device_802_11_wireless_get_mode (device));
|
|
g_print ("Bitrate: %d\n", nm_device_802_11_wireless_get_bitrate (device));
|
|
|
|
str = nm_device_802_11_wireless_get_hw_address (device);
|
|
g_print ("MAC: %s\n", str);
|
|
|
|
g_print ("AccessPoints:\n");
|
|
aps = nm_device_802_11_wireless_get_access_points (device);
|
|
for (iter = aps; iter; iter = iter->next) {
|
|
dump_access_point (NM_ACCESS_POINT (iter->data));
|
|
g_print ("\n");
|
|
}
|
|
|
|
g_slist_foreach (aps, (GFunc) g_object_unref, NULL);
|
|
g_slist_free (aps);
|
|
}
|
|
|
|
static void
|
|
dump_wired (NMDevice8023Ethernet *device)
|
|
{
|
|
const char *str;
|
|
|
|
g_print ("Speed: %d\n", nm_device_802_3_ethernet_get_speed (device));
|
|
|
|
str = nm_device_802_3_ethernet_get_hw_address (device);
|
|
g_print ("MAC: %s\n", str);
|
|
}
|
|
|
|
static void
|
|
dump_device (NMDevice *device)
|
|
{
|
|
char *str;
|
|
guint32 u;
|
|
NMDeviceState state;
|
|
|
|
str = nm_device_get_iface (device);
|
|
g_print ("Interface: %s\n", str);
|
|
g_free (str);
|
|
|
|
str = nm_device_get_udi (device);
|
|
g_print ("Udi: %s\n", str);
|
|
g_free (str);
|
|
|
|
str = nm_device_get_driver (device);
|
|
g_print ("Driver: %s\n", str);
|
|
g_free (str);
|
|
|
|
u = nm_device_get_ip4_address (device);
|
|
g_print ("IP address: %d\n", u);
|
|
|
|
state = nm_device_get_state (device);
|
|
g_print ("State: %d\n", state);
|
|
|
|
if (state == NM_DEVICE_STATE_ACTIVATED) {
|
|
NMIP4Config *cfg = nm_device_get_ip4_config (device);
|
|
dump_ip4_config (cfg);
|
|
g_object_unref (cfg);
|
|
}
|
|
|
|
if (NM_IS_DEVICE_802_3_ETHERNET (device))
|
|
dump_wired (NM_DEVICE_802_3_ETHERNET (device));
|
|
else if (NM_IS_DEVICE_802_11_WIRELESS (device))
|
|
dump_wireless (NM_DEVICE_802_11_WIRELESS (device));
|
|
}
|
|
|
|
static gboolean
|
|
test_devices (NMClient *client)
|
|
{
|
|
GSList *list, *iter;
|
|
|
|
list = nm_client_get_devices (client);
|
|
g_print ("Got devices:\n");
|
|
for (iter = list; iter; iter = iter->next) {
|
|
NMDevice *device = NM_DEVICE (iter->data);
|
|
dump_device (device);
|
|
g_print ("\n");
|
|
}
|
|
|
|
g_slist_free (list);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static void
|
|
device_added_cb (NMClient *client, NMDevice *device, gpointer user_data)
|
|
{
|
|
g_print ("New device added\n");
|
|
dump_device (device);
|
|
}
|
|
|
|
static void
|
|
device_removed_cb (NMClient *client, NMDevice *device, gpointer user_data)
|
|
{
|
|
g_print ("Device removed\n");
|
|
dump_device (device);
|
|
}
|
|
|
|
#if 0
|
|
static gboolean
|
|
device_deactivate (gpointer user_data)
|
|
{
|
|
NMDevice *device = NM_DEVICE (user_data);
|
|
|
|
nm_device_deactivate (device);
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
static void
|
|
device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data)
|
|
{
|
|
char *str;
|
|
|
|
str = nm_device_get_iface (device);
|
|
g_print ("Device state changed: %s %d\n", str, state);
|
|
g_free (str);
|
|
|
|
if (state == NM_DEVICE_STATE_ACTIVATED) {
|
|
g_print ("Scheduling device deactivation\n");
|
|
g_timeout_add (5 * 1000,
|
|
device_deactivate,
|
|
device);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
static void
|
|
manager_running (NMClient *client, gboolean running, gpointer user_data)
|
|
{
|
|
if (running) {
|
|
g_print ("NM appeared\n");
|
|
/* test_wireless_enabled (client); */
|
|
test_get_state (client);
|
|
test_devices (client);
|
|
} else
|
|
g_print ("NM disappeared\n");
|
|
}
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
NMClient *client;
|
|
|
|
g_type_init ();
|
|
|
|
client = nm_client_new ();
|
|
if (!client) {
|
|
exit (1);
|
|
}
|
|
|
|
g_signal_connect (client, "manager-running", G_CALLBACK (manager_running), NULL);
|
|
manager_running (client, nm_client_manager_is_running (client), NULL);
|
|
|
|
g_signal_connect (client, "device-added",
|
|
G_CALLBACK (device_added_cb), NULL);
|
|
g_signal_connect (client, "device-removed",
|
|
G_CALLBACK (device_removed_cb), NULL);
|
|
|
|
g_main_loop_run (g_main_loop_new (NULL, FALSE));
|
|
|
|
g_object_unref (client);
|
|
|
|
return 0;
|
|
}
|