26 #include <webcfg_utils.h>
28 #include "safec_lib.h"
29 #include "XrdkCentralComBSStore.h"
35 #include <webcfg_generic.h>
37 #define UNUSED(x) (void )(x)
38 #define RET_SUCCESS 100
39 #define RET_FAILURE 102
41 static char fw_version[64] = {0};
42 static char model_name[64] = {0};
43 static char device_mac[64] = {0};
44 static char force_sync[256] = {0};
45 static char force_sync_transID[256] = {0};
47 pthread_cond_t *get_global_sync_condition(
void);
48 pthread_mutex_t *get_global_sync_mutex(
void);
49 void initWebConfigMultipartTask(
unsigned long status);
51 #define TR181_CMD "tr181 -s %s -v %s "
53 static int getKeyVal(
char *key,
char *value)
55 FILE *fp = fopen(DEV_DETAILS_FILE,
"r");
60 char appendkey[] =
"=";
61 char str[512] = {
'\0'};
62 char searchkey[64] = {
'\0'};
64 strncpy(searchkey, key, strlen(key));
65 strcat(searchkey, appendkey);
66 while(fscanf(fp,
"%s", str) != EOF)
68 char *searchVal = NULL;
69 if(searchVal = strstr(str, searchkey))
71 searchVal = searchVal + strlen(searchkey);
72 strncpy(value, searchVal, (strlen(str) - strlen(searchkey))+1);
77 for (i=j=0; i<strlen(value); i++)
80 value[j++] = value[i];
84 for(i=0; i<=strlen(value); i++) {
85 if(value[i]>=65&&value[i]<=90)
93 RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,
"webcfg: [%s] %d key = %s, value = %s rval= %d\n\n", __FUNCTION__, __LINE__, key, value, rval);
97 char* get_deviceMAC(
void)
99 if(0 == device_mac[0])
100 getKeyVal( (
char*)
"estb_mac", device_mac);
101 RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,
"webcfg: [%s] %d %s \n", __FUNCTION__, __LINE__, device_mac);
105 int Get_Webconfig_URL(
char *pString)
110 rc = strcpy_s(stRfcData.
paramName, strlen(
"Device.X_RDK_WebConfig.URL")+1,
"Device.X_RDK_WebConfig.URL");
113 RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s:%d]webcfg: Failed to copy.\n", __FUNCTION__, __LINE__);
118 m_bsStore = XBSStore::getInstance();
119 if (fcNoFault != m_bsStore->getValue(&stRfcData) ) {
120 RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s:%d]webcfg: Failed to get RFC Value.\n", __FUNCTION__, __LINE__);
125 strcpy_s(pString,strlen(BLE_DETECTION_WEBCFG_ENDPOINT)+1,BLE_DETECTION_WEBCFG_ENDPOINT);
126 RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s:%d]webcfg: Empty [%s] Value, so using default URL [%s]\n", __FUNCTION__, __LINE__,stRfcData.
paramName, pString );
130 RDK_LOG(RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s:%d]webcfg: The URL Value is \"%s\".\n", __FUNCTION__, __LINE__, stRfcData.
paramValue);
134 rc = strcpy_s(pString, strlen(url) + 1, url);
140 strncat(pString,(
const char *)BLE_DETECTION_WEBCFG_SUFIX, strlen(BLE_DETECTION_WEBCFG_SUFIX)+1);
143 if(strlen(pString) == 0) {
144 rc=strcpy_s(pString,strlen(BLE_DETECTION_WEBCFG_ENDPOINT)+1,BLE_DETECTION_WEBCFG_ENDPOINT);
151 RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,
"[%s:%d] The \"Device.X_RDK_WebConfig.URL\" is [%s] \n", __FUNCTION__,__LINE__, pString);
157 char *getSerialNumber(
void)
159 char *serialNumber = (
char*)
" ";
160 return strdup(serialNumber);
163 char *getModelName(
void)
165 char *device_model_name = NULL;
166 if(0 == model_name[0])
167 getKeyVal( (
char *)
"model_number", model_name);
168 device_model_name = strdup(model_name);
169 RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,
"webcfg: [%s] %d %s \n", __FUNCTION__, __LINE__, device_model_name);
170 return device_model_name;
173 char *getFirmwareVersion(
void)
175 char *firmware_version = NULL;
176 if(0 == fw_version[0])
177 getKeyVal((
char *)
"imageVersion", fw_version);
178 firmware_version = strdup(fw_version);
179 RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,
"webcfg: [%s] %d %s \n", __FUNCTION__, __LINE__, firmware_version);
180 return firmware_version;
183 char *get_global_systemReadyTime(
void)
188 char *getDeviceBootTime(
void)
193 char *getProductClass(
void)
198 char *getRebootReason(
void)
203 void setValues(
const param_t paramVal[],
const unsigned int paramCount,
const int setType,
char *transactionId, money_trace_spans *timeSpan, WDMP_STATUS *retStatus,
int *ccspStatus)
206 UNUSED(transactionId);
209 int ret = 0, count = 0, len = 0;
212 for (count = 0; count < paramCount ; count++) {
213 len = strlen(TR181_CMD) + strlen(paramVal[count].name) + strlen(paramVal[count].value);
214 cmd = (
char*)malloc(len);
217 sprintf(cmd, TR181_CMD, paramVal[count].name, paramVal[count].value);
218 RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,
"webcfg: [%s] %d command to execute %s \n", __FUNCTION__, __LINE__, cmd);
223 if(-1 == fgetc(fp)) {
224 *ccspStatus = RET_SUCCESS;
225 *retStatus = WDMP_SUCCESS;
227 *ccspStatus = RET_FAILURE;
228 *retStatus = WDMP_FAILURE;
233 *ccspStatus = RET_FAILURE;
234 *retStatus = WDMP_FAILURE;
236 if(WDMP_SUCCESS != *retStatus)
243 int setForceSync(
char* pString,
char *transactionId,
int *pStatus)
246 memset(force_sync,0,
sizeof(force_sync));
247 rc=strcpy_s(force_sync,
sizeof(force_sync),pString);
252 if((force_sync[0] !=
'\0') && (strlen(force_sync)>0)) {
253 if(strlen(force_sync_transID)>0) {
254 RDK_LOG(RDK_LOG_INFO, LOG_TR69HOSTIF,
"webcfg: [%s] %d Force sync is already in progress, Ignoring this request.\n",__FUNCTION__, __LINE__);
258 pthread_mutex_lock (get_global_sync_mutex());
260 if(transactionId !=NULL && (strlen(transactionId)>0)) {
261 rc=strcpy_s(force_sync_transID,
sizeof(force_sync_transID), transactionId);
268 pthread_cond_signal(get_global_sync_condition());
269 pthread_mutex_unlock(get_global_sync_mutex());
272 memset(force_sync_transID,0,
sizeof(force_sync_transID));
277 int getForceSync(
char** pString,
char **transactionId )
279 if((force_sync[0] !=
'\0') && strlen(force_sync)>0) {
280 *pString = strdup(force_sync);
281 *transactionId = strdup(force_sync_transID);
284 *transactionId = NULL;