switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / MPEGDVBBundle / DTCPPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   David Wagner <dw6@berlios.de>
27 /** \file
28     \brief DTCPPacket public header */
29
30 #ifndef HH_SENF_Packets_MPEGDVBBundle_DTCPPacket_
31 #define HH_SENF_Packets_MPEGDVBBundle_DTCPPacket_ 1
32
33 // Custom includes
34 #include <senf/Packets/DefaultBundle/IPv6Packet.hh>
35
36 //#include "DTCPPacket.mpp"
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38
39 namespace senf {
40
41 #   define DTCP_V4_MCADDRESS "224.0.0.36"
42 #   define DTCP_V6_MCADDRESS "FF02:0:0:0:0:0:1:4"
43 #   define DTCP_UDP_PORT 652
44
45     struct DTCPIPv4AddressListParser : public PacketParserBase
46     {
47 #       include SENF_PARSER()
48
49         SENF_PARSER_PRIVATE_FIELD( fbipCount_, UInt8Parser ); //<pkgdraw: hide
50         SENF_PARSER_PRIVATE_FIELD( reserved_, UInt8Parser ); //<pkgdraw: hide
51
52         SENF_PARSER_VECTOR( fbips, fbipCount_, INet4AddressParser );
53
54         // Needed since we do NOT want to init fbipCount_ or reseverd_. And since
55         // INet4AddressParser::init() is a no-op, we can just as well disable init completely
56         SENF_PARSER_INIT() {}
57
58         SENF_PARSER_FINALIZE(DTCPIPv4AddressListParser);
59     };
60
61     struct DTCPIPv6AddressListParser : public PacketParserBase
62     {
63 #       include SENF_PARSER()
64
65         SENF_PARSER_PRIVATE_FIELD( fbipCount_, UInt8Parser ); //<pkgdraw: hide
66         SENF_PARSER_PRIVATE_FIELD( reserved_, UInt8Parser ); //<pkgdraw: hide
67
68         SENF_PARSER_VECTOR( fbips, fbipCount_, INet6AddressParser );
69
70         // Needed since we do NOT want to init fbipCount_ or reseverd_. And since
71         // INet4AddressParser::init() is a no-op, we can just as well disable init completely
72         SENF_PARSER_INIT() {}
73
74         SENF_PARSER_FINALIZE(DTCPIPv6AddressListParser);
75     };
76
77     /** \brief Parse a DTCP HELLO packet
78
79         Parser implementing the DTCP packet according to RFC 3077
80
81         \see DTCPHelloPacketType
82      */
83     struct DTCPHelloPacketParser : public PacketParserBase
84     {
85 #       include SENF_PARSER()
86
87         //>pkgdraw: name=vers
88         SENF_PARSER_BITFIELD         ( versionNumber,        4, unsigned );  // must be 1
89         SENF_PARSER_BITFIELD         ( command,              4, unsigned );  //<pkgdraw: name=cmd
90
91         enum Command { JOIN=1, LEAVE=2 };
92
93         SENF_PARSER_FIELD            ( interval,             UInt8Parser );  // should be 5
94         SENF_PARSER_FIELD            ( sequenceNumber,       UInt16Parser );
95
96         SENF_PARSER_PRIVATE_BITFIELD ( reserved0_,           3, unsigned );  //<pkgdraw: name=
97         SENF_PARSER_BITFIELD         ( receiveCapableFeed,   1, bool );
98         SENF_PARSER_BITFIELD_RO      ( ipVersion,            4, unsigned );  // 4=IPv4, 6=IPv6
99
100         SENF_PARSER_FIELD            ( tunnelProtocol,       UInt8Parser );
101         SENF_PARSER_FIELD_RO         ( fbipCount,            UInt8Parser );
102         //>pkgdraw: name=
103         SENF_PARSER_PRIVATE_FIELD    ( reserved1_,           UInt8Parser );  // must be zero
104
105         // Go back to fbipCount so the variant has access to that field
106         SENF_PARSER_GOTO( fbipCount );
107
108         SENF_PARSER_VARIANT          ( fbipList_,            ipVersion,
109                            ( ids(na, has_v4fbipList, init_v4fbipList,
110                                  key(4, DTCPIPv4AddressListParser)) )
111                            ( ids(na, has_v6fbipList, init_v6fbipList,
112                                  key(6, DTCPIPv6AddressListParser)) ) );
113
114         // We define the two variant accessors ourselves so we can directly return the vector and
115         // not the collection parser which contains the vector ...
116
117         typedef DTCPIPv4AddressListParser::fbips_t v4fbipList_t;
118         v4fbipList_t v4fbipList() { return fbipList_().get<0>().fbips(); }
119
120         typedef DTCPIPv6AddressListParser::fbips_t v6fbipList_t;
121         v6fbipList_t v6fbipList() { return fbipList_().get<1>().fbips(); }
122
123         SENF_PARSER_FINALIZE(DTCPHelloPacketParser);
124     };
125
126     /** \brief DTCP HELLO packet
127
128         \par Packet type (typedef):
129             \ref DTCPHelloPacket
130
131         \par Fields:
132             \ref DTCPHelloPacketParser
133
134         \image html DTCPPacket.png
135
136         \ingroup protocolbundle_mpegdvb
137      */
138     struct DTCPHelloPacketType
139         : public PacketTypeBase,
140           public PacketTypeMixin<DTCPHelloPacketType>
141     {
142         typedef PacketTypeMixin<DTCPHelloPacketType> mixin;
143         typedef ConcretePacket<DTCPHelloPacketType> packet;
144         typedef DTCPHelloPacketParser parser;
145
146         using mixin::nextPacketRange;
147         using mixin::init;
148         using mixin::initSize;
149
150         static void dump(packet p, std::ostream & os);
151     };
152
153     /** \brief DTCP packet typedef */
154     typedef DTCPHelloPacketType::packet DTCPHelloPacket;
155 }
156
157 //-/////////////////////////////////////////////////////////////////////////////////////////////////
158 //#include "DTCPPacket.cci"
159 //#include "DTCPPacket.ct"
160 //#include "DTCPPacket.cti"
161 #endif
162
163 \f
164 // Local Variables:
165 // mode: c++
166 // fill-column: 100
167 // comment-column: 40
168 // c-file-style: "senf"
169 // indent-tabs-mode: nil
170 // ispell-local-dictionary: "american"
171 // compile-command: "scons -u test"
172 // End: