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/descriptor.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/frame/dissector/dissector.hh>
00038 # include <wipal/wifi/frame/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 void operator () (const pcapxx::frame_descriptor<>& d);
00081
00082 protected:
00084 static const std::string db_null;
00085
00086 enum
00087 {
00089 channels_max = 14
00090 };
00091
00092
00093
00094
00095
00097 struct hooks: public wifi::frame::dissector_default_hooks
00098 {
00099 hooks(wifi::addr_mapping& m);
00100
00101 std::string addrs() const;
00102 std::string beacon_timestamp() const;
00103 std::string fragnum() const;
00104 std::string seqnum() const;
00105 std::string error() const;
00106
00107 protected:
00108
00109 void invalid_type_or_subtype_hook(const void*, size_t, status);
00110 void truncated_frame_hook(const void*, size_t, status);
00111 void addr_hook(const void*, size_t, unsigned, const wifi::addr&);
00112 void seq_ctl_hook(const void*, size_t, unsigned, unsigned);
00113 void beacon_hook(const wifi::frame::mgt::header*, size_t);
00114 void end_of_frame_hook(const void*, size_t, status);
00115
00116 private:
00117
00118 wifi::addr_mapping& mapping_;
00119 std::string addrs_;
00120 std::string beacon_timestamp_;
00121 std::string fragnum_;
00122 std::string seqnum_;
00123 std::string error_;
00124 };
00125
00126
00128 static std::string frames_data_filename(const std::string&, unsigned);
00129
00131 static std::string mapping_filename(const std::string&, unsigned);
00132
00137 std::string handle_time_data(const pcapxx::pkthdr*);
00138
00140 void handle_malformed_prism();
00141
00150 const prism::header*
00151 handle_prism_header(const std::string& time_string,
00152 const void*,
00153 size_t caplen);
00154
00156 unsigned last_channel_;
00157
00159 boost::posix_time::ptime last_frame_;
00160
00162 unsigned last_id_[channels_max];
00163
00165 std::vector<tool::datafile> frames_data_;
00166
00168 std::vector<wifi::addr_mapping> mappings_;
00169 };
00170
00171 }
00172
00173 # include "wit_importer.hxx"
00174
00175 #endif // ! WIT_IMPORTER_HH_