diff options
author | Glen Kuhne <kuh@google.com> | 2017-05-12 03:07:45 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-12 03:07:45 +0000 |
commit | d8c6cda12ac48ab79c12898fa7391d3f1a98c41f (patch) | |
tree | 55b3814dafeccd51dbc57c6804c57ab309d0ff10 /service | |
parent | b35914a00f01c79164264b53b3d81c2e83b292ee (diff) | |
parent | 88d77863cb2caeb3a994f7931a08bded96efa71b (diff) |
Merge "P2P: handle null p2p_dev_address sta auth/deauth" into oc-dev
am: 88d77863cb
Change-Id: Ie17920b067c19e9e417757462984e5a574230517
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java | 33 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/util/NativeUtil.java | 2 |
2 files changed, 24 insertions, 11 deletions
diff --git a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java index 1d106c066..56d5fc8d3 100644 --- a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java +++ b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceCallback.java @@ -33,6 +33,7 @@ import com.android.server.wifi.util.NativeUtil; import libcore.util.HexEncoding; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -462,6 +463,24 @@ public class SupplicantP2pIfaceCallback extends ISupplicantP2pIfaceCallback.Stub mMonitor.broadcastP2pServiceDiscoveryResponse(mInterface, response); } + private WifiP2pDevice createStaEventDevice(byte[] srcAddress, byte[] p2pDeviceAddress) { + WifiP2pDevice device = new WifiP2pDevice(); + byte[] deviceAddressBytes; + // Legacy STAs may not supply a p2pDeviceAddress (signaled by a zero'd p2pDeviceAddress) + // In this case, use srcAddress instead + if (!Arrays.equals(NativeUtil.ANY_MAC_BYTES, p2pDeviceAddress)) { + deviceAddressBytes = p2pDeviceAddress; + } else { + deviceAddressBytes = srcAddress; + } + try { + device.deviceAddress = NativeUtil.macAddressFromByteArray(deviceAddressBytes); + } catch (Exception e) { + Log.e(TAG, "Could not decode MAC address", e); + return null; + } + return device; + } /** * Used to indicate when a STA device is connected to this device. @@ -471,11 +490,8 @@ public class SupplicantP2pIfaceCallback extends ISupplicantP2pIfaceCallback.Stub */ public void onStaAuthorized(byte[] srcAddress, byte[] p2pDeviceAddress) { logd("STA authorized on " + mInterface); - WifiP2pDevice device = new WifiP2pDevice(); - try { - device.deviceAddress = NativeUtil.macAddressFromByteArray(p2pDeviceAddress); - } catch (Exception e) { - Log.e(TAG, "Could not decode MAC address.", e); + WifiP2pDevice device = createStaEventDevice(srcAddress, p2pDeviceAddress); + if (device == null) { return; } mMonitor.broadcastP2pApStaConnected(mInterface, device); @@ -490,11 +506,8 @@ public class SupplicantP2pIfaceCallback extends ISupplicantP2pIfaceCallback.Stub */ public void onStaDeauthorized(byte[] srcAddress, byte[] p2pDeviceAddress) { logd("STA deauthorized on " + mInterface); - WifiP2pDevice device = new WifiP2pDevice(); - try { - device.deviceAddress = NativeUtil.macAddressFromByteArray(p2pDeviceAddress); - } catch (Exception e) { - Log.e(TAG, "Could not decode MAC address.", e); + WifiP2pDevice device = createStaEventDevice(srcAddress, p2pDeviceAddress); + if (device == null) { return; } mMonitor.broadcastP2pApStaDisconnected(mInterface, device); diff --git a/service/java/com/android/server/wifi/util/NativeUtil.java b/service/java/com/android/server/wifi/util/NativeUtil.java index a13b682a0..07c3f9b38 100644 --- a/service/java/com/android/server/wifi/util/NativeUtil.java +++ b/service/java/com/android/server/wifi/util/NativeUtil.java @@ -36,7 +36,7 @@ import java.util.ArrayList; */ public class NativeUtil { private static final String ANY_MAC_STR = "any"; - private static final byte[] ANY_MAC_BYTES = {0, 0, 0, 0, 0, 0}; + public static final byte[] ANY_MAC_BYTES = {0, 0, 0, 0, 0, 0}; private static final int MAC_LENGTH = 6; private static final int MAC_OUI_LENGTH = 3; private static final int MAC_STR_LENGTH = MAC_LENGTH * 2 + 5; |