* [Bluez-devel] hcid patch
@ 2005-09-30 18:22 Claudio Takahasi
2005-10-01 9:49 ` Marcel Holtmann
0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2005-09-30 18:22 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1.1: Type: text/plain, Size: 2985 bytes --]
Hi folks/Marcel,
The patch is attached. The basic structure to start the development of the
"sdp", "network", "serial", ... was added.
There are a lot not implemented methods.
Regards,
Claudio.
>>>>Main Features
1. added multiple bt adapter support
2. added the structures to support profiles
3. Modified paths to "/org/bluez/Devices" and "/org/bluez/Manager". Where
"Devices" is going to provide
device configuration services currently provided by hciconfig tool. The
"Manager" will handle
services related to connection establishment and setup, including profiles,
sdp and device discovery.
>>>>Next Action
1. Move the functions to to suitable file names( eg: dbus-mgr.c and
dbus-dev.c)
2. Define the device based path name.
>>>>How Test
1. /org/bluez/Devices, device up
$dbus-send --system --dest=org.bluez --type=method_call /org/bluez/Devices
org.bluez.Devices.Up
2. /org/bluez/Manager, Device list
$dbus-send --system --dest=org.bluez --type=method_call /org/bluez/Manager
org.bluez.Manager.DeviceList
comment: This service returns an array of devices. The reply signature is
"a(ss)", where the first string is the device name(eg: hci0, hci1) and the
second string is the bluetooth address. You have to develop a python client
or a "c" client to see the content.
3. /org/bluez/Manager/default/Controller, Inquiry
$dbus-send --system --dest=org.bluez --type=method_call
/org/bluez/Manager/default/Controller org.bluez.Manager.Inquiry byte:4
byte:10 uint16:0
or
$dbus-send --system --dest=org.bluez --type=method_call
/org/bluez/Manager/hci0/Controller org.bluez.Manager.Inquiry byte:4 byte:10
uint16:0
comment: This service returns an array of devices. The reply signature is
"a(suq)", where the first string is the bt address, the snd is the class and
the last is the clock offset. You have to develop a python client or a "c"
client to see the content.
4. /org/bluez/Manager/default/Controller, Periodic Inquiry
$dbus-send --system --dest=org.bluez --type=method_call
/org/bluez/Manager/default/Controller
org.bluez.Manager.PeriodicInquirybyte:4 byte:27 byte:49
or
$dbus-send --system --dest=org.bluez --type=method_call
/org/bluez/Manager/hci0/Controller org.bluez.Manager.PeriodicInquiry byte:4
byte:27 byte:49
5. /org/bluez/Manager/default/Controller, Cancel Periodic Inquiry
dbus-send --system --dest=org.bluez --type=method_call
/org/bluez/Manager/default/Controller org.bluez.Manager.CancelPeriodic
or
dbus-send --system --dest=org.bluez --type=method_call
/org/bluez/Manager/hci0/Controller org.bluez.Manager.CancelPeriodic
6. /org/bluez/Manager/default/Controller, RoleSwitch
dbus-send --system --dest=org.bluez --type=method_call
/org/bluez/Manager/default/Controller
org.bluez.Manager.RoleSwitchstring:AA:AA:AA:AA:AA:AA byte:1
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #1.2: Type: text/html, Size: 3416 bytes --]
[-- Attachment #2: hcid_dbus_0009.patch --]
[-- Type: application/octet-stream, Size: 47068 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus-internal.h 1969-12-31 21:00:00.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus-internal.h 2005-09-30 10:52:40.000000000 -0300
@@ -0,0 +1,82 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2000-2001 Qualcomm Incorporated
+ * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
+ * Copyright (C) 2002-2005 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
+ * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
+ * SOFTWARE IS DISCLAIMED.
+ *
+ *
+ * $Id: dbus-internal.h,v 0.1 2005/09/16 08:00:00 holtmann Exp $
+ */
+
+#ifndef __H_BLUEZ_DBUS_INTERNAL_H__
+#define __H_BLUEZ_DBUS_INTERNAL_H__
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <dbus/dbus.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#define DEVICE_ID_LENGTH (4)
+
+#define BLUETOOTH_DEVICE_NAME_LEN (18)
+#define BLUETOOTH_DEVICE_ADDR_LEN (18)
+
+#define MAX_PATH_LENGTH (64)
+
+
+
+typedef DBusMessage* (service_handler_func_t)(DBusMessage *, void *);
+typedef int8_t register_function_t(DBusConnection *conn, uint8_t dft_reg, uint16_t id);
+typedef int8_t unregister_function_t(DBusConnection *conn, uint8_t unreg_dft, uint16_t id);
+
+typedef struct
+{
+ const char *name;
+ service_handler_func_t *handler_func;
+ const char *signature;
+}service_table_t;
+
+typedef const service_table_t* get_svc_table_func_t(void);
+typedef struct {
+ const char *name;
+ uint8_t status; /* 1:active 0:disabled */
+ uint8_t dft_reg; /* dft path registered */
+ register_function_t *reg_func;
+ unregister_function_t *unreg_func;
+ get_svc_table_func_t *get_svc_table; /* return the service table */
+}__attribute__((packed))profile_obj_path_data_t;
+
+/* D-Bus Manager functions */
+gboolean mgr_dbus_reg_device_paths(uint16_t id);
+gboolean mgr_dbus_unreg_device_paths(uint16_t id);
+
+/* HCI functions */
+const service_table_t *get_hci_table(void);
+int8_t hci_dbus_reg_obj_path(DBusConnection *conn, uint8_t dft_reg, uint16_t id);
+int8_t hci_dbus_unreg_obj_path(DBusConnection *conn, uint8_t unreg_dft, uint16_t id);
+
+
+#endif //__H_BLUEZ_DBUS_INTERNAL_H__
--- bluez-utils-cvs.orig/hcid/hcid.h 2005-09-23 14:09:28.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/hcid.h 2005-09-27 17:13:45.000000000 -0300
@@ -122,6 +122,7 @@
#ifdef ENABLE_DBUS
gboolean hcid_dbus_init(void);
+void hcid_dbus_exit(void);
void hcid_dbus_request_pin(int dev, struct hci_conn_info *ci);
void hcid_dbus_inquiry_start(bdaddr_t *local);
void hcid_dbus_inquiry_complete(bdaddr_t *local);
--- bluez-utils-cvs.orig/hcid/dbus.h 1969-12-31 21:00:00.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-09-30 14:54:13.000000000 -0300
@@ -0,0 +1,200 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2000-2001 Qualcomm Incorporated
+ * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
+ * Copyright (C) 2002-2005 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
+ * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
+ * SOFTWARE IS DISCLAIMED.
+ *
+ *
+ * $Id: dbus.h,v 0.1 2005/09/16 08:00:00 holtmann Exp $
+ */
+
+#ifndef __H_BLUEZ_DBUS_H__
+#define __H_BLUEZ_DBUS_H__
+
+#define __END_SIG__ DBUS_TYPE_INVALID_AS_STRING
+
+/* bluetoothd Bus name */
+#define BLUEZ_DBUS_NAME "org.bluez"
+#define HCI_DFT_DEVICE_NAME "default"
+#define HCI_DEVICE_NAME "hci"
+
+#define BLUEZ_DBUS_DEVS_PATH "/org/bluez/Devices"
+#define BLUEZ_DBUS_DEVS_INTERFACE BLUEZ_DBUS_NAME".Devices"
+
+#define BLUEZ_DBUS_MGR_PATH "/org/bluez/Manager"
+#define BLUEZ_DBUS_MGR_INTERFACE BLUEZ_DBUS_NAME".Manager"
+
+/*========================================================================
+ BlueZ D-Bus Device service definitions "/org/bluez/Device"
+ *========================================================================*/
+#define DEV_UP_REQ "Up"
+#define DEV_DOWN_REQ "Down"
+#define DEV_RESET_REQ "Reset"
+#define DEV_SET_PROPERTY_REQ "SetProperty"
+#define DEV_GET_PROPERTY_REQ "GetProperty"
+
+#define DEV_UP_REQ_SIGNATURE __END_SIG__
+#define DEV_DOWN_REQ_SIGNATURE __END_SIG__
+#define DEV_RESET_REQ_SIGNATURE __END_SIG__
+#define DEV_SET_PROPERTY_REQ_SIGNATURE __END_SIG__
+#define DEV_GET_PROPERTY_REQ_SIGNATURE __END_SIG__
+
+
+//TODO add the other hciconfig features
+
+/*========================================================================
+ BlueZ D-Bus Manager service definitions "/org/bluez/Manager"
+ *========================================================================*/
+
+ /* ===== Manager definitions, services under BLUEZ_DBUS_DEVS_PATH ===== */
+#define MGR_GET_DEV_REQ "DeviceList"
+#define MGR_INIT_REQ "Init"
+
+/* Enable/Disable services controller, pan, serial, ... */
+#define MGR_ENABLE_REQ "Enable"
+#define MGR_DISABLE_REQ "Disable"
+
+//signatures
+#define MGR_GET_DEV_REQ_SIGNATURE __END_SIG__
+
+/* yya(ss)*/
+#define MGR_GET_DEV_REPLY_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_ARRAY_AS_STRING\
+ HCI_DEVICE_STRUCT_SIGNATURE\
+ __END_SIG__
+
+/* ===== HCI definitions ===== */
+#define BLUEZ_DBUS_HCI "Controller"
+#define BLUEZ_DBUS_HCI_PATH BLUEZ_DBUS_MGR_PATH"/"BLUEZ_DBUS_HCI
+#define BLUEZ_DBUS_HCI_INTERFACE BLUEZ_DBUS_MGR_INTERFACE"."BLUEZ_DBUS_HCI
+
+//HCI signals
+#define BLUEZ_DBUS_HCI_SIG_INQ_START "InquiryStartSig"
+#define BLUEZ_DBUS_HCI_SIG_INQ_COMPLETE "InquiryCompleteSig"
+#define BLUEZ_DBUS_HCI_SIG_INQ_RESULT "InquiryResultSig"
+#define BLUEZ_DBUS_HCI_SIG_REMOTE_NAME "RemoteNameSig"
+
+//HCI Provided services
+#define HCI_PERIODIC_INQ_REQ "PeriodicInquiry"
+#define HCI_CANCEL_PERIODIC_INQ_REQ "CancelPeriodic"
+#define HCI_INQ_REQ "Inquiry"
+#define HCI_ROLE_SWITCH_REQ "RoleSwitch"
+
+
+#define HCI_PERIODIC_INQ_REQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ __END_SIG__
+
+#define HCI_CANCEL_PERIODIC_INQ_REQ_SIGNATURE __END_SIG__
+
+#define HCI_INQ_REQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ __END_SIG__
+
+#define HCI_ROLE_SWITCH_REQ_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ __END_SIG__
+
+#define HCI_DEVICE_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING
+
+#define HCI_INQ_REPLY_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_UINT32_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING\
+ __END_SIG__
+
+
+/* ===== SDP definitions ===== */
+#define BLUEZ_DBUS_SDP "Service"
+//Default path for Service
+#define BLUEZ_DBUS_SDP_PATH BLUEZ_DBUS_MGR_PATH"/"HCI_DFT_DEVICE_NAME"/"BLUEZ_DBUS_SDP
+//SDP signals
+//SDP Provided services
+//SDP signatures
+
+
+/* ===== RFCOMM definitions ===== */
+#define BLUEZ_DBUS_SERIAL "Serial"
+//Default path for Serial
+#define BLUEZ_DBUS_SERIAL_PATH BLUEZ_DBUS_MGR_PATH"/"HCI_DFT_DEVICE_NAME"/"BLUEZ_DBUS_SERIAL
+//RFCOMM signals
+//RFCOMM Provided services
+//RFCOMM signatures
+
+
+/* ===== PAN definitions ===== */
+#define BLUEZ_DBUS_NET "Network"
+//Default path for Network
+#define BLUEZ_DBUS_NET_PATH BLUEZ_DBUS_MGR_PATH"/"HCI_DFT_DEVICE_NAME"/"BLUEZ_DBUS_NET
+//PAN signals
+//PAN Provided services
+//PAN signatures
+
+/* ===== HID definitions ===== */
+#define BLUEZ_DBUS_HID "HID"
+//Default path for HID
+#define BLUEZ_DBUS_HID_PATH BLUEZ_DBUS_MGR_PATH"/"HCI_DFT_DEVICE_NAME"/"BLUEZ_DBUS_HID
+
+//HID signals
+//HID Provided services
+//HID signatures
+
+
+/* ===== Common Error messages of org.bluez. =====*/
+#define BLUEZ_DBUS_ERR_FAILED BLUEZ_DBUS_NAME".EFailed"
+#define BLUEZ_DBUS_ERR_NO_MEMORY BLUEZ_DBUS_NAME".ENoMemory"
+//TODO What are the other error types?
+
+
+/* BLUEZ_DBUS_ERR_FAILED
+ * EFailed error messages signature is : sni
+ * Where the first argument is a string(error message description),
+ * the second is a uint16 that contains the error class(system, dbus or hci).
+ * The last argument is a int32 that contains the error code(errno
+ * for system errors, a dbus error code defined below or a hci error).
+ * For hci error see the bluetooth specification.
+ */
+
+/* first argument of the error msg */
+#define BLUEZ_ECLASS_SYSTEM (0x01)
+#define BLUEZ_ECLASS_DBUS (0x02)
+#define BLUEZ_ECLASS_HCI (0x03) /* see Bluetooth error code */
+
+/* D-Bus error code (second argument of the error msg)*/
+#define BLUEZ_EDBUS_UNKNOWN_METHOD (0x01)
+#define BLUEZ_EDBUS_WRONG_SIGNATURE (0x02)
+#define BLUEZ_EDBUS_WRONG_PARAM (0x03)
+#define BLUEZ_EDBUS_RECORD_NOT_FOUND (0x04)
+
+/* BLUEZ_DBUS_ERR_NO_MEMORY */
+#define BLUEZ_DBUS_ERR_NO_MEMORY_STR "No memory"
+
+
+#endif /*__H_BLUEZ_DBUS_H__*/
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-09-23 14:09:28.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-09-30 14:57:43.000000000 -0300
@@ -33,6 +33,9 @@
#endif
#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/syslog.h>
@@ -45,8 +48,12 @@
#include "glib-ectomy.h"
#include "hcid.h"
+#include "dbus.h"
+#include "dbus-internal.h"
+#include "util.h"
static DBusConnection *connection;
+static int8_t num_adapters = 0;
#define TIMEOUT (30 * 1000) /* 30 seconds */
@@ -55,13 +62,144 @@
#define REQUEST_NAME "PinRequest"
#define PATH_NAME "/org/bluez/PinAgent"
-#define WRONG_ARGS_ERROR "org.bluez.Error.WrongArgs"
struct pin_request {
int dev;
bdaddr_t bda;
};
+
+/*
+ * D-Bus error messages functions and declarations.
+ * This section should be moved to a common file
+ * in the future
+ *
+ */
+typedef struct {
+ uint8_t code;
+ const char *str;
+}bluez_error_t;
+
+static const bluez_error_t error_array[] = {
+ { BLUEZ_EDBUS_UNKNOWN_METHOD, "Method not found"},
+ { BLUEZ_EDBUS_WRONG_SIGNATURE, "Wrong method signature"},
+ { BLUEZ_EDBUS_WRONG_PARAM, "Invalid parameters"},
+ { BLUEZ_EDBUS_RECORD_NOT_FOUND, "No record found"},
+ { 0, NULL }
+};
+
+static const char *bluez_dbus_error_to_str(const uint16_t eclass, const int32_t ecode)
+{
+ const bluez_error_t *ptr;
+
+ if (eclass == BLUEZ_ECLASS_SYSTEM) {
+ return strerror(ecode);
+ } else { /* BLUEZ_ECLASS_DBUS */
+
+ for (ptr = error_array; ptr->code; ptr++) {
+ if(ptr->code == ecode) {
+ return ptr->str;
+ }
+ }
+ }
+ return NULL;
+}
+
+DBusMessage *bluez_new_failure_msg(DBusMessage *msg, const uint16_t eclass, const int32_t ecode)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const char *error_msg = NULL;
+
+ error_msg = bluez_dbus_error_to_str(eclass, ecode);
+
+ if (error_msg) {
+
+ reply = dbus_message_new_error(msg, BLUEZ_DBUS_ERR_FAILED, error_msg);
+
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16 ,&eclass);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32 ,&ecode);
+ }
+
+ return reply;
+}
+
+/*
+ * Object path register/unregister functions
+ *
+ */
+static profile_obj_path_data_t obj_path_table[] = {
+ {BLUEZ_DBUS_HCI, 1, 0, hci_dbus_reg_obj_path, hci_dbus_unreg_obj_path, get_hci_table },
+ /*{ BLUEZ_DBUS_SDP, 0, 0, sdp_dbus_reg_obj_path, sdp_dbus_unreg_obj_path, NULL },*/
+ /*{ BLUEZ_DBUS_NET, 0, 0, net_dbus_reg_obj_path, net_dbus_unreg_obj_path, NULL },*/
+ /*{ BLUEZ_DBUS_HID, 0, 0, hid_dbus_reg_obj_path, hid_dbus_unreg_obj_path , NULL },*/
+ /*{ BLUEZ_DBUS_SERIAL, 0, 0, serial_dbus_reg_obj_path, serial_dbus_unreg_obj_path, NULL },*/
+ {NULL, 0, 0, NULL, NULL, NULL}
+};
+
+/*
+ * Device Message handler functions object table declaration
+ */
+static DBusHandlerResult msg_func(DBusConnection *conn, DBusMessage *msg, void *data);
+
+static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data);
+
+static const DBusObjectPathVTable obj_vtable = {
+ NULL,
+ &msg_func,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+/*
+ * Service provided under the path BLUEZ_DBUS_DEVS_PATH
+ * TODO add the handlers
+ */
+static const service_table_t dev_services[] = {
+ {DEV_UP_REQ, handle_not_implemented_req, DEV_UP_REQ_SIGNATURE},
+ {DEV_DOWN_REQ, handle_not_implemented_req, DEV_DOWN_REQ_SIGNATURE},
+ {DEV_RESET_REQ, handle_not_implemented_req, DEV_RESET_REQ_SIGNATURE },
+ {DEV_SET_PROPERTY_REQ, handle_not_implemented_req, DEV_SET_PROPERTY_REQ_SIGNATURE },
+ {DEV_GET_PROPERTY_REQ, handle_not_implemented_req, DEV_GET_PROPERTY_REQ_SIGNATURE },
+ {NULL, NULL, NULL}
+};
+
+/*
+ * Manager Message handler functions object table declaration
+ *
+ */
+static const service_table_t mgr_services[] = {
+ {MGR_GET_DEV_REQ, handle_get_devices_req, MGR_GET_DEV_REQ_SIGNATURE},
+ {MGR_INIT_REQ, handle_not_implemented_req, NULL },
+ {MGR_ENABLE_REQ, handle_not_implemented_req, NULL },
+ {MGR_DISABLE_REQ, handle_not_implemented_req, NULL },
+ {NULL, handle_not_implemented_req, NULL}
+};
+
+
+/*
+ * HCI Manager Message handler functions object table declaration
+ *
+ */
+static DBusHandlerResult hci_signal_filter (DBusConnection *conn, DBusMessage *msg, void *data);
+
+static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data);
+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 const service_table_t hci_services[] = {
+ {HCI_PERIODIC_INQ_REQ, handle_periodic_inq_req, HCI_PERIODIC_INQ_REQ_SIGNATURE},
+ {HCI_CANCEL_PERIODIC_INQ_REQ, handle_cancel_periodic_inq_req, HCI_CANCEL_PERIODIC_INQ_REQ_SIGNATURE},
+ {HCI_ROLE_SWITCH_REQ, handle_role_switch_req, HCI_ROLE_SWITCH_REQ_SIGNATURE},
+ {HCI_INQ_REQ, handle_inq_req, HCI_INQ_REQ_SIGNATURE},
+ {NULL, NULL, NULL}
+};
+
static void reply_handler_function(DBusPendingCall *call, void *user_data)
{
struct pin_request *req = (struct pin_request *) user_data;
@@ -170,8 +308,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryStart");
+ message = dbus_message_new_signal(BLUEZ_DBUS_HCI_PATH,
+ BLUEZ_DBUS_HCI_INTERFACE,
+ BLUEZ_DBUS_HCI_SIG_INQ_START);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry start message");
goto failed;
@@ -204,8 +343,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryComplete");
+ message = dbus_message_new_signal(BLUEZ_DBUS_HCI_PATH,
+ BLUEZ_DBUS_HCI_INTERFACE,
+ BLUEZ_DBUS_HCI_SIG_INQ_COMPLETE);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
goto failed;
@@ -241,8 +381,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
baswap(&tmp, peer); peer_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryResult");
+ message = dbus_message_new_signal(BLUEZ_DBUS_HCI_PATH,
+ BLUEZ_DBUS_HCI_INTERFACE,
+ BLUEZ_DBUS_HCI_SIG_INQ_RESULT);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry result message");
goto failed;
@@ -280,8 +421,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
baswap(&tmp, peer); peer_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "RemoteName");
+ message = dbus_message_new_signal(BLUEZ_DBUS_HCI_PATH,
+ BLUEZ_DBUS_HCI_INTERFACE,
+ BLUEZ_DBUS_HCI_SIG_REMOTE_NAME);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
goto failed;
@@ -388,6 +530,8 @@
{
DBusError error;
+ num_adapters = 0;
+
dbus_error_init(&error);
connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
@@ -398,8 +542,755 @@
return FALSE;
}
+ dbus_bus_request_name(connection, BLUEZ_DBUS_NAME,
+ DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ syslog(LOG_ERR,"D-Bus Error: %s\n", error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ //Registering the device path
+ if (!dbus_connection_register_object_path(connection, BLUEZ_DBUS_DEVS_PATH, &obj_vtable, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", BLUEZ_DBUS_DEVS_PATH);
+ return FALSE;
+ } else {
+ syslog(LOG_INFO,"registering - path:%s", BLUEZ_DBUS_DEVS_PATH);
+ }
+
+ //Registering the manager path
+
+ if (!dbus_connection_register_object_path(connection, BLUEZ_DBUS_MGR_PATH, &obj_vtable, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", BLUEZ_DBUS_MGR_PATH);
+ return FALSE;
+ } else {
+ syslog(LOG_INFO,"registering - path:%s", BLUEZ_DBUS_MGR_PATH);
+ }
+
+
+ if (!dbus_connection_add_filter (connection, hci_signal_filter, NULL, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to add filter");
+ return FALSE;
+ }
+
dbus_connection_set_watch_functions(connection,
add_watch, remove_watch, watch_toggled, NULL, NULL);
return TRUE;
}
+
+/*
+ * @brief This function is responsible for register all service for
+ * each new hci device
+ * Detailed description: When a HCI_DEV_UP event is received or the
+ * daemon is initialized the service paths must be registered. eg:
+ * pan, sdp, hci, rfcomm paths.
+ * @param id device id
+ * @return TRUE/FALSE
+ */
+gboolean mgr_dbus_reg_device_paths(uint16_t id)
+{
+ profile_obj_path_data_t *ptr = obj_path_table;
+ int8_t ret = 0;
+
+ if (connection) {
+ for (;ptr->name; ptr++) {
+ ret = (ptr->reg_func(connection, ptr->dft_reg, id));
+ if (ret < 0) {
+ break;
+ }
+ /* the default path is now registered */
+ ptr->dft_reg = 1;
+ }
+
+ if (!ret) {
+ num_adapters++;
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * @brief This function is responsible for unregister all service for
+ * a detached hci device
+ * Detailed description: When a HCI_DEV_DOWN event is received the
+ * service paths must be unregistered. eg: pan, sdp, hci, rfcomm paths.
+ * @param id device id
+ * @return TRUE/FALSE
+ */
+gboolean mgr_dbus_unreg_device_paths(uint16_t id)
+{
+ profile_obj_path_data_t *ptr = obj_path_table;
+ uint8_t dft_unreg = 0;
+
+ if (connection) {
+ for (;ptr->name; ptr++) {
+ dft_unreg = (num_adapters > 1)? 0:1;
+ num_adapters--;
+ ptr->unreg_func(connection, dft_unreg, id);
+
+ if (dft_unreg ) {
+ ptr->dft_reg = 0;
+ }
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * @brief HCI object path register function
+ * Detailed description: function responsible for register a new hci
+ * D-Bus path. If necessary the default path must be registered too.
+ * @param conn D-Bus connection
+ * @param dft_reg register the default path(0 or !0)
+ * @param id hci device identification
+ * @return (0-Success/-1 failure)
+ */
+int8_t hci_dbus_reg_obj_path(DBusConnection *conn, uint8_t dft_reg, uint16_t id)
+{
+ char path[MAX_PATH_LENGTH];
+ int8_t ret = 0;
+ uint16_t *ptr_id = (int16_t*)malloc(1);
+ uint16_t *ptr_id_dft;
+
+ /* register the default path*/
+ if (!dft_reg) {
+ ptr_id_dft = (int16_t*)malloc(1);
+ *ptr_id_dft = 0xFFFF;
+ sprintf(path, "%s/%s/%s", BLUEZ_DBUS_MGR_PATH, HCI_DFT_DEVICE_NAME, BLUEZ_DBUS_HCI);
+
+ syslog(LOG_INFO, "registering dft path:%s - id:%d", path, 0xFFFF);
+
+ if (!dbus_connection_register_object_path(conn, path, &obj_vtable, ptr_id_dft)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", path);
+ //ignore, the default path was already registered
+ }
+
+ }
+
+ *ptr_id = id;
+
+ /* register the default path*/
+ sprintf(path, "%s/%s%d/%s", BLUEZ_DBUS_MGR_PATH, HCI_DEVICE_NAME, id ,BLUEZ_DBUS_HCI);
+
+ syslog(LOG_INFO, "registering - path:%s - id:%d",path, id);
+
+ if (!dbus_connection_register_object_path(conn, path, &obj_vtable, ptr_id)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", path);
+ return (-1);
+ }
+
+ return ret;
+}
+
+/*
+ * @brief HCI object path unregister function
+ * Detailed description: function responsible for unregister HCI D-Bus
+ * path for a detached hci device. If necessary the default path must
+ * be registered too.
+ * @param conn D-Bus connection
+ * @param unreg_dft register the default path(0 or !0)
+ * @param id hci device identification
+ * @return (0-Success/-1 failure)
+ */
+int8_t hci_dbus_unreg_obj_path(DBusConnection *conn, uint8_t unreg_dft, uint16_t id)
+{
+ int8_t ret = 0;
+ char path[MAX_PATH_LENGTH];
+ char dft_path[MAX_PATH_LENGTH];
+ uint16_t *data;
+
+ if (unreg_dft) {
+ sprintf(dft_path, "%s/%s/%s", BLUEZ_DBUS_MGR_PATH, HCI_DFT_DEVICE_NAME, BLUEZ_DBUS_HCI);
+ syslog(LOG_INFO, "%s - unregistering dft:%s", __PRETTY_FUNCTION__, dft_path);
+ 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, (void*)&data))
+ {
+ if(data)
+ free(data);
+ data = NULL;
+ }
+ }
+
+ }
+
+ sprintf(path, "%s/%s%d/%s", BLUEZ_DBUS_MGR_PATH, HCI_DEVICE_NAME, id, BLUEZ_DBUS_HCI);
+ syslog(LOG_INFO, "%s - unregistering spec:%s", __PRETTY_FUNCTION__, path);
+ 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, (void*)&data))
+ {
+ if(data)
+ free(data);
+ data = NULL;
+ }
+ }
+
+ return ret;
+}
+
+
+const service_table_t *get_hci_table(void) {
+ return hci_services;
+}
+/*****************************************************************
+ *
+ * Section reserved to HCI Manaher D-Bus message handlers
+ *
+ *****************************************************************/
+void hcid_dbus_exit(void)
+{
+ char path[MAX_PATH_LENGTH];
+ char fst_parent[] = BLUEZ_DBUS_MGR_PATH;
+ char snd_parent[MAX_PATH_LENGTH];
+ char **fst_level = NULL;
+ char **snd_level = NULL;
+ char *ptr1;
+ char *ptr2;
+
+ if (!connection)
+ return;
+ /* unregister all objects paths */
+
+ if (!dbus_connection_unregister_object_path (connection, BLUEZ_DBUS_DEVS_PATH)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", BLUEZ_DBUS_DEVS_PATH);
+ } else {
+ syslog(LOG_INFO,"unregistering - path:%s", BLUEZ_DBUS_DEVS_PATH);
+ }
+
+ if (!dbus_connection_unregister_object_path (connection, BLUEZ_DBUS_MGR_PATH)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", BLUEZ_DBUS_MGR_PATH);
+ } else {
+ syslog(LOG_INFO,"unregistering - path:%s", BLUEZ_DBUS_MGR_PATH);
+ }
+
+ //getting the first level
+ dbus_connection_list_registered(connection, fst_parent, &fst_level);
+
+ for ( ;*fst_level; fst_level++) {
+ ptr1 = *fst_level;
+ sprintf(snd_parent, "%s/%s", fst_parent, ptr1);
+
+ //getting the second level
+ dbus_connection_list_registered(connection, snd_parent, &snd_level);
+
+ if (!(*snd_level)) {
+ //no child
+ sprintf(path, "%s/%s", BLUEZ_DBUS_MGR_PATH, ptr1);
+
+ syslog(LOG_INFO, "unregistering path: %s", path);
+
+ if (!dbus_connection_unregister_object_path (connection, path)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", path);
+ }
+ continue;
+ }
+
+ for ( ;*snd_level; snd_level++) {
+ //unregistering child level path
+ ptr2 = *snd_level;
+ sprintf(path, "%s/%s/%s", BLUEZ_DBUS_MGR_PATH, ptr1, ptr2);
+
+ syslog(LOG_INFO, "unregistering path: %s", path);
+
+ if (!dbus_connection_unregister_object_path (connection, path)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", path);
+ }
+ }
+ if (*snd_level)
+ dbus_free_string_array(snd_level);
+ }
+
+ if (*fst_level)
+ dbus_free_string_array(fst_level);
+}
+
+static DBusHandlerResult hci_signal_filter (DBusConnection *conn, DBusMessage *msg, void *data)
+{
+ DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ const char *iface;
+ const char *method;
+
+ if (!msg || !conn)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (dbus_message_get_type (msg) != DBUS_MESSAGE_TYPE_SIGNAL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member(msg);
+
+ if (strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) {
+ if (strcmp(method, "Disconnected") == 0){
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ } else if (strcmp(iface, DBUS_INTERFACE_DBUS) == 0) {
+ if (strcmp(method, "NameOwnerChanged") == 0) {
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ if (strcmp(method, "NameAcquired") == 0) {
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ }
+ return ret;
+}
+/*
+ * There is only one message handler function for all object paths
+ *
+ */
+
+static DBusHandlerResult msg_func(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ const service_table_t *ptr_handlers = NULL;
+ DBusMessage *reply = NULL;
+ uint16_t type;
+ const char *iface;
+ const char *method;
+ const char *signature;
+ const char *path;
+ const char *rel_path;
+ const char *tmp_iface = NULL;
+ uint8_t result = BLUEZ_EDBUS_UNKNOWN_METHOD;
+ DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;;
+ uint8_t found = 0;
+
+
+ path = dbus_message_get_path(msg);
+ type = dbus_message_get_type(msg);
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member (msg);
+ signature = dbus_message_get_signature(msg);
+
+
+
+ //get the user data
+ if (strcmp(path, BLUEZ_DBUS_DEVS_PATH) == 0) {
+ ptr_handlers = dev_services; //TODO
+ tmp_iface = BLUEZ_DBUS_DEVS_INTERFACE;
+ found = 1;
+ } else if (strcmp(path, BLUEZ_DBUS_MGR_PATH) == 0) {
+ ptr_handlers = mgr_services;//TODO
+ tmp_iface = BLUEZ_DBUS_MGR_INTERFACE;
+ found = 1;
+ } else {
+ /* only msg to registered object paths will be received */
+
+ profile_obj_path_data_t *mgr_child = obj_path_table;
+ rel_path = strrchr(path,'/');
+ rel_path++;
+
+ if (rel_path) {
+ for (;mgr_child->name; mgr_child++) {
+ if(strcmp(mgr_child->name, rel_path) == 0) {
+ ptr_handlers = mgr_child->get_svc_table();
+ found = 1;
+ }
+ }
+
+ tmp_iface = BLUEZ_DBUS_MGR_INTERFACE;
+ }
+ }
+
+ if (found && (type == DBUS_MESSAGE_TYPE_METHOD_CALL) &&
+ (strcmp(iface, tmp_iface) == 0) && (method != NULL)) {
+
+ for (; ptr_handlers->name; ptr_handlers++) {
+ if (strcmp(method, ptr_handlers->name) == 0) {
+ /* resetting unknown method. It's possible handle method overload */
+ result = BLUEZ_EDBUS_WRONG_SIGNATURE;
+ if (strcmp(ptr_handlers->signature, signature) == 0) {
+ if(ptr_handlers->handler_func) {
+ reply = (ptr_handlers->handler_func)(msg, data);
+ result = 0; /* resetting wrong signature*/
+ } else {
+ syslog(LOG_INFO, "Service not implemented");
+ }
+ break;
+ }
+
+ }
+ }
+
+ if (result) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_DBUS, result);
+ syslog(LOG_INFO, "%s - %s", __PRETTY_FUNCTION__,
+ (result == BLUEZ_EDBUS_UNKNOWN_METHOD?"Unknown Method": "Wrong signature"));
+ }
+
+ /* 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;
+ } else {
+ syslog(LOG_INFO, "Request not handled");
+ }
+ return ret;
+}
+
+
+
+
+static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data)
+{
+ write_inquiry_mode_cp inq_mode;
+ periodic_inquiry_cp inq_param;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ uint8_t length;
+ uint8_t max_period;
+ uint8_t min_period;
+ int32_t sock = -1;
+ int32_t dev_id = -1;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ if ((dev_id = hci_get_route(NULL)) < 0) {
+ syslog(LOG_ERR, "Bluetooth device is not available");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, ENODEV);
+ goto cleanup;
+
+ }
+
+ if ((sock = hci_open_dev(dev_id)) < 0) {
+ syslog(LOG_ERR, "HCI device open failed");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, ENODEV);
+ goto cleanup;
+ }
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &length);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &min_period);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &max_period);
+
+ if ((length >= min_period) || (min_period >= max_period)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_DBUS, BLUEZ_EDBUS_WRONG_PARAM);
+ goto cleanup;
+ }
+
+ inq_param.num_rsp = 100;
+ inq_param.length = length;
+
+ inq_param.max_period = max_period;
+ inq_param.min_period = min_period;
+
+ /* General/Unlimited Inquiry Access Code (GIAC) */
+ inq_param.lap[0] = 0x33;
+ inq_param.lap[1] = 0x8b;
+ inq_param.lap[2] = 0x9e;
+
+ inq_mode.mode = 1; //INQUIRY_WITH_RSSI;
+
+ if (hci_send_cmd(sock, OGF_HOST_CTL, OCF_WRITE_INQUIRY_MODE,
+ WRITE_INQUIRY_MODE_CP_SIZE, &inq_mode) < 0) {
+ syslog(LOG_ERR, "Can't set inquiry mode:%s.", strerror(errno));
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, errno);
+ goto cleanup;
+ }
+
+ if (hci_send_cmd(sock, OGF_LINK_CTL, OCF_PERIODIC_INQUIRY,
+ PERIODIC_INQUIRY_CP_SIZE, &inq_param) < 0) {
+ syslog(LOG_ERR, "Can't send HCI commands:%s.", strerror(errno));
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, errno);
+ goto cleanup;
+ } else {
+
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE ,&result);
+ }
+
+cleanup:
+
+ if (sock > 0)
+ close(sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ int32_t sock = -1;
+ int32_t dev_id = -1;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ if ((dev_id = hci_get_route(NULL)) < 0) {
+ syslog(LOG_ERR, "Bluetooth device is not available");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, ENODEV);
+ goto cleanup;
+
+ }
+
+ if ((sock = hci_open_dev(dev_id)) < 0) {
+ syslog(LOG_ERR, "HCI device open failed");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, ENODEV);
+ goto cleanup;
+ }
+
+ if (hci_send_cmd(sock, OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY, 0 , NULL) < 0) {
+ syslog(LOG_ERR, "Send hci command failed.");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, errno);
+ } else {
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE ,&result);
+ }
+
+cleanup:
+ if (sock > 0)
+ close(sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_inq_req(DBusMessage *msg, void *data)
+{
+ const char array_sig[] = HCI_INQ_REPLY_SIGNATURE;
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ DBusMessage *reply = NULL;
+ inquiry_info *info = NULL;
+ char addr[18];
+ const char *paddr = addr;
+ int32_t dev_id = -1;
+ uint32_t class = 0;
+ uint16_t clock_offset;
+ uint16_t flags;
+ int8_t length;
+ int8_t num_rsp;
+ int8_t i;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ if ((dev_id = hci_get_route(NULL)) < 0) {
+ syslog(LOG_ERR, "Bluetooth device is not available");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, ENODEV);
+ goto cleanup;
+
+ }
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &length);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &num_rsp);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &flags);
+
+ if ((length <= 0) || (num_rsp <= 0)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_DBUS, BLUEZ_EDBUS_WRONG_PARAM);
+ goto cleanup;
+ }
+
+ num_rsp = hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);
+
+ if (num_rsp < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, errno);
+ } else {
+ 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 < num_rsp; i++) {
+ ba2str(&(info+i)->bdaddr, addr);
+
+ clock_offset = btohs((info+i)->clock_offset);
+ /* only 3 bytes are used */
+ memcpy(&class, (info+i)->dev_class, 3);
+
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING , &paddr);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT32 , &class);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 , &clock_offset);
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+ dbus_message_iter_close_container(&iter, &array_iter);
+ }
+
+cleanup:
+ if(info)
+ bt_free(info);
+
+ return NULL;
+}
+
+static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ char *str_bdaddr = NULL;
+ bdaddr_t bdaddr;
+ uint8_t role;
+ int32_t dev_id = -1, sock = -1;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &str_bdaddr);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &role);
+
+ str2ba(str_bdaddr, &bdaddr);
+
+ dev_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr);
+
+ if (dev_id < 0) {
+ syslog(LOG_ERR, "Bluetooth device failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, ENODEV);
+ goto cleanup;
+ }
+
+ sock = hci_open_dev(dev_id);
+
+ if (sock < 0) {
+ syslog(LOG_ERR, "HCI device open failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, ENODEV);
+ goto cleanup;
+ }
+
+ if (hci_switch_role(sock, &bdaddr, role, 10000) < 0) {
+ syslog(LOG_ERR, "Switch role request failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, errno);
+ } else {
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &result);
+ }
+cleanup:
+
+ return reply;
+}
+
+
+/*****************************************************************
+ *
+ * Section reserved to Device D-Bus message handlers
+ *
+ *****************************************************************/
+static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ DBusMessage *reply = NULL;
+
+ struct hci_dev_list_req *dl = NULL;
+ struct hci_dev_req *dr = NULL;
+ struct hci_dev_info di;
+ int16_t i;
+ int32_t sock = -1;
+
+ char aname[BLUETOOTH_DEVICE_NAME_LEN];
+ char aaddr[BLUETOOTH_DEVICE_ADDR_LEN];
+ char *paddr = aaddr;
+ char *pname = aname;
+ const char array_sig[] = HCI_DEVICE_STRUCT_SIGNATURE;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ /* Create and bind HCI socket */
+ if ((sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
+ syslog(LOG_ERR, "Can't open HCI socket: %s (%d)",
+ strerror(errno), errno);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, errno);
+ goto cleanup;
+ }
+
+
+ dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
+
+ if (!dl) {
+ syslog(LOG_ERR, "Can't allocate memory");
+ reply = dbus_message_new_error(msg, BLUEZ_DBUS_ERR_NO_MEMORY, BLUEZ_DBUS_ERR_NO_MEMORY_STR);
+ goto cleanup;
+ }
+
+ dl->dev_num = HCI_MAX_DEV;
+ dr = dl->dev_req;
+
+ if (ioctl(sock, HCIGETDEVLIST, (void *) dl) < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ECLASS_SYSTEM, errno);
+ goto cleanup;
+ }
+
+
+ /* active bluetooth adapter found */
+ 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);
+ dr = dl->dev_req;
+
+ for (i = 0; i < dl->dev_num; i++, dr++) {
+ if (hci_test_bit(HCI_UP, &dr->dev_opt)) {
+ memset(&di, 0 , sizeof(struct hci_dev_info));
+ di.dev_id = dr->dev_id;
+
+ if (!ioctl(sock, HCIGETDEVINFO, (void *) &di)) {
+ strcpy(aname, di.name);
+ ba2str(&di.bdaddr, aaddr);
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL,
+ &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&pname);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&paddr);
+ syslog(LOG_INFO, "%s - (%s, %s)", __PRETTY_FUNCTION__, pname, paddr);
+
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+ }
+ }
+ dbus_message_iter_close_container(&iter, &array_iter);
+
+cleanup:
+ if (dl)
+ free(dl);
+
+ if (sock > 0)
+ close (sock);
+
+ return reply;
+}
+
+
+
+static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data) {
+ const char *path;
+ const char *iface;
+ const char *method;
+
+ path = dbus_message_get_path(msg);
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member(msg);
+
+ syslog(LOG_INFO, "Not Implemented - path:%s, iface:%s method:%s", path, iface, method);
+
+ return NULL;
+
+}
\ No newline at end of file
--- bluez-utils-cvs.orig/hcid/main.c 2005-09-23 14:09:28.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/main.c 2005-09-30 15:19:18.000000000 -0300
@@ -57,6 +57,10 @@
#include "hcid.h"
#include "lib.h"
+#ifdef ENABLE_DBUS
+#include "dbus-internal.h"
+#endif
+
struct hcid_opts hcid;
struct device_opts default_device;
struct device_opts *parser_device;
@@ -375,6 +379,9 @@
if (hcid.security && hci_test_bit(HCI_UP, &dr->dev_opt))
start_security_manager(dr->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_reg_device_paths(dr->dev_id);
+#endif
}
free(dl);
@@ -438,12 +445,18 @@
configure_device(sd->dev_id);
if (hcid.security)
start_security_manager(sd->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_reg_device_paths(sd->dev_id);
+#endif
break;
case HCI_DEV_DOWN:
syslog(LOG_INFO, "HCI dev %d down", sd->dev_id);
if (hcid.security)
stop_security_manager(sd->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_unreg_device_paths(sd->dev_id);
+#endif
break;
}
}
@@ -627,7 +640,9 @@
g_main_run(event_loop);
free_device_opts();
-
+#ifdef ENABLE_DBUS
+ hcid_dbus_exit();
+#endif
syslog(LOG_INFO, "Exit.");
return 0;
}
--- bluez-utils-cvs.orig/common/util.h 1969-12-31 21:00:00.000000000 -0300
+++ bluez-utils-cvs-hcid/common/util.h 2005-09-23 17:58:44.000000000 -0300
@@ -0,0 +1,35 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2005 Claudio Takahasi <claudio.takahasi@indt.org.br>
+ * Copyright (C) 2002-2005 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
+ * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
+ * SOFTWARE IS DISCLAIMED.
+ *
+ *
+ * $Id: util.h,v 0.1 2005/09/23 08:00:00 holtmann Exp $
+ */
+
+#ifndef __H_BLUEZ_UTIL_H__
+#define __H_BLUEZ_UTIL_H__
+
+int find_conn(int s, int dev_id, long arg);
+
+#endif //__H_BLUEZ_UTIL_H__
--- bluez-utils-cvs.orig/common/Makefile.am 2005-09-23 14:09:28.000000000 -0300
+++ bluez-utils-cvs-hcid/common/Makefile.am 2005-09-23 17:58:44.000000000 -0300
@@ -2,10 +2,12 @@
# $Id: Makefile.am,v 1.2 2005/08/05 11:07:34 holtmann Exp $
#
-noinst_LIBRARIES = libtextfile.a
+noinst_LIBRARIES = libtextfile.a libutil.a
libtextfile_a_SOURCES = textfile.h textfile.c
+libutil_a_SOURCES = util.h util.c
+
noinst_PROGRAMS = test_textfile
test_textfile_LDADD = libtextfile.a
--- bluez-utils-cvs.orig/common/util.c 1969-12-31 21:00:00.000000000 -0300
+++ bluez-utils-cvs-hcid/common/util.c 2005-09-23 17:58:44.000000000 -0300
@@ -0,0 +1,80 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2005 Claudio Takahasi <claudio.takahasi@indt.org.br>
+ * Copyright (C) 2002-2005 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
+ * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
+ * SOFTWARE IS DISCLAIMED.
+ *
+ *
+ * $Id: util.c,v 0.1 2005/09/23 08:00:00 holtmann Exp $
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <string.h>
+
+#include <sys/ioctl.h>
+#include <sys/syslog.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
+#include <bluetooth/hci_lib.h>
+
+
+int find_conn(int s, int dev_id, long arg)
+{
+ struct hci_conn_list_req *cl = NULL;
+ struct hci_conn_info *ci;
+ int i;
+ int result = 0;
+
+ if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
+ syslog(LOG_ERR, "Can't allocate memory\n");
+ return 0;
+ }
+
+ cl->dev_id = dev_id;
+ cl->conn_num = 10;
+ ci = cl->conn_info;
+
+ if (ioctl(s, HCIGETCONNLIST, (void *) cl)) {
+ syslog(LOG_ERR, "Can't get connection list\n");
+ return 0;
+ }
+
+ for (i = 0; i < cl->conn_num; i++, ci++) {
+ if (!bacmp((bdaddr_t *) arg, &ci->bdaddr)) {
+ result = 1;
+ goto cleanup;
+ }
+ }
+cleanup:
+ if(cl)
+ free(cl);
+ return result;
+}
--- bluez-utils-cvs.orig/tools/Makefile.am 2005-09-23 14:09:28.000000000 -0300
+++ bluez-utils-cvs-hcid/tools/Makefile.am 2005-09-23 17:58:22.000000000 -0300
@@ -44,7 +44,7 @@
hciconfig_LDADD = @BLUEZ_LIBS@ $(top_builddir)/common/libtextfile.a
hcitool_SOURCES = hcitool.c oui.h oui.c
-hcitool_LDADD = @BLUEZ_LIBS@ $(top_builddir)/common/libtextfile.a
+hcitool_LDADD = @BLUEZ_LIBS@ $(top_builddir)/common/libtextfile.a $(top_builddir)/common/libutil.a
l2ping_LDADD = @BLUEZ_LIBS@
--- bluez-utils-cvs.orig/tools/hcitool.c 2005-09-23 14:09:28.000000000 -0300
+++ bluez-utils-cvs-hcid/tools/hcitool.c 2005-09-27 15:53:39.000000000 -0300
@@ -49,6 +49,7 @@
#include "textfile.h"
#include "oui.h"
+#include "util.h"
#define for_each_opt(opt, long, short) while ((opt=getopt_long(argc, argv, short ? short:"+", long, NULL)) != -1)
@@ -103,32 +104,6 @@
return 0;
}
-static int find_conn(int s, int dev_id, long arg)
-{
- struct hci_conn_list_req *cl;
- struct hci_conn_info *ci;
- int i;
-
- if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
- perror("Can't allocate memory");
- exit(1);
- }
- cl->dev_id = dev_id;
- cl->conn_num = 10;
- ci = cl->conn_info;
-
- if (ioctl(s, HCIGETCONNLIST, (void *) cl)) {
- perror("Can't get connection list");
- exit(1);
- }
-
- for (i = 0; i < cl->conn_num; i++, ci++)
- if (!bacmp((bdaddr_t *) arg, &ci->bdaddr))
- return 1;
-
- return 0;
-}
-
static void hex_dump(char *pref, int width, unsigned char *buf, int len)
{
register int i,n;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] hcid patch
2005-09-30 18:22 [Bluez-devel] hcid patch Claudio Takahasi
@ 2005-10-01 9:49 ` Marcel Holtmann
2005-10-03 14:08 ` Claudio Takahasi
0 siblings, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2005-10-01 9:49 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> The patch is attached. The basic structure to start the development of
> the "sdp", "network", "serial", ... was added.
> There are a lot not implemented methods.
this patch looks like this:
common/Makefile.am | 4
common/util.c | 80 ++++
common/util.h | 35 +
hcid/dbus-internal.h | 82 ++++
hcid/dbus.c | 909 ++++++++++++++++++++++++++++++++++++++++++++++++++-
hcid/dbus.h | 200 +++++++++++
hcid/hcid.h | 1
hcid/main.c | 17
tools/Makefile.am | 2
tools/hcitool.c | 27 -
10 files changed, 1319 insertions(+), 38 deletions(-)
It is changing everything and looks like a previous patch that I
reviewed.
I don't wanna see any changes outside hcid/dbus.[ch] at the moment and
the error definitions we agreed on are not included. It seems you just
modified one of your older patches with the new objects and paths. I
want to include something before the next release, but I am going the
full patch at the moment.
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] 8+ messages in thread
* Re: [Bluez-devel] hcid patch
2005-10-01 9:49 ` Marcel Holtmann
@ 2005-10-03 14:08 ` Claudio Takahasi
2005-10-03 21:02 ` Marcel Holtmann
0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2005-10-03 14:08 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1.1: Type: text/plain, Size: 2716 bytes --]
Hi Marcel,
I kept some log information, if you want remove it I can send another patch.
The error code definition was included. I am using "hciX" in the path name
until we receive a answer from dbus list. Services under the path
/org/bluez/Devices weren't implemented yet.
Is there other changes in this patch?
Regards,
Claudio
>>>>Main Features
1. added multiple bt adapter support
2. added the structures to support profiles
3. Modified paths to "/org/bluez/Devices" and "/org/bluez/Manager". Where
"Devices" is going to provide device configuration services currently
provided by hciconfig tool. The "Manager" will handle services related to
connection establishment and setup, including profiles, sdp and device
discovery.
4. Added error new code definition
>>>>Next Action
1. Move the functions to to suitable file names( eg: dbus-mgr.c and
dbus-dev.c)
2. Define the device based path name. (waiting D-Bus mailing list answers)
3. Investigate fallback behaviour(how handle properly unregistered paths)
On 10/1/05, Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Claudio,
>
> > The patch is attached. The basic structure to start the development of
> > the "sdp", "network", "serial", ... was added.
> > There are a lot not implemented methods.
>
> this patch looks like this:
>
> common/Makefile.am | 4
> common/util.c | 80 ++++
> common/util.h | 35 +
> hcid/dbus-internal.h | 82 ++++
> hcid/dbus.c | 909 ++++++++++++++++++++++++++++++++++++++++++++++++++-
> hcid/dbus.h | 200 +++++++++++
> hcid/hcid.h | 1
> hcid/main.c | 17
> tools/Makefile.am | 2
> tools/hcitool.c | 27 -
> 10 files changed, 1319 insertions(+), 38 deletions(-)
>
> It is changing everything and looks like a previous patch that I
> reviewed.
>
> I don't wanna see any changes outside hcid/dbus.[ch] at the moment and
> the error definitions we agreed on are not included. It seems you just
> modified one of your older patches with the new objects and paths. I
> want to include something before the next release, but I am going the
> full patch at the moment.
>
> 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
>
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #1.2: Type: text/html, Size: 4029 bytes --]
[-- Attachment #2: hcid_dbus_0010.patch --]
[-- Type: application/octet-stream, Size: 41148 bytes --]
--- bluez-utils-cvs.orig/hcid/hcid.h 2005-08-25 15:32:41.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/hcid.h 2005-10-03 11:02:36.000000000 -0300
@@ -122,6 +122,9 @@
#ifdef ENABLE_DBUS
gboolean hcid_dbus_init(void);
+void hcid_dbus_exit(void);
+gboolean mgr_dbus_reg_device_paths(uint16_t id);
+gboolean mgr_dbus_unreg_device_paths(uint16_t id);
void hcid_dbus_request_pin(int dev, struct hci_conn_info *ci);
void hcid_dbus_inquiry_start(bdaddr_t *local);
void hcid_dbus_inquiry_complete(bdaddr_t *local);
--- bluez-utils-cvs.orig/hcid/dbus.h 1969-12-31 21:00:00.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-03 10:49:28.000000000 -0300
@@ -0,0 +1,209 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2000-2001 Qualcomm Incorporated
+ * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
+ * Copyright (C) 2002-2005 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
+ * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
+ * SOFTWARE IS DISCLAIMED.
+ *
+ *
+ * $Id: dbus.h,v 0.1 2005/09/16 08:00:00 holtmann Exp $
+ */
+
+#ifndef __H_BLUEZ_DBUS_H__
+#define __H_BLUEZ_DBUS_H__
+
+#define __END_SIG__ DBUS_TYPE_INVALID_AS_STRING
+
+/* bluetoothd Bus name */
+#define BLUEZ_DBUS_NAME "org.bluez"
+#define DFT_DEVICE_ID (0xFFFF)
+#define HCI_DFT_DEVICE_NAME "default"
+#define HCI_DEVICE_NAME "hci"
+
+#define BLUEZ_DBUS_DEVS_PATH "/org/bluez/Devices"
+#define BLUEZ_DBUS_DEVS_INTERFACE BLUEZ_DBUS_NAME".Devices"
+
+#define BLUEZ_DBUS_MGR_PATH "/org/bluez/Manager"
+#define BLUEZ_DBUS_MGR_INTERFACE BLUEZ_DBUS_NAME".Manager"
+
+/*========================================================================
+ BlueZ D-Bus Device service definitions "/org/bluez/Device"
+ *========================================================================*/
+#define DEV_UP_REQ "Up"
+#define DEV_DOWN_REQ "Down"
+#define DEV_RESET_REQ "Reset"
+#define DEV_SET_PROPERTY_REQ "SetProperty"
+#define DEV_GET_PROPERTY_REQ "GetProperty"
+
+#define DEV_UP_REQ_SIGNATURE __END_SIG__
+#define DEV_DOWN_REQ_SIGNATURE __END_SIG__
+#define DEV_RESET_REQ_SIGNATURE __END_SIG__
+#define DEV_SET_PROPERTY_REQ_SIGNATURE __END_SIG__
+#define DEV_GET_PROPERTY_REQ_SIGNATURE __END_SIG__
+
+
+//TODO add the other hciconfig features
+
+/*========================================================================
+ BlueZ D-Bus Manager service definitions "/org/bluez/Manager"
+ *========================================================================*/
+
+ /* ===== Manager definitions, services under BLUEZ_DBUS_DEVS_PATH ===== */
+#define MGR_GET_DEV_REQ "DeviceList"
+#define MGR_INIT_REQ "Init"
+
+/* Enable/Disable services controller, pan, serial, ... */
+#define MGR_ENABLE_REQ "Enable"
+#define MGR_DISABLE_REQ "Disable"
+
+//signatures
+#define MGR_GET_DEV_REQ_SIGNATURE __END_SIG__
+
+/* yya(ss)*/
+#define MGR_GET_DEV_REPLY_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_ARRAY_AS_STRING\
+ HCI_DEVICE_STRUCT_SIGNATURE\
+ __END_SIG__
+
+/* ===== HCI definitions ===== */
+#define BLUEZ_DBUS_HCI "Controller"
+#define BLUEZ_DBUS_HCI_PATH BLUEZ_DBUS_MGR_PATH"/"BLUEZ_DBUS_HCI
+#define BLUEZ_DBUS_HCI_INTERFACE BLUEZ_DBUS_MGR_INTERFACE"."BLUEZ_DBUS_HCI
+
+//HCI signals
+#define BLUEZ_DBUS_HCI_SIG_INQ_START "InquiryStartSig"
+#define BLUEZ_DBUS_HCI_SIG_INQ_COMPLETE "InquiryCompleteSig"
+#define BLUEZ_DBUS_HCI_SIG_INQ_RESULT "InquiryResultSig"
+#define BLUEZ_DBUS_HCI_SIG_REMOTE_NAME "RemoteNameSig"
+
+//HCI Provided services
+#define HCI_PERIODIC_INQ_REQ "PeriodicInquiry"
+#define HCI_CANCEL_PERIODIC_INQ_REQ "CancelPeriodic"
+#define HCI_INQ_REQ "Inquiry"
+#define HCI_ROLE_SWITCH_REQ "RoleSwitch"
+
+
+#define HCI_PERIODIC_INQ_REQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ __END_SIG__
+
+#define HCI_CANCEL_PERIODIC_INQ_REQ_SIGNATURE __END_SIG__
+
+#define HCI_INQ_REQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ __END_SIG__
+
+#define HCI_ROLE_SWITCH_REQ_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ __END_SIG__
+
+#define HCI_DEVICE_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING
+
+#define HCI_INQ_REPLY_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_UINT32_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING\
+ __END_SIG__
+
+
+/* ===== SDP definitions ===== */
+#define BLUEZ_DBUS_SDP "Service"
+//Default path for Service
+#define BLUEZ_DBUS_SDP_PATH BLUEZ_DBUS_MGR_PATH"/"HCI_DFT_DEVICE_NAME"/"BLUEZ_DBUS_SDP
+//SDP signals
+//SDP Provided services
+//SDP signatures
+
+
+/* ===== RFCOMM definitions ===== */
+#define BLUEZ_DBUS_SERIAL "Serial"
+//Default path for Serial
+#define BLUEZ_DBUS_SERIAL_PATH BLUEZ_DBUS_MGR_PATH"/"HCI_DFT_DEVICE_NAME"/"BLUEZ_DBUS_SERIAL
+//RFCOMM signals
+//RFCOMM Provided services
+//RFCOMM signatures
+
+
+/* ===== PAN definitions ===== */
+#define BLUEZ_DBUS_NET "Network"
+//Default path for Network
+#define BLUEZ_DBUS_NET_PATH BLUEZ_DBUS_MGR_PATH"/"HCI_DFT_DEVICE_NAME"/"BLUEZ_DBUS_NET
+//PAN signals
+//PAN Provided services
+//PAN signatures
+
+/* ===== HID definitions ===== */
+#define BLUEZ_DBUS_HID "HID"
+//Default path for HID
+#define BLUEZ_DBUS_HID_PATH BLUEZ_DBUS_MGR_PATH"/"HCI_DFT_DEVICE_NAME"/"BLUEZ_DBUS_HID
+
+//HID signals
+//HID Provided services
+//HID signatures
+
+
+/* ===== Common Error messages of org.bluez. =====*/
+#define BLUEZ_DBUS_ERR_FAILED BLUEZ_DBUS_NAME".EFailed"
+//TODO What are the other error types?
+
+
+/* BLUEZ_DBUS_ERR_FAILED
+ * EFailed error messages signature is : sni
+ * Where the first argument is a string(error message description),
+ * the second is a uint16 that contains the error class(system, dbus or hci).
+ * The last argument is a int32 that contains the error code(errno
+ * for system errors, a dbus error code defined below or a hci error).
+ * For hci error see the bluetooth specification.
+ */
+
+/* Error code offsets */
+#define BLUEZ_EBT_OFFSET (0x00000000) /* see Bluetooth error code */
+#define BLUEZ_EBT_EXT_OFFSET (0x00000100)
+#define BLUEZ_EDBUS_OFFSET (0x00010000)
+#define BLUEZ_ESYSTEM_OFFSET (0x00020000)
+#define BLUEZ_EFUTURE_OFFSET (0x00040000)
+
+
+/* D-Bus error code, class BLUEZ_EDBUS_OFFSET */
+#define BLUEZ_EDBUS_UNKNOWN_METHOD (0x01 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_WRONG_SIGNATURE (0x02 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_WRONG_PARAM (0x03 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_RECORD_NOT_FOUND (0x04 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_NO_MEM (0x05 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_CONN_NOT_FOUND (0x06 + BLUEZ_EDBUS_OFFSET)
+
+/* D-Bus error code, class BLUEZ_ESYSTEM_OFFSET */
+#define BLUEZ_ESYSTEM_ENODEV (ENODEV + BLUEZ_ESYSTEM_OFFSET)
+
+
+/* BLUEZ_DBUS_ERR_NO_MEMORY */
+#define BLUEZ_DBUS_ERR_NO_MEMORY_STR "No memory"
+
+
+#endif /*__H_BLUEZ_DBUS_H__*/
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-09-22 09:09:16.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-03 10:48:19.000000000 -0300
@@ -33,9 +33,14 @@
#endif
#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/syslog.h>
+
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
@@ -45,22 +50,229 @@
#include "glib-ectomy.h"
#include "hcid.h"
+#include "dbus.h"
static DBusConnection *connection;
+static int8_t num_adapters = 0;
#define TIMEOUT (30 * 1000) /* 30 seconds */
+#define BLUETOOTH_DEVICE_NAME_LEN (18)
+#define BLUETOOTH_DEVICE_ADDR_LEN (18)
+#define MAX_PATH_LENGTH (64)
#define SERVICE_NAME "org.bluez.PinAgent"
#define INTERFACE_NAME SERVICE_NAME
#define REQUEST_NAME "PinRequest"
#define PATH_NAME "/org/bluez/PinAgent"
-#define WRONG_ARGS_ERROR "org.bluez.Error.WrongArgs"
struct pin_request {
int dev;
bdaddr_t bda;
};
+/*
+ * next action: move to a common header
+ */
+
+
+typedef DBusMessage* (service_handler_func_t)(DBusMessage *, void *);
+
+typedef struct
+{
+ const char *name;
+ service_handler_func_t *handler_func;
+ const char *signature;
+}service_table_t;
+
+typedef int8_t register_function_t(DBusConnection *conn, uint8_t dft_reg, uint16_t id);
+typedef int8_t unregister_function_t(DBusConnection *conn, uint8_t unreg_dft, uint16_t id);
+
+const service_table_t *get_hci_table(void);
+int8_t hci_dbus_reg_obj_path(DBusConnection *conn, uint8_t dft_reg, uint16_t id);
+int8_t hci_dbus_unreg_obj_path(DBusConnection *conn, uint8_t unreg_dft, uint16_t id);
+
+
+typedef const service_table_t* get_svc_table_func_t(void);
+typedef struct {
+ const char *name;
+ uint8_t status; /* 1:active 0:disabled */
+ uint8_t dft_reg; /* dft path registered */
+ register_function_t *reg_func;
+ unregister_function_t *unreg_func;
+ get_svc_table_func_t *get_svc_table; /* return the service table */
+}__attribute__((packed))profile_obj_path_data_t;
+
+/*
+ * next action: Move to /common directory
+ */
+
+static int find_conn(int s, int dev_id, long arg)
+{
+ struct hci_conn_list_req *cl;
+ struct hci_conn_info *ci;
+ int i;
+
+ if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
+ syslog(LOG_ERR, "Can't allocate memory");
+ return 0;
+ }
+ cl->dev_id = dev_id;
+ cl->conn_num = 10;
+ ci = cl->conn_info;
+
+ if (ioctl(s, HCIGETCONNLIST, (void *) cl)) {
+ syslog(LOG_ERR, "Can't get connection list");
+ return 0;
+ }
+
+ for (i = 0; i < cl->conn_num; i++, ci++)
+ if (!bacmp((bdaddr_t *) arg, &ci->bdaddr))
+ return 1;
+
+ return 0;
+}
+
+
+/*
+ * D-Bus error messages functions and declarations.
+ * This section should be moved to a common file
+ * in the future
+ *
+ */
+typedef struct {
+ uint32_t code;
+ const char *str;
+}bluez_error_t;
+
+static const bluez_error_t error_array[] = {
+ { BLUEZ_EDBUS_UNKNOWN_METHOD, "Method not found"},
+ { BLUEZ_EDBUS_WRONG_SIGNATURE, "Wrong method signature"},
+ { BLUEZ_EDBUS_WRONG_PARAM, "Invalid parameters"},
+ { BLUEZ_EDBUS_RECORD_NOT_FOUND, "No record found"},
+ { 0, NULL }
+};
+
+static const char *bluez_dbus_error_to_str(const uint32_t ecode)
+{
+ const bluez_error_t *ptr;
+ uint32_t raw_code = 0;
+
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ if (ecode & BLUEZ_ESYSTEM_OFFSET) {
+ /* System error */
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+ 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) {
+ /* D-Bus error */
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+ for (ptr = error_array; ptr->code; ptr++) {
+ if(ptr->code == ecode) {
+ syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, ptr->str);
+ return ptr->str;
+ }
+ }
+ }
+ return NULL;
+}
+
+DBusMessage *bluez_new_failure_msg(DBusMessage *msg, const uint32_t ecode)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const char *error_msg = NULL;
+
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ error_msg = bluez_dbus_error_to_str(ecode);
+
+ if (error_msg) {
+
+ reply = dbus_message_new_error(msg, BLUEZ_DBUS_ERR_FAILED, error_msg);
+
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32 ,&ecode);
+ }
+
+ return reply;
+}
+
+/*
+ * Object path register/unregister functions
+ *
+ */
+static profile_obj_path_data_t obj_path_table[] = {
+ {BLUEZ_DBUS_HCI, 1, 0, hci_dbus_reg_obj_path, hci_dbus_unreg_obj_path, get_hci_table },
+ /*{ BLUEZ_DBUS_SDP, 0, 0, sdp_dbus_reg_obj_path, sdp_dbus_unreg_obj_path, NULL },*/
+ /*{ BLUEZ_DBUS_NET, 0, 0, net_dbus_reg_obj_path, net_dbus_unreg_obj_path, NULL },*/
+ /*{ BLUEZ_DBUS_HID, 0, 0, hid_dbus_reg_obj_path, hid_dbus_unreg_obj_path , NULL },*/
+ /*{ BLUEZ_DBUS_SERIAL, 0, 0, serial_dbus_reg_obj_path, serial_dbus_unreg_obj_path, NULL },*/
+ {NULL, 0, 0, NULL, NULL, NULL}
+};
+
+/*
+ * Device Message handler functions object table declaration
+ */
+static DBusHandlerResult msg_func(DBusConnection *conn, DBusMessage *msg, void *data);
+
+static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data);
+
+static const DBusObjectPathVTable obj_vtable = {
+ NULL,
+ &msg_func,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+/*
+ * Service provided under the path BLUEZ_DBUS_DEVS_PATH
+ * TODO add the handlers
+ */
+static const service_table_t dev_services[] = {
+ {DEV_UP_REQ, handle_not_implemented_req, DEV_UP_REQ_SIGNATURE},
+ {DEV_DOWN_REQ, handle_not_implemented_req, DEV_DOWN_REQ_SIGNATURE},
+ {DEV_RESET_REQ, handle_not_implemented_req, DEV_RESET_REQ_SIGNATURE },
+ {DEV_SET_PROPERTY_REQ, handle_not_implemented_req, DEV_SET_PROPERTY_REQ_SIGNATURE },
+ {DEV_GET_PROPERTY_REQ, handle_not_implemented_req, DEV_GET_PROPERTY_REQ_SIGNATURE },
+ {NULL, NULL, NULL}
+};
+
+/*
+ * Manager Message handler functions object table declaration
+ *
+ */
+static const service_table_t mgr_services[] = {
+ {MGR_GET_DEV_REQ, handle_get_devices_req, MGR_GET_DEV_REQ_SIGNATURE},
+ {MGR_INIT_REQ, handle_not_implemented_req, NULL },
+ {MGR_ENABLE_REQ, handle_not_implemented_req, NULL },
+ {MGR_DISABLE_REQ, handle_not_implemented_req, NULL },
+ {NULL, handle_not_implemented_req, NULL}
+};
+
+
+/*
+ * HCI Manager Message handler functions object table declaration
+ *
+ */
+static DBusHandlerResult hci_signal_filter (DBusConnection *conn, DBusMessage *msg, void *data);
+
+static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data);
+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 const service_table_t hci_services[] = {
+ {HCI_PERIODIC_INQ_REQ, handle_periodic_inq_req, HCI_PERIODIC_INQ_REQ_SIGNATURE},
+ {HCI_CANCEL_PERIODIC_INQ_REQ, handle_cancel_periodic_inq_req, HCI_CANCEL_PERIODIC_INQ_REQ_SIGNATURE},
+ {HCI_ROLE_SWITCH_REQ, handle_role_switch_req, HCI_ROLE_SWITCH_REQ_SIGNATURE},
+ {HCI_INQ_REQ, handle_inq_req, HCI_INQ_REQ_SIGNATURE},
+ {NULL, NULL, NULL}
+};
static void reply_handler_function(DBusPendingCall *call, void *user_data)
{
@@ -170,8 +382,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryStart");
+ message = dbus_message_new_signal(BLUEZ_DBUS_HCI_PATH,
+ BLUEZ_DBUS_HCI_INTERFACE,
+ BLUEZ_DBUS_HCI_SIG_INQ_START);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry start message");
goto failed;
@@ -204,8 +417,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryComplete");
+ message = dbus_message_new_signal(BLUEZ_DBUS_HCI_PATH,
+ BLUEZ_DBUS_HCI_INTERFACE,
+ BLUEZ_DBUS_HCI_SIG_INQ_COMPLETE);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
goto failed;
@@ -241,8 +455,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
baswap(&tmp, peer); peer_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryResult");
+ message = dbus_message_new_signal(BLUEZ_DBUS_HCI_PATH,
+ BLUEZ_DBUS_HCI_INTERFACE,
+ BLUEZ_DBUS_HCI_SIG_INQ_RESULT);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry result message");
goto failed;
@@ -280,8 +495,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
baswap(&tmp, peer); peer_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "RemoteName");
+ message = dbus_message_new_signal(BLUEZ_DBUS_HCI_PATH,
+ BLUEZ_DBUS_HCI_INTERFACE,
+ BLUEZ_DBUS_HCI_SIG_REMOTE_NAME);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
goto failed;
@@ -388,6 +604,8 @@
{
DBusError error;
+ num_adapters = 0;
+
dbus_error_init(&error);
connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
@@ -398,8 +616,774 @@
return FALSE;
}
+ dbus_bus_request_name(connection, BLUEZ_DBUS_NAME,
+ DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ syslog(LOG_ERR,"D-Bus Error: %s\n", error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ //Registering the device path
+ if (!dbus_connection_register_object_path(connection, BLUEZ_DBUS_DEVS_PATH, &obj_vtable, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", BLUEZ_DBUS_DEVS_PATH);
+ return FALSE;
+ } else {
+ syslog(LOG_INFO,"registering - path:%s", BLUEZ_DBUS_DEVS_PATH);
+ }
+
+ //Registering the manager path
+ if (!dbus_connection_register_object_path(connection, BLUEZ_DBUS_MGR_PATH, &obj_vtable, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", BLUEZ_DBUS_MGR_PATH);
+ return FALSE;
+ } else {
+ syslog(LOG_INFO,"registering - path:%s", BLUEZ_DBUS_MGR_PATH);
+ }
+
+
+ if (!dbus_connection_add_filter (connection, hci_signal_filter, NULL, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to add filter");
+ return FALSE;
+ }
+
dbus_connection_set_watch_functions(connection,
add_watch, remove_watch, watch_toggled, NULL, NULL);
return TRUE;
}
+
+/*
+ * @brief This function is responsible for register all service for
+ * each new hci device
+ * Detailed description: When a HCI_DEV_UP event is received or the
+ * daemon is initialized the service paths must be registered. eg:
+ * pan, sdp, hci, rfcomm paths.
+ * @param id device id
+ * @return TRUE/FALSE
+ */
+gboolean mgr_dbus_reg_device_paths(uint16_t id)
+{
+ profile_obj_path_data_t *ptr = obj_path_table;
+ int8_t ret = 0;
+
+ if (connection) {
+ for (;ptr->name; ptr++) {
+ ret = (ptr->reg_func(connection, ptr->dft_reg, id));
+ if (ret < 0) {
+ break;
+ }
+ /* the default path is now registered */
+ ptr->dft_reg = 1;
+ }
+
+ if (!ret) {
+ num_adapters++;
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * @brief This function is responsible for unregister all service for
+ * a detached hci device
+ * Detailed description: When a HCI_DEV_DOWN event is received the
+ * service paths must be unregistered. eg: pan, sdp, hci, rfcomm paths.
+ * @param id device id
+ * @return TRUE/FALSE
+ */
+gboolean mgr_dbus_unreg_device_paths(uint16_t id)
+{
+ profile_obj_path_data_t *ptr = obj_path_table;
+ uint8_t dft_unreg = 0;
+
+ if (connection) {
+ for (;ptr->name; ptr++) {
+ dft_unreg = (num_adapters > 1)? 0:1;
+ num_adapters--;
+ ptr->unreg_func(connection, dft_unreg, id);
+
+ if (dft_unreg ) {
+ ptr->dft_reg = 0;
+ }
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * @brief HCI object path register function
+ * Detailed description: function responsible for register a new hci
+ * D-Bus path. If necessary the default path must be registered too.
+ * @param conn D-Bus connection
+ * @param dft_reg register the default path(0 or !0)
+ * @param id hci device identification
+ * @return (0-Success/-1 failure)
+ */
+int8_t hci_dbus_reg_obj_path(DBusConnection *conn, uint8_t dft_reg, uint16_t id)
+{
+ char path[MAX_PATH_LENGTH];
+ int8_t ret = 0;
+ uint16_t *ptr_id = (int16_t*)malloc(1);
+ uint16_t *ptr_id_dft;
+
+ /* register the default path*/
+ if (!dft_reg) {
+ ptr_id_dft = (int16_t*)malloc(1);
+ *ptr_id_dft = DFT_DEVICE_ID;
+ sprintf(path, "%s/%s/%s", BLUEZ_DBUS_MGR_PATH, HCI_DFT_DEVICE_NAME, BLUEZ_DBUS_HCI);
+
+ syslog(LOG_INFO, "registering dft path:%s - id:%d", path, DFT_DEVICE_ID);
+
+ if (!dbus_connection_register_fallback(conn, path, &obj_vtable, ptr_id_dft)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", path);
+ //ignore, the default path was already registered
+ }
+
+ }
+
+ *ptr_id = id;
+
+ /* register the default path*/
+ sprintf(path, "%s/%s%d/%s", BLUEZ_DBUS_MGR_PATH, HCI_DEVICE_NAME, id ,BLUEZ_DBUS_HCI);
+
+ syslog(LOG_INFO, "registering - path:%s - id:%d",path, id);
+
+ if (!dbus_connection_register_fallback(conn, path, &obj_vtable, ptr_id)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", path);
+ return (-1);
+ }
+
+ return ret;
+}
+
+/*
+ * @brief HCI object path unregister function
+ * Detailed description: function responsible for unregister HCI D-Bus
+ * path for a detached hci device. If necessary the default path must
+ * be registered too.
+ * @param conn D-Bus connection
+ * @param unreg_dft register the default path(0 or !0)
+ * @param id hci device identification
+ * @return (0-Success/-1 failure)
+ */
+int8_t hci_dbus_unreg_obj_path(DBusConnection *conn, uint8_t unreg_dft, uint16_t id)
+{
+ int8_t ret = 0;
+ char path[MAX_PATH_LENGTH];
+ char dft_path[MAX_PATH_LENGTH];
+ uint16_t *data;
+
+ if (unreg_dft) {
+ sprintf(dft_path, "%s/%s/%s", BLUEZ_DBUS_MGR_PATH, HCI_DFT_DEVICE_NAME, BLUEZ_DBUS_HCI);
+ syslog(LOG_INFO, "%s - unregistering dft:%s", __PRETTY_FUNCTION__, dft_path);
+ 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, (void*)&data))
+ {
+ if(data)
+ free(data);
+ data = NULL;
+ }
+ }
+
+ }
+
+ sprintf(path, "%s/%s%d/%s", BLUEZ_DBUS_MGR_PATH, HCI_DEVICE_NAME, id, BLUEZ_DBUS_HCI);
+ syslog(LOG_INFO, "%s - unregistering spec:%s", __PRETTY_FUNCTION__, path);
+ 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, (void*)&data))
+ {
+ if(data)
+ free(data);
+ data = NULL;
+ }
+ }
+
+ return ret;
+}
+
+
+const service_table_t *get_hci_table(void) {
+ return hci_services;
+}
+/*****************************************************************
+ *
+ * Section reserved to HCI Manaher D-Bus message handlers
+ *
+ *****************************************************************/
+void hcid_dbus_exit(void)
+{
+ char path[MAX_PATH_LENGTH];
+ char fst_parent[] = BLUEZ_DBUS_MGR_PATH;
+ char snd_parent[MAX_PATH_LENGTH];
+ char **fst_level = NULL;
+ char **snd_level = NULL;
+ char *ptr1;
+ char *ptr2;
+
+ if (!connection)
+ return;
+ /* unregister all objects paths */
+
+ if (!dbus_connection_unregister_object_path (connection, BLUEZ_DBUS_DEVS_PATH)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", BLUEZ_DBUS_DEVS_PATH);
+ } else {
+ syslog(LOG_INFO,"unregistering - path:%s", BLUEZ_DBUS_DEVS_PATH);
+ }
+
+ if (!dbus_connection_unregister_object_path (connection, BLUEZ_DBUS_MGR_PATH)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", BLUEZ_DBUS_MGR_PATH);
+ } else {
+ syslog(LOG_INFO,"unregistering - path:%s", BLUEZ_DBUS_MGR_PATH);
+ }
+
+ //getting the first level
+ dbus_connection_list_registered(connection, fst_parent, &fst_level);
+
+ for ( ;*fst_level; fst_level++) {
+ ptr1 = *fst_level;
+ sprintf(snd_parent, "%s/%s", fst_parent, ptr1);
+
+ //getting the second level
+ dbus_connection_list_registered(connection, snd_parent, &snd_level);
+
+ if (!(*snd_level)) {
+ //no child
+ sprintf(path, "%s/%s", BLUEZ_DBUS_MGR_PATH, ptr1);
+
+ syslog(LOG_INFO, "unregistering path: %s", path);
+
+ if (!dbus_connection_unregister_object_path (connection, path)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", path);
+ }
+ continue;
+ }
+
+ for ( ;*snd_level; snd_level++) {
+ //unregistering child level path
+ ptr2 = *snd_level;
+ sprintf(path, "%s/%s/%s", BLUEZ_DBUS_MGR_PATH, ptr1, ptr2);
+
+ syslog(LOG_INFO, "unregistering path: %s", path);
+
+ if (!dbus_connection_unregister_object_path (connection, path)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", path);
+ }
+ }
+ if (*snd_level)
+ dbus_free_string_array(snd_level);
+ }
+
+ if (*fst_level)
+ dbus_free_string_array(fst_level);
+}
+
+static DBusHandlerResult hci_signal_filter (DBusConnection *conn, DBusMessage *msg, void *data)
+{
+ DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ const char *iface;
+ const char *method;
+
+ if (!msg || !conn)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (dbus_message_get_type (msg) != DBUS_MESSAGE_TYPE_SIGNAL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member(msg);
+
+ if (strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) {
+ if (strcmp(method, "Disconnected") == 0){
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ } else if (strcmp(iface, DBUS_INTERFACE_DBUS) == 0) {
+ if (strcmp(method, "NameOwnerChanged") == 0) {
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ if (strcmp(method, "NameAcquired") == 0) {
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ }
+ return ret;
+}
+/*
+ * There is only one message handler function for all object paths
+ *
+ */
+
+static DBusHandlerResult msg_func(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ const service_table_t *ptr_handlers = NULL;
+ DBusMessage *reply = NULL;
+ uint16_t type;
+ const char *iface;
+ const char *method;
+ const char *signature;
+ const char *path;
+ const char *rel_path;
+ const char *tmp_iface = NULL;
+ uint32_t result = BLUEZ_EDBUS_UNKNOWN_METHOD;
+ DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;;
+ uint8_t found = 0;
+
+
+ path = dbus_message_get_path(msg);
+ type = dbus_message_get_type(msg);
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member (msg);
+ signature = dbus_message_get_signature(msg);
+
+ syslog (LOG_INFO, "%s - path:%s", __PRETTY_FUNCTION__, path);
+
+ //get the user data
+ if (strcmp(path, BLUEZ_DBUS_DEVS_PATH) == 0) {
+ ptr_handlers = dev_services;
+ tmp_iface = BLUEZ_DBUS_DEVS_INTERFACE;
+ found = 1;
+ } else if (strcmp(path, BLUEZ_DBUS_MGR_PATH) == 0) {
+ ptr_handlers = mgr_services;
+ tmp_iface = BLUEZ_DBUS_MGR_INTERFACE;
+ found = 1;
+ } else {
+ /* only msg to registered object paths will be received */
+
+ profile_obj_path_data_t *mgr_child = obj_path_table;
+ rel_path = strrchr(path,'/');
+ rel_path++;
+
+ if (rel_path) {
+ for (;mgr_child->name; mgr_child++) {
+ if(strcmp(mgr_child->name, rel_path) == 0) {
+ ptr_handlers = mgr_child->get_svc_table();
+ found = 1;
+ }
+ }
+
+ tmp_iface = BLUEZ_DBUS_MGR_INTERFACE;
+ }
+ }
+
+ if (found && (type == DBUS_MESSAGE_TYPE_METHOD_CALL) &&
+ (strcmp(iface, tmp_iface) == 0) && (method != NULL)) {
+
+ for (; ptr_handlers->name; ptr_handlers++) {
+ if (strcmp(method, ptr_handlers->name) == 0) {
+ /* resetting unknown method. It's possible handle method overload */
+ result = BLUEZ_EDBUS_WRONG_SIGNATURE;
+ if (strcmp(ptr_handlers->signature, signature) == 0) {
+ if(ptr_handlers->handler_func) {
+ reply = (ptr_handlers->handler_func)(msg, data);
+ result = 0; /* resetting wrong signature*/
+ } else {
+ syslog(LOG_INFO, "Service not implemented");
+ }
+ break;
+ }
+
+ }
+ }
+
+ if (result) {
+ reply = bluez_new_failure_msg(msg, result);
+ syslog(LOG_INFO, "%s - %s", __PRETTY_FUNCTION__,
+ (result == BLUEZ_EDBUS_UNKNOWN_METHOD?"Unknown Method": "Wrong signature"));
+ }
+
+ /* 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;
+ } else {
+ syslog(LOG_INFO, "Request not handled");
+ }
+ return ret;
+}
+
+
+static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data)
+{
+ write_inquiry_mode_cp inq_mode;
+ periodic_inquiry_cp inq_param;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ uint8_t length;
+ uint8_t max_period;
+ uint8_t min_period;
+ int32_t sock = -1;
+ int32_t dev_id = -1;
+
+ if (*udata == DFT_DEVICE_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 cleanup;
+
+ }
+ } else {
+ dev_id = *udata;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ if ((sock = hci_open_dev(dev_id)) < 0) {
+ syslog(LOG_ERR, "HCI device open failed");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &length);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &min_period);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &max_period);
+
+ if ((length >= min_period) || (min_period >= max_period)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+ goto cleanup;
+ }
+
+ inq_param.num_rsp = 100;
+ inq_param.length = length;
+
+ inq_param.max_period = max_period;
+ inq_param.min_period = min_period;
+
+ /* General/Unlimited Inquiry Access Code (GIAC) */
+ inq_param.lap[0] = 0x33;
+ inq_param.lap[1] = 0x8b;
+ inq_param.lap[2] = 0x9e;
+
+ inq_mode.mode = 1; //INQUIRY_WITH_RSSI;
+
+ if (hci_send_cmd(sock, OGF_HOST_CTL, OCF_WRITE_INQUIRY_MODE,
+ WRITE_INQUIRY_MODE_CP_SIZE, &inq_mode) < 0) {
+ syslog(LOG_ERR, "Can't set inquiry mode:%s.", strerror(errno));
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ }
+
+ if (hci_send_cmd(sock, OGF_LINK_CTL, OCF_PERIODIC_INQUIRY,
+ PERIODIC_INQUIRY_CP_SIZE, &inq_param) < 0) {
+ syslog(LOG_ERR, "Can't send HCI commands:%s.", strerror(errno));
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ } else {
+
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE ,&result);
+ }
+
+cleanup:
+
+ if (sock > 0)
+ close(sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ int32_t sock = -1;
+ int32_t dev_id = -1;
+
+ if (*udata == DFT_DEVICE_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 cleanup;
+
+ }
+ } else {
+ dev_id = *udata;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ if ((sock = hci_open_dev(dev_id)) < 0) {
+ syslog(LOG_ERR, "HCI device open failed");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ if (hci_send_cmd(sock, OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY, 0 , NULL) < 0) {
+ syslog(LOG_ERR, "Send hci command failed.");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ } else {
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE ,&result);
+ }
+
+cleanup:
+ if (sock > 0)
+ close(sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_inq_req(DBusMessage *msg, void *data)
+{
+ char addr[18];
+ const char array_sig[] = HCI_INQ_REPLY_SIGNATURE;
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ DBusMessage *reply = NULL;
+ inquiry_info *info = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ const char *paddr = addr;
+ int32_t dev_id = -1;
+ uint32_t class = 0;
+ uint16_t clock_offset;
+ uint16_t flags;
+ int8_t length;
+ int8_t num_rsp;
+ int8_t i;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ if (*udata == DFT_DEVICE_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 cleanup;
+ }
+ } else {
+ dev_id = (int32_t)*udata;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &length);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &num_rsp);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &flags);
+
+ if ((length <= 0) || (num_rsp <= 0)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+ goto cleanup;
+ }
+
+ num_rsp = hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);
+
+ if (num_rsp < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ } else {
+ 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 < num_rsp; i++) {
+ ba2str(&(info+i)->bdaddr, addr);
+
+ clock_offset = btohs((info+i)->clock_offset);
+ /* only 3 bytes are used */
+ memcpy(&class, (info+i)->dev_class, 3);
+
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING , &paddr);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT32 , &class);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 , &clock_offset);
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+ dbus_message_iter_close_container(&iter, &array_iter);
+ }
+
+cleanup:
+ if(info)
+ bt_free(info);
+
+ return NULL;
+}
+
+static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ char *str_bdaddr = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ bdaddr_t bdaddr;
+ uint8_t role;
+ int32_t dev_id = -1, sock = -1;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &str_bdaddr);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &role);
+
+ str2ba(str_bdaddr, &bdaddr);
+
+ dev_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr);
+
+
+ if (dev_id < 0) {
+ syslog(LOG_ERR, "Bluetooth device failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ if (*udata != DFT_DEVICE_ID && *udata != dev_id) {
+ syslog(LOG_ERR, "Connection not found\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
+ goto cleanup;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ sock = hci_open_dev(dev_id);
+
+ if (sock < 0) {
+ syslog(LOG_ERR, "HCI device open failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ if (hci_switch_role(sock, &bdaddr, role, 10000) < 0) {
+ syslog(LOG_ERR, "Switch role request failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ } else {
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &result);
+ }
+cleanup:
+
+ return reply;
+}
+
+
+/*****************************************************************
+ *
+ * Section reserved to Device D-Bus message handlers
+ *
+ *****************************************************************/
+static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ DBusMessage *reply = NULL;
+
+ struct hci_dev_list_req *dl = NULL;
+ struct hci_dev_req *dr = NULL;
+ struct hci_dev_info di;
+ int16_t i;
+ int32_t sock = -1;
+
+ char aname[BLUETOOTH_DEVICE_NAME_LEN];
+ char aaddr[BLUETOOTH_DEVICE_ADDR_LEN];
+ char *paddr = aaddr;
+ char *pname = aname;
+ const char array_sig[] = HCI_DEVICE_STRUCT_SIGNATURE;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ /* Create and bind HCI socket */
+ if ((sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
+ syslog(LOG_ERR, "Can't open HCI socket: %s (%d)",
+ strerror(errno), errno);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ }
+
+
+ dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
+
+ if (!dl) {
+ syslog(LOG_ERR, "Can't allocate memory");
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+ goto cleanup;
+ }
+
+ dl->dev_num = HCI_MAX_DEV;
+ dr = dl->dev_req;
+
+ if (ioctl(sock, HCIGETDEVLIST, (void *) dl) < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ }
+
+
+ /* active bluetooth adapter found */
+ 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);
+ dr = dl->dev_req;
+
+ for (i = 0; i < dl->dev_num; i++, dr++) {
+ if (hci_test_bit(HCI_UP, &dr->dev_opt)) {
+ memset(&di, 0 , sizeof(struct hci_dev_info));
+ di.dev_id = dr->dev_id;
+
+ if (!ioctl(sock, HCIGETDEVINFO, (void *) &di)) {
+ strcpy(aname, di.name);
+ ba2str(&di.bdaddr, aaddr);
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL,
+ &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&pname);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&paddr);
+ syslog(LOG_INFO, "%s - (%s, %s)", __PRETTY_FUNCTION__, pname, paddr);
+
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+ }
+ }
+ dbus_message_iter_close_container(&iter, &array_iter);
+
+cleanup:
+ if (dl)
+ free(dl);
+
+ if (sock > 0)
+ close (sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data) {
+ const char *path;
+ const char *iface;
+ const char *method;
+
+ path = dbus_message_get_path(msg);
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member(msg);
+
+ syslog(LOG_INFO, "Not Implemented - path:%s, iface:%s method:%s", path, iface, method);
+
+ return NULL;
+
+}
--- bluez-utils-cvs.orig/hcid/main.c 2005-07-05 18:15:44.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/main.c 2005-10-03 10:58:28.000000000 -0300
@@ -375,6 +375,9 @@
if (hcid.security && hci_test_bit(HCI_UP, &dr->dev_opt))
start_security_manager(dr->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_reg_device_paths(dr->dev_id);
+#endif
}
free(dl);
@@ -438,12 +441,18 @@
configure_device(sd->dev_id);
if (hcid.security)
start_security_manager(sd->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_reg_device_paths(sd->dev_id);
+#endif
break;
case HCI_DEV_DOWN:
syslog(LOG_INFO, "HCI dev %d down", sd->dev_id);
if (hcid.security)
stop_security_manager(sd->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_unreg_device_paths(sd->dev_id);
+#endif
break;
}
}
@@ -627,7 +636,9 @@
g_main_run(event_loop);
free_device_opts();
-
+#ifdef ENABLE_DBUS
+ hcid_dbus_exit();
+#endif
syslog(LOG_INFO, "Exit.");
return 0;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] hcid patch
2005-10-03 14:08 ` Claudio Takahasi
@ 2005-10-03 21:02 ` Marcel Holtmann
2005-10-04 12:33 ` Claudio Takahasi
0 siblings, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2005-10-03 21:02 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> I kept some log information, if you want remove it I can send another
> patch. The error code definition was included. I am using "hciX" in
> the path name until we receive a answer from dbus list. Services under
> the path /org/bluez/Devices weren't implemented yet.
>
> Is there other changes in this patch?
this thing looks quite good, but now we need to clean up some other
parts of your constants and function naming. And please try to keep the
BlueZ/kernel coding style.
The overall BLUEZ_DBUS prefix looks like a good idea at the beginning,
but I think we don't need it at all. So this should be enough:
#define DEVICE_PATH "/org/bluez/Device"
#define DEVICE_INTERFACE "org.bluez.Device"
#define MANAGER_PATH "/org/bluez/Manager"
#define MANAGER_INTERFACE "org.bluez.Manager"
Please also stop to shortcut some names. For example DFT for DEFAULT.
Simple write the full name, because then it is easy to read this code.
The other thing is that I don't like the difference between *_REQ and
*_SIG in the names/constants. Please don't use them.
Also please don't include any RFCOMM, PAN, HID etc. related things,
because they are not important right now and they make my life of
merging the initial step into better D-Bus a lot harder.
For the error part we will use org.bluez.Error and not EFailed or
anything like this. Since all the error stuff is currently not used, I
don't think it is a good idea to add it to the initial patch. Looking at
HAL the use of org.bluez.NoSuchDevice, etc. seems to make sense, too.
Do we really need that service_table_t thingy now? I think we should
start without it.
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] 8+ messages in thread
* Re: [Bluez-devel] hcid patch
2005-10-03 21:02 ` Marcel Holtmann
@ 2005-10-04 12:33 ` Claudio Takahasi
2005-10-04 12:47 ` Claudio Takahasi
0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2005-10-04 12:33 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1.1: Type: text/plain, Size: 2773 bytes --]
Hi Marcel,
Your suggestions were done!
Regarding service_table_t, if we remove it, the logic will be based on
"if"and "else", see the HAL message filter function. In my opinion
service_table_t is more clear.
If you think that is really necessary remove the error handling and the
service_table_t I can do it in the next patch.
Regards,
Claudio.
On 10/3/05, Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Claudio,
>
> > I kept some log information, if you want remove it I can send another
> > patch. The error code definition was included. I am using "hciX" in
> > the path name until we receive a answer from dbus list. Services under
> > the path /org/bluez/Devices weren't implemented yet.
> >
> > Is there other changes in this patch?
>
> this thing looks quite good, but now we need to clean up some other
> parts of your constants and function naming. And please try to keep the
> BlueZ/kernel coding style.
>
> The overall BLUEZ_DBUS prefix looks like a good idea at the beginning,
> but I think we don't need it at all. So this should be enough:
>
> #define DEVICE_PATH "/org/bluez/Device"
> #define DEVICE_INTERFACE "org.bluez.Device"
>
> #define MANAGER_PATH "/org/bluez/Manager"
> #define MANAGER_INTERFACE "org.bluez.Manager"
>
> Please also stop to shortcut some names. For example DFT for DEFAULT.
> Simple write the full name, because then it is easy to read this code.
>
> The other thing is that I don't like the difference between *_REQ and
> *_SIG in the names/constants. Please don't use them.
>
> Also please don't include any RFCOMM, PAN, HID etc. related things,
> because they are not important right now and they make my life of
> merging the initial step into better D-Bus a lot harder.
>
> For the error part we will use org.bluez.Error and not EFailed or
> anything like this. Since all the error stuff is currently not used, I
> don't think it is a good idea to add it to the initial patch. Looking at
> HAL the use of org.bluez.NoSuchDevice, etc. seems to make sense, too.
>
> Do we really need that service_table_t thingy now? I think we should
> start without it.
>
> 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
>
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #1.2: Type: text/html, Size: 3705 bytes --]
[-- Attachment #2: Type: text/html, Size: 3576 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] hcid patch
2005-10-04 12:33 ` Claudio Takahasi
@ 2005-10-04 12:47 ` Claudio Takahasi
2005-10-04 13:11 ` Johan Hedberg
0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2005-10-04 12:47 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1.1: Type: text/plain, Size: 3217 bytes --]
Hi folks,
Sorry, I forgot attach the patch.
On 10/4/05, Claudio Takahasi <cktakahasi@gmail.com> wrote:
>
>
> Hi Marcel,
>
> Your suggestions were done!
> Regarding service_table_t, if we remove it, the logic will be based on
> "if"and "else", see the HAL message filter function. In my opinion
> service_table_t is more clear.
>
> If you think that is really necessary remove the error handling and the
> service_table_t I can do it in the next patch.
>
> Regards,
> Claudio.
>
>
>
>
>
> On 10/3/05, Marcel Holtmann <marcel@holtmann.org> wrote:
> >
> > Hi Claudio,
> >
> > > I kept some log information, if you want remove it I can send another
> > > patch. The error code definition was included. I am using "hciX" in
> > > the path name until we receive a answer from dbus list. Services under
> >
> > > the path /org/bluez/Devices weren't implemented yet.
> > >
> > > Is there other changes in this patch?
> >
> > this thing looks quite good, but now we need to clean up some other
> > parts of your constants and function naming. And please try to keep the
> > BlueZ/kernel coding style.
> >
> > The overall BLUEZ_DBUS prefix looks like a good idea at the beginning,
> > but I think we don't need it at all. So this should be enough:
> >
> > #define DEVICE_PATH "/org/bluez/Device"
> > #define DEVICE_INTERFACE "org.bluez.Device"
> >
> > #define MANAGER_PATH "/org/bluez/Manager"
> > #define MANAGER_INTERFACE "org.bluez.Manager"
> >
> > Please also stop to shortcut some names. For example DFT for DEFAULT.
> > Simple write the full name, because then it is easy to read this code.
> >
> > The other thing is that I don't like the difference between *_REQ and
> > *_SIG in the names/constants. Please don't use them.
> >
> > Also please don't include any RFCOMM, PAN, HID etc. related things,
> > because they are not important right now and they make my life of
> > merging the initial step into better D-Bus a lot harder.
> >
> > For the error part we will use org.bluez.Error and not EFailed or
> > anything like this. Since all the error stuff is currently not used, I
> > don't think it is a good idea to add it to the initial patch. Looking at
> > HAL the use of org.bluez.NoSuchDevice, etc. seems to make sense, too.
> >
> > Do we really need that service_table_t thingy now? I think we should
> > start without it.
> >
> > 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
> >
>
>
>
> --
> ---------------------------------------------------------
> 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: 4864 bytes --]
[-- Attachment #2: hcid_dbus_0011.patch --]
[-- Type: application/octet-stream, Size: 39714 bytes --]
--- bluez-utils-cvs.orig/hcid/hcid.h 2005-08-25 15:32:41.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/hcid.h 2005-10-03 11:02:36.000000000 -0300
@@ -122,6 +122,9 @@
#ifdef ENABLE_DBUS
gboolean hcid_dbus_init(void);
+void hcid_dbus_exit(void);
+gboolean mgr_dbus_reg_device_paths(uint16_t id);
+gboolean mgr_dbus_unreg_device_paths(uint16_t id);
void hcid_dbus_request_pin(int dev, struct hci_conn_info *ci);
void hcid_dbus_inquiry_start(bdaddr_t *local);
void hcid_dbus_inquiry_complete(bdaddr_t *local);
--- bluez-utils-cvs.orig/hcid/dbus.h 1969-12-31 21:00:00.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-04 09:20:26.000000000 -0300
@@ -0,0 +1,169 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2000-2001 Qualcomm Incorporated
+ * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
+ * Copyright (C) 2002-2005 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
+ * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
+ * SOFTWARE IS DISCLAIMED.
+ *
+ *
+ * $Id: dbus.h,v 0.1 2005/09/16 08:00:00 holtmann Exp $
+ */
+
+#ifndef __H_BLUEZ_DBUS_H__
+#define __H_BLUEZ_DBUS_H__
+
+#define __END_SIG__ DBUS_TYPE_INVALID_AS_STRING
+
+/* bluetoothd Bus name */
+#define BLUEZ_DBUS_NAME "org.bluez"
+#define DEFAULT_DEVICE_ID (0xFFFF)
+#define HCI_DEFAULT_DEVICE_NAME "default"
+#define HCI_DEVICE_NAME "hci"
+
+#define DEVICE_PATH "/org/bluez/Devices"
+#define DEVICE_INTERFACE BLUEZ_DBUS_NAME".Devices"
+
+#define MANAGER_PATH "/org/bluez/Manager"
+#define MANAGER_INTERFACE BLUEZ_DBUS_NAME".Manager"
+
+/*========================================================================
+ BlueZ D-Bus Device service definitions "/org/bluez/Device"
+ *========================================================================*/
+#define DEV_UP "Up"
+#define DEV_DOWN "Down"
+#define DEV_RESET "Reset"
+#define DEV_SET_PROPERTY "SetProperty"
+#define DEV_GET_PROPERTY "GetProperty"
+
+#define DEV_UP_SIGNATURE __END_SIG__
+#define DEV_DOWN_SIGNATURE __END_SIG__
+#define DEV_RESET_SIGNATURE __END_SIG__
+#define DEV_SET_PROPERTY_SIGNATURE __END_SIG__
+#define DEV_GET_PROPERTY_SIGNATURE __END_SIG__
+
+
+//TODO add the other hciconfig features
+
+/*========================================================================
+ BlueZ D-Bus Manager service definitions "/org/bluez/Manager"
+ *========================================================================*/
+
+ /* ===== Manager definitions, services under DEVICE_PATH ===== */
+#define MGR_GET_DEV "DeviceList"
+#define MGR_INIT "Init"
+
+/* Enable/Disable services controller, pan, serial, ... */
+#define MGR_ENABLE "Enable"
+#define MGR_DISABLE "Disable"
+
+//signatures
+#define MGR_GET_DEV_SIGNATURE __END_SIG__
+
+/* yya(ss)*/
+#define MGR_GET_DEV_REPLY_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_ARRAY_AS_STRING\
+ HCI_DEVICE_STRUCT_SIGNATURE\
+ __END_SIG__
+
+/* ===== HCI definitions ===== */
+#define BLUEZ_HCI "Controller"
+#define BLUEZ_HCI_PATH MANAGER_PATH"/"BLUEZ_HCI
+#define BLUEZ_HCI_INTERFACE MANAGER_INTERFACE"."BLUEZ_HCI
+
+//HCI signals
+#define BLUEZ_HCI_INQ_START "InquiryStartSig"
+#define BLUEZ_HCI_INQ_COMPLETE "InquiryCompleteSig"
+#define BLUEZ_HCI_INQ_RESULT "InquiryResultSig"
+#define BLUEZ_HCI_REMOTE_NAME "RemoteNameSig"
+
+//HCI Provided services
+#define HCI_PERIODIC_INQ "PeriodicInquiry"
+#define HCI_CANCEL_PERIODIC_INQ "CancelPeriodic"
+#define HCI_INQ "Inquiry"
+#define HCI_ROLE_SWITCH "RoleSwitch"
+
+
+#define HCI_PERIODIC_INQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ __END_SIG__
+
+#define HCI_CANCEL_PERIODIC_INQ_SIGNATURE __END_SIG__
+
+#define HCI_INQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ __END_SIG__
+
+#define HCI_ROLE_SWITCH_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ __END_SIG__
+
+#define HCI_DEVICE_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING
+
+#define HCI_INQ_REPLY_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_UINT32_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING\
+ __END_SIG__
+
+
+/* ===== Common Error messages of org.bluez. =====*/
+#define BLUEZ_DBUS_ERROR BLUEZ_DBUS_NAME".Error"
+
+
+/* BLUEZ_DBUS_ERROR
+ * EFailed error messages signature is : su
+ * Where the first argument is a string(error message description),
+ * the last is a uint32 that contains the error class(system, dbus or hci).
+ */
+
+/* Error code offsets */
+#define BLUEZ_EBT_OFFSET (0x00000000) /* see Bluetooth error code */
+#define BLUEZ_EBT_EXT_OFFSET (0x00000100)
+#define BLUEZ_EDBUS_OFFSET (0x00010000)
+#define BLUEZ_ESYSTEM_OFFSET (0x00020000)
+#define BLUEZ_EFUTURE_OFFSET (0x00040000)
+
+
+/* D-Bus error code, class BLUEZ_EDBUS_OFFSET */
+#define BLUEZ_EDBUS_UNKNOWN_METHOD (0x01 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_WRONG_SIGNATURE (0x02 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_WRONG_PARAM (0x03 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_RECORD_NOT_FOUND (0x04 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_NO_MEM (0x05 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_CONN_NOT_FOUND (0x06 + BLUEZ_EDBUS_OFFSET)
+
+/* D-Bus error code, class BLUEZ_ESYSTEM_OFFSET */
+#define BLUEZ_ESYSTEM_ENODEV (ENODEV + BLUEZ_ESYSTEM_OFFSET)
+
+
+/* BLUEZ_DBUS_ERR_NO_MEMORY */
+#define BLUEZ_DBUS_ERR_NO_MEMORY_STR "No memory"
+
+
+#endif /*__H_BLUEZ_DBUS_H__*/
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-09-22 09:09:16.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-04 08:57:27.000000000 -0300
@@ -33,9 +33,14 @@
#endif
#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/syslog.h>
+
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
@@ -45,22 +50,226 @@
#include "glib-ectomy.h"
#include "hcid.h"
+#include "dbus.h"
static DBusConnection *connection;
+static int8_t num_adapters = 0;
#define TIMEOUT (30 * 1000) /* 30 seconds */
+#define BLUETOOTH_DEVICE_NAME_LEN (18)
+#define BLUETOOTH_DEVICE_ADDR_LEN (18)
+#define MAX_PATH_LENGTH (64)
+
+#define PINAGENT_SERVICE_NAME "org.bluez.PinAgent"
+#define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
+#define PIN_REQUEST "PinRequest"
+#define PINAGENT_PATH "/org/bluez/PinAgent"
-#define SERVICE_NAME "org.bluez.PinAgent"
-#define INTERFACE_NAME SERVICE_NAME
-#define REQUEST_NAME "PinRequest"
-#define PATH_NAME "/org/bluez/PinAgent"
-
-#define WRONG_ARGS_ERROR "org.bluez.Error.WrongArgs"
struct pin_request {
int dev;
bdaddr_t bda;
};
+/*
+ * next action: move to a common header
+ */
+
+
+typedef DBusMessage* (service_handler_func_t)(DBusMessage *, void *);
+
+typedef struct
+{
+ const char *name;
+ service_handler_func_t *handler_func;
+ const char *signature;
+}service_table_t;
+
+typedef int8_t register_function_t(DBusConnection *conn, uint8_t dft_reg, uint16_t id);
+typedef int8_t unregister_function_t(DBusConnection *conn, uint8_t unreg_dft, uint16_t id);
+
+const service_table_t *get_hci_table(void);
+int8_t hci_dbus_reg_obj_path(DBusConnection *conn, uint8_t dft_reg, uint16_t id);
+int8_t hci_dbus_unreg_obj_path(DBusConnection *conn, uint8_t unreg_dft, uint16_t id);
+
+
+typedef const service_table_t* get_svc_table_func_t(void);
+typedef struct {
+ const char *name;
+ uint8_t status; /* 1:active 0:disabled */
+ uint8_t dft_reg; /* dft path registered */
+ register_function_t *reg_func;
+ unregister_function_t *unreg_func;
+ get_svc_table_func_t *get_svc_table; /* return the service table */
+}__attribute__((packed))profile_obj_path_data_t;
+
+/*
+ * next action: Move to /common directory
+ */
+
+static int find_conn(int s, int dev_id, long arg)
+{
+ struct hci_conn_list_req *cl;
+ struct hci_conn_info *ci;
+ int i;
+
+ if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
+ syslog(LOG_ERR, "Can't allocate memory");
+ return 0;
+ }
+ cl->dev_id = dev_id;
+ cl->conn_num = 10;
+ ci = cl->conn_info;
+
+ if (ioctl(s, HCIGETCONNLIST, (void *) cl)) {
+ syslog(LOG_ERR, "Can't get connection list");
+ return 0;
+ }
+
+ for (i = 0; i < cl->conn_num; i++, ci++)
+ if (!bacmp((bdaddr_t *) arg, &ci->bdaddr))
+ return 1;
+
+ return 0;
+}
+
+
+/*
+ * D-Bus error messages functions and declarations.
+ * This section should be moved to a common file
+ * in the future
+ *
+ */
+typedef struct {
+ uint32_t code;
+ const char *str;
+}bluez_error_t;
+
+static const bluez_error_t error_array[] = {
+ { BLUEZ_EDBUS_UNKNOWN_METHOD, "Method not found"},
+ { BLUEZ_EDBUS_WRONG_SIGNATURE, "Wrong method signature"},
+ { BLUEZ_EDBUS_WRONG_PARAM, "Invalid parameters"},
+ { BLUEZ_EDBUS_RECORD_NOT_FOUND, "No record found"},
+ { 0, NULL }
+};
+
+static const char *bluez_dbus_error_to_str(const uint32_t ecode)
+{
+ const bluez_error_t *ptr;
+ uint32_t raw_code = 0;
+
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ if (ecode & BLUEZ_ESYSTEM_OFFSET) {
+ /* System error */
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+ 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) {
+ /* D-Bus error */
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+ for (ptr = error_array; ptr->code; ptr++) {
+ if(ptr->code == ecode) {
+ syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, ptr->str);
+ return ptr->str;
+ }
+ }
+ }
+ return NULL;
+}
+
+DBusMessage *bluez_new_failure_msg(DBusMessage *msg, const uint32_t ecode)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const char *error_msg = NULL;
+
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ error_msg = bluez_dbus_error_to_str(ecode);
+
+ if (error_msg) {
+
+ reply = dbus_message_new_error(msg, BLUEZ_DBUS_ERROR, error_msg);
+
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32 ,&ecode);
+ }
+
+ return reply;
+}
+
+/*
+ * Object path register/unregister functions
+ *
+ */
+static profile_obj_path_data_t obj_path_table[] = {
+ {BLUEZ_HCI, 1, 0, hci_dbus_reg_obj_path, hci_dbus_unreg_obj_path, get_hci_table },
+ /* add other profiles here */
+ {NULL, 0, 0, NULL, NULL, NULL}
+};
+
+/*
+ * Device Message handler functions object table declaration
+ */
+static DBusHandlerResult msg_func(DBusConnection *conn, DBusMessage *msg, void *data);
+
+static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data);
+
+static const DBusObjectPathVTable obj_vtable = {
+ NULL,
+ &msg_func,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+/*
+ * Service provided under the path DEVICE_PATH
+ * TODO add the handlers
+ */
+static const service_table_t dev_services[] = {
+ {DEV_UP, handle_not_implemented_req, DEV_UP_SIGNATURE},
+ {DEV_DOWN, handle_not_implemented_req, DEV_DOWN_SIGNATURE},
+ {DEV_RESET, handle_not_implemented_req, DEV_RESET_SIGNATURE },
+ {DEV_SET_PROPERTY, handle_not_implemented_req, DEV_SET_PROPERTY_SIGNATURE },
+ {DEV_GET_PROPERTY, handle_not_implemented_req, DEV_GET_PROPERTY_SIGNATURE },
+ {NULL, NULL, NULL}
+};
+
+/*
+ * Manager Message handler functions object table declaration
+ *
+ */
+static const service_table_t mgr_services[] = {
+ {MGR_GET_DEV, handle_get_devices_req, MGR_GET_DEV_SIGNATURE},
+ {MGR_INIT, handle_not_implemented_req, NULL },
+ {MGR_ENABLE, handle_not_implemented_req, NULL },
+ {MGR_DISABLE, handle_not_implemented_req, NULL },
+ {NULL, handle_not_implemented_req, NULL}
+};
+
+
+/*
+ * HCI Manager Message handler functions object table declaration
+ *
+ */
+static DBusHandlerResult hci_signal_filter (DBusConnection *conn, DBusMessage *msg, void *data);
+
+static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data);
+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 const service_table_t 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},
+ {NULL, NULL, NULL}
+};
static void reply_handler_function(DBusPendingCall *call, void *user_data)
{
@@ -126,8 +335,8 @@
uint8_t *addr = (uint8_t *) &ci->bdaddr;
dbus_bool_t out = ci->out;
- message = dbus_message_new_method_call(SERVICE_NAME, PATH_NAME,
- INTERFACE_NAME, REQUEST_NAME);
+ message = dbus_message_new_method_call(PINAGENT_SERVICE_NAME, PINAGENT_PATH,
+ PINAGENT_INTERFACE, PIN_REQUEST);
if (message == NULL) {
syslog(LOG_ERR, "Couldn't allocate D-BUS message");
goto failed;
@@ -165,13 +374,14 @@
void hcid_dbus_inquiry_start(bdaddr_t *local)
{
DBusMessage *message;
- char *local_addr;
+ char *local_addr;
bdaddr_t tmp;
baswap(&tmp, local); local_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryStart");
+ message = dbus_message_new_signal(BLUEZ_HCI_PATH,
+ BLUEZ_HCI_INTERFACE,
+ BLUEZ_HCI_INQ_START);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry start message");
goto failed;
@@ -204,8 +414,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryComplete");
+ message = dbus_message_new_signal(BLUEZ_HCI_PATH,
+ BLUEZ_HCI_INTERFACE,
+ BLUEZ_HCI_INQ_COMPLETE);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
goto failed;
@@ -241,8 +452,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
baswap(&tmp, peer); peer_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryResult");
+ message = dbus_message_new_signal(BLUEZ_HCI_PATH,
+ BLUEZ_HCI_INTERFACE,
+ BLUEZ_HCI_INQ_RESULT);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry result message");
goto failed;
@@ -280,8 +492,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
baswap(&tmp, peer); peer_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "RemoteName");
+ message = dbus_message_new_signal(BLUEZ_HCI_PATH,
+ BLUEZ_HCI_INTERFACE,
+ BLUEZ_HCI_REMOTE_NAME);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
goto failed;
@@ -388,6 +601,8 @@
{
DBusError error;
+ num_adapters = 0;
+
dbus_error_init(&error);
connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
@@ -398,8 +613,774 @@
return FALSE;
}
+ dbus_bus_request_name(connection, BLUEZ_DBUS_NAME,
+ DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ syslog(LOG_ERR,"D-Bus Error: %s\n", error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ //Registering the device path
+ if (!dbus_connection_register_object_path(connection, DEVICE_PATH, &obj_vtable, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", DEVICE_PATH);
+ return FALSE;
+ } else {
+ syslog(LOG_INFO,"registering - path:%s", DEVICE_PATH);
+ }
+
+ //Registering the manager path
+ if (!dbus_connection_register_object_path(connection, MANAGER_PATH, &obj_vtable, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", MANAGER_PATH);
+ return FALSE;
+ } else {
+ syslog(LOG_INFO,"registering - path:%s", MANAGER_PATH);
+ }
+
+
+ if (!dbus_connection_add_filter (connection, hci_signal_filter, NULL, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to add filter");
+ return FALSE;
+ }
+
dbus_connection_set_watch_functions(connection,
add_watch, remove_watch, watch_toggled, NULL, NULL);
return TRUE;
}
+
+/*
+ * @brief This function is responsible for register all service for
+ * each new hci device
+ * Detailed description: When a HCI_DEV_UP event is received or the
+ * daemon is initialized the service paths must be registered. eg:
+ * pan, sdp, hci, rfcomm paths.
+ * @param id device id
+ * @return TRUE/FALSE
+ */
+gboolean mgr_dbus_reg_device_paths(uint16_t id)
+{
+ profile_obj_path_data_t *ptr = obj_path_table;
+ int8_t ret = 0;
+
+ if (connection) {
+ for (;ptr->name; ptr++) {
+ ret = (ptr->reg_func(connection, ptr->dft_reg, id));
+ if (ret < 0) {
+ break;
+ }
+ /* the default path is now registered */
+ ptr->dft_reg = 1;
+ }
+
+ if (!ret) {
+ num_adapters++;
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * @brief This function is responsible for unregister all service for
+ * a detached hci device
+ * Detailed description: When a HCI_DEV_DOWN event is received the
+ * service paths must be unregistered. eg: pan, sdp, hci, rfcomm paths.
+ * @param id device id
+ * @return TRUE/FALSE
+ */
+gboolean mgr_dbus_unreg_device_paths(uint16_t id)
+{
+ profile_obj_path_data_t *ptr = obj_path_table;
+ uint8_t dft_unreg = 0;
+
+ if (connection) {
+ for (;ptr->name; ptr++) {
+ dft_unreg = (num_adapters > 1)? 0:1;
+ num_adapters--;
+ ptr->unreg_func(connection, dft_unreg, id);
+
+ if (dft_unreg ) {
+ ptr->dft_reg = 0;
+ }
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * @brief HCI object path register function
+ * Detailed description: function responsible for register a new hci
+ * D-Bus path. If necessary the default path must be registered too.
+ * @param conn D-Bus connection
+ * @param dft_reg register the default path(0 or !0)
+ * @param id hci device identification
+ * @return (0-Success/-1 failure)
+ */
+int8_t hci_dbus_reg_obj_path(DBusConnection *conn, uint8_t dft_reg, uint16_t id)
+{
+ char path[MAX_PATH_LENGTH];
+ int8_t ret = 0;
+ uint16_t *ptr_id = (int16_t*)malloc(1);
+ uint16_t *ptr_id_dft;
+
+ /* register the default path*/
+ if (!dft_reg) {
+ ptr_id_dft = (int16_t*)malloc(1);
+ *ptr_id_dft = DEFAULT_DEVICE_ID;
+ sprintf(path, "%s/%s/%s", MANAGER_PATH, HCI_DEFAULT_DEVICE_NAME, BLUEZ_HCI);
+
+ syslog(LOG_INFO, "registering dft path:%s - id:%d", path, DEFAULT_DEVICE_ID);
+
+ if (!dbus_connection_register_fallback(conn, path, &obj_vtable, ptr_id_dft)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", path);
+ //ignore, the default path was already registered
+ }
+
+ }
+
+ *ptr_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_fallback(conn, path, &obj_vtable, ptr_id)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", path);
+ return (-1);
+ }
+
+ return ret;
+}
+
+/*
+ * @brief HCI object path unregister function
+ * Detailed description: function responsible for unregister HCI D-Bus
+ * path for a detached hci device. If necessary the default path must
+ * be registered too.
+ * @param conn D-Bus connection
+ * @param unreg_dft register the default path(0 or !0)
+ * @param id hci device identification
+ * @return (0-Success/-1 failure)
+ */
+int8_t hci_dbus_unreg_obj_path(DBusConnection *conn, uint8_t unreg_dft, uint16_t id)
+{
+ int8_t ret = 0;
+ char path[MAX_PATH_LENGTH];
+ char dft_path[MAX_PATH_LENGTH];
+ uint16_t *data;
+
+ if (unreg_dft) {
+ sprintf(dft_path, "%s/%s/%s", MANAGER_PATH, HCI_DEFAULT_DEVICE_NAME, BLUEZ_HCI);
+ syslog(LOG_INFO, "%s - unregistering dft:%s", __PRETTY_FUNCTION__, dft_path);
+ 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, (void*)&data))
+ {
+ if(data)
+ free(data);
+ data = NULL;
+ }
+ }
+
+ }
+
+ sprintf(path, "%s/%s%d/%s", MANAGER_PATH, HCI_DEVICE_NAME, id, BLUEZ_HCI);
+ syslog(LOG_INFO, "%s - unregistering spec:%s", __PRETTY_FUNCTION__, path);
+ 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, (void*)&data))
+ {
+ if(data)
+ free(data);
+ data = NULL;
+ }
+ }
+
+ return ret;
+}
+
+
+const service_table_t *get_hci_table(void) {
+ return hci_services;
+}
+/*****************************************************************
+ *
+ * Section reserved to HCI Manaher D-Bus message handlers
+ *
+ *****************************************************************/
+void hcid_dbus_exit(void)
+{
+ char path[MAX_PATH_LENGTH];
+ char fst_parent[] = MANAGER_PATH;
+ char snd_parent[MAX_PATH_LENGTH];
+ char **fst_level = NULL;
+ char **snd_level = NULL;
+ char *ptr1;
+ char *ptr2;
+
+ if (!connection)
+ return;
+ /* unregister all objects paths */
+
+ if (!dbus_connection_unregister_object_path (connection, DEVICE_PATH)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", DEVICE_PATH);
+ } else {
+ syslog(LOG_INFO,"unregistering - path:%s", DEVICE_PATH);
+ }
+
+ if (!dbus_connection_unregister_object_path (connection, MANAGER_PATH)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", MANAGER_PATH);
+ } else {
+ syslog(LOG_INFO,"unregistering - path:%s", MANAGER_PATH);
+ }
+
+ //getting the first level
+ dbus_connection_list_registered(connection, fst_parent, &fst_level);
+
+ for ( ;*fst_level; fst_level++) {
+ ptr1 = *fst_level;
+ sprintf(snd_parent, "%s/%s", fst_parent, ptr1);
+
+ //getting the second level
+ dbus_connection_list_registered(connection, snd_parent, &snd_level);
+
+ if (!(*snd_level)) {
+ //no child
+ sprintf(path, "%s/%s", MANAGER_PATH, ptr1);
+
+ syslog(LOG_INFO, "unregistering path: %s", path);
+
+ if (!dbus_connection_unregister_object_path (connection, path)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", path);
+ }
+ continue;
+ }
+
+ for ( ;*snd_level; snd_level++) {
+ //unregistering child level path
+ ptr2 = *snd_level;
+ sprintf(path, "%s/%s/%s", MANAGER_PATH, ptr1, ptr2);
+
+ syslog(LOG_INFO, "unregistering path: %s", path);
+
+ if (!dbus_connection_unregister_object_path (connection, path)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", path);
+ }
+ }
+ if (*snd_level)
+ dbus_free_string_array(snd_level);
+ }
+
+ if (*fst_level)
+ dbus_free_string_array(fst_level);
+}
+
+static DBusHandlerResult hci_signal_filter (DBusConnection *conn, DBusMessage *msg, void *data)
+{
+ DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ const char *iface;
+ const char *method;
+
+ if (!msg || !conn)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (dbus_message_get_type (msg) != DBUS_MESSAGE_TYPE_SIGNAL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member(msg);
+
+ if (strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) {
+ if (strcmp(method, "Disconnected") == 0){
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ } else if (strcmp(iface, DBUS_INTERFACE_DBUS) == 0) {
+ if (strcmp(method, "NameOwnerChanged") == 0) {
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ if (strcmp(method, "NameAcquired") == 0) {
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ }
+ return ret;
+}
+/*
+ * There is only one message handler function for all object paths
+ *
+ */
+
+static DBusHandlerResult msg_func(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ const service_table_t *ptr_handlers = NULL;
+ DBusMessage *reply = NULL;
+ uint16_t type;
+ const char *iface;
+ const char *method;
+ const char *signature;
+ const char *path;
+ const char *rel_path;
+ const char *tmp_iface = NULL;
+ uint32_t result = BLUEZ_EDBUS_UNKNOWN_METHOD;
+ DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;;
+ uint8_t found = 0;
+
+
+ path = dbus_message_get_path(msg);
+ type = dbus_message_get_type(msg);
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member (msg);
+ signature = dbus_message_get_signature(msg);
+
+ syslog (LOG_INFO, "%s - path:%s", __PRETTY_FUNCTION__, path);
+
+ //get the user data
+ if (strcmp(path, DEVICE_PATH) == 0) {
+ ptr_handlers = dev_services;
+ tmp_iface = DEVICE_INTERFACE;
+ found = 1;
+ } else if (strcmp(path, MANAGER_PATH) == 0) {
+ ptr_handlers = mgr_services;
+ tmp_iface = MANAGER_INTERFACE;
+ found = 1;
+ } else {
+ /* only msg to registered object paths will be received */
+
+ profile_obj_path_data_t *mgr_child = obj_path_table;
+ rel_path = strrchr(path,'/');
+ rel_path++;
+
+ if (rel_path) {
+ for (;mgr_child->name; mgr_child++) {
+ if(strcmp(mgr_child->name, rel_path) == 0) {
+ ptr_handlers = mgr_child->get_svc_table();
+ found = 1;
+ }
+ }
+
+ tmp_iface = MANAGER_INTERFACE;
+ }
+ }
+
+ if (found && (type == DBUS_MESSAGE_TYPE_METHOD_CALL) &&
+ (strcmp(iface, tmp_iface) == 0) && (method != NULL)) {
+
+ for (; ptr_handlers->name; ptr_handlers++) {
+ if (strcmp(method, ptr_handlers->name) == 0) {
+ /* resetting unknown method. It's possible handle method overload */
+ result = BLUEZ_EDBUS_WRONG_SIGNATURE;
+ if (strcmp(ptr_handlers->signature, signature) == 0) {
+ if(ptr_handlers->handler_func) {
+ reply = (ptr_handlers->handler_func)(msg, data);
+ result = 0; /* resetting wrong signature*/
+ } else {
+ syslog(LOG_INFO, "Service not implemented");
+ }
+ break;
+ }
+
+ }
+ }
+
+ if (result) {
+ reply = bluez_new_failure_msg(msg, result);
+ syslog(LOG_INFO, "%s - %s", __PRETTY_FUNCTION__,
+ (result == BLUEZ_EDBUS_UNKNOWN_METHOD?"Unknown Method": "Wrong signature"));
+ }
+
+ /* 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;
+ } else {
+ syslog(LOG_INFO, "Request not handled");
+ }
+ return ret;
+}
+
+
+static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data)
+{
+ write_inquiry_mode_cp inq_mode;
+ periodic_inquiry_cp inq_param;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ uint8_t length;
+ uint8_t max_period;
+ uint8_t min_period;
+ int32_t sock = -1;
+ int32_t dev_id = -1;
+
+ if (*udata == DEFAULT_DEVICE_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 cleanup;
+
+ }
+ } else {
+ dev_id = *udata;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ if ((sock = hci_open_dev(dev_id)) < 0) {
+ syslog(LOG_ERR, "HCI device open failed");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &length);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &min_period);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &max_period);
+
+ if ((length >= min_period) || (min_period >= max_period)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+ goto cleanup;
+ }
+
+ inq_param.num_rsp = 100;
+ inq_param.length = length;
+
+ inq_param.max_period = max_period;
+ inq_param.min_period = min_period;
+
+ /* General/Unlimited Inquiry Access Code (GIAC) */
+ inq_param.lap[0] = 0x33;
+ inq_param.lap[1] = 0x8b;
+ inq_param.lap[2] = 0x9e;
+
+ inq_mode.mode = 1; //INQUIRY_WITH_RSSI;
+
+ if (hci_send_cmd(sock, OGF_HOST_CTL, OCF_WRITE_INQUIRY_MODE,
+ WRITE_INQUIRY_MODE_CP_SIZE, &inq_mode) < 0) {
+ syslog(LOG_ERR, "Can't set inquiry mode:%s.", strerror(errno));
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ }
+
+ if (hci_send_cmd(sock, OGF_LINK_CTL, OCF_PERIODIC_INQUIRY,
+ PERIODIC_INQUIRY_CP_SIZE, &inq_param) < 0) {
+ syslog(LOG_ERR, "Can't send HCI commands:%s.", strerror(errno));
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ } else {
+
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE ,&result);
+ }
+
+cleanup:
+
+ if (sock > 0)
+ close(sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ int32_t sock = -1;
+ int32_t dev_id = -1;
+
+ if (*udata == DEFAULT_DEVICE_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 cleanup;
+
+ }
+ } else {
+ dev_id = *udata;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ if ((sock = hci_open_dev(dev_id)) < 0) {
+ syslog(LOG_ERR, "HCI device open failed");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ if (hci_send_cmd(sock, OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY, 0 , NULL) < 0) {
+ syslog(LOG_ERR, "Send hci command failed.");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ } else {
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE ,&result);
+ }
+
+cleanup:
+ if (sock > 0)
+ close(sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_inq_req(DBusMessage *msg, void *data)
+{
+ char addr[18];
+ const char array_sig[] = HCI_INQ_REPLY_SIGNATURE;
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ DBusMessage *reply = NULL;
+ inquiry_info *info = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ const char *paddr = addr;
+ int32_t dev_id = -1;
+ uint32_t class = 0;
+ uint16_t clock_offset;
+ uint16_t flags;
+ int8_t length;
+ int8_t num_rsp;
+ int8_t i;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ if (*udata == DEFAULT_DEVICE_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 cleanup;
+ }
+ } else {
+ dev_id = (int32_t)*udata;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &length);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &num_rsp);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &flags);
+
+ if ((length <= 0) || (num_rsp <= 0)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+ goto cleanup;
+ }
+
+ num_rsp = hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);
+
+ if (num_rsp < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ } else {
+ 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 < num_rsp; i++) {
+ ba2str(&(info+i)->bdaddr, addr);
+
+ clock_offset = btohs((info+i)->clock_offset);
+ /* only 3 bytes are used */
+ memcpy(&class, (info+i)->dev_class, 3);
+
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING , &paddr);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT32 , &class);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 , &clock_offset);
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+ dbus_message_iter_close_container(&iter, &array_iter);
+ }
+
+cleanup:
+ if(info)
+ bt_free(info);
+
+ return NULL;
+}
+
+static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ char *str_bdaddr = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ bdaddr_t bdaddr;
+ uint8_t role;
+ int32_t dev_id = -1, sock = -1;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &str_bdaddr);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &role);
+
+ str2ba(str_bdaddr, &bdaddr);
+
+ dev_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr);
+
+
+ if (dev_id < 0) {
+ syslog(LOG_ERR, "Bluetooth device failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ if (*udata != DEFAULT_DEVICE_ID && *udata != dev_id) {
+ syslog(LOG_ERR, "Connection not found\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
+ goto cleanup;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ sock = hci_open_dev(dev_id);
+
+ if (sock < 0) {
+ syslog(LOG_ERR, "HCI device open failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ if (hci_switch_role(sock, &bdaddr, role, 10000) < 0) {
+ syslog(LOG_ERR, "Switch role request failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ } else {
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &result);
+ }
+cleanup:
+
+ return reply;
+}
+
+
+/*****************************************************************
+ *
+ * Section reserved to Device D-Bus message handlers
+ *
+ *****************************************************************/
+static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ DBusMessage *reply = NULL;
+
+ struct hci_dev_list_req *dl = NULL;
+ struct hci_dev_req *dr = NULL;
+ struct hci_dev_info di;
+ int16_t i;
+ int32_t sock = -1;
+
+ char aname[BLUETOOTH_DEVICE_NAME_LEN];
+ char aaddr[BLUETOOTH_DEVICE_ADDR_LEN];
+ char *paddr = aaddr;
+ char *pname = aname;
+ const char array_sig[] = HCI_DEVICE_STRUCT_SIGNATURE;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ /* Create and bind HCI socket */
+ if ((sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
+ syslog(LOG_ERR, "Can't open HCI socket: %s (%d)",
+ strerror(errno), errno);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ }
+
+
+ dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
+
+ if (!dl) {
+ syslog(LOG_ERR, "Can't allocate memory");
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+ goto cleanup;
+ }
+
+ dl->dev_num = HCI_MAX_DEV;
+ dr = dl->dev_req;
+
+ if (ioctl(sock, HCIGETDEVLIST, (void *) dl) < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ }
+
+
+ /* active bluetooth adapter found */
+ 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);
+ dr = dl->dev_req;
+
+ for (i = 0; i < dl->dev_num; i++, dr++) {
+ if (hci_test_bit(HCI_UP, &dr->dev_opt)) {
+ memset(&di, 0 , sizeof(struct hci_dev_info));
+ di.dev_id = dr->dev_id;
+
+ if (!ioctl(sock, HCIGETDEVINFO, (void *) &di)) {
+ strcpy(aname, di.name);
+ ba2str(&di.bdaddr, aaddr);
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL,
+ &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&pname);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&paddr);
+ syslog(LOG_INFO, "%s - (%s, %s)", __PRETTY_FUNCTION__, pname, paddr);
+
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+ }
+ }
+ dbus_message_iter_close_container(&iter, &array_iter);
+
+cleanup:
+ if (dl)
+ free(dl);
+
+ if (sock > 0)
+ close (sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data) {
+ const char *path;
+ const char *iface;
+ const char *method;
+
+ path = dbus_message_get_path(msg);
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member(msg);
+
+ syslog(LOG_INFO, "Not Implemented - path:%s, iface:%s method:%s", path, iface, method);
+
+ return NULL;
+
+}
--- bluez-utils-cvs.orig/hcid/main.c 2005-07-05 18:15:44.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/main.c 2005-10-03 10:58:28.000000000 -0300
@@ -375,6 +375,9 @@
if (hcid.security && hci_test_bit(HCI_UP, &dr->dev_opt))
start_security_manager(dr->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_reg_device_paths(dr->dev_id);
+#endif
}
free(dl);
@@ -438,12 +441,18 @@
configure_device(sd->dev_id);
if (hcid.security)
start_security_manager(sd->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_reg_device_paths(sd->dev_id);
+#endif
break;
case HCI_DEV_DOWN:
syslog(LOG_INFO, "HCI dev %d down", sd->dev_id);
if (hcid.security)
stop_security_manager(sd->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_unreg_device_paths(sd->dev_id);
+#endif
break;
}
}
@@ -627,7 +636,9 @@
g_main_run(event_loop);
free_device_opts();
-
+#ifdef ENABLE_DBUS
+ hcid_dbus_exit();
+#endif
syslog(LOG_INFO, "Exit.");
return 0;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] hcid patch
2005-10-04 12:47 ` Claudio Takahasi
@ 2005-10-04 13:11 ` Johan Hedberg
2005-10-04 13:31 ` Claudio Takahasi
0 siblings, 1 reply; 8+ messages in thread
From: Johan Hedberg @ 2005-10-04 13:11 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
I see that you have removed "Req" from the end of method call names.
However, you still have "Sig" appended to the signal names. Is that
intentional or have you just forgotten to remove that?
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] 8+ messages in thread
* Re: [Bluez-devel] hcid patch
2005-10-04 13:11 ` Johan Hedberg
@ 2005-10-04 13:31 ` Claudio Takahasi
0 siblings, 0 replies; 8+ messages in thread
From: Claudio Takahasi @ 2005-10-04 13:31 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1.1: Type: text/plain, Size: 968 bytes --]
Hi folks/Johan,
Sorry, I forgot remove it.
I fixed it in this new patch.
Regards,
Claudio
On 10/4/05, Johan Hedberg <johan.hedberg@nokia.com> wrote:
>
> Hi Claudio,
>
> I see that you have removed "Req" from the end of method call names.
> However, you still have "Sig" appended to the signal names. Is that
> intentional or have you just forgotten to remove that?
>
> 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
>
--
---------------------------------------------------------
Claudio Takahasi
Nokia's Institute of Technology - INdT
claudio.takahasi@indt.org.br
[-- Attachment #1.2: Type: text/html, Size: 1557 bytes --]
[-- Attachment #2: hcid_dbus_0012.patch --]
[-- Type: application/octet-stream, Size: 39702 bytes --]
--- bluez-utils-cvs.orig/hcid/hcid.h 2005-08-25 15:32:41.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/hcid.h 2005-10-03 11:02:36.000000000 -0300
@@ -122,6 +122,9 @@
#ifdef ENABLE_DBUS
gboolean hcid_dbus_init(void);
+void hcid_dbus_exit(void);
+gboolean mgr_dbus_reg_device_paths(uint16_t id);
+gboolean mgr_dbus_unreg_device_paths(uint16_t id);
void hcid_dbus_request_pin(int dev, struct hci_conn_info *ci);
void hcid_dbus_inquiry_start(bdaddr_t *local);
void hcid_dbus_inquiry_complete(bdaddr_t *local);
--- bluez-utils-cvs.orig/hcid/dbus.h 1969-12-31 21:00:00.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.h 2005-10-04 10:26:51.000000000 -0300
@@ -0,0 +1,169 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2000-2001 Qualcomm Incorporated
+ * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
+ * Copyright (C) 2002-2005 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
+ * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
+ * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
+ * SOFTWARE IS DISCLAIMED.
+ *
+ *
+ * $Id: dbus.h,v 0.1 2005/09/16 08:00:00 holtmann Exp $
+ */
+
+#ifndef __H_BLUEZ_DBUS_H__
+#define __H_BLUEZ_DBUS_H__
+
+#define __END_SIG__ DBUS_TYPE_INVALID_AS_STRING
+
+/* bluetoothd Bus name */
+#define BLUEZ_DBUS_NAME "org.bluez"
+#define DEFAULT_DEVICE_ID (0xFFFF)
+#define HCI_DEFAULT_DEVICE_NAME "default"
+#define HCI_DEVICE_NAME "hci"
+
+#define DEVICE_PATH "/org/bluez/Devices"
+#define DEVICE_INTERFACE BLUEZ_DBUS_NAME".Devices"
+
+#define MANAGER_PATH "/org/bluez/Manager"
+#define MANAGER_INTERFACE BLUEZ_DBUS_NAME".Manager"
+
+/*========================================================================
+ BlueZ D-Bus Device service definitions "/org/bluez/Device"
+ *========================================================================*/
+#define DEV_UP "Up"
+#define DEV_DOWN "Down"
+#define DEV_RESET "Reset"
+#define DEV_SET_PROPERTY "SetProperty"
+#define DEV_GET_PROPERTY "GetProperty"
+
+#define DEV_UP_SIGNATURE __END_SIG__
+#define DEV_DOWN_SIGNATURE __END_SIG__
+#define DEV_RESET_SIGNATURE __END_SIG__
+#define DEV_SET_PROPERTY_SIGNATURE __END_SIG__
+#define DEV_GET_PROPERTY_SIGNATURE __END_SIG__
+
+
+//TODO add the other hciconfig features
+
+/*========================================================================
+ BlueZ D-Bus Manager service definitions "/org/bluez/Manager"
+ *========================================================================*/
+
+ /* ===== Manager definitions, services under DEVICE_PATH ===== */
+#define MGR_GET_DEV "DeviceList"
+#define MGR_INIT "Init"
+
+/* Enable/Disable services controller, pan, serial, ... */
+#define MGR_ENABLE "Enable"
+#define MGR_DISABLE "Disable"
+
+//signatures
+#define MGR_GET_DEV_SIGNATURE __END_SIG__
+
+/* yya(ss)*/
+#define MGR_GET_DEV_REPLY_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_ARRAY_AS_STRING\
+ HCI_DEVICE_STRUCT_SIGNATURE\
+ __END_SIG__
+
+/* ===== HCI definitions ===== */
+#define BLUEZ_HCI "Controller"
+#define BLUEZ_HCI_PATH MANAGER_PATH"/"BLUEZ_HCI
+#define BLUEZ_HCI_INTERFACE MANAGER_INTERFACE"."BLUEZ_HCI
+
+//HCI signals
+#define BLUEZ_HCI_INQ_START "InquiryStart"
+#define BLUEZ_HCI_INQ_COMPLETE "InquiryComplete"
+#define BLUEZ_HCI_INQ_RESULT "InquiryResult"
+#define BLUEZ_HCI_REMOTE_NAME "RemoteName"
+
+//HCI Provided services
+#define HCI_PERIODIC_INQ "PeriodicInquiry"
+#define HCI_CANCEL_PERIODIC_INQ "CancelPeriodic"
+#define HCI_INQ "Inquiry"
+#define HCI_ROLE_SWITCH "RoleSwitch"
+
+
+#define HCI_PERIODIC_INQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ __END_SIG__
+
+#define HCI_CANCEL_PERIODIC_INQ_SIGNATURE __END_SIG__
+
+#define HCI_INQ_SIGNATURE DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ __END_SIG__
+
+#define HCI_ROLE_SWITCH_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_BYTE_AS_STRING\
+ __END_SIG__
+
+#define HCI_DEVICE_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING
+
+#define HCI_INQ_REPLY_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING\
+ DBUS_TYPE_STRING_AS_STRING\
+ DBUS_TYPE_UINT32_AS_STRING\
+ DBUS_TYPE_UINT16_AS_STRING\
+ DBUS_STRUCT_END_CHAR_AS_STRING\
+ __END_SIG__
+
+
+/* ===== Common Error messages of org.bluez. =====*/
+#define BLUEZ_DBUS_ERROR BLUEZ_DBUS_NAME".Error"
+
+
+/* BLUEZ_DBUS_ERROR
+ * EFailed error messages signature is : su
+ * Where the first argument is a string(error message description),
+ * the last is a uint32 that contains the error class(system, dbus or hci).
+ */
+
+/* Error code offsets */
+#define BLUEZ_EBT_OFFSET (0x00000000) /* see Bluetooth error code */
+#define BLUEZ_EBT_EXT_OFFSET (0x00000100)
+#define BLUEZ_EDBUS_OFFSET (0x00010000)
+#define BLUEZ_ESYSTEM_OFFSET (0x00020000)
+#define BLUEZ_EFUTURE_OFFSET (0x00040000)
+
+
+/* D-Bus error code, class BLUEZ_EDBUS_OFFSET */
+#define BLUEZ_EDBUS_UNKNOWN_METHOD (0x01 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_WRONG_SIGNATURE (0x02 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_WRONG_PARAM (0x03 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_RECORD_NOT_FOUND (0x04 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_NO_MEM (0x05 + BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_CONN_NOT_FOUND (0x06 + BLUEZ_EDBUS_OFFSET)
+
+/* D-Bus error code, class BLUEZ_ESYSTEM_OFFSET */
+#define BLUEZ_ESYSTEM_ENODEV (ENODEV + BLUEZ_ESYSTEM_OFFSET)
+
+
+/* BLUEZ_DBUS_ERR_NO_MEMORY */
+#define BLUEZ_DBUS_ERR_NO_MEMORY_STR "No memory"
+
+
+#endif /*__H_BLUEZ_DBUS_H__*/
--- bluez-utils-cvs.orig/hcid/dbus.c 2005-09-22 09:09:16.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/dbus.c 2005-10-04 08:57:27.000000000 -0300
@@ -33,9 +33,14 @@
#endif
#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/syslog.h>
+
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
@@ -45,22 +50,226 @@
#include "glib-ectomy.h"
#include "hcid.h"
+#include "dbus.h"
static DBusConnection *connection;
+static int8_t num_adapters = 0;
#define TIMEOUT (30 * 1000) /* 30 seconds */
+#define BLUETOOTH_DEVICE_NAME_LEN (18)
+#define BLUETOOTH_DEVICE_ADDR_LEN (18)
+#define MAX_PATH_LENGTH (64)
+
+#define PINAGENT_SERVICE_NAME "org.bluez.PinAgent"
+#define PINAGENT_INTERFACE PINAGENT_SERVICE_NAME
+#define PIN_REQUEST "PinRequest"
+#define PINAGENT_PATH "/org/bluez/PinAgent"
-#define SERVICE_NAME "org.bluez.PinAgent"
-#define INTERFACE_NAME SERVICE_NAME
-#define REQUEST_NAME "PinRequest"
-#define PATH_NAME "/org/bluez/PinAgent"
-
-#define WRONG_ARGS_ERROR "org.bluez.Error.WrongArgs"
struct pin_request {
int dev;
bdaddr_t bda;
};
+/*
+ * next action: move to a common header
+ */
+
+
+typedef DBusMessage* (service_handler_func_t)(DBusMessage *, void *);
+
+typedef struct
+{
+ const char *name;
+ service_handler_func_t *handler_func;
+ const char *signature;
+}service_table_t;
+
+typedef int8_t register_function_t(DBusConnection *conn, uint8_t dft_reg, uint16_t id);
+typedef int8_t unregister_function_t(DBusConnection *conn, uint8_t unreg_dft, uint16_t id);
+
+const service_table_t *get_hci_table(void);
+int8_t hci_dbus_reg_obj_path(DBusConnection *conn, uint8_t dft_reg, uint16_t id);
+int8_t hci_dbus_unreg_obj_path(DBusConnection *conn, uint8_t unreg_dft, uint16_t id);
+
+
+typedef const service_table_t* get_svc_table_func_t(void);
+typedef struct {
+ const char *name;
+ uint8_t status; /* 1:active 0:disabled */
+ uint8_t dft_reg; /* dft path registered */
+ register_function_t *reg_func;
+ unregister_function_t *unreg_func;
+ get_svc_table_func_t *get_svc_table; /* return the service table */
+}__attribute__((packed))profile_obj_path_data_t;
+
+/*
+ * next action: Move to /common directory
+ */
+
+static int find_conn(int s, int dev_id, long arg)
+{
+ struct hci_conn_list_req *cl;
+ struct hci_conn_info *ci;
+ int i;
+
+ if (!(cl = malloc(10 * sizeof(*ci) + sizeof(*cl)))) {
+ syslog(LOG_ERR, "Can't allocate memory");
+ return 0;
+ }
+ cl->dev_id = dev_id;
+ cl->conn_num = 10;
+ ci = cl->conn_info;
+
+ if (ioctl(s, HCIGETCONNLIST, (void *) cl)) {
+ syslog(LOG_ERR, "Can't get connection list");
+ return 0;
+ }
+
+ for (i = 0; i < cl->conn_num; i++, ci++)
+ if (!bacmp((bdaddr_t *) arg, &ci->bdaddr))
+ return 1;
+
+ return 0;
+}
+
+
+/*
+ * D-Bus error messages functions and declarations.
+ * This section should be moved to a common file
+ * in the future
+ *
+ */
+typedef struct {
+ uint32_t code;
+ const char *str;
+}bluez_error_t;
+
+static const bluez_error_t error_array[] = {
+ { BLUEZ_EDBUS_UNKNOWN_METHOD, "Method not found"},
+ { BLUEZ_EDBUS_WRONG_SIGNATURE, "Wrong method signature"},
+ { BLUEZ_EDBUS_WRONG_PARAM, "Invalid parameters"},
+ { BLUEZ_EDBUS_RECORD_NOT_FOUND, "No record found"},
+ { 0, NULL }
+};
+
+static const char *bluez_dbus_error_to_str(const uint32_t ecode)
+{
+ const bluez_error_t *ptr;
+ uint32_t raw_code = 0;
+
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ if (ecode & BLUEZ_ESYSTEM_OFFSET) {
+ /* System error */
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+ 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) {
+ /* D-Bus error */
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+ for (ptr = error_array; ptr->code; ptr++) {
+ if(ptr->code == ecode) {
+ syslog(LOG_INFO, "%s - msg:%s", __PRETTY_FUNCTION__, ptr->str);
+ return ptr->str;
+ }
+ }
+ }
+ return NULL;
+}
+
+DBusMessage *bluez_new_failure_msg(DBusMessage *msg, const uint32_t ecode)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const char *error_msg = NULL;
+
+ syslog (LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ error_msg = bluez_dbus_error_to_str(ecode);
+
+ if (error_msg) {
+
+ reply = dbus_message_new_error(msg, BLUEZ_DBUS_ERROR, error_msg);
+
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32 ,&ecode);
+ }
+
+ return reply;
+}
+
+/*
+ * Object path register/unregister functions
+ *
+ */
+static profile_obj_path_data_t obj_path_table[] = {
+ {BLUEZ_HCI, 1, 0, hci_dbus_reg_obj_path, hci_dbus_unreg_obj_path, get_hci_table },
+ /* add other profiles here */
+ {NULL, 0, 0, NULL, NULL, NULL}
+};
+
+/*
+ * Device Message handler functions object table declaration
+ */
+static DBusHandlerResult msg_func(DBusConnection *conn, DBusMessage *msg, void *data);
+
+static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data);
+static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data);
+
+static const DBusObjectPathVTable obj_vtable = {
+ NULL,
+ &msg_func,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+/*
+ * Service provided under the path DEVICE_PATH
+ * TODO add the handlers
+ */
+static const service_table_t dev_services[] = {
+ {DEV_UP, handle_not_implemented_req, DEV_UP_SIGNATURE},
+ {DEV_DOWN, handle_not_implemented_req, DEV_DOWN_SIGNATURE},
+ {DEV_RESET, handle_not_implemented_req, DEV_RESET_SIGNATURE },
+ {DEV_SET_PROPERTY, handle_not_implemented_req, DEV_SET_PROPERTY_SIGNATURE },
+ {DEV_GET_PROPERTY, handle_not_implemented_req, DEV_GET_PROPERTY_SIGNATURE },
+ {NULL, NULL, NULL}
+};
+
+/*
+ * Manager Message handler functions object table declaration
+ *
+ */
+static const service_table_t mgr_services[] = {
+ {MGR_GET_DEV, handle_get_devices_req, MGR_GET_DEV_SIGNATURE},
+ {MGR_INIT, handle_not_implemented_req, NULL },
+ {MGR_ENABLE, handle_not_implemented_req, NULL },
+ {MGR_DISABLE, handle_not_implemented_req, NULL },
+ {NULL, handle_not_implemented_req, NULL}
+};
+
+
+/*
+ * HCI Manager Message handler functions object table declaration
+ *
+ */
+static DBusHandlerResult hci_signal_filter (DBusConnection *conn, DBusMessage *msg, void *data);
+
+static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data);
+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 const service_table_t 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},
+ {NULL, NULL, NULL}
+};
static void reply_handler_function(DBusPendingCall *call, void *user_data)
{
@@ -126,8 +335,8 @@
uint8_t *addr = (uint8_t *) &ci->bdaddr;
dbus_bool_t out = ci->out;
- message = dbus_message_new_method_call(SERVICE_NAME, PATH_NAME,
- INTERFACE_NAME, REQUEST_NAME);
+ message = dbus_message_new_method_call(PINAGENT_SERVICE_NAME, PINAGENT_PATH,
+ PINAGENT_INTERFACE, PIN_REQUEST);
if (message == NULL) {
syslog(LOG_ERR, "Couldn't allocate D-BUS message");
goto failed;
@@ -165,13 +374,14 @@
void hcid_dbus_inquiry_start(bdaddr_t *local)
{
DBusMessage *message;
- char *local_addr;
+ char *local_addr;
bdaddr_t tmp;
baswap(&tmp, local); local_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryStart");
+ message = dbus_message_new_signal(BLUEZ_HCI_PATH,
+ BLUEZ_HCI_INTERFACE,
+ BLUEZ_HCI_INQ_START);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry start message");
goto failed;
@@ -204,8 +414,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryComplete");
+ message = dbus_message_new_signal(BLUEZ_HCI_PATH,
+ BLUEZ_HCI_INTERFACE,
+ BLUEZ_HCI_INQ_COMPLETE);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry complete message");
goto failed;
@@ -241,8 +452,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
baswap(&tmp, peer); peer_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "InquiryResult");
+ message = dbus_message_new_signal(BLUEZ_HCI_PATH,
+ BLUEZ_HCI_INTERFACE,
+ BLUEZ_HCI_INQ_RESULT);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS inquiry result message");
goto failed;
@@ -280,8 +492,9 @@
baswap(&tmp, local); local_addr = batostr(&tmp);
baswap(&tmp, peer); peer_addr = batostr(&tmp);
- message = dbus_message_new_signal("/org/bluez/DevAgent",
- "org.bluez.DevAgent", "RemoteName");
+ message = dbus_message_new_signal(BLUEZ_HCI_PATH,
+ BLUEZ_HCI_INTERFACE,
+ BLUEZ_HCI_REMOTE_NAME);
if (message == NULL) {
syslog(LOG_ERR, "Can't allocate D-BUS remote name message");
goto failed;
@@ -388,6 +601,8 @@
{
DBusError error;
+ num_adapters = 0;
+
dbus_error_init(&error);
connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
@@ -398,8 +613,774 @@
return FALSE;
}
+ dbus_bus_request_name(connection, BLUEZ_DBUS_NAME,
+ DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ syslog(LOG_ERR,"D-Bus Error: %s\n", error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ //Registering the device path
+ if (!dbus_connection_register_object_path(connection, DEVICE_PATH, &obj_vtable, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", DEVICE_PATH);
+ return FALSE;
+ } else {
+ syslog(LOG_INFO,"registering - path:%s", DEVICE_PATH);
+ }
+
+ //Registering the manager path
+ if (!dbus_connection_register_object_path(connection, MANAGER_PATH, &obj_vtable, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", MANAGER_PATH);
+ return FALSE;
+ } else {
+ syslog(LOG_INFO,"registering - path:%s", MANAGER_PATH);
+ }
+
+
+ if (!dbus_connection_add_filter (connection, hci_signal_filter, NULL, NULL)) {
+ syslog(LOG_ERR,"DBUS failed to add filter");
+ return FALSE;
+ }
+
dbus_connection_set_watch_functions(connection,
add_watch, remove_watch, watch_toggled, NULL, NULL);
return TRUE;
}
+
+/*
+ * @brief This function is responsible for register all service for
+ * each new hci device
+ * Detailed description: When a HCI_DEV_UP event is received or the
+ * daemon is initialized the service paths must be registered. eg:
+ * pan, sdp, hci, rfcomm paths.
+ * @param id device id
+ * @return TRUE/FALSE
+ */
+gboolean mgr_dbus_reg_device_paths(uint16_t id)
+{
+ profile_obj_path_data_t *ptr = obj_path_table;
+ int8_t ret = 0;
+
+ if (connection) {
+ for (;ptr->name; ptr++) {
+ ret = (ptr->reg_func(connection, ptr->dft_reg, id));
+ if (ret < 0) {
+ break;
+ }
+ /* the default path is now registered */
+ ptr->dft_reg = 1;
+ }
+
+ if (!ret) {
+ num_adapters++;
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * @brief This function is responsible for unregister all service for
+ * a detached hci device
+ * Detailed description: When a HCI_DEV_DOWN event is received the
+ * service paths must be unregistered. eg: pan, sdp, hci, rfcomm paths.
+ * @param id device id
+ * @return TRUE/FALSE
+ */
+gboolean mgr_dbus_unreg_device_paths(uint16_t id)
+{
+ profile_obj_path_data_t *ptr = obj_path_table;
+ uint8_t dft_unreg = 0;
+
+ if (connection) {
+ for (;ptr->name; ptr++) {
+ dft_unreg = (num_adapters > 1)? 0:1;
+ num_adapters--;
+ ptr->unreg_func(connection, dft_unreg, id);
+
+ if (dft_unreg ) {
+ ptr->dft_reg = 0;
+ }
+ }
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/*
+ * @brief HCI object path register function
+ * Detailed description: function responsible for register a new hci
+ * D-Bus path. If necessary the default path must be registered too.
+ * @param conn D-Bus connection
+ * @param dft_reg register the default path(0 or !0)
+ * @param id hci device identification
+ * @return (0-Success/-1 failure)
+ */
+int8_t hci_dbus_reg_obj_path(DBusConnection *conn, uint8_t dft_reg, uint16_t id)
+{
+ char path[MAX_PATH_LENGTH];
+ int8_t ret = 0;
+ uint16_t *ptr_id = (int16_t*)malloc(1);
+ uint16_t *ptr_id_dft;
+
+ /* register the default path*/
+ if (!dft_reg) {
+ ptr_id_dft = (int16_t*)malloc(1);
+ *ptr_id_dft = DEFAULT_DEVICE_ID;
+ sprintf(path, "%s/%s/%s", MANAGER_PATH, HCI_DEFAULT_DEVICE_NAME, BLUEZ_HCI);
+
+ syslog(LOG_INFO, "registering dft path:%s - id:%d", path, DEFAULT_DEVICE_ID);
+
+ if (!dbus_connection_register_fallback(conn, path, &obj_vtable, ptr_id_dft)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", path);
+ //ignore, the default path was already registered
+ }
+
+ }
+
+ *ptr_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_fallback(conn, path, &obj_vtable, ptr_id)) {
+ syslog(LOG_ERR,"DBUS failed to register %s object", path);
+ return (-1);
+ }
+
+ return ret;
+}
+
+/*
+ * @brief HCI object path unregister function
+ * Detailed description: function responsible for unregister HCI D-Bus
+ * path for a detached hci device. If necessary the default path must
+ * be registered too.
+ * @param conn D-Bus connection
+ * @param unreg_dft register the default path(0 or !0)
+ * @param id hci device identification
+ * @return (0-Success/-1 failure)
+ */
+int8_t hci_dbus_unreg_obj_path(DBusConnection *conn, uint8_t unreg_dft, uint16_t id)
+{
+ int8_t ret = 0;
+ char path[MAX_PATH_LENGTH];
+ char dft_path[MAX_PATH_LENGTH];
+ uint16_t *data;
+
+ if (unreg_dft) {
+ sprintf(dft_path, "%s/%s/%s", MANAGER_PATH, HCI_DEFAULT_DEVICE_NAME, BLUEZ_HCI);
+ syslog(LOG_INFO, "%s - unregistering dft:%s", __PRETTY_FUNCTION__, dft_path);
+ 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, (void*)&data))
+ {
+ if(data)
+ free(data);
+ data = NULL;
+ }
+ }
+
+ }
+
+ sprintf(path, "%s/%s%d/%s", MANAGER_PATH, HCI_DEVICE_NAME, id, BLUEZ_HCI);
+ syslog(LOG_INFO, "%s - unregistering spec:%s", __PRETTY_FUNCTION__, path);
+ 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, (void*)&data))
+ {
+ if(data)
+ free(data);
+ data = NULL;
+ }
+ }
+
+ return ret;
+}
+
+
+const service_table_t *get_hci_table(void) {
+ return hci_services;
+}
+/*****************************************************************
+ *
+ * Section reserved to HCI Manaher D-Bus message handlers
+ *
+ *****************************************************************/
+void hcid_dbus_exit(void)
+{
+ char path[MAX_PATH_LENGTH];
+ char fst_parent[] = MANAGER_PATH;
+ char snd_parent[MAX_PATH_LENGTH];
+ char **fst_level = NULL;
+ char **snd_level = NULL;
+ char *ptr1;
+ char *ptr2;
+
+ if (!connection)
+ return;
+ /* unregister all objects paths */
+
+ if (!dbus_connection_unregister_object_path (connection, DEVICE_PATH)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", DEVICE_PATH);
+ } else {
+ syslog(LOG_INFO,"unregistering - path:%s", DEVICE_PATH);
+ }
+
+ if (!dbus_connection_unregister_object_path (connection, MANAGER_PATH)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", MANAGER_PATH);
+ } else {
+ syslog(LOG_INFO,"unregistering - path:%s", MANAGER_PATH);
+ }
+
+ //getting the first level
+ dbus_connection_list_registered(connection, fst_parent, &fst_level);
+
+ for ( ;*fst_level; fst_level++) {
+ ptr1 = *fst_level;
+ sprintf(snd_parent, "%s/%s", fst_parent, ptr1);
+
+ //getting the second level
+ dbus_connection_list_registered(connection, snd_parent, &snd_level);
+
+ if (!(*snd_level)) {
+ //no child
+ sprintf(path, "%s/%s", MANAGER_PATH, ptr1);
+
+ syslog(LOG_INFO, "unregistering path: %s", path);
+
+ if (!dbus_connection_unregister_object_path (connection, path)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", path);
+ }
+ continue;
+ }
+
+ for ( ;*snd_level; snd_level++) {
+ //unregistering child level path
+ ptr2 = *snd_level;
+ sprintf(path, "%s/%s/%s", MANAGER_PATH, ptr1, ptr2);
+
+ syslog(LOG_INFO, "unregistering path: %s", path);
+
+ if (!dbus_connection_unregister_object_path (connection, path)) {
+ syslog(LOG_ERR,"DBUS failed to unregister %s object", path);
+ }
+ }
+ if (*snd_level)
+ dbus_free_string_array(snd_level);
+ }
+
+ if (*fst_level)
+ dbus_free_string_array(fst_level);
+}
+
+static DBusHandlerResult hci_signal_filter (DBusConnection *conn, DBusMessage *msg, void *data)
+{
+ DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ const char *iface;
+ const char *method;
+
+ if (!msg || !conn)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (dbus_message_get_type (msg) != DBUS_MESSAGE_TYPE_SIGNAL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member(msg);
+
+ if (strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) {
+ if (strcmp(method, "Disconnected") == 0){
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ } else if (strcmp(iface, DBUS_INTERFACE_DBUS) == 0) {
+ if (strcmp(method, "NameOwnerChanged") == 0) {
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ if (strcmp(method, "NameAcquired") == 0) {
+ ret = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ }
+ return ret;
+}
+/*
+ * There is only one message handler function for all object paths
+ *
+ */
+
+static DBusHandlerResult msg_func(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ const service_table_t *ptr_handlers = NULL;
+ DBusMessage *reply = NULL;
+ uint16_t type;
+ const char *iface;
+ const char *method;
+ const char *signature;
+ const char *path;
+ const char *rel_path;
+ const char *tmp_iface = NULL;
+ uint32_t result = BLUEZ_EDBUS_UNKNOWN_METHOD;
+ DBusHandlerResult ret = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;;
+ uint8_t found = 0;
+
+
+ path = dbus_message_get_path(msg);
+ type = dbus_message_get_type(msg);
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member (msg);
+ signature = dbus_message_get_signature(msg);
+
+ syslog (LOG_INFO, "%s - path:%s", __PRETTY_FUNCTION__, path);
+
+ //get the user data
+ if (strcmp(path, DEVICE_PATH) == 0) {
+ ptr_handlers = dev_services;
+ tmp_iface = DEVICE_INTERFACE;
+ found = 1;
+ } else if (strcmp(path, MANAGER_PATH) == 0) {
+ ptr_handlers = mgr_services;
+ tmp_iface = MANAGER_INTERFACE;
+ found = 1;
+ } else {
+ /* only msg to registered object paths will be received */
+
+ profile_obj_path_data_t *mgr_child = obj_path_table;
+ rel_path = strrchr(path,'/');
+ rel_path++;
+
+ if (rel_path) {
+ for (;mgr_child->name; mgr_child++) {
+ if(strcmp(mgr_child->name, rel_path) == 0) {
+ ptr_handlers = mgr_child->get_svc_table();
+ found = 1;
+ }
+ }
+
+ tmp_iface = MANAGER_INTERFACE;
+ }
+ }
+
+ if (found && (type == DBUS_MESSAGE_TYPE_METHOD_CALL) &&
+ (strcmp(iface, tmp_iface) == 0) && (method != NULL)) {
+
+ for (; ptr_handlers->name; ptr_handlers++) {
+ if (strcmp(method, ptr_handlers->name) == 0) {
+ /* resetting unknown method. It's possible handle method overload */
+ result = BLUEZ_EDBUS_WRONG_SIGNATURE;
+ if (strcmp(ptr_handlers->signature, signature) == 0) {
+ if(ptr_handlers->handler_func) {
+ reply = (ptr_handlers->handler_func)(msg, data);
+ result = 0; /* resetting wrong signature*/
+ } else {
+ syslog(LOG_INFO, "Service not implemented");
+ }
+ break;
+ }
+
+ }
+ }
+
+ if (result) {
+ reply = bluez_new_failure_msg(msg, result);
+ syslog(LOG_INFO, "%s - %s", __PRETTY_FUNCTION__,
+ (result == BLUEZ_EDBUS_UNKNOWN_METHOD?"Unknown Method": "Wrong signature"));
+ }
+
+ /* 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;
+ } else {
+ syslog(LOG_INFO, "Request not handled");
+ }
+ return ret;
+}
+
+
+static DBusMessage* handle_periodic_inq_req(DBusMessage *msg, void *data)
+{
+ write_inquiry_mode_cp inq_mode;
+ periodic_inquiry_cp inq_param;
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ uint8_t length;
+ uint8_t max_period;
+ uint8_t min_period;
+ int32_t sock = -1;
+ int32_t dev_id = -1;
+
+ if (*udata == DEFAULT_DEVICE_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 cleanup;
+
+ }
+ } else {
+ dev_id = *udata;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ if ((sock = hci_open_dev(dev_id)) < 0) {
+ syslog(LOG_ERR, "HCI device open failed");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &length);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &min_period);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &max_period);
+
+ if ((length >= min_period) || (min_period >= max_period)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+ goto cleanup;
+ }
+
+ inq_param.num_rsp = 100;
+ inq_param.length = length;
+
+ inq_param.max_period = max_period;
+ inq_param.min_period = min_period;
+
+ /* General/Unlimited Inquiry Access Code (GIAC) */
+ inq_param.lap[0] = 0x33;
+ inq_param.lap[1] = 0x8b;
+ inq_param.lap[2] = 0x9e;
+
+ inq_mode.mode = 1; //INQUIRY_WITH_RSSI;
+
+ if (hci_send_cmd(sock, OGF_HOST_CTL, OCF_WRITE_INQUIRY_MODE,
+ WRITE_INQUIRY_MODE_CP_SIZE, &inq_mode) < 0) {
+ syslog(LOG_ERR, "Can't set inquiry mode:%s.", strerror(errno));
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ }
+
+ if (hci_send_cmd(sock, OGF_LINK_CTL, OCF_PERIODIC_INQUIRY,
+ PERIODIC_INQUIRY_CP_SIZE, &inq_param) < 0) {
+ syslog(LOG_ERR, "Can't send HCI commands:%s.", strerror(errno));
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ } else {
+
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE ,&result);
+ }
+
+cleanup:
+
+ if (sock > 0)
+ close(sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_cancel_periodic_inq_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ int32_t sock = -1;
+ int32_t dev_id = -1;
+
+ if (*udata == DEFAULT_DEVICE_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 cleanup;
+
+ }
+ } else {
+ dev_id = *udata;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ if ((sock = hci_open_dev(dev_id)) < 0) {
+ syslog(LOG_ERR, "HCI device open failed");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ if (hci_send_cmd(sock, OGF_LINK_CTL, OCF_EXIT_PERIODIC_INQUIRY, 0 , NULL) < 0) {
+ syslog(LOG_ERR, "Send hci command failed.");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ } else {
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE ,&result);
+ }
+
+cleanup:
+ if (sock > 0)
+ close(sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_inq_req(DBusMessage *msg, void *data)
+{
+ char addr[18];
+ const char array_sig[] = HCI_INQ_REPLY_SIGNATURE;
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ DBusMessage *reply = NULL;
+ inquiry_info *info = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ const char *paddr = addr;
+ int32_t dev_id = -1;
+ uint32_t class = 0;
+ uint16_t clock_offset;
+ uint16_t flags;
+ int8_t length;
+ int8_t num_rsp;
+ int8_t i;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ if (*udata == DEFAULT_DEVICE_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 cleanup;
+ }
+ } else {
+ dev_id = (int32_t)*udata;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &length);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &num_rsp);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &flags);
+
+ if ((length <= 0) || (num_rsp <= 0)) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+ goto cleanup;
+ }
+
+ num_rsp = hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);
+
+ if (num_rsp < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ } else {
+ 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 < num_rsp; i++) {
+ ba2str(&(info+i)->bdaddr, addr);
+
+ clock_offset = btohs((info+i)->clock_offset);
+ /* only 3 bytes are used */
+ memcpy(&class, (info+i)->dev_class, 3);
+
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING , &paddr);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT32 , &class);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_UINT16 , &clock_offset);
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+ dbus_message_iter_close_container(&iter, &array_iter);
+ }
+
+cleanup:
+ if(info)
+ bt_free(info);
+
+ return NULL;
+}
+
+static DBusMessage* handle_role_switch_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessage *reply = NULL;
+ char *str_bdaddr = NULL;
+ const uint16_t *udata = (uint16_t *)data;
+ bdaddr_t bdaddr;
+ uint8_t role;
+ int32_t dev_id = -1, sock = -1;
+
+ dbus_message_iter_init(msg, &iter);
+ dbus_message_iter_get_basic(&iter, &str_bdaddr);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &role);
+
+ str2ba(str_bdaddr, &bdaddr);
+
+ dev_id = hci_for_each_dev(HCI_UP, find_conn, (long) &bdaddr);
+
+
+ if (dev_id < 0) {
+ syslog(LOG_ERR, "Bluetooth device failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ if (*udata != DEFAULT_DEVICE_ID && *udata != dev_id) {
+ syslog(LOG_ERR, "Connection not found\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_CONN_NOT_FOUND);
+ goto cleanup;
+ }
+
+ syslog(LOG_INFO, "%s - line:%d - dev_id:%d", __PRETTY_FUNCTION__, __LINE__, dev_id);
+
+ sock = hci_open_dev(dev_id);
+
+ if (sock < 0) {
+ syslog(LOG_ERR, "HCI device open failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
+ goto cleanup;
+ }
+
+ if (hci_switch_role(sock, &bdaddr, role, 10000) < 0) {
+ syslog(LOG_ERR, "Switch role request failed\n");
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ } else {
+ uint8_t result = 0;
+ /* return TRUE to indicate that operation was completed */
+ reply = dbus_message_new_method_return(msg);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_BYTE, &result);
+ }
+cleanup:
+
+ return reply;
+}
+
+
+/*****************************************************************
+ *
+ * Section reserved to Device D-Bus message handlers
+ *
+ *****************************************************************/
+static DBusMessage* handle_get_devices_req(DBusMessage *msg, void *data)
+{
+ DBusMessageIter iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter struct_iter;
+ DBusMessage *reply = NULL;
+
+ struct hci_dev_list_req *dl = NULL;
+ struct hci_dev_req *dr = NULL;
+ struct hci_dev_info di;
+ int16_t i;
+ int32_t sock = -1;
+
+ char aname[BLUETOOTH_DEVICE_NAME_LEN];
+ char aaddr[BLUETOOTH_DEVICE_ADDR_LEN];
+ char *paddr = aaddr;
+ char *pname = aname;
+ const char array_sig[] = HCI_DEVICE_STRUCT_SIGNATURE;
+
+ syslog(LOG_INFO, "%s - line:%d", __PRETTY_FUNCTION__, __LINE__);
+
+ /* Create and bind HCI socket */
+ if ((sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
+ syslog(LOG_ERR, "Can't open HCI socket: %s (%d)",
+ strerror(errno), errno);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ }
+
+
+ dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
+
+ if (!dl) {
+ syslog(LOG_ERR, "Can't allocate memory");
+ reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
+ goto cleanup;
+ }
+
+ dl->dev_num = HCI_MAX_DEV;
+ dr = dl->dev_req;
+
+ if (ioctl(sock, HCIGETDEVLIST, (void *) dl) < 0) {
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ goto cleanup;
+ }
+
+
+ /* active bluetooth adapter found */
+ 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);
+ dr = dl->dev_req;
+
+ for (i = 0; i < dl->dev_num; i++, dr++) {
+ if (hci_test_bit(HCI_UP, &dr->dev_opt)) {
+ memset(&di, 0 , sizeof(struct hci_dev_info));
+ di.dev_id = dr->dev_id;
+
+ if (!ioctl(sock, HCIGETDEVINFO, (void *) &di)) {
+ strcpy(aname, di.name);
+ ba2str(&di.bdaddr, aaddr);
+ dbus_message_iter_open_container(&array_iter, DBUS_TYPE_STRUCT, NULL,
+ &struct_iter);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&pname);
+ dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING ,&paddr);
+ syslog(LOG_INFO, "%s - (%s, %s)", __PRETTY_FUNCTION__, pname, paddr);
+
+ dbus_message_iter_close_container(&array_iter, &struct_iter);
+ }
+ }
+ }
+ dbus_message_iter_close_container(&iter, &array_iter);
+
+cleanup:
+ if (dl)
+ free(dl);
+
+ if (sock > 0)
+ close (sock);
+
+ return reply;
+}
+
+static DBusMessage* handle_not_implemented_req(DBusMessage *msg, void *data) {
+ const char *path;
+ const char *iface;
+ const char *method;
+
+ path = dbus_message_get_path(msg);
+ iface = dbus_message_get_interface(msg);
+ method = dbus_message_get_member(msg);
+
+ syslog(LOG_INFO, "Not Implemented - path:%s, iface:%s method:%s", path, iface, method);
+
+ return NULL;
+
+}
--- bluez-utils-cvs.orig/hcid/main.c 2005-07-05 18:15:44.000000000 -0300
+++ bluez-utils-cvs-hcid/hcid/main.c 2005-10-03 10:58:28.000000000 -0300
@@ -375,6 +375,9 @@
if (hcid.security && hci_test_bit(HCI_UP, &dr->dev_opt))
start_security_manager(dr->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_reg_device_paths(dr->dev_id);
+#endif
}
free(dl);
@@ -438,12 +441,18 @@
configure_device(sd->dev_id);
if (hcid.security)
start_security_manager(sd->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_reg_device_paths(sd->dev_id);
+#endif
break;
case HCI_DEV_DOWN:
syslog(LOG_INFO, "HCI dev %d down", sd->dev_id);
if (hcid.security)
stop_security_manager(sd->dev_id);
+#ifdef ENABLE_DBUS
+ mgr_dbus_unreg_device_paths(sd->dev_id);
+#endif
break;
}
}
@@ -627,7 +636,9 @@
g_main_run(event_loop);
free_device_opts();
-
+#ifdef ENABLE_DBUS
+ hcid_dbus_exit();
+#endif
syslog(LOG_INFO, "Exit.");
return 0;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-10-04 13:31 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-30 18:22 [Bluez-devel] hcid patch Claudio Takahasi
2005-10-01 9:49 ` Marcel Holtmann
2005-10-03 14:08 ` Claudio Takahasi
2005-10-03 21:02 ` Marcel Holtmann
2005-10-04 12:33 ` Claudio Takahasi
2005-10-04 12:47 ` Claudio Takahasi
2005-10-04 13:11 ` Johan Hedberg
2005-10-04 13:31 ` Claudio Takahasi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.