BLE Gatt Client Socket write and notify implementation
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / gatt / bt-service-gatt.c
index 2fc24ee..4448648 100644 (file)
@@ -1661,7 +1661,7 @@ static void __bt_handle_gatt_server_acquire_write_requested(event_gatts_srvc_acq
        struct gatt_server_req_info *req_info = NULL;
        bluetooth_device_address_t dev_addr;
        char  adress[BT_ADDRESS_STRING_SIZE] = {'/0',};
-       ;
+
        BT_INFO("GATT Server ACQUIRE  Write Req Connection ID: [%d]", event->attr_trans.conn_id);
        BT_INFO("GATT Server  ACQUIRE Write Req Transaction ID:[%d]", event->attr_trans.trans_id);
        BT_INFO("GATT Server ACQUIRE Write Req Attribute Handle: [%d]", event->attr_trans.attr_handle);
@@ -1686,7 +1686,6 @@ static void __bt_handle_gatt_server_acquire_write_requested(event_gatts_srvc_acq
                        event->mtu, event->attr_trans.offset, adress);
        BT_INFO("GATT Server ACQUIRE Write Req Attribute remote adress : [%s]", adress);
 
-
        _bt_send_event(BT_GATT_SERVER_EVENT,
                        BLUETOOTH_EVENT_GATT_SERVER_ACQUIRE_WRITE,
                        param);
@@ -4288,6 +4287,100 @@ int _bt_gatt_read_descriptor_value(
        return BLUETOOTH_ERROR_NONE;
 }
 
+/*acquire Notify*/
+int _bt_gatt_acquire_notify(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
+{
+       struct gatt_server_info_t *conn_info = NULL;
+       oal_gatt_srvc_id_t srvc_id;
+       oal_gatt_id_t char_id;
+       int ret = OAL_STATUS_SUCCESS;
+       char *addr;
+
+       BT_CHECK_PARAMETER(chr, return);
+
+       BT_INFO("+");
+
+       addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
+       _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
+
+       /* Check if remote GATT Server is connected or not */
+       conn_info = __bt_find_remote_gatt_server_info(addr);
+       if (conn_info) {
+               BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
+                               conn_info->addr, conn_info->connection_id);
+       } else {
+               BT_ERR("GATT Server is not yet connected..");
+               g_free(addr);
+               return BLUETOOTH_ERROR_NOT_CONNECTED;
+       }
+
+       srvc_id.is_prmry = TRUE;
+       srvc_id.id.inst_id = chr->svc.instance_id;
+       memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
+
+       char_id.inst_id = chr->characteristic.instance_id;
+       memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
+
+               ret = gattc_acquire_notify(conn_info->connection_id, &srvc_id, &char_id, fd, mtu);
+
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               g_free(addr);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       BT_INFO("GATT characterstics FD [%d]  mtu[%d]", *fd, *mtu);
+       g_free(addr);
+       return BLUETOOTH_ERROR_NONE;
+}
+
+/*acquire Write*/
+int _bt_gatt_acquire_write(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, int *mtu)
+{
+
+       struct gatt_server_info_t *conn_info = NULL;
+       oal_gatt_srvc_id_t srvc_id;
+       oal_gatt_id_t char_id;
+       int ret = OAL_STATUS_SUCCESS;
+       char *addr;
+
+       BT_CHECK_PARAMETER(chr, return);
+
+       BT_INFO("+");
+
+       addr = g_malloc0(sizeof(char) * BT_ADDRESS_STRING_SIZE);
+       _bt_convert_addr_type_to_string(addr, chr->device_address.addr);
+
+       /* Check if remote GATT Server is connected or not */
+       conn_info = __bt_find_remote_gatt_server_info(addr);
+       if (conn_info) {
+               BT_INFO("GATT Server [%s] is connected, conn Id [%d]",
+                               conn_info->addr, conn_info->connection_id);
+       } else {
+               BT_ERR("GATT Server is not yet connected..");
+               g_free(addr);
+               return BLUETOOTH_ERROR_NOT_CONNECTED;
+       }
+
+       srvc_id.is_prmry = TRUE;
+       srvc_id.id.inst_id = chr->svc.instance_id;
+       memcpy(srvc_id.id.uuid.uuid, chr->svc.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
+
+       char_id.inst_id = chr->characteristic.instance_id;
+       memcpy(char_id.uuid.uuid, chr->characteristic.uuid, BLUETOOTH_UUID_HEX_MAX_LEN);
+
+               ret = gattc_acquire_write(conn_info->connection_id, &srvc_id, &char_id,
+                                       OAL_GATT_AUTH_REQ_NONE, fd, mtu);
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               g_free(addr);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+       BT_INFO("GATT characterstics FD [%d]  mtu [%d]", *fd, *mtu);
+       g_free(addr);
+       return BLUETOOTH_ERROR_NONE;
+
+}
+
 
 /* Write Characteristic */
 int _bt_gatt_write_characteristic_value_by_type(