RDK Documentation (Open Sourced RDK Components)
xdiscovery_private.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 #ifndef XDISCOVERY_PRIVATE_H_
21 #define XDISCOVERY_PRIVATE_H_
22 
23 #ifdef G_LOG_DOMAIN
24 #undef G_LOG_DOMAIN
25 #endif
26 #define G_LOG_DOMAIN "XUPNP"
27 #define XUPNP_RESCAN_INTERVAL 22000000
28 #define XDISC_SERVICE "urn:schemas-upnp-org:service:DiscoverFriendlies:1"
29 #define XDISC_SERVICE_IDENTITY "urn:schemas-upnp-org:service:X1Identity:1"
30 #define XDISC_SERVICE_MEDIA "urn:schemas-upnp-org:service:X1MediaConfiguration:1"
31 #define XDISC_SERVICE_GW_CFG "urn:schemas-upnp-org:service:X1GatewayConfiguration:1"
32 #define XDISC_SERVICE_QAM_CFG "urn:schemas-upnp-org:service:X1QamConfiguration:1"
33 #define XDISC_SERVICE_TIME "urn:schemas-upnp-org:service:X1Time:1"
34 #define XDISC_SERVICE_PROTECTION "urn:schemas-upnp-org:service:DeviceProtection:1"
35 
36 #define MAX_ENTRIES 1024
37 #define MAX_OVERFLOW 1024
38 #define MAX_BUF_SIZE 2048
39 #define MAC_ADDRESS_SIZE 20
40 
41 #ifdef BROADBAND
42 typedef enum { DP_SUCCESS=0, DP_INVALID_MAC, DP_COLLISION, DP_WLIST_ERROR} dp_wlist_ss_t;
43 typedef enum { FIFO_OK=0, FIFO_FULL=1, FIFO_EMPTY=2} fstat_t;
44 
45 #define DEF_FIFO(name, max_size, type) \
46  typedef struct fname1 { \
47  type entries[max_size]; \
48  unsigned int tail; \
49  unsigned int size;\
50  } fname1_t; \
51  fname1_t name;
52 
53 #define INIT_FIFO(name, max_size) \
54 { \
55  name.tail = max_size;\
56  name.size = max_size; \
57 }
58 
59 #define ENQUEUE_FIFO(name, value, ret) \
60 { \
61  if (name.tail > 0) { \
62  name.tail--; \
63  name.entries[name.tail] = value; \
64  ret = FIFO_OK; \
65  } \
66  else { \
67  ret = FIFO_FULL; \
68  } \
69 } \
70 
71 #define DEQUEUE_FIFO(name, value, ret) \
72 { \
73  if (name.tail != name.size) {\
74  value = name.entries[name.tail]; \
75  name.tail++; \
76  ret = FIFO_OK; \
77  } \
78  else { \
79  ret = FIFO_EMPTY; \
80  } \
81 }
82 
83 typedef struct dp_wlist {
84  long ipaddr;
85  char macaddr[MAC_ADDRESS_SIZE];
86  short ofb_index;
87 }dp_wlist_t;
88 #endif
89 
90 struct ProxyMapping {
91  GUPnPDeviceProxy *proxy;
92  GUPnPServiceProxyAction *action;
93  GSource *timeout_src;
94 };
95 
96 typedef struct _gwyDeviceData {
97  GString* serial_num;
98  gboolean isgateway;
99  gboolean requirestrm;
100  GString* gwyip;
101  GString* gwyipv6;
102  GString* gatewaystbip;
103  GString* ipv6prefix;
104  GString* devicename;
105  GString* bcastmacaddress;
106  GString* hostmacaddress;
107  GString* recvdevtype;
108  GString* devicetype;
109  GString* buildversion;
110  GString* dsgtimezone;
111  gint rawoffset;
112  gint dstoffset;
113  gint dstsavings;
114  gboolean usesdaylighttime;
115  GString* baseurl;
116  GString* basetrmurl;
117  GString* playbackurl;
118  GString* dataGatewayIPaddress;
119  GString* dnsconfig;
120  GString* etchosts;
121  GString* systemids;
122  GString* receiverid;
123  gboolean devFoundFlag;
124  gboolean isRouteSet;
125  gboolean isOwnGateway;
126  gboolean isDevRefactored;
127  GUPnPServiceInfo* sproxy;
128  GUPnPServiceInfo* sproxy_i;
129  GUPnPServiceInfo* sproxy_m;
130  GUPnPServiceInfo* sproxy_g;
131  GUPnPServiceInfo* sproxy_q;
132  GUPnPServiceInfo* sproxy_t;
133  GString* modelclass;
134  GString* modelnumber;
135  GString* deviceid;
136  GString* hardwarerevision;
137  GString* softwarerevision;
138  GString* managementurl;
139  GString* make;
140  GString* accountid;
141  GString* ipSubNet;
142  GString* clientip;
143 } GwyDeviceData;
144 
145 GList* xdevlist= NULL;
146 //const char* host_ip = "eth0";
147 const guint host_port = 50759;
148 
149 GMutex *mutex;
150 GMutex *devMutex;
151 GCond *cond;
152 GMainContext *main_context;
153 GUPnPContext *context;
154 GUPnPContext *upnpContextDeviceProtect;
155 GUPnPControlPoint* cp, *cp_client, *cp_gw, *cp_bgw;
156 GString* outputfilename;
157 GString* outputcontents;
158 GString* ipMode;
159 FILE *logoutfile;
160 GString *ownSerialNo;
161 char ipaddress[INET6_ADDRSTRLEN];
162 gchar *bcastmac;
163 
164 typedef struct
165 {
166  gchar *discIf,*gwIf;
167  gchar *gwSetupFile,*logFile,*outputJsonFile,*disCertFile, *disCertPath, *disKeyFile, *disKeyPath;
168  gboolean enableGwSetup;
169  gint GwPriority;
170 } ConfSettings;
171 
172 ConfSettings *disConf;
173 
174 
175 #ifdef USE_XUPNP_TZ_UPDATE
176 struct _Timezone
177 {
178  char* upnpTZ;
179  char* tz;
180  char* tzInDst;
181 } m_timezoneinfo[] =
182 {
183  {"US/Hawaii", "HST11", "HST11HDT,M3.2.0,M11.1.0"},
184  {"US/Alaska", "AKST", "AKST09AKDT,M3.2.0,M11.1.0"},
185  {"US/Pacific", "PST08", "PST08PDT,M3.2.0,M11.1.0"},
186  {"US/Mountain", "MST07","MST07MDT,M3.2.0,M11.1.0"},
187  {"US/Central", "CST06","CST06CDT,M3.2.0,M11.1.0"},
188  {"US/Eastern", "EST05","EST05EDT,M3.2.0,M11.1.0"},
189 };
190 #endif
191 
192 void* verify_devices();
193 gboolean init_gwydata(GwyDeviceData* gwydata);
194 gboolean sendDiscoveryResult(const char* outfilename);
195 void delOldItemsFromList(gboolean bDeleteAll);
196 
197 void xupnp_logger (const gchar *log_domain, GLogLevelFlags log_level,
198  const gchar *message, gpointer user_data);
199 
200 gboolean verifyDeviceAttributeChanges(GUPnPServiceProxy *, GwyDeviceData *);
201 static void on_last_change (GUPnPServiceProxy *sproxy, const char *variable_name, GValue *value, gpointer user_data);
202 gboolean readconffile(const char* configfile);
203 gboolean getserialnum(GString* ownSerialNo);
204 int getipaddress(const char* ifname, char* ipAddressBuffer, gboolean ipv6Enabled);
205 char *replace_string(char *src_string, char *sub_string, char *replace_string);
206 gboolean replace_hn_with_local(GwyDeviceData* gwydata);
207 gboolean replace_local_device_ip(GwyDeviceData* gwydata);
208 gboolean checkvalidip( char* ipAddress);
209 gboolean checkvalidhostname( char* hostname);
210 void broadcastIPModeChange(void);
211 
212 
213 #if defined(ENABLE_FEATURE_TELEMETRY2_0)
214 #include <telemetry_busmessage_sender.h>
215 #endif
216 
217 
218 gchar *getmacaddress(const gchar *ifname);
219 
220 gboolean delete_gwyitem(const char* serial_num);
221 gboolean process_gw_services(GUPnPServiceProxy *sproxy, GwyDeviceData* gwData);
222 gboolean free_gwydata(GwyDeviceData* gwydata);
223 gboolean process_gw_services_identity(GUPnPServiceProxy *sproxy, GwyDeviceData* gwData);
224 gboolean process_gw_services_media_config(GUPnPServiceProxy *sproxy, GwyDeviceData* gwData);
225 gboolean process_gw_services_time_config(GUPnPServiceProxy *sproxy, GwyDeviceData* gwData);
226 gboolean process_gw_services_gateway_config(GUPnPServiceProxy *sproxy, GwyDeviceData* gwData);
227 gboolean process_gw_services_qam_config(GUPnPServiceProxy *sproxy, GwyDeviceData* gwData);
228 gboolean processStringRequest(const GUPnPServiceProxy *sproxy ,const char * requestFn, const char * responseFn, gchar ** result, gboolean isInCriticalPath);
229 #endif /* XDISCOVERY_PRIVATE_H_ */
verify_devices
void * verify_devices()
Verify and update the gateway list according to the availability of the gateway devices connected to ...
Definition: idm_client.c:310
replace_string
char * replace_string(char *src_string, char *sub_string, char *replace_string)
Replace all occurrences of a sub-string in the given string to value the specified.
Definition: xdiscovery.c:4009
delOldItemsFromList
void delOldItemsFromList(gboolean bDeleteAll)
Delete all the devices from the device list or delete devices marked as "Not Found" from device list.
Definition: xdiscovery.c:3637
readconffile
gboolean readconffile(const char *configfile)
This function is used to retrieve the data from the device configuration file.
Definition: xcal-device-library.c:2328
getserialnum
gboolean getserialnum(GString *ownSerialNo)
This function is used to get the serial number of the device from the vendor specific file.
Definition: xcal-device-library.c:227
checkvalidip
gboolean checkvalidip(char *ipAddress)
This will check whether the input IP Address is a valid IPv4 or IPv6 address.
Definition: xdiscovery.c:4153
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
ConfSettings
Definition: xdevice-library-private.h:27
ProxyMapping
Definition: xdiscovery_private.h:90
getmacaddress
gchar * getmacaddress(const gchar *ifname)
This function is used to get the mac address of the target device.
Definition: xcal-device-library.c:2920
replace_local_device_ip
gboolean replace_local_device_ip(GwyDeviceData *gwydata)
When the discovered device is the own device then MOcA IP is replaced.
Definition: xdiscovery.c:4130
getipaddress
int getipaddress(const char *ifname, char *ipAddressBuffer, gboolean ipv6Enabled)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:2951
_gwyDeviceData
Definition: xdiscovery_private.h:96
delete_gwyitem
gboolean delete_gwyitem(const char *serial_num)
Deletes a gateway entry from the list of Gateway devices if it matches with the serial number supplie...
Definition: idm_client.c:346
free_gwydata
gboolean free_gwydata(GwyDeviceData *gwydata)
Uninitialize gateway data attributes by resetting them to default value.
Definition: xdiscovery.c:2803
xupnp_logger
void xupnp_logger(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
This function is used to log the messages of XUPnP applications. Each Log message will be written to ...
Definition: xcal-device-library.c:249
replace_hn_with_local
gboolean replace_hn_with_local(GwyDeviceData *gwydata)
Replace IP Address part of the Gateway URL attributes from home networking IP with the local host IP....
Definition: xdiscovery.c:2709
init_gwydata
gboolean init_gwydata(GwyDeviceData *gwydata)
Initializes gateway attributes such as serial number, IP details , MAC details, URL details etc.
Definition: idm_client.c:267
sendDiscoveryResult
gboolean sendDiscoveryResult(const char *outfilename)
This will store the updated device discovery results in local storage as JSON formatted data.
Definition: xdiscovery.c:3087
processStringRequest
gboolean processStringRequest(const GUPnPServiceProxy *sproxy, const char *requestFn, const char *responseFn, gchar **result, gboolean isInCriticalPath)
This function is used to retrieve a string parameter from discovered data. Use this function only whe...
Definition: idm_client.c:280
process_gw_services
gboolean process_gw_services(GUPnPServiceProxy *sproxy, GwyDeviceData *gwData)
This function is used to get attributes of different Gateway services using GUPnP Service Proxy.
Definition: xdiscovery.c:2149