op->last = end;
}
-static void discover_secondary_cb(bool success, uint8_t att_ecode,
- struct bt_gatt_result *result,
- void *user_data)
+static bool discovery_parse_services(struct discovery_op *op, bool primary,
+ struct bt_gatt_iter *iter)
{
- struct discovery_op *op = user_data;
struct bt_gatt_client *client = op->client;
- struct bt_gatt_iter iter;
struct gatt_db_attribute *attr;
uint16_t start, end;
uint128_t u128;
bt_uuid_t uuid;
char uuid_str[MAX_LEN_UUID_STR];
- struct handle_range *range;
-
- discovery_req_clear(client);
-
- if (!success) {
- switch (att_ecode) {
- case BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND:
- case BT_ATT_ERROR_UNSUPPORTED_GROUP_TYPE:
- success = true;
- att_ecode = 0;
- goto next;
- default:
- util_debug(client->debug_callback, client->debug_data,
- "Secondary service discovery failed."
- " ATT ECODE: 0x%02x", att_ecode);
- goto done;
- }
- }
-
- if (!result || !bt_gatt_iter_init(&iter, result)) {
- success = false;
- goto done;
- }
- util_debug(client->debug_callback, client->debug_data,
- "Secondary services found: %u",
- bt_gatt_result_service_count(result));
-
- while (bt_gatt_iter_next_service(&iter, &start, &end, u128.data)) {
+ while (bt_gatt_iter_next_service(iter, &start, &end, u128.data)) {
bt_uuid128_create(&uuid, u128);
/* Log debug message */
start, end, uuid_str);
/* Store the service */
+
#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
if (client->in_svc_chngd) {
util_debug(client->debug_callback, client->debug_data,
gatt_db_clear_range(client->db, start, end);
}
#endif
- attr = gatt_db_insert_service(client->db, start, &uuid, false,
+ attr = gatt_db_insert_service(client->db, start, &uuid, primary,
end - start + 1);
if (!attr) {
gatt_db_clear_range(client->db, start, end);
util_debug(client->debug_callback,
client->debug_data,
"Failed to store service");
- success = false;
- goto done;
+ return false;
}
/* Database has changed adjust last handle */
op->last = end;
discovery_found_service(op, attr, start, end);
}
+ return true;
+}
+
+static void discover_secondary_cb(bool success, uint8_t att_ecode,
+ struct bt_gatt_result *result,
+ void *user_data)
+{
+ struct discovery_op *op = user_data;
+ struct bt_gatt_client *client = op->client;
+ struct bt_gatt_iter iter;
+ struct handle_range *range;
+
+ discovery_req_clear(client);
+
+ if (!success) {
+ switch (att_ecode) {
+ case BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND:
+ case BT_ATT_ERROR_UNSUPPORTED_GROUP_TYPE:
+ success = true;
+ att_ecode = 0;
+ goto next;
+ default:
+ util_debug(client->debug_callback, client->debug_data,
+ "Secondary service discovery failed."
+ " ATT ECODE: 0x%02x", att_ecode);
+ goto done;
+ }
+ }
+
+ if (!result || !bt_gatt_iter_init(&iter, result)) {
+ success = false;
+ goto done;
+ }
+
+ util_debug(client->debug_callback, client->debug_data,
+ "Secondary services found: %u",
+ bt_gatt_result_service_count(result));
+
+ if (!discovery_parse_services(op, false, &iter)) {
+ success = false;
+ goto done;
+ }
+
next:
if (queue_isempty(op->pending_svcs) || queue_isempty(op->discov_ranges))
goto done;
struct discovery_op *op = user_data;
struct bt_gatt_client *client = op->client;
struct bt_gatt_iter iter;
- struct gatt_db_attribute *attr;
- uint16_t start, end;
- uint128_t u128;
- bt_uuid_t uuid;
- char uuid_str[MAX_LEN_UUID_STR];
discovery_req_clear(client);
"Primary services found: %u",
bt_gatt_result_service_count(result));
- while (bt_gatt_iter_next_service(&iter, &start, &end, u128.data)) {
- bt_uuid128_create(&uuid, u128);
-
- /* Log debug message. */
- bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str));
- util_debug(client->debug_callback, client->debug_data,
- "start: 0x%04x, end: 0x%04x, uuid: %s",
- start, end, uuid_str);
-
-#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
- if (client->in_svc_chngd) {
- util_debug(client->debug_callback, client->debug_data,
- "In service changed, delete service first.");
- gatt_db_clear_range(client->db, start, end);
- }
-#endif
- attr = gatt_db_insert_service(client->db, start, &uuid, true,
- end - start + 1);
- if (!attr) {
- gatt_db_clear_range(client->db, start, end);
- attr = gatt_db_insert_service(client->db, start, &uuid,
- true, end - start + 1);
- if (!attr) {
- util_debug(client->debug_callback,
- client->debug_data,
- "Failed to store service");
- success = false;
- goto done;
- }
- /* Database has changed adjust last handle */
- op->last = end;
- }
-
- /* Update pending list */
- discovery_found_service(op, attr, start, end);
+ if (!discovery_parse_services(op, true, &iter)) {
+ success = false;
+ goto done;
}
secondary: