Commit 687e4c40 authored by Mark Stevens's avatar Mark Stevens
Browse files

update to duco/rk 3128-6003-6.0

parent b7615bd4
......@@ -20,6 +20,44 @@
#if __cplusplus
extern "C" {
#endif
enum WIFI_CHIP_TYPE_LIST{
RTL8188CU = 0,
RTL8192CU,
RTL8188EU,
BCM4330,
RK901,
RK903,
AP6335,
AP6234,
AP6441,
MT7601,
RTL8723AS,
RTL8723AU,
RTL8723BS,
RTL8723BU,
RTL8192DU,
MT6620,
ESP8089,
NUM_MAX,
};
enum {
KERNEL_VERSION_3_0_8 = 1,
KERNEL_VERSION_3_0_36,
KERNEL_VERSION_3_10,
};
int check_wifi_chip_type(void);
int check_wifi_preload(void);
int check_wifi_chip_type_string(char *type);
int rk_wifi_power_ctrl(int on);
int rk_wifi_load_driver(int enable);
int check_wireless_ready(void);
int get_kernel_version(void);
/**
* Load the Wi-Fi driver.
......
......@@ -35,7 +35,14 @@ ifdef WIFI_DRIVER_STATE_OFF
LOCAL_CFLAGS += -DWIFI_DRIVER_STATE_OFF=\"$(WIFI_DRIVER_STATE_OFF)\"
endif
LOCAL_SRC_FILES += wifi/wifi.c
LOCAL_SRC_FILES += wifi/rk_wifi_ctrl.c
ifeq ($(strip $(BOARD_CONNECTIVITY_VENDOR)), RealTek)
LOCAL_SRC_FILES += ../realtek/wlan/libhardware_legacy/wifi/wifi_realtek.c
else
LOCAL_SRC_FILES += wifi/wifi.c
endif
ifdef WPA_SUPPLICANT_VERSION
LOCAL_CFLAGS += -DLIBWPA_CLIENT_EXISTS
......
/*
* Copyright 2008, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <sys/socket.h>
#include <unistd.h>
#include <poll.h>
#include "hardware_legacy/wifi.h"
#include "libwpa_client/wpa_ctrl.h"
#define LOG_TAG "WifiHW"
#include "cutils/log.h"
#include "cutils/memory.h"
#include "cutils/misc.h"
#include "cutils/properties.h"
#include "private/android_filesystem_config.h"
#ifdef HAVE_LIBC_SYSTEM_PROPERTIES
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
#endif
#define WIFI_CHIP_TYPE_PATH "/sys/class/rkwifi/chip"
#define WIFI_POWER_INF "/sys/class/rkwifi/power"
#define WIFI_DRIVER_INF "/sys/class/rkwifi/driver"
#define WIFI_PRELOAD_INF "/sys/class/rkwifi/preload"
int check_wifi_chip_type(void);
int check_wifi_chip_type_string(char *type);
int rk_wifi_power_ctrl(int on);
int rk_wifi_load_driver(int enable);
int check_wireless_ready(void);
int get_kernel_version(void);
int check_wifi_preload(void)
{
int wififd, ret = 0;
wififd = open(WIFI_PRELOAD_INF, O_RDONLY);
if( wififd < 0 ) {
ALOGD("%s: Wifi driver is not preload when bootup, load when open wifi.\n", __func__);
return 0;
}
close(wififd);
ALOGD("%s: Wifi driver is preload when bootup.\n", __func__);
return 1;
}
int check_wifi_chip_type_string(char *type)
{
int wififd, ret = 0;
char buf[64];
int wifi_chip_type = RTL8188EU;
wififd = open(WIFI_CHIP_TYPE_PATH, O_RDONLY);
if( wififd < 0 ){
ALOGD("Can't open %s, errno = %d", WIFI_CHIP_TYPE_PATH, errno);
ret = -1;
goto fail_exit;
}
memset(buf, 0, 64);
if( 0 == read(wififd, buf, 32) ){
ALOGD("read %s failed", WIFI_CHIP_TYPE_PATH);
close(wififd);
ret = -1;
goto fail_exit;
}
close(wififd);
strcpy(type, buf);
ALOGD("%s: %s", __func__, type);
fail_exit:
return ret;
}
int check_wifi_chip_type(void)
{
int wififd;
char buf[64];
int wifi_chip_type = RTL8188EU;
wififd = open(WIFI_CHIP_TYPE_PATH, O_RDONLY);
if( wififd < 0 ){
ALOGD("Can't open %s, errno = %d", WIFI_CHIP_TYPE_PATH, errno);
goto done;
}
memset(buf, 0, 64);
if( 0 == read(wififd, buf, 10) ){
ALOGD("read %s failed", WIFI_CHIP_TYPE_PATH);
close(wififd);
goto done;
}
close(wififd);
if(0 == strncmp(buf, "RTL8188CU", strlen("RTL8188CU")) )
{
wifi_chip_type = RTL8188CU;
ALOGD("Read wifi chip type OK ! wifi_chip_type = RTL8188CU");
}
if(0 == strncmp(buf, "RTL8188EU", strlen("RTL8188EU")) )
{
wifi_chip_type = RTL8188EU;
ALOGD("Read wifi chip type OK ! wifi_chip_type = RTL8188EU");
}
else if (0 == strncmp(buf, "BCM4330", strlen("BCM4330")) )
{
wifi_chip_type = BCM4330;
ALOGD("Read wifi chip type OK ! wifi_chip_type = BCM4330");
}
else if (0 == strncmp(buf, "RK901", strlen("RK901")) )
{
wifi_chip_type = RK901;
ALOGD("Read wifi chip type OK ! wifi_chip_type = RK901");
}
else if (0 == strncmp(buf, "RK903", strlen("RK903")) )
{
wifi_chip_type = RK903;
ALOGD("Read wifi chip type OK ! wifi_chip_type = RK903");
}
else if (0 == strncmp(buf,"ESP8089",strlen("ESP8089")))
{
wifi_chip_type = ESP8089;
ALOGD("Read wifi chip type OK ! wifi_chip_type = ESP8089");
}
done:
return wifi_chip_type;
}
int rk_wifi_power_ctrl(int on)
{
int sz, fd = -1;
int ret = -1;
char buffer = '0';
ALOGE("rk_wifi_power_ctrl:(%d)", on);
switch(on)
{
case 0:
buffer = '0';
break;
case 1:
buffer = '1';
break;
}
fd = open(WIFI_POWER_INF, O_WRONLY);
if (fd < 0)
{
ALOGE("rk_wifi_power_ctrl: open(%s) for write failed: %s (%d)",
WIFI_POWER_INF, strerror(errno), errno);
return ret;
}
sz = write(fd, &buffer, 1);
if (sz < 0) {
ALOGE("rk_wifi_power_ctrl: write(%s) failed: %s (%d)",
&buffer, strerror(errno),errno);
}
else {
ret = 0;
usleep(1000*1000);
}
if (fd >= 0)
close(fd);
return ret;
}
/* enable = 0 or 1 */
/* 0 - rmmod driver; 1 - insmod driver. */
int rk_wifi_load_driver(int enable)
{
int sz, fd = -1;
int ret = -1;
char buffer = '0';
ALOGE("rk_wifi_load_driver:(%s)", enable? "insmod":"rmmod");
switch(enable)
{
case 0:
buffer = '0';
break;
case 1:
buffer = '1';
break;
}
fd = open(WIFI_DRIVER_INF, O_WRONLY);
if (fd < 0)
{
ALOGE("rk_wifi_load_driver: open(%s) for write failed: %s (%d)",
WIFI_DRIVER_INF, strerror(errno), errno);
return ret;
}
sz = write(fd, &buffer, 1);
if (sz < 0) {
ALOGE("rk_wifi_load_driver: write(%s) failed: %s (%d)",
&buffer, strerror(errno),errno);
}
else {
ret = 0;
usleep(1000*1000);
}
if (fd >= 0)
close(fd);
return ret;
}
/* 0 - not ready; 1 - ready. */
int check_wireless_ready(void)
{
char line[1024], *ptr = NULL;
FILE *fp = NULL;
fp = fopen("/proc/net/wireless", "r");
if (fp == NULL) {
ALOGE("Couldn't open /proc/net/wireless\n");
return 0;
}
while(fgets(line, 1024, fp)) {
if ((strstr(line, "wlan0:") != NULL) || (strstr(line, "p2p0:") != NULL)) {
ALOGD("Wifi driver is ready for now...");
fclose(fp);
return 1;
}
}
fclose(fp);
ALOGE("Wifi driver is not ready.\n");
return 0;
}
int get_kernel_version(void)
{
int fd, version = 0;
char buf[64];
fd = open("/proc/version", O_RDONLY);
if (fd < 0) {
ALOGD("Can't open '/proc/version', errno = %d", errno);
goto fderror;
}
memset(buf, 0, 64);
if( 0 == read(fd, buf, 64) ){
ALOGD("read '/proc/version' failed");
close(fd);
goto fderror;
}
close(fd);
if (strstr(buf, "Linux version 3.10") != NULL) {
version = KERNEL_VERSION_3_10;
ALOGD("Kernel version is 3.10.");
} else {
version = KERNEL_VERSION_3_0_36;
ALOGD("Kernel version is 3.0.36.");
}
return version;
fderror:
return -1;
}
......@@ -99,6 +99,13 @@ static char primary_iface[PROPERTY_VALUE_MAX];
#define WIFI_DRIVER_LOADER_DELAY 1000000
static const char IFACE_DIR[] = "/data/system/wpa_supplicant";
#ifndef WIFI_DRIVER_MODULE_PATH
#define WIFI_DRIVER_MODULE_PATH "/system/lib/modules/none"
#endif
#ifndef WIFI_DRIVER_MODULE_NAME
#define WIFI_DRIVER_MODULE_NAME "wlan"
#endif
#ifdef WIFI_DRIVER_MODULE_PATH
static const char DRIVER_MODULE_NAME[] = WIFI_DRIVER_MODULE_NAME;
static const char DRIVER_MODULE_TAG[] = WIFI_DRIVER_MODULE_NAME " ";
......@@ -111,6 +118,10 @@ static const char SUPPLICANT_NAME[] = "wpa_supplicant";
static const char SUPP_PROP_NAME[] = "init.svc.wpa_supplicant";
static const char P2P_SUPPLICANT_NAME[] = "p2p_supplicant";
static const char P2P_PROP_NAME[] = "init.svc.p2p_supplicant";
static const char RTL_SUPPLICANT_NAME[] = "p2p_supp_rtl";
static const char RTL_PROP_NAME[] = "init.svc.p2p_supp_rtl";
static const char ESP_SUPPLICANT_NAME[] = "p2p_supp_esp";
static const char ESP_PROP_NAME[] = "init.svc.p2p_supp_esp";
static const char SUPP_CONFIG_TEMPLATE[]= "/system/etc/wifi/wpa_supplicant.conf";
static const char SUPP_CONFIG_FILE[] = "/data/misc/wifi/wpa_supplicant.conf";
static const char P2P_CONFIG_FILE[] = "/data/misc/wifi/p2p_supplicant.conf";
......@@ -132,6 +143,8 @@ static char supplicant_name[PROPERTY_VALUE_MAX];
/* Is either SUPP_PROP_NAME or P2P_PROP_NAME */
static char supplicant_prop_name[PROPERTY_KEY_MAX];
static char wifi_type[64];
static int insmod(const char *filename, const char *args)
{
void *module;
......@@ -216,16 +229,17 @@ int wifi_change_driver_state(const char *state)
int is_wifi_driver_loaded() {
char driver_status[PROPERTY_VALUE_MAX];
#ifdef WIFI_DRIVER_MODULE_PATH
//#ifdef WIFI_DRIVER_MODULE_PATH
FILE *proc;
char line[sizeof(DRIVER_MODULE_TAG)+10];
#endif
//#endif
if (!property_get(DRIVER_PROP_NAME, driver_status, NULL)
|| strcmp(driver_status, "ok") != 0) {
return 0; /* driver not loaded */
}
#ifdef WIFI_DRIVER_MODULE_PATH
if (check_wifi_preload() == 0) { //#ifdef WIFI_DRIVER_MODULE_PATH
/*
* If the property says the driver is loaded, check to
* make sure that the property setting isn't just left
......@@ -246,88 +260,87 @@ int is_wifi_driver_loaded() {
fclose(proc);
property_set(DRIVER_PROP_NAME, "unloaded");
return 0;
#else
} else { //#else
return 1;
#endif
} //#endif
}
int wifi_load_driver()
{
#ifdef WIFI_DRIVER_MODULE_PATH
char driver_status[PROPERTY_VALUE_MAX];
int count = 100; /* wait at most 20 seconds for completion */
if (is_wifi_driver_loaded()) {
return 0;
}
if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0)
return -1;
if (strcmp(FIRMWARE_LOADER,"") == 0) {
/* usleep(WIFI_DRIVER_LOADER_DELAY); */
property_set(DRIVER_PROP_NAME, "ok");
}
else {
property_set("ctl.start", FIRMWARE_LOADER);
}
sched_yield();
while (count-- > 0) {
if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
ALOGD("%s", __func__);
if (check_wifi_preload() == 0) { //#ifdef WIFI_DRIVER_MODULE_PATH
char driver_status[PROPERTY_VALUE_MAX];
int count = 100; /* wait at most 20 seconds for completion */
if (check_wireless_ready()) {
return 0;
}
if (rk_wifi_load_driver(1) < 0) {
return -1;
}
if (strcmp(FIRMWARE_LOADER,"") == 0) {
/* usleep(WIFI_DRIVER_LOADER_DELAY); */
property_set(DRIVER_PROP_NAME, "ok");
}
else {
property_set("ctl.start", FIRMWARE_LOADER);
}
sched_yield();
while (count-- > 0) {
/*
if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
if (strcmp(driver_status, "ok") == 0)
return 0;
else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
wifi_unload_driver();
return -1;
}
}
*/
if (check_wireless_ready()) {
property_set(DRIVER_PROP_NAME, "ok");
return 0;
else if (strcmp(driver_status, "failed") == 0) {
wifi_unload_driver();
return -1;
}
usleep(200000);
}
usleep(200000);
}
property_set(DRIVER_PROP_NAME, "timeout");
wifi_unload_driver();
return -1;
#else
#ifdef WIFI_DRIVER_STATE_CTRL_PARAM
if (is_wifi_driver_loaded()) {
return 0;
}
if (wifi_change_driver_state(WIFI_DRIVER_STATE_ON) < 0)
property_set(DRIVER_PROP_NAME, "timeout");
wifi_unload_driver();
return -1;
#endif
property_set(DRIVER_PROP_NAME, "ok");
return 0;
#endif
} else { //#else
property_set(DRIVER_PROP_NAME, "ok");
return 0;
} //#endif
}
int wifi_unload_driver()
{
int ret;
usleep(200000); /* allow to finish interface down */
#ifdef WIFI_DRIVER_MODULE_PATH
if (rmmod(DRIVER_MODULE_NAME) == 0) {
int count = 20; /* wait at most 10 seconds for completion */
while (count-- > 0) {
if (!is_wifi_driver_loaded())
ALOGD("%s", __func__);
if (check_wifi_preload() == 0) { //#ifdef WIFI_DRIVER_MODULE_PATH
ret = rk_wifi_load_driver(0);
if (ret == 0) {
int count = 20; /* wait at most 10 seconds for completion */
while (count-- > 0) {
//if (!is_wifi_driver_loaded())
if (!check_wireless_ready())
break;
usleep(500000);
}
usleep(500000); /* allow card removal */
if (count) {
return 0;
}
return -1;
} else
return -1;
#else
#ifdef WIFI_DRIVER_STATE_CTRL_PARAM
if (is_wifi_driver_loaded()) {
if (wifi_change_driver_state(WIFI_DRIVER_STATE_OFF) < 0)
usleep(500000);
}
usleep(500000); /* allow card removal */
if (count) {
return 0;
}
return -1;
}
#endif
property_set(DRIVER_PROP_NAME, "unloaded");
return 0;
#endif
} else
return -1;
} else { //#else
property_set(DRIVER_PROP_NAME, "unloaded");
return 0;
} //#endif
}
int ensure_entropy_file_exists()
......@@ -446,9 +459,22 @@ int wifi_start_supplicant(int p2p_supported)
const prop_info *pi;
unsigned serial = 0, i;
if (wifi_type[0] == 0)
check_wifi_chip_type_string(wifi_type);
if (p2p_supported) {
strcpy(supplicant_name, P2P_SUPPLICANT_NAME);
strcpy(supplicant_prop_name, P2P_PROP_NAME);
/*if (get_kernel_version() == KERNEL_VERSION_3_10)*/ {
if (!strncmp(wifi_type, "ESP", 3)) {
strcpy(supplicant_name, ESP_SUPPLICANT_NAME);
strcpy(supplicant_prop_name, ESP_PROP_NAME);
} else if (!strncmp(wifi_type, "RTL", 3)){
strcpy(supplicant_name, RTL_SUPPLICANT_NAME);
strcpy(supplicant_prop_name, RTL_PROP_NAME);
} else {
strcpy(supplicant_name, P2P_SUPPLICANT_NAME);
strcpy(supplicant_prop_name, P2P_PROP_NAME);
}
}
/* Ensure p2p config file is created */
if (ensure_config_file_exists(P2P_CONFIG_FILE) < 0) {
......@@ -460,6 +486,7 @@ int wifi_start_supplicant(int p2p_supported)
strcpy(supplicant_name, SUPPLICANT_NAME);
strcpy(supplicant_prop_name, SUPP_PROP_NAME);
}
ALOGD("%s: %s", __func__, supplicant_name);
/* Check whether already running */
if (property_get(supplicant_prop_name, supp_status, NULL)
......@@ -526,9 +553,21 @@ int wifi_stop_supplicant(int p2p_supported)
char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
int count = 50; /* wait at most 5 seconds for completion */
if (wifi_type[0] == 0)
check_wifi_chip_type_string(wifi_type);
if (p2p_supported) {
strcpy(supplicant_name, P2P_SUPPLICANT_NAME);
strcpy(supplicant_prop_name, P2P_PROP_NAME);
/*if (get_kernel_version() == KERNEL_VERSION_3_10)*/ {
if (!strncmp(wifi_type, "ESP", 3)) {
strcpy(supplicant_name, ESP_SUPPLICANT_NAME);
strcpy(supplicant_prop_name, ESP_PROP_NAME);
} else if (!strncmp(wifi_type, "RTL", 3)){
strcpy(supplicant_name, RTL_SUPPLICANT_NAME);
strcpy(supplicant_prop_name, RTL_PROP_NAME);
} else {
strcpy(supplicant_name, P2P_SUPPLICANT_NAME);
strcpy(supplicant_prop_name, P2P_PROP_NAME);
}
}
} else {
strcpy(supplicant_name, SUPPLICANT_NAME);
strcpy(supplicant_prop_name, SUPP_PROP_NAME);
......@@ -817,6 +856,12 @@ int wifi_change_fw_path(const char *fwpath)
int fd;
int ret = 0;
if (wifi_type[0] == 0)
check_wifi_chip_type_string(wifi_type);
if (0 != strncmp(wifi_type, "AP", 2)) {
return 0;
}
if (!fwpath)
return ret;
fd = TEMP_FAILURE_RETRY(open(WIFI_DRIVER_FW_PATH_PARAM, O_WRONLY));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment