RDK Documentation (Open Sourced RDK Components)
Components_XrdkSDCard.cpp
Go to the documentation of this file.
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 tr69hostif
24 * @{
25 * @defgroup hostif
26 * @{
27 **/
28 
29 
30 
31 /**
32  * @file Components_XrdkSDCard.cpp
33  * @brief This source file contains the APIs of TR069 Components external SD Card.
34  */
35 
36 /**
37 * @defgroup tr69hostif
38 * @{
39 * @defgroup hostif
40 * @{
41 **/
42 
43 
44 #ifdef USE_XRDK_SDCARD_PROFILE
45 #include "rdk_debug.h"
46 #include "hostIf_main.h"
47 #include "Components_XrdkSDCard.h"
48 
49 #ifdef USE_RDK_STORAGE_MANAGER_V2
50 #include "rdkStorageMgr.h"
51 /* Declare variable types that can be used to reduce amount change */
52 typedef union _uSDCardParamValue {
53  char uchVal[128];
54  unsigned int ui32Val;
55  int iVal;
56  bool bVal;
57 } uSDCard_Param_Val;
58 
59 typedef enum _eSD_PROPERTY_Type {
60  SD_Capacity,
61  SD_CardFailed,
62  SD_LifeElapsed,
63  SD_LotID,
64  SD_Manufacturer,
65  SD_Model,
66  SD_ReadOnly,
67  SD_SerialNumber,
68  SD_TSBQualified,
69  SD_Status
70 } eSD_ParamPropertyType;
71 
72 typedef struct _strMgrSDcardPropParam_t {
73  uSDCard_Param_Val sdCardProp;
74  eSD_ParamPropertyType eSDPropType;
75 } strMgrSDcardPropParam_t;
76 
77 #else
78 #include "storageMgr.h"
79 #endif /* USE_RDK_STORAGE_MANAGER_V2 */
80 #include "safec_lib.h"
81 
82 static bool getSDCardProperties(strMgrSDcardPropParam_t *);
83 
84 hostIf_STBServiceXSDCard *hostIf_STBServiceXSDCard::instance = NULL;
85 
86 hostIf_STBServiceXSDCard* hostIf_STBServiceXSDCard::getInstance()
87 {
88  if (!instance)
89  {
90  try
91  {
92  instance = new hostIf_STBServiceXSDCard();
93  }
94  catch(const std::exception& e)
95  {
96  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Caught exception \" %s\"\n", __FUNCTION__, e.what());
97  }
98  }
99  return instance;
100 }
101 
102 
103 void hostIf_STBServiceXSDCard::closeInstance(hostIf_STBServiceXSDCard *pDev)
104 {
105  if(pDev)
106  {
107  delete pDev;
108  }
109 }
110 
111 /**
112  * @brief Class default Constructor.
113  */
114 hostIf_STBServiceXSDCard::hostIf_STBServiceXSDCard()
115 {
116  /* capacity = 0;
117  cardFailed = false;
118  lifeElapsed = 0;
119  readOnly = false;
120  tsbQualified = false;
121  memset(lotID, '\0', SD_PARAM_LEN);
122  memset(manufacturer, '\0', SD_PARAM_LEN);
123  memset(model, '\0', SD_PARAM_LEN);
124  memset(serialNumber, '\0', SD_PARAM_LEN); */
125 }
126 
127 /**
128  * @brief This function set the external SD Card interface attribute such as capacity,
129  * cardFailed, lifeElapsed, lotID, manufacturer, model, readOnly, serialNumber, tsbQualified
130  * in a connected external SD Card. Currently not implemented.
131  *
132  * @param[in] stMsgData HostIf Message Request param contains the external SD Card attribute value.
133  *
134  * @return Returns an Integer value.
135  * @retval 0 If successfully set the hostIf external SD Card interface attribute.
136  * @retval -1 If Not able to set the hostIf external SD Card interface attribute.
137  * @retval -2 If Not handle the hostIf external SD Card interface attribute.
138  * @ingroup TR69_HOSTIF_STBSERVICES_SDCARD_API
139  */
140 int hostIf_STBServiceXSDCard::handleSetMsg(HOSTIF_MsgData_t *stMsgData)
141 {
142  int ret = NOT_HANDLED;
143  return ret;
144 }
145 
146 /**
147  * @brief This function get the external SD Card interface attribute such as capacity,
148  * cardFailed, lifeElapsed, lotID, manufacturer, model, readOnly, serialNumber, tsbQualified
149  * in a connected external SD Card.
150  *
151  * @param[in] stMsgData HostIf Message Request param contains the external SD Card attribute value.
152  *
153  * @return Returns an Integer value.
154  * @retval 0 If successfully get the hostIf external SD Card interface attribute.
155  * @retval -1 If Not able to get the hostIf external SD Card interface attribute.
156  * @retval -2 If Not handle the hostIf external SD Card interface attribute.
157  * @ingroup TR69_HOSTIF_STBSERVICES_SDCARD_API
158  */
159 int hostIf_STBServiceXSDCard::handleGetMsg(HOSTIF_MsgData_t *stMsgData)
160 {
161  int ret = NOT_HANDLED;
162  const char *path = NULL, *paramName = NULL;
163  try {
164  int str_len = strlen(X_SDCARD_OBJ);
165  path = stMsgData->paramName;
166 
167  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s]Entering... \n", __FILE__, __FUNCTION__);
168 
169  if(NULL == path) {
170  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s:%d]Failed : Parameter is NULL, %s \n", __FILE__, __FUNCTION__, __LINE__, path);
171  return ret;
172  }
173 
174  if((strncasecmp(path, X_SDCARD_OBJ, str_len) != 0)) {
175  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s:%d]Failed : Mismatch parameter path : %s \n", __FILE__, __FUNCTION__, __LINE__, path);
176  return ret;
177  }
178  const char *tmp_ptr = strchr(path+str_len-1,'.');
179  if(tmp_ptr == NULL) {
180  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Parameter is NULL \n", __FILE__, __FUNCTION__);
181  return ret;
182  }
183 
184  tmp_ptr++;
185  paramName = tmp_ptr;
186  if (strcasecmp(paramName, CAPACITY_STRING) == 0)
187  {
188  ret = getCapacity(stMsgData);
189  }
190  else if (strcasecmp(paramName, CARDFAILED_STRING) == 0)
191  {
192  ret = getCardFailed(stMsgData);
193  }
194  else if (strcasecmp(paramName, LIFEELAPSED_STRING) == 0)
195  {
196  ret = getLifeElapsed(stMsgData);
197  }
198  else if (strcasecmp(paramName, LOTID_STRING) == 0)
199  {
200  ret = getLotID(stMsgData);
201  }
202  else if (strcasecmp(paramName, MANUFACTURED_STRING) == 0)
203  {
204  ret = getManufacturer(stMsgData);
205  }
206  else if (strcasecmp(paramName, MODEL_STRING) == 0)
207  {
208  ret = getModel(stMsgData);
209  }
210  else if (strcasecmp(paramName, READONLY_STRING) == 0)
211  {
212  ret = getReadOnly(stMsgData);
213  }
214  else if (strcasecmp(paramName, SERIALNUMBER_STRING) == 0)
215  {
216  ret = getSerialNumber(stMsgData);
217  }
218  else if (strcasecmp(paramName, TSBQUALIFIED_STRING) == 0)
219  {
220  ret = getTSBQualified(stMsgData);
221  }
222  else if (strcasecmp(paramName, SDCARD_STATUS) == 0)
223  {
224  ret = getStatus(stMsgData);
225  }
226  else
227  {
228  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Parameter \'%s\' is Not Supported \n", __FILE__, __FUNCTION__, paramName);
229  ret = NOK;
230  }
231  }
232  catch (const std::exception& e )
233  {
234  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Exception caught %s \n", __FILE__, __FUNCTION__, e.what());
235  return NOK;
236  }
237  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s]Exiting... \n", __FILE__, __FUNCTION__);
238  return ret;
239 }
240 
241 /************************************************************
242  * Description : Get SD Card memory size in MB
243  * Precondition : SDCard should be connected to STB
244  * Input : stMsgData -> HOSTIF_MsgData_t
245 
246  * Return : OK -> Success
247  NOK -> Failure
248 ************************************************************/
249 int hostIf_STBServiceXSDCard::getCapacity(HOSTIF_MsgData_t *stMsgData)
250 {
251  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
252 
253  try {
254  strMgrSDcardPropParam_t param;
255  memset(&param, '\0', sizeof(param));
256  param.eSDPropType = SD_Capacity;
257  if(getSDCardProperties(&param) ) {
258  // Capacity from getSDCardProperties is in bytes, Need to convert it to MB.
259  unsigned long long capacityBytes = 0;
260  int capacityMegaBytes = 0;
261  capacityBytes = (unsigned long long) param.sdCardProp.ui32Val;
262  capacityMegaBytes = (capacityBytes /1024/1024) ;
263  put_int(stMsgData->paramValue, capacityMegaBytes);
264  }
265  stMsgData->paramtype=hostIf_UnsignedIntType;
266  }
267  catch (const std::exception& e) {
268  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
269  return NOK;
270  }
271  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
272  return OK;
273 }
274 
275 
276 /************************************************************
277  * Description : Get the cardfailed status.
278  * 'true' if the card is no longer readable/writable
279  * which could be due to Card/Host interface failure
280  * Precondition : SDCard should be connected to STB
281  * Input : CardFailed-> Complete Parameter path
282 
283  * Return : OK -> Success
284  NOK -> Failure
285  value -> 0: false
286  -> 1: true
287 
288 ************************************************************/
289 
290 int hostIf_STBServiceXSDCard::getCardFailed(HOSTIF_MsgData_t *stMsgData)
291 {
292  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
293  try {
294  strMgrSDcardPropParam_t param;
295  memset(&param, '\0', sizeof(param));
296  param.eSDPropType = SD_CardFailed;
297  if(getSDCardProperties(&param) ) {
298  put_boolean(stMsgData->paramValue, param.sdCardProp.bVal);
299  }
300  stMsgData->paramtype=hostIf_BooleanType;
301  }
302  catch (const std::exception& e) {
303  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
304  return NOK;
305  }
306  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
307  return OK;
308 }
309 
310 
311 /************************************************************
312  * Description : Get Life Elapsed of SDcard. The value range
313  * from 0 to 100. It may increment in 10% or lower
314  * increments (e.g. 5% or 1%) depending on
315  * Card+Host capabilities. Refer CMD56.
316  * Precondition : SDCard should be connected to STB
317  * Input : stMsgData -> Complete Parameter path
318  * "Device.Services.STBService.1.Components.X_RDKCENTRAL-COM_SDCard.LifeElapsed"
319  *
320  * Return : OK -> Success
321  * NOK -> Failure
322  *
323 ************************************************************/
324 
325 int hostIf_STBServiceXSDCard::getLifeElapsed(HOSTIF_MsgData_t *stMsgData)
326 {
327  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
328  try {
329  strMgrSDcardPropParam_t param;
330  memset(&param, '\0', sizeof(param));
331  param.eSDPropType = SD_LifeElapsed;
332  if(getSDCardProperties(&param) ) {
333  put_int(stMsgData->paramValue, param.sdCardProp.iVal);
334  }
335  stMsgData->paramtype=hostIf_IntegerType;
336  }
337  catch (const std::exception& e) {
338  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
339  return NOK;
340  }
341  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
342  return OK;
343 }
344 
345 
346 /************************************************************
347  * Description : Get LotID of SDCard
348  * Precondition : SDCard should be connected to STB
349  * Input : stMsgData -> Complete Parameter path
350 
351  * Return : OK -> Success
352  NOK -> Failure
353 
354 ************************************************************/
355 
356 int hostIf_STBServiceXSDCard::getLotID(HOSTIF_MsgData_t *stMsgData)
357 {
358  errno_t rc = -1;
359  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
360  try {
361  strMgrSDcardPropParam_t param;
362  memset(&param, '\0', sizeof(param));
363  param.eSDPropType = SD_LotID;
364  if(getSDCardProperties(&param) ) {
365  rc=strcpy_s((char *)stMsgData->paramValue,sizeof(stMsgData->paramValue), (const char*) param.sdCardProp.uchVal);
366  if(rc!=EOK)
367  {
368  ERR_CHK(rc);
369  }
370  }
371  stMsgData->paramtype=hostIf_StringType;
372  }
373  catch (const std::exception& e) {
374  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
375  return NOK;
376  }
377  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
378  return OK;
379 }
380 
381 /************************************************************
382  * Description : Get Manufacturer of SD Flash card
383  * (1 byte MID field in CID register)
384  * Precondition : SDCard should be connected to STB
385  * Input : stMsgData -> HOSTIF_MsgData_t, which contains
386  * complete path path.
387 
388  * Return : OK -> Success
389  NOK -> Failure
390 
391 ************************************************************/
392 
393 int hostIf_STBServiceXSDCard::getManufacturer(HOSTIF_MsgData_t *stMsgData)
394 {
395  errno_t rc = -1;
396  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
397  try {
398  strMgrSDcardPropParam_t param;
399  memset(&param, '\0', sizeof(param));
400  param.eSDPropType = SD_Manufacturer;
401  if(getSDCardProperties(&param) ) {
402  rc=strcpy_s((char *)stMsgData->paramValue,sizeof(stMsgData->paramValue), (const char*) param.sdCardProp.uchVal);
403  if(rc!=EOK)
404  {
405  ERR_CHK(rc);
406  }
407  }
408  stMsgData->paramtype=hostIf_StringType;
409  }
410  catch (const std::exception& e) {
411  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
412  return NOK;
413  }
414  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
415  return OK;
416 }
417 
418 
419 /************************************************************
420  * Description : Get Model of SD Flash card
421  * (5 character PNM field in CID register)
422  * Precondition : SD card should be connected to STB
423  * Input : tMsgData -> HOSTIF_MsgData_t, which contains
424  * complete path path.
425 
426  * Return : OK -> Success
427  NOK -> Failure
428  value -> the audio decibel (DB) level
429 ************************************************************/
430 
431 int hostIf_STBServiceXSDCard::getModel(HOSTIF_MsgData_t *stMsgData)
432 {
433  errno_t rc = -1;
434  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
435  try {
436  strMgrSDcardPropParam_t param;
437  memset(&param, '\0', sizeof(param));
438  param.eSDPropType = SD_Model;
439  if(getSDCardProperties(&param) ) {
440  rc=strcpy_s((char *)stMsgData->paramValue,sizeof(stMsgData->paramValue), (const char*) param.sdCardProp.uchVal);
441  if(rc!=EOK)
442  {
443  ERR_CHK(rc);
444  }
445  }
446  stMsgData->paramtype=hostIf_StringType;
447  }
448  catch (const std::exception& e) {
449  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
450  return NOK;
451  }
452  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
453  return OK;
454 }
455 
456 /************************************************************
457  * Description : Get ReadOnly value of SD Flash card
458  * True if user has switched SD Card to read
459  * only mode. False otherwise.
460  * Precondition : HDMI Display should be connected to STB
461  * Input : tMsgData -> HOSTIF_MsgData_t, which contains
462  * complete path path.
463 
464  * Return : OK -> Success
465  NOK -> Failure
466 
467 ************************************************************/
468 
469 int hostIf_STBServiceXSDCard::getReadOnly(HOSTIF_MsgData_t *stMsgData)
470 {
471  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
472  try {
473  strMgrSDcardPropParam_t param;
474  memset(&param, '\0', sizeof(param));
475  param.eSDPropType = SD_ReadOnly;
476  if(getSDCardProperties(&param) ) {
477  put_boolean(stMsgData->paramValue, param.sdCardProp.bVal);
478  }
479  stMsgData->paramtype=hostIf_BooleanType;
480  }
481  catch (const std::exception& e) {
482  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
483  return NOK;
484  }
485  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
486  return OK;
487 }
488 
489 /************************************************************
490  * Description : Get Unique serial number of SD Flash card
491  * Precondition : SDcard should be connected to STB
492  * Input : tMsgData -> HOSTIF_MsgData_t, which contains
493  * complete path path.
494 
495  * Return : OK -> Success
496  NOK -> Failure
497  value -> 32 bit PSN field in CID register
498 ************************************************************/
499 int hostIf_STBServiceXSDCard::getSerialNumber(HOSTIF_MsgData_t *stMsgData)
500 {
501  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
502  try {
503  strMgrSDcardPropParam_t param;
504  memset(&param, '\0', sizeof(param));
505  param.eSDPropType = SD_SerialNumber;
506  if(getSDCardProperties(&param) ) {
507  sprintf(stMsgData->paramValue,"%s" ,param.sdCardProp.uchVal);
508  }
509  stMsgData->paramtype=hostIf_StringType;
510  }
511  catch (const std::exception& e) {
512  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
513  return NOK;
514  }
515  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
516  return OK;
517 }
518 
519 /************************************************************
520  * Description : Get TSBQualified
521  * Precondition : HDMI Display should be connected to STB
522  * Input : tMsgData -> HOSTIF_MsgData_t, which contains
523  * complete path path.
524 
525  * Return : OK -> Success
526  NOK -> Failure
527  value -> True if card is approved for Comcast TSB use.
528  For Xi3v1, this will be based on the expected signature.
529  False otherwise.
530 ************************************************************/
531 
532 int hostIf_STBServiceXSDCard::getTSBQualified(HOSTIF_MsgData_t *stMsgData)
533 {
534  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
535  try {
536  strMgrSDcardPropParam_t param;
537  memset(&param, '\0', sizeof(param));
538  param.eSDPropType = SD_TSBQualified;
539  if(getSDCardProperties(&param) ) {
540  put_boolean(stMsgData->paramValue, param.sdCardProp.bVal);
541  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] param.sdCardProp.bVal: %d\n", __FUNCTION__, __FILE__, param.sdCardProp.bVal);
542  }
543  stMsgData->paramtype=hostIf_BooleanType;
544  }
545  catch (const std::exception& e) {
546  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
547  return NOK;
548  }
549  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
550  return OK;
551 }
552 
553 /************************************************************
554  * Description : Get TSBQualified
555  * Precondition : HDMI Display should be connected to STB
556  * Input : tMsgData -> HOSTIF_MsgData_t, which contains
557  * complete path path.
558 
559  * Return : OK -> Success
560  NOK -> Failure
561  value -> True if card is approved for Comcast TSB use.
562  For Xi3v1, this will be based on the expected signature.
563  False otherwise.
564 ************************************************************/
565 
566 int hostIf_STBServiceXSDCard::getStatus(HOSTIF_MsgData_t *stMsgData)
567 {
568  errno_t rc = -1;
569  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
570  try {
571  strMgrSDcardPropParam_t param;
572  memset(&param, '\0', sizeof(param));
573  param.eSDPropType = SD_Status;
574  if(getSDCardProperties(&param) ) {
575  rc=strcpy_s((char *)stMsgData->paramValue,sizeof(stMsgData->paramValue), (const char*) param.sdCardProp.uchVal);
576  if(rc!=EOK)
577  {
578  ERR_CHK(rc);
579  }
580  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] param.sdCardProp.bchVal: %d\n", __FUNCTION__, __FILE__, param.sdCardProp.uchVal);
581  }
582  stMsgData->paramtype=hostIf_StringType;
583  }
584  catch (const std::exception& e) {
585  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception : %s\r\n",__FUNCTION__, e.what());
586  return NOK;
587  }
588  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
589  return OK;
590 }
591 
592 
593 
594 bool getSDCardProperties(strMgrSDcardPropParam_t *sdCardParam)
595 {
596  errno_t safec_rc = -1;
597 #ifdef USE_RDK_STORAGE_MANAGER_V2
598  bool rc = true;
599  static char sdCardDeviceID[RDK_STMGR_MAX_STRING_LENGTH] = "";
600  static char sdCardPartitionID[RDK_STMGR_MAX_STRING_LENGTH] = "";
601 
602  eSTMGRReturns stRet;
603  if ('\0' == sdCardDeviceID[0])
604  {
605  eSTMGRDeviceInfoList deviceInfoList;
606  memset (&deviceInfoList, 0, sizeof(deviceInfoList));
607  stRet = rdkStorage_getDeviceInfoList(&deviceInfoList);
608  for (int i = 0; i < deviceInfoList.m_numOfDevices; i++)
609  {
610  if (RDK_STMGR_DEVICE_TYPE_SDCARD == deviceInfoList.m_devices[i].m_type)
611  {
612  safec_rc=memcpy_s (&sdCardDeviceID, RDK_STMGR_MAX_STRING_LENGTH ,&deviceInfoList.m_devices[i].m_deviceID, RDK_STMGR_MAX_STRING_LENGTH);
613  if(safec_rc!= EOK)
614  {
615  ERR_CHK(safec_rc);
616  }
617  safec_rc=memcpy_s (&sdCardPartitionID, RDK_STMGR_MAX_STRING_LENGTH , &deviceInfoList.m_devices[i].m_partitions, RDK_STMGR_MAX_STRING_LENGTH);
618  if(safec_rc!= EOK)
619  {
620  ERR_CHK(safec_rc);
621  }
622  break;
623  }
624  }
625  }
626 
627  if ('\0' != sdCardDeviceID[0])
628  {
629  if (sdCardParam->eSDPropType == SD_LifeElapsed)
630  {
631  eSTMGRHealthInfo healthInfo;
632  memset (&healthInfo, 0 , sizeof(healthInfo));
633  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getHealth (sdCardDeviceID, &healthInfo))
634  {
635  sdCardParam->sdCardProp.iVal = -1;
636  /* FIXME: Update string from "used" to a proper proposed value */
637  for (int i = 0; i < healthInfo.m_diagnostics.m_list.m_numOfAttributes; i++)
638  {
639  if (0 == strcmp (healthInfo.m_diagnostics.m_list.m_diagnostics[i].m_name, "used"))
640  {
641  sdCardParam->sdCardProp.iVal = atoi (healthInfo.m_diagnostics.m_list.m_diagnostics[i].m_value);
642  break;
643  }
644  }
645  }
646  else
647  {
648  sdCardParam->sdCardProp.iVal = -1;
649  }
650  }
651  else
652  {
653  eSTMGRDeviceInfo deviceInfo;
654  memset (&deviceInfo, 0 , sizeof(deviceInfo));
655  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (sdCardDeviceID, &deviceInfo))
656  {
657  switch(sdCardParam->eSDPropType)
658  {
659  case SD_Capacity:
660  sdCardParam->sdCardProp.ui32Val = deviceInfo.m_capacity;
661  break;
662  case SD_CardFailed:
663  /* FIXME: The original code always returns false. so #defined it */
664 #if 0
665  if(deviceInfo.status == SM_DEV_STATUS_NOT_QUALIFIED || deviceInfo.status == SM_DEV_STATUS_NOT_PRESENT)
666  {
667  sdCardParam->sdCardProp.bVal = false;
668  }
669  else
670  {
671  sdCardParam->sdCardProp.bVal = false;
672  }
673 #else
674  sdCardParam->sdCardProp.bVal = false;
675 #endif
676  break;
677  case SD_LotID:
678  {
679  safec_rc=strcpy_s (sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), deviceInfo.m_hwVersion);
680  if(safec_rc!=EOK)
681  {
682  ERR_CHK(safec_rc);
683  }
684  break;
685  }
686  case SD_Manufacturer:
687  {
688  safec_rc=strcpy_s(sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal),deviceInfo.m_manufacturer);
689  if(safec_rc!=EOK)
690  {
691  ERR_CHK(safec_rc);
692  }
693  break;
694  }
695  case SD_Model:
696  {
697  safec_rc=strcpy_s (sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), deviceInfo.m_model);
698  if(safec_rc!=EOK)
699  {
700  ERR_CHK(safec_rc);
701  }
702  break;
703  }
704  case SD_ReadOnly:
705  sdCardParam->sdCardProp.bVal = (deviceInfo.m_status == RDK_STMGR_DEVICE_STATUS_READ_ONLY) ? true : false;
706  break;
707  case SD_SerialNumber:
708  {
709  safec_rc=strcpy_s(sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), deviceInfo.m_serialNumber);
710  if(safec_rc!=EOK)
711  {
712  ERR_CHK(safec_rc);
713  }
714  break;
715  }
716  case SD_Status:
717  {
718  switch (deviceInfo.m_status)
719  {
720  case RDK_STMGR_DEVICE_STATUS_OK:
721  {
722  safec_rc=strcpy_s (sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), "SDCARD_OK");
723  if(safec_rc!=EOK)
724  {
725  ERR_CHK(safec_rc);
726  }
727  break;
728  }
729  case RDK_STMGR_DEVICE_STATUS_READ_ONLY:
730  {
731  safec_rc=strcpy_s (sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), "SDCARD_READ_ONLY");
732  if(safec_rc!=EOK)
733  {
734  ERR_CHK(safec_rc);
735  }
736  break;
737  }
738  case RDK_STMGR_DEVICE_STATUS_NOT_PRESENT:
739  {
740  safec_rc=strcpy_s (sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), "SDCARD_NOT_PRESENT");
741  if(safec_rc!=EOK)
742  {
743  ERR_CHK(safec_rc);
744  }
745  break;
746  }
747  case RDK_STMGR_DEVICE_STATUS_NOT_QUALIFIED:
748  {
749  safec_rc=strcpy_s (sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), "SDCARD_NOT_QUALIFIED");
750  if(safec_rc!=EOK)
751  {
752  ERR_CHK(safec_rc);
753  }
754  break;
755  }
756  case RDK_STMGR_DEVICE_STATUS_DISK_FULL:
757  {
758  safec_rc=strcpy_s (sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), "SDCARD_DISK_FULL");
759  if(safec_rc!=EOK)
760  {
761  ERR_CHK(safec_rc);
762  }
763  break;
764  }
765  case RDK_STMGR_DEVICE_STATUS_READ_FAILURE:
766  {
767  safec_rc=strcpy_s (sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), "SDCARD_READ_FAILURE");
768  if(safec_rc!=EOK)
769  {
770  ERR_CHK(safec_rc);
771  }
772  break;
773  }
774  case RDK_STMGR_DEVICE_STATUS_WRITE_FAILURE:
775  {
776  safec_rc=strcpy_s (sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), "SDCARD_WRITE_FAILURE");
777  if(safec_rc!=EOK)
778  {
779  ERR_CHK(safec_rc);
780  }
781  break;
782  }
783  }
784  break;
785  }
786  case SD_TSBQualified:
787  sdCardParam->sdCardProp.bVal = (deviceInfo.m_status != RDK_STMGR_DEVICE_STATUS_NOT_QUALIFIED &&
788  deviceInfo.m_status != RDK_STMGR_DEVICE_STATUS_UNKNOWN);
789  break;
790  }
791  }
792  else
793  {
794  RDK_LOG(RDK_LOG_WARN, LOG_TR69HOSTIF, "[%s] Gettng the device specific information failed\n",__FUNCTION__);
795  switch(sdCardParam->eSDPropType)
796  {
797  case SD_Status:
798  {
799  safec_rc=strcpy_s(sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), (const char*)"None");
800  if(safec_rc!=EOK)
801  {
802  ERR_CHK(safec_rc);
803  }
804  break;
805  }
806  }
807  }
808  }
809  }
810  else
811  {
812  RDK_LOG(RDK_LOG_WARN, LOG_TR69HOSTIF, "[%s] This platform does not have SD card\n",__FUNCTION__);
813  switch(sdCardParam->eSDPropType)
814  {
815  case SD_Status:
816  {
817  safec_rc=strcpy_s(sdCardParam->sdCardProp.uchVal,sizeof(sdCardParam->sdCardProp.uchVal), (const char*)"None");
818  if(safec_rc!=EOK)
819  {
820  ERR_CHK(safec_rc);
821  }
822  break;
823  }
824  }
825  }
826 
827 
828  return rc;
829 #else
830  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
831  IARM_Bus_STRMgr_Param_t param;
832  bool ret = true;
833 
834  memset(&param, 0, sizeof(param));
835 
836  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
837  try {
838  param.data.stSDCardParams.eSDPropType = sdCardParam->eSDPropType;
839 
840  retVal = IARM_Bus_Call(IARM_BUS_ST_MGR_NAME, IARM_BUS_STORAGE_MGR_API_GetSDcardPropertyInfo, (void *)&param, sizeof(param));
841 
842  if(retVal == IARM_RESULT_SUCCESS && (param.status))
843  {
844  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"[%s] Successfully return from \'%s\' \n", __FUNCTION__, IARM_BUS_STORAGE_MGR_API_GetSDcardPropertyInfo);
845  sdCardParam->sdCardProp = param.data.stSDCardParams.sdCardProp;
846  }
847  else {
848 
849  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s] Failed to return from \'%s\' \n", __FUNCTION__, IARM_BUS_STORAGE_MGR_API_GetSDcardPropertyInfo);
850  ret = false;
851  }
852 
853  }
854  catch (const std::exception& e) {
855  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Exception %s\r\n",__FUNCTION__, e.what());
856  ret = false;
857  }
858  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
859  return ret;
860 #endif
861 }
862 
863 
864 #endif
865 
866 
867 /** @} */
868 /** @} */
Components_XrdkSDCard.h
The header file provides components Xrdk SDCard information APIs.
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
rdk_debug.h
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
put_boolean
void put_boolean(char *ptr, bool val)
This function converts the input data to Boolean type.
Definition: hostIf_utils.cpp:191
hostIf_main.h
hostIf_main API.
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
hostIf_STBServiceXSDCard
This class provides the TR-069 components XSD Card information.
Definition: Components_XrdkSDCard.h:81
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152