-
Notifications
You must be signed in to change notification settings - Fork 0
/
upnpdescgen.c
executable file
·1362 lines (1278 loc) · 37.7 KB
/
upnpdescgen.c
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
/* $Id: upnpdescgen.c,v 1.83 2017/05/27 07:47:57 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2018 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#ifdef ENABLE_EVENTS
#include "getifaddr.h"
#include "upnpredirect.h"
#endif
#include "upnpdescgen.h"
#include "miniupnpdpath.h"
#include "upnpglobalvars.h"
#include "upnpdescstrings.h"
#include "upnpurns.h"
#include "getconnstatus.h"
/* Event magical values codes */
#define SETUPREADY_MAGICALVALUE (248)
#define CONNECTIONSTATUS_MAGICALVALUE (249)
#define FIREWALLENABLED_MAGICALVALUE (250)
#define INBOUNDPINHOLEALLOWED_MAGICALVALUE (251)
#define SYSTEMUPDATEID_MAGICALVALUE (252)
#define PORTMAPPINGNUMBEROFENTRIES_MAGICALVALUE (253)
#define EXTERNALIPADDRESS_MAGICALVALUE (254)
#define DEFAULTCONNECTIONSERVICE_MAGICALVALUE (255)
static const char * const upnptypes[] =
{
"string",
"boolean",
"ui2",
"ui4",
"bin.base64"
};
static const char * const upnpdefaultvalues[] =
{
0,
"IP_Routed"/*"Unconfigured"*/, /* 1 default value for ConnectionType */
"3600", /* 2 default value for PortMappingLeaseDuration */
"Unconfigured", /* 3 default value for ConnectionStatus */
"0", /* 4 default value for RSIPAvailable */
"1", /* 5 default value for NATEnabled */
"ERROR_NONE", /* 6 default value for LastConnectionError */
};
static const char * const upnpallowedvalues[] =
{
0, /* 0 */
"DSL", /* 1 */
"POTS",
"Cable",
"Ethernet",
0,
"Up", /* 6 */
"Down",
"Initializing",
"Unavailable",
0,
"TCP", /* 11 */
"UDP",
0,
"Unconfigured", /* 14 */
"IP_Routed",
"IP_Bridged",
0,
"Unconfigured", /* 18 */
"Connecting",
"Connected",
"PendingDisconnect",
"Disconnecting",
"Disconnected",
0,
"ERROR_NONE", /* 25 */
/* Optionals values :
* ERROR_COMMAND_ABORTED
* ERROR_NOT_ENABLED_FOR_INTERNET
* ERROR_USER_DISCONNECT
* ERROR_ISP_DISCONNECT
* ERROR_IDLE_DISCONNECT
* ERROR_FORCED_DISCONNECT
* ERROR_NO_CARRIER
* ERROR_IP_CONFIGURATION
* ERROR_UNKNOWN */
0,
"", /* 27 */
0
};
static const int upnpallowedranges[] = {
0,
/* 1 PortMappingLeaseDuration */
0,
604800,
/* 3 InternalPort */
1,
65535,
/* 5 LeaseTime */
1,
86400,
/* 7 OutboundPinholeTimeout */
100,
200,
};
static const char * magicargname[] = {
0,
"StartPort", /* 1 */
"EndPort", /* 2 */
"RemoteHost", /* 3 */
"RemotePort", /* 4 */
"InternalClient", /* 5 */
"InternalPort", /* 6 */
"IsWorking", /* 7 */
#ifdef ENABLE_DP_SERVICE
"ProtocolType", /* 8 */
"InMessage", /* 9 */
"OutMessage", /* 10 */
"ProtocolList", /* 11 */
"RoleList", /* 12 */
#endif /* ENABLE_DP_SERVICE */
};
static const char xmlver[] =
"<?xml version=\"1.0\"?>\r\n";
static const char root_service[] =
"scpd xmlns=\"urn:schemas-upnp-org:service-1-0\"";
static const char root_device[] =
"root xmlns=\"urn:schemas-upnp-org:device-1-0\"";
/* root Description of the UPnP Device
* fixed to match UPnP_IGD_InternetGatewayDevice 1.0.pdf
* Needs to be checked with UPnP-gw-InternetGatewayDevice-v2-Device.pdf
* presentationURL is only "recommended" but the router doesn't appears
* in "Network connections" in Windows XP if it is not present. */
static const struct XMLElt rootDesc[] =
{
/* 0 */
{root_device, INITHELPER(1,2)},
{"specVersion", INITHELPER(3,2)},
#if defined(ENABLE_L3F_SERVICE) || defined(HAS_DUMMY_SERVICE) || defined(ENABLE_DP_SERVICE)
{"device", INITHELPER(5,13)},
#else
{"device", INITHELPER(5,12)},
#endif
{"/major", UPNP_VERSION_MAJOR_STR},
{"/minor", UPNP_VERSION_MINOR_STR},
/* 5 */
{"/deviceType", DEVICE_TYPE_IGD},
/* urn:schemas-upnp-org:device:InternetGatewayDevice:1 or 2 */
#ifdef ENABLE_MANUFACTURER_INFO_CONFIGURATION
{"/friendlyName", friendly_name/*ROOTDEV_FRIENDLYNAME*/}, /* required */
{"/manufacturer", manufacturer_name/*ROOTDEV_MANUFACTURER*/}, /* required */
/* 8 */
{"/manufacturerURL", manufacturer_url/*ROOTDEV_MANUFACTURERURL*/}, /* optional */
{"/modelDescription", model_description/*ROOTDEV_MODELDESCRIPTION*/}, /* recommended */
{"/modelName", model_name/*ROOTDEV_MODELNAME*/}, /* required */
{"/modelNumber", modelnumber},
{"/modelURL", model_url/*ROOTDEV_MODELURL*/},
#else
{"/friendlyName", ROOTDEV_FRIENDLYNAME}, /* required */
{"/manufacturer", ROOTDEV_MANUFACTURER}, /* required */
/* 8 */
{"/manufacturerURL", ROOTDEV_MANUFACTURERURL}, /* optional */
{"/modelDescription", ROOTDEV_MODELDESCRIPTION}, /* recommended */
{"/modelName", ROOTDEV_MODELNAME}, /* required */
{"/modelNumber", modelnumber},
{"/modelURL", ROOTDEV_MODELURL},
#endif
{"/serialNumber", serialnumber},
{"/UDN", uuidvalue_igd}, /* required */
/* see if /UPC is needed. */
#ifdef ENABLE_6FC_SERVICE
#define SERVICES_OFFSET 63
#else
#define SERVICES_OFFSET 58
#endif
#if defined(ENABLE_L3F_SERVICE) || defined(HAS_DUMMY_SERVICE) || defined(ENABLE_DP_SERVICE)
/* here we dening Services for the root device :
* L3F and DUMMY and DeviceProtection */
#ifdef ENABLE_L3F_SERVICE
#define NSERVICES1 1
#else
#define NSERVICES1 0
#endif
#ifdef HAS_DUMMY_SERVICE
#define NSERVICES2 1
#else
#define NSERVICES2 0
#endif
#ifdef ENABLE_DP_SERVICE
#define NSERVICES3 1
#else
#define NSERVICES3 0
#endif
#define NSERVICES (NSERVICES1+NSERVICES2+NSERVICES3)
{"serviceList", INITHELPER(SERVICES_OFFSET,NSERVICES)},
{"deviceList", INITHELPER(18,1)},
{"/presentationURL", presentationurl}, /* recommended */
#else
{"deviceList", INITHELPER(18,1)},
{"/presentationURL", presentationurl}, /* recommended */
{0,0},
#endif
/* 18 */
{"device", INITHELPER(19,13)},
/* 19 */
{"/deviceType", DEVICE_TYPE_WAN}, /* required */
/* urn:schemas-upnp-org:device:WANDevice:1 or 2 */
{"/friendlyName", WANDEV_FRIENDLYNAME},
{"/manufacturer", WANDEV_MANUFACTURER},
{"/manufacturerURL", WANDEV_MANUFACTURERURL},
{"/modelDescription" , WANDEV_MODELDESCRIPTION},
{"/modelName", WANDEV_MODELNAME},
{"/modelNumber", WANDEV_MODELNUMBER},
{"/modelURL", WANDEV_MODELURL},
{"/serialNumber", serialnumber},
{"/UDN", uuidvalue_wan},
{"/UPC", WANDEV_UPC}, /* UPC (=12 digit barcode) is optional */
/* 30 */
{"serviceList", INITHELPER(32,1)},
{"deviceList", INITHELPER(38,1)},
/* 32 */
{"service", INITHELPER(33,5)},
/* 33 */
{"/serviceType",
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"},
/*{"/serviceId", "urn:upnp-org:serviceId:WANCommonInterfaceConfig"}, */
{"/serviceId", "urn:upnp-org:serviceId:WANCommonIFC1"}, /* required */
{"/SCPDURL", WANCFG_PATH},
{"/controlURL", WANCFG_CONTROLURL},
{"/eventSubURL", WANCFG_EVENTURL},
/* 38 */
{"device", INITHELPER(39,12)},
/* 39 */
{"/deviceType", DEVICE_TYPE_WANC},
/* urn:schemas-upnp-org:device:WANConnectionDevice:1 or 2 */
{"/friendlyName", WANCDEV_FRIENDLYNAME},
{"/manufacturer", WANCDEV_MANUFACTURER},
{"/manufacturerURL", WANCDEV_MANUFACTURERURL},
{"/modelDescription", WANCDEV_MODELDESCRIPTION},
{"/modelName", WANCDEV_MODELNAME},
{"/modelNumber", WANCDEV_MODELNUMBER},
{"/modelURL", WANCDEV_MODELURL},
{"/serialNumber", serialnumber},
{"/UDN", uuidvalue_wcd},
{"/UPC", WANCDEV_UPC}, /* UPC (=12 digit Barcode) is optional */
#ifdef ENABLE_6FC_SERVICE
{"serviceList", INITHELPER(51,2)},
#else
{"serviceList", INITHELPER(51,1)},
#endif
/* 51 */
{"service", INITHELPER(53,5)},
{"service", INITHELPER(58,5)},
/* 53 */
{"/serviceType", SERVICE_TYPE_WANIPC},
/* urn:schemas-upnp-org:service:WANIPConnection:2 for v2 */
{"/serviceId", SERVICE_ID_WANIPC},
/* urn:upnp-org:serviceId:WANIPConn1 or 2 */
{"/SCPDURL", WANIPC_PATH},
{"/controlURL", WANIPC_CONTROLURL},
{"/eventSubURL", WANIPC_EVENTURL},
#ifdef ENABLE_6FC_SERVICE
/* 58 */
{"/serviceType", "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1"},
{"/serviceId", "urn:upnp-org:serviceId:WANIPv6Firewall1"},
{"/SCPDURL", WANIP6FC_PATH},
{"/controlURL", WANIP6FC_CONTROLURL},
{"/eventSubURL", WANIP6FC_EVENTURL},
#endif
/* 58 / 63 = SERVICES_OFFSET*/
#if defined(HAS_DUMMY_SERVICE) || defined(ENABLE_L3F_SERVICE) || defined(ENABLE_DP_SERVICE)
{"service", INITHELPER(SERVICES_OFFSET+2,5)},
{"service", INITHELPER(SERVICES_OFFSET+7,5)},
#endif
#ifdef HAS_DUMMY_SERVICE
/* 60 / 65 = SERVICES_OFFSET+2 */
{"/serviceType", "urn:schemas-dummy-com:service:Dummy:1"},
{"/serviceId", "urn:dummy-com:serviceId:dummy1"},
{"/SCPDURL", DUMMY_PATH},
{"/controlURL", "/dummy"},
{"/eventSubURL", "/dummy"},
#endif
#ifdef ENABLE_L3F_SERVICE
/* 60 / 65 = SERVICES_OFFSET+2 */
{"/serviceType", "urn:schemas-upnp-org:service:Layer3Forwarding:1"},
{"/serviceId", "urn:upnp-org:serviceId:L3Forwarding1"},
{"/SCPDURL", L3F_PATH},
{"/controlURL", L3F_CONTROLURL}, /* The Layer3Forwarding service is only */
{"/eventSubURL", L3F_EVENTURL}, /* recommended, not mandatory */
#endif
#ifdef ENABLE_DP_SERVICE
/* InternetGatewayDevice v2 :
* it is RECOMMEDED that DeviceProtection service is implemented and applied.
* If DeviceProtection is not implemented and applied, it is RECOMMENDED
* that control points are able to access only actions and parameters defined
* as Public role. */
/* 65 / 70 = SERVICES_OFFSET+7 */
{"/serviceType", "urn:schemas-upnp-org:service:DeviceProtection:1"},
{"/serviceId", "urn:upnp-org:serviceId:DeviceProtection1"},
{"/SCPDURL", DP_PATH},
{"/controlURL", DP_CONTROLURL},
{"/eventSubURL", DP_EVENTURL},
#endif
{0, 0}
};
/* WANIPCn.xml */
/* see UPnP_IGD_WANIPConnection 1.0.pdf
static struct XMLElt scpdWANIPCn[] =
{
{root_service, {INITHELPER(1,2)}},
{0, {0}}
};
*/
static const struct argument AddPortMappingArgs[] =
{
{1, 11}, /* RemoteHost */
{1, 12}, /* ExternalPort */
{1, 14}, /* PortMappingProtocol */
{1, 13}, /* InternalPort */
{1, 15}, /* InternalClient */
{1, 9}, /* PortMappingEnabled */
{1, 16}, /* PortMappingDescription */
{1, 10}, /* PortMappingLeaseDuration */
{0, 0}
};
#ifdef IGD_V2
static const struct argument AddAnyPortMappingArgs[] =
{
{1, 11}, /* RemoteHost */
{1, 12}, /* ExternalPort */
{1, 14}, /* PortMappingProtocol */
{1, 13}, /* InternalPort */
{1, 15}, /* InternalClient */
{1, 9}, /* PortMappingEnabled */
{1, 16}, /* PortMappingDescription */
{1, 10}, /* PortMappingLeaseDuration */
{2, 12}, /* NewReservedPort / ExternalPort */
{0, 0}
};
static const struct argument DeletePortMappingRangeArgs[] =
{
{1|(1<<2), 12}, /* NewStartPort / ExternalPort */
{1|(2<<2), 12}, /* NewEndPort / ExternalPort */
{1, 14}, /* NewProtocol / PortMappingProtocol */
{1, 18}, /* NewManage / A_ARG_TYPE_Manage */
{0, 0}
};
static const struct argument GetListOfPortMappingsArgs[] =
{
{1|(1<<2), 12}, /* NewStartPort / ExternalPort */
{1|(2<<2), 12}, /* NewEndPort / ExternalPort */
{1, 14}, /* NewProtocol / PortMappingProtocol */
{1, 18}, /* NewManage / A_ARG_TYPE_Manage */
{1, 8}, /* NewNumberOfPorts / PortMappingNumberOfEntries */
{2, 19}, /* NewPortListing / A_ARG_TYPE_PortListing */
{0, 0}
};
#endif
static const struct argument GetExternalIPAddressArgs[] =
{
{2, 7},
{0, 0}
};
static const struct argument DeletePortMappingArgs[] =
{
{1, 11}, /* RemoteHost */
{1, 12}, /* ExternalPort */
{1, 14}, /* PortMappingProtocol */
{0, 0}
};
static const struct argument SetConnectionTypeArgs[] =
{
{1, 0},
{0, 0}
};
static const struct argument GetConnectionTypeInfoArgs[] =
{
{2, 0},
{2, 1},
{0, 0}
};
static const struct argument GetStatusInfoArgs[] =
{
{2, 2},
{2, 4},
{2, 3},
{0, 0}
};
static const struct argument GetNATRSIPStatusArgs[] =
{
{2, 5},
{2, 6},
{0, 0}
};
static const struct argument GetGenericPortMappingEntryArgs[] =
{
{1, 8},
{2, 11},
{2, 12},
{2, 14},
{2, 13},
{2, 15},
{2, 9},
{2, 16},
{2, 10},
{0, 0}
};
static const struct argument GetSpecificPortMappingEntryArgs[] =
{
{1, 11},
{1, 12},
{1, 14},
{2, 13},
{2, 15},
{2, 9},
{2, 16},
{2, 10},
{0, 0}
};
static const struct action WANIPCnActions[] =
{
{"SetConnectionType", SetConnectionTypeArgs}, /* R */
{"GetConnectionTypeInfo", GetConnectionTypeInfoArgs}, /* R */
{"RequestConnection", 0}, /* R */
/*{"RequestTermination", 0},*/ /* O */
{"ForceTermination", 0}, /* R */
/*{"SetAutoDisconnectTime", 0},*/ /* O */
/*{"SetIdleDisconnectTime", 0},*/ /* O */
/*{"SetWarnDisconnectDelay", 0}, */ /* O */
{"GetStatusInfo", GetStatusInfoArgs}, /* R */
/*GetAutoDisconnectTime*/ /* O */
/*GetIdleDisconnectTime*/ /* O */
/*GetWarnDisconnectDelay*/ /* O */
{"GetNATRSIPStatus", GetNATRSIPStatusArgs}, /* R */
{"GetGenericPortMappingEntry", GetGenericPortMappingEntryArgs}, /* R */
{"GetSpecificPortMappingEntry", GetSpecificPortMappingEntryArgs}, /* R */
{"AddPortMapping", AddPortMappingArgs}, /* R */
{"DeletePortMapping", DeletePortMappingArgs}, /* R */
{"GetExternalIPAddress", GetExternalIPAddressArgs}, /* R */
#ifdef IGD_V2
{"DeletePortMappingRange", DeletePortMappingRangeArgs}, /* R, IGD v2 */
{"GetListOfPortMappings", GetListOfPortMappingsArgs}, /* R, IGD v2 */
{"AddAnyPortMapping", AddAnyPortMappingArgs}, /* R, IGD v2 */
#endif
#if 0
{"AddPortMapping", AddPortMappingArgs}, /* R */
{"GetExternalIPAddress", GetExternalIPAddressArgs}, /* R */
{"DeletePortMapping", DeletePortMappingArgs}, /* R */
{"SetConnectionType", SetConnectionTypeArgs}, /* R */
{"GetConnectionTypeInfo", GetConnectionTypeInfoArgs}, /* R */
{"RequestConnection", 0}, /* R */
{"ForceTermination", 0}, /* R */
{"GetStatusInfo", GetStatusInfoArgs}, /* R */
{"GetNATRSIPStatus", GetNATRSIPStatusArgs}, /* R */
{"GetGenericPortMappingEntry", GetGenericPortMappingEntryArgs}, /* R */
{"GetSpecificPortMappingEntry", GetSpecificPortMappingEntryArgs}, /* R */
/* added in v2 UPnP-gw-WANIPConnection-v2-Service.pdf */
#ifdef IGD_V2
{"AddAnyPortMapping", AddAnyPortMappingArgs},
{"DeletePortMappingRange", DeletePortMappingRangeArgs},
{"GetListOfPortMappings", GetListOfPortMappingsArgs},
#endif
#endif
{0, 0}
};
/* R=Required, O=Optional */
/* ignore "warning: missing initializer" */
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
/* struct stateVar :
* {name, itype(&event), idefault, iallowedlist, ieventvalue} */
static const struct stateVar WANIPCnVars[] =
{
/* 0 */
#if 0
{"ConnectionType", 0, 0/*1*/}, /* required */
{"PossibleConnectionTypes", 0|0x80, 0, 14, 15},
#elif 0
{"ConnectionType", 0, 1, 14, 15}, /* required */
{"PossibleConnectionTypes", 0|0x80, 0, 0, 15},
#else
{"ConnectionType", 0, 1, 0, 15}, /* required */
{"PossibleConnectionTypes", 0|0x80, 0, 14, 15},
#endif
/* Required
* Allowed values : Unconfigured / IP_Routed / IP_Bridged */
{"ConnectionStatus", 0|0x80, 3, 18,
CONNECTIONSTATUS_MAGICALVALUE }, /* required */
/* Allowed Values : Unconfigured / Connecting(opt) / Connected
* PendingDisconnect(opt) / Disconnecting (opt)
* Disconnected */
{"Uptime", 3, 0}, /* Required */
{"LastConnectionError", 0, 6, 25}, /* required : */
/* Allowed Values : ERROR_NONE(req) / ERROR_COMMAND_ABORTED(opt)
* ERROR_NOT_ENABLED_FOR_INTERNET(opt)
* ERROR_USER_DISCONNECT(opt)
* ERROR_ISP_DISCONNECT(opt)
* ERROR_IDLE_DISCONNECT(opt)
* ERROR_FORCED_DISCONNECT(opt)
* ERROR_NO_CARRIER(opt)
* ERROR_IP_CONFIGURATION(opt)
* ERROR_UNKNOWN(opt) */
{"RSIPAvailable", 1, 4}, /* required */
{"NATEnabled", 1, 5}, /* required */
{"ExternalIPAddress", 0|0x80, 0, 0,
EXTERNALIPADDRESS_MAGICALVALUE}, /* required. Default : empty string */
{"PortMappingNumberOfEntries", 2|0x80, 0, 0,
PORTMAPPINGNUMBEROFENTRIES_MAGICALVALUE}, /* required >= 0 */
{"PortMappingEnabled", 1, 0}, /* Required */
/* 10 */
{"PortMappingLeaseDuration", 3, 2, 1}, /* required */
{"RemoteHost", 0, 0}, /* required. Default : empty string */
{"ExternalPort", 2, 0}, /* required */
{"InternalPort", 2, 0, 3}, /* required */
{"PortMappingProtocol", 0, 0, 11}, /* required allowedValues: TCP/UDP */
{"InternalClient", 0, 0}, /* required */
{"PortMappingDescription", 0, 0}, /* required default: empty string */
/* added in v2 UPnP-gw-WANIPConnection-v2-Service.pdf */
#ifdef IGD_V2
{"SystemUpdateID", 3|0x80, 0, 0, SYSTEMUPDATEID_MAGICALVALUE},
{"A_ARG_TYPE_Manage", 1, 0},
{"A_ARG_TYPE_PortListing", 0, 0},
#endif
{0, 0}
};
static const struct serviceDesc scpdWANIPCn =
{ WANIPCnActions, WANIPCnVars };
/* WANCfg.xml */
/* See UPnP_IGD_WANCommonInterfaceConfig 1.0.pdf */
static const struct argument GetCommonLinkPropertiesArgs[] =
{
{2, 0},
{2, 1},
{2, 2},
{2, 3},
{0, 0}
};
static const struct argument GetTotalBytesSentArgs[] =
{
{2, 4},
{0, 0}
};
static const struct argument GetTotalBytesReceivedArgs[] =
{
{2, 5},
{0, 0}
};
static const struct argument GetTotalPacketsSentArgs[] =
{
{2, 6},
{0, 0}
};
static const struct argument GetTotalPacketsReceivedArgs[] =
{
{2, 7},
{0, 0}
};
static const struct action WANCfgActions[] =
{
{"GetCommonLinkProperties", GetCommonLinkPropertiesArgs}, /* Required */
{"GetTotalBytesSent", GetTotalBytesSentArgs}, /* optional */
{"GetTotalBytesReceived", GetTotalBytesReceivedArgs}, /* optional */
{"GetTotalPacketsSent", GetTotalPacketsSentArgs}, /* optional */
{"GetTotalPacketsReceived", GetTotalPacketsReceivedArgs}, /* optional */
{0, 0}
};
/* See UPnP_IGD_WANCommonInterfaceConfig 1.0.pdf */
static const struct stateVar WANCfgVars[] =
{
{"WANAccessType", 0, 0, 1},
/* Allowed Values : DSL / POTS / Cable / Ethernet
* Default value : empty string */
{"Layer1UpstreamMaxBitRate", 3, 0},
{"Layer1DownstreamMaxBitRate", 3, 0},
{"PhysicalLinkStatus", 0|0x80, 0, 6, 6},
/* allowed values :
* Up / Down / Initializing (optional) / Unavailable (optionnal)
* no Default value
* Evented */
{"TotalBytesSent", 3, 0}, /* Optional */
{"TotalBytesReceived", 3, 0}, /* Optional */
{"TotalPacketsSent", 3, 0}, /* Optional */
{"TotalPacketsReceived", 3, 0},/* Optional */
/*{"MaximumActiveConnections", 2, 0}, // allowed Range value // OPTIONAL */
/*{"WANAccessProvider", 0, 0},*/ /* Optional */
{0, 0}
};
static const struct serviceDesc scpdWANCfg =
{ WANCfgActions, WANCfgVars };
#ifdef ENABLE_L3F_SERVICE
/* Read UPnP_IGD_Layer3Forwarding_1.0.pdf */
static const struct argument SetDefaultConnectionServiceArgs[] =
{
{1, 0}, /* in */
{0, 0}
};
static const struct argument GetDefaultConnectionServiceArgs[] =
{
{2, 0}, /* out */
{0, 0}
};
static const struct action L3FActions[] =
{
{"SetDefaultConnectionService", SetDefaultConnectionServiceArgs}, /* Req */
{"GetDefaultConnectionService", GetDefaultConnectionServiceArgs}, /* Req */
{0, 0}
};
static const struct stateVar L3FVars[] =
{
{"DefaultConnectionService", 0|0x80, 0, 0,
DEFAULTCONNECTIONSERVICE_MAGICALVALUE}, /* Required */
{0, 0}
};
static const struct serviceDesc scpdL3F =
{ L3FActions, L3FVars };
#endif
#ifdef ENABLE_6FC_SERVICE
/* see UPnP-gw-WANIPv6FirewallControl-v1-Service.pdf */
static const struct argument GetFirewallStatusArgs[] =
{
{2|0x80, 0}, /* OUT : FirewallEnabled */
{2|0x80, 6}, /* OUT : InboundPinholeAllowed */
{0, 0}
};
static const struct argument GetOutboundPinholeTimeoutArgs[] =
{
{1|0x80|(3<<2), 1}, /* RemoteHost IN A_ARG_TYPE_IPv6Address */
{1|0x80|(4<<2), 2}, /* RemotePort IN A_ARG_TYPE_Port */
{1|0x80|(5<<2), 1}, /* InternalClient IN A_ARG_TYPE_IPv6Address */
{1|0x80|(6<<2), 2}, /* InternalPort IN A_ARG_TYPE_Port */
{1|0x80, 3}, /* Protocol IN A_ARG_TYPE_Protocol */
{2|0x80, 7}, /* OutboundPinholeTimeout OUT A_ARG_TYPE_OutboundPinholeTimeout */
{0, 0}
};
static const struct argument AddPinholeArgs[] =
{
{1|0x80|(3<<2), 1}, /* RemoteHost IN A_ARG_TYPE_IPv6Address */
{1|0x80|(4<<2), 2}, /* RemotePort IN A_ARG_TYPE_Port */
{1|0x80|(5<<2), 1}, /* InternalClient IN A_ARG_TYPE_IPv6Address */
{1|0x80|(6<<2), 2}, /* InternalPort IN A_ARG_TYPE_Port */
{1|0x80, 3}, /* Protocol IN A_ARG_TYPE_Protocol */
{1|0x80, 5}, /* LeaseTime IN A_ARG_TYPE_LeaseTime */
{2|0x80, 4}, /* UniqueID OUT A_ARG_TYPE_UniqueID */
{0, 0}
};
static const struct argument UpdatePinholeArgs[] =
{
{1|0x80, 4}, /* UniqueID IN A_ARG_TYPE_UniqueID */
{1, 5}, /* LeaseTime IN A_ARG_TYPE_LeaseTime */
{0, 0}
};
static const struct argument DeletePinholeArgs[] =
{
{1|0x80, 4}, /* UniqueID IN A_ARG_TYPE_UniqueID */
{0, 0}
};
static const struct argument GetPinholePacketsArgs[] =
{
{1|0x80, 4}, /* UniqueID IN A_ARG_TYPE_UniqueID */
{2|0x80, 9}, /* PinholePackets OUT A_ARG_TYPE_PinholePackets */
{0, 0}
};
static const struct argument CheckPinholeWorkingArgs[] =
{
{1|0x80, 4}, /* UniqueID IN A_ARG_TYPE_UniqueID */
{2|0x80|(7<<2), 8}, /* IsWorking OUT A_ARG_TYPE_Boolean */
{0, 0}
};
static const struct action IPv6FCActions[] =
{
{"GetFirewallStatus", GetFirewallStatusArgs}, /* Req */
{"GetOutboundPinholeTimeout", GetOutboundPinholeTimeoutArgs}, /* Opt */
{"AddPinhole", AddPinholeArgs}, /* Req */
{"UpdatePinhole", UpdatePinholeArgs}, /* Req */
{"DeletePinhole", DeletePinholeArgs}, /* Req */
{"GetPinholePackets", GetPinholePacketsArgs}, /* Req */
{"CheckPinholeWorking", CheckPinholeWorkingArgs}, /* Opt */
{0, 0}
};
static const struct stateVar IPv6FCVars[] =
{
{"FirewallEnabled", 1|0x80, 0, 0,
FIREWALLENABLED_MAGICALVALUE}, /* Required */
{"A_ARG_TYPE_IPv6Address", 0, 0, 0, 0}, /* Required */
{"A_ARG_TYPE_Port", 2, 0, 0, 0}, /* Required */
{"A_ARG_TYPE_Protocol", 2, 0, 0, 0}, /* Required */
/* 4 */
{"A_ARG_TYPE_UniqueID", 2, 0, 0, 0}, /* Required */
{"A_ARG_TYPE_LeaseTime", 3, 0, 5, 0}, /* Required */
{"InboundPinholeAllowed", 1|0x80, 0, 0,
INBOUNDPINHOLEALLOWED_MAGICALVALUE}, /* Required */
{"A_ARG_TYPE_OutboundPinholeTimeout", 3, 0, 7, 0}, /* Optional */
/* 8 */
{"A_ARG_TYPE_Boolean", 1, 0, 0, 0}, /* Optional */
{"A_ARG_TYPE_PinholePackets", 3, 0, 0, 0}, /* Required */
{0, 0}
};
static const struct serviceDesc scpd6FC =
{ IPv6FCActions, IPv6FCVars };
#endif
#ifdef ENABLE_DP_SERVICE
/* UPnP-gw-DeviceProtection-v1-Service.pdf */
static const struct argument SendSetupMessageArgs[] =
{
{1|0x80|(8<<2), 6}, /* ProtocolType : in ProtocolType / A_ARG_TYPE_String */
{1|0x80|(9<<2), 5}, /* InMessage : in InMessage / A_ARG_TYPE_Base64 */
{2|0x80|(10<<2), 5}, /* OutMessage : out OutMessage / A_ARG_TYPE_Base64 */
{0, 0}
};
static const struct argument GetSupportedProtocolsArgs[] =
{
{2|0x80|(11<<2), 1}, /* ProtocolList : out ProtocolList / SupportedProtocols */
{0, 0}
};
static const struct argument GetAssignedRolesArgs[] =
{
{2|0x80|(12<<2), 6}, /* RoleList : out RoleList / A_ARG_TYPE_String */
{0, 0}
};
static const struct action DPActions[] =
{
{"SendSetupMessage", SendSetupMessageArgs},
{"GetSupportedProtocols", GetSupportedProtocolsArgs},
{"GetAssignedRoles", GetAssignedRolesArgs},
{0, 0}
};
static const struct stateVar DPVars[] =
{
{"SetupReady", 1|0x80, 0, 0, SETUPREADY_MAGICALVALUE},
{"SupportedProtocols", 0},
{"A_ARG_TYPE_ACL", 0},
{"A_ARG_TYPE_IdentityList", 0},
{"A_ARG_TYPE_Identity", 0},
{"A_ARG_TYPE_Base64", 4},
{"A_ARG_TYPE_String", 0},
{0, 0}
};
static const struct serviceDesc scpdDP =
{ DPActions, DPVars };
#endif
/* strcat_str()
* concatenate the string and use realloc to increase the
* memory buffer if needed. */
static char *
strcat_str(char * str, int * len, int * tmplen, const char * s2)
{
int s2len;
int newlen;
char * p;
s2len = (int)strlen(s2);
if(*tmplen <= (*len + s2len))
{
if(s2len < 256)
newlen = *tmplen + 256;
else
newlen = *tmplen + s2len + 1;
p = (char *)realloc(str, newlen);
if(p == NULL) /* handle a failure of realloc() */
return str;
str = p;
*tmplen = newlen;
}
/*strcpy(str + *len, s2); */
memcpy(str + *len, s2, s2len + 1);
*len += s2len;
return str;
}
/* strcat_char() :
* concatenate a character and use realloc to increase the
* size of the memory buffer if needed */
static char *
strcat_char(char * str, int * len, int * tmplen, char c)
{
char * p;
if(*tmplen <= (*len + 1))
{
*tmplen += 256;
p = (char *)realloc(str, *tmplen);
if(p == NULL) /* handle a failure of realloc() */
{
*tmplen -= 256;
return str;
}
str = p;
}
str[*len] = c;
(*len)++;
return str;
}
/* strcat_int()
* concatenate the string representation of the integer.
* call strcat_char() */
static char *
strcat_int(char * str, int * len, int * tmplen, int i)
{
char buf[16];
int j;
if(i < 0) {
str = strcat_char(str, len, tmplen, '-');
i = -i;
} else if(i == 0) {
/* special case for 0 */
str = strcat_char(str, len, tmplen, '0');
return str;
}
j = 0;
while(i && j < (int)sizeof(buf)) {
buf[j++] = '0' + (i % 10);
i = i / 10;
}
while(j > 0) {
str = strcat_char(str, len, tmplen, buf[--j]);
}
return str;
}
/* iterative subroutine using a small stack
* This way, the progam stack usage is kept low */
static char *
genXML(char * str, int * len, int * tmplen,
const struct XMLElt * p)
{
#define GENXML_STACK_SIZE 16
unsigned short i, j;
unsigned long k;
int top;
const char * eltname, *s;
char c;
struct {
unsigned short i;
unsigned short j;
const char * eltname;
} pile[GENXML_STACK_SIZE]; /* stack */
top = -1;
i = 0; /* current node */
j = 1; /* i + number of nodes*/
for(;;)
{
eltname = p[i].eltname;
if(!eltname)
return str;
if(eltname[0] == '/')
{
/* leaf node */
if(p[i].data && p[i].data[0])
{
/*printf("<%s>%s<%s>\n", eltname+1, p[i].data, eltname); */
str = strcat_char(str, len, tmplen, '<');
str = strcat_str(str, len, tmplen, eltname+1);
str = strcat_char(str, len, tmplen, '>');
#ifdef RANDOMIZE_URLS
if(p[i].data[0] == '/')
{
/* prepend all URL paths with a "random" value */
str = strcat_char(str, len, tmplen, '/');
str = strcat_str(str, len, tmplen, random_url);
}
#endif /* RANDOMIZE_URLS */
str = strcat_str(str, len, tmplen, p[i].data);
#ifdef IGD_V2
/* checking a single 'u' saves us 4 strcmp() calls most of the time */
if (GETFLAG(FORCEIGDDESCV1MASK) && (p[i].data[0] == 'u'))
{
if ((strcmp(p[i].data, DEVICE_TYPE_IGD) == 0) ||
(strcmp(p[i].data, DEVICE_TYPE_WAN) == 0) ||
(strcmp(p[i].data, DEVICE_TYPE_WANC) == 0) ||
(strcmp(p[i].data, SERVICE_TYPE_WANIPC) == 0) )
{
str[*len - 1] = '1'; /* Change the version number to 1 */
}
}
#endif
str = strcat_char(str, len, tmplen, '<');
str = strcat_str(str, len, tmplen, eltname);
str = strcat_char(str, len, tmplen, '>');
}
for(;;)
{
if(top < 0)
return str;
i = ++(pile[top].i);
j = pile[top].j;
/*printf(" pile[%d]\t%d %d\n", top, i, j); */
if(i==j)
{
/*printf("</%s>\n", pile[top].eltname); */
str = strcat_char(str, len, tmplen, '<');
str = strcat_char(str, len, tmplen, '/');
s = pile[top].eltname;
for(c = *s; c > ' '; c = *(++s))
str = strcat_char(str, len, tmplen, c);
str = strcat_char(str, len, tmplen, '>');
top--;
}
else
break;
}
}
else
{
/* node with child(ren) */
/*printf("<%s>\n", eltname); */
str = strcat_char(str, len, tmplen, '<');
str = strcat_str(str, len, tmplen, eltname);
if(memcmp(eltname, "root ", 5) == 0) {
char configid_str[16];
/* add configId attribute, required by UDA 1.1 */
snprintf(configid_str, sizeof(configid_str), "\"%u\"", upnp_configid);
str = strcat_str(str, len, tmplen, " configId=");
str = strcat_str(str, len, tmplen, configid_str);
}
str = strcat_char(str, len, tmplen, '>');
k = (unsigned long)p[i].data;
i = k & 0xffff;
j = i + (k >> 16);
if(top < (GENXML_STACK_SIZE - 1)) {
top++;
/*printf(" +pile[%d]\t%d %d\n", top, i, j); */
pile[top].i = i;
pile[top].j = j;
pile[top].eltname = eltname;
#ifdef DEBUG
} else {
fprintf(stderr, "*** GenXML(): stack OVERFLOW ***\n");
#endif /* DEBUG */
}
}
}
}
/* genRootDesc() :
* - Generate the root description of the UPnP device.
* - the len argument is used to return the length of
* the returned string.
* - tmp_uuid argument is used to build the uuid string */
char *