-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxcal-device-main.c
More file actions
2020 lines (1960 loc) · 78.4 KB
/
xcal-device-main.c
File metadata and controls
2020 lines (1960 loc) · 78.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* If not stated otherwise in this file or this component's Licenses.txt file the
* following copyright and licenses apply:
*
* Copyright 2018 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <libgupnp/gupnp.h>
//#include <libgssdp/gssdp.h>
#include <stdio.h>
#include <stdlib.h>
#include <gmodule.h>
#include <stdbool.h>
#include <memory.h>
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <string.h>
#include "secure_wrapper.h"
#include "xdevice.h"
#ifdef INCLUDE_BREAKPAD
#include "breakpad_wrapper.h"
#else
#endif
#ifdef ENABLE_SD_NOTIFY
#include <systemd/sd-daemon.h>
#endif
#include "rdk_safeclib.h"
#define DEVICE_XML_PATH "/etc/xupnp/"
#define DEVICE_XML_FILE "BasicDevice.xml"
#define CLIENT_DEVICE_XML_FILE "X1Renderer.xml"
#define GW_DEVICE_XML_FILE "X1VideoGateway.xml"
#define BROADBAND_DEVICE_XML_FILE "X1BroadbandGateway.xml"
#define LOG_FILE "/opt/logs/xdevice.log"
#define DEVICE_PROTECTION_CONTEXT_PORT 50757
#define MAXSIZE 256
#define RUIURLSIZE 2048
#define URLSIZE 512
#ifndef BOOL
#define BOOL unsigned char
#endif
#ifndef BROADBAND
int xPKI_check_rfc();
#endif
static GMainLoop *main_loop;
char devBcastIf[MAXSIZE],serial_Num[MAXSIZE], cvpInterface[MAXSIZE], cvPXmlFile[MAXSIZE],playBackUrl[URLSIZE],devXMlPath[MAXSIZE],uUid[MAXSIZE],ruiUrl[RUIURLSIZE];
char devXMlFile [MAXSIZE],devBcastIf[MAXSIZE],serial_Num[MAXSIZE],cvpInterface[MAXSIZE],cvPXmlFile[MAXSIZE],ipv6preFix[MAXSIZE],trmUrl[MAXSIZE],urL[MAXSIZE];
char gwyIp[MAXSIZE],gwyIpv6[MAXSIZE],gwystbIp[MAXSIZE],hostMacaddress[MAXSIZE],bcastMacaddress[MAXSIZE],recvdevType[MAXSIZE],deviceType[MAXSIZE],modelclass[MAXSIZE],modelNumber[MAXSIZE],deviceid[MAXSIZE],hardwarerevision[MAXSIZE],softwarerevision[MAXSIZE],managementurl[MAXSIZE],Make[MAXSIZE],accountId[MAXSIZE],clientIp[MAXSIZE];
char buildVersion[MAXSIZE],dnsConfig[MAXSIZE],systemIds[MAXSIZE],dataGatewayIPAddress[MAXSIZE],dsgtimeZone[MAXSIZE],deviceName[MAXSIZE],etcHosts[RUIURLSIZE],receiverId[MAXSIZE],ipsubnet[MAXSIZE];
char devPXmlFile[MAXSIZE], devCertFile[MAXSIZE], devCertPath[MAXSIZE], devKeyFile[MAXSIZE], devKeyPath[MAXSIZE];
gint rawoffset, dstoffset, dstsavings, devBcastPort, cvpPort;
gboolean usedaylightsavings,allowgwy,requiresTrm;
char *caFile="/tmp/UPnP_CA";
static int rfc_enabled;
#ifdef SAFEC_DUMMY_API
//adding strcmp_s defination
errno_t strcmp_s(const char * d,int max ,const char * src,int *r)
{
*r= strcmp(d,src);
return EOK;
}
#endif
static xmlNode * get_node_by_name(xmlNode * node, const char *node_name)
{
errno_t rc = -1;
int ind = -1;
xmlNode * cur_node = NULL;
xmlNode * ret = NULL;
for (cur_node = node ; cur_node ; cur_node = cur_node->next)
{
rc = strcmp_s(cur_node->name, strlen(cur_node->name), node_name, &ind);
ERR_CHK(rc);
if ((ind ==0) && (rc == EOK))
{
return cur_node;
}
ret = get_node_by_name(cur_node->children, node_name);
if ( ret != NULL )
break;
}
return ret;
}
/**
* @brief This function is used to set new value to the given node from the xml file.
*
* @param[in] doc Xml document.
* @param[in] node_name The name of the node to be updated.
* @param[in] new_value New value to be set for the node.
*
* @return Returns Integer value '0' if successfully sets the new node value else returns '1'.
* @ingroup XUPNP_XCALDEV_FUNC
*/
int set_content(xmlDoc* doc, const char * node_name, const char * new_value)
{
xmlNode * root_element = NULL;
xmlNode * target_node = NULL;
root_element = xmlDocGetRootElement(doc);
target_node = get_node_by_name(root_element, node_name);
if (target_node==NULL)
{
g_printerr("Couldn't locate the Target node\n");
return 1;
}
xmlNodeSetContent(target_node,new_value);
return 0;
}
/**
* @brief This function is used to update the xml node values UDN, serialNumber and friendlyName.
*
* @param[in] xmlfilename Name of the XML file.
* @param[in] struuid Unique device Id .
* @param[in] serialno Serial number.
* @param[in] friendlyName Friendly name.
*
* @return Returns TRUE if successfully updated the xml data else returns FALSE.
* @ingroup XUPNP_XCALDEV_FUNC
*/
BOOL updatexmldata(const char* xmlfilename, const char* struuid, const char* serialno, const char* friendlyName)
{
LIBXML_TEST_VERSION
xmlDoc * doc = open_document(xmlfilename);
if (doc == NULL)
{
g_printerr ("Error reading the Device XML file\n");
return FALSE;
}
if(rfc_enabled)
{
if (set_content(doc, "UPC", "10000")!=0)
{
g_printerr ("Error setting the upc in conf xml\n");
return FALSE;
}
g_message("Added UPC value to %s",xmlfilename);
}
else
{
if (set_content(doc, "UPC", "")!=0)
{
g_printerr ("Error setting the upc in conf xml\n");
return FALSE;
}
g_message("Updated UPC value as empty string in %s",xmlfilename);
}
if (set_content(doc, "UDN", struuid)!=0)
{
g_printerr ("Error setting the unique device id in conf xml\n");
return FALSE;
}
if (set_content(doc, "serialNumber", serialno)!=0)
{
g_printerr ("Error setting the serial number in conf xml\n");
return FALSE;
}
if(NULL != friendlyName)
{
if (set_content(doc, "friendlyName", friendlyName)!=0)
{
g_printerr ("Error setting the friendlyName number in conf xml\n");
return FALSE;
}
}
else
{
g_printerr ("friendlyName is NULL\n");
}
FILE *fp = fopen(xmlfilename, "w");
if (fp==NULL)
{
g_printerr ("Error opening the conf xml file for writing\n");
return FALSE;
}
else if (xmlDocFormatDump(fp, doc, 1) == -1)
{
g_printerr ("Could not write the conf to xml file\n");
/*Coverity Fix CID 125137,28460 RESOURCE_LEAK */
fclose(fp);
xmlFreeDoc(doc);
return FALSE;
}
fclose(fp);
xmlFreeDoc(doc);
xmlCleanupParser();
return TRUE;
}
/**
* @brief A generic function to notify all the clients whenever there is a change found in the
* service variable values.
*
* @param[in] varname Node name to be notified.
* @param[in] strvalue New value to be notified.
* @ingroup XUPNP_XCALDEV_FUNC
*/
void notify_value_change(const char* varname, const char* strvalue)
{
if ((service_ready==FALSE) )
{
g_warning("Received notificaton before start of Service");
}
else
{
// GValue value = {0};
GValue value = G_VALUE_INIT;
g_value_init(&value, G_TYPE_STRING);
g_value_set_static_string(&value, strvalue);
g_message("Sending value change notification Name %s - Value: %s", varname, strvalue);
gupnp_service_notify_value((GUPnPService *)upnpService, varname, &value);
//g_value_unset(&value);
}
return;
}
/**
* @brief Supporting function for reading the XML file
*
* @param[in] file_name Name of the xml file
*
* @return Returns the resulting document tree.
* @ingroup XUPNP_XCALDEV_FUNC
*/
xmlDoc * open_document(const char * file_name)
{
xmlDoc * ret;
ret = xmlReadFile(file_name, NULL, 0);
if (ret == NULL)
{
//g_printerr("Failed to parse %s\n", file_name);
return NULL;
}
return ret;
}
/**
* @brief Callback function which is invoked when getBaseURL action is invoked and this sets the
* state variable for base url.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
*
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetBaseUrl */
G_MODULE_EXPORT void
get_url_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//static int counter=0;
//counter++;
//g_print ("Got a call back for url %d\n", counter);
getBaseUrl(urL);
gupnp_service_action_set (action, "BaseUrl", G_TYPE_STRING, urL, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getBaseTrmUrl action is invoked and this sets the state
* variable for base TRM Url.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
*
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetBaseTrmUrl */
G_MODULE_EXPORT void
get_trm_url_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back for trm url, value is %s\n", trmurl->str); trmUrl
getTrmUrl(trmUrl);
gupnp_service_action_set (action, "BaseTrmUrl", G_TYPE_STRING, trmUrl, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getPlaybackUrl action is invoked and this sets
* the state variable for Playback Url.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetPlayBackUrl */
G_MODULE_EXPORT void
get_playback_url_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_message ("Got a call back for playback url, value is %s\n", playbackurl->str);
if (getTuneReady())
{
//g_message ("Got a call back for playback url, value is %s\n", playbackurl->str);
getPlaybackUrl(playBackUrl);
gupnp_service_action_set (action, "PlaybackUrl", G_TYPE_STRING, playBackUrl ,NULL);
}
else
{
//g_message ("Got a call back for playback url, Sending NULL\n", playbackurl->str);
gupnp_service_action_set (action, "PlaybackUrl", G_TYPE_STRING, "NULL", NULL);
}
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getGatewayIP action is invoked and this sets
* the state variable for Gateway IP.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetGatewayIP */
G_MODULE_EXPORT void
get_gwyip_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getGatewayIp(gwyIp);
gupnp_service_action_set (action, "GatewayIP", G_TYPE_STRING, gwyIp, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getGatewayIPv6 action is invoked and this sets
* the state variable for Gateway IPv6.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetGatewayIPv6 */
G_MODULE_EXPORT void
get_gwyipv6_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getGatewayIpv6(gwyIpv6);
gupnp_service_action_set (action, "GatewayIPv6", G_TYPE_STRING, gwyIpv6, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getGatewayStbIP action is invoked and this sets
* the state variable for Gateway STB IP.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
*
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetGatewayIP */
G_MODULE_EXPORT void
get_gwystbip_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getGatewayStbIp(gwystbIp);
gupnp_service_action_set (action, "GatewayStbIP", G_TYPE_STRING, gwystbIp, NULL);
gupnp_service_action_return (action);
}
#ifndef BROADBAND
/**
* @brief Callback function which is invoked when getIpv6Prefix action is invoked and this sets
* the state variable for IPv6 Prefix.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
*
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetIpv6Prefix */
G_MODULE_EXPORT void
get_ipv6prefix_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n"); ipv6preFix
getIpv6Prefix(ipv6preFix);
gupnp_service_action_set (action, "Ipv6Prefix", G_TYPE_STRING, ipv6preFix, NULL);
gupnp_service_action_return (action);
}
#endif
/**
* @brief Callback function which is invoked when getHostMacAddress action is invoked and this sets
* the state variable for Host MAC Address.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetHostMacAddress */
G_MODULE_EXPORT void
get_hostmacaddress_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getHostMacAddress(hostMacaddress);
gupnp_service_action_set (action, "HostMacAddress", G_TYPE_STRING, hostMacaddress, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getBcastMacAddress action is invoked and this sets
* the state variable for Broadcast MAC Address.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetBcastMacAddress */
G_MODULE_EXPORT void
get_bcastmacaddress_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
// getBcastMacAddress(bcastMacaddress);
gupnp_service_action_set (action, "BcastMacAddress", G_TYPE_STRING, bcastMacaddress, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getRecvDevType action is invoked and this sets
* the state variable for Receive Device Type.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetRecvDevType */
G_MODULE_EXPORT void
get_recvdevtype_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getRecvDevType(recvdevType);
gupnp_service_action_set (action, "RecvDevType", G_TYPE_STRING, recvdevType, NULL);
gupnp_service_action_return (action);
}
/* GetDeviceType */
G_MODULE_EXPORT void
get_devicetype_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getDeviceType(deviceType);
gupnp_service_action_set (action, "DeviceType", G_TYPE_STRING, deviceType, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getBuildVersion action is invoked and this sets
* the state variable for Build Version.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetBuildVersion */
G_MODULE_EXPORT void
get_buildversion_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getBuildVersion(buildVersion);
gupnp_service_action_set (action, "BuildVersion", G_TYPE_STRING, buildVersion, NULL);
gupnp_service_action_return (action);
}
#ifndef BROADBAND
/**
* @brief Callback function which is invoked when getDnsConfig action is invoked and this sets
* the state variable for DNS Config.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetDnsConfig */
G_MODULE_EXPORT void
get_dnsconfig_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
getDnsConfig(dnsConfig);
gupnp_service_action_set (action, "DnsConfig", G_TYPE_STRING, dnsConfig, NULL);
gupnp_service_action_return (action);
}
#endif
/**
* @brief Callback function which is invoked when getSystemIds action is invoked and this sets
* the state variable for System Id.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetSystemsIds */
G_MODULE_EXPORT void
get_systemids_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getSystemsIds(systemIds);
gupnp_service_action_set (action, "SystemIds", G_TYPE_STRING, systemIds, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getdataGatewayIPaddress action is invoked and this sets
* the state variable for DataGatewayIPaddress.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetDataGatewayIPaddress */
G_MODULE_EXPORT void
get_dataGatewayIPaddress_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
if ( rfc_enabled )
{
getGatewayStbIp(dataGatewayIPAddress);
}
else
{
getRouteDataGateway(dataGatewayIPAddress);
}
gupnp_service_action_set (action, "DataGatewayIPaddress", G_TYPE_STRING, dataGatewayIPAddress, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when IPSubNet action is invoked and this sets
* the state variable for IPSubNet.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetIPSubNet */
G_MODULE_EXPORT void
get_ipsubnet_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
getIpSubnet(ipsubnet);
gupnp_service_action_set (action, "IPSubNet", G_TYPE_STRING, ipsubnet, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when TimeZone action is invoked and this sets
* the state variable for Time Zone.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetTimeZone */
G_MODULE_EXPORT void
get_timezone_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
if(getIsuseGliDiagEnabled()) {
getTimeZone(dsgtimeZone);
}
gupnp_service_action_set (action, "TimeZone", G_TYPE_STRING, dsgtimeZone, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getRawOffSet action is invoked and this sets
* the state variable for Raw Offset.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetRawOffSet */
G_MODULE_EXPORT void
get_rawoffset_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
getRawOffSet(&rawoffset);
gupnp_service_action_set (action,"RawOffSet", G_TYPE_INT, rawoffset, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getDSTSavings action is invoked and this sets
* the state variable for DST Savings.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetDSTSavings */
G_MODULE_EXPORT void
get_dstsavings_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
getDstSavings(&dstsavings);
gupnp_service_action_set (action,"DSTSavings", G_TYPE_INT, dstsavings, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getUsesDaylightTime action is invoked and this sets
* the state variable for Uses Daylight Time.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetUsesDaylightTime */
G_MODULE_EXPORT void
get_usesdaylighttime_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
getUsesDayLightTime((unsigned char *)&usedaylightsavings);
gupnp_service_action_set (action,"UsesDaylightTime", G_TYPE_BOOLEAN, usedaylightsavings, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getDeviceName action is invoked and this sets
* the state variable for Uses Service Name.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetDeviceName */
G_MODULE_EXPORT void
get_devicename_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
getDeviceName(deviceName);
gupnp_service_action_set (action,"DeviceName", G_TYPE_STRING, deviceName, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getDSTOffset action is invoked and this sets
* the state variable for DST Offset.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetDSTOffset */
G_MODULE_EXPORT void
get_dstoffset_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
getDstOffset(&dstoffset);
gupnp_service_action_set (action,"DSTOffset", G_TYPE_INT, dstoffset, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getHosts action is invoked and this sets
* the state variable for Hosts.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetEtcHosts */
G_MODULE_EXPORT void
get_hosts_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getHosts(etcHosts);
gupnp_service_action_set (action, "Hosts", G_TYPE_STRING, etcHosts, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getIsGateway action is invoked and this sets
* the state variable for Gatway is active or not.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetIsGateway */
G_MODULE_EXPORT void
get_isgateway_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
gchar *clientMacAddr=NULL;
gchar *clientIpAddr=NULL;
gboolean deviceProtectionEnabled=TRUE;
if(rfc_enabled)
{
if(gupnp_service_action_get_argument_count(action))
{
gupnp_service_action_get (action, "deviceProtection", G_TYPE_BOOLEAN,&deviceProtectionEnabled, NULL);
if(!deviceProtectionEnabled)
{
gupnp_service_action_get (action, "macAddr", G_TYPE_STRING, &clientMacAddr, NULL);
gupnp_service_action_get (action, "ipAddr", G_TYPE_STRING, &clientIpAddr, NULL);
if((clientMacAddr) && (clientIpAddr))
g_warning("Device Protection Disabled Device : %s,%s",clientMacAddr,clientIpAddr);
else
g_warning("Device Protection Disabled Device without details");
}
}
else
g_warning("Device Protection Not supported legacy Device");
}
getIsGateway((unsigned char *)&allowgwy);
gupnp_service_action_set (action, "IsGateway", G_TYPE_BOOLEAN, allowgwy, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when getRequiresTRM action is invoked and this sets
* the state variable for Requiring TRM.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* IsTrmRequired */
G_MODULE_EXPORT void
get_requirestrm_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
getRequiresTRM((unsigned char *)&requiresTrm);
gupnp_service_action_set (action, "RequiresTRM", G_TYPE_BOOLEAN, requiresTrm, NULL);
gupnp_service_action_return (action);
}
/**
* @brief Callback function which is invoked when GetCompatibleUIs action is invoked and this sets
* the state variable for InputDeviceProfile, UIFilter and UIListing.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetRuiBaseUrl */
G_MODULE_EXPORT void
get_rui_url_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//must init every callback because it generates a unique
//device number for each return value.
if(!getRUIUrl(ruiUrl)){
g_print("Error in initializing RUI url value\n");
//g_print ("Got a call back for Ruiurl, value is %s\n", ruiurl->str);
}
gupnp_service_action_get (action,"InputDeviceProfile", G_TYPE_STRING, inDevProfile->str, NULL);
gupnp_service_action_get (action,"UIFilter", G_TYPE_STRING, uiFilter->str,NULL);
gupnp_service_action_set (action, "UIListing", G_TYPE_STRING, ruiUrl, NULL);
gupnp_service_action_return (action);
}
/*Coverity Fix CID: 45236 to 45244 MISSED_RETURN */
G_MODULE_EXPORT void
get_modelclass_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getDeviceType(modelclass);
gupnp_service_action_set (action, "ModelClass", G_TYPE_STRING, modelclass, NULL);
gupnp_service_action_return (action);
}
G_MODULE_EXPORT void
get_modelnumber_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getModelNumber(modelNumber);
gupnp_service_action_set (action, "ModelNumber", G_TYPE_STRING, modelNumber, NULL);
gupnp_service_action_return (action);
}
G_MODULE_EXPORT void
get_deviceid_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
gupnp_service_action_set (action, "DeviceId", G_TYPE_STRING, deviceid, NULL);
gupnp_service_action_return (action);
}
G_MODULE_EXPORT void
get_hardwarerevision_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
gupnp_service_action_set (action, "HardwareRevision", G_TYPE_STRING, hardwarerevision, NULL);
gupnp_service_action_return (action);
}
G_MODULE_EXPORT void
get_softwarerevision_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
gupnp_service_action_set (action, "SoftwareRevision", G_TYPE_STRING, softwarerevision, NULL);
gupnp_service_action_return (action);
}
G_MODULE_EXPORT void
get_managementurl_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
gupnp_service_action_set (action, "ManagementURL", G_TYPE_STRING, managementurl, NULL);
gupnp_service_action_return (action);
}
G_MODULE_EXPORT void
get_make_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
getMake(Make);
gupnp_service_action_set (action, "Make", G_TYPE_STRING, Make, NULL);
gupnp_service_action_return (action);
}
G_MODULE_EXPORT void
get_recev_id_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
gupnp_service_action_set (action, "ReceiverId", G_TYPE_STRING, receiverId, NULL);
gupnp_service_action_return (action);
}
G_MODULE_EXPORT void
get_account_id_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
gchar *clientAccountId=NULL;
//SoupMessage *msg;
gchar *clientMacAddr=NULL;
gchar *clientIpAddr=NULL;
#ifdef BROADBAND
int ret = 0;
#endif
/* Get the client account Id value */
gupnp_service_action_get (action, "SAccountId", G_TYPE_STRING, &clientAccountId, NULL);
gupnp_service_action_set (action, "GAccountId", G_TYPE_STRING, accountId, NULL);
gupnp_service_action_get (action, "macAddr", G_TYPE_STRING, &clientMacAddr, NULL);
gupnp_service_action_get (action, "ipAddr", G_TYPE_STRING, &clientIpAddr, NULL);
if ((clientAccountId) && (!strcmp(clientAccountId, accountId)))
{
g_warning("Client connection account ID same : %s,%s,%s,%s" , accountId,clientAccountId,clientMacAddr,clientIpAddr);
#ifdef BROADBAND
// add whitelist
#if !defined (NO_MOCA_FEATURE_SUPPORT)
g_warning("/usr/ccsp/moca/moca_whitelist_ctl.sh add %s",clientIpAddr);
ret = v_secure_system("/usr/ccsp/moca/moca_whitelist_ctl.sh add %s", clientIpAddr);
if(ret != 0) {
g_warning("Failure in executing command via v_secure_system. ret:[%d] ;\n", ret);
}
#endif
#endif
gupnp_service_action_return (action);
}
else
{
// AccountId is not matching.
// Log the message, accountId receivede
// Disconnect soup session TBD.
g_warning("Client connection account ID mismatch found : %s,%s,%s,%s" , accountId,clientAccountId,clientMacAddr,clientIpAddr);
#ifdef BROADBAND
#if !defined (NO_MOCA_FEATURE_SUPPORT)
g_warning("/usr/ccsp/moca/moca_whitelist_ctl.sh del %s", clientIpAddr);
ret = v_secure_system("/usr/ccsp/moca/moca_whitelist_ctl.sh del %s", clientIpAddr);
if(ret != 0) {
g_warning("Failure in executing command via v_secure_system. ret:[%d] ;\n", ret);
}
#endif
#endif
//msg = gupnp_service_action_get_message(action);
gupnp_service_action_return (action);
//g_warning("service action returning error ");
//gupnp_service_action_return_error (action, 402, "Account Id not matching");
//g_warning("service action aborting session ");
//gupnp_service_action_abort_session(service);
}
//g_warning("get_account_id_cb exit ");
}
/**
* @brief Callback function which is invoked when getClientIP action is invoked and this sets
* the state variable for Client IP.
*
* @param[in] service Name of the service.
* @param[out] action Action to be invoked.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* GetGatewayIP */
G_MODULE_EXPORT void
get_client_ip_cb (GUPnPService *service, GUPnPServiceAction *action, gpointer user_data)
{
//g_print ("Got a call back\n");
gupnp_service_action_set (action, "ClientIP", G_TYPE_STRING, clientIp, NULL);
gupnp_service_action_return (action);
}
/*
* State Variable query handlers
*/
/**
* @brief Callback function which is invoked when getUrl action is invoked.
*
* @param[in] service Name of the service.
* @param[in] variable State(Query)variable.
* @param[in] value New value to be assigned.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* BaseUrl */
G_MODULE_EXPORT void
query_url_cb (GUPnPService *service, char *variable, GValue *value, gpointer user_data)
{
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, urL);
}
/**
* @brief Callback function which is invoked when TrmUrl action is invoked and this sets
* the state variable with a new TRM Url value.
*
* @param[in] service Name of the service.
* @param[in] variable State(Query) variable.
* @param[in] value New value to be assigned.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* BaseTrmUrl */
G_MODULE_EXPORT void
query_trm_url_cb (GUPnPService *service, char *variable, GValue *value, gpointer user_data)
{
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, trmUrl);
}
/**
* @brief Callback function which is invoked when PlaybackUrl action is invoked and this sets
* the state variable with a new playback url.
*
* @param[in] service Name of the service.
* @param[in] variable State(Query) variable.
* @param[in] value New value to be assigned.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* PlaybackUrl */
G_MODULE_EXPORT void
query_playback_url_cb (GUPnPService *service, char *variable, GValue *value, gpointer user_data)
{
if(getTuneReady())
{
//g_message ("Got a query for playback url, sending %s\n", playbackurl->str);
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, playBackUrl);
}
else
{
//g_message ("Got a query for playback url, sending NULL");
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, "NULL");
}
}
/**
* @brief Callback function which is invoked when DataGatewayIPaddress action is invoked and this sets
* the state variable with a new DataGatewayIPaddress.
*
* @param[in] service Name of the service.
* @param[in] variable State(Query) variable.
* @param[in] value New value to be assigned.
* @param[in] user_data Usually null will be passed.
* @ingroup XUPNP_XCALDEV_FUNC
*/
/* DataGatewayIPaddress */
G_MODULE_EXPORT void
query_dataGatewayIPaddress_cb (GUPnPService *service, char *variable, GValue *value, gpointer user_data)
{
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, dataGatewayIPAddress);
}
/**
* @brief Callback function which is invoked when DeviceName action is invoked and this sets
* the state variable with a new device name.
*
* @param[in] service Name of the service.
* @param[in] variable State(Query) variable.
* @param[in] value New value to be assigned.