RDK Documentation (Open Sourced RDK Components)
xcal-device-library.c
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 2018 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 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <glib.h>
23 #include <sys/types.h>
24 #include <libsoup/soup.h>
25 #include <sys/socket.h>
26 #include <sys/ioctl.h>
27 #include <net/if.h>
28 #include <ifaddrs.h>
29 #include <netinet/in.h>
30 #include <stdbool.h>
31 #include "xdevice-library-private.h"
32 #include "syscfg/syscfg.h"
33 #include <glib/gprintf.h>
34 #include <glib/gstdio.h>
35 #include <arpa/inet.h>
36 
37 #include <platform_hal.h>
38 #include "rdk_safeclib.h"
39 #include "secure_wrapper.h"
40 
41 #ifndef INET6_ADDRSTRLEN
42 #define INET6_ADDRSTRLEN 46
43 #endif
44 #define MAXSIZE 256
45 #ifndef BOOL
46 #define BOOL unsigned char
47 #endif
48 
49 #define ISOLATION_IF "brlan10"
50 #define PRIVATE_LAN_BRIDGE "brlan0"
51 #define WIFI_IF "brlan0:0"
52 #define UDN_IF "erouter0"
53 #define PARTNER_ID "partnerId"
54 #define RECEIVER_ID "deviceId"
55 #define BCAST_PORT 50755
56 #define LOG_FILE "/rdklogs/logs/xdevice.log"
57 #define DEVICE_XML_PATH "/etc/xupnp/"
58 #define DEVICE_XML_FILE "BasicDevice.xml"
59 #define BROADBAND_DEVICE_XML_FILE "X1BroadbandGateway.xml"
60 #define MAX_FILE_LENGTH 256
61 #define MAX_OUTVALUE 256
62 #define RUIURLSIZE 2048
63 #define URLSIZE 512
64 #define DEVICE_KEY_PATH "/tmp/"
65 #define DEVICE_KEY_FILE "xpki_key"
66 #define DEVICE_CERT_PATH "/tmp/"
67 #define DEVICE_CERT_FILE "xpki_cert"
68 
69 #define LINK_LOCAL_ADDR "169.254"
70 #ifndef F_OK
71 #define F_OK 0
72 #endif
73 
74 #ifndef BOOL
75 #define BOOL unsigned char
76 #endif
77 #ifndef TRUE
78 #define TRUE 1
79 #endif
80 #ifndef FALSE
81 #define FALSE 0
82 #endif
83 #ifndef RETURN_OK
84 #define RETURN_OK 0
85 #endif
86 #ifndef RETURN_ERR
87 #define RETURN_ERR -1
88 #endif
89 
90 typedef enum serviceListCb {
91  SERIAL_NUMBER,
92  IPV6_PREFIX,
93  TUNE_READY,
94 } serviceListCb;
95 
96 #define DEVICE_PROPERTY_FILE "/etc/device.properties"
97 #define GET_DEVICEID_SCRIPT "/lib/rdk/getDeviceId.sh"
98 #define DEVICE_NAME_FILE "/opt/hn_service_settings.conf"
99 
100 #define HST_RAWOFFSET (-11 * 60 * 60 * 1000)
101 #define AKST_RAWOFFSET (-9 * 60 * 60 * 1000)
102 #define PST_RAWOFFSET (-8 * 60 * 60 * 1000)
103 #define MST_RAWOFFSET (-7 * 60 * 60 * 1000)
104 #define CST_RAWOFFSET (-6 * 60 * 60 * 1000)
105 #define EST_RAWOFFSET (-5 * 60 * 60 * 1000)
106 gboolean ipv6Enabled = FALSE;
107 char ipAddressBuffer[INET6_ADDRSTRLEN] = {0};
108 char stbipAddressBuffer[INET6_ADDRSTRLEN] = {0};
109 
110 #if 0
111 static struct TZStruct {
112  char *inputTZ;
113  char *javaTZ;
114  int rawOffset;
115  gboolean usesDST;
116 } tzStruct[] = {
117  {"HST11", "US/Hawaii", HST_RAWOFFSET, 1},
118  {"HST11HDT,M3.2.0,M11.1.0", "US/Hawaii", HST_RAWOFFSET, 1},
119  {"AKST", "US/Alaska", AKST_RAWOFFSET, 1},
120  {"AKST09AKDT", "US/Alaska", AKST_RAWOFFSET, 1},
121  {"PST08", "US/Pacific", PST_RAWOFFSET, 1},
122  {"PST08PDT,M3.2.0,M11.1.0", "US/Pacific", PST_RAWOFFSET, 1},
123  {"MST07", "US/Mountain", MST_RAWOFFSET, 1},
124  {"MST07MDT,M3.2.0,M11.1.0", "US/Mountain", MST_RAWOFFSET, 1},
125  {"CST06", "US/Central", CST_RAWOFFSET, 1},
126  {"CST06CDT,M3.2.0,M11.1.0", "US/Central", CST_RAWOFFSET, 1},
127  {"EST05", "US/Eastern", EST_RAWOFFSET, 1},
128  {"EST05EDT,M3.2.0,M11.1.0", "US/Eastern", EST_RAWOFFSET, 1}
129 };
130 #endif
131 
132 #define COMCAST_PARTNET_KEY "comcast"
133 #define COX_PARTNET_KEY "cox"
134 
135 ConfSettings *devConf;
136 
137 #define ARRAY_COUNT(array) (sizeof(array)/sizeof(array[0]))
138 
139 #if 0
140 static STRING_MAP partnerNameMap[] = {
141  {COMCAST_PARTNET_KEY, "comcast"},
142  {COX_PARTNET_KEY , "cox"},
143 };
144 static STRING_MAP friendlyNameMap[] = {
145  {COMCAST_PARTNET_KEY, "XFINITY"},
146  {COX_PARTNET_KEY , "Contour"},
147 };
148 static STRING_MAP productNameMap[] = {
149  {COMCAST_PARTNET_KEY, "xfinity"},
150  {COX_PARTNET_KEY , "contour"},
151 };
152 static STRING_MAP serviceNameMap[] = {
153  {COMCAST_PARTNET_KEY, "Comcast XFINITY Guide"},
154  {COX_PARTNET_KEY , "Cox Contour Guide"},
155 };
156 static STRING_MAP serviceDescriptionMap[] = {
157  {COMCAST_PARTNET_KEY, "Comcast XFINITY Guide application"},
158  {COX_PARTNET_KEY , "Cox Contour Guide application"},
159 };
160 static STRING_MAP gatewayNameMap[] = {
161  {COMCAST_PARTNET_KEY, "Comcast Gateway"},
162  {COX_PARTNET_KEY , "Cox Gateway"},
163 };
164 #endif
165 
166 xupnpEventCallback eventCallback;
167 
168 void xupnpEventCallback_register(xupnpEventCallback callback_func)
169 {
170  eventCallback=callback_func;
171 }
172 
173 int check_rfc()
174 {
175  errno_t rc = -1;
176  int ind = -1;
177  char temp[24] = {0};
178  if (!syscfg_get(NULL, "Refactor", temp, sizeof(temp)) )
179  {
180  if(temp != NULL)
181  {
182  rc = strcmp_s("true",strlen("true"),temp,&ind);
183  ERR_CHK(rc);
184  if((!ind) && (rc == EOK))
185  {
186  g_message("New Device Refactoring rfc_enabled");
187  return 1;
188  }
189  }
190  }
191  else
192  {
193  g_message("check_rfc: Failed Unable to find the RFC parameter");
194  }
195  return 0;
196 }
197 
198 BOOL getAccountId(char *outValue)
199 {
200  char temp[24] = {0};
201  int rc;
202  errno_t rc1 = -1;
203 
204  rc = syscfg_get(NULL, "AccountID", temp, sizeof(temp));
205  if(!rc)
206  {
207  if (check_null(outValue))
208  {
209  rc1 = strcpy_s(outValue,MAX_OUTVALUE,temp);
210  if(rc1 == EOK)
211  {
212  return TRUE;
213  }
214  else
215  {
216  ERR_CHK(rc1);
217  }
218  }
219  }
220  else
221  {
222  g_message("getAccountId: Unable to get the Account Id");
223  }
224  return FALSE;
225 }
226 
227 gboolean getserialnum(GString* serial_num)
228 {
229  gboolean result = FALSE;
230  if ( platform_hal_PandMDBInit() == 0)
231  {
232  g_message("getserialnum: hal PandMDB initiated successfully");
233  if ( platform_hal_GetSerialNumber(serial_num->str) == 0)
234  {
235  g_message("getserialnum: serialNumber from hal:%s", serial_num->str);
236  result = TRUE;
237  }
238  else
239  {
240  g_error("getserialnum: Unable to get SerialNumber");
241  }
242  }
243  else
244  {
245  g_message("getserialnum: Failed to initiate hal DB to fetch SerialNumber");
246  }
247  return result;
248 }
249 void xupnp_logger (const gchar *log_domain, GLogLevelFlags log_level,
250  const gchar *message, gpointer user_data)
251 {
252 
253  GTimeVal timeval;
254  char *timestr;
255  g_get_current_time(&timeval);
256  if (logoutfile == NULL)
257  {
258  // Fall back to console output if unable to open file
259  g_print (" g_time_val_to_iso8601(&timeval): %s\n", message);
260  return;
261  }
262 
263  timestr = g_time_val_to_iso8601(&timeval);
264  g_fprintf (logoutfile, "%s : %s\n", timestr, message);
265  g_free(timestr);
266  fflush(logoutfile);
267 
268 }
269 /**
270  * @brief This function is used to get partner ID.
271  *
272  * @return Returns partner ID.
273  * @ingroup XUPNP_XCALDEV_FUNC
274  */
275 
276 #if 0
277 static char *getPartnerID()
278 {
279  return partner_id->str;
280 }
281 #endif
282 
283 #ifndef BROADBAND_SUPPORT
284 #if 0
285 /**
286  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
287  *
288  * @param[in] ifname Name of the network interface.
289  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
290  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
291  *
292  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
293  * @ingroup XUPNP_XCALDEV_FUNC
294  */
295 static char *getPartnerName()
296 {
297  return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(partnerNameMap),
298  partnerNameMap);
299 }
300 /**
301  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
302  *
303  * @param[in] ifname Name of the network interface.
304  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
305  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
306  *
307  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
308  * @ingroup XUPNP_XCALDEV_FUNC
309  */
310 static char *getFriendlyName()
311 {
312  return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(friendlyNameMap),
313  friendlyNameMap);
314 }
315 /**
316  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
317  *
318  * @param[in] ifname Name of the network interface.
319  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
320  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
321  *
322  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
323  * @ingroup XUPNP_XCALDEV_FUNC
324  */
325 static char *getProductName()
326 {
327  return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(productNameMap),
328  productNameMap);
329 }
330 /**
331  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
332  *
333  * @param[in] ifname Name of the network interface.
334  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
335  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
336  *
337  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
338  * @ingroup XUPNP_XCALDEV_FUNC
339  */
340 static char *getServiceName()
341 {
342  return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(serviceNameMap),
343  serviceNameMap);
344 }
345 /**
346  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
347  *
348  * @param[in] ifname Name of the network interface.
349  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
350  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
351  *
352  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
353  * @ingroup XUPNP_XCALDEV_FUNC
354  */
355 static char *getServiceDescription()
356 {
357  return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(serviceDescriptionMap),
358  serviceDescriptionMap);
359 }
360 /**
361  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
362  *
363  * @param[in] ifname Name of the network interface.
364  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
365  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
366  *
367  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
368  * @ingroup XUPNP_XCALDEV_FUNC
369  */
370 static char *getGatewayName()
371 {
372  return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(gatewayNameMap),
373  gatewayNameMap);
374 }
375 #endif
376 #endif
377 /**
378  * @brief This function is used to retrieve the information from the device file.
379  *
380  * @param[in] deviceFile Name of the device configuration file.
381  *
382  * @return Returns TRUE if successfully reads the device file else returns FALSE.
383  * @ingroup XUPNP_XCALDEV_FUNC
384  */
385 gboolean readDevFile(const char *deviceFile)
386 {
387  GError *error=NULL;
388  gboolean result = FALSE;
389  gchar* devfilebuffer = NULL;
390  gchar counter=0;
391 
392  if (deviceFile == NULL)
393  {
394  g_message("device properties file not found");
395  return result;
396  }
397 
398  result = g_file_get_contents (deviceFile, &devfilebuffer, NULL, &error);
399  if (result == FALSE)
400  {
401  g_message("No contents in device properties");
402  }
403  else
404  {
405  /* reset result = FALSE to identify device properties from devicefile contents */
406  result = FALSE;
407  gchar **tokens = g_strsplit_set(devfilebuffer,",='\n'", -1);
408  guint toklength = g_strv_length(tokens);
409  guint loopvar=0;
410  for (loopvar=0; loopvar<toklength; loopvar++)
411  {
412  if (g_strrstr(g_strstrip(tokens[loopvar]), "DEVICE_TYPE"))
413  {
414  if ((loopvar+1) < toklength )
415  {
416  counter++;
417  g_string_assign(recvdevtype, g_strstrip(tokens[loopvar+1]));
418  }
419  if (counter == 6)
420  {
421  result = TRUE;
422  break;
423  }
424  }
425  else if(g_strrstr(g_strstrip(tokens[loopvar]), "BUILD_VERSION"))
426  {
427  if ((loopvar+1) < toklength )
428  {
429  counter++;
430  g_string_assign(buildversion, g_strstrip(tokens[loopvar+1]));
431  }
432  if (counter == 6)
433  {
434  result = TRUE;
435  break;
436  }
437  }
438  else if(g_strrstr(g_strstrip(tokens[loopvar]), "BOX_TYPE"))
439  {
440  if ((loopvar+1) < toklength )
441  {
442  counter++;
443  g_string_assign(devicetype, g_strstrip(tokens[loopvar+1]));
444  }
445  if (counter == 6)
446  {
447  result = TRUE;
448  break;
449  }
450  }
451  else if(g_strrstr(g_strstrip(tokens[loopvar]), "MODEL_NUM"))
452  {
453  if ((loopvar+1) < toklength )
454  {
455  counter++;
456  g_string_assign(devicename, g_strstrip(tokens[loopvar+1]));
457  }
458  if (counter == 6)
459  {
460  result = TRUE;
461  break;
462  }
463  }
464  if (g_strrstr(g_strstrip(tokens[loopvar]), "MFG_NAME"))
465  {
466  if ((loopvar+1) < toklength )
467  {
468  counter++;
469  g_string_assign(make, g_strstrip(tokens[loopvar+1]));
470  }
471  if (counter == 6)
472  {
473  result = TRUE;
474  break;
475  }
476  }
477  else
478  {
479  if (g_strrstr(g_strstrip(tokens[loopvar]), "MANUFACTURE"))
480  {
481  if ((loopvar+1) < toklength )
482  {
483  counter++;
484  g_string_assign(make, g_strstrip(tokens[loopvar+1]));
485  }
486  if (counter == 6)
487  {
488  result = TRUE;
489  break;
490  }
491  }
492  }
493 
494  }
495  g_strfreev(tokens);
496  }
497  g_string_printf(mocaIface,"%s",ISOLATION_IF);
498  g_string_printf(wifiIface,"%s",WIFI_IF);
499  if(result == FALSE)
500  {
501  g_message("RECEIVER_DEVICETYPE and BUILD_VERSION not found in %s",deviceFile);
502  }
503 
504  if(error)
505  {
506  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
507  g_clear_error(&error);
508  }
509 
510  //diagid=1000;
511  return result;
512 }
513 
514 /**
515  * @brief Supporting function for checking the content of given string is numeric or not.
516  *
517  * @param[in] str String for which the contents need to be verified.
518  *
519  * @return Returns TRUE if successfully checks the string is numeric else returns FALSE.
520  * @ingroup XUPNP_XCALDEV_FUNC
521  */
522 gboolean is_num(const gchar *str)
523 {
524 
525  unsigned int i=0;
526  gboolean isnum = TRUE;
527  for (i = 0; i < strlen(str); i++) {
528  if (!g_ascii_isdigit(str[i])) {
529  isnum = FALSE;
530  break;
531  }
532  }
533  return isnum;
534 }
535 
536 /**
537  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
538  *
539  * @param[in] ifname Name of the network interface.
540  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
541  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
542  *
543  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
544  * @ingroup XUPNP_XCALDEV_FUNC
545  */
546 BOOL check_empty(char *str)
547 {
548  if (str[0]) {
549  return TRUE;
550  }
551  return FALSE;
552 }
553 
554 BOOL check_null(char *str)
555 {
556  if (str) {
557  return TRUE;
558  }
559  return FALSE;
560 }
561 /**
562  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
563  *
564  * @param[in] ifname Name of the network interface.
565  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
566  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
567  *
568  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
569  * @ingroup XUPNP_XCALDEV_FUNC
570  */
571 BOOL getBaseUrl(char *outValue)
572 {
573  BOOL result = FALSE;
574  if ((!check_null((char *)gwyip)) || (!check_null(outValue)) || (!check_null((char *)recv_id))) {
575  g_message("getBaseUrl : NULL string !");
576  return result;
577  }
578  if (check_empty(gwyip->str) && check_empty(recv_id->str)) {
579  g_string_printf(url, "http://%s:8080/videoStreamInit?recorderId=%s",
580  gwyip->str, recv_id->str);
581  g_message ("The url is now %s.", url->str);
582  result = TRUE;
583  }
584  else
585  {
586  g_message("getBaseUrl : Empty url");
587  }
588  return result;
589 }
590 /**
591  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
592  *
593  * @param[in] ifname Name of the network interface.
594  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
595  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
596  *
597  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
598  * @ingroup XUPNP_XCALDEV_FUNC
599  */
600 BOOL getFogTsbUrl(char *outValue)
601 {
602  BOOL result = FALSE;
603  errno_t rc = -1;
604  if (!check_null(outValue)) {
605  g_message("getFogTsbUrl : NULL string !");
606  return result;
607  }
608  if (fogtsburl->str) {
609  rc = strcpy_s(outValue,MAX_OUTVALUE,fogtsburl->str);
610  if(rc == EOK)
611  {
612  result = TRUE;
613  }
614  else
615  {
616  ERR_CHK(rc);
617  }
618  } else {
619  g_message("getFogTsbUrl : No fogtsb url !");
620  }
621  return result;
622 }
623 /**
624  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
625  *
626  * @param[in] ifname Name of the network interface.
627  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
628  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
629  *
630  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
631  * @ingroup XUPNP_XCALDEV_FUNC
632  */
633 BOOL getDeviceName(char *outValue)
634 {
635  BOOL result = FALSE;
636  errno_t rc = -1;
637  if (!check_null(outValue)) {
638  g_message("getDeviceName : NULL string !");
639  return result;
640  }
641  if(devicename->str != NULL) {
642  rc = strcpy_s(outValue,MAX_OUTVALUE,devicename->str);
643  if(rc == EOK)
644  {
645  result = TRUE;
646  }
647  else
648  {
649  ERR_CHK(rc);
650  }
651  } else {
652  g_message("getDeviceName : No Device Name !");
653  }
654  return result;
655 }
656 /**
657  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
658  *
659  * @param[in] ifname Name of the network interface.
660  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
661  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
662  *
663  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
664  * @ingroup XUPNP_XCALDEV_FUNC
665  */
666 BOOL getDeviceType(char *outValue)
667 {
668  BOOL result = FALSE;
669  errno_t rc = -1;
670  if ((!check_null((char *)devicetype)) || (!check_null(outValue))) {
671  g_message("getDeviceType : NULL string !");
672  return result;
673  }
674  if (check_empty(devicetype->str)) {
675  rc = strcpy_s(outValue,MAX_OUTVALUE,devicetype->str);
676  if(rc == EOK)
677  {
678  result = TRUE;
679  }
680  else
681  {
682  ERR_CHK(rc);
683  }
684  }
685  else
686  {
687  g_message("getDeviceType : Empty device type");
688  }
689  return result;
690 }
691 /**
692  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
693  *
694  * @param[in] ifname Name of the network interface.
695  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
696  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
697  *
698  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
699  * @ingroup XUPNP_XCALDEV_FUNC
700  */
701 BOOL getBcastMacAddress(char *outValue)
702 {
703  BOOL result = FALSE;
704  errno_t rc = -1;
705  if (!check_null(outValue)) {
706  g_message("getBcastMacAddress : NULL string !");
707  return result;
708  }
709  if (devConf->bcastIf != NULL ) {
710  const gchar *bcastmac = (gchar *)getmacaddress(devConf->bcastIf);
711  if (bcastmac) {
712  g_message("Broadcast MAC address in interface: %s %s ", devConf->bcastIf,
713  bcastmac);
714  } else {
715  g_message("failed to retrieve macaddress on interface %s ", devConf->bcastIf);
716  return result;
717  }
718  g_string_assign(bcastmacaddress, bcastmac);
719  g_message("bcast mac address is %s", bcastmacaddress->str);
720  rc = strcpy_s(outValue,MAX_OUTVALUE,bcastmacaddress->str);
721  if(rc == EOK)
722  {
723  result = TRUE;
724  }
725  else
726  {
727  ERR_CHK(rc);
728  }
729  }
730  else
731  {
732  g_message("getBcastMacAddress : Empty broadcast interface");
733  }
734  return result;
735 
736 }
737 /**
738  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
739  *
740  * @param[in] ifname Name of the network interface.
741  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
742  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
743  *
744  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
745  * @ingroup XUPNP_XCALDEV_FUNC
746  */
747 BOOL getGatewayStbIp(char *outValue)
748 {
749  BOOL result = FALSE;
750  if ((!check_null((char *)gwystbip)) || (!check_null(outValue))) {
751  g_message("getGatewayStbIp : NULL string !");
752  return result;
753  }
754 #ifndef CLIENT_XCAL_SERVER
755  errno_t rc = -1;
756  if (check_empty(gwystbip->str)) {
757  rc = strcpy_s(outValue,MAX_OUTVALUE,gwystbip->str);
758  if(rc == EOK)
759  {
760  result = TRUE;
761  }
762  else
763  {
764  ERR_CHK(rc);
765  }
766  }
767 #endif
768  return result;
769 }
770 /**
771  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
772  *
773  * @param[in] ifname Name of the network interface.
774  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
775  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
776  *
777  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
778  * @ingroup XUPNP_XCALDEV_FUNC
779  */
780 BOOL getGatewayIpv6(char *outValue)
781 {
782  BOOL result = FALSE;
783  if ((!check_null((char *)gwyipv6)) || (!check_null(outValue))) {
784  g_message("getGatewayIpv6 : NULL string !");
785  return result;
786  }
787 #ifndef CLIENT_XCAL_SERVER
788  errno_t rc = -1;
789  if (check_empty(gwyipv6->str)) {
790  rc = strcpy_s(outValue,MAX_OUTVALUE,gwyipv6->str);
791  if(rc == EOK)
792  {
793  result = TRUE;
794  }
795  else
796  {
797  ERR_CHK(rc);
798  }
799  }
800 #endif
801  return result;
802 }
803 /**
804  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
805  *
806  * @param[in] ifname Name of the network interface.
807  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
808  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
809  *
810  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
811  * @ingroup XUPNP_XCALDEV_FUNC
812  */
813 BOOL getGatewayIp(char *outValue)
814 {
815  BOOL result = FALSE;
816  errno_t rc = -1;
817  if ((!check_null((char *)gwyip)) || (!check_null(outValue))) {
818  g_message("getGatewayIp : NULL string !");
819  return result;
820  }
821  if (check_empty(gwyip->str)) {
822  rc = strcpy_s(outValue,MAX_OUTVALUE,gwyip->str);
823  if(rc == EOK)
824  {
825  result = TRUE;
826  }
827  else
828  {
829  ERR_CHK(rc);
830  }
831  }
832  else
833  {
834  g_message("getGatewayIp : Empty gateway ip");
835  }
836  return result;
837 }
838 /**
839  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
840  *
841  * @param[in] ifname Name of the network interface.
842  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
843  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
844  *
845  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
846  * @ingroup XUPNP_XCALDEV_FUNC
847  */
848 BOOL getRecvDevType(char *outValue)
849 {
850  BOOL result = FALSE;
851  errno_t rc = -1;
852  if ((!check_null((char *)recvdevtype)) || (!check_null(outValue))) {
853  g_message("getRecvDevType : NULL string !");
854  return result;
855  }
856  if (check_empty(recvdevtype->str)) {
857  rc = strcpy_s(outValue,MAX_OUTVALUE,recvdevtype->str);
858  if(rc == EOK)
859  {
860  result = TRUE;
861  }
862  else
863  {
864  ERR_CHK(rc);
865  }
866  }
867  else
868  {
869  g_message("getRecvDevType : Empty receiver device type");
870  }
871  return result;
872 }
873 BOOL getBuildVersion(char *outValue)
874 {
875  BOOL result = FALSE;
876  errno_t rc = -1;
877  if ((!check_null((char *)buildversion)) || (!check_null(outValue))) {
878  g_message("getBuildVersion : NULL string !");
879  return result;
880  }
881  if (check_empty(buildversion->str)) {
882  rc = strcpy_s(outValue,MAX_OUTVALUE,buildversion->str);
883  if(rc == EOK)
884  {
885  result = TRUE;
886  }
887  else
888  {
889  ERR_CHK(rc);
890  }
891  }
892  else
893  {
894  g_message("getBuildVersion : Empty Build version");
895  }
896  return result;
897 }
898 BOOL getHostMacAddress(char *outValue)
899 {
900  BOOL result = FALSE;
901  if (!(check_null((char *)hostmacaddress)) || (!check_null(outValue))) {
902  g_message("getHostMacAddress : NULL string !");
903  return result;
904  }
905 #ifndef CLIENT_XCAL_SERVER
906  errno_t rc = -1;
907  if (devConf->hostMacIf != NULL) {
908  const gchar *hostmac = (gchar *)getmacaddress(devConf->hostMacIf);
909  if (hostmac) {
910  g_message("MAC address in interface: %s %s ", devConf->hostMacIf, hostmac);
911  } else {
912  g_message("failed to retrieve macaddress on interface %s ",
913  devConf->hostMacIf);
914  }
915  g_string_assign(hostmacaddress, hostmac);
916  g_message("Host mac address is %s", hostmacaddress->str);
917  rc = strcpy_s(outValue,MAX_OUTVALUE,hostmacaddress->str);
918  if(rc == EOK)
919  {
920  result = TRUE;
921  }
922  else
923  {
924  ERR_CHK(rc);
925  }
926  }
927 #endif
928  return result;
929 }
930 BOOL getSystemsIds(char *outValue)
931 {
932  BOOL result = FALSE;
933  errno_t rc = -1;
934  if ((!check_null((char *)systemids)) || (!check_null(outValue))) {
935  g_message("getSystemsIds : NULL string !");
936  return result;
937  }
938  if (check_empty(systemids->str)) {
939  rc = strcpy_s(outValue,MAX_OUTVALUE,systemids->str);
940  if(rc == EOK)
941  {
942  result = TRUE;
943  }
944  else
945  {
946  ERR_CHK(rc);
947  }
948  }
949  else
950  {
951  g_message("getSystemsIds : empty system ids");
952  }
953  return result;
954 }
955 gboolean gettimezone(void)
956 {
957  GError *error=NULL;
958  gboolean result = FALSE;
959  gchar* dsgproxyfile = NULL;
960 
961  if (devConf->dsgFile == NULL)
962  {
963  g_warning("dsg file name not found in config");
964  return result;
965  }
966  result = g_file_get_contents (devConf->dsgFile, &dsgproxyfile, NULL, &error);
967 
968  /* Coverity Fix for CID: 124792: Forward NULL */
969  if (result == FALSE) {
970 
971  g_warning("Problem in reading dsgproxyfile file %s",
972  error ? error->message : "NULL");
973 
974  }
975  else
976  {
977  /* reset result = FALSE to identify timezone from dsgproxyfile contents */
978  result = FALSE;
979  gchar **tokens = g_strsplit_set(dsgproxyfile,",=", -1);
980  guint toklength = g_strv_length(tokens);
981  guint loopvar=0;
982  for (loopvar=0; loopvar<toklength; loopvar++)
983  {
984  //g_print("Token is %s\n",g_strstrip(tokens[loopvar]));
985  if (g_strrstr(g_strstrip(tokens[loopvar]), "DSGPROXY_HOST_TIME_ZONE"))
986  {
987  if ((loopvar+1) < toklength )
988  {
989  g_string_assign(dsgtimezone, g_strstrip(tokens[loopvar+1]));
990  }
991  result = TRUE;
992  break;
993  }
994  }
995  g_strfreev(tokens);
996  }
997 
998  //diagid=1000;
999  if(error)
1000  {
1001  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
1002  g_clear_error(&error);
1003  }
1004 
1005  return result;
1006 }
1007 
1008 BOOL getIpSubnet(char *outValue)
1009 {
1010  BOOL result = FALSE;
1011  int ret = 0;
1012  if (!check_null(outValue)) {
1013  g_message("getIpSubnet : NULL string !");
1014  return result;
1015  }
1016  FILE *fp = NULL;
1017 
1018  if(!(fp = v_secure_popen("r", "ip -4 route show dev "PRIVATE_LAN_BRIDGE " | grep -v "LINK_LOCAL_ADDR " | grep src | awk '{print $1}'")))
1019  {
1020  return result;
1021  }
1022 
1023  while(fgets(outValue, sizeof(MAX_OUTVALUE), fp)!=NULL)
1024  {
1025  size_t len = strlen(outValue);
1026  if (len > 0 && outValue[len-1] == '\n') {
1027  outValue[len-1] = '\0';
1028  }
1029  }
1030 
1031  ret = v_secure_pclose(fp);
1032  if(ret != 0)
1033  {
1034  g_message("Error in closing pipe ! : %d \n", ret);
1035  }
1036  else {
1037  result = TRUE;
1038  }
1039  return result;
1040 }
1041 
1042 BOOL getTimeZone(char *outValue)
1043 {
1044  BOOL result = FALSE;
1045  errno_t rc = -1;
1046  if ((!check_null((char *)dsgtimezone)) || (!check_null(outValue))) {
1047  g_message("getTimeZone : NULL string !");
1048  return result;
1049  }
1050  if (check_empty(dsgtimezone->str)) {
1051  rc = strcpy_s(outValue,MAX_OUTVALUE, dsgtimezone->str);
1052  if(rc == EOK)
1053  {
1054  result = TRUE;
1055  }
1056  else
1057  {
1058  ERR_CHK(rc);
1059  }
1060  }
1061  else
1062  {
1063  g_message("getTimeZone : Empty timezone");
1064  }
1065  return result;
1066 }
1067 BOOL getRawOffSet(int *outValue)
1068 {
1069  *outValue = rawOffset;
1070  return TRUE;
1071 }
1072 BOOL getDstSavings(int *outValue)
1073 {
1074  *outValue = dstSavings;
1075  return TRUE;
1076 }
1077 BOOL getUsesDayLightTime(BOOL *outValue)
1078 {
1079  *outValue = usesDaylightTime;
1080  return TRUE;
1081 }
1082 BOOL getIsGateway(BOOL *outValue)
1083 {
1084  *outValue = devConf->allowGwy;
1085  return TRUE;
1086 }
1087 BOOL getHosts(char *outValue)
1088 {
1089  BOOL result = FALSE;
1090  errno_t rc = -1;
1091  if (!check_null(outValue)) {
1092  g_message("getHosts : NULL string !");
1093  return result;
1094  }
1095  if (check_empty(etchosts->str)) {
1096  rc = strcpy_s(outValue,RUIURLSIZE,etchosts->str);
1097  if(rc == EOK)
1098  {
1099  result = TRUE;
1100  }
1101  else
1102  {
1103  ERR_CHK(rc);
1104  }
1105  } else {
1106  g_message("getHosts : No Hosts Data available !");
1107  }
1108  return result;
1109 }
1110 BOOL getRequiresTRM(BOOL *outValue)
1111 {
1112  *outValue = requirestrm;
1113  return TRUE;
1114 }
1115 BOOL getBcastPort(int *outValue)
1116 {
1117  *outValue = devConf->bcastPort;
1118  return TRUE;
1119 }
1120 BOOL getBcastIp(char *outValue)
1121 {
1122  BOOL result = FALSE;
1123  errno_t rc = -1;
1124  if ((!check_null((char *)gwyip)) || (!check_null(outValue))) {
1125  g_message("getBcastIp : NULL string !");
1126  return result;
1127  }
1128  if (check_empty(gwyip->str)) {
1129  rc = strcpy_s(outValue,MAX_OUTVALUE,gwyip->str);
1130  if(rc == EOK)
1131  {
1132  result = TRUE;
1133  }
1134  else
1135  {
1136  ERR_CHK(rc);
1137  }
1138  }
1139  else
1140  {
1141  g_message("getBcastIp : Empty Broadcast Ip");
1142  }
1143  return result;
1144 }
1145 BOOL getBcastIf(char *outValue)
1146 {
1147  BOOL result = FALSE;
1148  errno_t rc = -1;
1149  if (!check_null(outValue)) {
1150  g_message("getBcastIf : NULL string !");
1151  return result;
1152  }
1153  if(check_empty(devConf->bcastIf)) {
1154  rc = strcpy_s(outValue, MAXSIZE, devConf->bcastIf);
1155  if(rc == EOK)
1156  {
1157  result = TRUE;
1158  }
1159  else
1160  {
1161  ERR_CHK(rc);
1162  }
1163  }
1164  else
1165  g_message("getBcastIf : No Bcast Interface found !");
1166  return result;
1167 }
1168 
1169 /**
1170  * @brief Supporting function for checking the given string is alphanumeric.
1171  *
1172  * @param[in] str String to be verified.
1173  *
1174  * @return Returns TRUE if successfully checks the string is alphanumeric else returns FALSE.
1175  * @ingroup XUPNP_XCALDEV_FUNC
1176  */
1177 gboolean is_alphanum(const gchar *str)
1178 {
1179  unsigned int i=0;
1180  gboolean isalphanum = TRUE;
1181  for (i = 0; i < strlen(str); i++) {
1182  if (!g_ascii_isalnum(str[i])) {
1183  isalphanum = FALSE;
1184  break;
1185  }
1186  }
1187  return isalphanum;
1188 }
1189 
1190 BOOL getRUIUrl(char *outValue)
1191 {
1192  return TRUE;
1193 }
1194 BOOL getSerialNum(char *outValue)
1195 {
1196  BOOL result = FALSE;
1197  errno_t rc = -1;
1198  if (!check_null(outValue)) {
1199  g_message("getSerialNum : NULL string !");
1200  return result;
1201  }
1202  if(check_empty(serial_num->str)) {
1203  rc = strcpy_s(outValue,MAX_OUTVALUE,serial_num->str);
1204  if(rc == EOK)
1205  {
1206  result = TRUE;
1207  }
1208  else
1209  {
1210  ERR_CHK(rc);
1211  }
1212  } else {
1213  g_message("getSerialNum : No Serial Number Available !");
1214  }
1215  return result;
1216 }
1217 BOOL getPartnerId(char *outValue)
1218 {
1219  BOOL result = FALSE;
1220  errno_t rc = -1;
1221  if (!check_null(outValue)) {
1222  g_message("getPartnerId : NULL string !");
1223  return result;
1224  } else {
1225  if (check_null((char *)partner_id) && check_empty(partner_id->str)) {
1226  rc = strcpy_s(outValue,MAX_OUTVALUE,partner_id->str);
1227  if(rc == EOK)
1228  {
1229  result = TRUE;
1230  }
1231  else
1232  {
1233  ERR_CHK(rc);
1234  }
1235  }
1236  else
1237  {
1238  g_message("getPartnerId : No partnerId available");
1239  }
1240  }
1241  return result;
1242 }
1243 BOOL getDevKeyPath(char *outValue)
1244 {
1245  BOOL result = FALSE;
1246  if ((!check_null(devConf->devKeyPath)) || (!check_null(outValue))) {
1247  g_message("getDevKeyPath: NULL string !");
1248  return result;
1249  }
1250  if (check_empty(devConf->devKeyPath)) {
1251  strncpy(outValue,devConf->devKeyPath, MAX_FILE_LENGTH);
1252  result = TRUE;
1253  } else
1254  g_message("getDevKeyPath : config has empty key path !");
1255  return result;
1256 }
1257 
1258 BOOL getDevKeyFile(char *outValue)
1259 {
1260  BOOL result = FALSE;
1261  if ((!check_null(devConf->devKeyFile)) || (!check_null(outValue))) {
1262  g_message("getDevKeyFile : NULL string !");
1263  return result;
1264  }
1265  if (check_empty(devConf->devKeyFile)) {
1266  strncpy(outValue,devConf->devKeyFile, MAX_FILE_LENGTH);
1267  result = TRUE;
1268  } else
1269  g_message("getDevKeyFile : config has empty key file !");
1270  return result;
1271 }
1272 
1273 BOOL getDevCertPath(char *outValue)
1274 {
1275  BOOL result = FALSE;
1276  if ((!check_null(devConf->devCertPath)) || (!check_null(outValue))) {
1277  g_message("getDevCertPath: NULL string !");
1278  return result;
1279  }
1280  if (check_empty(devConf->devCertPath)) {
1281  strncpy(outValue,devConf->devCertPath, MAX_FILE_LENGTH);
1282  result = TRUE;
1283  } else
1284  g_message("getDevCertPath: config has empty path!");
1285  return result;
1286 
1287 }
1288 
1289 BOOL getDevCertFile(char *outValue)
1290 {
1291  BOOL result = FALSE;
1292  if ((!check_null(devConf->devCertFile)) || (!check_null(outValue))) {
1293  g_message("getDevCertFile: NULL string !");
1294  return result;
1295  }
1296  if (check_empty(devConf->devCertFile)) {
1297  strncpy(outValue,devConf->devCertFile, MAX_FILE_LENGTH);
1298  result = TRUE;
1299  } else
1300  g_message("getDevCertFile: config has empty file !");
1301  return result;
1302 }
1303 
1304 BOOL getUidfromRecvId()
1305 {
1306  BOOL result = FALSE;
1307  guint loopvar = 0;
1308  gchar **tokens = g_strsplit_set(eroutermacaddress->str, "':''\n'", -1);
1309  guint toklength = g_strv_length(tokens);
1310  while (loopvar < toklength)
1311  {
1312  g_string_printf(recv_id, "ebf5a0a0-1dd1-11b2-a90f-%s%s%s%s%s%s", g_strstrip(tokens[loopvar]), g_strstrip(tokens[loopvar + 1]),g_strstrip(tokens[loopvar + 2]),g_strstrip(tokens[loopvar + 3]),g_strstrip(tokens[loopvar + 4]),g_strstrip(tokens[loopvar + 5]));
1313  g_message("getUidfromRecvId: recvId: %s", recv_id->str);
1314  result = TRUE;
1315  break;
1316  }
1317  g_strfreev(tokens);
1318  return result;
1319 }
1320 BOOL getUUID(char *outValue)
1321 {
1322  BOOL result = FALSE;
1323  if (!check_null(outValue)) {
1324  g_message("getUUID : NULL string !");
1325  return result;
1326  }
1327  if (getUidfromRecvId()){
1328  if( (check_empty(recv_id->str))) {
1329  sprintf(outValue, "uuid:%s", recv_id->str);
1330  result = TRUE;
1331  }
1332  else
1333  {
1334  g_message("getUUID : empty recvId");
1335  }
1336  }
1337  else
1338  {
1339  g_message("getUUID : could not get UUID");
1340  }
1341  return result;
1342 }
1343 
1344 BOOL getReceiverId(char *outValue)
1345 {
1346  BOOL result = FALSE;
1347  errno_t rc = -1;
1348  if (!check_null(outValue)) {
1349  g_message("getReceiverId : NULL string !");
1350  return result;
1351  }
1352  if(getUidfromRecvId())
1353  {
1354  if (check_null((char *)recv_id) && check_empty(recv_id->str)) {
1355  rc = strcpy_s(outValue,MAX_OUTVALUE,recv_id->str);
1356  if(rc == EOK)
1357  {
1358  result = TRUE;
1359  }
1360  else
1361  {
1362  ERR_CHK(rc);
1363  }
1364  }
1365  else
1366  {
1367  g_message("getReceiverId : empty recvId");
1368  }
1369  }
1370  else
1371  {
1372  g_message("getUUID : could not get UUID");
1373  }
1374  return result;
1375 }
1376 BOOL getTrmUrl(char *outValue)
1377 {
1378  BOOL result = FALSE;
1379  errno_t rc = -1;
1380  if (!check_null(outValue)) {
1381  g_message("getTrmUrl : NULL string !");
1382  return result;
1383  }
1384  if (check_empty(trmurl->str)) {
1385  rc = strcpy_s(outValue,MAX_OUTVALUE,trmurl->str);
1386  if(rc == EOK)
1387  {
1388  result = TRUE;
1389  }
1390  else
1391  {
1392  ERR_CHK(rc);
1393  }
1394  } else {
1395  g_message("getTrmUrl : No trmurl found");
1396  }
1397  return result;
1398 }
1399 BOOL getTuneReady()
1400 {
1401  return tune_ready;
1402 }
1403 BOOL getPlaybackUrl(char *outValue)
1404 {
1405  BOOL result = FALSE;
1406  errno_t rc = -1;
1407  if (!check_null(playbackurl->str)){
1408  g_message("getPlaybackUrl: NULL string !");
1409  return result;
1410  }
1411  if (check_empty(playbackurl->str))
1412  {
1413  rc = strcpy_s(outValue,URLSIZE, playbackurl->str);
1414  if(rc == EOK)
1415  {
1416  result = TRUE;
1417  }
1418  else
1419  {
1420  ERR_CHK(rc);
1421  }
1422  }
1423  else
1424  {
1425  g_message("getPlaybackUrl: Empty plabackurl");
1426  }
1427  return result;
1428 }
1429 BOOL getVideoBasedUrl(char *outValue)
1430 {
1431  BOOL result = FALSE;
1432  errno_t rc = -1;
1433  if (!check_null(outValue)) {
1434  g_message("getVideoBasedUrl : NULL string !");
1435  return result;
1436  }
1437  if (check_empty(videobaseurl->str)) {
1438  rc = strcpy_s(outValue,MAX_OUTVALUE, videobaseurl->str);
1439  if(rc == EOK)
1440  {
1441  result = TRUE;
1442  }
1443  else
1444  {
1445  ERR_CHK(rc);
1446  }
1447  } else {
1448  g_message("getVideoBasedUrl : No VideoBasedUrl found");
1449  }
1450  return result;
1451 }
1452 BOOL getIsuseGliDiagEnabled()
1453 {
1454  return devConf->useGliDiag;
1455 }
1456 BOOL getDstOffset(int *outValue)
1457 {
1458  *outValue = dstOffset;
1459  return TRUE;
1460 }
1461 BOOL getDisableTuneReadyStatus()
1462 {
1463  return devConf->disableTuneReady;
1464 }
1465 
1466 #ifndef CLIENT_XCAL_SERVER
1467 BOOL getCVPIp(char *outValue)
1468 {
1469  errno_t rc = -1;
1470  if (!check_null(outValue)) {
1471  g_message("getCVPIp : NULL string !");
1472  return FALSE;
1473  }
1474  ipAddressBuffer[0] = '\0';
1475  int result = getipaddress(devConf->cvpIf, ipAddressBuffer, FALSE);
1476  if (!result) {
1477  fprintf(stderr, "Could not locate the ipaddress of CVP2 interface %s\n",
1478  devConf->cvpIf);
1479  return FALSE;
1480  }
1481  g_message("ipaddress of the CVP2 interface %s", ipAddressBuffer);
1482  rc = strcpy_s(outValue,MAX_OUTVALUE,ipAddressBuffer);
1483  if(rc == EOK)
1484  {
1485  return TRUE;
1486  }
1487  else
1488  {
1489  ERR_CHK(rc);
1490  return FALSE;
1491  }
1492 }
1493 BOOL getCVPIf(char *outValue)
1494 {
1495  BOOL result = FALSE;
1496  errno_t rc = -1
1497  if (!check_null(outValue)) {
1498  g_message("getCVPIf : NULL string !");
1499  return result;
1500  }
1501  if (check_empty(devConf->cvpIf)) {
1502  rc = strcpy_s(outValue, MAXSIZE, devConf->cvpIf);
1503  if(rc == EOK)
1504  {
1505  result = TRUE;
1506  }
1507  else
1508  {
1509  ERR_CHK(rc);
1510  }
1511  }
1512  else
1513  {
1514  g_message("getCVPIf : Failed to get the CVP Interface");
1515  }
1516  return result;
1517 }
1518 BOOL getCVPPort(int *outValue)
1519 {
1520  BOOL result = FALSE;
1521  if (!check_null(outValue)) {
1522  g_message("getCVPPort : NULL string !");
1523  return result;
1524  }
1525  else
1526  {
1527  *outValue = devConf->cvpPort;
1528  result = TRUE;
1529  }
1530  return result;
1531 }
1532 BOOL getCVPXmlFile(char *outValue)
1533 {
1534  BOOL result = FALSE;
1535  errno_t rc = -1;
1536  if (!check_null(outValue)) {
1537  g_message("getCVPXmlFile : NULL string !");
1538  return result;
1539  }
1540  if (check_empty(devConf->cvpXmlFile)) {
1541  rc = strcpy_s(outValue, MAXSIZE, devConf->cvpXmlFile);
1542  if(rc == EOK)
1543  {
1544  result = TRUE;
1545  }
1546  else
1547  {
1548  ERR_CHK(rc);
1549  }
1550  }
1551  else
1552  {
1553  g_message("getCVPXmlFile : Failed to get the CVP XmlFile");
1554  }
1555  return result;
1556 }
1557 #endif
1558 
1559 BOOL getRouteDataGateway(char *outValue)
1560 {
1561  BOOL result = FALSE;
1562  errno_t rc = -1;
1563  if (!check_null(outValue)) {
1564  g_message("getRouteDataGateway : NULL string !");
1565  return result;
1566  }
1567  if(check_empty(dataGatewayIPaddress->str)) {
1568  rc = strcpy_s(outValue,MAX_OUTVALUE,dataGatewayIPaddress->str);
1569  if(rc == EOK)
1570  {
1571  result = TRUE;
1572  }
1573  else
1574  {
1575  ERR_CHK(rc);
1576  }
1577  } else
1578  g_message("getRouteDataGateway : error getting route data!");
1579  return result;
1580 }
1581 BOOL getLogFile(char *outValue)
1582 {
1583  BOOL result = FALSE;
1584  errno_t rc = -1;
1585  if (!check_null(outValue)) {
1586  g_message("getLogFile : NULL string !");
1587  return result;
1588  }
1589  if (check_empty(devConf->logFile)) {
1590  rc = strcpy_s(outValue,MAX_OUTVALUE,devConf->logFile);
1591  if(rc == EOK)
1592  {
1593  result = TRUE;
1594  }
1595  else
1596  {
1597  ERR_CHK(rc);
1598  }
1599  } else
1600  g_message("getLogFile : Config doesnt have a log file !");
1601  return result;
1602 }
1603 BOOL getEstbMacAddr(char *outValue)
1604 {
1605  BOOL result = FALSE;
1606 #ifndef CLIENT_XCAL_SERVER
1607  errno_t rc = -1;
1608  if ((!check_null(devConf->hostMacIf)) || (!check_null(outValue))) {
1609  g_message("getEstbMacAddr : NULL string !");
1610  return result;
1611  }
1612  if (!check_empty(hostmacaddress->str)) {
1613  const gchar *hostmac = (gchar *)getmacaddress(devConf->hostMacIf);
1614  if (hostmac) {
1615  g_message("MAC address in interface: %s %s ", devConf->hostMacIf, hostmac);
1616  g_string_assign(hostmacaddress,hostmac);
1617  result = TRUE;
1618  } else {
1619  g_message("failed to retrieve macaddress on interface %s ",
1620  devConf->hostMacIf);
1621  return result;
1622  }
1623  }
1624  rc = strcpy_s(outValue,MAX_OUTVALUE, hostmacaddress->str);
1625  if(rc == EOK)
1626  {
1627  result = TRUE;
1628  }
1629  else
1630  {
1631  ERR_CHK(rc);
1632  }
1633  g_message("Host mac address is %s", hostmacaddress->str);
1634 #endif
1635 return result;
1636 }
1637 BOOL getDevXmlPath(char *outValue)
1638 {
1639  BOOL result = FALSE;
1640  errno_t rc = -1;
1641  if ((!check_null(devConf->devXmlPath)) || (!check_null(outValue))) {
1642  g_message("getDevXmlPath : NULL string !");
1643  return result;
1644  }
1645  if (check_empty(devConf->devXmlPath)) {
1646  rc = strcpy_s(outValue,MAX_OUTVALUE,devConf->devXmlPath);
1647  if(rc == EOK)
1648  {
1649  result = TRUE;
1650  }
1651  else
1652  {
1653  ERR_CHK(rc);
1654  }
1655  } else
1656  g_message("getDevXmlPath : config has empty xml path !");
1657  return result;
1658 }
1659 
1660 BOOL getDevXmlFile(char *outValue, int refactor)
1661 {
1662  BOOL result = FALSE;
1663  if ((!check_null(devConf->devXmlFile)) || (!check_null(outValue))) {
1664  g_message("getDevXmlFile : NULL string !");
1665  return result;
1666  }
1667  if(!refactor)
1668  {
1669  if (check_empty(devConf->devXmlFile)) {
1670  sprintf(outValue, "%s/%s", devConf->devXmlPath, devConf->devXmlFile);
1671  result = TRUE;
1672  } else
1673  g_message("getDevXmlFile : config has empty xml file !");
1674  }
1675  else
1676  {
1677  sprintf(outValue, "%s/%s", devConf->devXmlPath,BROADBAND_DEVICE_XML_FILE);
1678  g_message("getDevXmlFile : refactor = %s",outValue);
1679  result = TRUE;
1680  }
1681  return result;
1682 }
1683 
1684 BOOL checkCVP2Enabled()
1685 {
1686  return devConf->enableCVP2;
1687 }
1688 
1689 BOOL getModelNumber(char *outValue)
1690 {
1691  BOOL result = FALSE;
1692  errno_t rc = -1;
1693  if ((!check_null(devicename->str)) || (!check_null(outValue))) {
1694  g_message("getModelNumber : NULL string !");
1695  return result;
1696  }
1697  if (check_empty(devicename->str)) {
1698  rc = strcpy_s(outValue,MAX_OUTVALUE,devicename->str);
1699  if(rc == EOK)
1700  {
1701  result = TRUE;
1702  }
1703  else
1704  {
1705  ERR_CHK(rc);
1706  }
1707  } else
1708  g_message("getModelNumber : config has empty modelnumber file !");
1709  return result;
1710 }
1711 
1712 BOOL getMake(char *outValue)
1713 {
1714  BOOL result = FALSE;
1715  errno_t rc = -1;
1716  if ((!check_null(make->str)) || (!check_null(outValue))) {
1717  g_message("getMake : NULL string !");
1718  return result;
1719  }
1720  if (check_empty(make->str)) {
1721  rc = strcpy_s(outValue,MAX_OUTVALUE,make->str);
1722  if(rc == EOK)
1723  {
1724  result = TRUE;
1725  }
1726  else
1727  {
1728  ERR_CHK(rc);
1729  }
1730  } else
1731  g_message("getMake : config has empty device make file !");
1732  return result;
1733 }
1734 
1735 BOOL xdeviceInit(char *devConfFile, char *devLogFile)
1736 {
1737  syscfg_init(); // to get values from syscfg.db
1738  url = g_string_new(NULL);
1739  trmurl = g_string_new(NULL);
1740  trmurlCVP2 = g_string_new(NULL);
1741  playbackurl = g_string_new(NULL);
1742  fogtsburl = g_string_new(NULL);
1743  playbackurlCVP2 = g_string_new(NULL);
1744  videobaseurl = g_string_new("null");
1745  gwyip = g_string_new(NULL);
1746  gwyipv6 = g_string_new(NULL);
1747  gwystbip = g_string_new(NULL);
1748  ipv6prefix = g_string_new(NULL);
1749  gwyipCVP2 = g_string_new(NULL);
1750  dnsconfig = g_string_new(NULL);
1751  systemids = g_string_new(NULL);
1752  dsgtimezone = g_string_new(NULL);
1753  etchosts = g_string_new(NULL);
1754  serial_num = g_string_new(NULL);
1755  channelmap_id = dac_id = plant_id = vodserver_id = 0;
1756  isgateway = FALSE;
1757  requirestrm = FALSE;
1758  service_ready = FALSE;
1759  tune_ready = FALSE;
1760  ruiurl = g_string_new(NULL);
1761  inDevProfile = g_string_new(NULL);
1762  uiFilter = g_string_new(NULL);
1763  recv_id = g_string_new(NULL);
1764  partner_id = g_string_new(NULL);
1765  hostmacaddress = g_string_new(NULL);
1766  bcastmacaddress = g_string_new(NULL);
1767  eroutermacaddress = g_string_new(NULL);
1768  devicename = g_string_new(NULL);
1769  buildversion = g_string_new(NULL);
1770  recvdevtype = g_string_new(NULL);
1771  devicetype = g_string_new(NULL);
1772  mocaIface = g_string_new(NULL);
1773  wifiIface = g_string_new(NULL);
1774  make = g_string_new(NULL);
1775  dataGatewayIPaddress = g_string_new(NULL);
1776 
1777  if (! check_null(devConfFile)) {
1778 #ifndef CLIENT_XCAL_SERVER
1779  g_message("No Configuration file please use /usr/bin/xcal-device /etc/xdevice.conf");
1780  exit(1);
1781 #endif
1782  }
1783 #ifndef CLIENT_XCAL_SERVER
1784  if(readconffile(devConfFile)==FALSE)
1785  {
1786  g_message("readconffile returned FALSE");
1787  devConf = g_new0(ConfSettings, 1);
1788  }
1789 #else
1790  devConf = g_new0(ConfSettings, 1);
1791 #endif
1792 
1793 #ifdef CLIENT_XCAL_SERVER
1794 
1795  if (! (devConf->bcastPort))
1796  devConf->bcastPort = BCAST_PORT;
1797  if (! (devConf->devPropertyFile))
1798  devConf->devPropertyFile = g_strdup(DEVICE_PROPERTY_FILE);
1799  if (! (devConf->deviceNameFile))
1800  devConf->deviceNameFile = g_strdup(DEVICE_NAME_FILE);
1801  if (! (devConf->logFile))
1802  devConf->logFile = g_strdup(LOG_FILE);
1803  if (! (devConf->devXmlPath))
1804  devConf->devXmlPath = g_strdup(DEVICE_XML_PATH);
1805  if (! (devConf->devXmlFile))
1806  devConf->devXmlFile = g_strdup(DEVICE_XML_FILE);
1807  if (! (devConf->devKeyFile))
1808  devConf->devKeyFile = g_strdup(DEVICE_KEY_FILE);
1809  if (! (devConf->devKeyPath))
1810  devConf->devKeyPath = g_strdup(DEVICE_KEY_PATH);
1811  if (! (devConf->devCertFile))
1812  devConf->devCertFile = g_strdup(DEVICE_CERT_FILE);
1813  if (! (devConf->devCertPath))
1814  devConf->devCertPath = g_strdup(DEVICE_CERT_PATH);
1815  devConf->allowGwy = FALSE;
1816  devConf->useIARM = TRUE;
1817  devConf->useGliDiag=TRUE;
1818 #endif
1819  if (check_null(devLogFile)) {
1820  logoutfile = g_fopen (devLogFile, "a");
1821  }
1822  else if (devConf->logFile) {
1823  logoutfile = g_fopen (devConf->logFile, "a");
1824  }
1825  else {
1826  g_message("xupnp not handling the logging");
1827  }
1828  if (logoutfile) {
1829  g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | \
1830  G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR, xupnp_logger,
1831  NULL);
1832  g_log_set_handler("libsoup", G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | \
1833  G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR, xupnp_logger,
1834  NULL);
1835  }
1836  g_message("Starting xdevice service");
1837  if (devConf->devPropertyFile != NULL) {
1838  if (readDevFile(devConf->devPropertyFile) == TRUE) {
1839  g_message("Receiver Type : %s Build Version : %s Device Type: %s moca %s wifi %s ",
1840  recvdevtype->str, buildversion->str, devicetype->str, mocaIface->str,
1841  wifiIface->str);
1842  } else {
1843  g_message(" ERROR in getting Receiver Type : %s Build Version : %s ",
1844  recvdevtype->str, buildversion->str);
1845  g_message("Receiver Type : %s Build Version : %s Device Type: %s moca %s wifi %s ",
1846  recvdevtype->str, buildversion->str, devicetype->str, mocaIface->str,
1847  wifiIface->str);
1848  }
1849  }
1850  int loop,result,assigned=0;
1851  for(loop=0;loop<10;loop++)
1852  {
1853 #ifndef CLIENT_XCAL_SERVER
1854  if ( access(devConf->ipv6FileLocation, F_OK ) != -1 )
1855  result = getipaddress(devConf->bcastIf, ipAddressBuffer, TRUE);
1856  if (!result) {
1857  fprintf(stderr,
1858  "In Ipv6 Could not locate the link local ipv6 address of the broadcast interface %s\n",
1859  devConf->bcastIf);
1860  g_critical("In Ipv6 Could not locate the link local ipv6 address of the broadcast interface %s\n",
1861  devConf->bcastIf);
1862  }
1863  else {
1864  assigned=1;
1865  g_message("ipaddress of the interface %s", ipAddressBuffer);
1866  }
1867  g_string_assign(gwyipv6, ipAddressBuffer);
1868  ipAddressBuffer[0] = '\0';
1869  result = getipaddress(devConf->bcastIf, ipAddressBuffer, FALSE);
1870  if (!result) {
1871  fprintf(stderr,
1872  "Could not locate the link local v4 ipaddress of the broadcast interface %s\n",
1873  devConf->bcastIf);
1874  g_critical("Could not locate the link local v4 ipaddress of the broadcast interface %s\n",
1875  devConf->bcastIf);
1876  } else {
1877  assigned=1;
1878  g_message("ipaddress of the interface %s", ipAddressBuffer);
1879  break;
1880  }
1881 #else
1882  ipAddressBuffer[0] = '\0';
1883  result = getipaddress(mocaIface->str, ipAddressBuffer, FALSE);
1884  if (!result) {
1885  g_message("Could not locate the ipaddress of the broadcast moca isolation interface %s",
1886  mocaIface->str);
1887  result = getipaddress(wifiIface->str, ipAddressBuffer, FALSE);
1888  if (!result) {
1889  g_message("Could not locate the ipaddress of the wifi broadcast interface %s",
1890  wifiIface->str);
1891  g_critical("Could not locate the link local v4 ipaddress of the broadcast interface %s\n",
1892  wifiIface->str);
1893  } else {
1894  devConf->bcastIf = g_strdup(wifiIface->str);
1895  g_message("ipaddress of the interface %s", ipAddressBuffer);
1896  assigned=1;
1897  break;
1898  }
1899  } else {
1900  devConf->bcastIf = g_strdup(mocaIface->str);
1901  g_message("ipaddress of the interface %s", ipAddressBuffer);
1902  assigned=1;
1903  break;
1904  }
1905 #endif
1906  sleep(1);
1907  }
1908  if(assigned != 0){
1909  g_message("Starting xdevice service on interface %s ipAddressBuffer= %s", devConf->bcastIf,ipAddressBuffer);
1910  }
1911  else{
1912  g_message("waited 10 seconds for interface to come up so giving up");
1913  exit(1);
1914  }
1915  g_message("Broadcast Network interface: %s", devConf->bcastIf);
1916  g_message("Dev XML File Name: %s", devConf->devXmlFile);
1917  g_string_assign(gwyip, ipAddressBuffer);
1918  //Init IARM Events
1919 #if defined(USE_XUPNP_IARM_BUS)
1920  gboolean iarminit = XUPnP_IARM_Init();
1921  if (iarminit == true) {
1922  //g_print("IARM init success");
1923  g_message("XUPNP IARM init success");
1924 #ifndef CLIENT_XCAL_SERVER
1925  getSystemValues();
1926 #endif
1927  } else {
1928  //g_print("IARM init failure");
1929  g_critical("XUPNP IARM init failed");
1930  }
1931 #endif //#if defined(USE_XUPNP_IARM_BUS)
1932 #ifndef CLIENT_XCAL_SERVER
1933  if (devConf->hostMacIf != NULL) {
1934  const gchar *hostmac = (gchar *)getmacaddress(devConf->hostMacIf);
1935  if (hostmac) {
1936  g_message("MAC address in interface: %s %s \n", devConf->hostMacIf, hostmac);
1937  } else {
1938  g_message("failed to retrieve macaddress on interface %s ",
1939  devConf->hostMacIf);
1940  }
1941  g_string_assign(hostmacaddress, hostmac);
1942  g_message("Host mac address is %s", hostmacaddress->str);
1943  }
1944 #endif
1945  if (devConf->bcastIf != NULL ) {
1946  const gchar *bcastmac = (gchar *)getmacaddress(devConf->bcastIf);
1947  if (bcastmac) {
1948  g_message("Broadcast MAC address in interface: %s %s ", devConf->bcastIf,
1949  bcastmac);
1950  } else {
1951  g_message("failed to retrieve macaddress on interface %s ", devConf->bcastIf);
1952  }
1953  g_string_assign(bcastmacaddress, bcastmac);
1954  g_message("bcast mac address is %s", bcastmacaddress->str);
1955  }
1956  const gchar *eroutermac = (gchar *)getmacaddress(UDN_IF);
1957  if(eroutermac)
1958  {
1959  g_message("Erouter0 MAC address in interface: %s %s",UDN_IF,
1960  eroutermac);
1961  }
1962  else
1963  {
1964  g_message("failed to retrieve macaddress on interface %s ", devConf->bcastIf);
1965  }
1966  g_string_assign(eroutermacaddress,eroutermac);
1967  g_message("erouter0 mac address is %s",eroutermacaddress->str);
1968  if(devicename->str != NULL)
1969  {
1970  g_message("Device Name : %s ", devicename->str);
1971  }
1972  else
1973  {
1974  g_message(" ERROR in getting Device Name ");
1975  }
1976 #ifndef CLIENT_XCAL_SERVER
1977  if (devConf->enableTRM == FALSE) {
1978  requirestrm = FALSE;
1979  g_string_printf(trmurl, NULL);
1980  } else {
1981  requirestrm = TRUE;
1982  g_string_printf(trmurl, "ws://%s:9988", ipAddressBuffer);
1983  }
1984 #endif
1985  if (devConf->allowGwy == FALSE) {
1986  isgateway = FALSE;
1987  }
1988 #ifndef CLIENT_XCAL_SERVER
1989  g_string_printf(playbackurl,
1990  "http://%s:8080/hnStreamStart?deviceId=%s&DTCP1HOST=%s&DTCP1PORT=5000",
1991  ipAddressBuffer, recv_id->str, ipAddressBuffer);
1992  if (getDnsConfig(dnsconfig->str) == TRUE) {
1993  g_print("Contents of dnsconfig is %s\n", dnsconfig->str);
1994  }
1995  if (updatesystemids() == TRUE) {
1996  g_message("System ids are %s", systemids->str);
1997  } else {
1998  g_warning("Error in finding system ids\n");
1999  }
2000 #if defined(USE_XUPNP_IARM_BUS)
2001  if ((strlen(g_strstrip(serial_num->str)) < 6)
2002  || (is_alphanum(serial_num->str) == FALSE)) {
2003  g_message("Serial Number not yet received.\n");
2004  }
2005  g_message("Received Serial Number:%s", serial_num->str);
2006 #else
2007  if (getserialnum(serial_num) == TRUE) {
2008  g_message("Serial Number is %s", serial_num->str);
2009  }
2010 #endif
2011 #else
2012  if (getserialnum(serial_num) == TRUE) {
2013  g_message("Serial Number is %s", serial_num->str);
2014  }
2015 #endif
2016 
2017 #ifndef CLIENT_XCAL_SERVER
2018  if (getetchosts() == TRUE) {
2019  g_message("EtcHosts Content is %s", etchosts->str);
2020  } else {
2021  g_message("Error in getting etc hosts");
2022  }
2023 #else
2024 
2025 #endif
2026 #ifndef CLIENT_XCAL_SERVER
2027  if (devConf->disableTuneReady == FALSE) {
2028  if (FALSE == tune_ready) {
2029  g_message("XUPnP: Tune Ready Not Yet Received.\n");
2030  }
2031  } else {
2032  g_message("Tune Ready check is disabled - Setting tune_ready to TRUE");
2033  tune_ready = TRUE;
2034  }
2035  if ((devConf->allowGwy == TRUE) && (ipv6Enabled == TRUE)
2036  && (devConf->ipv6PrefixFile != NULL)) {
2037  if (access(devConf->ipv6PrefixFile, F_OK ) == -1 ) {
2038  g_message("IPv6 Prefix File Not Yet Created.");
2039  }
2040  if (getIpv6Prefix(ipv6prefix->str) == FALSE) {
2041  g_message(" V6 prefix is not yet updated in file %s ",
2042  devConf->ipv6PrefixFile);
2043  }
2044  g_message("IPv6 prefix : %s ", ipv6prefix->str);
2045  } else {
2046  g_message("Box is in IPV4 or ipv6 prefix is empty or Not a gateway ipv6enabled = %d ipv6PrefixFile = %s allowGwy = %d ",
2047  ipv6Enabled, devConf->ipv6PrefixFile, devConf->allowGwy);
2048  }
2049  if (devConf->hostMacIf != NULL) {
2050  result = getipaddress(devConf->hostMacIf, stbipAddressBuffer, ipv6Enabled);
2051  if (!result) {
2052  g_message("Could not locate the ipaddress of the host mac interface %s\n",
2053  devConf->hostMacIf);
2054  } else
2055  g_message("ipaddress of the interface %s\n", stbipAddressBuffer);
2056  g_string_assign(gwystbip, stbipAddressBuffer);
2057  }
2058 #endif
2059 return TRUE;
2060 }
2061 
2062 /**
2063  * @brief This function is used to get the Receiver Id & Partner Id.
2064  *
2065  * When box in warehouse mode, the box does not have the receiver Id so the box need to be put the
2066  * broadcast MAC address as receiver Id.
2067  *
2068  * @param[in] id The Device ID node for which the value need to be retrieved. It is also used for
2069  * getting Partner Id.
2070  *
2071  * @return Returns Value of the Device Id on success else NULL.
2072  * @ingroup XUPNP_XCALDEV_FUNC
2073  */
2074 GString *getID( const gchar *id )
2075 {
2076  gboolean isDevIdPresent = FALSE;
2077  gshort counter =
2078  0; // to limit the logging if the user doesnt activate for long time
2079  GString *jsonData = g_string_new(NULL);
2080  GString *value = g_string_new(NULL);
2081 
2082  FILE *fp = NULL;
2083  if((fp = v_secure_popen("r", GET_DEVICEID_SCRIPT)))
2084  {
2085  char response[1024] = {0};
2086  fread(response, 1, sizeof(response)-1, fp);
2087  int ret = v_secure_pclose(fp);
2088  if(ret != 0)
2089  g_message("Error in closing pipe ! : %d \n", ret);
2090 
2091  if ((response[0] == '\0') && (counter < MAX_DEBUG_MESSAGE)) {
2092  counter ++;
2093  g_message("No Json string found in Auth url %s \n" ,
2094  response);
2095  } else {
2096  g_string_assign(jsonData, response);
2097  gchar **tokens = g_strsplit_set(jsonData->str, "{}:,\"", -1);
2098  guint tokLength = g_strv_length(tokens);
2099  guint loopvar = 0;
2100  for (loopvar = 0; loopvar < tokLength; loopvar++) {
2101  if (g_strrstr(g_strstrip(tokens[loopvar]), id)) {
2102  //"deviceId": "T00xxxxxxx" so omit 3 tokens ":" fromDeviceId
2103  if ((loopvar + 3) < tokLength ) {
2104  g_string_assign(value, g_strstrip(tokens[loopvar + 3]));
2105  if (value->str[0] != '\0') {
2106  isDevIdPresent = TRUE;
2107  break;
2108  }
2109  }
2110  }
2111  }
2112  if (!isDevIdPresent) {
2113  if (g_strrstr(id, PARTNER_ID)) {
2114  g_message("%s not found in Json string in Auth url %s \n ", id, jsonData->str);
2115  return value;
2116  }
2117  if (counter < MAX_DEBUG_MESSAGE ) {
2118  counter++;
2119  g_message("%s not found in Json string in Auth url %s \n ", id, jsonData->str);
2120  }
2121  } else {
2122  g_message("Successfully fetched %s %s \n ", id, value->str);
2123  //g_free(tokens);
2124  //#########
2125  //break;
2126  //#########
2127  }
2128  g_strfreev(tokens);
2129  }
2130  }
2131  else
2132  {
2133  g_message("The deviceId script %s can't be executed\n", GET_DEVICEID_SCRIPT);
2134  }
2135 
2136  g_string_free(jsonData, TRUE);
2137  return value;
2138 }
2139 
2140 /**
2141  * @brief This function is used to update the system Ids such as channelMapId, controllerId, plantId
2142  * and vodServerId.
2143  *
2144  * @return Returns TRUE if successfully updates the system ids, else returns FALSE.
2145  * @ingroup XUPNP_XCALDEV_FUNC
2146  */
2147 gboolean updatesystemids(void)
2148 {
2149  if (devConf->useGliDiag == TRUE) {
2150  g_string_printf(systemids,
2151  "channelMapId:%lu;controllerId:%lu;plantId:%lu;vodServerId:%lu",
2152  channelmap_id, dac_id, plant_id, vodserver_id);
2153  return TRUE;
2154  } else {
2155  /* Coverity Fix CID: 124887 : UnInitialised variable*/
2156  gchar *diagfile = NULL;
2157  unsigned long diagid = 0;
2158  gboolean result = FALSE;
2159  GError *error = NULL;
2160  if (devConf->diagFile == NULL) {
2161  g_warning("diag file name not found in config");
2162  return result;
2163  }
2164  result = g_file_get_contents (devConf->diagFile, &diagfile, NULL, &error);
2165  if (result == FALSE) {
2166  g_string_assign(systemids,
2167  "channelMapId:0;controllerId:0;plantId:0;vodServerId:0");
2168  } else {
2169  diagid = getidfromdiagfile("channelMapId", diagfile);
2170  g_string_printf(systemids, "channelMapId:%lu;", diagid);
2171  diagid = getidfromdiagfile("controllerId", diagfile);
2172  g_string_append_printf(systemids, "controllerId:%lu;", diagid);
2173  diagid = getidfromdiagfile("plantId", diagfile);
2174  g_string_append_printf(systemids, "plantId:%lu;", diagid);
2175  diagid = getidfromdiagfile("vodServerId", diagfile);
2176  g_string_append_printf(systemids, "vodServerId:%lu", diagid);
2177  }
2178  if (error) {
2179  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
2180  g_clear_error(&error);
2181  }
2182  return result;
2183  }
2184 }
2185 
2186 /**
2187  * @brief This function is used to get the device name from /devicename/devicename file.
2188  *
2189  * @return Returns TRUE if successfully gets the device name string else returns FALSE.
2190  * @ingroup XUPNP_XCALDEV_FUNC
2191  */
2192 gboolean parsedevicename(void)
2193 {
2194  GError *error = NULL;
2195  gboolean result = FALSE;
2196  gchar *devicenamefile = NULL;
2197  guint loopvar = 0;
2198  gboolean devicenamematch = FALSE;
2199  if (devConf->deviceNameFile == NULL) {
2200  g_warning("device name file name not found in config");
2201  return result;
2202  }
2203  result = g_file_get_contents (devConf->deviceNameFile, &devicenamefile, NULL,
2204  &error);
2205 
2206  /* Coverity Fix for CID: 125452 : Forward NULL */
2207  if (result == FALSE) {
2208  g_warning("Problem in reading /devicename/devicename file %s", error ? error->message : "NULL");
2209  } else {
2210  gchar **tokens = g_strsplit_set(devicenamefile, "'=''\n''\0'", -1);
2211  guint toklength = g_strv_length(tokens);
2212  while (loopvar < toklength) {
2213  if (g_strrstr(g_strstrip(tokens[loopvar]), "deviceName")) {
2214  result = TRUE;
2215  g_string_printf(devicename, "%s", g_strstrip(tokens[loopvar + 1]));
2216  g_message("device name = %s", devicename->str);
2217  devicenamematch = TRUE;
2218  break;
2219  }
2220  loopvar++;
2221  }
2222  g_strfreev(tokens);
2223  if (devicenamematch == FALSE) {
2224  g_message("No Matching devicename in file %s", devicenamefile);
2225  }
2226  }
2227  if (error) {
2228  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
2229  g_clear_error(&error);
2230  }
2231  g_free(devicenamefile);
2232  return result;
2233 }
2234 
2235 /**
2236  * @brief This function is used to retrieve the IPv6 prefix information from dibblers file.
2237  *
2238  * @return Returns TRUE if successfully gets the ipv6 prefix value else returns FALSE.
2239  * @ingroup XUPNP_XCALDEV_FUNC
2240  */
2241 gboolean parseipv6prefix(void)
2242 {
2243  GError *error = NULL;
2244  gboolean result = FALSE;
2245  gchar *prefixfile = NULL;
2246  guint loopvar = 0;
2247  guint prefixloopvar = 0;
2248  gboolean ifacematch = FALSE;
2249  gboolean prefixmatch = FALSE;
2250  gchar **prefixtokens;
2251  if (devConf->ipv6PrefixFile == NULL) {
2252  g_warning("ipv6PrefixFile file name not found in config");
2253  return result;
2254  }
2255  result = g_file_get_contents (devConf->ipv6PrefixFile, &prefixfile, NULL,
2256  &error);
2257  /* Coverity Fix for CID: 124926 : Forward NULL */
2258  if (result == FALSE) {
2259  g_warning("Problem in reading /prefix/prefix file %s", error ? error->message : "NULL");
2260  } else {
2261  gchar **tokens = g_strsplit_set(prefixfile, "'\n''\0'", -1);
2262  guint toklength = g_strv_length(tokens);
2263  while (loopvar < toklength) {
2264  if (ifacematch == FALSE) {
2265  if ((g_strrstr(g_strstrip(tokens[loopvar]), "ifacename"))
2266  && (g_strrstr(g_strstrip(tokens[loopvar]), devConf->hostMacIf))) {
2267  ifacematch = TRUE;
2268  }
2269  } else {
2270  if (g_strrstr(g_strstrip(tokens[loopvar]), "AddrPrefix")) {
2271  prefixtokens = g_strsplit_set(tokens[loopvar], "'<''>''='", -1);
2272  guint prefixtoklength = g_strv_length(prefixtokens);
2273  while (prefixloopvar < prefixtoklength) {
2274  if (g_strrstr(g_strstrip(prefixtokens[prefixloopvar]), "/AddrPrefix")) {
2275  prefixmatch = TRUE;
2276  result = TRUE;
2277  g_string_printf(ipv6prefix, "%s", prefixtokens[prefixloopvar - 1]);
2278  g_message("ipv6 prefix format in the file %s",
2279  prefixtokens[prefixloopvar - 1]);
2280  break;
2281  }
2282  prefixloopvar++;
2283  }
2284  g_strfreev(prefixtokens);
2285  }
2286  if (prefixmatch == TRUE)
2287  break;
2288  }
2289  loopvar++;
2290  }
2291  g_strfreev(tokens);
2292  if (prefixmatch == FALSE) {
2293  result = FALSE;
2294  g_message("No Matching ipv6 prefix in file %s", prefixfile);
2295  }
2296  }
2297  if (error) {
2298  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
2299  g_clear_error(&error);
2300  }
2301  g_free(prefixfile);
2302  return result;
2303 }
2304 /*
2305 * isVidiPathEnabled()
2306 * If /opt/vidiPathEnabled does not exist, indicates VidiPath is NOT enabled.
2307 * If /opt/vidiPathEnabled exists, VidiPath is enabled.
2308 */
2309 #define VIDIPATH_FLAG "/opt/vidiPathEnabled"
2310 
2311 #ifndef CLIENT_XCAL_SERVER
2312 static int isVidiPathEnabled()
2313 {
2314  if (access(VIDIPATH_FLAG, F_OK) == 0)
2315  return 1; //vidipath enabled
2316  return 0; //vidipath not enabled
2317 }
2318 #endif
2319 
2320 /**
2321  * @brief This function is used to retrieve the data from the device configuration file
2322  *
2323  * @param[in] configfile Device configuration file name.
2324  *
2325  * @return Returns TRUE if successfully reads the configuration else returns FALSE.
2326  * @ingroup XUPNP_XCALDEV_FUNC
2327  */
2328 gboolean readconffile(const char *configfile)
2329 {
2330  GKeyFile *keyfile = NULL;
2331  GKeyFileFlags flags;
2332  GError *error = NULL;
2333  /* Create a new GKeyFile object and a bitwise list of flags. */
2334  keyfile = g_key_file_new ();
2335  flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
2336  /* Load the GKeyFile from keyfile.conf or return. */
2337  if (!g_key_file_load_from_file (keyfile, configfile, flags, &error)) {
2338  if (error) {
2339  g_error ("%s\n", error->message);
2340  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
2341  g_clear_error(&error);
2342  }
2343  if (keyfile) {
2344  g_key_file_free(keyfile);
2345  }
2346  return FALSE;
2347  }
2348  //g_message("Starting with Settings %s\n", g_key_file_to_data(keyfile, NULL,
2349  // NULL));
2350  devConf = g_new0(ConfSettings, 1);
2351  /*
2352  # Names of all network interfaces used for publishing
2353  [Network]
2354  BCastIf=eth1
2355  BCastPort=50755
2356  StreamIf=eth1
2357  TrmIf=eth1
2358  GwIf=eth1
2359  CvpIf=eth1
2360  CvpPort=50753
2361  HostMacIf=wan
2362  */
2363  /* Read in data from the key file from the group "Network". */
2364  devConf->bcastIf = g_key_file_get_string (keyfile, "Network",
2365  "BCastIf", NULL);
2366  devConf->bcastPort = g_key_file_get_integer (keyfile, "Network",
2367  "BCastPort", NULL);
2368 #ifndef CLIENT_XCAL_SERVER
2369  devConf->streamIf = g_key_file_get_string (keyfile, "Network",
2370  "StreamIf", NULL);
2371  devConf->trmIf = g_key_file_get_string (keyfile, "Network",
2372  "TrmIf", NULL);
2373  devConf->gwIf = g_key_file_get_string (keyfile, "Network", "GwIf",
2374  NULL);
2375  devConf->cvpIf = g_key_file_get_string (keyfile, "Network",
2376  "CvpIf", NULL);
2377  devConf->cvpPort = g_key_file_get_integer (keyfile, "Network",
2378  "CvpPort", NULL);
2379  devConf->hostMacIf = g_key_file_get_string (keyfile, "Network",
2380  "HostMacIf", NULL);
2381 #endif
2382  /*
2383  # Paths and names of all input data files
2384  [DataFiles]
2385  OemFile=//etc//udhcpc.vendor_specific
2386  DnsFile=//etc//resolv.dnsmasq
2387  DsgFile=//tmp//dsgproxy_slp_attributes.txt
2388  DiagFile=//tmp//mnt/diska3//persistent//usr//1112//703e//diagnostics.json
2389  HostsFile=//etc//hosts
2390  WbFile=/opt/www/whitebox/wbdevice.dat
2391  DevXmlPath=/opt/xupnp/
2392  DevXmlFile=BasicDevice.xml
2393  LogFile=/opt/logs/xdevice.log
2394  AuthServerUrl=http://localhost:50050/device/generateAuthToken
2395  DevPropertyFile=/etc/device.properties
2396  Ipv6FileLocation=/tmp/stb_ipv6
2397  Ipv6PrefixFile=/tmp/stb_ipv6
2398  DeviceNameFile=/opt/hn_service_settings.conf
2399  */
2400  /* Read in data from the key file from the group "DataFiles". */
2401 #ifndef CLIENT_XCAL_SERVER
2402  devConf->oemFile = g_key_file_get_string (keyfile, "DataFiles",
2403  "OemFile", NULL);
2404  devConf->dnsFile = g_key_file_get_string (keyfile, "DataFiles",
2405  "DnsFile", NULL);
2406  devConf->dsgFile = g_key_file_get_string (keyfile, "DataFiles",
2407  "DsgFile", NULL);
2408  devConf->diagFile = g_key_file_get_string (keyfile, "DataFiles",
2409  "DiagFile", NULL);
2410  devConf->wbFile = g_key_file_get_string (keyfile, "DataFiles",
2411  "WbFile", NULL);
2412  devConf->devXmlPath = g_key_file_get_string (keyfile, "DataFiles",
2413  "DevXmlPath", NULL);
2414  devConf->devXmlFile = g_key_file_get_string (keyfile, "DataFiles",
2415  "DevXmlFile", NULL);
2416  devConf->cvpXmlFile = g_key_file_get_string (keyfile, "DataFiles",
2417  "CvpXmlFile", NULL);
2418  devConf->logFile = g_key_file_get_string (keyfile, "DataFiles",
2419  "LogFile", NULL);
2420  devConf->ipv6FileLocation = g_key_file_get_string (keyfile,
2421  "DataFiles", "Ipv6FileLocation", NULL);
2422  devConf->ipv6PrefixFile = g_key_file_get_string (keyfile, "DataFiles",
2423  "Ipv6PrefixFile", NULL);
2424  devConf->devCertFile = g_key_file_get_string (keyfile, "DataFiles",
2425  "DevCertFile", NULL);
2426  devConf->devKeyFile = g_key_file_get_string (keyfile, "DataFiles",
2427  "DevKeyFile", NULL);
2428  devConf->devCertPath = g_key_file_get_string (keyfile, "DataFiles",
2429  "DevCertPath", NULL);
2430  devConf->devKeyPath = g_key_file_get_string (keyfile, "DataFiles",
2431  "DevKeyPath", NULL);
2432 #endif
2433  devConf->deviceNameFile = g_key_file_get_string (keyfile, "DataFiles",
2434  "DeviceNameFile", NULL);
2435  devConf->devPropertyFile = g_key_file_get_string (keyfile,
2436  "DataFiles", "DevPropertyFile", NULL);
2437  /*
2438  # Enable/Disable feature flags
2439  [Flags]
2440  EnableCVP2=false
2441  UseIARM=true
2442  AllowGwy=true
2443  EnableTRM=true
2444  UseGliDiag=true
2445  DisableTuneReady=true
2446  enableHostMacPblsh=true
2447  wareHouseMode=true
2448  rmfCrshSupp=false
2449  */
2450  devConf->useIARM = g_key_file_get_boolean (keyfile, "Flags",
2451  "UseIARM", NULL);
2452  devConf->allowGwy = g_key_file_get_boolean (keyfile, "Flags",
2453  "AllowGwy", NULL);
2454 #ifndef CLIENT_XCAL_SERVER
2455  devConf->enableCVP2 = isVidiPathEnabled();
2456  devConf->ruiPath = g_key_file_get_string (keyfile, "Rui", "RuiPath" , NULL);
2457  if (devConf->ruiPath == NULL ) { //only use overrides if ruiPath is not present
2458  devConf->uriOverride = g_key_file_get_string (keyfile, "Rui", "uriOverride",
2459  NULL);
2460  } else {
2461  devConf->uriOverride = NULL;
2462  }
2463  devConf->enableTRM = g_key_file_get_boolean (keyfile, "Flags",
2464  "EnableTRM", NULL);
2465  devConf->useGliDiag = g_key_file_get_boolean (keyfile, "Flags",
2466  "UseGliDiag", NULL);
2467  devConf->disableTuneReady = g_key_file_get_boolean (keyfile,
2468  "Flags", "DisableTuneReady", NULL);
2469  devConf->enableHostMacPblsh = g_key_file_get_boolean (keyfile,
2470  "Flags", "EnableHostMacPblsh", NULL);
2471  devConf->rmfCrshSupp = g_key_file_get_boolean (keyfile, "Flags",
2472  "rmfCrshSupp", NULL);
2473  devConf->wareHouseMode = g_key_file_get_boolean (keyfile, "Flags",
2474  "wareHouseMode", NULL);
2475 #endif
2476  g_key_file_free(keyfile);
2477 #ifndef CLIENT_XCAL_SERVER
2478  if ((devConf->bcastIf == NULL) || (devConf->bcastPort == 0)
2479  || (devConf->devXmlPath == NULL) ||
2480  (devConf->devXmlFile == NULL) || (devConf->wbFile == NULL)) {
2481  g_warning("Invalid or no values found for mandatory parameters\n");
2482  return FALSE;
2483  }
2484 #endif
2485  return TRUE;
2486 }
2487 
2488 /*-----------------------------
2489 * Initialize ipAddressBufferCVP2 with ip address at devConf->cvp2If
2490 */
2491 #if 0
2492 static void initIpAddressBufferCVP2( char *ipAddressBufferCVP2)
2493 {
2494  int result = getipaddress(devConf->cvpIf, ipAddressBufferCVP2, FALSE);
2495 
2496  if (!result)
2497  {
2498  fprintf(stderr,"Could not locate the ipaddress of CVP2 interface %s\n", devConf->cvpIf);
2499  }
2500 
2501  g_message("ipaddress of the CVP2 interface %s\n", ipAddressBufferCVP2);
2502  g_string_assign(gwyipCVP2, ipAddressBufferCVP2);
2503 }
2504 #endif
2505 
2506 /*-----------------------------
2507 * Returns pointer to string of eSTBMAC without ':' chars
2508 * Uses global hostmacaddress GString for address value
2509 * Returned string must be g_string_free() if not NULL
2510 */
2511 
2512 /**
2513  * @brief This function is used to get the MAC address of the eSTB. It uses global hostmacaddress
2514  * GString to get the address value.
2515  *
2516  * @return Returned string must be g_string_free() if not NULL.
2517  * @ingroup XUPNP_XCALDEV_FUNC
2518  */
2519 GString* get_eSTBMAC(void)
2520 {
2521  if (hostmacaddress != NULL && hostmacaddress->len == 17)//length of address with ':' chars
2522  {
2523  GString* addr = g_string_new(NULL);
2524 
2525  int i = 0;
2526  for (i = 0; i < hostmacaddress->len; ++i)
2527  {
2528  if (i != 2 && i != 5 && i != 8 && i != 11 && i != 14 )//positions of ':' char
2529  {
2530  addr = g_string_append_c(addr,(hostmacaddress->str)[i]);
2531  }
2532  }
2533  return g_string_ascii_up(addr);
2534  }
2535  return NULL;
2536 }
2537 
2538 #if 0
2539 /*-----------------------------
2540 * Creates a XML escaped string from input
2541 */
2542 static void xmlescape(gchar *instr, GString *outstr)
2543 {
2544  for (; *instr; instr++)
2545  {
2546  switch (*instr)
2547  {
2548  case '&':
2549  g_string_append_printf(outstr,"%s","&amp;");
2550  break;
2551  case '\"':
2552  g_string_append_printf(outstr,"%s","&guot;");
2553  break;
2554  case '\'':
2555  g_string_append_printf(outstr,"%s","&apos;");
2556  break;
2557  case '<':
2558  g_string_append_printf(outstr,"%s","&lt;");
2559  break;
2560  case '>':
2561  g_string_append_printf(outstr,"%s","&gt;");
2562  break;
2563  default:
2564  g_string_append_printf(outstr,"%c",*instr);
2565  break;
2566  }
2567  }
2568 }
2569 
2570 /*-----------------------------
2571 * Creates a URI escaped string from input using RFC 2396 reserved chars
2572 * The output matches what javascript encodeURIComponent() generates
2573 */
2574 static void uriescape(unsigned char *instr, GString *outstr)
2575 {
2576  int i;
2577  char unreserved[256] = {0}; //array of unreserved chars or 0 flag
2578 
2579  for (i = 0; i < 256; ++i) //init unreserved chars
2580  {
2581  unreserved[i] = isalnum(i) || i == '-' || i == '_' || i == '.' || i == '!' || i == '~'
2582  || i == '*' || i == '\'' || i == '(' || i == ')'
2583  ? i : 0;
2584  }
2585 
2586  for (; *instr; instr++) //escape the input string to the output string
2587  {
2588  if (unreserved[*instr]) //if defined as unreserved
2589  g_string_append_printf(outstr,"%c",*instr);
2590  else
2591  g_string_append_printf(outstr,"%%%02X",*instr);
2592  }
2593 }
2594 
2595 
2596 /*-----------------------------
2597 * Creates the escaped rui <uri> element value
2598 */
2599 static GString *get_uri_value()
2600 {
2601  //create a unique udn value
2602  //struct timeval now;
2603  //int rc = gettimeofday(&now,NULL);
2604  GTimeVal timeval;
2605  g_get_current_time(&timeval);
2606  double t = timeval.tv_sec + (timeval.tv_usec /
2607  1000000.0); //number of seconds and microsecs since epoch
2608  char udnvalue[25];
2609  snprintf(udnvalue, 25, "%s%f", "CVP-", t);
2610  //get current ip address for CVP2
2611  char ipAddressBufferCVP2[INET6_ADDRSTRLEN];
2612  initIpAddressBufferCVP2(ipAddressBufferCVP2);
2613  //init uri parameters with current ip address
2614  g_string_printf(trmurlCVP2, "ws://%s:9988", ipAddressBufferCVP2);
2615  g_string_printf(playbackurlCVP2,
2616  "http://%s:8080/hnStreamStart?deviceId=%s&DTCP1HOST=%s&DTCP1PORT=5000",
2617  ipAddressBufferCVP2, recv_id->str, ipAddressBufferCVP2);
2618  //initialize urivalue from xdevice.conf if present
2619  gchar *urilink;
2620  if (devConf->uriOverride != NULL)
2621  urilink = devConf->uriOverride;
2622  else
2623  urilink = "http://syndeo.xcal.tv/app/x2rui/rui.html";
2624  //g_print("before g_strconcat urilink: %s\n",urilink);
2625  //parse the systemids
2626  //systemids-str must have the following format
2627  //channelMapId:%lu;controllerId:%lu;plantId:%lu;vodServerId:%lu
2628  g_print("systemids->str: %s\n", systemids->str);
2629  GString *channelMapId = NULL;
2630  char *pId = "channelMapId:";
2631  char *pChannelMapId = strstr(systemids->str, pId);
2632  if (pChannelMapId != NULL) {
2633  pChannelMapId += strlen(pId);
2634  size_t len = strcspn(pChannelMapId, ";");
2635  channelMapId = g_string_new_len(pChannelMapId, len);
2636  }
2637  if (channelMapId == NULL)
2638  channelMapId = g_string_new("0");
2639  GString *controllerId = NULL;
2640  pId = "controllerId:";
2641  char *pControllerId = strstr(systemids->str, pId);
2642  if (pControllerId != NULL) {
2643  pControllerId += strlen(pId);
2644  size_t len = strcspn(pControllerId, ";");
2645  controllerId = g_string_new_len(pControllerId, len);
2646  }
2647  if (controllerId == NULL)
2648  controllerId = g_string_new("0");
2649  GString *plantId = NULL;
2650  pId = "plantId:";
2651  char *pPlantId = strstr(systemids->str, pId);
2652  if (pPlantId != NULL) {
2653  pPlantId += strlen(pId);
2654  size_t len = strcspn(pPlantId, ";");
2655  plantId = g_string_new_len(pPlantId, len);
2656  }
2657  if (plantId == NULL)
2658  plantId = g_string_new("0");
2659  GString *vodServerId = NULL;
2660  pId = "vodServerId:";
2661  char *pVodServerId = strstr(systemids->str, pId);
2662  if (pVodServerId != NULL) {
2663  pVodServerId += strlen(pId);
2664  size_t len = strcspn(pVodServerId, ";");
2665  vodServerId = g_string_new_len(pVodServerId, len);
2666  }
2667  if (vodServerId == NULL)
2668  vodServerId = g_string_new("0");
2669  GString *eSTBMAC = get_eSTBMAC();
2670  if (eSTBMAC == NULL) {
2671  eSTBMAC = g_string_new("UNKNOWN");
2672  }
2673  gchar *gw_value = g_strconcat(
2674  "{"
2675  "\"deviceType\":\"DMS\","
2676  "\"friendlyName\":\"" , getGatewayName(), "\","
2677  "\"receiverID\":\"" , recv_id->str, "\","
2678  "\"udn\":\"" , udnvalue, "\","
2679  "\"gatewayIP\":\"" , gwyipCVP2->str, "\","
2680  "\"baseURL\":\"" , playbackurlCVP2->str, "\","
2681  "\"trmURL\":\"" , trmurlCVP2->str, "\","
2682  "\"channelMapId\":\"" , channelMapId->str, "\","
2683  "\"controllerId\":\"" , controllerId->str, "\","
2684  "\"plantId\":\"" , plantId->str, "\","
2685  "\"vodServerId\":\"" , vodServerId->str, "\","
2686  "\"eSTBMAC\":\"" , eSTBMAC->str, "\""
2687  "}", NULL );
2688  g_string_free(eSTBMAC, TRUE);
2689  g_string_free(channelMapId, TRUE);
2690  g_string_free(controllerId, TRUE);
2691  g_string_free(plantId, TRUE);
2692  g_string_free(vodServerId, TRUE);
2693  //gchar *gw_value = "a&b\"c\'d<e>f;g/h?i:j@k&l=m+n$o,p{}q'r_s-t.u!v~x*y(z)"; //test string with reserved chars
2694  //g_print("gw_value string before escape = %s\n",gw_value);
2695  GString *gwescapededstr = g_string_sized_new(strlen(gw_value) *
2696  3);//x3, big enough for all of the chars to be escaped
2697  uriescape(gw_value, gwescapededstr);
2698  g_free(gw_value);
2699  //g_print("gw_value string after URI escape = %s\n",gwescapededstr->str);
2700  gchar *uri = g_strconcat( urilink, "?partner=", getPartnerID(), "&gw=",
2701  gwescapededstr->str, NULL );
2702  g_string_free(gwescapededstr, TRUE);
2703  GString *xmlescapedstr = g_string_sized_new(strlen(uri) *
2704  2);//x2 should be big enough
2705  xmlescape(uri, xmlescapedstr);
2706  g_free(uri);
2707  //g_print("uri string after XML escape = %s\n",xmlescapedstr->str);
2708  return xmlescapedstr;
2709 }
2710 #endif
2711 
2712 /**
2713  * @brief This function is used to get the hosts IP information from hosts configuration file "/etc/hosts".
2714  *
2715  * @return Returns TRUE if successfully gets the hosts else returns FALSE.
2716  * @ingroup XUPNP_XCALDEV_FUNC
2717  */
2718 gboolean getetchosts(void)
2719 {
2720  GError *error = NULL;
2721  gboolean result = FALSE;
2722  gchar *etchostsfile = NULL;
2723  gchar *hostsFile;
2724  if ( ipv6Enabled == TRUE )
2725  hostsFile = g_strdup("//etc//xi-xconf-hosts.list");
2726  else
2727  hostsFile = g_strdup("//etc//hosts");
2728  result = g_file_get_contents (hostsFile, &etchostsfile, NULL, &error);
2729 
2730  /* Coverity Fix for CID: 125218 : Forward NULL*/
2731  if (result == FALSE) {
2732  g_warning("Problem in reading %s file %s", hostsFile, error ? error->message : "NULL");
2733  } else {
2734  gchar **tokens = g_strsplit_set(etchostsfile, "\n\0", -1);
2735  //etchosts->str = g_strjoinv(";", tokens);
2736  guint toklength = g_strv_length(tokens);
2737  guint loopvar = 0;
2738  if ((toklength > 0) && (strlen(g_strstrip(tokens[0])) > 0) &&
2739  (g_strrstr(g_strstrip(tokens[0]), "127.0.0.1") == NULL)) {
2740  g_string_printf(etchosts, "%s", gwyip->str);
2741  g_string_append_printf(etchosts, "%s", " ");
2742  g_string_append_printf(etchosts, "%s;", g_strstrip(tokens[0]));
2743  } else {
2744  g_string_assign(etchosts, "");
2745  }
2746  for (loopvar = 1; loopvar < toklength; loopvar++) {
2747  //g_print("Token is %s\n",g_strstrip(tokens[loopvar]));
2748  //Do not send localhost 127.0.0.1 mapping
2749  if (g_strrstr(g_strstrip(tokens[loopvar]), "127.0.0.1") == NULL) {
2750  if (strlen(g_strstrip(tokens[loopvar])) > 0) {
2751  g_string_append_printf(etchosts, "%s", gwyip->str);
2752  g_string_append_printf(etchosts, "%s", " ");
2753  g_string_append_printf(etchosts, "%s;", g_strstrip(tokens[loopvar]));
2754  }
2755  }
2756  }
2757  g_strfreev(tokens);
2758  }
2759  //diagid=1000;
2760  //g_print("Etc Hosts contents are %s", etchosts->str);
2761  g_free(hostsFile);
2762  if (error) {
2763  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
2764  g_clear_error(&error);
2765  }
2766  return result;
2767 }
2768 
2769 /**
2770  * @brief This function is used to get the serial number of the device from the vendor specific file.
2771  *
2772  * @param[out] serial_num Manufacturer serial number
2773  *
2774  * @return Returns TRUE if successfully gets the serial number else, returns FALSE.
2775  * @ingroup XUPNP_XCALDEV_FUNC
2776  */
2777 gboolean parseserialnum(GString *serial_num)
2778 {
2779 #ifndef CLIENT_XCAL_SERVER
2780  GError *error = NULL;
2781  gboolean result = FALSE;
2782  gchar *udhcpcvendorfile = NULL;
2783  result = g_file_get_contents ("//etc//udhcpc.vendor_specific",
2784  &udhcpcvendorfile, NULL, &error);
2785  if (result == FALSE) {
2786  g_warning("Problem in reading /etc/udhcpcvendorfile file %s", error->message);
2787  } else {
2788  /* reset result = FALSE to identify serial number from udhcpcvendorfile contents */
2789  result = FALSE;
2790  gchar **tokens = g_strsplit_set(udhcpcvendorfile, " \n\t\b\0", -1);
2791  guint toklength = g_strv_length(tokens);
2792  guint loopvar = 0;
2793  for (loopvar = 0; loopvar < toklength; loopvar++) {
2794  //g_print("Token is %s\n",g_strstrip(tokens[loopvar]));
2795  if (g_strrstr(g_strstrip(tokens[loopvar]), "SUBOPTION4")) {
2796  if ((loopvar + 1) < toklength ) {
2797  g_string_assign(serial_num, g_strstrip(tokens[loopvar + 2]));
2798  }
2799  result = TRUE;
2800  break;
2801  }
2802  }
2803  g_strfreev(tokens);
2804  }
2805  //diagid=1000;
2806  if (error) {
2807  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
2808  g_clear_error(&error);
2809  }
2810  return result;
2811 #else
2812 /* bool bRet;
2813  IARM_Bus_MFRLib_GetSerializedData_Param_t param;
2814  IARM_Result_t iarmRet = IARM_RESULT_IPCCORE_FAIL;
2815  memset(&param, 0, sizeof(param));
2816  param.type = mfrSERIALIZED_TYPE_SERIALNUMBER;
2817  iarmRet = IARM_Bus_Call(IARM_BUS_MFRLIB_NAME,
2818  IARM_BUS_MFRLIB_API_GetSerializedData, &param, sizeof(param));
2819  if (iarmRet == IARM_RESULT_SUCCESS) {
2820  if (param.buffer && param.bufLen) {
2821  g_message( " serialized data %s \n", param.buffer );
2822  g_string_assign(serial_num, param.buffer);
2823  bRet = true;
2824  } else {
2825  g_message( " serialized data is empty \n" );
2826  bRet = false;
2827  }
2828  } else {
2829  bRet = false;
2830  g_message( "IARM CALL failed for mfrtype \n");
2831  }
2832  return bRet;*/
2833 #endif
2834  return TRUE;
2835 }
2836 
2837 /**
2838  * @brief This function is used to get the system Id information from the diagnostic file.
2839  *
2840  * @param[in] diagparam Parameter for which value(system Id) need to be retrieved from the diagnostic file.
2841  * @param[in] diagfilecontents The diagnostic filename
2842  *
2843  * @return Returns value of the system Id.
2844  * @ingroup XUPNP_XCALDEV_FUNC
2845  */
2846 unsigned long getidfromdiagfile(const gchar *diagparam,
2847  const gchar *diagfilecontents)
2848 {
2849  unsigned long diagid = 0;
2850  gchar **tokens = g_strsplit_set(diagfilecontents, ":,{}", -1);
2851  guint toklength = g_strv_length(tokens);
2852  guint loopvar = 0;
2853  for (loopvar = 0; loopvar < toklength; loopvar++) {
2854  if (g_strrstr(g_strstrip(tokens[loopvar]), diagparam)) {
2855  if ((loopvar + 1) < toklength )
2856  diagid = strtoul(tokens[loopvar + 1], NULL, 10);
2857  }
2858  }
2859  g_strfreev(tokens);
2860  return diagid;
2861 }
2862 
2863 /**
2864  * @brief This function is used to get the DNS value from DNS mask configuration file.
2865  *
2866  * @return Returns TRUE if successfully gets the DNS configuration, else returns FALSE.
2867  * @ingroup XUPNP_XCALDEV_FUNC
2868  */
2869 gboolean parsednsconfig(void)
2870 {
2871  GError *error = NULL;
2872  gboolean result = FALSE;
2873  gchar *dnsconfigfile = NULL;
2874  GString *strdnsconfig = g_string_new(NULL);
2875  if (devConf->dnsFile == NULL) {
2876  g_warning("dnsconfig file name not found in config");
2877  return result;
2878  }
2879  result = g_file_get_contents (devConf->dnsFile, &dnsconfigfile, NULL, &error);
2880  /* Coverity Fix for CID: 125036 : Forward NULL */
2881  if (result == FALSE) {
2882  g_warning("Problem in reading dnsconfig file %s", error ? error->message : "NULL");
2883  } else {
2884  gchar **tokens = g_strsplit_set(dnsconfigfile, "\n\0", -1);
2885  //etchosts->str = g_strjoinv(";", tokens);
2886  guint toklength = g_strv_length(tokens);
2887  guint loopvar = 0;
2888  gboolean firsttok = TRUE;
2889  for (loopvar = 0; loopvar < toklength; loopvar++) {
2890  if ((strlen(g_strstrip(tokens[loopvar])) > 0)) {
2891  // g_message("Token is %s\n",g_strstrip(tokens[loopvar]));
2892  if (firsttok == FALSE) {
2893  g_string_append_printf(strdnsconfig, "%s;", g_strstrip(tokens[loopvar]));
2894  } else {
2895  g_string_printf(strdnsconfig, "%s;", g_strstrip(tokens[loopvar]));
2896  firsttok = FALSE;
2897  }
2898  }
2899  }
2900  g_string_assign(dnsconfig, strdnsconfig->str);
2901  g_string_free(strdnsconfig, TRUE);
2902  g_message("DNS Config is %s", dnsconfig->str);
2903  g_strfreev(tokens);
2904  }
2905  if (error) {
2906  /* g_clear_error() frees the GError *error memory and reset pointer if set in above operation */
2907  g_clear_error(&error);
2908  }
2909  return result;
2910 }
2911 
2912 /**
2913  * @brief This function is used to get the mac address of the target device.
2914  *
2915  * @param[in] ifname Name of the network interface.
2916  *
2917  * @return Returns the mac address of the interface given.
2918  * @ingroup XUPNP_XCALDEV_FUNC
2919  */
2920 gchar *getmacaddress(const gchar *ifname)
2921 {
2922  errno_t rc = -1;
2923  int fd;
2924  struct ifreq ifr;
2925  unsigned char *mac;
2926  GString *data = g_string_new(NULL);
2927  fd = socket(AF_INET, SOCK_DGRAM, 0);
2928  ifr.ifr_addr.sa_family = AF_INET;
2929  rc = strcpy_s(ifr.ifr_name,IFNAMSIZ - 1,ifname);
2930  ERR_CHK(rc);
2931  ioctl(fd, SIOCGIFHWADDR, &ifr);
2932  close(fd);
2933  mac = (unsigned char *)ifr.ifr_hwaddr.sa_data;
2934  //display mac address
2935  //g_print("Mac : %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n" , mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
2936  g_string_printf(data, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], mac[1], mac[2],
2937  mac[3], mac[4], mac[5]);
2938  return data->str;
2939 }
2940 
2941 /**
2942  * @brief This function is used to get the IP address based on IPv6 or IPv4 is enabled.
2943  *
2944  * @param[in] ifname Name of the network interface.
2945  * @param[out] ipAddressBuffer Character buffer to hold the IP address.
2946  * @param[in] ipv6Enabled Flag to check whether IPV6 is enabled
2947  *
2948  * @return Returns an integer value '1' if successfully gets the IP address else returns '0'.
2949  * @ingroup XUPNP_XCALDEV_FUNC
2950  */
2951 int getipaddress(const char *ifname, char *ipAddressBuffer,
2952  gboolean ipv6Enabled)
2953 {
2954  struct ifaddrs *ifAddrStruct = NULL;
2955  struct ifaddrs *ifa = NULL;
2956  void *tmpAddrPtr = NULL;
2957  getifaddrs(&ifAddrStruct);
2958  errno_t rc = -1;
2959  int ind = -1;
2960  //char addressBuffer[INET_ADDRSTRLEN] = NULL;
2961  int found = 0;
2962  for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
2963  if (ifa->ifa_addr == NULL) continue;
2964  if (ipv6Enabled == TRUE) {
2965  // check it is IP6
2966  // is a valid IP6 Address
2967  rc = strcmp_s(ifa->ifa_name,strlen(ifa->ifa_name),ifname,&ind);
2968  ERR_CHK(rc);
2969  if(((!ind) && (rc == EOK)) && (ifa ->ifa_addr->sa_family == AF_INET6))
2970  {
2971  tmpAddrPtr = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
2972  inet_ntop(AF_INET6, tmpAddrPtr, ipAddressBuffer, INET6_ADDRSTRLEN);
2973  //if (strcmp(ifa->ifa_name,"eth0")==0trcmp0(g_strstrip(devConf->mocaMacIf),ifname) == 0)
2974  if (((g_strcmp0(g_strstrip(devConf->bcastIf), ifname) == 0)
2975  && (IN6_IS_ADDR_LINKLOCAL(tmpAddrPtr)))
2976  || ((!(IN6_IS_ADDR_LINKLOCAL(tmpAddrPtr)))
2977  && (g_strcmp0(g_strstrip(devConf->hostMacIf), ifname) == 0))) {
2978  found = 1;
2979  break;
2980  }
2981  }
2982  } else {
2983  if (ifa ->ifa_addr->sa_family == AF_INET) { // check it is IP4
2984  // is a valid IP4 Address
2985  tmpAddrPtr = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
2986  inet_ntop(AF_INET, tmpAddrPtr, ipAddressBuffer, INET_ADDRSTRLEN);
2987  //if (strcmp(ifa->ifa_name,"eth0")==0)
2988  rc = strcmp_s(ifa->ifa_name,strlen(ifa->ifa_name),ifname,&ind);
2989  ERR_CHK(rc);
2990  if((!ind) && (rc == EOK))
2991  {
2992  found = 1;
2993  break;
2994  }
2995  }
2996  }
2997  }
2998  if (ifAddrStruct != NULL) freeifaddrs(ifAddrStruct);
2999  return found;
3000 }
gettimezone
gboolean gettimezone(void)
This function is used to get the time zone. It gets the time zone information from the device configu...
Definition: xcal-device-library.c:955
getBcastMacAddress
unsigned char getBcastMacAddress(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:701
getetchosts
gboolean getetchosts(void)
This function is used to get the hosts IP information from hosts configuration file "/etc/hosts".
Definition: xcal-device-library.c:2718
parseipv6prefix
gboolean parseipv6prefix(void)
This function is used to retrieve the IPv6 prefix information from dibblers file.
Definition: xcal-device-library.c:2241
getGatewayIpv6
unsigned char getGatewayIpv6(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:780
parsedevicename
gboolean parsedevicename(void)
This function is used to get the device name from /devicename/devicename file.
Definition: xcal-device-library.c:2192
get_eSTBMAC
GString * get_eSTBMAC(void)
This function is used to get the MAC address of the eSTB. It uses global hostmacaddress GString to ge...
Definition: xcal-device-library.c:2519
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
check_empty
unsigned char check_empty(char *str)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:546
getDeviceType
unsigned char getDeviceType(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:666
parsednsconfig
gboolean parsednsconfig(void)
This function is used to get the DNS value from DNS mask configuration file.
Definition: xcal-device-library.c:2869
getDeviceName
unsigned char getDeviceName(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:633
_STRING_MAP
Definition: xdevice-library-private.h:47
readDevFile
gboolean readDevFile(const char *deviceFile)
This function is used to get partner ID.
Definition: xcal-device-library.c:385
getserialnum
gboolean getserialnum(GString *serial_num)
This function is used to get the serial number of the device from the vendor specific file.
Definition: xcal-device-library.c:227
getIpv6Prefix
unsigned char getIpv6Prefix(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal_device_library.c:1094
getStrValueFromMap
static char * getStrValueFromMap(char *pszKey, int nPairs, STRING_MAP map[])
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal_device_library.c:288
ConfSettings
Definition: xdevice-library-private.h:27
is_num
gboolean is_num(const gchar *str)
Supporting function for checking the content of given string is numeric or not.
Definition: xcal-device-library.c:522
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
getGatewayStbIp
unsigned char getGatewayStbIp(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:747
updatesystemids
gboolean updatesystemids(void)
This function is used to update the system Ids such as channelMapId, controllerId,...
Definition: xcal-device-library.c:2147
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
parseserialnum
gboolean parseserialnum(GString *serial_num)
This function is used to get the serial number of the device from the vendor specific file.
Definition: xcal-device-library.c:2777
getidfromdiagfile
unsigned long getidfromdiagfile(const gchar *diagparam, const gchar *diagfilecontents)
This function is used to get the system Id information from the diagnostic file.
Definition: xcal-device-library.c:2846
getFogTsbUrl
unsigned char getFogTsbUrl(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:600
getID
GString * getID(const gchar *id)
This function is used to get the Receiver Id & Partner Id.
Definition: xcal-device-library.c:2074
TZStruct
Definition: xcal_device_library.c:126
getRecvDevType
unsigned char getRecvDevType(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:848
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
is_alphanum
gboolean is_alphanum(const gchar *str)
Supporting function for checking the given string is alphanumeric.
Definition: xcal-device-library.c:1177
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
getBaseUrl
unsigned char getBaseUrl(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:571
getGatewayIp
unsigned char getGatewayIp(char *outValue)
This function is used to get the IP address based on IPv6 or IPv4 is enabled.
Definition: xcal-device-library.c:813