[TDS] Modify ReadValue and WriteValue API's 93/146393/3 accepted/tizen/4.0/unified/20170905.175107 accepted/tizen/unified/20170830.160938 submit/tizen/20170829.085542 submit/tizen_4.0/20170905.000523
authorAnupam Roy <anupam.r@samsung.com>
Mon, 28 Aug 2017 09:17:42 +0000 (14:47 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Mon, 28 Aug 2017 09:45:25 +0000 (15:15 +0530)
GATT ReadValue and WriteValue API's are
modified by Bluez upstream while moving the
GATT DBUS API's from EXPERIMENTAL to STABLE.

Accordingly, TDS Seeker API's are modified in
this patch to match latest ReadValue and
WriteValue API's.

Change-Id: I94316fe1212f38bcafad0345669182b248f8a44a
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-api/bt-event-handler.c
bt-api/bt-request-sender.c
bt-service/bt-service-tds.c

index 141c706..f1cb967 100644 (file)
@@ -2988,8 +2988,8 @@ static void __bt_tds_event_filter(GDBusConnection *connection,
                ind_res.tds_data.length = g_variant_get_size(byte_var);
 
                buffer = (char *) g_variant_get_data(byte_var);
+               BT_DBG("[len = %d]", ind_res.tds_data.length);
                memcpy(ind_res.tds_data.data, buffer, ind_res.tds_data.length);
-               g_free(buffer);
 
                _bt_convert_addr_string_to_type(ind_res.rem_addr.addr, address);
 
index 2a00c51..258182e 100644 (file)
@@ -243,7 +243,7 @@ static void __bt_get_event_info(int service_function, GArray *output,
                break;
        case BT_TDS_ACTIVATE_CONTROL_POINT:
                *event_type = BT_TDS_EVENT;
-               *event = BLUETOOTH_EVENT_TDS_ACTIVATION_INDICATION;
+               *event = BLUETOOTH_EVENT_TDS_ACTIVATION_RESULT;
                ret_if(output == NULL);
                *param_data = &g_array_index(output,
                        bluetooth_device_address_t, 0);
index b7c4099..fc4dc03 100644 (file)
@@ -1312,6 +1312,8 @@ int _bt_tds_read_transport_data(int request_id, char *sender,
        GDBusConnection *conn;
        char *address = NULL;
        bt_tds_data_read_req_info *info = NULL;
+       GVariantBuilder *builder = NULL;
+       guint16 offset = 0;
 
        BT_CHECK_PARAMETER(handle, return);
        BT_CHECK_PARAMETER(sender, return);
@@ -1331,12 +1333,15 @@ int _bt_tds_read_transport_data(int request_id, char *sender,
                return BLUETOOTH_ERROR_IN_PROGRESS;
        }
 
-       g_dbus_connection_call(conn,
-                       BT_BLUEZ_NAME,
-                       handle,
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+       /*offset*/
+       g_variant_builder_add(builder, "{sv}", "offset",
+                       g_variant_new("q", offset));
+
+       g_dbus_connection_call(conn, BT_BLUEZ_NAME, handle,
                        GATT_DESC_INTERFACE,
                        "ReadValue",
-                       NULL,
+                       g_variant_new("(a{sv})", builder),
                        G_VARIANT_TYPE("(ay)"),
                        G_DBUS_CALL_FLAGS_NONE,
                        -1,
@@ -1344,6 +1349,8 @@ int _bt_tds_read_transport_data(int request_id, char *sender,
                        (GAsyncReadyCallback)__bt_tds_transport_data_read_desc_cb,
                        (gpointer)address);
 
+       g_variant_builder_unref(builder);
+
        /* Save Info in pending list */
        info = g_malloc0(sizeof(bt_tds_data_read_req_info));
        info->remote_address = g_strdup(address);
@@ -1497,6 +1504,24 @@ int _bt_tds_enable_control_point(int request_id, char *sender, bluetooth_device_
        return BLUETOOTH_ERROR_NONE;
 }
 
+static int __bluetooth_get_att_error_code(GError *error)
+{
+       int att_ecode = 0;
+       int len;
+       char *str = NULL;
+
+       BT_ERR("Error : %s", error->message);
+       str = g_strrstr(error->message, "ATT error: 0x");
+       if (str) {
+               len = strlen(str);
+               att_ecode =  g_ascii_xdigit_value(str[len-2]) << 4;
+               att_ecode += g_ascii_xdigit_value(str[len-1]);
+       } else
+               return BLUETOOTH_ATT_ERROR_INTERNAL;
+
+       return att_ecode;
+}
+
 static void __bluetooth_internal_activation_request_cb(GObject *source_object,
                        GAsyncResult *res, gpointer user_data)
 {
@@ -1506,7 +1531,6 @@ static void __bluetooth_internal_activation_request_cb(GObject *source_object,
        GVariant *param = NULL;
        GVariant *out_param1 = NULL;
        int result = BLUETOOTH_ERROR_NONE;
-       guint8 att_ecode = 0;
        char *address = NULL;
        bt_tds_activation_info *info = NULL;
        request_info_t *req_info = NULL;
@@ -1516,16 +1540,8 @@ static void __bluetooth_internal_activation_request_cb(GObject *source_object,
        system_gconn = _bt_gdbus_get_system_gconn();
        value = g_dbus_connection_call_finish(system_gconn, res, &error);
 
-       if (error) {
-               BT_ERR("Error : %s \n", error->message);
-               result = BLUETOOTH_ERROR_INTERNAL;
-       } else {
-               g_variant_get(value, "(y)", &att_ecode);
-               if (att_ecode) {
-                       result =  BLUETOOTH_ERROR_INTERNAL;
-                       BT_ERR("ATT Error code: %d \n", att_ecode);
-               }
-       }
+       if (error)
+               result = __bluetooth_get_att_error_code(error);
 
        address = (char *)user_data;
        info = __bt_tds_activation_info_by_address(address);
@@ -1603,7 +1619,10 @@ int _bt_tds_activate_control_point(int request_id, char *sender, bluetooth_devic
                                        char *handle, unsigned char *param, int length)
 {
        GVariant *val;
-       GVariantBuilder *builder;
+       GVariantBuilder *builder1;
+       GVariant *options;
+       GVariantBuilder *builder2;
+       guint16 offset = 0;
        int i;
        bt_tds_activation_info *info = NULL;
        GDBusConnection *conn;
@@ -1630,12 +1649,19 @@ int _bt_tds_activate_control_point(int request_id, char *sender, bluetooth_devic
                return BLUETOOTH_ERROR_IN_PROGRESS;
        }
 
-       builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+       builder1 = g_variant_builder_new(G_VARIANT_TYPE("ay"));
 
        for (i = 0; i < length; i++)
-               g_variant_builder_add(builder, "y", param[i]);
+               g_variant_builder_add(builder1, "y", param[i]);
+
+       val = g_variant_new("ay", builder1);
+
+       builder2 = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+       /*offset*/
+       g_variant_builder_add(builder2, "{sv}", "offset",
+                       g_variant_new_uint16(offset));
 
-       val = g_variant_new("(ay)", builder);
+       options = g_variant_new("a{sv}", builder2);
 
        /* Activate Control Point */
        g_dbus_connection_call(conn,
@@ -1643,14 +1669,16 @@ int _bt_tds_activate_control_point(int request_id, char *sender, bluetooth_devic
                        handle,
                        GATT_CHAR_INTERFACE,
                        "WriteValue",
-                       val,
-                       G_VARIANT_TYPE("(y)"),
+                       g_variant_new("(@ay@a{sv})",
+                               val, options),
+                       NULL,
                        G_DBUS_CALL_FLAGS_NONE,
                        -1, NULL,
                        (GAsyncReadyCallback)__bluetooth_internal_activation_request_cb,
                        (gpointer)address);
 
-       g_variant_builder_unref(builder);
+       g_variant_builder_unref(builder1);
+       g_variant_builder_unref(builder2);
 
        if (info == NULL) {
                info = g_malloc0(sizeof(bt_tds_activation_info));