diff options
-rw-r--r-- | hcid/Makefile.am | 10 | ||||
-rw-r--r-- | hcid/dbus-adapter.c | 34 | ||||
-rw-r--r-- | hcid/dbus-adapter.h | 115 | ||||
-rw-r--r-- | hcid/dbus-common.c | 31 | ||||
-rw-r--r-- | hcid/dbus-common.h | 72 | ||||
-rw-r--r-- | hcid/dbus-error.c | 2 | ||||
-rw-r--r-- | hcid/dbus-error.h | 64 | ||||
-rw-r--r-- | hcid/dbus-manager.c | 7 | ||||
-rw-r--r-- | hcid/dbus-manager.h | 31 | ||||
-rw-r--r-- | hcid/dbus-rfcomm.c | 4 | ||||
-rw-r--r-- | hcid/dbus-rfcomm.h | 31 | ||||
-rw-r--r-- | hcid/dbus-sdp.c | 3 | ||||
-rw-r--r-- | hcid/dbus-sdp.h | 52 | ||||
-rw-r--r-- | hcid/dbus-security.c | 4 | ||||
-rw-r--r-- | hcid/dbus-security.h | 74 | ||||
-rw-r--r-- | hcid/dbus-service.c | 5 | ||||
-rw-r--r-- | hcid/dbus-service.h | 41 | ||||
-rw-r--r-- | hcid/dbus-test.c | 3 | ||||
-rw-r--r-- | hcid/dbus-test.h | 33 | ||||
-rw-r--r-- | hcid/dbus.c | 84 | ||||
-rw-r--r-- | hcid/dbus.h | 255 |
21 files changed, 624 insertions, 331 deletions
diff --git a/hcid/Makefile.am b/hcid/Makefile.am index c1ac1c4d..498e0589 100644 --- a/hcid/Makefile.am +++ b/hcid/Makefile.am @@ -20,10 +20,12 @@ noinst_PROGRAMS = passkey-agent service-agent auth-agent hcid_SOURCES = main.c security.c device.c storage.c \ sdp.c sdp.h hcid.h parser.h parser.y \ lexer.l kword.c kword.h \ - dbus.h dbus.c dbus-common.c \ - dbus-error.c dbus-manager.c dbus-adapter.c \ - dbus-device.c dbus-service.c dbus-security.c \ - dbus-test.c dbus-sdp.c dbus-rfcomm.c + dbus.h dbus.c dbus-common.c dbus-common.h \ + dbus-error.c dbus-error.h dbus-manager.c dbus-manager.h \ + dbus-adapter.c dbus-adapter.h \ + dbus-device.c dbus-device.h dbus-service.c dbus-service.h \ + dbus-security.c dbus-security.h dbus-test.c dbus-test.h \ + dbus-sdp.c dbus-sdp.h dbus-rfcomm.c dbus-rfcomm.h hcid_LDADD = @DBUS_LIBS@ @BLUEZ_LIBS@ $(top_builddir)/common/libhelper.a diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index ec27559e..8fecc265 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -42,10 +42,15 @@ #include "hcid.h" #include "dbus.h" +#include "dbus-adapter.h" #include "textfile.h" #include "oui.h" #include "list.h" +#include "dbus-common.h" +#include "dbus-sdp.h" +#include "dbus-error.h" +#include "dbus-adapter.h" static const char *service_cls[] = { "positioning", @@ -2773,33 +2778,14 @@ static struct service_data dev_services[] = { { NULL, NULL } }; -DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void *data) +DBusHandlerResult handle_adapter_method(DBusConnection *conn, DBusMessage *msg, void *data) { - const char *iface, *name; + service_handler_func_t handler; - iface = dbus_message_get_interface(msg); - name = dbus_message_get_member(msg); + handler = find_service_handler(dev_services, msg); - if (!strcmp(DBUS_INTERFACE_INTROSPECTABLE, iface) && - !strcmp("Introspect", name)) { - return simple_introspect(conn, msg, data); - } else if (!strcmp(ADAPTER_INTERFACE, iface)) { - service_handler_func_t handler; - - handler = find_service_handler(dev_services, msg); - - if (handler) - return handler(conn, msg, data); - else - return error_unknown_method(conn, msg); - } else if (!strcmp(SECURITY_INTERFACE, iface)) - return handle_security_method(conn, msg, data); - else if (!strcmp(TEST_INTERFACE, iface)) - return handle_test_method(conn, msg, data); - else if (!strcmp(RFCOMM_INTERFACE, iface)) - return handle_rfcomm_method(conn, msg, data); - else if (!strcmp(SDP_INTERFACE, iface)) - return handle_sdp_method(conn, msg, data); + if (handler) + return handler(conn, msg, data); else return error_unknown_method(conn, msg); } diff --git a/hcid/dbus-adapter.h b/hcid/dbus-adapter.h new file mode 100644 index 00000000..3c21c179 --- /dev/null +++ b/hcid/dbus-adapter.h @@ -0,0 +1,115 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2006 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 as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __ADAPTER_H +#define __ADAPTER_H + +#include <dbus/dbus.h> +#include "list.h" +#include "glib-ectomy.h" + +#define ADAPTER_INTERFACE "org.bluez.Adapter" + +#define INVALID_DEV_ID 0xFFFF + +#define BONDING_TIMEOUT 45000 /* 45 sec */ + +/* Discover types */ +#define DISCOVER_TYPE_NONE 0x00 +#define STD_INQUIRY 0x01 +#define PERIODIC_INQUIRY 0x02 + +/* Actions executed after inquiry complete */ +#define RESOLVE_NAME 0x10 + +typedef enum { + NAME_ANY, + NAME_NOT_REQUIRED, /* used by get remote name without name resolving */ + NAME_REQUIRED, /* remote name needs be resolved */ + NAME_REQUESTED, /* HCI remote name request was sent */ + NAME_SENT /* D-Bus signal RemoteNameUpdated sent */ +} name_status_t; + +struct remote_dev_info { + bdaddr_t bdaddr; + int8_t rssi; + name_status_t name_status; +}; + +struct bonding_request_info { + bdaddr_t bdaddr; + DBusConnection *conn; + DBusMessage *rq; + GIOChannel *io; + guint io_id; + int hci_status; + int cancel; + int auth_active; +}; + +struct pending_pin_info { + bdaddr_t bdaddr; + int replied; /* If we've already replied to the request */ +}; + +struct active_conn_info { + bdaddr_t bdaddr; + uint16_t handle; +}; + +struct adapter { + uint16_t dev_id; + int up; + char address[18]; /* adapter Bluetooth Address */ + guint timeout_id; /* discoverable timeout id */ + uint32_t discov_timeout; /* discoverable time(msec) */ + uint8_t mode; /* scan mode */ + int discov_active; /* standard discovery active: includes name resolution step */ + int pdiscov_active; /* periodic discovery active */ + int pinq_idle; /* tracks the idle time for periodic inquiry */ + int discov_type; /* type requested */ + int pdiscov_resolve_names; /* Resolve names when doing periodic discovery */ + struct slist *found_devices; + struct slist *oor_devices; /* out of range device list */ + char *pdiscov_requestor; /* periodic discovery requestor unique name */ + char *discov_requestor; /* discovery requestor unique name */ + DBusMessage *discovery_cancel; /* discovery cancel message request */ + struct slist *passkey_agents; + struct slist *auth_agents; /* Authorization agents */ + bdaddr_t agents_disabled; /* temporarely disable agents for bda */ + struct slist *active_conn; + struct bonding_request_info *bonding; + struct slist *pin_reqs; +}; + +DBusHandlerResult handle_adapter_method(DBusConnection *conn, DBusMessage *msg, void *data); + +const char *major_class_str(uint32_t class); + +const char *minor_class_str(uint32_t class); + +struct slist *service_classes_str(uint32_t class); + +int pending_remote_name_cancel(struct adapter *adapter); + +#endif /* __ADAPTER_H */ diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c index 74e2d3ae..0c8d0339 100644 --- a/hcid/dbus-common.c +++ b/hcid/dbus-common.c @@ -48,6 +48,13 @@ #include "hcid.h" #include "list.h" #include "dbus.h" +#include "dbus-error.h" +#include "dbus-adapter.h" +#include "dbus-security.h" +#include "dbus-test.h" +#include "dbus-rfcomm.h" +#include "dbus-sdp.h" +#include "dbus-common.h" static int name_listener_initialized = 0; @@ -470,3 +477,27 @@ int check_address(const char *addr) return 0; } +DBusHandlerResult handle_method_call(DBusConnection *conn, DBusMessage *msg, void *data) +{ + const char *iface, *name; + + iface = dbus_message_get_interface(msg); + name = dbus_message_get_member(msg); + + if (!strcmp(DBUS_INTERFACE_INTROSPECTABLE, iface) && + !strcmp("Introspect", name)) + return simple_introspect(conn, msg, data); + else if (!strcmp(ADAPTER_INTERFACE, iface)) + return handle_adapter_method(conn, msg, data); + else if (!strcmp(SECURITY_INTERFACE, iface)) + return handle_security_method(conn, msg, data); + else if (!strcmp(TEST_INTERFACE, iface)) + return handle_test_method(conn, msg, data); + else if (!strcmp(RFCOMM_INTERFACE, iface)) + return handle_rfcomm_method(conn, msg, data); + else if (!strcmp(SDP_INTERFACE, iface)) + return handle_sdp_method(conn, msg, data); + else + return error_unknown_method(conn, msg); +} + diff --git a/hcid/dbus-common.h b/hcid/dbus-common.h new file mode 100644 index 00000000..6bfbe33b --- /dev/null +++ b/hcid/dbus-common.h @@ -0,0 +1,72 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2006 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 as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __BLUEZ_DBUS_COMMON_H +#define __BLUEZ_DBUS_COMMON_H + +#include <bluetooth/bluetooth.h> +#include <bluetooth/sdp.h> + +#define BASE_PATH "/org/bluez" + +#define MAX_PATH_LENGTH 64 + +typedef DBusHandlerResult (*service_handler_func_t) (DBusConnection *conn, + DBusMessage *msg, + void *user_data); + +struct service_data { + const char *name; + service_handler_func_t handler_func; +}; + +typedef void (*name_cb_t)(const char *name, void *user_data); + +int name_listener_add(DBusConnection *connection, const char *name, + name_cb_t func, void *user_data); +int name_listener_remove(DBusConnection *connection, const char *name, + name_cb_t func, void *user_data); + +DBusHandlerResult simple_introspect(DBusConnection *conn, DBusMessage *msg, void *data); + +service_handler_func_t find_service_handler(struct service_data *services, DBusMessage *msg); + +int str2uuid(uuid_t *uuid, const char *string); + +int l2raw_connect(const char *local, const bdaddr_t *remote); + +int check_address(const char *addr); + +static inline DBusHandlerResult send_message_and_unref(DBusConnection *conn, DBusMessage *msg) +{ + if (msg) { + dbus_connection_send(conn, msg, NULL); + dbus_message_unref(msg); + } + + return DBUS_HANDLER_RESULT_HANDLED; +} + +DBusHandlerResult handle_method_call(DBusConnection *conn, DBusMessage *msg, void *data); + +#endif /* __BLUEZ_DBUS_COMMON_H */ diff --git a/hcid/dbus-error.c b/hcid/dbus-error.c index 4a169c5c..b6cc86d0 100644 --- a/hcid/dbus-error.c +++ b/hcid/dbus-error.c @@ -32,6 +32,8 @@ #include "hcid.h" #include "dbus.h" +#include "dbus-common.h" +#include "dbus-error.h" DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, int err) { diff --git a/hcid/dbus-error.h b/hcid/dbus-error.h new file mode 100644 index 00000000..2ce50d68 --- /dev/null +++ b/hcid/dbus-error.h @@ -0,0 +1,64 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2006 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 as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __BLUEZ_DBUS_ERROR_H +#define __BLUEZ_DBUS_ERROR_H + +#define ERROR_INTERFACE "org.bluez.Error" + +DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, int err); +DBusHandlerResult error_not_ready(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_not_authorized(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_no_such_adapter(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_not_supported(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_request_deferred(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_not_connected(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_not_in_progress(DBusConnection *conn, DBusMessage *msg, const char *str); +DBusHandlerResult error_unsupported_major_class(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, DBusMessage *msg, int err); +DBusHandlerResult error_bonding_already_exists(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_bonding_does_not_exist(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_bonding_in_progress(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_bonding_not_in_progress(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_authentication_canceled(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_discover_in_progress(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_connect_in_progress(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_connect_not_in_progress(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_record_does_not_exist(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_passkey_agent_already_exists(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_passkey_agent_does_not_exist(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_auth_agent_already_exists(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_auth_agent_does_not_exist(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_binding_does_not_exist(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_service_already_exists(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_service_does_not_exist(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_service_search_in_progress(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_connect_canceled(DBusConnection *conn, DBusMessage *msg); +DBusHandlerResult error_sdp_failed(DBusConnection *conn, DBusMessage *msg, int err); +DBusHandlerResult error_audit_already_exists(DBusConnection *conn, DBusMessage *msg); + +#endif /* __BLUEZ_DBUS_ERROR_H */ diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index 87799309..0def0476 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -40,6 +40,11 @@ #include "hcid.h" #include "dbus.h" #include "list.h" +#include "dbus-common.h" +#include "dbus-error.h" +#include "dbus-security.h" +#include "dbus-service.h" +#include "dbus-manager.h" static DBusHandlerResult interface_version(DBusConnection *conn, DBusMessage *msg, void *data) @@ -313,7 +318,7 @@ static struct service_data methods[] = { { NULL, NULL } }; -DBusHandlerResult msg_func_manager(DBusConnection *conn, +DBusHandlerResult handle_manager_method(DBusConnection *conn, DBusMessage *msg, void *data) { service_handler_func_t handler; diff --git a/hcid/dbus-manager.h b/hcid/dbus-manager.h new file mode 100644 index 00000000..17b34052 --- /dev/null +++ b/hcid/dbus-manager.h @@ -0,0 +1,31 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2006 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 as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __MANAGER_H +#define __MANAGER_H + +#define MANAGER_INTERFACE "org.bluez.Manager" + +DBusHandlerResult handle_manager_method(DBusConnection *conn, DBusMessage *msg, void *data); + +#endif /* __MANAGER_H */ diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c index 8a7cc84c..0217ef96 100644 --- a/hcid/dbus-rfcomm.c +++ b/hcid/dbus-rfcomm.c @@ -47,6 +47,10 @@ #include "list.h" #include "glib-ectomy.h" #include "dbus.h" +#include "dbus-common.h" +#include "dbus-error.h" +#include "dbus-sdp.h" +#include "dbus-rfcomm.h" /* Waiting for udev to create the device node */ #define MAX_OPEN_TRIES 5 diff --git a/hcid/dbus-rfcomm.h b/hcid/dbus-rfcomm.h new file mode 100644 index 00000000..49763e0a --- /dev/null +++ b/hcid/dbus-rfcomm.h @@ -0,0 +1,31 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2006 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 as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __BLUEZ_DBUS_RFCOMM_H +#define __BLUEZ_DBUS_RFCOMM_H + +#define RFCOMM_INTERFACE "org.bluez.RFCOMM" + +DBusHandlerResult handle_rfcomm_method(DBusConnection *conn, DBusMessage *msg, void *data); + +#endif /* __BLUEZ_DBUS_RFCOMM_H */ diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c index 3cbce9e8..1d3d9f1d 100644 --- a/hcid/dbus-sdp.c +++ b/hcid/dbus-sdp.c @@ -49,6 +49,9 @@ #include "dbus.h" #include "hcid.h" #include "textfile.h" +#include "dbus-common.h" +#include "dbus-error.h" +#include "dbus-sdp.h" #define MAX_IDENTIFIER_LEN 29 /* "XX:XX:XX:XX:XX:XX/0xYYYYYYYY\0" */ diff --git a/hcid/dbus-sdp.h b/hcid/dbus-sdp.h new file mode 100644 index 00000000..378a1456 --- /dev/null +++ b/hcid/dbus-sdp.h @@ -0,0 +1,52 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2006 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 as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __BLUEZ_DBUS_SDP_H +#define __BLUEZ_DBUS_SDP_H + +#include <stdint.h> +#include <bluetooth/bluetooth.h> +#include <bluetooth/sdp.h> + +#define SDP_INTERFACE "org.bluez.SDP" + +DBusHandlerResult handle_sdp_method(DBusConnection *conn, DBusMessage *msg, void *data); + +DBusHandlerResult get_remote_svc_handles(DBusConnection *conn, DBusMessage *msg, void *data); + +DBusHandlerResult get_remote_svc_rec(DBusConnection *conn, DBusMessage *msg, void *data); + +uint16_t sdp_str2svclass(const char *str); + +typedef void get_record_cb_t(sdp_record_t *rec, void *data, int err); + +int get_record_with_uuid(DBusConnection *conn, DBusMessage *msg, + uint16_t dev_id, const char *dst, + const uuid_t *uuid, get_record_cb_t *cb, void *data); + +int get_record_with_handle(DBusConnection *conn, DBusMessage *msg, + uint16_t dev_id, const char *dst, + uint32_t handle, get_record_cb_t *cb, void *data); + + +#endif /* __BLUEZ_DBUS_SDP_H */ diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index 6d5f0b15..022d32fd 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -38,6 +38,10 @@ #include "dbus.h" #include "hcid.h" +#include "dbus-common.h" +#include "dbus-service.h" +#include "dbus-error.h" +#include "dbus-security.h" #define REQUEST_TIMEOUT (60 * 1000) /* 60 seconds */ #define AGENT_TIMEOUT (10 * 60 * 1000) /* 10 minutes */ diff --git a/hcid/dbus-security.h b/hcid/dbus-security.h new file mode 100644 index 00000000..5b849374 --- /dev/null +++ b/hcid/dbus-security.h @@ -0,0 +1,74 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2006 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 as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __BLUEZ_DBUS_SECURITY_H +#define __BLUEZ_DBUS_SECURITY_H + +#define SECURITY_INTERFACE "org.bluez.Security" + +struct passkey_agent { + struct adapter *adapter; + DBusConnection *conn; + char *addr; + char *name; + char *path; + struct slist *pending_requests; + int exited; + guint timeout; +}; + +struct pending_agent_request { + struct passkey_agent *agent; + int dev; + bdaddr_t sba; + bdaddr_t bda; + char *path; + DBusPendingCall *call; + int old_if; + char *pin; +}; + +struct authorization_agent { + DBusConnection *conn; + char *name; + char *path; + int exited; +}; + +DBusHandlerResult handle_security_method(DBusConnection *conn, DBusMessage *msg, void *data); + +int handle_passkey_request(DBusConnection *conn, int dev, const char *path, + bdaddr_t *sba, bdaddr_t *dba); + +int handle_confirm_request(DBusConnection *conn, int dev, const char *path, + bdaddr_t *sba, bdaddr_t *dba, const char *pin); + +void release_default_agent(void); + +void release_default_auth_agent(void); + +void release_passkey_agents(struct adapter *adapter, bdaddr_t *bda); + +void cancel_passkey_agent_requests(struct slist *agents, const char *path, bdaddr_t *dba); + +#endif /* __BLUEZ_DBUS_SECURITY_H */ diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index 10d811a6..6d61bb3e 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -35,6 +35,11 @@ #include "hcid.h" #include "dbus.h" #include "list.h" +#include "dbus-common.h" +#include "dbus-error.h" +#include "dbus-manager.h" +#include "dbus-adapter.h" +#include "dbus-service.h" #define START_REPLY_TIMEOUT 5000 diff --git a/hcid/dbus-service.h b/hcid/dbus-service.h new file mode 100644 index 00000000..ea58014e --- /dev/null +++ b/hcid/dbus-service.h @@ -0,0 +1,41 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2006 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 as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __BLUEZ_DBUS_SERVICE_H +#define __BLUEZ_DBUS_SERVICE_H + +struct service_agent { + char *id; /* Connection id */ + char *name; + char *description; + int running; + struct slist *trusted_devices; +}; + +int register_service_agent(DBusConnection *conn, const char *sender, const char *path, + const char *name, const char *description); +int unregister_service_agent(DBusConnection *conn, const char *sender, const char *path); +void release_service_agents(DBusConnection *conn); +void append_available_services(DBusMessageIter *iter); + +#endif /* __BLUEZ_DBUS_SERVICE_H */ diff --git a/hcid/dbus-test.c b/hcid/dbus-test.c index 9a1a14e7..2153aed7 100644 --- a/hcid/dbus-test.c +++ b/hcid/dbus-test.c @@ -35,6 +35,9 @@ #include "hcid.h" #include "dbus.h" +#include "dbus-common.h" +#include "dbus-error.h" +#include "dbus-test.h" #define L2INFO_TIMEOUT (2 * 1000) diff --git a/hcid/dbus-test.h b/hcid/dbus-test.h new file mode 100644 index 00000000..0467a335 --- /dev/null +++ b/hcid/dbus-test.h @@ -0,0 +1,33 @@ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2004-2006 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 as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __BLUEZ_DBUS_TEST_H +#define __BLUEZ_DBUS_TEST_H + +#define TEST_INTERFACE "org.bluez.Test" + +DBusHandlerResult handle_test_method(DBusConnection *conn, DBusMessage *msg, void *data); + +void process_audits_list(const char *adapter_path); + +#endif /* __BLUEZ_DBUS_TEST_H */ diff --git a/hcid/dbus.c b/hcid/dbus.c index ce470ab5..f2d55548 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -46,6 +46,15 @@ #include "dbus.h" #include "textfile.h" #include "list.h" +#include "dbus-common.h" +#include "dbus-error.h" +#include "dbus-test.h" +#include "dbus-security.h" +#include "dbus-service.h" +#include "dbus-manager.h" +#include "dbus-adapter.h" + +#define BLUEZ_NAME "org.bluez" static DBusConnection *connection; @@ -347,13 +356,13 @@ DBusMessage *dev_signal_factory(int devid, const char *prop_name, int first, * Virtual table that handle the object path hierarchy */ -static const DBusObjectPathVTable obj_dev_vtable = { - .message_function = &msg_func_device, +static const DBusObjectPathVTable adapter_vtable = { + .message_function = &handle_method_call, .unregister_function = NULL }; -static const DBusObjectPathVTable obj_mgr_vtable = { - .message_function = &msg_func_manager, +static const DBusObjectPathVTable manager_vtable = { + .message_function = &handle_manager_method, .unregister_function = NULL }; @@ -363,46 +372,6 @@ static const DBusObjectPathVTable obj_mgr_vtable = { static DBusHandlerResult hci_dbus_signal_filter(DBusConnection *conn, DBusMessage *msg, void *data); -static int register_dbus_path(const char *path, uint16_t dev_id, - const DBusObjectPathVTable *pvtable, - gboolean fallback) -{ - struct adapter *adapter; - - info("Register path:%s fallback:%d", path, fallback); - - adapter = malloc(sizeof(struct adapter)); - if (!adapter) { - error("Failed to alloc memory to DBUS path register data (%s)", - path); - return -1; - } - - memset(adapter, 0, sizeof(struct adapter)); - - adapter->dev_id = dev_id; - - adapter->pdiscov_resolve_names = 1; - - if (fallback) { - if (!dbus_connection_register_fallback(connection, path, - pvtable, adapter)) { - error("D-Bus failed to register %s fallback", path); - free(adapter); - return -1; - } - } else { - if (!dbus_connection_register_object_path(connection, path, - pvtable, adapter)) { - error("D-Bus failed to register %s object", path); - free(adapter); - return -1; - } - } - - return 0; -} - static void reply_pending_requests(const char *path, struct adapter *adapter) { DBusMessage *message; @@ -544,11 +513,28 @@ int hcid_dbus_register_device(uint16_t id) char path[MAX_PATH_LENGTH]; char *pptr = path; DBusMessage *message; + struct adapter *adapter; snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (register_dbus_path(path, id, &obj_dev_vtable, FALSE) < 0) + adapter = malloc(sizeof(struct adapter)); + if (!adapter) { + error("Failed to alloc memory to D-Bus path register data (%s)", + path); return -1; + } + + memset(adapter, 0, sizeof(struct adapter)); + + adapter->dev_id = id; + adapter->pdiscov_resolve_names = 1; + + if (!dbus_connection_register_object_path(connection, path, + &adapter_vtable, adapter)) { + error("D-Bus failed to register %s object", path); + free(adapter); + return -1; + } /* * Send the adapter added signal @@ -1935,7 +1921,7 @@ int hcid_dbus_init(void) dbus_connection_set_exit_on_disconnect(connection, FALSE); - ret_val = dbus_bus_request_name(connection, BASE_INTERFACE, 0, &err); + ret_val = dbus_bus_request_name(connection, BLUEZ_NAME, 0, &err); if (ret_val != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ) { error("Service could not become the primary owner."); @@ -1948,9 +1934,11 @@ int hcid_dbus_init(void) return -1; } - if (register_dbus_path(BASE_PATH, INVALID_DEV_ID, &obj_mgr_vtable, - TRUE) < 0) + if (!dbus_connection_register_fallback(connection, BASE_PATH, + &manager_vtable, NULL)) { + error("D-Bus failed to register %s fallback", BASE_PATH); return -1; + } if (!dbus_connection_add_filter(connection, hci_dbus_signal_filter, NULL, NULL)) { diff --git a/hcid/dbus.h b/hcid/dbus.h index 478949a1..695633db 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -24,168 +24,8 @@ #ifndef __H_BLUEZ_DBUS_H__ #define __H_BLUEZ_DBUS_H__ -#include <stdint.h> #include <dbus/dbus.h> -#include <bluetooth/bluetooth.h> -#include <bluetooth/sdp.h> -#include "list.h" -#include "glib-ectomy.h" - -#define BASE_PATH "/org/bluez" -#define BASE_INTERFACE "org.bluez" - -#define ADAPTER_INTERFACE BASE_INTERFACE ".Adapter" - -#define MANAGER_INTERFACE BASE_INTERFACE ".Manager" - -#define ERROR_INTERFACE BASE_INTERFACE ".Error" - -#define SECURITY_INTERFACE BASE_INTERFACE ".Security" - -#define TEST_INTERFACE BASE_INTERFACE ".Test" - -#define RFCOMM_INTERFACE BASE_INTERFACE ".RFCOMM" - -#define SDP_INTERFACE BASE_INTERFACE ".SDP" - -#define INVALID_DEV_ID 0xFFFF - -#define MAX_PATH_LENGTH 64 - -#define BONDING_TIMEOUT 45000 /* 45 sec */ - -typedef DBusHandlerResult (*service_handler_func_t) (DBusConnection *conn, - DBusMessage *msg, - void *user_data); - -struct service_data { - const char *name; - service_handler_func_t handler_func; -}; - -/* Discover types */ -#define DISCOVER_TYPE_NONE 0x00 -#define STD_INQUIRY 0x01 -#define PERIODIC_INQUIRY 0x02 - -/* Actions executed after inquiry complete */ -#define RESOLVE_NAME 0x10 - -typedef enum { - NAME_ANY, - NAME_NOT_REQUIRED, /* used by get remote name without name resolving */ - NAME_REQUIRED, /* remote name needs be resolved */ - NAME_REQUESTED, /* HCI remote name request was sent */ - NAME_SENT /* D-Bus signal RemoteNameUpdated sent */ -} name_status_t; - -struct remote_dev_info { - bdaddr_t bdaddr; - int8_t rssi; - name_status_t name_status; -}; - -struct bonding_request_info { - bdaddr_t bdaddr; - DBusConnection *conn; - DBusMessage *rq; - GIOChannel *io; - guint io_id; - int hci_status; - int cancel; - int auth_active; -}; - -struct pending_pin_info { - bdaddr_t bdaddr; - int replied; /* If we've already replied to the request */ -}; - -struct active_conn_info { - bdaddr_t bdaddr; - uint16_t handle; -}; - -struct adapter { - uint16_t dev_id; - int up; - char address[18]; /* adapter Bluetooth Address */ - guint timeout_id; /* discoverable timeout id */ - uint32_t discov_timeout; /* discoverable time(msec) */ - uint8_t mode; /* scan mode */ - int discov_active; /* standard discovery active: includes name resolution step */ - int pdiscov_active; /* periodic discovery active */ - int pinq_idle; /* tracks the idle time for periodic inquiry */ - int discov_type; /* type requested */ - int pdiscov_resolve_names; /* Resolve names when doing periodic discovery */ - struct slist *found_devices; - struct slist *oor_devices; /* out of range device list */ - char *pdiscov_requestor; /* periodic discovery requestor unique name */ - char *discov_requestor; /* discovery requestor unique name */ - DBusMessage *discovery_cancel; /* discovery cancel message request */ - struct slist *passkey_agents; - struct slist *auth_agents; /* Authorization agents */ - bdaddr_t agents_disabled; /* temporarely disable agents for bda */ - struct slist *active_conn; - struct bonding_request_info *bonding; - struct slist *pin_reqs; -}; - -struct passkey_agent { - struct adapter *adapter; - DBusConnection *conn; - char *addr; - char *name; - char *path; - struct slist *pending_requests; - int exited; - guint timeout; -}; - -struct pending_agent_request { - struct passkey_agent *agent; - int dev; - bdaddr_t sba; - bdaddr_t bda; - char *path; - DBusPendingCall *call; - int old_if; - char *pin; -}; - -struct authorization_agent { - DBusConnection *conn; - char *name; - char *path; - int exited; -}; - -struct service_agent { - char *id; /* Connection id */ - char *name; - char *description; - int running; - struct slist *trusted_devices; -}; - -typedef int register_function_t(DBusConnection *conn, uint16_t id); -typedef int unregister_function_t(DBusConnection *conn, uint16_t id); - -DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void *data); -DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void *data); - -int register_service_agent(DBusConnection *conn, const char *sender, const char *path, - const char *name, const char *description); -int unregister_service_agent(DBusConnection *conn, const char *sender, const char *path); -void release_service_agents(DBusConnection *conn); -void append_available_services(DBusMessageIter *iter); - -const char *major_class_str(uint32_t class); -const char *minor_class_str(uint32_t class); -struct slist *service_classes_str(uint32_t class); - -DBusHandlerResult bluez_new_failure_msg(DBusConnection *conn, DBusMessage *msg, - const uint32_t ecode); +#include "dbus-adapter.h" DBusMessage *dev_signal_factory(const int devid, const char *prop_name, const int first, ...); @@ -193,95 +33,11 @@ DBusMessage *new_authentication_return(DBusMessage *msg, uint8_t status); int get_default_dev_id(void); -DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, int err); -DBusHandlerResult error_not_ready(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_not_authorized(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_no_such_adapter(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_not_supported(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_request_deferred(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_not_connected(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_not_in_progress(DBusConnection *conn, DBusMessage *msg, const char *str); -DBusHandlerResult error_unsupported_major_class(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, DBusMessage *msg, int err); -DBusHandlerResult error_bonding_already_exists(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_bonding_does_not_exist(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_bonding_in_progress(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_bonding_not_in_progress(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_authentication_canceled(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_discover_in_progress(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_connect_in_progress(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_connect_not_in_progress(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_record_does_not_exist(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_passkey_agent_already_exists(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_passkey_agent_does_not_exist(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_auth_agent_already_exists(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_auth_agent_does_not_exist(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_binding_does_not_exist(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_service_already_exists(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_service_does_not_exist(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_service_search_in_progress(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_connect_canceled(DBusConnection *conn, DBusMessage *msg); -DBusHandlerResult error_sdp_failed(DBusConnection *conn, DBusMessage *msg, int err); -DBusHandlerResult error_audit_already_exists(DBusConnection *conn, DBusMessage *msg); - -typedef void (*name_cb_t)(const char *name, void *user_data); - -int name_listener_add(DBusConnection *connection, const char *name, - name_cb_t func, void *user_data); -int name_listener_remove(DBusConnection *connection, const char *name, - name_cb_t func, void *user_data); - -int l2raw_connect(const char *local, const bdaddr_t *remote); - -int check_address(const char *addr); - -void process_audits_list(const char *adapter_path); - -DBusHandlerResult handle_test_method(DBusConnection *conn, DBusMessage *msg, void *data); - -DBusHandlerResult handle_security_method(DBusConnection *conn, DBusMessage *msg, void *data); - -DBusHandlerResult handle_rfcomm_method(DBusConnection *conn, DBusMessage *msg, void *data); - -DBusHandlerResult handle_sdp_method(DBusConnection *conn, DBusMessage *msg, void *data); -DBusHandlerResult get_remote_svc_handles(DBusConnection *conn, DBusMessage *msg, void *data); -DBusHandlerResult get_remote_svc_rec(DBusConnection *conn, DBusMessage *msg, void *data); - -DBusHandlerResult simple_introspect(DBusConnection *conn, DBusMessage *msg, void *data); - -service_handler_func_t find_service_handler(struct service_data *services, DBusMessage *msg); -int str2uuid(uuid_t *uuid, const char *string); - void create_bond_req_exit(const char *name, struct adapter *adapter); void discover_devices_req_exit(const char *name, struct adapter *adapter); int cancel_discovery(struct adapter *adapter); void periodic_discover_req_exit(const char *name, struct adapter *adapter); int cancel_periodic_discovery(struct adapter *adapter); -int pending_remote_name_cancel(struct adapter *adapter); - -int handle_passkey_request(DBusConnection *conn, int dev, const char *path, - bdaddr_t *sba, bdaddr_t *dba); -int handle_confirm_request(DBusConnection *conn, int dev, const char *path, - bdaddr_t *sba, bdaddr_t *dba, const char *pin); -void release_default_agent(void); -void release_default_auth_agent(void); -void release_passkey_agents(struct adapter *adapter, bdaddr_t *bda); -void cancel_passkey_agent_requests(struct slist *agents, const char *path, bdaddr_t *dba); - -static inline DBusHandlerResult send_message_and_unref(DBusConnection *conn, DBusMessage *reply) -{ - if (reply) { - dbus_connection_send(conn, reply, NULL); - - dbus_message_unref(reply); - } - - return DBUS_HANDLER_RESULT_HANDLED; -} int active_conn_find_by_bdaddr(const void *data, const void *user_data); void bonding_request_free(struct bonding_request_info *dev); @@ -294,13 +50,4 @@ int found_device_req_name(struct adapter *dbus_data); int discov_timeout_handler(void *data); -uint16_t sdp_str2svclass(const char *str); -typedef void get_record_cb_t(sdp_record_t *rec, void *data, int err); -int get_record_with_uuid(DBusConnection *conn, DBusMessage *msg, - uint16_t dev_id, const char *dst, - const uuid_t *uuid, get_record_cb_t *cb, void *data); -int get_record_with_handle(DBusConnection *conn, DBusMessage *msg, - uint16_t dev_id, const char *dst, - uint32_t handle, get_record_cb_t *cb, void *data); - #endif /* __H_BLUEZ_DBUS_H__ */ |