From 32bc30cfb73bc9bb5d7995b76bcfd92750255d48 Mon Sep 17 00:00:00 2001 From: Gowtham Anandha Babu Date: Wed, 5 Jul 2017 19:24:13 +0530 Subject: [PATCH] [OTP] Fix object type uuid format According to spec, object type UUID should be 16/32/128 bits. Change-Id: Ice83951e6963374e0bd4966f7b3dc5428dcf12a8 Signed-off-by: Gowtham Anandha Babu --- bt-otp/bt-otpserver.c | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/bt-otp/bt-otpserver.c b/bt-otp/bt-otpserver.c index c68068d..f283dd0 100644 --- a/bt-otp/bt-otpserver.c +++ b/bt-otp/bt-otpserver.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "bt-otpserver.h" #include "bluetooth-api.h" @@ -1239,15 +1240,42 @@ fail: return BLUETOOTH_ERROR_NONE; } -void convert_to_hex(struct object_metadata *object, char *type, char *value) +void convert_to_hex(struct object_metadata *object, char *metadata, char *value) { struct tm fc_tm; - BT_DBG("type : %s", type); + BT_DBG("Metadata : %s", metadata); - memset(value, 0, 8); + memset(value, 0, 16); - if (!g_strcmp0(type, "size")) { + if (!g_strcmp0(metadata, "type")) { + /* Convert UUID string to 128 bit UUID */ + uint32_t data0, data4; + uint16_t data1, data2, data3, data5; + + if (!object->type || sscanf(object->type, + "%08x-%04hx-%04hx-%04hx-%08x%04hx", + &data0, &data1, &data2, + &data3, &data4, &data5) != 6) { + BT_ERR("Object Type UUID not updated"); + return; + } + + data0 = htonl(data0); + data1 = htons(data1); + data2 = htons(data2); + data3 = htons(data3); + data4 = htonl(data4); + data5 = htons(data5); + + memcpy(value, &data0, 4); + memcpy(value+4, &data1, 2); + memcpy(value+6, &data2, 2); + memcpy(value+8, &data3, 2); + memcpy(value+10, &data4, 4); + memcpy(value+14, &data5, 2); + + } else if (!g_strcmp0(metadata, "size")) { value[3] = (object->curr_size >> 24) & 0xFF; value[2] = (object->curr_size >> 16) & 0xFF; @@ -1259,7 +1287,7 @@ void convert_to_hex(struct object_metadata *object, char *type, char *value) value[5] = (object->alloc_size >> 8) & 0xFF; value[4] = object->alloc_size & 0xFF; - } else if (!g_strcmp0(type, "date")) { + } else if (!g_strcmp0(metadata, "date")) { localtime_r(&(object->first_created), &fc_tm); @@ -1271,7 +1299,7 @@ void convert_to_hex(struct object_metadata *object, char *type, char *value) value[5] = fc_tm.tm_min & 0xFF; value[6] = fc_tm.tm_sec & 0xFF; - } else if (!g_strcmp0(type, "id")) { + } else if (!g_strcmp0(metadata, "id")) { value[5] = (object->id >> 48) & 0xFF; value[4] = (object->id >> 32) & 0xFF; @@ -1280,7 +1308,7 @@ void convert_to_hex(struct object_metadata *object, char *type, char *value) value[1] = (object->id >> 8) & 0xFF; value[0] = object->id & 0xFF; - } else if (!g_strcmp0(type, "props")) { + } else if (!g_strcmp0(metadata, "props")) { value[3] = (object->props >> 24) & 0xFF; value[2] = (object->props >> 16) & 0xFF; value[1] = (object->props >> 8) & 0xFF; @@ -1290,13 +1318,14 @@ void convert_to_hex(struct object_metadata *object, char *type, char *value) void update_obj_metadata_charc_value(struct object_metadata *object) { - /* Value can be of maximum eight bytes */ - char value[8]; + /* Value can be of maximum 16 bytes */ + char value[16]; _bt_otp_set_char_value(otp_object_name_obj_path, object->name, strlen(object->name)); - _bt_otp_set_char_value(otp_object_type_obj_path, object->type, - strlen(object->type)); + + convert_to_hex(object, "type", value); + _bt_otp_set_char_value(otp_object_type_obj_path, value, 16); convert_to_hex(object, "size", value); _bt_otp_set_char_value(otp_object_size_obj_path, value, 8); -- 2.7.4