2f1c1481d9153e09511807b8cec115f490b7d273
[senf.git] / Packets / 80211Bundle / WLANPacket.cc
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Christian Niephaus <cni@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 // 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 prefix_ senf::MACAddressParser senf::WLANPacket_DataFrameParser::destinationAddress()
34     const
35 {
36     switch (dsBits()) {
37     case 0 :
38     case 2 :
39         return addr1();
40     }
41     return addr3();
42 }
43
44 prefix_ senf::MACAddressParser senf::WLANPacket_DataFrameParser::sourceAddress()
45     const
46 {
47     switch (dsBits())
48     {
49     case 0 :
50     case 1 :
51         return addr2();
52         break;
53     case 2 :
54         return addr3();
55         break;
56 //TODO wds frames
57 //    case 3:
58 //        return addr4();
59     }
60     //just to avoid compiler warning
61     //TODO
62     return addr1();
63 }
64
65 prefix_ senf::MACAddressParser senf::WLANPacket_DataFrameParser::bssid()
66     const
67 {
68     switch (dsBits())
69     {
70     case 0 :
71         return addr3();
72         break;
73     case 1 :
74         return addr1();
75         break;
76     case 2:
77         return addr2();
78     }
79     //just to avoid compiler warning
80     //TODO
81     return addr1();
82 }
83
84
85 prefix_ void senf::WLANPacketType::dump(packet p, std::ostream &os)
86 {
87     boost::io::ios_all_saver ias(os);
88     os << "802.11 MAC Frame:\n"
89        << "  Type           : " << unsigned( p->type()) << "\n"
90        << "  Subtype        : " << unsigned( p->subtype()) << "\n"
91        << "  Retransmission : " << unsigned( p->retry()) << "\n"
92        << "  Duration       : " << unsigned( p->duration()) << "\n";
93     if (p->is_mgtFrame()) {
94         os << "  Management-Frame:\n" 
95            << "    BSSID               : " << p->mgtFrame().bssid() << "\n"
96            << "    Destination Address : " << p->mgtFrame().destinationAddress() << "\n"
97            << "    Source Address      : " << p->mgtFrame().sourceAddress() << "\n"
98            << "    Sequence Number     : " << unsigned( p->mgtFrame().sequenceNumber()) << "\n"
99            << "    Fragment Number     : " << unsigned( p->mgtFrame().fragmentNumber()) << "\n";
100     }
101     if (p->is_ctrlFrame()) {
102         os << "  Control-Frame ";
103         if (p->ctrlFrame().is_cts()) os << "(CTS):\n";
104         if (p->ctrlFrame().is_ack()) os << "(ACK):\n";
105         if (p->ctrlFrame().is_rts()) os << "(RTS):\n";
106         os << "    Receiver Address : " << p->ctrlFrame().receiverAddress() << "\n";
107         if (p->ctrlFrame().is_rts())
108             os << "    Source Address : " << p->ctrlFrame().sourceAddress() << "\n";
109     }
110     if (p->is_dataFrame()) {
111         os << "  Data-Frame:\n"
112            << "    Sequence Number     : " << unsigned( p->mgtFrame().sequenceNumber()) << "\n"
113            << "    Fragment Number     : " << unsigned( p->mgtFrame().fragmentNumber()) << "\n";
114     }
115 };
116
117
118
119
120 #undef prefix_