00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIT_IMPORTER_HH_
00023 # define WIT_IMPORTER_HH_
00024
00025 # include <string>
00026 # include <map>
00027 # include <vector>
00028
00029 # include <boost/date_time/posix_time/posix_time.hpp>
00030 # include <boost/shared_ptr.hpp>
00031
00032 # include <wipal/tool/datafile.hh>
00033 # include <wipal/pcap/stream.hh>
00034 # include <wipal/wifi/addr.hh>
00035 # include <wipal/wifi/addr_mapping.hh>
00036 # include <wipal/phy/prism_header.hh>
00037 # include <wipal/wifi/dissector/dissector.hh>
00038 # include <wipal/wifi/dissector/default_hooks.hh>
00039
00040 namespace wit
00041 {
00042
00049 struct importer
00050 {
00052 enum error
00053 {
00054 success = 0,
00055 malformed_frame = 1,
00056 malformed_prism = 2,
00057 malformed_802 = 3,
00058 malformed_other = 4,
00059 driver_reported = 5,
00060 unexpected_section = 6,
00061 bad_length = 7,
00062 bad_type_subtype = 8
00063 };
00064
00072 importer(const std::string& prefix);
00073
00080 template <class T>
00081 void operator () (const wpl::pkt::packet<T>& d);
00082
00083 protected:
00085 static const std::string db_null;
00086
00087 enum
00088 {
00090 channels_max = 14
00091 };
00092
00093
00094
00095
00096
00098 struct hooks: public wpl::wifi::dissector_default_hooks
00099 {
00100 hooks(wpl::wifi::addr_mapping& m);
00101
00102 std::string addrs() const;
00103 std::string beacon_timestamp() const;
00104 std::string fragnum() const;
00105 std::string seqnum() const;
00106 std::string error() const;
00107
00108 protected:
00109
00110 void invalid_type_or_subtype_hook(const void*, size_t, status);
00111 void truncated_frame_hook(const void*, size_t, status);
00112 void addr_hook(const void*, size_t,
00113 unsigned, const wpl::wifi::addr&);
00114 void seq_ctl_hook(const void*, size_t, unsigned, unsigned);
00115 void beacon_hook(const wpl::wifi::mgt::header*, size_t);
00116 void end_of_frame_hook(const void*, size_t, status);
00117
00118 private:
00119
00120 wpl::wifi::addr_mapping& mapping_;
00121 std::string addrs_;
00122 std::string beacon_timestamp_;
00123 std::string fragnum_;
00124 std::string seqnum_;
00125 std::string error_;
00126 };
00127
00128
00130 static std::string frames_data_filename(const std::string&, unsigned);
00131
00133 static std::string mapping_filename(const std::string&, unsigned);
00134
00139 std::string handle_time_data(const wpl::pkt::metadata&);
00140
00142 void handle_malformed_prism();
00143
00152 const wpl::prism::header*
00153 handle_prism_header(const std::string& time_string,
00154 const void*,
00155 size_t caplen);
00156
00158 unsigned last_channel_;
00159
00161 boost::posix_time::ptime last_frame_;
00162
00164 unsigned last_id_[channels_max];
00165
00167 std::vector<wpl::tool::datafile> frames_data_;
00168
00170 std::vector<wpl::wifi::addr_mapping> mappings_;
00171 };
00172
00173 }
00174
00175 # include "wit_importer.hxx"
00176
00177 #endif // ! WIT_IMPORTER_HH_