summaryrefslogtreecommitdiffstats
path: root/service
diff options
context:
space:
mode:
authorxinhe <xinhe@google.com>2015-02-04 16:39:45 -0800
committerxin He <xinhe@google.com>2015-02-06 21:21:50 +0000
commit826282265badbd85c5386573fbced1755696fe83 (patch)
tree611c4648f045a4e4c1e7650f6ca7898142a59ac8 /service
parent2b26ad17b41b6cc7c5663aa47a66239cf698794f (diff)
downloadandroid_frameworks_opt_net_wifi-826282265badbd85c5386573fbced1755696fe83.tar.gz
android_frameworks_opt_net_wifi-826282265badbd85c5386573fbced1755696fe83.tar.bz2
android_frameworks_opt_net_wifi-826282265badbd85c5386573fbced1755696fe83.zip
get channel list from driver for SoftAP channel selection
Instead of hard coding the available channel list, we should get channel list from driver Bug:19237543 Change-Id: Ibe1fbbdc39a6cf69a0b36cfb9c6b63025d0b914d
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiNative.java2
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java65
-rw-r--r--service/jni/com_android_server_wifi_WifiNative.cpp3
3 files changed, 65 insertions, 5 deletions
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java
index 32a503686..c78763c82 100644
--- a/service/java/com/android/server/wifi/WifiNative.java
+++ b/service/java/com/android/server/wifi/WifiNative.java
@@ -1160,8 +1160,6 @@ public class WifiNative {
synchronized public static boolean startHal() {
Log.i(TAG, "startHal");
synchronized (mLock) {
- if (sHalIsStarted)
- return true;
if (sHalFailed)
return false;
if (startHalNative() && (getInterfaces() != 0) && (sWlan0Index != -1)) {
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index eba65403e..8081dabb0 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -115,11 +115,13 @@ import java.io.PrintWriter;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Queue;
+import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
@@ -142,6 +144,7 @@ public class WifiStateMachine extends StateMachine {
private static boolean VDBG = false;
private static boolean VVDBG = false;
private static boolean mLogMessages = false;
+ private static final String TAG = "WifiStateMachine";
private static final int ONE_HOUR_MILLI = 1000 * 60 * 60;
@@ -344,6 +347,8 @@ public class WifiStateMachine extends StateMachine {
// Used as debug to indicate which configuration last was removed
private WifiConfiguration lastForgetConfigurationAttempt = null;
+ //Random used by softAP channel Selection
+ private static Random mRandom = new Random(Calendar.getInstance().getTimeInMillis());
boolean isRoaming() {
return mAutoRoaming == WifiAutoJoinController.AUTO_JOIN_ROAMING
|| mAutoRoaming == WifiAutoJoinController.AUTO_JOIN_EXTENDED_ROAMING;
@@ -4511,13 +4516,71 @@ public class WifiStateMachine extends StateMachine {
mWifiNative.disconnect();
}
+ private int convertFrequencyToChannelNumber(int frequency) {
+ if (frequency >= 2412 && frequency <= 2484) {
+ return (frequency -2412) / 5 + 1;
+ } else if (frequency >= 5170 && frequency <=5825) {
+ //DFS is included
+ return (frequency -5170) / 5 + 34;
+ } else {
+ return 0;
+ }
+ }
+
+ private int chooseApChannel(int apBand) {
+ int apChannel;
+ int band;
+ int[] channel;
+ if(apBand == 0) {
+ band = 1;
+ } else {
+ //5G without DFS
+ band = 2;
+ }
+
+ if(DBG) {
+ Log.d(TAG, "SoftAP get channels from Band: " + band);
+ }
+
+ channel = mWifiNative.getChannelsForBand(band);
+ if (channel != null && channel.length > 0) {
+ apChannel = channel[mRandom.nextInt(channel.length)];
+ apChannel = convertFrequencyToChannelNumber(apChannel);
+ } else {
+ Log.e(TAG, "SoftAp do not get available channel list");
+ apChannel = 0;
+ }
+
+ if(DBG) {
+ Log.d(TAG, "SoftAp set on channel " + apChannel);
+ }
+
+ return apChannel;
+ }
+
+
/* Current design is to not set the config on a running hostapd but instead
* stop and start tethering when user changes config on a running access point
*
* TODO: Add control channel setup through hostapd that allows changing config
* on a running daemon
*/
- private void startSoftApWithConfig(final WifiConfiguration config) {
+ private void startSoftApWithConfig(final WifiConfiguration configuration) {
+ // set channel
+ final WifiConfiguration config = new WifiConfiguration(configuration);
+
+ if (DBG) {
+ Log.d(TAG, "SoftAp config channel is: " + config.apChannel);
+ }
+ //fix me -- set country code through HAL Here
+ if (config.apChannel == 0) {
+ config.apChannel = chooseApChannel(config.apBand);
+ if (config.apChannel == 0) {
+ //fail to get available channel
+ sendMessage(CMD_START_AP_FAILURE);
+ return;
+ }
+ }
// Start hostapd on a separate thread
new Thread(new Runnable() {
public void run() {
diff --git a/service/jni/com_android_server_wifi_WifiNative.cpp b/service/jni/com_android_server_wifi_WifiNative.cpp
index cdd07271f..864b88d51 100644
--- a/service/jni/com_android_server_wifi_WifiNative.cpp
+++ b/service/jni/com_android_server_wifi_WifiNative.cpp
@@ -249,7 +249,6 @@ int set_iface_flags(const char *ifname, int dev_up) {
static jboolean android_net_wifi_startHal(JNIEnv* env, jclass cls) {
wifi_handle halHandle = getWifiHandle(env, cls);
-
if (halHandle == NULL) {
int ret = set_iface_flags("wlan0", 1);
if(ret != 0) {
@@ -265,7 +264,7 @@ static jboolean android_net_wifi_startHal(JNIEnv* env, jclass cls) {
ALOGD("halHandle = %p, mVM = %p, mCls = %p", halHandle, mVM, mCls);
return res == WIFI_SUCCESS;
} else {
- return true;
+ return (set_iface_flags("wlan0", 1) == 0);
}
}