blob: 307c48c0dab3d7b99f8bfc0d371a2acb9163c796 [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 Mehat3c5a6f02009-05-22 15:36:13 -070033TiwlanWifiController::TiwlanWifiController(PropertyManager *propmngr, char *modpath, char *modname, char *modargs) :
34 WifiController(propmngr, modpath, modname, modargs) {
San Mehatdc266072009-05-06 11:16:52 -070035}
36
37int TiwlanWifiController::powerUp() {
38 return 0; // Powerup is currently done when the driver is loaded
39}
40
41int TiwlanWifiController::powerDown() {
42 return 0; // Powerdown is currently done when the driver is unloaded
43}
44
45bool TiwlanWifiController::isPoweredUp() {
46 return isKernelModuleLoaded(getModuleName());
47}
48
49int TiwlanWifiController::loadFirmware() {
50 char driver_status[PROPERTY_VALUE_MAX];
51 int count = 100;
52
San Mehatdc266072009-05-06 11:16:52 -070053 property_set("ctl.start", "wlan_loader");
54 sched_yield();
55
56 // Wait for driver to be ready
57 while (count-- > 0) {
58 if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
59 if (strcmp(driver_status, "ok") == 0)
60 return 0;
61 else if (strcmp(DRIVER_PROP_NAME, "failed") == 0)
62 return -1;
63 }
64 usleep(200000);
65 }
66 property_set(DRIVER_PROP_NAME, "timeout");
67 return -1;
68}
San Mehat1441e762009-05-07 11:37:10 -070069
70bool TiwlanWifiController::isFirmwareLoaded() {
San Mehat69772dc2009-05-10 09:27:07 -070071 // Always load the firmware
San Mehat1441e762009-05-07 11:37:10 -070072 return false;
73}