diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-03-23 19:10:37 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-03-23 19:10:37 +0000 |
commit | 2e39ac58720cba4fc6e889ec5f18a8ce1d67276c (patch) | |
tree | eb8dbe17339e56498a7e234b33d30ace48117dde /network | |
parent | bdb402511c964ba8d65fd4657c638ab3c5fbf438 (diff) |
network: Fixed string/service id/uuid convertion functions
Diffstat (limited to 'network')
-rw-r--r-- | network/common.c | 46 | ||||
-rw-r--r-- | network/common.h | 4 | ||||
-rw-r--r-- | network/connection.c | 18 | ||||
-rw-r--r-- | network/manager.c | 25 |
4 files changed, 59 insertions, 34 deletions
diff --git a/network/common.c b/network/common.c index 1649eb70..1be7bbe4 100644 --- a/network/common.c +++ b/network/common.c @@ -40,6 +40,10 @@ static int ctl; +#define PANU_UUID "00001115-0000-1000-8000-00805f9b34fb" +#define NAP_UUID "00001116-0000-1000-8000-00805f9b34fb" +#define GN_UUID "00001117-0000-1000-8000-00805f9b34fb" + /* Compatibility with old ioctls */ #define OLD_BNEPCONADD 1 #define OLD_BNEPCONDEL 2 @@ -52,32 +56,44 @@ static unsigned long bnepgetconnlist; static unsigned long bnepgetconninfo; static struct { - char *str; - uint16_t uuid; + const char *name; /* Friendly name */ + const char *uuid128; /* UUID 128 */ + uint16_t id; /* Service class identifier */ } __svc[] = { - { "PANU", BNEP_SVC_PANU }, - { "NAP", BNEP_SVC_NAP }, - { "GN", BNEP_SVC_GN }, + { "PANU", PANU_UUID, BNEP_SVC_PANU }, + { "GN", GN_UUID, BNEP_SVC_GN }, + { "NAP", NAP_UUID, BNEP_SVC_NAP }, { NULL } }; -int bnep_str2svc(char *svc, uint16_t *uuid) +uint16_t bnep_service_id(const char *svc) { int i; - for (i = 0; __svc[i].str; i++) - if (!strcasecmp(svc, __svc[i].str)) { - *uuid = __svc[i].uuid; - return 0; + + /* Friendly service name */ + for (i = 0; __svc[i].name; i++) + if (!strcasecmp(svc, __svc[i].name)) { + return __svc[i].id; + } + + /* UUID 128 string */ + for (i = 0; __svc[i].uuid128; i++) + if (!strcasecmp(svc, __svc[i].uuid128)) { + return __svc[i].id; } - return -1; + + /* FIXME: Missing HEX string verification */ + + return 0; } -char *bnep_svc2str(uint16_t uuid) +const char *bnep_uuid(uint16_t id) { int i; - for (i = 0; __svc[i].str; i++) - if (__svc[i].uuid == uuid) - return __svc[i].str; + + for (i = 0; __svc[i].uuid128; i++) + if (__svc[i].id == id) + return __svc[i].uuid128; return NULL; } diff --git a/network/common.h b/network/common.h index 11e0b77b..7dfc920a 100644 --- a/network/common.h +++ b/network/common.h @@ -24,8 +24,8 @@ int bnep_init(void); int bnep_cleanup(void); -int bnep_str2svc(char *svc, uint16_t *uuid); -char *bnep_svc2str(uint16_t uuid); +uint16_t bnep_service_id(const char *svc); +const char *bnep_uuid(uint16_t uuid); int bnep_kill_connection(const char *addr); int bnep_kill_all_connections(void); diff --git a/network/connection.c b/network/connection.c index 12a563ad..97034ad6 100644 --- a/network/connection.c +++ b/network/connection.c @@ -50,10 +50,10 @@ struct network_conn { DBusConnection *conn; - char *raddr; - char *path; - char *dev; - uint16_t uuid; + char *raddr; /* Remote Bluetooth Address */ + char *path; /* D-Bus path */ + char *dev; /* BNEP interface name */ + uint16_t id; /* Service Class Identifier */ gboolean up; }; @@ -149,7 +149,7 @@ int bnep_create_connection(int sk, struct network_conn *nc) req->ctrl = BNEP_SETUP_CONN_REQ; req->uuid_size = 2; /* 16bit UUID */ s = (void *) req->service; - s->dst = htons(nc->uuid); + s->dst = htons(nc->id); s->src = htons(BNEP_SVC_PANU); if (send(sk, pkt, sizeof(*req) + sizeof(*s), 0) != -1) { @@ -182,15 +182,15 @@ static DBusHandlerResult get_uuid(DBusConnection *conn, DBusMessage *msg, void *data) { struct network_conn *nc = data; - char *svc; + const char *uuid; DBusMessage *reply; - svc = bnep_svc2str(nc->uuid); + uuid = bnep_uuid(nc->id); reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - dbus_message_append_args(reply, DBUS_TYPE_STRING, &svc, + dbus_message_append_args(reply, DBUS_TYPE_STRING, &uuid, DBUS_TYPE_INVALID); return send_message_and_unref(conn, reply); @@ -433,7 +433,7 @@ int connection_register(DBusConnection *conn, const char *path, nc->path = g_strdup(path); nc->raddr = g_strdup(addr); /* FIXME: Check uuid format */ - bnep_str2svc(uuid, &nc->uuid); + nc->id = bnep_service_id(uuid); /* FIXME: Check for device */ nc->dev = g_new(char, 16); snprintf(nc->dev, 16, "bnep%d", bnep++); diff --git a/network/manager.c b/network/manager.c index dde8c908..ff4d05d4 100644 --- a/network/manager.c +++ b/network/manager.c @@ -28,6 +28,7 @@ #include <bluetooth/bluetooth.h> #include <bluetooth/hci.h> #include <bluetooth/hci_lib.h> +#include <bluetooth/bnep.h> #include <glib.h> @@ -120,26 +121,32 @@ static DBusHandlerResult create_server(DBusConnection *conn, { struct manager *mgr = data; DBusError derr; - const char *uuid; + const char *str; char *path; + uint16_t id; dbus_error_init(&derr); if (!dbus_message_get_args(msg, &derr, - DBUS_TYPE_STRING, &uuid, + DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID)) { err_invalid_args(conn, msg, derr.message); dbus_error_free(&derr); return DBUS_HANDLER_RESULT_HANDLED; } + id = bnep_service_id(str); + if ((id != BNEP_SVC_GN) && (id != BNEP_SVC_NAP)) + return err_invalid_args(conn, msg, "Not supported"); + path = g_new0(char, 32); - snprintf(path, 32, NETWORK_PATH "/server/%s", uuid); + snprintf(path, 32, NETWORK_PATH "/server/%X", id); /* Path already registered */ if (g_slist_find_custom(mgr->servers, path, (GCompareFunc) strcmp)) - return create_path(conn, msg, path, NULL); + return create_path(conn, msg, path, NULL); /* Return already exist error */ - if (server_register(conn, path, uuid) == -1) { + /* FIXME: define which type should be used -- string/uuid str/uui128 */ + if (server_register(conn, path, str) == -1) { err_failed(conn, msg, "D-Bus path registration failed"); g_free(path); return DBUS_HANDLER_RESULT_HANDLED; @@ -217,23 +224,25 @@ static DBusHandlerResult create_connection(DBusConnection *conn, static int uid = 0; DBusError derr; const char *addr; - const char *uuid; + const char *str; char *path; dbus_error_init(&derr); if (!dbus_message_get_args(msg, &derr, DBUS_TYPE_STRING, &addr, - DBUS_TYPE_STRING, &uuid, + DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID)) { err_invalid_args(conn, msg, derr.message); dbus_error_free(&derr); return DBUS_HANDLER_RESULT_HANDLED; } + /* FIXME: Check for supported/implemented client connection */ + path = g_new0(char, 32); snprintf(path, 32, NETWORK_PATH "/connection%d", uid++); - if (connection_register(conn, path, addr, uuid) == -1) { + if (connection_register(conn, path, addr, str) == -1) { err_failed(conn, msg, "D-Bus path registration failed"); g_free(path); return DBUS_HANDLER_RESULT_HANDLED; |