blob: c61d97a5a0d40a4e37e652e740ff61573240bcfa [file] [log] [blame]
San Mehatdc266072009-05-06 11:16:52 -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 */
San Mehat3c5a6f02009-05-22 15:36:13 -070016
San Mehatdc266072009-05-06 11:16:52 -070017#ifndef _WIFI_CONTROLLER_H
18#define _WIFI_CONTROLLER_H
19
20#include <sys/types.h>
21
22#include "Controller.h"
San Mehat3aff2d12009-06-15 14:10:44 -070023#include "ScanResult.h"
24#include "WifiNetwork.h"
25#include "ISupplicantEventHandler.h"
San Mehatdc266072009-05-06 11:16:52 -070026
27class NetInterface;
28class Supplicant;
San Mehat1441e762009-05-07 11:37:10 -070029class WifiScanner;
San Mehat3aff2d12009-06-15 14:10:44 -070030class SupplicantAssociatingEvent;
31class SupplicantAssociatedEvent;
32class SupplicantConnectedEvent;
33class SupplicantScanResultsEvent;
34class SupplicantStateChangeEvent;
35class SupplicantDisconnectedEvent;
San Mehat1441e762009-05-07 11:37:10 -070036
San Mehat3aff2d12009-06-15 14:10:44 -070037class WifiController : public Controller, public ISupplicantEventHandler {
San Mehatdc266072009-05-06 11:16:52 -070038public:
39 static const uint32_t SCAN_ENABLE_MASK = 0x01;
40 static const uint32_t SCAN_ACTIVE_MASK = 0x02;
41 static const uint32_t SCAN_REPEAT_MASK = 0x04;
42
43 static const uint32_t SCANMODE_NONE = 0;
44 static const uint32_t SCANMODE_PASSIVE_ONESHOT = SCAN_ENABLE_MASK;
45 static const uint32_t SCANMODE_PASSIVE_CONTINUOUS = SCAN_ENABLE_MASK | SCAN_REPEAT_MASK;
46 static const uint32_t SCANMODE_ACTIVE_ONESHOT = SCAN_ENABLE_MASK | SCAN_ACTIVE_MASK;
47 static const uint32_t SCANMODE_ACTIVE_CONTINUOUS = SCAN_ENABLE_MASK | SCAN_ACTIVE_MASK | SCAN_REPEAT_MASK;
48
49private:
50 Supplicant *mSupplicant;
51 char mModulePath[255];
52 char mModuleName[64];
53 char mModuleArgs[255];
San Mehat3aff2d12009-06-15 14:10:44 -070054
San Mehat1441e762009-05-07 11:37:10 -070055 uint32_t mCurrentScanMode;
56 WifiScanner *mScanner;
San Mehat3aff2d12009-06-15 14:10:44 -070057 int mSupplicantState;
58
59 ScanResultCollection *mLatestScanResults;
60 pthread_mutex_t mLatestScanResultsLock;
61
San Mehat3c5a6f02009-05-22 15:36:13 -070062 bool mEnabled;
San Mehatdc266072009-05-06 11:16:52 -070063
64public:
San Mehat3aff2d12009-06-15 14:10:44 -070065 WifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs);
San Mehatdc266072009-05-06 11:16:52 -070066 virtual ~WifiController() {}
67
68 int start();
69 int stop();
70
San Mehat3c5a6f02009-05-22 15:36:13 -070071 WifiNetwork *createNetwork();
San Mehat82a21162009-05-12 17:26:28 -070072 int removeNetwork(int networkId);
73 WifiNetworkCollection *createNetworkList();
San Mehat1441e762009-05-07 11:37:10 -070074
San Mehat3c5a6f02009-05-22 15:36:13 -070075 virtual int set(const char *name, const char *value);
76 virtual const char *get(const char *name, char *buffer, size_t maxlen);
San Mehat48765672009-05-20 15:28:43 -070077
San Mehat82a21162009-05-12 17:26:28 -070078 ScanResultCollection *createScanResults();
San Mehatdc266072009-05-06 11:16:52 -070079
80 char *getModulePath() { return mModulePath; }
81 char *getModuleName() { return mModuleName; }
82 char *getModuleArgs() { return mModuleArgs; }
83
84 Supplicant *getSupplicant() { return mSupplicant; }
85
San Mehatdc266072009-05-06 11:16:52 -070086protected:
San Mehat3c5a6f02009-05-22 15:36:13 -070087 // Move this crap into a 'driver'
San Mehatdc266072009-05-06 11:16:52 -070088 virtual int powerUp() = 0;
89 virtual int powerDown() = 0;
90 virtual int loadFirmware();
San Mehat1441e762009-05-07 11:37:10 -070091
92 virtual bool isFirmwareLoaded() = 0;
San Mehatdc266072009-05-06 11:16:52 -070093 virtual bool isPoweredUp() = 0;
94
San Mehat48765672009-05-20 15:28:43 -070095private:
San Mehat3c5a6f02009-05-22 15:36:13 -070096 void sendStatusBroadcast(const char *msg);
San Mehat48765672009-05-20 15:28:43 -070097 int setScanMode(uint32_t mode);
98 int enable();
99 int disable();
San Mehat3aff2d12009-06-15 14:10:44 -0700100
101 // ISupplicantEventHandler methods
102 virtual void onAssociatingEvent(SupplicantAssociatingEvent *evt);
103 virtual void onAssociatedEvent(SupplicantAssociatedEvent *evt);
104 virtual void onConnectedEvent(SupplicantConnectedEvent *evt);
105 virtual void onScanResultsEvent(SupplicantScanResultsEvent *evt);
106 virtual void onStateChangeEvent(SupplicantStateChangeEvent *evt);
107 virtual void onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent *evt);
108 virtual void onDisconnectedEvent(SupplicantDisconnectedEvent *evt);
109#if 0
110 virtual void onTerminatingEvent(SupplicantEvent *evt);
111 virtual void onPasswordChangedEvent(SupplicantEvent *evt);
112 virtual void onEapNotificationEvent(SupplicantEvent *evt);
113 virtual void onEapStartedEvent(SupplicantEvent *evt);
114 virtual void onEapMethodEvent(SupplicantEvent *evt);
115 virtual void onEapSuccessEvent(SupplicantEvent *evt);
116 virtual void onEapFailureEvent(SupplicantEvent *evt);
117 virtual void onLinkSpeedEvent(SupplicantEvent *evt);
118 virtual void onDriverStateEvent(SupplicantEvent *evt);
119#endif
120
San Mehatdc266072009-05-06 11:16:52 -0700121};
122
123#endif