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