static void tethering_changed(struct connman_technology *technology) { connman_bool_t tethering = technology->tethering; connman_dbus_property_changed_basic(technology->path, CONNMAN_TECHNOLOGY_INTERFACE, "Tethering", DBUS_TYPE_BOOLEAN, &tethering); technology_save(technology); }
static void technology_load(struct connman_technology *technology) { GKeyFile *keyfile; gchar *identifier; GError *error = NULL; connman_bool_t enable; DBG("technology %p", technology); keyfile = __connman_storage_load_global(); /* Fallback on disabling technology if file not found. */ if (keyfile == NULL) { if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET) /* We enable ethernet by default */ technology->enable_persistent = TRUE; else technology->enable_persistent = FALSE; return; } identifier = g_strdup_printf("%s", get_name(technology->type)); if (identifier == NULL) goto done; enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error); if (error == NULL) technology->enable_persistent = enable; else { if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET) technology->enable_persistent = TRUE; else technology->enable_persistent = FALSE; technology_save(technology); g_clear_error(&error); } technology->tethering_ident = g_key_file_get_string(keyfile, identifier, "Tethering.Identifier", NULL); technology->tethering_passphrase = g_key_file_get_string(keyfile, identifier, "Tethering.Passphrase", NULL); done: g_free(identifier); g_key_file_free(keyfile); return; }
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); }