RDK Documentation (Open Sourced RDK Components)
Service_Storage_PhyMedium.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 Service_Storage_PhyMedium.cpp
22  * @brief This source file contains the APIs of TR069 storage service physical medium.
23  */
24 #include <string.h>
25 #include <errno.h>
27 #include "Service_Storage.h"
28 
29 #ifdef YOCTO_BUILD
30 #include "secure_wrapper.h"
31 #endif
32 
33 #define MAX_CMD_LEN 256
34 #define MAX_BUF_LEN 256
35 #define MAX_IP_LEN 16
36 #define MAX_MEDIUM_LEN 64
37 #define CMD_TO_GET_MED_NUM "fdisk -l | grep Disk | egrep -v \"mtdblock|mmcblk\"| wc -l"
38 #define CMD_TO_GET_MED_NAME "fdisk -l | grep Disk | egrep -v \"mtdblock|mmcblk\"| sed -n %dp | awk '{print $2}'"
39 #define CMD_TO_CHECK_SMART_CAP "smartctl --scan | awk 'BEGIN {ORS=\",\"}{ print $1}'"
40 #define CMD_TO_CHECK_SMART_HEALTH "smartctl -A %s | egrep \"%s\" | awk 'BEGIN {ORS=\",\"} {print $9}'"
41 #define STORAGE_PHYMED_SMARTPARAMS "Raw_Read_Error_Rate|\
42 Reported_Uncorrect|\
43 Airflow_Temperature_Cel|\
44 G-Sense_Error_Rate|\
45 Reallocated_Sector_Ct|\
46 Temperature_Celsius"
47 
48 
49 PhysicalMediumMembers_t hostIf_PhysicalMedium::physicalMediumMembers = {{'\0'}, {'\0'}, {'\0'}, {'\0'}, {'\0'}, {'\0'}, {'\0'}, false, 0, {'\0'}, 0, false, {'\0'}, false};
50 GHashTable *hostIf_PhysicalMedium::phyMedHash = NULL;
51 GMutex *hostIf_PhysicalMedium::m_mutex = NULL;
52 
53 /**
54  * @enum ePhyMediumErrorCode_t
55  * @brief The enum holds the required error code parameters such as command execution fail, invalid
56  * param etc.. for the error code physical medium storage service.
57  */
58 typedef enum
59 {
60  PHYMED_GEN_FAILURE = -1,
61  PHYMED_CMD_EXEC_FAIL = -2,
62  PHYMED_INVALID_PARAM = -3
64 
65 /**
66  * @enum ePhyMedHealthCode_t
67  * @brief The enum holds the required health code parameters such as health invalid, health ok etc..
68  * for the health code physical medium storage service.
69  */
70 typedef enum
71 {
72  PHYMED_HEALTH_INVALID = 100,
73  PHYMED_HEALTH_OK = 101,
74  PHYMED_HEALTH_FAILING = 102,
75  PHYMED_HEALTH_ERROR = 103,
77 
78 /* Constructor for hostIf_PhysicalMedium*/
79 
80 /**
81  * @brief Class Constructor of the class hostIf_PhysicalMedium.
82  *
83  * It will initialize the device id and instance number of the storage service.
84  *
85  * @param[in] storageServiceInstanceNumber Instance number of the storage service.
86  * @param[in] dev_id Device identification number.
87  */
88 hostIf_PhysicalMedium::hostIf_PhysicalMedium(int storageServiceInstanceNumber, int dev_id):storageServiceInstanceNumber(storageServiceInstanceNumber),dev_id(dev_id)
89 {
90  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Inside constructor for dev_id:%d\n", dev_id);
91 }
92 
93 /**
94  * @brief This function get the lock before setting or getting the attributes of the
95  * host interface physical medium.
96  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
97  */
99 {
100  if(!m_mutex)
101  {
102  m_mutex = g_mutex_new();
103  }
104  g_mutex_lock(m_mutex);
105 }
106 
107 /**
108  * @brief This function use to release the lock before setting or getting the
109  * attributes of the host interface physical medium.
110  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
111  */
113 {
114  g_mutex_unlock(m_mutex);
115 }
116 
117 int hostIf_PhysicalMedium::rebuildHash()
118 {
119  HOSTIF_MsgData_t stMsgData;
120  int storageServiceMaxInstance =0;
121  int phyMedMaxInstance = 0;
122  int retVal = OK;
123  hostIf_PhysicalMedium* pRet = NULL;
124 
125 
126  if(phyMedHash)
127  {
128  closeAllInstances();
129  }
130  else
131  {
132  phyMedHash = g_hash_table_new(NULL, NULL);
133  }
134 
135  memset(&stMsgData, 0 ,sizeof(stMsgData));
136  if(OK == hostIf_StorageSrvc :: get_Device_StorageSrvc_ClientNumberOfEntries(&stMsgData))
137  {
138  storageServiceMaxInstance = stMsgData.paramValue;
139  for(int storageServiceInstance = 1; storageServiceInstance<= storageServiceMaxInstance; storageServiceInstance++)
140  {
141  memset(&stMsgData, 0 ,sizeof(stMsgData));
142  if((phyMedMaxInstance = getPhysicalMediumNumberOfEntries (storageServiceInstance))!=0)
143  {
144  for( int phyMedInstance = 1; phyMedInstance<= phyMedMaxInstance; phyMedInstance++)
145  {
146  try
147  {
148  pRet = new hostIf_PhysicalMedium(storageServiceInstance, phyMedInstance);
149  g_hash_table_insert(phyMedHash, (gpointer)((storageServiceInstance * 100 ) + phyMedInstance), pRet);
150  }
151  catch(int e)
152  {
153  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create physical medium instance..\n");
154  }
155  }
156  }
157  else
158  {
159  retVal = NOK;
160  }
161  }
162  }
163  else
164  {
165  retVal = NOK;
166  }
167  return retVal;
168 }
169 
170 hostIf_PhysicalMedium* hostIf_PhysicalMedium::getInstance(int storageServiceInstanceNumber, int dev_id)
171 {
172  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Entering [%s]\n", __FUNCTION__);
173  int maxInstance = 0;
174  HOSTIF_MsgData_t stMsgData;
175  hostIf_PhysicalMedium* pRet = NULL;
176  if(NULL == phyMedHash)
177  {
178  rebuildHash();
179  }
180  pRet = (hostIf_PhysicalMedium *)g_hash_table_lookup(phyMedHash, (gpointer) ((storageServiceInstanceNumber * 100) + dev_id));
181  return pRet;
182 }
183 
184 
185 GList* hostIf_PhysicalMedium::getAllInstances()
186 {
187  if(phyMedHash)
188  return g_hash_table_get_keys(phyMedHash);
189  return NULL;
190 }
191 
192 
193 void hostIf_PhysicalMedium::closeInstance(hostIf_PhysicalMedium *pDev)
194 {
195  if(pDev)
196  {
197  g_hash_table_remove(phyMedHash, (gconstpointer)pDev->dev_id);
198  delete pDev;
199  }
200 }
201 
202 
203 void hostIf_PhysicalMedium::closeAllInstances()
204 {
205  if(phyMedHash)
206  {
207  GList* values_list = g_hash_table_get_values (phyMedHash);
208  GList* tmp_list = values_list;
209  while(tmp_list)
210  {
211  hostIf_PhysicalMedium* pDev = (hostIf_PhysicalMedium *)tmp_list->data;
212  tmp_list = tmp_list->next;
213  closeInstance(pDev);
214  }
215  g_list_free(values_list);
216  }
217 }
218 
219 
220 int hostIf_PhysicalMedium :: getPhysicalMediumNumberOfEntries(int StorageServiceId)
221 {
222  int num = 0;
223  char cmd[MAX_CMD_LEN]={'\0'};
224  FILE* cmdOp = NULL;
225  char buffer[MAX_BUF_LEN]={'\0'};
226 
227  if (1 == StorageServiceId)
228  {
229  snprintf(cmd, MAX_CMD_LEN, CMD_TO_GET_MED_NUM);
230  cmdOp = popen(cmd, "r");
231  if(NULL != cmdOp)
232  {
233  fgets(buffer, MAX_BUF_LEN, cmdOp);
234  num = strtol(buffer,NULL,10);
235  pclose(cmdOp);
236  }
237  else
238  {
239  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error in execuing the command:%s errno:%d\n", cmd, errno);
240  }
241  }
242  return num;
243 
244 }
245 
246 int hostIf_PhysicalMedium:: get_Device_Service_StorageMedium_ClientNumberOfEntries(HOSTIF_MsgData_t *stMsgData, int dev_id)
247 {
248 
249  int num = 0;
250  int retVal = NOK;
251  errno = 0;
252  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Received dev_id:%d\n",dev_id);
253  num = getPhysicalMediumNumberOfEntries(dev_id);
254  put_int(stMsgData->paramValue, num);
255  stMsgData->paramtype = hostIf_UnsignedIntType;
256  stMsgData->paramLen = sizeof(unsigned int);
257  retVal = OK;
258  if(OK != rebuildHash())
259  {
260  retVal = NOK;
261  }
262  return retVal;
263 }
264 
265 /**
266  * @brief This function get the name of the storage service medium.
267  *
268  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
269  *
270  * @return Returns an Integer value.
271  * @retval 0 If successfully get the hostIf storage medium interface attribute.
272  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
273  * @retval -2 If Not handle the hostIf storage medium interface attribute.
274  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
275  */
277 {
278  int ret = get_StorageService_PhyMed_Fields(eName);
279  if(OK == ret)
280  {
281  strncpy(stMsgData->paramValue, physicalMediumMembers.name, TR69HOSTIFMGR_MAX_PARAM_LEN -1);
282  stMsgData->paramValue[TR69HOSTIFMGR_MAX_PARAM_LEN -1]='\0';
283  stMsgData->paramLen=strlen(physicalMediumMembers.name);
284  stMsgData->paramtype = hostIf_StringType;
285  }
286  return ret;
287 }
288 
289 /**
290  * @brief This function get the health of the storage service medium.
291  *
292  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
293  *
294  * @return Returns an Integer value.
295  * @retval 0 If successfully get the hostIf storage medium interface attribute.
296  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
297  * @retval -2 If Not handle the hostIf storage medium interface attribute.
298  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
299  */
301 {
302  int ret = get_StorageService_PhyMed_Fields(eHealth);
303  if(OK == ret)
304  {
305  strncpy(stMsgData->paramValue, physicalMediumMembers.health, TR69HOSTIFMGR_MAX_PARAM_LEN -1);
306  stMsgData->paramValue[TR69HOSTIFMGR_MAX_PARAM_LEN -1]='\0';
307  stMsgData->paramLen=strlen(physicalMediumMembers.health);
308  stMsgData->paramtype = hostIf_StringType;
309  }
310  return ret;
311 }
312 
313 /**
314  * @brief This function get the SMART capability of the storage service medium.
315  *
316  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
317  *
318  * @return Returns an Integer value.
319  * @retval 0 If successfully get the hostIf storage medium interface attribute.
320  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
321  * @retval -2 If Not handle the hostIf storage medium interface attribute.
322  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
323  */
325 {
326  int ret = get_StorageService_PhyMed_Fields(eSmartCapable);
327  if(OK == ret)
328  {
329  put_int(stMsgData->paramValue, physicalMediumMembers.smartCapable);
330  stMsgData->paramLen=sizeof(bool);
331  stMsgData->paramtype = hostIf_BooleanType;
332  }
333  return ret;
334 }
335 
336 /**
337  * @brief This function get the alias of storage service medium.
338  * Currently not implemented.
339  *
340  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
341  *
342  * @return Returns an Integer value.
343  * @retval 0 If successfully get the hostIf storage medium interface attribute.
344  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
345  * @retval -2 If Not handle the hostIf storage medium interface attribute.
346  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
347  */
349 {
350  // TODO
351  return NOK;
352 }
353 
354 /**
355  * @brief This function get the vendor of the storage service medium.
356  * Currently not implemented.
357  *
358  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
359  *
360  * @return Returns an Integer value.
361  * @retval 0 If successfully get the hostIf storage medium interface attribute.
362  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
363  * @retval -2 If Not handle the hostIf storage medium interface attribute.
364  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
365  */
367 {
368  // TODO
369  return NOK;
370 }
371 
372 /**
373  * @brief This function get the model number of the storage service medium.
374  * Currently not implemented.
375  *
376  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
377  *
378  * @return Returns an Integer value.
379  * @retval 0 If successfully get the hostIf storage medium interface attribute.
380  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
381  * @retval -2 If Not handle the hostIf storage medium interface attribute.
382  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
383  */
385 {
386  // TODO
387  return NOK;
388 }
389 
390 /**
391  * @brief This function get the serial number of the storage service medium.
392  * Currently not implemented.
393  *
394  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
395  *
396  * @return Returns an Integer value.
397  * @retval 0 If successfully get the hostIf storage medium interface attribute.
398  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
399  * @retval -2 If Not handle the hostIf storage medium interface attribute.
400  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
401  */
403 {
404  // TODO
405  return NOK;
406 }
407 
408 /**
409  * @brief This function get the firmware version of the storage service medium.
410  * Currently not implemented.
411  *
412  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
413  *
414  * @return Returns an Integer value.
415  * @retval 0 If successfully get the hostIf storage medium interface attribute.
416  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
417  * @retval -2 If Not handle the hostIf storage medium interface attribute.
418  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
419  */
421 {
422  // TODO
423  return NOK;
424 }
425 
426 /**
427  * @brief This function get the connection type of the storage service medium.
428  * Currently not implemented.
429  *
430  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
431  *
432  * @return Returns an Integer value.
433  * @retval 0 If successfully get the hostIf storage medium interface attribute.
434  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
435  * @retval -2 If Not handle the hostIf storage medium interface attribute.
436  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
437  */
439 {
440  // TODO
441  return NOK;
442 }
443 
444 /**
445  * @brief This function get the storage service medium removable.
446  * Currently not implemented.
447  *
448  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
449  *
450  * @return Returns an Integer value.
451  * @retval 0 If successfully get the hostIf storage medium interface attribute.
452  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
453  * @retval -2 If Not handle the hostIf storage medium interface attribute.
454  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
455  */
457 {
458  // TODO
459  return NOK;
460 }
461 
462 /**
463  * @brief This function get the status of the storage service medium.
464  * Currently not implemented.
465  *
466  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
467  *
468  * @return Returns an Integer value.
469  * @retval 0 If successfully get the hostIf storage medium interface attribute.
470  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
471  * @retval -2 If Not handle the hostIf storage medium interface attribute.
472  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
473  */
475 {
476  // TODO
477  return NOK;
478 }
479 
480 /**
481  * @brief This function get the uptime of the storage service medium.
482  * Currently not implemented.
483  *
484  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
485  *
486  * @return Returns an Integer value.
487  * @retval 0 If successfully get the hostIf storage medium interface attribute.
488  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
489  * @retval -2 If Not handle the hostIf storage medium interface attribute.
490  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
491  */
493 {
494  // TODO
495  return NOK;
496 }
497 
498 /**
499  * @brief This function get the storage service medium hot swappable.
500  * Currently not implemented.
501  *
502  * @param[in] stMsgData HostIf Message Request param contains the storage medium attribute value.
503  *
504  * @return Returns an Integer value.
505  * @retval 0 If successfully get the hostIf storage medium interface attribute.
506  * @retval -1 If Not able to get the hostIf storage medium interface attribute.
507  * @retval -2 If Not handle the hostIf storage medium interface attribute.
508  * @ingroup TR69_HOSTIF_STORAGE_PHYSICALMEDIUM_API
509  */
511 {
512  // TODO
513  return NOK;
514 }
515 
516 int hostIf_PhysicalMedium::get_StorageService_PhyMed_Fields(ePhysicalMediumMembers_t phyMedMember)
517 {
518  FILE* cmdOP;
519  int ret=NOK;
520  int len;
521  char mediumName[MAX_MEDIUM_LEN]={'\0'};
522  char buffer[MAX_BUF_LEN]={'\0'};
523  char dupbuf[MAX_BUF_LEN]={'\0'};
524  char cmd[MAX_CMD_LEN]={'\0'};
525  char *token=NULL;
526  char *savePtr=NULL;
527  int ipNumOfEntries=0;
528  int index=0;
529  GList *devList =NULL;
530  GList *elem=NULL;
531  HOSTIF_MsgData_t msgData;
532 
533  memset(&msgData, 0, sizeof(msgData));
534  ret=getMediumName(mediumName);
535  if(ret!=OK)
536  return ret;
537 
538 
539  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"Entering [%s] asking for member %d\n", __FUNCTION__, phyMedMember);
540  switch(phyMedMember)
541  {
542  case eName:
543  strncpy(physicalMediumMembers.name,mediumName,strlen(mediumName));
544  break;
545  case eSmartCapable:
546  physicalMediumMembers.smartCapable = isSmartCapable();
547  break;
548  case eHealth:
549  if(!isSmartCapable())
550  {
551  snprintf(physicalMediumMembers.health, MAX_PHY_MED_HEALTH_LEN, "Error");
552  }
553  else
554  {
555  int health = isMediumHealthOK();
556  switch(health)
557  {
558  case PHYMED_HEALTH_OK:
559  snprintf(physicalMediumMembers.health, MAX_PHY_MED_HEALTH_LEN, "OK");
560  break;
561  case PHYMED_HEALTH_FAILING:
562  snprintf(physicalMediumMembers.health, MAX_PHY_MED_HEALTH_LEN, "Failing");
563  break;
564  case PHYMED_HEALTH_ERROR:
565  snprintf(physicalMediumMembers.health, MAX_PHY_MED_HEALTH_LEN, "Error");
566  break;
567  default:
568  ret=NOK;
569  break;
570  }
571  }
572  break;
573  default:
574  ret=NOK;
575  }
576  return ret;
577 }
578 
579 int hostIf_PhysicalMedium::getMediumName(char* mediumName)
580 {
581  FILE* cmdOp = NULL;
582  char cmd[MAX_CMD_LEN]= {'\0'};
583  char buffer[MAX_BUF_LEN] = {'\0'};
584  int retVal = NOK;
585  errno = 0;
586  if(1 == storageServiceInstanceNumber)
587  {
588  snprintf(cmd, MAX_CMD_LEN, CMD_TO_GET_MED_NAME, this->dev_id);
589  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Executing command:%s\n",cmd);
590  cmdOp = popen(cmd,"r");
591  if (NULL!= cmdOp)
592  {
593  fgets(buffer,MAX_BUF_LEN,cmdOp);
594  buffer[strlen(buffer)-2]='\0'; // -2 because the buffer has \n as the penaltimate character. Here we replace it with \0
595  strncpy(mediumName,buffer,strlen(buffer));
596  pclose(cmdOp);
597  retVal = OK;
598  }
599  else
600  {
601  retVal = PHYMED_CMD_EXEC_FAIL;
602  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error in execuing the command:%s errno:%d\n", cmd, errno);
603  }
604  }
605  return retVal;
606 }
607 
608 bool hostIf_PhysicalMedium::isSmartCapable()
609 {
610  FILE* cmdOp = NULL;
611  char cmd[MAX_CMD_LEN]= {'\0'};
612  char buffer[MAX_BUF_LEN] = {'\0'};
613  char mediumName[MAX_PHY_MED_NAME_LEN] = {'\0'};
614  char *token=NULL;
615  char *savePtr=NULL;
616  bool smartCapable = false;
617  errno = 0;
618 
619  if (OK == getMediumName(mediumName))
620  {
621  if(1 == storageServiceInstanceNumber)
622  {
623  snprintf(cmd,MAX_CMD_LEN,CMD_TO_CHECK_SMART_CAP);
624  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Executing command:%s\n",cmd);
625  cmdOp = popen(cmd,"r");
626  if(NULL != cmdOp)
627  {
628  fgets(buffer,MAX_BUF_LEN,cmdOp);
629  token = strtok_r(buffer,",",&savePtr);
630  if(NULL!= token)
631  {
632  do{
633  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s\n",token);
634  if(strcmp(token,mediumName)==0)
635  {
636  smartCapable = true;
637  break;
638  }
639  }while((token=strtok_r(NULL,",",&savePtr )));
640  }
641  pclose(cmdOp);
642  }
643  else
644  {
645  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error in execuing the command:%s errno:%d\n", cmd, errno);
646  }
647  }
648  }
649  return smartCapable;
650 }
651 
652 int hostIf_PhysicalMedium :: isMediumHealthOK()
653 {
654  FILE* cmdOp = NULL;
655  char cmd[MAX_CMD_LEN]= {'\0'};
656  char buffer[MAX_BUF_LEN] = {'\0'};
657  char mediumName[MAX_PHY_MED_NAME_LEN] = {'\0'};
658  char *token=NULL;
659  char *savePtr=NULL;
660  int health = PHYMED_HEALTH_INVALID;
661  errno = 0;
662 
663  if(OK == getMediumName(mediumName))
664  {
665  if( 1 == storageServiceInstanceNumber)
666  {
667  snprintf(cmd,MAX_CMD_LEN, CMD_TO_CHECK_SMART_HEALTH ,mediumName, STORAGE_PHYMED_SMARTPARAMS);
668  RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,"Executing command:%s\n",cmd);
669 #ifdef YOCTO_BUILD
670  cmdOp = v_secure_popen("r",CMD_TO_CHECK_SMART_HEALTH,mediumName,STORAGE_PHYMED_SMARTPARAMS);
671 #else
672  cmdOp = popen(cmd,"r");
673 #endif
674  if(NULL != cmdOp)
675  {
676  fgets(buffer,MAX_BUF_LEN,cmdOp);
677  token = strtok_r(buffer,",",&savePtr);
678  if(NULL!= token)
679  {
680  do{
681  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"%s\n",token);
682  if(strcmp(token,"-")==0)
683  {
684  health = (health <=PHYMED_HEALTH_OK)?PHYMED_HEALTH_OK:health;
685  }
686  if(strcmp(token,"FAILING_NOW")==0)
687  {
688  health = (health<PHYMED_HEALTH_FAILING)?PHYMED_HEALTH_FAILING:health;
689  }
690  if(strcmp(token,"In_the_past")==0)
691  {
692  health = PHYMED_HEALTH_ERROR;
693  }
694  }while((token=strtok_r(NULL,",",&savePtr )));
695  }
696  else
697  {
698  health=PHYMED_INVALID_PARAM;
699  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error in parsing output\n");
700  }
701 #ifdef YOCTO_BUILD
702  v_secure_pclose(cmdOp);
703 #else
704  pclose(cmdOp);
705 #endif
706  }
707  else
708  {
709  health = PHYMED_CMD_EXEC_FAIL;
710  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error in executing Command:%d \n",errno);
711  }
712  }
713  }
714  return health;
715 }
ePhyMediumErrorCode_t
ePhyMediumErrorCode_t
The enum holds the required error code parameters such as command execution fail, invalid param etc....
Definition: Service_Storage_PhyMedium.cpp:58
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Status
int get_Device_Service_StorageMedium_Status(HOSTIF_MsgData_t *stMsgData)
This function get the status of the storage service medium. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:474
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Health
int get_Device_Service_StorageMedium_Health(HOSTIF_MsgData_t *stMsgData)
This function get the health of the storage service medium.
Definition: Service_Storage_PhyMedium.cpp:300
Service_Storage.h
The header file provides storage service information APIs.
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Alias
int get_Device_Service_StorageMedium_Alias(HOSTIF_MsgData_t *stMsgData)
This function get the alias of storage service medium. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:348
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_SerialNumber
int get_Device_Service_StorageMedium_SerialNumber(HOSTIF_MsgData_t *stMsgData)
This function get the serial number of the storage service medium. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:402
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_HotSwappable
int get_Device_Service_StorageMedium_HotSwappable(HOSTIF_MsgData_t *stMsgData)
This function get the storage service medium hot swappable. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:510
ePhyMedHealthCode_t
ePhyMedHealthCode_t
The enum holds the required health code parameters such as health invalid, health ok etc....
Definition: Service_Storage_PhyMedium.cpp:70
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_FirmwareVersion
int get_Device_Service_StorageMedium_FirmwareVersion(HOSTIF_MsgData_t *stMsgData)
This function get the firmware version of the storage service medium. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:420
ePhysicalMediumMembers_t
ePhysicalMediumMembers_t
It contains the members variables of the ePhysicalMediumMembers_t enum.
Definition: Service_Storage_PhyMedium.h:92
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Removable
int get_Device_Service_StorageMedium_Removable(HOSTIF_MsgData_t *stMsgData)
This function get the storage service medium removable. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:456
hostIf_PhysicalMedium::hostIf_PhysicalMedium
hostIf_PhysicalMedium(int StorageServiceInstanceNumber, int dev_id)
Class Constructor of the class hostIf_PhysicalMedium.
Definition: Service_Storage_PhyMedium.cpp:88
Service_Storage_PhyMedium.h
The header file provides storage service physical medium information APIs.
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Vendor
int get_Device_Service_StorageMedium_Vendor(HOSTIF_MsgData_t *stMsgData)
This function get the vendor of the storage service medium. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:366
hostIf_PhysicalMedium::getLock
void getLock()
This function get the lock before setting or getting the attributes of the host interface physical me...
Definition: Service_Storage_PhyMedium.cpp:98
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
hostIf_PhysicalMedium
This class provides the TR-069 host interface physical medium information.
Definition: Service_Storage_PhyMedium.h:114
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_SMARTCapable
int get_Device_Service_StorageMedium_SMARTCapable(HOSTIF_MsgData_t *stMsgData)
This function get the SMART capability of the storage service medium.
Definition: Service_Storage_PhyMedium.cpp:324
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Name
int get_Device_Service_StorageMedium_Name(HOSTIF_MsgData_t *stMsgData)
This function get the name of the storage service medium.
Definition: Service_Storage_PhyMedium.cpp:276
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Model
int get_Device_Service_StorageMedium_Model(HOSTIF_MsgData_t *stMsgData)
This function get the model number of the storage service medium. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:384
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
physicalMediumMembers
It contains the members variables of the physicalMediumMembers structure.
Definition: Service_Storage_PhyMedium.h:70
hostIf_PhysicalMedium::releaseLock
void releaseLock()
This function use to release the lock before setting or getting the attributes of the host interface ...
Definition: Service_Storage_PhyMedium.cpp:112
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_ConnectionType
int get_Device_Service_StorageMedium_ConnectionType(HOSTIF_MsgData_t *stMsgData)
This function get the connection type of the storage service medium. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:438
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175
hostIf_PhysicalMedium::get_Device_Service_StorageMedium_Uptime
int get_Device_Service_StorageMedium_Uptime(HOSTIF_MsgData_t *stMsgData)
This function get the uptime of the storage service medium. Currently not implemented.
Definition: Service_Storage_PhyMedium.cpp:492