RDK Documentation (Open Sourced RDK Components)
mfrCli.c
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 
22 /**
23 * @defgroup iarmmgrs
24 * @{
25 * @defgroup mfr
26 * @{
27 **/
28 
29 
30 #include <string.h>
31 #include "iarmUtil.h"
32 #include "libIARM.h"
33 #include "libIBus.h"
34 #include "libIARMCore.h"
35 #include "mfrMgr.h"
36 #include "mfrCrypto.h"
37 #include <stdio.h>
38 #include <sys/types.h>
39 #include <unistd.h>
40 #include "safec_lib.h"
41 
42 static char writeImageCbModule[MAX_BUF] = "";
43 static char cliName[32];
44 static mfrUpgradeStatusNotify_t cb_notify = {0,};
45 
46 static void _eventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
47 {
48  errno_t safec_rc = -1;
49  int ind = -1;
50 
51  safec_rc = strcmp_s(IARM_BUS_MFRLIB_NAME, strlen(IARM_BUS_MFRLIB_NAME), owner, &ind);
52  ERR_CHK(safec_rc);
53  if(((!ind) && (safec_rc == EOK)) && (eventId == IARM_BUS_MFRMGR_EVENT_STATUS_UPDATE))
54  {
55 
57 
58  if(cb_notify.cb)
59  {
60  cb_notify.cb(param->status, cb_notify.cbData);
61  }
62  }
63 }
64 
65 mfrError_t mfr_init( )
66 {
67  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
68  printf("Initializing MFR module \n");
70  (char *)IARM_BUS_MFRLIB_API_Init,
71  NULL,
72  0);
73 
74  if (IARM_RESULT_SUCCESS == rpcRet)
75  {
76  printf("Iarm call returned success in %s \n",__func__);
77  return mfrERR_NONE;
78  }
79 
81  return mfrERR_GENERAL;
82 }
83 
84 mfrError_t mfr_shutdown( )
85 {
86  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
88  (char *)IARM_BUS_MFRLIB_API_Shutdown,
89  NULL,
90  0);
91  if (IARM_RESULT_SUCCESS == rpcRet)
92  {
93  return mfrERR_NONE;
94  }
95  return mfrERR_GENERAL;
96 }
97 
98 mfrError_t mfrGetSerializedData( mfrSerializedType_t type, mfrSerializedData_t *data, mfrEncryptFunction_t crypto)
99 {
100  IARM_Result_t rpcRet;
102  errno_t safec_rc = -1;
103 
104  param.type = type;
105  param.bufLen = 0;
106 
107  data->buf = NULL;
108  data->bufLen = 0;
109 
110 
111  if(NULL !=crypto)
112  {
113  safec_rc = strcpy_s(param.crypto, sizeof(param.crypto), "mfrCrypto_Encrypt");
114  }
115  else
116  {
117  safec_rc = strcpy_s(param.crypto, sizeof(param.crypto), "");
118  }
119  if(safec_rc != EOK)
120  {
121  ERR_CHK(safec_rc);
122  return mfrERR_GENERAL;
123  }
124  do{
125 
126  printf("%s: Calling Get Serialized..\n",__func__);
129  (void*)&param,
130  sizeof(param));
131 
132  if (IARM_RESULT_SUCCESS != rpcRet)
133  {
134  printf("%s: failed while trying to get size of param..\n",__func__);
135  // break;
136  }
137 
138  data->buf = (char *) malloc (param.bufLen);
139  safec_rc = memcpy_s(data->buf, param.bufLen, (char *)param.buffer, param.bufLen);
140  if(safec_rc != EOK)
141  {
142  ERR_CHK(safec_rc);
143  if (data->buf)
144  free(dat->buf);
145  return mfrERR_GENERAL;
146  }
147  data->bufLen = param.bufLen;
148  data->freeBuf = free;
149 
150  }while (0);
151 
152  if(rpcRet == IARM_RESULT_SUCCESS)
153  return mfrERR_NONE;
154 
155  return mfrERR_GENERAL;
156 }
157 
158 mfrError_t mfrSetSerializedData( mfrSerializedType_t type, mfrSerializedData_t *data, mfrDecryptFunction_t crypto)
159 {
160  IARM_Result_t rpcRet;
162  errno_t safec_rc = -1;
163  do{
164  param.bufLen = (data->bufLen < MAX_SERIALIZED_BUF)?data->bufLen:MAX_SERIALIZED_BUF;
165 
166  if(NULL !=crypto)
167  {
168  safec_rc = strcpy_s(param.crypto, sizeof(param.crypto), "mfrCrypto_Decrypt");
169  }
170  else
171  {
172  safec_rc = strcpy_s(param.crypto, sizeof(param.crypto), "");
173  }
174  if(safec_rc != EOK)
175  {
176  ERR_CHK(safec_rc);
177  return mfrERR_GENERAL;
178  }
179  param.type = type;
180  safec_rc = memcpy_s(((char*)param.buffer), sizeof(param.buffer), data->buf, param.bufLen);
181  if(safec_rc != EOK)
182  {
183  ERR_CHK(safec_rc);
184  return mfrERR_GENERAL;
185  }
186 
188  (char *)IARM_BUS_MFRLIB_API_SetSerializedData,
189  (void*)&param,
191 
192  if (IARM_RESULT_SUCCESS != rpcRet)
193  {
194  printf("%s: failed while trying to write param..\n",__func__);
195  rpcRet = IARM_RESULT_IPCCORE_FAIL;
196  break;
197  }
198 
199  }while(0);
200 
201  if(rpcRet == IARM_RESULT_SUCCESS)
202  return mfrERR_NONE;
203  return mfrERR_GENERAL;
204 }
205 
206 mfrError_t mfrWriteImage(const char *name, const char *path, mfrImageType_t type, mfrUpgradeStatusNotify_t notify)
207 {
208  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
210  errno_t safec_rc = -1;
211 
212  safec_rc = strcpy_s(param.name, sizeof(param.name), name);
213  if(safec_rc != EOK)
214  {
215  ERR_CHK(safec_rc);
216  return mfrERR_GENERAL;
217  }
218 
219  safec_rc = strcpy_s(param.path, sizeof(param.path), path);
220  if(safec_rc != EOK)
221  {
222  ERR_CHK(safec_rc);
223  return mfrERR_GENERAL;
224  }
225 
226  param.type = type;
227  param.interval = notify.interval;
228 
231  (void *)&param,
232  sizeof(param));
233 
234  if(IARM_RESULT_SUCCESS == rpcRet)
235  {
236  cb_notify = notify;
237  return mfrERR_NONE;
238  }
239  return mfrERR_GENERAL;
240 }
241 
242 mfrError_t mfrSetImageWriteProgress(const char * imageName, mfrImageType_t imageType, mfrUpgradeProgress_t progress)
243 {
244 
245  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
247  errno_t safec_rc = -1;
248 
249  safec_rc = strcpy_s(param.imageName, sizeof(param.imageName), imageName);
250  if(safec_rc != EOK)
251  {
252  ERR_CHK(safec_rc);
253  return mfrERR_GENERAL;
254  }
255 
256  param.imageType = imageType;
257  param.progress = progress;
258 
260  (char *)IARM_BUS_MFRLIB_API_SetImageWriteProgress,
261  (void *)&param,
262  sizeof(param));
263 
264  if(IARM_RESULT_SUCCESS == rpcRet)
265  {
266  return mfrERR_NONE;
267  }
268  return mfrERR_GENERAL;
269 }
270 
271 
272 mfrError_t mfrGetImageWriteProgress(const char * imageName,mfrImageType_t imageType,mfrUpgradeProgress_t *progress)
273 {
274 
275  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
277  errno_t safec_rc = -1;
278 
279  printf("Inside %s \n",__func__);
280  safec_rc = strcpy_s(param.imageName, sizeof(param.imageName), imageName);
281  if(safec_rc != EOK)
282  {
283  ERR_CHK(safec_rc);
284  return mfrERR_GENERAL;
285  }
286 
287  param.imageType = imageType;
289  (char *)IARM_BUS_MFRLIB_API_GetImageWriteProgress,
290  (void *)&param,
291  sizeof(param));
292 
293  if(IARM_RESULT_SUCCESS == rpcRet)
294  {
295  *progress = param.progress;
296  return mfrERR_NONE;
297  }
298  return mfrERR_GENERAL;
299 }
300 
301 
302 mfrError_t mfrDeletePDRI( )
303 {
304  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
307  NULL,
308  0);
309  if(IARM_RESULT_SUCCESS == rpcRet)
310  {
311  return mfrERR_NONE;
312  }
313  return mfrERR_GENERAL;
314 }
315 
316 mfrError_t mfrScrubAllBanks( )
317 {
318  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
321  NULL,
322  0);
323  if(IARM_RESULT_SUCCESS == rpcRet)
324  {
325  return mfrERR_NONE;
326  }
327  return mfrERR_GENERAL;
328 }
329 
330 
331 mfrError_t mfrReboot(const char *imageName)
332 {
333 
334  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
336  errno_t safec_rc = -1;
337 
338  safec_rc = strcpy_s(param.imageName, sizeof(param.imageName), imageName);
339  if(safec_rc != EOK)
340  {
341  ERR_CHK(safec_rc);
342  return mfrERR_GENERAL;
343  }
344 
345 
347  (char *)IARM_BUS_MFRLIB_API_Reboot,
348  (void *)&param,
349  sizeof(param));
350 
351  if(IARM_RESULT_SUCCESS == rpcRet)
352  {
353  return mfrERR_NONE;
354  }
355  return mfrERR_GENERAL;
356 }
357 
358 
359 mfrError_t mfrSetCableCardType(mfrCableCardType_t type)
360 {
361 
362  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
364 
365  param.type = type;
366 
368  (char *)IARM_BUS_MFRLIB_API_SetCableCardType,
369  (void *)&param,
370  sizeof(param));
371 
372  if(IARM_RESULT_SUCCESS == rpcRet)
373  {
374  return mfrERR_NONE;
375  }
376  return mfrERR_GENERAL;
377 }
378 
379 mfrError_t mfrSetHostFirmwareInfo(const mfrHostFirmwareInfo_t *firmwareInfo)
380 {
381 
382  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
384  errno_t safec_rc = -1;
385 
386  safec_rc = strcpy_s(param.version, sizeof(param.version), firmwareInfo->firmwareVersion);
387  if(safec_rc != EOK)
388  {
389  ERR_CHK(safec_rc);
390  return mfrERR_GENERAL;
391  }
392 
393  param.day = firmwareInfo-> firmwareDay;
394  param.month = firmwareInfo->firmwareMonth;
395  param.year = firmwareInfo->firmwareYear;
396 
398  (char *)IARM_BUS_MFRLIB_API_SetHostFirmwareInfo,
399  (void *)&param,
400  sizeof(param));
401 
402  if(IARM_RESULT_SUCCESS == rpcRet)
403  {
404  return mfrERR_NONE;
405  }
406  return mfrERR_GENERAL;
407 }
408 
409 mfrError_t mfrGetBootImageName(int bootInstance, char *bootImageName, int *len, mfrImageType_t bootImageType)
410 {
411 
412  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
414  errno_t safec_rc = -1;
415 
416 // strcpy(param.imageName,bootImageName);
417  param.bootInstance = bootInstance;
418 // param.len = *len;
419  param.type = bootImageType;
421  (char *)IARM_BUS_MFRLIB_API_GetBootImageName,
422  (void *)&param,
423  sizeof(param));
424 
425  if(IARM_RESULT_SUCCESS == rpcRet)
426  {
427  *len = param.len;
428  safec_rc = memcpy_s(bootImageName, sizeof(param.imageName), param.imageName, param.len);
429  if(safec_rc != EOK)
430  {
431  ERR_CHK(safec_rc);
432  return mfrERR_GENERAL;
433  }
434 
435  return mfrERR_NONE;
436  }
437  return mfrERR_GENERAL;
438 }
439 mfrError_t mfrGetPathConfiguration(mfrConfigPathType_t type, char *path, int *len)
440 {
441 
442  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
444  errno_t safec_rc = -1;
445 
446  //strcpy(param.path,path);
447  param.type = type;
448  //param.len = *len;
450  (char *)IARM_BUS_MFRLIB_API_GetPathConfiguration,
451  (void *)&param,
452  sizeof(param));
453 
454  if(IARM_RESULT_SUCCESS == rpcRet)
455  {
456  *len = param.len;
457  if(NULL != path)
458  {
459  safec_rc = memcpy_s(path, sizeof(param.path), param.path, param.len);
460  if(safec_rc != EOK)
461  {
462  ERR_CHK(safec_rc);
463  return mfrERR_GENERAL;
464  }
465 
466  return mfrERR_NONE;
467  }
468  }
469  return mfrERR_GENERAL;
470 }
471 
473 {
474 
475  IARM_Result_t rpcRet = IARM_RESULT_SUCCESS;
477  errno_t safec_rc = -1;
478 
479  safec_rc = memcpy_s(param.seedIn, sizeof(param.seedIn), params->seedIn, sizeof(param.seedIn));
480  if(safec_rc != EOK)
481  {
482  ERR_CHK(safec_rc);
483  return mfrERR_GENERAL;
484  }
485 
486  safec_rc = memcpy_s(param.keyOut, sizeof(param.keyOut), params->keyOut, sizeof(param.keyOut));
487  if(safec_rc != EOK)
488  {
489  ERR_CHK(safec_rc);
490  return mfrERR_GENERAL;
491  }
492 
494  (char *)IARM_BUS_MFRLIB_API_GetDFAST2Data,
495  (void *)&param,
496  sizeof(param));
497 
498  if(IARM_RESULT_SUCCESS == rpcRet)
499  {
500  return mfrERR_NONE;
501  }
502  return mfrERR_GENERAL;
503 }
504 
505 
506 
507 /** @} */
508 /** @} */
mfrSetCableCardType
mfrError_t mfrSetCableCardType(mfrCableCardType_t type)
Sets the cable card type.
Definition: mfrCli.c:359
_IARM_Bus_MFRLib_SerializedData_Param_t::bufLen
int bufLen
Definition: mfrMgr.h:125
IARM_BUS_MFRLIB_API_ScrubAllBanks
#define IARM_BUS_MFRLIB_API_ScrubAllBanks
Definition: mfrMgr.h:106
mfrWriteImage
mfrError_t mfrWriteImage(const char *name, const char *path, mfrImageType_t type, mfrUpgradeStatusNotify_t notify)
Validate and Write the image into flash. The process should follow these major steps: 1) Validate hea...
Definition: mfrCli.c:206
_IARM_Bus_MFRLib_Reboot_Param_t
Definition: mfrMgr.h:148
mfrScrubAllBanks
mfrError_t mfrScrubAllBanks(void)
Delete the platform images.
Definition: mfrCli.c:316
mfrDeletePDRI
mfrError_t mfrDeletePDRI(void)
Delete the P-DRI image if it is present.
Definition: mfrCli.c:302
IARM_BUS_MFRLIB_API_WriteImage
#define IARM_BUS_MFRLIB_API_WriteImage
Definition: mfrMgr.h:102
mfrGetSerializedData
mfrError_t mfrGetSerializedData(mfrSerializedType_t type, mfrSerializedData_t *data, mfrEncryptFunction_t crypto)
Retrieve Serialized Read-Only data from device. The serialized data is returned as a byte stream....
Definition: mfrCli.c:98
_IARM_Bus_MFRLib_SerializedData_Param_t::type
mfrSerializedType_t type
Definition: mfrMgr.h:123
mfrSetSerializedData
mfrError_t mfrSetSerializedData(mfrSerializedType_t type, mfrSerializedData_t *data, mfrDecryptFunction_t crypto)
Write Serialized data to device. The serialized data written as a byte stream. The 'crypto' parameter...
Definition: mfrCli.c:158
mfrReboot
mfrError_t mfrReboot(const char *imageName)
Reboots the box with image of given name.
Definition: mfrCli.c:331
IARM_Bus_Call
IARM_Result_t IARM_Bus_Call(const char *ownerName, const char *methodName, void *arg, size_t argLen)
This API is used to Invoke RPC method by its application name and method name.
Definition: iarm_bus.c:57
mfr_shutdown
mfrError_t mfr_shutdown(void)
Shutdowns the mfr library. This function should be called to free resources in mfr library while sh...
Definition: mfrCli.c:84
mfrSetImageWriteProgress
mfrError_t mfrSetImageWriteProgress(const char *imageName, mfrImageType_t imageType, mfrUpgradeProgress_t progress)
Set the the progress of image upgrade.
Definition: mfrCli.c:242
mfrGetImageWriteProgress
mfrError_t mfrGetImageWriteProgress(const char *imageName, mfrImageType_t imageType, mfrUpgradeProgress_t *progress)
Retrieves the last/latest progress of image upgrade If the upgrade is in not progress,...
Definition: mfrCli.c:272
mfrGetBootImageName
mfrError_t mfrGetBootImageName(int bootInstance, char *bootImageName, int *len, mfrImageType_t bootImageType)
Retrieve the image name used by box when booting up. (I.e. current active image)
Definition: mfrCli.c:409
_mfrUpgradeStatusNotify_t
Definition: mfrTypes.h:225
IARM_Bus_RegisterEventHandler
IARM_Result_t IARM_Bus_RegisterEventHandler(const char *ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler)
This API register to listen to event and provide the callback function for event notification....
Definition: iarmMgrMocks.cpp:43
_IARM_Bus_MFRLib_GetDFAST2Data_Param_t
Definition: mfrMgr.h:176
_IARM_BUS_MfrMgr_StatusUpdate_EventData_t
Definition: mfrMgr.h:193
mfrGetPathConfiguration
mfrError_t mfrGetPathConfiguration(mfrConfigPathType_t type, char *path, int *len)
Retrieves the path configuration name.
Definition: mfrCli.c:439
libIBus.h
RDK IARM-Bus API Declarations.
_IARM_Bus_MFRLib_SetImageWriteProgress_Param_t
Definition: mfrMgr.h:142
IARM_BUS_MFRMGR_EVENT_STATUS_UPDATE
@ IARM_BUS_MFRMGR_EVENT_STATUS_UPDATE
Definition: mfrMgr.h:188
_IARM_BUS_MfrMgr_StatusUpdate_EventData_t::status
mfrUpgradeStatus_t status
Definition: mfrMgr.h:194
_IARM_Bus_MFRLib_WriteImage_Param_t
Definition: mfrMgr.h:129
_IARM_Bus_MFRLib_SetHostFirmwareInfo_Param_t
Definition: mfrMgr.h:156
mfr_init
mfrError_t mfr_init(void)
Initialize the mfr library. This function should be call once before the functions in this API can ...
Definition: mfrCli.c:65
mfrDecryptFunction_t
mfrError_t(* mfrDecryptFunction_t)(const mfrSerializedData_t *pCipherText, mfrSerializedData_t *pClearText)
crypto funcionality. This function should be called to decrypt a block of data that are encrypted by ...
Definition: mfrTypes.h:253
_IARM_Bus_MFRLib_WriteImage_Param_t::interval
int interval
Definition: mfrMgr.h:133
_IARM_Bus_MFRLib_WriteImage_Param_t::path
char path[255]
Definition: mfrMgr.h:131
IARM_BUS_MFRLIB_API_GetSerializedData
#define IARM_BUS_MFRLIB_API_GetSerializedData
Definition: mfrMgr.h:100
_IARM_Bus_MFRLib_GetPathConfiguration_Param_t
Definition: mfrMgr.h:170
IARM_BUS_MFRLIB_NAME
#define IARM_BUS_MFRLIB_NAME
Definition: mfrMgr.h:98
mfrEncryptFunction_t
mfrError_t(* mfrEncryptFunction_t)(const mfrSerializedData_t *pClearText, mfrSerializedData_t *pCipherText)
crypto funcionality. This function should be called to encrypt a block of data
Definition: mfrTypes.h:242
mfrSetHostFirmwareInfo
mfrError_t mfrSetHostFirmwareInfo(const mfrHostFirmwareInfo_t *firmwareInfo)
Sets the Host firmware information.
Definition: mfrCli.c:379
_mfrSerializedData_t
Definition: mfrTypes.h:50
_IARM_Bus_MFRLib_GetImageWriteProgress_Param_t
Definition: mfrMgr.h:136
IARM_BUS_MFRLIB_API_DeletePDRI
#define IARM_BUS_MFRLIB_API_DeletePDRI
Definition: mfrMgr.h:105
_IARM_Bus_MFRLib_GetBootImageName_Param_t
Definition: mfrMgr.h:163
_IARM_Bus_MFRLib_WriteImage_Param_t::name
char name[255]
Definition: mfrMgr.h:130
_mfrHostFrmwareInfo_t
Definition: mfrTypes.h:209
_mfrDFAST2Params_t
Definition: mfrTypes.h:199
_IARM_Bus_MFRLib_SerializedData_Param_t
Definition: mfrMgr.h:122
_IARM_Bus_MFRLib_SetCableCardType_Param_t
Definition: mfrMgr.h:152
_IARM_Bus_MFRLib_WriteImage_Param_t::type
mfrImageType_t type
Definition: mfrMgr.h:132
mfrGetDFAST2Data
mfrError_t mfrGetDFAST2Data(mfrDFAST2Params_t *params)
Triggers DFAST operations.
Definition: mfrCli.c:472