add wps pin from device capability
Bug: 3119043 Bug: 3112178 Change-Id: Iaae6bcf53e11f7fac82b3c604ddc27ff05e00542
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
#include "wifi.h"
|
||||
|
||||
#define WIFI_PKG_NAME "android/net/wifi/WifiNative"
|
||||
#define BUF_SIZE 256
|
||||
|
||||
namespace android {
|
||||
|
||||
@ -67,7 +68,7 @@ static int doCommand(const char *cmd, char *replybuf, int replybuflen)
|
||||
|
||||
static jint doIntCommand(const char *cmd)
|
||||
{
|
||||
char reply[256];
|
||||
char reply[BUF_SIZE];
|
||||
|
||||
if (doCommand(cmd, reply, sizeof(reply)) != 0) {
|
||||
return (jint)-1;
|
||||
@ -78,7 +79,7 @@ static jint doIntCommand(const char *cmd)
|
||||
|
||||
static jboolean doBooleanCommand(const char *cmd, const char *expect)
|
||||
{
|
||||
char reply[256];
|
||||
char reply[BUF_SIZE];
|
||||
|
||||
if (doCommand(cmd, reply, sizeof(reply)) != 0) {
|
||||
return (jboolean)JNI_FALSE;
|
||||
@ -137,7 +138,7 @@ static void android_net_wifi_closeSupplicantConnection(JNIEnv* env, jobject claz
|
||||
|
||||
static jstring android_net_wifi_waitForEvent(JNIEnv* env, jobject clazz)
|
||||
{
|
||||
char buf[256];
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
int nread = ::wifi_wait_for_event(buf, sizeof buf);
|
||||
if (nread > 0) {
|
||||
@ -159,7 +160,7 @@ static jint android_net_wifi_addNetworkCommand(JNIEnv* env, jobject clazz)
|
||||
|
||||
static jboolean android_net_wifi_wpsPbcCommand(JNIEnv* env, jobject clazz, jstring bssid)
|
||||
{
|
||||
char cmdstr[50];
|
||||
char cmdstr[BUF_SIZE];
|
||||
jboolean isCopy;
|
||||
|
||||
const char *bssidStr = env->GetStringUTFChars(bssid, &isCopy);
|
||||
@ -172,9 +173,9 @@ static jboolean android_net_wifi_wpsPbcCommand(JNIEnv* env, jobject clazz, jstri
|
||||
return doBooleanCommand(cmdstr, "OK");
|
||||
}
|
||||
|
||||
static jboolean android_net_wifi_wpsPinCommand(JNIEnv* env, jobject clazz, jstring bssid, int apPin)
|
||||
static jboolean android_net_wifi_wpsPinFromAccessPointCommand(JNIEnv* env, jobject clazz, jstring bssid, int apPin)
|
||||
{
|
||||
char cmdstr[50];
|
||||
char cmdstr[BUF_SIZE];
|
||||
jboolean isCopy;
|
||||
|
||||
const char *bssidStr = env->GetStringUTFChars(bssid, &isCopy);
|
||||
@ -187,13 +188,29 @@ static jboolean android_net_wifi_wpsPinCommand(JNIEnv* env, jobject clazz, jstri
|
||||
return doBooleanCommand(cmdstr, "OK");
|
||||
}
|
||||
|
||||
static jint android_net_wifi_wpsPinFromDeviceCommand(JNIEnv* env, jobject clazz, jstring bssid)
|
||||
{
|
||||
char cmdstr[BUF_SIZE];
|
||||
jboolean isCopy;
|
||||
|
||||
const char *bssidStr = env->GetStringUTFChars(bssid, &isCopy);
|
||||
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "WPS_PIN %s", bssidStr);
|
||||
env->ReleaseStringUTFChars(bssid, bssidStr);
|
||||
|
||||
if ((numWritten == -1) || (numWritten >= (int)sizeof(cmdstr))) {
|
||||
return false;
|
||||
}
|
||||
return doIntCommand(cmdstr);
|
||||
}
|
||||
|
||||
|
||||
static jboolean android_net_wifi_setNetworkVariableCommand(JNIEnv* env,
|
||||
jobject clazz,
|
||||
jint netId,
|
||||
jstring name,
|
||||
jstring value)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
jboolean isCopy;
|
||||
|
||||
const char *nameStr = env->GetStringUTFChars(name, &isCopy);
|
||||
@ -216,7 +233,7 @@ static jstring android_net_wifi_getNetworkVariableCommand(JNIEnv* env,
|
||||
jint netId,
|
||||
jstring name)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
jboolean isCopy;
|
||||
|
||||
const char *nameStr = env->GetStringUTFChars(name, &isCopy);
|
||||
@ -234,7 +251,7 @@ static jstring android_net_wifi_getNetworkVariableCommand(JNIEnv* env,
|
||||
|
||||
static jboolean android_net_wifi_removeNetworkCommand(JNIEnv* env, jobject clazz, jint netId)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
|
||||
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "REMOVE_NETWORK %d", netId);
|
||||
int cmdTooLong = numWritten >= (int)sizeof(cmdstr);
|
||||
@ -247,7 +264,7 @@ static jboolean android_net_wifi_enableNetworkCommand(JNIEnv* env,
|
||||
jint netId,
|
||||
jboolean disableOthers)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
const char *cmd = disableOthers ? "SELECT_NETWORK" : "ENABLE_NETWORK";
|
||||
|
||||
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "%s %d", cmd, netId);
|
||||
@ -258,7 +275,7 @@ static jboolean android_net_wifi_enableNetworkCommand(JNIEnv* env,
|
||||
|
||||
static jboolean android_net_wifi_disableNetworkCommand(JNIEnv* env, jobject clazz, jint netId)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
|
||||
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "DISABLE_NETWORK %d", netId);
|
||||
int cmdTooLong = numWritten >= (int)sizeof(cmdstr);
|
||||
@ -352,7 +369,7 @@ static jboolean android_net_wifi_stopPacketFiltering(JNIEnv* env, jobject clazz)
|
||||
|
||||
static jint android_net_wifi_getRssiHelper(const char *cmd)
|
||||
{
|
||||
char reply[256];
|
||||
char reply[BUF_SIZE];
|
||||
int rssi = -200;
|
||||
|
||||
if (doCommand(cmd, reply, sizeof(reply)) != 0) {
|
||||
@ -391,7 +408,7 @@ static jint android_net_wifi_getRssiApproxCommand(JNIEnv* env, jobject clazz)
|
||||
|
||||
static jint android_net_wifi_getLinkSpeedCommand(JNIEnv* env, jobject clazz)
|
||||
{
|
||||
char reply[256];
|
||||
char reply[BUF_SIZE];
|
||||
int linkspeed;
|
||||
|
||||
if (doCommand("DRIVER LINKSPEED", reply, sizeof(reply)) != 0) {
|
||||
@ -405,8 +422,8 @@ static jint android_net_wifi_getLinkSpeedCommand(JNIEnv* env, jobject clazz)
|
||||
|
||||
static jstring android_net_wifi_getMacAddressCommand(JNIEnv* env, jobject clazz)
|
||||
{
|
||||
char reply[256];
|
||||
char buf[256];
|
||||
char reply[BUF_SIZE];
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
if (doCommand("DRIVER MACADDR", reply, sizeof(reply)) != 0) {
|
||||
return env->NewStringUTF(NULL);
|
||||
@ -421,7 +438,7 @@ static jstring android_net_wifi_getMacAddressCommand(JNIEnv* env, jobject clazz)
|
||||
|
||||
static jboolean android_net_wifi_setPowerModeCommand(JNIEnv* env, jobject clazz, jint mode)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
|
||||
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "DRIVER POWERMODE %d", mode);
|
||||
int cmdTooLong = numWritten >= (int)sizeof(cmdstr);
|
||||
@ -431,7 +448,7 @@ static jboolean android_net_wifi_setPowerModeCommand(JNIEnv* env, jobject clazz,
|
||||
|
||||
static jint android_net_wifi_getPowerModeCommand(JNIEnv* env, jobject clazz)
|
||||
{
|
||||
char reply[256];
|
||||
char reply[BUF_SIZE];
|
||||
int power;
|
||||
|
||||
if (doCommand("DRIVER GETPOWER", reply, sizeof(reply)) != 0) {
|
||||
@ -469,7 +486,7 @@ static jint android_net_wifi_getBandCommand(JNIEnv* env, jobject clazz)
|
||||
|
||||
static jboolean android_net_wifi_setNumAllowedChannelsCommand(JNIEnv* env, jobject clazz, jint numChannels)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
|
||||
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "DRIVER SCAN-CHANNELS %u", numChannels);
|
||||
int cmdTooLong = numWritten >= (int)sizeof(cmdstr);
|
||||
@ -479,7 +496,7 @@ static jboolean android_net_wifi_setNumAllowedChannelsCommand(JNIEnv* env, jobje
|
||||
|
||||
static jint android_net_wifi_getNumAllowedChannelsCommand(JNIEnv* env, jobject clazz)
|
||||
{
|
||||
char reply[256];
|
||||
char reply[BUF_SIZE];
|
||||
int numChannels;
|
||||
|
||||
if (doCommand("DRIVER SCAN-CHANNELS", reply, sizeof(reply)) != 0) {
|
||||
@ -495,7 +512,7 @@ static jint android_net_wifi_getNumAllowedChannelsCommand(JNIEnv* env, jobject c
|
||||
|
||||
static jboolean android_net_wifi_setBluetoothCoexistenceModeCommand(JNIEnv* env, jobject clazz, jint mode)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
|
||||
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "DRIVER BTCOEXMODE %d", mode);
|
||||
int cmdTooLong = numWritten >= (int)sizeof(cmdstr);
|
||||
@ -505,7 +522,7 @@ static jboolean android_net_wifi_setBluetoothCoexistenceModeCommand(JNIEnv* env,
|
||||
|
||||
static jboolean android_net_wifi_setBluetoothCoexistenceScanModeCommand(JNIEnv* env, jobject clazz, jboolean setCoexScanMode)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
|
||||
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "DRIVER BTCOEXSCAN-%s", setCoexScanMode ? "START" : "STOP");
|
||||
int cmdTooLong = numWritten >= (int)sizeof(cmdstr);
|
||||
@ -527,7 +544,7 @@ static jboolean android_net_wifi_reloadConfigCommand(JNIEnv* env, jobject clazz)
|
||||
|
||||
static jboolean android_net_wifi_setScanResultHandlingCommand(JNIEnv* env, jobject clazz, jint mode)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
|
||||
int numWritten = snprintf(cmdstr, sizeof(cmdstr), "AP_SCAN %d", mode);
|
||||
int cmdTooLong = numWritten >= (int)sizeof(cmdstr);
|
||||
@ -537,7 +554,7 @@ static jboolean android_net_wifi_setScanResultHandlingCommand(JNIEnv* env, jobje
|
||||
|
||||
static jboolean android_net_wifi_addToBlacklistCommand(JNIEnv* env, jobject clazz, jstring bssid)
|
||||
{
|
||||
char cmdstr[256];
|
||||
char cmdstr[BUF_SIZE];
|
||||
jboolean isCopy;
|
||||
|
||||
const char *bssidStr = env->GetStringUTFChars(bssid, &isCopy);
|
||||
@ -636,7 +653,10 @@ static JNINativeMethod gWifiMethods[] = {
|
||||
{ "addToBlacklistCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_addToBlacklistCommand },
|
||||
{ "clearBlacklistCommand", "()Z", (void*) android_net_wifi_clearBlacklistCommand },
|
||||
{ "startWpsPbcCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_wpsPbcCommand },
|
||||
{ "startWpsPinCommand", "(Ljava/lang/String;I)Z", (void*) android_net_wifi_wpsPinCommand },
|
||||
{ "startWpsWithPinFromAccessPointCommand", "(Ljava/lang/String;I)Z",
|
||||
(void*) android_net_wifi_wpsPinFromAccessPointCommand },
|
||||
{ "startWpsWithPinFromDeviceCommand", "(Ljava/lang/String;)I",
|
||||
(void*) android_net_wifi_wpsPinFromDeviceCommand },
|
||||
{ "doDhcpRequest", "(Landroid/net/DhcpInfo;)Z", (void*) android_net_wifi_doDhcpRequest },
|
||||
{ "getDhcpError", "()Ljava/lang/String;", (void*) android_net_wifi_getDhcpError },
|
||||
};
|
||||
|
@ -872,9 +872,19 @@ public class WifiService extends IWifiManager.Stub {
|
||||
mWifiStateMachine.startWpsPbc(bssid);
|
||||
}
|
||||
|
||||
public void startWpsPin(String bssid, int apPin) {
|
||||
public void startWpsWithPinFromAccessPoint(String bssid, int apPin) {
|
||||
enforceChangePermission();
|
||||
mWifiStateMachine.startWpsPin(bssid, apPin);
|
||||
mWifiStateMachine.startWpsWithPinFromAccessPoint(bssid, apPin);
|
||||
}
|
||||
|
||||
public int startWpsWithPinFromDevice(String bssid) {
|
||||
enforceChangePermission();
|
||||
if (mChannel != null) {
|
||||
return mWifiStateMachine.syncStartWpsWithPinFromDevice(mChannel, bssid);
|
||||
} else {
|
||||
Slog.e(TAG, "mChannel is not initialized");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
|
@ -108,6 +108,8 @@ interface IWifiManager
|
||||
|
||||
void startWpsPbc(String bssid);
|
||||
|
||||
void startWpsPin(String bssid, int apPin);
|
||||
void startWpsWithPinFromAccessPoint(String bssid, int apPin);
|
||||
|
||||
int startWpsWithPinFromDevice(String bssid);
|
||||
}
|
||||
|
||||
|
@ -361,10 +361,11 @@ class WifiConfigStore {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start WPS pin method configuration
|
||||
* Start WPS pin method configuration with pin obtained
|
||||
* from the access point
|
||||
*/
|
||||
static boolean startWpsPin(String bssid, int apPin) {
|
||||
if (WifiNative.startWpsPinCommand(bssid, apPin)) {
|
||||
static boolean startWpsWithPinFromAccessPoint(String bssid, int apPin) {
|
||||
if (WifiNative.startWpsWithPinFromAccessPointCommand(bssid, apPin)) {
|
||||
/* WPS leaves all networks disabled */
|
||||
markAllNetworksDisabled();
|
||||
return true;
|
||||
@ -373,6 +374,21 @@ class WifiConfigStore {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start WPS pin method configuration with pin obtained
|
||||
* from the device
|
||||
*/
|
||||
static int startWpsWithPinFromDevice(String bssid) {
|
||||
int pin = WifiNative.startWpsWithPinFromDeviceCommand(bssid);
|
||||
/* WPS leaves all networks disabled */
|
||||
if (pin != -1) {
|
||||
markAllNetworksDisabled();
|
||||
} else {
|
||||
Log.e(TAG, "Failed to start WPS pin method configuration");
|
||||
}
|
||||
return pin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start WPS push button configuration
|
||||
*/
|
||||
|
@ -1050,18 +1050,35 @@ public class WifiManager {
|
||||
|
||||
/**
|
||||
* Start Wi-fi Protected Setup pin method configuration
|
||||
* with pin obtained from the access point
|
||||
*
|
||||
* @param bssid BSSID of the access point
|
||||
* @param apPin PIN issued by the access point
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void startWpsPin(String bssid, int apPin) {
|
||||
public void startWpsWithPinFromAccessPoint(String bssid, int apPin) {
|
||||
try {
|
||||
mService.startWpsPin(bssid, apPin);
|
||||
mService.startWpsWithPinFromAccessPoint(bssid, apPin);
|
||||
} catch (RemoteException e) { }
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Wi-fi Protected Setup pin method configuration
|
||||
* with pin obtained from the device
|
||||
*
|
||||
* @param bssid BSSID of the access point
|
||||
* @return pin generated by device
|
||||
* @hide
|
||||
*/
|
||||
public int startWpsWithPinFromDevice(String bssid) {
|
||||
try {
|
||||
return mService.startWpsWithPinFromDevice(bssid);
|
||||
} catch (RemoteException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows an application to keep the Wi-Fi radio awake.
|
||||
* Normally the Wi-Fi radio may turn off when the user has not used the device in a while.
|
||||
|
@ -153,7 +153,9 @@ public class WifiNative {
|
||||
|
||||
public native static boolean startWpsPbcCommand(String bssid);
|
||||
|
||||
public native static boolean startWpsPinCommand(String bssid, int apPin);
|
||||
public native static boolean startWpsWithPinFromAccessPointCommand(String bssid, int apPin);
|
||||
|
||||
public native static int startWpsWithPinFromDeviceCommand(String bssid);
|
||||
|
||||
public native static boolean doDhcpRequest(DhcpInfo results);
|
||||
|
||||
|
@ -301,9 +301,10 @@ public class WifiStateMachine extends HierarchicalStateMachine {
|
||||
* supplicant config.
|
||||
*/
|
||||
private static final int CMD_FORGET_NETWORK = 92;
|
||||
/* Start Wi-Fi protected setup */
|
||||
private static final int CMD_START_WPS = 93;
|
||||
|
||||
/* Start Wi-Fi protected setup push button configuration */
|
||||
private static final int CMD_START_WPS_PBC = 93;
|
||||
/* Start Wi-Fi protected setup pin method configuration */
|
||||
private static final int CMD_START_WPS_PIN = 94;
|
||||
/**
|
||||
* Interval in milliseconds between polling for connection
|
||||
* status items that are not sent via asynchronous events.
|
||||
@ -787,11 +788,18 @@ public class WifiStateMachine extends HierarchicalStateMachine {
|
||||
}
|
||||
|
||||
public void startWpsPbc(String bssid) {
|
||||
sendMessage(obtainMessage(CMD_START_WPS, bssid));
|
||||
sendMessage(obtainMessage(CMD_START_WPS_PBC, bssid));
|
||||
}
|
||||
|
||||
public void startWpsPin(String bssid, int apPin) {
|
||||
sendMessage(obtainMessage(CMD_START_WPS, apPin, 0, bssid));
|
||||
public void startWpsWithPinFromAccessPoint(String bssid, int apPin) {
|
||||
sendMessage(obtainMessage(CMD_START_WPS_PIN, apPin, 0, bssid));
|
||||
}
|
||||
|
||||
public int syncStartWpsWithPinFromDevice(AsyncChannel channel, String bssid) {
|
||||
Message resultMsg = channel.sendMessageSynchronously(CMD_START_WPS_PIN, bssid);
|
||||
int result = resultMsg.arg1;
|
||||
resultMsg.recycle();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void enableRssiPolling(boolean enabled) {
|
||||
@ -1654,7 +1662,8 @@ public class WifiStateMachine extends HierarchicalStateMachine {
|
||||
case CMD_CONNECT_NETWORK:
|
||||
case CMD_SAVE_NETWORK:
|
||||
case CMD_FORGET_NETWORK:
|
||||
case CMD_START_WPS:
|
||||
case CMD_START_WPS_PBC:
|
||||
case CMD_START_WPS_PIN:
|
||||
break;
|
||||
default:
|
||||
Log.e(TAG, "Error! unhandled message" + message);
|
||||
@ -2395,17 +2404,11 @@ public class WifiStateMachine extends HierarchicalStateMachine {
|
||||
/* Expect a disconnection from the old connection */
|
||||
transitionTo(mDisconnectingState);
|
||||
break;
|
||||
case CMD_START_WPS:
|
||||
case CMD_START_WPS_PBC:
|
||||
String bssid = (String) message.obj;
|
||||
int apPin = message.arg1;
|
||||
boolean success;
|
||||
if (apPin != 0) {
|
||||
/* WPS pin method configuration */
|
||||
success = WifiConfigStore.startWpsPin(bssid, apPin);
|
||||
} else {
|
||||
/* WPS push button configuration */
|
||||
success = WifiConfigStore.startWpsPbc(bssid);
|
||||
}
|
||||
/* WPS push button configuration */
|
||||
boolean success = WifiConfigStore.startWpsPbc(bssid);
|
||||
|
||||
/* During WPS setup, all other networks are disabled. After
|
||||
* a successful connect a new config is created in the supplicant.
|
||||
*
|
||||
@ -2422,6 +2425,24 @@ public class WifiStateMachine extends HierarchicalStateMachine {
|
||||
transitionTo(mDisconnectingState);
|
||||
}
|
||||
break;
|
||||
case CMD_START_WPS_PIN:
|
||||
bssid = (String) message.obj;
|
||||
int apPin = message.arg1;
|
||||
int pin;
|
||||
if (apPin != 0) {
|
||||
/* WPS pin from access point */
|
||||
success = WifiConfigStore.startWpsWithPinFromAccessPoint(bssid, apPin);
|
||||
} else {
|
||||
pin = WifiConfigStore.startWpsWithPinFromDevice(bssid);
|
||||
success = (pin != -1);
|
||||
mReplyChannel.replyToMessage(message, CMD_START_WPS_PIN, pin);
|
||||
}
|
||||
if (success) {
|
||||
mWpsStarted = true;
|
||||
/* Expect a disconnection from the old connection */
|
||||
transitionTo(mDisconnectingState);
|
||||
}
|
||||
break;
|
||||
case SCAN_RESULTS_EVENT:
|
||||
/* Set the scan setting back to "connect" mode */
|
||||
WifiNative.setScanResultHandlingCommand(CONNECT_MODE);
|
||||
|
Reference in New Issue
Block a user