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