summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikel Astiz <mikel.astiz@bmw-carit.de>2012-10-19 17:39:22 +0200
committerJohan Hedberg <johan.hedberg@intel.com>2012-10-25 13:35:22 +0300
commit60be28030fac9f606f5f1de07e4830af202c3414 (patch)
tree225c24f1510aec085294daa011ee55c6e1fc9193
parentafa7a207d3a53e9ec25915d645780c17162ea841 (diff)
network: Add network .connect and .disconnect
Add the btd_profile hooks to connect and disconnect all three network roles.
-rw-r--r--profiles/network/manager.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index eda0bbe3..87d263a3 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
@@ -47,6 +47,12 @@
static gboolean conf_security = TRUE;
+struct connect_req {
+ struct btd_device *device;
+ struct btd_profile *profile;
+ btd_profile_cb cb;
+};
+
static void read_config(const char *file)
{
GKeyFile *keyfile;
@@ -73,6 +79,57 @@ done:
conf_security ? "true" : "false");
}
+static void connect_profile_cb(struct btd_device *device, int err,
+ const char *pdev, void *data)
+{
+ struct connect_req *req = data;
+
+ req->cb(req->profile, req->device, err);
+
+ g_free(req);
+}
+
+static int connect_profile(struct btd_device *dev, struct btd_profile *profile,
+ uint16_t id, btd_profile_cb cb)
+{
+ struct connect_req *req;
+ int err;
+
+ DBG("path %s id %u", device_get_path(dev), id);
+
+ req = g_new0(struct connect_req, 1);
+ req->device = dev;
+ req->profile = profile;
+ req->cb = cb;
+
+ err = connection_connect(dev, BNEP_SVC_PANU, NULL, connect_profile_cb,
+ req);
+ if (err < 0) {
+ g_free(req);
+ return err;
+ }
+
+ return 0;
+}
+
+static int disconnect_profile(struct btd_device *dev,
+ struct btd_profile *profile,
+ uint16_t id, btd_profile_cb cb)
+{
+ int err;
+
+ DBG("path %s id %u", device_get_path(dev), id);
+
+ err = connection_disconnect(dev, id, NULL);
+ if (err < 0)
+ return err;
+
+ if (cb)
+ cb(profile, dev, 0);
+
+ return 0;
+}
+
static int panu_probe(struct btd_profile *p, struct btd_device *device,
GSList *uuids)
{
@@ -88,6 +145,18 @@ static void network_remove(struct btd_profile *p, struct btd_device *device)
connection_unregister(device);
}
+static int panu_connect(struct btd_device *dev, struct btd_profile *profile,
+ btd_profile_cb cb)
+{
+ return connect_profile(dev, profile, BNEP_SVC_PANU, cb);
+}
+
+static int panu_disconnect(struct btd_device *dev, struct btd_profile *profile,
+ btd_profile_cb cb)
+{
+ return disconnect_profile(dev, profile, BNEP_SVC_PANU, cb);
+}
+
static int panu_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
{
const gchar *path = adapter_get_path(adapter);
@@ -115,6 +184,18 @@ static int gn_probe(struct btd_profile *p, struct btd_device *device,
return connection_register(device, BNEP_SVC_GN);
}
+static int gn_connect(struct btd_device *dev, struct btd_profile *profile,
+ btd_profile_cb cb)
+{
+ return connect_profile(dev, profile, BNEP_SVC_GN, cb);
+}
+
+static int gn_disconnect(struct btd_device *dev, struct btd_profile *profile,
+ btd_profile_cb cb)
+{
+ return disconnect_profile(dev, profile, BNEP_SVC_GN, cb);
+}
+
static int gn_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
{
const gchar *path = adapter_get_path(adapter);
@@ -142,6 +223,18 @@ static int nap_probe(struct btd_profile *p, struct btd_device *device,
return connection_register(device, BNEP_SVC_NAP);
}
+static int nap_connect(struct btd_device *dev, struct btd_profile *profile,
+ btd_profile_cb cb)
+{
+ return connect_profile(dev, profile, BNEP_SVC_NAP, cb);
+}
+
+static int nap_disconnect(struct btd_device *dev, struct btd_profile *profile,
+ btd_profile_cb cb)
+{
+ return disconnect_profile(dev, profile, BNEP_SVC_NAP, cb);
+}
+
static int nap_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
{
const gchar *path = adapter_get_path(adapter);
@@ -166,6 +259,8 @@ static struct btd_profile panu_profile = {
.remote_uuids = BTD_UUIDS(PANU_UUID),
.device_probe = panu_probe,
.device_remove = network_remove,
+ .connect = panu_connect,
+ .disconnect = panu_disconnect,
.adapter_probe = panu_server_probe,
.adapter_remove = panu_server_remove,
};
@@ -175,6 +270,8 @@ static struct btd_profile gn_profile = {
.remote_uuids = BTD_UUIDS(GN_UUID),
.device_probe = gn_probe,
.device_remove = network_remove,
+ .connect = gn_connect,
+ .disconnect = gn_disconnect,
.adapter_probe = gn_server_probe,
.adapter_remove = gn_server_remove,
};
@@ -184,6 +281,8 @@ static struct btd_profile nap_profile = {
.remote_uuids = BTD_UUIDS(NAP_UUID),
.device_probe = nap_probe,
.device_remove = network_remove,
+ .connect = nap_connect,
+ .disconnect = nap_disconnect,
.adapter_probe = nap_server_probe,
.adapter_remove = nap_server_remove,
};