00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef WIFI_FRAME_FILTER_UNIQUELY_IDENTIFIABLE_HXX_
00023 # define WIFI_FRAME_FILTER_UNIQUELY_IDENTIFIABLE_HXX_
00024
00025 # include <wipal/wifi/frame/dissector/dissector.hh>
00026 # include <wipal/wifi/frame/unique_id/unique_id.hh>
00027 # include <wipal/wifi/frame/filter/non_noisy_prism.hh>
00028
00029 namespace wifi
00030 {
00031 namespace frame
00032 {
00033 namespace filter
00034 {
00035
00036 namespace internals
00037 {
00038
00039 template <class U, class I, class H, class B1, class B2>
00040 uniquely_identifiable_iterator<U, I, H, B1, B2>::
00041 uniquely_identifiable_iterator(const iterable_type& uif,
00042 bool end):
00043 super_type (),
00044 iterable_ (&uif),
00045 next_ (end ? uif.end_ : uif.begin_),
00046 frame_count_ (0),
00047 uframe_count_ (0)
00048 {
00049 if (not end)
00050 increment();
00051 }
00052
00053 template <class U, class I, class H, class B1, class B2>
00054 bool
00055 uniquely_identifiable_iterator<U, I, H, B1, B2>::
00056 equal(const uniquely_identifiable_iterator& rhs) const
00057 {
00058 if (not rhs.value())
00059 return not this->value();
00060 return next_ == rhs.next_;
00061 }
00062
00063 template <class U, class I, class H, class B1, class B2>
00064 void
00065 uniquely_identifiable_iterator<U, I, H, B1, B2>::increment()
00066 {
00067 unique_id_factory<U> factory;
00068 boost::optional<U> id;
00069
00070 while (next_ != iterable_->end_ and not id)
00071 {
00072 mactime_.tick<H>(*next_, iterable_->phy_end_);
00073 id = factory.template build<H>(*next_, *iterable_->mapping_);
00074 ++next_;
00075 ++frame_count_;
00076 }
00077 if (id)
00078 {
00079 this->value() = value_type (mactime_.microseconds(), id.get());
00080 ++uframe_count_;
00081 }
00082 else
00083 this->value() = boost::none_t ();
00084 }
00085
00086 template <class U, class I, class H, class B1, class B2>
00087 unsigned
00088 uniquely_identifiable_iterator<U, I, H, B1, B2>::frame_count() const
00089 {
00090 return frame_count_;
00091 }
00092
00093 template <class U, class I, class H, class B1, class B2>
00094 unsigned
00095 uniquely_identifiable_iterator<U, I, H, B1, B2>::
00096 unique_frame_count() const
00097 {
00098 return uframe_count_;
00099 }
00100
00101 }
00102
00103 template <class U, class I, class H, class B>
00104 uniquely_identifiable<U, I, H, B>::
00105 uniquely_identifiable(const I& begin,
00106 const I& end,
00107 addr_mapping& mapping,
00108 tool::endian::endianness phy_end):
00109 begin_ (begin),
00110 end_ (end),
00111 mapping_ (&mapping),
00112 phy_end_ (phy_end)
00113 {
00114 }
00115
00116 template <class U, class HT, class I, class F>
00117 void
00118 for_each_uniquely_identifiable(const I& first,
00119 const I& last,
00120 tool::opt::list& opts,
00121 F& func)
00122 {
00123 typedef tool::endian::endianness endianness;
00124
00125 const endianness& end = opts["endianness"].get<endianness>();
00126 addr_mapping& map = opts["mapping"].get<addr_mapping>();
00127
00128 if (opts["ignore_noisy_prism"].get<bool>())
00129 {
00130 typedef non_noisy_prism<I> filter_type;
00131 typedef typename filter_type::iterator iterator;
00132 typedef uniquely_identifiable<U, iterator, HT> unique_type;
00133
00134 filter_type f (first, last);
00135 unique_type u (f.begin(), f.end(), map, end);
00136
00137 u.for_each(func);
00138 }
00139 else
00140 {
00141 typedef uniquely_identifiable<U, I, HT> unique_type;
00142
00143 unique_type u (first, last, map, end);
00144
00145 u.for_each(func);
00146 }
00147 }
00148
00149
00150 template <class U, class HT, class I, class F>
00151 void
00152 for_each_uniquely_identifiable(const I& first,
00153 const I& last,
00154 const tool::opt::list& opts,
00155 const F& func)
00156 {
00157 typedef tool::endian::endianness endianness;
00158
00159 const endianness& end = opts["endianness"].get<endianness>();
00160 addr_mapping& map = opts["mapping"].get<addr_mapping>();
00161
00162 if (opts["ignore_noisy_prism"].get<bool>())
00163 {
00164 typedef non_noisy_prism<I> filter_type;
00165 typedef typename filter_type::iterator iterator;
00166 typedef uniquely_identifiable<U, iterator, HT> unique_type;
00167
00168 filter_type f (first, last);
00169 unique_type u (f.begin(), f.end(), map, end);
00170
00171 u.for_each(func);
00172 }
00173 else
00174 {
00175 typedef uniquely_identifiable<U, I, HT> unique_type;
00176
00177 unique_type u (first, last, map, end);
00178
00179 u.for_each(func);
00180 }
00181 }
00182
00183 }
00184
00185 }
00186
00187 }
00188
00189 #endif // ! WIFI_FRAME_FILTER_UNIQUELY_IDENTIFIABLE_HXX_