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 <wipal/phy/phy.hh>
00026
00027 namespace phy
00028 {
00029
00030
00031
00032
00033
00034 template <class B>
00035 typename time<B>::impl_type
00036 time<B>::get() const
00037 {
00038 return this->exact().get_impl();
00039 }
00040
00041 template <class B>
00042 typename time<B>::exact_type&
00043 time<B>::operator += (tool::microseconds microseconds)
00044 {
00045 return this->increment(microseconds);
00046 }
00047
00048 template <class B>
00049 typename time<B>::exact_type
00050 time<B>::operator + (tool::microseconds microseconds) const
00051 {
00052 exact_type r (this->exact());
00053
00054 r.increment(microseconds);
00055 return r;
00056 }
00057
00058 template <class B>
00059 time<B>::~time()
00060 {
00061 }
00062
00063
00064
00065
00066
00067
00068 template <class Bottom>
00069 typename uint64_time<Bottom>::impl_type
00070 uint64_time<Bottom>::get_impl() const
00071 {
00072 return ms_count_;
00073 }
00074
00075 template <class Bottom>
00076 typename uint64_time<Bottom>::exact_type&
00077 uint64_time<Bottom>::increment(const tool::microseconds& microseconds)
00078 {
00079 const uint64_t lo = mpz_class (microseconds &
00080 mpz_class (uint32_t (-1))).get_ui();
00081 const uint64_t hi = mpz_class (microseconds >> 32).get_ui();
00082
00083 ms_count_ += (hi << 32) | lo;
00084
00085 return this->exact();
00086 }
00087
00088 template <class Bottom>
00089 uint64_time<Bottom>::uint64_time(): ms_count_ (0)
00090 {
00091 }
00092
00093 template <class Bottom>
00094 uint64_time<Bottom>::uint64_time(uint64_t tsft): ms_count_ (tsft)
00095 {
00096 }
00097
00098
00099
00100
00101
00102
00103 template <class B>
00104 size_t
00105 header<B>::len(size_t caplen, bool swapped) const
00106 {
00107 return this->exact().len_impl(caplen, swapped);
00108 }
00109
00110 template <class B>
00111 const void*
00112 header<B>::decapsulate(size_t caplen, bool swapped) const
00113 {
00114 const size_t len = this->exact().len_impl(caplen, swapped);
00115
00116 return len > caplen ? 0 : reinterpret_cast<const uint8_t*> (this) + len;
00117 }
00118
00119 template <class B>
00120 typename header<B>::time_type
00121 header<B>::time_get(bool swapped) const
00122 {
00123 return this->exact().time_get_impl(swapped);
00124 }
00125
00126 template <class B>
00127 void
00128 header<B>::time_set(const time_type& time, bool swapped)
00129 {
00130 this->exact().time_set_impl(time, swapped);
00131 }
00132
00133 template <class B>
00134 bool
00135 header<B>::eq_80211(const pcapxx::frame_descriptor& lhs,
00136 const pcapxx::frame_descriptor& rhs,
00137 tool::endian::endianness phy_end)
00138 {
00139 using tool::endian::need_swap;
00140
00141 const pcapxx::pkthdr& lhs_pcap = *lhs.pcap_header().get();
00142 const pcapxx::pkthdr& rhs_pcap = *rhs.pcap_header().get();
00143
00144 const bool lhs_sw = need_swap(phy_end, lhs_pcap.swapped);
00145 const bool rhs_sw = need_swap(phy_end, rhs_pcap.swapped);
00146
00147 const exact_type* const lhs_phy = (reinterpret_cast<const exact_type*>
00148 (lhs.bytes().get()));
00149 const exact_type* const rhs_phy = (reinterpret_cast<const exact_type*>
00150 (rhs.bytes().get()));
00151
00152 const void* const lhs_ieee = lhs_phy->decapsulate(lhs_pcap.caplen,
00153 lhs_sw);
00154 const void* const rhs_ieee = rhs_phy->decapsulate(rhs_pcap.caplen,
00155 rhs_sw);
00156
00157 const ssize_t lhs_caplen = (lhs_pcap.caplen -
00158 lhs_phy->len(lhs_pcap.caplen,
00159 lhs_sw));
00160 const ssize_t rhs_caplen = (rhs_pcap.caplen -
00161 rhs_phy->len(rhs_pcap.caplen,
00162 rhs_sw));
00163
00164 const ssize_t caplen = std::min(lhs_caplen, rhs_caplen);
00165
00166 return caplen <= 0 ? false : 0 == memcmp(lhs_ieee, rhs_ieee, caplen);
00167 }
00168
00169 template <class B>
00170 bool
00171 header<B>::eq_time_and_80211(const pcapxx::frame_descriptor& lhs,
00172 const pcapxx::frame_descriptor& rhs,
00173 tool::endian::endianness phy_end,
00174 unsigned prec)
00175 {
00176 return
00177 exact_type::eq_time(lhs, rhs, phy_end, prec)?
00178 eq_80211(lhs, rhs, phy_end):
00179 false;
00180 }
00181
00182 template <class B>
00183 header<B>::~header()
00184 {
00185 }
00186
00187 }
00188
00189 #endif // ! PHY_PHY_HXX_