1 /*
2  * Copyright (C) 2016 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 #ifndef WIFICOND_NET_MLME_EVENT_H_
18 #define WIFICOND_NET_MLME_EVENT_H_
19 
20 #include <array>
21 #include <memory>
22 
23 #include <linux/if_ether.h>
24 
25 #include <android-base/macros.h>
26 
27 namespace android {
28 namespace wificond {
29 
30 class NL80211Packet;
31 
32 class MlmeConnectEvent {
33  public:
34   static std::unique_ptr<MlmeConnectEvent> InitFromPacket(
35       const NL80211Packet* packet);
36   // Returns the BSSID of the associated AP.
GetBSSID()37   const std::array<uint8_t, ETH_ALEN>& GetBSSID() const { return bssid_; }
38   // Get the status code of this connect event.
39   // 0 = success, non-zero = failure.
40   // Status codes definition: IEEE 802.11-2012, 8.4.1.9, Table 8-37
GetStatusCode()41   uint16_t GetStatusCode() const { return status_code_; }
GetInterfaceIndex()42   uint32_t GetInterfaceIndex() const { return interface_index_; }
IsTimeout()43   bool IsTimeout() const { return is_timeout_; }
44 
45  private:
46   MlmeConnectEvent() = default;
47 
48   uint32_t interface_index_;
49   std::array<uint8_t, ETH_ALEN> bssid_;
50   uint16_t status_code_;
51   bool is_timeout_;
52 
53   DISALLOW_COPY_AND_ASSIGN(MlmeConnectEvent);
54 };
55 
56 class MlmeAssociateEvent {
57  public:
58   static std::unique_ptr<MlmeAssociateEvent> InitFromPacket(
59       const NL80211Packet* packet);
60   // Returns the BSSID of the associated AP.
GetBSSID()61   const std::array<uint8_t, ETH_ALEN>& GetBSSID() const { return bssid_; }
62   // Get the status code of this associate event.
63   // 0 = success, non-zero = failure.
64   // Status codes definition: IEEE 802.11-2012, 8.4.1.9, Table 8-37
GetStatusCode()65   uint16_t GetStatusCode() const { return status_code_; }
GetInterfaceIndex()66   uint32_t GetInterfaceIndex() const { return interface_index_; }
IsTimeout()67   bool IsTimeout() const { return is_timeout_; }
68 
69  private:
70   MlmeAssociateEvent() = default;
71 
72   uint32_t interface_index_;
73   std::array<uint8_t, ETH_ALEN> bssid_;
74   uint16_t status_code_;
75   bool is_timeout_;
76 
77   DISALLOW_COPY_AND_ASSIGN(MlmeAssociateEvent);
78 };
79 
80 class MlmeRoamEvent {
81  public:
82   static std::unique_ptr<MlmeRoamEvent> InitFromPacket(
83       const NL80211Packet* packet);
84   // Returns the BSSID of the associated AP.
GetBSSID()85   const std::array<uint8_t, ETH_ALEN>& GetBSSID() const { return bssid_; }
GetInterfaceIndex()86   uint32_t GetInterfaceIndex() const { return interface_index_; }
87 
88  private:
89   MlmeRoamEvent() = default;
90 
91   uint32_t interface_index_;
92   std::array<uint8_t, ETH_ALEN> bssid_;
93 
94   DISALLOW_COPY_AND_ASSIGN(MlmeRoamEvent);
95 };
96 
97 
98 class MlmeDisconnectEvent {
99  public:
100   static std::unique_ptr<MlmeDisconnectEvent> InitFromPacket(
101       const NL80211Packet* packet);
GetInterfaceIndex()102   uint32_t GetInterfaceIndex() const { return interface_index_; }
103  private:
104   MlmeDisconnectEvent() = default;
105 
106   uint32_t interface_index_;
107   std::array<uint8_t, ETH_ALEN> bssid_;
108 
109   DISALLOW_COPY_AND_ASSIGN(MlmeDisconnectEvent);
110 };
111 
112 class MlmeDisassociateEvent {
113  public:
114   static std::unique_ptr<MlmeDisassociateEvent> InitFromPacket(
115       const NL80211Packet* packet);
GetInterfaceIndex()116   uint32_t GetInterfaceIndex() const { return interface_index_; }
117  private:
118   MlmeDisassociateEvent() = default;
119 
120   uint32_t interface_index_;
121   std::array<uint8_t, ETH_ALEN> bssid_;
122 
123   DISALLOW_COPY_AND_ASSIGN(MlmeDisassociateEvent);
124 };
125 
126 }  // namespace wificond
127 }  // namespace android
128 
129 #endif  // WIFICOND_NET_MLME_EVENT_H_
130