static DBusMessage *disable_technology(DBusConnection *conn, DBusMessage *msg, void *data) { enum connman_service_type type; const char *str; DBG("conn %p", conn); dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID); if (g_strcmp0(str, "ethernet") == 0) type = CONNMAN_SERVICE_TYPE_ETHERNET; else if (g_strcmp0(str, "wifi") == 0) type = CONNMAN_SERVICE_TYPE_WIFI; else if (g_strcmp0(str, "wimax") == 0) type = CONNMAN_SERVICE_TYPE_WIMAX; else if (g_strcmp0(str, "bluetooth") == 0) type = CONNMAN_SERVICE_TYPE_BLUETOOTH; else if (g_strcmp0(str, "cellular") == 0) type = CONNMAN_SERVICE_TYPE_CELLULAR; else return __connman_error_invalid_arguments(msg); if (__connman_notifier_is_registered(type) == FALSE) return __connman_error_not_registered(msg); if (__connman_notifier_is_enabled(type) == FALSE) return __connman_error_already_disabled(msg); __connman_technology_disable(type, msg); return NULL; }
static DBusMessage *set_powered(struct connman_technology *technology, DBusMessage *msg, connman_bool_t powered) { DBusMessage *reply = NULL; int err = 0; if (technology->rfkill_driven && technology->hardblocked == TRUE) { err = -EACCES; goto make_reply; } if (powered == TRUE) err = technology_enable(technology); else err = technology_disable(technology); if (err != -EBUSY) { technology->enable_persistent = powered; technology_save(technology); } make_reply: if (err == -EINPROGRESS) { technology->pending_reply = dbus_message_ref(msg); technology->pending_timeout = g_timeout_add_seconds(10, technology_pending_reply, technology); } else if (err == -EALREADY) { if (powered == TRUE) reply = __connman_error_already_enabled(msg); else reply = __connman_error_already_disabled(msg); } else if (err < 0) reply = __connman_error_failed(msg, -err); else reply = g_dbus_create_reply(msg, DBUS_TYPE_INVALID); return reply; }
static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg, void *data) { struct connman_technology *technology = data; DBusMessageIter iter, value; const char *name; int type; DBG("conn %p", conn); if (dbus_message_iter_init(msg, &iter) == FALSE) return __connman_error_invalid_arguments(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return __connman_error_invalid_arguments(msg); dbus_message_iter_get_basic(&iter, &name); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) return __connman_error_invalid_arguments(msg); dbus_message_iter_recurse(&iter, &value); type = dbus_message_iter_get_arg_type(&value); DBG("property %s", name); if (g_str_equal(name, "Tethering") == TRUE) { int err; connman_bool_t tethering; if (type != DBUS_TYPE_BOOLEAN) return __connman_error_invalid_arguments(msg); if (connman_technology_is_tethering_allowed(technology->type) == FALSE) { DBG("%s tethering not allowed by config file", __connman_service_type2string(technology->type)); return __connman_error_not_supported(msg); } dbus_message_iter_get_basic(&value, &tethering); if (technology->tethering == tethering) { if (tethering == FALSE) return __connman_error_already_disabled(msg); else return __connman_error_already_enabled(msg); } err = set_tethering(technology, tethering); if (err < 0) return __connman_error_failed(msg, -err); technology->tethering_persistent = tethering; technology_save(technology); } else if (g_str_equal(name, "TetheringIdentifier") == TRUE) { const char *str; dbus_message_iter_get_basic(&value, &str); if (technology->type != CONNMAN_SERVICE_TYPE_WIFI) return __connman_error_not_supported(msg); if (strlen(str) < 1 || strlen(str) > 32) return __connman_error_invalid_arguments(msg); if (g_strcmp0(technology->tethering_ident, str) != 0) { g_free(technology->tethering_ident); technology->tethering_ident = g_strdup(str); technology_save(technology); connman_dbus_property_changed_basic(technology->path, CONNMAN_TECHNOLOGY_INTERFACE, "TetheringIdentifier", DBUS_TYPE_STRING, &technology->tethering_ident); } } else if (g_str_equal(name, "TetheringPassphrase") == TRUE) { const char *str; dbus_message_iter_get_basic(&value, &str); if (technology->type != CONNMAN_SERVICE_TYPE_WIFI) return __connman_error_not_supported(msg); if (strlen(str) < 8 || strlen(str) > 63) return __connman_error_passphrase_required(msg); if (g_strcmp0(technology->tethering_passphrase, str) != 0) { g_free(technology->tethering_passphrase); technology->tethering_passphrase = g_strdup(str); technology_save(technology); connman_dbus_property_changed_basic(technology->path, CONNMAN_TECHNOLOGY_INTERFACE, "TetheringPassphrase", DBUS_TYPE_STRING, &technology->tethering_passphrase); } } else if (g_str_equal(name, "Powered") == TRUE) { connman_bool_t enable; if (type != DBUS_TYPE_BOOLEAN) return __connman_error_invalid_arguments(msg); dbus_message_iter_get_basic(&value, &enable); return set_powered(technology, msg, enable); } else return __connman_error_invalid_property(msg); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }