Modify firmware API 73/151273/3
authorhhk86.heo <hhk86.heo@samsung.com>
Wed, 20 Sep 2017 09:22:46 +0000 (18:22 +0900)
committerheo hyungkang <hhk86.heo@samsung.com>
Thu, 21 Sep 2017 05:40:11 +0000 (05:40 +0000)
- Add API : fmwup_set_firmware_resource_value (update, update time property)
- Change API : increase parameter of state_changed_cb for newfirmware
- Change naming of API : fmwup_unset_resource_changed_cb -> fmwup_unset_state_changed_cb
- Add code : init package property when update done.

Change-Id: Ide498d2b8d96506bb73ee65ac6afd092d03a1247

inc/fmwup_resource.h
inc/fmwup_resource_internal.h
src/fmwup_resource.c
src/fmwup_resource_internal.c
test/CMakeLists.txt
test/fmwup_test.c

index 00b66b3f6c5e8e2d83b6a8140b298f94cddceec2..a0a82092a74b26c15bcdeb18d58e34679d72c451 100644 (file)
@@ -36,10 +36,15 @@ typedef enum {
 
 
 typedef enum {
+       /* GET */
        FMWUP_RES_UPDATE_STATE = 0,
        FMWUP_RES_UPDATE_RESULT,
        FMWUP_RES_CURRENT_VERSION,
-       FMWUP_RES_NEW_VERSION
+       FMWUP_RES_NEW_VERSION,
+
+       /* SET */
+       FMWUP_RES_UPDATE,
+       FMWUP_RES_UPDATE_TIME
 }fmwup_res_type_e;
 
 typedef enum {
@@ -76,7 +81,7 @@ typedef enum {
 } firmware_res_prop_e;
 #endif
 
-typedef void (*state_changed_cb)(fmwup_state_e value);
+typedef void (*state_changed_cb)(fmwup_state_e value, bool is_new_firmware);
 
 
 EXPORT_API int fmwup_create_firmware_resource(OCResourceHandle *firmware_res_h);
@@ -87,12 +92,14 @@ EXPORT_API int fmwup_set_firmware_download_path(const char *download_path);
 
 EXPORT_API int fmwup_set_state_changed_cb(state_changed_cb callback);
 
-EXPORT_API void fmwup_unset_resource_changed_cb(void);
+EXPORT_API void fmwup_unset_state_changed_cb(void);
 
 EXPORT_API int fmwup_get_newest_firmware_from_server();
 
 EXPORT_API int fmwup_get_firmware_resource_value(fmwup_res_type_e res_type, char **value);
 
+EXPORT_API int fmwup_set_firmware_resource_value(fmwup_res_type_e res_type, char *value);
+
 EXPORT_API int fmwup_check_firmware_upgraded(void);
 
 
index b62f2ff7092be34bcbd9b9a8bea19b8e39105600..3d34f2e2670721f3a35002f78022623d622c4f2f 100644 (file)
@@ -26,6 +26,7 @@
 #define OC_RSRVD_FIRMWARE_UPDATE                       "update"
 #define OC_RSRVD_FIRMWARE_PROGRESS                     "progress"
 #define OC_RSRVD_FIRMWARE_UPDATE_TIME          "updatetime"
+#define OC_RSRVD_FIRMWARE_DESCRIPTION          "description"
 
 #define OC_RSRVD_FIRMWARE_CURRENT_VERSION      "version"
 #define OC_RSRVD_FIRMWARE_NEW_VERSION          "newversion"
@@ -65,7 +66,8 @@ typedef struct {
     int result;                                        //[R][M] 0: Initial, 1: Success, 2: Not enough space, 3: Out of ram, 4: Connection lost, 5: Invalid binary, 6: Invalid uri, 7: Update failed, 8: Unsupported protocol
     int update;                                        //[RW][M] 0: Initial, 1: Download Image, 2: Upgrade Image, 3:Dwonload and Upgrade, 4 Scheduled Upgrade
     int progress;                                      //[R][O] 0-100 range based progress include downloading state.
-    int64_t update_time;                       //[RW][O] case of (4 – update) (scheduled)  TODO: ISO 8601
+    char *update_time;                 //[RW][O] case of (4 – update) (scheduled)  TODO: ISO 8601
+    char *description;                 //[RW][O] Description
 
     /* Package Information */
     char *current_version;             //[R][M] Current firmware version
@@ -117,9 +119,11 @@ OCEntityHandlerResult fmwup_handle_firmware_entity(OCEntityHandlerFlag flag,
 
 void fmwup_get_firmware_info(fmwup_s *firmware_info);
 
+int fmwup_update_command(int64_t update_type);
+
 void fmwup_propagate_firmware_resource(void);
 
-void fmwup_propagate_firmware_status_resource(fmwup_update_property_e state, fmwup_result_property_e result);
+void fmwup_propagate_firmware_status_resource(fmwup_update_property_e state, fmwup_result_property_e result, bool is_new_firwmare);
 
 int fmwup_http_send_request(fmwup_http_req_e type, char *req_url, char **res_header, char **res_body);
 
index 24e336807ec5b796e722628a3a0118bfea86bc51..eb02617582b698b93d315f44a6c59efd5804eb45 100644 (file)
@@ -88,7 +88,7 @@ int fmwup_set_state_changed_cb(state_changed_cb callback)
        return FMWUP_SUCCESS;
 }
 
-void fmwup_unset_resource_changed_cb(void)
+void fmwup_unset_state_changed_cb(void)
 {
        g_state_changed_cb = NULL;
 }
@@ -144,6 +144,56 @@ int fmwup_get_firmware_resource_value(fmwup_res_type_e res_type, char **value)
 }
 
 
+int fmwup_set_firmware_resource_value(fmwup_res_type_e res_type, char *value)
+{
+       if (!g_firmware_resource) {
+               FWR_LOGE("g_firmware_resource is NULL");
+               return FMWUP_NULL_PTR;
+       }
+
+       if (value == NULL) {
+               FWR_LOGE("value is NULL");
+               return FMWUP_INVALID_VALUE;
+       }
+
+       int result = FMWUP_SUCCESS;
+
+       switch (res_type) {
+       case FMWUP_RES_UPDATE:
+           if (value == NULL || (value && strlen(value) != 1)) {
+               result = FMWUP_INVALID_VALUE;
+               FWR_LOGE("value is invalid");
+               break;
+           }
+       FWR_LOGI("value is [%s]", value);
+
+           int64_t update = (int64_t)atoi(value);
+               if (fmwup_update_command(update) != 0) {
+                       result = FMWUP_MEMORY_ERR;
+                       FWR_LOGE("allocate failed");
+               }
+               break;
+
+       case FMWUP_RES_UPDATE_TIME:
+               if (g_strcmp0(value, g_firmware_resource->update_time)) {
+                       g_free(g_firmware_resource->update_time);
+                       g_firmware_resource->update_time = g_strdup(value);
+               } else {
+                       result = FMWUP_ALREADY_EXIST;
+                       FWR_LOGI("Invalid res_type[%d]", res_type);
+               }
+               break;
+
+       default :
+               result = FMWUP_INVALID_VALUE;
+               FWR_LOGI("Invalid res_type[%d]", res_type);
+               break;
+       }
+
+       return result;
+}
+
+
 int fmwup_check_firmware_upgraded(void)
 {
        if (!g_firmware_resource) {
@@ -154,8 +204,24 @@ int fmwup_check_firmware_upgraded(void)
        if (g_firmware_resource->state == FMWUP_STATE_UPDATING) {
                FWR_LOGD("***Firmware Upgrade Done***");
 
+               /* Initialize - new firmware information - */
+               g_free(g_firmware_resource->new_version);
+               g_firmware_resource->new_version = g_strdup("");
+               vconf_set_str(VCONF_FIRMWARE_UPDATE_PACKAGE_NEW_VERSION, "");
+
+               g_free(g_firmware_resource->package_uri);
+               g_firmware_resource->package_uri = g_strdup("");
+               vconf_set_str(VCONF_FIRMWARE_UPDATE_PACKAGE_URL, "");
+
+               g_free(g_firmware_resource->package_md5);
+               g_firmware_resource->package_md5 = g_strdup("");
+               vconf_set_str(VCONF_FIRMWARE_UPDATE_PACKAGE_MD5, "");
+
+               g_firmware_resource->package_size = 0;
+               vconf_set_dbl(VCONF_FIRMWARE_UPDATE_PACKAGE_SIZE, (double)0);
+
                // TODO :: It should be checked and set result value according to upgrade result
-               fmwup_propagate_firmware_status_resource(FMWUP_STATE_IDLE, FMWUP_RESULT_SUCCESS);
+               fmwup_propagate_firmware_status_resource(FMWUP_STATE_IDLE, FMWUP_RESULT_SUCCESS, false);
 
        } else {
                FWR_LOGE("is not updating, state[%d]", g_firmware_resource->state);
index 61a32981ba32d477571cfb25a2506d8352b83bb0..f5234a8f65b9ffa8d008311de29913d29901d7f5 100644 (file)
@@ -106,7 +106,7 @@ void fmwup_propagate_firmware_resource(void)
 }
 
 
-void fmwup_propagate_firmware_status_resource(fmwup_update_property_e state, fmwup_result_property_e result)
+void fmwup_propagate_firmware_status_resource(fmwup_update_property_e state, fmwup_result_property_e result, bool is_new_firmware)
 {
 
        g_firmware_resource->state = state;
@@ -118,12 +118,12 @@ void fmwup_propagate_firmware_status_resource(fmwup_update_property_e state, fmw
        fmwup_propagate_firmware_resource();
 
        if (g_state_changed_cb) {
-               g_state_changed_cb(g_firmware_resource->state);
+               g_state_changed_cb(g_firmware_resource->state, is_new_firmware);
        }
 
        if (!(result == FMWUP_RESULT_INITIAL)) {
                //init state, result in failed case
-               g_firmware_resource->state = FMWUP_EXEC_IDLE;
+               g_firmware_resource->state = FMWUP_STATE_IDLE;
                g_firmware_resource->result = FMWUP_RESULT_INITIAL;
 
                vconf_set_int(VCONF_FIRMWARE_UPDATE_STATE, (const int)g_firmware_resource->state);
@@ -158,7 +158,7 @@ void _handle_update_command(int64_t update_type)
 
        if ((g_firmware_resource->state == FMWUP_STATE_IDLE) && (update_type == FMWUP_EXEC_DOWNLOAD || update_type == FMWUP_EXEC_DOWNLOAD_AND_UPGRADE)) {
                FWR_LOGD("***Downloading image from [%s] ***", g_firmware_resource->package_uri);
-               fmwup_propagate_firmware_status_resource(FMWUP_STATE_DOWNLOADING, FMWUP_RESULT_INITIAL);
+               fmwup_propagate_firmware_status_resource(FMWUP_STATE_DOWNLOADING, FMWUP_RESULT_INITIAL, true);
 
 #ifdef _USE_WWST_
 
@@ -202,12 +202,12 @@ void _handle_update_command(int64_t update_type)
 #endif
 
                FWR_LOGD("*** Firmware image downloaded ***");
-               fmwup_propagate_firmware_status_resource(FMWUP_STATE_DOWNLOADED, FMWUP_RESULT_INITIAL);
+               fmwup_propagate_firmware_status_resource(FMWUP_STATE_DOWNLOADED, FMWUP_RESULT_INITIAL, true);
        }
 
        if ((g_firmware_resource->state == FMWUP_STATE_DOWNLOADED) &&
                        (update_type == FMWUP_EXEC_UPGRADE || update_type == FMWUP_EXEC_DOWNLOAD_AND_UPGRADE)) {
-               fmwup_propagate_firmware_status_resource(FMWUP_STATE_UPDATING, FMWUP_RESULT_INITIAL);
+               fmwup_propagate_firmware_status_resource(FMWUP_STATE_UPDATING, FMWUP_RESULT_INITIAL, true);
 
                //TODO: To upgrade using interface of fota-client
                _exec_update();
@@ -215,7 +215,7 @@ void _handle_update_command(int64_t update_type)
 
 _END_OF_FUNC_:
        if (result != FMWUP_RESULT_INITIAL) {
-               fmwup_propagate_firmware_status_resource(FMWUP_STATE_IDLE, result);
+               fmwup_propagate_firmware_status_resource(FMWUP_STATE_IDLE, result, true);
        }
 
 #ifdef _USE_WWST_
@@ -247,7 +247,8 @@ OCRepPayload* _construct_response_of_firmware()
        OCRepPayloadSetPropInt(payload, OC_RSRVD_FIRMWARE_RESULT, (int64_t)g_firmware_resource->result);
        OCRepPayloadSetPropInt(payload, OC_RSRVD_FIRMWARE_UPDATE, (int64_t)g_firmware_resource->update);
        OCRepPayloadSetPropInt(payload, OC_RSRVD_FIRMWARE_PROGRESS, (int64_t)g_firmware_resource->progress);
-       OCRepPayloadSetPropInt(payload, OC_RSRVD_FIRMWARE_UPDATE_TIME, g_firmware_resource->update_time);
+       OCRepPayloadSetPropString(payload, OC_RSRVD_FIRMWARE_UPDATE_TIME, g_firmware_resource->update_time);
+       OCRepPayloadSetPropString(payload, OC_RSRVD_FIRMWARE_DESCRIPTION, g_firmware_resource->description);
 
        OCRepPayloadSetPropString(payload, OC_RSRVD_FIRMWARE_CURRENT_VERSION, g_firmware_resource->current_version);
        OCRepPayloadSetPropString(payload, OC_RSRVD_FIRMWARE_NEW_VERSION, g_firmware_resource->new_version);
@@ -276,6 +277,8 @@ void *_worker(void *data)
 
 void _update_firmware_resource(OCRepPayload *input)
 {
+
+       /* write to non volatile data - package info */
        char *new_firmware = NULL;
        if (OCRepPayloadGetPropString(input, OC_RSRVD_FIRMWARE_NEW_VERSION, &new_firmware)) {
                if (g_strcmp0(new_firmware, g_firmware_resource->new_version)) {
@@ -288,7 +291,6 @@ void _update_firmware_resource(OCRepPayload *input)
 
                char *package_uri = NULL;
                if (OCRepPayloadGetPropString(input, OC_RSRVD_FIRMWARE_PACKAGE_URI, &package_uri)) {
-                       FWR_LOGI("g_firmware_resource->package_uri = [%s]", package_uri);
                        if (g_strcmp0(package_uri, g_firmware_resource->package_uri)) {
                                g_free(g_firmware_resource->package_uri);
                                g_firmware_resource->package_uri = g_strdup(package_uri);
@@ -299,49 +301,85 @@ void _update_firmware_resource(OCRepPayload *input)
                } else {
                        FWR_LOGE("package_uri none");
                }
+
+               int64_t package_size;
+               if (OCRepPayloadGetPropInt(input, OC_RSRVD_FIRMWARE_PACKAGE_SIZE, &package_size)) {
+                       g_firmware_resource->package_size = package_size;
+                       vconf_set_dbl(VCONF_FIRMWARE_UPDATE_PACKAGE_SIZE, (double)package_size);
+                       FWR_LOGI("g_firmware_resource->package_size = [%lld]", package_size);
+               } else {
+                       FWR_LOGI("package_size none");
+               }
+
+               char *package_md5 = NULL;
+               if (OCRepPayloadGetPropString(input, OC_RSRVD_FIRMWARE_PACKAGE_MD5, &package_md5)) {
+                       if (g_strcmp0(package_md5, g_firmware_resource->package_md5)) {
+                               g_free(g_firmware_resource->package_md5);
+                               g_firmware_resource->package_md5 = g_strdup(package_md5);
+                               vconf_set_str(VCONF_FIRMWARE_UPDATE_PACKAGE_MD5, package_md5);
+                       }
+                       g_free(package_md5);
+                       FWR_LOGI("g_firmware_resource->package_md5 = [%s]", g_firmware_resource->package_md5);
+               } else {
+                       FWR_LOGI("package_md5 none");
+               }
+
+               if (g_state_changed_cb) {
+                       g_state_changed_cb(g_firmware_resource->state, true);
+               }
        }
 
-       int64_t package_size;
-       if (OCRepPayloadGetPropInt(input, OC_RSRVD_FIRMWARE_PACKAGE_SIZE, &package_size)) {
-               g_firmware_resource->package_size = package_size;
-               vconf_set_dbl(VCONF_FIRMWARE_UPDATE_PACKAGE_SIZE, (double)package_size);
-               FWR_LOGI("g_firmware_resource->package_size = [%lld]", package_size);
+
+       /* write to volatile data - update info */
+       char *update_time = NULL;
+       if (OCRepPayloadGetPropString(input, OC_RSRVD_FIRMWARE_UPDATE_TIME, &update_time)) {
+               if (g_strcmp0(update_time, g_firmware_resource->update_time)) {
+                       g_free(g_firmware_resource->update_time);
+                       g_firmware_resource->update_time = g_strdup(update_time);
+               }
+
+               g_free(update_time);
+               FWR_LOGI("g_firmware_resource->update_time = [%s]", g_firmware_resource->update_time);
+               /* TODO : Check Scheduled update , */
        }
 
-       char *package_md5 = NULL;
-       if (OCRepPayloadGetPropString(input, OC_RSRVD_FIRMWARE_PACKAGE_MD5, &package_md5)) {
-               if (g_strcmp0(package_md5, g_firmware_resource->package_md5)) {
-                       g_free(g_firmware_resource->package_md5);
-                       g_firmware_resource->package_md5 = g_strdup(package_md5);
-                       vconf_set_str(VCONF_FIRMWARE_UPDATE_PACKAGE_MD5, package_md5);
+       char *description = NULL;
+       if (OCRepPayloadGetPropString(input, OC_RSRVD_FIRMWARE_DESCRIPTION, &description)) {
+               if (g_strcmp0(description, g_firmware_resource->description)) {
+                       g_free(g_firmware_resource->description);
+                       g_firmware_resource->description = g_strdup(description);
                }
-               g_free(package_md5);
-               FWR_LOGI("g_firmware_resource->package_md5 = [%s]", g_firmware_resource->package_md5);
+
+               g_free(description);
+               FWR_LOGI("g_firmware_resource->description = [%s]", g_firmware_resource->description);
        }
 
-       int64_t update_time;
-       if (OCRepPayloadGetPropInt(input, OC_RSRVD_FIRMWARE_UPDATE_TIME, &update_time)) {
-               g_firmware_resource->update_time = update_time;
-               FWR_LOGI("g_firmware_resource->update_time = [%lld]", update_time);
-               /* TODO : Check Scheduled update , */
+       int64_t update;
+       if (OCRepPayloadGetPropInt(input, OC_RSRVD_FIRMWARE_UPDATE, &update)) {
+               FWR_LOGD("update command = [%lld]", update);
+               fmwup_update_command(update);
        }
 
+       fmwup_propagate_firmware_resource();
+}
+
+
+int fmwup_update_command(int64_t update_type)
+{
        int64_t *update = (int64_t *)calloc(1, sizeof(int64_t));
        if (!update) {
                FWR_LOGE("Memory allocation error!");
-               return;
+               return -1;
        }
 
-       if (OCRepPayloadGetPropInt(input, OC_RSRVD_FIRMWARE_UPDATE, update)) {
-               FWR_LOGD("update command = [%lld]", *update);
-               g_firmware_resource->update = *update;
-               pthread_t pThread;
-               pthread_create(&pThread, NULL, _worker, update);
-       } else {
-               g_free(update);
-       }
+       g_firmware_resource->update = (int)update_type;
 
-       fmwup_propagate_firmware_resource();
+       *update = update_type;
+
+       pthread_t pThread;
+       pthread_create(&pThread, NULL, _worker, update);
+
+       return 0;
 }
 
 
@@ -450,15 +488,17 @@ OCEntityHandlerResult fmwup_handle_firmware_entity(OCEntityHandlerFlag flag,
 
 void fmwup_get_firmware_info(fmwup_s *firmware_info)
 {
-       char *manufacturer = NULL;
-       char *model_name = NULL;
+       int update_state;
+       int update_result;
+
        char *cur_firmware_ver = NULL;
        char *new_firmware_ver = NULL;
        double package_size = 0;
        char *package_md5 = NULL;
        char *download_url = NULL;
-       int update_state;
-       int update_result;
+
+       char *manufacturer = NULL;
+       char *model_name = NULL;
 
 #if 1
     OCGetPropertyValue(PAYLOAD_TYPE_PLATFORM, OC_RSRVD_MFG_NAME, (void **)&manufacturer);
@@ -496,8 +536,8 @@ void fmwup_get_firmware_info(fmwup_s *firmware_info)
        package_md5 = vconf_get_str(VCONF_FIRMWARE_UPDATE_PACKAGE_MD5);
        download_url = vconf_get_str(VCONF_FIRMWARE_UPDATE_PACKAGE_URL);
 
-       FWR_LOGD("manufacturer=[%s]", manufacturer);
-       FWR_LOGD("model_name=[%s]", model_name);
+       FWR_LOGD("firmware_update_state=[%d]", update_state);
+       FWR_LOGD("firmware_update_result=[%d]", update_result);
 
        FWR_LOGD("firmware_ver=[%s]", cur_firmware_ver);
        FWR_LOGD("firmware_new_ver=[%s]", new_firmware_ver);
@@ -505,20 +545,23 @@ void fmwup_get_firmware_info(fmwup_s *firmware_info)
        FWR_LOGD("firmware_md5=[%s]", package_md5);
        FWR_LOGD("firmware_package_size=[%lld]", (int64_t)package_size);
 
-       FWR_LOGD("firmware_update_state=[%d]", update_state);
-       FWR_LOGD("firmware_update_result=[%d]", update_result);
+       FWR_LOGD("manufacturer=[%s]", manufacturer);
+       FWR_LOGD("model_name=[%s]", model_name);
 
-       firmware_info->manufacturer = g_strdup(manufacturer);
-       firmware_info->model_name = g_strdup(model_name);
+       firmware_info->state = update_state;
+       firmware_info->result = update_result;
+       firmware_info->update_time = g_strdup("");
+       firmware_info->description = g_strdup("");
 
        firmware_info->current_version = g_strdup(cur_firmware_ver);
        firmware_info->new_version = g_strdup(new_firmware_ver);
        firmware_info->package_uri = g_strdup(download_url);
-       firmware_info->package_md5 = g_strdup(package_md5);
        firmware_info->package_size = (int64_t)package_size;
+       firmware_info->package_md5 = g_strdup(package_md5);
+
+       firmware_info->manufacturer = g_strdup(manufacturer);
+       firmware_info->model_name = g_strdup(model_name);
 
-       firmware_info->state = update_state;
-       firmware_info->result = update_result;
 
        g_free(manufacturer);
        g_free(model_name);
index 24c4b06ef7d3ca1255d8a5d56dbea5b558164e73..439da6eae8526e117e999757f03f4cb4989fee3c 100644 (file)
@@ -1,7 +1,7 @@
 set(testapp "fmwup_test")
 
-ADD_DEFINITIONS(-D__WITH_DTLS__ -D__WITH_TLS__ -DRD_CLIENT -D_USE_WWST_)
-#ADD_DEFINITIONS(-DRD_CLIENT)
+#ADD_DEFINITIONS(-D__WITH_DTLS__ -D__WITH_TLS__ -DRD_CLIENT -D_USE_WWST_)
+ADD_DEFINITIONS(-DRD_CLIENT)
 
 SET(FMWUP_TEST_SRCS
     ${CMAKE_CURRENT_SOURCE_DIR}/fmwup_test.c
index bf9d7415d28556f4416b4a2b5da147161de58405..2c0a1839eb4aed7eb4670df9ad682f70c5800fd3 100644 (file)
@@ -1118,9 +1118,9 @@ int _destory_default_res()
 }
 
 
-static void _state_changed_cb(fmwup_state_e value)
+static void _state_changed_cb(fmwup_state_e value, bool is_new_firmware)
 {
-       printf("state_changed_cb [%d]\n", value);
+       printf("state_changed_cb state[%d], is_new_firmware[%d]\n", value, is_new_firmware);
 }
 
 
@@ -1136,7 +1136,7 @@ int _set_state_changed_cb()
 
 int _unset_state_changed_cb()
 {
-       fmwup_unset_resource_changed_cb();
+       fmwup_unset_state_changed_cb();
        return 0;
 }