(ehRequest->query && (g_strcmp0(ehRequest->query, "") && \
!_compare_resource_interface(ehRequest->query, OC_RSRVD_INTERFACE_DEFAULT))))
{
- FWR_LOGD("Not supported Interface");
+ FWR_LOGE("Not supported Interface");
return OC_EH_BAD_REQ;
}
{
FILE* fp = fopen(UPDATE_FILE, "w");
if(!fp) {
- FWR_LOGD("fopen error: %d", errno);
+ FWR_LOGE("fopen error: %d", errno);
return;
}
fclose(fp);
}
+void fmwup_propagate_firmware_status_resource(fmwup_update_property_e state, fmwup_result_property_e result)
+{
+
+ g_firmware_resource->state = state;
+ g_firmware_resource->result = result;
+
+ vconf_set_int(VCONF_FIRMWARE_UPDATE_STATE, (const int)g_firmware_resource->state);
+ vconf_set_int(VCONF_FIRMWARE_UPDATE_RESULT, (const int)g_firmware_resource->result);
+
+ fmwup_propagate_firmware_resource();
+
+ if (g_state_changed_cb) {
+ g_state_changed_cb(g_firmware_resource->state);
+ }
+
+ if (!(result == FMWUP_RESULT_INITIAL)) {
+ //init state, result in failed case
+ g_firmware_resource->state = FMWUP_EXEC_IDLE;
+ g_firmware_resource->result = FMWUP_RESULT_INITIAL;
+
+ vconf_set_int(VCONF_FIRMWARE_UPDATE_STATE, (const int)g_firmware_resource->state);
+ vconf_set_int(VCONF_FIRMWARE_UPDATE_RESULT, (const int)g_firmware_resource->result);
+
+ fmwup_propagate_firmware_resource();
+ }
+}
+
+
void _handle_update_command(int64_t update_type)
{
- int result = 0;
-
- if (g_strcmp0(g_firmware_resource->package_uri, "") && (
- (g_firmware_resource->state == 0 && update_type == FMWUP_EXEC_DOWNLOAD) ||
- (g_firmware_resource->state == 0 && update_type == FMWUP_EXEC_DOWNLOAD_AND_UPGRADE))) {
- if (g_firmware_resource->new_version && \
- g_strcmp0(g_firmware_resource->current_version, g_firmware_resource->new_version)) {
- FWR_LOGD("***Downloading image from [%s] ***", g_firmware_resource->package_uri);
- g_firmware_resource->state = FMWUP_STATE_DOWNLOADING;
- g_firmware_resource->result = 0;
- fmwup_propagate_firmware_resource();
- if (g_state_changed_cb) {
- g_state_changed_cb(g_firmware_resource->state);
- }
+ int result = FMWUP_RESULT_INITIAL;
+#ifdef _USE_WWST_
+ char *res_header = NULL;
+ char *res_body = NULL;
+ char *request_uri = NULL;
+ char *sec_download_url = NULL;
+ char *download_path = NULL;
+#endif
+
+ if (g_strcmp0(g_firmware_resource->package_uri, "") == 0 ||
+ g_strcmp0(g_firmware_resource->new_version, "") == 0 ||
+ g_strcmp0(g_firmware_resource->current_version, g_firmware_resource->new_version) == 0)
+ {
+ FWR_LOGE("Invalid value, package_uri[%s], new_version[%s], current_version[%s]",
+ g_firmware_resource->package_uri, g_firmware_resource->new_version, g_firmware_resource->current_version);
+ result = FMWUP_RESULT_UPDATE_FAILED;
+ goto _END_OF_FUNC_;
+ }
+
+
+ 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);
#ifdef _USE_WWST_
- char *res_header = NULL;
- char *res_body = NULL;
-// char *request_uri = g_strconcat(g_firmware_resource->package_uri, REST_API_DOWNLOAD_URL, CURRENT_VERSION,
-// g_firmware_resource->current_version, TOKEN, TOKEN_KEY_TEMP, NULL);
- char *request_uri = g_strconcat(g_firmware_resource->package_uri, NULL);
- FWR_LOGI("request_uri[%s]", request_uri);
+ //request_uri = g_strconcat(g_firmware_resource->package_uri, REST_API_DOWNLOAD_URL, CURRENT_VERSION,
+ // g_firmware_resource->current_version, TOKEN, TOKEN_KEY_TEMP, NULL);
+ request_uri = g_strconcat(g_firmware_resource->package_uri, NULL);
+ download_path = g_strconcat(g_download_path, FIRMWARE_FILE_NAME, NULL);
- if (fmwup_http_send_request(FMWUP_HTTP_GET, request_uri, &res_header, &res_body) != 0) {
- FWR_LOGE("cannot get Secure URL");
- } else {
- //parsing
- FWR_LOGI("res_header[%s] res_body[%s]",res_header, res_body);
-
- char *sec_download_url = NULL;
- if (_parse_secure_url(res_body, &sec_download_url)) {
-
- char *download_path = g_strconcat(g_download_path, FIRMWARE_FILE_NAME, NULL);
- FWR_LOGI("download url[%s] download path[%s]",sec_download_url, download_path);
-
- if (fmwup_http_download_file(sec_download_url, (const char *)download_path) != 0) {
- g_firmware_resource->state = FMWUP_STATE_IDLE;
- vconf_set_int(VCONF_FIRMWARE_UPDATE_STATE, g_firmware_resource->state);
- g_firmware_resource->result = 6;
- vconf_set_int(VCONF_FIRMWARE_UPDATE_RESULT, g_firmware_resource->result);
-
- fmwup_propagate_firmware_resource();
- if (g_state_changed_cb) {
- g_state_changed_cb(g_firmware_resource->state);
- }
-
- g_free(download_path);
- return;
- }
-
- g_free(download_path);
- g_free(sec_download_url);
- } else {
- FWR_LOGE("_parse_secure_url failed");
- }
- }
+ FWR_LOGI("request_uri[%s]", request_uri);
- g_free(request_uri);
+ if (fmwup_http_send_request(FMWUP_HTTP_GET, request_uri, &res_header, &res_body) != 0) {
+ FWR_LOGE("cannot get Secure URL");
+ result = FMWUP_RESULT_INVALID_URL;
+ goto _END_OF_FUNC_;
+ } else {
+ //parsing
+ FWR_LOGI("res_header[%s] res_body[%s]",res_header, res_body);
-#else
- if (fmwup_http_download_file(g_firmware_resource->package_uri, (const char *)g_download_path) != 0) {
- g_firmware_resource->state = FMWUP_STATE_IDLE;
- vconf_set_int(VCONF_FIRMWARE_UPDATE_STATE, g_firmware_resource->state);
- fmwup_propagate_firmware_resource();
- if (g_state_changed_cb) {
- g_state_changed_cb(g_firmware_resource->state);
- }
- return;
- }
-#endif
+ if (_parse_secure_url(res_body, &sec_download_url)) {
+ FWR_LOGI("download url[%s] download path[%s]",sec_download_url, download_path);
- FWR_LOGD("*** Firmware image downloaded ***");
- g_firmware_resource->state = FMWUP_STATE_DOWNLOADED;
- vconf_set_int(VCONF_FIRMWARE_UPDATE_STATE, g_firmware_resource->state);
+ if (fmwup_http_download_file(sec_download_url, (const char *)download_path) != 0) {
+ FWR_LOGE("fmwup_http_download_file failed");
+ result = FMWUP_RESULT_INVALID_URL;
+ goto _END_OF_FUNC_;
+ }
- fmwup_propagate_firmware_resource();
- if (g_state_changed_cb) {
- g_state_changed_cb(g_firmware_resource->state);
+ } else {
+ FWR_LOGE("_parse_secure_url failed");
+ result = FMWUP_RESULT_INVALID_URL;
+ goto _END_OF_FUNC_;
}
- } else {
- /* LOG("No need to upgrade to new firmware [%s] from [%s]", \
- g_firmware_resource->new_version, g_firmware_resource->current_version); */
- return;
}
+
+#else
+ if (fmwup_http_download_file(g_firmware_resource->package_uri, (const char *)g_download_path) != 0) {
+ FWR_LOGE("fmwup_http_download_file failed");
+ result = FMWUP_RESULT_INVALID_URL;
+ goto _END_OF_FUNC_;
+ }
+#endif
+
+ FWR_LOGD("*** Firmware image downloaded ***");
+ fmwup_propagate_firmware_status_resource(FMWUP_STATE_DOWNLOADED, FMWUP_RESULT_INITIAL);
}
- if (g_firmware_resource->state == FMWUP_STATE_DOWNLOADED) {
- if (update_type == FMWUP_EXEC_UPGRADE || update_type == FMWUP_EXEC_DOWNLOAD_AND_UPGRADE) {
- g_firmware_resource->state = FMWUP_STATE_UPDATING;
- vconf_set_int(VCONF_FIRMWARE_UPDATE_STATE, g_firmware_resource->state);
- fmwup_propagate_firmware_resource();
- if (g_state_changed_cb) {
- g_state_changed_cb(g_firmware_resource->state);
- }
+ 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);
- _exec_update();
- }
+ //TODO: To upgrade using interface of fota-client
+ _exec_update();
}
+
+_END_OF_FUNC_:
+ if (result != FMWUP_RESULT_INITIAL) {
+ fmwup_propagate_firmware_status_resource(FMWUP_STATE_IDLE, result);
+ }
+
+#ifdef _USE_WWST_
+ g_free(res_header);
+ g_free(res_body);
+ g_free(download_path);
+ g_free(sec_download_url);
+ g_free(request_uri);
+#endif
+
+ return;
}
OCRepPayload* _construct_response_of_firmware()
{
- FWR_LOGD("_construct_response_of_firmware()");
+ FWR_ENTER
OCRepPayload* payload = OCRepPayloadCreate();
if (!payload) {
- FWR_LOGD("Failed to allocate Payload");
+ FWR_LOGE("Failed to allocate Payload");
return NULL;
}
OCRepPayloadSetPropBool(payload, OC_RSRVD_FIRMWARE_ACTIVE_CHECK, g_firmware_resource->active_check);
-
+ FWR_EXIT
return payload;
}
g_free(g_firmware_resource->new_version);
g_firmware_resource->new_version = g_strdup(new_firmware);
vconf_set_str(VCONF_FIRMWARE_UPDATE_PACKAGE_NEW_VERSION, new_firmware);
- if (g_state_changed_cb) {
- g_state_changed_cb(g_firmware_resource->state);
- }
}
g_free(new_firmware);
- FWR_LOGD("g_firmware_resource->new_version = [%s]", g_firmware_resource->new_version);
+ FWR_LOGI("g_firmware_resource->new_version = [%s]", g_firmware_resource->new_version);
char *package_uri = NULL;
if (OCRepPayloadGetPropString(input, OC_RSRVD_FIRMWARE_PACKAGE_URI, &package_uri)) {
- FWR_LOGD("g_firmware_resource->package_uri = [%s]", 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);
vconf_set_str(VCONF_FIRMWARE_UPDATE_PACKAGE_URL, package_uri);
}
g_free(package_uri);
- FWR_LOGD("g_firmware_resource->package_uri = [%s]", g_firmware_resource->package_uri);
+ FWR_LOGI("g_firmware_resource->package_uri = [%s]", g_firmware_resource->package_uri);
} else {
- FWR_LOGE("package uri none");
+ FWR_LOGE("package_uri none");
}
}
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_LOGD("g_firmware_resource->package_size = [%lld]", package_size);
+ FWR_LOGI("g_firmware_resource->package_size = [%lld]", package_size);
}
char *package_md5 = NULL;
vconf_set_str(VCONF_FIRMWARE_UPDATE_PACKAGE_MD5, package_md5);
}
g_free(package_md5);
- FWR_LOGD("g_firmware_resource->package_md5 = [%s]", g_firmware_resource->package_md5);
+ FWR_LOGI("g_firmware_resource->package_md5 = [%s]", g_firmware_resource->package_md5);
}
int64_t update_time;
if (OCRepPayloadGetPropInt(input, OC_RSRVD_FIRMWARE_UPDATE_TIME, &update_time)) {
g_firmware_resource->update_time = update_time;
- FWR_LOGD("g_firmware_resource->update_time = [%lld]", update_time);
+ FWR_LOGI("g_firmware_resource->update_time = [%lld]", update_time);
/* TODO : Check Scheduled update , */
}
int64_t *update = (int64_t *)calloc(1, sizeof(int64_t));
if (!update) {
- FWR_LOGD("Memory allocation error!");
+ FWR_LOGE("Memory allocation error!");
return;
}
pthread_t pThread;
pthread_create(&pThread, NULL, _worker, update);
} else {
- free(update);
+ g_free(update);
}
-
fmwup_propagate_firmware_resource();
}
OCEntityHandlerResult _process_post_request(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
{
- FWR_LOGD("ProcessPostRequest enter");
+ FWR_ENTER
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION) {
- FWR_LOGD("Incoming payload not a representation");
+ FWR_LOGE("Incoming payload not a representation");
return ehResult;
}
OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
if (!input) {
- FWR_LOGD("Failed to parse");
+ FWR_LOGE("Failed to parse");
return ehResult;
}
*payload = getResp;
ehResult = OC_EH_OK;
+ FWR_EXIT
return ehResult;
}
// Send the response
if (OCDoResponse(&response) != OC_STACK_OK) {
- FWR_LOGD("Error sending response");
+ FWR_LOGE("Error sending response");
ehRet = OC_EH_ERROR;
}
if (OC_REST_POST == entityHandlerRequest->method || OC_REST_PUT == entityHandlerRequest->method) {
if (OCNotifyAllObservers(g_firmware_resource->resource_handle, OC_NA_QOS) != OC_STACK_OK) {
- printf("Fail to OCNotifyAllObservers()\n");
+ FWR_LOGI("Fail to OCNotifyAllObservers()");
ehRet = OC_EH_ERROR;
}
}
#endif
if (vconf_get_int(VCONF_FIRMWARE_UPDATE_STATE, &update_state) != 0) {
- FWR_LOGD("vconf_get_int() is failed");
+ FWR_LOGE("vconf_get_int() is failed");
}
if (vconf_get_int(VCONF_FIRMWARE_UPDATE_RESULT, &update_result) != 0) {
- FWR_LOGD("vconf_get_int() is failed");
+ FWR_LOGE("vconf_get_int() is failed");
}
if (vconf_get_dbl(VCONF_FIRMWARE_UPDATE_PACKAGE_SIZE, &package_size) != 0) {
- FWR_LOGD("vconf_get_dbl() is failed");
+ FWR_LOGE("vconf_get_dbl() is failed");
}
new_firmware_ver = vconf_get_str(VCONF_FIRMWARE_UPDATE_PACKAGE_NEW_VERSION);
package_md5 = vconf_get_str(VCONF_FIRMWARE_UPDATE_PACKAGE_MD5);