24 #include <libgupnp/gupnp.h>
31 #include <sys/types.h>
33 #include <netinet/in.h>
34 #include <sys/ioctl.h>
37 #include <arpa/inet.h>
42 #include <libxml/tree.h>
43 #include <libxml/parser.h>
46 #include "rdk_safeclib.h"
47 #ifdef CLIENT_XCAL_SERVER
50 #ifdef ENABLE_BREAKPAD
51 #include "breakpadWrapper.h"
54 #ifdef ENABLE_SD_NOTIFY
55 #include <systemd/sd-daemon.h>
59 #if defined(USE_XUPNP_IARM_BUS)
61 #include "libIARMCore.h"
63 #include "libIBusDaemon.h"
65 #define G_VALUE_INIT {0,{{0}}}
67 #define RECEIVER_ID "deviceId"
68 #define PARTNER_ID "partnerId"
69 #define SLEEP_INTERVAL 7000000
71 #define BCAST_PORT 50755
72 #define DEVICE_PROPERTY_FILE "/etc/device.properties"
73 #define GET_DEVICEID_SCRIPT "/lib/rdk/getDeviceId.sh"
74 #define DEVICE_NAME_FILE "/opt/hn_service_settings.conf"
75 #define LOG_FILE "/opt/logs/xdevice.log"
76 #define DEVICE_XML_PATH "/etc/xupnp/"
77 #define DEVICE_XML_FILE "BasicDevice.xml"
78 static GMainLoop *main_loop;
80 IARM_Bus_Daemon_SysMode_t sysModeParam;
85 #define HST_RAWOFFSET (-11 * 60 * 60 * 1000)
86 #define AKST_RAWOFFSET (-9 * 60 * 60 * 1000)
87 #define PST_RAWOFFSET (-8 * 60 * 60 * 1000)
88 #define MST_RAWOFFSET (-7 * 60 * 60 * 1000)
89 #define CST_RAWOFFSET (-6 * 60 * 60 * 1000)
90 #define EST_RAWOFFSET (-5 * 60 * 60 * 1000)
91 gboolean ipv6Enabled=FALSE;
93 #ifdef SAFEC_DUMMY_API
95 errno_t strcmp_s(
const char * d,
int max ,
const char * src,
int *r)
111 {
"HST11",
"US/Hawaii", HST_RAWOFFSET, 1},
112 {
"HST11HDT,M3.2.0,M11.1.0",
"US/Hawaii", HST_RAWOFFSET, 1},
113 {
"AKST",
"US/Alaska", AKST_RAWOFFSET, 1},
114 {
"AKST09AKDT",
"US/Alaska", AKST_RAWOFFSET, 1},
115 {
"PST08",
"US/Pacific", PST_RAWOFFSET, 1},
116 {
"PST08PDT,M3.2.0,M11.1.0",
"US/Pacific", PST_RAWOFFSET, 1},
117 {
"MST07",
"US/Mountain", MST_RAWOFFSET, 1},
118 {
"MST07MDT,M3.2.0,M11.1.0",
"US/Mountain", MST_RAWOFFSET, 1},
119 {
"CST06",
"US/Central", CST_RAWOFFSET, 1},
120 {
"CST06CDT,M3.2.0,M11.1.0",
"US/Central", CST_RAWOFFSET, 1},
121 {
"EST05",
"US/Eastern", EST_RAWOFFSET, 1},
122 {
"EST05EDT,M3.2.0,M11.1.0",
"US/Eastern", EST_RAWOFFSET, 1}
125 static void mapTimeZoneToJavaFormat(
char* payload)
128 int len =
sizeof(tzStruct)/
sizeof(
struct TZStruct );
130 for (; i < len; i++ )
132 if (g_strcmp0(tzStruct[i].inputTZ, payload) == 0)
135 g_string_assign(dsgtimezone, tzStruct[i].javaTZ);
140 rawOffset = tzStruct[i].rawOffset;
141 usesDaylightTime= tzStruct[i].usesDST;
147 #define COMCAST_PARTNET_KEY "comcast"
148 #define COX_PARTNET_KEY "cox"
156 #define ARRAY_COUNT(array) (sizeof(array)/sizeof(array[0]))
159 {COMCAST_PARTNET_KEY,
"comcast"},
160 {COX_PARTNET_KEY ,
"cox"},
164 {COMCAST_PARTNET_KEY,
"XFINITY"},
165 {COX_PARTNET_KEY ,
"Contour"},
169 {COMCAST_PARTNET_KEY,
"xfinity"},
170 {COX_PARTNET_KEY ,
"contour"},
174 {COMCAST_PARTNET_KEY,
"Comcast XFINITY Guide"},
175 {COX_PARTNET_KEY ,
"Cox Contour Guide"},
179 {COMCAST_PARTNET_KEY,
"Comcast XFINITY Guide application"},
180 {COX_PARTNET_KEY ,
"Cox Contour Guide application"},
184 {COMCAST_PARTNET_KEY,
"Comcast Gateway"},
185 {COX_PARTNET_KEY ,
"Cox Gateway"},
191 for(i = 0; i < nPairs; i++)
193 int nKeyLen = strlen(map[i].pszKey);
194 if(0==strncasecmp(map[i].pszKey, pszKey, nKeyLen))
return map[i].pszValue;
198 return map[0].pszValue;
201 static char * getPartnerID()
203 return partner_id->str;
206 static char * getPartnerName()
208 return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(partnerNameMap), partnerNameMap);
211 static char * getFriendlyName()
213 return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(friendlyNameMap), friendlyNameMap);
216 static char * getProductName()
218 return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(productNameMap), productNameMap);
221 static char * getServiceName()
223 return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(serviceNameMap), serviceNameMap);
226 static char * getServiceDescription()
228 return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(serviceDescriptionMap), serviceDescriptionMap);
231 static char * getGatewayName()
233 return getStrValueFromMap(getPartnerID(), ARRAY_COUNT(gatewayNameMap), gatewayNameMap);
236 static void _sysEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
243 if ((eventId != IARM_BUS_SYSMGR_EVENT_SYSTEMSTATE) || (ind != 0) || (rc != EOK))
248 IARM_Bus_SYSMgr_SystemState_t stateId = sysEventData->data.systemStates.stateId;
249 int state = sysEventData->data.systemStates.state;
253 case IARM_BUS_SYSMGR_SYSSTATE_TUNEREADY:
254 if (tune_ready != sysEventData->data.systemStates.state)
256 tune_ready = sysEventData->data.systemStates.state;
257 if (devConf->rmfCrshSupp ==
TRUE)
259 if (tune_ready ==
TRUE)
261 gupnp_root_device_set_available (dev,
TRUE);
262 g_message(
" Start publishing %d ",tune_ready);
263 if (devConf->useGliDiag == FALSE)
272 gupnp_root_device_set_available (dev,FALSE);
273 g_message(
" Stop publishing %d ",tune_ready);
278 if (devConf->useGliDiag == FALSE)
285 g_message(
"Tune Ready Update Received: %d", tune_ready);
288 case IARM_BUS_SYSMGR_SYSSTATE_STB_SERIAL_NO:
289 g_string_assign(serial_num, sysEventData->data.systemStates.payload);
290 g_message(
"Serial Number Update Received: %s", serial_num->str);
292 case IARM_BUS_SYSMGR_SYSSTATE_CHANNELMAP:
293 g_message(
"Received channel map update");
294 if (sysEventData->data.systemStates.error)
299 else if (sysEventData->data.systemStates.state == 2)
301 if ((strlen(sysEventData->data.systemStates.payload) > 0) &&
302 is_num(sysEventData->data.systemStates.payload) ==
TRUE)
304 channelmap_id=strtoul(sysEventData->data.systemStates.payload, NULL, 10);
307 g_message(
"Received channel map id: %lu", channelmap_id);
314 case IARM_BUS_SYSMGR_SYSSTATE_DAC_ID:
315 g_message(
"Received controller id update");
316 if (sysEventData->data.systemStates.error)
321 else if (sysEventData->data.systemStates.state == 2)
323 if ((strlen(sysEventData->data.systemStates.payload) > 0) &&
324 (
is_num(sysEventData->data.systemStates.payload) ==
TRUE))
326 dac_id=strtoul(sysEventData->data.systemStates.payload, NULL, 10);
329 g_message(
"Received controller id: %lu", dac_id);
335 case IARM_BUS_SYSMGR_SYSSTATE_PLANT_ID:
336 g_message(
"Received plant id update");
337 if (sysEventData->data.systemStates.error)
342 else if (sysEventData->data.systemStates.state == 2)
344 if ((strlen(sysEventData->data.systemStates.payload) > 0) &&
345 is_num(sysEventData->data.systemStates.payload) ==
TRUE)
347 plant_id=strtoul(sysEventData->data.systemStates.payload, NULL, 10);
350 g_message(
"Received plant id: %lu", plant_id);
356 case IARM_BUS_SYSMGR_SYSSTATE_VOD_AD:
357 g_message(
"Received vod server id update");
358 if (sysEventData->data.systemStates.error)
363 else if (sysEventData->data.systemStates.state == 2)
365 if ((strlen(sysEventData->data.systemStates.payload) > 0) &&
366 is_num(sysEventData->data.systemStates.payload) ==
TRUE)
368 vodserver_id=strtoul(sysEventData->data.systemStates.payload, NULL, 10);
371 g_message(
"Received vod server id: %lu", vodserver_id);
378 case IARM_BUS_SYSMGR_SYSSTATE_TIME_ZONE:
379 g_message(
"Received timezone update");
380 if (sysEventData->data.systemStates.error)
383 g_message(
"Time zone error");
385 else if (sysEventData->data.systemStates.state == 2)
387 if ((strlen(sysEventData->data.systemStates.payload) > 1))
391 mapTimeZoneToJavaFormat ((
char*)sysEventData->data.systemStates.payload);
394 g_message(
"Received dsgtimezone: %s", dsgtimezone->str);
395 g_message(
"Received rawOffset: %d", rawOffset);
400 case IARM_BUS_SYSMGR_SYSSTATE_DST_OFFSET :
401 if (sysEventData->data.systemStates.error)
403 g_message(
"dst offset error ");
405 else if (sysEventData->data.systemStates.state == 2)
407 dstOffset= atoi(sysEventData->data.systemStates.payload);
408 dstSavings=(dstOffset*60000);
409 g_message(
"Received dstSavings: %d", dstSavings);
410 if (g_strcmp0(g_strstrip(dsgtimezone->str),
"null") != 0)
445 IARM_Bus_CommonAPI_SysModeChange_Param_t *param = (IARM_Bus_CommonAPI_SysModeChange_Param_t *)arg;
446 g_message(
"Sys Mode Change::New mode --> %d, Old mode --> %d\n",param->newMode,param->oldMode);
447 sysModeParam=param->newMode;
448 return IARM_RESULT_SUCCESS;
451 static void _routesysEventHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
455 rc = strcmp_s(owner, strlen(owner), IARM_BUS_NM_SRV_MGR_NAME, &ind );
457 if((ind == 0) && (rc == EOK))
460 case IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_DATA:
465 if(g_strcmp0(g_strstrip(param->routeIp),dataGatewayIPaddress->str) != 0)
467 g_string_assign(dataGatewayIPaddress,param->routeIp);
468 g_message(
"route IP for the device %s ",dataGatewayIPaddress->str);
472 g_message(
"same route is send %s %s ",param->routeIp,dataGatewayIPaddress->str);
475 g_message(
" route ip is empty");
491 gboolean XUPnP_IARM_Init(
void)
493 g_message(
"<<<<< Iniializing IARM XUPnP >>>>>>>>");
498 g_message(
"<<<<<<<%s - Failed in IARM Bus IARM_Bus_Init>>>>>>>>",__FUNCTION__);
503 g_message(
"<<<<<<<%s - Failed in IARM_Bus_Connect>>>>>>>>",__FUNCTION__);
510 g_message(
"<<<<<<<%s - Registered the SYSMGR BUS Events >>>>>>>>",__FUNCTION__);
512 g_message(
"<<<<<<<%s - Registering Callback for Warehouse Mode Check >>>>>>>>",__FUNCTION__);
517 void getRouteData(
void)
520 IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_ROUTE_MGR_API_getCurrentRouteData, ¶m,
sizeof(param));
523 g_string_assign(dataGatewayIPaddress,param.route.routeIp);
524 g_message(
"getRouteData: route IP for the device %s ",dataGatewayIPaddress->str);
528 g_message(
"route data not available");
544 void getSystemValues(
void)
555 channelmap_id=strtoul(param.
channel_map.payload, NULL, 10);
556 g_message(
"Channel map id available. Value %lu", channelmap_id);
559 if (param.dac_id.state == 2)
561 if (strlen(param.dac_id.payload) > 0
564 dac_id=strtoul(param.dac_id.payload, NULL, 10);
565 g_message(
"dac id available. Value %lu", dac_id);
569 if (param.plant_id.state == 2)
571 if (strlen(param.plant_id.payload) > 0
574 plant_id=strtoul(param.plant_id.payload, NULL, 10);
575 g_message(
"plant id available. Value %lu", plant_id);
579 if (param.vod_ad.state == 2)
581 if (strlen(param.vod_ad.payload) > 0
584 vodserver_id=strtoul(param.vod_ad.payload, NULL, 10);
585 g_message(
"vod ad available. Value %lu", vodserver_id);
589 if (param.time_zone_available.state == 2)
591 if (strlen(param.time_zone_available.payload) > 0
594 g_message(
"Timezone is available. Value %s",param.time_zone_available.payload);
596 mapTimeZoneToJavaFormat ((
char*)param.time_zone_available.payload);
597 g_message(
"dsgtimezone: %s", dsgtimezone->str);
598 g_message(
"rawOffset: %d", rawOffset);
602 if (param.dst_offset.state == 2)
604 if (strlen(param.dst_offset.payload) > 0)
606 dstOffset= atoi(param.dst_offset.payload);
608 dstSavings=(dstOffset*60000);
609 g_message(
"dstSavings: %d", dstSavings);
610 if (g_strcmp0(g_strstrip(dsgtimezone->str),
"null") != 0)
616 if (tune_ready != param.TuneReadyStatus.state)
618 tune_ready = param.TuneReadyStatus.state;
622 g_message(
"Tune Ready: %d\n", tune_ready);
623 if (param.stb_serial_no.payload != NULL)
625 g_string_assign(serial_num, param.stb_serial_no.payload);
626 g_message(
"Serial no: %s\n", serial_num->str);
629 g_message(
"Serial no is NULL\n");
646 #endif //#if defined(USE_XUPNP_IARM_BUS)
660 const gchar *message, gpointer user_data)
664 g_get_current_time(&timeval);
665 if (logoutfile == NULL)
668 g_print (
"%s: g_time_val_to_iso8601(&timeval): %s\n", message);
672 g_fprintf (logoutfile,
"%s : %s\n", g_time_val_to_iso8601(&timeval), message);
689 get_url_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
694 gupnp_service_action_set (action,
"BaseUrl", G_TYPE_STRING, url->str, NULL);
695 gupnp_service_action_return (action);
710 get_trm_url_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
713 gupnp_service_action_set (action,
"BaseTrmUrl", G_TYPE_STRING, trmurl->str, NULL);
714 gupnp_service_action_return (action);
731 if (tune_ready ==
TRUE)
734 gupnp_service_action_set (action,
"PlaybackUrl", G_TYPE_STRING, playbackurl->str, NULL);
740 gupnp_service_action_set (action,
"PlaybackUrl", G_TYPE_STRING,
"NULL", NULL);
742 gupnp_service_action_return (action);
756 get_gwyip_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
759 gupnp_service_action_set (action,
"GatewayIP", G_TYPE_STRING, gwyip->str, NULL);
760 gupnp_service_action_return (action);
774 get_gwyipv6_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
777 gupnp_service_action_set (action,
"GatewayIPv6", G_TYPE_STRING, gwyipv6->str, NULL);
778 gupnp_service_action_return (action);
793 get_gwystbip_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
796 gupnp_service_action_set (action,
"GatewayStbIP", G_TYPE_STRING, gwystbip->str, NULL);
797 gupnp_service_action_return (action);
815 gupnp_service_action_set (action,
"Ipv6Prefix", G_TYPE_STRING, ipv6prefix->str, NULL);
816 gupnp_service_action_return (action);
833 gupnp_service_action_set (action,
"HostMacAddress", G_TYPE_STRING, hostmacaddress->str, NULL);
834 gupnp_service_action_return (action);
851 gupnp_service_action_set (action,
"BcastMacAddress", G_TYPE_STRING, bcastmacaddress->str, NULL);
852 gupnp_service_action_return (action);
869 gupnp_service_action_set (action,
"RecvDevType", G_TYPE_STRING, recvdevtype->str, NULL);
870 gupnp_service_action_return (action);
875 get_devicetype_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
878 gupnp_service_action_set (action,
"DeviceType", G_TYPE_STRING, devicetype->str, NULL);
879 gupnp_service_action_return (action);
895 gupnp_service_action_set (action,
"BuildVersion", G_TYPE_STRING, buildversion->str, NULL);
896 gupnp_service_action_return (action);
913 gupnp_service_action_set (action,
"DnsConfig", G_TYPE_STRING, dnsconfig->str, NULL);
914 gupnp_service_action_return (action);
932 gupnp_service_action_set (action,
"SystemIds", G_TYPE_STRING, systemids->str, NULL);
933 gupnp_service_action_return (action);
949 gupnp_service_action_set (action,
"DataGatewayIPaddress", G_TYPE_STRING, dataGatewayIPaddress->str, NULL);
950 gupnp_service_action_return (action);
964 get_timezone_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
967 if (devConf->useGliDiag == FALSE)
969 gupnp_service_action_set (action,
"TimeZone", G_TYPE_STRING, dsgtimezone->str, NULL);
970 gupnp_service_action_return (action);
986 gupnp_service_action_set (action,
"RawOffSet", G_TYPE_INT, rawOffset, NULL);
987 gupnp_service_action_return (action);
1000 G_MODULE_EXPORT
void
1003 gupnp_service_action_set (action,
"DSTSavings", G_TYPE_INT, dstSavings, NULL);
1004 gupnp_service_action_return (action);
1017 G_MODULE_EXPORT
void
1020 gupnp_service_action_set (action,
"UsesDaylightTime", G_TYPE_BOOLEAN, usesDaylightTime, NULL);
1021 gupnp_service_action_return (action);
1034 G_MODULE_EXPORT
void
1038 gupnp_service_action_set (action,
"DeviceName", G_TYPE_STRING, devicename->str, NULL);
1039 gupnp_service_action_return (action);
1052 G_MODULE_EXPORT
void
1055 gupnp_service_action_set (action,
"DSTOffset", G_TYPE_INT, dstOffset, NULL);
1056 gupnp_service_action_return (action);
1069 G_MODULE_EXPORT
void
1070 get_hosts_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
1074 gupnp_service_action_set (action,
"Hosts", G_TYPE_STRING, etchosts->str, NULL);
1075 gupnp_service_action_return (action);
1088 G_MODULE_EXPORT
void
1092 gupnp_service_action_set (action,
"IsGateway", G_TYPE_BOOLEAN, isgateway, NULL);
1093 gupnp_service_action_return (action);
1106 G_MODULE_EXPORT
void
1109 gupnp_service_action_set (action,
"RequiresTRM", G_TYPE_BOOLEAN, requirestrm, NULL);
1110 gupnp_service_action_return (action);
1123 G_MODULE_EXPORT
void
1124 get_rui_url_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
1129 g_print(
"Error in initializing RUI url value\n");
1132 gupnp_service_action_get (action,
"InputDeviceProfile", G_TYPE_STRING, inDevProfile->str, NULL);
1133 gupnp_service_action_get (action,
"UIFilter", G_TYPE_STRING, uiFilter->str,NULL);
1134 gupnp_service_action_set (action,
"UIListing", G_TYPE_STRING, ruiurl->str, NULL);
1135 gupnp_service_action_return (action);
1153 G_MODULE_EXPORT
void
1154 query_url_cb (GUPnPService *service,
char *variable, GValue *value, gpointer user_data)
1156 g_value_init (value, G_TYPE_STRING);
1157 g_value_set_string (value, url->str);
1171 G_MODULE_EXPORT
void
1174 g_value_init (value, G_TYPE_STRING);
1175 g_value_set_string (value, trmurl->str);
1189 G_MODULE_EXPORT
void
1192 if (tune_ready ==
TRUE)
1195 g_value_init (value, G_TYPE_STRING);
1196 g_value_set_string (value, playbackurl->str);
1201 g_value_init (value, G_TYPE_STRING);
1202 g_value_set_string (value,
"NULL");
1218 G_MODULE_EXPORT
void
1221 g_value_init (value, G_TYPE_STRING);
1222 g_value_set_string (value, dataGatewayIPaddress->str);
1238 G_MODULE_EXPORT
void
1241 g_value_init (value, G_TYPE_STRING);
1242 g_value_set_string (value, devicename->str);
1256 G_MODULE_EXPORT
void
1257 query_gwyip_cb (GUPnPService *service,
char *variable, GValue *value, gpointer user_data)
1259 g_value_init (value, G_TYPE_STRING);
1260 g_value_set_string (value, gwyip->str);
1274 G_MODULE_EXPORT
void
1277 g_value_init (value, G_TYPE_STRING);
1278 g_value_set_string (value, gwyipv6->str);
1292 G_MODULE_EXPORT
void
1295 g_value_init (value, G_TYPE_STRING);
1296 g_value_set_string (value, gwystbip->str);
1310 G_MODULE_EXPORT
void
1313 g_value_init (value, G_TYPE_STRING);
1314 g_value_set_string (value, ipv6prefix->str);
1328 G_MODULE_EXPORT
void
1331 g_value_init (value, G_TYPE_STRING);
1332 g_value_set_string (value, hostmacaddress->str);
1346 G_MODULE_EXPORT
void
1349 g_value_init (value, G_TYPE_STRING);
1350 g_value_set_string (value, bcastmacaddress->str);
1364 G_MODULE_EXPORT
void
1367 g_value_init (value, G_TYPE_STRING);
1368 g_value_set_string (value, recvdevtype->str);
1372 G_MODULE_EXPORT
void
1373 query_devicetype_cb (GUPnPService *service,
char *variable, GValue *value, gpointer user_data)
1375 g_value_init (value, G_TYPE_STRING);
1376 g_value_set_string (value, devicetype->str);
1390 G_MODULE_EXPORT
void
1393 g_value_init (value, G_TYPE_STRING);
1394 g_value_set_string (value, buildversion->str);
1408 G_MODULE_EXPORT
void
1411 g_value_init (value, G_TYPE_STRING);
1412 g_value_set_string (value, dnsconfig->str);
1426 G_MODULE_EXPORT
void
1430 g_value_init (value, G_TYPE_STRING);
1431 g_value_set_string (value, systemids->str);
1445 G_MODULE_EXPORT
void
1448 if (devConf->useGliDiag == FALSE)
1450 g_value_init (value, G_TYPE_STRING);
1451 g_value_set_string (value, dsgtimezone->str);
1465 G_MODULE_EXPORT
void
1466 query_hosts_cb (GUPnPService *service,
char *variable, GValue *value, gpointer user_data)
1469 g_value_init (value, G_TYPE_STRING);
1470 g_value_set_string (value, etchosts->str);
1484 G_MODULE_EXPORT
void
1488 g_value_init (value, G_TYPE_BOOLEAN);
1489 g_value_set_boolean (value, isgateway);
1503 G_MODULE_EXPORT
void
1507 g_value_init (value, G_TYPE_BOOLEAN);
1508 g_value_set_boolean (value, requirestrm);
1522 G_MODULE_EXPORT
void
1525 g_value_init (value, G_TYPE_STRING);
1526 g_value_set_string (value, ruiurl->str);
1540 G_MODULE_EXPORT
void
1543 g_value_init (value, G_TYPE_INT);
1544 g_value_set_int (value, rawOffset);
1558 G_MODULE_EXPORT
void
1561 g_value_init (value, G_TYPE_INT);
1562 g_value_set_int (value, dstOffset);
1576 G_MODULE_EXPORT
void
1579 g_value_init (value, G_TYPE_INT);
1580 g_value_set_int (value, dstSavings);
1594 G_MODULE_EXPORT
void
1597 g_value_init (value, G_TYPE_BOOLEAN);
1598 g_value_set_boolean (value, usesDaylightTime);
1601 void* checkMainLoopRunning()
1603 guint checkMainLoopCounter=0;
1606 if (! g_main_loop_is_running(main_loop))
1608 if(checkMainLoopCounter < 7)
1609 g_message(
"TELEMETRY_XUPNP_DEVICE_MAIN_LOOP_NOT_RUNNING");
1610 checkMainLoopCounter++;
1612 usleep(SLEEP_INTERVAL);
1617 main (
int argc,
char **argv)
1622 GError *error = NULL;
1623 url = g_string_new(
"null");
1624 trmurl = g_string_new(
"null");
1625 trmurlCVP2 = g_string_new(
"null");
1626 playbackurl = g_string_new(
"null");
1627 playbackurlCVP2 = g_string_new(
"null");
1628 gwyip = g_string_new(
"null");
1629 gwyipv6 = g_string_new(
"null");
1630 gwystbip = g_string_new(
"null");
1631 ipv6prefix = g_string_new(
"null");
1632 gwyipCVP2 = g_string_new(
"null");
1633 dnsconfig = g_string_new(
"null");
1634 systemids = g_string_new(
"null");
1635 dsgtimezone = g_string_new(
"null");
1636 etchosts = g_string_new(
"null");
1637 serial_num = g_string_new(
"null");
1638 channelmap_id = dac_id = plant_id = vodserver_id = 0;
1641 service_ready=FALSE;
1643 ruiurl = g_string_new(
"null");
1644 inDevProfile = g_string_new(
"null");
1645 uiFilter = g_string_new(
"null");
1646 recv_id = g_string_new(
"null");
1647 partner_id = g_string_new(
"null");
1648 hostmacaddress = g_string_new(
"null");
1649 bcastmacaddress = g_string_new(
"null");
1650 devicename = g_string_new(
"null");
1651 buildversion = g_string_new(
"null");
1652 recvdevtype = g_string_new(
"null");
1653 devicetype = g_string_new(
"null");
1654 mocaIface = g_string_new(
"null");
1655 wifiIface = g_string_new(
"null");
1656 dataGatewayIPaddress = g_string_new(
"null");
1659 char ipAddressBuffer[INET6_ADDRSTRLEN];
1660 char stbipAddressBuffer[INET6_ADDRSTRLEN];
1662 g_thread_init (NULL);
1667 #ifdef ENABLE_BREAKPAD
1668 installExceptionHandler();
1672 fprintf(stderr,
"Error in arguments\nUsage: %s config file name (eg: %s /etc/xdevice.conf)\n", argv[0], argv[0]);
1673 #ifndef CLIENT_XCAL_SERVER
1682 const char* configfilename = argv[1];
1686 g_print(
"Unable to find xdevice config, giving up\n");
1687 #ifndef CLIENT_XCAL_SERVER
1692 #ifdef CLIENT_XCAL_SERVER
1693 if(! (devConf->bcastPort))
1694 devConf->bcastPort=BCAST_PORT;
1695 if(! (devConf->devPropertyFile))
1696 devConf->devPropertyFile=g_strdup(DEVICE_PROPERTY_FILE);
1697 if(! (devConf->deviceNameFile))
1698 devConf->deviceNameFile=g_strdup(DEVICE_NAME_FILE);
1699 if(! (devConf->logFile))
1700 devConf->logFile=g_strdup(LOG_FILE);
1701 if(! (devConf->devXmlPath))
1702 devConf->devXmlPath=g_strdup(DEVICE_XML_PATH);
1703 if(! (devConf->devXmlFile))
1704 devConf->devXmlFile=g_strdup(DEVICE_XML_FILE);
1705 devConf->allowGwy=FALSE;
1706 devConf->useIARM=
TRUE;
1707 devConf->useGliDiag=
TRUE;
1710 char* logfilename = argv[2];
1713 logoutfile = g_fopen (logfilename,
"a");
1717 g_message(
"xupnp not handling the logging");
1721 g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | \
1722 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR,
xupnp_logger, NULL);
1724 g_message(
"Starting xdevice service on interface %s", devConf->bcastIf);
1725 g_print(
"Starting xdevice service on interface %s\n", devConf->bcastIf);
1728 char* xmlfilename = g_strconcat(devConf->devXmlPath,
"/", devConf->devXmlFile, NULL);
1729 const guint host_port = devConf->bcastPort;
1730 if (devConf->devPropertyFile != NULL)
1734 g_message(
"Receiver Type : %s Build Version : %s Device Type: %s moca %s wifi %s \n", recvdevtype->str,buildversion->str,devicetype->str,mocaIface->str,wifiIface->str);
1738 g_message(
" ERROR in getting Receiver Type : %s Build Version : %s \n", recvdevtype->str,buildversion->str);
1739 g_message(
"Receiver Type : %s Build Version : %s Device Type: %s moca %s wifi %s \n", recvdevtype->str,buildversion->str,devicetype->str,mocaIface->str,wifiIface->str);
1744 #ifndef CLIENT_XCAL_SERVER
1745 if( access(devConf->ipv6FileLocation, F_OK ) != -1 )
1750 fprintf(stderr,
"In Ipv6 Could not locate the link local ipv6 address of the broadcast interface %s\n", devConf->bcastIf);
1751 g_critical(
"In Ipv6 Could not locate the link local ipv6 address of the broadcast interface %s\n", devConf->bcastIf);
1754 g_string_assign(gwyipv6, ipAddressBuffer);
1755 result =
getipaddress(devConf->bcastIf,ipAddressBuffer,FALSE);
1759 fprintf(stderr,
"Could not locate the link local v4 ipaddress of the broadcast interface %s\n", devConf->bcastIf);
1760 g_critical(
"Could not locate the link local v4 ipaddress of the broadcast interface %s\n", devConf->bcastIf);
1764 g_message(
"ipaddress of the interface %s\n", ipAddressBuffer);
1766 int result =
getipaddress(mocaIface->str,ipAddressBuffer,FALSE);
1769 g_message(
"Could not locate the ipaddress of the broadcast interface %s",mocaIface->str);
1770 result =
getipaddress(wifiIface->str,ipAddressBuffer,FALSE);
1773 g_message(
"Could not locate the ipaddress of the wifi broadcast interface %s",wifiIface->str);
1774 g_critical(
"Could not locate the link local v4 ipaddress of the broadcast interface %s\n", devConf->bcastIf);
1779 devConf->bcastIf=g_strdup(wifiIface->str);
1784 devConf->bcastIf=g_strdup(mocaIface->str);
1786 g_message(
"Starting xdevice service on interface %s", devConf->bcastIf);
1793 g_message(
"Broadcast Network interface: %s\n", devConf->bcastIf);
1794 g_message(
"Dev XML File Name: %s\n", devConf->devXmlFile);
1795 g_message(
"Use IARM value is: %u\n", devConf->useIARM);
1797 g_string_assign(gwyip, ipAddressBuffer);
1800 #if defined(USE_XUPNP_IARM_BUS)
1801 gboolean iarminit = XUPnP_IARM_Init();
1805 g_message(
"XUPNP IARM init success");
1806 #ifndef CLIENT_XCAL_SERVER
1813 g_critical(
"XUPNP IARM init failed");
1815 #endif //#if defined(USE_XUPNP_IARM_BUS)
1817 #ifndef CLIENT_XCAL_SERVER
1818 if(devConf->hostMacIf != NULL)
1820 const gchar* hostmac=(gchar*)
getmacaddress(devConf->hostMacIf);
1823 g_message(
"MAC address in interface: %s %s \n", devConf->hostMacIf,hostmac);
1827 g_message(
"failed to retrieve macaddress on interface %s ", devConf->hostMacIf);
1829 g_string_assign(hostmacaddress,hostmac);
1830 g_message(
"Host mac address is %s",hostmacaddress->str);
1833 if (devConf->bcastIf != NULL )
1835 const gchar* bcastmac=(gchar*)
getmacaddress(devConf->bcastIf);
1838 g_message(
"Broadcast MAC address in interface: %s %s \n", devConf->bcastIf,bcastmac);
1842 g_message(
"failed to retrieve macaddress on interface %s ", devConf->bcastIf);
1844 g_string_assign(bcastmacaddress,bcastmac);
1845 g_message(
"bcast mac address is %s",bcastmacaddress->str);
1847 if (devConf->deviceNameFile != NULL)
1851 g_message(
"Device Name : %s ", devicename->str);
1855 g_message(
" ERROR in getting Device Name ");
1860 g_message(
"getting the receiver id from %s", GET_DEVICEID_SCRIPT);
1861 recv_id=
getID(RECEIVER_ID);
1863 g_string_printf(url,
"http://%s:8080/videoStreamInit?recorderId=%s", ipAddressBuffer, recv_id->str);
1864 g_print (
"The url is now %s.\n", url->str);
1866 #ifndef CLIENT_XCAL_SERVER
1867 if (devConf->enableTRM == FALSE)
1870 g_string_printf(trmurl,
"NULL");
1875 g_string_printf(trmurl,
"ws://%s:9988", ipAddressBuffer);
1878 if(devConf->allowGwy == FALSE)
1884 #ifndef CLIENT_XCAL_SERVER
1885 g_string_printf(playbackurl,
"http://%s:8080/hnStreamStart?deviceId=%s&DTCP1HOST=%s&DTCP1PORT=5000", ipAddressBuffer, recv_id->str, ipAddressBuffer);
1889 g_print(
"Contents of dnsconfig is %s\n", dnsconfig->str);
1894 g_message(
"System ids are %s\n", systemids->str);
1898 g_warning(
"Error in finding system ids\n");
1902 #if defined(USE_XUPNP_IARM_BUS)
1903 while ((strlen(g_strstrip(serial_num->str)) < 6) || (
is_alphanum(serial_num->str) == FALSE))
1905 g_message(
"XUPnP: Waiting for Serial Number\n");
1908 g_message(
"Received Serial Number:%s", serial_num->str);
1912 g_print(
"Serial Number is %s\n", serial_num->str);
1918 g_print(
"Serial Number is %s\n", serial_num->str);
1923 #ifndef CLIENT_XCAL_SERVER
1926 g_print(
"EtcHosts Content is \n%s\n", etchosts->str);
1930 g_print(
"Error in getting etc hosts\n");
1935 const char* struuid = g_strconcat(
"uuid:", g_strstrip(recv_id->str),NULL);
1936 result =
updatexmldata(xmlfilename, struuid, serial_num->str,
"XFINITY");
1940 fprintf(stderr,
"Failed to open the device xml file %s\n", xmlfilename);
1944 fprintf(stderr,
"Updated the device xml file %s\n", xmlfilename);
1947 upnpContext = gupnp_context_new (NULL, devConf->bcastIf, devConf->bcastPort, &error);
1949 upnpContext = gupnp_context_new (devConf->bcastIf, devConf->bcastPort, &error);
1952 g_printerr (
"Error creating the Broadcast context: %s\n",
1955 g_clear_error(&error);
1956 return EXIT_FAILURE;
1960 gupnp_context_set_subscription_timeout(upnpContext, 0);
1962 dev = gupnp_root_device_new (upnpContext, devConf->devXmlFile, devConf->devXmlPath);
1964 dev = gupnp_root_device_new (upnpContext, devConf->devXmlFile, devConf->devXmlPath, &error);
1967 #ifndef CLIENT_XCAL_SERVER
1968 if (devConf->disableTuneReady == FALSE)
1970 while (FALSE == tune_ready)
1972 g_message(
"XUPnP: Waiting for Tune Ready\n");
1979 g_message(
"Tune Ready check is disabled - Setting tune_ready to TRUE");
1982 if((devConf->allowGwy ==
TRUE) && (ipv6Enabled==
TRUE) && (devConf->ipv6PrefixFile != NULL))
1984 while(access(devConf->ipv6PrefixFile, F_OK ) == -1 )
1987 g_message(
" Waiting to get IPv6 prefix file ");
1993 g_message(
" V6 prefix is not yet updated in file %s ",devConf->ipv6PrefixFile);
1996 g_message(
"IPv6 prefix : %s ", ipv6prefix->str);
2000 g_message(
"Box is in IPV4 or ipv6 prefix is empty or Not a gateway ipv6enabled = %d ipv6PrefixFile = %s allowGwy = %d ",ipv6Enabled,devConf->ipv6PrefixFile,devConf->allowGwy);
2002 if(devConf->hostMacIf != NULL)
2004 result =
getipaddress(devConf->hostMacIf,stbipAddressBuffer,ipv6Enabled);
2008 g_message(
"Could not locate the ipaddress of the host mac interface %s\n", devConf->hostMacIf);
2011 g_message(
"ipaddress of the interface %s\n", stbipAddressBuffer);
2013 g_string_assign(gwystbip, stbipAddressBuffer);
2016 gupnp_root_device_set_available (dev,
TRUE);
2017 upnpService = gupnp_device_info_get_service
2018 (GUPNP_DEVICE_INFO (dev),
"urn:schemas-upnp-org:service:DiscoverFriendlies:1");
2020 g_printerr (
"Cannot get DiscoverFriendlies service\n");
2022 return EXIT_FAILURE;
2025 #ifdef ENABLE_SD_NOTIFY
2026 sd_notifyf(0,
"READY=1\n"
2027 "STATUS=xcal-device is Successfully Initialized\n"
2029 (
unsigned long) getpid());
2033 g_signal_connect (upnpService,
"action-invoked::GetBaseUrl", G_CALLBACK (
get_url_cb), NULL);
2034 g_signal_connect (upnpService,
"action-invoked::GetBaseTrmUrl", G_CALLBACK (
get_trm_url_cb), NULL);
2035 g_signal_connect (upnpService,
"action-invoked::GetGatewayIP", G_CALLBACK (
get_gwyip_cb), NULL);
2036 g_signal_connect (upnpService,
"action-invoked::GetGatewayIPv6", G_CALLBACK (
get_gwyipv6_cb), NULL);
2037 g_signal_connect (upnpService,
"action-invoked::GetIpv6Prefix", G_CALLBACK (
get_ipv6prefix_cb), NULL);
2038 g_signal_connect (upnpService,
"action-invoked::GetGatewayStbIP", G_CALLBACK (
get_gwystbip_cb), NULL);
2039 g_signal_connect (upnpService,
"action-invoked::GetDnsConfig", G_CALLBACK (
get_dnsconfig_cb), NULL);
2040 g_signal_connect (upnpService,
"action-invoked::GetSystemIds", G_CALLBACK (
get_systemids_cb), NULL);
2041 g_signal_connect (upnpService,
"action-invoked::GetTimeZone", G_CALLBACK (
get_timezone_cb), NULL);
2042 g_signal_connect (upnpService,
"action-invoked::GetHosts", G_CALLBACK (
get_hosts_cb), NULL);
2043 g_signal_connect (upnpService,
"action-invoked::GetRequiresTRM", G_CALLBACK (
get_requirestrm_cb), NULL);
2044 g_signal_connect (upnpService,
"action-invoked::GetHostMacAddress", G_CALLBACK (
get_hostmacaddress_cb), NULL);
2045 g_signal_connect (upnpService,
"action-invoked::GetRawOffSet", G_CALLBACK (
get_rawoffset_cb), NULL);
2046 g_signal_connect (upnpService,
"action-invoked::GetDSTOffset", G_CALLBACK (
get_dstoffset_cb), NULL);
2047 g_signal_connect (upnpService,
"action-invoked::GetDSTSavings", G_CALLBACK (
get_dstsavings_cb), NULL);
2048 g_signal_connect (upnpService,
"action-invoked::GetUsesDaylightTime", G_CALLBACK (
get_usesdaylighttime_cb), NULL);
2049 g_signal_connect (upnpService,
"action-invoked::GetPlaybackUrl", G_CALLBACK (
get_playback_url_cb), NULL);
2051 g_signal_connect (upnpService,
"action-invoked::GetDeviceName", G_CALLBACK (
get_devicename_cb), NULL);
2052 g_signal_connect (upnpService,
"action-invoked::GetIsGateway", G_CALLBACK (
get_isgateway_cb), NULL);
2053 g_signal_connect (upnpService,
"action-invoked::GetBcastMacAddress", G_CALLBACK (
get_bcastmacaddress_cb), NULL);
2054 g_signal_connect (upnpService,
"action-invoked::GetRecvDevType", G_CALLBACK (
get_recvdevtype_cb), NULL);
2055 g_signal_connect (upnpService,
"action-invoked::GetDeviceType", G_CALLBACK (get_devicetype_cb), NULL);
2056 g_signal_connect (upnpService,
"action-invoked::GetBuildVersion", G_CALLBACK (
get_buildversion_cb), NULL);
2058 g_signal_connect (upnpService,
"query-variable::Url", G_CALLBACK (
query_url_cb), NULL);
2059 g_signal_connect (upnpService,
"query-variable::TrmUrl", G_CALLBACK (
query_trm_url_cb), NULL);
2060 g_signal_connect (upnpService,
"query-variable::GatewayIP", G_CALLBACK (
query_gwyip_cb), NULL);
2061 g_signal_connect (upnpService,
"query-variable::GatewayIPv6", G_CALLBACK (
query_gwyipv6_cb), NULL);
2062 g_signal_connect (upnpService,
"query-variable::Ipv6Prefix", G_CALLBACK (
query_ipv6prefix_cb), NULL);
2063 g_signal_connect (upnpService,
"query-variable::GatewayStbIP", G_CALLBACK (
query_gwystbip_cb), NULL);
2064 g_signal_connect (upnpService,
"query-variable::DnsConfig", G_CALLBACK (
query_dnsconfig_cb), NULL);
2065 g_signal_connect (upnpService,
"query-variable::SystemIds", G_CALLBACK (
query_systemids_cb), NULL);
2066 g_signal_connect (upnpService,
"query-variable::TimeZone", G_CALLBACK (
query_timezone_cb), NULL);
2067 g_signal_connect (upnpService,
"query-variable::Hosts", G_CALLBACK (
query_hosts_cb), NULL);
2068 g_signal_connect (upnpService,
"query-variable::RequiresTRM", G_CALLBACK (
query_requirestrm_cb), NULL);
2070 g_signal_connect (upnpService,
"query-variable::RawOffSet", G_CALLBACK (
query_rawoffset_cb), NULL);
2071 g_signal_connect (upnpService,
"query-variable::DSTOffset", G_CALLBACK (
query_dstoffset_cb), NULL);
2072 g_signal_connect (upnpService,
"query-variable::DSTSavings", G_CALLBACK (
query_dstsavings_cb), NULL);
2074 g_signal_connect (upnpService,
"query-variable::PlaybackUrl", G_CALLBACK (
query_playback_url_cb), NULL);
2076 g_signal_connect (upnpService,
"query-variable::DeviceName", G_CALLBACK (
query_devicename_cb), NULL);
2077 g_signal_connect (upnpService,
"query-variable::IsGateway", G_CALLBACK (
query_isgateway_cb), NULL);
2079 g_signal_connect (upnpService,
"query-variable::RecvDevType", G_CALLBACK (
query_recvdevtype_cb), NULL);
2080 g_signal_connect (upnpService,
"query-variable::DeviceType", G_CALLBACK (query_devicetype_cb), NULL);
2081 g_signal_connect (upnpService,
"query-variable::BuildVersion", G_CALLBACK (
query_buildversion_cb), NULL);
2085 #ifndef CLIENT_XCAL_SERVER
2087 if (devConf->enableCVP2)
2089 char* cvpxmlfilename = g_strconcat(g_strstrip(devConf->devXmlPath),
"/", g_strstrip(devConf->cvpXmlFile), NULL);
2090 g_print(
"Starting CVP2 Service with %s\n", cvpxmlfilename);
2092 char * struuidcvp = NULL;
2096 struuidcvp = g_strconcat(
"uuid:AA5859B7-EFF4-42FD-BB92-", mac->str, NULL);
2097 g_string_free(mac,
TRUE);
2101 g_print(
"RemoteUIServerDevice UDN value: %s\n",struuidcvp);
2102 partner_id=
getID(PARTNER_ID);
2106 result =
updatexmldata(cvpxmlfilename, struuidcvp, serial_num->str, getFriendlyName());
2112 g_free( cvpxmlfilename);
2117 g_printerr(
"Failed to open the RemoteUIServerDevice xml file\n");
2121 g_print(
"Updated the RemoteUIServerDevice xml file\n");
2124 cvpcontext = gupnp_context_new (NULL, devConf->cvpIf, devConf->cvpPort, &error);
2126 cvpcontext = gupnp_context_new (devConf->cvpIf, devConf->cvpPort, &error);
2129 g_printerr (
"Error creating the CVP context: %s\n", error->message);
2131 g_clear_error(&error);
2132 return EXIT_FAILURE;
2136 gupnp_context_set_subscription_timeout(cvpcontext, 0);
2138 cvpdev = gupnp_root_device_new (cvpcontext, devConf->cvpXmlFile, devConf->devXmlPath);
2140 cvpdev = gupnp_root_device_new (cvpcontext, devConf->cvpXmlFile, devConf->devXmlPath, &error);
2142 gupnp_root_device_set_available (cvpdev,
TRUE);
2145 cvpservice = gupnp_device_info_get_service
2146 (GUPNP_DEVICE_INFO (cvpdev),
"urn:schemas-upnp-org:service:RemoteUIServer:1");
2148 g_printerr (
"Cannot get RemoteUI service\n");
2150 return EXIT_FAILURE;
2152 g_signal_connect (cvpservice,
"action-invoked::GetCompatibleUIs", G_CALLBACK (
get_rui_url_cb), NULL);
2165 main_loop = g_main_loop_new (NULL, FALSE);
2166 thread = g_thread_create(checkMainLoopRunning, NULL,FALSE, NULL);
2167 g_main_loop_run (main_loop);
2170 g_main_loop_unref (main_loop);
2171 g_object_unref (upnpService);
2172 g_object_unref (dev);
2173 g_object_unref (upnpContext);
2175 return EXIT_SUCCESS;
2188 int getipaddress(
const char* ifname,
char* ipAddressBuffer, gboolean ipv6Enabled)
2190 struct ifaddrs * ifAddrStruct=NULL;
2191 struct ifaddrs * ifa=NULL;
2192 void * tmpAddrPtr=NULL;
2195 getifaddrs(&ifAddrStruct);
2198 for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
2199 if (ifa->ifa_addr == NULL)
continue;
2200 if (ipv6Enabled ==
TRUE)
2203 rc = strcmp_s(ifa->ifa_name, strlen(ifa->ifa_name), ifname, &ind);
2205 if (((ind == 0) && (rc == EOK)) && (ifa ->ifa_addr->sa_family==AF_INET6))
2207 tmpAddrPtr=&((
struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
2209 inet_ntop(AF_INET6, tmpAddrPtr, ipAddressBuffer, INET6_ADDRSTRLEN);
2212 if ((g_strcmp0(g_strstrip(devConf->bcastIf),ifname) == 0) && (IN6_IS_ADDR_LINKLOCAL(tmpAddrPtr)) || ((!(IN6_IS_ADDR_LINKLOCAL(tmpAddrPtr))) && (g_strcmp0(g_strstrip(devConf->hostMacIf),ifname) == 0)))
2222 if (ifa ->ifa_addr->sa_family==AF_INET) {
2224 tmpAddrPtr=&((
struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
2226 inet_ntop(AF_INET, tmpAddrPtr, ipAddressBuffer, INET_ADDRSTRLEN);
2229 rc = strcmp_s(ifa->ifa_name, strlen(ifa->ifa_name), ifname, &ind);
2231 if((ind == 0) && (rc == EOK))
2240 if (ifAddrStruct!=NULL) freeifaddrs(ifAddrStruct);
2259 GString *data=g_string_new(NULL);
2261 fd = socket(AF_INET, SOCK_DGRAM, 0);
2263 ifr.ifr_addr.sa_family = AF_INET;
2264 rc = strcpy_s(ifr.ifr_name , IFNAMSIZ-1, ifname);
2268 ioctl(fd, SIOCGIFHWADDR, &ifr);
2272 mac = (
unsigned char *)ifr.ifr_hwaddr.sa_data;
2276 g_string_printf(data,
"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
2290 gboolean result = FALSE;
2291 gchar* dnsconfigfile = NULL;
2292 GString* strdnsconfig = g_string_new(NULL);
2294 if (devConf->dnsFile == NULL)
2296 g_warning(
"dnsconfig file name not found in config");
2299 result = g_file_get_contents (devConf->dnsFile, &dnsconfigfile, NULL, &error);
2300 if (result == FALSE)
2302 g_warning(
"Problem in reading dnsconfig file %s", error->message);
2306 gchar **tokens = g_strsplit_set(dnsconfigfile,
"\n\0", -1);
2308 guint toklength = g_strv_length(tokens);
2310 gboolean firsttok =
TRUE;
2312 for (loopvar=0; loopvar<toklength; loopvar++)
2314 if ((strlen(g_strstrip(tokens[loopvar])) > 0))
2317 if (firsttok == FALSE)
2319 g_string_append_printf(strdnsconfig,
"%s;",g_strstrip(tokens[loopvar]));
2323 g_string_printf(strdnsconfig,
"%s;",g_strstrip(tokens[loopvar]));
2329 g_string_assign(dnsconfig, strdnsconfig->str);
2330 g_string_free(strdnsconfig,
TRUE);
2331 g_message(
"DNS Config is %s",dnsconfig->str);
2338 g_clear_error(&error);
2353 if (devConf->useGliDiag ==
TRUE)
2355 g_string_printf(systemids,
"channelMapId:%lu;controllerId:%lu;plantId:%lu;vodServerId:%lu",
2356 channelmap_id,dac_id,plant_id,vodserver_id);
2362 unsigned long diagid=0;
2363 gboolean result = FALSE;
2366 if (devConf->diagFile == NULL)
2368 g_warning(
"diag file name not found in config");
2371 result = g_file_get_contents (devConf->diagFile, &diagfile, NULL, &error);
2372 if (result == FALSE) {
2373 g_string_assign(systemids,
"channelMapId:0;controllerId:0;plantId:0;vodServerId:0");
2378 g_string_printf(systemids,
"channelMapId:%lu;", diagid);
2380 g_string_append_printf(systemids,
"controllerId:%lu;", diagid);
2382 g_string_append_printf(systemids,
"plantId:%lu;", diagid);
2384 g_string_append_printf(systemids,
"vodServerId:%lu", diagid);
2391 g_clear_error(&error);
2411 unsigned long diagid=0;
2412 gchar **tokens = g_strsplit_set(diagfilecontents,
":,{}", -1);
2413 guint toklength = g_strv_length(tokens);
2416 for (loopvar=0; loopvar<toklength; loopvar++)
2418 if (g_strrstr(g_strstrip(tokens[loopvar]), diagparam))
2420 if ((loopvar+1) < toklength )
2421 diagid=strtoul(tokens[loopvar+1], NULL, 10);
2439 gboolean result = FALSE;
2440 gchar* dsgproxyfile = NULL;
2442 if (devConf->dsgFile == NULL)
2444 g_warning(
"dsg file name not found in config");
2447 result = g_file_get_contents (devConf->dsgFile, &dsgproxyfile, NULL, &error);
2448 if (result == FALSE) {
2449 g_warning(
"Problem in reading dsgproxyfile file %s", error->message);
2455 gchar **tokens = g_strsplit_set(dsgproxyfile,
",=", -1);
2456 guint toklength = g_strv_length(tokens);
2458 for (loopvar=0; loopvar<toklength; loopvar++)
2461 if (g_strrstr(g_strstrip(tokens[loopvar]),
"DSGPROXY_HOST_TIME_ZONE"))
2463 if ((loopvar+1) < toklength )
2465 g_string_assign(dsgtimezone, g_strstrip(tokens[loopvar+1]));
2479 g_clear_error(&error);
2495 #ifndef CLIENT_XCAL_SERVER
2497 gboolean result = FALSE;
2498 gchar* udhcpcvendorfile = NULL;
2500 result = g_file_get_contents (
"//etc//udhcpc.vendor_specific", &udhcpcvendorfile, NULL, &error);
2501 if (result == FALSE) {
2502 g_warning(
"Problem in reading /etc/udhcpcvendorfile file %s", error->message);
2508 gchar **tokens = g_strsplit_set(udhcpcvendorfile,
" \n\t\b\0", -1);
2509 guint toklength = g_strv_length(tokens);
2511 for (loopvar=0; loopvar<toklength; loopvar++)
2514 if (g_strrstr(g_strstrip(tokens[loopvar]),
"SUBOPTION4"))
2516 if ((loopvar+1) < toklength )
2518 g_string_assign(serial_num, g_strstrip(tokens[loopvar+2]));
2531 g_clear_error(&error);
2539 IARM_Result_t iarmRet = IARM_RESULT_IPCCORE_FAIL;
2540 rc = memset_s(¶m,
sizeof(param), 0,
sizeof(param));
2542 param.
type = mfrSERIALIZED_TYPE_SERIALNUMBER;
2544 if(iarmRet == IARM_RESULT_SUCCESS)
2548 g_message(
" serialized data %s \n",param.
buffer );
2549 g_string_assign(serial_num,param.
buffer);
2554 g_message(
" serialized data is empty \n" );
2561 g_message(
"IARM CALL failed for mfrtype \n");
2576 gboolean result = FALSE;
2577 gchar* etchostsfile = NULL;
2580 if( ipv6Enabled ==
TRUE )
2581 hostsFile=g_strdup(
"//etc//xi-xconf-hosts.list");
2583 hostsFile=g_strdup(
"//etc//hosts");
2584 result = g_file_get_contents (hostsFile, &etchostsfile, NULL, &error);
2585 if (result == FALSE) {
2586 g_warning(
"Problem in reading %s file %s", hostsFile,error->message);
2590 gchar **tokens = g_strsplit_set(etchostsfile,
"\n\0", -1);
2592 guint toklength = g_strv_length(tokens);
2594 if ((toklength > 0) && (strlen(g_strstrip(tokens[0])) > 0) &&
2595 (g_strrstr(g_strstrip(tokens[0]),
"127.0.0.1") == NULL))
2597 g_string_printf(etchosts,
"%s",gwyip->str);
2598 g_string_append_printf(etchosts,
"%s",
" ");
2599 g_string_append_printf(etchosts,
"%s;", g_strstrip(tokens[0]));
2603 g_string_assign(etchosts,
"");
2606 for (loopvar=1; loopvar<toklength; loopvar++)
2610 if (g_strrstr(g_strstrip(tokens[loopvar]),
"127.0.0.1") == NULL)
2612 if (strlen(g_strstrip(tokens[loopvar])) > 0)
2614 g_string_append_printf(etchosts,
"%s",gwyip->str);
2615 g_string_append_printf(etchosts,
"%s",
" ");
2616 g_string_append_printf(etchosts,
"%s;",g_strstrip(tokens[loopvar]));
2629 g_clear_error(&error);
2638 static void uriescape(
unsigned char *instr, GString *outstr)
2641 char unreserved[256] = {0};
2643 for (i = 0; i < 256; ++i)
2645 unreserved[i] = isalnum(i) || i ==
'-' || i ==
'_' || i ==
'.' || i ==
'!' || i ==
'~'
2646 || i ==
'*' || i ==
'\'' || i ==
'(' || i ==
')'
2650 for (; *instr; instr++)
2652 if (unreserved[*instr])
2653 g_string_append_printf(outstr,
"%c",*instr);
2655 g_string_append_printf(outstr,
"%%%02X",*instr);
2662 static void xmlescape(gchar *instr, GString *outstr)
2664 for (; *instr; instr++)
2669 g_string_append_printf(outstr,
"%s",
"&");
2672 g_string_append_printf(outstr,
"%s",
"&guot;");
2675 g_string_append_printf(outstr,
"%s",
"'");
2678 g_string_append_printf(outstr,
"%s",
"<");
2681 g_string_append_printf(outstr,
"%s",
">");
2684 g_string_append_printf(outstr,
"%c",*instr);
2705 if (hostmacaddress != NULL && hostmacaddress->len == 17)
2707 GString* addr = g_string_new(NULL);
2710 for (i = 0; i < hostmacaddress->len; ++i)
2712 if (i != 2 && i != 5 && i != 8 && i != 11 && i != 14 )
2714 addr = g_string_append_c(addr,(hostmacaddress->str)[i]);
2717 return g_string_ascii_up(addr);
2725 static void initIpAddressBufferCVP2(
char *ipAddressBufferCVP2)
2727 int result =
getipaddress(devConf->cvpIf, ipAddressBufferCVP2, FALSE);
2731 fprintf(stderr,
"Could not locate the ipaddress of CVP2 interface %s\n", devConf->cvpIf);
2734 g_message(
"ipaddress of the CVP2 interface %s\n", ipAddressBufferCVP2);
2735 g_string_assign(gwyipCVP2, ipAddressBufferCVP2);
2739 static GString *get_compatible_uis_icon(
int nSize,
int nDepth,
const char * pszImageType,
const char * pszImageExt)
2741 GString * icon = g_string_new(NULL);
2742 g_string_printf(icon,
2744 "<mimetype>image/%s</mimetype>"
2746 "<height>%d</height>"
2747 "<depth>%d</depth> <url>http://syndeo.xcal.tv/app/x2rui/dlna/%s/%s_%d.%s</url>"
2762 static GString *get_compatible_uis_icon_list()
2764 GString * icon1 = get_compatible_uis_icon( 48, 32,
"png",
"png");
2765 GString * icon2 = get_compatible_uis_icon(120, 32,
"png",
"png");
2766 GString * icon3 = get_compatible_uis_icon( 48, 32,
"jpeg",
"jpg");
2767 GString * icon4 = get_compatible_uis_icon(120, 32,
"jpeg",
"jpg");
2769 GString * iconList = g_string_new(NULL);
2770 g_string_printf(iconList,
2783 g_string_free(icon1,
TRUE);
2784 g_string_free(icon2,
TRUE);
2785 g_string_free(icon3,
TRUE);
2786 g_string_free(icon4,
TRUE);
2794 static GString *get_uri_value()
2800 g_get_current_time(&timeval);
2802 double t = timeval.tv_sec + (timeval.tv_usec/1000000.0);
2804 snprintf(udnvalue,25,
"%s%f",
"CVP-",t);
2807 char ipAddressBufferCVP2[INET6_ADDRSTRLEN];
2808 initIpAddressBufferCVP2(ipAddressBufferCVP2);
2811 g_string_printf(trmurlCVP2,
"ws://%s:9988", ipAddressBufferCVP2);
2812 g_string_printf(playbackurlCVP2,
"http://%s:8080/hnStreamStart?deviceId=%s&DTCP1HOST=%s&DTCP1PORT=5000", ipAddressBufferCVP2, recv_id->str, ipAddressBufferCVP2);
2817 if (devConf->uriOverride != NULL)
2818 urilink = devConf->uriOverride;
2820 urilink =
"http://syndeo.xcal.tv/app/x2rui/rui.html";
2827 g_print(
"systemids->str: %s\n", systemids->str);
2828 GString *channelMapId = NULL;
2829 char * pId =
"channelMapId:";
2830 char *pChannelMapId = strstr(systemids->str,pId);
2831 if (pChannelMapId != NULL)
2833 pChannelMapId += strlen(pId);
2834 size_t len = strcspn(pChannelMapId,
";");
2835 channelMapId = g_string_new_len(pChannelMapId, len);
2837 if (channelMapId == NULL)
2838 channelMapId = g_string_new(
"0");
2840 GString *controllerId = NULL;
2841 pId =
"controllerId:";
2842 char *pControllerId = strstr(systemids->str,pId);
2843 if (pControllerId != NULL)
2845 pControllerId += strlen(pId);
2846 size_t len = strcspn(pControllerId,
";");
2847 controllerId = g_string_new_len(pControllerId, len);
2849 if (controllerId == NULL)
2850 controllerId = g_string_new(
"0");
2852 GString *plantId = NULL;
2854 char *pPlantId = strstr(systemids->str,pId);
2855 if (pPlantId != NULL)
2857 pPlantId += strlen(pId);
2858 size_t len = strcspn(pPlantId,
";");
2859 plantId = g_string_new_len(pPlantId, len);
2861 if (plantId == NULL)
2862 plantId = g_string_new(
"0");
2864 GString *vodServerId = NULL;
2865 pId =
"vodServerId:";
2866 char *pVodServerId = strstr(systemids->str,pId);
2867 if (pVodServerId != NULL)
2869 pVodServerId += strlen(pId);
2870 size_t len = strcspn(pVodServerId,
";");
2871 vodServerId = g_string_new_len(pVodServerId, len);
2873 if (vodServerId == NULL)
2874 vodServerId = g_string_new(
"0");
2877 if (eSTBMAC == NULL)
2879 eSTBMAC = g_string_new(
"UNKNOWN");
2883 gchar* gw_value= g_strconcat(
2885 "\"deviceType\":\"DMS\","
2886 "\"friendlyName\":\"" ,getGatewayName(),
"\","
2887 "\"receiverID\":\"" ,recv_id->str,
"\","
2888 "\"udn\":\"" ,udnvalue,
"\","
2889 "\"gatewayIP\":\"" ,gwyipCVP2->str,
"\","
2890 "\"baseURL\":\"" ,playbackurlCVP2->str,
"\","
2891 "\"trmURL\":\"" ,trmurlCVP2->str,
"\","
2892 "\"channelMapId\":\"" ,channelMapId->str,
"\","
2893 "\"controllerId\":\"" ,controllerId->str,
"\","
2894 "\"plantId\":\"" ,plantId->str,
"\","
2895 "\"vodServerId\":\"" ,vodServerId->str,
"\","
2896 "\"eSTBMAC\":\"" ,eSTBMAC->str,
"\""
2899 g_string_free(eSTBMAC,
TRUE);
2900 g_string_free(channelMapId,
TRUE);
2901 g_string_free(controllerId,
TRUE);
2902 g_string_free(plantId,
TRUE);
2903 g_string_free(vodServerId,
TRUE);
2908 GString *gwescapededstr = g_string_sized_new(strlen(gw_value) * 3);
2910 uriescape(gw_value,gwescapededstr);
2916 gchar* uri = g_strconcat( urilink,
"?partner=", getPartnerID(),
"&gw=", gwescapededstr->str, NULL );
2918 g_string_free(gwescapededstr,
TRUE);
2920 GString *xmlescapedstr = g_string_sized_new(strlen(uri) * 2);
2922 xmlescape(uri, xmlescapedstr);
2928 return xmlescapedstr;
2945 if ( ruiurl->str != NULL )
2947 g_string_free( ruiurl,
TRUE);
2950 if (devConf->ruiPath != NULL)
2952 g_print(
"getruiurl using xdevice.conf RuiPath=value\n");
2953 ruiurl = g_string_new(g_strconcat(devConf->ruiPath, NULL));
2958 GString *urivalue = get_uri_value();
2959 GString *iconlist = get_compatible_uis_icon_list();
2962 ruiurl = g_string_new(NULL);
2963 g_string_printf(ruiurl,
2964 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
2965 "<uilist xmlns=\"urn:schemas-upnp-org:remoteui:uilist-1-0\" "
2966 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:schemas-upnp-org:remoteui:uilist-1-0 CompatibleUIs.xsd\">"
2968 "<uiID>1234-9876-1265-8758</uiID>"
2970 "<description>%s</description>"
2973 "<lifetime>-1</lifetime>"
2974 "<protocol shortName=\"DLNA-HTML5-1.0\">"
2982 getServiceDescription(),
2987 g_string_free(urivalue,
TRUE);
2988 g_string_free(iconlist,
TRUE);
2994 static xmlNode * get_node_by_name(xmlNode * node,
const char *node_name)
2996 xmlNode * cur_node = NULL;
2997 xmlNode * ret = NULL;
3001 for (cur_node = node ; cur_node ; cur_node = cur_node->next)
3003 rc = strcmp_s(cur_node->name, strlen(cur_node->name), node_name, &ind);
3005 if ((ind == 0) && (rc == EOK))
3009 ret = get_node_by_name(cur_node->children, node_name);
3026 int set_content(xmlDoc* doc,
const char * node_name,
const char * new_value)
3028 xmlNode * root_element = NULL;
3029 xmlNode * target_node = NULL;
3031 root_element = xmlDocGetRootElement(doc);
3032 target_node = get_node_by_name(root_element, node_name);
3034 if (target_node==NULL)
3036 g_printerr(
"Couldn't locate the Target node\n");
3040 xmlNodeSetContent(target_node,new_value);
3056 xmlNode * root_element = xmlDocGetRootElement(doc);
3057 xmlNode * xml_node = get_node_by_name(root_element, node_name);
3061 g_printerr(
"Couldn't locate the %s node\n", node_name);
3065 return xmlNodeGetContent(xml_node);
3080 ret = xmlReadFile(file_name, NULL, 0);
3094 #define VIDIPATH_FLAG "/opt/vidiPathEnabled"
3096 static int isVidiPathEnabled()
3098 if (access(VIDIPATH_FLAG,F_OK) == 0)
3114 GKeyFile *keyfile = NULL;
3115 GKeyFileFlags flags;
3116 GError *error = NULL;
3120 keyfile = g_key_file_new ();
3121 flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
3124 if (!g_key_file_load_from_file (keyfile, configfile, flags, &error))
3128 g_error (
"%s\n", error->message);
3131 g_clear_error(&error);
3135 g_key_file_free(keyfile);
3139 g_message(
"Starting with Settings %s\n", g_key_file_to_data(keyfile, NULL, NULL));
3157 devConf->bcastIf = g_key_file_get_string (keyfile,
"Network",
"BCastIf", NULL);
3158 devConf->bcastPort = g_key_file_get_integer (keyfile,
"Network",
"BCastPort", NULL);
3159 #ifndef CLIENT_XCAL_SERVER
3160 devConf->streamIf = g_key_file_get_string (keyfile,
"Network",
"StreamIf", NULL);
3161 devConf->trmIf = g_key_file_get_string (keyfile,
"Network",
"TrmIf", NULL);
3162 devConf->gwIf = g_key_file_get_string (keyfile,
"Network",
"GwIf", NULL);
3163 devConf->cvpIf = g_key_file_get_string (keyfile,
"Network",
"CvpIf", NULL);
3164 devConf->cvpPort = g_key_file_get_integer (keyfile,
"Network",
"CvpPort", NULL);
3165 devConf->hostMacIf = g_key_file_get_string (keyfile,
"Network",
"HostMacIf", NULL);
3185 #ifndef CLIENT_XCAL_SERVER
3186 devConf->oemFile = g_key_file_get_string (keyfile,
"DataFiles",
"OemFile", NULL);
3187 devConf->dnsFile = g_key_file_get_string (keyfile,
"DataFiles",
"DnsFile", NULL);
3188 devConf->dsgFile = g_key_file_get_string (keyfile,
"DataFiles",
"DsgFile", NULL);
3189 devConf->diagFile = g_key_file_get_string (keyfile,
"DataFiles",
"DiagFile", NULL);
3190 devConf->devXmlPath = g_key_file_get_string (keyfile,
"DataFiles",
"DevXmlPath", NULL);
3191 devConf->devXmlFile = g_key_file_get_string (keyfile,
"DataFiles",
"DevXmlFile", NULL);
3192 devConf->cvpXmlFile = g_key_file_get_string (keyfile,
"DataFiles",
"CvpXmlFile", NULL);
3193 devConf->logFile = g_key_file_get_string (keyfile,
"DataFiles",
"LogFile", NULL);
3194 devConf->ipv6FileLocation = g_key_file_get_string (keyfile,
"DataFiles",
"Ipv6FileLocation", NULL);
3195 devConf->ipv6PrefixFile = g_key_file_get_string (keyfile,
"DataFiles",
"Ipv6PrefixFile", NULL);
3196 devConf->enableCVP2 = isVidiPathEnabled();
3198 devConf->deviceNameFile = g_key_file_get_string (keyfile,
"DataFiles",
"DeviceNameFile", NULL);
3199 devConf->devPropertyFile = g_key_file_get_string (keyfile,
"DataFiles",
"DevPropertyFile", NULL);
3213 devConf->useIARM = g_key_file_get_boolean (keyfile,
"Flags",
"UseIARM", NULL);
3214 devConf->allowGwy = g_key_file_get_boolean (keyfile,
"Flags",
"AllowGwy", NULL);
3215 #ifndef CLIENT_XCAL_SERVER
3216 devConf->enableCVP2 = isVidiPathEnabled();
3218 devConf->ruiPath = g_key_file_get_string (keyfile,
"Rui",
"RuiPath" , NULL);
3220 if (devConf->ruiPath == NULL )
3222 devConf->uriOverride = g_key_file_get_string (keyfile,
"Rui",
"uriOverride", NULL);
3226 devConf->uriOverride = NULL;
3228 devConf->enableTRM = g_key_file_get_boolean (keyfile,
"Flags",
"EnableTRM", NULL);
3229 devConf->useGliDiag = g_key_file_get_boolean (keyfile,
"Flags",
"UseGliDiag", NULL);
3230 devConf->disableTuneReady = g_key_file_get_boolean (keyfile,
"Flags",
"DisableTuneReady", NULL);
3231 devConf->enableHostMacPblsh = g_key_file_get_boolean (keyfile,
"Flags",
"EnableHostMacPblsh", NULL);
3232 devConf->rmfCrshSupp = g_key_file_get_boolean (keyfile,
"Flags",
"rmfCrshSupp", NULL);
3233 devConf->wareHouseMode = g_key_file_get_boolean (keyfile,
"Flags",
"wareHouseMode", NULL);
3236 g_key_file_free(keyfile);
3237 #ifndef CLIENT_XCAL_SERVER
3238 if ((devConf->bcastIf == NULL)|| (devConf->bcastPort == 0) || (devConf->devXmlPath == NULL) ||
3239 (devConf->devXmlFile == NULL))
3241 g_warning(
"Invalid or no values found for mandatory parameters\n");
3260 gboolean
updatexmldata(
const char* xmlfilename,
const char* struuid,
const char* serialno,
const char* friendlyName)
3268 g_printerr (
"Error reading the Device XML file\n");
3274 g_printerr (
"Error setting the unique device id in conf xml\n");
3277 if (
set_content(doc,
"serialNumber", serialno)!=0)
3279 g_printerr (
"Error setting the serial number in conf xml\n");
3283 if(NULL != friendlyName)
3285 if (
set_content(doc,
"friendlyName", friendlyName)!=0)
3287 g_printerr (
"Error setting the friendlyName number in conf xml\n");
3293 g_printerr (
"friendlyName is NULL\n");
3296 FILE *fp = fopen(xmlfilename,
"w");
3300 g_printerr (
"Error opening the conf xml file for writing\n");
3303 else if (xmlDocFormatDump(fp, doc, 1) == -1)
3305 g_printerr (
"Could not write the conf to xml file\n");
3326 if ((service_ready==FALSE) || (!upnpService))
3328 g_warning(
"Received notificaton before start of Service");
3333 GValue value = G_VALUE_INIT;
3334 g_value_init(&value, G_TYPE_STRING);
3335 g_value_set_static_string(&value, strvalue);
3336 g_message(
"Sending value change notification Name %s - Value: %s", varname, strvalue);
3337 gupnp_service_notify_value(upnpService, varname, &value);
3353 if ((service_ready==FALSE) || (!upnpService))
3355 g_warning(
"Received notificaton before start of Service");
3359 GValue value = G_VALUE_INIT;
3360 g_value_init(&value, G_TYPE_INT);
3361 g_value_set_int(&value, intvalue);
3362 g_message(
"Sending value change notification Name %s - Value: %d", varname, intvalue);
3363 gupnp_service_notify_value(upnpService, varname, &value);
3381 gboolean isalphanum =
TRUE;
3382 for (i = 0; i < strlen(str); i++) {
3383 if (!g_ascii_isalnum(str[i])) {
3399 gboolean
is_num(
const gchar *str)
3403 gboolean isnum =
TRUE;
3404 for (i = 0; i < strlen(str); i++) {
3405 if (!g_ascii_isdigit(str[i])) {
3427 gboolean isDevIdPresent=FALSE;
3430 GString* jsonData=g_string_new(NULL);
3431 GString* value=g_string_new(NULL);
3435 #if defined(USE_XUPNP_IARM_BUS)
3436 if(( devConf->wareHouseMode ==
TRUE ) || (IARM_BUS_SYS_MODE_WAREHOUSE == sysModeParam))
3438 const gchar* bcastmac=(gchar*)
getmacaddress(devConf->bcastIf);
3439 g_string_assign(value, bcastmac);
3440 g_message(
"In WareHouse Mode recvid %s bcastmac %s \n ",recv_id->str,bcastmac);
3443 #endif //#if defined(USE_XUPNP_IARM_BUS)
3446 if((fp = v_secure_popen(
"r", GET_DEVICEID_SCRIPT)))
3448 char response[1024] = {0};
3449 fread(response, 1,
sizeof(response)-1, fp);
3450 int ret = v_secure_pclose(fp);
3452 g_message(
"Error in closing pipe ! : %d \n", ret);
3454 if ((response[0] ==
'\0') && (counter < MAX_DEBUG_MESSAGE))
3457 g_message(
"No Json string found in Auth url %s \n" ,response);
3461 g_string_assign(jsonData,response);
3462 gchar **tokens = g_strsplit_set(jsonData->str,
"{}:,\"", -1);
3463 guint tokLength = g_strv_length(tokens);
3465 for (loopvar=0; loopvar<tokLength; loopvar++)
3467 if (g_strrstr(g_strstrip(tokens[loopvar]),
id))
3470 if ((loopvar+3) < tokLength )
3472 g_string_assign(value, g_strstrip(tokens[loopvar+3]));
3473 if(value->str[0] !=
'\0')
3475 isDevIdPresent=
TRUE;
3483 if (g_strrstr(
id,PARTNER_ID))
3485 g_message(
"%s not found in Json string in Auth url %s \n ",
id,jsonData->str);
3488 if (counter < MAX_DEBUG_MESSAGE )
3491 g_message(
"%s not found in Json string in Auth url %s \n ",
id,jsonData->str);
3497 g_message(
"Successfully fetched %s %s \n ",
id,value->str);
3506 g_message(
"The deviceId script %s can't be executed\n", GET_DEVICEID_SCRIPT);
3511 g_string_free(jsonData,
TRUE);
3527 gboolean result = FALSE;
3528 gchar* devfilebuffer = NULL;
3531 if (deviceFile == NULL)
3533 g_message(
"device properties file not found");
3537 result = g_file_get_contents (deviceFile, &devfilebuffer, NULL, &error);
3538 if (result == FALSE)
3540 g_message(
"No contents in device properties");
3546 gchar **tokens = g_strsplit_set(devfilebuffer,
",='\n'", -1);
3547 guint toklength = g_strv_length(tokens);
3549 for (loopvar=0; loopvar<toklength; loopvar++)
3551 if (g_strrstr(g_strstrip(tokens[loopvar]),
"RECEIVER_DEVICETYPE"))
3553 if ((loopvar+1) < toklength )
3556 g_string_assign(recvdevtype, g_strstrip(tokens[loopvar+1]));
3564 else if(g_strrstr(g_strstrip(tokens[loopvar]),
"BUILD_VERSION"))
3566 if ((loopvar+1) < toklength )
3569 g_string_assign(buildversion, g_strstrip(tokens[loopvar+1]));
3577 else if(g_strrstr(g_strstrip(tokens[loopvar]),
"BOX_TYPE"))
3579 if ((loopvar+1) < toklength )
3582 g_string_assign(devicetype, g_strstrip(tokens[loopvar+1]));
3590 if (g_strrstr(g_strstrip(tokens[loopvar]),
"MOCA_INTERFACE"))
3592 if ((loopvar+1) < toklength )
3595 g_string_assign(mocaIface, g_strstrip(tokens[loopvar+1]));
3603 if (g_strrstr(g_strstrip(tokens[loopvar]),
"WIFI_INTERFACE"))
3605 if ((loopvar+1) < toklength )
3608 g_string_assign(wifiIface, g_strstrip(tokens[loopvar+1]));
3623 g_message(
"RECEIVER_DEVICETYPE and BUILD_VERSION not found in %s",deviceFile);
3629 g_clear_error(&error);
3642 if ((g_strcmp0(g_strstrip(dsgtimezone->str),
"US/Mountain") == 0) && (dstOffset == 0))
3644 g_string_assign(dsgtimezone,
"US/Arizona");
3645 g_message(
"XUPnP: changing timezone timezone= %s dst offset = %d \n",dsgtimezone->str,dstOffset);
3647 else if ((g_strcmp0(g_strstrip(dsgtimezone->str),
"US/Central") == 0) && (dstOffset == 0))
3649 g_string_assign(dsgtimezone,
"Canada/Saskatchewan");
3650 g_message(
"XUPnP: changing timezone timezone= %s dst offset = %d \n",dsgtimezone->str,dstOffset);
3669 gboolean result = FALSE;
3670 gchar* prefixfile = NULL;
3672 guint prefixloopvar=0;
3673 gboolean ifacematch = FALSE;
3674 gboolean prefixmatch = FALSE;
3675 gchar **prefixtokens;
3676 if (devConf->ipv6PrefixFile == NULL)
3678 g_warning(
"ipv6PrefixFile file name not found in config");
3681 result = g_file_get_contents (devConf->ipv6PrefixFile, &prefixfile, NULL, &error);
3682 if (result == FALSE) {
3683 g_warning(
"Problem in reading /prefix/prefix file %s", error->message);
3687 gchar **tokens = g_strsplit_set(prefixfile,
"'\n''\0'", -1);
3688 guint toklength = g_strv_length(tokens);
3690 while(loopvar < toklength)
3692 if(ifacematch==FALSE)
3694 if ((g_strrstr(g_strstrip(tokens[loopvar]),
"ifacename")) && (g_strrstr(g_strstrip(tokens[loopvar]), devConf->hostMacIf)))
3701 if(g_strrstr(g_strstrip(tokens[loopvar]),
"AddrPrefix"))
3703 prefixtokens = g_strsplit_set(tokens[loopvar],
"'<''>''='", -1);
3704 guint prefixtoklength = g_strv_length(prefixtokens);
3705 while(prefixloopvar<prefixtoklength)
3707 if(g_strrstr(g_strstrip(prefixtokens[prefixloopvar]),
"/AddrPrefix"))
3712 g_string_printf(ipv6prefix,
"%s",prefixtokens[prefixloopvar-1]);
3713 g_message(
"ipv6 prefix format in the file %s",prefixtokens[prefixloopvar-1]);
3718 g_strfreev(prefixtokens);
3720 if(prefixmatch ==
TRUE)
3727 if(prefixmatch == FALSE)
3730 g_message(
"No Matching ipv6 prefix in file %s",prefixfile);
3736 g_clear_error(&error);
3751 gboolean result = FALSE;
3752 gchar* devicenamefile = NULL;
3754 gboolean devicenamematch = FALSE;
3755 if (devConf->deviceNameFile == NULL)
3757 g_warning(
"device name file name not found in config");
3760 result = g_file_get_contents (devConf->deviceNameFile, &devicenamefile, NULL, &error);
3761 if (result == FALSE) {
3762 g_warning(
"Problem in reading /devicename/devicename file %s", error->message);
3766 gchar **tokens = g_strsplit_set(devicenamefile,
"'=''\n''\0'", -1);
3767 guint toklength = g_strv_length(tokens);
3769 while(loopvar < toklength)
3771 if (g_strrstr(g_strstrip(tokens[loopvar]),
"deviceName"))
3774 g_string_printf(devicename,
"%s",g_strstrip(tokens[loopvar+1]));
3775 g_message(
"device name = %s",devicename->str);
3776 devicenamematch=
TRUE;
3783 if(devicenamematch == FALSE)
3785 g_message(
"No Matching devicename in file %s",devicenamefile);
3791 g_clear_error(&error);
3793 g_free(devicenamefile);