diff --git a/Makefile.plugins b/Makefile.plugins
index 3df5eb1..eb16765 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
profiles/audio/a2dp-codecs.h
builtin_modules += network
-builtin_sources += profiles/network/main.c \
- profiles/network/manager.h profiles/network/manager.c \
+builtin_sources += profiles/network/manager.h profiles/network/manager.c \
profiles/network/common.h profiles/network/common.c \
profiles/network/server.h profiles/network/server.c \
profiles/network/connection.h \
diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index 1856eb8..3157e31 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
#include "error.h"
#include "common.h"
+#include "manager.h"
#include "connection.h"
#define NETWORK_PEER_INTERFACE "org.bluez.Network"
};
struct network_conn {
- btd_connection_cb cb;
- void *cb_data;
char dev[16]; /* Interface name */
uint16_t id; /* Role: Service Class Identifier */
conn_state state;
device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
nc->dc_id = 0;
+ network_disconnected(nc->peer->device, nc->id, 0);
+
info("%s disconnected", nc->dev);
bnep_if_down(nc->dev);
nc->timeout_source = 0;
}
- if (nc->cb)
- nc->cb(nc->peer->device, err, NULL, nc->cb_data);
+ network_connected(nc->peer->device, nc->id, err);
g_io_channel_shutdown(nc->io, TRUE, NULL);
g_io_channel_unref(nc->io);
bnep_if_up(nc->dev);
- if (nc->cb)
- nc->cb(nc->peer->device, 0, nc->dev, nc->cb_data);
+ network_connected(nc->peer->device, nc->id, 0);
conn = btd_get_dbus_connection();
path = device_get_path(nc->peer->device);
}
/* Connect and initiate BNEP session */
-int connection_connect(struct btd_device *device, uint16_t id,
- const char *owner,
- btd_connection_cb cb, void *data)
+int connection_connect(struct btd_device *device, uint16_t id)
{
struct network_peer *peer;
struct network_conn *nc;
return -EIO;
nc->state = CONNECTING;
- nc->cb = cb;
- nc->cb_data = data;
return 0;
}
-int connection_disconnect(struct btd_device *device, uint16_t id,
- const char *caller)
+int connection_disconnect(struct btd_device *device, uint16_t id)
{
struct network_peer *peer;
struct network_conn *nc;
diff --git a/profiles/network/connection.h b/profiles/network/connection.h
index e67b0ec..32356f9 100644
--- a/profiles/network/connection.h
+++ b/profiles/network/connection.h
*
*/
-typedef void (*btd_connection_cb)(struct btd_device *device, int err,
- const char *pdev, void *data);
-
int connection_register(struct btd_device *device, uint16_t id);
void connection_unregister(struct btd_device *device);
-int connection_connect(struct btd_device *device, uint16_t id,
- const char *owner,
- btd_connection_cb cb, void *data);
-int connection_disconnect(struct btd_device *device, uint16_t id,
- const char *caller);
+int connection_connect(struct btd_device *device, uint16_t id);
+int connection_disconnect(struct btd_device *device, uint16_t id);
diff --git a/profiles/network/main.c b/profiles/network/main.c
deleted file mode 100644
index 99a1954..0000000
--- a/profiles/network/main.c
+++ /dev/null
-/*
- *
- * BlueZ - Bluetooth protocol stack for Linux
- *
- * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-
-#include <gdbus/gdbus.h>
-
-#include "plugin.h"
-#include "manager.h"
-
-static int network_init(void)
-{
- return network_manager_init();
-}
-
-static void network_exit(void)
-{
- network_manager_exit();
-}
-
-BLUETOOTH_PLUGIN_DEFINE(network, VERSION,
- BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, network_init, network_exit)
diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index 9958099..0a3683c 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
#include <gdbus/gdbus.h>
#include "log.h"
+#include "plugin.h"
#include "adapter.h"
#include "device.h"
conf_security ? "true" : "false");
}
-static void connect_profile_cb(struct btd_device *device, int err,
- const char *pdev, void *data)
-{
- struct btd_profile *profile = data;
-
- device_profile_connected(device, profile, err);
-}
-
-static int connect_profile(struct btd_device *dev, struct btd_profile *profile,
- uint16_t id)
-{
- DBG("path %s id %u", device_get_path(dev), id);
-
- return connection_connect(dev, id, NULL, connect_profile_cb, profile);
-}
-
-static int disconnect_profile(struct btd_device *dev,
- struct btd_profile *profile,
- uint16_t id)
-{
- int err;
-
- DBG("path %s id %u", device_get_path(dev), id);
-
- err = connection_disconnect(dev, id, NULL);
- if (err < 0)
- return err;
-
- device_profile_disconnected(dev, profile, 0);
-
- return 0;
-}
-
static int panu_probe(struct btd_profile *p, struct btd_device *device,
GSList *uuids)
{
static int panu_connect(struct btd_device *dev, struct btd_profile *profile)
{
- return connect_profile(dev, profile, BNEP_SVC_PANU);
+ return connection_connect(dev, BNEP_SVC_PANU);
}
static int panu_disconnect(struct btd_device *dev, struct btd_profile *profile)
{
- return disconnect_profile(dev, profile, BNEP_SVC_PANU);
+ return connection_disconnect(dev, BNEP_SVC_PANU);
}
static int panu_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
static int gn_connect(struct btd_device *dev, struct btd_profile *profile)
{
- return connect_profile(dev, profile, BNEP_SVC_GN);
+ return connection_connect(dev, BNEP_SVC_GN);
}
static int gn_disconnect(struct btd_device *dev, struct btd_profile *profile)
{
- return disconnect_profile(dev, profile, BNEP_SVC_GN);
+ return connection_disconnect(dev, BNEP_SVC_GN);
}
static int gn_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
static int nap_connect(struct btd_device *dev, struct btd_profile *profile)
{
- return connect_profile(dev, profile, BNEP_SVC_NAP);
+ return connection_connect(dev, BNEP_SVC_NAP);
}
static int nap_disconnect(struct btd_device *dev, struct btd_profile *profile)
{
- return disconnect_profile(dev, profile, BNEP_SVC_NAP);
+ return connection_disconnect(dev, BNEP_SVC_NAP);
}
static int nap_server_probe(struct btd_profile *p, struct btd_adapter *adapter)
.adapter_remove = nap_server_remove,
};
-int network_manager_init(void)
+void network_connected(struct btd_device *dev, int id, int err)
+{
+ switch (id) {
+ case BNEP_SVC_PANU:
+ device_profile_connected(dev, &panu_profile, err);
+ break;
+ case BNEP_SVC_GN:
+ device_profile_connected(dev, &gn_profile, err);
+ break;
+ case BNEP_SVC_NAP:
+ device_profile_connected(dev, &gn_profile, err);
+ break;
+ default:
+ error("Invalid id %d passed to network_connected", id);
+ break;
+ }
+}
+
+void network_disconnected(struct btd_device *dev, int id, int err)
+{
+ switch (id) {
+ case BNEP_SVC_PANU:
+ device_profile_disconnected(dev, &panu_profile, err);
+ break;
+ case BNEP_SVC_GN:
+ device_profile_disconnected(dev, &gn_profile, err);
+ break;
+ case BNEP_SVC_NAP:
+ device_profile_disconnected(dev, &gn_profile, err);
+ break;
+ default:
+ error("Invalid id %d passed to network_disconnected", id);
+ break;
+ }
+}
+
+static int network_init(void)
{
read_config(CONFIGDIR "/network.conf");
return 0;
}
-void network_manager_exit(void)
+static void network_exit(void)
{
server_exit();
bnep_cleanup();
}
+
+BLUETOOTH_PLUGIN_DEFINE(network, VERSION,
+ BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, network_init, network_exit)
diff --git a/profiles/network/manager.h b/profiles/network/manager.h
index 5ba1f0e..8a8c065 100644
--- a/profiles/network/manager.h
+++ b/profiles/network/manager.h
*
*/
-int network_manager_init(void);
-void network_manager_exit(void);
+void network_connected(struct btd_device *dev, int id, int err);
+void network_disconnected(struct btd_device *dev, int id, int err);