128cac0ea5f3c26b9945eb2dac708d95e2fe346c
[senf.git] / 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_DTCPPacket_
27 #define HH_DTCPPacket_ 1
28
29 // Custom includes
30 #include "../../Packets/Packets.hh"
31 #include "../../Packets/DefaultBundle/IPv4Packet.hh"
32 #include "../../Packets/DefaultBundle/IPv6Packet.hh"
33
34 //#include "DTCPPacket.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
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 );
48         SENF_PARSER_PRIVATE_FIELD( reserved_, UInt8Parser );
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 );
64         SENF_PARSER_PRIVATE_FIELD( reserved_, UInt8Parser );
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 DTCPPacketType
80      */
81     struct DTCPHelloPacketParser : public PacketParserBase
82     {
83 #       include SENF_PARSER()
84
85         SENF_PARSER_BITFIELD         ( versionNumber,        4, unsigned );  // must be 1
86         SENF_PARSER_BITFIELD         ( command,              4, unsigned );
87
88         enum Command { JOIN=1, LEAVE=2 };
89
90         SENF_PARSER_FIELD            ( interval,             UInt8Parser );  // should be 5
91         SENF_PARSER_FIELD            ( sequenceNumber,       UInt16Parser );
92
93         SENF_PARSER_PRIVATE_BITFIELD ( reserved0_,           3, unsigned );
94         SENF_PARSER_BITFIELD         ( receiveCapableFeed,   1, bool );
95         SENF_PARSER_BITFIELD_RO      ( ipVersion,            4, unsigned );  // 4=IPv4, 6=IPv6
96
97         SENF_PARSER_FIELD            ( tunnelProtocol,       UInt8Parser ); 
98         SENF_PARSER_FIELD_RO         ( fbipCount,            UInt8Parser );
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         \ingroup protocolbundle_mpegdvb
131      */
132     struct DTCPHelloPacketType
133         : public PacketTypeBase,
134           public PacketTypeMixin<DTCPHelloPacketType>
135     {
136         typedef PacketTypeMixin<DTCPHelloPacketType> mixin;
137         typedef ConcretePacket<DTCPHelloPacketType> packet;
138         typedef DTCPHelloPacketParser parser;
139     
140         using mixin::nextPacketRange;
141         using mixin::init;
142         using mixin::initSize;
143         
144         static void dump(packet p, std::ostream & os);
145     };
146     
147     /** \brief DTCP packet typedef */
148     typedef DTCPHelloPacketType::packet DTCPHelloPacket;
149 }
150
151 ///////////////////////////////hh.e////////////////////////////////////////
152 //#include "DTCPPacket.cci"
153 //#include "DTCPPacket.ct"
154 //#include "DTCPPacket.cti"
155 #endif
156
157 \f
158 // Local Variables:
159 // mode: c++
160 // fill-column: 100
161 // comment-column: 40
162 // c-file-style: "senf"
163 // indent-tabs-mode: nil
164 // ispell-local-dictionary: "american"
165 // compile-command: "scons -u test"
166 // End: