20 #ifdef INCLUDE_BREAKPAD
21 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
22 #include <client/linux/handler/exception_handler.h>
24 #include "breakpadwrap.h"
28 #include "NetworkMgrMain.h"
29 #include "wifiSrvMgr.h"
39 #include <arpa/inet.h>
41 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
42 #include "connectivity.h"
45 #ifdef ENABLE_STUN_CLIENT
46 #include "StunClient.h"
49 #ifdef ENABLE_ROUTE_SUPPORT
50 #include "routeSrvMgr.h"
53 #ifdef USE_RDK_MOCA_HAL
54 #include "mocaSrvMgr.h"
57 #ifdef ENABLE_NLMONITOR
58 #include "netlinkifc.h"
61 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
66 #include "safec_lib.h"
68 #define STRCPY_S(dest,size,source) \
71 char configProp_FilePath[100] = {
'\0'};;
74 #ifdef ENABLE_STUN_CLIENT
75 #define STUN_DEFAULT_BIND_TIMEOUT 30 //seconds
76 #define STUN_DEFAULT_CACHE_TIMEOUT 0 //seconds (0 for disable)
79 #define NETSRVMGR_DHCP_SERVERIP_PATH "/tmp/netsrvmgr.dhcp.server.ip"
82 #ifdef USE_RDK_WIFI_HAL
85 #endif // USE_RDK_WIFI_HAL
86 static bool parse_telemetry_logging_configuration(
char *);
87 static void teleParamList_free (gpointer val);
89 static void netSrvMgr_start();
90 static void netSrvMgr_Loop();
92 #ifdef RDK_LOGGER_ENABLED
93 int b_rdk_logger_enabled = 0;
95 void logCallback(
const char *buff)
101 static void NetworkMgr_SignalHandler (
int sigNum);
102 static bool read_ConfigProps();
103 void Read_Telemetery_Param_File();
104 static bool update_telemetryParams_list(gchar *,
telemetryParams *, gchar *, gchar *);
107 static void _eventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len);
108 static IARM_Result_t getActiveInterface(
void *arg);
109 static IARM_Result_t getNetworkInterfaces(
void *arg);
110 #ifdef ENABLE_NLMONITOR
111 static IARM_Result_t getInterfaceList(
void *arg);
112 static IARM_Result_t getDefaultInterface(
void *arg);
113 #endif // ifdef ENABLE_NLMONITOR
114 static IARM_Result_t setDefaultInterface(
void *arg);
115 static IARM_Result_t isInterfaceEnabled(
void *arg);
116 static IARM_Result_t setInterfaceEnabled(
void *arg);
117 static IARM_Result_t
getSTBip(
void *arg);
118 static IARM_Result_t setIPSettings(
void *arg);
119 static IARM_Result_t getIPSettings(
void *arg);
120 static bool getDNSip(
const unsigned int family,
char *primaryDNS,
char *secondaryDNS);
121 static IARM_Result_t getSTBip_family(
void *arg);
122 static IARM_Result_t isConnectedToInternet(
void *arg);
123 static IARM_Result_t setConnectivityTestEndpoints(
void *arg);
124 static IARM_Result_t isAvailable(
void *arg);
125 #ifdef ENABLE_STUN_CLIENT
126 static IARM_Result_t getPublicIP(
void* arg);
128 #endif // ifdef ENABLE_IARM
130 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
131 static bool isFeatureEnabled(
const char* feature);
132 static bool validate_interface_can_be_disabled (
const char* interface);
133 #ifdef ENABLE_NLMONITOR
134 static bool getDefaultInterface(std::string &interface, std::string &gateway);
135 #endif // ifdef ENABLE_NLMONITOR
136 static bool setDefaultInterface(
const char* interface,
bool persist);
137 static bool setInterfaceEnabled(
const char* interface,
bool enabled,
bool persist);
138 static bool setInterfaceState(std::string interface_name,
bool enabled);
141 #ifdef ENABLE_STUN_CLIENT
144 #endif // if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
146 std::string gDhcpServerIP;
147 static bool getDhcpServerIP();
149 void NetworkMgr_SignalHandler (
int sigNum)
151 LOG_ERR(
"Received signal %d", sigNum);
152 signal(sigNum, SIG_DFL );
153 #ifdef USE_RDK_WIFI_HAL
155 if (wifiParams_Tele_Period1.paramlist != NULL) {
156 g_list_free_full(wifiParams_Tele_Period1.paramlist, (GDestroyNotify)&teleParamList_free);
159 if (wifiParams_Tele_Period2.paramlist != NULL)
161 g_list_free_full(wifiParams_Tele_Period2.paramlist, (GDestroyNotify)&teleParamList_free);
163 #endif // USE_RDK_WIFI_HAL
164 kill(getpid(), sigNum );
168 #ifdef INCLUDE_BREAKPAD
169 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
170 static bool breakpadDumpCallback(
const google_breakpad::MinidumpDescriptor& descriptor,
174 LOG_INFO(
"breakpadDumpCallback: Netsrvmgr crashed ---- Dump path: %s", descriptor.path());
186 const char*
getenvOrDefault (
const char* name,
const char* defaultValue)
188 char* value = getenv (name);
189 return value ? value : defaultValue;
192 static bool split (
const std::string &str,
char delimiter, std::vector<std::string> &tokens,
int min_expected_tokens = 0)
194 std::stringstream stream (str);
197 while (getline (stream, token, delimiter))
198 tokens.push_back (token);
199 if (min_expected_tokens > 0 && tokens.size () < min_expected_tokens)
201 LOG_ERR(
"Unexpected number of tokens. Arguments received = %s", str.c_str ());
209 static void eventInterfaceEnabledStatusChanged(
const std::string& interface,
bool enabled)
211 LOG_INFO(
"interface=%s, enabled=%d", interface.c_str(), enabled);
214 snprintf(e.interface,
sizeof(e.interface),
"%s", interface.c_str());
217 if (IARM_RESULT_SUCCESS !=
IARM_Bus_BroadcastEvent (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS, &e,
sizeof(e)))
219 LOG_ERR(
"IARM Bus Error!");
223 static void eventInterfaceConnectionStatusChanged(
const std::string& interface,
bool connected)
225 LOG_INFO(
"interface=%s, connected=%d", interface.c_str(), connected);
228 snprintf(e.interface,
sizeof(e.interface),
"%s", interface.c_str());
229 e.status = connected;
231 if (IARM_RESULT_SUCCESS !=
IARM_Bus_BroadcastEvent (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS, &e,
sizeof(e)))
233 LOG_ERR(
"IARM Bus Error!");
237 static void eventInterfaceIPAddressStatusChanged (
const std::string& interface,
const std::string& ip_address,
bool is_ipv6,
bool acquired)
239 LOG_INFO(
"interface=%s, ip_address=%s, is_ipv6=%d, acquired=%d", interface.c_str(), ip_address.c_str(), is_ipv6, acquired);
242 snprintf(e.interface,
sizeof(e.interface),
"%s", interface.c_str());
243 snprintf(e.ip_address,
sizeof(e.ip_address),
"%s", ip_address.c_str());
245 e.acquired = acquired;
247 if (IARM_RESULT_SUCCESS !=
IARM_Bus_BroadcastEvent (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS, &e,
sizeof(e)))
249 LOG_ERR(
"IARM Bus Error!");
254 if (getDhcpServerIP())
256 LOG_INFO(
"Updated the DHCP Server IP Address: [%s]", gDhcpServerIP.c_str());
261 static void eventDefaultInterfaceChanged(
const std::string& oldInterface,
const std::string& newInterface)
263 LOG_INFO(
"oldInterface=%s, newInterface=%s", oldInterface.c_str(), newInterface.c_str());
266 snprintf(e.oldInterface,
sizeof(e.oldInterface),
"%s", oldInterface.c_str());
267 snprintf(e.newInterface,
sizeof(e.newInterface),
"%s", newInterface.c_str());
269 if (IARM_RESULT_SUCCESS !=
IARM_Bus_BroadcastEvent (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE, &e,
sizeof(e)))
271 LOG_ERR(
"IARM Bus Error!");
275 #endif // ifdef ENABLE_IARM
277 #ifdef ENABLE_NLMONITOR
279 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
281 class DefaultGatewayMACLogger
284 static DefaultGatewayMACLogger& getInstance()
286 static DefaultGatewayMACLogger instance;
290 DefaultGatewayMACLogger(
const DefaultGatewayMACLogger&) =
delete;
291 void operator=(
const DefaultGatewayMACLogger&) =
delete;
296 pthread_mutex_lock(&mutex);
298 pthread_cond_signal(&cond);
299 pthread_mutex_unlock(&mutex);
303 static void* default_gateway_mac_logger(
void* arg)
306 ((DefaultGatewayMACLogger*) arg)->default_gateway_mac_logger();
310 void default_gateway_mac_logger()
313 struct timespec timeout;
314 bool timedout =
true;
315 std::string default_gateway_mac, last_logged_default_gateway_mac;
321 clock_gettime(CLOCK_MONOTONIC, &timeout);
322 timeout.tv_sec += DEFAULT_GATEWAY_MAC_LOGGING_INTERVAL_SECONDS;
324 pthread_mutex_lock(&mutex);
326 while (!signaled && !timedout)
327 if (ETIMEDOUT == pthread_cond_timedwait (&cond, &mutex, &timeout))
329 LOG_INFO(
"Triggered by %s", timedout ?
"timeout" :
"signal");
331 pthread_mutex_unlock(&mutex);
333 if (get_default_gateway_mac(default_gateway_mac) && (default_gateway_mac != last_logged_default_gateway_mac || timedout))
335 LOG_INFO(
"Default gateway MAC = %s", default_gateway_mac.c_str());
336 #ifdef USE_TELEMETRY_2_0
337 telemetry_event_s(
"gw_mac_split", (
char*) default_gateway_mac.c_str());
338 #endif // #ifdef USE_TELEMETRY_2_0
339 last_logged_default_gateway_mac = default_gateway_mac;
345 bool get_default_gateway_mac(std::string& default_gateway_mac)
349 std::string default_interface, default_gateway_ip;
351 if (NetLinkIfc::get_instance()->getDefaultRoute(
true, default_interface, default_gateway_ip))
353 LOG_DBG(
"ipv6 default route exists");
356 else if (NetLinkIfc::get_instance()->getDefaultRoute(
false, default_interface, default_gateway_ip))
358 LOG_DBG(
"ipv4 default route exists");
363 LOG_ERR(
"no default route exists");
367 iface_info default_interface_info;
368 if (NetLinkIfc::get_instance()->getInterface(default_interface, default_interface_info) ==
false)
370 LOG_ERR(
"interface %s does not exist", default_interface.c_str());
373 if (default_interface_info.m_if_flags & IFF_RUNNING == 0)
375 LOG_ERR(
"interface %s is disconnected", default_interface.c_str());
379 NetLinkIfc::get_instance()->get_neigh_mac_addr(default_interface, default_gateway_ip, is_ipv6, default_gateway_mac);
380 if (default_gateway_mac.empty())
382 LOG_ERR(
"default_gateway_mac is empty");
388 DefaultGatewayMACLogger() : signaled(false)
393 pthread_mutex_init(&mutex, NULL);
395 pthread_condattr_t condattr;
396 pthread_condattr_init(&condattr);
397 if (0 != (rc = pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC)))
398 LOG_ERR(
"pthread_condattr_setclock returned %d", rc);
399 if (0 != (rc = pthread_cond_init(&cond, &condattr)))
400 LOG_ERR(
"pthread_cond_init returned %d", rc);
403 pthread_attr_init(&attr);
404 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
405 pthread_t default_gateway_mac_logger_thread;
406 if (0 != (rc = pthread_create(&default_gateway_mac_logger_thread, &attr, &default_gateway_mac_logger,
this)))
407 LOG_ERR(
"pthread_create returned %d", rc);
410 ~DefaultGatewayMACLogger()
413 pthread_cond_destroy(&cond);
414 pthread_mutex_destroy(&mutex);
417 static const int DEFAULT_GATEWAY_MAC_LOGGING_INTERVAL_SECONDS = 600;
419 pthread_mutex_t mutex;
423 #endif // ifndef ENABLE_XCAM_SUPPORT and XHB1 and XHC3
425 static void detectDefaultInterfaceChange()
428 static std::string default_interface (
"");
429 std::string old_default_interface = default_interface;
431 getDefaultInterface (default_interface, gateway);
432 if (old_default_interface != default_interface)
433 eventDefaultInterfaceChanged (old_default_interface, default_interface);
434 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
435 DefaultGatewayMACLogger::getInstance().signal();
439 static void linkCallback(std::string args)
442 LOG_INFO(
"Arguments received = %s", args.c_str());
443 std::vector<std::string> tokens;
444 if (split(args,
' ', tokens, 2) ==
false)
447 if (tokens[1] ==
"up")
448 eventInterfaceEnabledStatusChanged(tokens[0],
true);
449 else if (tokens[1] ==
"down")
451 eventInterfaceEnabledStatusChanged(tokens[0],
false);
452 detectDefaultInterfaceChange();
454 else if (tokens[1] ==
"add")
455 eventInterfaceConnectionStatusChanged(tokens[0],
true);
456 else if (tokens[1] ==
"delete")
457 eventInterfaceConnectionStatusChanged(tokens[0],
false);
460 static void addressCallback(std::string args)
463 LOG_INFO(
"Arguments received = %s", args.c_str());
464 std::vector<std::string> tokens;
465 if (split(args,
' ', tokens, 5) ==
false)
468 if (tokens[4] !=
"global")
473 eventInterfaceIPAddressStatusChanged(tokens[2], tokens[3], tokens[1] ==
"ipv6", tokens[0] ==
"add");
475 if ((tokens[2].find(
':') != std::string::npos) && (tokens[0] ==
"delete"))
476 detectDefaultInterfaceChange();
479 const int DEFAULT_PRIORITY = 1024;
480 const int MAX_DEFAULT_ROUTES_PER_INTERFACE = 20;
482 static void defaultRouteCallback(std::string args)
485 LOG_INFO(
" Arguments received = %s", args.c_str());
486 std::vector<std::string> tokens;
487 if (split(args,
' ', tokens, 7) ==
false)
490 detectDefaultInterfaceChange();
493 #endif // ifdef ENABLE_NLMONITOR
495 int main(
int argc,
char *argv[])
497 const char* debugConfigFile = NULL;
498 const char* configFilePath = NULL;
501 IARM_Result_t err = IARM_RESULT_IPCCORE_FAIL;
504 signal (SIGHUP, NetworkMgr_SignalHandler);
505 signal (SIGINT, NetworkMgr_SignalHandler);
506 signal (SIGQUIT, NetworkMgr_SignalHandler);
507 signal (SIGTERM, NetworkMgr_SignalHandler);
509 signal (SIGPIPE, SIG_IGN);
514 if(strcmp(argv[itr],
"--debugconfig")==0)
519 debugConfigFile = argv[itr];
527 if(strcmp(argv[itr],
"--configFilePath")==0)
532 configFilePath = argv[itr];
533 memset(&configProp_FilePath,0,
sizeof(configProp_FilePath));
534 strncpy(configProp_FilePath, configFilePath,
sizeof(configProp_FilePath));
545 if(IARM_RESULT_SUCCESS != err)
551 if(IARM_RESULT_SUCCESS != err)
558 #ifdef RDK_LOGGER_ENABLED
561 memset(&configProp_FilePath,0,
sizeof(configProp_FilePath));
562 strncpy(configProp_FilePath, configFilePath,
sizeof(configProp_FilePath));
565 IARM_Bus_RegisterForLog(logCallback);
573 #ifdef INCLUDE_BREAKPAD
574 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
575 std::string minidump_path;
576 RFC_ParamData_t secValue = {0};
577 WDMP_STATUS status = getRFCParameter(
"SecureCoreFile",
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.SecDump.Enable", &secValue);
578 if (( WDMP_SUCCESS == status ) && ( 0 == strncmp(secValue.value,
"false", 5)))
580 minidump_path =
"/opt/minidumps";
584 minidump_path =
"/opt/secure/minidumps";
586 google_breakpad::MinidumpDescriptor descriptor(minidump_path.c_str());
587 google_breakpad::ExceptionHandler eh(descriptor, NULL, breakpadDumpCallback, NULL,
true, -1);
590 BreakPadWrapExceptionHandler eh;
591 eh = newBreakPadWrapExceptionHandler();
595 if(
false == read_ConfigProps()) {
596 confProp.wifiProps.max_timeout = MAX_TIME_OUT_PERIOD;
597 #ifdef ENABLE_LOST_FOUND
598 confProp.wifiProps.bEnableLostFound =
false;
599 confProp.wifiProps.lnfRetryInSecs = MAX_TIME_OUT_PERIOD;
600 confProp.wifiProps.lnfStartInSecs = MAX_TIME_OUT_PERIOD;
601 STRCPY_S(confProp.wifiProps.authServerURL,
sizeof(confProp.wifiProps.authServerURL),
"http://localhost:50050/authService/getDeviceId");
604 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3) && !defined(XHV1)
605 Read_Telemetery_Param_File();
610 #ifdef ENABLE_NLMONITOR
613 #endif // ifdef ENABLE_NLMONITOR
622 IARM_Bus_RegisterCall(IARM_BUS_NETSRVMGR_API_setConnectivityTestEndpoints, setConnectivityTestEndpoints);
624 #ifdef ENABLE_STUN_CLIENT
629 #ifdef ENABLE_SD_NOTIFY
630 sd_notifyf(0,
"READY=1\n"
631 "STATUS=netsrvmgr is Successfully Initialized\n"
633 (
unsigned long) getpid());
640 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
642 bool isFeatureEnabled(
const char* feature)
644 RFC_ParamData_t param = {0};
645 if (WDMP_SUCCESS != getRFCParameter(
"netsrvmgr", feature, ¶m))
647 LOG_ERR(
"getRFCParameter for %s failed.", feature);
650 LOG_INFO(
"name = %s, type = %d, value = %s", param.name, param.type, param.value);
651 return (strcmp(param.value,
"true") == 0);
654 bool validate_interface_can_be_disabled (
const char* interface)
656 if (isFeatureEnabled(
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Network.AllowDisableDefaultNetwork.Enable"))
659 char activeInterface[INTERFACE_SIZE];
662 LOG_ERR(
"Cannot determine the active interface");
665 if (strcmp (interface, activeInterface) == 0)
667 LOG_ERR(
"Cannot disable the active interface '%s'", activeInterface);
673 #ifdef USE_RDK_WIFI_HAL
676 static void launch_pni_controller ()
678 LOG_INFO(
"systemctl restart pni_controller.service");
679 system(
"systemctl restart pni_controller.service");
682 #endif // USE_RDK_WIFI_HAL
684 #endif // ifndef ENABLE_XCAM_SUPPORT and XHB1 and XHC3
686 void netSrvMgr_start()
690 #ifdef ENABLE_NLMONITOR
691 NetLinkIfc* netifc = NetLinkIfc::get_instance();
692 netifc->addSubscriber(
new FunctionSubscriber(NlType::link, linkCallback));
693 netifc->addSubscriber(
new FunctionSubscriber(NlType::address, addressCallback));
694 netifc->addSubscriber(
new FunctionSubscriber(NlType::dfltroute, defaultRouteCallback));
695 netifc->initialize();
699 #ifdef ENABLE_ROUTE_SUPPORT
700 RouteNetworkMgr::getInstance()->Start();
703 #ifdef USE_RDK_WIFI_HAL
704 WiFiNetworkMgr::getInstance()->Init();
705 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
706 launch_pni_controller();
708 WiFiNetworkMgr::getInstance()->setWifiEnabled (
true);
709 #endif // ifndef ENABLE_XCAM_SUPPORT and XHB1 and XHC3
710 #endif // USE_RDK_WIFI_HAL
712 #ifdef USE_RDK_MOCA_HAL
713 MocaNetworkMgr::getInstance()->Start();
717 void netSrvMgr_Loop()
723 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
724 printf(
"I-ARM NET-SRV-MGR: HeartBeat at %s\r\n", ctime(&curr));
733 NetworkMedium* createNetworkMedium(NetworkMedium::NetworkType _type)
737 if(_type==NetworkMedium::WIFI)
745 static bool read_ConfigProps()
749 GKeyFile *key_file = NULL;
750 GError *error = NULL;
752 gdouble double_value = 0;
753 guint group = 0, key = 0;
754 static char *ethIfName=NULL;
756 if(configProp_FilePath[0] ==
'\0')
758 LOG_ERR(
"Failed to read NETSRVMGR Configuration file");
762 key_file = g_key_file_new();
765 LOG_ERR(
"Failed to g_key_file_new()");
769 if(!g_key_file_load_from_file(key_file, configProp_FilePath, G_KEY_FILE_KEEP_COMMENTS, &error))
771 LOG_ERR(
"Failed with \"%s\"", error->message);
776 gsize groups_id, num_keys;
777 gchar **groups = NULL, **keys = NULL, *value = NULL;
778 ethIfName=getenv(
"ETHERNET_INTERFACE");
780 groups = g_key_file_get_groups(key_file, &groups_id);
782 for(group = 0; group < groups_id; group++)
784 LOG_DBG(
"Group %u/%u: \t%s", group, groups_id - 1, groups[group]);
785 if(0 == strncasecmp(WIFI_CONFIG, groups[group], strlen(groups[group])))
787 keys = g_key_file_get_keys(key_file, groups[group], &num_keys, &error);
788 for(key = 0; key < num_keys; key++)
790 value = g_key_file_get_value(key_file, groups[group], keys[key], &error);
791 LOG_DBG(
"[ \t\tkey %u/%u: \t%s => %s]", key, num_keys - 1, keys[key], value);
792 if(0 == strncasecmp(MAX_TIMEOUT_ON_DISCONNECT, keys[key], strlen(keys[key])))
794 confProp.wifiProps.max_timeout = atoi(value);
796 #ifdef ENABLE_LOST_FOUND
799 confProp.wifiProps.bEnableLostFound = (atoi(value) == 0) ?
false :
true;
801 if(0 == strncasecmp(LAF_CONNECT_RETRY_INTERVAL, keys[key], strlen(keys[key])))
803 confProp.wifiProps.lnfRetryInSecs = atoi(value);
805 if(0 == strncasecmp(LAF_CONNECT_START_INTERVAL, keys[key], strlen(keys[key])))
807 confProp.wifiProps.lnfStartInSecs = atoi(value);
809 if(0 == strncasecmp(GET_AUTHTOKEN_URL, keys[key], strlen(keys[key]) ) )
811 STRCPY_S(confProp.wifiProps.getAuthTokenUrl,
sizeof(confProp.wifiProps.getAuthTokenUrl), value);
813 if(0 == strncasecmp(GET_LFAT_URL, keys[key], strlen(keys[key]) ) )
815 STRCPY_S(confProp.wifiProps.getLfatUrl,
sizeof(confProp.wifiProps.getLfatUrl), value);
817 if(0 == strncasecmp(SET_LFAT_URL, keys[key], strlen(keys[key]) ) )
819 STRCPY_S(confProp.wifiProps.setLfatUrl,
sizeof(confProp.wifiProps.setLfatUrl), value);
821 if(0 == strncasecmp(LFAT_VERSION, keys[key], strlen(keys[key]) ) )
823 STRCPY_S(confProp.wifiProps.lfatVersion,
sizeof(confProp.wifiProps.lfatVersion), value);
825 if(0 == strncasecmp(LFAT_TTL, keys[key], strlen(keys[key]) ) )
827 confProp.wifiProps.lfatTTL = atoi(value);
829 if(0 == strncasecmp(LAF_CONNECTION_RETRY, keys[key], strlen(keys[key]) ) )
831 confProp.wifiProps.lnfRetryCount = atoi(value);
834 if(0 == strncasecmp(AUTHSERVER_URL, keys[key], strlen(keys[key])))
836 STRCPY_S(confProp.wifiProps.authServerURL,
sizeof(confProp.wifiProps.authServerURL), value);
838 if(0 == strncasecmp(DISABLE_WPS_XRE, keys[key], strlen(keys[key])))
840 confProp.wifiProps.disableWpsXRE = (atoi(value) == 0) ?
false :
true;
842 if(value) g_free(value);
844 if(keys) g_strfreev(keys);
846 #ifdef ENABLE_STUN_CLIENT
847 else if(0 == strncasecmp(STUN_CONFIG, groups[group], strlen(groups[group])))
849 keys = g_key_file_get_keys(key_file, groups[group], &num_keys, &error);
850 for(key = 0; key < num_keys; key++)
852 value = g_key_file_get_value(key_file, groups[group], keys[key], &error);
854 LOG_DBG(
"[ \t\tkey %u/%u: \t%s => %s]", key, num_keys - 1, keys[key], value);
856 if(0 == strncasecmp(STUN_SERVER, keys[key], strlen(keys[key])))
858 STRCPY_S(confProp.stunProps.server,
sizeof(confProp.stunProps.server), value);
860 else if(0 == strncasecmp(STUN_PORT, keys[key], strlen(keys[key])))
862 confProp.stunProps.port = atoi(value);
864 else if(0 == strncasecmp(STUN_INTERFACE, keys[key], strlen(keys[key])))
866 STRCPY_S(confProp.stunProps.interface,
sizeof(confProp.stunProps.interface), value);
868 else if(0 == strncasecmp(STUN_IPV6, keys[key], strlen(keys[key])))
870 confProp.stunProps.ipv6 = (atoi(value) == 0) ?
false :
true;
872 else if(0 == strncasecmp(STUN_BIND_TIMEOUT, keys[key], strlen(keys[key])))
874 confProp.stunProps.bind_timeout = atoi(value);
876 else if(0 == strncasecmp(STUN_CACHE_TIMEOUT, keys[key], strlen(keys[key])))
878 confProp.stunProps.cache_timeout = atoi(value);
880 if(value) g_free(value);
882 if(keys) g_strfreev(keys);
884 if(!confProp.stunProps.bind_timeout)
885 confProp.stunProps.bind_timeout = STUN_DEFAULT_BIND_TIMEOUT;
887 if(!confProp.stunProps.cache_timeout)
888 confProp.stunProps.cache_timeout = STUN_DEFAULT_CACHE_TIMEOUT;
890 LOG_WARN(
"stun config: server=%s port=%u iface=%s ipv6=%u bind_timeout=%u cache_timeout=%u",
891 confProp.stunProps.server,
892 confProp.stunProps.port,
893 confProp.stunProps.interface,
894 confProp.stunProps.ipv6,
895 confProp.stunProps.bind_timeout,
896 confProp.stunProps.cache_timeout);
900 if(groups) g_strfreev(groups);
902 if(key_file) g_key_file_free(key_file);
908 void Read_Telemetery_Param_File()
911 gchar *contents = NULL;
913 GError *error = NULL;
915 gboolean fstatus = g_file_get_contents ((
const gchar *) TELEMETRY_LOGGING_PARAM_FILE, &contents, &length, &error);
918 LOG_ERR(
"Failed to read \"%s\" file using g_file_get_contents() due to %s(%d)",
919 TELEMETRY_LOGGING_PARAM_FILE, error->message, error->code);
923 LOG_DBG(
"Successfully read \"%s\". The file Contents are \"%s\" with length (%d).", TELEMETRY_LOGGING_PARAM_FILE, contents, (
int)length);
927 parse_telemetry_logging_configuration(contents);
933 static void printf_list_info(GList *list)
936 printf(
"Since list is NULL, Failed to print info.");
940 GList *iter = g_list_first(list);
943 LOG_INFO(
"Parameter Name : \"%s\"", (
char *)iter->data);
944 iter = g_list_next(iter);
949 bool parse_telemetry_logging_configuration(gchar *
string)
955 LOG_ERR(
"Failed due to NULL request buffer");
959 #ifdef USE_RDK_WIFI_HAL
960 wifiParams_Tele_Period1.timePeriod = 0;
961 wifiParams_Tele_Period1.paramlist = NULL;
963 update_telemetryParams_list(
string, &wifiParams_Tele_Period1, (gchar *)T_PERIOD_1_INTERVAL, (gchar *)T_PERIOD_1_PARAMETER_LIST);
965 wifiParams_Tele_Period2.timePeriod = 0;
966 wifiParams_Tele_Period2.paramlist = NULL;
968 update_telemetryParams_list(
string, &wifiParams_Tele_Period2, (gchar *)T_PERIOD_2_INTERVAL, (gchar *)T_PERIOD_2_PARAMETER_LIST);
970 #endif // USE_RDK_WIFI_HAL
975 bool update_telemetryParams_list(gchar *input_buffer,
telemetryParams *telemery_params, gchar *time_period_string, gchar *param_name_string)
977 cJSON *request_msg = NULL;
981 request_msg = cJSON_Parse(input_buffer);
985 LOG_ERR(
"Failed to parse json buffer with \"%s\"", cJSON_GetErrorPtr());
990 int item, arrSize = 0;
991 cJSON* param_item = NULL, *param_list_obj = NULL;
993 telemery_params->timePeriod = cJSON_GetObjectItem(request_msg, time_period_string)->valueint;
994 param_list_obj = cJSON_GetObjectItem(request_msg, param_name_string);
996 arrSize = cJSON_GetArraySize(param_list_obj);
998 for ( item = 0; item < arrSize; item++) {
999 param_item = cJSON_GetArrayItem(param_list_obj, item);
1001 LOG_ERR(
"Failed in cJSON_GetArrayItem()");
1004 telemery_params->paramlist = g_list_prepend(telemery_params->paramlist, g_strdup(param_item->valuestring));
1007 if(telemery_params->paramlist)
1008 telemery_params->paramlist = g_list_reverse(telemery_params->paramlist);
1010 cJSON_Delete(request_msg);
1016 void teleParamList_free (gpointer val)
1020 LOG_DBG(
"\"%s\"", (gchar *)val);
1027 IARM_Result_t getActiveInterface(
void *arg)
1030 IARM_Result_t ret = IARM_RESULT_SUCCESS;
1031 char devName[INTERFACE_SIZE]={0};
1033 param->activeIface[0]=
'\0';
1036 STRCPY_S(param->activeIface,
sizeof(param->activeIface), devName);
1040 LOG_ERR(
"No Route Found");
1045 LOG_ERR(
"Get Active interface type failed for %s", devName);
1049 STRCPY_S(param->activeIface,
sizeof(param->activeIface), devName);
1054 LOG_ERR(
" No Active Interface.");
1057 LOG_INFO(
"Current Active Interface : [%s].", param->activeIface);
1058 LOG_INFO(
"TELEMETRY_NETWORK_MANAGER_ACTIVE_INTERFACE:%s", param->activeIface);
1062 IARM_Result_t getNetworkInterfaces(
void *arg)
1065 IARM_Result_t ret = IARM_RESULT_SUCCESS;
1066 char devName[INTERFACE_LIST]={0};
1068 param->allNetworkInterfaces[0]=
'\0';
1071 g_stpcpy(param->allNetworkInterfaces,devName);
1073 LOG_ERR(
"list of Network Interface is empty");
1074 param->interfaceCount=count;
1075 LOG_INFO(
"list of Network Interface : [%s]", param->allNetworkInterfaces);
1079 void _eventHandler (
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
1083 if (strcmp (owner, IARM_BUS_NM_SRV_MGR_NAME) != 0)
1090 #ifdef USE_RDK_WIFI_HAL
1091 case IARM_BUS_NETWORK_MANAGER_EVENT_WIFI_INTERFACE_STATE:
1093 WiFiNetworkMgr::getInstance()->setWifiEnabled (param->isInterfaceEnabled);
1096 #endif // USE_RDK_WIFI_HAL
1102 #ifdef ENABLE_NLMONITOR
1104 IARM_Result_t getInterfaceList(
void *arg)
1108 std::vector<iface_info> interfaces;
1109 NetLinkIfc::get_instance()->getInterfaces(interfaces);
1110 list->size = interfaces.size();
1111 if (list->size > (
sizeof(list->interfaces)/
sizeof(list->interfaces[0])))
1113 LOG_INFO(
" Size of list is larger than allocated size. Size returned = %d", list->size);
1114 return IARM_RESULT_IPCCORE_FAIL;
1116 for (
int i = 0; i < list->size; i++)
1118 LOG_INFO(
"Before Copying name=%s, mac=%s, flags=0x%08x",
1119 interfaces[i].m_if_name.c_str(), interfaces[i].m_if_macaddr.c_str(), interfaces[i].m_if_flags);
1120 snprintf(list->interfaces[i].name,
sizeof(list->interfaces[i].name),
"%s", interfaces[i].m_if_name.c_str());
1121 snprintf(list->interfaces[i].mac,
sizeof(list->interfaces[i].mac),
"%s", interfaces[i].m_if_macaddr.c_str());
1122 list->interfaces[i].flags = interfaces[i].m_if_flags;
1123 LOG_INFO(
"name=%s, mac=%s, flags=0x%08x",
1124 list->interfaces[i].name, list->interfaces[i].mac, list->interfaces[i].flags);
1126 return IARM_RESULT_SUCCESS;
1129 IARM_Result_t getDefaultInterface(
void *arg)
1133 std::string interface;
1134 std::string gateway;
1135 if (getDefaultInterface(interface, gateway))
1137 snprintf(default_route->interface,
sizeof(default_route->interface),
"%s", interface.c_str());
1138 snprintf(default_route->gateway,
sizeof(default_route->gateway),
"%s", gateway.c_str());
1144 return IARM_RESULT_SUCCESS;
1147 #endif // ifdef ENABLE_NLMONITOR
1149 IARM_Result_t setDefaultInterface(
void *arg)
1153 return setDefaultInterface (param->setInterface, param->persist) ? IARM_RESULT_SUCCESS : IARM_RESULT_IPCCORE_FAIL;
1156 IARM_Result_t isInterfaceEnabled(
void *arg)
1160 return isInterfaceEnabled(param->setInterface, param->isInterfaceEnabled) ? IARM_RESULT_SUCCESS : IARM_RESULT_IPCCORE_FAIL;
1166 IARM_Result_t setInterfaceEnabled(
void *arg)
1170 return setInterfaceEnabled (param->setInterface, param->isInterfaceEnabled, param->persist) ? IARM_RESULT_SUCCESS : IARM_RESULT_IPCCORE_FAIL;
1173 IARM_Result_t setIPSettings(
void *arg)
1177 return setIPSettings (param) ? IARM_RESULT_SUCCESS : IARM_RESULT_IPCCORE_FAIL;
1180 IARM_Result_t getIPSettings(
void *arg)
1184 return getIPSettings (param) ? IARM_RESULT_SUCCESS : IARM_RESULT_IPCCORE_FAIL;
1190 IARM_Result_t ret = IARM_RESULT_SUCCESS;
1191 char stbip[MAX_IP_ADDRESS_LEN];
1197 STRCPY_S(param->activeIfaceIpaddr,
sizeof(param->activeIfaceIpaddr), stbip);
1198 LOG_INFO(
"stb ipaddress : [%s]", stbip);
1201 LOG_ERR(
"stb ipaddress not found");
1205 IARM_Result_t getSTBip_family(
void *arg)
1208 IARM_Result_t ret = IARM_RESULT_SUCCESS;
1209 char stbip[MAX_IP_ADDRESS_LEN];
1213 if (netSrvMgrUtiles::getSTBip_family(stbip,param->ipfamily))
1215 STRCPY_S(param->activeIfaceIpaddr,
sizeof(param->activeIfaceIpaddr), stbip);
1216 LOG_INFO(
"stb ipaddress : [%s]", stbip);
1219 LOG_ERR(
"stb ipaddress not found");
1223 IARM_Result_t isConnectedToInternet(
void *arg)
1226 long timeout_ms = 2000;
1227 LOG_INFO(
"test_connectivity: : BEGIN timeout = %ldms", timeout_ms);
1228 bool connectivity = test_connectivity(timeout_ms);
1229 LOG_INFO(
"test_connectivity: : %s", connectivity ?
"PASS" :
"FAIL");
1230 *((
bool*) arg) = connectivity;
1231 return IARM_RESULT_SUCCESS;
1234 IARM_Result_t setConnectivityTestEndpoints(
void *arg)
1238 std::vector<std::string> endpoints(param->endpoints, param->endpoints + param->size);
1239 return set_connectivity_test_endpoints(endpoints) ? IARM_RESULT_SUCCESS : IARM_RESULT_IPCCORE_FAIL;
1242 IARM_Result_t isAvailable(
void *arg)
1245 LOG_INFO(
"[%s] IARM_BUS_NETSRVMGR_API_isAvailable is called", MODULE_NAME);
1246 return IARM_RESULT_SUCCESS;
1248 #ifdef ENABLE_STUN_CLIENT
1249 IARM_Result_t getPublicIP(
void *arg)
1253 return getPublicIP (param) ? IARM_RESULT_SUCCESS : IARM_RESULT_IPCCORE_FAIL;
1256 #endif // ENABLE_IARM
1259 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
1265 static void mark(
const char* filename,
bool persist)
1268 snprintf (fqn,
sizeof(fqn),
"/tmp/%s", filename);
1269 FILE *fp = fopen(fqn,
"w");
1273 snprintf (fqn,
sizeof(fqn),
"/opt/persistent/%s", filename);
1274 FILE *fp = fopen(fqn,
"w");
1283 static void unmark(
const char* filename,
bool persist)
1286 snprintf (fqn,
sizeof(fqn),
"/tmp/%s", filename);
1290 snprintf (fqn,
sizeof(fqn),
"/opt/persistent/%s", filename);
1295 #ifdef ENABLE_NLMONITOR
1296 bool getDefaultInterface(std::string &interface, std::string &gateway)
1300 if (NetLinkIfc::get_instance()->getDefaultRoute(
true, interface, gateway) ||
1301 NetLinkIfc::get_instance()->getDefaultRoute(
false, interface, gateway))
1303 LOG_INFO(
"default route interface = %s gateway = %s", interface.c_str(), gateway.c_str());
1314 #endif // ifdef ENABLE_NLMONITOR
1316 bool setDefaultInterface (
const char* interface,
bool persist)
1319 LOG_INFO(
"interface = [%s], persist = [%d]", interface, persist);
1321 #ifdef USE_RDK_WIFI_HAL
1322 if (strcmp (interface,
"ETHERNET") == 0)
1324 unmark(
"pni_wifi", persist);
1325 launch_pni_controller();
1328 else if (strcmp (interface,
"WIFI") == 0)
1331 const char* RFC_PNI_ENABLE =
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.PreferredNetworkInterface.Enable";
1332 if (isFeatureEnabled(RFC_PNI_ENABLE) ==
false)
1334 LOG_ERR(
"failed. RFC %s is not set.", RFC_PNI_ENABLE);
1338 if (isInterfaceEnabled(interface, enabled) && !enabled)
1340 LOG_ERR(
"failed. interface [%s] is disabled", interface);
1343 mark(
"pni_wifi", persist);
1344 launch_pni_controller();
1347 LOG_ERR(
"failed. Build configuration DISABLE_PNI is set");
1349 #endif // DISABLE_PNI
1352 if (strcmp (interface,
"ETHERNET") == 0)
1354 LOG_INFO(
"nothing to do. interface [%s] is always the default interface.", interface);
1357 #endif // #ifdef USE_RDK_WIFI_HAL
1360 LOG_ERR(
"failed. interface [%s] is invalid", interface);
1365 bool isInterfaceEnabled(
const char* interface,
bool& enabled)
1368 LOG_INFO(
"interface = [%s]", interface);
1370 std::string interface_name;
1371 if (strcmp (interface,
"ETHERNET") == 0)
1375 #ifdef USE_RDK_WIFI_HAL
1376 else if (strcmp (interface,
"WIFI") == 0)
1380 #endif // USE_RDK_WIFI_HAL
1383 LOG_ERR(
"interface [%s] is invalid", interface);
1386 #ifdef ENABLE_NLMONITOR
1387 std::vector<iface_info> interfaces;
1388 NetLinkIfc::get_instance()->getInterfaces(interfaces);
1389 for (
const auto& i : interfaces)
1391 if (i.m_if_name == interface_name)
1393 enabled = ((i.m_if_flags & IFF_UP) != 0);
1394 LOG_INFO(
"interface = [%s] enabled = [%d]", interface, enabled);
1398 #endif // ifdef ENABLE_NLMONITOR
1399 LOG_ERR(
"interface = [%s] enabled = [NA]", interface);
1403 bool setInterfaceEnabled (
const char* interface,
bool enabled,
bool persist)
1406 LOG_INFO(
"interface = [%s] enable = [%d] persist = [%d]", interface, enabled, persist);
1408 #ifndef USE_RDK_WIFI_HAL
1409 if (strcmp (interface,
"ETHERNET") == 0)
1413 LOG_INFO(
"nothing to do. interface [%s] is always enabled", interface);
1418 LOG_ERR(
"failed. interface [%s] cannot be disabled", interface);
1423 if (strcmp (interface,
"ETHERNET") == 0)
1427 unmark(
"ethernet_disallowed", persist);
1429 launch_pni_controller();
1434 mark(
"ethernet_disallowed", persist);
1436 launch_pni_controller();
1440 else if (strcmp (interface,
"WIFI") == 0)
1444 unmark(
"wifi_disallowed", persist);
1446 WiFiNetworkMgr::getInstance()->setWifiEnabled(
true);
1447 launch_pni_controller();
1450 else if (validate_interface_can_be_disabled(interface))
1452 mark(
"wifi_disallowed", persist);
1454 WiFiNetworkMgr::getInstance()->setWifiEnabled(
false);
1455 launch_pni_controller();
1460 LOG_ERR(
"failed. interface [%s] cannot be disabled.", interface);
1464 #endif // ifndef USE_RDK_WIFI_HAL
1467 LOG_ERR(
"failed. interface [%s] is invalid.", interface);
1472 bool getDNSip (
const unsigned int family,
char *primaryDNS,
char *secondaryDNS)
1475 char* dns[2] = {primaryDNS, secondaryDNS};
1476 std::string line, keyword, value;
1477 unsigned char s[
sizeof(
struct in6_addr)];
1478 std::ifstream f(
"/etc/resolv.dnsmasq");
1481 LOG_ERR(
"DNS file is not present");
1484 for (
int i = 0; i < 2 && std::getline (f, line); )
1486 std::istringstream ss(line);
1488 if (keyword ==
"nameserver")
1490 ss >> std::ws >> value;
1491 if (1 == inet_pton(family, value.c_str(), s))
1493 STRCPY_S(dns[i++], INET6_ADDRSTRLEN, value.c_str());
1501 static bool getDhcpServerIP()
1504 std::ifstream f(NETSRVMGR_DHCP_SERVERIP_PATH);
1507 LOG_INFO(
"DHCP SERVER IP file is not present");
1511 std::getline (f, line);
1512 struct in_addr ipv4address;
1513 if (inet_pton(AF_INET, line.c_str(), &ipv4address) <= 0)
1515 LOG_ERR(
"invalid ipaddress [%s]", line.c_str());
1520 gDhcpServerIP = line;
1530 return 0 == strcmp(ip_settings1.ipaddress, ip_settings2.ipaddress) &&
1531 0 == strcmp(ip_settings1.netmask, ip_settings2.netmask) &&
1532 0 == strcmp(ip_settings1.gateway, ip_settings2.gateway) &&
1533 0 == strcmp(ip_settings1.primarydns, ip_settings2.primarydns) &&
1534 0 == strcmp(ip_settings1.secondarydns, ip_settings2.secondarydns);
1540 FILE *fp = fopen(ip_settings_filename,
"r");
1543 char name_value_entry[512];
1544 while (NULL != fgets(name_value_entry,
sizeof(name_value_entry), fp))
1546 char* key = strtok (name_value_entry,
"=\n");
1547 char* value = strtok (NULL,
"=\n");
1548 if (0 == strcmp (key,
"ipaddress"))
1549 snprintf(ip_settings.ipaddress,
sizeof(ip_settings.ipaddress),
"%s", value);
1550 else if (0 == strcmp (key,
"netmask"))
1551 snprintf(ip_settings.netmask,
sizeof(ip_settings.netmask),
"%s", value);
1552 else if (0 == strcmp (key,
"gateway"))
1553 snprintf(ip_settings.gateway,
sizeof(ip_settings.gateway),
"%s", value);
1554 else if (0 == strcmp (key,
"primarydns"))
1555 snprintf(ip_settings.primarydns,
sizeof(ip_settings.primarydns),
"%s", value);
1556 else if (0 == strcmp (key,
"secondarydns"))
1557 snprintf(ip_settings.secondarydns,
sizeof(ip_settings.secondarydns),
"%s", value);
1566 FILE *fp = fopen(ip_settings_filename,
"w");
1569 fprintf(fp,
"ipaddress=%s\nnetmask=%s\ngateway=%s\nprimarydns=%s\nsecondarydns=%s\n",
1570 ip_settings.ipaddress, ip_settings.netmask, ip_settings.gateway, ip_settings.primarydns, ip_settings.secondarydns);
1576 void ipv4_reconfigure_interface (
const char* interface)
1579 std::string default_interface;
1580 std::string default_gateway;
1581 if ( getDefaultInterface(default_interface, default_gateway) && (0 != strcmp(interface, default_interface.c_str())) )
1584 snprintf (command,
sizeof(command),
"/lib/rdk/pni_controller.sh ipv4_reconfigure_interface %s", interface);
1585 LOG_INFO(
"Executing command [%s]", command);
1586 int status = system(command);
1587 LOG_INFO(
"Exit code [%d] from command [%s]", status, command);
1590 bool valid_ipv4_netmask (uint32_t mask)
1598 return (x & y) == 0;
1604 LOG_INFO(
"interface [%s], ipversion [%s], autoconfig [%d], ipaddress [%s], netmask [%s], gateway [%s], primarydns [%s], secondarydns [%s]",
1605 param->interface, param->ipversion, param->autoconfig, param->ipaddress, param->netmask, param->gateway, param->primarydns, param->secondarydns);
1607 std:
string secondarydns = param->secondarydns;
1608 const char* RFC_MANUALIP_ENABLE =
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Network.ManualIPSettings.Enable";
1610 bool ethernet =
true;
1611 if (0 == strcasecmp(param->interface,
"WIFI"))
1615 else if (0 != strcasecmp(param->interface,
"ETHERNET"))
1617 LOG_ERR(
"unsupported interface [%s]", param->interface);
1621 const char *
interface = ethernet ? getenv("ETHERNET_INTERFACE") : getenv("WIFI_INTERFACE");
1622 if (interface == NULL)
1624 LOG_ERR(
"failed to identify interface");
1628 const char* ip_settings_file = ethernet ?
"/opt/persistent/ip.eth0.0" :
"/opt/persistent/ip.wifi.0";
1629 bool autoconfig = ( access(ip_settings_file, F_OK) != 0 );
1631 LOG_INFO(
"interface: [%s], autoconfig: current [%d] requested [%d]", interface, autoconfig, param->autoconfig);
1633 if (param->autoconfig)
1635 param->isSupported =
true;
1638 LOG_INFO(
"already in autoconfig mode.");
1641 else if (0 != remove(ip_settings_file))
1643 LOG_ERR(
"remove(%s) returned errno %d (%s)", ip_settings_file, errno, strerror(errno));
1646 ipv4_reconfigure_interface (interface);
1651 if (isFeatureEnabled(RFC_MANUALIP_ENABLE) ==
false)
1653 LOG_ERR(
"RFC for manual IP settings is not enabled");
1654 param->isSupported =
false;
1658 if (0 != strcasecmp(param->ipversion,
"ipv4"))
1660 LOG_ERR(
"unsupported ipversion [%s]", param->ipversion);
1661 param->isSupported =
false;
1665 struct in_addr ipv4address;
1666 if (!inet_pton(AF_INET, param->ipaddress, &ipv4address))
1668 LOG_ERR(
"invalid ipaddress [%s]", param->ipaddress);
1671 if (!inet_pton(AF_INET, param->netmask, &ipv4address) || !valid_ipv4_netmask(ntohl(ipv4address.s_addr)))
1673 LOG_ERR(
"invalid netmask [%s]", param->netmask);
1676 if (!inet_pton(AF_INET, param->gateway, &ipv4address))
1678 LOG_ERR(
"invalid gateway [%s]", param->gateway);
1681 if (!inet_pton(AF_INET, param->primarydns, &ipv4address))
1683 LOG_ERR(
"invalid primarydns [%s]", param->primarydns);
1686 if (!secondarydns.empty())
1688 if (!inet_pton(AF_INET, param->secondarydns, &ipv4address))
1690 LOG_ERR(
"invalid secondarydns [%s]", param->secondarydns);
1695 if (!autoconfig && ip_settings_file_read(ip_settings_file, current_ip_settings) && ip_settings_compare(current_ip_settings, *param))
1697 LOG_INFO(
"provided config is same as the current config");
1700 if (!ip_settings_file_write(ip_settings_file, *param))
1702 LOG_ERR(
"failed to save the new config. enabling dhcp");
1703 remove(ip_settings_file);
1704 ipv4_reconfigure_interface (interface);
1707 ipv4_reconfigure_interface (interface);
1716 char interface[16] = {0};
1718 std::string gateway;
1719 char primaryDNSaddr[INET6_ADDRSTRLEN]={0};
1720 char secondaryDNSaddr[INET6_ADDRSTRLEN]={0};
1722 const char* RFC_MANUALIP_ENABLE =
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.Network.ManualIPSettings.Enable";
1723 if (isFeatureEnabled(RFC_MANUALIP_ENABLE) ==
false)
1725 LOG_INFO(
"Manual IP settings RFC is disabled");
1727 param->errCode = NETWORK_IPADDRESS_ACQUIRED;
1728 if (0 == strcasecmp (param->interface,
"WIFI") )
1730 char* c = getenv(
"WIFI_INTERFACE");
1731 snprintf (interface,
sizeof(interface),
"%s", c ? c :
"");
1732 struct stat stat_buf;
1733 param->autoconfig = (access(
"/opt/persistent/ip.wifi.0", F_OK ) != 0 ) ?
true :(stat(
"/opt/persistent/ip.wifi.0", &stat_buf) == 0 ? stat_buf.st_size == 0 :
false);
1735 else if (0 == strcasecmp(param->interface,
"ETHERNET"))
1737 char* c = getenv(
"ETHERNET_INTERFACE");
1738 snprintf (interface,
sizeof(interface),
"%s", c ? c :
"");
1739 struct stat stat_buf;
1740 param->autoconfig = (access(
"/opt/persistent/ip.eth0.0", F_OK ) != 0 ) ?
true :(stat(
"/opt/persistent/ip.eth0.0", &stat_buf) == 0 ? stat_buf.st_size == 0 :
false);
1745 LOG_ERR(
"No routable interface found.");
1746 param->errCode = NETWORK_NO_ROUTE_INTERFACE;
1749 else if (0 == strcasecmp(interface, getenv(
"ETHERNET_INTERFACE")))
1751 STRCPY_S(param->interface,
sizeof(param->interface),
"ETHERNET");
1752 struct stat stat_buf;
1753 param->autoconfig = (access(
"/opt/persistent/ip.eth0.0", F_OK ) != 0 ) ?
true :(stat(
"/opt/persistent/ip.eth0.0", &stat_buf) == 0 ? stat_buf.st_size == 0 :
false);
1756 else if (0 == strcasecmp(interface, getenv(
"WIFI_INTERFACE")))
1758 STRCPY_S(param->interface,
sizeof(param->interface),
"WIFI");
1759 struct stat stat_buf;
1760 param->autoconfig = (access(
"/opt/persistent/ip.wifi.0", F_OK ) != 0 ) ?
true :(stat(
"/opt/persistent/ip.wifi.0", &stat_buf) == 0 ? stat_buf.st_size == 0 :
false);
1762 LOG_INFO(
"interface [%s]", interface);
1765 if (strcasecmp (param->ipversion,
"IPV6") == 0)
1769 LOG_ERR(
"stb ipv6 ipaddress not found");
1770 param->errCode = NETWORK_IPADDRESS_NOTFOUND;
1774 else if (strcasecmp (param->ipversion,
"IPV4") == 0)
1779 LOG_ERR(
"stb ipv4 ipaddress not found.");
1780 param->errCode = NETWORK_IPADDRESS_NOTFOUND;
1786 STRCPY_S(param->ipversion,
sizeof(param->ipversion),
"IPV6");
1790 STRCPY_S(param->ipversion,
sizeof(param->ipversion),
"IPV4");
1795 LOG_ERR(
"stb ipaddress not found");
1796 param->errCode = NETWORK_IPADDRESS_NOTFOUND;
1801 if(NetLinkIfc::get_instance()->getDefaultRoute(is_ipv6, inter, gateway))
1803 snprintf(param->gateway,
sizeof(param->gateway),
"%s", gateway.c_str());
1804 LOG_INFO(
"Default Gateway [%s]", param->gateway);
1808 LOG_INFO(
"Default Gateway not present ");
1809 param->errCode = NETWORK_NO_DEFAULT_ROUTE;
1813 if ((param->autoconfig) && (!is_ipv6))
1815 snprintf(param->dhcp_server,
sizeof(param->dhcp_server),
"%s", gDhcpServerIP.c_str());
1819 snprintf(param->dhcp_server,
sizeof(param->dhcp_server),
"");
1821 LOG_INFO(
"DHCP Server IP Address [%s]", param->dhcp_server);
1824 if (
getDNSip(is_ipv6 ? AF_INET6 : AF_INET,primaryDNSaddr, secondaryDNSaddr))
1826 STRCPY_S(param->primarydns,
sizeof(param->primarydns), primaryDNSaddr);
1827 STRCPY_S(param->secondarydns,
sizeof(param->secondarydns), secondaryDNSaddr);
1828 LOG_INFO(
"Primary DNS %s", param->primarydns);
1829 LOG_INFO(
"Secondary DNS %s", param->secondarydns);
1833 LOG_INFO(
"No DNS ip is confiured");
1834 param->errCode = NETWORK_DNS_NOT_CONFIGURED;
1839 bool setInterfaceState (std::string interface_name,
bool enabled)
1841 if (interface_name.empty())
1843 LOG_ERR(
"no interface name");
1847 snprintf (command,
sizeof(command),
"ip link set dev %s %s", interface_name.c_str(), enabled ?
"up" :
"down");
1853 #ifdef ENABLE_STUN_CLIENT
1856 std::string host (param->server[0] ? param->server : confProp.stunProps.server);
1857 uint16_t port (param->port ? param->port : confProp.stunProps.port);
1858 stun::protocol proto (param->ipv6 ? stun::protocol::af_inet6 : stun::protocol::af_inet);
1859 uint16_t bindtm (param->bind_timeout ? param->bind_timeout : confProp.stunProps.bind_timeout);
1860 uint16_t cachetm (param->cache_timeout ? param->cache_timeout : confProp.stunProps.cache_timeout);
1861 std:
string interface = param->interface;
1862 char activeInterface[INTERFACE_SIZE];
1864 long timeout_ms = 2000;
1865 LOG_DBG(
"BEGIN timeout = %ldms", timeout_ms);
1866 bool connectivity = (test_connectivity(timeout_ms) > 0);
1869 LOG_ERR(
"testConnectivity failed: internet not available");
1873 if (0 == strcasecmp(param->interface,
"WIFI"))
1877 else if (0 == strcasecmp(param->interface,
"ETHERNET"))
1881 else if (0 == strcasecmp(param->interface,
"MOCA"))
1885 else if (interface.empty())
1891 LOG_ERR(
"No routable interface found");
1895 interface = activeInterface;
1899 LOG_ERR(
"failed to identify interface");
1903 LOG_INFO(
"interface value: %s", interface.c_str());
1904 std::string iface (param->interface[0] ? interface : confProp.stunProps.interface);
1907 if(stunClient.bind(host, port, iface, proto, bindtm, cachetm, result))
1909 strncpy(param->public_ip, result.public_ip.c_str(), MAX_IP_ADDRESS_LEN);
1919 #endif // ifndef ENABLE_XCAM_SUPPORT and XHB1 and XHC3