35 #include "hostIf_utils.h"
38 #include "hostIf_XrdkCentralT2_ReqHandler.h"
39 #include "safec_lib.h"
44 #ifdef USE_MoCA_PROFILE
50 #ifdef USE_WIFI_PROFILE
53 #ifdef USE_DHCPv4_PROFILE
56 #ifdef USE_STORAGESERVICE_PROFILE
59 #ifdef USE_INTFSTACK_PROFILE
62 #ifdef SNMP_ADAPTER_ENABLED
67 extern GHashTable* paramMgrhash;
69 static std::mutex get_handler_mutex;
70 static std::mutex set_handler_mutex;
77 std::lock_guard<std::mutex> lock(get_handler_mutex);
81 msgHandler *pMsgHandler = HostIf_GetMgr(stMsgData);
86 catch (
const std::exception& e)
88 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"[%s:%d] Exception caught %s\n", __FUNCTION__, __LINE__, e.what());
98 std::lock_guard<std::mutex> lock(set_handler_mutex);
99 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
102 msgHandler *pMsgHandler = HostIf_GetMgr(stMsgData);
107 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
117 msgHandler *pMsgHandler = HostIf_GetMgr(stMsgData);
120 ret = pMsgHandler->handleGetAttributesMsg(stMsgData);
130 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s:%s] Entering...\n", __FUNCTION__, __FILE__);
132 msgHandler *pMsgHandler = HostIf_GetMgr(stMsgData);
133 if (NULL != pMsgHandler)
135 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"Valid Handler for %s", __FUNCTION__, __FILE__,stMsgData->
paramName);
138 ret = pMsgHandler->handleSetAttributesMsg(stMsgData);
149 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Entering...\n", __FUNCTION__, __FILE__);
155 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Exiting...\n", __FUNCTION__, __FILE__);
166 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
167 if(NULL == *stMsgData)
175 stMsgDummyData->
reqType = HOSTIF_GET;
177 *stMsgData = stMsgDummyData;
179 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
187 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
188 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"\n****************************************************\n");
189 cout <<
"Parameter Name : "<< stMsgData->
paramName << endl;
190 cout <<
"Parameter Request Type : "<< stMsgData->
reqType << endl;
192 case hostIf_StringType:
193 cout <<
"Parameter Value : "<< (
char *)stMsgData->
paramValue << endl;
195 case hostIf_BooleanType:
196 cout <<
"Parameter Value : "<< (get_boolean(stMsgData->
paramValue)?
"true":
"false") << endl;
199 cout <<
"Parameter Value : "<< get_int(stMsgData->
paramValue) << endl;
201 cout <<
"Parameter Length : "<< stMsgData->
paramLen << endl;
202 cout <<
"Parameter Type : "<< stMsgData->
paramtype << endl;
203 cout <<
"Parameter Instance number : "<< stMsgData->
instanceNum << endl;
204 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"****************************************************\n");
205 RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,
"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
208 bool hostIf_initalize_ConfigManger()
212 char param[100] = {
'\0'};
213 char mgr[16] = {
'\0'};
217 fp = fopen(argList.confFile,
"r");
221 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s]Error opening the %s file\n", __FILE__, __FUNCTION__, argList.confFile );
226 paramMgrhash = g_hash_table_new(g_str_hash, g_int_equal);
229 while (fscanf( fp,
"%s %s", param, mgr) != EOF)
231 if(strcasecmp(mgr,
"deviceMgr") == 0)
233 mgrName = HOSTIF_DeviceMgr;
235 else if(strcasecmp(mgr,
"dsMgr") == 0)
237 mgrName = HOSTIF_DSMgr;
239 else if(strcasecmp(mgr,
"telemetryMgr") == 0)
241 mgrName = HOSTIF_TelemetryMgr;
243 #ifdef USE_MoCA_PROFILE
244 else if(strcasecmp(mgr,
"mocaMgr") == 0)
246 mgrName = HOSTIF_MoCAMgr;
250 else if(strcasecmp(mgr,
"xreMgr") == 0)
252 mgrName = HOSTIF_XREMgr;
255 else if(strcasecmp(mgr,
"ethernetMgr") == 0)
257 mgrName = HOSTIF_EthernetMgr;
259 else if(strcasecmp(mgr,
"ipMgr") == 0)
261 mgrName = HOSTIF_IPMgr;
263 else if(strcasecmp(mgr,
"timeMgr") == 0)
265 mgrName = HOSTIF_TimeMgr;
267 #ifdef USE_WIFI_PROFILE
268 else if (strcasecmp(mgr,
"wifiMgr") == 0)
270 mgrName = HOSTIF_WiFiMgr;
273 #ifdef USE_DHCPv4_PROFILE
274 else if(strcasecmp(mgr,
"dhcpv4Mgr") == 0)
276 mgrName = HOSTIF_DHCPv4;
279 #ifdef USE_INTFSTACK_PROFILE
280 else if(strcasecmp(mgr,
"ifStackMgr") == 0)
282 mgrName = HOSTIF_InterfaceStack;
285 #ifdef USE_STORAGESERVICE_PROFILE
286 else if(strcasecmp(mgr,
"storageSrvcMgr") == 0)
288 mgrName = HOSTIF_StorageSrvcMgr;
291 #ifdef SNMP_ADAPTER_ENABLED
292 else if(strcasecmp(mgr,
"snmpAdapterMgr") == 0)
294 mgrName = HOSTIF_SNMPAdapterMgr;
297 else if(strcasecmp(mgr,
"rdkProfileMgr") == 0)
299 mgrName = HOSTIF_RdkProfileMgr;
302 if(mgrName != HOSTIF_INVALID_Mgr) {
303 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"param: %s \tMgr: [%s => %d]\n", param, mgr, mgrName);
304 g_hash_table_insert(paramMgrhash, (gpointer)g_strdup(param), (gpointer)mgrName);
306 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"Invalid Hostif Manager for param %s, Skipping...\n", param);
312 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"Failed to initialize hash table.\n");
321 const char *pParam = stMsgHandlerData->
paramName;
324 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s()] Get proper manager for parameter :- %s \n", __FUNCTION__,stMsgHandlerData->
paramName);
325 if(NULL != paramMgrhash)
327 GList *list = g_hash_table_get_keys(paramMgrhash);
330 char *data = (
char *)keys->data;
331 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s()] DATA = %s\n",__FUNCTION__, data);
332 if(strncmp(data,pParam,strlen(data)) == 0)
334 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s()] pParam: %s data:%s\n", __FUNCTION__,pParam, data);
341 gpointer item_ptr = g_hash_table_lookup(paramMgrhash, (
char *)keys->data);
342 if(item_ptr == NULL) {
343 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s] Not able to find proper manager for param %s.\n",pParam);
349 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s][For Parameter path: \"%s\"; Manager :%d ] \n", __FUNCTION__, pParam, mgrId);
353 pRet = DSClientReqHandler::getInstance();
357 pRet = XREClientReqHandler::getInstance();
360 case HOSTIF_DeviceMgr:
361 pRet = DeviceClientReqHandler::getInstance();
363 #ifdef USE_MoCA_PROFILE
365 pRet = MoCAClientReqHandler::getInstance();
368 case HOSTIF_EthernetMgr:
369 pRet = EthernetClientReqHandler::getInstance();
372 pRet = TimeClientReqHandler::getInstance();
375 pRet = IPClientReqHandler::getInstance();
377 #ifdef USE_WIFI_PROFILE
379 pRet = WiFiReqHandler::getInstance();
382 #ifdef USE_DHCPv4_PROFILE
384 pRet = DHCPv4ClientReqHandler::getInstance();
387 #ifdef USE_INTFSTACK_PROFILE
388 case HOSTIF_InterfaceStack:
389 pRet = InterfaceStackClientReqHandler::getInstance();
392 #ifdef USE_STORAGESERVICE_PROFILE
393 case HOSTIF_StorageSrvcMgr:
394 pRet = StorageSrvcReqHandler::getInstance();
397 #ifdef SNMP_ADAPTER_ENABLED
398 case HOSTIF_SNMPAdapterMgr:
399 pRet = SNMPClientReqHandler::getInstance();
402 case HOSTIF_TelemetryMgr:
403 pRet = XRdkCentralT2::getInstance();
405 case HOSTIF_RdkProfileMgr:
406 pRet = X_rdk_req_hdlr::getInstance();
414 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s()]Not able to get Key parameter :- %s \n", __FUNCTION__,stMsgHandlerData->
paramName);
421 RDK_LOG(RDK_LOG_INFO,LOG_TR69HOSTIF,
"[%s()] paramMgrhash is Null parameter :- %s \n", __FUNCTION__,stMsgHandlerData->
paramName);
427 bool hostIf_ConfigProperties_Init()
430 GKeyFile *key_file = NULL;
431 GError *error = NULL;
433 gdouble double_value = 0;
434 guint group = 0, key = 0;
437 if(argList.confFile[0] ==
'\0')
439 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] Failed to read Hostif Manager Configuration file \n", __FILE__, __FUNCTION__, __LINE__);
443 key_file = g_key_file_new();
446 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"[%s:%s:%d] Failed to g_key_file_new() \n", __FILE__, __FUNCTION__, __LINE__);
450 if(!g_key_file_load_from_file(key_file, argList.confFile, G_KEY_FILE_KEEP_COMMENTS, &error))
452 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"%s", error->message);
457 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"[%s:%s:%d]\n", __FILE__, __FUNCTION__, __LINE__);
458 paramMgrhash = g_hash_table_new(g_str_hash, g_int_equal);
460 gsize groups_id, num_keys;
461 gchar **groups, **keys, *value;
462 groups = g_key_file_get_groups(key_file, &groups_id);
463 for(group = 0; group < groups_id; group++)
465 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"group %u/%u: \t%s\n", group, groups_id - 1, groups[group]);
466 if(0 == strncasecmp(HOSTIF_MGR_GROUP, groups[group], strlen(groups[group])))
468 keys = g_key_file_get_keys(key_file, groups[group], &num_keys, &error);
469 for(key = 0; key < num_keys; key++)
471 value = g_key_file_get_value(key_file, groups[group], keys[key], &error);
472 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"\t\tkey %u/%u: \t%s => %s\n", key, num_keys - 1, keys[key], value);
474 if(strcasecmp(value,
"deviceMgr") == 0)
476 mgrName = HOSTIF_DeviceMgr;
478 else if(strcasecmp(value,
"dsMgr") == 0)
480 mgrName = HOSTIF_DSMgr;
482 #ifdef USE_MoCA_PROFILE
483 else if(strcasecmp(value,
"mocaMgr") == 0)
485 mgrName = HOSTIF_MoCAMgr;
489 else if(strcasecmp(value,
"xreMgr") == 0)
491 mgrName = HOSTIF_XREMgr;
494 else if(strcasecmp(value,
"ethernetMgr") == 0)
496 mgrName = HOSTIF_EthernetMgr;
498 else if(strcasecmp(value,
"ipMgr") == 0)
500 mgrName = HOSTIF_IPMgr;
502 else if(strcasecmp(value,
"timeMgr") == 0)
504 mgrName = HOSTIF_TimeMgr;
507 #ifdef USE_DHCPv4_PROFILE
508 else if(strcasecmp(value,
"dhcpv4Mgr") == 0)
510 mgrName = HOSTIF_DHCPv4;
513 #ifdef USE_STORAGESERVICE_PROFILE
514 else if(strcasecmp(value,
"storageSrvcMgr") == 0)
516 mgrName = HOSTIF_StorageSrvcMgr;
519 #ifdef SNMP_ADAPTER_ENABLED
520 else if(strcasecmp(value,
"snmpAdapterMgr") == 0)
522 mgrName = HOSTIF_SNMPAdapterMgr;
525 RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,
"param: %s \tMgr: [%s => %d]\n", keys[key], value, mgrName);
526 g_hash_table_insert(paramMgrhash, (gpointer)g_strdup(keys[key]), (gpointer)mgrName);
532 else if(0 == strncasecmp(HOSTIF_MGR_GROUP, groups[group], strlen(groups[group])))
536 else if (0 == strncasecmp(HOSTIF_GENERAL_CONG_GROUP, groups[group], strlen(groups[group])))
545 g_key_file_free(key_file);