network: using service class identifier instead of the uuid 128 string for server registration

This commit is contained in:
Claudio Takahasi 2007-03-23 21:04:08 +00:00
parent 696c7534ec
commit ef3649fd9e
5 changed files with 26 additions and 16 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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);