diff --git a/src/backupSession.c b/src/backupSession.c index 7390757..f4bc14b 100644 --- a/src/backupSession.c +++ b/src/backupSession.c @@ -595,7 +595,8 @@ void load_download(mxml_node_t *tree,struct cwmp *cwmp) } } list_add (&(download_request->list), ilist->prev); - count_download_queue++; + if(download_request->scheduled_time != 0) + count_download_queue++; } void load_transfer_complete(mxml_node_t *tree,struct cwmp *cwmp) diff --git a/src/external.c b/src/external.c index df238a7..b010916 100644 --- a/src/external.c +++ b/src/external.c @@ -57,13 +57,13 @@ inline void external_free_list_value_change() parameter_container_delete_all(&external_list_value_change); } -void external_downloadResp (char *fault_code) +void external_downloadFaultResp (char *fault_code) { FREE(external_MethodFault); external_MethodFault = fault_code ? strdup(fault_code) : NULL; } -void external_fetch_downloadResp (char **fault) +void external_fetch_downloadFaultResp (char **fault) { *fault = external_MethodFault; external_MethodFault = NULL; @@ -412,9 +412,8 @@ int external_simple(char *arg) return 0; } -int external_download(char *url, char *size, char *type, char *user, char *pass, time_t scheduled_time) +int external_download(char *url, char *size, char *type, char *user, char *pass) { - char delay[256]; CWMP_LOG(INFO,"executing download url '%s'", url); if ((uproc.pid = fork()) == -1) @@ -445,9 +444,6 @@ int external_download(char *url, char *size, char *type, char *user, char *pass, argv[i++] = "--pass"; argv[i++] = pass; } - sprintf(delay,"%ld",scheduled_time); - argv[i++] = "--delay"; - argv[i++] = delay; argv[i++] = NULL; execvp(argv[0], (char **) argv); diff --git a/src/inc/external.h b/src/inc/external.h index cacf05e..e4e4a75 100644 --- a/src/inc/external.h +++ b/src/inc/external.h @@ -26,8 +26,8 @@ extern pthread_mutex_t external_mutex_value_change; extern struct list_head external_list_value_change; extern struct list_head external_list_parameter; -void external_downloadResp (char *fault_code); -void external_fetch_downloadResp (char **fault_code); +void external_downloadFaultResp (char *fault_code); +void external_fetch_downloadFaultResp (char **fault_code); void external_setParamValRespStatus (char *status); void external_fetch_setParamValRespStatus (char **status); void external_setParamAttrResp (char *status, char *fault); @@ -42,7 +42,7 @@ int external_get_action_execute(); int external_set_action_write(char *action, char *name, char *value, char *change); int external_set_action_execute(char *action); int external_simple(char *arg); -int external_download(char *url, char *size, char *type, char *user, char *pass, time_t scheduled_time); +int external_download(char *url, char *size, char *type, char *user, char *pass); int external_apply_download(char *type); void external_add_list_paramameter(char *param_name, char *param_data, char *param_type, char *fault_code); void external_free_list_parameter(); diff --git a/src/scripts/freecwmp.sh b/src/scripts/freecwmp.sh index 7479644..d3e076e 100644 --- a/src/scripts/freecwmp.sh +++ b/src/scripts/freecwmp.sh @@ -19,9 +19,8 @@ DEFINE_boolean 'force' false 'force getting values for certain parameters' 'f' DEFINE_string 'url' '' 'file to download [download only]' 'u' DEFINE_string 'size' '' 'size of file to download [download only]' 's' DEFINE_string 'type' '' 'type of file to download [download only]' 't' -DEFINE_string 'user' '' 'username for downloading file [download only]' 'a' -DEFINE_string 'pass' '' 'password for downloading file [download only]' 'p' -DEFINE_string 'delay' '' 'scheduled_time for downloading file [download only]' 'y' +DEFINE_string 'user' '' 'username for downloading file [download only]' 'U' +DEFINE_string 'pass' '' 'password for downloading file [download only]' 'P' FLAGS_HELP=`cat << EOF USAGE: $0 [flags] command [parameter] [values] @@ -441,10 +440,6 @@ if [ "$action" = "download" ]; then rm /tmp/firmware_upgrade_image_last_valid 2> /dev/null mv /tmp/firmware_upgrade_image /tmp/firmware_upgrade_image_last_valid 2> /dev/null freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" - if [ "${FLAGS_delay}" = "0" ];then - echo "/bin/sh /usr/sbin/freecwmp apply download --type ${FLAGS_type}" > /tmp/end_session.sh - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "action_end_session" }' 2> /dev/null - fi fi else let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED @@ -454,17 +449,9 @@ if [ "$action" = "download" ]; then elif [ "${FLAGS_type}" = "2" ];then mv /tmp/freecwmp_download /tmp/web_content.ipk 2> /dev/null freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" - if [ "${FLAGS_delay}" = "0" ];then - echo "/bin/sh /usr/sbin/freecwmp apply download --type ${FLAGS_type}" > /tmp/end_session.sh - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "action_end_session" }' 2> /dev/null - fi elif [ "${FLAGS_type}" = "3" ];then mv /tmp/freecwmp_download /tmp/vendor_configuration_file.cfg 2> /dev/null freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT" - if [ "${FLAGS_delay}" = "0" ];then - echo "/bin/sh /usr/sbin/freecwmp apply download --type ${FLAGS_type}" > /tmp/end_session.sh - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "action_end_session" }' 2> /dev/null - fi else let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE freecwmp_fault_output "" "$fault_code" diff --git a/src/scripts/functions/common b/src/scripts/functions/common index 4f0809d..8cf5261 100644 --- a/src/scripts/functions/common +++ b/src/scripts/functions/common @@ -94,7 +94,7 @@ freecwmp_fault_output() { ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 SetParameterAttributes '{"success": "'$success'", "fault_code": "'$fault_code'"}' 2> /dev/null ;; *download) - ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 download '{"fault_code": "'$fault_code'"}' 2> /dev/null + ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 downloadFault '{"fault_code": "'$fault_code'"}' 2> /dev/null ;; esac } @@ -430,7 +430,7 @@ freecwmp_execute_functions() freecwmp_check_image() { - . /etc/functions.sh; include /lib/upgrade; platform_check_image /tmp/freecwmp_download + . /etc/functions.sh; include /lib/upgrade; platform_check_image /tmp/firmware_upgrade_image return $? } diff --git a/src/ubus.c b/src/ubus.c index 3a676d1..7c8bebf 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -62,27 +62,27 @@ static enum download_fault { __DOWNLOAD_MAX }; -static const struct blobmsg_policy download_policy[] = { +static const struct blobmsg_policy download_fault_policy[] = { [DOWNLOAD_FAULT] = { .name = "fault_code", .type = BLOBMSG_TYPE_STRING }, }; static int -freecwmpd_handle_download(struct ubus_context *ctx, struct ubus_object *obj, +freecwmpd_handle_downloadFault(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { int tmp; struct blob_attr *tb[__DOWNLOAD_MAX]; - blobmsg_parse(download_policy, ARRAY_SIZE(download_policy), tb, + blobmsg_parse(download_fault_policy, ARRAY_SIZE(download_fault_policy), tb, blob_data(msg), blob_len(msg)); if (!tb[DOWNLOAD_FAULT]) return UBUS_STATUS_INVALID_ARGUMENT; - CWMP_LOG(INFO,"triggered ubus download %s", blobmsg_data(tb[DOWNLOAD_FAULT])); + CWMP_LOG(INFO,"triggered ubus downloadFault %s", blobmsg_data(tb[DOWNLOAD_FAULT])); - external_downloadResp (blobmsg_data(tb[DOWNLOAD_FAULT])); + external_downloadFaultResp (blobmsg_data(tb[DOWNLOAD_FAULT])); return 0; } @@ -432,7 +432,7 @@ freecwmpd_handle_delObject(struct ubus_context *ctx, struct ubus_object *obj, static const struct ubus_method freecwmp_methods[] = { UBUS_METHOD("notify", freecwmpd_handle_notify, notify_policy), - UBUS_METHOD("download", freecwmpd_handle_download, download_policy), + UBUS_METHOD("downloadFault", freecwmpd_handle_downloadFault, download_fault_policy), UBUS_METHOD("GetParameterValues", freecwmpd_handle_getParamValues, getParamValues_policy), UBUS_METHOD("SetParameterValuesFault", freecwmpd_handle_setParamValuesFault, setParamValuesFault_policy), UBUS_METHOD("SetParameterValuesStatus", freecwmpd_handle_setParamValuesStatus, setParamValuesStatus_policy), diff --git a/src/xml.c b/src/xml.c index 91f8559..da07ecb 100644 --- a/src/xml.c +++ b/src/xml.c @@ -1770,19 +1770,12 @@ int cwmp_launch_download(struct download *pdownload, struct transfer_complete ** download_startTime = mix_get_time(); - if(pdownload->scheduled_time != 0) - { - bkp_session_delete_download(pdownload); - bkp_session_save(); - } + bkp_session_delete_download(pdownload); + bkp_session_save(); sprintf(file_size,"%d",pdownload->file_size); - if(external_download(pdownload->url, file_size, pdownload->file_type, pdownload->username, pdownload->password, pdownload->scheduled_time)) - { - error = FAULT_CPE_DOWNLOAD_FAILURE; - } - - external_fetch_downloadResp(&fault_code); + external_download(pdownload->url, file_size, pdownload->file_type, pdownload->username, pdownload->password); + external_fetch_downloadFaultResp(&fault_code); if(fault_code != NULL) { @@ -1810,7 +1803,7 @@ int cwmp_launch_download(struct download *pdownload, struct transfer_complete ** p->command_key = strdup(pdownload->command_key); p->start_time = download_startTime; p->complete_time = mix_get_time(); - if(error) + if(error != FAULT_CPE_NO_FAULT) { p->fault_code = error; } @@ -1839,7 +1832,10 @@ void *thread_cwmp_rpc_cpe_download (void *v) { pdownload = list_entry(list_download.next,struct download, list); current_time = time(NULL); - timeout = current_time - pdownload->scheduled_time; + if(pdownload->scheduled_time != 0) + timeout = current_time - pdownload->scheduled_time; + else + timeout = 0; if((timeout >= 0)&&(timeout > time_of_grace)) { pthread_mutex_lock (&mutex_download); @@ -1859,7 +1855,8 @@ void *thread_cwmp_rpc_cpe_download (void *v) cwmp_root_cause_TransferComplete (cwmp,ptransfer_complete); } list_del (&(pdownload->list)); - count_download_queue--; + if(pdownload->scheduled_time != 0) + count_download_queue--; cwmp_free_download_request(pdownload); pthread_mutex_unlock (&mutex_download); } @@ -1873,7 +1870,7 @@ void *thread_cwmp_rpc_cpe_download (void *v) cwmp_root_cause_TransferComplete (cwmp,ptransfer_complete); } external_apply_download(pdownload->file_type); - external_fetch_downloadResp(&fault_code); + external_fetch_downloadFaultResp(&fault_code); if(fault_code != NULL) { if(strcmp(fault_code,"0") != 0) @@ -1898,7 +1895,8 @@ void *thread_cwmp_rpc_cpe_download (void *v) pthread_cond_signal (&(cwmp->threshold_session_send)); pthread_mutex_lock (&mutex_download); list_del (&(pdownload->list)); - count_download_queue--; + if(pdownload->scheduled_time != 0) + count_download_queue--; cwmp_free_download_request(pdownload); pthread_mutex_unlock (&mutex_download); continue; @@ -1951,7 +1949,8 @@ int cwmp_scheduledDownload_remove_all() download = list_entry(list_download.next,struct download, list); list_del (&(download->list)); bkp_session_delete_download(download); - count_download_queue--; + if(download->scheduled_time != 0) + count_download_queue--; cwmp_free_download_request(download); } pthread_mutex_unlock (&mutex_download); @@ -2109,86 +2108,47 @@ int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc) if(error == FAULT_CPE_NO_FAULT) { - if(download_delay == 0) - { - bkp_session_insert_download(download); - bkp_session_save(); - error = cwmp_launch_download(download,&ptransfer_complete); - if(error != FAULT_CPE_NO_FAULT) - { - if(cwmp_root_cause_TransferComplete (&cwmp_main, ptransfer_complete) != CWMP_OK) - { - cwmp_free_download_request(download); - return -1; - } - } -// else -// { -// external_apply_download(download->file_type); -// external_fetch_downloadResp(&fault_code); -// if(fault_code != NULL) -// { -// if(strcmp(fault_code,"0") != 0) -// { -// for(i=0;i<__FAULT_CPE_MAX;i++) -// { -// if(strcmp(FAULT_CPE_ARRAY[i].CODE,fault_code) == 0) -// { -// error = i; -// break; -// } -// } -// } -// free(fault_code); -// bkp_session_delete_transfer_complete(ptransfer_complete); -// ptransfer_complete->fault_code = atoi(fault_code); -// bkp_session_insert_transfer_complete(ptransfer_complete); -// bkp_session_save(); -// cwmp_root_cause_TransferComplete (&cwmp_main,ptransfer_complete); -// } -// } - cwmp_free_download_request(download); - } - else - { - pthread_mutex_lock (&mutex_download); + pthread_mutex_lock (&mutex_download); + if(download_delay != 0) scheduled_time = time(NULL) + download_delay; - list_for_each(ilist,&(list_download)) + list_for_each(ilist,&(list_download)) + { + idownload = list_entry(ilist,struct download, list); + if (idownload->scheduled_time == scheduled_time) { - idownload = list_entry(ilist,struct download, list); - if (idownload->scheduled_time == scheduled_time) - { - pthread_mutex_unlock (&mutex_download); - return 0; - } - if (idownload->scheduled_time > scheduled_time) - { - cond_signal = true; - break; - } + pthread_mutex_unlock (&mutex_download); + return 0; } - list_add (&(download->list), ilist->prev); + if (idownload->scheduled_time > scheduled_time) + { + cond_signal = true; + break; + } + } + list_add (&(download->list), ilist->prev); + if(download_delay != 0) + { count_download_queue++; download->scheduled_time = scheduled_time; - bkp_session_insert_download(download); - bkp_session_save(); - CWMP_LOG(INFO,"Download will start in %us",download_delay); - if (cond_signal) + } + bkp_session_insert_download(download); + bkp_session_save(); + CWMP_LOG(INFO,"Download will start in %us",download_delay); + if (cond_signal) + { + pthread_cond_signal(&threshold_download); + } + pthread_mutex_unlock (&mutex_download); + if (!thread_download_is_working) + { + thread_download_is_working = true; + error = pthread_create(&download_thread, NULL, &thread_cwmp_rpc_cpe_download, (void *)&cwmp_main); + if (error<0) { - pthread_cond_signal(&threshold_download); - } - pthread_mutex_unlock (&mutex_download); - if (!thread_download_is_working) - { - thread_download_is_working = true; - error = pthread_create(&download_thread, NULL, &thread_cwmp_rpc_cpe_download, (void *)&cwmp_main); - if (error<0) - { - CWMP_LOG(ERROR,"Error when creating the download thread!"); - thread_download_is_working = false; - return -1; - } + CWMP_LOG(ERROR,"Error when creating the download thread!"); + thread_download_is_working = false; + return -1; } } }