summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2010-07-30 14:08:44 (GMT)
committerSamuel Ortiz <sameo@linux.intel.com>2010-08-02 17:16:11 (GMT)
commitd885703619a775d053e0170eb2acb080fa205841 (patch)
tree21a6ad89488e289e2c5fb7a0bfdeaa9998091c06
parentde41f828cf9decef412165c2895cb6ddc73be455 (diff)
downloadconnman-d885703619a775d053e0170eb2acb080fa205841.zip
connman-d885703619a775d053e0170eb2acb080fa205841.tar.gz
connman-d885703619a775d053e0170eb2acb080fa205841.tar.bz2
Link providers with services
With each provider we now have a VPN type service.
-rw-r--r--src/connman.h26
-rw-r--r--src/provider.c27
-rw-r--r--src/service.c65
3 files changed, 105 insertions, 13 deletions
diff --git a/src/connman.h b/src/connman.h
index d0b1d2d..1a913a1 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -425,6 +425,19 @@ connman_bool_t __connman_tethering_get_status(void);
int __connman_tethering_set_status(connman_bool_t status);
void __connman_tethering_update_interface(const char *interface);
+#include <connman/provider.h>
+
+void __connman_provider_list(DBusMessageIter *iter, void *user_data);
+int __connman_provider_create_and_connect(DBusMessage *msg);
+const char * __connman_provider_get_ident(struct connman_provider *provider);
+int __connman_provider_indicate_state(struct connman_provider *provider,
+ enum connman_provider_state state);
+int __connman_provider_indicate_error(struct connman_provider *provider,
+ enum connman_provider_error error);
+int __connman_provider_remove(const char *path);
+void __connman_provider_cleanup(void);
+int __connman_provider_init(void);
+
#include <connman/service.h>
int __connman_service_init(void);
@@ -438,6 +451,7 @@ void __connman_service_put(struct connman_service *service);
struct connman_service *__connman_service_lookup_from_network(struct connman_network *network);
struct connman_service *__connman_service_create_from_network(struct connman_network *network);
+struct connman_service *__connman_service_create_from_provider(struct connman_provider *provider);
void __connman_service_update_from_network(struct connman_network *network);
void __connman_service_remove_from_network(struct connman_network *network);
@@ -513,18 +527,6 @@ struct connman_location *__connman_service_get_location(struct connman_service *
int __connman_location_detect(struct connman_service *service);
int __connman_location_finish(struct connman_service *service);
-#include <connman/provider.h>
-
-void __connman_provider_list(DBusMessageIter *iter, void *user_data);
-int __connman_provider_create_and_connect(DBusMessage *msg);
-int __connman_provider_indicate_state(struct connman_provider *provider,
- enum connman_provider_state state);
-int __connman_provider_indicate_error(struct connman_provider *provider,
- enum connman_provider_error error);
-int __connman_provider_remove(const char *path);
-void __connman_provider_cleanup(void);
-int __connman_provider_init(void);
-
#include <connman/notifier.h>
int __connman_technology_init(void);
diff --git a/src/provider.c b/src/provider.c
index 81c7b4d..66fb628 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -37,6 +37,7 @@ static GSList *driver_list = NULL;
struct connman_provider {
struct connman_element element;
+ struct connman_service *vpn_service;
char *identifier;
char *path;
enum connman_provider_state state;
@@ -140,6 +141,8 @@ static void connman_provider_setup_vpn_ipv4(struct connman_provider *provider,
struct connman_provider *connman_provider_ref(struct connman_provider *provider)
{
+ DBG("provider %p", provider);
+
if (connman_element_ref(&provider->element) == NULL)
return NULL;
@@ -148,6 +151,8 @@ struct connman_provider *connman_provider_ref(struct connman_provider *provider)
void connman_provider_unref(struct connman_provider *provider)
{
+ DBG("provider %p", provider);
+
connman_element_unref(&provider->element);
}
@@ -241,6 +246,9 @@ static int connman_provider_disconnect(struct connman_provider *provider)
__connman_provider_indicate_state(provider,
CONNMAN_PROVIDER_STATE_DISCONNECT);
+
+ __connman_service_indicate_state(provider->vpn_service,
+ CONNMAN_SERVICE_STATE_DISCONNECT);
if (err < 0) {
if (err != -EINPROGRESS)
return err;
@@ -512,11 +520,15 @@ int connman_provider_set_connected(struct connman_provider *provider,
}
__connman_provider_indicate_state(provider,
CONNMAN_PROVIDER_STATE_READY);
+ __connman_service_indicate_state(provider->vpn_service,
+ CONNMAN_SERVICE_STATE_READY);
} else {
reply_pending(provider, ECONNABORTED);
connman_element_unregister_children(&provider->element);
__connman_provider_indicate_state(provider,
CONNMAN_PROVIDER_STATE_DISCONNECT);
+ __connman_service_indicate_state(provider->vpn_service,
+ CONNMAN_SERVICE_STATE_DISCONNECT);
}
return 0;
@@ -543,6 +555,7 @@ static void provider_free(gpointer user_data)
g_free(provider->domain);
g_free(provider->identifier);
g_free(provider->dns);
+ __connman_service_put(provider->vpn_service);
}
static void unregister_provider(gpointer data)
@@ -561,6 +574,8 @@ static void provider_destruct(struct connman_element *element)
{
struct connman_provider *provider = element->private;
+ DBG("provider %p", provider);
+
provider_free(provider);
}
@@ -768,6 +783,10 @@ int __connman_provider_create_and_connect(DBusMessage *msg)
g_dbus_send_reply(connection, msg,
DBUS_TYPE_OBJECT_PATH, &provider->path,
DBUS_TYPE_INVALID);
+
+ provider->vpn_service =
+ __connman_service_create_from_provider(provider);
+
return 0;
failed:
@@ -779,6 +798,14 @@ failed:
return err;
}
+const char * __connman_provider_get_ident(struct connman_provider *provider)
+{
+ if (provider == NULL)
+ return NULL;
+
+ return provider->identifier;
+}
+
int connman_provider_set_string(struct connman_provider *provider,
const char *key, const char *value)
{
diff --git a/src/service.c b/src/service.c
index 2ddda9f..4ad1432 100644
--- a/src/service.c
+++ b/src/service.c
@@ -90,6 +90,7 @@ struct connman_service {
connman_bool_t login_required;
struct connman_ipconfig *ipconfig;
struct connman_network *network;
+ struct connman_provider *provider;
char **nameservers;
char *nameserver;
char **domains;
@@ -3275,7 +3276,7 @@ static void update_from_network(struct connman_service *service,
*
* Look up service by network and if not found, create one
*/
-struct connman_service *__connman_service_create_from_network(struct connman_network *network)
+struct connman_service * __connman_service_create_from_network(struct connman_network *network)
{
struct connman_service *service;
const char *ident, *group;
@@ -3416,6 +3417,68 @@ void __connman_service_remove_from_network(struct connman_network *network)
__connman_service_put(service);
}
+/**
+ * __connman_service_create_from_provider:
+ * @provider: provider structure
+ *
+ * Look up service by provider and if not found, create one
+ */
+struct connman_service *
+__connman_service_create_from_provider(struct connman_provider *provider)
+{
+ struct connman_service *service;
+ const char *ident, *str;
+ char *name;
+ int index = connman_provider_get_index(provider);
+
+ DBG("provider %p", provider);
+
+ ident = __connman_provider_get_ident(provider);
+ if (ident == NULL)
+ return NULL;
+
+ name = g_strdup_printf("vpn_%s", ident);
+ service = __connman_service_get(name);
+ g_free(name);
+
+ if (service == NULL)
+ return NULL;
+
+ service->type = CONNMAN_SERVICE_TYPE_VPN;
+ service->provider = provider;
+ service->autoconnect = FALSE;
+
+ service->state = CONNMAN_SERVICE_STATE_IDLE;
+
+ str = connman_provider_get_string(provider, "Name");
+ if (str != NULL) {
+ g_free(service->name);
+ service->name = g_strdup(str);
+ service->hidden = FALSE;
+ } else {
+ g_free(service->name);
+ service->name = NULL;
+ service->hidden = TRUE;
+ }
+
+ service->strength = 0;
+
+ service->ipconfig = connman_ipconfig_create(index);
+ if (service->ipconfig == NULL)
+ return service;
+
+ connman_ipconfig_set_method(service->ipconfig,
+ CONNMAN_IPCONFIG_METHOD_MANUAL);
+
+ connman_ipconfig_set_data(service->ipconfig, service);
+
+ connman_ipconfig_set_ops(service->ipconfig, &service_ops);
+
+ service_register(service);
+
+ return service;
+}
+
void __connman_service_stats_update(struct connman_service *service,
unsigned int rx_packets, unsigned int tx_packets,
unsigned int rx_bytes, unsigned int tx_bytes,