ff4f2710bd8495d8a9a07feed4333ca15172d068
[senf.git] / Packets / 80211Bundle / WLANPacket.cc
1 // $Id: $
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Christian Niephaus <christian.niephaus@fokus.fraunhofer.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 // Definition of non-inline non-template functions
24
25 // Custom includes
26 #include "WLANPacket.hh"
27 #include "../../Packets/Packets.hh"
28 #include "../DefaultBundle/LlcSnapPacket.hh"
29 #include <boost/io/ios_state.hpp>
30
31 #define prefix_
32
33 namespace
34 {
35
36 }
37
38 prefix_ senf::MACAddressParser senf::WLANPacketParser_DataFrameParser::da()
39     const
40 {
41     switch (dsBits())
42     {
43     case 0 :
44     case 2 :
45         return addr1();
46         break;
47     case 1 :
48     case 3 :
49         return addr3();
50         break;
51     }
52 }
53
54 prefix_ senf::MACAddressParser senf::WLANPacketParser_DataFrameParser::sa()
55     const
56 {
57     switch (dsBits())
58     {
59     case 0 :
60     case 1 :
61         return addr2();
62         break;
63     case 2 :
64         return addr3();
65         break;
66 //TODO wds frames
67 //    case 3:
68 //        return addr4();
69     }
70 }
71
72 prefix_ senf::MACAddressParser senf::WLANPacketParser_DataFrameParser::bssid()
73     const
74 {
75     switch (dsBits())
76     {
77     case 0 :
78         return addr3();
79         break;
80     case 1 :
81         return addr1();
82         break;
83     case 2:
84         return addr2();
85     }
86 }
87
88 //shift some bits to read the 12bit sequence number bit field in LSB byte order
89 prefix_ boost::uint16_t senf::WLANPacketParser_MgtFrameParser::sequenceNumber()
90     const
91 {
92     boost::uint16_t seqN = 0;
93     seqN |= seqNumber_2();
94     seqN <<= 4;
95     seqN |= seqNumber_1();
96     return seqN;
97 }
98
99 //shift some bits to read the 12bit sequence number bit field in LSB byte order
100 prefix_ boost::uint16_t senf::WLANPacketParser_DataFrameParser::sequenceNumber()
101     const
102 {
103     boost::uint16_t seqN = 0;
104     seqN |= seqNumber_2();
105     seqN <<= 4;
106     seqN |= seqNumber_1();
107     return seqN;
108 }
109
110 prefix_ void senf::WLANPacketType::dump(packet p, std::ostream &os)
111 {
112     boost::io::ios_all_saver ias(os);
113     os  << "802.11 MAC Frame:\n"
114         << "  Type              : " << unsigned (p->type()) << "\n"
115         << "  Subtype           : " << unsigned (p->subtype()) << "\n"
116         << "  Retransmission    : " << unsigned (p->retry()) << "\n"
117         << "  Duration          : " << unsigned (p->duration()) << "\n";
118
119     if (p->has_mgtFrame())
120     {
121         os << "  BSSID              : " << p->mgtFrame().bssid() << "\n";
122         os << "  Destination Addr.  : " << p->mgtFrame().da() << "\n";
123         os << "  Source Addr.  : " << p->mgtFrame().sa() << "\n";
124     }
125
126 };
127
128
129
130
131 #undef prefix_