Home | History | Annotate | Download | only in src

Lines Matching full:device

53 #include "device.h"
85 struct btd_device *device;
92 struct btd_device *device;
98 struct btd_device *device;
192 if (req->device)
193 btd_device_unref(req->device);
204 struct btd_device *device = req->device;
205 struct btd_adapter *adapter = device->adapter;
208 if (device_is_creating(device, NULL))
209 device_set_temporary(device, TRUE);
213 bt_cancel_discovery(&src, &device->bdaddr);
215 device->browse = NULL;
221 struct btd_device *device = user_data;
222 struct btd_adapter *adapter = device->adapter;
225 if (device->agent)
226 agent_free(device->agent);
228 if (agent && (agent_is_busy(agent, device) ||
229 agent_is_busy(agent, device->authr)))
232 g_slist_foreach(device->uuids, (GFunc) g_free, NULL);
233 g_slist_free(device->uuids);
235 if (device->tmp_records)
236 sdp_list_free(device->tmp_records,
239 if (device->disconn_timer)
240 g_source_remove(device->disconn_timer);
242 if (device->discov_timer)
243 g_source_remove(device->discov_timer);
245 DBG("%p", device);
247 g_free(device->authr);
248 g_free(device->path);
249 g_free(device->alias);
250 g_free(device);
253 gboolean device_is_paired(struct btd_device *device)
255 return device->paired;
258 gboolean device_is_trusted(struct btd_device *device)
260 return device->trusted;
266 struct btd_device *device = user_data;
267 struct btd_adapter *adapter = device->adapter;
280 ba2str(&device->bdaddr, dstaddr);
303 ptr = device->name;
307 if (device->alias != NULL)
308 ptr = device->alias;
317 if (read_remote_class(&src, &device->bdaddr, &class) == 0) {
328 boolean = device_is_paired(device);
332 boolean = device_is_trusted(device);
336 boolean = device->blocked;
340 boolean = (device->handle != 0);
345 uuids = g_new0(char *, g_slist_length(device->uuids) + 1);
346 for (i = 0, l = device->uuids; l; l = l->next, i++)
363 struct btd_device *device = data;
364 struct btd_adapter *adapter = device->adapter;
370 if ((device->alias == NULL && g_str_equal(alias, "")) ||
371 g_strcmp0(device->alias, alias) == 0)
376 ba2str(&device->bdaddr, dstaddr);
386 g_free(device->alias);
387 device->alias = g_str_equal(alias, "") ? NULL : g_strdup(alias);
399 struct btd_device *device = data;
400 struct btd_adapter *adapter = device->adapter;
405 if (device->trusted == value)
410 ba2str(&device->bdaddr, dstaddr);
418 device->trusted = value;
428 struct btd_device *device)
432 driver->remove(device);
434 device->drivers = g_slist_remove(device->drivers, driver_data);
440 struct btd_device *device = user_data;
443 uint16_t dev_id = adapter_get_dev_id(device->adapter);
445 device->disconn_timer = 0;
452 cp.handle = htobs(device->handle);
464 static int device_block(DBusConnection *conn, struct btd_device *device)
469 if (device->blocked)
472 dev_id = adapter_get_dev_id(device->adapter);
478 if (device->handle)
479 do_disconnect(device);
481 g_slist_foreach(device->drivers, (GFunc) driver_remove, device);
483 if (ioctl(dd, HCIBLOCKADDR, &device->bdaddr) < 0) {
491 device->blocked = TRUE;
493 adapter_get_address(device->adapter, &src);
495 err = write_blocked(&src, &device->bdaddr, TRUE);
499 device_set_temporary(device, FALSE);
501 emit_property_changed(conn, device->path, DEVICE_INTERFACE, "Blocked",
502 DBUS_TYPE_BOOLEAN, &device->blocked);
507 static int device_unblock(DBusConnection *conn, struct btd_device *device,
513 if (!device->blocked)
516 dev_id = adapter_get_dev_id(device->adapter);
522 if (ioctl(dd, HCIUNBLOCKADDR, &device->bdaddr) < 0) {
530 device->blocked = FALSE;
532 adapter_get_address(device->adapter, &src);
534 err = write_blocked(&src, &device->bdaddr, FALSE);
539 emit_property_changed(conn, device->path,
541 DBUS_TYPE_BOOLEAN, &device->blocked);
542 device_probe_drivers(device, device->uuids);
551 struct btd_device *device = data;
555 err = device_block(conn, device);
557 err = device_unblock(conn, device, FALSE);
639 struct btd_device *device = user_data;
643 if (device->browse)
652 err = device_browse(device, conn, msg, NULL, FALSE);
663 err = device_browse(device, conn, msg, &uuid, FALSE);
756 struct btd_device *device = user_data;
760 if (!device->browse)
765 if (!dbus_message_is_method_call(device->browse->msg, DEVICE_INTERFACE,
771 requestor = browse_request_get_requestor(device->browse);
779 discover_services_reply(device->browse, -ECANCELED, NULL);
781 browse_request_cancel(device->browse);
796 void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
801 if (device->bonding)
802 bonding_request_cancel(device->bonding);
804 if (device->browse)
805 browse_request_cancel(device->browse);
808 device->disconnects = g_slist_append(device->disconnects,
811 if (device->disconn_timer)
814 l = device->watches;
821 /* temporary is set if device is going to be removed */
822 data->watch(device, device->temporary,
826 g_slist_foreach(device->watches, (GFunc) g_free, NULL);
827 g_slist_free(device->watches);
828 device->watches = NULL;
830 device->disconn_timer = g_timeout_add_seconds(DISCONNECT_TIMER,
831 do_disconnect, device);
833 g_dbus_emit_signal(conn, device->path,
841 struct btd_device *device = user_data;
843 if (!device->handle)
846 "Device is not connected");
848 device_request_disconnect(device, msg);
885 struct btd_device *device = user_data;
900 rec = btd_device_get_record(device, pattern);
936 gboolean device_is_connected(struct btd_device *device)
938 return (device->handle != 0);
941 static void device_set_connected(struct btd_device *device,
945 emit_property_changed(conn, device->path, DEVICE_INTERFACE,
948 if (connected && device->secmode3) {
949 struct btd_adapter *adapter = device_get_adapter(device);
954 device->secmode3 = FALSE;
956 hcid_dbus_bonding_process_complete(&sba, &device->bdaddr, 0);
960 void device_add_connection(struct btd_device *device, DBusConnection *conn,
963 if (device->handle) {
965 device->path, handle, device->handle);
969 device->handle = handle;
971 device_set_connected(device, conn, TRUE);
974 void device_remove_connection(struct btd_device *device, DBusConnection *conn,
977 if (handle && device->handle != handle) {
979 device->path, handle, device->handle);
983 device->handle = 0;
985 if (device->disconn_timer > 0) {
986 g_source_remove(device->disconn_timer);
987 device->disconn_timer = 0;
990 while (device->disconnects) {
991 DBusMessage *msg = device->disconnects->data;
994 device->disconnects = g_slist_remove(device->disconnects, msg);
997 device_set_connected(device, conn, FALSE);
1000 gboolean device_has_connection(struct btd_device *device, uint16_t handle)
1002 return (handle == device->handle);
1005 uint16_t device_get_handle(struct btd_device *device)
1007 return device->handle;
1010 guint device_add_disconnect_watch(struct btd_device *device,
1023 device->watches = g_slist_append(device->watches, data);
1028 void device_remove_disconnect_watch(struct btd_device *device, guint id)
1032 for (l = device->watches; l; l = l->next) {
1036 device->watches = g_slist_remove(device->watches,
1046 gboolean device_get_secmode3_conn(struct btd_device *device)
1048 return device->secmode3;
1051 void device_set_secmode3_conn(struct btd_device *device, gboolean enable)
1053 device->secmode3 = enable;
1061 struct btd_device *device;
1066 device = g_try_malloc0(sizeof(struct btd_device));
1067 if (device == NULL)
1071 device->path = g_strdup_printf("%s/dev_%s", adapter_path, address_up);
1072 g_strdelimit(device->path, ":", '_');
1075 DBG("Creating device %s", device->path);
1077 if (g_dbus_register_interface(conn, device->path, DEVICE_INTERFACE,
1079 device, device_free) == FALSE) {
1080 device_free(device);
1084 str2ba(address, &device->bdaddr);
1085 device->adapter = adapter;
1088 read_device_name(srcaddr, address, device->name);
1090 device->alias = g_strdup(alias);
1091 device->trusted = read_trust(&src, address, GLOBAL_TRUST);
1093 if (read_blocked(&src, &device->bdaddr))
1094 device_block(conn, device);
1096 device->auth = 0xff;
1098 if (read_link_key(&src, &device->bdaddr, NULL, NULL) == 0)
1099 device->paired = TRUE;
1101 return btd_device_ref(device);
1104 void device_set_name(struct btd_device *device, const char *name)
1108 if (strncmp(name, device->name, MAX_NAME_LENGTH) == 0)
1111 strncpy(device->name, name, MAX_NAME_LENGTH);
1113 emit_property_changed(conn, device->path,
1117 if (device->alias != NULL)
1120 emit_property_changed(conn, device->path,
1125 void device_get_name(struct btd_device *device, char *name, size_t len)
1127 strncpy(name, device->name, len);
1130 void device_remove_bonding(struct btd_device *device)
1137 adapter_get_address(device->adapter, &bdaddr);
1139 ba2str(&device->bdaddr, dstaddr);
1147 dev_id = adapter_get_dev_id(device->adapter);
1154 hci_delete_stored_link_key(dd, &device->bdaddr, 0, HCI_REQ_TIMEOUT);
1159 static void device_remove_stored(struct btd_device *device)
1165 adapter_get_address(device->adapter, &src);
1166 ba2str(&device->bdaddr, addr);
1168 if (device->paired)
1169 device_remove_bonding(device);
1172 delete_all_records(&src, &device->bdaddr);
1174 if (device->blocked)
1175 device_unblock(conn, device, TRUE);
1178 void device_remove(struct btd_device *device, gboolean remove_stored)
1181 DBG("Removing device %s", device->path);
1183 if (device->agent)
1184 agent_free(device->agent);
1186 if (device->bonding)
1187 device_cancel_bonding(device, HCI_OE_USER_ENDED_CONNECTION);
1189 if (device->browse)
1190 browse_request_cancel(device->browse);
1192 if (device->handle)
1193 do_disconnect(device);
1196 device_remove_stored(device);
1198 g_slist_foreach(device->drivers, (GFunc) driver_remove, device);
1199 g_slist_free(device->drivers);
1200 device->drivers = NULL;
1202 btd_device_unref(device);
1205 gint device_address_cmp(struct btd_device *device, const gchar *address)
1209 ba2str(&device->bdaddr, addr);
1237 static GSList *device_match_pattern(struct btd_device *device,
1247 rec = btd_device_get_record(device, profile_uuid);
1258 static GSList *device_match_driver(struct btd_device *device,
1282 match = device_match_pattern(device, *uuid, profiles);
1290 void device_probe_drivers(struct btd_device *device, GSList *profiles)
1295 if (device->blocked) {
1296 DBG("Skipping drivers for blocked device %s", device->path);
1300 DBG("Probe drivers for %s", device->path);
1307 probe_uuids = device_match_driver(device, driver, profiles);
1314 err = driver->probe(device, probe_uuids);
1316 error("probe failed with driver %s for device %s",
1317 driver->name, device->path);
1325 device->drivers = g_slist_append(device->drivers, driver_data);
1331 GSList *l = g_slist_find_custom(device->uuids, list->data,
1336 device->uuids = g_slist_insert_sorted(device->uuids,
1342 static void device_remove_drivers(struct btd_device *device, GSList *uuids)
1344 struct btd_adapter *adapter = device_get_adapter(device);
1352 ba2str(&device->bdaddr, dstaddr);
1354 records = read_records(&src, &device->bdaddr);
1356 DBG("Remove drivers for %s", device->path);
1358 for (list = device->drivers; list; list = next) {
1370 DBG("UUID %s was removed from device %s",
1373 driver->remove(device);
1374 device->drivers = g_slist_remove(device->drivers,
1385 device->uuids = g_slist_remove(device->uuids, list->data);
1402 static void services_changed(struct btd_device *device)
1409 uuids = g_new0(char *, g_slist_length(device->uuids) + 1);
1410 for (i = 0, l = device->uuids; l; l = l->next, i++)
1413 emit_array_property_changed(conn, device->path, DEVICE_INTERFACE,
1429 struct btd_device *device = req->device;
1430 struct btd_adapter *adapter = device_get_adapter(device);
1437 ba2str(&device->bdaddr, dstaddr);
1498 l = g_slist_find_custom(device->uuids, profile_uuid,
1515 static void store_profiles(struct btd_device *device)
1517 struct btd_adapter *adapter = device->adapter;
1523 if (!device->uuids) {
1524 write_device_profiles(&src, &device->bdaddr, "");
1528 str = bt_list2string(device->uuids);
1529 write_device_profiles(&src, &device->bdaddr, str);
1533 static void create_device_reply(struct btd_device *device, struct browse_req *req)
1541 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &device->path,
1550 struct btd_device *device = req->device;
1554 device->path, strerror(-err), -err);
1560 if (device->tmp_records)
1561 sdp_list_free(device->tmp_records,
1564 device->tmp_records = req->records;
1568 DBG("%s: No service update", device->path);
1574 device_probe_drivers(device, req->profiles_added);
1578 device_remove_drivers(device, req->profiles_removed);
1581 services_changed(req->device);
1589 discover_services_reply(req, err, device->tmp_records);
1592 create_device_reply(device, req);
1600 create_device_reply(device, req);
1601 device_set_temporary(device, FALSE);
1605 if (!device->temporary)
1606 store_profiles(device);
1607 device->browse = NULL;
1614 struct btd_device *device = req->device;
1615 struct btd_adapter *adapter = device->adapter;
1636 bt_search_service(&src, &device->bdaddr, &uuid,
1656 for (l = req->device->uuids; l; l = l->next)
1661 int device_browse(struct btd_device *device, DBusConnection *conn,
1664 struct btd_adapter *adapter = device->adapter;
1671 if (device->browse)
1682 req->device = btd_device_ref(device);
1693 device->browse = req;
1707 err = bt_search_service(&src, &device->bdaddr,
1710 device->browse = NULL;
1717 struct btd_adapter *device_get_adapter(struct btd_device *device)
1719 if (!device)
1722 return device->adapter;
1725 void device_get_address(struct btd_device *device, bdaddr_t *bdaddr)
1727 bacpy(bdaddr, &device->bdaddr);
1730 const gchar *device_get_path(struct btd_device *device)
1732 if (!device)
1735 return device->path;
1738 struct agent *device_get_agent(struct btd_device *device)
1740 if (!device)
1743 if (device->agent)
1744 return device->agent;
1746 return adapter_get_agent(device->adapter);
1749 gboolean device_is_busy(struct btd_device *device)
1751 return device->browse ? TRUE : FALSE;
1754 gboolean device_is_temporary(struct btd_device *device)
1756 return device->temporary;
1759 void device_set_temporary(struct btd_device *device, gboolean temporary)
1761 if (!device)
1764 device->temporary = temporary;
1767 void device_set_cap(struct btd_device *device, uint8_t cap)
1769 if (!device)
1772 device->cap = cap;
1775 uint8_t device_get_cap(struct btd_device *device)
1777 return device->cap;
1780 void device_set_auth(struct btd_device *device, uint8_t auth)
1782 if (!device)
1785 device->auth = auth;
1788 uint8_t device_get_auth(struct btd_device *device)
1790 return device->auth;
1795 struct btd_device *device = user_data;
1797 device_browse(device, NULL, NULL, NULL, TRUE);
1799 device->discov_timer = 0;
1861 struct btd_device *device;
1878 device = bonding->device;
1881 if (!device)
1884 device->bonding = NULL;
1886 if (!device->agent)
1889 agent_cancel(device->agent);
1890 agent_free(device->agent);
1891 device->agent = NULL;
1894 void device_set_paired(struct btd_device *device, gboolean value)
1898 if (device->paired == value)
1901 device->paired = value;
1903 emit_property_changed(conn, device->path, DEVICE_INTERFACE, "Paired",
1909 struct btd_device *device = user_data;
1911 device->agent = NULL;
1913 if (device->authr)
1914 device->authr->agent = NULL;
1919 struct btd_device *device,
1928 DBG("%s: requesting bonding", device->path);
1933 agent = agent_create(device->adapter, name, agent_path,
1937 device);
1943 device->agent = agent;
1946 device->path, name, agent_path);
1957 static int device_authentication_requested(struct btd_device *device,
1965 dd = hci_open_dev(adapter_get_dev_id(device->adapter));
2009 struct btd_device *device = user_data;
2013 if (!device->bonding) {
2032 status = device_authentication_requested(device, handle);
2040 device_cancel_bonding(device, status);
2045 struct btd_device *device = user_data;
2047 DBG("%s: requestor exited before bonding was completed", device->path);
2049 if (device->authr)
2050 device_cancel_authentication(device, FALSE);
2052 if (device->bonding) {
2053 device->bonding->listener_id = 0;
2054 device_request_disconnect(device, NULL);
2058 DBusMessage *device_create_bonding(struct btd_device *device,
2067 struct btd_adapter *adapter = device->adapter;
2076 ba2str(&device->bdaddr, dstaddr);
2078 if (device->bonding)
2101 io = bt_io_connect(BT_IO_L2RAW, bonding_connect_cb, device,
2104 BT_IO_OPT_DEST_BDADDR, &device->bdaddr,
2117 bonding = bonding_request_new(conn, msg, device, agent_path,
2128 create_bond_req_exit, device,
2131 device->bonding = bonding;
2132 bonding->device = device;
2137 void device_simple_pairing_complete(struct btd_device *device, uint8_t status)
2139 struct authentication_req *auth = device->authr;
2145 void device_bonding_complete(struct btd_device *device, uint8_t status)
2147 struct bonding_req *bonding = device->bonding;
2148 struct authentication_req *auth = device->authr;
2154 device_cancel_authentication(device, TRUE);
2155 device_cancel_bonding(device, status);
2159 device->auth = 0xff;
2161 g_free(device->authr);
2162 device->authr = NULL;
2164 if (device->renewed_key)
2167 device_set_temporary(device, FALSE);
2176 if (device->discov_timer) {
2177 g_source_remove(device->discov_timer);
2178 device->discov_timer = 0;
2181 device_browse(device, bonding->conn, bonding->msg,
2186 if (!device->browse && !device->discov_timer &&
2192 device->discov_timer = g_timeout_add_seconds(
2195 device);
2199 device_set_paired(device, TRUE);
2202 gboolean device_is_creating(struct btd_device *device, const char *sender)
2206 if (device->bonding && device->bonding->msg)
2207 msg = device->bonding->msg;
2208 else if (device->browse && device->browse->msg)
2209 msg = device->browse->msg;
2225 gboolean device_is_bonding(struct btd_device *device, const char *sender)
2227 struct bonding_req *bonding = device->bonding;
2229 if (!device->bonding)
2238 void device_cancel_bonding(struct btd_device *device, uint8_t status)
2240 struct bonding_req *bonding = device->bonding;
2246 DBG("%s: canceling bonding request", device->path);
2248 if (device->authr)
2249 device_cancel_authentication(device, FALSE);
2262 struct btd_device *device = auth->device;
2268 ((agent_pincode_cb) auth->cb)(agent, err, pincode, device);
2270 device->authr->cb = NULL;
2271 device->authr->agent = NULL;
2277 struct btd_device *device = auth->device;
2283 ((agent_cb) auth->cb)(agent, err, device);
2285 device->authr->cb = NULL;
2286 device->authr->agent = NULL;
2293 struct btd_device *device = auth->device;
2299 ((agent_oob_data_cb) auth->cb)(agent, err, hash, randomizer, device);
2301 device->authr->cb = NULL;
2302 device->authr->agent = NULL;
2309 struct btd_device *device = auth->device;
2315 ((agent_passkey_cb) auth->cb)(agent, err, passkey, device);
2317 device->authr->cb = NULL;
2318 device->authr->agent = NULL;
2324 struct btd_device *device = auth->device;
2330 ((agent_cb) auth->cb)(agent, err, device);
2335 int device_request_oob_availability(struct btd_device *device,
2341 DBG("%s: requesting agent oob availability", device->path);
2343 agent = device_get_agent(device);
2349 err = agent_request_oob_availability(agent, device_get_path(device),
2359 int device_request_authentication(struct btd_device *device, auth_type_t type,
2366 DBG("%s: requesting agent authentication", device->path);
2368 agent = device_get_agent(device);
2376 auth->device = device;
2379 device->authr = auth;
2383 err = agent_request_pincode(agent, device, pincode_cb,
2387 err = agent_request_passkey(agent, device, passkey_cb,
2391 err = agent_request_confirmation(agent, device, passkey,
2395 err = agent_display_passkey(agent, device, passkey);
2398 err = agent_request_oob_data(agent, device, oob_data_cb, auth, NULL);
2404 err = agent_request_pairing_consent(agent, device,
2414 device->authr = NULL;
2422 struct btd_device *device;
2429 device = auth->device;
2437 ((agent_pincode_cb) auth->cb)(agent, &err, NULL, device);
2440 ((agent_cb) auth->cb)(agent, &err, device);
2443 ((agent_passkey_cb) auth->cb)(agent, &err, 0, device);
2446 ((agent_oob_data_cb) auth->cb)(agent, &err, 0, 0, device);
2449 ((agent_cb) auth->cb) (agent, &err, device);
2461 void device_cancel_authentication(struct btd_device *device, gboolean aborted)
2463 struct authentication_req *auth = device->authr;
2468 DBG("%s: canceling authentication request", device->path);
2476 device->authr = NULL;
2480 gboolean device_is_authenticating(struct btd_device *device)
2482 return (device->authr != NULL);
2485 gboolean device_is_authorizing(struct btd_device *device)
2487 return device->authorizing;
2490 void device_set_authorizing(struct btd_device *device, gboolean auth)
2492 device->authorizing = auth;
2495 void device_set_renewed_key(struct btd_device *device, gboolean renewed)
2497 device->renewed_key = renewed;
2500 void btd_device_add_uuid(struct btd_device *device, const char *uuid)
2505 if (g_slist_find_custom(device->uuids, uuid,
2512 device_probe_drivers(device, uuid_list);
2517 store_profiles(device);
2518 services_changed(device);
2521 const sdp_record_t *btd_device_get_record(struct btd_device *device,
2526 if (device->tmp_records) {
2529 record = find_record_in_list(device->tmp_records, uuid);
2534 adapter_get_address(device->adapter, &src);
2536 device->tmp_records = read_records(&src, &device->bdaddr);
2537 if (!device->tmp_records)
2540 return find_record_in_list(device->tmp_records, uuid);
2543 gboolean device_set_debug_key(struct btd_device *device, uint8_t *key)
2546 device->has_debug_key = FALSE;
2550 memcpy(device->debug_key, key, 16);
2551 device->has_debug_key = TRUE;
2556 gboolean device_get_debug_key(struct btd_device *device, uint8_t *key)
2558 if (!device->has_debug_key)
2562 memcpy(key, device->debug_key, 16);
2579 struct btd_device *btd_device_ref(struct btd_device *device)
2581 device->ref++;
2583 DBG("%p: ref=%d", device, device->ref);
2585 return device;
2588 void btd_device_unref(struct btd_device *device)
2593 device->ref--;
2595 DBG("%p: ref=%d", device, device->ref);
2597 if (device->ref > 0)
2600 path = g_strdup(device->path);