static void find_by_type_val_att_cb(struct gatt_db_attribute *attrib, void *user_data) { uint16_t handle, end_handle; struct find_by_type_val_data *data = user_data; if (data->ecode) return; if (data->len + 4 > data->mtu - 1) return; /* * This OP is only valid for Primary Service per the spec * page 562, so this should work. */ gatt_db_attribute_get_service_data(attrib, &handle, &end_handle, NULL, NULL); if (!handle || !end_handle) { data->ecode = BT_ATT_ERROR_UNLIKELY; return; } put_le16(handle, data->pdu + data->len); put_le16(end_handle, data->pdu + data->len + 2); data->len += 4; }
static struct service *service_create(struct gatt_db_attribute *attr, struct btd_gatt_client *client) { struct service *service; const char *device_path = device_get_path(client->device); bt_uuid_t uuid; service = new0(struct service, 1); if (!service) return NULL; service->chrcs = queue_new(); if (!service->chrcs) { free(service); return NULL; } service->pending_ext_props = queue_new(); if (!service->pending_ext_props) { queue_destroy(service->chrcs, NULL); free(service); return NULL; } service->client = client; gatt_db_attribute_get_service_data(attr, &service->start_handle, &service->end_handle, &service->primary, &uuid); bt_uuid_to_uuid128(&uuid, &service->uuid); service->path = g_strdup_printf("%s/service%04x", device_path, service->start_handle); if (!g_dbus_register_interface(btd_get_dbus_connection(), service->path, GATT_SERVICE_IFACE, NULL, NULL, service_properties, service, service_free)) { error("Unable to register GATT service with handle 0x%04x for " "device %s", service->start_handle, client->devaddr); service_free(service); return NULL; } DBG("Exported GATT service: %s", service->path); /* Set service active so we can skip discovering next time */ gatt_db_service_set_active(attr, true); /* Mark the service as claimed since it going to be exported */ gatt_db_service_set_claimed(attr, true); return service; }
static void print_service(struct gatt_db_attribute *attr, void *user_data) { struct server *server = user_data; uint16_t start, end; bool primary; bt_uuid_t uuid; if (!gatt_db_attribute_get_service_data(attr, &start, &end, &primary, &uuid)) return; printf(COLOR_RED "service" COLOR_OFF " - start: 0x%04x, " "end: 0x%04x, type: %s, uuid: ", start, end, primary ? "primary" : "secondary"); print_uuid(&uuid); gatt_db_service_foreach_incl(attr, print_incl, server); gatt_db_service_foreach_char(attr, print_chrc, NULL); printf("\n"); }