RDK Documentation (Open Sourced RDK Components)
netsrvmgrUtiles.h
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  * @file netSrvMgrUtiles.h
21  * @brief The header file provides components netSrvMgrUtiles information APIs.
22  */
23 
24 /**
25  * @defgroup NETSRVMGR Network Service Manager
26  * - Network Service Manager dynamically detect Network interfaces, send notifications to subscribers.
27  * - Provides 3 major functionalities such as Wi-Fi, Route, MoCA.
28  *
29  * @defgroup NETSRVMGR_TYPES Network Service Manager Types
30  * @ingroup NETSRVMGR
31  *
32  * @defgroup NETSRVMGR_APIS Network Service Manager APIs
33  * @ingroup NETSRVMGR
34  *
35  **/
36 
37 #ifndef _NETSRVMGRUTILES_H_
38 #define _NETSRVMGRUTILES_H_
39 #pragma once
40 
41 #include <iostream>
42 #include "logging.h"
43 
44 /**
45  * @addtogroup NETSRVMGR_TYPES
46  * @{
47  */
48 #define MAC_ADDR_BUFF_LEN 18
49 
50 #define SYSTEM_COMMAND_SHELL_NOT_FOUND 127
51 #define SYSTEM_COMMAND_SHELL_SUCESS 23
52 #define SYSTEM_COMMAND_ERROR -1
53 #define BUFFER_SIZE_SCRIPT_OUTPUT 512
54 
55 /** @} */ //END OF GROUP NETSRVMGR_TYPES
56 
57 #ifdef USE_TELEMETRY_2_0
58 
59 #include <telemetry_busmessage_sender.h>
60 
61 void telemetry_init(char* name);
62 void telemetry_event_s(char* marker, char* value);
63 void telemetry_event_d(char* marker, int value);
64 
65 #endif // #ifdef USE_TELEMETRY_2_0
66 
67 namespace netSrvMgrUtiles
68 {
69 /**
70  * @addtogroup NETSRVMGR_APIS
71  * @{
72  */
73 
74 /**
75  * @brief This function is used to get the MAC address for the provided interface.
76  *
77  * @param[in] ifName_in Indicates the interface name which the mac address is required.
78  * @param[out] macAddress_out Indicates the mac address of ifname_in interface name.
79  *
80  * @return Returns true if successfully gets the mac address of interface provided or else false.
81  */
82 bool getMacAddress_IfName(const char *ifName_in, char macAddress_out[MAC_ADDR_BUFF_LEN]);
83 
84 /**
85  * @brief This function trigger the process by which the DHCP client renews or updates its IP address configuration data with the
86  * DHCP server.
87  *
88  * @param[in] operation DHCP lease renew / DHCP lease release and renew.
89  * @param[in] interface interface to operate on.
90  */
91 void triggerDhcpLease(const char* operation, const char* interface);
92 void triggerDhcpRenew(const char* interface = NULL);
93 void triggerDhcpReleaseAndRenew(const char* interface);
94 
95 /**
96  * @brief This function retrieves information about the active routing interface.
97  *
98  * @param[out] devname Device name buffer to be filled.
99  *
100  * @return Returns true if successfully found the route interface or else false.
101  */
102 bool getRouteInterface(char* devname);
103 
104 /**
105  * @brief This function gets the device interface type(Ethernet/MOCA/WIFI) of the input device name.
106  * This function reads the device interface type from device properties file.
107  *
108  * @param[in/out] Interface deviceName as input and Device type buffer to be filled as output.
109  *
110  * @return Returns true if successfully gets the route interface type or else false.
111  */
112 bool readDevFile(char *deviceName);
113 
114 /**
115  * @brief This function parse all the device interface details and gives all the network interface device name in the output buffer.
116  * This function also returns the total network interface count.
117  *
118  * @param[out] devAllInterface Every interface device names.
119  *
120  * @return Returns total network interface count.
121  */
122 char getAllNetworkInterface(char* devAllInterface);
123 
124 /**
125  * @brief This function retrieves the current time using the requested format specifier.
126  *
127  * @param[out] currTime Current time to be filled.
128  * @param[in] timeFormat Requested time format to give the current time.
129  *
130  * @return Returns true if successfully gets the current time and converted to specified format or else false.
131  */
132 bool getCurrentTime(char* currTime,const char *timeFormat);
133 
134 /**
135  * @brief This function returns the Ethernet active status of the interface, if finds the status from interface status file.
136  *
137  * @param[out] interfaceName Interface name for which network status required.
138  *
139  * @return Returns true if Ethernet mode is "Up" or else false.
140  */
141 bool checkInterfaceActive(char *interfaceName);
142 
143 /**
144  * @brief This function is used to get STB IP address and its IP version.
145  *
146  * @param[out] stbip STB IP.
147  * @param[out] isIpv6 Internet Protocol Version.
148  *
149  * @return Returns true if successfully gets the IP details, Otherwise returns false.
150  */
151 bool getSTBip(char *stbip,bool *isIpv6);
152 
153 /**
154  * @brief This function is used to get Interface IP address and on which interface.
155  *
156  * @param[in] ifName ` Interface in string format. Valid values are "ETHERNET" or "WIFI"
157  * @param[in] family IP Address family in string format. Valid values are "ipv6" or "ipv4"
158  * @param[out] InterfaceIP IP of the Interface .
159  * @param[out] netmask Netmask of the interface
160  *
161  * @return Returns true if successfully gets the IP details, Otherwise returns false.
162  */
163 bool getInterfaceConfig(const char *ifName, const unsigned int family, char *interfaceIp, char *netMask);
164 
165 /**
166  * @brief This function is used to get Interface IP address and on which interface.
167  *
168  * @param[out] Interface IP IP of the Interface .
169  * @param[out] interface Internet Protocol Version.
170  *
171  * @return Returns true if successfully gets the IP details, Otherwise returns false.
172  */
173 bool getDNSip(const unsigned int family, char *primaryDNS, char *secondaryDNS);
174 
175 /*
176  * @brief This function is used to get STB IP address for a given address family.
177  *
178  * @param[in] family IP Address family in string format. Valid values are "ipv6" or "ipv4"
179  * @param[out] stbip STB IP.
180  *
181  * @return Returns true if successfully gets the IP details, Otherwise returns false.
182  */
183 bool getSTBip_family(char *stbip,const char *family);
184 
185 /**
186  * @brief This function gets the active interface device type(Ethernet/MOCA/WIFI).
187  *
188  * @param[out] devname Device type buffer to be filled.
189  *
190  * @return Returns true if successfully gets the route interface type or else false.
191  */
192 bool getRouteInterfaceType(char* devname);
193 
194 /**
195  * @brief This function checks whether IP string(IPv4 and IPv6) is link local address or not.
196  *
197  * @param[in] stbip STB IP.
198  * @param[in] family Interface family.
199  *
200  * @return Returns false in case of not supported interface family data passed.
201  */
202 bool chk_ipaddr_linklocal(const char *stbip,unsigned int family);
203 
204 /**
205  * @brief This function is used to get the current active interface(WIFI/MOCA).
206  *
207  * @param[out] currentInterface Current active Interface.
208  *
209  * @return Returns true is successfully gets the current active interface details.
210  */
211 bool currentActiveInterface(char *currentInterface);
212 
213 /**
214  * @brief This function checks whether the input ipv6 address is based on specified mac address.
215  *
216  * @param[in] ipv6Addr IP address.
217  * @param[in] macAddr MAC address.
218  *
219  * @return Returns true if global ipv6 address is on mac based, Otherwise false.
220  */
221 bool check_global_v6_based_macaddress(std::string ipv6Addr,std::string macAddr);
222 
223 /**
224  * @brief This function checks whether the input ipv6 address is Unique Local Address.
225  *
226  * @param[in] ipv6Addr IP address.
227  *
228  * @return Returns true if global ipv6 address is ULA, Otherwise false.
229  */
230 bool check_global_v6_ula_address(std::string ipv6Addr);
231 
232 
233 /**
234  * @brief This function is used to get the output of running the specified command.
235  *
236  * @param[in] command command to run.
237  * @param[out] output_buffer output buffer into which to put command's output
238  * @param[in] output_buffer_size output buffer size
239  *
240  * @return Returns true if it gets the command's output successfully, Otherwise false.
241  */
242 bool getCommandOutput(const char *command, char *output_buffer, size_t output_buffer_size);
243 
244 /**
245  * @brief This function is used to get the NetMask address for the provided interface.
246  *
247  * @param[in] ifName_in Indicates the interface name which the netMask is required.
248  * @param[out] netMask_out Indicates the netMask address of ifname_in interface name.
249  *
250  * @return Returns true if successfully gets the NetMask address of interface provided or else false.
251  */
252 bool getNetMask_IfName(const char *ifName_in, const unsigned int, char *netMask_out);
253 
254 /**
255  * @brief This function checks if the input ipv4 address is a unicast address reserved for documentation.
256  *
257  * @param[in] ipv4_address IPv4 address.
258  *
259  * @return Returns true if input ipv4 address is a unicast address reserved for documentation.
260  */
261 bool isIPv4AddressScopeDocumentation(const std::string& ipv4_address);
262 
263 }
264 
265 
266 /** @} */ //END OF GROUP NETSRVMGR_APIS
267 #endif /* _NETSRVMGRUTILES_H_ */
268 
getDNSip
bool getDNSip(const unsigned int family, char *primaryDNS, char *secondaryDNS)
This function is used to get Interface IP address and on which interface.
Definition: netSrvMgrMain.cpp:1472
netSrvMgrUtiles::chk_ipaddr_linklocal
bool chk_ipaddr_linklocal(const char *stbip, unsigned int family)
This function checks whether IP string(IPv4 and IPv6) is link local address or not.
Definition: netsrvmgrUtiles.cpp:636
netSrvMgrUtiles::check_global_v6_based_macaddress
bool check_global_v6_based_macaddress(std::string ipv6Addr, std::string macAddr)
This function checks whether the input ipv6 address is based on specified mac address.
Definition: netsrvmgrUtiles.cpp:688
netSrvMgrUtiles::check_global_v6_ula_address
bool check_global_v6_ula_address(std::string ipv6Addr)
This function checks whether the input ipv6 address is Unique Local Address.
Definition: netsrvmgrUtiles.cpp:719
netSrvMgrUtiles::checkInterfaceActive
bool checkInterfaceActive(char *interfaceName)
This function returns the Ethernet active status of the interface, if finds the status from interface...
Definition: netsrvmgrUtiles.cpp:409
netSrvMgrUtiles::readDevFile
bool readDevFile(char *deviceName)
This function gets the device interface type(Ethernet/MOCA/WIFI) of the input device name....
Definition: netsrvmgrUtiles.cpp:289
netSrvMgrUtiles::getSTBip
bool getSTBip(char *stbip, bool *isIpv6)
This function is used to get STB IP address and its IP version.
Definition: netsrvmgrUtiles.cpp:535
netSrvMgrUtiles::getAllNetworkInterface
char getAllNetworkInterface(char *devAllInterface)
This function parse all the device interface details and gives all the network interface device name ...
Definition: netsrvmgrUtiles.cpp:349
netSrvMgrUtiles::getInterfaceConfig
bool getInterfaceConfig(const char *ifName, const unsigned int family, char *interfaceIp, char *netMask)
This function is used to get Interface IP address and on which interface.
Definition: netsrvmgrUtiles.cpp:481
netSrvMgrUtiles::getMacAddress_IfName
bool getMacAddress_IfName(const char *ifName_in, char macAddress_out[18])
This function is used to get the MAC address for the provided interface.
netSrvMgrUtiles::triggerDhcpLease
void triggerDhcpLease(const char *operation, const char *interface)
This function trigger the process by which the DHCP client renews or updates its IP address configura...
Definition: netsrvmgrUtiles.cpp:171
netSrvMgrUtiles::getRouteInterfaceType
bool getRouteInterfaceType(char *devname)
This function gets the active interface device type(Ethernet/MOCA/WIFI).
Definition: netsrvmgrUtiles.cpp:272
netSrvMgrUtiles::getCommandOutput
bool getCommandOutput(const char *command, char *output_buffer, size_t output_buffer_size)
This function is used to get the output of running the specified command.
Definition: netsrvmgrUtiles.cpp:737
netSrvMgrUtiles::isIPv4AddressScopeDocumentation
bool isIPv4AddressScopeDocumentation(const std::string &ipv4_address)
This function checks if the input ipv4 address is a unicast address reserved for documentation.
Definition: netsrvmgrUtiles.cpp:803
netSrvMgrUtiles::currentActiveInterface
bool currentActiveInterface(char *currentInterface)
This function is used to get the current active interface(WIFI/MOCA).
Definition: netsrvmgrUtiles.cpp:656
netSrvMgrUtiles::getCurrentTime
bool getCurrentTime(char *currTime, const char *timeFormat)
This function retrieves the current time using the requested format specifier.
Definition: netsrvmgrUtiles.cpp:389
netSrvMgrUtiles::getRouteInterface
bool getRouteInterface(char *devname)
This function retrieves information about the active routing interface.
Definition: netsrvmgrUtiles.cpp:263
netSrvMgrUtiles::getNetMask_IfName
bool getNetMask_IfName(const char *ifName_in, const unsigned int, char *netMask_out)
This function is used to get the NetMask address for the provided interface.
Definition: netsrvmgrUtiles.cpp:757