From de1e9fa9fbc4b7f4b08415d805a6e5212e655d95 Mon Sep 17 00:00:00 2001 From: Irfan Sheriff Date: Tue, 1 May 2012 16:15:23 -0700 Subject: P2p fixes - Fix group idle settings - Fix provision discovery event handling. We only care about device address. - Fix WPS setup at start Bug: 6427634 Change-Id: I0b1a7d73199e373350001114f4607bc39f2a53ba Signed-off-by: isheriff@google.com Signed-off-by: Yoshihiko Ikenaga --- wifi/java/android/net/wifi/WifiNative.java | 24 +++--- .../android/net/wifi/p2p/WifiP2pProvDiscEvent.java | 85 ++-------------------- wifi/java/android/net/wifi/p2p/WifiP2pService.java | 47 +++++++----- 3 files changed, 49 insertions(+), 107 deletions(-) (limited to 'wifi') diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java index 26229be..73618f6 100644 --- a/wifi/java/android/net/wifi/WifiNative.java +++ b/wifi/java/android/net/wifi/WifiNative.java @@ -442,8 +442,8 @@ public class WifiNative { return doBooleanCommand("SET p2p_ssid_postfix " + postfix); } - public boolean setP2pGroupIdle(String iface, int time) { - return doBooleanCommand("SET interface=" + iface + " p2p_group_idle " + time); + public boolean setP2pGroupIdle(int time) { + return doBooleanCommand("SET p2p_group_idle " + time); } public void setPowerSave(boolean enabled) { @@ -467,7 +467,7 @@ public class WifiNative { * P2P connection over STA */ public boolean setConcurrencyPriority(String s) { - return doBooleanCommand("P2P_SET conc_priority " + s); + return doBooleanCommand("P2P_SET conc_pref " + s); } public boolean p2pFind() { @@ -536,15 +536,17 @@ public class WifiNative { /* Persist unless there is an explicit request to not do so*/ //if (config.persist != WifiP2pConfig.Persist.NO) args.add("persistent"); - if (joinExistingGroup) args.add("join"); - - //TODO: This can be adapted based on device plugged in state and - //device battery state - int groupOwnerIntent = config.groupOwnerIntent; - if (groupOwnerIntent < 0 || groupOwnerIntent > 15) { - groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT; + if (joinExistingGroup) { + args.add("join"); + } else { + //TODO: This can be adapted based on device plugged in state and + //device battery state + int groupOwnerIntent = config.groupOwnerIntent; + if (groupOwnerIntent < 0 || groupOwnerIntent > 15) { + groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT; + } + args.add("go_intent=" + groupOwnerIntent); } - args.add("go_intent=" + groupOwnerIntent); String command = "P2P_CONNECT "; for (String s : args) command += s + " "; diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java b/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java index f70abe8..b3f34b4 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java @@ -50,19 +50,10 @@ public class WifiP2pProvDiscEvent { /** * @param string formats supported include * - * P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27 - * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27 - * group_capab=0x0 - * + * P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 * P2P-PROV-DISC-PBC-RESP 02:12:47:f2:5a:36 - * - * P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27 - * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27 - * group_capab=0x0 - * - * P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 p2p_dev_addr=42:fc:89:e1:e2:27 - * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27 - * group_capab=0x0 + * P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 + * P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 * * Note: The events formats can be looked up in the wpa_supplicant code * @hide @@ -80,51 +71,12 @@ public class WifiP2pProvDiscEvent { else if (tokens[0].endsWith("SHOW-PIN")) event = SHOW_PIN; else throw new IllegalArgumentException("Malformed event " + string); + device = new WifiP2pDevice(); + device.deviceAddress = tokens[1]; - for (String token : tokens) { - String[] nameValue = token.split("="); - if (nameValue.length != 2) { - //mac address without key is device address - if (token.matches("(([0-9a-f]{2}:){5}[0-9a-f]{2})")) { - device.deviceAddress = token; - } else if (token.matches("[0-9]+")) { - pin = token; - } else { - //ignore; - } - continue; - } - - if (nameValue[0].equals("p2p_dev_addr")) { - device.deviceAddress = nameValue[1]; - continue; - } - - if (nameValue[0].equals("pri_dev_type")) { - device.primaryDeviceType = nameValue[1]; - continue; - } - - if (nameValue[0].equals("name")) { - device.deviceName = trimQuotes(nameValue[1]); - continue; - } - - if (nameValue[0].equals("config_methods")) { - device.wpsConfigMethodsSupported = parseHex(nameValue[1]); - continue; - } - - if (nameValue[0].equals("dev_capab")) { - device.deviceCapability = parseHex(nameValue[1]); - continue; - } - - if (nameValue[0].equals("group_capab")) { - device.groupCapability = parseHex(nameValue[1]); - continue; - } + if (event == SHOW_PIN) { + pin = tokens[2]; } } @@ -135,27 +87,4 @@ public class WifiP2pProvDiscEvent { sbuf.append("\n pin: ").append(pin); return sbuf.toString(); } - - private String trimQuotes(String str) { - str = str.trim(); - if (str.startsWith("'") && str.endsWith("'")) { - return str.substring(1, str.length()-1); - } - return str; - } - - //supported formats: 0x1abc, 0X1abc, 1abc - private int parseHex(String hexString) { - int num = 0; - if (hexString.startsWith("0x") || hexString.startsWith("0X")) { - hexString = hexString.substring(2); - } - - try { - num = Integer.parseInt(hexString, 16); - } catch(NumberFormatException e) { - Log.e(TAG, "Failed to parse hex string " + hexString); - } - return num; - } } diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java index f0adb25..b4a879a 100644 --- a/wifi/java/android/net/wifi/p2p/WifiP2pService.java +++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java @@ -88,7 +88,7 @@ import java.util.HashMap; import java.util.List; /** - * WifiP2pService inclues a state machine to perform Wi-Fi p2p operations. Applications + * WifiP2pService includes a state machine to perform Wi-Fi p2p operations. Applications * communicate with this service to issue device discovery and connectivity requests * through the WifiP2pManager interface. The state machine communicates with the wifi * driver through wpa_supplicant and handles the event responses through WifiMonitor. @@ -432,9 +432,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub { loge("Unexpected group creation, remove " + mGroup); mWifiNative.p2pGroupRemove(mGroup.getInterface()); break; + // A group formation failure is always followed by + // a group removed event. Flushing things at group formation + // failure causes supplicant issues. Ignore right now. case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT: - loge("Unexpected group failure, flush peers"); - mWifiNative.p2pFlush(); break; default: loge("Unhandled message " + message); @@ -838,8 +839,10 @@ public class WifiP2pService extends IWifiP2pManager.Stub { //group negotiation comes through causes issues break; case WifiP2pManager.CREATE_GROUP: - mAutonomousGroup = true; - if (mWifiNative.p2pGroupAdd()) { + mAutonomousGroup = true; + // An autonomous GO requires group idle settings to be reset + mWifiNative.setP2pGroupIdle(0); + if (mWifiNative.p2pGroupAdd()) { replyToMessage(message, WifiP2pManager.CREATE_GROUP_SUCCEEDED); } else { replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED, @@ -860,6 +863,11 @@ public class WifiP2pService extends IWifiP2pManager.Stub { if (DBG) logd(getName()); sendMessageDelayed(obtainMessage(GROUP_CREATING_TIMED_OUT, ++mGroupCreatingTimeoutIndex, 0), GROUP_CREATING_WAIT_TIME_MS); + + // Set default group idle settings + if (!mAutonomousGroup) { + mWifiNative.setP2pGroupIdle(GROUP_IDLE_TIME_S); + } } @Override @@ -882,7 +890,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { //Do a supplicant p2p_cancel which only cancels an ongoing //group negotiation. This will fail for a pending provision //discovery or for a pending user action, but at the framework - //level, we always treat cancel as succeded and enter + //level, we always treat cancel as succeeded and enter //an inactive state mWifiNative.p2pCancelConnect(); handleGroupCreationFailure(); @@ -1034,11 +1042,16 @@ public class WifiP2pService extends IWifiP2pManager.Stub { transitionTo(mGroupCreatedState); break; case WifiMonitor.P2P_GO_NEGOTIATION_FAILURE_EVENT: - case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT: + case WifiMonitor.P2P_GROUP_REMOVED_EVENT: if (DBG) logd(getName() + " go failure"); handleGroupCreationFailure(); transitionTo(mInactiveState); break; + // A group formation failure is always followed by + // a group removed event. Flushing things at group formation + // failure causes supplicant issues. Ignore right now. + case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT: + break; default: return NOT_HANDLED; } @@ -1061,10 +1074,6 @@ public class WifiP2pService extends IWifiP2pManager.Stub { setWifiP2pInfoOnGroupFormation(SERVER_ADDRESS); sendP2pConnectionChangedBroadcast(); } - - if (!mAutonomousGroup) { - mWifiNative.setP2pGroupIdle(mGroup.getInterface(), GROUP_IDLE_TIME_S); - } } @Override @@ -1155,6 +1164,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { mGroup = null; mWifiNative.p2pFlush(); + mServiceDiscReqId = null; if (changed) sendP2pPeersChangedBroadcast(); transitionTo(mInactiveState); break; @@ -1537,13 +1547,13 @@ public class WifiP2pService extends IWifiP2pManager.Stub { mWifiNative.setPersistentReconnect(true); mThisDevice.deviceName = getPersistedDeviceName(); mWifiNative.setDeviceName(mThisDevice.deviceName); - //DIRECT-XY-DEVICENAME (XY is randomly generated) + // DIRECT-XY-DEVICENAME (XY is randomly generated) mWifiNative.setP2pSsidPostfix("-" + mThisDevice.deviceName); mWifiNative.setDeviceType(mThisDevice.primaryDeviceType); - //The supplicant default is to support everything, but a bug necessitates - //the framework to specify this explicitly - mWifiNative.setConfigMethods("keypad display push_button"); - //STA has higher priority over P2P + // Supplicant defaults to using virtual display with display + // which refers to a remote display. Use physical_display + mWifiNative.setConfigMethods("virtual_push_button physical_display keypad"); + // STA has higher priority over P2P mWifiNative.setConcurrencyPriority("sta"); mThisDevice.deviceAddress = mWifiNative.p2pGetDeviceAddress(); @@ -1567,11 +1577,12 @@ public class WifiP2pService extends IWifiP2pManager.Stub { /* After cancelling group formation, new connections on existing peers can fail * at supplicant. Flush and restart discovery */ mWifiNative.p2pFlush(); + mServiceDiscReqId = null; sendMessage(WifiP2pManager.DISCOVER_PEERS); } //State machine initiated requests can have replyTo set to null indicating - //there are no recepients, we ignore those reply actions + //there are no recipients, we ignore those reply actions private void replyToMessage(Message msg, int what) { if (msg.replyTo == null) return; Message dstMsg = obtainMessage(msg); @@ -1650,7 +1661,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { mServiceDiscReqId = null; } - /* TODO: We could track individual service adds seperately and avoid + /* TODO: We could track individual service adds separately and avoid * having to do update all service requests on every new request */ private boolean addServiceRequest(Messenger m, WifiP2pServiceRequest req) { -- cgit v1.1