4b9e675cad1a2abad6a0769ea843bc04361a9d54
[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/Packets.hh>
31 #include <senf/Packets/DefaultBundle/IPv4Packet.hh>
32 #include <senf/Packets/DefaultBundle/IPv6Packet.hh>
33
34 //#include "DTCPPacket.mpp"
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36
37 namespace senf {
38
39 #   define DTCP_V4_MCADDRESS "224.0.0.36"
40 #   define DTCP_V6_MCADDRESS "FF02:0:0:0:0:0:1:4"
41 #   define DTCP_UDP_PORT 652
42
43     struct DTCPIPv4AddressListParser : public PacketParserBase
44     {
45 #       include SENF_PARSER()
46
47         SENF_PARSER_PRIVATE_FIELD( fbipCount_, UInt8Parser ); //<pkgdraw: hide
48         SENF_PARSER_PRIVATE_FIELD( reserved_, UInt8Parser ); //<pkgdraw: hide
49
50         SENF_PARSER_VECTOR( fbips, fbipCount_, INet4AddressParser );
51
52         // Needed since we do NOT want to init fbipCount_ or reseverd_. And since
53         // INet4AddressParser::init() is a no-op, we can just as well disable init completely
54         SENF_PARSER_INIT() {}
55
56         SENF_PARSER_FINALIZE(DTCPIPv4AddressListParser);
57     };
58
59     struct DTCPIPv6AddressListParser : public PacketParserBase
60     {
61 #       include SENF_PARSER()
62
63         SENF_PARSER_PRIVATE_FIELD( fbipCount_, UInt8Parser ); //<pkgdraw: hide
64         SENF_PARSER_PRIVATE_FIELD( reserved_, UInt8Parser ); //<pkgdraw: hide
65
66         SENF_PARSER_VECTOR( fbips, fbipCount_, INet6AddressParser );
67
68         // Needed since we do NOT want to init fbipCount_ or reseverd_. And since
69         // INet4AddressParser::init() is a no-op, we can just as well disable init completely
70         SENF_PARSER_INIT() {}
71
72         SENF_PARSER_FINALIZE(DTCPIPv6AddressListParser);
73     };
74
75     /** \brief Parse a DTCP HELLO packet
76
77         Parser implementing the DTCP packet according to RFC 3077
78
79         \see DTCPHelloPacketType
80      */
81     struct DTCPHelloPacketParser : public PacketParserBase
82     {
83 #       include SENF_PARSER()
84
85         //>pkgdraw: name=vers
86         SENF_PARSER_BITFIELD         ( versionNumber,        4, unsigned );  // must be 1
87         SENF_PARSER_BITFIELD         ( command,              4, unsigned );  //<pkgdraw: name=cmd
88
89         enum Command { JOIN=1, LEAVE=2 };
90
91         SENF_PARSER_FIELD            ( interval,             UInt8Parser );  // should be 5
92         SENF_PARSER_FIELD            ( sequenceNumber,       UInt16Parser );
93
94         SENF_PARSER_PRIVATE_BITFIELD ( reserved0_,           3, unsigned );  //<pkgdraw: name=
95         SENF_PARSER_BITFIELD         ( receiveCapableFeed,   1, bool );
96         SENF_PARSER_BITFIELD_RO      ( ipVersion,            4, unsigned );  // 4=IPv4, 6=IPv6
97
98         SENF_PARSER_FIELD            ( tunnelProtocol,       UInt8Parser );
99         SENF_PARSER_FIELD_RO         ( fbipCount,            UInt8Parser );
100         //>pkgdraw: name=
101         SENF_PARSER_PRIVATE_FIELD    ( reserved1_,           UInt8Parser );  // must be zero
102
103         // Go back to fbipCount so the variant has access to that field
104         SENF_PARSER_GOTO( fbipCount );
105
106         SENF_PARSER_VARIANT          ( fbipList_,            ipVersion,
107                            ( ids(na, has_v4fbipList, init_v4fbipList,
108                                  key(4, DTCPIPv4AddressListParser)) )
109                            ( ids(na, has_v6fbipList, init_v6fbipList,
110                                  key(6, DTCPIPv6AddressListParser)) ) );
111
112         // We define the two variant accessors ourselves so we can directly return the vector and
113         // not the collection parser which contains the vector ...
114
115         typedef DTCPIPv4AddressListParser::fbips_t v4fbipList_t;
116         v4fbipList_t v4fbipList() { return fbipList_().get<0>().fbips(); }
117
118         typedef DTCPIPv6AddressListParser::fbips_t v6fbipList_t;
119         v6fbipList_t v6fbipList() { return fbipList_().get<1>().fbips(); }
120
121         SENF_PARSER_FINALIZE(DTCPHelloPacketParser);
122     };
123
124     /** \brief DTCP HELLO packet
125
126         \par Packet type (typedef):
127             \ref DTCPHelloPacket
128
129         \par Fields:
130             \ref DTCPHelloPacketParser
131
132         \image html DTCPPacket.png
133
134         \ingroup protocolbundle_mpegdvb
135      */
136     struct DTCPHelloPacketType
137         : public PacketTypeBase,
138           public PacketTypeMixin<DTCPHelloPacketType>
139     {
140         typedef PacketTypeMixin<DTCPHelloPacketType> mixin;
141         typedef ConcretePacket<DTCPHelloPacketType> packet;
142         typedef DTCPHelloPacketParser parser;
143
144         using mixin::nextPacketRange;
145         using mixin::init;
146         using mixin::initSize;
147
148         static void dump(packet p, std::ostream & os);
149     };
150
151     /** \brief DTCP packet typedef */
152     typedef DTCPHelloPacketType::packet DTCPHelloPacket;
153 }
154
155 //-/////////////////////////////////////////////////////////////////////////////////////////////////
156 //#include "DTCPPacket.cci"
157 //#include "DTCPPacket.ct"
158 //#include "DTCPPacket.cti"
159 #endif
160
161 \f
162 // Local Variables:
163 // mode: c++
164 // fill-column: 100
165 // comment-column: 40
166 // c-file-style: "senf"
167 // indent-tabs-mode: nil
168 // ispell-local-dictionary: "american"
169 // compile-command: "scons -u test"
170 // End: