static int gap_accept(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); struct gatt_db *db = btd_device_get_gatt_db(device); struct bt_gatt_client *client = btd_device_get_gatt_client(device); struct gas *gas = btd_service_get_user_data(service); char addr[18]; bt_uuid_t gap_uuid; ba2str(device_get_address(device), addr); DBG("GAP profile accept (%s)", addr); if (!gas) { error("GAP service not handled by profile"); return -1; } gas->db = gatt_db_ref(db); gas->client = bt_gatt_client_ref(client); /* Handle the GAP services */ bt_uuid16_create(&gap_uuid, GAP_UUID16); gatt_db_foreach_service(db, &gap_uuid, foreach_gap_service, gas); if (!gas->attr) { error("GAP attribute not found"); gas_reset(gas); return -1; } btd_service_connecting_complete(service, 0); return 0; }
void btd_gatt_client_ready(struct btd_gatt_client *client) { struct bt_gatt_client *gatt; if (!client) return; gatt = btd_device_get_gatt_client(client->device); if (!gatt) { error("GATT client not initialized"); return; } bt_gatt_client_unref(client->gatt); client->gatt = bt_gatt_client_ref(gatt); client->ready = true; create_services(client); }
void btd_gatt_client_connected(struct btd_gatt_client *client) { struct bt_gatt_client *gatt; gatt = btd_device_get_gatt_client(client->device); if (!gatt) { error("GATT client not initialized"); return; } DBG("Device connected."); bt_gatt_client_unref(client->gatt); client->gatt = bt_gatt_client_ref(gatt); /* * Services have already been created before. Re-enable notifications * for any pre-registered notification sessions. */ queue_foreach(client->all_notify_clients, register_notify, client); }
static int gap_driver_accept(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); struct gatt_db *db = btd_device_get_gatt_db(device); struct bt_gatt_client *client = btd_device_get_gatt_client(device); struct gas *gas; GSList *l; char addr[18]; bt_uuid_t gap_uuid; ba2str(device_get_address(device), addr); DBG("GAP profile accept (%s)", addr); l = g_slist_find_custom(devices, device, cmp_device); if (!l) { error("GAP service not handled by profile"); return -1; } gas = l->data; /* Clean-up any old client/db and acquire the new ones */ gas->attr = NULL; gatt_db_unregister(gas->db, gas->db_id); gatt_db_unref(gas->db); bt_gatt_client_unref(gas->client); gas->db = gatt_db_ref(db); gas->client = bt_gatt_client_ref(client); gas->db_id = gatt_db_register(db, service_added, service_removed, gas, NULL); /* Handle the GAP services */ bt_uuid16_create(&gap_uuid, GAP_UUID16); gatt_db_foreach_service(db, &gap_uuid, foreach_gap_service, gas); return 0; }