Skip to content

Commit de1e9fa

Browse files
committed
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 <yoshihiko.ikenaga@jp.sony.com>
1 parent faac929 commit de1e9fa

File tree

3 files changed

+49
-107
lines changed

3 files changed

+49
-107
lines changed

wifi/java/android/net/wifi/WifiNative.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ public boolean setP2pSsidPostfix(String postfix) {
442442
return doBooleanCommand("SET p2p_ssid_postfix " + postfix);
443443
}
444444

445-
public boolean setP2pGroupIdle(String iface, int time) {
446-
return doBooleanCommand("SET interface=" + iface + " p2p_group_idle " + time);
445+
public boolean setP2pGroupIdle(int time) {
446+
return doBooleanCommand("SET p2p_group_idle " + time);
447447
}
448448

449449
public void setPowerSave(boolean enabled) {
@@ -467,7 +467,7 @@ public boolean setP2pPowerSave(String iface, boolean enabled) {
467467
* P2P connection over STA
468468
*/
469469
public boolean setConcurrencyPriority(String s) {
470-
return doBooleanCommand("P2P_SET conc_priority " + s);
470+
return doBooleanCommand("P2P_SET conc_pref " + s);
471471
}
472472

473473
public boolean p2pFind() {
@@ -536,15 +536,17 @@ public String p2pConnect(WifiP2pConfig config, boolean joinExistingGroup) {
536536
/* Persist unless there is an explicit request to not do so*/
537537
//if (config.persist != WifiP2pConfig.Persist.NO) args.add("persistent");
538538

539-
if (joinExistingGroup) args.add("join");
540-
541-
//TODO: This can be adapted based on device plugged in state and
542-
//device battery state
543-
int groupOwnerIntent = config.groupOwnerIntent;
544-
if (groupOwnerIntent < 0 || groupOwnerIntent > 15) {
545-
groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT;
539+
if (joinExistingGroup) {
540+
args.add("join");
541+
} else {
542+
//TODO: This can be adapted based on device plugged in state and
543+
//device battery state
544+
int groupOwnerIntent = config.groupOwnerIntent;
545+
if (groupOwnerIntent < 0 || groupOwnerIntent > 15) {
546+
groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT;
547+
}
548+
args.add("go_intent=" + groupOwnerIntent);
546549
}
547-
args.add("go_intent=" + groupOwnerIntent);
548550

549551
String command = "P2P_CONNECT ";
550552
for (String s : args) command += s + " ";

wifi/java/android/net/wifi/p2p/WifiP2pProvDiscEvent.java

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,10 @@ public WifiP2pProvDiscEvent() {
5050
/**
5151
* @param string formats supported include
5252
*
53-
* P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
54-
* pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
55-
* group_capab=0x0
56-
*
53+
* P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27
5754
* P2P-PROV-DISC-PBC-RESP 02:12:47:f2:5a:36
58-
*
59-
* P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
60-
* pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
61-
* group_capab=0x0
62-
*
63-
* P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 p2p_dev_addr=42:fc:89:e1:e2:27
64-
* pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
65-
* group_capab=0x0
55+
* P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27
56+
* P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607
6657
*
6758
* Note: The events formats can be looked up in the wpa_supplicant code
6859
* @hide
@@ -80,51 +71,12 @@ public WifiP2pProvDiscEvent(String string) throws IllegalArgumentException {
8071
else if (tokens[0].endsWith("SHOW-PIN")) event = SHOW_PIN;
8172
else throw new IllegalArgumentException("Malformed event " + string);
8273

74+
8375
device = new WifiP2pDevice();
76+
device.deviceAddress = tokens[1];
8477

85-
for (String token : tokens) {
86-
String[] nameValue = token.split("=");
87-
if (nameValue.length != 2) {
88-
//mac address without key is device address
89-
if (token.matches("(([0-9a-f]{2}:){5}[0-9a-f]{2})")) {
90-
device.deviceAddress = token;
91-
} else if (token.matches("[0-9]+")) {
92-
pin = token;
93-
} else {
94-
//ignore;
95-
}
96-
continue;
97-
}
98-
99-
if (nameValue[0].equals("p2p_dev_addr")) {
100-
device.deviceAddress = nameValue[1];
101-
continue;
102-
}
103-
104-
if (nameValue[0].equals("pri_dev_type")) {
105-
device.primaryDeviceType = nameValue[1];
106-
continue;
107-
}
108-
109-
if (nameValue[0].equals("name")) {
110-
device.deviceName = trimQuotes(nameValue[1]);
111-
continue;
112-
}
113-
114-
if (nameValue[0].equals("config_methods")) {
115-
device.wpsConfigMethodsSupported = parseHex(nameValue[1]);
116-
continue;
117-
}
118-
119-
if (nameValue[0].equals("dev_capab")) {
120-
device.deviceCapability = parseHex(nameValue[1]);
121-
continue;
122-
}
123-
124-
if (nameValue[0].equals("group_capab")) {
125-
device.groupCapability = parseHex(nameValue[1]);
126-
continue;
127-
}
78+
if (event == SHOW_PIN) {
79+
pin = tokens[2];
12880
}
12981
}
13082

@@ -135,27 +87,4 @@ public String toString() {
13587
sbuf.append("\n pin: ").append(pin);
13688
return sbuf.toString();
13789
}
138-
139-
private String trimQuotes(String str) {
140-
str = str.trim();
141-
if (str.startsWith("'") && str.endsWith("'")) {
142-
return str.substring(1, str.length()-1);
143-
}
144-
return str;
145-
}
146-
147-
//supported formats: 0x1abc, 0X1abc, 1abc
148-
private int parseHex(String hexString) {
149-
int num = 0;
150-
if (hexString.startsWith("0x") || hexString.startsWith("0X")) {
151-
hexString = hexString.substring(2);
152-
}
153-
154-
try {
155-
num = Integer.parseInt(hexString, 16);
156-
} catch(NumberFormatException e) {
157-
Log.e(TAG, "Failed to parse hex string " + hexString);
158-
}
159-
return num;
160-
}
16190
}

wifi/java/android/net/wifi/p2p/WifiP2pService.java

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
import java.util.List;
8989

9090
/**
91-
* WifiP2pService inclues a state machine to perform Wi-Fi p2p operations. Applications
91+
* WifiP2pService includes a state machine to perform Wi-Fi p2p operations. Applications
9292
* communicate with this service to issue device discovery and connectivity requests
9393
* through the WifiP2pManager interface. The state machine communicates with the wifi
9494
* driver through wpa_supplicant and handles the event responses through WifiMonitor.
@@ -432,9 +432,10 @@ public boolean processMessage(Message message) {
432432
loge("Unexpected group creation, remove " + mGroup);
433433
mWifiNative.p2pGroupRemove(mGroup.getInterface());
434434
break;
435+
// A group formation failure is always followed by
436+
// a group removed event. Flushing things at group formation
437+
// failure causes supplicant issues. Ignore right now.
435438
case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
436-
loge("Unexpected group failure, flush peers");
437-
mWifiNative.p2pFlush();
438439
break;
439440
default:
440441
loge("Unhandled message " + message);
@@ -838,8 +839,10 @@ public boolean processMessage(Message message) {
838839
//group negotiation comes through causes issues
839840
break;
840841
case WifiP2pManager.CREATE_GROUP:
841-
mAutonomousGroup = true;
842-
if (mWifiNative.p2pGroupAdd()) {
842+
mAutonomousGroup = true;
843+
// An autonomous GO requires group idle settings to be reset
844+
mWifiNative.setP2pGroupIdle(0);
845+
if (mWifiNative.p2pGroupAdd()) {
843846
replyToMessage(message, WifiP2pManager.CREATE_GROUP_SUCCEEDED);
844847
} else {
845848
replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED,
@@ -860,6 +863,11 @@ public void enter() {
860863
if (DBG) logd(getName());
861864
sendMessageDelayed(obtainMessage(GROUP_CREATING_TIMED_OUT,
862865
++mGroupCreatingTimeoutIndex, 0), GROUP_CREATING_WAIT_TIME_MS);
866+
867+
// Set default group idle settings
868+
if (!mAutonomousGroup) {
869+
mWifiNative.setP2pGroupIdle(GROUP_IDLE_TIME_S);
870+
}
863871
}
864872

865873
@Override
@@ -882,7 +890,7 @@ public boolean processMessage(Message message) {
882890
//Do a supplicant p2p_cancel which only cancels an ongoing
883891
//group negotiation. This will fail for a pending provision
884892
//discovery or for a pending user action, but at the framework
885-
//level, we always treat cancel as succeded and enter
893+
//level, we always treat cancel as succeeded and enter
886894
//an inactive state
887895
mWifiNative.p2pCancelConnect();
888896
handleGroupCreationFailure();
@@ -1034,11 +1042,16 @@ public boolean processMessage(Message message) {
10341042
transitionTo(mGroupCreatedState);
10351043
break;
10361044
case WifiMonitor.P2P_GO_NEGOTIATION_FAILURE_EVENT:
1037-
case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
1045+
case WifiMonitor.P2P_GROUP_REMOVED_EVENT:
10381046
if (DBG) logd(getName() + " go failure");
10391047
handleGroupCreationFailure();
10401048
transitionTo(mInactiveState);
10411049
break;
1050+
// A group formation failure is always followed by
1051+
// a group removed event. Flushing things at group formation
1052+
// failure causes supplicant issues. Ignore right now.
1053+
case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
1054+
break;
10421055
default:
10431056
return NOT_HANDLED;
10441057
}
@@ -1061,10 +1074,6 @@ public void enter() {
10611074
setWifiP2pInfoOnGroupFormation(SERVER_ADDRESS);
10621075
sendP2pConnectionChangedBroadcast();
10631076
}
1064-
1065-
if (!mAutonomousGroup) {
1066-
mWifiNative.setP2pGroupIdle(mGroup.getInterface(), GROUP_IDLE_TIME_S);
1067-
}
10681077
}
10691078

10701079
@Override
@@ -1155,6 +1164,7 @@ public boolean processMessage(Message message) {
11551164

11561165
mGroup = null;
11571166
mWifiNative.p2pFlush();
1167+
mServiceDiscReqId = null;
11581168
if (changed) sendP2pPeersChangedBroadcast();
11591169
transitionTo(mInactiveState);
11601170
break;
@@ -1537,13 +1547,13 @@ private void initializeP2pSettings() {
15371547
mWifiNative.setPersistentReconnect(true);
15381548
mThisDevice.deviceName = getPersistedDeviceName();
15391549
mWifiNative.setDeviceName(mThisDevice.deviceName);
1540-
//DIRECT-XY-DEVICENAME (XY is randomly generated)
1550+
// DIRECT-XY-DEVICENAME (XY is randomly generated)
15411551
mWifiNative.setP2pSsidPostfix("-" + mThisDevice.deviceName);
15421552
mWifiNative.setDeviceType(mThisDevice.primaryDeviceType);
1543-
//The supplicant default is to support everything, but a bug necessitates
1544-
//the framework to specify this explicitly
1545-
mWifiNative.setConfigMethods("keypad display push_button");
1546-
//STA has higher priority over P2P
1553+
// Supplicant defaults to using virtual display with display
1554+
// which refers to a remote display. Use physical_display
1555+
mWifiNative.setConfigMethods("virtual_push_button physical_display keypad");
1556+
// STA has higher priority over P2P
15471557
mWifiNative.setConcurrencyPriority("sta");
15481558

15491559
mThisDevice.deviceAddress = mWifiNative.p2pGetDeviceAddress();
@@ -1567,11 +1577,12 @@ private void handleGroupCreationFailure() {
15671577
/* After cancelling group formation, new connections on existing peers can fail
15681578
* at supplicant. Flush and restart discovery */
15691579
mWifiNative.p2pFlush();
1580+
mServiceDiscReqId = null;
15701581
sendMessage(WifiP2pManager.DISCOVER_PEERS);
15711582
}
15721583

15731584
//State machine initiated requests can have replyTo set to null indicating
1574-
//there are no recepients, we ignore those reply actions
1585+
//there are no recipients, we ignore those reply actions
15751586
private void replyToMessage(Message msg, int what) {
15761587
if (msg.replyTo == null) return;
15771588
Message dstMsg = obtainMessage(msg);
@@ -1650,7 +1661,7 @@ private void clearSupplicantServiceRequest() {
16501661
mServiceDiscReqId = null;
16511662
}
16521663

1653-
/* TODO: We could track individual service adds seperately and avoid
1664+
/* TODO: We could track individual service adds separately and avoid
16541665
* having to do update all service requests on every new request
16551666
*/
16561667
private boolean addServiceRequest(Messenger m, WifiP2pServiceRequest req) {

0 commit comments

Comments
 (0)