struct gas {
struct btd_device *device;
struct gatt_db *db;
- unsigned int db_id;
struct bt_gatt_client *client;
struct gatt_db_attribute *attr;
};
static void gas_free(struct gas *gas)
{
- gatt_db_unregister(gas->db, gas->db_id);
gatt_db_unref(gas->db);
bt_gatt_client_unref(gas->client);
btd_device_unref(gas->device);
handle_gap_service(gas);
}
-static void service_added(struct gatt_db_attribute *attr, void *user_data)
-{
- struct gas *gas = user_data;
- bt_uuid_t uuid, gap_uuid;
-
- if (!bt_gatt_client_is_ready(gas->client))
- return;
-
- gatt_db_attribute_get_service_uuid(attr, &uuid);
- bt_uuid16_create(&gap_uuid, GAP_UUID16);
-
- if (bt_uuid_cmp(&uuid, &gap_uuid))
- return;
-
- if (gas->attr) {
- error("More than one GAP service added to device");
- return;
- }
-
- DBG("GAP service added");
-
- gas->attr = attr;
- handle_gap_service(gas);
-}
-
-static void service_removed(struct gatt_db_attribute *attr, void *user_data)
-{
- struct gas *gas = user_data;
-
- if (gas->attr != attr)
- return;
-
- DBG("GAP service removed");
-
- gas->attr = NULL;
-}
-
static int gap_driver_accept(struct btd_service *service)
{
struct btd_device *device = btd_service_get_device(service);
/* 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);