summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
Diffstat (limited to 'hcid')
-rw-r--r--hcid/dbus-common.c46
-rw-r--r--hcid/dbus-rfcomm.c41
-rw-r--r--hcid/dbus-sdp.c25
-rw-r--r--hcid/dbus.h1
4 files changed, 63 insertions, 50 deletions
diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c
index e4278330..1687f7e1 100644
--- a/hcid/dbus-common.c
+++ b/hcid/dbus-common.c
@@ -31,6 +31,9 @@
#include <stdlib.h>
#include <string.h>
+#include <bluetooth/sdp.h>
+#include <bluetooth/sdp_lib.h>
+
#include <dbus/dbus.h>
#include "hcid.h"
@@ -327,3 +330,46 @@ service_handler_func_t find_service_handler(struct service_data *handlers, DBusM
return NULL;
}
+
+int str2uuid(uuid_t *uuid, const char *string)
+{
+ uint16_t svclass, data1, data2, data3, data5;
+ uint32_t data0, data4;
+
+ svclass = sdp_str2svclass(string);
+ if (svclass) {
+ sdp_uuid16_create(uuid, sdp_str2svclass(string));
+ return 0;
+ }
+
+ if (strlen(string) == 36 &&
+ string[8] == '-' &&
+ string[13] == '-' &&
+ string[18] == '-' &&
+ string[23] == '-' &&
+ sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
+ &data0, &data1, &data2, &data3, &data4, &data5) == 6) {
+ uint8_t val[16];
+
+ data0 = htonl(data0);
+ data1 = htons(data1);
+ data2 = htons(data2);
+ data3 = htons(data3);
+ data4 = htonl(data4);
+ data5 = htons(data5);
+
+ memcpy(&val[0], &data0, 4);
+ memcpy(&val[4], &data1, 2);
+ memcpy(&val[6], &data2, 2);
+ memcpy(&val[8], &data3, 2);
+ memcpy(&val[10], &data4, 4);
+ memcpy(&val[14], &data5, 2);
+
+ sdp_uuid128_create(uuid, val);
+ return 0;
+ }
+
+ return -1;
+}
+
+
diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c
index 225175f0..e413851c 100644
--- a/hcid/dbus-rfcomm.c
+++ b/hcid/dbus-rfcomm.c
@@ -650,47 +650,6 @@ failed:
rfcomm_continue_data_free(cdata);
}
-static int str2uuid(uuid_t *uuid, const char *string)
-{
- uint16_t svclass, data1, data2, data3, data5;
- uint32_t data0, data4;
-
- svclass = sdp_str2svclass(string);
- if (svclass) {
- sdp_uuid16_create(uuid, sdp_str2svclass(string));
- return 0;
- }
-
- if (strlen(string) == 36 &&
- string[8] == '-' &&
- string[13] == '-' &&
- string[18] == '-' &&
- string[23] == '-' &&
- sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
- &data0, &data1, &data2, &data3, &data4, &data5) == 6) {
- uint8_t val[16];
-
- data0 = htonl(data0);
- data1 = htons(data1);
- data2 = htons(data2);
- data3 = htons(data3);
- data4 = htonl(data4);
- data5 = htons(data5);
-
- memcpy(&val[0], &data0, 4);
- memcpy(&val[4], &data1, 2);
- memcpy(&val[6], &data2, 2);
- memcpy(&val[8], &data3, 2);
- memcpy(&val[10], &data4, 4);
- memcpy(&val[14], &data5, 2);
-
- sdp_uuid128_create(uuid, val);
- return 0;
- }
-
- return -1;
-}
-
static DBusHandlerResult rfcomm_connect_req(DBusConnection *conn,
DBusMessage *msg, void *data)
{
diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c
index 6a101bd7..f17c8c31 100644
--- a/hcid/dbus-sdp.c
+++ b/hcid/dbus-sdp.c
@@ -934,7 +934,6 @@ static int remote_svc_handles_conn_cb(struct transaction_context *ctxt)
const char *dst, *svc;
uuid_t uuid;
int err = 0;
- uint32_t class;
if (sdp_set_notify(ctxt->session, remote_svc_handles_completed_cb, ctxt) < 0) {
err = -EINVAL;
@@ -946,9 +945,13 @@ static int remote_svc_handles_conn_cb(struct transaction_context *ctxt)
DBUS_TYPE_STRING, &svc,
DBUS_TYPE_INVALID);
- if (strlen(svc) > 0 ){
- class = sdp_str2svclass(svc);
- sdp_uuid16_create(&uuid, class);
+ if (strlen(svc) > 0) {
+ /* Check if it is a service name string */
+ if (str2uuid(&uuid, svc) < 0) {
+ /* check if the service string is a hex */
+ uint32_t uuid_hex = strtol(svc, NULL, 16);
+ sdp_uuid16_create(&uuid, uuid_hex);
+ }
} else
sdp_uuid16_create(&uuid, PUBLIC_BROWSE_GROUP);
@@ -973,7 +976,7 @@ DBusHandlerResult get_remote_svc_handles(DBusConnection *conn, DBusMessage *msg,
struct hci_dbus_data *dbus_data = data;
const char *dst, *svc;
int err = 0;
- uint32_t class;
+ uuid_t uuid;
if (!dbus_message_get_args(msg, NULL,
DBUS_TYPE_STRING, &dst,
@@ -982,10 +985,14 @@ DBusHandlerResult get_remote_svc_handles(DBusConnection *conn, DBusMessage *msg,
return error_invalid_arguments(conn, msg);
if (strlen(svc) > 0) {
- class = sdp_str2svclass(svc);
- if (!class) {
- error("Invalid service class name");
- return error_invalid_arguments(conn, msg);
+ /* Check if it is a service name string */
+ if (str2uuid(&uuid, svc) < 0) {
+ /* check if the service string is a hex */
+ uint32_t uuid_hex = strtol(svc, NULL, 16);
+ if (!uuid_hex) {
+ error("Invalid service class name");
+ return error_invalid_arguments(conn, msg);
+ }
}
}
diff --git a/hcid/dbus.h b/hcid/dbus.h
index 660a0b56..b32fec9f 100644
--- a/hcid/dbus.h
+++ b/hcid/dbus.h
@@ -215,6 +215,7 @@ DBusHandlerResult get_remote_svc_rec(DBusConnection *conn, DBusMessage *msg, voi
DBusHandlerResult simple_introspect(DBusConnection *conn, DBusMessage *msg, void *data);
service_handler_func_t find_service_handler(struct service_data *services, DBusMessage *msg);
+int str2uuid(uuid_t *uuid, const char *string);
void create_bond_req_exit(const char *name, struct hci_dbus_data *pdata);
void discover_devices_req_exit(const char *name, struct hci_dbus_data *pdata);