Loading wifi/java/android/net/wifi/WifiMonitor.java +10 −2 Original line number Diff line number Diff line Loading @@ -196,7 +196,7 @@ public class WifiMonitor { private static final String P2P_PROV_DISC_SHOW_PIN_STR = "P2P-PROV-DISC-SHOW-PIN"; private static final String HOST_AP_EVENT_PREFIX_STR = "AP"; /* AP-STA-CONNECTED 42:fc:89:a8:96:09 */ /* AP-STA-CONNECTED 42:fc:89:a8:96:09 dev_addr=02:90:4c:a0:92:54 */ private static final String AP_STA_CONNECTED_STR = "AP-STA-CONNECTED"; /* AP-STA-DISCONNECTED 42:fc:89:a8:96:09 */ private static final String AP_STA_DISCONNECTED_STR = "AP-STA-DISCONNECTED"; Loading Loading @@ -504,9 +504,17 @@ public class WifiMonitor { */ private void handleHostApEvents(String dataString) { String[] tokens = dataString.split(" "); /* AP-STA-CONNECTED 42:fc:89:a8:96:09 dev_addr=02:90:4c:a0:92:54 */ if (tokens[0].equals(AP_STA_CONNECTED_STR)) { mStateMachine.sendMessage(AP_STA_CONNECTED_EVENT, tokens[1]); String[] nameValue = tokens[2].split("="); if (nameValue.length != 2) return; WifiP2pDevice device = new WifiP2pDevice(); device.interfaceAddress = tokens[1]; device.deviceAddress = nameValue[1]; mStateMachine.sendMessage(AP_STA_CONNECTED_EVENT, device); /* AP-STA-DISCONNECTED 42:fc:89:a8:96:09 */ } else if (tokens[0].equals(AP_STA_DISCONNECTED_STR)) { //TODO: fix this once wpa_supplicant reports this consistently mStateMachine.sendMessage(AP_STA_DISCONNECTED_EVENT, tokens[1]); } } Loading wifi/java/android/net/wifi/WifiNative.java +3 −1 Original line number Diff line number Diff line Loading @@ -307,9 +307,11 @@ public class WifiNative { 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 = 3; //default value groupOwnerIntent = 7; //default value } args.add("go_intent=" + groupOwnerIntent); Loading wifi/java/android/net/wifi/p2p/WifiP2pDevice.java +4 −4 Original line number Diff line number Diff line Loading @@ -34,12 +34,12 @@ public class WifiP2pDevice implements Parcelable { /** * The device name is a user friendly string to identify a Wi-Fi p2p device */ public String deviceName; public String deviceName = ""; /** * The device MAC address uniquely identifies a Wi-Fi p2p device */ public String deviceAddress; public String deviceAddress = ""; /** * interfaceAddress Loading Loading @@ -134,7 +134,7 @@ public class WifiP2pDevice implements Parcelable { * @hide */ public WifiP2pDevice(String string) throws IllegalArgumentException { String[] tokens = string.split(" "); String[] tokens = string.split("[ \n]"); if (tokens.length < 1) { throw new IllegalArgumentException("Malformed supplicant event"); Loading Loading @@ -166,7 +166,7 @@ public class WifiP2pDevice implements Parcelable { continue; } if (nameValue[0].equals("name")) { if (nameValue[0].equals("name") || nameValue[0].equals("device_name")) { deviceName = trimQuotes(nameValue[1]); continue; } Loading wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java +13 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,19 @@ public class WifiP2pDeviceList implements Parcelable { mDevices.add(device); } /** @hide */ public void updateInterfaceAddress(WifiP2pDevice device) { for (WifiP2pDevice d : mDevices) { //Found, update interface address if (d.equals(device)) { d.interfaceAddress = device.interfaceAddress; return; } } //Not found, add a new one mDevices.add(device); } /** @hide */ public boolean remove(WifiP2pDevice device) { if (device == null) return false; Loading wifi/java/android/net/wifi/p2p/WifiP2pService.java +55 −19 Original line number Diff line number Diff line Loading @@ -727,6 +727,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub { case WifiP2pManager.CONNECT: if (DBG) logd(getName() + " sending connect"); mSavedPeerConfig = (WifiP2pConfig) message.obj; String updatedPeerDetails = WifiNative.p2pPeer(mSavedPeerConfig.deviceAddress); mPeers.update(new WifiP2pDevice(updatedPeerDetails)); mPersistGroup = false; int netId = configuredNetworkId(mSavedPeerConfig.deviceAddress); if (netId >= 0) { Loading @@ -736,13 +738,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { //If peer is a GO, we do not need to send provisional discovery, //the supplicant takes care of it. if (isGroupOwner(mSavedPeerConfig.deviceAddress)) { String pin = WifiNative.p2pConnect(mSavedPeerConfig, JOIN_GROUP); try { Integer.parseInt(pin); notifyInvitationSent(pin, mSavedPeerConfig.deviceAddress); } catch (NumberFormatException ignore) { // do nothing if p2pConnect did not return a pin } p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP); transitionTo(mGroupNegotiationState); } else { transitionTo(mProvisionDiscoveryState); Loading @@ -758,8 +754,27 @@ public class WifiP2pService extends IWifiP2pManager.Stub { break; case WifiMonitor.P2P_INVITATION_RECEIVED_EVENT: WifiP2pGroup group = (WifiP2pGroup) message.obj; //TODO: fix p2p invitation to handle as a regular config //and update mSavedPeerConfig WifiP2pDevice owner = group.getOwner(); if (owner == null) { if (DBG) loge("Ignored invitation from null owner"); break; } mSavedPeerConfig = new WifiP2pConfig(); mSavedPeerConfig.deviceAddress = group.getOwner().deviceAddress; //Check if we have the owner in peer list and use appropriate //wps method. Default is to use PBC. if ((owner = getDeviceFromPeerList(owner.deviceAddress)) != null) { if (owner.wpsPbcSupported()) { mSavedPeerConfig.wps.setup = WpsInfo.PBC; } else if (owner.wpsKeypadSupported()) { mSavedPeerConfig.wps.setup = WpsInfo.KEYPAD; } else if (owner.wpsDisplaySupported()) { mSavedPeerConfig.wps.setup = WpsInfo.DISPLAY; } } transitionTo(mUserAuthorizingInvitationState); break; case WifiMonitor.P2P_PROV_DISC_PBC_REQ_EVENT: Loading Loading @@ -853,9 +868,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub { case PEER_CONNECTION_USER_ACCEPT: //TODO: handle persistence if (isGroupOwner(mSavedPeerConfig.deviceAddress)) { WifiNative.p2pConnect(mSavedPeerConfig, JOIN_GROUP); p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP); } else { WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP); p2pConnectWithPinDisplay(mSavedPeerConfig, FORM_GROUP); } updateDeviceStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.INVITED); sendP2pPeersChangedBroadcast(); Loading Loading @@ -1007,20 +1022,22 @@ public class WifiP2pService extends IWifiP2pManager.Stub { if (DBG) logd(getName() + message.toString()); switch (message.what) { case WifiMonitor.AP_STA_CONNECTED_EVENT: //After a GO setup, STA connected event comes with interface address String interfaceAddress = (String) message.obj; String deviceAddress = getDeviceAddress(interfaceAddress); WifiP2pDevice device = (WifiP2pDevice) message.obj; String deviceAddress = device.deviceAddress; if (deviceAddress != null) { mGroup.addClient(deviceAddress); mPeers.updateInterfaceAddress(device); updateDeviceStatus(deviceAddress, WifiP2pDevice.CONNECTED); if (DBG) logd(getName() + " ap sta connected"); sendP2pPeersChangedBroadcast(); } else { loge("Connect on unknown device address : " + interfaceAddress); loge("Connect on null device address, ignore"); } break; case WifiMonitor.AP_STA_DISCONNECTED_EVENT: interfaceAddress = (String) message.obj; //TODO: the disconnection event is still inconsistent and reports //interface address. Fix this after wpa_supplicant is fixed. String interfaceAddress = (String) message.obj; deviceAddress = getDeviceAddress(interfaceAddress); if (deviceAddress != null) { updateDeviceStatus(deviceAddress, WifiP2pDevice.AVAILABLE); Loading @@ -1039,7 +1056,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { sendP2pPeersChangedBroadcast(); if (DBG) loge(getName() + " ap sta disconnected"); } else { loge("Disconnect on unknown device address : " + interfaceAddress); loge("Disconnect on unknown interface address : " + interfaceAddress); } break; case DhcpStateMachine.CMD_POST_DHCP_ACTION: Loading Loading @@ -1087,7 +1104,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { transitionTo(mInactiveState); break; case WifiMonitor.P2P_DEVICE_LOST_EVENT: WifiP2pDevice device = (WifiP2pDevice) message.obj; device = (WifiP2pDevice) message.obj; //Device loss for a connected device indicates it is not in discovery any more if (mGroup.contains(device)) { if (DBG) logd("Lost " + device +" , do nothing"); Loading Loading @@ -1388,13 +1405,32 @@ public class WifiP2pService extends IWifiP2pManager.Stub { private String getDeviceAddress(String interfaceAddress) { for (WifiP2pDevice d : mPeers.getDeviceList()) { if (interfaceAddress.equals(WifiNative.p2pGetInterfaceAddress(d.deviceAddress))) { if (interfaceAddress.equals(d.interfaceAddress)) { return d.deviceAddress; } } return null; } private WifiP2pDevice getDeviceFromPeerList(String deviceAddress) { for (WifiP2pDevice d : mPeers.getDeviceList()) { if (d.deviceAddress.equals(deviceAddress)) { return d; } } return null; } private void p2pConnectWithPinDisplay(WifiP2pConfig config, boolean join) { String pin = WifiNative.p2pConnect(config, join); try { Integer.parseInt(pin); notifyInvitationSent(pin, config.deviceAddress); } catch (NumberFormatException ignore) { // do nothing if p2pConnect did not return a pin } } private void initializeP2pSettings() { WifiNative.setPersistentReconnect(true); WifiNative.setDeviceName(mThisDevice.deviceName); Loading Loading
wifi/java/android/net/wifi/WifiMonitor.java +10 −2 Original line number Diff line number Diff line Loading @@ -196,7 +196,7 @@ public class WifiMonitor { private static final String P2P_PROV_DISC_SHOW_PIN_STR = "P2P-PROV-DISC-SHOW-PIN"; private static final String HOST_AP_EVENT_PREFIX_STR = "AP"; /* AP-STA-CONNECTED 42:fc:89:a8:96:09 */ /* AP-STA-CONNECTED 42:fc:89:a8:96:09 dev_addr=02:90:4c:a0:92:54 */ private static final String AP_STA_CONNECTED_STR = "AP-STA-CONNECTED"; /* AP-STA-DISCONNECTED 42:fc:89:a8:96:09 */ private static final String AP_STA_DISCONNECTED_STR = "AP-STA-DISCONNECTED"; Loading Loading @@ -504,9 +504,17 @@ public class WifiMonitor { */ private void handleHostApEvents(String dataString) { String[] tokens = dataString.split(" "); /* AP-STA-CONNECTED 42:fc:89:a8:96:09 dev_addr=02:90:4c:a0:92:54 */ if (tokens[0].equals(AP_STA_CONNECTED_STR)) { mStateMachine.sendMessage(AP_STA_CONNECTED_EVENT, tokens[1]); String[] nameValue = tokens[2].split("="); if (nameValue.length != 2) return; WifiP2pDevice device = new WifiP2pDevice(); device.interfaceAddress = tokens[1]; device.deviceAddress = nameValue[1]; mStateMachine.sendMessage(AP_STA_CONNECTED_EVENT, device); /* AP-STA-DISCONNECTED 42:fc:89:a8:96:09 */ } else if (tokens[0].equals(AP_STA_DISCONNECTED_STR)) { //TODO: fix this once wpa_supplicant reports this consistently mStateMachine.sendMessage(AP_STA_DISCONNECTED_EVENT, tokens[1]); } } Loading
wifi/java/android/net/wifi/WifiNative.java +3 −1 Original line number Diff line number Diff line Loading @@ -307,9 +307,11 @@ public class WifiNative { 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 = 3; //default value groupOwnerIntent = 7; //default value } args.add("go_intent=" + groupOwnerIntent); Loading
wifi/java/android/net/wifi/p2p/WifiP2pDevice.java +4 −4 Original line number Diff line number Diff line Loading @@ -34,12 +34,12 @@ public class WifiP2pDevice implements Parcelable { /** * The device name is a user friendly string to identify a Wi-Fi p2p device */ public String deviceName; public String deviceName = ""; /** * The device MAC address uniquely identifies a Wi-Fi p2p device */ public String deviceAddress; public String deviceAddress = ""; /** * interfaceAddress Loading Loading @@ -134,7 +134,7 @@ public class WifiP2pDevice implements Parcelable { * @hide */ public WifiP2pDevice(String string) throws IllegalArgumentException { String[] tokens = string.split(" "); String[] tokens = string.split("[ \n]"); if (tokens.length < 1) { throw new IllegalArgumentException("Malformed supplicant event"); Loading Loading @@ -166,7 +166,7 @@ public class WifiP2pDevice implements Parcelable { continue; } if (nameValue[0].equals("name")) { if (nameValue[0].equals("name") || nameValue[0].equals("device_name")) { deviceName = trimQuotes(nameValue[1]); continue; } Loading
wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java +13 −0 Original line number Diff line number Diff line Loading @@ -79,6 +79,19 @@ public class WifiP2pDeviceList implements Parcelable { mDevices.add(device); } /** @hide */ public void updateInterfaceAddress(WifiP2pDevice device) { for (WifiP2pDevice d : mDevices) { //Found, update interface address if (d.equals(device)) { d.interfaceAddress = device.interfaceAddress; return; } } //Not found, add a new one mDevices.add(device); } /** @hide */ public boolean remove(WifiP2pDevice device) { if (device == null) return false; Loading
wifi/java/android/net/wifi/p2p/WifiP2pService.java +55 −19 Original line number Diff line number Diff line Loading @@ -727,6 +727,8 @@ public class WifiP2pService extends IWifiP2pManager.Stub { case WifiP2pManager.CONNECT: if (DBG) logd(getName() + " sending connect"); mSavedPeerConfig = (WifiP2pConfig) message.obj; String updatedPeerDetails = WifiNative.p2pPeer(mSavedPeerConfig.deviceAddress); mPeers.update(new WifiP2pDevice(updatedPeerDetails)); mPersistGroup = false; int netId = configuredNetworkId(mSavedPeerConfig.deviceAddress); if (netId >= 0) { Loading @@ -736,13 +738,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { //If peer is a GO, we do not need to send provisional discovery, //the supplicant takes care of it. if (isGroupOwner(mSavedPeerConfig.deviceAddress)) { String pin = WifiNative.p2pConnect(mSavedPeerConfig, JOIN_GROUP); try { Integer.parseInt(pin); notifyInvitationSent(pin, mSavedPeerConfig.deviceAddress); } catch (NumberFormatException ignore) { // do nothing if p2pConnect did not return a pin } p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP); transitionTo(mGroupNegotiationState); } else { transitionTo(mProvisionDiscoveryState); Loading @@ -758,8 +754,27 @@ public class WifiP2pService extends IWifiP2pManager.Stub { break; case WifiMonitor.P2P_INVITATION_RECEIVED_EVENT: WifiP2pGroup group = (WifiP2pGroup) message.obj; //TODO: fix p2p invitation to handle as a regular config //and update mSavedPeerConfig WifiP2pDevice owner = group.getOwner(); if (owner == null) { if (DBG) loge("Ignored invitation from null owner"); break; } mSavedPeerConfig = new WifiP2pConfig(); mSavedPeerConfig.deviceAddress = group.getOwner().deviceAddress; //Check if we have the owner in peer list and use appropriate //wps method. Default is to use PBC. if ((owner = getDeviceFromPeerList(owner.deviceAddress)) != null) { if (owner.wpsPbcSupported()) { mSavedPeerConfig.wps.setup = WpsInfo.PBC; } else if (owner.wpsKeypadSupported()) { mSavedPeerConfig.wps.setup = WpsInfo.KEYPAD; } else if (owner.wpsDisplaySupported()) { mSavedPeerConfig.wps.setup = WpsInfo.DISPLAY; } } transitionTo(mUserAuthorizingInvitationState); break; case WifiMonitor.P2P_PROV_DISC_PBC_REQ_EVENT: Loading Loading @@ -853,9 +868,9 @@ public class WifiP2pService extends IWifiP2pManager.Stub { case PEER_CONNECTION_USER_ACCEPT: //TODO: handle persistence if (isGroupOwner(mSavedPeerConfig.deviceAddress)) { WifiNative.p2pConnect(mSavedPeerConfig, JOIN_GROUP); p2pConnectWithPinDisplay(mSavedPeerConfig, JOIN_GROUP); } else { WifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP); p2pConnectWithPinDisplay(mSavedPeerConfig, FORM_GROUP); } updateDeviceStatus(mSavedPeerConfig.deviceAddress, WifiP2pDevice.INVITED); sendP2pPeersChangedBroadcast(); Loading Loading @@ -1007,20 +1022,22 @@ public class WifiP2pService extends IWifiP2pManager.Stub { if (DBG) logd(getName() + message.toString()); switch (message.what) { case WifiMonitor.AP_STA_CONNECTED_EVENT: //After a GO setup, STA connected event comes with interface address String interfaceAddress = (String) message.obj; String deviceAddress = getDeviceAddress(interfaceAddress); WifiP2pDevice device = (WifiP2pDevice) message.obj; String deviceAddress = device.deviceAddress; if (deviceAddress != null) { mGroup.addClient(deviceAddress); mPeers.updateInterfaceAddress(device); updateDeviceStatus(deviceAddress, WifiP2pDevice.CONNECTED); if (DBG) logd(getName() + " ap sta connected"); sendP2pPeersChangedBroadcast(); } else { loge("Connect on unknown device address : " + interfaceAddress); loge("Connect on null device address, ignore"); } break; case WifiMonitor.AP_STA_DISCONNECTED_EVENT: interfaceAddress = (String) message.obj; //TODO: the disconnection event is still inconsistent and reports //interface address. Fix this after wpa_supplicant is fixed. String interfaceAddress = (String) message.obj; deviceAddress = getDeviceAddress(interfaceAddress); if (deviceAddress != null) { updateDeviceStatus(deviceAddress, WifiP2pDevice.AVAILABLE); Loading @@ -1039,7 +1056,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { sendP2pPeersChangedBroadcast(); if (DBG) loge(getName() + " ap sta disconnected"); } else { loge("Disconnect on unknown device address : " + interfaceAddress); loge("Disconnect on unknown interface address : " + interfaceAddress); } break; case DhcpStateMachine.CMD_POST_DHCP_ACTION: Loading Loading @@ -1087,7 +1104,7 @@ public class WifiP2pService extends IWifiP2pManager.Stub { transitionTo(mInactiveState); break; case WifiMonitor.P2P_DEVICE_LOST_EVENT: WifiP2pDevice device = (WifiP2pDevice) message.obj; device = (WifiP2pDevice) message.obj; //Device loss for a connected device indicates it is not in discovery any more if (mGroup.contains(device)) { if (DBG) logd("Lost " + device +" , do nothing"); Loading Loading @@ -1388,13 +1405,32 @@ public class WifiP2pService extends IWifiP2pManager.Stub { private String getDeviceAddress(String interfaceAddress) { for (WifiP2pDevice d : mPeers.getDeviceList()) { if (interfaceAddress.equals(WifiNative.p2pGetInterfaceAddress(d.deviceAddress))) { if (interfaceAddress.equals(d.interfaceAddress)) { return d.deviceAddress; } } return null; } private WifiP2pDevice getDeviceFromPeerList(String deviceAddress) { for (WifiP2pDevice d : mPeers.getDeviceList()) { if (d.deviceAddress.equals(deviceAddress)) { return d; } } return null; } private void p2pConnectWithPinDisplay(WifiP2pConfig config, boolean join) { String pin = WifiNative.p2pConnect(config, join); try { Integer.parseInt(pin); notifyInvitationSent(pin, config.deviceAddress); } catch (NumberFormatException ignore) { // do nothing if p2pConnect did not return a pin } } private void initializeP2pSettings() { WifiNative.setPersistentReconnect(true); WifiNative.setDeviceName(mThisDevice.deviceName); Loading