RDK Documentation (Open Sourced RDK Components)
Components_XrdkEMMC.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  * @file Components_XrdkEMMC.cpp
22  * @brief This source file contains API implementation to handle data model parameters for the eMMC component.
23  */
24 
25 /**
26 * @defgroup tr69hostif
27 * @{
28 * @defgroup hostif
29 * @{
30 **/
31 
32 #ifdef USE_XRDK_EMMC_PROFILE
33 
34 #include "rdk_debug.h"
35 #include "hostIf_main.h"
36 #include "Components_XrdkEMMC.h"
37 
38 #include <exception>
39 #include <map>
40 
41 #ifdef USE_RDK_STORAGE_MANAGER_V2
42 #include "rdkStorageMgr.h"
43 #else
44 #include "storageMgr.h"
45 #endif // ifdef USE_RDK_STORAGE_MANAGER_V2
46 #include "safec_lib.h"
47 
48 hostIf_STBServiceXeMMC *hostIf_STBServiceXeMMC::instance = NULL;
49 
50 hostIf_STBServiceXeMMC* hostIf_STBServiceXeMMC::getInstance()
51 {
52  errno_t safec_rc = -1;
53  if (!instance)
54  {
55  char emmcDeviceID[RDK_STMGR_MAX_STRING_LENGTH] = "";
56  char emmcPartitionID[RDK_STMGR_MAX_STRING_LENGTH] = "";
57 
58  eSTMGRDeviceInfoList deviceInfoList;
59  eSTMGRReturns stRet = rdkStorage_getDeviceInfoList (&deviceInfoList);
60  for (int i = 0; i < deviceInfoList.m_numOfDevices; i++)
61  {
62  if (RDK_STMGR_DEVICE_TYPE_EMMCCARD == deviceInfoList.m_devices[i].m_type)
63  {
64  safec_rc=memcpy_s (emmcDeviceID, RDK_STMGR_MAX_STRING_LENGTH , &deviceInfoList.m_devices[i].m_deviceID,RDK_STMGR_MAX_STRING_LENGTH);
65  if(safec_rc!=EOK)
66  {
67  ERR_CHK(safec_rc);
68  }
69  safec_rc=memcpy_s (emmcPartitionID, RDK_STMGR_MAX_STRING_LENGTH , &deviceInfoList.m_devices[i].m_partitions,RDK_STMGR_MAX_STRING_LENGTH);
70  if(safec_rc!=EOK)
71  {
72  ERR_CHK(safec_rc);
73  }
74  break;
75  }
76  }
77 
78  try
79  {
80  if (*emmcDeviceID)
81  {
82  instance = new hostIf_STBServiceXeMMC(emmcDeviceID, emmcPartitionID);
83  }
84  else
85  {
86  RDK_LOG(RDK_LOG_WARN, LOG_TR69HOSTIF, "[%s] Failed: eMMC not found\n",__FUNCTION__);
87  }
88  }
89  catch(const std::exception& e)
90  {
91  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s] Caught exception \" %s\"\n", __FUNCTION__, e.what());
92  }
93  }
94  return instance;
95 }
96 
97 void hostIf_STBServiceXeMMC::closeInstance(hostIf_STBServiceXeMMC *pDev)
98 {
99  if(pDev)
100  {
101  delete pDev;
102  }
103 }
104 
105 hostIf_STBServiceXeMMC::hostIf_STBServiceXeMMC(char* emmcDeviceID, char* emmcPartitionID)
106 {
107  snprintf (this->emmcDeviceID, sizeof(this->emmcDeviceID), "%s", emmcDeviceID);
108  snprintf (this->emmcPartitionID, sizeof(this->emmcPartitionID), "%s", emmcPartitionID);
109 }
110 
111 int hostIf_STBServiceXeMMC::handleSetMsg(HOSTIF_MsgData_t *stMsgData)
112 {
113  int ret = NOT_HANDLED;
114  return ret;
115 }
116 
117 int hostIf_STBServiceXeMMC::handleGetMsg(HOSTIF_MsgData_t *stMsgData)
118 {
119  LOG_ENTRY_EXIT;
120 
121  typedef int (hostIf_STBServiceXeMMC::*getter_function) (HOSTIF_MsgData_t *);
122  typedef std::pair<const char*, getter_function> getter_function_entry;
123  #define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))
124 
125  static getter_function_entry getter_function_map[] = {
126  {"Capacity", &hostIf_STBServiceXeMMC::getCapacity},
127  {"LifeElapsedA", &hostIf_STBServiceXeMMC::getLifeElapsedA},
128  {"LifeElapsedB", &hostIf_STBServiceXeMMC::getLifeElapsedB},
129  {"LotID", &hostIf_STBServiceXeMMC::getLotID},
130  {"Manufacturer", &hostIf_STBServiceXeMMC::getManufacturer},
131  {"Model", &hostIf_STBServiceXeMMC::getModel},
132  {"ReadOnly", &hostIf_STBServiceXeMMC::getReadOnly},
133  {"SerialNumber", &hostIf_STBServiceXeMMC::getSerialNumber},
134  {"TSBQualified", &hostIf_STBServiceXeMMC::getTSBQualified},
135  {"PreEOLStateSystem", &hostIf_STBServiceXeMMC::getPreEOLStateSystem},
136  {"PreEOLStateEUDA", &hostIf_STBServiceXeMMC::getPreEOLStateEUDA},
137  {"PreEOLStateMLC", &hostIf_STBServiceXeMMC::getPreEOLStateMLC},
138  {"FirmwareVersion", &hostIf_STBServiceXeMMC::getFirmwareVersion},
139  {"DeviceReport", &hostIf_STBServiceXeMMC::getDeviceReport} };
140 
141  int str_len = strlen(X_EMMC_OBJ);
142  if ((strncasecmp(stMsgData->paramName, X_EMMC_OBJ, str_len) != 0))
143  {
144  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Failed : Mismatch parameter path : %s\n", __FILE__, __FUNCTION__, stMsgData->paramName);
145  return NOK;
146  }
147 
148  const char *paramName = strchr(stMsgData->paramName + str_len - 1, '.');
149  if (paramName == NULL)
150  {
151  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Parameter is NULL \n", __FILE__, __FUNCTION__);
152  return NOK;
153  }
154  paramName++;
155 
156  try
157  {
158  for (const auto& entry : getter_function_map)
159  if (strcasecmp (paramName, entry.first) == 0)
160  return CALL_MEMBER_FN(*this, entry.second)(stMsgData);
161  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s:%s] Parameter \'%s\' is Not Supported \n", __FILE__, __FUNCTION__, paramName);
162  }
163  catch (const std::exception& e)
164  {
165  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Exception caught %s \n", __FILE__, __FUNCTION__, e.what());
166  }
167  return NOK;
168 }
169 
170 int hostIf_STBServiceXeMMC::getCapacity(HOSTIF_MsgData_t *stMsgData)
171 {
172  LOG_ENTRY_EXIT;
173 
174  stMsgData->paramtype = hostIf_UnsignedIntType;
175 
176  eSTMGRDeviceInfo deviceInfo;
177  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (emmcDeviceID, &deviceInfo))
178  {
179  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF, "[%s:%s] deviceInfo.m_capacity = %llu\n",
180  __FILE__, __FUNCTION__, deviceInfo.m_capacity);
181 
182  put_int(stMsgData->paramValue, (int) (deviceInfo.m_capacity / 1024 / 1024)); // returned capacity is in bytes, convert to MB
183  return OK;
184  }
185  else
186  {
187  put_int(stMsgData->paramValue, 0);
188  return NOK;
189  }
190 }
191 
192 int hostIf_STBServiceXeMMC::getLifeElapsedA(HOSTIF_MsgData_t *stMsgData)
193 {
194  LOG_ENTRY_EXIT;
195 
196  return getLifeElapsed(stMsgData, "LifeElapsedA");
197 }
198 
199 int hostIf_STBServiceXeMMC::getLifeElapsedB(HOSTIF_MsgData_t *stMsgData)
200 {
201  LOG_ENTRY_EXIT;
202 
203  return getLifeElapsed(stMsgData, "LifeElapsedB");
204 }
205 
206 int hostIf_STBServiceXeMMC::getLifeElapsed(HOSTIF_MsgData_t *stMsgData, const char* life_elapsed_type)
207 {
208  LOG_ENTRY_EXIT;
209 
210  stMsgData->paramtype = hostIf_IntegerType;
211 
212  eSTMGRHealthInfo healthInfo;
213  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getHealth (emmcDeviceID, &healthInfo))
214  {
215  for (int i = 0; i < healthInfo.m_lifetimesList.m_numOfAttributes; i++)
216  {
217  if (0 == strcmp (healthInfo.m_lifetimesList.m_diagnostics[i].m_name, life_elapsed_type))
218  {
219  put_int(stMsgData->paramValue, atoi (healthInfo.m_lifetimesList.m_diagnostics[i].m_value));
220  return OK;
221  }
222  }
223  }
224 
225  put_int(stMsgData->paramValue, -1); // Error
226  return NOK;
227 }
228 
229 int hostIf_STBServiceXeMMC::getLotID(HOSTIF_MsgData_t *stMsgData)
230 {
231  LOG_ENTRY_EXIT;
232 
233  stMsgData->paramtype = hostIf_StringType;
234 
235  errno_t rc = -1;
236  eSTMGRDeviceInfo deviceInfo;
237  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (emmcDeviceID, &deviceInfo))
238  {
239  rc=strcpy_s((char*) stMsgData->paramValue, sizeof(stMsgData->paramValue),deviceInfo.m_hwVersion);
240  if(rc!=EOK)
241  {
242  ERR_CHK(rc);
243  }
244  return OK;
245  }
246  else
247  {
248  stMsgData->paramValue[0]='\0';
249  return NOK;
250  }
251 }
252 
253 int hostIf_STBServiceXeMMC::getManufacturer(HOSTIF_MsgData_t *stMsgData)
254 {
255  LOG_ENTRY_EXIT;
256 
257  stMsgData->paramtype = hostIf_StringType;
258 
259  errno_t rc = -1;
260  eSTMGRDeviceInfo deviceInfo;
261  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (emmcDeviceID, &deviceInfo))
262  {
263  rc=strcpy_s((char*) stMsgData->paramValue,sizeof(stMsgData->paramValue), deviceInfo.m_manufacturer);
264  if(rc!=EOK)
265  {
266  ERR_CHK(rc);
267  }
268  return OK;
269  }
270  else
271  {
272  stMsgData->paramValue[0]='\0';
273  return NOK;
274  }
275 }
276 
277 int hostIf_STBServiceXeMMC::getModel(HOSTIF_MsgData_t *stMsgData)
278 {
279  LOG_ENTRY_EXIT;
280 
281  stMsgData->paramtype = hostIf_StringType;
282 
283  errno_t rc = -1;
284  eSTMGRDeviceInfo deviceInfo;
285  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (emmcDeviceID, &deviceInfo))
286  {
287  rc=strcpy_s((char*) stMsgData->paramValue,sizeof(stMsgData->paramValue), deviceInfo.m_model);
288  if(rc!=EOK)
289  {
290  ERR_CHK(rc);
291  }
292  return OK;
293  }
294  else
295  {
296  stMsgData->paramValue[0]='\0';
297  return NOK;
298  }
299 }
300 
301 int hostIf_STBServiceXeMMC::getReadOnly(HOSTIF_MsgData_t *stMsgData)
302 {
303  LOG_ENTRY_EXIT;
304 
305  stMsgData->paramtype = hostIf_BooleanType;
306 
307  eSTMGRDeviceInfo deviceInfo;
308  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (emmcDeviceID, &deviceInfo))
309  {
310  put_boolean(stMsgData->paramValue, (deviceInfo.m_status == RDK_STMGR_DEVICE_STATUS_READ_ONLY));
311  return OK;
312  }
313  else
314  {
315  put_boolean(stMsgData->paramValue, true);
316  return NOK;
317  }
318 }
319 
320 int hostIf_STBServiceXeMMC::getSerialNumber(HOSTIF_MsgData_t *stMsgData)
321 {
322  LOG_ENTRY_EXIT;
323 
324  stMsgData->paramtype = hostIf_StringType;
325 
326  errno_t rc = -1;
327  eSTMGRDeviceInfo deviceInfo;
328  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (emmcDeviceID, &deviceInfo))
329  {
330  rc=strcpy_s((char*) stMsgData->paramValue,sizeof(stMsgData->paramValue), deviceInfo.m_serialNumber);
331  if(rc!=EOK)
332  {
333  ERR_CHK(rc);
334  }
335  return OK;
336  }
337  else
338  {
339  stMsgData->paramValue[0]='\0';
340  return NOK;
341  }
342 }
343 
344 // TODO: is a "TSBQualified" data model parameter even needed for an eMMC (which cannot be pulled out of the device) ?
345 int hostIf_STBServiceXeMMC::getTSBQualified(HOSTIF_MsgData_t *stMsgData)
346 {
347  LOG_ENTRY_EXIT;
348 
349  stMsgData->paramtype = hostIf_BooleanType;
350 
351  eSTMGRDeviceInfo deviceInfo;
352  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (emmcDeviceID, &deviceInfo))
353  {
354  put_boolean(stMsgData->paramValue, (deviceInfo.m_status != RDK_STMGR_DEVICE_STATUS_NOT_QUALIFIED));
355  return OK;
356  }
357  else
358  {
359  put_boolean(stMsgData->paramValue, true); // assume eMMC (a non-user-removable part) is Comcast-approved and thus TSB-qualified
360  return OK;
361  }
362 }
363 
364 int hostIf_STBServiceXeMMC::getPreEOLStateSystem(HOSTIF_MsgData_t *stMsgData)
365 {
366  LOG_ENTRY_EXIT;
367 
368  return getPreEOLState(stMsgData, "PreEOLStateSystem");
369 }
370 
371 int hostIf_STBServiceXeMMC::getPreEOLStateEUDA(HOSTIF_MsgData_t *stMsgData)
372 {
373  LOG_ENTRY_EXIT;
374 
375  return getPreEOLState(stMsgData, "PreEOLStateEUDA");
376 }
377 
378 int hostIf_STBServiceXeMMC::getPreEOLStateMLC(HOSTIF_MsgData_t *stMsgData)
379 {
380  LOG_ENTRY_EXIT;
381 
382  return getPreEOLState(stMsgData, "PreEOLStateMLC");
383 }
384 
385 int hostIf_STBServiceXeMMC::getPreEOLState(HOSTIF_MsgData_t *stMsgData, const char* pre_eol_state_type)
386 {
387  LOG_ENTRY_EXIT;
388 
389  stMsgData->paramtype = hostIf_StringType;
390 
391  eSTMGRHealthInfo healthInfo;
392  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getHealth (emmcDeviceID, &healthInfo))
393  {
394  for (int i = 0; i < healthInfo.m_healthStatesList.m_numOfAttributes; i++)
395  {
396  if (0 == strcmp (healthInfo.m_healthStatesList.m_diagnostics[i].m_name, pre_eol_state_type))
397  {
398  snprintf (stMsgData->paramValue, sizeof (stMsgData->paramValue), healthInfo.m_healthStatesList.m_diagnostics[i].m_value);
399  return OK;
400  }
401  }
402  }
403 
404  snprintf (stMsgData->paramValue, sizeof (stMsgData->paramValue), "Error");
405  return NOK;
406 }
407 
408 int hostIf_STBServiceXeMMC::getFirmwareVersion(HOSTIF_MsgData_t *stMsgData)
409 {
410  LOG_ENTRY_EXIT;
411 
412  stMsgData->paramtype = hostIf_StringType;
413 
414  errno_t rc = -1;
415  eSTMGRDeviceInfo deviceInfo;
416  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getDeviceInfo (emmcDeviceID, &deviceInfo))
417  {
418  rc=strcpy_s((char*) stMsgData->paramValue,sizeof(stMsgData->paramValue), deviceInfo.m_firmwareVersion);
419  if(rc!=EOK)
420  {
421  ERR_CHK(rc);
422  }
423  return OK;
424  }
425  else
426  {
427  stMsgData->paramValue[0]='\0';
428  return NOK;
429  }
430 }
431 
432 int hostIf_STBServiceXeMMC::getDeviceReport(HOSTIF_MsgData_t *stMsgData)
433 {
434  LOG_ENTRY_EXIT;
435 
436  stMsgData->paramtype = hostIf_StringType;
437 
438  eSTMGRHealthInfo healthInfo;
439  if (RDK_STMGR_RETURN_SUCCESS == rdkStorage_getHealth (emmcDeviceID, &healthInfo))
440  {
441  snprintf(stMsgData->paramValue, sizeof(stMsgData->paramValue), healthInfo.m_diagnostics.m_blob);
442 // memcpy(stMsgData->paramValue, healthInfo.m_diagnostics.m_blob, sizeof (healthInfo.m_diagnostics.m_blob));
443 // stMsgData->paramValue[sizeof (healthInfo.m_diagnostics.m_blob)] = '\0';
444 // stMsgData->paramLen = sizeof (healthInfo.m_diagnostics.m_blob);
445  return OK;
446  }
447 
448  stMsgData->paramValue[0] = '\0';
449 // stMsgData->paramLen = 0;
450  return NOK;
451 }
452 
453 #endif // ifdef USE_XRDK_EMMC_PROFILE
454 
455 /** @} */
456 /** @} */
Components_XrdkEMMC.h
eMMC diagnostic APIs.
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_STBServiceXeMMC
Definition: Components_XrdkEMMC.h:44
_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
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152