1 /* 2 * 3 * BlueZ - Bluetooth protocol stack for Linux 4 * 5 * Copyright (C) 2006-2010 Nokia Corporation 6 * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org> 7 * 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 * 23 */ 24 25 #include <bluetooth/bluetooth.h> 26 #include <bluetooth/sdp.h> 27 #include <dbus/dbus.h> 28 #include <glib.h> 29 30 #define ADAPTER_INTERFACE "org.bluez.Adapter" 31 32 /* Discover types */ 33 #define DISCOVER_TYPE_NONE 0x00 34 #define STD_INQUIRY 0x01 35 #define PERIODIC_INQUIRY 0x02 36 37 /* Actions executed after inquiry complete */ 38 #define RESOLVE_NAME 0x10 39 40 #define MAX_NAME_LENGTH 248 41 42 typedef enum { 43 NAME_ANY, 44 NAME_NOT_REQUIRED, /* used by get remote name without name resolving */ 45 NAME_REQUIRED, /* remote name needs be resolved */ 46 NAME_REQUESTED, /* HCI remote name request was sent */ 47 NAME_SENT /* D-Bus signal RemoteNameUpdated sent */ 48 } name_status_t; 49 50 struct btd_adapter; 51 52 struct remote_dev_info { 53 bdaddr_t bdaddr; 54 int8_t rssi; 55 uint32_t class; 56 char *name; 57 char *alias; 58 dbus_bool_t legacy; 59 name_status_t name_status; 60 }; 61 62 struct hci_dev { 63 int ignore; 64 65 uint8_t features[8]; 66 uint8_t lmp_ver; 67 uint16_t lmp_subver; 68 uint16_t hci_rev; 69 uint16_t manufacturer; 70 71 uint8_t ssp_mode; 72 uint8_t name[MAX_NAME_LENGTH]; 73 }; 74 75 int adapter_start(struct btd_adapter *adapter); 76 77 int adapter_stop(struct btd_adapter *adapter); 78 79 int adapter_update(struct btd_adapter *adapter, uint8_t cls); 80 81 int adapter_update_ssp_mode(struct btd_adapter *adapter, uint8_t mode); 82 83 struct btd_device *adapter_get_device(DBusConnection *conn, 84 struct btd_adapter *adapter, const char *address); 85 86 struct btd_device *adapter_find_device(struct btd_adapter *adapter, const char *dest); 87 88 struct btd_device *adapter_find_connection(struct btd_adapter *adapter, uint16_t handle); 89 90 void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter, 91 struct btd_device *device, 92 gboolean remove_storage); 93 struct btd_device *adapter_create_device(DBusConnection *conn, 94 struct btd_adapter *adapter, const char *address); 95 96 int pending_remote_name_cancel(struct btd_adapter *adapter); 97 98 int adapter_resolve_names(struct btd_adapter *adapter); 99 100 void clear_found_devices_list(struct btd_adapter *adapter); 101 102 struct btd_adapter *adapter_create(DBusConnection *conn, int id, 103 gboolean devup); 104 void adapter_remove(struct btd_adapter *adapter); 105 uint16_t adapter_get_dev_id(struct btd_adapter *adapter); 106 const gchar *adapter_get_path(struct btd_adapter *adapter); 107 void adapter_get_address(struct btd_adapter *adapter, bdaddr_t *bdaddr); 108 void adapter_set_state(struct btd_adapter *adapter, int state); 109 int adapter_get_state(struct btd_adapter *adapter); 110 gboolean adapter_is_ready(struct btd_adapter *adapter); 111 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter, 112 struct remote_dev_info *match); 113 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr, 114 int8_t rssi, uint32_t class, const char *name, 115 const char *alias, gboolean legacy, 116 name_status_t name_status); 117 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr); 118 void adapter_emit_device_found(struct btd_adapter *adapter, 119 struct remote_dev_info *dev); 120 void adapter_update_oor_devices(struct btd_adapter *adapter); 121 void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode); 122 void adapter_setname_complete(bdaddr_t *local, uint8_t status); 123 void adapter_update_tx_power(bdaddr_t *bdaddr, uint8_t status, void *ptr); 124 void adapter_update_local_name(bdaddr_t *bdaddr, uint8_t status, void *ptr); 125 void adapter_service_insert(const bdaddr_t *bdaddr, void *rec); 126 void adapter_service_remove(const bdaddr_t *bdaddr, void *rec); 127 sdp_list_t *adapter_get_services(struct btd_adapter *adapter); 128 void adapter_set_class_complete(bdaddr_t *bdaddr, uint8_t status); 129 130 struct agent *adapter_get_agent(struct btd_adapter *adapter); 131 void adapter_add_connection(struct btd_adapter *adapter, 132 struct btd_device *device, uint16_t handle); 133 void adapter_remove_connection(struct btd_adapter *adapter, 134 struct btd_device *device, uint16_t handle); 135 gboolean adapter_has_discov_sessions(struct btd_adapter *adapter); 136 137 struct btd_adapter *btd_adapter_ref(struct btd_adapter *adapter); 138 void btd_adapter_unref(struct btd_adapter *adapter); 139 140 int btd_adapter_set_class(struct btd_adapter *adapter, uint8_t major, 141 uint8_t minor); 142 143 144 struct btd_adapter_driver { 145 const char *name; 146 int (*probe) (struct btd_adapter *adapter); 147 void (*remove) (struct btd_adapter *adapter); 148 }; 149 150 typedef void (*service_auth_cb) (DBusError *derr, void *user_data); 151 152 int btd_register_adapter_driver(struct btd_adapter_driver *driver); 153 void btd_unregister_adapter_driver(struct btd_adapter_driver *driver); 154 int btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst, 155 const char *uuid, service_auth_cb cb, void *user_data); 156 int btd_cancel_authorization(const bdaddr_t *src, const bdaddr_t *dst); 157 158 const char *adapter_any_get_path(void); 159 160 const char *btd_adapter_any_request_path(void); 161 void btd_adapter_any_release_path(void); 162 gboolean adapter_is_pairable(struct btd_adapter *adapter); 163 gboolean adapter_powering_down(struct btd_adapter *adapter); 164 165 int btd_adapter_restore_powered(struct btd_adapter *adapter); 166 int btd_adapter_switch_online(struct btd_adapter *adapter); 167 int btd_adapter_switch_offline(struct btd_adapter *adapter); 168 169 struct btd_adapter_ops { 170 int (*setup) (void); 171 void (*cleanup) (void); 172 int (*start) (int index); 173 int (*stop) (int index); 174 int (*set_powered) (int index, gboolean powered); 175 int (*set_connectable) (int index); 176 int (*set_discoverable) (int index); 177 int (*set_limited_discoverable) (int index, uint32_t class, 178 gboolean limited); 179 int (*start_discovery) (int index, gboolean periodic); 180 int (*stop_discovery) (int index); 181 int (*resolve_name) (int index, bdaddr_t *bdaddr); 182 int (*cancel_resolve_name) (int index, bdaddr_t *bdaddr); 183 int (*set_name) (int index, const char *name); 184 int (*read_name) (int index); 185 int (*set_class) (int index, uint32_t class); 186 }; 187 188 int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops); 189 void btd_adapter_cleanup_ops(struct btd_adapter_ops *btd_adapter_ops); 190 int adapter_ops_setup(void); 191