From ef3649fd9e62bd989ff67a125a05c962d5640fd3 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Fri, 23 Mar 2007 21:04:08 +0000 Subject: network: using service class identifier instead of the uuid 128 string for server registration --- network/common.c | 16 +++++++++++++--- network/common.h | 3 ++- network/manager.c | 5 ++--- network/server.c | 16 ++++++++-------- network/server.h | 2 +- 5 files changed, 26 insertions(+), 16 deletions(-) (limited to 'network') diff --git a/network/common.c b/network/common.c index 7fbfee91..ec10cc34 100644 --- a/network/common.c +++ b/network/common.c @@ -60,9 +60,9 @@ static struct { const char *uuid128; /* UUID 128 */ uint16_t id; /* Service class identifier */ } __svc[] = { - { "PANU", PANU_UUID, BNEP_SVC_PANU }, - { "GN", GN_UUID, BNEP_SVC_GN }, - { "NAP", NAP_UUID, BNEP_SVC_NAP }, + { "panu", PANU_UUID, BNEP_SVC_PANU }, + { "gn", GN_UUID, BNEP_SVC_GN }, + { "nap", NAP_UUID, BNEP_SVC_NAP }, { NULL } }; @@ -101,6 +101,16 @@ const char *bnep_uuid(uint16_t id) return NULL; } +const char *bnep_name(uint16_t id) +{ + int i; + + for (i = 0; __svc[i].name; i++) + if (__svc[i].id == id) + return __svc[i].name; + return NULL; +} + int bnep_init(void) { ctl = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_BNEP); diff --git a/network/common.h b/network/common.h index 7dfc920a..36bb66b2 100644 --- a/network/common.h +++ b/network/common.h @@ -25,7 +25,8 @@ int bnep_init(void); int bnep_cleanup(void); uint16_t bnep_service_id(const char *svc); -const char *bnep_uuid(uint16_t uuid); +const char *bnep_uuid(uint16_t id); +const char *bnep_name(uint16_t id); int bnep_kill_connection(const char *addr); int bnep_kill_all_connections(void); diff --git a/network/manager.c b/network/manager.c index ff4d05d4..6740f100 100644 --- a/network/manager.c +++ b/network/manager.c @@ -139,14 +139,13 @@ static DBusHandlerResult create_server(DBusConnection *conn, return err_invalid_args(conn, msg, "Not supported"); path = g_new0(char, 32); - snprintf(path, 32, NETWORK_PATH "/server/%X", id); + snprintf(path, 32, NETWORK_PATH "/server/%s", bnep_name(id)); /* Path already registered */ if (g_slist_find_custom(mgr->servers, path, (GCompareFunc) strcmp)) return create_path(conn, msg, path, NULL); /* Return already exist error */ - /* FIXME: define which type should be used -- string/uuid str/uui128 */ - if (server_register(conn, path, str) == -1) { + if (server_register(conn, path, id) == -1) { err_failed(conn, msg, "D-Bus path registration failed"); g_free(path); return DBUS_HANDLER_RESULT_HANDLED; diff --git a/network/server.c b/network/server.c index 5cfb332e..80c8df9e 100644 --- a/network/server.c +++ b/network/server.c @@ -37,14 +37,15 @@ #define NETWORK_SERVER_INTERFACE "org.bluez.network.Server" +#include "common.h" #include "server.h" struct network_server { char *iface; /* Routing interface */ char *name; char *path; - char *uuid; /* UUID 128 */ dbus_bool_t secure; + uint16_t id; /* Service class identifier */ }; static DBusHandlerResult get_uuid(DBusConnection *conn, @@ -52,13 +53,15 @@ static DBusHandlerResult get_uuid(DBusConnection *conn, { struct network_server *ns = data; DBusMessage *reply; + const char *uuid; reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; + uuid = bnep_uuid(ns->id); dbus_message_append_args(reply, - DBUS_TYPE_STRING, &ns->uuid, + DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID); return send_message_and_unref(conn, reply); @@ -264,9 +267,6 @@ static void server_free(struct network_server *ns) if (ns->path) g_free(ns->path); - if (ns->uuid) - g_free(ns->uuid); - g_free(ns); } @@ -285,14 +285,14 @@ static const DBusObjectPathVTable server_table = { .unregister_function = server_unregister, }; -int server_register(DBusConnection *conn, const char *path, const char *uuid) +int server_register(DBusConnection *conn, const char *path, uint16_t id) { struct network_server *ns; if (!conn) return -EINVAL; - if (!path || !uuid) + if (!path) return -EINVAL; ns = g_new0(struct network_server, 1); @@ -305,7 +305,7 @@ int server_register(DBusConnection *conn, const char *path, const char *uuid) } ns->path = g_strdup(path); - ns->uuid = g_strdup(uuid); + ns->id = id; info("Registered server path:%s", ns->path); return 0; diff --git a/network/server.h b/network/server.h index a3fba6d1..bb15e4d7 100644 --- a/network/server.h +++ b/network/server.h @@ -20,4 +20,4 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ -int server_register(DBusConnection *conn, const char *path, const char *uuid); +int server_register(DBusConnection *conn, const char *path, uint16_t id); -- cgit