* [Bluez-devel] hcid patch (remote name and connections)
@ 2005-10-11 14:26 Claudio Takahasi
2005-10-11 14:49 ` [Bluez-devel] " Claudio Takahasi
2005-10-11 18:01 ` [Bluez-devel] " Marcel Holtmann
0 siblings, 2 replies; 14+ messages in thread
From: Claudio Takahasi @ 2005-10-11 14:26 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1.1: Type: text/plain, Size: 371 bytes --]
Hi folks/Marcel,
I added the support to remote name and display connections.
This patch is based on dbus.c revision 1.20
There is a command line client attached to test the added services.
Regards,
Claudio
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #1.2: Type: text/html, Size: 500 bytes --]
[-- Attachment #2: bluez-hcid-dbus-client.tar.gz --]
[-- Type: application/x-gzip, Size: 388546 bytes --]
[-- Attachment #3: rem_name_connections_01.patch --]
[-- Type: application/octet-stream, Size: 7599 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2005-10-09 19:15:22.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-10 17:37:57.000000000 -0300
@@ -122,6 +122,8 @@
#define HCI_CANCEL_PERIODIC_INQ "CancelPeriodic"
#define HCI_INQ "Inquiry"
#define HCI_ROLE_SWITCH "RoleSwitch"
+#define HCI_REMOTE_NAME "RemoteName"
+#define HCI_CONNECTIONS "Connections"
#define HCI_PERIODIC_INQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
@@ -139,6 +141,21 @@
#define HCI_ROLE_SWITCH_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
DBUS_TYPE_BYTE_AS_STRING\
__END_SIG__
+
+#define HCI_REMOTE_NAME_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+ __END_SIG__
+
+#define HCI_CONNECTIONS_SIGNATURE __END_SIG__
+
+#define HCI_CONN_INFO_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_TYPE_UINT32_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING\
+ __END_SIG__
#define HCI_DEVICE_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
DBUS_TYPE_STRING_AS_STRING\
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-10-11 11:10:21.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-11 11:20:40.000000000 -0300
@@ -58,6 +58,7 @@
#define BLUETOOTH_DEVICE_NAME_LEN (18)
#define BLUETOOTH_DEVICE_ADDR_LEN (18)
#define MAX_PATH_LENGTH (64)
+#define READ_REMOTE_NAME_TIMEOUT 25000
#define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
#define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -125,14 +126,12 @@
if (ecode & BLUEZ_ESYSTEM_OFFSET) {
/* System error */
- raw_code = (!BLUEZ_ESYSTEM_OFFSET) & ecode;
- syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, strerror(raw_code));
+ raw_code = (~BLUEZ_ESYSTEM_OFFSET) & ecode;
return strerror(raw_code);
} else if (ecode & BLUEZ_EDBUS_OFFSET) {
/* D-Bus error */
for (ptr = error_array; ptr->code; ptr++) {
if (ptr->code == ecode) {
- syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, ptr->str);
return ptr->str;
}
}
@@ -217,12 +216,16 @@
static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data);
static DBusMessage* handle_inq_req(DBusMessage *msg, void *data);
static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_remote_name_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data);
static const struct service_data hci_services[] = {
{ HCI_PERIODIC_INQ, handle_periodic_inq_req, HCI_PERIODIC_INQ_SIGNATURE },
{ HCI_CANCEL_PERIODIC_INQ, handle_cancel_periodic_inq_req, HCI_CANCEL_PERIODIC_INQ_SIGNATURE },
{ HCI_ROLE_SWITCH, handle_role_switch_req, HCI_ROLE_SWITCH_SIGNATURE },
{ HCI_INQ, handle_inq_req, HCI_INQ_SIGNATURE },
+ { HCI_REMOTE_NAME, handle_remote_name_req, HCI_REMOTE_NAME_SIGNATURE },
+ { HCI_CONNECTIONS, handle_display_conn_req, HCI_CONNECTIONS_SIGNATURE },
{ NULL, NULL, NULL }
};
@@ -838,7 +841,6 @@
signature = dbus_message_get_signature(msg);
syslog (LOG_INFO, "%s - path:%s, udata:0x%X", __PRETTY_FUNCTION__, path, (guint) udata);
-
if (strcmp(path, DEVICE_PATH) == 0) {
ptr_handlers = dev_services;
tmp_iface = DEVICE_INTERFACE;
@@ -898,17 +900,18 @@
reply = bluez_new_failure_msg(msg, result);
}
- /* send an error or the success reply*/
- if (reply) {
- if (!dbus_connection_send (conn, reply, NULL)) {
- syslog(LOG_ERR, "%s line:%d Can't send reply message!",
- __PRETTY_FUNCTION__, __LINE__) ;
- }
- dbus_message_unref (reply);
- }
ret = DBUS_HANDLER_RESULT_HANDLED;
}
+
+ /* send an error or the success reply*/
+ if (reply) {
+ if (!dbus_connection_send (conn, reply, NULL)) {
+ syslog(LOG_ERR, "Can't send reply message!");
+ }
+ dbus_message_unref (reply);
+ }
+
return ret;
}
@@ -1162,6 +1165,126 @@
return reply;
}
+static DBusMessage* handle_remote_name_req(DBusMessage *msg, void *data)
+{
+ char name[64];
+ const char *pname = name;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ long udata = (long) data;
+ int dev_id = -1;
+ int dd = -1;
+ const char *str_bdaddr;
+ bdaddr_t bdaddr;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &str_bdaddr);
+
+ str2ba(str_bdaddr, &bdaddr);
+
+ if (udata == DEFAULT_DEVICE_PATH_ID) {
+ if ((dev_id = hci_get_route(&bdaddr)) < 0) {
+ syslog(LOG_ERR, "Bluetooth device is not available");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto failed;
+ }
+ } else {
+ dev_id = (int) udata;
+ }
+
+ if ((dd = hci_open_dev(dev_id)) > 0) {
+
+ if (hci_read_remote_name(dd, &bdaddr, sizeof(name), name, READ_REMOTE_NAME_TIMEOUT) ==0) {
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &pname);
+ } else {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ }
+ } else {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ }
+
+ if (dd > 0)
+ close (dd);
+
+failed:
+ return reply;
+}
+
+static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data)
+{
+ struct hci_conn_list_req *cl = NULL;
+ struct hci_conn_info *ci = NULL;
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ char addr[18];
+ const char array_sig[] = HCI_CONN_INFO_STRUCT_SIGNATURE;
+ const char *paddr = addr;
+ long udata = (long) data;
+ int i;
+ int dev_id = -1;
+ int sk;
+
+ if (udata == DEFAULT_DEVICE_PATH_ID) {
+ if ((dev_id = hci_get_route(NULL)) < 0) {
+ syslog(LOG_ERR, "Bluetooth device is not available");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto failed;
+ }
+ } else {
+ dev_id = (int) udata;
+ }
+
+ sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+
+ if (sk < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+ goto failed;
+ }
+
+ cl->dev_id = dev_id;
+ cl->conn_num = 10;
+ ci = cl->conn_info;
+
+ if (ioctl(sk, HCIGETCONNLIST, (void *) cl)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, array_sig, &array_iter);
+
+ for (i = 0; i < cl->conn_num; i++, ci++) {
+ ba2str(&ci->bdaddr, addr);
+
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 ,&(ci->handle));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&paddr);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE ,&(ci->type));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE ,&(ci->out));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 ,&(ci->state));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT32 ,&(ci->link_mode));
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+
+ dbus_message_iter_close_container(&iter, &array_iter);
+failed:
+
+ if (cl)
+ free (cl);
+
+ return reply;
+}
+
/*****************************************************************
*
* Section reserved to Device D-Bus message handlers
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bluez-devel] Re: hcid patch (remote name and connections)
2005-10-11 14:26 [Bluez-devel] hcid patch (remote name and connections) Claudio Takahasi
@ 2005-10-11 14:49 ` Claudio Takahasi
2005-10-11 19:47 ` Steven Singer
2005-10-11 18:01 ` [Bluez-devel] " Marcel Holtmann
1 sibling, 1 reply; 14+ messages in thread
From: Claudio Takahasi @ 2005-10-11 14:49 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1.1: Type: text/plain, Size: 974 bytes --]
Hi folks, Marcel,
I added the support to remote name and display connections.
This patch is based on dbus.c revision 1.20
Marcel, please ignore the blocked e-mail. I sent a big attachement. :)
There is a command line client to test the added services:
http://www.cin.ufpe.br/~ckt/bluez/bluez-hcid-dbus-client.tar.gz
Regards,
Claudio.
On 10/11/05, Claudio Takahasi <cktakahasi@gmail.com> wrote:
>
> Hi folks/Marcel,
>
> I added the support to remote name and display connections.
> This patch is based on dbus.c revision 1.20
>
> There is a command line client attached to test the added services.
>
> Regards,
> Claudio
>
> --
> ---------------------------------------------------------
> Claudio Takahasi
> Nokia's Institute of Technology - INdT
> claudio.takahasi@indt.org.br
>
>
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #1.2: Type: text/html, Size: 1668 bytes --]
[-- Attachment #2: rem_name_connections_01.patch --]
[-- Type: application/octet-stream, Size: 7599 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2005-10-09 19:15:22.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-10 17:37:57.000000000 -0300
@@ -122,6 +122,8 @@
#define HCI_CANCEL_PERIODIC_INQ "CancelPeriodic"
#define HCI_INQ "Inquiry"
#define HCI_ROLE_SWITCH "RoleSwitch"
+#define HCI_REMOTE_NAME "RemoteName"
+#define HCI_CONNECTIONS "Connections"
#define HCI_PERIODIC_INQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
@@ -139,6 +141,21 @@
#define HCI_ROLE_SWITCH_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
DBUS_TYPE_BYTE_AS_STRING\
__END_SIG__
+
+#define HCI_REMOTE_NAME_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+ __END_SIG__
+
+#define HCI_CONNECTIONS_SIGNATURE __END_SIG__
+
+#define HCI_CONN_INFO_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_TYPE_UINT32_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING\
+ __END_SIG__
#define HCI_DEVICE_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
DBUS_TYPE_STRING_AS_STRING\
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-10-11 11:10:21.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-11 11:20:40.000000000 -0300
@@ -58,6 +58,7 @@
#define BLUETOOTH_DEVICE_NAME_LEN (18)
#define BLUETOOTH_DEVICE_ADDR_LEN (18)
#define MAX_PATH_LENGTH (64)
+#define READ_REMOTE_NAME_TIMEOUT 25000
#define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
#define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -125,14 +126,12 @@
if (ecode & BLUEZ_ESYSTEM_OFFSET) {
/* System error */
- raw_code = (!BLUEZ_ESYSTEM_OFFSET) & ecode;
- syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, strerror(raw_code));
+ raw_code = (~BLUEZ_ESYSTEM_OFFSET) & ecode;
return strerror(raw_code);
} else if (ecode & BLUEZ_EDBUS_OFFSET) {
/* D-Bus error */
for (ptr = error_array; ptr->code; ptr++) {
if (ptr->code == ecode) {
- syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, ptr->str);
return ptr->str;
}
}
@@ -217,12 +216,16 @@
static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data);
static DBusMessage* handle_inq_req(DBusMessage *msg, void *data);
static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_remote_name_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data);
static const struct service_data hci_services[] = {
{ HCI_PERIODIC_INQ, handle_periodic_inq_req, HCI_PERIODIC_INQ_SIGNATURE },
{ HCI_CANCEL_PERIODIC_INQ, handle_cancel_periodic_inq_req, HCI_CANCEL_PERIODIC_INQ_SIGNATURE },
{ HCI_ROLE_SWITCH, handle_role_switch_req, HCI_ROLE_SWITCH_SIGNATURE },
{ HCI_INQ, handle_inq_req, HCI_INQ_SIGNATURE },
+ { HCI_REMOTE_NAME, handle_remote_name_req, HCI_REMOTE_NAME_SIGNATURE },
+ { HCI_CONNECTIONS, handle_display_conn_req, HCI_CONNECTIONS_SIGNATURE },
{ NULL, NULL, NULL }
};
@@ -838,7 +841,6 @@
signature = dbus_message_get_signature(msg);
syslog (LOG_INFO, "%s - path:%s, udata:0x%X", __PRETTY_FUNCTION__, path, (guint) udata);
-
if (strcmp(path, DEVICE_PATH) == 0) {
ptr_handlers = dev_services;
tmp_iface = DEVICE_INTERFACE;
@@ -898,17 +900,18 @@
reply = bluez_new_failure_msg(msg, result);
}
- /* send an error or the success reply*/
- if (reply) {
- if (!dbus_connection_send (conn, reply, NULL)) {
- syslog(LOG_ERR, "%s line:%d Can't send reply message!",
- __PRETTY_FUNCTION__, __LINE__) ;
- }
- dbus_message_unref (reply);
- }
ret = DBUS_HANDLER_RESULT_HANDLED;
}
+
+ /* send an error or the success reply*/
+ if (reply) {
+ if (!dbus_connection_send (conn, reply, NULL)) {
+ syslog(LOG_ERR, "Can't send reply message!");
+ }
+ dbus_message_unref (reply);
+ }
+
return ret;
}
@@ -1162,6 +1165,126 @@
return reply;
}
+static DBusMessage* handle_remote_name_req(DBusMessage *msg, void *data)
+{
+ char name[64];
+ const char *pname = name;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ long udata = (long) data;
+ int dev_id = -1;
+ int dd = -1;
+ const char *str_bdaddr;
+ bdaddr_t bdaddr;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &str_bdaddr);
+
+ str2ba(str_bdaddr, &bdaddr);
+
+ if (udata == DEFAULT_DEVICE_PATH_ID) {
+ if ((dev_id = hci_get_route(&bdaddr)) < 0) {
+ syslog(LOG_ERR, "Bluetooth device is not available");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto failed;
+ }
+ } else {
+ dev_id = (int) udata;
+ }
+
+ if ((dd = hci_open_dev(dev_id)) > 0) {
+
+ if (hci_read_remote_name(dd, &bdaddr, sizeof(name), name, READ_REMOTE_NAME_TIMEOUT) ==0) {
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &pname);
+ } else {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ }
+ } else {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ }
+
+ if (dd > 0)
+ close (dd);
+
+failed:
+ return reply;
+}
+
+static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data)
+{
+ struct hci_conn_list_req *cl = NULL;
+ struct hci_conn_info *ci = NULL;
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ char addr[18];
+ const char array_sig[] = HCI_CONN_INFO_STRUCT_SIGNATURE;
+ const char *paddr = addr;
+ long udata = (long) data;
+ int i;
+ int dev_id = -1;
+ int sk;
+
+ if (udata == DEFAULT_DEVICE_PATH_ID) {
+ if ((dev_id = hci_get_route(NULL)) < 0) {
+ syslog(LOG_ERR, "Bluetooth device is not available");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto failed;
+ }
+ } else {
+ dev_id = (int) udata;
+ }
+
+ sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+
+ if (sk < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+ goto failed;
+ }
+
+ cl->dev_id = dev_id;
+ cl->conn_num = 10;
+ ci = cl->conn_info;
+
+ if (ioctl(sk, HCIGETCONNLIST, (void *) cl)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, array_sig, &array_iter);
+
+ for (i = 0; i < cl->conn_num; i++, ci++) {
+ ba2str(&ci->bdaddr, addr);
+
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 ,&(ci->handle));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&paddr);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE ,&(ci->type));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE ,&(ci->out));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 ,&(ci->state));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT32 ,&(ci->link_mode));
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+
+ dbus_message_iter_close_container(&iter, &array_iter);
+failed:
+
+ if (cl)
+ free (cl);
+
+ return reply;
+}
+
/*****************************************************************
*
* Section reserved to Device D-Bus message handlers
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] hcid patch (remote name and connections)
2005-10-11 14:26 [Bluez-devel] hcid patch (remote name and connections) Claudio Takahasi
2005-10-11 14:49 ` [Bluez-devel] " Claudio Takahasi
@ 2005-10-11 18:01 ` Marcel Holtmann
2005-10-11 19:28 ` Johan Hedberg
1 sibling, 1 reply; 14+ messages in thread
From: Marcel Holtmann @ 2005-10-11 18:01 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> I added the support to remote name and display connections.
> This patch is based on dbus.c revision 1.20
let's wait until Johan finished his patch to remove the bad pointer
versus integer casting.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] hcid patch (remote name and connections)
2005-10-11 18:01 ` [Bluez-devel] " Marcel Holtmann
@ 2005-10-11 19:28 ` Johan Hedberg
2005-10-11 19:45 ` Steven Singer
0 siblings, 1 reply; 14+ messages in thread
From: Johan Hedberg @ 2005-10-11 19:28 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 540 bytes --]
On Tue, Oct 11, 2005, Marcel Holtmann wrote:
> let's wait until Johan finished his patch to remove the bad pointer
> versus integer casting.
Here you go. The idea was to wait for Claudio's new patch to be applied
first, but I guess we can do it in this order also. Btw, I haven't
tested the patch too much, but at least it compiles without warnings and
seems to run also withough any problems. The patch also changes the
dbus_watch stuff to use dynamically allocated memory instead of the
integer-pointer cast it was doing earlier.
Johan
[-- Attachment #2: dbus-struct.patch --]
[-- Type: text/plain, Size: 9331 bytes --]
Index: dbus.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.c,v
retrieving revision 1.20
diff -u -r1.20 dbus.c
--- dbus.c 11 Oct 2005 10:13:10 -0000 1.20
+++ dbus.c 11 Oct 2005 19:05:56 -0000
@@ -77,6 +77,10 @@
const char *signature;
};
+struct hci_dbus_data {
+ uint16_t id;
+};
+
typedef int register_function_t(DBusConnection *conn, int dft_reg, uint16_t id);
typedef int unregister_function_t(DBusConnection *conn, int unreg_dft, uint16_t id);
@@ -507,12 +511,16 @@
{
GIOCondition cond = G_IO_HUP | G_IO_ERR;
GIOChannel *io;
- gulong id;
+ guint *id;
int fd, flags;
if (!dbus_watch_get_enabled(watch))
return TRUE;
+ id = malloc(sizeof(guint));
+ if (id == NULL)
+ return FALSE;
+
fd = dbus_watch_get_fd(watch);
io = g_io_channel_unix_new(fd);
flags = dbus_watch_get_flags(watch);
@@ -520,21 +528,23 @@
if (flags & DBUS_WATCH_READABLE) cond |= G_IO_IN;
if (flags & DBUS_WATCH_WRITABLE) cond |= G_IO_OUT;
- id = (gulong) g_io_add_watch(io, cond, watch_func, watch);
+ *id = g_io_add_watch(io, cond, watch_func, watch);
- dbus_watch_set_data(watch, (void *) id, NULL);
+ dbus_watch_set_data(watch, id, NULL);
return TRUE;
}
static void remove_watch(DBusWatch *watch, void *data)
{
- gulong id = (gulong) dbus_watch_get_data(watch);
+ guint *id = dbus_watch_get_data(watch);
dbus_watch_set_data(watch, NULL, NULL);
- if (id)
- g_io_remove_watch((guint) id);
+ if (id) {
+ g_io_remove_watch(*id);
+ free(id);
+ }
}
static void watch_toggled(DBusWatch *watch, void *data)
@@ -549,6 +559,7 @@
gboolean hcid_dbus_init(void)
{
+ struct hci_dbus_data *data;
DBusError error;
dbus_error_init(&error);
@@ -572,16 +583,28 @@
return FALSE;
}
+ data = malloc(sizeof(struct hci_dbus_data));
+ if (data == NULL)
+ return FALSE;
+
+ data->id = DEVICE_PATH_ID;
+
if (!dbus_connection_register_object_path(connection, DEVICE_PATH,
- &obj_vtable, (void *)DEVICE_PATH_ID)) {
+ &obj_vtable, data)) {
syslog(LOG_ERR, "Can't register %s object", DEVICE_PATH);
return FALSE;
}
syslog(LOG_INFO,"Registered %s object", DEVICE_PATH);
+ data = malloc(sizeof(struct hci_dbus_data));
+ if (data == NULL)
+ return FALSE;
+
+ data->id = MANAGER_PATH_ID;
+
if (!dbus_connection_register_fallback(connection, MANAGER_PATH,
- &obj_vtable, (void *)MANAGER_PATH_ID)) {
+ &obj_vtable, data)) {
syslog(LOG_ERR, "Can't register %s object", MANAGER_PATH);
return FALSE;
}
@@ -608,15 +631,32 @@
char **snd_level = NULL;
char *ptr1;
char *ptr2;
+ void *data = NULL;
if (!connection)
return;
+ if (dbus_connection_get_object_path_data(connection,
+ DEVICE_PATH, &data)) {
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ }
+
if (!dbus_connection_unregister_object_path(connection, DEVICE_PATH))
syslog(LOG_ERR, "Can't unregister %s object", DEVICE_PATH);
else
syslog(LOG_INFO, "Unregistered %s object", DEVICE_PATH);
+ if (dbus_connection_get_object_path_data(connection,
+ MANAGER_PATH, &data)) {
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ }
+
if (!dbus_connection_unregister_object_path(connection, MANAGER_PATH))
syslog(LOG_ERR, "Can't unregister %s object", MANAGER_PATH);
else
@@ -635,6 +675,14 @@
syslog(LOG_INFO, "Unregistered %s object", path);
+ if (dbus_connection_get_object_path_data(connection,
+ path, &data)) {
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ }
+
if (!dbus_connection_unregister_object_path(connection, path))
syslog(LOG_ERR, "Can't unregister %s object", path);
@@ -647,6 +695,14 @@
syslog(LOG_INFO, "Unregistered %s object", path);
+ if (dbus_connection_get_object_path_data(connection,
+ path, &data)) {
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ }
+
if (!dbus_connection_unregister_object_path(connection, path))
syslog(LOG_ERR, "Can't unregister %s object", path);
}
@@ -709,6 +765,7 @@
*/
static int hci_dbus_reg_obj_path(DBusConnection *conn, int dft_reg, uint16_t id)
{
+ struct hci_dbus_data *data;
char path[MAX_PATH_LENGTH];
/* register the default path*/
@@ -723,12 +780,18 @@
}
}
+ data = malloc(sizeof(struct hci_dbus_data));
+ if (data == NULL)
+ return -1;
+
+ data->id = id;
+
/* register the default path*/
sprintf(path, "%s/%s%d/%s", MANAGER_PATH, HCI_DEVICE_NAME, id, BLUEZ_HCI);
syslog(LOG_INFO, "registering - path:%s - id:%d",path, id);
- if (!dbus_connection_register_object_path(conn, path, &obj_vtable, (void *) ((long) id))) {
+ if (!dbus_connection_register_object_path(conn, path, &obj_vtable, data)) {
syslog(LOG_ERR,"DBUS failed to register %s object", path);
/* ignore, the path was already registered */
}
@@ -751,6 +814,7 @@
int ret = 0;
char path[MAX_PATH_LENGTH];
char dft_path[MAX_PATH_LENGTH];
+ void *data = NULL;
if (unreg_dft) {
sprintf(dft_path, "%s/%s/%s", MANAGER_PATH, HCI_DEFAULT_DEVICE_NAME, BLUEZ_HCI);
@@ -758,6 +822,13 @@
if (!dbus_connection_unregister_object_path (connection, dft_path)) {
syslog(LOG_ERR,"DBUS failed to unregister %s object", dft_path);
ret = -1;
+ } else {
+ if (dbus_connection_get_object_path_data(conn, dft_path, &data)) {
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ }
}
}
@@ -766,6 +837,13 @@
if (!dbus_connection_unregister_object_path (connection, path)) {
syslog(LOG_ERR,"DBUS failed to unregister %s object", path);
ret = -1;
+ } else {
+ if (dbus_connection_get_object_path_data(conn, path, &data)) {
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ }
}
return ret;
@@ -826,7 +904,7 @@
const char *path;
const char *rel_path;
const char *tmp_iface = NULL;
- long udata = (long) data;
+ struct hci_dbus_data *dbus_data = data;
uint32_t result = BLUEZ_EDBUS_UNKNOWN_METHOD;
DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
uint8_t found = 0;
@@ -837,7 +915,7 @@
method = dbus_message_get_member (msg);
signature = dbus_message_get_signature(msg);
- syslog (LOG_INFO, "%s - path:%s, udata:0x%X", __PRETTY_FUNCTION__, path, (guint) udata);
+ syslog (LOG_INFO, "%s - path:%s, id:0x%X", __PRETTY_FUNCTION__, path, dbus_data->id);
if (strcmp(path, DEVICE_PATH) == 0) {
ptr_handlers = dev_services;
@@ -846,7 +924,7 @@
} else {
if (strcmp(path, MANAGER_PATH) > 0) {
/* it is device specific path */
- if ( udata == MANAGER_PATH_ID ) {
+ if ( dbus_data->id == MANAGER_PATH_ID ) {
/* fallback handling. The child path IS NOT registered */
reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_UNKNOWN_PATH);
ret = DBUS_HANDLER_RESULT_HANDLED;
@@ -918,14 +996,14 @@
periodic_inquiry_cp inq_param;
DBusMessageIter iter;
DBusMessage *reply = NULL;
- long udata = (long) data;
+ struct hci_dbus_data *dbus_data = data;
uint8_t length;
uint8_t max_period;
uint8_t min_period;
int sock = -1;
int dev_id = -1;
- if (udata == DEFAULT_DEVICE_PATH_ID) {
+ if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
if ((dev_id = hci_get_route(NULL)) < 0) {
syslog(LOG_ERR, "Bluetooth device is not available");
reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
@@ -933,7 +1011,7 @@
}
} else
- dev_id = (int) udata;
+ dev_id = dbus_data->id;
if ((sock = hci_open_dev(dev_id)) < 0) {
syslog(LOG_ERR, "HCI device open failed");
@@ -997,18 +1075,18 @@
{
DBusMessageIter iter;
DBusMessage *reply = NULL;
- long udata = (long) data;
+ struct hci_dbus_data *dbus_data = data;
int sock = -1;
int dev_id = -1;
- if (udata == DEFAULT_DEVICE_PATH_ID) {
+ if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
if ((dev_id = hci_get_route(NULL)) < 0) {
syslog(LOG_ERR, "Bluetooth device is not available");
reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
goto failed;
}
} else
- dev_id = (int) udata;
+ dev_id = dbus_data->id;
if ((sock = hci_open_dev(dev_id)) < 0) {
syslog(LOG_ERR, "HCI device open failed");
@@ -1043,7 +1121,7 @@
DBusMessageIter struct_iter;
DBusMessage *reply = NULL;
inquiry_info *info = NULL;
- long udata = (long) data;
+ struct hci_dbus_data *dbus_data = data;
const char *paddr = addr;
int dev_id = -1;
int i;
@@ -1053,14 +1131,14 @@
int8_t length;
int8_t num_rsp;
- if (udata == DEFAULT_DEVICE_PATH_ID) {
+ if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
if ((dev_id = hci_get_route(NULL)) < 0) {
syslog(LOG_ERR, "Bluetooth device is not available");
reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
goto failed;
}
} else
- dev_id = (int) udata;
+ dev_id = dbus_data->id;
dbus_message_iter_init(msg, &iter);
dbus_message_iter_get_basic(&iter, &length);
@@ -1112,7 +1190,7 @@
DBusMessageIter iter;
DBusMessage *reply = NULL;
char *str_bdaddr = NULL;
- long udata = (long) data;
+ struct hci_dbus_data *dbus_data = data;
bdaddr_t bdaddr;
uint8_t role;
int dev_id = -1;
@@ -1133,7 +1211,7 @@
goto failed;
}
- if (udata != DEFAULT_DEVICE_PATH_ID && udata != dev_id) {
+ if (dbus_data->id != DEFAULT_DEVICE_PATH_ID && dbus_data->id != dev_id) {
syslog(LOG_ERR, "Connection not found\n");
reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
goto failed;
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] hcid patch (remote name and connections)
2005-10-11 19:28 ` Johan Hedberg
@ 2005-10-11 19:45 ` Steven Singer
2005-10-11 19:55 ` Johan Hedberg
0 siblings, 1 reply; 14+ messages in thread
From: Steven Singer @ 2005-10-11 19:45 UTC (permalink / raw)
To: bluez-devel
Johan Hedberg wrote:
> + id = malloc(sizeof(guint));
I'd recommend encapsulating the id in a structure rather than allocating
sizeof(guint). It doesn't cost you much time now and if, in the future,
you ever need to store any more information then the structure's already
there.
I noticed you already have a structure struct hci_dbus_data which
contains just an integer. Did you mean to use that here or are they
logically separate types (that just happen to be the same at the
moment)?
- Steven
--
This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] Re: hcid patch (remote name and connections)
2005-10-11 14:49 ` [Bluez-devel] " Claudio Takahasi
@ 2005-10-11 19:47 ` Steven Singer
2005-10-11 20:07 ` Claudio Takahasi
0 siblings, 1 reply; 14+ messages in thread
From: Steven Singer @ 2005-10-11 19:47 UTC (permalink / raw)
To: bluez-devel
Claudio Takahasi wrote:
> + if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
...
> + cl->conn_num = 10;
*cough* magic number *cough*
- Steven
--
This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] hcid patch (remote name and connections)
2005-10-11 19:45 ` Steven Singer
@ 2005-10-11 19:55 ` Johan Hedberg
2005-10-11 22:48 ` Marcel Holtmann
0 siblings, 1 reply; 14+ messages in thread
From: Johan Hedberg @ 2005-10-11 19:55 UTC (permalink / raw)
To: bluez-devel
Hi Steven,
On Tue, Oct 11, 2005, Steven Singer wrote:
> I'd recommend encapsulating the id in a structure rather than allocating
> sizeof(guint). It doesn't cost you much time now and if, in the future,
> you ever need to store any more information then the structure's already
> there.
> I noticed you already have a structure struct hci_dbus_data which
> contains just an integer. Did you mean to use that here or are they
> logically separate types (that just happen to be the same at the
> moment)?
The watch code is logically completely separate from the code that uses
the hci_dbus_data struct (the "id" variable refers to a GIOChannel id
while in the hci_dbus_data struct id refers to the device id). It is
also much simpler than the code that uses hci_dbus_data and I don't
think that anything besides the GIOChannel id needs to be passed to the
remove_watch function.
Johan
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] Re: hcid patch (remote name and connections)
2005-10-11 19:47 ` Steven Singer
@ 2005-10-11 20:07 ` Claudio Takahasi
2005-10-11 21:14 ` Steven Singer
0 siblings, 1 reply; 14+ messages in thread
From: Claudio Takahasi @ 2005-10-11 20:07 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]
It's from hcitool code :)
I will replace by "7", the maximum number of connections. Is it ok?
Regards,
Claudio
On 10/11/05, Steven Singer <steven.singer@csr.com> wrote:
>
> Claudio Takahasi wrote:
> > + if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
> ...
> > + cl->conn_num = 10;
>
> *cough* magic number *cough*
>
> - Steven
> --
>
>
> This message has been scanned for viruses by BlackSpider MailControl -
> www.blackspider.com <http://www.blackspider.com>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #2: Type: text/html, Size: 1747 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] Re: hcid patch (remote name and connections)
2005-10-11 20:07 ` Claudio Takahasi
@ 2005-10-11 21:14 ` Steven Singer
2005-10-11 22:37 ` Marcel Holtmann
0 siblings, 1 reply; 14+ messages in thread
From: Steven Singer @ 2005-10-11 21:14 UTC (permalink / raw)
To: bluez-devel
Claudio Takahasi wrote:
> It's from hcitool code :)
:-)
Still, that's no reason to propagate the error. Fix it and port the fix
back to hcitool (and wherever else it's escaped from).
> I will replace by "7", the maximum number of connections. Is it ok?
It wasn't the value I was concerned about. It was the free-floating 10
in the code twice.
A #define should allay my immediate concerns, however, a better solution
would be to avoid the use of hard-coded constant limits. Is there any way
to retrieve the current number of connections?
Strictly, 7 isn't the maximum number of connections - it's the maximum
number of active slaves a master can have. In theory the number of
simultaneous connections a device can have is limited only by the number
of ACL handles (about 4000). In practice, it's limited by the amount of
memory on the device and the need to service all the connections.
If you have more than one HCI dongle then you can have even more
connections.
In practice, 10 is probably sufficient for today, but by making it a
#define with a self-documenting name, it's easy for someone to change it
in the future.
If the kernel has some limit on the maximum number of connections then
use that (and get it from the kernel or a #include, don't copy the number
into your code).
If you can't get the number of connections from the kernel then that
suggests that there's a kernel API missing.
You may be able to work round the missing API depending on the behaviour
of HCIGETCONNLIST when the array size (N) is too small to hold all the
connections (M).
* If it causes a segmentation fault and terminates your program then
you may be in trouble.
* If it copies the first N connections and returns with conn_num
set to N then test for conn_num being set to N on return and
if it is, double N and try again.
* If it copies the first N connections and returns with conn_num
set to M then make two calls: the first with N = 0 and the second
with N = M.
- Steven
--
This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] Re: hcid patch (remote name and connections)
2005-10-11 21:14 ` Steven Singer
@ 2005-10-11 22:37 ` Marcel Holtmann
0 siblings, 0 replies; 14+ messages in thread
From: Marcel Holtmann @ 2005-10-11 22:37 UTC (permalink / raw)
To: bluez-devel
Hi Steven,
> > It's from hcitool code :)
>
> :-)
>
> Still, that's no reason to propagate the error. Fix it and port the fix
> back to hcitool (and wherever else it's escaped from).
>
> > I will replace by "7", the maximum number of connections. Is it ok?
>
> It wasn't the value I was concerned about. It was the free-floating 10
> in the code twice.
the current API sucks and so we have some more of these crazy numbers
flying around. I am aware of them and the new sysfs based interface will
hopefully solve all our problems.
All of these magic number are from the really beginnings of BlueZ where
it was almost impossible to get any CSR based dongles or PCMCIA cards ;)
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] hcid patch (remote name and connections)
2005-10-11 19:55 ` Johan Hedberg
@ 2005-10-11 22:48 ` Marcel Holtmann
2005-10-12 19:38 ` Johan Hedberg
0 siblings, 1 reply; 14+ messages in thread
From: Marcel Holtmann @ 2005-10-11 22:48 UTC (permalink / raw)
To: bluez-devel
Hi Johan,
> > I'd recommend encapsulating the id in a structure rather than allocating
> > sizeof(guint). It doesn't cost you much time now and if, in the future,
> > you ever need to store any more information then the structure's already
> > there.
> > I noticed you already have a structure struct hci_dbus_data which
> > contains just an integer. Did you mean to use that here or are they
> > logically separate types (that just happen to be the same at the
> > moment)?
>
> The watch code is logically completely separate from the code that uses
> the hci_dbus_data struct (the "id" variable refers to a GIOChannel id
> while in the hci_dbus_data struct id refers to the device id). It is
> also much simpler than the code that uses hci_dbus_data and I don't
> think that anything besides the GIOChannel id needs to be passed to the
> remove_watch function.
the patch is in and I agree with you that it makes no sense to take care
of this issue, because we will no longer use GIOChannel in bluetoothd in
the future.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] hcid patch (remote name and connections)
2005-10-11 22:48 ` Marcel Holtmann
@ 2005-10-12 19:38 ` Johan Hedberg
2005-10-12 21:14 ` Claudio Takahasi
0 siblings, 1 reply; 14+ messages in thread
From: Johan Hedberg @ 2005-10-12 19:38 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 143 bytes --]
Hi,
I missed one place in the code where hci_dbus_data should be allocated
(thanks to Claudio for noticing). Here's a patch to fix it.
Johan
[-- Attachment #2: segfault.patch --]
[-- Type: text/plain, Size: 820 bytes --]
Index: hcid/dbus.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus.c,v
retrieving revision 1.21
diff -u -r1.21 dbus.c
--- hcid/dbus.c 11 Oct 2005 22:45:38 -0000 1.21
+++ hcid/dbus.c 12 Oct 2005 19:13:14 -0000
@@ -774,7 +774,13 @@
syslog(LOG_INFO, "registering dft path:%s - id:%d", path, DEFAULT_DEVICE_PATH_ID);
- if (!dbus_connection_register_object_path(conn, path, &obj_vtable, (void *) DEFAULT_DEVICE_PATH_ID)) {
+ data = malloc(sizeof(struct hci_dbus_data));
+ if (data == NULL)
+ return -1;
+
+ data->id = DEFAULT_DEVICE_PATH_ID;
+
+ if (!dbus_connection_register_object_path(conn, path, &obj_vtable, data)) {
syslog(LOG_ERR,"DBUS failed to register %s object", path);
/* ignore, the default path was already registered */
}
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] hcid patch (remote name and connections)
2005-10-12 19:38 ` Johan Hedberg
@ 2005-10-12 21:14 ` Claudio Takahasi
2005-10-13 9:38 ` Marcel Holtmann
0 siblings, 1 reply; 14+ messages in thread
From: Claudio Takahasi @ 2005-10-12 21:14 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1.1: Type: text/plain, Size: 617 bytes --]
Hi,
This is the patch to add remote name and display connections. I fixed a
bitwise operation in the error message function and the dbus message
handler.
Apply the segmentation fault patch before!
Regards,
Claudio.
On 10/12/05, Johan Hedberg <johan.hedberg@nokia.com> wrote:
>
> Hi,
>
> I missed one place in the code where hci_dbus_data should be allocated
> (thanks to Claudio for noticing). Here's a patch to fix it.
>
> Johan
>
>
>
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #1.2: Type: text/html, Size: 1008 bytes --]
[-- Attachment #2: rem_name_connections_02.patch --]
[-- Type: text/x-patch, Size: 7327 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2005-10-09 19:15:22.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-10 17:37:57.000000000 -0300
@@ -122,6 +122,8 @@
#define HCI_CANCEL_PERIODIC_INQ "CancelPeriodic"
#define HCI_INQ "Inquiry"
#define HCI_ROLE_SWITCH "RoleSwitch"
+#define HCI_REMOTE_NAME "RemoteName"
+#define HCI_CONNECTIONS "Connections"
#define HCI_PERIODIC_INQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
@@ -139,6 +141,21 @@
#define HCI_ROLE_SWITCH_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
DBUS_TYPE_BYTE_AS_STRING\
__END_SIG__
+
+#define HCI_REMOTE_NAME_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+ __END_SIG__
+
+#define HCI_CONNECTIONS_SIGNATURE __END_SIG__
+
+#define HCI_CONN_INFO_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_TYPE_UINT32_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING\
+ __END_SIG__
#define HCI_DEVICE_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
DBUS_TYPE_STRING_AS_STRING\
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-10-12 16:57:30.692627760 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-12 17:30:01.708028336 -0300
@@ -58,6 +58,8 @@
#define BLUETOOTH_DEVICE_NAME_LEN (18)
#define BLUETOOTH_DEVICE_ADDR_LEN (18)
#define MAX_PATH_LENGTH (64)
+#define READ_REMOTE_NAME_TIMEOUT (25000)
+#define MAX_CONN_NUMBER (10)
#define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
#define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
@@ -129,7 +131,7 @@
if (ecode & BLUEZ_ESYSTEM_OFFSET) {
/* System error */
- raw_code = (!BLUEZ_ESYSTEM_OFFSET) & ecode;
+ raw_code = (~BLUEZ_ESYSTEM_OFFSET) & ecode;
syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, strerror(raw_code));
return strerror(raw_code);
} else if (ecode & BLUEZ_EDBUS_OFFSET) {
@@ -221,12 +223,16 @@
static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data);
static DBusMessage* handle_inq_req(DBusMessage *msg, void *data);
static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_remote_name_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data);
static const struct service_data hci_services[] = {
{ HCI_PERIODIC_INQ, handle_periodic_inq_req, HCI_PERIODIC_INQ_SIGNATURE },
{ HCI_CANCEL_PERIODIC_INQ, handle_cancel_periodic_inq_req, HCI_CANCEL_PERIODIC_INQ_SIGNATURE },
{ HCI_ROLE_SWITCH, handle_role_switch_req, HCI_ROLE_SWITCH_SIGNATURE },
{ HCI_INQ, handle_inq_req, HCI_INQ_SIGNATURE },
+ { HCI_REMOTE_NAME, handle_remote_name_req, HCI_REMOTE_NAME_SIGNATURE },
+ { HCI_CONNECTIONS, handle_display_conn_req, HCI_CONNECTIONS_SIGNATURE },
{ NULL, NULL, NULL }
};
@@ -982,17 +988,17 @@
reply = bluez_new_failure_msg(msg, result);
}
- /* send an error or the success reply*/
- if (reply) {
- if (!dbus_connection_send (conn, reply, NULL)) {
- syslog(LOG_ERR, "%s line:%d Can't send reply message!",
- __PRETTY_FUNCTION__, __LINE__) ;
- }
- dbus_message_unref (reply);
- }
-
ret = DBUS_HANDLER_RESULT_HANDLED;
}
+
+ /* send an error or the success reply*/
+ if (reply) {
+ if (!dbus_connection_send (conn, reply, NULL)) {
+ syslog(LOG_ERR, "Can't send reply message!") ;
+ }
+ dbus_message_unref (reply);
+ }
+
return ret;
}
@@ -1246,6 +1252,132 @@
return reply;
}
+static DBusMessage* handle_remote_name_req(DBusMessage *msg, void *data)
+{
+ char name[64];
+ const char *pname = name;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ struct hci_dbus_data *dbus_data = data;
+ int dev_id = -1;
+ int dd = -1;
+ const char *str_bdaddr;
+ bdaddr_t bdaddr;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &str_bdaddr);
+
+ str2ba(str_bdaddr, &bdaddr);
+
+ if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
+ if ((dev_id = hci_get_route(&bdaddr)) < 0) {
+ syslog(LOG_ERR, "Bluetooth device is not available");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto failed;
+ }
+ } else {
+ dev_id = dbus_data->id;
+ }
+
+ if ((dd = hci_open_dev(dev_id)) > 0) {
+
+ if (hci_read_remote_name(dd, &bdaddr, sizeof(name), name, READ_REMOTE_NAME_TIMEOUT) ==0) {
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &pname);
+ syslog(LOG_INFO, "Remote Name: %s", pname);
+ } else {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ }
+ } else {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ }
+
+ if (dd > 0)
+ close (dd);
+
+failed:
+ return reply;
+}
+
+static DBusMessage* handle_display_conn_req(DBusMessage *msg, void *data)
+{
+ struct hci_conn_list_req *cl = NULL;
+ struct hci_conn_info *ci = NULL;
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ char addr[18];
+ const char array_sig[] = HCI_CONN_INFO_STRUCT_SIGNATURE;
+ const char *paddr = addr;
+ struct hci_dbus_data *dbus_data = data;
+ int i;
+ int dev_id = -1;
+ int sk;
+
+ if (dbus_data->id == DEFAULT_DEVICE_PATH_ID) {
+ if ((dev_id = hci_get_route(NULL)) < 0) {
+ syslog(LOG_ERR, "Bluetooth device is not available");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto failed;
+ }
+ } else {
+ dev_id = dbus_data->id;
+ }
+
+ sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+
+ if (sk < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ if (!(cl = malloc(MAX_CONN_NUMBER * sizeof(*ci) + sizeof(*cl)))) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+ goto failed;
+ }
+
+ cl->dev_id = dev_id;
+ cl->conn_num = MAX_CONN_NUMBER;
+ ci = cl->conn_info;
+
+ if (ioctl(sk, HCIGETCONNLIST, (void *) cl)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto failed;
+ }
+
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, array_sig, &array_iter);
+
+ for (i = 0; i < cl->conn_num; i++, ci++) {
+ ba2str(&ci->bdaddr, addr);
+
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 ,&(ci->handle));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&paddr);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE ,&(ci->type));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_BYTE ,&(ci->out));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 ,&(ci->state));
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT32 ,&(ci->link_mode));
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+
+ dbus_message_iter_close_container(&iter, &array_iter);
+failed:
+
+ if (sk > 0)
+ close (sk);
+
+ if (cl)
+ free (cl);
+
+ return reply;
+}
+
+
+
/*****************************************************************
*
* Section reserved to Device D-Bus message handlers
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] hcid patch (remote name and connections)
2005-10-12 21:14 ` Claudio Takahasi
@ 2005-10-13 9:38 ` Marcel Holtmann
0 siblings, 0 replies; 14+ messages in thread
From: Marcel Holtmann @ 2005-10-13 9:38 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> This is the patch to add remote name and display connections. I fixed
> a bitwise operation in the error message function and the dbus message
> handler.
>
> Apply the segmentation fault patch before!
I applied both patches, but you should start looking at my changes to
your previous patch. There are some ways to code the if clauses a little
bit better using goto. This will make the code better readable. I might
fix this up later anyhow, but at the moment my Internet connection is
limited.
Regards
Marcel
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2005-10-13 9:38 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-11 14:26 [Bluez-devel] hcid patch (remote name and connections) Claudio Takahasi
2005-10-11 14:49 ` [Bluez-devel] " Claudio Takahasi
2005-10-11 19:47 ` Steven Singer
2005-10-11 20:07 ` Claudio Takahasi
2005-10-11 21:14 ` Steven Singer
2005-10-11 22:37 ` Marcel Holtmann
2005-10-11 18:01 ` [Bluez-devel] " Marcel Holtmann
2005-10-11 19:28 ` Johan Hedberg
2005-10-11 19:45 ` Steven Singer
2005-10-11 19:55 ` Johan Hedberg
2005-10-11 22:48 ` Marcel Holtmann
2005-10-12 19:38 ` Johan Hedberg
2005-10-12 21:14 ` Claudio Takahasi
2005-10-13 9:38 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).