Added feature : notification of GATT char Changed Value
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-gatt.c
index f80599f..3731335 100644 (file)
@@ -212,6 +212,7 @@ static void cb_gattc_write_characteristic(int conn_id, int status, btgatt_write_
 static void cb_gattc_write_descriptor(int conn_id, int status, btgatt_write_params_t *p_data);
 static void cb_gattc_register_for_notification(int conn_id, int registered, int status,
                        btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id);
+static void cb_gattc_notify(int conn_id, btgatt_notify_params_t *p_data);
 
 /*TODO GATT CLient callbacks will be implemented in subsequent patches */
 static const btgatt_client_callbacks_t btgatt_client_callbacks = {
@@ -225,7 +226,7 @@ static const btgatt_client_callbacks_t btgatt_client_callbacks = {
        cb_gattc_get_descriptor, /*cb_gattc_get_descriptor*/
        NULL, /*cb_gattc_get_included_service*/
        cb_gattc_register_for_notification, /*cb_gattc_register_for_notification*/
-       NULL, /*cb_gattc_notify*/
+       cb_gattc_notify, /*cb_gattc_notify*/
        cb_gattc_read_characteristic, /*cb_gattc_read_characteristic*/
        cb_gattc_write_characteristic, /*cb_gattc_write_characteristic*/
        cb_gattc_read_descriptor, /*cb_gattc_read_descriptor*/
@@ -1535,6 +1536,47 @@ static void cb_gattc_register_for_notification(int client_if, int registered, in
        send_event(event_type, event, sizeof(*event));
 }
 
+static void cb_gattc_notify(int conn_id, btgatt_notify_params_t *p_data)
+{
+       bdstr_t bdstr;
+       char uuid_str1[2*BT_UUID_STRING_MAX];
+       char uuid_str2[2*BT_UUID_STRING_MAX];
+
+       BT_INFO("BTGATT Client Notify Callback, conn_id:%d", conn_id);
+       BT_INFO("Server Address:[%s], is_notify:[%d], len:[%d]",
+               bdt_bd2str((bt_address_t *)&(p_data->bda), &bdstr), p_data->is_notify, p_data->len);
+
+       uuid_to_stringname((oal_uuid_t *)&(p_data->srvc_id.id.uuid), uuid_str1);
+       uuid_to_stringname((oal_uuid_t *)&(p_data->char_id.uuid), uuid_str2);
+
+       BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]",
+               uuid_str1, p_data->srvc_id.id.inst_id, p_data->srvc_id.is_primary ? "Primary" : "Secondary");
+       BT_INFO("Charac=> UUID: [%s], Inst_id: [%u]", uuid_str2, p_data->char_id.inst_id);
+
+       if (p_data->len > 0) {
+               char *data = NULL;
+               data = g_malloc(3*p_data->len+1);
+               if (!data) {
+                       BT_ERR("memory allocation failed");
+                       return;
+               }
+
+               convert_hex_2_str((unsigned char *)p_data->value, p_data->len, data);
+               BT_INFO("Notified Data: [%s]", data);
+
+               event_gattc_notify_data *event = g_new0(event_gattc_notify_data, 1);
+               memcpy(event->address.addr, p_data->bda.address, BT_ADDRESS_BYTES_NUM);
+               event->is_notify = p_data->is_notify;
+               event->data_len = p_data->len;
+               memcpy(event->data, p_data->value, event->data_len);
+               memcpy(&(event->char_id), &(p_data->char_id), sizeof(oal_gatt_id_t));
+               memcpy(&(event->srvc_id), &(p_data->srvc_id), sizeof(oal_gatt_srvc_id_t));
+
+               send_event_bda_trace(OAL_EVENT_GATTC_NOTIFY_DATA, event, sizeof(*event), (bt_address_t *)&p_data->bda);
+               g_free(data);
+       }
+}
+
 
 static void cb_gattc_read_characteristic(int conn_id, int status, btgatt_read_params_t *p_data)
 {