[Bluetooth][OTP-Client] Handle GATT operations for OTP
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-otp.c
index 85cf974..23eb5eb 100644 (file)
 #include "bt-request-sender.h"
 #include "bt-event-handler.h"
 
+static int _bluetooth_handle_get_len(const char *str)
+{
+       int i;
+       for (i = 0; str && str[i] != '\0'; i++);
+       return i;
+}
+
 BT_EXPORT_API int bluetooth_otp_server_init(const char *directory)
 {
        int result = BLUETOOTH_ERROR_INTERNAL;
@@ -78,4 +85,71 @@ BT_EXPORT_API int bluetooth_otp_server_deinit()
 
        BT_DBG("-");
        return result;
+}
+
+BT_EXPORT_API int bluetooth_otp_read_characteristic_value(const char *handle)
+{
+       char *path;
+       int path_len = 0;
+       bt_user_info_t *user_info;
+       int result = BLUETOOTH_ERROR_INTERNAL;
+       BT_DBG("+");
+
+       BT_CHECK_PARAMETER(handle, return);
+       BT_CHECK_ENABLED_LE(return);
+
+       user_info = _bt_get_user_data(BT_COMMON);
+       retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       path = g_strdup(handle);
+       path_len = _bluetooth_handle_get_len(path);
+       g_array_append_vals(in_param1, path, path_len);
+       g_free(path);
+
+       result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_OTP_READ_VALUE,
+                       in_param1, in_param2, in_param3, in_param4,
+                       user_info->cb, user_info->user_data);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       BT_DBG("-");
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_otp_enable_notification(const char *handle)
+{
+       char *path;
+       int path_len = 0;
+       bt_user_info_t *user_info;
+       int result = BLUETOOTH_ERROR_INTERNAL;
+       BT_DBG("+");
+
+       BT_CHECK_PARAMETER(handle, return);
+       BT_CHECK_ENABLED_LE(return);
+
+       user_info = _bt_get_user_data(BT_COMMON);
+       retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       path = g_strdup(handle);
+       path_len = _bluetooth_handle_get_len(path);
+       g_array_append_vals(in_param1, path, path_len);
+       g_free(path);
+
+       result = _bt_send_request_async(
+                                       BT_BLUEZ_SERVICE,
+                                       BT_OTP_ENABLE_NOTIFICATION,
+                                       in_param1, in_param2,
+                                       in_param3, in_param4,
+                                       user_info->cb, user_info->user_data);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       BT_DBG("-");
+       return result;
 }
\ No newline at end of file