• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 android.net.wifi;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 import androidx.annotation.Keep;
23 
24 /**
25  * From <code>defs.h</code> in <code>wpa_supplicant</code>.
26  * <p/>
27  * These enumeration values are used to indicate the current wpa_supplicant
28  * state. This is more fine-grained than most users will be interested in.
29  * In general, it is better to use
30  * {@link android.net.NetworkInfo.State NetworkInfo.State}.
31  * <p/>
32  * Note, the order of these enum constants must match the numerical values of the
33  * state constants in <code>defs.h</code> in <code>wpa_supplicant</code>.
34  */
35 public enum SupplicantState implements Parcelable {
36     /**
37      * This state indicates that client is not associated, but is likely to
38      * start looking for an access point. This state is entered when a
39      * connection is lost.
40      */
41     DISCONNECTED,
42 
43     /**
44      * Interface is disabled
45      * <p/>
46      * This state is entered if the network interface is disabled.
47      * wpa_supplicant refuses any new operations that would
48      * use the radio until the interface has been enabled.
49      */
50     INTERFACE_DISABLED,
51 
52     /**
53      * Inactive state (wpa_supplicant disabled).
54      * <p/>
55      * This state is entered if there are no enabled networks in the
56      * configuration. wpa_supplicant is not trying to associate with a new
57      * network and external interaction (e.g., ctrl_iface call to add or
58      * enable a network) is needed to start association.
59      */
60     INACTIVE,
61 
62     /**
63      * Scanning for a network.
64      * <p/>
65      * This state is entered when wpa_supplicant starts scanning for a
66      * network.
67      */
68     SCANNING,
69 
70     /**
71      * Trying to authenticate with a BSS/SSID
72      * <p/>
73      * This state is entered when wpa_supplicant has found a suitable BSS
74      * to authenticate with and the driver is configured to try to
75      * authenticate with this BSS.
76      */
77     AUTHENTICATING,
78 
79     /**
80      * Trying to associate with a BSS/SSID.
81      * <p/>
82      * This state is entered when wpa_supplicant has found a suitable BSS
83      * to associate with and the driver is configured to try to associate
84      * with this BSS in ap_scan=1 mode. When using ap_scan=2 mode, this
85      * state is entered when the driver is configured to try to associate
86      * with a network using the configured SSID and security policy.
87      */
88     ASSOCIATING,
89 
90     /**
91      * Association completed.
92      * <p/>
93      * This state is entered when the driver reports that association has
94      * been successfully completed with an AP. If IEEE 802.1X is used
95      * (with or without WPA/WPA2), wpa_supplicant remains in this state
96      * until the IEEE 802.1X/EAPOL authentication has been completed.
97      */
98     ASSOCIATED,
99 
100     /**
101      * WPA 4-Way Key Handshake in progress.
102      * <p/>
103      * This state is entered when WPA/WPA2 4-Way Handshake is started. In
104      * case of WPA-PSK, this happens when receiving the first EAPOL-Key
105      * frame after association. In case of WPA-EAP, this state is entered
106      * when the IEEE 802.1X/EAPOL authentication has been completed.
107      */
108     FOUR_WAY_HANDSHAKE,
109 
110     /**
111      * WPA Group Key Handshake in progress.
112      * <p/>
113      * This state is entered when 4-Way Key Handshake has been completed
114      * (i.e., when the supplicant sends out message 4/4) and when Group
115      * Key rekeying is started by the AP (i.e., when supplicant receives
116      * message 1/2).
117      */
118     GROUP_HANDSHAKE,
119 
120     /**
121      * All authentication completed.
122      * <p/>
123      * This state is entered when the full authentication process is
124      * completed. In case of WPA2, this happens when the 4-Way Handshake is
125      * successfully completed. With WPA, this state is entered after the
126      * Group Key Handshake; with IEEE 802.1X (non-WPA) connection is
127      * completed after dynamic keys are received (or if not used, after
128      * the EAP authentication has been completed). With static WEP keys and
129      * plaintext connections, this state is entered when an association
130      * has been completed.
131      * <p/>
132      * This state indicates that the supplicant has completed its
133      * processing for the association phase and that data connection is
134      * fully configured. Note, however, that there may not be any IP
135      * address associated with the connection yet. Typically, a DHCP
136      * request needs to be sent at this point to obtain an address.
137      */
138     COMPLETED,
139 
140     /**
141      * An Android-added state that is reported when a client issues an
142      * explicit DISCONNECT command. In such a case, the supplicant is
143      * not only dissociated from the current access point (as for the
144      * DISCONNECTED state above), but it also does not attempt to connect
145      * to any access point until a RECONNECT or REASSOCIATE command
146      * is issued by the client.
147      */
148     DORMANT,
149 
150     /**
151      * No connection to wpa_supplicant.
152      * <p/>
153      * This is an additional pseudo-state to handle the case where
154      * wpa_supplicant is not running and/or we have not been able
155      * to establish a connection to it.
156      */
157     UNINITIALIZED,
158 
159     /**
160      * A pseudo-state that should normally never be seen.
161      */
162     INVALID;
163 
164     /**
165      * Returns {@code true} if the supplicant state is valid and {@code false}
166      * otherwise.
167      * @param state The supplicant state
168      * @return {@code true} if the supplicant state is valid and {@code false}
169      * otherwise.
170      */
isValidState(SupplicantState state)171     public static boolean isValidState(SupplicantState state) {
172         return state != UNINITIALIZED && state != INVALID;
173     }
174 
175 
176     /** Supplicant associating or authenticating is considered a handshake state {@hide} */
isHandshakeState(SupplicantState state)177     public static boolean isHandshakeState(SupplicantState state) {
178         switch(state) {
179             case AUTHENTICATING:
180             case ASSOCIATING:
181             case ASSOCIATED:
182             case FOUR_WAY_HANDSHAKE:
183             case GROUP_HANDSHAKE:
184                 return true;
185             case COMPLETED:
186             case DISCONNECTED:
187             case INTERFACE_DISABLED:
188             case INACTIVE:
189             case SCANNING:
190             case DORMANT:
191             case UNINITIALIZED:
192             case INVALID:
193                 return false;
194             default:
195                 throw new IllegalArgumentException("Unknown supplicant state");
196         }
197     }
198 
199     /** @hide */
200     @Keep
isConnecting(SupplicantState state)201     public static boolean isConnecting(SupplicantState state) {
202         switch(state) {
203             case AUTHENTICATING:
204             case ASSOCIATING:
205             case ASSOCIATED:
206             case FOUR_WAY_HANDSHAKE:
207             case GROUP_HANDSHAKE:
208             case COMPLETED:
209                 return true;
210             case DISCONNECTED:
211             case INTERFACE_DISABLED:
212             case INACTIVE:
213             case SCANNING:
214             case DORMANT:
215             case UNINITIALIZED:
216             case INVALID:
217                 return false;
218             default:
219                 throw new IllegalArgumentException("Unknown supplicant state");
220         }
221     }
222 
223     /** @hide */
isDriverActive(SupplicantState state)224     public static boolean isDriverActive(SupplicantState state) {
225         switch(state) {
226             case DISCONNECTED:
227             case DORMANT:
228             case INACTIVE:
229             case AUTHENTICATING:
230             case ASSOCIATING:
231             case ASSOCIATED:
232             case SCANNING:
233             case FOUR_WAY_HANDSHAKE:
234             case GROUP_HANDSHAKE:
235             case COMPLETED:
236                 return true;
237             case INTERFACE_DISABLED:
238             case UNINITIALIZED:
239             case INVALID:
240                 return false;
241             default:
242                 throw new IllegalArgumentException("Unknown supplicant state");
243         }
244     }
245 
246     /** Implement the Parcelable interface {@hide} */
describeContents()247     public int describeContents() {
248         return 0;
249     }
250 
251     /** Implement the Parcelable interface {@hide} */
writeToParcel(Parcel dest, int flags)252     public void writeToParcel(Parcel dest, int flags) {
253         dest.writeString(name());
254     }
255 
256     /** Implement the Parcelable interface {@hide} */
257     public static final @android.annotation.NonNull Creator<SupplicantState> CREATOR =
258         new Creator<SupplicantState>() {
259             public SupplicantState createFromParcel(Parcel in) {
260                 return SupplicantState.valueOf(in.readString());
261             }
262 
263             public SupplicantState[] newArray(int size) {
264                 return new SupplicantState[size];
265             }
266         };
267 
268 }
269