WifiController.h revision 4876567cb9c6a69ce21fd2b1c5bcce5a6f274276
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#ifndef _WIFI_CONTROLLER_H
17#define _WIFI_CONTROLLER_H
18
19#include <sys/types.h>
20
21#include "Controller.h"
22
23class NetInterface;
24class Supplicant;
25class WifiScanner;
26
27#include "ScanResult.h"
28#include "WifiNetwork.h"
29
30class WifiController : public Controller {
31public:
32    static const uint32_t SCAN_ENABLE_MASK       = 0x01;
33    static const uint32_t SCAN_ACTIVE_MASK       = 0x02;
34    static const uint32_t SCAN_REPEAT_MASK       = 0x04;
35
36    static const uint32_t SCANMODE_NONE               = 0;
37    static const uint32_t SCANMODE_PASSIVE_ONESHOT    = SCAN_ENABLE_MASK;
38    static const uint32_t SCANMODE_PASSIVE_CONTINUOUS = SCAN_ENABLE_MASK | SCAN_REPEAT_MASK;
39    static const uint32_t SCANMODE_ACTIVE_ONESHOT     = SCAN_ENABLE_MASK | SCAN_ACTIVE_MASK;
40    static const uint32_t SCANMODE_ACTIVE_CONTINUOUS  = SCAN_ENABLE_MASK | SCAN_ACTIVE_MASK | SCAN_REPEAT_MASK;
41
42private:
43    Supplicant *mSupplicant;
44    char        mModulePath[255];
45    char        mModuleName[64];
46    char        mModuleArgs[255];
47    uint32_t    mCurrentScanMode;
48    WifiScanner *mScanner;
49
50public:
51    WifiController(char *modpath, char *modname, char *modargs);
52    virtual ~WifiController() {}
53
54    int start();
55    int stop();
56
57    int addNetwork();
58    int removeNetwork(int networkId);
59    WifiNetworkCollection *createNetworkList();
60
61    virtual int setProperty(const char *name, char *value);
62    virtual const char *getProperty(const char *name, char *buffer,
63                                    size_t maxlen);
64
65    ScanResultCollection *createScanResults();
66
67    char *getModulePath() { return mModulePath; }
68    char *getModuleName() { return mModuleName; }
69    char *getModuleArgs() { return mModuleArgs; }
70
71    Supplicant *getSupplicant() { return mSupplicant; }
72
73protected:
74    virtual int powerUp() = 0;
75    virtual int powerDown() = 0;
76    virtual int loadFirmware();
77
78    virtual bool isFirmwareLoaded() = 0;
79    virtual bool isPoweredUp() = 0;
80
81    void sendStatusBroadcast(const char *msg);
82
83private:
84    int setScanMode(uint32_t mode);
85    int enable();
86    int disable();
87
88};
89
90#endif
91