00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PHY_PHY_HXX_
00023 # define PHY_PHY_HXX_
00024
00025 # include <iostream>
00026
00027 # include <wipal/phy/phy.hh>
00028
00029 namespace wpl
00030 {
00031
00032 namespace phy
00033 {
00034
00035
00036
00037
00038
00039 template <class B>
00040 typename time<B>::impl_type
00041 time<B>::get() const
00042 {
00043 return this->exact().get_impl();
00044 }
00045
00046 template <class B>
00047 typename time<B>::exact_type&
00048 time<B>::operator += (tool::microseconds microseconds)
00049 {
00050 return this->increment(microseconds);
00051 }
00052
00053 template <class B>
00054 typename time<B>::exact_type
00055 time<B>::operator + (tool::microseconds microseconds) const
00056 {
00057 exact_type r (this->exact());
00058
00059 r.increment(microseconds);
00060 return r;
00061 }
00062
00063 template <class B>
00064 time<B>::~time()
00065 {
00066 }
00067
00068
00069
00070
00071
00072
00073 template <class Bottom>
00074 typename uint64_time<Bottom>::impl_type
00075 uint64_time<Bottom>::get_impl() const
00076 {
00077 return ms_count_;
00078 }
00079
00080 template <class Bottom>
00081 typename uint64_time<Bottom>::exact_type&
00082 uint64_time<Bottom>::increment(const tool::microseconds& microseconds)
00083 {
00084 const tool::microseconds base (ms_count_);
00085 const tool::microseconds result (base + microseconds);
00086
00087 ms_count_ = result.get_uint64();
00088
00089 return this->exact();
00090 }
00091
00092 template <class Bottom>
00093 uint64_time<Bottom>::uint64_time(): ms_count_ (0)
00094 {
00095 }
00096
00097 template <class Bottom>
00098 uint64_time<Bottom>::uint64_time(uint64_t tsft): ms_count_ (tsft)
00099 {
00100 }
00101
00102
00103
00104
00105
00106
00107 template <class B>
00108 size_t
00109 header<B>::len(size_t caplen, bool swapped) const
00110 {
00111 return this->exact().len_impl(caplen, swapped);
00112 }
00113
00114 template <class B>
00115 const void*
00116 header<B>::decapsulate(size_t caplen, bool swapped) const
00117 {
00118 const size_t len = this->exact().len_impl(caplen, swapped);
00119
00120 return len > caplen ? 0 : reinterpret_cast<const uint8_t*> (this) + len;
00121 }
00122
00123 template <class B>
00124 typename header<B>::time_type
00125 header<B>::time_get(bool swapped) const
00126 {
00127 return this->exact().time_get_impl(swapped);
00128 }
00129
00130 template <class B>
00131 void
00132 header<B>::time_set(const time_type& time, bool swapped)
00133 {
00134 this->exact().time_set_impl(time, swapped);
00135 }
00136
00137 template <class B>
00138 template <class S1, class S2>
00139 bool
00140 header<B>::eq_80211(const pkt::packet<S1>& lhs,
00141 const pkt::packet<S2>& rhs,
00142 tool::end::endianness phy_end)
00143 {
00144 using tool::need_swap;
00145
00146 const pkt::metadata& lhs_meta = lhs.meta();
00147 const pkt::metadata& rhs_meta = rhs.meta();
00148
00149 const bool lhs_sw = need_swap(phy_end, lhs.swapped());
00150 const bool rhs_sw = need_swap(phy_end, rhs.swapped());
00151
00152 const exact_type* const lhs_phy = (static_cast<const exact_type*>
00153 (lhs.bytes()));
00154 const exact_type* const rhs_phy = (static_cast<const exact_type*>
00155 (rhs.bytes()));
00156
00157 const void* const lhs_ieee = lhs_phy->decapsulate(lhs_meta.caplen,
00158 lhs_sw);
00159 const void* const rhs_ieee = rhs_phy->decapsulate(rhs_meta.caplen,
00160 rhs_sw);
00161
00162 const ssize_t lhs_caplen = (lhs_meta.caplen -
00163 lhs_phy->len(lhs_meta.caplen,
00164 lhs_sw));
00165 const ssize_t rhs_caplen = (rhs_meta.caplen -
00166 rhs_phy->len(rhs_meta.caplen,
00167 rhs_sw));
00168
00169 const ssize_t caplen = std::min(lhs_caplen, rhs_caplen);
00170
00171 return caplen <= 0 ? false : 0 == memcmp(lhs_ieee, rhs_ieee, caplen);
00172 }
00173
00174 template <class B>
00175 template <class S1, class S2>
00176 bool
00177 header<B>::eq_time_and_80211(const pkt::packet<S1>& lhs,
00178 const pkt::packet<S2>& rhs,
00179 const unsigned prec,
00180 const tool::end::endianness phy_end)
00181 {
00182 return (exact_type::eq_time(lhs, rhs, prec, phy_end) and
00183 eq_80211(lhs, rhs, phy_end));
00184 }
00185
00186 template <class B>
00187 header<B>::~header()
00188 {
00189 }
00190
00191 }
00192
00193 }
00194
00195 #endif // ! PHY_PHY_HXX_