diff options
Diffstat (limited to 'wifi/java/android/net')
-rw-r--r-- | wifi/java/android/net/wifi/IWifiManager.aidl | 3 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiChannel.aidl | 19 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiChannel.java | 85 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiManager.java | 13 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiNative.java | 30 | ||||
-rw-r--r-- | wifi/java/android/net/wifi/WifiStateMachine.java | 21 |
6 files changed, 171 insertions, 0 deletions
diff --git a/wifi/java/android/net/wifi/IWifiManager.aidl b/wifi/java/android/net/wifi/IWifiManager.aidl index 8049988..e53d6ac 100644 --- a/wifi/java/android/net/wifi/IWifiManager.aidl +++ b/wifi/java/android/net/wifi/IWifiManager.aidl @@ -19,6 +19,7 @@ package android.net.wifi; import android.net.wifi.WifiInfo; import android.net.wifi.WifiConfiguration; import android.net.wifi.ScanResult; +import android.net.wifi.WifiChannel; import android.net.DhcpInfo; import android.os.Messenger; @@ -71,6 +72,8 @@ interface IWifiManager boolean isIbssSupported(); + List<WifiChannel> getSupportedChannels(); + boolean saveConfiguration(); DhcpInfo getDhcpInfo(); diff --git a/wifi/java/android/net/wifi/WifiChannel.aidl b/wifi/java/android/net/wifi/WifiChannel.aidl new file mode 100644 index 0000000..e12def3 --- /dev/null +++ b/wifi/java/android/net/wifi/WifiChannel.aidl @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2013, 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. + */ + +package android.net.wifi; + +parcelable WifiChannel; diff --git a/wifi/java/android/net/wifi/WifiChannel.java b/wifi/java/android/net/wifi/WifiChannel.java new file mode 100644 index 0000000..ba6a64f --- /dev/null +++ b/wifi/java/android/net/wifi/WifiChannel.java @@ -0,0 +1,85 @@ + +package android.net.wifi; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * A class representing one wifi channel or frequency + * @hide + */ +public class WifiChannel implements Parcelable { + public int channel; + public int frequency; + public boolean ibssAllowed; + + public String toString() { + StringBuffer sbuf = new StringBuffer(); + sbuf.append(" channel: ").append(channel); + sbuf.append(" freq: ").append(frequency); + sbuf.append(" MHz"); + sbuf.append(" IBSS: ").append(ibssAllowed ? "allowed" : "not allowed"); + sbuf.append('\n'); + return sbuf.toString(); + } + + @Override + public boolean equals(Object o) { + if (o instanceof WifiChannel) { + WifiChannel w = (WifiChannel)o; + return (this.channel == w.channel && + this.frequency == w.frequency && + this.ibssAllowed == w.ibssAllowed); + } + return false; + } + + /** Implement the Parcelable interface */ + public int describeContents() { + return 0; + } + + public WifiChannel() { + channel = 0; + frequency = 0; + ibssAllowed = false; + } + + public WifiChannel(int ch, int freq, boolean ibss) { + channel = ch; + frequency = freq; + ibssAllowed = ibss; + } + + /* Copy constructor */ + public WifiChannel(WifiChannel source) { + if (source != null) { + channel = source.channel; + frequency = source.frequency; + ibssAllowed = source.ibssAllowed; + } + } + + /** Implement the Parcelable interface */ + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(channel); + dest.writeInt(frequency); + dest.writeInt(ibssAllowed ? 1 : 0); + } + + /** Implement the Parcelable interface */ + public static final Creator<WifiChannel> CREATOR = + new Creator<WifiChannel>() { + public WifiChannel createFromParcel(Parcel in) { + WifiChannel ch = new WifiChannel(); + ch.channel = in.readInt(); + ch.frequency = in.readInt(); + ch.ibssAllowed = (in.readInt() == 1); + return ch; + } + + public WifiChannel[] newArray(int size) { + return new WifiChannel[size]; + } + }; +} diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index f74dfe1..12701fa 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -884,6 +884,19 @@ public class WifiManager { } /** + * Get a list of supported channels / frequencies + * @return a List of WifiChannels + * @hide + */ + public List<WifiChannel> getSupportedChannels() { + try { + return mService.getSupportedChannels(); + } catch (RemoteException e) { + return null; + } + } + + /** * Return the DHCP-assigned addresses from the last successful DHCP request, * if any. * @return the DHCP information diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index 66bd90b..43e3d33 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -811,5 +811,35 @@ public class WifiNative { return false; } + public List<WifiChannel> getSupportedChannels() { + boolean ibssAllowed; + List<WifiChannel> channels = new ArrayList<WifiChannel>(); + String ret = doStringCommand("GET_CAPABILITY freq"); + + if (!TextUtils.isEmpty(ret)) { + String[] lines = ret.split("\n"); + for (String l : lines) { + if (l.startsWith("Mode") || TextUtils.isEmpty(l)) continue; + + String[] tokens = l.split(" "); + if (tokens.length < 4) continue; + + if (tokens.length == 6 && tokens[5].contains("NO_IBSS")) + ibssAllowed = false; + else + ibssAllowed = true; + + try { + WifiChannel ch = new WifiChannel(Integer.parseInt(tokens[1]), Integer.parseInt(tokens[3]), ibssAllowed); + if (!channels.contains(ch)) + channels.add(ch); + } catch (java.lang.NumberFormatException e) { + Log.d(mTAG, "Can't parse: " + l); + } + } + } + return channels; + } + public native static boolean setMode(int mode); } diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java index 2eed0c2..dc4d757 100644 --- a/wifi/java/android/net/wifi/WifiStateMachine.java +++ b/wifi/java/android/net/wifi/WifiStateMachine.java @@ -151,6 +151,8 @@ public class WifiStateMachine extends StateMachine { private PowerManager.WakeLock mSuspendWakeLock; + private List<WifiChannel> mSupportedChannels; + /** * Interval in milliseconds between polling for RSSI * and linkspeed information @@ -373,6 +375,9 @@ public class WifiStateMachine extends StateMachine { /* Is IBSS mode supported by the driver? */ public static final int CMD_GET_IBSS_SUPPORTED = BASE + 134; + /* Get supported channels */ + public static final int CMD_GET_SUPPORTED_CHANNELS = BASE + 135; + private static final int CONNECT_MODE = 1; private static final int SCAN_ONLY_MODE = 2; @@ -1101,6 +1106,13 @@ public class WifiStateMachine extends StateMachine { return result; } + public List<WifiChannel> syncGetSupportedChannels(AsyncChannel channel) { + Message resultMsg = channel.sendMessageSynchronously(CMD_GET_SUPPORTED_CHANNELS); + List<WifiChannel> result = (List<WifiChannel>) resultMsg.obj; + resultMsg.recycle(); + return result; + } + /** * Set the operational frequency band * @param band @@ -1950,6 +1962,9 @@ public class WifiStateMachine extends StateMachine { case CMD_GET_IBSS_SUPPORTED: replyToMessage(message, message.what, FAILURE); break; + case CMD_GET_SUPPORTED_CHANNELS: + replyToMessage(message, message.what, (List<WifiChannel>) null); + break; case CMD_GET_CONFIGURED_NETWORKS: replyToMessage(message, message.what, (List<WifiConfiguration>) null); break; @@ -2419,6 +2434,7 @@ public class WifiStateMachine extends StateMachine { initializeWpsDetails(); mIbssSupported = mWifiNative.getModeCapability("IBSS"); + mSupportedChannels = mWifiNative.getSupportedChannels(); sendSupplicantConnectionChangedBroadcast(true); transitionTo(mDriverStartedState); @@ -2452,6 +2468,7 @@ public class WifiStateMachine extends StateMachine { case CMD_START_PACKET_FILTERING: case CMD_STOP_PACKET_FILTERING: case CMD_GET_IBSS_SUPPORTED: + case CMD_GET_SUPPORTED_CHANNELS: deferMessage(message); break; default: @@ -2599,6 +2616,7 @@ public class WifiStateMachine extends StateMachine { } break; case CMD_GET_IBSS_SUPPORTED: + case CMD_GET_SUPPORTED_CHANNELS: deferMessage(message); break; default: @@ -2948,6 +2966,9 @@ public class WifiStateMachine extends StateMachine { case CMD_GET_IBSS_SUPPORTED: replyToMessage(message, message.what, mIbssSupported ? 1 : 0); break; + case CMD_GET_SUPPORTED_CHANNELS: + replyToMessage(message, message.what, mSupportedChannels); + break; default: return NOT_HANDLED; } |