}
}
+static void __print_gatt_handler(bt_gatt_h gatt_handle)
+{
+ if (!gatt_handle) {
+ TC_PRT("Invalid handler");
+ return;
+ }
+
+ char *type;
+ char *role;
+ bt_gatt_common_s *handle = (bt_gatt_common_s *)gatt_handle;
+
+ if (handle->type == BT_GATT_TYPE_SERVICE)
+ type = g_strdup("Service");
+ else if (handle->type == BT_GATT_TYPE_CHARACTERISTIC)
+ type = g_strdup("Characteristic");
+ else if (handle->type == BT_GATT_TYPE_DESCRIPTOR)
+ type = g_strdup("Descriptor");
+ else
+ type = g_strdup("Unknown");
+
+ if (handle->role == BT_GATT_ROLE_SERVER)
+ role = g_strdup("Server");
+ else if (handle->role == BT_GATT_ROLE_CLIENT)
+ role = g_strdup("Client");
+ else
+ role = g_strdup("Unknown");
+
+ TC_PRT("GATT %s [%s]", type, role);
+ TC_PRT("%s [%s]", handle->path, handle->uuid);
+
+ g_free(type);
+ g_free(role);
+}
+
void __bt_gatt_server_read_value_requested_cb(
const char *remote_address, int request_id,
bt_gatt_server_h server, bt_gatt_h gatt_handle,
char char_value_1[3] = {0, 1, 2};
int resp_status = BT_ATT_ERROR_NONE;
- TC_PRT("__bt_gatt_server_read_value_requested_cb");
- TC_PRT("remote_address %s", remote_address);
- TC_PRT("req_id %d", request_id);
- TC_PRT("server %s", (char *)server);
- TC_PRT("gatt_handle %s", (char *)gatt_handle);
- TC_PRT("Offset %d", offset);
+ __print_gatt_handler(gatt_handle);
+ TC_PRT("[%s] req_id %d, offset %d", remote_address, request_id, offset);
+ printf("\n");
+
/* Get the attribute new values here */
bt_gatt_server_send_response(request_id,
BLUETOOTH_GATT_ATT_REQUEST_TYPE_READ, offset,
bt_gatt_server_h server, bt_gatt_h gatt_handle,
void *user_data)
{
- TC_PRT("__bt_gatt_server_notification_state_change_cb");
- TC_PRT("notify %d", notify);
+ __print_gatt_handler(gatt_handle);
+ TC_PRT("Notification %s [%d]", notify ? "enabled" : "disabled", notify);
TC_PRT("server %s", (char *)server);
- TC_PRT("gatt_handle %s", (char *)gatt_handle);
+ printf("\n\n");
+
}
const char *value, int len, void *user_data)
{
int i, resp_status = BT_ATT_ERROR_NONE;
- TC_PRT("remote_address : %s", remote_address);
- TC_PRT("Response needed : %d", response_needed);
- TC_PRT("offset : %d", offset);
- TC_PRT("len [%d] : ", len);
+
+ __print_gatt_handler(gatt_handle);
+ TC_PRT("[%s] req_id %d, response_needed %d, offset %d, len %d",
+ remote_address, request_id, response_needed, offset, len);
+
for (i = 0; i < len; i++)
printf("%d ", value[i]);
bt_gatt_h descriptor = NULL;
char *service_uuid = "000018f2-0000-1000-8000-00805f9b34fb";
char *char_uuid = "00002af6-0000-1000-8000-00805f9b34fb";
- char *desc_uuid = "00002a56-0000-1000-8000-00805f9b34fb";
+ char *desc_uuid = "2902"; // CCCD
char char_value[4] = {10, 20, 30, 40};
- char desc_value[4] = {12, 34, 56, 78};
+ char desc_value[2] = {0, 0}; // Notification disabled
int value_length = 4;
int permissions = BT_GATT_PERMISSION_READ | BT_GATT_PERMISSION_WRITE;
int properties = BT_GATT_PROPERTY_BROADCAST | BT_GATT_PROPERTY_READ |
&service);
TC_PRT("bt_gatt_service_create : %s \n", __bt_get_error_message(ret));
+ /* Read & Write & Notify characteristics UUID */
ret = bt_gatt_characteristic_create(char_uuid, permissions,
properties, char_value,
value_length, &characteristic);
bt_gatt_server_set_read_value_requested_cb(characteristic,
__bt_gatt_server_read_value_requested_cb, NULL);
+
+ ret = bt_gatt_server_set_write_value_requested_cb(characteristic,
+ __bt_gatt_server_write_value_requested_cb, NULL);
+
+ ret = bt_gatt_server_set_characteristic_notification_state_change_cb(characteristic,
+ __bt_gatt_server_notification_state_change_cb, NULL);
+
ret = bt_gatt_service_add_characteristic(service, characteristic);
TC_PRT("bt_gatt_service_add_characteristic : %s\n", __bt_get_error_message(ret));
+ /* CCCD for Notify characteristics */
ret = bt_gatt_descriptor_create(desc_uuid, permissions,
desc_value, value_length, &descriptor);
TC_PRT("bt_gatt_descriptor_create : %s\n", __bt_get_error_message(ret));
- bt_gatt_server_set_read_value_requested_cb(descriptor,
- __bt_gatt_server_read_value_requested_cb, NULL);
-
- ret = bt_gatt_server_set_write_value_requested_cb(descriptor,
- __bt_gatt_server_write_value_requested_cb,
- NULL);
-
ret = bt_gatt_characteristic_add_descriptor(characteristic, descriptor);
TC_PRT("bt_gatt_characteristic_add_descriptor : %s\n", __bt_get_error_message(ret));