blob: 6945e3ea215361988bf34ca9e57fffb88e0d00e9 [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#include <stdlib.h>
18#include <fcntl.h>
19#include <errno.h>
20#include <string.h>
21
22#include <cutils/properties.h>
23#define LOG_TAG "TiwlanWifiController"
24#include <cutils/log.h>
25
San Mehat3c5a6f02009-05-22 15:36:13 -070026#include "PropertyManager.h"
San Mehatdc266072009-05-06 11:16:52 -070027#include "TiwlanWifiController.h"
28
29#define DRIVER_PROP_NAME "wlan.driver.status"
30
31extern "C" int sched_yield(void);
32
San Mehat3aff2d12009-06-15 14:10:44 -070033TiwlanWifiController::TiwlanWifiController(PropertyManager *propmngr,
34 IControllerHandler *handlers,
35 char *modpath, char *modname,
36 char *modargs) :
37 WifiController(propmngr, handlers, modpath, modname,
38 modargs) {
San Mehatdc266072009-05-06 11:16:52 -070039}
40
41int TiwlanWifiController::powerUp() {
42 return 0; // Powerup is currently done when the driver is loaded
43}
44
45int TiwlanWifiController::powerDown() {
46 return 0; // Powerdown is currently done when the driver is unloaded
47}
48
49bool TiwlanWifiController::isPoweredUp() {
50 return isKernelModuleLoaded(getModuleName());
51}
52
53int TiwlanWifiController::loadFirmware() {
54 char driver_status[PROPERTY_VALUE_MAX];
55 int count = 100;
56
San Mehatdc266072009-05-06 11:16:52 -070057 property_set("ctl.start", "wlan_loader");
58 sched_yield();
59
60 // Wait for driver to be ready
61 while (count-- > 0) {
62 if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
63 if (strcmp(driver_status, "ok") == 0)
64 return 0;
65 else if (strcmp(DRIVER_PROP_NAME, "failed") == 0)
66 return -1;
67 }
68 usleep(200000);
69 }
70 property_set(DRIVER_PROP_NAME, "timeout");
71 return -1;
72}
San Mehat1441e762009-05-07 11:37:10 -070073
74bool TiwlanWifiController::isFirmwareLoaded() {
San Mehat69772dc2009-05-10 09:27:07 -070075 // Always load the firmware
San Mehat1441e762009-05-07 11:37:10 -070076 return false;
77}