blob: 15ec647eaa44717e4e5849892a58c08f01d3dcbe [file] [log] [blame]
San Mehat82a21162009-05-12 17:26:28 -07001/*
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#ifndef _WIFI_NETWORK_H
18#define _WIFI_NETWORK_H
19
20#include <sys/types.h>
21
San Mehat3c5a6f02009-05-22 15:36:13 -070022#include <utils/List.h>
San Mehat82a21162009-05-12 17:26:28 -070023
San Mehatc4a895b2009-06-23 21:10:57 -070024#include "Property.h"
25
26class PropertyManager;
27
San Mehat82a21162009-05-12 17:26:28 -070028class KeyManagementMask {
29public:
San Mehat21e90f02009-06-01 10:04:21 -070030 static const uint32_t UNKNOWN = 0;
31 static const uint32_t NONE = 0x01;
32 static const uint32_t WPA_PSK = 0x02;
33 static const uint32_t WPA_EAP = 0x04;
34 static const uint32_t IEEE8021X = 0x08;
San Mehat82a21162009-05-12 17:26:28 -070035 static const uint32_t ALL = WPA_PSK | WPA_EAP | IEEE8021X;
36};
37
38class SecurityProtocolMask {
39public:
40 static const uint32_t WPA = 0x01;
41 static const uint32_t RSN = 0x02;
42};
43
44class AuthenticationAlgorithmMask {
45public:
46 static const uint32_t OPEN = 0x01;
47 static const uint32_t SHARED = 0x02;
48 static const uint32_t LEAP = 0x04;
49};
50
San Mehat3c5a6f02009-05-22 15:36:13 -070051class PairwiseCiphersMask {
San Mehat82a21162009-05-12 17:26:28 -070052public:
53 static const uint32_t NONE = 0x00;
54 static const uint32_t TKIP = 0x01;
55 static const uint32_t CCMP = 0x02;
56};
57
San Mehat3c5a6f02009-05-22 15:36:13 -070058class GroupCiphersMask {
San Mehat82a21162009-05-12 17:26:28 -070059public:
60 static const uint32_t WEP40 = 0x01;
61 static const uint32_t WEP104 = 0x02;
62 static const uint32_t TKIP = 0x04;
63 static const uint32_t CCMP = 0x08;
64};
65
66class Supplicant;
San Mehat3c5a6f02009-05-22 15:36:13 -070067class Controller;
68class WifiController;
San Mehat82a21162009-05-12 17:26:28 -070069
San Mehatc4a895b2009-06-23 21:10:57 -070070class WifiNetwork {
71 class WifiNetworkIntegerProperty : public IntegerProperty {
72 protected:
73 WifiNetwork *mWn;
74 public:
75 WifiNetworkIntegerProperty(WifiNetwork *wn, const char *name, bool ro,
76 int elements);
77 virtual ~WifiNetworkIntegerProperty() {}
78 virtual int set(int idx, int value) = 0;
79 virtual int get(int idx, int *buffer) = 0;
80 };
81 friend class WifiNetwork::WifiNetworkIntegerProperty;
San Mehat3c5a6f02009-05-22 15:36:13 -070082
San Mehatc4a895b2009-06-23 21:10:57 -070083 class WifiNetworkStringProperty : public StringProperty {
84 protected:
85 WifiNetwork *mWn;
86 public:
87 WifiNetworkStringProperty(WifiNetwork *wn, const char *name, bool ro,
88 int elements);
89 virtual ~WifiNetworkStringProperty() {}
90 virtual int set(int idx, const char *value) = 0;
91 virtual int get(int idx, char *buffer, size_t max) = 0;
92 };
93 friend class WifiNetwork::WifiNetworkStringProperty;
94
95 class WifiNetworkEnabledProperty : public WifiNetworkIntegerProperty {
96 public:
97 WifiNetworkEnabledProperty(WifiNetwork *wn);
98 virtual ~WifiNetworkEnabledProperty() {};
99 int set(int idx, int value);
100 int get(int idx, int *buffer);
101 };
102
103 class WifiNetworkPriorityProperty : public WifiNetworkIntegerProperty {
104 public:
105 WifiNetworkPriorityProperty(WifiNetwork *wn);
106 virtual ~WifiNetworkPriorityProperty() {};
107 int set(int idx, int value);
108 int get(int idx, int *buffer);
109 };
110
111 class WifiNetworkDefaultKeyIndexProperty : public WifiNetworkIntegerProperty {
112 public:
113 WifiNetworkDefaultKeyIndexProperty(WifiNetwork *wn);
114 virtual ~WifiNetworkDefaultKeyIndexProperty() {};
115 int set(int idx, int value);
116 int get(int idx, int *buffer);
117 };
118
119 class WifiNetworkSsidProperty : public WifiNetworkStringProperty {
120 public:
121 WifiNetworkSsidProperty(WifiNetwork *wn);
122 virtual ~WifiNetworkSsidProperty() {};
123 int set(int idx, const char *value);
124 int get(int idx, char *buffer, size_t max);
125 };
126
127 class WifiNetworkBssidProperty : public WifiNetworkStringProperty {
128 public:
129 WifiNetworkBssidProperty(WifiNetwork *wn);
130 virtual ~WifiNetworkBssidProperty() {};
131 int set(int idx, const char *value);
132 int get(int idx, char *buffer, size_t max);
133 };
134
135 class WifiNetworkPskProperty : public WifiNetworkStringProperty {
136 public:
137 WifiNetworkPskProperty(WifiNetwork *wn);
138 virtual ~WifiNetworkPskProperty() {};
139 int set(int idx, const char *value);
140 int get(int idx, char *buffer, size_t max);
141 };
142
143 class WifiNetworkKeyManagementProperty : public WifiNetworkStringProperty {
144 public:
145 WifiNetworkKeyManagementProperty(WifiNetwork *wn);
146 virtual ~WifiNetworkKeyManagementProperty() {};
147 int set(int idx, const char *value);
148 int get(int idx, char *buffer, size_t max);
149 };
150
151 class WifiNetworkAuthAlgorithmsProperty : public WifiNetworkStringProperty {
152 public:
153 WifiNetworkAuthAlgorithmsProperty(WifiNetwork *wn);
154 virtual ~WifiNetworkAuthAlgorithmsProperty() {};
155 int set(int idx, const char *value);
156 int get(int idx, char *buffer, size_t max);
157 };
158
159 class WifiNetworkProtocolsProperty : public WifiNetworkStringProperty {
160 public:
161 WifiNetworkProtocolsProperty(WifiNetwork *wn);
162 virtual ~WifiNetworkProtocolsProperty() {};
163 int set(int idx, const char *value);
164 int get(int idx, char *buffer, size_t max);
165 };
166
167 class WifiNetworkWepKeyProperty : public WifiNetworkStringProperty {
168 public:
169 WifiNetworkWepKeyProperty(WifiNetwork *wn);
170 virtual ~WifiNetworkWepKeyProperty() {};
171 int set(int idx, const char *value);
172 int get(int idx, char *buffer, size_t max);
173 };
174
175 class WifiNetworkPairwiseCiphersProperty : public WifiNetworkStringProperty {
176 public:
177 WifiNetworkPairwiseCiphersProperty(WifiNetwork *wn);
178 virtual ~WifiNetworkPairwiseCiphersProperty() {};
179 int set(int idx, const char *value);
180 int get(int idx, char *buffer, size_t max);
181 };
182
183 class WifiNetworkGroupCiphersProperty : public WifiNetworkStringProperty {
184 public:
185 WifiNetworkGroupCiphersProperty(WifiNetwork *wn);
186 virtual ~WifiNetworkGroupCiphersProperty() {};
187 int set(int idx, const char *value);
188 int get(int idx, char *buffer, size_t max);
189 };
190
191 class WifiNetworkHiddenSsidProperty : public WifiNetworkStringProperty {
192 public:
193 WifiNetworkHiddenSsidProperty(WifiNetwork *wn);
194 virtual ~WifiNetworkHiddenSsidProperty() {};
195 int set(int idx, const char *value);
196 int get(int idx, char *buffer, size_t max);
197 };
San Mehat3c5a6f02009-05-22 15:36:13 -0700198
199private:
San Mehat82a21162009-05-12 17:26:28 -0700200 Supplicant *mSuppl;
San Mehat3c5a6f02009-05-22 15:36:13 -0700201 WifiController *mController;
San Mehat82a21162009-05-12 17:26:28 -0700202
203 /*
204 * Unique network id - normally provided by supplicant
205 */
206 int mNetid;
207
208 /*
209 * The networks' SSID. Can either be an ASCII string,
210 * which must be enclosed in double quotation marks
211 * (ie: "MyNetwork"), or a string of hex digits which
212 * are not enclosed in quotes (ie: 01ab7893)
213 */
214 char *mSsid;
215
216 /*
217 * When set, this entry should only be used
218 * when associating with the AP having the specified
219 * BSSID. The value is a string in the format of an
220 * Ethernet MAC address
221 */
222 char *mBssid;
223
224 /*
225 * Pre-shared key for use with WPA-PSK
226 */
227 char *mPsk;
228
229 /*
230 * Up to four WEP keys. Either in ASCII string enclosed in
231 * double quotes, or a string of hex digits
232 */
233 char *mWepKeys[4];
234
235 /*
236 * Default WEP key index, ranging from 0 -> NUM_WEP_KEYS -1
237 */
238 int mDefaultKeyIndex;
239
240 /*
241 * Priority determines the preference given to a network by
242 * supplicant when choosing an access point with which
243 * to associate
244 */
245 int mPriority;
246
247 /*
248 * This is a network that does not broadcast it's SSID, so an
249 * SSID-specific probe request must be used for scans.
250 */
251 char *mHiddenSsid;
252
253 /*
254 * The set of key management protocols supported by this configuration.
255 */
San Mehatc4a895b2009-06-23 21:10:57 -0700256 uint32_t mKeyManagement;
San Mehat82a21162009-05-12 17:26:28 -0700257
258 /*
259 * The set of security protocols supported by this configuration.
260 */
San Mehatc4a895b2009-06-23 21:10:57 -0700261 uint32_t mProtocols;
San Mehat82a21162009-05-12 17:26:28 -0700262
263 /*
264 * The set of authentication protocols supported by this configuration.
265 */
San Mehatc4a895b2009-06-23 21:10:57 -0700266 uint32_t mAuthAlgorithms;
San Mehat82a21162009-05-12 17:26:28 -0700267
268 /*
269 * The set of pairwise ciphers for WPA supported by this configuration.
270 */
San Mehatc4a895b2009-06-23 21:10:57 -0700271 uint32_t mPairwiseCiphers;
San Mehat82a21162009-05-12 17:26:28 -0700272
273 /*
274 * The set of group ciphers for WPA supported by this configuration.
275 */
San Mehatc4a895b2009-06-23 21:10:57 -0700276 uint32_t mGroupCiphers;
San Mehat82a21162009-05-12 17:26:28 -0700277
San Mehat3c5a6f02009-05-22 15:36:13 -0700278 /*
279 * Set if this Network is enabled
280 */
281 bool mEnabled;
282
San Mehatc4a895b2009-06-23 21:10:57 -0700283 char *mPropNamespace;
284 struct {
285 WifiNetworkEnabledProperty *propEnabled;
286 WifiNetworkSsidProperty *propSsid;
287 WifiNetworkBssidProperty *propBssid;
288 WifiNetworkPskProperty *propPsk;
289 WifiNetworkWepKeyProperty *propWepKey;
290 WifiNetworkDefaultKeyIndexProperty *propDefKeyIdx;
291 WifiNetworkPriorityProperty *propPriority;
292 WifiNetworkKeyManagementProperty *propKeyManagement;
293 WifiNetworkProtocolsProperty *propProtocols;
294 WifiNetworkAuthAlgorithmsProperty *propAuthAlgorithms;
295 WifiNetworkPairwiseCiphersProperty *propPairwiseCiphers;
296 WifiNetworkGroupCiphersProperty *propGroupCiphers;
297 WifiNetworkHiddenSsidProperty *propHiddenSsid;
298 } mStaticProperties;
San Mehat3c5a6f02009-05-22 15:36:13 -0700299private:
300 WifiNetwork();
San Mehat3c5a6f02009-05-22 15:36:13 -0700301
San Mehat82a21162009-05-12 17:26:28 -0700302public:
San Mehat3c5a6f02009-05-22 15:36:13 -0700303 WifiNetwork(WifiController *c, Supplicant *suppl, int networkId);
304 WifiNetwork(WifiController *c, Supplicant *suppl, const char *data);
305
San Mehat82a21162009-05-12 17:26:28 -0700306 virtual ~WifiNetwork();
307
San Mehat3c5a6f02009-05-22 15:36:13 -0700308 WifiNetwork *clone();
San Mehatc4a895b2009-06-23 21:10:57 -0700309 int attachProperties(PropertyManager *pm, const char *nsName);
310 int detachProperties(PropertyManager *pm, const char *nsName);
San Mehat3c5a6f02009-05-22 15:36:13 -0700311
San Mehat82a21162009-05-12 17:26:28 -0700312 int getNetworkId() { return mNetid; }
313 const char *getSsid() { return mSsid; }
314 const char *getBssid() { return mBssid; }
315 const char *getPsk() { return mPsk; }
316 const char *getWepKey(int idx) { return mWepKeys[idx]; }
317 int getDefaultKeyIndex() { return mDefaultKeyIndex; }
318 int getPriority() { return mPriority; }
319 const char *getHiddenSsid() { return mHiddenSsid; }
San Mehatc4a895b2009-06-23 21:10:57 -0700320 uint32_t getKeyManagement() { return mKeyManagement; }
321 uint32_t getProtocols() { return mProtocols; }
322 uint32_t getAuthAlgorithms() { return mAuthAlgorithms; }
323 uint32_t getPairwiseCiphers() { return mPairwiseCiphers; }
324 uint32_t getGroupCiphers() { return mGroupCiphers; }
San Mehat3c5a6f02009-05-22 15:36:13 -0700325 bool getEnabled() { return mEnabled; }
326 Controller *getController() { return (Controller *) mController; }
San Mehat82a21162009-05-12 17:26:28 -0700327
San Mehat3c5a6f02009-05-22 15:36:13 -0700328 int setEnabled(bool enabled);
329 int setSsid(const char *ssid);
330 int setBssid(const char *bssid);
331 int setPsk(const char *psk);
332 int setWepKey(int idx, const char *key);
San Mehat82a21162009-05-12 17:26:28 -0700333 int setDefaultKeyIndex(int idx);
334 int setPriority(int pri);
San Mehat3c5a6f02009-05-22 15:36:13 -0700335 int setHiddenSsid(const char *ssid);
San Mehatc4a895b2009-06-23 21:10:57 -0700336 int setKeyManagement(uint32_t mask);
337 int setProtocols(uint32_t mask);
338 int setAuthAlgorithms(uint32_t mask);
339 int setPairwiseCiphers(uint32_t mask);
340 int setGroupCiphers(uint32_t mask);
San Mehat3c5a6f02009-05-22 15:36:13 -0700341
342 // XXX:Should this really be exposed?.. meh
343 int refresh();
San Mehatc4a895b2009-06-23 21:10:57 -0700344
345private:
346 int parseKeyManagementMask(const char *buffer, uint32_t *mask);
347 int parseProtocolsMask(const char *buffer, uint32_t *mask);
348 int parseAuthAlgorithmsMask(const char *buffer, uint32_t *mask);
349 int parsePairwiseCiphersMask(const char *buffer, uint32_t *mask);
350 int parseGroupCiphersMask(const char *buffer, uint32_t *mask);
351 void createProperties();
San Mehat82a21162009-05-12 17:26:28 -0700352};
353
354typedef android::List<WifiNetwork *> WifiNetworkCollection;
355
356#endif