• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2006-2007  Nokia Corporation
6  *  Copyright (C) 2004-2009  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 <dbus/dbus.h>
27 #include <glib.h>
28 
29 #define ADAPTER_INTERFACE	"org.bluez.Adapter"
30 
31 /* Discover types */
32 #define DISCOVER_TYPE_NONE	0x00
33 #define STD_INQUIRY		0x01
34 #define PERIODIC_INQUIRY	0x02
35 
36 /* Actions executed after inquiry complete */
37 #define RESOLVE_NAME		0x10
38 
39 #define MAX_NAME_LENGTH		248
40 
41 typedef enum {
42 	NAME_ANY,
43 	NAME_NOT_REQUIRED, /* used by get remote name without name resolving */
44 	NAME_REQUIRED,      /* remote name needs be resolved       */
45 	NAME_REQUESTED,    /* HCI remote name request was sent    */
46 	NAME_SENT          /* D-Bus signal RemoteNameUpdated sent */
47 } name_status_t;
48 
49 struct btd_adapter;
50 
51 struct remote_dev_info {
52 	bdaddr_t bdaddr;
53 	int8_t rssi;
54 	uint32_t class;
55 	char *name;
56 	char *alias;
57 	dbus_bool_t legacy;
58 	name_status_t name_status;
59 };
60 
61 struct hci_dev {
62 	int ignore;
63 
64 	uint8_t  features[8];
65 	uint8_t  lmp_ver;
66 	uint16_t lmp_subver;
67 	uint16_t hci_rev;
68 	uint16_t manufacturer;
69 
70 	uint8_t  ssp_mode;
71 	uint8_t  name[MAX_NAME_LENGTH];
72 	uint8_t  class[3];
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_get_class(struct btd_adapter *adapter, uint8_t *cls);
82 
83 int adapter_set_class(struct btd_adapter *adapter, uint8_t *cls);
84 
85 int adapter_update_ssp_mode(struct btd_adapter *adapter, uint8_t mode);
86 
87 struct btd_device *adapter_get_device(DBusConnection *conn,
88 				struct btd_adapter *adapter, const char *address);
89 
90 struct btd_device *adapter_find_device(struct btd_adapter *adapter, const char *dest);
91 
92 struct btd_device *adapter_find_connection(struct btd_adapter *adapter, uint16_t handle);
93 
94 void adapter_disable_svc_cache(struct btd_adapter *adapter);
95 
96 void adapter_remove_device(DBusConnection *conn, struct btd_adapter *adapter,
97 				struct btd_device *device);
98 struct btd_device *adapter_create_device(DBusConnection *conn,
99 				struct btd_adapter *adapter, const char *address);
100 
101 int pending_remote_name_cancel(struct btd_adapter *adapter);
102 
103 int adapter_resolve_names(struct btd_adapter *adapter);
104 
105 void clear_found_devices_list(struct btd_adapter *adapter);
106 
107 struct btd_adapter *adapter_create(DBusConnection *conn, int id,
108 				gboolean devup);
109 void adapter_remove(struct btd_adapter *adapter);
110 uint16_t adapter_get_dev_id(struct btd_adapter *adapter);
111 const gchar *adapter_get_path(struct btd_adapter *adapter);
112 void adapter_get_address(struct btd_adapter *adapter, bdaddr_t *bdaddr);
113 void adapter_set_state(struct btd_adapter *adapter, int state);
114 int adapter_get_state(struct btd_adapter *adapter);
115 gboolean adapter_is_ready(struct btd_adapter *adapter);
116 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
117 						struct remote_dev_info *match);
118 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
119 				int8_t rssi, uint32_t class, const char *name,
120 				const char *alias, gboolean legacy,
121 				name_status_t name_status);
122 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
123 void adapter_emit_device_found(struct btd_adapter *adapter,
124 				struct remote_dev_info *dev);
125 void adapter_update_oor_devices(struct btd_adapter *adapter);
126 void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode);
127 void adapter_setname_complete(bdaddr_t *local, uint8_t status);
128 void adapter_update_local_name(bdaddr_t *bdaddr, uint8_t status, void *ptr);
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 int set_major_and_minor_class(struct btd_adapter *adapter, uint8_t major,
140 								uint8_t minor);
141 
142 
143 struct btd_adapter_driver {
144 	const char *name;
145 	int (*probe) (struct btd_adapter *adapter);
146 	void (*remove) (struct btd_adapter *adapter);
147 };
148 
149 typedef void (*service_auth_cb) (DBusError *derr, void *user_data);
150 
151 int btd_register_adapter_driver(struct btd_adapter_driver *driver);
152 void btd_unregister_adapter_driver(struct btd_adapter_driver *driver);
153 int btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst,
154 		const char *uuid, service_auth_cb cb, void *user_data);
155 int btd_cancel_authorization(const bdaddr_t *src, const bdaddr_t *dst);
156 
157 const char *adapter_any_get_path(void);
158 
159 const char *btd_adapter_any_request_path(void);
160 void btd_adapter_any_release_path(void);
161 gboolean adapter_is_pairable(struct btd_adapter *adapter);
162 gboolean adapter_powering_down(struct btd_adapter *adapter);
163 
164 int btd_adapter_restore_powered(struct btd_adapter *adapter);
165 int btd_adapter_switch_offline(struct btd_adapter *adapter);
166 
167 struct btd_adapter_ops {
168 	int (*setup) (void);
169 	void (*cleanup) (void);
170 	int (*start) (int index);
171 	int (*stop) (int index);
172 	int (*set_powered) (int index, gboolean powered);
173 	int (*set_connectable) (int index);
174 	int (*set_discoverable) (int index);
175 	int (*set_limited_discoverable) (int index, const uint8_t *cls,
176 						gboolean limited);
177 	int (*start_discovery) (int index, gboolean periodic);
178 	int (*stop_discovery) (int index);
179 	int (*resolve_name) (int index, bdaddr_t *bdaddr);
180 	int (*cancel_resolve_name) (int index, bdaddr_t *bdaddr);
181 	int (*set_name) (int index, const char *name);
182 	int (*read_name) (int index);
183 };
184 
185 int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
186 void btd_adapter_cleanup_ops(struct btd_adapter_ops *btd_adapter_ops);
187 int adapter_ops_setup(void);
188