diff options
author | Etan Cohen <etancohen@google.com> | 2017-07-14 22:15:03 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-07-14 22:15:03 +0000 |
commit | 65af05ee2ee44aeb56d42790c80c003b82f4ea55 (patch) | |
tree | 1879ae2732e3700ea14e414807565f74a130e67b /service | |
parent | ec0922425c007ba22527e0cacad1445d5f0d0ad8 (diff) | |
parent | 3dd02f1e60b930f59d33c462aa2daefb4baf65e5 (diff) |
Merge changes I3934b68b,Ic1b3a97b into oc-dr1-dev
* changes:
[AWARE] Restrict number of data interfaces and paths
[AWARE] Create a locally maintained peer ID instead of firmware ID
Diffstat (limited to 'service')
4 files changed, 84 insertions, 35 deletions
diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java index ca12d5d52..558274c8d 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareDataPathStateManager.java @@ -635,6 +635,14 @@ public class WifiAwareDataPathStateManager { + " - can't parse network specifier"); return false; } + + // TODO (b/63635780) support more then a single concurrent NDP + if (mNetworkRequestsCache.size() > 0) { + Log.e(TAG, "WifiAwareNetworkFactory.acceptRequest: request=" + request + + " - >1 concurrent NDPs aren't supported (yet)."); + return false; + } + mNetworkRequestsCache.put(networkSpecifier, nnri); return true; @@ -673,7 +681,7 @@ public class WifiAwareDataPathStateManager { } nnri.interfaceName = selectInterfaceForRequest(nnri); - mMgr.initiateDataPathSetup(networkSpecifier, nnri.networkSpecifier.peerId, + mMgr.initiateDataPathSetup(networkSpecifier, nnri.peerInstanceId, NanDataPathChannelCfg.CHANNEL_NOT_REQUESTED, selectChannelForRequest(nnri), nnri.peerDiscoveryMac, nnri.interfaceName, nnri.networkSpecifier.pmk, nnri.networkSpecifier.passphrase, nnri.networkSpecifier.isOutOfBand()); @@ -846,6 +854,7 @@ public class WifiAwareDataPathStateManager { public int uid; public String interfaceName; public int pubSubId = 0; + public int peerInstanceId = 0; public byte[] peerDiscoveryMac = null; public int ndpId; public byte[] peerDataMac; @@ -857,6 +866,7 @@ public class WifiAwareDataPathStateManager { static AwareNetworkRequestInformation processNetworkSpecifier(WifiAwareNetworkSpecifier ns, WifiAwareStateManager mgr, WifiPermissionsWrapper permissionWrapper) { int uid, pubSubId = 0; + int peerInstanceId = 0; byte[] peerMac = ns.peerMac; if (VDBG) { @@ -919,15 +929,17 @@ public class WifiAwareDataPathStateManager { if (ns.type == WifiAwareNetworkSpecifier.NETWORK_SPECIFIER_TYPE_IB) { pubSubId = session.getPubSubId(); - String peerMacStr = session.getMac(ns.peerId, null); - if (peerMacStr == null) { + WifiAwareDiscoverySessionState.PeerInfo peerInfo = session.getPeerInfo( + ns.peerId); + if (peerInfo == null) { Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns - + " -- no MAC address associated with this peer id -- peerId=" + + " -- no peer info associated with this peer id -- peerId=" + ns.peerId); return null; } + peerInstanceId = peerInfo.mInstanceId; try { - peerMac = HexEncoding.decode(peerMacStr.toCharArray(), false); + peerMac = peerInfo.mMac; if (peerMac == null || peerMac.length != 6) { Log.e(TAG, "processNetworkSpecifier: networkSpecifier=" + ns + " -- invalid peer MAC address"); @@ -979,6 +991,7 @@ public class WifiAwareDataPathStateManager { : AwareNetworkRequestInformation.STATE_RESPONDER_IDLE; nnri.uid = uid; nnri.pubSubId = pubSubId; + nnri.peerInstanceId = peerInstanceId; nnri.peerDiscoveryMac = peerMac; nnri.networkSpecifier = ns; @@ -990,7 +1003,8 @@ public class WifiAwareDataPathStateManager { StringBuilder sb = new StringBuilder("AwareNetworkRequestInformation: "); sb.append("state=").append(state).append(", ns=").append(networkSpecifier).append( ", uid=").append(uid).append(", interfaceName=").append(interfaceName).append( - ", pubSubId=").append(pubSubId).append(", peerDiscoveryMac=").append( + ", pubSubId=").append(pubSubId).append(", peerInstanceId=").append( + peerInstanceId).append(", peerDiscoveryMac=").append( peerDiscoveryMac == null ? "" : String.valueOf(HexEncoding.encode(peerDiscoveryMac))).append( ", ndpId=").append(ndpId).append(", peerDataMac=").append( diff --git a/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java b/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java index ac3dee414..86f4e37c2 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareDiscoverySessionState.java @@ -28,6 +28,7 @@ import libcore.util.HexEncoding; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.Arrays; /** * Manages the state of a single Aware discovery session (publish or subscribe). @@ -40,6 +41,8 @@ public class WifiAwareDiscoverySessionState { private static final boolean DBG = false; private static final boolean VDBG = false; // STOPSHIP if true + private int mNextPeerIdToBeAllocated = 100; // used to create a unique peer ID + private final WifiAwareNativeApi mWifiAwareNativeApi; private int mSessionId; private byte mPubSubId; @@ -47,7 +50,24 @@ public class WifiAwareDiscoverySessionState { private boolean mIsPublishSession; private final long mCreationTime; - private final SparseArray<String> mMacByRequestorInstanceId = new SparseArray<>(); + static class PeerInfo { + PeerInfo(int instanceId, byte[] mac) { + mInstanceId = instanceId; + mMac = mac; + } + + int mInstanceId; + byte[] mMac; + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("instanceId ["); + sb.append(mInstanceId).append(", mac=").append(HexEncoding.encode(mMac)).append("]"); + return sb.toString(); + } + } + + private final SparseArray<PeerInfo> mPeerInfoByRequestorInstanceId = new SparseArray<>(); public WifiAwareDiscoverySessionState(WifiAwareNativeApi wifiAwareNativeApi, int sessionId, byte pubSubId, IWifiAwareDiscoverySessionCallback callback, boolean isPublishSession, @@ -81,16 +101,11 @@ public class WifiAwareDiscoverySessionState { } /** - * Return the MAC address (String) of the specified peer ID - or a null if no such address is + * Return the peer information of the specified peer ID - or a null if no such peer ID is * registered. */ - public String getMac(int peerId, String sep) { - String mac = mMacByRequestorInstanceId.get(peerId); - if (mac != null && sep != null && !sep.isEmpty()) { - mac = new StringBuilder(mac).insert(10, sep).insert(8, sep).insert(6, sep) - .insert(4, sep).insert(2, sep).toString(); - } - return mac; + public PeerInfo getPeerInfo(int peerId) { + return mPeerInfoByRequestorInstanceId.get(peerId); } /** @@ -190,8 +205,8 @@ public class WifiAwareDiscoverySessionState { * callbacks related to the message (success/failure). */ public boolean sendMessage(short transactionId, int peerId, byte[] message, int messageId) { - String peerMacStr = mMacByRequestorInstanceId.get(peerId); - if (peerMacStr == null) { + PeerInfo peerInfo = mPeerInfoByRequestorInstanceId.get(peerId); + if (peerInfo == null) { Log.e(TAG, "sendMessage: attempting to send a message to an address which didn't " + "match/contact us"); try { @@ -201,10 +216,9 @@ public class WifiAwareDiscoverySessionState { } return false; } - byte[] peerMac = HexEncoding.decode(peerMacStr.toCharArray(), false); - boolean success = mWifiAwareNativeApi.sendMessage(transactionId, mPubSubId, peerId, peerMac, - message, messageId); + boolean success = mWifiAwareNativeApi.sendMessage(transactionId, mPubSubId, + peerInfo.mInstanceId, peerInfo.mMac, message, messageId); if (!success) { try { mCallback.onMessageSendFail(messageId, NanStatusType.INTERNAL_FAILURE); @@ -233,13 +247,10 @@ public class WifiAwareDiscoverySessionState { */ public void onMatch(int requestorInstanceId, byte[] peerMac, byte[] serviceSpecificInfo, byte[] matchFilter) { - String prevMac = mMacByRequestorInstanceId.get(requestorInstanceId); - mMacByRequestorInstanceId.put(requestorInstanceId, new String(HexEncoding.encode(peerMac))); - - if (DBG) Log.d(TAG, "onMatch: previous peer MAC replaced - " + prevMac); + int peerId = getPeerIdOrAddIfNew(requestorInstanceId, peerMac); try { - mCallback.onMatch(requestorInstanceId, serviceSpecificInfo, matchFilter); + mCallback.onMatch(peerId, serviceSpecificInfo, matchFilter); } catch (RemoteException e) { Log.w(TAG, "onMatch: RemoteException (FYI): " + e); } @@ -256,20 +267,35 @@ public class WifiAwareDiscoverySessionState { * @param message The received message. */ public void onMessageReceived(int requestorInstanceId, byte[] peerMac, byte[] message) { - String prevMac = mMacByRequestorInstanceId.get(requestorInstanceId); - mMacByRequestorInstanceId.put(requestorInstanceId, new String(HexEncoding.encode(peerMac))); - - if (DBG) { - Log.d(TAG, "onMessageReceived: previous peer MAC replaced - " + prevMac); - } + int peerId = getPeerIdOrAddIfNew(requestorInstanceId, peerMac); try { - mCallback.onMessageReceived(requestorInstanceId, message); + mCallback.onMessageReceived(peerId, message); } catch (RemoteException e) { Log.w(TAG, "onMessageReceived: RemoteException (FYI): " + e); } } + private int getPeerIdOrAddIfNew(int requestorInstanceId, byte[] peerMac) { + for (int i = 0; i < mPeerInfoByRequestorInstanceId.size(); ++i) { + PeerInfo peerInfo = mPeerInfoByRequestorInstanceId.valueAt(i); + if (peerInfo.mInstanceId == requestorInstanceId && Arrays.equals(peerMac, + peerInfo.mMac)) { + return mPeerInfoByRequestorInstanceId.keyAt(i); + } + } + + int newPeerId = mNextPeerIdToBeAllocated++; + PeerInfo newPeerInfo = new PeerInfo(requestorInstanceId, peerMac); + mPeerInfoByRequestorInstanceId.put(newPeerId, newPeerInfo); + + if (DBG) { + Log.d(TAG, "New peer info: peerId=" + newPeerId + ", peerInfo=" + newPeerInfo); + } + + return newPeerId; + } + /** * Dump the internal state of the class. */ @@ -278,6 +304,6 @@ public class WifiAwareDiscoverySessionState { pw.println(" mSessionId: " + mSessionId); pw.println(" mIsPublishSession: " + mIsPublishSession); pw.println(" mPubSubId: " + mPubSubId); - pw.println(" mMacByRequestorInstanceId: [" + mMacByRequestorInstanceId + "]"); + pw.println(" mPeerInfoByRequestorInstanceId: [" + mPeerInfoByRequestorInstanceId + "]"); } } diff --git a/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java b/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java index 35773210b..6fdcc36c6 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareNativeCallback.java @@ -167,6 +167,11 @@ public class WifiAwareNativeCallback extends IWifiNanIfaceEventCallback.Stub imp capabilities.maxSubscribeInterfaceAddresses; frameworkCapabilities.supportedCipherSuites = capabilities.supportedCipherSuites; + // TODO (b/63635780, b/63635857): enable framework support of >1 NDI and >1 NDP per NDI + // Until then: force corresponding capabilities to 1. + frameworkCapabilities.maxNdiInterfaces = 1; + frameworkCapabilities.maxNdpSessions = 1; + mWifiAwareStateManager.onCapabilitiesUpdateResponse(id, frameworkCapabilities); } else { Log.e(TAG, "notifyCapabilitiesResponse: error code=" + status.status + " (" diff --git a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java index aa5a426ed..30aa42a26 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareStateManager.java @@ -48,6 +48,7 @@ import com.android.internal.util.MessageUtils; import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.internal.util.WakeupMessage; +import com.android.server.wifi.util.NativeUtil; import com.android.server.wifi.util.WifiPermissionsWrapper; import libcore.util.HexEncoding; @@ -2332,10 +2333,13 @@ public class WifiAwareStateManager implements WifiAwareShellCommand.DelegatedShe for (RttManager.RttParams param : params) { String peerIdStr = param.bssid; try { - param.bssid = session.getMac(Integer.parseInt(peerIdStr), ":"); - if (param.bssid == null) { + WifiAwareDiscoverySessionState.PeerInfo peerInfo = session.getPeerInfo( + Integer.parseInt(peerIdStr)); + if (peerInfo == null || peerInfo.mMac == null) { Log.d(TAG, "startRangingLocal: no MAC address for peer ID=" + peerIdStr); param.bssid = ""; + } else { + param.bssid = NativeUtil.macAddressFromByteArray(peerInfo.mMac); } } catch (NumberFormatException e) { Log.e(TAG, "startRangingLocal: invalid peer ID specification (in bssid field): '" |