+void __connman_technology_list_struct(DBusMessageIter *array)
+{
+ GSList *list;
+ DBusMessageIter entry;
+
+ for (list = technology_list; list; list = list->next) {
+ struct connman_technology *technology = list->data;
+
+ if (technology->path == NULL)
+ continue;
+
+ dbus_message_iter_open_container(array, DBUS_TYPE_STRUCT,
+ NULL, &entry);
+ dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
+ &technology->path);
+ append_properties(&entry, technology);
+ dbus_message_iter_close_container(array, &entry);
+ }
+}
+
+static gboolean technology_pending_reply(gpointer user_data)
+{
+ struct connman_technology *technology = user_data;
+ DBusMessage *reply;
+
+ /* Power request timedout, send ETIMEDOUT. */
+ if (technology->pending_reply != NULL) {
+ reply = __connman_error_failed(technology->pending_reply, ETIMEDOUT);
+ if (reply != NULL)
+ g_dbus_send_message(connection, reply);
+
+ dbus_message_unref(technology->pending_reply);
+ technology->pending_reply = NULL;
+ technology->pending_timeout = 0;
+ }
+
+ return FALSE;
+}
+
+static int technology_enable(struct connman_technology *technology,
+ DBusMessage *msg)
+{
+ GSList *list;
+ int err = 0;
+ int ret = -ENODEV;
+ DBusMessage *reply;
+
+ DBG("technology %p enable", technology);
+
+ __sync_synchronize();
+ if (technology->enabled > 0) {
+ err = -EALREADY;
+ goto done;
+ }
+
+ if (technology->pending_reply != NULL) {
+ err = -EBUSY;
+ goto done;
+ }
+
+ if (msg != NULL) {
+ /*
+ * This is a bit of a trick. When msg is not NULL it means
+ * thats technology_enable was invoked from the manager API.
+ * Hence we save the state here.
+ */
+ technology->enable_persistent = TRUE;
+ save_state(technology);
+ }
+
+ __connman_rfkill_block(technology->type, FALSE);
+
+ /*
+ * An empty device list means that devices in the technology
+ * were rfkill blocked. The unblock above will enable the devs.
+ */
+ if (technology->device_list == NULL) {
+ ret = 0;
+ goto done;
+ }
+
+ for (list = technology->device_list; list; list = list->next) {
+ struct connman_device *device = list->data;
+
+ err = __connman_device_enable(device);
+ /*
+ * err = 0 : Device was enabled right away.
+ * If atleast one device gets enabled, we consider
+ * the technology to be enabled.
+ */
+ if (err == 0)
+ ret = 0;
+ }
+
+done:
+ if (ret == 0) {
+ if (msg != NULL)
+ g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
+ return ret;
+ }
+
+ if (msg != NULL) {
+ if (err == -EINPROGRESS) {
+ technology->pending_reply = dbus_message_ref(msg);
+ technology->pending_timeout = g_timeout_add_seconds(10,
+ technology_pending_reply, technology);
+ } else {
+ reply = __connman_error_failed(msg, -err);
+ if (reply != NULL)
+ g_dbus_send_message(connection, reply);
+ }
+ }
+
+ return err;
+}
+
+static int technology_disable(struct connman_technology *technology,
+ DBusMessage *msg)
+{
+ GSList *list;
+ int err = 0;
+ int ret = -ENODEV;
+ DBusMessage *reply;
+
+ DBG("technology %p disable", technology);
+
+ __sync_synchronize();
+ if (technology->enabled == 0) {
+ err = -EALREADY;
+ goto done;
+ }
+
+ if (technology->pending_reply != NULL) {
+ err = -EBUSY;
+ goto done;
+ }
+
+ if (technology->tethering == TRUE)
+ set_tethering(technology, FALSE);
+
+ if (msg != NULL) {
+ technology->enable_persistent = FALSE;
+ save_state(technology);
+ }
+
+ __connman_rfkill_block(technology->type, TRUE);
+
+ for (list = technology->device_list; list; list = list->next) {
+ struct connman_device *device = list->data;
+
+ err = __connman_device_disable(device);
+ if (err == 0)
+ ret = 0;
+ }
+
+done:
+ if (ret == 0) {
+ if (msg != NULL)
+ g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
+ return ret;
+ }
+
+ if (msg != NULL) {
+ if (err == -EINPROGRESS) {
+ technology->pending_reply = dbus_message_ref(msg);
+ technology->pending_timeout = g_timeout_add_seconds(10,
+ technology_pending_reply, technology);
+ } else {
+ reply = __connman_error_failed(msg, -err);
+ if (reply != NULL)
+ g_dbus_send_message(connection, reply);
+ }
+ }
+
+ return err;
+}
+