blob: 8a7e33f9eaa4efb4d183b1c0e60a39ae07f49a50 [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 */
16#include <string.h>
17#include <errno.h>
18
19#define LOG_TAG "WifiController"
20#include <cutils/log.h>
21
22#include "Supplicant.h"
23#include "WifiController.h"
24
25WifiController::WifiController(char *modpath, char *modname, char *modargs) :
26 Controller("WIFI") {
27 strncpy(mModulePath, modpath, sizeof(mModulePath));
28 strncpy(mModuleName, modname, sizeof(mModuleName));
29 strncpy(mModuleArgs, modargs, sizeof(mModuleArgs));
30
31 mSupplicant = new Supplicant();
32 mCurrentScanMode = 0;
33}
34
35int WifiController::start() {
36 return 0;
37}
38
39int WifiController::stop() {
40 errno = ENOSYS;
41 return -1;
42}
43
44int WifiController::enable() {
45 if (!isPoweredUp() && powerUp()) {
46 LOGE("Powerup failed (%s)", strerror(errno));
47 return -1;
48 }
49
50 if (mModuleName[0] != '\0' && !isKernelModuleLoaded(mModuleName)) {
51 if (loadKernelModule(mModulePath, mModuleArgs)) {
52 LOGE("Kernel module load failed (%s)", strerror(errno));
53 goto out_powerdown;
54 }
55 }
56
57 if (loadFirmware()) {
58 LOGE("Firmware load failed (%s)", strerror(errno));
59 goto out_powerdown;
60 }
61
62 if (!mSupplicant->isStarted() && mSupplicant->start()) {
63 LOGE("Supplicant start failed (%s)", strerror(errno));
64 goto out_unloadmodule;
65 }
66
67 return 0;
68
69out_unloadmodule:
70 if (mModuleName[0] != '\0' && !isKernelModuleLoaded(mModuleName)) {
71 if (unloadKernelModule(mModuleName)) {
72 LOGE("Unable to unload module after failure!");
73 }
74 }
75
76out_powerdown:
77 if (powerDown()) {
78 LOGE("Unable to powerdown after failure!");
79 }
80 return -1;
81}
82
83int WifiController::disable() {
84 LOGD("disable()");
85
86 if (mSupplicant->isStarted() && mSupplicant->stop()) {
87 LOGE("Supplicant stop failed (%s)", strerror(errno));
88 return -1;
89 }
90
91 if (mModuleName[0] != '\0' && isKernelModuleLoaded(mModuleName)) {
92 if (unloadKernelModule(mModuleName)) {
93 LOGE("Unable to unload module (%s)", strerror(errno));
94 return -1;
95 }
96 }
97
98 if (isPoweredUp() && powerDown()) {
99 LOGE("Powerdown failed (%s)", strerror(errno));
100 return -1;
101 }
102 return 0;
103}
104
105int WifiController::loadFirmware() {
106 return 0;
107}
108
109int WifiController::setScanMode(int mode) {
110 int rc = 0;
111
112 if (mCurrentScanMode == mode)
113 return 0;
114
115 if (!(mode & SCAN_ENABLE_MASK)) {
116 if (mCurrentScanMode & SCAN_REPEAT_MASK)
117 stopPeriodicScan();
118 } else if (mode & SCAN_REPEAT_MASK)
119 rc = startPeriodicScan();
120 else
121 rc = mSupplicant->triggerScan(mode & SCAN_ACTIVE_MASK);
122
123 return rc;
124}
125
126int WifiController::startPeriodicScan() {
127 errno = -ENOSYS;
128 return -1;
129}
130
131int WifiController::stopPeriodicScan() {
132 errno = -ENOSYS;
133 return -1;
134}