From 7baa2961de13fdaa41531ec3f5092f41e0401fd5 Mon Sep 17 00:00:00 2001 From: Abhay agarwal Date: Thu, 26 Dec 2019 09:54:44 +0530 Subject: [PATCH] Set length for payload device uid Signed-off-by: Abhay agarwal --- include/ua-api.h | 12 +++++++++-- ua-daemon/data/ua_db.sql | 1 + ua-daemon/include/ua-manager-core.h | 2 ++ ua-daemon/src/pm/ua-pm-util.c | 10 +++++---- ua-daemon/src/ua-manager-core.c | 25 +++++++++++----------- ua-daemon/src/ua-manager-db.c | 1 + ua-daemon/src/ua-manager-device-service-db.c | 2 +- ua-daemon/src/ua-manager-payload-db.c | 31 +++++++++++++++------------- ua-plugins/include/ua-plugin.h | 2 ++ 9 files changed, 53 insertions(+), 33 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index f02da1c..26ab5c2 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -59,7 +59,13 @@ typedef enum { * @brief Device's BLE payload DEVICE_UID length. * @since_tizen 5.5 */ -#define UAM_BLE_PAYLOAD_DEVICE_UID_LEN 17 +#define UAM_BLE_PAYLOAD_DEVICE_UID_MAX_LEN 17 + +/** + * @brief Device's BLE payload user_data max length. + * @since_tizen 6.0 + */ +#define UAM_PAYLOAD_USER_DATA_MAX_LEN 17 /** * @brief Max. BT MAC address length. @@ -487,8 +493,10 @@ typedef struct { char primary_key; /** Primary Key */ char device_icon; /** Device icon */ char secondary_key; /** Purpose */ - char device_uid[UAM_BLE_PAYLOAD_DEVICE_UID_LEN + 1]; /** DEVICE_UID */ + int device_uid_len; /** Device uid length */ + char device_uid[UAM_BLE_PAYLOAD_DEVICE_UID_MAX_LEN + 1]; /** DEVICE_UID */ char bt_mac[UAM_BT_MAC_ADDRESS_STRING_LEN]; /** BT MAC Address */ + char user_data[UAM_PAYLOAD_USER_DATA_MAX_LEN + 1]; /** User Data */ } uam_ble_payload_s; /** diff --git a/ua-daemon/data/ua_db.sql b/ua-daemon/data/ua_db.sql index c83282d..ab1fe7b 100644 --- a/ua-daemon/data/ua_db.sql +++ b/ua-daemon/data/ua_db.sql @@ -44,6 +44,7 @@ CREATE TABLE IF NOT EXISTS payloads ( payload_number INTEGER PRIMARY KEY AUTOINCREMENT, primary_key TEXT, secondary_key TEXT, + device_uid_len INTEGER, device_uid TEXT, device_icon TEXT, device_number INTEGER, diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index 7e881f5..077f7a0 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -58,7 +58,9 @@ typedef struct { char primary_key; /** Primary key */ char device_icon; /** Device icon */ char secondary_key; /** Purpose */ + int device_uid_len; /** Device uid length */ char *device_uid; /** DEVICE_UID */ + char *user_data; /** User data */ char *bt_mac; /** BT MAC Address */ char *device_id; /**< Device ID */ uam_tech_type_e tech_type; /**< Connectivity type */ diff --git a/ua-daemon/src/pm/ua-pm-util.c b/ua-daemon/src/pm/ua-pm-util.c index b935548..be1e3f5 100644 --- a/ua-daemon/src/pm/ua-pm-util.c +++ b/ua-daemon/src/pm/ua-pm-util.c @@ -138,12 +138,12 @@ void _pm_util_uam_db_payload_to_uas_payload( dst_payload->primary_key = src_payload->primary_key; dst_payload->device_icon = src_payload->device_icon; dst_payload->secondary_key = src_payload->secondary_key; + dst_payload->device_uid_len = src_payload->device_uid_len; dst_payload->device_uid = g_memdup((src_payload->device_uid), - UAM_BLE_PAYLOAD_DEVICE_UID_LEN); + src_payload->device_uid_len); dst_payload->bt_mac = g_memdup((src_payload->bt_mac), UAM_BT_MAC_ADDRESS_STRING_LEN); } - UAM_DBG("payload primary key: [%d]", dst_payload->primary_key); } void _pm_util_uas_payload_to_uam_payload( @@ -153,14 +153,16 @@ void _pm_util_uas_payload_to_uam_payload( dst_payload->primary_key = src_payload->primary_key; dst_payload->device_icon = src_payload->device_icon; dst_payload->secondary_key = src_payload->secondary_key; + dst_payload->device_uid_len = src_payload->device_uid_len; + memset(dst_payload->device_uid, 0, src_payload->device_uid_len); + memset(dst_payload->bt_mac, 0, UAM_BT_MAC_ADDRESS_STRING_LEN); if (src_payload->device_uid) memcpy(dst_payload->device_uid, - src_payload->device_uid, UAM_BLE_PAYLOAD_DEVICE_UID_LEN); + src_payload->device_uid, src_payload->device_uid_len); if (src_payload->bt_mac) memcpy(dst_payload->bt_mac, src_payload->bt_mac, UAM_BT_MAC_ADDRESS_STRING_LEN); } - UAM_DBG("payload primary key: [%d]", dst_payload->primary_key); } void _pm_util_uas_device_info_free(uas_device_info_t *device) diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 7726818..c01a6a9 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -240,9 +240,11 @@ static void __print_svc_dev(gpointer data, gpointer user_data) void __print_payload(uam_ble_payload_s *payload) { ret_if(NULL == payload); - UAM_DBG("Payload primary key: [%d], secondary_key: [%d], device_icon: [%d]", - payload->primary_key, payload->secondary_key, payload->device_icon); - for (int i = 0; i < UAM_BLE_PAYLOAD_DEVICE_UID_LEN; i++) + UAM_DBG("Payload primary key: [%d], secondary_key: [%d], device_icon: [%d] " \ + "device uid len: [%d]", + payload->primary_key, payload->secondary_key, payload->device_icon, + payload->device_uid_len); + for (int i = 0; i < payload->device_uid_len; i++) UAM_DBG("Device uid [0x%2.2x]", payload->device_uid[i]); } @@ -702,11 +704,12 @@ static void __uam_copy_db_payload_info(uam_ble_payload_s *dst_payload, dst_payload->primary_key = src_payload->primary_key; dst_payload->device_icon = src_payload->device_icon; dst_payload->secondary_key = src_payload->secondary_key; - memset(dst_payload->device_uid, 0, UAM_BLE_PAYLOAD_DEVICE_UID_LEN + 1); + dst_payload->device_uid_len = src_payload->device_uid_len; + memset(dst_payload->device_uid, 0, src_payload->device_uid_len); memset(dst_payload->bt_mac, 0, UAM_BT_MAC_ADDRESS_STRING_LEN); if (src_payload->device_uid) memcpy(dst_payload->device_uid, - src_payload->device_uid, UAM_BLE_PAYLOAD_DEVICE_UID_LEN); + src_payload->device_uid, src_payload->device_uid_len); if (src_payload->bt_mac) memcpy(dst_payload->bt_mac, src_payload->bt_mac, UAM_BT_MAC_ADDRESS_STRING_LEN); @@ -720,8 +723,9 @@ static void __uam_copy_uam_payload_info( dst_payload->primary_key = src_payload->primary_key; dst_payload->device_icon = src_payload->device_icon; dst_payload->secondary_key = src_payload->secondary_key; + dst_payload->device_uid_len = src_payload->device_uid_len; dst_payload->device_uid = g_memdup(&(src_payload->device_uid), - UAM_BLE_PAYLOAD_DEVICE_UID_LEN); + src_payload->device_uid_len); dst_payload->bt_mac = g_memdup(&(src_payload->bt_mac), UAM_BT_MAC_ADDRESS_STRING_LEN); } @@ -2403,8 +2407,7 @@ int _uam_core_init(void) db_users = _uam_db_get_all_users(); if (!db_users) { UAM_INFO_C("No users in database"); - } - else { + } else { for (l = db_users; NULL != l; l = g_slist_next(l)) { db_user_info_t *info = l->data; uam_db_user_info_t *user; @@ -2426,8 +2429,7 @@ int _uam_core_init(void) db_svc_list = _uam_service_db_get_all_services(); if (!db_svc_list) { UAM_INFO_C("No services in database"); - } - else { + } else { for (l = db_svc_list; NULL != l; l = g_slist_next(l)) { db_service_info_t *db_svc = l->data; uam_db_service_info_t *service; @@ -2492,8 +2494,7 @@ int _uam_core_init(void) db_devices = _uam_device_db_get_all_devices(); if (!db_devices) { UAM_INFO_C("No Devices registered in database"); - } - else { + } else { for (l = db_devices; NULL != l; l = g_slist_next(l)) { db_device_info_t *db_info = l->data; uam_db_user_info_t *user; diff --git a/ua-daemon/src/ua-manager-db.c b/ua-daemon/src/ua-manager-db.c index de1a01d..a250c0f 100644 --- a/ua-daemon/src/ua-manager-db.c +++ b/ua-daemon/src/ua-manager-db.c @@ -58,6 +58,7 @@ "payload_number INTEGER PRIMARY KEY AUTOINCREMENT, " \ "primary_key TEXT, " \ "secondary_key TEXT, " \ + "device_uid_len INTEGER, " \ "device_uid TEXT, " \ "device_icon TEXT, " \ "device_number INTEGER, " \ diff --git a/ua-daemon/src/ua-manager-device-service-db.c b/ua-daemon/src/ua-manager-device-service-db.c index 2696b8d..f0e9a22 100644 --- a/ua-daemon/src/ua-manager-device-service-db.c +++ b/ua-daemon/src/ua-manager-device-service-db.c @@ -801,7 +801,7 @@ GSList *_uam_db_get_service_devices_info() buf = (char *)sqlite3_column_text(stmt, 7); if (buf) memcpy(info->payload_info.device_uid, buf, - UAM_BLE_PAYLOAD_DEVICE_UID_LEN); + UAM_BLE_PAYLOAD_DEVICE_UID_MAX_LEN); buf = (char *)sqlite3_column_text(stmt, 8); info->payload_info.device_icon = buf ? *buf : 1; diff --git a/ua-daemon/src/ua-manager-payload-db.c b/ua-daemon/src/ua-manager-payload-db.c index 8c60583..553d470 100644 --- a/ua-daemon/src/ua-manager-payload-db.c +++ b/ua-daemon/src/ua-manager-payload-db.c @@ -25,8 +25,8 @@ #include "ua-manager-database.h" #define SELECT_ALL_PAYLOADS "SELECT P.primary_key, P.secondary_key, " \ - "P.device_uid, P.device_icon, D.device_id, D.tech_type " \ - "FROM payloads as P JOIN devices as D USING(device_number)" + "P.device_uid_len, P.device_uid, P.device_icon, D.device_id, " \ + "D.tech_type FROM payloads as P JOIN devices as D USING(device_number)" #define SELECT_PAYLOAD_DEVICE "SELECT device_number FROM payloads " \ "where primary_key = ? AND secondary_key = ? AND device_uid = ?" @@ -34,7 +34,7 @@ "where primary_key = ? AND secondary_key = ? AND device_uid = ?" #define INSERT_PAYLOAD "insert into payloads (primary_key, " \ - "secondary_key, device_uid, device_icon, device_number)" \ + "secondary_key, device_uid_len, device_uid, device_icon, device_number)" \ "values (?, ?, ?, ?, ?)" #define DELETE_ALL_PAYLOADS "delete from payloads" @@ -258,11 +258,13 @@ int _uam_db_insert_payload_info( error_code, handle_error); DB_ACTION(sqlite3_bind_text(stmt, 2, &(payload->secondary_key), 1, SQLITE_TRANSIENT), error_code, handle_error); - DB_ACTION(sqlite3_bind_text(stmt, 3, payload->device_uid, UAM_BLE_PAYLOAD_DEVICE_UID_LEN + 1, SQLITE_TRANSIENT), + DB_ACTION(sqlite3_bind_int(stmt, 3, payload->device_uid_len), error_code, handle_error); - DB_ACTION(sqlite3_bind_text(stmt, 4, &(payload->device_icon), 1, SQLITE_TRANSIENT), + DB_ACTION(sqlite3_bind_text(stmt, 4, payload->device_uid, payload->device_uid_len, SQLITE_TRANSIENT), error_code, handle_error); - DB_ACTION(sqlite3_bind_int(stmt, 5, device_number), + DB_ACTION(sqlite3_bind_text(stmt, 5, &(payload->device_icon), 1, SQLITE_TRANSIENT), + error_code, handle_error); + DB_ACTION(sqlite3_bind_int(stmt, 6, device_number), error_code, handle_error); sql_ret = sqlite3_step(stmt); @@ -298,7 +300,7 @@ int _uam_db_get_payload_device_number(uam_ble_payload_s *payload, error_code, handle_error); DB_ACTION(sqlite3_bind_text(stmt, 2, &(payload->secondary_key), 1, SQLITE_TRANSIENT), error_code, handle_error); - DB_ACTION(sqlite3_bind_text(stmt, 3, payload->device_uid, UAM_BLE_PAYLOAD_DEVICE_UID_LEN + 1, SQLITE_TRANSIENT), + DB_ACTION(sqlite3_bind_text(stmt, 3, payload->device_uid, UAM_BLE_PAYLOAD_DEVICE_UID_MAX_LEN + 1, SQLITE_TRANSIENT), error_code, handle_error); do { @@ -339,7 +341,7 @@ int _uam_db_get_payload_number(uam_ble_payload_s *payload, error_code, handle_error); DB_ACTION(sqlite3_bind_text(stmt, 2, &(payload->secondary_key), 1, SQLITE_TRANSIENT), error_code, handle_error); - DB_ACTION(sqlite3_bind_text(stmt, 3, payload->device_uid, UAM_BLE_PAYLOAD_DEVICE_UID_LEN + 1, SQLITE_TRANSIENT), + DB_ACTION(sqlite3_bind_text(stmt, 3, payload->device_uid, UAM_BLE_PAYLOAD_DEVICE_UID_MAX_LEN + 1, SQLITE_TRANSIENT), error_code, handle_error); do { @@ -405,21 +407,22 @@ GSList *_uam_db_get_all_payloads(void) break; case SQLITE_ROW: info = g_new0(db_payload_info_t, 1); - memset(info->payload_info.device_uid, 0, UAM_BLE_PAYLOAD_DEVICE_UID_LEN + 1); + memset(info->payload_info.device_uid, 0, UAM_BLE_PAYLOAD_DEVICE_UID_MAX_LEN + 1); buf = (char *)sqlite3_column_text(stmt, 0); info->payload_info.primary_key = buf ? *buf : 13; buf = (char *)sqlite3_column_text(stmt, 1); info->payload_info.secondary_key = buf ? *buf : 1; - buf = (char *)sqlite3_column_text(stmt, 2); + info->payload_info.device_uid_len = sqlite3_column_int(stmt, 2); + buf = (char *)sqlite3_column_text(stmt, 3); if (buf) memcpy(info->payload_info.device_uid, buf, - UAM_BLE_PAYLOAD_DEVICE_UID_LEN); - buf = (char *)sqlite3_column_text(stmt, 3); + UAM_BLE_PAYLOAD_DEVICE_UID_MAX_LEN); + buf = (char *)sqlite3_column_text(stmt, 4); info->payload_info.device_icon = buf ? *buf : 1; - g_strlcpy(info->device_id, (char *)sqlite3_column_text(stmt, 4), + g_strlcpy(info->device_id, (char *)sqlite3_column_text(stmt, 5), UAM_DEVICE_ID_MAX_STRING_LEN); - info->type = sqlite3_column_int(stmt, 5); + info->type = sqlite3_column_int(stmt, 6); UAM_INFO("primary key: %d secondary key: %d", info->payload_info.primary_key, diff --git a/ua-plugins/include/ua-plugin.h b/ua-plugins/include/ua-plugin.h index 0059618..20fdbfe 100644 --- a/ua-plugins/include/ua-plugin.h +++ b/ua-plugins/include/ua-plugin.h @@ -104,8 +104,10 @@ typedef struct { char primary_key; /** Primary Key */ char device_icon; /** Device icon */ char secondary_key; /** Secondary key */ + int device_uid_len; /** Device uid len */ char *device_uid; /** DEVICE_UID */ char *bt_mac; /** BT MAC Address */ + char *user_data; /** User data */ } uas_payload_info_t; /* Device information structure */ -- 2.7.4