summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hcid/dbus-manager.c80
-rw-r--r--hcid/dbus-service.c66
-rw-r--r--hcid/dbus-service.h11
3 files changed, 115 insertions, 42 deletions
diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c
index e9d5822b..dd071ce1 100644
--- a/hcid/dbus-manager.c
+++ b/hcid/dbus-manager.c
@@ -49,7 +49,6 @@
#include "dbus-manager.h"
static int default_adapter_id = -1;
-static uint32_t next_handle = 0x10000;
static int autostart = 1;
static DBusHandlerResult interface_version(DBusConnection *conn,
@@ -364,11 +363,11 @@ static DBusHandlerResult unregister_shadow_service(DBusConnection *conn,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static sdp_record_t *service_record_extract(DBusMessageIter *iter)
+static sdp_buf_t *service_record_extract(DBusMessageIter *iter)
{
+ sdp_buf_t *sdp_buf;
uint8_t buff[SDP_RSP_BUFFER_SIZE];
- sdp_record_t *record;
- int recsize, index = 0;
+ int index = 0;
uint8_t value;
memset(buff, 0, SDP_RSP_BUFFER_SIZE);
@@ -380,9 +379,17 @@ static sdp_record_t *service_record_extract(DBusMessageIter *iter)
dbus_message_iter_next(iter);
}
- record = sdp_extract_pdu(buff, &recsize);
+ sdp_buf = malloc(sizeof(sdp_buf_t));
+ if (!sdp_buf)
+ return NULL;
- return record;
+ memset(sdp_buf, 0, sizeof(sdp_buf_t));
+ sdp_buf->data = malloc(index);
+ sdp_buf->data_size = index;
+ sdp_buf->buf_size = index;
+ memcpy(sdp_buf->data, buff, index);
+
+ return sdp_buf;
}
static DBusHandlerResult add_service_record(DBusConnection *conn,
@@ -391,7 +398,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,
struct service_agent *agent;
DBusMessageIter iter, array_iter;
DBusMessage *reply;
- sdp_record_t *record;
+ struct binary_record *rec;
const char *path;
int err;
@@ -418,16 +425,21 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- record = service_record_extract(&array_iter);
- if (!record) {
+ rec = binary_record_new();
+ if (!rec)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ rec->buf = service_record_extract(&array_iter);
+ if (!rec->buf) {
+ binary_record_free(rec);
dbus_message_unref(reply);
return error_invalid_arguments(conn, msg);
}
- record->handle = next_handle++;
-
if (agent->running) {
sdp_session_t *sess;
+ uint32_t handle = 0;
+
sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0);
if (!sess) {
err = errno;
@@ -436,8 +448,8 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,
goto fail;
}
- if (sdp_device_record_register(sess, BDADDR_ANY, record,
- SDP_RECORD_PERSIST) < 0) {
+ if (sdp_device_record_register_binary(sess, BDADDR_LOCAL, rec->buf->data,
+ rec->buf->data_size, SDP_RECORD_PERSIST, &handle) < 0) {
err = errno;
sdp_close(sess);
error("Record registration failed: %s (%d)",
@@ -445,37 +457,34 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,
goto fail;
}
+ rec->handle = handle;
+
sdp_close(sess);
}
- agent->records = slist_append(agent->records, record);
+ agent->records = slist_append(agent->records, rec);
dbus_message_append_args(msg,
- DBUS_TYPE_UINT32, &record->handle),
+ DBUS_TYPE_UINT32, &rec->handle),
DBUS_TYPE_INVALID;
return send_message_and_unref(conn, reply);
fail:
- sdp_record_free(record);
+ binary_record_free(rec);
dbus_message_unref(reply);
return error_failed(conn, msg, err);
}
-static int sdp_record_cmp(sdp_record_t *a, uint32_t *handle)
-{
- return (a->handle - *handle);
-}
-
static DBusHandlerResult remove_service_record(DBusConnection *conn,
DBusMessage *msg, void *data)
{
struct service_agent *agent;
+ struct binary_record *rec;
DBusMessage *reply;
struct slist *l;
const char *path;
uint32_t handle;
- void *rec;
if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_STRING, &path,
@@ -493,7 +502,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn,
return error_not_authorized(conn, msg);
- l = slist_find(agent->records, &handle, (cmp_func_t) sdp_record_cmp);
+ l = slist_find(agent->records, &handle, (cmp_func_t) binary_record_cmp);
if (!l)
return error_record_does_not_exist(conn, msg);
@@ -506,15 +515,26 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn,
/* If the service agent is running: remove it from the from sdpd */
if (agent->running) {
- struct slist *lunreg = NULL;
- lunreg = slist_append(lunreg, rec);
- //unregister_agent_records(lunreg);
- lunreg = slist_remove(lunreg, rec);
- slist_free(lunreg);
+ sdp_session_t *sess;
+
+ /* FIXME: attach to a specific adapter */
+ sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0);
+ if (!sess) {
+ error("Can't connect to sdp daemon:(%s, %d)",
+ strerror(errno), errno);
+ goto fail;
+ }
+
+ if (sdp_device_record_unregister_binary(sess, BDADDR_ANY,
+ rec->handle) < 0) {
+ error("Service Record unregistration failed:(%s, %d)",
+ strerror(errno), errno);
+ }
+ sdp_close(sess);
}
- /* FIXME: currently sdp_device_record_unregister free the service record */
- //sdp_record_free(rec);
+fail:
+ binary_record_free(rec);
return send_message_and_unref(conn, reply);
}
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c
index b4207059..00693439 100644
--- a/hcid/dbus-service.c
+++ b/hcid/dbus-service.c
@@ -46,6 +46,39 @@
static struct slist *services = NULL;
+struct binary_record *binary_record_new()
+{
+ struct binary_record *rec;
+ rec = malloc(sizeof(struct binary_record));
+ if (!rec)
+ return NULL;
+
+ memset(rec, 0, sizeof(struct binary_record));
+ rec->handle = 0xffffffff;
+
+ return rec;
+}
+
+void binary_record_free(struct binary_record *rec)
+{
+ if (!rec)
+ return;
+
+ if (rec->buf) {
+ if (rec->buf->data)
+ free(rec->buf->data);
+ free(rec->buf);
+ }
+
+ free(rec);
+}
+
+int binary_record_cmp(struct binary_record *rec, uint32_t *handle)
+{
+ return (rec->handle - *handle);
+}
+
+
struct service_call *service_call_new(DBusConnection *conn, DBusMessage *msg,
struct service_agent *agent)
{
@@ -128,8 +161,7 @@ static void service_agent_free(struct service_agent *agent)
}
if (agent->records) {
- /* FIXME: currently sdp_device_record_unregister free the service record */
- //slist_foreach(agent->records, (slist_func_t) sdp_record_free, NULL);
+ slist_foreach(agent->records, (slist_func_t) binary_record_free, NULL);
slist_free(agent->records);
}
@@ -176,7 +208,8 @@ mem_fail:
int register_agent_records(struct slist *lrecords)
{
sdp_session_t *sess;
- sdp_record_t *rec;
+ struct binary_record *rec;
+ uint32_t handle;
/* FIXME: attach to a specific adapter */
sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0);
@@ -187,12 +220,19 @@ int register_agent_records(struct slist *lrecords)
while (lrecords) {
rec = lrecords->data;
- if (sdp_device_record_register(sess, BDADDR_ANY, rec, SDP_RECORD_PERSIST) < 0) {
+ lrecords = lrecords->next;
+
+ if (!rec || !rec->buf)
+ continue;
+
+ handle = 0;
+ if (sdp_device_record_register_binary(sess, BDADDR_LOCAL, rec->buf->data,
+ rec->buf->data_size, SDP_RECORD_PERSIST, &handle) < 0) {
/* FIXME: If just one of the service record registration fails */
- error("Service Record registration failed:(%s, %d)", strerror(errno), errno);
+ error("Service Record registration failed:(%s, %d)",
+ strerror(errno), errno);
}
-
- lrecords = lrecords->next;
+ rec->handle = handle;
}
sdp_close(sess);
return 0;
@@ -201,7 +241,7 @@ int register_agent_records(struct slist *lrecords)
static int unregister_agent_records(struct slist *lrecords)
{
sdp_session_t *sess;
- sdp_record_t *rec;
+ struct binary_record *rec;
/* FIXME: attach to a specific adapter */
sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0);
@@ -212,11 +252,15 @@ static int unregister_agent_records(struct slist *lrecords)
while (lrecords) {
rec = lrecords->data;
- if (sdp_device_record_unregister(sess, BDADDR_ANY, rec) < 0) {
+ lrecords = lrecords->next;
+ if (!rec)
+ continue;
+
+ if (sdp_device_record_unregister_binary(sess, BDADDR_ANY, rec->handle) < 0) {
/* FIXME: If just one of the service record registration fails */
- error("Service Record unregistration failed:(%s, %d)", strerror(errno), errno);
+ error("Service Record unregistration failed:(%s, %d)",
+ strerror(errno), errno);
}
- lrecords = lrecords->next;
}
sdp_close(sess);
return 0;
diff --git a/hcid/dbus-service.h b/hcid/dbus-service.h
index 3ed36099..4476d937 100644
--- a/hcid/dbus-service.h
+++ b/hcid/dbus-service.h
@@ -34,7 +34,7 @@ struct service_agent {
char *description;
int running;
struct slist *trusted_devices;
- struct slist *records;
+ struct slist *records; /* list of binary records */
};
struct service_call {
@@ -43,6 +43,15 @@ struct service_call {
struct service_agent *agent;
};
+struct binary_record {
+ uint32_t handle;
+ sdp_buf_t *buf;
+};
+
+struct binary_record *binary_record_new();
+void binary_record_free(struct binary_record *rec);
+int binary_record_cmp(struct binary_record *rec, uint32_t *handle);
+
int register_service_agent(DBusConnection *conn, const char *sender, const char *path,
const char *name, const char *description);
int unregister_service_agent(DBusConnection *conn, const char *sender,