Add option for selecting WiFi/Supplicant driver from command line
[connman] / plugins / iospm.c
index b9d657d..af6250b 100644 (file)
 #define CONNMAN_API_SUBJECT_TO_CHANGE
 #include <connman/plugin.h>
 #include <connman/notifier.h>
+#include <connman/dbus.h>
 #include <connman/log.h>
 
+#define IOSPM_SERVICE          "com.intel.mid.ospm"
+#define IOSPM_INTERFACE                IOSPM_SERVICE ".Comms"
+
+#define IOSPM_BLUETOOTH                "/com/intel/mid/ospm/bluetooth"
+#define IOSPM_FLIGHT_MODE      "/com/intel/mid/ospm/flight_mode"
+
+static DBusConnection *connection;
+
+static void send_indication(const char *path, connman_bool_t enabled)
+{
+       DBusMessage *message;
+       const char *method;
+
+       DBG("path %s enabled %d", path, enabled);
+
+       if (enabled == TRUE)
+               method = "IndicateStart";
+       else
+               method = "IndicateStop";
+
+       message = dbus_message_new_method_call(IOSPM_SERVICE, path,
+                                               IOSPM_INTERFACE, method);
+       if (message == NULL)
+               return;
+
+       dbus_message_set_no_reply(message, TRUE);
+
+       dbus_connection_send(connection, message, NULL);
+
+       dbus_message_unref(message);
+}
+
+static void iospm_device_enabled(enum connman_device_type type,
+                                               connman_bool_t enabled)
+{
+       switch (type) {
+       case CONNMAN_DEVICE_TYPE_UNKNOWN:
+       case CONNMAN_DEVICE_TYPE_VENDOR:
+       case CONNMAN_DEVICE_TYPE_ETHERNET:
+       case CONNMAN_DEVICE_TYPE_WIFI:
+       case CONNMAN_DEVICE_TYPE_WIMAX:
+       case CONNMAN_DEVICE_TYPE_GPS:
+       case CONNMAN_DEVICE_TYPE_HSO:
+       case CONNMAN_DEVICE_TYPE_NOZOMI:
+       case CONNMAN_DEVICE_TYPE_HUAWEI:
+       case CONNMAN_DEVICE_TYPE_NOVATEL:
+               break;
+       case CONNMAN_DEVICE_TYPE_BLUETOOTH:
+               send_indication(IOSPM_BLUETOOTH, enabled);
+               break;
+       }
+}
+
+static void iospm_offline_mode(connman_bool_t enabled)
+{
+       send_indication(IOSPM_FLIGHT_MODE, enabled);
+}
+
 static struct connman_notifier iospm_notifier = {
        .name           = "iospm",
        .priority       = CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
+       .device_enabled = iospm_device_enabled,
+       .offline_mode   = iospm_offline_mode,
 };
 
 static int iospm_init(void)
 {
+       connection = connman_dbus_get_connection();
+
        return connman_notifier_register(&iospm_notifier);
 }
 
 static void iospm_exit(void)
 {
        connman_notifier_unregister(&iospm_notifier);
+
+       dbus_connection_unref(connection);
 }
 
 CONNMAN_PLUGIN_DEFINE(ospm, "Intel OSPM notification plugin", VERSION,