23 #include <sys/types.h>
24 #include <libsoup/soup.h>
25 #include <sys/socket.h>
26 #include <sys/ioctl.h>
29 #include <netinet/in.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>
37 #include <platform_hal.h>
38 #include "rdk_safeclib.h"
39 #include "secure_wrapper.h"
41 #ifndef INET6_ADDRSTRLEN
42 #define INET6_ADDRSTRLEN 46
46 #define BOOL unsigned char
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
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"
69 #define LINK_LOCAL_ADDR "169.254"
75 #define BOOL unsigned char
90 typedef enum serviceListCb {
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"
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};
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}
132 #define COMCAST_PARTNET_KEY "comcast"
133 #define COX_PARTNET_KEY "cox"
137 #define ARRAY_COUNT(array) (sizeof(array)/sizeof(array[0]))
141 {COMCAST_PARTNET_KEY,
"comcast"},
142 {COX_PARTNET_KEY ,
"cox"},
145 {COMCAST_PARTNET_KEY,
"XFINITY"},
146 {COX_PARTNET_KEY ,
"Contour"},
149 {COMCAST_PARTNET_KEY,
"xfinity"},
150 {COX_PARTNET_KEY ,
"contour"},
153 {COMCAST_PARTNET_KEY,
"Comcast XFINITY Guide"},
154 {COX_PARTNET_KEY ,
"Cox Contour Guide"},
157 {COMCAST_PARTNET_KEY,
"Comcast XFINITY Guide application"},
158 {COX_PARTNET_KEY ,
"Cox Contour Guide application"},
161 {COMCAST_PARTNET_KEY,
"Comcast Gateway"},
162 {COX_PARTNET_KEY ,
"Cox Gateway"},
166 xupnpEventCallback eventCallback;
168 void xupnpEventCallback_register(xupnpEventCallback callback_func)
170 eventCallback=callback_func;
178 if (!syscfg_get(NULL,
"Refactor", temp,
sizeof(temp)) )
182 rc = strcmp_s(
"true",strlen(
"true"),temp,&ind);
184 if((!ind) && (rc == EOK))
186 g_message(
"New Device Refactoring rfc_enabled");
193 g_message(
"check_rfc: Failed Unable to find the RFC parameter");
198 BOOL getAccountId(
char *outValue)
204 rc = syscfg_get(NULL,
"AccountID", temp,
sizeof(temp));
207 if (check_null(outValue))
209 rc1 = strcpy_s(outValue,MAX_OUTVALUE,temp);
222 g_message(
"getAccountId: Unable to get the Account Id");
229 gboolean result = FALSE;
230 if ( platform_hal_PandMDBInit() == 0)
232 g_message(
"getserialnum: hal PandMDB initiated successfully");
233 if ( platform_hal_GetSerialNumber(serial_num->str) == 0)
235 g_message(
"getserialnum: serialNumber from hal:%s", serial_num->str);
240 g_error(
"getserialnum: Unable to get SerialNumber");
245 g_message(
"getserialnum: Failed to initiate hal DB to fetch SerialNumber");
250 const gchar *message, gpointer user_data)
255 g_get_current_time(&timeval);
256 if (logoutfile == NULL)
259 g_print (
" g_time_val_to_iso8601(&timeval): %s\n", message);
263 timestr = g_time_val_to_iso8601(&timeval);
264 g_fprintf (logoutfile,
"%s : %s\n", timestr, message);
277 static char *getPartnerID()
279 return partner_id->str;
283 #ifndef BROADBAND_SUPPORT
295 static char *getPartnerName()
310 static char *getFriendlyName()
325 static char *getProductName()
340 static char *getServiceName()
355 static char *getServiceDescription()
358 serviceDescriptionMap);
370 static char *getGatewayName()
388 gboolean result = FALSE;
389 gchar* devfilebuffer = NULL;
392 if (deviceFile == NULL)
394 g_message(
"device properties file not found");
398 result = g_file_get_contents (deviceFile, &devfilebuffer, NULL, &error);
401 g_message(
"No contents in device properties");
407 gchar **tokens = g_strsplit_set(devfilebuffer,
",='\n'", -1);
408 guint toklength = g_strv_length(tokens);
410 for (loopvar=0; loopvar<toklength; loopvar++)
412 if (g_strrstr(g_strstrip(tokens[loopvar]),
"DEVICE_TYPE"))
414 if ((loopvar+1) < toklength )
417 g_string_assign(recvdevtype, g_strstrip(tokens[loopvar+1]));
425 else if(g_strrstr(g_strstrip(tokens[loopvar]),
"BUILD_VERSION"))
427 if ((loopvar+1) < toklength )
430 g_string_assign(buildversion, g_strstrip(tokens[loopvar+1]));
438 else if(g_strrstr(g_strstrip(tokens[loopvar]),
"BOX_TYPE"))
440 if ((loopvar+1) < toklength )
443 g_string_assign(devicetype, g_strstrip(tokens[loopvar+1]));
451 else if(g_strrstr(g_strstrip(tokens[loopvar]),
"MODEL_NUM"))
453 if ((loopvar+1) < toklength )
456 g_string_assign(devicename, g_strstrip(tokens[loopvar+1]));
464 if (g_strrstr(g_strstrip(tokens[loopvar]),
"MFG_NAME"))
466 if ((loopvar+1) < toklength )
469 g_string_assign(make, g_strstrip(tokens[loopvar+1]));
479 if (g_strrstr(g_strstrip(tokens[loopvar]),
"MANUFACTURE"))
481 if ((loopvar+1) < toklength )
484 g_string_assign(make, g_strstrip(tokens[loopvar+1]));
497 g_string_printf(mocaIface,
"%s",ISOLATION_IF);
498 g_string_printf(wifiIface,
"%s",WIFI_IF);
501 g_message(
"RECEIVER_DEVICETYPE and BUILD_VERSION not found in %s",deviceFile);
507 g_clear_error(&error);
526 gboolean isnum =
TRUE;
527 for (i = 0; i < strlen(str); i++) {
528 if (!g_ascii_isdigit(str[i])) {
554 BOOL check_null(
char *str)
574 if ((!check_null((
char *)gwyip)) || (!check_null(outValue)) || (!check_null((
char *)recv_id))) {
575 g_message(
"getBaseUrl : NULL string !");
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);
586 g_message(
"getBaseUrl : Empty url");
604 if (!check_null(outValue)) {
605 g_message(
"getFogTsbUrl : NULL string !");
608 if (fogtsburl->str) {
609 rc = strcpy_s(outValue,MAX_OUTVALUE,fogtsburl->str);
619 g_message(
"getFogTsbUrl : No fogtsb url !");
637 if (!check_null(outValue)) {
638 g_message(
"getDeviceName : NULL string !");
641 if(devicename->str != NULL) {
642 rc = strcpy_s(outValue,MAX_OUTVALUE,devicename->str);
652 g_message(
"getDeviceName : No Device Name !");
670 if ((!check_null((
char *)devicetype)) || (!check_null(outValue))) {
671 g_message(
"getDeviceType : NULL string !");
675 rc = strcpy_s(outValue,MAX_OUTVALUE,devicetype->str);
687 g_message(
"getDeviceType : Empty device type");
705 if (!check_null(outValue)) {
706 g_message(
"getBcastMacAddress : NULL string !");
709 if (devConf->bcastIf != NULL ) {
710 const gchar *bcastmac = (gchar *)
getmacaddress(devConf->bcastIf);
712 g_message(
"Broadcast MAC address in interface: %s %s ", devConf->bcastIf,
715 g_message(
"failed to retrieve macaddress on interface %s ", devConf->bcastIf);
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);
732 g_message(
"getBcastMacAddress : Empty broadcast interface");
750 if ((!check_null((
char *)gwystbip)) || (!check_null(outValue))) {
751 g_message(
"getGatewayStbIp : NULL string !");
754 #ifndef CLIENT_XCAL_SERVER
757 rc = strcpy_s(outValue,MAX_OUTVALUE,gwystbip->str);
783 if ((!check_null((
char *)gwyipv6)) || (!check_null(outValue))) {
784 g_message(
"getGatewayIpv6 : NULL string !");
787 #ifndef CLIENT_XCAL_SERVER
790 rc = strcpy_s(outValue,MAX_OUTVALUE,gwyipv6->str);
817 if ((!check_null((
char *)gwyip)) || (!check_null(outValue))) {
818 g_message(
"getGatewayIp : NULL string !");
822 rc = strcpy_s(outValue,MAX_OUTVALUE,gwyip->str);
834 g_message(
"getGatewayIp : Empty gateway ip");
852 if ((!check_null((
char *)recvdevtype)) || (!check_null(outValue))) {
853 g_message(
"getRecvDevType : NULL string !");
857 rc = strcpy_s(outValue,MAX_OUTVALUE,recvdevtype->str);
869 g_message(
"getRecvDevType : Empty receiver device type");
873 BOOL getBuildVersion(
char *outValue)
877 if ((!check_null((
char *)buildversion)) || (!check_null(outValue))) {
878 g_message(
"getBuildVersion : NULL string !");
882 rc = strcpy_s(outValue,MAX_OUTVALUE,buildversion->str);
894 g_message(
"getBuildVersion : Empty Build version");
898 BOOL getHostMacAddress(
char *outValue)
901 if (!(check_null((
char *)hostmacaddress)) || (!check_null(outValue))) {
902 g_message(
"getHostMacAddress : NULL string !");
905 #ifndef CLIENT_XCAL_SERVER
907 if (devConf->hostMacIf != NULL) {
908 const gchar *hostmac = (gchar *)
getmacaddress(devConf->hostMacIf);
910 g_message(
"MAC address in interface: %s %s ", devConf->hostMacIf, hostmac);
912 g_message(
"failed to retrieve macaddress on interface %s ",
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);
930 BOOL getSystemsIds(
char *outValue)
934 if ((!check_null((
char *)systemids)) || (!check_null(outValue))) {
935 g_message(
"getSystemsIds : NULL string !");
939 rc = strcpy_s(outValue,MAX_OUTVALUE,systemids->str);
951 g_message(
"getSystemsIds : empty system ids");
958 gboolean result = FALSE;
959 gchar* dsgproxyfile = NULL;
961 if (devConf->dsgFile == NULL)
963 g_warning(
"dsg file name not found in config");
966 result = g_file_get_contents (devConf->dsgFile, &dsgproxyfile, NULL, &error);
969 if (result == FALSE) {
971 g_warning(
"Problem in reading dsgproxyfile file %s",
972 error ? error->message :
"NULL");
979 gchar **tokens = g_strsplit_set(dsgproxyfile,
",=", -1);
980 guint toklength = g_strv_length(tokens);
982 for (loopvar=0; loopvar<toklength; loopvar++)
985 if (g_strrstr(g_strstrip(tokens[loopvar]),
"DSGPROXY_HOST_TIME_ZONE"))
987 if ((loopvar+1) < toklength )
989 g_string_assign(dsgtimezone, g_strstrip(tokens[loopvar+1]));
1002 g_clear_error(&error);
1008 BOOL getIpSubnet(
char *outValue)
1010 BOOL result = FALSE;
1012 if (!check_null(outValue)) {
1013 g_message(
"getIpSubnet : NULL string !");
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}'")))
1023 while(fgets(outValue,
sizeof(MAX_OUTVALUE), fp)!=NULL)
1025 size_t len = strlen(outValue);
1026 if (len > 0 && outValue[len-1] ==
'\n') {
1027 outValue[len-1] =
'\0';
1031 ret = v_secure_pclose(fp);
1034 g_message(
"Error in closing pipe ! : %d \n", ret);
1042 BOOL getTimeZone(
char *outValue)
1044 BOOL result = FALSE;
1046 if ((!check_null((
char *)dsgtimezone)) || (!check_null(outValue))) {
1047 g_message(
"getTimeZone : NULL string !");
1051 rc = strcpy_s(outValue,MAX_OUTVALUE, dsgtimezone->str);
1063 g_message(
"getTimeZone : Empty timezone");
1067 BOOL getRawOffSet(
int *outValue)
1069 *outValue = rawOffset;
1072 BOOL getDstSavings(
int *outValue)
1074 *outValue = dstSavings;
1077 BOOL getUsesDayLightTime(BOOL *outValue)
1079 *outValue = usesDaylightTime;
1082 BOOL getIsGateway(BOOL *outValue)
1084 *outValue = devConf->allowGwy;
1087 BOOL getHosts(
char *outValue)
1089 BOOL result = FALSE;
1091 if (!check_null(outValue)) {
1092 g_message(
"getHosts : NULL string !");
1096 rc = strcpy_s(outValue,RUIURLSIZE,etchosts->str);
1106 g_message(
"getHosts : No Hosts Data available !");
1110 BOOL getRequiresTRM(BOOL *outValue)
1112 *outValue = requirestrm;
1115 BOOL getBcastPort(
int *outValue)
1117 *outValue = devConf->bcastPort;
1120 BOOL getBcastIp(
char *outValue)
1122 BOOL result = FALSE;
1124 if ((!check_null((
char *)gwyip)) || (!check_null(outValue))) {
1125 g_message(
"getBcastIp : NULL string !");
1129 rc = strcpy_s(outValue,MAX_OUTVALUE,gwyip->str);
1141 g_message(
"getBcastIp : Empty Broadcast Ip");
1145 BOOL getBcastIf(
char *outValue)
1147 BOOL result = FALSE;
1149 if (!check_null(outValue)) {
1150 g_message(
"getBcastIf : NULL string !");
1154 rc = strcpy_s(outValue, MAXSIZE, devConf->bcastIf);
1165 g_message(
"getBcastIf : No Bcast Interface found !");
1180 gboolean isalphanum =
TRUE;
1181 for (i = 0; i < strlen(str); i++) {
1182 if (!g_ascii_isalnum(str[i])) {
1190 BOOL getRUIUrl(
char *outValue)
1194 BOOL getSerialNum(
char *outValue)
1196 BOOL result = FALSE;
1198 if (!check_null(outValue)) {
1199 g_message(
"getSerialNum : NULL string !");
1203 rc = strcpy_s(outValue,MAX_OUTVALUE,serial_num->str);
1213 g_message(
"getSerialNum : No Serial Number Available !");
1217 BOOL getPartnerId(
char *outValue)
1219 BOOL result = FALSE;
1221 if (!check_null(outValue)) {
1222 g_message(
"getPartnerId : NULL string !");
1225 if (check_null((
char *)partner_id) &&
check_empty(partner_id->str)) {
1226 rc = strcpy_s(outValue,MAX_OUTVALUE,partner_id->str);
1238 g_message(
"getPartnerId : No partnerId available");
1243 BOOL getDevKeyPath(
char *outValue)
1245 BOOL result = FALSE;
1246 if ((!check_null(devConf->devKeyPath)) || (!check_null(outValue))) {
1247 g_message(
"getDevKeyPath: NULL string !");
1251 strncpy(outValue,devConf->devKeyPath, MAX_FILE_LENGTH);
1254 g_message(
"getDevKeyPath : config has empty key path !");
1258 BOOL getDevKeyFile(
char *outValue)
1260 BOOL result = FALSE;
1261 if ((!check_null(devConf->devKeyFile)) || (!check_null(outValue))) {
1262 g_message(
"getDevKeyFile : NULL string !");
1266 strncpy(outValue,devConf->devKeyFile, MAX_FILE_LENGTH);
1269 g_message(
"getDevKeyFile : config has empty key file !");
1273 BOOL getDevCertPath(
char *outValue)
1275 BOOL result = FALSE;
1276 if ((!check_null(devConf->devCertPath)) || (!check_null(outValue))) {
1277 g_message(
"getDevCertPath: NULL string !");
1281 strncpy(outValue,devConf->devCertPath, MAX_FILE_LENGTH);
1284 g_message(
"getDevCertPath: config has empty path!");
1289 BOOL getDevCertFile(
char *outValue)
1291 BOOL result = FALSE;
1292 if ((!check_null(devConf->devCertFile)) || (!check_null(outValue))) {
1293 g_message(
"getDevCertFile: NULL string !");
1297 strncpy(outValue,devConf->devCertFile, MAX_FILE_LENGTH);
1300 g_message(
"getDevCertFile: config has empty file !");
1304 BOOL getUidfromRecvId()
1306 BOOL result = FALSE;
1308 gchar **tokens = g_strsplit_set(eroutermacaddress->str,
"':''\n'", -1);
1309 guint toklength = g_strv_length(tokens);
1310 while (loopvar < toklength)
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);
1320 BOOL getUUID(
char *outValue)
1322 BOOL result = FALSE;
1323 if (!check_null(outValue)) {
1324 g_message(
"getUUID : NULL string !");
1327 if (getUidfromRecvId()){
1329 sprintf(outValue,
"uuid:%s", recv_id->str);
1334 g_message(
"getUUID : empty recvId");
1339 g_message(
"getUUID : could not get UUID");
1344 BOOL getReceiverId(
char *outValue)
1346 BOOL result = FALSE;
1348 if (!check_null(outValue)) {
1349 g_message(
"getReceiverId : NULL string !");
1352 if(getUidfromRecvId())
1354 if (check_null((
char *)recv_id) &&
check_empty(recv_id->str)) {
1355 rc = strcpy_s(outValue,MAX_OUTVALUE,recv_id->str);
1367 g_message(
"getReceiverId : empty recvId");
1372 g_message(
"getUUID : could not get UUID");
1376 BOOL getTrmUrl(
char *outValue)
1378 BOOL result = FALSE;
1380 if (!check_null(outValue)) {
1381 g_message(
"getTrmUrl : NULL string !");
1385 rc = strcpy_s(outValue,MAX_OUTVALUE,trmurl->str);
1395 g_message(
"getTrmUrl : No trmurl found");
1403 BOOL getPlaybackUrl(
char *outValue)
1405 BOOL result = FALSE;
1407 if (!check_null(playbackurl->str)){
1408 g_message(
"getPlaybackUrl: NULL string !");
1413 rc = strcpy_s(outValue,URLSIZE, playbackurl->str);
1425 g_message(
"getPlaybackUrl: Empty plabackurl");
1429 BOOL getVideoBasedUrl(
char *outValue)
1431 BOOL result = FALSE;
1433 if (!check_null(outValue)) {
1434 g_message(
"getVideoBasedUrl : NULL string !");
1438 rc = strcpy_s(outValue,MAX_OUTVALUE, videobaseurl->str);
1448 g_message(
"getVideoBasedUrl : No VideoBasedUrl found");
1452 BOOL getIsuseGliDiagEnabled()
1454 return devConf->useGliDiag;
1456 BOOL getDstOffset(
int *outValue)
1458 *outValue = dstOffset;
1461 BOOL getDisableTuneReadyStatus()
1463 return devConf->disableTuneReady;
1466 #ifndef CLIENT_XCAL_SERVER
1467 BOOL getCVPIp(
char *outValue)
1470 if (!check_null(outValue)) {
1471 g_message(
"getCVPIp : NULL string !");
1474 ipAddressBuffer[0] =
'\0';
1475 int result =
getipaddress(devConf->cvpIf, ipAddressBuffer, FALSE);
1477 fprintf(stderr,
"Could not locate the ipaddress of CVP2 interface %s\n",
1481 g_message(
"ipaddress of the CVP2 interface %s", ipAddressBuffer);
1482 rc = strcpy_s(outValue,MAX_OUTVALUE,ipAddressBuffer);
1493 BOOL getCVPIf(
char *outValue)
1495 BOOL result = FALSE;
1497 if (!check_null(outValue)) {
1498 g_message(
"getCVPIf : NULL string !");
1502 rc = strcpy_s(outValue, MAXSIZE, devConf->cvpIf);
1514 g_message(
"getCVPIf : Failed to get the CVP Interface");
1518 BOOL getCVPPort(
int *outValue)
1520 BOOL result = FALSE;
1521 if (!check_null(outValue)) {
1522 g_message(
"getCVPPort : NULL string !");
1527 *outValue = devConf->cvpPort;
1532 BOOL getCVPXmlFile(
char *outValue)
1534 BOOL result = FALSE;
1536 if (!check_null(outValue)) {
1537 g_message(
"getCVPXmlFile : NULL string !");
1541 rc = strcpy_s(outValue, MAXSIZE, devConf->cvpXmlFile);
1553 g_message(
"getCVPXmlFile : Failed to get the CVP XmlFile");
1559 BOOL getRouteDataGateway(
char *outValue)
1561 BOOL result = FALSE;
1563 if (!check_null(outValue)) {
1564 g_message(
"getRouteDataGateway : NULL string !");
1568 rc = strcpy_s(outValue,MAX_OUTVALUE,dataGatewayIPaddress->str);
1578 g_message(
"getRouteDataGateway : error getting route data!");
1581 BOOL getLogFile(
char *outValue)
1583 BOOL result = FALSE;
1585 if (!check_null(outValue)) {
1586 g_message(
"getLogFile : NULL string !");
1590 rc = strcpy_s(outValue,MAX_OUTVALUE,devConf->logFile);
1600 g_message(
"getLogFile : Config doesnt have a log file !");
1603 BOOL getEstbMacAddr(
char *outValue)
1605 BOOL result = FALSE;
1606 #ifndef CLIENT_XCAL_SERVER
1608 if ((!check_null(devConf->hostMacIf)) || (!check_null(outValue))) {
1609 g_message(
"getEstbMacAddr : NULL string !");
1613 const gchar *hostmac = (gchar *)
getmacaddress(devConf->hostMacIf);
1615 g_message(
"MAC address in interface: %s %s ", devConf->hostMacIf, hostmac);
1616 g_string_assign(hostmacaddress,hostmac);
1619 g_message(
"failed to retrieve macaddress on interface %s ",
1620 devConf->hostMacIf);
1624 rc = strcpy_s(outValue,MAX_OUTVALUE, hostmacaddress->str);
1633 g_message(
"Host mac address is %s", hostmacaddress->str);
1637 BOOL getDevXmlPath(
char *outValue)
1639 BOOL result = FALSE;
1641 if ((!check_null(devConf->devXmlPath)) || (!check_null(outValue))) {
1642 g_message(
"getDevXmlPath : NULL string !");
1646 rc = strcpy_s(outValue,MAX_OUTVALUE,devConf->devXmlPath);
1656 g_message(
"getDevXmlPath : config has empty xml path !");
1660 BOOL getDevXmlFile(
char *outValue,
int refactor)
1662 BOOL result = FALSE;
1663 if ((!check_null(devConf->devXmlFile)) || (!check_null(outValue))) {
1664 g_message(
"getDevXmlFile : NULL string !");
1670 sprintf(outValue,
"%s/%s", devConf->devXmlPath, devConf->devXmlFile);
1673 g_message(
"getDevXmlFile : config has empty xml file !");
1677 sprintf(outValue,
"%s/%s", devConf->devXmlPath,BROADBAND_DEVICE_XML_FILE);
1678 g_message(
"getDevXmlFile : refactor = %s",outValue);
1684 BOOL checkCVP2Enabled()
1686 return devConf->enableCVP2;
1689 BOOL getModelNumber(
char *outValue)
1691 BOOL result = FALSE;
1693 if ((!check_null(devicename->str)) || (!check_null(outValue))) {
1694 g_message(
"getModelNumber : NULL string !");
1698 rc = strcpy_s(outValue,MAX_OUTVALUE,devicename->str);
1708 g_message(
"getModelNumber : config has empty modelnumber file !");
1712 BOOL getMake(
char *outValue)
1714 BOOL result = FALSE;
1716 if ((!check_null(make->str)) || (!check_null(outValue))) {
1717 g_message(
"getMake : NULL string !");
1721 rc = strcpy_s(outValue,MAX_OUTVALUE,make->str);
1731 g_message(
"getMake : config has empty device make file !");
1735 BOOL xdeviceInit(
char *devConfFile,
char *devLogFile)
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;
1757 requirestrm = FALSE;
1758 service_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);
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");
1783 #ifndef CLIENT_XCAL_SERVER
1786 g_message(
"readconffile returned FALSE");
1793 #ifdef CLIENT_XCAL_SERVER
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;
1819 if (check_null(devLogFile)) {
1820 logoutfile = g_fopen (devLogFile,
"a");
1822 else if (devConf->logFile) {
1823 logoutfile = g_fopen (devConf->logFile,
"a");
1826 g_message(
"xupnp not handling the logging");
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,
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,
1836 g_message(
"Starting xdevice service");
1837 if (devConf->devPropertyFile != NULL) {
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,
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,
1850 int loop,result,assigned=0;
1851 for(loop=0;loop<10;loop++)
1853 #ifndef CLIENT_XCAL_SERVER
1854 if ( access(devConf->ipv6FileLocation, F_OK ) != -1 )
1858 "In Ipv6 Could not locate the link local ipv6 address of the broadcast interface %s\n",
1860 g_critical(
"In Ipv6 Could not locate the link local ipv6 address of the broadcast interface %s\n",
1865 g_message(
"ipaddress of the interface %s", ipAddressBuffer);
1867 g_string_assign(gwyipv6, ipAddressBuffer);
1868 ipAddressBuffer[0] =
'\0';
1869 result =
getipaddress(devConf->bcastIf, ipAddressBuffer, FALSE);
1872 "Could not locate the link local v4 ipaddress of the broadcast interface %s\n",
1874 g_critical(
"Could not locate the link local v4 ipaddress of the broadcast interface %s\n",
1878 g_message(
"ipaddress of the interface %s", ipAddressBuffer);
1882 ipAddressBuffer[0] =
'\0';
1883 result =
getipaddress(mocaIface->str, ipAddressBuffer, FALSE);
1885 g_message(
"Could not locate the ipaddress of the broadcast moca isolation interface %s",
1887 result =
getipaddress(wifiIface->str, ipAddressBuffer, FALSE);
1889 g_message(
"Could not locate the ipaddress of the wifi broadcast interface %s",
1891 g_critical(
"Could not locate the link local v4 ipaddress of the broadcast interface %s\n",
1894 devConf->bcastIf = g_strdup(wifiIface->str);
1895 g_message(
"ipaddress of the interface %s", ipAddressBuffer);
1900 devConf->bcastIf = g_strdup(mocaIface->str);
1901 g_message(
"ipaddress of the interface %s", ipAddressBuffer);
1909 g_message(
"Starting xdevice service on interface %s ipAddressBuffer= %s", devConf->bcastIf,ipAddressBuffer);
1912 g_message(
"waited 10 seconds for interface to come up so giving up");
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);
1919 #if defined(USE_XUPNP_IARM_BUS)
1920 gboolean iarminit = XUPnP_IARM_Init();
1921 if (iarminit ==
true) {
1923 g_message(
"XUPNP IARM init success");
1924 #ifndef CLIENT_XCAL_SERVER
1929 g_critical(
"XUPNP IARM init failed");
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);
1936 g_message(
"MAC address in interface: %s %s \n", devConf->hostMacIf, hostmac);
1938 g_message(
"failed to retrieve macaddress on interface %s ",
1939 devConf->hostMacIf);
1941 g_string_assign(hostmacaddress, hostmac);
1942 g_message(
"Host mac address is %s", hostmacaddress->str);
1945 if (devConf->bcastIf != NULL ) {
1946 const gchar *bcastmac = (gchar *)
getmacaddress(devConf->bcastIf);
1948 g_message(
"Broadcast MAC address in interface: %s %s ", devConf->bcastIf,
1951 g_message(
"failed to retrieve macaddress on interface %s ", devConf->bcastIf);
1953 g_string_assign(bcastmacaddress, bcastmac);
1954 g_message(
"bcast mac address is %s", bcastmacaddress->str);
1959 g_message(
"Erouter0 MAC address in interface: %s %s",UDN_IF,
1964 g_message(
"failed to retrieve macaddress on interface %s ", devConf->bcastIf);
1966 g_string_assign(eroutermacaddress,eroutermac);
1967 g_message(
"erouter0 mac address is %s",eroutermacaddress->str);
1968 if(devicename->str != NULL)
1970 g_message(
"Device Name : %s ", devicename->str);
1974 g_message(
" ERROR in getting Device Name ");
1976 #ifndef CLIENT_XCAL_SERVER
1977 if (devConf->enableTRM == FALSE) {
1978 requirestrm = FALSE;
1979 g_string_printf(trmurl, NULL);
1982 g_string_printf(trmurl,
"ws://%s:9988", ipAddressBuffer);
1985 if (devConf->allowGwy == FALSE) {
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);
1996 g_message(
"System ids are %s", systemids->str);
1998 g_warning(
"Error in finding system ids\n");
2000 #if defined(USE_XUPNP_IARM_BUS)
2001 if ((strlen(g_strstrip(serial_num->str)) < 6)
2003 g_message(
"Serial Number not yet received.\n");
2005 g_message(
"Received Serial Number:%s", serial_num->str);
2008 g_message(
"Serial Number is %s", serial_num->str);
2013 g_message(
"Serial Number is %s", serial_num->str);
2017 #ifndef CLIENT_XCAL_SERVER
2019 g_message(
"EtcHosts Content is %s", etchosts->str);
2021 g_message(
"Error in getting etc hosts");
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");
2032 g_message(
"Tune Ready check is disabled - Setting tune_ready to TRUE");
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.");
2041 g_message(
" V6 prefix is not yet updated in file %s ",
2042 devConf->ipv6PrefixFile);
2044 g_message(
"IPv6 prefix : %s ", ipv6prefix->str);
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);
2049 if (devConf->hostMacIf != NULL) {
2050 result =
getipaddress(devConf->hostMacIf, stbipAddressBuffer, ipv6Enabled);
2052 g_message(
"Could not locate the ipaddress of the host mac interface %s\n",
2053 devConf->hostMacIf);
2055 g_message(
"ipaddress of the interface %s\n", stbipAddressBuffer);
2056 g_string_assign(gwystbip, stbipAddressBuffer);
2076 gboolean isDevIdPresent = FALSE;
2079 GString *jsonData = g_string_new(NULL);
2080 GString *value = g_string_new(NULL);
2083 if((fp = v_secure_popen(
"r", GET_DEVICEID_SCRIPT)))
2085 char response[1024] = {0};
2086 fread(response, 1,
sizeof(response)-1, fp);
2087 int ret = v_secure_pclose(fp);
2089 g_message(
"Error in closing pipe ! : %d \n", ret);
2091 if ((response[0] ==
'\0') && (counter < MAX_DEBUG_MESSAGE)) {
2093 g_message(
"No Json string found in Auth url %s \n" ,
2096 g_string_assign(jsonData, response);
2097 gchar **tokens = g_strsplit_set(jsonData->str,
"{}:,\"", -1);
2098 guint tokLength = g_strv_length(tokens);
2100 for (loopvar = 0; loopvar < tokLength; loopvar++) {
2101 if (g_strrstr(g_strstrip(tokens[loopvar]),
id)) {
2103 if ((loopvar + 3) < tokLength ) {
2104 g_string_assign(value, g_strstrip(tokens[loopvar + 3]));
2105 if (value->str[0] !=
'\0') {
2106 isDevIdPresent =
TRUE;
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);
2117 if (counter < MAX_DEBUG_MESSAGE ) {
2119 g_message(
"%s not found in Json string in Auth url %s \n ",
id, jsonData->str);
2122 g_message(
"Successfully fetched %s %s \n ",
id, value->str);
2133 g_message(
"The deviceId script %s can't be executed\n", GET_DEVICEID_SCRIPT);
2136 g_string_free(jsonData,
TRUE);
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);
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");
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");
2170 g_string_printf(systemids,
"channelMapId:%lu;", diagid);
2172 g_string_append_printf(systemids,
"controllerId:%lu;", diagid);
2174 g_string_append_printf(systemids,
"plantId:%lu;", diagid);
2176 g_string_append_printf(systemids,
"vodServerId:%lu", diagid);
2180 g_clear_error(&error);
2194 GError *error = NULL;
2195 gboolean result = FALSE;
2196 gchar *devicenamefile = NULL;
2198 gboolean devicenamematch = FALSE;
2199 if (devConf->deviceNameFile == NULL) {
2200 g_warning(
"device name file name not found in config");
2203 result = g_file_get_contents (devConf->deviceNameFile, &devicenamefile, NULL,
2207 if (result == FALSE) {
2208 g_warning(
"Problem in reading /devicename/devicename file %s", error ? error->message :
"NULL");
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")) {
2215 g_string_printf(devicename,
"%s", g_strstrip(tokens[loopvar + 1]));
2216 g_message(
"device name = %s", devicename->str);
2217 devicenamematch =
TRUE;
2223 if (devicenamematch == FALSE) {
2224 g_message(
"No Matching devicename in file %s", devicenamefile);
2229 g_clear_error(&error);
2231 g_free(devicenamefile);
2243 GError *error = NULL;
2244 gboolean result = FALSE;
2245 gchar *prefixfile = NULL;
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");
2255 result = g_file_get_contents (devConf->ipv6PrefixFile, &prefixfile, NULL,
2258 if (result == FALSE) {
2259 g_warning(
"Problem in reading /prefix/prefix file %s", error ? error->message :
"NULL");
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))) {
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")) {
2277 g_string_printf(ipv6prefix,
"%s", prefixtokens[prefixloopvar - 1]);
2278 g_message(
"ipv6 prefix format in the file %s",
2279 prefixtokens[prefixloopvar - 1]);
2284 g_strfreev(prefixtokens);
2286 if (prefixmatch ==
TRUE)
2292 if (prefixmatch == FALSE) {
2294 g_message(
"No Matching ipv6 prefix in file %s", prefixfile);
2299 g_clear_error(&error);
2309 #define VIDIPATH_FLAG "/opt/vidiPathEnabled"
2311 #ifndef CLIENT_XCAL_SERVER
2312 static int isVidiPathEnabled()
2314 if (access(VIDIPATH_FLAG, F_OK) == 0)
2330 GKeyFile *keyfile = NULL;
2331 GKeyFileFlags flags;
2332 GError *error = NULL;
2334 keyfile = g_key_file_new ();
2335 flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
2337 if (!g_key_file_load_from_file (keyfile, configfile, flags, &error)) {
2339 g_error (
"%s\n", error->message);
2341 g_clear_error(&error);
2344 g_key_file_free(keyfile);
2364 devConf->bcastIf = g_key_file_get_string (keyfile,
"Network",
2366 devConf->bcastPort = g_key_file_get_integer (keyfile,
"Network",
2368 #ifndef CLIENT_XCAL_SERVER
2369 devConf->streamIf = g_key_file_get_string (keyfile,
"Network",
2371 devConf->trmIf = g_key_file_get_string (keyfile,
"Network",
2373 devConf->gwIf = g_key_file_get_string (keyfile,
"Network",
"GwIf",
2375 devConf->cvpIf = g_key_file_get_string (keyfile,
"Network",
2377 devConf->cvpPort = g_key_file_get_integer (keyfile,
"Network",
2379 devConf->hostMacIf = g_key_file_get_string (keyfile,
"Network",
2401 #ifndef CLIENT_XCAL_SERVER
2402 devConf->oemFile = g_key_file_get_string (keyfile,
"DataFiles",
2404 devConf->dnsFile = g_key_file_get_string (keyfile,
"DataFiles",
2406 devConf->dsgFile = g_key_file_get_string (keyfile,
"DataFiles",
2408 devConf->diagFile = g_key_file_get_string (keyfile,
"DataFiles",
2410 devConf->wbFile = g_key_file_get_string (keyfile,
"DataFiles",
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",
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);
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);
2450 devConf->useIARM = g_key_file_get_boolean (keyfile,
"Flags",
2452 devConf->allowGwy = g_key_file_get_boolean (keyfile,
"Flags",
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 ) {
2458 devConf->uriOverride = g_key_file_get_string (keyfile,
"Rui",
"uriOverride",
2461 devConf->uriOverride = NULL;
2463 devConf->enableTRM = g_key_file_get_boolean (keyfile,
"Flags",
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);
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");
2492 static void initIpAddressBufferCVP2(
char *ipAddressBufferCVP2)
2494 int result =
getipaddress(devConf->cvpIf, ipAddressBufferCVP2, FALSE);
2498 fprintf(stderr,
"Could not locate the ipaddress of CVP2 interface %s\n", devConf->cvpIf);
2501 g_message(
"ipaddress of the CVP2 interface %s\n", ipAddressBufferCVP2);
2502 g_string_assign(gwyipCVP2, ipAddressBufferCVP2);
2521 if (hostmacaddress != NULL && hostmacaddress->len == 17)
2523 GString* addr = g_string_new(NULL);
2526 for (i = 0; i < hostmacaddress->len; ++i)
2528 if (i != 2 && i != 5 && i != 8 && i != 11 && i != 14 )
2530 addr = g_string_append_c(addr,(hostmacaddress->str)[i]);
2533 return g_string_ascii_up(addr);
2542 static void xmlescape(gchar *instr, GString *outstr)
2544 for (; *instr; instr++)
2549 g_string_append_printf(outstr,
"%s",
"&");
2552 g_string_append_printf(outstr,
"%s",
"&guot;");
2555 g_string_append_printf(outstr,
"%s",
"'");
2558 g_string_append_printf(outstr,
"%s",
"<");
2561 g_string_append_printf(outstr,
"%s",
">");
2564 g_string_append_printf(outstr,
"%c",*instr);
2574 static void uriescape(
unsigned char *instr, GString *outstr)
2577 char unreserved[256] = {0};
2579 for (i = 0; i < 256; ++i)
2581 unreserved[i] = isalnum(i) || i ==
'-' || i ==
'_' || i ==
'.' || i ==
'!' || i ==
'~'
2582 || i ==
'*' || i ==
'\'' || i ==
'(' || i ==
')'
2586 for (; *instr; instr++)
2588 if (unreserved[*instr])
2589 g_string_append_printf(outstr,
"%c",*instr);
2591 g_string_append_printf(outstr,
"%%%02X",*instr);
2599 static GString *get_uri_value()
2605 g_get_current_time(&timeval);
2606 double t = timeval.tv_sec + (timeval.tv_usec /
2609 snprintf(udnvalue, 25,
"%s%f",
"CVP-", t);
2611 char ipAddressBufferCVP2[INET6_ADDRSTRLEN];
2612 initIpAddressBufferCVP2(ipAddressBufferCVP2);
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);
2620 if (devConf->uriOverride != NULL)
2621 urilink = devConf->uriOverride;
2623 urilink =
"http://syndeo.xcal.tv/app/x2rui/rui.html";
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);
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);
2647 if (controllerId == NULL)
2648 controllerId = g_string_new(
"0");
2649 GString *plantId = NULL;
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);
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);
2667 if (vodServerId == NULL)
2668 vodServerId = g_string_new(
"0");
2670 if (eSTBMAC == NULL) {
2671 eSTBMAC = g_string_new(
"UNKNOWN");
2673 gchar *gw_value = g_strconcat(
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,
"\""
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);
2695 GString *gwescapededstr = g_string_sized_new(strlen(gw_value) *
2697 uriescape(gw_value, gwescapededstr);
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) *
2705 xmlescape(uri, xmlescapedstr);
2708 return xmlescapedstr;
2720 GError *error = NULL;
2721 gboolean result = FALSE;
2722 gchar *etchostsfile = NULL;
2724 if ( ipv6Enabled ==
TRUE )
2725 hostsFile = g_strdup(
"//etc//xi-xconf-hosts.list");
2727 hostsFile = g_strdup(
"//etc//hosts");
2728 result = g_file_get_contents (hostsFile, &etchostsfile, NULL, &error);
2731 if (result == FALSE) {
2732 g_warning(
"Problem in reading %s file %s", hostsFile, error ? error->message :
"NULL");
2734 gchar **tokens = g_strsplit_set(etchostsfile,
"\n\0", -1);
2736 guint toklength = g_strv_length(tokens);
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]));
2744 g_string_assign(etchosts,
"");
2746 for (loopvar = 1; loopvar < toklength; loopvar++) {
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]));
2764 g_clear_error(&error);
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);
2790 gchar **tokens = g_strsplit_set(udhcpcvendorfile,
" \n\t\b\0", -1);
2791 guint toklength = g_strv_length(tokens);
2793 for (loopvar = 0; loopvar < toklength; 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]));
2808 g_clear_error(&error);
2847 const gchar *diagfilecontents)
2849 unsigned long diagid = 0;
2850 gchar **tokens = g_strsplit_set(diagfilecontents,
":,{}", -1);
2851 guint toklength = g_strv_length(tokens);
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);
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");
2879 result = g_file_get_contents (devConf->dnsFile, &dnsconfigfile, NULL, &error);
2881 if (result == FALSE) {
2882 g_warning(
"Problem in reading dnsconfig file %s", error ? error->message :
"NULL");
2884 gchar **tokens = g_strsplit_set(dnsconfigfile,
"\n\0", -1);
2886 guint toklength = g_strv_length(tokens);
2888 gboolean firsttok =
TRUE;
2889 for (loopvar = 0; loopvar < toklength; loopvar++) {
2890 if ((strlen(g_strstrip(tokens[loopvar])) > 0)) {
2892 if (firsttok == FALSE) {
2893 g_string_append_printf(strdnsconfig,
"%s;", g_strstrip(tokens[loopvar]));
2895 g_string_printf(strdnsconfig,
"%s;", g_strstrip(tokens[loopvar]));
2900 g_string_assign(dnsconfig, strdnsconfig->str);
2901 g_string_free(strdnsconfig,
TRUE);
2902 g_message(
"DNS Config is %s", dnsconfig->str);
2907 g_clear_error(&error);
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);
2931 ioctl(fd, SIOCGIFHWADDR, &ifr);
2933 mac = (
unsigned char *)ifr.ifr_hwaddr.sa_data;
2936 g_string_printf(data,
"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], mac[1], mac[2],
2937 mac[3], mac[4], mac[5]);
2952 gboolean ipv6Enabled)
2954 struct ifaddrs *ifAddrStruct = NULL;
2955 struct ifaddrs *ifa = NULL;
2956 void *tmpAddrPtr = NULL;
2957 getifaddrs(&ifAddrStruct);
2962 for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
2963 if (ifa->ifa_addr == NULL)
continue;
2964 if (ipv6Enabled ==
TRUE) {
2967 rc = strcmp_s(ifa->ifa_name,strlen(ifa->ifa_name),ifname,&ind);
2969 if(((!ind) && (rc == EOK)) && (ifa ->ifa_addr->sa_family == AF_INET6))
2971 tmpAddrPtr = &((
struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
2972 inet_ntop(AF_INET6, tmpAddrPtr, ipAddressBuffer, INET6_ADDRSTRLEN);
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))) {
2983 if (ifa ->ifa_addr->sa_family == AF_INET) {
2985 tmpAddrPtr = &((
struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
2986 inet_ntop(AF_INET, tmpAddrPtr, ipAddressBuffer, INET_ADDRSTRLEN);
2988 rc = strcmp_s(ifa->ifa_name,strlen(ifa->ifa_name),ifname,&ind);
2990 if((!ind) && (rc == EOK))
2998 if (ifAddrStruct != NULL) freeifaddrs(ifAddrStruct);