36 #include "libIARMCore.h"
37 #include "safec_lib.h"
39 static int is_connected = 0;
41 static char writeImageCbModule[MAX_BUF] =
"";
45 static IARM_Result_t getSerializedData_(
void *arg)
48 IARM_Result_t retCode = IARM_RESULT_IPCCORE_FAIL;
50 mfrError_t err = mfrERR_NONE;
52 errno_t safec_rc = -1;
56 if(mfrERR_NONE == err)
58 safec_rc = memcpy_s(param->
buffer,
sizeof(param->
buffer), data.buf, data.bufLen);
65 data.freeBuf(data.buf);
67 return IARM_RESULT_INVALID_PARAM;
70 param->
bufLen = data.bufLen;
73 data.freeBuf(data.buf);
75 retCode=IARM_RESULT_SUCCESS;
80 static IARM_Result_t deletePDRI_(
void *arg)
82 typedef mfrError_t (*mfrDeletePDRI_t)(void);
84 #ifndef RDK_MFRLIB_NAME
85 LOG(
"Please define RDK_MFRLIB_NAME\r\n");
86 return IARM_RESULT_INVALID_STATE;
88 static mfrDeletePDRI_t func = 0;
90 void *dllib = dlopen(RDK_MFRLIB_NAME, RTLD_LAZY);
92 func = (mfrDeletePDRI_t) dlsym(dllib,
"mfrDeletePDRI");
94 LOG(
"mfrDeletePDRI(void) is defined and loaded\r\n");
97 LOG(
"mfrDeletePDRI(void) is not defined\r\n");
99 return IARM_RESULT_INVALID_STATE;
104 LOG(
"Opening RDK_MFRLIB_NAME [%s] failed\r\n", RDK_MFRLIB_NAME);
105 return IARM_RESULT_INVALID_STATE;
109 IARM_Result_t retCode = IARM_RESULT_INVALID_STATE;
110 mfrError_t err = mfrERR_NONE;
116 if(mfrERR_NONE == err)
118 LOG(
"Calling mfrDeletePDRI returned err %d\r\n", err);
119 retCode = IARM_RESULT_SUCCESS;
127 static IARM_Result_t scrubAllBanks_(
void *arg)
129 typedef mfrError_t (*mfrScrubAllBanks_t)(void);
131 #ifndef RDK_MFRLIB_NAME
132 LOG(
"Please define RDK_MFRLIB_NAME\r\n");
133 return IARM_RESULT_INVALID_STATE;
135 static mfrScrubAllBanks_t func = 0;
137 void *dllib = dlopen(RDK_MFRLIB_NAME, RTLD_LAZY);
139 func = (mfrScrubAllBanks_t) dlsym(dllib,
"mfrScrubAllBanks");
141 LOG(
"mfrScrubAllBanks(void) is defined and loaded\r\n");
144 LOG(
"mfrScrubAllBanks(void) is not defined\r\n");
146 return IARM_RESULT_INVALID_STATE;
151 LOG(
"Opening RDK_MFRLIB_NAME [%s] failed\r\n", RDK_MFRLIB_NAME);
152 return IARM_RESULT_INVALID_STATE;
156 IARM_Result_t retCode = IARM_RESULT_INVALID_STATE;
157 mfrError_t err = mfrERR_NONE;
163 if(mfrERR_NONE == err)
165 LOG(
"Calling mfrScrubAllBanks returned err %d\r\n", err);
166 retCode = IARM_RESULT_SUCCESS;
173 #ifdef ENABLE_MFR_WIFI
174 static IARM_Result_t mfrWifiEraseAllData_(
void *arg)
176 typedef mfrError_t (*mfrWifiEraseAllData_t)(void);
178 #ifndef RDK_MFRLIB_NAME
179 LOG(
"Please define RDK_MFRLIB_NAME\r\n");
180 return IARM_RESULT_INVALID_STATE;
182 static mfrWifiEraseAllData_t func = 0;
184 void *dllib = dlopen(RDK_MFRLIB_NAME, RTLD_LAZY);
186 func = (mfrWifiEraseAllData_t) dlsym(dllib,
"WIFI_EraseAllData");
188 LOG(
"mfrWifiEraseAllData(void) is defined and loaded\r\n");
191 LOG(
"mfrWifiEraseAllData(void) is not defined\r\n");
193 return IARM_RESULT_INVALID_STATE;
198 LOG(
"Opening RDK_MFRLIB_NAME [%s] failed\r\n", RDK_MFRLIB_NAME);
199 return IARM_RESULT_INVALID_STATE;
203 IARM_Result_t retCode = IARM_RESULT_INVALID_STATE;
204 WIFI_API_RESULT err = WIFI_API_RESULT_SUCCESS;
210 if(WIFI_API_RESULT_SUCCESS == err)
212 LOG(
"Calling mfrWifiEraseAllData returned err %d\r\n", err);
213 retCode = IARM_RESULT_SUCCESS;
220 static IARM_Result_t mfrWifiCredentials_(
void *arg)
223 IARM_Result_t retCode = IARM_RESULT_IPCCORE_FAIL;
225 WIFI_API_RESULT err = WIFI_API_RESULT_SUCCESS;
227 errno_t safec_rc = -1;
229 if (param->requestType == WIFI_SET_CREDENTIALS)
231 safec_rc = strcpy_s(data.cSSID,
sizeof(data.cSSID), param->wifiCredentials.cSSID);
235 return IARM_RESULT_INVALID_PARAM;
238 safec_rc = strcpy_s(data.cPassword,
sizeof(data.cPassword), param->wifiCredentials.cPassword);
242 return IARM_RESULT_INVALID_PARAM;
245 data.iSecurityMode = param->wifiCredentials.iSecurityMode;
247 LOG(
"WIFI_SetCredentials ssid = %s \r\n", param->wifiCredentials.cSSID);
249 if(WIFI_API_RESULT_SUCCESS == err)
251 retCode=IARM_RESULT_SUCCESS;
254 LOG(
"Calling WIFI_SetCredentials returned err %d\r\n", err);
258 data.iSecurityMode = -1;
261 if(WIFI_API_RESULT_SUCCESS == err)
263 safec_rc = strcpy_s(param->wifiCredentials.cSSID,
sizeof(param->wifiCredentials.cSSID), data.cSSID);
267 return IARM_RESULT_INVALID_PARAM;
270 safec_rc = strcpy_s(param->wifiCredentials.cPassword,
sizeof(param->wifiCredentials.cPassword), data.cPassword);
274 return IARM_RESULT_INVALID_PARAM;
277 param->wifiCredentials.iSecurityMode = data.iSecurityMode;
279 retCode=IARM_RESULT_SUCCESS;
280 LOG(
"WIFI_GetCredentials ssid = %s SecurityMode = %d \r\n", data.cSSID, data.iSecurityMode);
283 LOG(
"Calling WIFI_GetCredentials returned err %d\r\n", err);
285 param->returnVal=err;
293 errno_t safec_rc = -1;
295 param.status = status;
297 LOG(
"In writeImage callback: error = %d, percentage = %02.02\n",status.error,status.percentage/100,status.percentage%100);
301 safec_rc = memcpy_s(param.
cbData,
sizeof(param.
cbData), cbData,
sizeof(param.
cbData));
315 static IARM_Result_t writeImage_(
void *arg)
320 #ifndef RDK_MFRLIB_NAME
321 LOG(
"Please define RDK_MFRLIB_NAME\r\n");
322 LOG(
"Exiting writeImage_\n");
323 return IARM_RESULT_INVALID_STATE;
325 static mfrWriteImage_ func = 0;
326 LOG(
"In writeImage_\n");
328 void *dllib = dlopen(RDK_MFRLIB_NAME, RTLD_LAZY);
330 func = (mfrWriteImage_) dlsym(dllib,
"mfrWriteImage");
332 LOG(
"mfrWriteImage is defined and loaded\r\n");
335 LOG(
"mfrWriteImage is not defined\r\n");
336 LOG(
"Exiting writeImage_\n");
338 return IARM_RESULT_INVALID_STATE;
343 LOG(
"Opening RDK_MFRLIB_NAME [%s] failed\r\n", RDK_MFRLIB_NAME);
344 LOG(
"Exiting writeImage_\n");
345 return IARM_RESULT_INVALID_STATE;
349 IARM_Result_t retCode = IARM_RESULT_INVALID_STATE;
350 mfrError_t err = mfrERR_NONE;
351 errno_t safec_rc = -1;
358 notifyStruct.cbData = pParam->
cbData;
359 notifyStruct.interval = pParam->
interval;
360 notifyStruct.cb = writeImageCb;
362 safec_rc = strcpy_s(writeImageCbModule,
sizeof(writeImageCbModule),pParam->
callerModuleName);
366 return IARM_RESULT_INVALID_PARAM;
369 lastStatus.progress = mfrUPGRADE_PROGRESS_NOT_STARTED;
371 err = func(pParam->
name, pParam->
path, pParam->
type, notifyStruct);
373 if(mfrERR_NONE == err)
375 LOG(
"Calling mfrWriteImage returned err %d\r\n", err);
376 retCode = IARM_RESULT_SUCCESS;
379 while( lastStatus.progress == mfrUPGRADE_PROGRESS_NOT_STARTED )
381 LOG(
"Waiting for upgrade to start\n");
386 while( lastStatus.progress == mfrUPGRADE_PROGRESS_STARTED )
388 LOG(
"Waiting for upgrade to complete\n");
392 LOG(
"Update process complete..\n");
394 if(lastStatus.progress != mfrUPGRADE_PROGRESS_COMPLETED)
396 retCode = IARM_RESULT_IPCCORE_FAIL;
401 LOG(
"Exiting writeImage_\n");
407 IARM_Result_t setBootloaderPattern_(
void *arg)
410 #ifndef RDK_MFRLIB_NAME
411 LOG(
"Please define RDK_MFRLIB_NAME. Cannot resolve mfrSetBootloaderPattern without it.\n");
412 return IARM_RESULT_INVALID_STATE;
415 static int symbol_lookup_complete = 0;
418 if(0 == symbol_lookup_complete) {
419 symbol_lookup_complete = 1;
420 void *dllib = dlopen(RDK_MFRLIB_NAME, RTLD_LAZY);
425 LOG(
"mfrSetBootloaderPattern is defined and loaded\n");
428 LOG(
"mfrSetBootloaderPattern is not defined\n");
429 return IARM_RESULT_INVALID_STATE;
433 LOG(
"Opening RDK_MFRLIB_NAME [%s] failed\n", RDK_MFRLIB_NAME);
434 LOG(
"Exiting setBootloaderPattern_\n");
435 return IARM_RESULT_INVALID_STATE;
440 LOG(
"mfrSetBootloaderPattern is not defined\n");
441 return IARM_RESULT_INVALID_STATE;
445 IARM_Result_t retCode = IARM_RESULT_SUCCESS;
446 mfrError_t err = mfrERR_NONE;
449 LOG(
"Calling mfrSetBootloaderPattern with setting 0x%x\n", pParam->pattern);
450 err = func(pParam->pattern);
451 if(mfrERR_NONE != err)
453 LOG(
"Calling mfrSetBootloaderPattern returned error 0x%x\n", err);
454 retCode = IARM_RESULT_INVALID_PARAM;
463 IARM_Result_t err = IARM_RESULT_SUCCESS;
465 LOG(
"Entering [%s] - [%s] - disabling io redirect buf\r\n", __FUNCTION__,
IARM_BUS_MFRLIB_NAME);
466 setvbuf(stdout, NULL, _IOLBF, 0);
472 LOG(
"Error initializing MFR library..\n");
473 err = IARM_RESULT_INVALID_STATE;
479 if(IARM_RESULT_SUCCESS != err)
481 LOG(
"Error initializing IARM.. error code : %d\n",err);
487 if(IARM_RESULT_SUCCESS != err)
489 LOG(
"Error connecting to IARM.. error code : %d\n",err);
494 if(IARM_RESULT_SUCCESS != err)
496 LOG(
"Error registering call(getSerializedData) in IARM.. error code : %d\n",err);
501 if(IARM_RESULT_SUCCESS != err)
503 LOG(
"Error registering call(deletePDRI) in IARM.. error code : %d\n",err);
509 if(IARM_RESULT_SUCCESS != err)
511 LOG(
"Error registering call(scrubAllBanks) in IARM.. error code : %d\n",err);
516 if(IARM_RESULT_SUCCESS != err)
518 LOG(
"Error registering call(writeImage) in IARM.. error code : %d\n",err);
523 if(IARM_RESULT_SUCCESS != err)
525 LOG(
"Error registering call(setBootloaderPattern_) in IARM.. error code : %d\n",err);
528 #ifdef ENABLE_MFR_WIFI
531 if(IARM_RESULT_SUCCESS != err)
533 LOG(
"Error registering call(wifiEraseAllData) in IARM.. error code : %d\n",err);
538 if(IARM_RESULT_SUCCESS != err)
540 LOG(
"Error registering call(mfrWifiGetCredentials) in IARM.. error code : %d\n",err);
547 if(err != IARM_RESULT_SUCCESS)
567 return IARM_RESULT_SUCCESS;
576 LOG(
"I-ARM MFR Lib: HeartBeat at %s\r\n", ctime(&curr));
579 return IARM_RESULT_SUCCESS;