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_HASH_HXX_
00023 # define WIFI_FRAME_HASH_HXX_
00024
00025 # include <wipal/wifi/frame/unique_id/hash.hh>
00026 # include <wipal/wifi/frame/frame.hh>
00027 # include <wipal/wifi/frame/mgt.hh>
00028
00029 namespace wifi
00030 {
00031
00032 namespace frame
00033 {
00034
00035 namespace internals
00036 {
00037
00038 hash_value::hash_value(const void* data, size_t len)
00039 {
00040 MD5(static_cast<const unsigned char*> (data), len, &this->front());
00041 }
00042
00043 }
00044
00045 template <class HeaderType>
00046 boost::optional<hsh_id>
00047 unique_id_factory<hsh_id>::build(const pcapxx::frame_descriptor& desc,
00048 addr_mapping&)
00049 {
00050 const void* frame;
00051 size_t caplen;
00052
00053 if (not internals::strip_phy_header<HeaderType>(frame, caplen, desc) or
00054 not caplen)
00055 return boost::none_t ();
00056
00057 const type::frame_type ty = type_of(frame);
00058 const unsigned st = subtype_of(frame);
00059
00060 switch (ty)
00061 {
00062 case type::management:
00063 switch (st)
00064 {
00065 case mgt::subtype::probe_resp:
00066 if (control_flag(3, frame))
00067 return boost::none_t ();
00068 return hsh_id (desc.pcap_header()->id,
00069 internals::hash_value (frame, caplen));
00070
00071 case mgt::subtype::beacon:
00072 return hsh_id (desc.pcap_header()->id,
00073 internals::hash_value (frame, caplen));
00074
00075 default:
00076 return boost::none_t ();
00077 }
00078
00079 default:
00080 return boost::none_t ();
00081 }
00082 }
00083
00084 }
00085
00086 }
00087
00088 WP_HASH_NAMESPACE_BEGIN
00089
00090 inline
00091 size_t
00092 hash<wifi::frame::internals::hash_value>::
00093 operator () (const wifi::frame::internals::hash_value& v) const
00094 {
00095 typedef wifi::frame::internals::hash_value hash_value;
00096 typedef hash_value::value_type value_type;
00097 typedef hash_value::const_iterator const_iterator;
00098
00099 size_t r = 0;
00100 const_iterator i = v.begin();
00101 const const_iterator e = v.end();
00102
00103 while (i != e)
00104 for (unsigned j = 0; i != e and j < sizeof (size_t); ++i, ++j)
00105 r ^= (*i << (j * 8));
00106
00107 return r;
00108 }
00109
00110 WP_HASH_NAMESPACE_END
00111
00112 #endif // ! WIFI_FRAME_HASH_HXX_