RDK Documentation (Open Sourced RDK Components)
Device_MoCA_Interface_X_RDKCENTRAL_COM_MeshTable.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 2018 RDK Management
6  * Copyright 2018 Broadcom Inc.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19 */
20 
21 /**
22  * @file Device_MoCA_Interface_X_RDKCENTRAL_COM_MeshTable.cpp
23  *
24  * @brief Device_MoCA_Interface_X_RDKCENTRAL_COM_MeshTable API Implementation.
25  *
26  * This is the implementation of the Device_MoCA_Interface_X_RDKCENTRAL_COM_MeshTable API.
27  *
28  * @par Document
29  * TBD Relevant design or API documentation.
30  *
31  */
32 
33 /** @addtogroup Device_MoCA_Interface_X_RDKCENTRAL-COM_MeshTable Implementation
34  * This is the implementation of the Device Public API.
35  * @{
36  */
37 
38 /*****************************************************************************
39  * STANDARD INCLUDE FILES
40  *****************************************************************************/
41 /*MoCA include files*/
42 
44 #include "rdk_moca_hal.h"
45 
46 
47 #define QUERY_INTERVAL 5
48 
49 static RMH_NodeMesh_Uint32_t gResponse;
50 static RMH_NodeMesh_Uint32_t gResBondedConn;
51 static time_t firstExTime = 0;
52 
53 
54 X_RDKCENTRAL_COM_MeshTable::X_RDKCENTRAL_COM_MeshTable(int _dev_id):
55  backupTxNodeID(0),
56  backupRxNodeID(0),
57  backupPHYTxRate(0),
58 
59  bCalledTxNodeID(false),
60  bCalledRxNodeID(false),
61  bCalledPHYTxRate(false)
62 {
63  dev_id = _dev_id;
64 }
65 
66 GHashTable *X_RDKCENTRAL_COM_MeshTable::ifHash = NULL;
67 
68 X_RDKCENTRAL_COM_MeshTable* X_RDKCENTRAL_COM_MeshTable::getInstance(int dev_id) {
69 
70  X_RDKCENTRAL_COM_MeshTable* instance = NULL;
71 
72  if (ifHash)
73  {
74  instance = (X_RDKCENTRAL_COM_MeshTable*) g_hash_table_lookup(ifHash, (gpointer) dev_id);
75  }
76  else
77  {
78  ifHash = g_hash_table_new(NULL, NULL);
79  }
80 
81  if (!instance)
82  {
83  try
84  {
85  instance = new X_RDKCENTRAL_COM_MeshTable(dev_id);
86  g_hash_table_insert(ifHash, (gpointer)dev_id, instance);
87  }
88  catch(int e)
89  {
90  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create X_RDKCENTRAL_COM_MeshTable instance..\n");
91  }
92  }
93 
94  return instance;
95 }
96 
97 void X_RDKCENTRAL_COM_MeshTable::closeInstance(X_RDKCENTRAL_COM_MeshTable *pDev) {
98  if(pDev) {
99  delete pDev;
100  }
101 }
102 
103 void X_RDKCENTRAL_COM_MeshTable::closeAllInstances() {}
104 
105 GList* X_RDKCENTRAL_COM_MeshTable::getAllAssociateDevs() {
106  return NULL;
107 }
108 
109 
110 /****************************************************************************************************************************************************/
111 // Device.MoCA.Interface.X_RDKCENTRAL-COM.MeshTable Table Profile. Getters:
112 /****************************************************************************************************************************************************/
113 
114 static
115 bool InstanceToIndex(unsigned int instanceNumber, unsigned int *_i, unsigned int *_j) {
116  unsigned int i,j;
117  int nodeInstance = 1;
118 
119  time_t currExTime = time (NULL);
120  if ((currExTime - firstExTime ) > QUERY_INTERVAL) {
121  RMH_Handle rmh=RMH_Initialize(NULL, NULL);
122  if (rmh) {
123  RMH_Result ret = RMH_Network_GetTxUnicastPhyRate(rmh, &gResponse);
124  if (ret == RMH_SUCCESS) {
125  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%u] RMH_Network_GetTxUnicastPhyRate PHY rates refreshed\n", __FUNCTION__, __LINE__, RMH_ResultToString(ret));
126  firstExTime = time (NULL);
127  } else {
128  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%u] RMH_Network_GetTxUnicastPhyRate failed with result %s. Not updating cache.\n", __FUNCTION__, __LINE__, RMH_ResultToString(ret));
129  }
130  RMH_Network_GetBondedConnections(rmh, &gResBondedConn);
131  RMH_Destroy(rmh);
132  }
133  else {
134  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"[%s:%u] Failed in RMH_Initialize. Not updating cache.\n", __FUNCTION__, __LINE__);
135  }
136  }
137 
138  for (i = 0; i < RMH_MAX_MOCA_NODES; i++) {
139  if (gResponse.nodePresent[i]) {
140  for (j = 0; j < RMH_MAX_MOCA_NODES; j++) {
141  if (i!=j && gResponse.nodePresent[j]) {
142  if (instanceNumber == nodeInstance++ ) {
143  *_i=i;
144  *_j=j;
145  return true;
146  }
147  }
148  }
149  }
150  }
151  return false;
152 }
153 
154 
155 int X_RDKCENTRAL_COM_MeshTable::get_MeshTxNodeId(HOSTIF_MsgData_t *stMsgData,unsigned int instanceNumber,bool *pChanged) {
156  int ret=OK;
157  unsigned int i,j;
158 
159  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entry \n", __FILE__, __FUNCTION__);
160 
161  if (InstanceToIndex(instanceNumber, &i, &j)) {
162  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] Index %d : MeshTxNode %d : MeshRxNode %d : MeshPHYTxRate %d \n", \
163  __FILE__, __FUNCTION__, instanceNumber, i, j, gResponse.nodeValue[i].nodeValue[j]);
164  put_int(stMsgData->paramValue, i);
165  stMsgData->paramtype = hostIf_UnsignedIntType;
166  stMsgData->paramLen = 4;
167  }
168  else {
169  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] failed to look up instance %d!\n", __FILE__, __FUNCTION__, instanceNumber);
170  ret=NOK;
171  }
172 
173  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exit \n", __FILE__, __FUNCTION__);
174  return ret;
175 }
176 
177 
178 int X_RDKCENTRAL_COM_MeshTable::get_MeshRxNodeId(HOSTIF_MsgData_t *stMsgData,unsigned int instanceNumber,bool *pChanged) {
179  int ret=OK;
180  unsigned int i,j;
181 
182  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entry \n", __FILE__, __FUNCTION__);
183 
184  if (InstanceToIndex(instanceNumber, &i, &j)) {
185  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] Index %d : MeshTxNode %d : MeshRxNode %d : MeshPHYTxRate %d \n", \
186  __FILE__, __FUNCTION__, instanceNumber, i, j, gResponse.nodeValue[i].nodeValue[j]);
187  put_int(stMsgData->paramValue, j);
188  stMsgData->paramtype = hostIf_UnsignedIntType;
189  stMsgData->paramLen = 4;
190  }
191  else {
192  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] failed to look up instance %d!\n", __FILE__, __FUNCTION__, instanceNumber);
193  ret=NOK;
194  }
195 
196  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exit \n", __FILE__, __FUNCTION__);
197  return ret;
198 }
199 
200 
201 int X_RDKCENTRAL_COM_MeshTable::get_MeshPHYTxRate(HOSTIF_MsgData_t *stMsgData,unsigned int instanceNumber,bool *pChanged) {
202  int ret=OK;
203  unsigned int i,j;
204 
205  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entry \n", __FILE__, __FUNCTION__);
206 
207  if (InstanceToIndex(instanceNumber, &i, &j)) {
208  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] Index %d : MeshTxNode %d : MeshRxNode %d : MeshPHYTxRate %d \n", \
209  __FILE__, __FUNCTION__, instanceNumber, i, j, gResponse.nodeValue[i].nodeValue[j]);
210  put_int(stMsgData->paramValue, gResponse.nodeValue[i].nodeValue[j]);
211  stMsgData->paramtype = hostIf_UnsignedIntType;
212  stMsgData->paramLen = 4;
213  }
214  else {
215  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] failed to look up instance %d!\n", __FILE__, __FUNCTION__, instanceNumber);
216  ret=NOK;
217  }
218 
219  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exit \n", __FILE__, __FUNCTION__);
220  return ret;
221 }
222 
223 int X_RDKCENTRAL_COM_MeshTable::get_BondedChannel(HOSTIF_MsgData_t *stMsgData,unsigned int instanceNumber,bool *pChanged) {
224  int ret=OK;
225  unsigned int i,j;
226 
227  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entry \n", __FILE__, __FUNCTION__);
228 
229  if (InstanceToIndex(instanceNumber, &i, &j)) {
230  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] Index %d : MeshTxNode %d : MeshRxNode %d : MeshPHYTxRate %d \n", \
231  __FILE__, __FUNCTION__, instanceNumber, i, j, gResponse.nodeValue[i].nodeValue[j]);
232  put_int(stMsgData->paramValue, gResBondedConn.nodeValue[i].nodeValue[j]);
233  stMsgData->paramtype = hostIf_UnsignedIntType;
234  stMsgData->paramLen = 4;
235  }
236  else {
237  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] failed to look up instance %d!\n", __FILE__, __FUNCTION__, instanceNumber);
238  ret=NOK;
239  }
240 
241  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exit \n", __FILE__, __FUNCTION__);
242  return ret;
243 }
244 /* End of doxygen group */
245 /**
246  * @}
247  */
248 
249 /* End of file xxx_api.c. */
X_RDKCENTRAL_COM_MeshTable::get_MeshTxNodeId
int get_MeshTxNodeId(HOSTIF_MsgData_t *stMsgData, unsigned int associatedDeviceNum, bool *pChanged=NULL)
Get the node ID of the transmit MoCA node from MoCA Mesh table of MoCA connected device.
Definition: Device_MoCA_Interface_X_RDKCENTRAL_COM_MeshTable.cpp:155
X_RDKCENTRAL_COM_MeshTable::get_MeshRxNodeId
int get_MeshRxNodeId(HOSTIF_MsgData_t *stMsgData, unsigned int associatedDeviceNum, bool *pChanged=NULL)
Get the node ID of the receive MoCA node from MoCA mesh table of MoCA connected device.
Definition: Device_MoCA_Interface_X_RDKCENTRAL_COM_MeshTable.cpp:178
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
Device_MoCA_Interface_X_RDKCENTRAL_COM_MeshTable.h
RMH
Definition: librmh.h:57
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
RMH_Network_GetTxUnicastPhyRate
RMH_Result RMH_Network_GetTxUnicastPhyRate(const RMH_Handle handle, RMH_NodeMesh_Uint32_t *response)
Return the unicast transmit PHY rates between all nodes on the network.
X_RDKCENTRAL_COM_MeshTable
Definition: Device_MoCA_Interface_X_RDKCENTRAL_COM_MeshTable.h:89
RMH_NodeMesh_Uint32_t
Definition: rmh_type.h:205
RMH_Initialize
RMH_Handle RMH_Initialize(const RMH_EventCallback eventCB, void *userContext)
Initialize the RMH library and return a handle to the instance.
Definition: librmh_api_no_wrap.c:23
RMH_ResultToString
const char *const RMH_ResultToString(const RMH_Result value)
Convert RMH_Result to a string.
Definition: librmh_api_no_wrap.c:84
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
RMH_Destroy
RMH_Result RMH_Destroy(RMH_Handle handle)
Destroy the instance of RMH library which was created by RMH_Initialize.
X_RDKCENTRAL_COM_MeshTable::get_MeshPHYTxRate
int get_MeshPHYTxRate(HOSTIF_MsgData_t *stMsgData, unsigned int associatedDeviceNum, bool *pChanged=NULL)
Get the Associated Device's presence indicator.
Definition: Device_MoCA_Interface_X_RDKCENTRAL_COM_MeshTable.cpp:201
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