RDK Documentation (Open Sourced RDK Components)
routeSrvMgr.h
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 #include "sysMgr.h"
21 #include "libIBus.h"
22 #include "libIARM.h"
23 #include "libIARMCore.h"
24 #define MODULE_NAME "ROUTE_MODULE"
25 
26 /**
27  * @addtogroup NETSRVMGR_TYPES
28  * @{
29  */
30 typedef struct _gwyDeviceData {
31  GString* serial_num;
32  GString* gwyip;
33  GString* gwyipv6;
34  GString* ipv6prefix;
35  GString* devicetype;
36  GString* dnsconfig;
37  gboolean isRouteSet;
39 
40 typedef struct _routeInfo
41 {
42  bool isIPv4;
43  GString* ipStr;
44  GString* ipv6Pfix;
45 } routeInfo;
46 /** @} */ //END OF GROUP NETSRVMGR_TYPES
47 
49 {
50 public:
51  static RouteNetworkMgr* getInstance();
52  int Start();
53  static gboolean storeRouteDetails(unsigned int messageLength);
54  static gboolean checkExistingRouteValid();
55  static gboolean delRouteList();
56  static gboolean setRoute();
57  static gboolean sendCurrentRouteData();
58 
59 private:
61  virtual ~RouteNetworkMgr();
62  static bool instanceIsReady;
63  static RouteNetworkMgr* instance;
64  static bool getGatewayResults(char* gatewayResults, unsigned int messageLength);
65  static gboolean init_gwydata(GwyDeviceData* gwydata);
66  static gboolean free_gwydata(GwyDeviceData* gwydata);
67  static gboolean delGatewayList();
68  static gboolean printGatewayList();
69  static gboolean parse_store_gateway_data(char *array);
70  static gboolean getRouteInterface(char * routeIf);
71  static gboolean readDevFile(char *deviceFile,char *mocaIface,char *wifiIface);
72  static int getipaddress(char* ifname, char* ipAddressBuffer, gboolean ipv6Enabled);
73  static gboolean checkAddRouteInfo(char *ipAddr,bool isIPv4,char *ipv6Pfix);
74  static gboolean addRouteToList(char *ipAddr,bool isIPv4,char *ipv6Pfix);
75  static gboolean checkRemoveRouteInfo(char *ipAddr,bool isIPv4);
76  static gboolean removeRouteFromList(routeInfo *routeInfoData);
77  static gboolean printExistingRouteValid();
78  static guint g_list_find_ip(routeInfo* gwData, gconstpointer* ip );
79  static guint g_list_find_gw(GwyDeviceData* gwData, gconstpointer* ip );
80  static gboolean getCurrentRoute(char * routeIp,gboolean* isIpv4);
81  static IARM_Result_t getCurrentRouteData(void *arg);
82 };
83 
84 /**
85  * @addtogroup NETSRVMGR_TYPES
86  * @{
87  */
88 #define IARM_BUS_ROUTE_MGR_API_getCurrentRouteData "getCurrentRouteData"
89 typedef struct _routeEventData_t {
90  char routeIp[46];
91  gboolean ipv4;
92  char routeIf[10];
94 
96  routeEventData_t route;
97  bool status;
99 /** @} */ //END OF GROUP NETSRVMGR_TYPES
100 
101 
102 /**
103  * @addtogroup NETSRVMGR_APIS
104  * @{
105  */
106 
107 /**
108  * @brief This function is used to init thread attributes and create thread to send route data event.
109  */
111 
112 /**
113  * @brief Thread function handles the current route data by identifying appropriate IP mode to send route data event.
114  * This functions sends event to IARM client, so that listeners are notified by this event.
115  */
116 void* sendDefaultGatewayRouteThrd(void* arg);
117 
118 /**
119  * @brief This function is used to init thread attributes and create thread to get route data.
120  */
121 void getGatewayRouteData();
122 static void _evtHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
123 
124 /**
125  * @brief When there is a new gateway data, this thread function used IARM Bus call to get XUPNP device information.
126  * Received gateway results would be parsed and append the gateway route data to the route list.
127  */
128 void* getGatewayRouteDataThrd(void* arg);
129 
130 /**
131  * @brief This will check whether the input IP Address is a valid IPv4 or IPv6 address.
132  *
133  * @param[in] ipAddress IP Address in string format.
134  *
135  * @return Returns TRUE if IP address is valid else returns FALSE.
136  */
137 gboolean checkvalidip( char* ipAddress);
138 
139 /**
140  * @brief This function will check whether a Host name is valid by validating all the associated IP addresses.
141  *
142  * @param[in] hostname Host name represented as a string.
143  *
144  * @return Returns TRUE if host name is valid else returns FALSE.
145  */
146 gboolean checkvalidhostname( char* hostname);
147 
148 /**
149  * @brief This function is used to check whether the input IP Address belongs to IPv4 or IPv6 address.
150  *
151  * @param[in] v6Prefix IP prefix string.
152  *
153  * @return Returns TRUE if version 6 prefix is valid, Otherwise it belongs to IPV4 so returns FALSE.
154  */
155 bool checkIpMode(char *v6Prefix);
156 /** @} */ //END OF GROUP NETSRVMGR_APIS
157 
158 /**
159  * @addtogroup NETSRVMGR_TYPES
160  * @{
161  */
162 typedef enum _NetworkManager_Route_EventId_t {
163  IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_DATA = 10,
164  IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_MAX,
165 } IARM_Bus_NetworkManager_Route_EventId_t;
166 /** @} */ //END OF GROUP NETSRVMGR_TYPES
167 // xupnp dependency
168 
169 #define _IARM_XUPNP_NAME "XUPnP" /*!< Method to Get the Xupnp Info */
170 #define IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo "GetXUPNPDeviceInfo" /*!< Method to Get the Xupnp Info */
getGatewayRouteData
void getGatewayRouteData()
This function is used to init thread attributes and create thread to get route data.
Definition: routeSrvMgr.cpp:201
RouteNetworkMgr::getGatewayResults
static bool getGatewayResults(char *gatewayResults, unsigned int messageLength)
This function used IARM Bus call to get XUPNP device information and returns the result as a string.
Definition: routeSrvMgr.cpp:165
checkIpMode
bool checkIpMode(char *v6Prefix)
This function is used to check whether the input IP Address belongs to IPv4 or IPv6 address.
Definition: routeSrvMgr.cpp:1009
sysMgr.h
IARM-Bus Sys Manager Public API.
checkvalidip
gboolean checkvalidip(char *ipAddress)
This will check whether the input IP Address is a valid IPv4 or IPv6 address.
Definition: xdiscovery.c:4153
RouteNetworkMgr
Definition: routeSrvMgr.h:48
sendDefaultGatewayRouteThrd
void * sendDefaultGatewayRouteThrd(void *arg)
Thread function handles the current route data by identifying appropriate IP mode to send route data ...
Definition: routeSrvMgr.cpp:1187
_IARM_Bus_RouteSrvMgr_RouteData_Param_t
Definition: xdevice-library.h:127
libIBus.h
RDK IARM-Bus API Declarations.
sendDefaultGatewayRoute
void sendDefaultGatewayRoute()
This function is used to init thread attributes and create thread to send route data event.
Definition: routeSrvMgr.cpp:1172
RouteNetworkMgr::storeRouteDetails
static gboolean storeRouteDetails(unsigned int messageLength)
This is invoked when there is a new gateway data.
Definition: routeSrvMgr.cpp:226
_gwyDeviceData
Definition: xdiscovery_private.h:96
getGatewayRouteDataThrd
void * getGatewayRouteDataThrd(void *arg)
When there is a new gateway data, this thread function used IARM Bus call to get XUPNP device informa...
Definition: routeSrvMgr.cpp:245
RouteNetworkMgr::getipaddress
static int getipaddress(char *ifname, char *ipAddressBuffer, gboolean ipv6Enabled)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: routeSrvMgr.cpp:819
_routeInfo
Definition: routeSrvMgr.h:40
checkvalidhostname
gboolean checkvalidhostname(char *hostname)
This function will check whether a Host name is valid by validating all the associated IP addresses.
Definition: xdiscovery.c:4184
_routeEventData_t
Definition: xdevice-library.h:121