#include "src/shared/gatt-db.h"
#include "src/shared/gatt-client.h"
#if defined TIZEN_FEATURE_BLUEZ_MODIFY
-#include "../log.h"
#include "../../profile.h"
#endif
#define GATT_SVC_UUID 0x1801
#define SVC_CHNGD_UUID 0x2a05
+#define DBG(_client, _format, arg...) \
+ gatt_log(_client, "%s:%s() " _format, __FILE__, __func__, ## arg)
struct ready_cb {
bt_gatt_client_callback_t callback;
static bool read_db_hash(struct discovery_op *op);
+static void gatt_log(struct bt_gatt_client *client, const char *format, ...)
+{
+ va_list ap;
+
+ if (!client || !format || !client->debug_callback)
+ return;
+
+ va_start(ap, format);
+ util_debug_va(client->debug_callback, client->debug_data, format, ap);
+ va_end(ap);
+}
+
static void discovery_op_complete(struct discovery_op *op, bool success,
uint8_t err)
{
gatt_db_attribute_get_service_data(attr, &start, &end,
NULL, NULL);
- util_debug(op->client->debug_callback, op->client->debug_data,
- "service disappeared: start 0x%04x end 0x%04x",
- start, end);
+ DBG(op->client, "service disappeared: start 0x%04x end 0x%04x",
+ start, end);
gatt_db_remove_service(op->client->db, attr);
}
if (includes_count == 0)
goto failed;
- util_debug(client->debug_callback, client->debug_data,
- "Included services found: %u",
- includes_count);
+ DBG(client, "Included services found: %u", includes_count);
for (i = 0; i < includes_count; i++) {
if (!bt_gatt_iter_next_included_service(&iter, &handle, &start,
/* Log debug message */
bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str));
- util_debug(client->debug_callback, client->debug_data,
- "handle: 0x%04x, start: 0x%04x, end: 0x%04x,"
+ DBG(client, "handle: 0x%04x, start: 0x%04x, end: 0x%04x,"
"uuid: %s", handle, start, end, uuid_str);
attr = gatt_db_get_attribute(client->db, start);
if (!attr) {
- util_debug(client->debug_callback, client->debug_data,
+ DBG(client,
"Unable to find attribute at 0x%04x: skipping",
start);
continue;
attr = gatt_db_insert_included(client->db, handle, attr);
if (!attr) {
- util_debug(client->debug_callback, client->debug_data,
+ DBG(client,
"Unable to add include attribute at 0x%04x",
handle);
goto failed;
* attribute.
*/
if (gatt_db_attribute_get_handle(attr) != handle) {
- util_debug(client->debug_callback, client->debug_data,
+ DBG(client,
"Invalid attribute 0x%04x expect it at 0x%04x",
gatt_db_attribute_get_handle(attr), handle);
goto failed;
if (client->discovery_req)
return;
- util_debug(client->debug_callback, client->debug_data,
- "Failed to start characteristic discovery");
+ DBG(client, "Failed to start characteristic discovery");
+
discovery_op_unref(op);
failed:
discovery_op_complete(op, false, att_ecode);
NULL, NULL, NULL);
if (!attr) {
- util_debug(client->debug_callback, client->debug_data,
+ DBG(client,
"Failed to insert characteristic at 0x%04x",
chrc_data->value_handle);
goto done;
}
- util_debug(client->debug_callback, client->debug_data,
- "Failed to start descriptor discovery");
+ DBG(client, "Failed to start descriptor discovery");
+
discovery_op_unref(op);
goto failed;
{
struct bt_gatt_client *client = user_data;
- util_debug(client->debug_callback, client->debug_data,
- "Value set status: %d", err);
+ DBG(client, "Value set status: %d", err);
}
static void ext_prop_read_cb(bool success, uint8_t att_ecode,
if (desc_count == 0)
goto failed;
- util_debug(client->debug_callback, client->debug_data,
- "Descriptors found: %u", desc_count);
+ DBG(client, "Descriptors found: %u", desc_count);
bt_uuid16_create(&ext_prop_uuid, GATT_CHARAC_EXT_PROPER_UUID);
/* Log debug message */
bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str));
- util_debug(client->debug_callback, client->debug_data,
- "handle: 0x%04x, uuid: %s",
- handle, uuid_str);
+
+ DBG(client, "handle: 0x%04x, uuid: %s", handle, uuid_str);
attr = gatt_db_insert_descriptor(client->db, handle,
&uuid, 0, NULL, NULL,
gatt_db_attribute_get_type(attr)))
continue;
- util_debug(client->debug_callback, client->debug_data,
- "Failed to insert descriptor at 0x%04x",
+ DBG(client, "Failed to insert descriptor at 0x%04x",
handle);
goto failed;
}
goto failed;
chrc_count = bt_gatt_result_characteristic_count(result);
- util_debug(client->debug_callback, client->debug_data,
- "Characteristics found: %u", chrc_count);
+
+ DBG(client, "Characteristics found: %u", chrc_count);
if (chrc_count == 0)
goto failed;
/* 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, value: 0x%04x, "
+ DBG(client, "start: 0x%04x, end: 0x%04x, value: 0x%04x, "
"props: 0x%02x, uuid: %s",
start, end, value, properties, uuid_str);
if (client->discovery_req)
return;
- util_debug(client->debug_callback, client->debug_data,
- "Failed to start included services discovery");
+ DBG(client, "Failed to start included services discovery");
discovery_op_unref(op);
/* 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",
+ DBG(client, "start: 0x%04x, end: 0x%04x, uuid: %s",
start, end, uuid_str);
/* Store the service */
attr = gatt_db_insert_service(client->db, start, &uuid,
false, end - start + 1);
if (!attr) {
- util_debug(client->debug_callback,
- client->debug_data,
- "Failed to store service");
+ DBG(client, "Failed to store service");
return false;
}
/* Database has changed adjust last handle */
att_ecode = 0;
goto next;
default:
- util_debug(client->debug_callback, client->debug_data,
- "Secondary service discovery failed."
+ DBG(client, "Secondary service discovery failed."
" ATT ECODE: 0x%02x", att_ecode);
goto done;
}
goto done;
}
- util_debug(client->debug_callback, client->debug_data,
- "Secondary services found: %u",
+ DBG(client, "Secondary services found: %u",
bt_gatt_result_service_count(result));
if (!discovery_parse_services(op, false, &iter)) {
if (client->discovery_req)
return;
- util_debug(client->debug_callback, client->debug_data,
- "Failed to start included services discovery");
+ DBG(client, "Failed to start included services discovery");
+
discovery_op_unref(op);
success = false;
att_ecode = 0;
goto secondary;
default:
- util_debug(client->debug_callback, client->debug_data,
- "Primary service discovery failed."
+ DBG(client, "Primary service discovery failed."
" ATT ECODE: 0x%02x", att_ecode);
goto done;
}
goto done;
}
- util_debug(client->debug_callback, client->debug_data,
- "Primary services found: %u",
+ DBG(client, "Primary services found: %u",
bt_gatt_result_service_count(result));
if (!discovery_parse_services(op, true, &iter)) {
if (client->discovery_req)
return;
- util_debug(client->debug_callback, client->debug_data,
- "Failed to start secondary service discovery");
+ DBG(client, "Failed to start secondary service discovery");
+
discovery_op_unref(op);
success = false;
if (client->discovery_req)
return;
- util_debug(client->debug_callback, client->debug_data,
- "Failed to initiate primary service discovery");
+ DBG(client, "Failed to initiate primary service discovery");
client->in_init = false;
notify_client_ready(client, false, BT_ATT_ERROR_UNLIKELY);
{
struct bt_gatt_client *client = user_data;
- util_debug(client->debug_callback, client->debug_data,
- "Value set status: %d", err);
+ DBG(client, "Value set status: %d", err);
}
static void db_hash_read_value_cb(struct gatt_db_attribute *attrib,
bt_gatt_iter_init(&iter, result);
bt_gatt_iter_next_read_by_type(&iter, &handle, &len, &value);
- util_debug(client->debug_callback, client->debug_data,
- "DB Hash found: handle 0x%04x length 0x%04x",
- handle, len);
+ DBG(client, "DB Hash found: handle 0x%04x length 0x%04x",
+ handle, len);
if (len != 16)
goto discover;
/* Check if the has has changed since last time */
if (hash && !memcmp(hash, value, len)) {
- util_debug(client->debug_callback, client->debug_data,
- "DB Hash match: skipping discovery");
+ DBG(client, "DB Hash match: skipping discovery");
queue_remove_all(op->pending_svcs, NULL, NULL, NULL);
discovery_op_complete(op, true, 0);
return;
}
- util_debug(client->debug_callback, client->debug_data,
- "DB Hash value:");
+ DBG(client, "DB Hash value:");
+
util_hexdump(' ', value, len, client->debug_callback,
client->debug_data);
bt_gatt_iter_init(&iter, result);
bt_gatt_iter_next_read_by_type(&iter, &handle, &len, &value);
- util_debug(client->debug_callback, client->debug_data,
- "Server Features found: handle 0x%04x "
+ DBG(client, "Server Features found: handle 0x%04x "
"length 0x%04x value 0x%02x", handle, len,
value[0]);
client->mtu_req_id = 0;
if (!success) {
- util_debug(client->debug_callback, client->debug_data,
- "MTU Exchange failed. ATT ECODE: 0x%02x",
+ DBG(client, "MTU Exchange failed. ATT ECODE: 0x%02x",
att_ecode);
/*
return;
}
- util_debug(client->debug_callback, client->debug_data,
- "att client MTU exchange complete, with MTU: %u",
+ DBG(client, "MTU exchange complete, with MTU: %u",
bt_att_get_mtu(client->att));
discover:
struct bt_gatt_client *client = user_data;
if (att_ecode) {
- util_debug(client->debug_callback, client->debug_data,
+ DBG(client,
"Failed to register handler for \"Service Changed\"");
success = false;
client->svc_chngd_ind_id = 0;
client->svc_chngd_registered = true;
success = true;
- util_debug(client->debug_callback, client->debug_data,
- "Registered handler for \"Service Changed\": %u",
+ DBG(client, "Registered handler for \"Service Changed\": %u",
client->svc_chngd_ind_id);
done:
client->in_svc_chngd = false;
if (!success && att_ecode != BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND) {
- util_debug(client->debug_callback, client->debug_data,
+ DBG(client,
"Failed to discover services within changed range - "
"error: 0x%02x", att_ecode);
if (register_service_changed(client))
return;
- util_debug(client->debug_callback, client->debug_data,
+ DBG(client,
"Failed to re-register handler for \"Service Changed\"");
}
discovery_op_free(op);
fail:
- util_debug(client->debug_callback, client->debug_data,
- "Failed to initiate service discovery"
- " after Service Changed");
+ DBG(client,
+ "Failed to initiate service discovery after Service Changed");
}
static void service_changed_cb(uint16_t value_handle, const uint8_t *value,
end = get_le16(value + 2);
if (start > end) {
- util_debug(client->debug_callback, client->debug_data,
+ DBG(client,
"Service Changed received with invalid handles");
return;
}
- util_debug(client->debug_callback, client->debug_data,
- "Service Changed received - start: 0x%04x end: 0x%04x",
+ DBG(client, "Service Changed received - start: 0x%04x end: 0x%04x",
start, end);
if (!client->in_svc_chngd) {
{
struct bt_gatt_client *client = user_data;
- util_debug(client->debug_callback, client->debug_data,
- "Server Features Value set status: %d", err);
+ DBG(client, "Server Features Value set status: %d", err);
}
static void write_server_features(struct bt_gatt_client *client, uint8_t feat)
if (!gatt_db_attribute_write(attr, 0, &feat, sizeof(feat),
0, NULL, server_feat_write_value,
client))
- util_debug(client->debug_callback, client->debug_data,
- "Unable to store Server Features");
+ DBG(client, "Unable to store Server Features");
}
static void write_client_features(struct bt_gatt_client *client)
client->features |= BT_GATT_CHRC_CLI_FEAT_NFY_MULTI;
- util_debug(client->debug_callback, client->debug_data,
- "Writing Client Features 0x%02x", client->features);
+ DBG(client, "Writing Client Features 0x%02x", client->features);
bt_gatt_client_write_value(client, handle, &client->features,
sizeof(client->features), NULL, NULL, NULL);
if (register_service_changed(client))
goto done;
- util_debug(client->debug_callback, client->debug_data,
- "Failed to register handler for \"Service Changed\"");
+ DBG(client, "Failed to register handler for \"Service Changed\"");
success = false;
fail:
- util_debug(client->debug_callback, client->debug_data,
- "Failed to initialize gatt-client");
+ DBG(client, "Failed to initialize gatt-client");
op->success = false;
* prepare writes or this is brand new reliable session (id == 0)
*/
if (id != client->reliable_write_session_id) {
- util_debug(client->debug_callback, client->debug_data,
- "There is other reliable write session ongoing %u",
+ DBG(client, "There is other reliable write session ongoing %u",
client->reliable_write_session_id);
return 0;