9a5fac6945dbe67cb48674da3adc423c86940a00
[senf.git] / senf / Packets / MPEGDVBBundle / DTCPPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     David Wagner <dw6@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief DTCPPacket public header */
25
26 #ifndef HH_SENF_Packets_MPEGDVBBundle_DTCPPacket_
27 #define HH_SENF_Packets_MPEGDVBBundle_DTCPPacket_ 1
28
29 // Custom includes
30 #include <senf/Packets/DefaultBundle/IPv6Packet.hh>
31
32 //#include "DTCPPacket.mpp"
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34
35 namespace senf {
36
37 #   define DTCP_V4_MCADDRESS "224.0.0.36"
38 #   define DTCP_V6_MCADDRESS "FF02:0:0:0:0:0:1:4"
39 #   define DTCP_UDP_PORT 652
40
41     struct DTCPIPv4AddressListParser : public PacketParserBase
42     {
43 #       include SENF_PARSER()
44
45         SENF_PARSER_PRIVATE_FIELD( fbipCount_, UInt8Parser ); //<pkgdraw: hide
46         SENF_PARSER_PRIVATE_FIELD( reserved_, UInt8Parser ); //<pkgdraw: hide
47
48         SENF_PARSER_VECTOR( fbips, fbipCount_, INet4AddressParser );
49
50         // Needed since we do NOT want to init fbipCount_ or reseverd_. And since
51         // INet4AddressParser::init() is a no-op, we can just as well disable init completely
52         SENF_PARSER_INIT() {}
53
54         SENF_PARSER_FINALIZE(DTCPIPv4AddressListParser);
55     };
56
57     struct DTCPIPv6AddressListParser : public PacketParserBase
58     {
59 #       include SENF_PARSER()
60
61         SENF_PARSER_PRIVATE_FIELD( fbipCount_, UInt8Parser ); //<pkgdraw: hide
62         SENF_PARSER_PRIVATE_FIELD( reserved_, UInt8Parser ); //<pkgdraw: hide
63
64         SENF_PARSER_VECTOR( fbips, fbipCount_, INet6AddressParser );
65
66         // Needed since we do NOT want to init fbipCount_ or reseverd_. And since
67         // INet4AddressParser::init() is a no-op, we can just as well disable init completely
68         SENF_PARSER_INIT() {}
69
70         SENF_PARSER_FINALIZE(DTCPIPv6AddressListParser);
71     };
72
73     /** \brief Parse a DTCP HELLO packet
74
75         Parser implementing the DTCP packet according to RFC 3077
76
77         \see DTCPHelloPacketType
78      */
79     struct DTCPHelloPacketParser : public PacketParserBase
80     {
81 #       include SENF_PARSER()
82
83         //>pkgdraw: name=vers
84         SENF_PARSER_BITFIELD         ( versionNumber,        4, unsigned );  // must be 1
85         SENF_PARSER_BITFIELD         ( command,              4, unsigned );  //<pkgdraw: name=cmd
86
87         enum Command { JOIN=1, LEAVE=2 };
88
89         SENF_PARSER_FIELD            ( interval,             UInt8Parser );  // should be 5
90         SENF_PARSER_FIELD            ( sequenceNumber,       UInt16Parser );
91
92         SENF_PARSER_PRIVATE_BITFIELD ( reserved0_,           3, unsigned );  //<pkgdraw: name=
93         SENF_PARSER_BITFIELD         ( receiveCapableFeed,   1, bool );
94         SENF_PARSER_BITFIELD_RO      ( ipVersion,            4, unsigned );  // 4=IPv4, 6=IPv6
95
96         SENF_PARSER_FIELD            ( tunnelProtocol,       UInt8Parser );
97         SENF_PARSER_FIELD_RO         ( fbipCount,            UInt8Parser );
98         //>pkgdraw: name=
99         SENF_PARSER_PRIVATE_FIELD    ( reserved1_,           UInt8Parser );  // must be zero
100
101         // Go back to fbipCount so the variant has access to that field
102         SENF_PARSER_GOTO( fbipCount );
103
104         SENF_PARSER_VARIANT          ( fbipList_,            ipVersion,
105                            ( ids(na, has_v4fbipList, init_v4fbipList,
106                                  key(4, DTCPIPv4AddressListParser)) )
107                            ( ids(na, has_v6fbipList, init_v6fbipList,
108                                  key(6, DTCPIPv6AddressListParser)) ) );
109
110         // We define the two variant accessors ourselves so we can directly return the vector and
111         // not the collection parser which contains the vector ...
112
113         typedef DTCPIPv4AddressListParser::fbips_t v4fbipList_t;
114         v4fbipList_t v4fbipList() { return fbipList_().get<0>().fbips(); }
115
116         typedef DTCPIPv6AddressListParser::fbips_t v6fbipList_t;
117         v6fbipList_t v6fbipList() { return fbipList_().get<1>().fbips(); }
118
119         SENF_PARSER_FINALIZE(DTCPHelloPacketParser);
120     };
121
122     /** \brief DTCP HELLO packet
123
124         \par Packet type (typedef):
125             \ref DTCPHelloPacket
126
127         \par Fields:
128             \ref DTCPHelloPacketParser
129
130         \image html DTCPPacket.png
131
132         \ingroup protocolbundle_mpegdvb
133      */
134     struct DTCPHelloPacketType
135         : public PacketTypeBase,
136           public PacketTypeMixin<DTCPHelloPacketType>
137     {
138         typedef PacketTypeMixin<DTCPHelloPacketType> mixin;
139         typedef ConcretePacket<DTCPHelloPacketType> packet;
140         typedef DTCPHelloPacketParser parser;
141
142         using mixin::nextPacketRange;
143         using mixin::init;
144         using mixin::initSize;
145
146         static void dump(packet p, std::ostream & os);
147     };
148
149     /** \brief DTCP packet typedef */
150     typedef DTCPHelloPacketType::packet DTCPHelloPacket;
151 }
152
153 //-/////////////////////////////////////////////////////////////////////////////////////////////////
154 //#include "DTCPPacket.cci"
155 //#include "DTCPPacket.ct"
156 //#include "DTCPPacket.cti"
157 #endif
158
159 \f
160 // Local Variables:
161 // mode: c++
162 // fill-column: 100
163 // comment-column: 40
164 // c-file-style: "senf"
165 // indent-tabs-mode: nil
166 // ispell-local-dictionary: "american"
167 // compile-command: "scons -u test"
168 // End: