Hi all -- This patch adds support for HAL's new killswitch functionality. It is somewhat rudimentary and needs a bit of work (little things, nothing major), but I do not have the hardware to test the functionality. Can somebody test this? HAL should support killswitchs on Dell and VAIO laptops. Thanks! -- Benjamin Kreuter
Index: src/NetworkManager.c
===================================================================
--- src/NetworkManager.c (revision 2587)
+++ src/NetworkManager.c (working copy)
@@ -298,7 +298,79 @@
}
}
+/*
+ * nm_add_killswitch_device
+ *
+ * Adds a killswitch device to the list
+ *
+ */
+void nm_add_killswitch_device(NMData * data, char * udi)
+{
+// g_return_val_if_fail (data != NULL, NULL);
+// g_return_val_if_fail (udi != NULL, NULL);
+ /* Attempt to acquire mutex for killswitch list addition. If acquire fails,
+ * just ignore the device addition entirely.
+ */
+ if (nm_try_acquire_mutex (data->killswitch_list_mutex, __FUNCTION__))
+ {
+ data->killswitch_list = g_slist_append (data->killswitch_list, udi);
+// nm_device_deactivate (dev);
+ nm_unlock_mutex (data->killswitch_list_mutex, __FUNCTION__);
+
+// nm_policy_schedule_device_change_check (data);
+// nm_dbus_schedule_device_status_change_signal (data, dev, NULL, DEVICE_ADDED);
+ }
+ else
+ {
+ /* If we couldn't add the killswitch to our list, free its data. */
+ nm_warning ("could not acquire killswitch list mutex." );
+// g_object_unref (G_OBJECT (dev));
+// dev = NULL;
+ }
+}
+
+void nm_poll_killswitchs(gpointer _data)
+{
+ NMData * data = (NMData *)_data;
+ DBusMessage * message;
+ DBusConnection * connection = data->dbus_connection;
+ DBusError error;
+ GSList * elt;
+ NMDevice * dev;
+
+ while(1)
+ {
+// char * killswitchPower = libhal_device_get_property_string(ctx, udi, "killswitch.GetPower", NULL);
+ nm_lock_mutex (data->killswitch_list_mutex, __FUNCTION__);
+ for (elt = data->killswitch_list; elt; elt = g_slist_next (elt))
+ {
+ int status;
+ message = dbus_message_new_method_call("org.freedesktop.Hal.Device.KillSwitch", elt->data, "org.freedesktop.Hal.Device.KillSwitch", "GetPower");
+ message = dbus_connection_send_with_reply_and_block(connection, message, 500, &error);
+ if(dbus_error_is_set(&error))
+ {
+ nm_warning("Could not poll killswitch: ", error.message);
+ dbus_error_free(&error);
+ }
+ else
+ {
+ dbus_message_get_args(message, &error, DBUS_TYPE_UINT32, &status, DBUS_TYPE_INVALID);
+ if(status > 0)
+ {
+ // Switch is on, deactivate device
+ dev = nm_get_device_interface_from_hal(data->hal_ctx, elt->data);
+ nm_device_deactivate(dev);
+ }
+ }
+ }
+ nm_unlock_mutex (data->killswitch_list_mutex, __FUNCTION__);
+ g_usleep(500000);
+ }
+}
+
+GThread * polling_thread;
+
/*
* nm_add_initial_devices
*
@@ -308,7 +380,9 @@
void nm_add_initial_devices (NMData *data)
{
char ** net_devices;
+ char ** killswitchs;
int num_net_devices;
+ int num_killswitch_devices;
int i;
DBusError error;
@@ -338,6 +412,29 @@
}
libhal_free_string_array (net_devices);
+
+ /* Now, grab a list of killswitch devices... */
+ killswitchs = libhal_find_device_by_capability(data->hal_ctx, "killswitch", &num_killswitch_devices, &error);
+ if(dbus_error_is_set(&error))
+ {
+ nm_warning("could not find killswitch devices: %s", error.message);
+ dbus_error_free(&error);
+ }
+
+ if(killswitchs)
+ {
+ for(i = 0; i < num_killswitch_devices; i++)
+ {
+ char * dev;
+ if((dev = nm_get_device_interface_from_hal(data->hal_ctx, killswitchs[i])))
+ {
+ nm_add_killswitch_device(data, killswitchs[i]);
+ g_free(dev);
+ }
+ }
+ // TODO: Start polling thread...
+ polling_thread = g_thread_create(nm_poll_killswitchs, data, 0, NULL);
+ }
}
Index: src/NetworkManagerMain.h
===================================================================
--- src/NetworkManagerMain.h (revision 2587)
+++ src/NetworkManagerMain.h (working copy)
@@ -90,6 +90,10 @@
GSList * dialup_list;
GMutex * dialup_list_mutex;
+ /* Killswitch list */
+ GSList * killswitch_list;
+ GMutex * killswitch_list_mutex;
+
struct NMAccessPointList *allowed_ap_list;
struct NMAccessPointList *invalid_ap_list;
} NMData;
Attachment:
pgpBu8fFw2hdJ.pgp
Description: PGP signature