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 struct hash_hooks: public dissector_default_hooks
00044 {
00045
00046 inline
00047 void
00048 probe_resp_hook(const mgt::header* frame, size_t caplen)
00049 {
00050 if (not control_flag(3, frame))
00051 result_ = hash_value (frame, caplen);
00052 }
00053
00054 inline
00055 void
00056 beacon_hook(const mgt::header* frame, size_t caplen)
00057 {
00058 result_ = hash_value (frame, caplen);
00059 }
00060
00061 boost::optional<hash_value> result_;
00062 };
00063
00064 }
00065
00066 template <class HeaderType>
00067 boost::optional<hsh_id>
00068 unique_id_factory<hsh_id>::build(const pcapxx::frame_descriptor& desc,
00069 addr_mapping&)
00070 {
00071 WP_UNIQUE_ID_DISSECT(desc, d, internals::hash_hooks, h);
00072
00073 if (h.result_)
00074 return hsh_id (desc.pcap_header()->id, h.result_.get());
00075 else
00076 return boost::none_t ();
00077 }
00078
00079 }
00080
00081 }
00082
00083 WP_HASH_NAMESPACE_BEGIN
00084
00085 inline
00086 size_t
00087 hash<wifi::frame::internals::hash_value>::
00088 operator () (const wifi::frame::internals::hash_value& v) const
00089 {
00090 typedef wifi::frame::internals::hash_value hash_value;
00091 typedef hash_value::value_type value_type;
00092 typedef hash_value::const_iterator const_iterator;
00093
00094 size_t r = 0;
00095 const_iterator i = v.begin();
00096 const const_iterator e = v.end();
00097
00098 while (i != e)
00099 for (unsigned j = 0; i != e and j < sizeof (size_t); ++i, ++j)
00100 r ^= (*i << (j * 8));
00101
00102 return r;
00103 }
00104
00105 WP_HASH_NAMESPACE_END
00106
00107 #endif // ! WIFI_FRAME_HASH_HXX_