• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 package com.android.server.wifi;
17 
18 
19 import android.annotation.NonNull;
20 import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback;
21 import android.net.wifi.WifiConfiguration;
22 import android.net.wifi.WifiManager;
23 import android.util.Log;
24 
25 import java.util.ArrayList;
26 
27 abstract class SupplicantStaIfaceCallbackV1_3Impl extends
28         android.hardware.wifi.supplicant.V1_3.ISupplicantStaIfaceCallback.Stub {
29     private static final String TAG = SupplicantStaIfaceCallbackV1_3Impl.class.getSimpleName();
30     private final SupplicantStaIfaceHal mStaIfaceHal;
31     private final String mIfaceName;
32     private final WifiMonitor mWifiMonitor;
33     private final SupplicantStaIfaceHal.SupplicantStaIfaceHalCallbackV1_2 mCallbackV12;
34 
SupplicantStaIfaceCallbackV1_3Impl(@onNull SupplicantStaIfaceHal staIfaceHal, @NonNull String ifaceName, @NonNull WifiMonitor wifiMonitor)35     SupplicantStaIfaceCallbackV1_3Impl(@NonNull SupplicantStaIfaceHal staIfaceHal,
36             @NonNull String ifaceName,
37             @NonNull WifiMonitor wifiMonitor) {
38         mStaIfaceHal = staIfaceHal;
39         mIfaceName = ifaceName;
40         mWifiMonitor = wifiMonitor;
41         // Create an older callback for function delegation,
42         // and it would cascadingly create older one.
43         mCallbackV12 = mStaIfaceHal.new SupplicantStaIfaceHalCallbackV1_2(mIfaceName);
44     }
45 
46     @Override
onNetworkAdded(int id)47     public void onNetworkAdded(int id) {
48         mCallbackV12.onNetworkAdded(id);
49     }
50 
51     @Override
onNetworkRemoved(int id)52     public void onNetworkRemoved(int id) {
53         mCallbackV12.onNetworkRemoved(id);
54     }
55 
56     @Override
onStateChanged(int newState, byte[ ] bssid, int id, ArrayList<Byte> ssid)57     public void onStateChanged(int newState, byte[/* 6 */] bssid, int id,
58             ArrayList<Byte> ssid) {
59         mCallbackV12.onStateChanged(newState, bssid, id, ssid);
60     }
61 
62     @Override
onAnqpQueryDone(byte[ ] bssid, ISupplicantStaIfaceCallback.AnqpData data, ISupplicantStaIfaceCallback.Hs20AnqpData hs20Data)63     public void onAnqpQueryDone(byte[/* 6 */] bssid,
64             ISupplicantStaIfaceCallback.AnqpData data,
65             ISupplicantStaIfaceCallback.Hs20AnqpData hs20Data) {
66         mCallbackV12.onAnqpQueryDone(bssid, data, hs20Data);
67     }
68 
69     @Override
onHs20IconQueryDone(byte[ ] bssid, String fileName, ArrayList<Byte> data)70     public void onHs20IconQueryDone(byte[/* 6 */] bssid, String fileName,
71             ArrayList<Byte> data) {
72         mCallbackV12.onHs20IconQueryDone(bssid, fileName, data);
73     }
74 
75     @Override
onHs20SubscriptionRemediation(byte[ ] bssid, byte osuMethod, String url)76     public void onHs20SubscriptionRemediation(byte[/* 6 */] bssid,
77             byte osuMethod, String url) {
78         mCallbackV12.onHs20SubscriptionRemediation(bssid, osuMethod, url);
79     }
80 
81     @Override
onHs20DeauthImminentNotice(byte[ ] bssid, int reasonCode, int reAuthDelayInSec, String url)82     public void onHs20DeauthImminentNotice(byte[/* 6 */] bssid, int reasonCode,
83             int reAuthDelayInSec, String url) {
84         mCallbackV12.onHs20DeauthImminentNotice(bssid, reasonCode, reAuthDelayInSec, url);
85     }
86 
87     @Override
onDisconnected(byte[ ] bssid, boolean locallyGenerated, int reasonCode)88     public void onDisconnected(byte[/* 6 */] bssid, boolean locallyGenerated,
89             int reasonCode) {
90         mCallbackV12.onDisconnected(bssid, locallyGenerated, reasonCode);
91     }
92 
93     @Override
onAssociationRejected(byte[ ] bssid, int statusCode, boolean timedOut)94     public void onAssociationRejected(byte[/* 6 */] bssid, int statusCode,
95             boolean timedOut) {
96         mCallbackV12.onAssociationRejected(bssid, statusCode, timedOut);
97     }
98 
99     @Override
onAuthenticationTimeout(byte[ ] bssid)100     public void onAuthenticationTimeout(byte[/* 6 */] bssid) {
101         mCallbackV12.onAuthenticationTimeout(bssid);
102     }
103 
104     @Override
onBssidChanged(byte reason, byte[ ] bssid)105     public void onBssidChanged(byte reason, byte[/* 6 */] bssid) {
106         mCallbackV12.onBssidChanged(reason, bssid);
107     }
108 
109     @Override
onEapFailure()110     public void onEapFailure() {
111         mCallbackV12.onEapFailure();
112     }
113 
114     @Override
onEapFailure_1_1(int code)115     public void onEapFailure_1_1(int code) {
116         mCallbackV12.onEapFailure_1_1(code);
117     }
118 
119     @Override
onEapFailure_1_3(int code)120     public void onEapFailure_1_3(int code) {
121         mCallbackV12.onEapFailure_1_1(code);
122     }
123 
124     @Override
onWpsEventSuccess()125     public void onWpsEventSuccess() {
126         mCallbackV12.onWpsEventSuccess();
127     }
128 
129     @Override
onWpsEventFail(byte[ ] bssid, short configError, short errorInd)130     public void onWpsEventFail(byte[/* 6 */] bssid, short configError, short errorInd) {
131         mCallbackV12.onWpsEventFail(bssid, configError, errorInd);
132     }
133 
134     @Override
onWpsEventPbcOverlap()135     public void onWpsEventPbcOverlap() {
136         mCallbackV12.onWpsEventPbcOverlap();
137     }
138 
139     @Override
onExtRadioWorkStart(int id)140     public void onExtRadioWorkStart(int id) {
141         mCallbackV12.onExtRadioWorkStart(id);
142     }
143 
144     @Override
onExtRadioWorkTimeout(int id)145     public void onExtRadioWorkTimeout(int id) {
146         mCallbackV12.onExtRadioWorkTimeout(id);
147     }
148 
149     @Override
onDppSuccessConfigReceived(ArrayList<Byte> ssid, String password, byte[] psk, int securityAkm)150     public void onDppSuccessConfigReceived(ArrayList<Byte> ssid, String password,
151             byte[] psk, int securityAkm) {
152         mCallbackV12.onDppSuccessConfigReceived(
153                 ssid, password, psk, securityAkm);
154     }
155 
156     @Override
onDppSuccessConfigSent()157     public void onDppSuccessConfigSent() {
158         mCallbackV12.onDppSuccessConfigSent();
159     }
160 
161     @Override
onDppProgress(int code)162     public void onDppProgress(int code) {
163         mCallbackV12.onDppProgress(code);
164     }
165 
166     @Override
onDppFailure(int code)167     public void onDppFailure(int code) {
168         mCallbackV12.onDppFailure(code);
169     }
170 
171     @Override
onPmkCacheAdded(long expirationTimeInSec, ArrayList<Byte> serializedEntry)172     public void onPmkCacheAdded(long expirationTimeInSec, ArrayList<Byte> serializedEntry) {
173         WifiConfiguration curConfig = mStaIfaceHal.getCurrentNetworkLocalConfig(mIfaceName);
174 
175         if (curConfig == null) return;
176 
177         if (WifiConfigurationUtil.isConfigForPskNetwork(curConfig)) return;
178 
179         mStaIfaceHal.addPmkCacheEntry(mIfaceName,
180                 curConfig.networkId, expirationTimeInSec, serializedEntry);
181         mStaIfaceHal.logCallback(
182                 "onPmkCacheAdded: update pmk cache for config id "
183                 + curConfig.networkId
184                 + " on "
185                 + mIfaceName);
186     }
187 
188     @Override
onDppProgress_1_3(int code)189     public void onDppProgress_1_3(int code) {
190         if (mStaIfaceHal.getDppCallback() != null) {
191             mStaIfaceHal.getDppCallback().onProgress(code);
192         } else {
193             Log.e(TAG, "onDppProgress callback is null");
194         }
195     }
196 
197     @Override
onDppFailure_1_3(int code, String ssid, String channelList, ArrayList<Short> bandList)198     public void onDppFailure_1_3(int code, String ssid, String channelList,
199             ArrayList<Short> bandList) {
200         if (mStaIfaceHal.getDppCallback() != null) {
201             int[] bandListArray = null;
202 
203             // Convert operating class list to a primitive array
204             if (bandList != null) {
205                 bandListArray = new int[bandList.size()];
206 
207                 for (int i = 0; i < bandList.size(); i++) {
208                     bandListArray[i] = bandList.get(i).intValue();
209                 }
210             }
211             mStaIfaceHal.getDppCallback().onFailure(code, ssid, channelList, bandListArray);
212         } else {
213             Log.e(TAG, "onDppFailure callback is null");
214         }
215     }
216 
217     @Override
onDppSuccess(int code)218     public void onDppSuccess(int code) {
219         if (mStaIfaceHal.getDppCallback() != null) {
220             mStaIfaceHal.getDppCallback().onSuccess(code);
221         } else {
222             Log.e(TAG, "onDppFailure callback is null");
223         }
224     }
225 
226     @Override
onBssTmHandlingDone(BssTmData tmData)227     public void onBssTmHandlingDone(BssTmData tmData) {
228         MboOceController.BtmFrameData btmFrmData = new MboOceController.BtmFrameData();
229 
230         btmFrmData.mStatus = halToFrameworkBtmResponseStatus(tmData.status);
231         btmFrmData.mBssTmDataFlagsMask = halToFrameworkBssTmDataFlagsMask(tmData.flags);
232         btmFrmData.mBlockListDurationMs = tmData.assocRetryDelayMs;
233         if ((tmData.flags & BssTmDataFlagsMask.MBO_TRANSITION_REASON_CODE_INCLUDED) != 0) {
234             btmFrmData.mTransitionReason = halToFrameworkMboTransitionReason(
235                     tmData.mboTransitionReason);
236         }
237         if ((tmData.flags
238                 & BssTmDataFlagsMask.MBO_CELLULAR_DATA_CONNECTION_PREFERENCE_INCLUDED) != 0) {
239             btmFrmData.mCellPreference =
240                     halToFrameworkMboCellularDataConnectionPreference(tmData.mboCellPreference);
241         }
242         mStaIfaceHal.logCallback(
243                 "onBssTmHandlingDone: Handle BTM handling event");
244         mWifiMonitor.broadcastBssTmHandlingDoneEvent(mIfaceName, btmFrmData);
245     }
246 
halToFrameworkBtmResponseStatus(int status)247     private @MboOceConstants.BtmResponseStatus int halToFrameworkBtmResponseStatus(int status) {
248         switch (status) {
249             case BssTmStatusCode.ACCEPT:
250                 return MboOceConstants.BTM_RESPONSE_STATUS_ACCEPT;
251             case BssTmStatusCode.REJECT_UNSPECIFIED:
252                 return MboOceConstants.BTM_RESPONSE_STATUS_REJECT_UNSPECIFIED;
253             case BssTmStatusCode.REJECT_INSUFFICIENT_BEACON:
254                 return MboOceConstants.BTM_RESPONSE_STATUS_REJECT_INSUFFICIENT_BEACON;
255             case BssTmStatusCode.REJECT_INSUFFICIENT_CAPABITY:
256                 return MboOceConstants.BTM_RESPONSE_STATUS_REJECT_INSUFFICIENT_CAPABITY;
257             case BssTmStatusCode.REJECT_BSS_TERMINATION_UNDESIRED:
258                 return MboOceConstants.BTM_RESPONSE_STATUS_REJECT_BSS_TERMINATION_UNDESIRED;
259             case BssTmStatusCode.REJECT_BSS_TERMINATION_DELAY_REQUEST:
260                 return MboOceConstants.BTM_RESPONSE_STATUS_REJECT_BSS_TERMINATION_DELAY_REQUEST;
261             case BssTmStatusCode.REJECT_STA_CANDIDATE_LIST_PROVIDED:
262                 return MboOceConstants.BTM_RESPONSE_STATUS_REJECT_STA_CANDIDATE_LIST_PROVIDED;
263             case BssTmStatusCode.REJECT_NO_SUITABLE_CANDIDATES:
264                 return MboOceConstants.BTM_RESPONSE_STATUS_REJECT_NO_SUITABLE_CANDIDATES;
265             case BssTmStatusCode.REJECT_LEAVING_ESS:
266                 return MboOceConstants.BTM_RESPONSE_STATUS_REJECT_LEAVING_ESS;
267             default:
268                 return MboOceConstants.BTM_RESPONSE_STATUS_REJECT_RESERVED;
269         }
270     }
271 
halToFrameworkBssTmDataFlagsMask(int flags)272     private int halToFrameworkBssTmDataFlagsMask(int flags) {
273         int tmDataflags = 0;
274         if ((flags & BssTmDataFlagsMask.WNM_MODE_PREFERRED_CANDIDATE_LIST_INCLUDED) != 0) {
275             tmDataflags |= MboOceConstants.BTM_DATA_FLAG_PREFERRED_CANDIDATE_LIST_INCLUDED;
276         }
277         if ((flags & BssTmDataFlagsMask.WNM_MODE_ABRIDGED) != 0) {
278             tmDataflags |= MboOceConstants.BTM_DATA_FLAG_MODE_ABRIDGED;
279         }
280         if ((flags & BssTmDataFlagsMask.WNM_MODE_DISASSOCIATION_IMMINENT) != 0) {
281             tmDataflags |= MboOceConstants.BTM_DATA_FLAG_DISASSOCIATION_IMMINENT;
282         }
283         if ((flags & BssTmDataFlagsMask.WNM_MODE_BSS_TERMINATION_INCLUDED) != 0) {
284             tmDataflags |= MboOceConstants.BTM_DATA_FLAG_BSS_TERMINATION_INCLUDED;
285         }
286         if ((flags & BssTmDataFlagsMask.WNM_MODE_ESS_DISASSOCIATION_IMMINENT) != 0) {
287             tmDataflags |= MboOceConstants.BTM_DATA_FLAG_ESS_DISASSOCIATION_IMMINENT;
288         }
289         if ((flags & BssTmDataFlagsMask.MBO_TRANSITION_REASON_CODE_INCLUDED) != 0) {
290             tmDataflags |= MboOceConstants.BTM_DATA_FLAG_MBO_TRANSITION_REASON_CODE_INCLUDED;
291         }
292         if ((flags & BssTmDataFlagsMask.MBO_ASSOC_RETRY_DELAY_INCLUDED) != 0) {
293             tmDataflags |= MboOceConstants.BTM_DATA_FLAG_MBO_ASSOC_RETRY_DELAY_INCLUDED;
294         }
295         if ((flags & BssTmDataFlagsMask.MBO_CELLULAR_DATA_CONNECTION_PREFERENCE_INCLUDED) != 0) {
296             tmDataflags |=
297                     MboOceConstants.BTM_DATA_FLAG_MBO_CELL_DATA_CONNECTION_PREFERENCE_INCLUDED;
298         }
299         return tmDataflags;
300     }
301 
halToFrameworkMboTransitionReason( int reason)302     private @MboOceConstants.MboTransitionReason int halToFrameworkMboTransitionReason(
303             int reason) {
304         switch (reason) {
305             case MboTransitionReasonCode.UNSPECIFIED:
306                 return MboOceConstants.MBO_TRANSITION_REASON_UNSPECIFIED;
307             case MboTransitionReasonCode.EXCESSIVE_FRAME_LOSS:
308                 return MboOceConstants.MBO_TRANSITION_REASON_EXCESSIVE_FRAME_LOSS;
309             case MboTransitionReasonCode.EXCESSIVE_TRAFFIC_DELAY:
310                 return MboOceConstants.MBO_TRANSITION_REASON_EXCESSIVE_TRAFFIC_DELAY;
311             case MboTransitionReasonCode.INSUFFICIENT_BANDWIDTH:
312                 return MboOceConstants.MBO_TRANSITION_REASON_INSUFFICIENT_BANDWIDTH;
313             case MboTransitionReasonCode.LOAD_BALANCING:
314                 return MboOceConstants.MBO_TRANSITION_REASON_LOAD_BALANCING;
315             case MboTransitionReasonCode.LOW_RSSI:
316                 return MboOceConstants.MBO_TRANSITION_REASON_LOW_RSSI;
317             case MboTransitionReasonCode.RX_EXCESSIVE_RETRIES:
318                 return MboOceConstants.MBO_TRANSITION_REASON_RX_EXCESSIVE_RETRIES;
319             case MboTransitionReasonCode.HIGH_INTERFERENCE:
320                 return MboOceConstants.MBO_TRANSITION_REASON_HIGH_INTERFERENCE;
321             case MboTransitionReasonCode.GRAY_ZONE:
322                 return MboOceConstants.MBO_TRANSITION_REASON_GRAY_ZONE;
323             default:
324                 return MboOceConstants.MBO_TRANSITION_REASON_RESERVED;
325         }
326     }
327 
328     private @MboOceConstants.MboTransitionReason int
halToFrameworkMboCellularDataConnectionPreference(int cellPref)329             halToFrameworkMboCellularDataConnectionPreference(int cellPref) {
330         switch (cellPref) {
331             case MboCellularDataConnectionPrefValue.EXCLUDED:
332                 return MboOceConstants.MBO_CELLULAR_DATA_CONNECTION_EXCLUDED;
333             case MboCellularDataConnectionPrefValue.NOT_PREFERRED:
334                 return MboOceConstants.MBO_CELLULAR_DATA_CONNECTION_NOT_PREFERRED;
335             case MboCellularDataConnectionPrefValue.PREFERRED:
336                 return MboOceConstants.MBO_CELLULAR_DATA_CONNECTION_PREFERRED;
337             default:
338                 return MboOceConstants.MBO_CELLULAR_DATA_CONNECTION_RESERVED;
339         }
340     }
341 
342     @Override
onStateChanged_1_3(int newState, byte[ ] bssid, int id, ArrayList<Byte> ssid, boolean filsHlpSent)343     public void onStateChanged_1_3(int newState, byte[/* 6 */] bssid, int id,
344             ArrayList<Byte> ssid, boolean filsHlpSent) {
345         mCallbackV12.onStateChanged(newState, bssid, id, ssid, filsHlpSent);
346     }
347 }
348