26 #include <libgupnp/gupnp-control-point.h>
29 #include <libgssdp/gssdp.h>
31 #include <arpa/inet.h>
32 #include <sys/ioctl.h>
40 #include "xdiscovery_private.h"
41 #include "secure_wrapper.h"
42 #include <glib/gprintf.h>
44 #include <glib/gstdio.h>
45 #ifdef INCLUDE_BREAKPAD
46 #include "breakpad_wrapper.h"
53 #include <platform_hal.h>
55 #if defined(CLIENT_XCAL_SERVER) && !defined(BROADBAND)
58 int gatewayDetected=0;
59 gboolean partialDiscovery=FALSE;
60 #include "rdk_safeclib.h"
63 #include "rdk_logger_milestone.h"
67 #include <syscfg/syscfg.h>
69 #include <libsoup/soup.h>
71 #ifdef GUPNP_GENERIC_MEDIA_RENDERER
72 #include "mediabrowser_private.h"
73 #endif //GUPNP_GENERIC_MEDIA_RENDERER
75 #define OUTPLAYURL_SIZE 180 //current max size of playbackurl with ocap locator is 145 adding few more just to accomdate future increase in receiver id or ipv6.
77 #define DEVICE_PROTECTION_CONTEXT_PORT 50760
79 #define ACCOUNTID_SIZE 30
81 #define MILESTONE_LOG_FILENAME "/opt/logs/rdk_milestones.log"
87 const char* localHostIP=
"127.0.0.1";
88 static int rfc_enabled ;
89 #if !defined(BROADBAND)
90 #define RESTART_XDISCOVERY_FILE "/tmp/restartedXdiscovery"
94 #define WEBGUI_VIDEO_ANAL_FILE "/tmp/videoanalytic_started"
97 static GMainLoop *main_loop;
98 gboolean checkDevAddInProgress=FALSE;
99 #define WAIT_TIME_SEC 5
100 #define PNAME "/tmp/xpki_cert"
102 #define SHM_EXISTS 17
104 int getSoupStatusFromUrl(
char* url);
106 #ifdef SAFEC_DUMMY_API
108 errno_t strcmp_s(
const char * d,
int max ,
const char * src,
int *r)
114 char *cert_File=NULL;
116 char *ca_File=
"/tmp/UPnP_CA";
117 char accountId[ACCOUNTID_SIZE]={
'\0',};
123 DEF_FIFO(dp_wlist_fifo,MAX_OVERFLOW,
unsigned int);
124 dp_wlist_t *dp_wlist=NULL;
125 dp_wlist_ss_t dpnode_insert(
long ipaddr,
char *macaddr);
128 typedef GTlsInteraction XupnpTlsInteraction;
129 typedef GTlsInteractionClass XupnpTlsInteractionClass;
130 static void xupnp_tls_interaction_init (XupnpTlsInteraction *interaction);
131 static void xupnp_tls_interaction_class_init (XupnpTlsInteractionClass *xupnpClass);
132 static gboolean getAccountId(
char *outValue);
135 GType xupnp_tls_interaction_get_type (
void);
136 G_DEFINE_TYPE (XupnpTlsInteraction, xupnp_tls_interaction, G_TYPE_TLS_INTERACTION);
139 void dp_signal_handlr(
int sig)
143 if (dp_wlist && (shmId > 0))
145 shmdt((
void *) dp_wlist);
146 shmctl(shmId, IPC_RMID, NULL);
155 unsigned short dp_hashindex (
long ipaddr)
159 ret =(ipaddr & 0x3FF) + ((ipaddr >> 10)&0x3FF) + ((ipaddr >> 20)&0x3FF)
160 + ((ipaddr >> 30) & 0x3FF);
161 ret = ((ret & 0x3FF) + ((ret >> 10) && 0x3FF)) &0x3FF;
178 signal(SIGHUP,dp_signal_handlr);
179 signal(SIGINT,dp_signal_handlr);
180 signal(SIGQUIT,dp_signal_handlr);
181 signal(SIGABRT,dp_signal_handlr);
182 signal(SIGTSTP,dp_signal_handlr);
183 signal(SIGKILL,dp_signal_handlr);
186 if ((key = ftok(PNAME, PID)) != (key_t) -1) {
200 shmId = shmget(key, MAX_BUF_SIZE*
sizeof(dp_wlist_t),
201 S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH|IPC_CREAT);
205 g_message(
"dp_wlistInit:dp list creation, shared memory failure %d %s\n",
206 errno, strerror(errno));
207 if (errno != SHM_EXISTS) {
208 dp_wlist = (
void *) -1;
211 shmId = shmget(key, MAX_BUF_SIZE*
sizeof(dp_wlist_t), S_IRUSR|S_IRGRP|S_IROTH);
213 g_message(
"dp_wlistInit:shmget failure %d %s\n", errno, strerror(errno));
214 dp_wlist = (
void *) -1;
219 dp_wlist = (dp_wlist_t *) shmat(shmId, 0, 0);
220 if (dp_wlist == (
void *) -1)
222 g_message(
"dp_wlistInit: shared memory attach failed errno %d %s\n",
223 errno, strerror(errno));
229 for (i=MAX_ENTRIES; i<MAX_BUF_SIZE; i++)
231 ENQUEUE_FIFO(dp_wlist_fifo, i, fstat);
232 if (fstat== FIFO_FULL)
239 for (i=0; i<MAX_BUF_SIZE; i++)
244 dp_wlist[i].ofb_index=(short ) -1;
249 dp_wlist = (
void *) -1;
271 short dpnode_lookup(
long ipaddr,
char MAC[], dp_wlist_ss_t *stat,
272 unsigned short *lastnode)
276 if (dp_wlist == (
void *) -1)
return (DP_WLIST_ERROR);
277 index = dp_hashindex(ipaddr);
279 if (dp_wlist[index].ofb_index == (
short) -1)
return -1;
282 if (dp_wlist[index].ipaddr == ipaddr)
284 if (!strncmp(MAC, dp_wlist[index].macaddr, MAC_ADDRESS_SIZE))
290 *stat = DP_INVALID_MAC;
298 while (dp_wlist[index].ofb_index > 0)
301 index = dp_wlist[index].ofb_index;
302 if (dp_wlist[index].ipaddr == ipaddr)
304 if (!strncmp(MAC, dp_wlist[index].macaddr,
307 *stat = DP_COLLISION;
312 *stat = DP_INVALID_MAC;
317 *stat = DP_COLLISION;
336 dp_wlist_ss_t dpnode_insert(
long ipaddr,
char *macaddr)
339 dp_wlist_ss_t ret=DP_SUCCESS;
343 if (dp_wlist == (
void *) -1)
return (DP_WLIST_ERROR);;
344 if ((index = dpnode_lookup(ipaddr, macaddr, &stat,&pindex)) == (
short) -1)
347 if (stat == DP_COLLISION)
351 DEQUEUE_FIFO(dp_wlist_fifo, index, fret);
354 g_message(
"dpnode_insert:collsion ip:%lu mac:%s hash index %d\n",ipaddr, macaddr, index);
355 dp_wlist[pindex].ofb_index = index;
356 dp_wlist[index].ipaddr = ipaddr;
357 strncpy(dp_wlist[index].macaddr, macaddr, MAC_ADDRESS_SIZE);
358 dp_wlist[index].ofb_index = 0;
364 index = dp_hashindex (ipaddr);
365 g_message(
"dpnode_insert:new ip:%lu mac:%s hash index %d\n",ipaddr, macaddr, index);
366 dp_wlist[index].ipaddr = ipaddr;
367 strncpy(dp_wlist[index].macaddr, macaddr,MAC_ADDRESS_SIZE);
368 dp_wlist[index].ofb_index = 0;
374 if (stat == DP_INVALID_MAC)
376 g_message(
"dpnode_insert:mac update ip:%lu mac:%s hash index %d\n",ipaddr, macaddr, index);
378 strncpy(dp_wlist[index].macaddr, macaddr,MAC_ADDRESS_SIZE);
381 ret = DP_WLIST_ERROR;
396 void dpnode_delete(
long ipaddr,
char *macaddr)
400 unsigned short index, pindex, tindex;
402 if (((index = dpnode_lookup(ipaddr, macaddr, &stat, &pindex)) >= 0) && (index != DP_WLIST_ERROR))
405 if (index < MAX_ENTRIES )
409 if (dp_wlist[index].ofb_index ==0)
412 g_message(
"No Collision ip:%lu mac:%s \n",ipaddr, macaddr);
413 dp_wlist[index].ofb_index =-1;
414 dp_wlist[index].ipaddr = 0;
421 g_message(
"Collision ip:%lu mac:%s \n",ipaddr, macaddr);
422 tindex = dp_wlist[index].ofb_index;
423 dp_wlist[index].ofb_index = dp_wlist[tindex].ofb_index;
424 dp_wlist[index].ipaddr = dp_wlist[tindex].ipaddr;
425 strncpy(dp_wlist[index].macaddr, dp_wlist[tindex].macaddr,MAC_ADDRESS_SIZE);
426 dp_wlist[tindex].ofb_index=-1;
427 dp_wlist[tindex].ipaddr=0;
428 ENQUEUE_FIFO(dp_wlist_fifo, tindex, ret);
434 dp_wlist[pindex].ofb_index = dp_wlist[index].ofb_index;
435 dp_wlist[index].ofb_index=-1;
436 dp_wlist[index].ipaddr=0;
437 ENQUEUE_FIFO(dp_wlist_fifo, index, ret);
444 static void addRouteToMocaBridge(
char *subnetip)
447 ret = v_secure_system(
"/etc/Xupnp/addRouteToMocaBridge.sh %s &",subnetip );
449 g_message(
"Failure in executing command via v_secure_system. ret val : %d \n", ret);
454 xupnp_tls_interaction_init (XupnpTlsInteraction *interaction)
458 static GTlsInteractionResult
459 xupnp_tls_interaction_request_certificate (GTlsInteraction *interaction,
460 GTlsConnection *connection,
461 GTlsCertificateRequestFlags flags,
462 GCancellable *cancellable,
465 GTlsCertificate *cert;
466 GError *xupnp_error = NULL;
468 if ((cert_File == NULL) || (key_File == NULL) ) {
470 g_message(
" Certificate or Key file NULL");
471 return G_TLS_INTERACTION_FAILED;
474 cert = g_tls_certificate_new_from_files (cert_File,
477 g_assert_no_error (xupnp_error);
479 g_tls_connection_set_certificate (connection, cert);
480 g_object_unref (cert);
482 return G_TLS_INTERACTION_HANDLED;
486 xupnp_tls_interaction_class_init (XupnpTlsInteractionClass *xupnpClass)
488 GTlsInteractionClass *interaction_class = G_TLS_INTERACTION_CLASS (xupnpClass);
490 interaction_class->request_certificate = xupnp_tls_interaction_request_certificate;
494 gboolean getAccountId(
char *outValue)
496 char temp[ACCOUNTID_SIZE] = {0};
498 rc = syscfg_get(NULL,
"AccountID", temp,
sizeof(temp));
501 if ((outValue != NULL))
503 strncpy(outValue, temp, ACCOUNTID_SIZE-1);
509 g_message(
"getAccountId: Unable to get the Account Id");
514 gboolean getAccountId(
char *outValue)
516 gboolean result = FALSE;
518 RFC_ParamData_t param = {0};
520 WDMP_STATUS status = getRFCParameter(
"XUPNP",
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AccountInfo.AccountID",¶m);
522 if (status == WDMP_SUCCESS)
524 if (((param.value == NULL)))
526 g_message(
"getAccountId : NULL string !");
531 if (strncpy(outValue,param.value, ACCOUNTID_SIZE-1))
539 g_message(
"getAccountId: getRFCParameter Failed : %s\n", getRFCErrorString(status));
542 g_message(
"Not built with RFC support.");
548 gboolean selfDeviceDiscovered=FALSE;
549 gboolean bSerialNum=FALSE;
551 #if defined(USE_XUPNP_IARM) || defined(USE_XUPNP_IARM_BUS)
553 typedef struct _iarmDeviceData {
554 unsigned long bufferLength;
559 #define WAIT_TIME_SEC 5
560 #ifdef USE_XUPNP_IARM
562 static void *gCtx = NULL;
563 static void _GetXUPNPDeviceInfo(
void *callCtx,
unsigned long methodID,
void *arg,
unsigned int serial);
566 #include "libIARMCore.h"
568 IARM_Result_t _GetXUPNPDeviceInfo(
void *arg);
572 static IARM_Result_t GetXUPNPDeviceInfo(
char *pDeviceInfo,
unsigned long length)
574 g_mutex_lock(devMutex);
575 g_message(
"<<<<<<<IARM XUPnP Call Reached API Processor - length: %ld Output Data length: %d>>>>>>>>", length, outputcontents->len);
578 if (outputcontents->len <= length)
581 g_message(
"Output string is\n %s\nAddress of received memory is %p", outputcontents->str, pDeviceInfo);
583 strncpy (pDeviceInfo, outputcontents->str, outputcontents->len+1);
584 g_mutex_unlock(devMutex);
585 g_message(
"<<<<<<<IARM XUPnP Call Returned success from API Processor>>>>>>>>");
586 return IARM_RESULT_SUCCESS;
591 g_mutex_unlock(devMutex);
592 g_message(
"<<<<<<<IARM XUPnP Call Returned failure from API Processor>>>>>>>>");
593 return IARM_RESULT_INVALID_STATE;
601 static void notifyXUPnPDataUpdateEvent(
int eventId)
603 #ifdef USE_XUPNP_IARM
604 g_message(
"<<<<<<<IARM XUPnP Posted update request>>>>>>>>");
605 UIDev_EventData_t eventData;
606 eventData.id = eventId;
612 g_mutex_lock(devMutex);
613 eventData.data.xupnpData.deviceInfoLength = outputcontents->len+1;
614 g_mutex_unlock(devMutex);
615 UIDev_PublishEvent(eventId, &eventData);
619 g_mutex_lock(devMutex);
620 eventData.data.xupnpData.deviceInfoLength = outputcontents->len+1;
621 g_mutex_unlock(devMutex);
622 g_message(
"<<<<<<<IARM XUPnP Posted update request with Length %ld>>>>>>>>",eventData.data.xupnpData.deviceInfoLength);
628 #ifdef USE_XUPNP_IARM
637 void _evtHandler(
int eventId,
void *eventData)
650 void _evtHandler(
const char *owner, IARM_EventId_t eventId,
void *data,
size_t len)
653 g_message(
"<<<<<<<IARM XUPnP Received update request>>>>>>>>");
654 #ifdef USE_XUPNP_IARM
655 UIDev_EventData_t *evt = eventData;
656 if (eventId == UIDEV_EVENT_XUPNP_DATA_REQUEST)
658 notifyXUPnPDataUpdateEvent(UIDEV_EVENT_XUPNP_DATA_UPDATE);
666 if((ind == 0) && (rc == EOK))
689 gboolean XUPnP_IARM_Init(
void)
691 g_message(
"<<<<< Iniializing IARM XUPnP >>>>>>>>");
693 #ifdef USE_XUPNP_IARM
696 g_message(
"<<<<<<<IARM XUPnP Init Done>>>>>>>>");
697 if (UIDev_GetContext(&gCtx) == IARM_RESULT_SUCCESS) {
698 g_message(
"<<<<<<<IARM XUPnP Got the context>>>>>>>");
699 IARM_RegisterCall(gCtx,
"UIMgr",
"GetXUPNPDeviceInfo", _GetXUPNPDeviceInfo, NULL);
700 UIDev_RegisterEventHandler(UIDEV_EVENT_XUPNP_DATA_REQUEST, _evtHandler);
701 g_message(
"<<<<<<<IARM XUPnP Registered the events>>>>>>>>");
711 g_message(
"<<<<<<<%s - Failed in IARM Bus IARM_Bus_Init>>>>>>>>",__FUNCTION__);
716 g_message(
"<<<<<<<%s - Failed in IARM_Bus_Connect>>>>>>>>",__FUNCTION__);
723 g_message(
"<<<<<<<%s - Registered the BUS Events >>>>>>>>",__FUNCTION__);
730 #ifdef USE_XUPNP_IARM
731 static void _GetXUPNPDeviceInfo(
void *callCtx,
unsigned long methodID,
void *arg,
unsigned int serial)
733 IARM_Result_t _GetXUPNPDeviceInfo(
void *arg)
736 g_message(
"<<<<<<<IARM XUPnP API Call received>>>>>>>>");
739 #ifdef USE_XUPNP_IARM
740 IarmDeviceData *param = (IarmDeviceData *)arg;
741 g_message(
"Address of received memory is %p - Call 0", param->pBuffer);
742 IARM_Result_t ret = GetXUPNPDeviceInfo(param->pBuffer, param->bufferLength);
743 IARM_CallReturn(gCtx,
"UIMgr",
"GetXUPNPDeviceInfo", ret, serial);
750 IARM_Result_t retCode = IARM_RESULT_SUCCESS;
752 retCode = IARM_Malloc(IARM_MEMTYPE_PROCESSSHARE,param->
bufLength, &(param->
pBuffer));
753 g_message(
"Address of received memory is %p - Call 0", param->
pBuffer);
754 if(IARM_RESULT_SUCCESS == retCode)
761 g_mutex_unlock(mutex);
763 return IARM_RESULT_SUCCESS;
766 #endif //#if defined(USE_XUPNP_IARM) || defined(USE_XUPNP_IARM_BUS)
774 RFC_ParamData_t param = {0};
776 WDMP_STATUS status = getRFCParameter(
"XUPNP",
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.UPnPxPKI.Enable",¶m);
778 if (status == WDMP_SUCCESS)
780 rc = strcmp_s(param.value,
sizeof(param.value),
"true",&ind);
781 if ((ind == 0) && (rc == EOK))
783 g_message(
"New Device xPKI rfc_enabled and xdiscovery is running with new certs");
788 g_message(
"Running device protection with old certs");
793 g_message(
"getRFCParameter Failed : %s", getRFCErrorString(status));
796 g_message(
"Not built with RFC support.");
806 RFC_ParamData_t param = {0};
808 WDMP_STATUS status = getRFCParameter(
"XUPNP",
"Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.UPnP.Refactor.Enable",¶m);
810 if (status == WDMP_SUCCESS)
812 if (!strncmp(param.value,
"true", strlen(
"true")))
814 g_message(
"New Device Refactoring rfc_enabled");
819 g_message(
"Running older xdiscovery");
824 g_message(
"getRFCParameter Failed : %s", getRFCErrorString(status));
827 g_message(
"Not built with RFC support.");
834 if (!syscfg_get(NULL,
"Refactor", temp,
sizeof(temp)) )
836 rc = strcmp_s(
"true", strlen(
"true"), temp, &ind);
838 if((ind == 0) && (rc == EOK))
860 const gchar *message, gpointer user_data)
865 g_get_current_time(&timeval);
866 if (logoutfile == NULL)
869 g_print (
"g_time_val_to_iso8601(&timeval): %s\n", message);
873 date_str = g_time_val_to_iso8601 (&timeval);
874 g_fprintf (logoutfile,
"%s : %s\n", date_str, message);
886 if (g_strcmp0(g_strstrip(gwData->serial_num->str),g_strstrip((gchar *)sno)) == 0)
895 if (g_strcmp0(g_strstrip(gwData->receiverid->str),g_strstrip((gchar *)udn)) == 0)
904 gint result = g_strcmp0(g_strstrip(gwData1->serial_num->str),g_strstrip(gwData2->serial_num->str));
921 gboolean retval = FALSE;
923 if (g_list_length(xdevlist) > 0)
925 GList *element = NULL;
926 element = g_list_first(xdevlist);
929 gint result = g_strcmp0(g_strstrip((gchar *)(((
GwyDeviceData *)element->data)->serial_num->str)),g_strstrip((gchar *)sno));
936 rc = strcpy_s(outPlayUrl, OUTPLAYURL_SIZE, g_strstrip(((
GwyDeviceData *)element->data)->playbackurl->str));
946 strcat(outPlayUrl,
"&live=ocap://0xffff");
959 element = g_list_next(element);
968 device_proxy_unavailable_cb (GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
970 char gwyPlayUrl[OUTPLAYURL_SIZE]={
'\0'};
971 const gchar* sno = gupnp_device_info_get_serial_number (GUPNP_DEVICE_INFO (dproxy));
973 g_message (
"In unavailable_cb Device %s went down",sno);
975 if((g_strcmp0(g_strstrip(ownSerialNo->str),sno) == 0))
977 g_message (
"Self Device [%s][%s] not removing",sno,ownSerialNo->str);
978 g_free((gpointer)sno);
981 GUPnPServiceInfo *sproxy = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE);
983 if (gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)sproxy) ==
TRUE)
985 g_message(
"Removing notifications on %s", sno);
986 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)sproxy, FALSE);
987 gupnp_service_proxy_remove_notify((GUPnPServiceProxy *)sproxy,
"PlaybackUrl", on_last_change, NULL);
988 gupnp_service_proxy_remove_notify((GUPnPServiceProxy *)sproxy,
"SystemIds", on_last_change, NULL);
993 if(gwyPlayUrl[0] !=
'\0')
995 if (getSoupStatusFromUrl(gwyPlayUrl))
997 g_message(
"Network Multicast issue for device %s",sno);
998 g_free((gpointer)sno);
999 g_object_unref(sproxy);
1004 g_message(
"Can't reach device %s",sno);
1009 g_message(
"GW playback url is NULL");
1014 g_message(
"%s found, but unable to delete it from list", sno);
1018 g_message(
"Deleted %s from list", sno);
1022 g_free((gpointer)sno);
1023 g_object_unref(sproxy);
1027 device_proxy_unavailable_cb_client (GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
1029 const gchar* sno = gupnp_device_info_get_serial_number (GUPNP_DEVICE_INFO (dproxy));
1031 g_message (
"In unavailable_client Device %s went down",sno);
1032 if((g_strcmp0(g_strstrip(ownSerialNo->str),sno) == 0))
1034 g_message (
"Self Device [%s][%s] not removing",sno,ownSerialNo->str);
1035 g_free((gpointer)sno);
1038 GUPnPServiceInfo *sproxy = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_MEDIA);
1039 if (gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)sproxy) ==
TRUE)
1041 g_message(
"Removing notifications on %s", sno);
1042 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)sproxy, FALSE);
1046 g_message(
"%s found, but unable to delete it from list", sno);
1050 g_message(
"Deleted %s from list", sno);
1053 g_free((gpointer)sno);
1054 g_object_unref(sproxy);
1058 device_proxy_unavailable_cb_gw (GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
1060 const gchar* sno = gupnp_device_info_get_serial_number (GUPNP_DEVICE_INFO (dproxy));
1061 char gwyPlayUrl[OUTPLAYURL_SIZE]={0};
1062 g_message (
"In unavailable_gw Device %s went down",sno);
1063 if((g_strcmp0(g_strstrip(ownSerialNo->str),sno) == 0))
1065 g_message (
"Self Device [%s][%s] not removing",sno,ownSerialNo->str);
1066 g_free((gpointer)sno);
1069 GUPnPServiceInfo *sproxy = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_MEDIA);
1070 if (gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)sproxy) ==
TRUE)
1072 g_message(
"Removing notifications on %s", sno);
1073 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)sproxy, FALSE);
1074 gupnp_service_proxy_remove_notify((GUPnPServiceProxy *)sproxy,
"PlaybackUrl", on_last_change, NULL);
1078 if(gwyPlayUrl[0] !=
'\0')
1080 if (getSoupStatusFromUrl(gwyPlayUrl))
1082 g_message(
"Network Multicast issue for device %s",sno);
1083 g_free((gpointer)sno);
1084 g_object_unref(sproxy);
1089 g_message(
"Can't reach device %s",sno);
1094 g_message(
"GW playback url is NULL");
1098 g_message(
"%s found, but unable to delete it from list", sno);
1102 g_message(
"Deleted %s from list", sno);
1106 g_free((gpointer)sno);
1107 g_object_unref(sproxy);
1111 device_proxy_available_cb (GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
1121 g_message(
"Found a new device. deviceAddNo = %u ",deviceAddNo);
1123 if ((NULL==cp) || (NULL==dproxy))
1127 g_message(
"WARNING - Received a null pointer for gateway device device no %u",deviceAddNo);
1132 gchar* upc = gupnp_device_info_get_upc (GUPNP_DEVICE_INFO (dproxy));
1135 rc =strcmp_s(
"10000", strlen(
"10000"), upc, &ind);
1137 if((!ind) && (rc == EOK))
1139 g_message(
"Exiting the device addition as UPC value matched");
1146 gchar* sno = gupnp_device_info_get_serial_number (GUPNP_DEVICE_INFO (dproxy));
1147 GList* xdevlistitem = g_list_find_custom(xdevlist,sno,(GCompareFunc)g_list_find_sno);
1148 if(xdevlistitem!=NULL)
1152 if (
processStringRequest((GUPnPServiceProxy *)gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE),
"GetIpv6Prefix",
"Ipv6Prefix" , &temp, FALSE ))
1154 if(g_strcmp0(g_strstrip(temp),gwdata->ipv6prefix->str) != 0)
1156 g_string_assign(gwdata->ipv6prefix, temp);
1162 g_message(
"Existing as SNO is present in list so no update of devices %s device no %u",sno,deviceAddNo);
1173 g_critical(
"Could not allocate memory for Gwydata. Exiting...");
1177 gwydata->sproxy = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE);
1178 if(!gwydata->sproxy)
1181 g_message(
"Unable to get the services, sproxy null. returning");
1187 g_message(
"Device serial number is %s",sno);
1188 g_string_assign(gwydata->serial_num, sno);
1189 const char* udn = gupnp_device_info_get_udn(GUPNP_DEVICE_INFO (dproxy));
1192 if (g_strrstr(udn,
"uuid:"))
1194 gchar* receiverid = g_strndup(udn+5, strlen(udn)-5);
1197 g_message(
"Device receiver id is %s",receiverid);
1198 g_string_assign(gwydata->receiverid, receiverid);
1207 partialDiscovery=
TRUE;
1208 g_message(
"Exting from device_proxy_available_cb since mandatory paramters are not there device no %u",deviceAddNo);
1213 g_message(
"Device receiver id is NULL");
1217 g_message(
"Device UDN is NULL");
1220 if(g_strrstr(g_strstrip(gwydata->devicetype->str),
"XB") != NULL )
1222 g_message(
"Discovered a XB device");
1224 else if(g_strrstr(g_strstrip(gwydata->devicetype->str),
"XI") == NULL )
1226 g_message(
"Discovered a XG device");
1227 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy,
"PlaybackUrl", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1228 g_message(
"Failed to add url notifications for %s", sno);
1229 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy,
"SystemIds", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1230 g_message(
"Failed to add systemid notifications for %s", sno);
1231 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy,
"DnsConfig", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1232 g_message(
"Failed to add DNS notifications for %s", sno);
1233 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy,
"TimeZone", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1234 g_message(
"Failed to add TimeZone notifications for %s", sno);
1238 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy,
"DataGatewayIPaddress", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1239 g_message(
"Failed to add DataGatewayIPaddress notifications for %s", sno);
1241 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)gwydata->sproxy,
TRUE);
1243 if (gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)gwydata->sproxy) == FALSE)
1245 g_message(
"Failed to register for notifications on %s", sno);
1246 g_clear_object(&(gwydata->sproxy));
1250 g_message(
"Exting from device_proxy_available_cb deviceAddNo = %u",deviceAddNo);
1266 device_proxy_available_cb_client (GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
1268 g_message(
"Found a new Client device. deviceAddNo = %u ",deviceAddNo);
1270 if ((NULL==cp) || (NULL==dproxy))
1273 g_message(
"WARNING - Received a null pointer for client device device no %u",deviceAddNo);
1276 gchar* sno = gupnp_device_info_get_serial_number (GUPNP_DEVICE_INFO (dproxy));
1277 GList* xdevlistitem = g_list_find_custom(xdevlist,sno,(GCompareFunc)g_list_find_sno);
1278 if(xdevlistitem!=NULL)
1281 g_message(
"Existing as client SNO is present in list so no update of devices %s device no %u",sno,deviceAddNo);
1288 gwydata->sproxy_i = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_IDENTITY);
1289 gwydata->sproxy_m = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_MEDIA);
1292 g_message(
"XI device serial number is %s",sno);
1293 g_string_assign(gwydata->serial_num, sno);
1294 const char* udn = gupnp_device_info_get_udn(GUPNP_DEVICE_INFO (dproxy));
1297 if (g_strrstr(udn,
"uuid:"))
1299 gchar* receiverid = g_strndup(udn+5, strlen(udn)-5);
1302 g_message(
"Client device receiver id is %s",receiverid);
1303 g_string_assign(gwydata->receiverid, receiverid);
1305 if(!process_gw_services_identity((GUPnPServiceProxy *)gwydata->sproxy_i, gwydata))
1311 g_message(
"Exting from device_proxy_available_cb_client since mandatory paramters are not there device no %u",deviceAddNo);
1316 g_message(
"Received XI Identity service");
1318 if(!process_gw_services_media_config((GUPnPServiceProxy *)gwydata->sproxy_m, gwydata))
1324 g_message(
"Exting from device_proxy_available_cb_client since mandatory paramters are not there device no %u",deviceAddNo);
1329 g_message(
"Received XI Media Config service");
1330 gwydata->isDevRefactored =
TRUE;
1333 g_message(
"Failed to update gw data into the list");
1334 g_critical(
"Unable to update the Client device-%s in the list",(
char*)gwydata->serial_num);
1341 g_message(
"Client device receiver id is NULL");
1347 g_message(
"Client UDN is NULL");
1350 g_message(
"Discovered a Xi device");
1353 g_message(
"Exting from Device_proxy_available_cb client deviceAddNo = %u",deviceAddNo);
1358 device_proxy_available_cb_gw (GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
1360 g_message(
"In device_proxy_available_cb_gw found a Gateway device. deviceAddNo = %u ",deviceAddNo);
1362 if ((NULL==cp) || (NULL==dproxy))
1365 g_message(
"WARNING - Received a null pointer for gateway device device no %u",deviceAddNo);
1368 gchar* sno = gupnp_device_info_get_serial_number (GUPNP_DEVICE_INFO (dproxy));
1369 GList* xdevlistitem = g_list_find_custom(xdevlist,sno,(GCompareFunc)g_list_find_sno);
1370 if(xdevlistitem!=NULL)
1374 if (
processStringRequest((GUPnPServiceProxy *)gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_GW_CFG),
"GetIpv6Prefix",
"Ipv6Prefix" , &temp, FALSE ))
1376 if(g_strcmp0(g_strstrip(temp),gwdata->ipv6prefix->str) != 0)
1378 g_string_assign(gwdata->ipv6prefix, temp);
1384 g_message(
"Existing available_cb_gw as SNO is present in list so no update of devices %s device no %u",sno,deviceAddNo);
1390 gwydata->sproxy_i = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_IDENTITY);
1391 gwydata->sproxy_m = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_MEDIA);
1392 gwydata->sproxy_t = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_TIME);
1393 gwydata->sproxy_g = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_GW_CFG);
1394 gwydata->sproxy_q = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_QAM_CFG);
1397 g_message(
"In available_cb_gw Gateway device serial number: %s",sno);
1398 g_string_assign(gwydata->serial_num, sno);
1399 const char* udn = gupnp_device_info_get_udn(GUPNP_DEVICE_INFO (dproxy));
1402 if (g_strrstr(udn,
"uuid:"))
1404 gchar* receiverid = g_strndup(udn+5, strlen(udn)-5);
1407 g_message(
"Gateway device receiver id is %s",receiverid);
1408 g_string_assign(gwydata->receiverid, receiverid);
1410 if(!process_gw_services_identity((GUPnPServiceProxy *)gwydata->sproxy_i, gwydata))
1416 partialDiscovery=
TRUE;
1417 g_message(
"Exting from available_cb_gw since mandatory paramters are not there device no %u",deviceAddNo);
1422 g_message(
"Received XI Identity service");
1424 if(!process_gw_services_media_config((GUPnPServiceProxy *)gwydata->sproxy_m, gwydata))
1430 partialDiscovery=
TRUE;
1431 g_message(
"Exting from available_cb_gw since mandatory paramters are not there device no %u",deviceAddNo);
1436 g_message(
"Received XI Media Config service");
1438 if(!process_gw_services_time_config((GUPnPServiceProxy *)gwydata->sproxy_t, gwydata))
1444 partialDiscovery=
TRUE;
1445 g_message(
"Exting from available_cb_gw since mandatory paramters are not there device no %u",deviceAddNo);
1450 g_message(
"Received XI Time Config service");
1452 if(!process_gw_services_gateway_config((GUPnPServiceProxy *)gwydata->sproxy_g, gwydata))
1458 partialDiscovery=
TRUE;
1459 g_message(
"Exting from available_cb_gw since mandatory paramters are not there device no %u",deviceAddNo);
1464 g_message(
"Received XI Gateway Config service");
1466 if(!process_gw_services_qam_config((GUPnPServiceProxy *)gwydata->sproxy_q, gwydata))
1472 partialDiscovery=
TRUE;
1473 g_message(
"Exting from available_cb_gw since mandatory paramters are not there device no %u",deviceAddNo);
1478 g_message(
"Received XI QAM Config service");
1479 gwydata->isDevRefactored =
TRUE;
1482 g_message(
"Failed to update gw data into the list\n");
1483 g_critical(
"Unable to update the gateway-%s in the device list",(
char*)gwydata->serial_num);
1490 g_message(
"In available_cb_gw gateway device receiver id is NULL");
1496 g_message(
"Gateway UDN is NULL");
1499 if(!strcasestr(g_strstrip(gwydata->devicetype->str),
"XI") )
1501 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy_m,
"PlaybackUrl", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1502 g_message(
"Failed to add url notifications for %s", sno);
1503 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy_q,
"SystemIds", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1504 g_message(
"Failed to add systemid notifications for %s", sno);
1505 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy_g,
"DnsConfig", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1506 g_message(
"Failed to add DNS notifications for %s", sno);
1507 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy_t,
"TimeZone", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1508 g_message(
"Failed to add TimeZone notifications for %s", sno);
1509 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy_q,
"VideoBaseUrl", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1510 g_message(
"Failed to add VideoBaseUrl notifications for %s", sno);
1512 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)gwydata->sproxy_m,
TRUE);
1513 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)gwydata->sproxy_t,
TRUE);
1514 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)gwydata->sproxy_g,
TRUE);
1515 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)gwydata->sproxy_q,
TRUE);
1517 if (gupnp_service_proxy_add_notify ((GUPnPServiceProxy *)gwydata->sproxy_m,
"FogTsbUrl", G_TYPE_STRING, on_last_change, NULL) == FALSE)
1518 g_message(
"Failed to add FogTsbUrl notifications for %s", sno);
1520 if ((gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)gwydata->sproxy_m) == FALSE) && (gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)gwydata->sproxy_t) == FALSE) && (gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)gwydata->sproxy_g) == FALSE) && (gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)gwydata->sproxy_q) == FALSE))
1522 g_message(
"Failed to register for notifications on %s", sno);
1523 g_object_unref(gwydata->sproxy_m);
1524 g_object_unref(gwydata->sproxy_t);
1525 g_object_unref(gwydata->sproxy_g);
1526 g_object_unref(gwydata->sproxy_q);
1530 g_message(
"Discovered a XG device");
1531 g_message(
"Exting from device_proxy_available_cb_gateway deviceAddNo = %u",deviceAddNo);
1535 device_proxy_unavailable_cb_bgw (GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
1537 const gchar* sno = gupnp_device_info_get_serial_number (GUPNP_DEVICE_INFO (dproxy));
1538 g_message (
"In unavailable_bgw Device %s went down",sno);
1539 if((g_strcmp0(g_strstrip(ownSerialNo->str),sno) == 0))
1541 g_message (
"Self Device [%s][%s] not removing",sno,ownSerialNo->str);
1542 g_free((gpointer)sno);
1547 g_message(
"%s found, but unable to delete it from list", sno);
1552 g_message(
"Deleted %s from list", sno);
1555 g_free((gpointer)sno);
1559 device_proxy_available_cb_bgw (GUPnPControlPoint *cp, GUPnPDeviceProxy *dproxy)
1561 g_message(
"In available_bgw found a Broadband device. deviceAddNo = %u ",deviceAddNo);
1563 if ((NULL==cp) || (NULL==dproxy))
1566 g_message(
"WARNING - Received a null pointer for broadband device device no %u",deviceAddNo);
1569 gchar* sno = gupnp_device_info_get_serial_number (GUPNP_DEVICE_INFO (dproxy));
1570 GList* xdevlistitem = g_list_find_custom(xdevlist,sno,(GCompareFunc)g_list_find_sno);
1571 if(xdevlistitem!=NULL)
1574 g_message(
"Existing available_cb_bgw as SNO is present in list so no update of devices %s device no %u",sno,deviceAddNo);
1575 g_free((gpointer)sno);
1580 gwydata->sproxy_i = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_IDENTITY);
1581 gwydata->sproxy_t = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_TIME);
1582 gwydata->sproxy_g = gupnp_device_info_get_service(GUPNP_DEVICE_INFO (dproxy), XDISC_SERVICE_GW_CFG);
1585 g_message(
"In available_cb_bgw Broadband device serial number: %s",sno);
1586 g_string_assign(gwydata->serial_num, sno);
1587 const char* udn = gupnp_device_info_get_udn(GUPNP_DEVICE_INFO (dproxy));
1590 if (g_strrstr(udn,
"uuid:"))
1592 gchar* receiverid = g_strndup(udn+5, strlen(udn)-5);
1595 g_message(
"Gateway device receiver id is %s",receiverid);
1596 g_string_assign(gwydata->receiverid, receiverid);
1598 if(!process_gw_services_identity((GUPnPServiceProxy *)gwydata->sproxy_i, gwydata))
1604 g_message(
"Exting from available_cb_bgw since Identity paramters are not there device no %u",deviceAddNo);
1609 g_message(
"Received XI Identity service");
1611 if(!process_gw_services_time_config((GUPnPServiceProxy *)gwydata->sproxy_t, gwydata))
1617 g_message(
"Exting from available_cb_bgw since Time paramters are not there device no %u",deviceAddNo);
1622 g_message(
"Received XI Time Config service");
1624 if(!process_gw_services_gateway_config((GUPnPServiceProxy *)gwydata->sproxy_g, gwydata))
1630 g_message(
"Exting from available_cb_bgw since mandatory paramters are not there device no %u",deviceAddNo);
1635 g_message(
"Received XI Gateway Config service");
1636 gwydata->isDevRefactored =
TRUE;
1639 g_message(
"Failed to update gw data into the list\n");
1640 g_critical(
"Unable to update the gateway-%s in the device list",(
char*)gwydata->serial_num);
1647 g_message(
"In available_cb_bgw gateway device receiver id is NULL");
1653 g_message(
"Gateway UDN is NULL");
1657 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)gwydata->sproxy_i,
TRUE);
1658 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)gwydata->sproxy_t,
TRUE);
1659 gupnp_service_proxy_set_subscribed((GUPnPServiceProxy *)gwydata->sproxy_g,
TRUE);
1661 if ((gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)gwydata->sproxy_i) == FALSE) && (gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)gwydata->sproxy_t) == FALSE) && (gupnp_service_proxy_get_subscribed((GUPnPServiceProxy *)gwydata->sproxy_g) == FALSE))
1663 g_message(
"Failed to register for notifications on %s", sno);
1664 g_object_unref(gwydata->sproxy_i);
1665 g_object_unref(gwydata->sproxy_t);
1666 g_object_unref(gwydata->sproxy_g);
1670 g_message(
"Discovered a XB device");
1671 g_message(
"Exting from device_proxy_available_cb_broadband deviceAddNo = %u",deviceAddNo);
1674 int main(
int argc,
char *argv[])
1677 g_thread_init (NULL);
1680 gboolean ipv6Enabled=FALSE;
1681 gboolean bInterfaceReady=FALSE;
1684 GTlsInteraction *xupnp_tlsinteraction= NULL;
1685 mutex = g_mutex_new ();
1686 devMutex = g_mutex_new ();
1687 cond = g_cond_new ();
1690 #ifdef INCLUDE_BREAKPAD
1691 breakpad_ExceptionHandler();
1695 outputcontents = g_string_new(NULL);
1696 ipMode = g_string_new(
"ipv4");
1698 ownSerialNo=g_string_new(NULL);
1701 fprintf(stderr,
"Error in arguments\nUsage: %s config file name (eg: /etc/xdiscovery.conf) %s log file location \n", argv[0], argv[1]);
1708 char* logfilename = argv[2];
1711 logoutfile = g_fopen (logfilename,
"a");
1720 g_message(
"xupnp not handling the logging");
1724 g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_INFO | G_LOG_LEVEL_MESSAGE | \
1725 G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR,
xupnp_logger, NULL);
1728 char* configfilename = argv[1];
1730 rfc_enabled = check_rfc();
1733 g_message(
"Running Older Xdiscovery");
1738 g_message(
"Unable to find xdevice config, Loading default settings ");
1760 gchar **tokens = g_strsplit_set(disConf->discIf,
",", -1);
1761 guint toklength = g_strv_length(tokens);
1763 for (loopvar=0; loopvar<toklength; loopvar++)
1765 if ((strlen(g_strstrip(tokens[loopvar])) > 0))
1767 int result =
getipaddress(g_strstrip(tokens[loopvar]),ipaddress,ipv6Enabled);
1770 g_message(
" \n ***Got Ip address for interface = %s ipaddr = %s *****",g_strstrip(tokens[loopvar]),ipaddress);
1771 g_stpcpy(disConf->discIf,g_strstrip(tokens[loopvar]));
1772 g_stpcpy(disConf->gwIf,g_strstrip(tokens[loopvar]));
1773 bInterfaceReady=
TRUE;
1780 for (retries=3; retries>0; retries--) {
1782 ipaddr =
getipaddress(g_strstrip(tokens[loopvar]),ipaddress,ipv6Enabled);
1784 g_message(
"\n **Got Ip address for interface = %s with retries = %d ipaddr = %s **",g_strstrip(tokens[loopvar]),retries,ipaddress);
1785 g_stpcpy(disConf->discIf,g_strstrip(tokens[loopvar]));
1786 g_stpcpy(disConf->gwIf,g_strstrip(tokens[loopvar]));
1787 bInterfaceReady=
TRUE;
1792 g_message(
"Could not locate the ipaddress of the broadcast interface %s continue with next ", g_strstrip(tokens[loopvar]));
1793 bInterfaceReady=FALSE;
1801 if ( FALSE == bInterfaceReady)
1804 fprintf(stderr,
"Could not locate the ipaddress of the discovery interface %s\n", disConf->discIf);
1805 g_critical(
"Could not locate the ipaddress of the discovery interface %s\n", disConf->discIf);
1809 g_message(
"Starting xdiscovery service on interface %s", disConf->discIf);
1810 g_print(
"Starting xdiscovery service on interface %s\n", disConf->discIf);
1816 main_context = g_main_context_new();
1817 context = gupnp_context_new (main_context, disConf->discIf, host_port, &error);
1819 context = gupnp_context_new (NULL, disConf->discIf, host_port, &error);
1822 context = gupnp_context_new (disConf->discIf, host_port, &error);
1826 g_message (
"Error creating the GUPnP context: %s", error->message);
1827 g_critical(
"Error creating the XUPnP context on %s:%d Error:%s", disConf->discIf, host_port, error->message);
1828 g_error_free (error);
1829 return EXIT_FAILURE;
1832 #if defined(USE_XUPNP_IARM) || defined(USE_XUPNP_IARM_BUS)
1833 gboolean iarminit = XUPnP_IARM_Init();
1837 g_message(
"XUPNP IARM init success");
1842 g_critical(
"XUPNP IARM init failed");
1846 #ifdef GUPNP_GENERIC_MEDIA_RENDERER
1848 #endif //GUPNP_GENERIC_MEDIA_RENDERER
1851 gupnp_context_set_subscription_timeout(context, 0);
1855 if (!getAccountId(accountId)) {
1856 g_message(
"Failed to retrieve AccountId of the control point");
1859 if(xPKI_check_rfc() == 1)
1861 cert_File= g_strdup (
"/tmp/xpki_cert");
1862 key_File= g_strdup (
"/tmp/xpki_key");
1863 g_message(
"Using xPKI certs for handshaking");
1866 if ( ( cert_File == NULL ) && (key_File == NULL )){
1867 if (g_path_is_absolute (disConf->disCertFile)) {
1868 cert_File= g_strdup (disConf->disCertFile);
1871 cert_File = g_build_filename (disConf->disCertPath, disConf->disCertFile, NULL);
1873 if (g_path_is_absolute (disConf->disKeyFile)) {
1874 key_File= g_strdup (disConf->disKeyFile);
1877 key_File = g_build_filename (disConf->disKeyPath, disConf->disKeyFile, NULL);
1880 if (((cert_File != NULL) && (key_File !=NULL)) && ((g_file_test(cert_File, G_FILE_TEST_EXISTS)) && (g_file_test(key_File, G_FILE_TEST_EXISTS))
1881 && (g_file_test(ca_File, G_FILE_TEST_EXISTS)))) {
1884 upnpContextDeviceProtect = gupnp_context_new_s ( NULL, disConf->discIf, DEVICE_PROTECTION_CONTEXT_PORT, cert_File, key_File, &error);
1886 upnpContextDeviceProtect = gupnp_context_new_s ( disConf->discIf, DEVICE_PROTECTION_CONTEXT_PORT, cert_File, key_File, &error);
1889 g_printerr (
"Error creating the Device Protection Broadcast context: %s\n",
1892 g_clear_error(&error);
1900 g_message(
"calling dp whitelistInit ");
1901 ret = dp_wlistInit();
1903 g_message(
"initialization of dp whitelist successful ");
1907 gupnp_context_set_subscription_timeout(upnpContextDeviceProtect, 0);
1908 xupnp_tlsinteraction = g_object_new (xupnp_tls_interaction_get_type (), NULL);
1909 g_message(
"tls interaction object created");
1911 gupnp_context_set_tls_params(upnpContextDeviceProtect,ca_File,key_File, xupnp_tlsinteraction);
1913 cp_client = gupnp_control_point_new(upnpContextDeviceProtect,
"urn:schemas-upnp-org:device:X1Renderer:1");
1914 g_signal_connect (cp_client,
"device-proxy-available", G_CALLBACK (device_proxy_available_cb_client), NULL);
1915 g_signal_connect (cp_client,
"device-proxy-unavailable", G_CALLBACK (device_proxy_unavailable_cb_client), NULL);
1916 gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp_client),
TRUE);
1917 g_message(
"X1Renderer controlpoint created");
1919 cp_gw = gupnp_control_point_new(upnpContextDeviceProtect,
"urn:schemas-upnp-org:device:X1VideoGateway:1");
1920 g_signal_connect (cp_gw,
"device-proxy-available", G_CALLBACK (device_proxy_available_cb_gw), NULL);
1921 g_signal_connect (cp_gw,
"device-proxy-unavailable", G_CALLBACK (device_proxy_unavailable_cb_gw), NULL);
1922 gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp_gw),
TRUE);
1923 g_message(
"X1VideoGateway controlpoint created");
1925 cp_bgw = gupnp_control_point_new(upnpContextDeviceProtect,
"urn:schemas-upnp-org:device:X1BroadbandGateway:1");
1926 g_signal_connect (cp_bgw,
"device-proxy-available", G_CALLBACK (device_proxy_available_cb_bgw), NULL);
1927 g_signal_connect (cp_bgw,
"device-proxy-unavailable", G_CALLBACK (device_proxy_unavailable_cb_bgw), NULL);
1928 gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp_bgw),
TRUE);
1929 g_message(
"X1BroadbandGateway controlpoint created");
1933 g_message(
"DeviceProtection Error: check Cert File or Key File or CA file not existing");
1938 cp = gupnp_control_point_new(context,
"urn:schemas-upnp-org:device:BasicDevice:1");
1939 g_signal_connect (cp,
"device-proxy-available", G_CALLBACK (device_proxy_available_cb), NULL);
1940 g_signal_connect (cp,
"device-proxy-unavailable", G_CALLBACK (device_proxy_unavailable_cb), NULL);
1941 gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp),
TRUE);
1943 #ifdef GUPNP_GENERIC_MEDIA_RENDERER
1945 #endif //GUPNP_GENERIC_MEDIA_RENDERER
1948 logMilestone(
"UPNP_START_DISCOVERY");
1950 g_message(
"UPNP_START_DISCOVERY");
1954 main_loop = g_main_loop_new (NULL, FALSE);
1956 main_loop = g_main_loop_new (main_context, FALSE);
1962 g_message(
"Started discovery on interface %s", disConf->discIf);
1963 g_main_loop_run (main_loop);
1964 g_main_loop_unref (main_loop);
1965 g_object_unref (cp);
1968 g_object_unref (cp_client);
1969 g_object_unref (cp_gw);
1970 g_object_unref (cp_bgw);
1971 g_object_unref (upnpContextDeviceProtect);
1972 g_object_unref (xupnp_tlsinteraction);
1975 #ifdef GUPNP_GENERIC_MEDIA_RENDERER
1977 #endif //GUPNP_GENERIC_MEDIA_RENDERER
1979 if (cert_File != NULL) {
1982 if (key_File != NULL) {
1985 g_object_unref (context);
1988 fclose (logoutfile);
2006 const char * responseFn,gboolean * result, gboolean isInCriticalPath)
2008 GError *error = NULL;
2011 GUPnPServiceProxyAction *action;
2012 action = gupnp_service_proxy_action_new (requestFn, NULL);
2013 gupnp_service_proxy_call_action ((GUPnPServiceProxy *)sproxy, action, NULL, &error);
2017 gupnp_service_proxy_action_get_result (action,
2018 &error, responseFn, G_TYPE_BOOLEAN, result, NULL);
2019 g_clear_pointer (&action, gupnp_service_proxy_action_unref);
2023 gupnp_service_proxy_send_action ((GUPnPServiceProxy *)sproxy, requestFn, &error, NULL, responseFn, G_TYPE_BOOLEAN, result ,NULL);
2025 if ( NULL != error )
2027 g_message (
"%s process gw services Error: %s\n", requestFn, error->message);
2028 if ( isInCriticalPath )
2030 g_message(
"TELEMETRY_XUPNP_PARTIAL_DISCOVERY:%d,%s",error->code, requestFn);
2032 g_clear_error(&error);
2051 const char * responseFn, gchar ** result, gboolean isInCriticalPath)
2053 GError *error = NULL;
2056 GUPnPServiceProxyAction *action;
2057 action = gupnp_service_proxy_action_new (requestFn, NULL);
2058 gupnp_service_proxy_call_action ((GUPnPServiceProxy *)sproxy, action, NULL, &error);
2062 gupnp_service_proxy_action_get_result (action,
2063 &error, responseFn, G_TYPE_STRING, result, NULL);
2064 g_clear_pointer (&action, gupnp_service_proxy_action_unref);
2068 gupnp_service_proxy_send_action ((GUPnPServiceProxy *)sproxy, requestFn, &error,NULL, responseFn, G_TYPE_STRING, result ,NULL);
2070 if ( NULL != error )
2072 g_message (
"%s process gw services Error: %s\n", requestFn, error->message);
2073 if ( isInCriticalPath )
2075 g_message(
"TELEMETRY_XUPNP_PARTIAL_DISCOVERY:%d,%s",error->code, requestFn);
2077 g_clear_error(&error);
2096 const char * responseFn,guint * result, gboolean isInCriticalPath)
2098 GError *error = NULL;
2101 GUPnPServiceProxyAction *action;
2102 action = gupnp_service_proxy_action_new (requestFn, NULL);
2103 gupnp_service_proxy_call_action ((GUPnPServiceProxy *)sproxy, action, NULL, &error);
2107 gupnp_service_proxy_action_get_result (action,
2108 &error, responseFn, G_TYPE_INT, result, NULL);
2109 g_clear_pointer (&action, gupnp_service_proxy_action_unref);
2113 gupnp_service_proxy_send_action ((GUPnPServiceProxy *)sproxy, requestFn , &error,NULL, responseFn, G_TYPE_INT, result ,NULL);
2115 if ( NULL != error )
2117 g_message (
"%s process gw services Error: %s\n", requestFn, error->message);
2118 if ( isInCriticalPath )
2120 g_message(
"TELEMETRY_XUPNP_PARTIAL_DISCOVERY:%d,%s",error->code, requestFn);
2122 g_clear_error(&error);
2154 GError *error = NULL;
2157 gboolean temp_b=FALSE;
2163 g_message(
"Entering into process_gw_services ");
2166 GUPnPServiceProxyAction * action = gupnp_service_proxy_action_new (
"GetIsGateway",
"deviceProtection", G_TYPE_BOOLEAN, FALSE,
"macAddr", G_TYPE_STRING, bcastmac,
"ipAddr",G_TYPE_STRING, ipaddress,NULL);
2167 gupnp_service_proxy_call_action (sproxy, action, NULL, &error);
2170 gupnp_service_proxy_action_get_result (action,
2171 &error,
"IsGateway", G_TYPE_BOOLEAN, &temp_b, NULL);
2172 g_clear_pointer (&action, gupnp_service_proxy_action_unref);
2175 gupnp_service_proxy_send_action (sproxy,
"GetIsGateway", &error,
"deviceProtection", G_TYPE_BOOLEAN, FALSE,
"macAddr", G_TYPE_STRING, bcastmac,
"ipAddr",G_TYPE_STRING, ipaddress,NULL,
"IsGateway", G_TYPE_BOOLEAN, &temp_b ,NULL);
2179 g_message (
"GetIsGateway process gw services Error: %s", error->message);
2180 g_message(
"TELEMETRY_XUPNP_PARTIAL_DISCOVERY:%d,IsGateway",error->code);
2181 g_clear_error(&error);
2186 gwData->isgateway = (gboolean)temp_b;
2190 g_string_assign(gwData->recvdevtype,temp);
2196 g_string_assign(gwData->buildversion,temp);
2202 g_string_assign(gwData->devicename,temp);
2208 g_string_assign(gwData->devicetype,temp);
2218 g_string_assign(gwData->bcastmacaddress,temp);
2222 if(!strcasestr(g_strstrip(gwData->devicetype->str),
"XI") )
2230 g_string_assign(gwData->baseurl,temp);
2240 g_string_assign(gwData->basetrmurl,temp);
2246 g_string_assign(gwData->gwyip,temp);
2252 g_string_assign(gwData->clientip,temp);
2258 g_string_assign(gwData->gwyipv6,temp);
2264 g_string_assign(gwData->gatewaystbip,temp);
2269 g_string_assign(gwData->ipv6prefix,temp);
2272 if (gwData && gwData->ipv6prefix && gwData->ipv6prefix->str && (g_strcmp0(gwData->ipv6prefix->str,
"") != 0))
2274 logMilestone(
"UPNP_RECV_IPV6_PREFIX");
2277 g_message(
"UPNP_RECV_IPV6_PREFIX");
2283 g_string_assign(gwData->dnsconfig,temp);
2288 g_string_assign(gwData->playbackurl,temp);
2295 g_message(
"GetPlaybackUrl = %s",gwData->playbackurl->str);
2299 g_string_assign(gwData->systemids,temp);
2305 g_string_assign(gwData->dsgtimezone,temp);
2311 g_string_assign(gwData->etchosts,temp);
2321 gwData->requirestrm = (gboolean)temp_b;
2326 g_string_assign(gwData->hostmacaddress,temp);
2332 gwData->rawoffset = (gint)temp_i;
2335 if (
processIntRequest( sproxy,
"GetDSTSavings",
"DSTSavings" , &temp_i, FALSE))
2337 gwData->dstsavings = (gint)temp_i;
2342 gwData->usesdaylighttime = (gboolean)temp_b;
2347 gwData->dstoffset = (gint)temp_i;
2352 g_message(
"Discovered a Xi device ");
2354 if (
processStringRequest(sproxy,
"GetDataGatewayIPaddress",
"DataGatewayIPaddress" , &temp, FALSE))
2356 g_string_assign(gwData->dataGatewayIPaddress,temp);
2359 g_message(
"GetDataGatewayIPaddress = %s",gwData->dataGatewayIPaddress->str);
2361 #ifndef CLIENT_XCAL_SERVER
2364 if (gwData->isOwnGateway == FALSE)
2368 g_message(
"Replaced MocaIP for %s with localhost", gwData->serial_num->str);
2372 gwData->devFoundFlag =
TRUE;
2373 gwData->isDevRefactored = FALSE;
2376 g_message(
"Failed to update gw data into the list");
2378 g_critical(
"Unable to update the gateway-%s in the device list",gwData->serial_num->str);
2381 g_message(
"Exiting from process_gw_services ");
2385 gboolean process_gw_services_identity(GUPnPServiceProxy *sproxy,
GwyDeviceData* gwData)
2390 GError *error = NULL;
2393 g_message(
"Entering into process_gw_services_identity ");
2398 GUPnPServiceProxyAction * action = gupnp_service_proxy_action_new (
"GetAccountId",
"SAccountId", G_TYPE_STRING, accountId,
"macAddr", G_TYPE_STRING, bcastmac,
"ipAddr",G_TYPE_STRING, ipaddress, NULL);
2399 gupnp_service_proxy_call_action (sproxy, action, NULL, &error);
2402 gupnp_service_proxy_action_get_result (action,
2403 &error,
"GAccountId", G_TYPE_STRING, &temp, NULL);
2404 g_clear_pointer (&action, gupnp_service_proxy_action_unref);
2407 gupnp_service_proxy_send_action (sproxy,
"GetAccountId", &error,
"SAccountId", G_TYPE_STRING, accountId,
"macAddr", G_TYPE_STRING, bcastmac,
"ipAddr",G_TYPE_STRING, ipaddress, NULL,
"GAccountId", G_TYPE_STRING, &temp, NULL);
2411 g_message (
"GetAccountId process gw Identity services Error: %s", error->message);
2412 g_clear_error(&error);
2416 g_message (
"Received account id: %s", temp);
2417 g_string_assign(gwData->accountid, temp);
2423 g_string_assign(gwData->recvdevtype, temp);
2428 g_string_assign(gwData->buildversion, temp);
2433 g_string_assign(gwData->devicename, temp);
2438 g_string_assign(gwData->devicetype, temp);
2443 g_string_assign(gwData->modelclass, temp);
2448 g_string_assign(gwData->modelnumber, temp);
2453 g_string_assign(gwData->deviceid, temp);
2458 g_string_assign(gwData->hardwarerevision, temp);
2463 g_string_assign(gwData->softwarerevision, temp);
2468 g_string_assign(gwData->managementurl, temp);
2473 g_string_assign(gwData->make, temp);
2478 g_string_assign(gwData->receiverid, temp);
2483 g_string_assign(gwData->clientip, temp);
2488 g_string_assign(gwData->bcastmacaddress, temp);
2492 g_message(
"Exiting from process_gw_services_identity ");
2497 gboolean process_gw_services_media_config(GUPnPServiceProxy *sproxy,
GwyDeviceData* gwData)
2504 g_message(
"Entering into process_gw services_media_config ");
2507 g_string_assign(gwData->playbackurl, temp);
2517 g_message(
"Exiting from process_gw_services_media_config ");
2521 gboolean process_gw_services_gateway_config(GUPnPServiceProxy *sproxy,
GwyDeviceData* gwData)
2526 GError *error = NULL;
2528 gboolean temp_b=FALSE;
2530 g_message(
"Entering into process_gw_services_gateway_config ");
2531 if (
processStringRequest(sproxy,
"GetDataGatewayIPaddress",
"DataGatewayIPaddress" , &temp, FALSE))
2533 g_string_assign(gwData->dataGatewayIPaddress, temp);
2539 g_string_assign(gwData->gatewaystbip, temp);
2544 g_string_assign(gwData->ipv6prefix, temp);
2549 g_string_assign(gwData->dnsconfig, temp);
2554 g_string_assign(gwData->devicename, temp);
2559 g_string_assign(gwData->bcastmacaddress,temp);
2564 g_string_assign(gwData->gwyipv6, temp);
2569 g_string_assign(gwData->gwyip, temp);
2574 g_string_assign(gwData->hostmacaddress, temp);
2579 g_string_assign(gwData->etchosts, temp);
2583 GUPnPServiceProxyAction * action = gupnp_service_proxy_action_new (
"GetIsGateway",
"deviceProtection", G_TYPE_BOOLEAN,
TRUE, NULL);
2584 gupnp_service_proxy_call_action (sproxy, action, NULL, &error);
2587 gupnp_service_proxy_action_get_result (action,
2588 &error,
"IsGateway", G_TYPE_BOOLEAN, &temp_b, NULL);
2589 g_clear_pointer (&action, gupnp_service_proxy_action_unref);
2593 gupnp_service_proxy_send_action (sproxy,
"GetIsGateway", &error,
"deviceProtection", G_TYPE_BOOLEAN,
TRUE, NULL,
"IsGateway", G_TYPE_BOOLEAN, &temp_b ,NULL);
2597 g_message (
"GetIsGateway process gw services Error: %s", error->message);
2598 g_message(
"TELEMETRY_XUPNP_PARTIAL_DISCOVERY:%d,IsGateway",error->code);
2599 g_clear_error(&error);
2604 gwData->isgateway = (gboolean)temp_b;
2609 g_string_assign(gwData->ipSubNet, temp);
2610 if(temp && strlen(temp))
2611 addRouteToMocaBridge(temp);
2615 g_message(
"Exiting from process_gw_services_gateway_config ");
2620 gboolean process_gw_services_time_config(GUPnPServiceProxy *sproxy,
GwyDeviceData* gwData)
2627 gboolean temp_b=FALSE;
2629 g_message(
"Entering into process_gw_services_time_config ");
2632 g_string_assign(gwData->dsgtimezone, temp);
2637 gwData->rawoffset = (gint)temp_i;
2639 if (
processIntRequest( sproxy,
"GetDSTSavings",
"DSTSavings" , &temp_i, FALSE))
2641 gwData->dstsavings = (gint)temp_i;
2645 gwData->usesdaylighttime = (gboolean)temp_b;
2649 gwData->dstoffset = (gint)temp_i;
2651 g_message(
"Exiting from process_gw_services_time_config ");
2655 gboolean process_gw_services_qam_config(GUPnPServiceProxy *sproxy,
GwyDeviceData* gwData)
2661 gboolean temp_b=FALSE;
2663 g_message(
"Entering into process_gw_services_qam_config ");
2668 g_string_assign(gwData->basetrmurl , temp);
2673 g_string_assign(gwData->systemids , temp);
2678 gwData->requirestrm = (gboolean)temp_b;
2687 #ifndef CLIENT_XCAL_SERVER
2688 if (gwData->isOwnGateway == FALSE)
2692 g_message(
"Replaced MocaIP for %s with localhost", gwData->serial_num->str);
2696 g_message(
"Exiting from process_gw_services_qam_config ");
2712 char * tempStr = NULL;
2715 tempStr =
replace_string(gwyData->playbackurl->str, gwyData->gwyip->str, (
char *)localHostIP);
2716 g_string_assign(gwyData->playbackurl, tempStr);
2720 tempStr =
replace_string(gwyData->baseurl->str, gwyData->gwyip->str, (
char *)localHostIP);
2721 g_string_assign(gwyData->baseurl,tempStr);
2725 tempStr =
replace_string(gwyData->basetrmurl->str, gwyData->gwyip->str, (
char *)localHostIP);
2726 g_string_assign(gwyData->basetrmurl,tempStr);
2730 g_message(
"baseurl:%s, playbackurl:%s, basetrumurl:%s", gwyData->baseurl->str,
2731 gwyData->playbackurl->str, gwyData->gwyip->str);
2746 gwydata->serial_num = g_string_new(NULL);
2747 gwydata->isgateway=FALSE;
2748 gwydata->requirestrm=
TRUE;
2749 gwydata->gwyip = g_string_new(NULL);
2750 gwydata->gwyipv6 = g_string_new(NULL);
2751 gwydata->hostmacaddress = g_string_new(NULL);
2752 gwydata->recvdevtype = g_string_new(NULL);
2753 gwydata->devicetype = g_string_new(NULL);
2754 gwydata->buildversion = g_string_new(NULL);
2755 gwydata->dsgtimezone = g_string_new(NULL);
2756 gwydata->ipSubNet = g_string_new(NULL);
2757 gwydata->dataGatewayIPaddress = g_string_new(NULL);
2758 gwydata->dstoffset = 0;
2759 gwydata->dstsavings = 0;
2760 gwydata->rawoffset = 0;
2761 gwydata->usesdaylighttime = FALSE;
2762 gwydata->baseurl = g_string_new(NULL);
2763 gwydata->basetrmurl = g_string_new(NULL);
2764 gwydata->playbackurl = g_string_new(NULL);
2765 gwydata->dnsconfig = g_string_new(NULL);
2766 gwydata->etchosts = g_string_new(NULL);
2767 gwydata->systemids = g_string_new(NULL);
2768 gwydata->receiverid = g_string_new(NULL);
2769 gwydata->gatewaystbip = g_string_new(NULL);
2770 gwydata->ipv6prefix = g_string_new(NULL);
2771 gwydata->devicename = g_string_new(NULL);
2772 gwydata->bcastmacaddress = g_string_new(NULL);
2773 gwydata->modelclass = g_string_new(NULL);
2774 gwydata->modelnumber = g_string_new(NULL);
2775 gwydata->deviceid = g_string_new(NULL);
2776 gwydata->hardwarerevision = g_string_new(NULL);
2777 gwydata->softwarerevision = g_string_new(NULL);
2778 gwydata->managementurl = g_string_new(NULL);
2779 gwydata->make = g_string_new(NULL);
2780 gwydata->accountid = g_string_new(NULL);
2781 gwydata->clientip = g_string_new(NULL);
2782 gwydata->devFoundFlag=FALSE;
2783 gwydata->isOwnGateway=FALSE;
2784 gwydata->isRouteSet=FALSE;
2785 gwydata->isDevRefactored=FALSE;
2786 gwydata->sproxy=NULL;
2787 gwydata->sproxy_i=NULL;
2788 gwydata->sproxy_m=NULL;
2789 gwydata->sproxy_t=NULL;
2790 gwydata->sproxy_g=NULL;
2791 gwydata->sproxy_q=NULL;
2807 g_string_free(gwydata->serial_num,
TRUE);
2808 g_string_free(gwydata->gwyip,
TRUE);
2809 g_string_free(gwydata->gwyipv6,
TRUE);
2810 g_string_free(gwydata->hostmacaddress,
TRUE);
2811 g_string_free(gwydata->recvdevtype,
TRUE);
2812 g_string_free(gwydata->devicetype,
TRUE);
2813 g_string_free(gwydata->buildversion,
TRUE);
2814 g_string_free(gwydata->dataGatewayIPaddress,
TRUE);
2815 g_string_free(gwydata->dsgtimezone,
TRUE);
2816 g_string_free(gwydata->ipSubNet,
TRUE);
2817 g_string_free(gwydata->baseurl,
TRUE);
2818 g_string_free(gwydata->basetrmurl,
TRUE);
2819 g_string_free(gwydata->playbackurl,
TRUE);
2820 g_string_free(gwydata->dnsconfig,
TRUE);
2821 g_string_free(gwydata->etchosts,
TRUE);
2822 g_string_free(gwydata->systemids,
TRUE);
2823 g_string_free(gwydata->receiverid,
TRUE);
2824 g_string_free(gwydata->gatewaystbip,
TRUE);
2825 g_string_free(gwydata->ipv6prefix,
TRUE);
2826 g_string_free(gwydata->devicename,
TRUE);
2827 g_string_free(gwydata->bcastmacaddress,
TRUE);
2828 g_string_free(gwydata->clientip,
TRUE);
2831 g_clear_object(&(gwydata->sproxy));
2833 if(gwydata->sproxy_i)
2835 g_string_free(gwydata->make,
TRUE);
2836 g_string_free(gwydata->accountid,
TRUE);
2837 g_string_free(gwydata->modelnumber,
TRUE);
2838 g_clear_object(&(gwydata->sproxy_i));
2840 if(gwydata->sproxy_m)
2842 g_clear_object(&(gwydata->sproxy_m));
2844 if(gwydata->sproxy_t)
2846 g_clear_object(&(gwydata->sproxy_t));
2848 if(gwydata->sproxy_g)
2850 g_clear_object(&(gwydata->sproxy_g));
2852 if(gwydata->sproxy_q)
2854 g_clear_object(&(gwydata->sproxy_q));
2872 char* sno = gwydata->serial_num->str;
2873 gchar* gwipaddr = gwydata->gwyip->str;
2876 dp_wlist_ss_t wstatus;
2882 GList* xdevlistitem = g_list_find_custom (xdevlist, sno, (GCompareFunc)g_list_find_sno);
2885 if (xdevlistitem != NULL)
2887 gint result = g_strcmp0(g_strstrip(((
GwyDeviceData *)xdevlistitem->data)->gwyip->str),g_strstrip(gwipaddr));
2889 if ((disConf->enableGwSetup ==
TRUE) && (gwydata->isRouteSet) && (result != 0))
2891 g_message(
"***** stored device gwip = %s new device gwip = %s result = %d sno = %s *****",(((
GwyDeviceData *)xdevlistitem->data)->gwyip->str),g_strstrip(gwipaddr),result,sno);
2893 ret = v_secure_system(
"route del default gw %s", gwydata->gwyip->str);
2895 g_message(
"Failure in executing v_secure_system. ret val: %d \n", ret);
2898 g_message(
"Clearing the default gateway %s from route list", gwydata->gwyip->str);
2906 g_message(
"Found device: %s in the list, but unable to delete for update", sno);
2912 g_message(
"Found device: %s in the list, Deleted before update", sno);
2917 g_message(
"Item %s not found in the list", sno);
2920 g_mutex_lock(mutex);
2921 xdevlist = g_list_insert_sorted_with_data(xdevlist, gwydata,(GCompareDataFunc)g_list_compare_sno, NULL);
2922 g_mutex_unlock(mutex);
2923 g_message(
"Inserted new/updated device %s in the list", sno);
2925 if ((rfc_enabled) && (gwydata->isDevRefactored)) {
2927 if(g_strrstr(g_strstrip(gwydata->devicetype->str),
"XG") != NULL)
2929 if (gwydata->gwyip->str) {
2930 ret = inet_aton(gwydata->gwyip->str, &x_r);
2932 if ((wstatus = dpnode_insert(x_r.s_addr, gwydata->bcastmacaddress->str)) != DP_WLIST_ERROR) {
2933 g_message(
"Inserted ip address:index %s:%d mac address %s to whitelist", gwydata->gwyip->str, x_r.s_addr, gwydata->bcastmacaddress->str);
2937 g_message(
"dpnode_insert failure");
2942 g_message(
"ip address conversion failure");
2947 g_message(
"gateway ip address empty");
2950 else if ((g_strrstr(g_strstrip(gwydata->devicetype->str),
"XID") != NULL ) || (g_strrstr(g_strstrip(gwydata->devicetype->str),
"XI3") != NULL))
2952 if (gwydata->clientip->str) {
2953 ret = inet_aton(gwydata->clientip->str, &x_r);
2955 if ((wstatus = dpnode_insert(x_r.s_addr, gwydata->bcastmacaddress->str)) != DP_WLIST_ERROR) {
2956 g_message(
"Inserted ip address:index %s:%d mac address %s to whitelist", gwydata->clientip->str, x_r.s_addr, gwydata->bcastmacaddress->str);
2960 g_message(
"dpnode_insert failure");
2965 g_message(
"ip address conversion failure");
2970 g_message(
"client ip address empty");
2985 g_critical(
"Got a device with empty serianl number");
3006 GList* lstXdev = g_list_find_custom (xdevlist, serial_num, (GCompareFunc)g_list_find_sno);
3011 g_mutex_lock(mutex);
3012 if(gwdata->isgateway ==
TRUE)
3014 #ifdef CLIENT_XCAL_SERVER
3015 if (gatewayDetected)
3019 g_message(
"Removing Gateway Device %s from the device list %d", gwdata->serial_num->str,gatewayDetected);
3022 if ((rfc_enabled) && (g_strrstr(g_strstrip(gwdata->devicetype->str),
"XG") != NULL ) && (gwdata->isDevRefactored)) {
3025 ret = inet_aton(gwdata->gwyip->str, &x_r);
3027 dpnode_delete(x_r.s_addr,
" ");
3032 g_message(
"Removing Gateway Device %s from the device list", gwdata->serial_num->str);
3037 g_message(
"Removing Client Device %s from the device list", gwdata->serial_num->str);
3039 if ((rfc_enabled) && ((g_strrstr(g_strstrip(gwdata->devicetype->str),
"XID") != NULL ) || (g_strrstr(g_strstrip(gwdata->devicetype->str),
"XI3") != NULL )) && (gwdata->isDevRefactored)) {
3042 ret = inet_aton(gwdata->clientip->str, &x_r);
3044 dpnode_delete(x_r.s_addr,
" ");
3059 xdevlist = g_list_remove_link(xdevlist, lstXdev);
3062 g_mutex_unlock(mutex);
3063 g_message(
"Deleted device %s from the list", serial_num);
3065 g_list_free (lstXdev);
3070 g_message(
"Device %s to be removed not in the discovered device list", serial_num);
3089 gboolean firstXG1GwData=
TRUE;
3090 gboolean firstXG2GwData=
TRUE;
3091 const gchar v4ModeValue[]=
"ipv4";
3092 const gchar v6ModeValue[]=
"ipv6";
3093 gboolean isMediaClientConnected=FALSE;
3100 GString *localOutputContents=g_string_new(NULL);
3101 GString *logDevicesList=g_string_new(NULL);
3102 g_string_printf(localOutputContents,
"{\n\"xmediagateways\":\n\t[");
3104 GList *xdevlistDup=NULL;
3105 g_mutex_lock(mutex);
3106 if((xdevlist) && (g_list_length(xdevlist) > 0))
3108 xdevlistDup = g_list_copy(xdevlist);
3109 g_mutex_unlock(mutex);
3111 element = g_list_first(xdevlistDup);
3114 g_string_append_printf(localOutputContents,
"\n\t\t{\n\t\t\t");
3116 if(g_strcmp0(gwdata->recvdevtype->str,
"broadband")) {
3117 g_string_append_printf(logDevicesList,
"%s,%s,", gwdata->bcastmacaddress->str, gwdata->devicetype->str);
3120 g_string_append_printf(localOutputContents,
"\"sno\":\"%s\",\n", gwdata->serial_num->str);
3121 g_string_append_printf(localOutputContents,
"\t\t\t\"isgateway\":\"%s\",\n", gwdata->isgateway?
"yes":
"no");
3122 g_string_append_printf(localOutputContents,
"\t\t\t\"deviceName\":\"%s\",\n", gwdata->devicename->str);
3123 g_string_append_printf(localOutputContents,
"\t\t\t\"recvDevType\":\"%s\",\n", gwdata->recvdevtype->str);
3124 g_string_append_printf(localOutputContents,
"\t\t\t\"DevType\":\"%s\",\n", gwdata->devicetype->str);
3125 g_string_append_printf(localOutputContents,
"\t\t\t\"bcastMacAddress\":\"%s\",\n", gwdata->bcastmacaddress->str);
3127 if(gwdata->sproxy_i != NULL)
3129 g_string_append_printf(localOutputContents,
"\t\t\t\"accountId\":\"%s\",\n", gwdata->accountid->str);
3130 g_string_append_printf(localOutputContents,
"\t\t\t\"modelNumber\":\"%s\",\n", gwdata->modelnumber->str);
3131 g_string_append_printf(localOutputContents,
"\t\t\t\"modelClass\":\"%s\",\n", gwdata->modelclass->str);
3132 g_string_append_printf(localOutputContents,
"\t\t\t\"make\":\"%s\",\n", gwdata->make->str);
3133 g_string_append_printf(localOutputContents,
"\t\t\t\"softwareRevision\":\"%s\",\n", gwdata->buildversion->str);
3134 if(g_strcmp0(gwdata->recvdevtype->str,
"broadband"))
3136 g_string_append_printf(localOutputContents,
"\t\t\t\"hardwareRevision\":\"%s\",\n", gwdata->hardwarerevision->str);
3137 g_string_append_printf(localOutputContents,
"\t\t\t\"managementUrl\":\"%s\",\n", gwdata->managementurl->str);
3142 g_string_append_printf(localOutputContents,
"\t\t\t\"buildVersion\":\"%s\",\n", gwdata->buildversion->str);
3144 if(strcasestr(g_strstrip(gwdata->devicetype->str),
"XI") == NULL )
3146 g_string_append_printf(localOutputContents,
"\t\t\t\"gatewayip\":\"%s\",\n", gwdata->gwyip->str);
3147 g_string_append_printf(localOutputContents,
"\t\t\t\"gatewayipv6\":\"%s\",\n", gwdata->gwyipv6->str);
3148 g_string_append_printf(localOutputContents,
"\t\t\t\"hostMacAddress\":\"%s\",\n", gwdata->hostmacaddress->str);
3149 if(g_strcmp0(gwdata->recvdevtype->str,
"hybrid"))
3150 g_string_append_printf(localOutputContents,
"\t\t\t\"IPSubNet\":\"%s\",\n", gwdata->ipSubNet->str);
3151 if(g_strcmp0(gwdata->recvdevtype->str,
"broadband"))
3153 g_string_append_printf(localOutputContents,
"\t\t\t\"gatewayStbIP\":\"%s\",\n", gwdata->gatewaystbip->str);
3154 g_string_append_printf(localOutputContents,
"\t\t\t\"ipv6Prefix\":\"%s\",\n", gwdata->ipv6prefix->str);
3155 g_string_append_printf(localOutputContents,
"\t\t\t\"timezone\":\"%s\",\n", gwdata->dsgtimezone->str);
3156 g_string_append_printf(localOutputContents,
"\t\t\t\"rawoffset\":\"%d\",\n", gwdata->rawoffset);
3157 g_string_append_printf(localOutputContents,
"\t\t\t\"dstoffset\":\"%d\",\n", gwdata->dstoffset);
3158 g_string_append_printf(localOutputContents,
"\t\t\t\"dstsavings\":\"%d\",\n", gwdata->dstsavings);
3159 g_string_append_printf(localOutputContents,
"\t\t\t\"usesdaylighttime\":\"%s\",\n", gwdata->usesdaylighttime?
"yes":
"no");
3160 g_string_append_printf(localOutputContents,
"\t\t\t\"requiresTRM\":\"%s\",\n", gwdata->requirestrm?
"true":
"false");
3161 g_string_append_printf(localOutputContents,
"\t\t\t\"baseTrmUrl\":\"%s\",\n", gwdata->basetrmurl->str);
3162 g_string_append_printf(localOutputContents,
"\t\t\t\"systemids\":\"%s\",\n", gwdata->systemids->str);
3163 g_string_append_printf(localOutputContents,
"\t\t\t\"playbackUrl\":\"%s\",\n", gwdata->playbackurl->str);
3164 g_string_append_printf(localOutputContents,
"\t\t\t\"dnsconfig\":\"%s\",\n", gwdata->dnsconfig->str);
3165 g_string_append_printf(localOutputContents,
"\t\t\t\"hosts\":\"%s\",\n", gwdata->etchosts->str);
3167 if(gwdata->sproxy_i != NULL)
3169 g_string_append_printf(localOutputContents,
"\t\t\t\"dataGatewayIPaddress\":\"%s\",\n", gwdata->dataGatewayIPaddress->str);
3170 g_string_append_printf(localOutputContents,
"\t\t\t\"clientip\":\"%s\",\n", gwdata->clientip->str);
3175 g_string_append_printf(localOutputContents,
"\t\t\t\"clientip\":\"%s\",\n", gwdata->clientip->str);
3176 g_string_append_printf(localOutputContents,
"\t\t\t\"dataGatewayIPaddress\":\"%s\",\n", gwdata->dataGatewayIPaddress->str);
3178 g_string_append_printf(localOutputContents,
"\t\t\t\"receiverid\":\"%s\"\n\t\t}", gwdata->receiverid->str);
3179 #ifdef CLIENT_XCAL_SERVER
3180 if (gwdata->isgateway)
3186 if((!selfDeviceDiscovered) && (g_strcmp0(g_strstrip(ownSerialNo->str),gwdata->serial_num->str) == 0))
3188 selfDeviceDiscovered=
TRUE;
3189 g_message(
"Self Discovery Success %s",ownSerialNo->str);
3195 GString *GwRouteParam=g_string_new(NULL);
3196 g_string_printf(GwRouteParam,
"%s" ,disConf->gwSetupFile);
3197 g_string_append_printf(GwRouteParam,
" \"%s\"" ,gwdata->gwyip->str);
3198 g_string_append_printf(GwRouteParam,
" \"%s\"" ,gwdata->dnsconfig->str);
3199 g_string_append_printf(GwRouteParam,
" \"%s\"" ,gwdata->etchosts->str);
3200 g_string_append_printf(GwRouteParam,
" \"%s\"" ,disConf->gwIf);
3201 g_string_append_printf(GwRouteParam,
" \"%d\"" ,disConf->GwPriority);
3202 g_string_append_printf(GwRouteParam,
" \"%s\"" ,gwdata->ipv6prefix->str);
3203 g_string_append_printf(GwRouteParam,
" \"%s\"" ,gwdata->gwyipv6->str);
3204 g_string_append_printf(GwRouteParam,
" \"%s\"" ,gwdata->devicetype->str);
3206 g_message(
"Calling gateway script %s",GwRouteParam->str);
3207 system(GwRouteParam->str);
3208 g_string_free(GwRouteParam,
TRUE);
3209 gwdata->isRouteSet =
TRUE;
3210 if(firstXG1GwData ==
TRUE)
3212 firstXG1GwData=FALSE;
3214 else if(firstXG2GwData ==
TRUE)
3217 firstXG2GwData=FALSE;
3220 if (g_strrstr(g_strstrip(gwdata->ipv6prefix->str),
"null") || ! *(gwdata->ipv6prefix->str))
3223 if( g_strcmp0(ipMode->str,v4ModeValue) != 0 )
3225 g_message(
"v4 mode changed");
3226 g_string_assign(ipMode,v4ModeValue);
3231 if( g_strcmp0(ipMode->str,v6ModeValue) != 0 )
3233 g_message(
"v6 mode changed");
3234 g_string_assign(ipMode,v6ModeValue);
3239 #ifdef USE_XUPNP_TZ_UPDATE
3240 if (g_strcmp0(g_strstrip(gwdata->dsgtimezone->str),
"null") != 0)
3241 broadcastTimeZoneChange(gwdata);
3245 element = g_list_next(element);
3246 if (element) g_string_append_printf(localOutputContents,
",");
3249 g_list_free(element);
3251 g_list_free(xdevlistDup);
3255 g_message(
"Send Discovery Result : Device List Null or Empty");
3256 g_mutex_unlock(mutex);
3258 if (logDevicesList->len)
3260 g_string_truncate(logDevicesList, logDevicesList->len-1);
3262 g_message(
"DISCOVERED_MANAGED_DEVICE:%s\n", logDevicesList->str);
3264 #if defined(ENABLE_FEATURE_TELEMETRY2_0)
3265 char telemetryBuff[4096] = {
'\0'};
3266 strncpy(telemetryBuff, logDevicesList->str, logDevicesList->len);
3267 t2_event_s(
"Discovered_MngdDev_split", telemetryBuff);
3271 g_string_append_printf(localOutputContents,
"\n\t]\n}\n");
3273 g_message(
"Output is\n%s", localOutputContents->str);
3274 g_mutex_lock(devMutex);
3275 g_string_assign(outputcontents,localOutputContents->str);
3276 g_mutex_unlock(devMutex);
3279 #if defined(USE_XUPNP_IARM)
3280 notifyXUPnPDataUpdateEvent(UIDEV_EVENT_XUPNP_DATA_UPDATE);
3281 #elif defined(USE_XUPNP_IARM_BUS)
3287 if (g_file_set_contents(outfilename, localOutputContents->str, -1, NULL)==FALSE)
3289 g_string_free(localOutputContents,
TRUE);
3290 g_print(
"xdiscovery:Problem in updating the output file contents\n");
3291 g_critical(
"Problem in updating the file contents");
3295 if (strstr(localOutputContents->str,
"mediaclient") != NULL)
3296 isMediaClientConnected =
TRUE;
3297 g_string_free(localOutputContents,
TRUE);
3304 if ((access(WEBGUI_VIDEO_ANAL_FILE, F_OK) == -1) && (isMediaClientConnected ==
TRUE))
3306 g_message(
"Open Video Analytic port if mediaclient is connected\n");
3307 ret = v_secure_system (
"/etc/webgui.sh &");
3309 g_message(
"Failure in executing command via v_secure_system. ret val : %d\n", ret);
3314 (void)(isMediaClientConnected);
3346 guint checkMainLoopCounter=0;
3347 guint sleepCounter=0;
3348 #ifdef CLIENT_XCAL_SERVER
3349 guint browserDisableEnableCounter=0;
3351 #if !defined(BROADBAND)
3352 guint selfDiscoveryFailCount=0;
3355 usleep(XUPNP_RESCAN_INTERVAL);
3359 if (! g_main_loop_is_running(main_loop))
3361 if(checkMainLoopCounter < 7)
3362 g_message(
"TELEMETRY_XUPNP_DISCOVERY_MAIN_LOOP_NOT_RUNNING");
3363 checkMainLoopCounter++;
3367 if((sleepCounter > 6) && (sleepCounter < 12))
3369 g_message(
"Device Addition %u going in main loop",deviceAddNo);
3372 usleep(XUPNP_RESCAN_INTERVAL);
3376 #if !defined(BROADBAND)
3377 if((!selfDeviceDiscovered) && (access(RESTART_XDISCOVERY_FILE, F_OK ) == -1))
3379 if (selfDiscoveryFailCount >= 20)
3381 FILE *fDiscoveryFile;
3382 fDiscoveryFile = fopen(RESTART_XDISCOVERY_FILE,
"w");
3383 if(! fDiscoveryFile)
3385 g_message(
"Restart Xdiscovery File open failure");
3389 g_message(
"Self Discovery Failed %d ! exiting",selfDiscoveryFailCount);
3390 fclose(fDiscoveryFile);
3395 selfDiscoveryFailCount++;
3399 #ifdef CLIENT_XCAL_SERVER
3401 if((partialDiscovery) && (!gatewayDetected) && (browserDisableEnableCounter <=2))
3403 g_message(
"Partial Device Discovery Disable Enable Resource Browser");
3404 gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(cp),FALSE);
3405 partialDiscovery=FALSE;
3406 usleep(XUPNP_RESCAN_INTERVAL/5);
3407 gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(cp),
TRUE);
3408 usleep(XUPNP_RESCAN_INTERVAL);
3409 browserDisableEnableCounter++;
3415 if (gssdp_resource_browser_rescan(GSSDP_RESOURCE_BROWSER(cp_client))==FALSE)
3417 g_message(
"Forced rescan failed for renderer");
3418 usleep(XUPNP_RESCAN_INTERVAL);
3420 if (gssdp_resource_browser_rescan(GSSDP_RESOURCE_BROWSER(cp_gw))==FALSE)
3422 g_message(
"Forced rescan failed for gateway");
3423 usleep(XUPNP_RESCAN_INTERVAL);
3425 if (gssdp_resource_browser_rescan(GSSDP_RESOURCE_BROWSER(cp_bgw))==FALSE)
3427 g_message(
"Forced rescan failed for broadband");
3428 usleep(XUPNP_RESCAN_INTERVAL);
3431 if (gssdp_resource_browser_rescan(GSSDP_RESOURCE_BROWSER(cp))==FALSE)
3433 g_message(
"Forced rescan failed");
3435 usleep(XUPNP_RESCAN_INTERVAL);
3441 usleep(XUPNP_RESCAN_INTERVAL);
3639 guint lenXDevList = 0;
3640 guint deletedDeviceNo=0;
3641 lenXDevList = g_list_length(xdevlist);
3644 if (lenXDevList > 0)
3647 GList *element = g_list_first(xdevlist);
3649 while (element && (lenXDevList > 0))
3651 gwdata = element->data;
3652 element = g_list_next(element);
3653 if (gwdata->isOwnGateway==FALSE)
3655 if (gwdata->devFoundFlag==FALSE || bDeleteAll==
TRUE)
3657 if(gwdata->isgateway ==
TRUE)
3658 g_message(
"Removing Gateway Device %s from the device list", gwdata->serial_num->str);
3660 g_message(
"Removing Client Device %s from the device list", gwdata->serial_num->str);
3662 if ((disConf->enableGwSetup ==
TRUE) && (gwdata->isRouteSet) &&
checkvalidip(gwdata->gwyip->str))
3664 ret = v_secure_system(
"route del default gw %s", gwdata->gwyip->str);
3666 g_message(
"Failure in executing command via v_secure_system. ret val : %d \n", ret);
3668 g_message(
"Clearing the default gateway %s from route list", gwdata->gwyip->str);
3673 g_mutex_lock(mutex);
3676 xdevlist = g_list_remove(xdevlist, gwdata);
3681 g_mutex_unlock(mutex);
3686 g_list_free(element);
3687 if(deletedDeviceNo > 0)
3689 g_message(
"removed %d devices,sending updated discovery result",deletedDeviceNo);
3695 static void on_last_change (GUPnPServiceProxy *sproxy,
const char *variable_name, GValue *value, gpointer user_data)
3698 const char* updated_value;
3699 gboolean bUpdateDiscoveryResult=FALSE;
3700 const char* udn = gupnp_service_info_get_udn(GUPNP_SERVICE_INFO(sproxy));
3701 g_message(
"Variable name is %s udn is %s", variable_name, udn);
3705 if (g_strrstr(udn,
"uuid:"))
3707 gchar* receiverid = g_strndup(udn+5, strlen(udn)-5);
3708 GList* xdevlistitem = g_list_find_custom (xdevlist, receiverid, (GCompareFunc)
g_list_find_udn);
3709 if (xdevlistitem != NULL)
3711 gwdata = xdevlistitem->data;
3712 g_message(
"Found device: %s - Receiver id %s in the list, Updating %s",
3713 gwdata->serial_num->str,gwdata->receiverid->str, variable_name);
3714 if (g_strcmp0(g_strstrip((gchar *)variable_name),
"PlaybackUrl") == 0)
3716 updated_value = g_value_get_string(value);
3717 g_message(
"Updated value is %s ", updated_value);
3718 if(g_strcmp0(g_strstrip((gchar *)updated_value),gwdata->playbackurl->str) != 0)
3720 bUpdateDiscoveryResult=
TRUE;
3721 g_string_assign(gwdata->playbackurl, updated_value);
3728 g_message(
"Replaced MocaIP for %s with localhost", gwdata->serial_num->str);
3735 if (g_strcmp0(g_strstrip((gchar *)variable_name),
"SystemIds") == 0)
3737 updated_value = g_value_get_string(value);
3738 g_message(
"Updated value is %s ", updated_value);
3739 if(g_strcmp0(g_strstrip((gchar *)updated_value),gwdata->systemids->str) != 0)
3741 bUpdateDiscoveryResult=
TRUE;
3742 g_string_assign(gwdata->systemids, updated_value);
3745 if (g_strcmp0(g_strstrip((gchar *)variable_name),
"DataGatewayIPaddress") == 0)
3747 updated_value = g_value_get_string(value);
3748 g_message(
"Updated value of DataGatewayIPaddressis %s ", updated_value);
3749 if(g_strcmp0(g_strstrip((gchar *)updated_value),gwdata->dataGatewayIPaddress->str) != 0)
3751 bUpdateDiscoveryResult=
TRUE;
3752 g_string_assign(gwdata->dataGatewayIPaddress, updated_value);
3755 if (g_strcmp0(g_strstrip((gchar *)variable_name),
"DnsConfig") == 0)
3757 updated_value = g_value_get_string(value);
3758 g_message(
"Updated value is %s ", updated_value);
3759 if(g_strcmp0(g_strstrip((gchar *)updated_value),gwdata->dnsconfig->str) != 0)
3761 bUpdateDiscoveryResult=
TRUE;
3762 g_string_assign(gwdata->dnsconfig, updated_value);
3765 if (g_strcmp0(g_strstrip((gchar *)variable_name),
"TimeZone") == 0)
3767 updated_value = g_value_get_string(value);
3768 g_message(
"Updated value is %s ", updated_value);
3769 if(g_strcmp0(g_strstrip((gchar *)updated_value),gwdata->dsgtimezone->str) != 0)
3771 bUpdateDiscoveryResult=
TRUE;
3772 g_string_assign(gwdata->dsgtimezone, updated_value);
3773 #ifdef USE_XUPNP_TZ_UPDATE
3774 if (g_strcmp0(g_strstrip(gwdata->dsgtimezone->str),
"null") != 0)
3775 broadcastTimeZoneChange(gwdata);
3779 if (g_strcmp0(g_strstrip((gchar*)variable_name),
"IPSubNet") == 0)
3781 updated_value = g_value_get_string(value);
3782 g_message(
"Updated value is %s ", updated_value);
3783 if(g_strcmp0(g_strstrip((gchar*)updated_value),gwdata->ipSubNet->str) != 0)
3785 bUpdateDiscoveryResult=
TRUE;
3786 g_string_assign(gwdata->ipSubNet, updated_value);
3787 if(updated_value && strlen(updated_value))
3788 addRouteToMocaBridge((
char*)updated_value);
3793 if(bUpdateDiscoveryResult)
3815 GKeyFile *keyfile = NULL;
3816 GKeyFileFlags flags;
3817 GError *error = NULL;
3823 keyfile = g_key_file_new ();
3824 flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
3827 if (!g_key_file_load_from_file (keyfile, configfile, flags, &error))
3830 g_error(
"%s",error->message);
3831 g_clear_error(&error);
3832 g_key_file_free(keyfile);
3847 disConf->discIf = g_key_file_get_string(keyfile,
"Network",
"discIf", NULL);
3848 disConf->gwIf = g_key_file_get_string(keyfile,
"Network",
"GwIf", NULL);
3849 disConf->GwPriority = g_key_file_get_integer(keyfile,
"Network",
"GwPriority", NULL);
3862 disConf->gwSetupFile = g_key_file_get_string(keyfile,
"DataFiles",
"gwSetupFile", NULL);
3863 disConf->logFile = g_key_file_get_string(keyfile,
"DataFiles",
"LogFile", NULL);
3864 disConf->outputJsonFile = g_key_file_get_string(keyfile,
"DataFiles",
"outputJsonFile", NULL);
3868 disConf->disCertFile= g_key_file_get_string(keyfile,
"DataFiles",
"certFile", NULL);
3869 disConf->disCertPath= g_key_file_get_string(keyfile,
"DataFiles",
"certPath", NULL);
3870 disConf->disKeyPath= g_key_file_get_string(keyfile,
"DataFiles",
"keyPath", NULL);
3871 disConf->disKeyFile= g_key_file_get_string(keyfile,
"DataFiles",
"keyFile", NULL);
3877 disConf->enableGwSetup = g_key_file_get_boolean(keyfile,
"Flags",
"enableGwSetup", NULL);
3879 g_key_file_free(keyfile);
3880 if (disConf->logFile == NULL)
3881 g_warning(
"configuration doesnt have log file so log file should be given explicitly or it will be written in console\n");
3883 if (disConf->discIf == NULL)
3885 g_warning(
"Invalid or no values found for mandatory parameters\n");
3893 g_warning(
"No configuration file \n");
3909 #ifndef CLIENT_XCAL_SERVER
3911 gboolean result = FALSE;
3912 gchar* udhcpcvendorfile = NULL;
3914 result = g_file_get_contents (
"//etc//udhcpc.vendor_specific", &udhcpcvendorfile, NULL, &error);
3915 if (result == FALSE) {
3916 g_message(
"Problem in reading /etc/udhcpcvendorfile file %s", error->message);
3922 gchar **tokens = g_strsplit_set(udhcpcvendorfile,
" \n\t\b\0", -1);
3923 guint toklength = g_strv_length(tokens);
3925 for (loopvar=0; loopvar<toklength; loopvar++)
3928 if (g_strrstr(g_strstrip(tokens[loopvar]),
"SUBOPTION4"))
3930 if ((loopvar+1) < toklength )
3932 g_string_assign(ownSerialNo, g_strstrip(tokens[loopvar+2]));
3934 g_message(
"serialNumber fetched from udhcpcvendorfile:%s", ownSerialNo->str);
3947 g_clear_error(&error);
3949 if (udhcpcvendorfile) g_free(udhcpcvendorfile);
3953 gboolean result = FALSE;
3954 char serialNumber[50] = {0};
3955 if ( platform_hal_GetSerialNumber(serialNumber) == 0)
3957 g_message(
"serialNumber returned from hal:%s", serialNumber);
3958 g_string_assign(ownSerialNo, serialNumber);
3964 g_error(
"Unable to get SerialNumber");
3970 IARM_Result_t iarmRet = IARM_RESULT_IPCCORE_FAIL;
3971 memset(¶m, 0,
sizeof(param));
3972 param.
type = mfrSERIALIZED_TYPE_SERIALNUMBER;
3974 if(iarmRet == IARM_RESULT_SUCCESS)
3978 g_message(
" serialized data %s \n",param.
buffer );
3979 g_string_assign(ownSerialNo,param.
buffer);
3985 g_message(
" serialized data is empty \n" );
3992 g_message(
"IARM CALL failed for mfrtype \n");
4011 char *return_str = NULL;
4012 char *insert_str = NULL;
4013 char *tmp_str = NULL;
4015 int distance, lenSubStr, lenRepStr, numOccurences;
4017 if ((!src_string) || (!sub_string) || (!
replace_string))
return src_string;
4019 lenSubStr = strlen(sub_string);
4022 insert_str = src_string;
4023 for (numOccurences = 0; (tmp_str = strstr(insert_str, sub_string)); ++numOccurences) {
4024 insert_str = tmp_str + lenSubStr;
4027 int rstrsize = strlen(src_string) + (lenRepStr - lenSubStr) * numOccurences + 1;
4028 tmp_str = return_str = malloc(rstrsize);
4030 if (!return_str)
return src_string;
4032 while (numOccurences--) {
4033 insert_str = strstr(src_string, sub_string);
4034 distance = insert_str - src_string;
4035 rc = strncpy_s(tmp_str, rstrsize, src_string, distance);
4037 tmp_str += distance;
4038 rstrsize -= distance;
4041 tmp_str += lenRepStr;
4042 rstrsize -= lenRepStr;
4043 src_string += distance + lenSubStr;
4045 rc =strcpy_s(tmp_str, rstrsize, src_string);
4063 int getipaddress(
const char* ifname,
char* ipAddressBuffer, gboolean ipv6Enabled)
4065 struct ifaddrs * ifAddrStruct=NULL;
4066 struct ifaddrs * ifa=NULL;
4067 void * tmpAddrPtr=NULL;
4069 if( getifaddrs(&ifAddrStruct) < 0 )
4071 g_message(
" getifaddrs is failed\n");
4079 for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
4080 if (ifa->ifa_addr == NULL)
continue;
4081 if ((ifa ->ifa_addr->sa_family==AF_INET6) && (ipv6Enabled ==
TRUE)) {
4083 tmpAddrPtr=&((
struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
4085 inet_ntop(AF_INET6, tmpAddrPtr, ipAddressBuffer, INET6_ADDRSTRLEN);
4088 rc = strcmp_s(ifa->ifa_name, strlen(ifa->ifa_name) ,ifname, &ind);
4090 if((ind == 0) && (rc == EOK))
4099 if (ifa ->ifa_addr->sa_family==AF_INET) {
4101 tmpAddrPtr=&((
struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
4103 inet_ntop(AF_INET, tmpAddrPtr, ipAddressBuffer, INET_ADDRSTRLEN);
4106 rc =strcmp_s(ifa->ifa_name,strlen(ifa->ifa_name), ifname, &ind);
4108 if((ind == 0) && (rc == EOK))
4117 if (ifAddrStruct!=NULL) freeifaddrs(ifAddrStruct);
4134 if ((g_strcmp0 (g_strstrip(gwydata->gwyip->str), g_strstrip(ipaddress)) == 0))
4136 g_message(
"isown gateway is true");
4137 gwydata->isOwnGateway=
TRUE;
4155 struct in_addr addr4;
4156 struct in6_addr addr6;
4157 int validip4 = inet_pton(AF_INET, ipAddress, &addr4);
4158 int validip6 = inet_pton(AF_INET6, ipAddress, &addr6);
4159 if (g_strrstr(g_strstrip(ipAddress),
"null") || ! *ipAddress )
4161 g_message (
"ipaddress are empty %s",ipAddress);
4165 if ((validip4 == 1 ) || (validip6 == 1 ))
4171 g_message(
"Not a valid ip address %s " , ipAddress);
4186 if (g_strrstr(g_strstrip(hostname),
"null") || ! *hostname )
4188 g_message (
"hostname values are empty %s",hostname);
4191 gchar **tokens = g_strsplit_set(hostname,
" ;\n\0", -1);
4192 guint toklength = g_strv_length(tokens);
4195 for (loopvar=0; loopvar<toklength; loopvar++)
4203 g_message(
" no valid ip so rejecting the dns values %s ",hostname);
4208 #if defined(USE_XUPNP_IARM) || defined(USE_XUPNP_IARM_BUS)
4209 void broadcastIPModeChange(
void)
4213 eventData.data.systemStates.stateId = IARM_BUS_SYSMGR_SYSSTATE_IP_MODE;
4214 eventData.data.systemStates.state = 1;
4215 eventData.data.systemStates.error = 0;
4216 rc = strcpy_s(eventData.data.systemStates.payload,
sizeof(eventData.data.systemStates.payload), ipMode->str);
4218 eventData.data.systemStates.payload[strlen(ipMode->str)]=
'\0';
4220 g_message(
"sent event for ipmode= %s",ipMode->str);
4224 #ifdef USE_XUPNP_TZ_UPDATE
4228 static int prevTzIndex = -1;
4229 int currTZIndex = -1;
4230 static bool IsDst =
false;
4234 int size =
sizeof(m_timezoneinfo)/
sizeof(
struct _Timezone);
4236 for (i = 0; i < size; i++ )
4238 if (g_strcmp0(m_timezoneinfo[i].upnpTZ, gwdata->dsgtimezone->str) == 0)
4246 if(currTZIndex == -1)
4248 g_message(
"broadcastTimeZoneChange: Do Not Update Inavlid Time Zone - %s ",gwdata->dsgtimezone->str);
4255 if((prevTzIndex != currTZIndex) || (IsDst != gwdata->usesdaylighttime))
4257 eventData.data.systemStates.stateId = IARM_BUS_SYSMGR_SYSSTATE_TIME_ZONE;
4258 eventData.data.systemStates.state = 2;
4259 eventData.data.systemStates.error = 0;
4262 if(gwdata->usesdaylighttime)
4264 snprintf(eventData.data.systemStates.payload,
4265 sizeof(eventData.data.systemStates.payload),
"%s", m_timezoneinfo[currTZIndex].tzInDst);
4269 snprintf(eventData.data.systemStates.payload,
4270 sizeof(eventData.data.systemStates.payload),
"%s", m_timezoneinfo[currTZIndex].tz);
4272 g_message(
"broadcastTimeZoneChange: sending SysMgr TZ Event with Payload - %s",eventData.data.systemStates.payload);
4275 prevTzIndex = currTZIndex;
4276 IsDst = gwdata->usesdaylighttime;
4281 int getSoupStatusFromUrl(
char* url)
4284 SoupSession *session = soup_session_sync_new_with_options (SOUP_SESSION_TIMEOUT,1, NULL);
4287 SoupMessage *msg = soup_message_new (
"HEAD", url);
4290 soup_session_send_message (session, msg);
4291 if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code))
4293 g_message(
"soup status for %s success",url);
4298 g_message(
"soup message creation failed url %s ",url);
4299 soup_session_abort (session);
4300 g_object_unref (session);
4303 g_message(
"soup session creation failed");
4320 GString *data = g_string_new(NULL);
4321 fd = socket(AF_INET, SOCK_DGRAM, 0);
4323 g_message(
"socket failed\n");
4326 ifr.ifr_addr.sa_family = AF_INET;
4327 strncpy(ifr.ifr_name , ifname , IFNAMSIZ - 1);
4329 if(ioctl(fd, SIOCGIFHWADDR, &ifr) < 0 )
4331 g_message(
" ioctl is failed\n");
4334 mac = (
unsigned char *)ifr.ifr_hwaddr.sa_data;
4337 g_string_printf(data,
"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], mac[1], mac[2],
4338 mac[3], mac[4], mac[5]);