struct connman_service {
gint refcount;
+ gint session_usage_count;
char *identifier;
char *path;
enum connman_service_type type;
- enum connman_service_mode mode;
enum connman_service_security security;
enum connman_service_state state_ipv4;
enum connman_service_state state_ipv6;
return NULL;
}
-static const char *mode2string(enum connman_service_mode mode)
-{
- switch (mode) {
- case CONNMAN_SERVICE_MODE_UNKNOWN:
- break;
- case CONNMAN_SERVICE_MODE_MANAGED:
- return "managed";
- case CONNMAN_SERVICE_MODE_ADHOC:
- return "adhoc";
- case CONNMAN_SERVICE_MODE_GPRS:
- return "gprs";
- case CONNMAN_SERVICE_MODE_EDGE:
- return "edge";
- case CONNMAN_SERVICE_MODE_UMTS:
- return "umts";
- }
-
- return NULL;
-}
-
static const char *security2string(enum connman_service_security security)
{
switch (security) {
return __connman_service_type2string(service->type);
}
-static void mode_changed(struct connman_service *service)
+static void state_changed(struct connman_service *service)
{
+ enum connman_service_state state;
const char *str;
- str = mode2string(service->mode);
- if (str == NULL)
- return;
-
- connman_dbus_property_changed_basic(service->path,
- CONNMAN_SERVICE_INTERFACE, "Mode",
- DBUS_TYPE_STRING, &str);
-}
+ state = combine_state(service->state_ipv4, service->state_ipv6);
-static void state_changed(struct connman_service *service)
-{
- const char *str;
+ __connman_notifier_service_state_changed(service, state);
- str = state2string(combine_state(service->state_ipv4,
- service->state_ipv6));
+ str = state2string(state);
if (str == NULL)
return;
}
-static void settings_changed(struct connman_service *service)
+static void settings_changed(struct connman_service *service,
+ struct connman_ipconfig *ipconfig)
{
connman_dbus_property_changed_dict(service->path,
CONNMAN_SERVICE_INTERFACE, "IPv4",
connman_dbus_property_changed_dict(service->path,
CONNMAN_SERVICE_INTERFACE, "IPv6",
append_ipv6, service);
+
+ __connman_notifier_ipconfig_changed(service, ipconfig);
}
static void ipv4_configuration_changed(struct connman_service *service)
}
GSequence *__connman_service_get_list(struct connman_session *session,
- service_match_cb service_match)
+ service_match_cb service_match,
+ create_service_entry_cb create_service_entry,
+ GDestroyNotify destroy_service_entry)
{
GSequence *list;
GSequenceIter *iter;
+ struct connman_service *service;
+ enum connman_service_state state;
+ struct service_entry *entry;
- list = g_sequence_new(NULL);
+ list = g_sequence_new(destroy_service_entry);
if (list == NULL)
return NULL;
while (g_sequence_iter_is_end(iter) == FALSE) {
service = g_sequence_get(iter);
- if (service_match(session, service) == TRUE)
- g_sequence_append(list, service);
+ if (service_match(session, service) == TRUE) {
+ state = combine_state(service->state_ipv4,
+ service->state_ipv6);
+ entry = create_service_entry(service, service->name,
+ state);
+ if (entry == NULL)
+ return list;
+
+ g_sequence_append(list, entry);
+ }
iter = g_sequence_iter_next(iter);
}
return list;
}
+void __connman_service_session_inc(struct connman_service *service)
+{
+ DBG("service %p", service);
+
+ g_atomic_int_inc(&service->session_usage_count);
+}
+
+connman_bool_t __connman_service_session_dec(struct connman_service *service)
+{
+ connman_bool_t in_use;
+
+ if (g_atomic_int_dec_and_test(&service->session_usage_count) == TRUE)
+ in_use = FALSE;
+ else
+ in_use = TRUE;
+
+ DBG("service %p last %d", service, in_use);
+
+ return in_use;
+}
+
static void append_properties(DBusMessageIter *dict, dbus_bool_t limited,
struct connman_service *service)
{
connman_dbus_dict_append_basic(dict, "Type",
DBUS_TYPE_STRING, &str);
- str = mode2string(service->mode);
- if (str != NULL)
- connman_dbus_dict_append_basic(dict, "Mode",
- DBUS_TYPE_STRING, &str);
-
connman_dbus_dict_append_array(dict, "Security",
DBUS_TYPE_STRING, append_security, service);
service->pac = g_strdup(pac);
}
+void __connman_service_set_identity(struct connman_service *service,
+ const char *identity)
+{
+ if (service->immutable)
+ return;
+
+ g_free(service->identity);
+ service->identity = g_strdup(identity);
+
+ if (service->network != NULL)
+ connman_network_set_string(service->network,
+ "WiFi.Identity",
+ service->identity);
+}
+
void __connman_service_set_passphrase(struct connman_service *service,
const char* passphrase)
{
}
static void request_input_cb (struct connman_service *service,
- const char *passphrase, void *user_data)
+ const char *identity, const char *passphrase,
+ void *user_data)
{
DBG ("RequestInput return, %p", service);
- if (passphrase == NULL && service->wps == FALSE)
+ if (identity == NULL && passphrase == NULL && service->wps == FALSE)
return;
+ if (identity != NULL)
+ __connman_service_set_identity(service, identity);
+
if (passphrase != NULL)
__connman_service_set_passphrase(service, passphrase);
g_hash_table_remove(service_hash, service->identifier);
+ __connman_notifier_service_remove(service);
+
stats_stop(service);
__connman_storage_save_service(service);
DBG("service %p", service);
service->refcount = 1;
+ service->session_usage_count = 0;
service->type = CONNMAN_SERVICE_TYPE_UNKNOWN;
- service->mode = CONNMAN_SERVICE_MODE_UNKNOWN;
service->security = CONNMAN_SERVICE_SECURITY_UNKNOWN;
service->state_ipv4 = CONNMAN_SERVICE_STATE_UNKNOWN;
return service->security;
}
+const char *__connman_service_get_phase2(struct connman_service *service)
+{
+ if (service == NULL)
+ return NULL;
+
+ return service->phase2;
+}
+
connman_bool_t __connman_service_wps_enabled(struct connman_service *service)
{
if (service == NULL)
return 0;
}
+connman_bool_t __connman_service_get_immutable(struct connman_service *service)
+{
+ if (service == NULL)
+ return FALSE;
+
+ return service->immutable;
+}
+
int __connman_service_set_immutable(struct connman_service *service,
connman_bool_t immutable)
{
else {
service_complete(service);
__connman_profile_changed(FALSE);
- __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
+ __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
+ }
+}
+
+int __connman_service_set_ipconfig_ready(struct connman_service *service,
+ enum connman_ipconfig_type type)
+{
+ enum connman_service_state state;
+ int err = 0;
+
+ DBG("service %p (%s) type %d (%s)",
+ service, service ? service->identifier : NULL,
+ type, __connman_ipconfig_type2string(type));
+
+ if (service == NULL)
+ return -EINVAL;
+
+ state = combine_state(service->state_ipv4, service->state_ipv6);
+
+ if (state == CONNMAN_SERVICE_STATE_READY ||
+ state == CONNMAN_SERVICE_STATE_ONLINE) {
+ err = -EALREADY;
+ } else {
+ err = __connman_service_indicate_state(service,
+ CONNMAN_SERVICE_STATE_READY, type);
}
+
+ return err;
}
int __connman_service_indicate_state(struct connman_service *service,
if (service_state == CONNMAN_SERVICE_STATE_IDLE ||
service_state == CONNMAN_SERVICE_STATE_FAILURE)
- __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
+ __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
return 0;
}
}
break;
case CONNMAN_SERVICE_SECURITY_8021X:
+ if (service->eap == NULL)
+ return -EINVAL;
+
+ /*
+ * never request credentials if using EAP-TLS
+ * (EAP-TLS networks need to be fully provisioned)
+ */
+ if (g_str_equal(service->eap, "tls") == TRUE)
+ break;
+
+ if (service->immutable != TRUE)
+ return -ENOKEY;
+
break;
}
break;
return 0;
if (err == -EINPROGRESS) {
- service->timeout = g_timeout_add_seconds(CONNECT_TIMEOUT,
- connect_timeout, service);
+ if (service->timeout == 0)
+ service->timeout = g_timeout_add_seconds(
+ CONNECT_TIMEOUT, connect_timeout, service);
return -EINPROGRESS;
}
g_strcmp0(security, "ieee8021x") != 0)
return -EINVAL;
- device = __connman_element_find_device(CONNMAN_SERVICE_TYPE_WIFI);
+ device = __connman_device_find_device(CONNMAN_SERVICE_TYPE_WIFI);
if (device == NULL)
return -EOPNOTSUPP;
return err;
}
+int __connman_service_provision(DBusMessage *msg)
+{
+ GKeyFile *keyfile = NULL;
+ const char *config_str = NULL;
+ char *group = NULL, *ident = NULL;
+ int err = 0;
+ struct connman_service *service;
+
+ DBG("");
+
+ dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &config_str,
+ DBUS_TYPE_INVALID);
+
+ if (config_str == NULL || strlen(config_str) == 0)
+ return -EINVAL;
+
+ keyfile = g_key_file_new();
+
+ /* populate GKeyFile with config_str */
+ if (g_key_file_load_from_data(keyfile, config_str,
+ strlen(config_str), 0, NULL) == FALSE) {
+ err = -EINVAL;
+ goto done;
+ }
+
+ /*
+ * read only one group of settings (only one service supported, no
+ * global settings)
+ */
+ group = g_key_file_get_start_group(keyfile);
+
+ if (group == NULL || g_str_has_prefix(group, "service_") == FALSE) {
+ err = -EINVAL;
+ goto done;
+ }
+
+ err = __connman_config_load_service(keyfile, group, TRUE);
+ if (err < 0)
+ goto done;
+
+ ident = group + strlen("service_");
+
+ /* trigger service provisioning if service exists */
+ service = lookup_by_identifier(ident);
+ if (service != NULL)
+ __connman_config_provision_service(service);
+
+ g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID);
+
+done:
+ if (group != NULL)
+ g_free(group);
+
+ if (keyfile != NULL)
+ g_key_file_free(keyfile);
+
+ return err;
+}
+
/**
* __connman_service_get:
* @identifier: service identifier
{
struct connman_service *service = connman_ipconfig_get_data(ipconfig);
- connman_info("%s up", connman_ipconfig_get_ifname(ipconfig));
+ DBG("%s up", connman_ipconfig_get_ifname(ipconfig));
link_changed(service);
static void service_down(struct connman_ipconfig *ipconfig)
{
- connman_info("%s down", connman_ipconfig_get_ifname(ipconfig));
+ DBG("%s down", connman_ipconfig_get_ifname(ipconfig));
}
static void service_lower_up(struct connman_ipconfig *ipconfig)
{
struct connman_service *service = connman_ipconfig_get_data(ipconfig);
- connman_info("%s lower up", connman_ipconfig_get_ifname(ipconfig));
+ DBG("%s lower up", connman_ipconfig_get_ifname(ipconfig));
stats_start(service);
}
{
struct connman_service *service = connman_ipconfig_get_data(ipconfig);
- connman_info("%s lower down", connman_ipconfig_get_ifname(ipconfig));
+ DBG("%s lower down", connman_ipconfig_get_ifname(ipconfig));
stats_stop(service);
__connman_storage_save_service(service);
enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
- connman_info("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
+ DBG("%s ip bound", connman_ipconfig_get_ifname(ipconfig));
type = __connman_ipconfig_get_config_type(ipconfig);
method = __connman_ipconfig_get_method(ipconfig);
if (type == CONNMAN_IPCONFIG_TYPE_IPV6 &&
method == CONNMAN_IPCONFIG_METHOD_AUTO)
- __connman_service_indicate_state(service,
- CONNMAN_SERVICE_STATE_READY,
+ __connman_service_set_ipconfig_ready(service,
CONNMAN_IPCONFIG_TYPE_IPV6);
- settings_changed(service);
+ settings_changed(service, ipconfig);
}
static void service_ip_release(struct connman_ipconfig *ipconfig)
enum connman_ipconfig_method method = CONNMAN_IPCONFIG_METHOD_UNKNOWN;
enum connman_ipconfig_type type = CONNMAN_IPCONFIG_TYPE_UNKNOWN;
- connman_info("%s ip release", connman_ipconfig_get_ifname(ipconfig));
+ DBG("%s ip release", connman_ipconfig_get_ifname(ipconfig));
type = __connman_ipconfig_get_config_type(ipconfig);
method = __connman_ipconfig_get_method(ipconfig);
CONNMAN_SERVICE_STATE_DISCONNECT,
CONNMAN_IPCONFIG_TYPE_IPV4);
- settings_changed(service);
+ settings_changed(service, ipconfig);
}
static const struct connman_ipconfig_ops service_ops = {
return CONNMAN_SERVICE_TYPE_UNKNOWN;
}
-static enum connman_service_mode convert_wifi_mode(const char *mode)
-{
- if (mode == NULL)
- return CONNMAN_SERVICE_MODE_UNKNOWN;
- else if (g_str_equal(mode, "managed") == TRUE)
- return CONNMAN_SERVICE_MODE_MANAGED;
- else if (g_str_equal(mode, "adhoc") == TRUE)
- return CONNMAN_SERVICE_MODE_ADHOC;
- else
- return CONNMAN_SERVICE_MODE_UNKNOWN;
-}
-
static enum connman_service_security convert_wifi_security(const char *security)
{
if (security == NULL)
return CONNMAN_SERVICE_SECURITY_UNKNOWN;
}
-static enum connman_service_mode convert_cellular_mode(connman_uint8_t mode)
-{
- switch (mode) {
- case 0:
- case 1:
- return CONNMAN_SERVICE_MODE_GPRS;
- case 3:
- return CONNMAN_SERVICE_MODE_EDGE;
- case 2:
- case 4:
- case 5:
- case 6:
- return CONNMAN_SERVICE_MODE_UMTS;
- }
-
- return CONNMAN_SERVICE_MODE_UNKNOWN;
-}
-
static void update_from_network(struct connman_service *service,
struct connman_network *network)
{
service->hidden = TRUE;
}
- service->strength = connman_network_get_uint8(network, "Strength");
+ service->strength = connman_network_get_strength(network);
service->roaming = connman_network_get_bool(network, "Roaming");
if (service->strength == 0) {
service->strength = strength;
}
- str = connman_network_get_string(network, "WiFi.Mode");
- service->mode = convert_wifi_mode(str);
-
str = connman_network_get_string(network, "WiFi.Security");
service->security = convert_wifi_security(str);
- if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR) {
- connman_uint8_t value = connman_network_get_uint8(network,
- "Cellular.Mode");
-
- service->mode = convert_cellular_mode(value);
- } else if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
+ if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
service->wps = connman_network_get_bool(network, "WiFi.WPS");
if (service->strength > strength && service->network != NULL) {
__connman_service_auto_connect();
}
+ __connman_notifier_service_add(service);
+
return service;
}
void __connman_service_update_from_network(struct connman_network *network)
{
struct connman_service *service;
- enum connman_service_mode mode;
- connman_uint8_t strength, value;
+ connman_uint8_t strength;
connman_bool_t roaming;
GSequenceIter *iter;
const char *name;
if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
service->wps = connman_network_get_bool(network, "WiFi.WPS");
- strength = connman_network_get_uint8(service->network, "Strength");
+ strength = connman_network_get_strength(service->network);
if (strength == service->strength)
goto roaming;
roaming:
roaming = connman_network_get_bool(service->network, "Roaming");
if (roaming == service->roaming)
- goto done;
+ return;
stats_enable = stats_enabled(service);
if (stats_enable == TRUE)
iter = g_hash_table_lookup(service_hash, service->identifier);
if (iter != NULL)
g_sequence_sort_changed(iter, service_compare, NULL);
-
-done:
- if (service->type != CONNMAN_SERVICE_TYPE_CELLULAR)
- return;
-
- value = connman_network_get_uint8(service->network, "Cellular.Mode");
- mode = convert_cellular_mode(value);
-
- if (mode == service->mode)
- return;
-
- service->mode = mode;
-
- mode_changed(service);
}
void __connman_service_remove_from_network(struct connman_network *network)
service_register(service);
+ __connman_notifier_service_add(service);
+
return service;
}