Skip to content

Commit

Permalink
Wifi: Enable Ad-Hoc (IBSS) network configuration
Browse files Browse the repository at this point in the history
This adds two public but hidden variables to WifiConfiguration: isIBSS and
frequency. These are used for configuring IBSS mode.

WifiConfigStore is exended to get and set these variables to wpa_supplicant
(via WifiNative).

Change-Id: Iab02c3d738c05c2de036350ea77b78789213e357
  • Loading branch information
Bruno Randolf authored and Whitehawkx committed Mar 25, 2013
1 parent 3d5ff06 commit 5072ab7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
35 changes: 35 additions & 0 deletions wifi/java/android/net/wifi/WifiConfigStore.java
Expand Up @@ -1006,6 +1006,23 @@ private NetworkUpdateResult addOrUpdateNetworkNative(WifiConfiguration config) {
break setVariables; break setVariables;
} }


if (config.isIBSS) {
if(!mWifiNative.setNetworkVariable(
netId,
WifiConfiguration.modeVarName,
"1")) {
loge("failed to set adhoc mode");
break setVariables;
}
if(!mWifiNative.setNetworkVariable(
netId,
WifiConfiguration.frequencyVarName,
Integer.toString(config.frequency))) {
loge("failed to set frequency");
break setVariables;
}
}

String allowedKeyManagementString = String allowedKeyManagementString =
makeString(config.allowedKeyManagement, WifiConfiguration.KeyMgmt.strings); makeString(config.allowedKeyManagement, WifiConfiguration.KeyMgmt.strings);
if (config.allowedKeyManagement.cardinality() != 0 && if (config.allowedKeyManagement.cardinality() != 0 &&
Expand Down Expand Up @@ -1356,6 +1373,24 @@ private void readNetworkVariables(WifiConfiguration config) {
} }
} }


value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.modeVarName);
config.isIBSS = false;
if (!TextUtils.isEmpty(value)) {
try {
config.isIBSS = Integer.parseInt(value) != 0;
} catch (NumberFormatException ignore) {
}
}

value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.frequencyVarName);
config.frequency = 0;
if (!TextUtils.isEmpty(value)) {
try {
config.frequency = Integer.parseInt(value);
} catch (NumberFormatException ignore) {
}
}

value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.wepTxKeyIdxVarName); value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.wepTxKeyIdxVarName);
config.wepTxKeyIndex = -1; config.wepTxKeyIndex = -1;
if (!TextUtils.isEmpty(value)) { if (!TextUtils.isEmpty(value)) {
Expand Down
24 changes: 24 additions & 0 deletions wifi/java/android/net/wifi/WifiConfiguration.java
Expand Up @@ -77,6 +77,10 @@ public class WifiConfiguration implements Parcelable {
/** {@hide} */ /** {@hide} */
public static final String hiddenSSIDVarName = "scan_ssid"; public static final String hiddenSSIDVarName = "scan_ssid";
/** {@hide} */ /** {@hide} */
public static final String modeVarName = "mode";
/** {@hide} */
public static final String frequencyVarName = "frequency";
/** {@hide} */
public static final int INVALID_NETWORK_ID = -1; public static final int INVALID_NETWORK_ID = -1;


/** {@hide} */ /** {@hide} */
Expand Down Expand Up @@ -327,6 +331,18 @@ private Status() { }
*/ */
public boolean hiddenSSID; public boolean hiddenSSID;


/**
* This is an Ad-Hoc (IBSS) network
* {@hide}
*/
public boolean isIBSS;

/**
* Frequency of the Ad-Hoc (IBSS) network, if newly created
* {@hide}
*/
public int frequency;

/** /**
* The set of key management protocols supported by this configuration. * The set of key management protocols supported by this configuration.
* See {@link KeyMgmt} for descriptions of the values. * See {@link KeyMgmt} for descriptions of the values.
Expand Down Expand Up @@ -405,6 +421,8 @@ public WifiConfiguration() {
BSSID = null; BSSID = null;
priority = 0; priority = 0;
hiddenSSID = false; hiddenSSID = false;
isIBSS = false;
frequency = 0;
disableReason = DISABLED_UNKNOWN_REASON; disableReason = DISABLED_UNKNOWN_REASON;
allowedKeyManagement = new BitSet(); allowedKeyManagement = new BitSet();
allowedProtocols = new BitSet(); allowedProtocols = new BitSet();
Expand Down Expand Up @@ -600,6 +618,8 @@ public WifiConfiguration(WifiConfiguration source) {
wepTxKeyIndex = source.wepTxKeyIndex; wepTxKeyIndex = source.wepTxKeyIndex;
priority = source.priority; priority = source.priority;
hiddenSSID = source.hiddenSSID; hiddenSSID = source.hiddenSSID;
isIBSS = source.isIBSS;
frequency = source.frequency;
allowedKeyManagement = (BitSet) source.allowedKeyManagement.clone(); allowedKeyManagement = (BitSet) source.allowedKeyManagement.clone();
allowedProtocols = (BitSet) source.allowedProtocols.clone(); allowedProtocols = (BitSet) source.allowedProtocols.clone();
allowedAuthAlgorithms = (BitSet) source.allowedAuthAlgorithms.clone(); allowedAuthAlgorithms = (BitSet) source.allowedAuthAlgorithms.clone();
Expand Down Expand Up @@ -628,6 +648,8 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(wepTxKeyIndex); dest.writeInt(wepTxKeyIndex);
dest.writeInt(priority); dest.writeInt(priority);
dest.writeInt(hiddenSSID ? 1 : 0); dest.writeInt(hiddenSSID ? 1 : 0);
dest.writeInt(isIBSS ? 1 : 0);
dest.writeInt(frequency);


writeBitSet(dest, allowedKeyManagement); writeBitSet(dest, allowedKeyManagement);
writeBitSet(dest, allowedProtocols); writeBitSet(dest, allowedProtocols);
Expand Down Expand Up @@ -659,6 +681,8 @@ public WifiConfiguration createFromParcel(Parcel in) {
config.wepTxKeyIndex = in.readInt(); config.wepTxKeyIndex = in.readInt();
config.priority = in.readInt(); config.priority = in.readInt();
config.hiddenSSID = in.readInt() != 0; config.hiddenSSID = in.readInt() != 0;
config.isIBSS = in.readInt() != 0;
config.frequency = in.readInt();
config.allowedKeyManagement = readBitSet(in); config.allowedKeyManagement = readBitSet(in);
config.allowedProtocols = readBitSet(in); config.allowedProtocols = readBitSet(in);
config.allowedAuthAlgorithms = readBitSet(in); config.allowedAuthAlgorithms = readBitSet(in);
Expand Down

0 comments on commit 5072ab7

Please sign in to comment.