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_SEQCTL_HXX_
00023 # define WIFI_FRAME_SEQCTL_HXX_
00024
00025 # include "seqctl.hh"
00026
00027 namespace wpl
00028 {
00029
00030 namespace wifi
00031 {
00032
00033
00034
00035
00036
00037 inline
00038 seqnum::seqnum(unsigned value): v_ (value)
00039 {
00040 assert(v_ < 4096);
00041 }
00042
00043 inline
00044 unsigned
00045 seqnum::get() const
00046 {
00047 return v_;
00048 }
00049
00050 inline
00051 bool
00052 seqnum::operator < (const seqnum& rhs) const
00053 {
00054 if (get() < rhs.get())
00055 return rhs.get() - get() < 2048;
00056 else
00057 return get() - rhs.get() > 2048;
00058 }
00059
00060 inline
00061 bool
00062 seqnum::operator <= (const seqnum& rhs) const
00063 {
00064 return *this == rhs or *this < rhs;
00065 }
00066
00067 inline
00068 bool
00069 seqnum::operator > (const seqnum& rhs) const
00070 {
00071 return not (*this <= rhs);
00072 }
00073
00074 inline
00075 bool
00076 seqnum::operator >= (const seqnum& rhs) const
00077 {
00078 return not (*this < rhs);
00079 }
00080
00081 inline
00082 bool
00083 seqnum::operator == (const seqnum& rhs) const
00084 {
00085 return get() == rhs.get();
00086 }
00087
00088 inline
00089 bool
00090 seqnum::operator != (const seqnum& rhs) const
00091 {
00092 return not (*this == rhs);
00093 }
00094
00095 inline
00096 int
00097 seqnum::operator - (const seqnum& rhs) const
00098 {
00099 if (get() < rhs.get())
00100 {
00101 const unsigned d = rhs.get() - get();
00102
00103 return d < 2048 ? -int (d) : int (4096 - d);
00104 }
00105 else
00106 {
00107 const unsigned d = get() - rhs.get();
00108
00109 return d > 2048 ? -int (4096 - d) : int (d);
00110 }
00111 }
00112
00113
00114
00115
00116
00117 inline
00118 seqctl::seqctl(unsigned seqnum, unsigned fragnum)
00119 {
00120 assert(seqnum < 4096);
00121 assert(fragnum < 16);
00122
00123 const uint16_t t = (seqnum << 4) | fragnum;
00124
00125 if (tool::need_swap(tool::end::little, false))
00126 seqctl_ = tool::extract_swapped_short_u(t);
00127 else
00128 seqctl_ = t;
00129 }
00130
00131 inline
00132 seqctl::seqctl(const uint16_t raw): seqctl_ (raw)
00133 {
00134 }
00135
00136 inline
00137 seqctl::seqctl(const void* raw):
00138 seqctl_ (*static_cast<const uint16_t*> (raw))
00139 {
00140 }
00141
00142 inline
00143 seqnum
00144 seqctl::seqnum_get() const
00145 {
00146 return tool::extract_little_endian_short_u(seqctl_) >> 4;
00147 }
00148
00149 inline
00150 unsigned
00151 seqctl::fragnum_get() const
00152 {
00153 return tool::extract_little_endian_short_u(seqctl_) & 0xF;
00154 }
00155
00156 inline
00157 bool
00158 seqctl::operator < (const seqctl& rhs) const
00159 {
00160 const seqnum l = seqnum_get();
00161 const seqnum r = rhs.seqnum_get();
00162
00163 if (l == r)
00164 return fragnum_get() < rhs.fragnum_get();
00165
00166 return l < r;
00167 }
00168
00169 inline
00170 bool
00171 seqctl::operator <= (const seqctl& rhs) const
00172 {
00173 return *this == rhs or *this < rhs;
00174 }
00175
00176 inline
00177 bool
00178 seqctl::operator > (const seqctl& rhs) const
00179 {
00180 return not (*this <= rhs);
00181 }
00182
00183 inline
00184 bool
00185 seqctl::operator >= (const seqctl& rhs) const
00186 {
00187 return not (*this < rhs);
00188 }
00189
00190 inline
00191 bool
00192 seqctl::operator == (const seqctl& rhs) const
00193 {
00194 return seqctl_ == rhs.seqctl_;
00195 }
00196
00197 inline
00198 bool
00199 seqctl::operator != (const seqctl& rhs) const
00200 {
00201 return not (*this == rhs);
00202 }
00203
00204
00205 }
00206
00207 }
00208
00209 #endif // ! WIFI_FRAME_SEQCTL_HXX_