1 /*
2  * Copyright (C) 2020 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 package com.android.server.wifi;
18 
19 import android.annotation.NonNull;
20 import android.hardware.wifi.supplicant.AssociationRejectionData;
21 import android.net.wifi.WifiManager;
22 import android.net.wifi.WifiSsid;
23 import android.util.Log;
24 
25 import com.android.server.wifi.util.NativeUtil;
26 
27 /**
28  * Stores assoc reject information passed from WifiMonitor.
29  */
30 public class AssocRejectEventInfo {
31     private static final String TAG = "AssocRejectEventInfo";
32 
33     @NonNull public final String ssid;
34     @NonNull public final String bssid;
35     public final int statusCode;
36     public final boolean timedOut;
37     public final MboOceController.OceRssiBasedAssocRejectAttr oceRssiBasedAssocRejectInfo;
38     public final MboOceController.MboAssocDisallowedAttr mboAssocDisallowedInfo;
39 
AssocRejectEventInfo(@onNull String ssid, @NonNull String bssid, int statusCode, boolean timedOut)40     public AssocRejectEventInfo(@NonNull String ssid, @NonNull String bssid, int statusCode,
41             boolean timedOut) {
42         if (ssid == null) {
43             Log.wtf(TAG, "Null SSID provided");
44             this.ssid = WifiManager.UNKNOWN_SSID;
45         } else {
46             this.ssid = ssid;
47         }
48         if (bssid == null) {
49             Log.wtf(TAG, "Null BSSID provided");
50             this.bssid = WifiManager.ALL_ZEROS_MAC_ADDRESS.toString();
51         } else {
52             this.bssid = bssid;
53         }
54         this.statusCode = statusCode;
55         this.timedOut = timedOut;
56         this.oceRssiBasedAssocRejectInfo = null;
57         this.mboAssocDisallowedInfo = null;
58     }
59 
AssocRejectEventInfo(android.hardware.wifi.supplicant.V1_4 .ISupplicantStaIfaceCallback.AssociationRejectionData assocRejectData)60     public AssocRejectEventInfo(android.hardware.wifi.supplicant.V1_4
61             .ISupplicantStaIfaceCallback.AssociationRejectionData assocRejectData) {
62         String ssid = WifiSsid.fromBytes(NativeUtil.byteArrayFromArrayList(assocRejectData.ssid))
63                 .toString();
64         String bssid = NativeUtil.macAddressFromByteArray(assocRejectData.bssid);
65         this.ssid = ssid;
66         this.bssid = bssid;
67         this.statusCode = assocRejectData.statusCode;
68         this.timedOut = assocRejectData.timedOut;
69         if (assocRejectData.isMboAssocDisallowedReasonCodePresent) {
70             this.mboAssocDisallowedInfo = new MboOceController.MboAssocDisallowedAttr(
71                     assocRejectData.mboAssocDisallowedReason);
72         } else {
73             this.mboAssocDisallowedInfo = null;
74         }
75         if (assocRejectData.isOceRssiBasedAssocRejectAttrPresent) {
76             this.oceRssiBasedAssocRejectInfo =
77                     new MboOceController.OceRssiBasedAssocRejectAttr(
78                             assocRejectData.oceRssiBasedAssocRejectData.deltaRssi,
79                             assocRejectData.oceRssiBasedAssocRejectData.retryDelayS);
80         } else {
81             this.oceRssiBasedAssocRejectInfo = null;
82         }
83     }
84 
85     // Constructor using the AIDL definition
AssocRejectEventInfo(AssociationRejectionData assocRejectData)86     public AssocRejectEventInfo(AssociationRejectionData assocRejectData) {
87         String ssid = WifiSsid.fromBytes(assocRejectData.ssid).toString();
88         String bssid = NativeUtil.macAddressFromByteArray(assocRejectData.bssid);
89         this.ssid = ssid;
90         this.bssid = bssid;
91         this.statusCode = assocRejectData.statusCode;
92         this.timedOut = assocRejectData.timedOut;
93         if (assocRejectData.isMboAssocDisallowedReasonCodePresent) {
94             this.mboAssocDisallowedInfo = new MboOceController.MboAssocDisallowedAttr(
95                     assocRejectData.mboAssocDisallowedReason);
96         } else {
97             this.mboAssocDisallowedInfo = null;
98         }
99         if (assocRejectData.isOceRssiBasedAssocRejectAttrPresent) {
100             this.oceRssiBasedAssocRejectInfo =
101                     new MboOceController.OceRssiBasedAssocRejectAttr(
102                             assocRejectData.oceRssiBasedAssocRejectData.deltaRssi,
103                             assocRejectData.oceRssiBasedAssocRejectData.retryDelayS);
104         } else {
105             this.oceRssiBasedAssocRejectInfo = null;
106         }
107     }
108 
109     @Override
toString()110     public String toString() {
111         StringBuffer sb = new StringBuffer();
112         sb.append(" ssid: ").append(ssid);
113         sb.append(" bssid: ").append(bssid);
114         sb.append(" statusCode: ").append(statusCode);
115         sb.append(" timedOut: ").append(timedOut);
116         sb.append(" oceRssiBasedAssocRejectInfo: ").append(oceRssiBasedAssocRejectInfo);
117         sb.append(" mboAssocDisallowedInfo: ").append(mboAssocDisallowedInfo);
118 
119         return sb.toString();
120     }
121 }
122