1 /*
2  * Copyright 2019, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "macaddress.h"
20 
21 #include <string.h>
22 
23 struct FrameId {
FrameIdFrameId24     FrameId() {}
FrameIdFrameId25     FrameId(uint64_t cookie, const MacAddress& transmitter)
26         : cookie(cookie), transmitter(transmitter) {
27     }
28     FrameId(const FrameId&) = default;
29     FrameId(FrameId&&) = default;
30 
31     FrameId& operator=(const FrameId&) = default;
32     FrameId& operator=(FrameId&&) = default;
33 
34     uint64_t cookie;
35     MacAddress transmitter;
36 };
37 
38 namespace std {
39 template<> struct hash<FrameId> {
40     size_t operator()(const FrameId& id) const {
41         size_t seed = 0;
42         hash_combine(seed, id.cookie);
43         hash_combine(seed, id.transmitter);
44         return seed;
45     }
46 };
47 }
48 
49 inline bool operator==(const FrameId& left, const FrameId& right) {
50     return left.cookie == right.cookie && left.transmitter == right.transmitter;
51 }
52 
53 inline bool operator<(const FrameId& left, const FrameId& right) {
54     if (left.cookie < right.cookie) {
55         return true;
56     }
57     if (left.cookie > right.cookie) {
58         return false;
59     }
60     return memcmp(left.transmitter.addr,
61                   right.transmitter.addr,
62                   sizeof(left.transmitter.addr)) < 0;
63 }
64