diff options
| author | 2018-04-16 20:15:12 +0900 | |
|---|---|---|
| committer | 2018-04-19 21:28:43 +0900 | |
| commit | bb2193bf5877b7a93aebefdb74a8c7f410a17907 (patch) | |
| tree | ac32a4ba2f7bf242aa61bb2e5706ac82e9eea6e8 | |
| parent | 8182e354d84a0cdf92458b268f96c28d2dce3cb6 (diff) | |
Add support for reading a snapshot of the APF data
No functional change yet, since startReadPacketFilter() has no callers
at this time. In the future, this new hook will be used to take
periodic snapshots of the APF memory (for instance, when the device
wakes up).
Design note: WifiStateMachine grabs the APF data synchronously
from another thread, but then the data snapshot is delivered to IpClient
via an asynchronous reply, following the same pattern used by other
commands. This means that there's no (practical) way for IpClient to
read the APF data just before replacing the APF program.
Even with this limitation, it's still possible to reliably decode packet
counters and compute deltas relative to the last snapshot, provided that
the address range isn't cleared when installing a new APF filter.
Bug: 73804303
Test: Manual - called the new code and inspected 'dumpsys wifi' output.
Change-Id: Ia0923d71cf3ee4128fb1c381557316300adac1a3
| -rw-r--r-- | services/net/java/android/net/ip/IpClient.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/services/net/java/android/net/ip/IpClient.java b/services/net/java/android/net/ip/IpClient.java index 87249dfc925f..9fdb31e11f50 100644 --- a/services/net/java/android/net/ip/IpClient.java +++ b/services/net/java/android/net/ip/IpClient.java @@ -16,6 +16,7 @@ package android.net.ip; +import com.android.internal.util.HexDump; import com.android.internal.util.MessageUtils; import com.android.internal.util.WakeupMessage; @@ -142,6 +143,12 @@ public class IpClient extends StateMachine { // Install an APF program to filter incoming packets. public void installPacketFilter(byte[] filter) {} + // Asynchronously read back the APF program & data buffer from the wifi driver. + // Due to Wifi HAL limitations, the current implementation only supports dumping the entire + // buffer. In response to this request, the driver returns the data buffer asynchronously + // by sending an IpClient#EVENT_READ_PACKET_FILTER_COMPLETE message. + public void startReadPacketFilter() {} + // If multicast filtering cannot be accomplished with APF, this function will be called to // actuate multicast filtering using another means. public void setFallbackMulticastFilter(boolean enabled) {} @@ -248,6 +255,11 @@ public class IpClient extends StateMachine { log("installPacketFilter(byte[" + filter.length + "])"); } @Override + public void startReadPacketFilter() { + mCallback.startReadPacketFilter(); + log("startReadPacketFilter()"); + } + @Override public void setFallbackMulticastFilter(boolean enabled) { mCallback.setFallbackMulticastFilter(enabled); log("setFallbackMulticastFilter(" + enabled + ")"); @@ -559,6 +571,7 @@ public class IpClient extends StateMachine { private static final int CMD_SET_MULTICAST_FILTER = 9; private static final int EVENT_PROVISIONING_TIMEOUT = 10; private static final int EVENT_DHCPACTION_TIMEOUT = 11; + private static final int EVENT_READ_PACKET_FILTER_COMPLETE = 12; private static final int MAX_LOG_RECORDS = 500; private static final int MAX_PACKET_RECORDS = 100; @@ -611,6 +624,7 @@ public class IpClient extends StateMachine { private ApfFilter mApfFilter; private boolean mMulticastFiltering; private long mStartTimeMillis; + private byte[] mApfDataSnapshot; public static class Dependencies { public INetworkManagementService getNMS() { @@ -823,6 +837,10 @@ public class IpClient extends StateMachine { sendMessage(EVENT_PRE_DHCP_ACTION_COMPLETE); } + public void readPacketFilterComplete(byte[] data) { + sendMessage(EVENT_READ_PACKET_FILTER_COMPLETE, data); + } + /** * Set the TCP buffer sizes to use. * @@ -863,6 +881,7 @@ public class IpClient extends StateMachine { final ProvisioningConfiguration provisioningConfig = mConfiguration; final ApfCapabilities apfCapabilities = (provisioningConfig != null) ? provisioningConfig.mApfCapabilities : null; + final byte[] apfDataSnapshot = mApfDataSnapshot; IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); pw.println(mTag + " APF dump:"); @@ -880,6 +899,14 @@ public class IpClient extends StateMachine { } } pw.decreaseIndent(); + pw.println(mTag + " latest APF data snapshot: "); + pw.increaseIndent(); + if (apfDataSnapshot != null) { + pw.println(HexDump.dumpHexString(apfDataSnapshot)); + } else { + pw.println("No last snapshot."); + } + pw.decreaseIndent(); pw.println(); pw.println(mTag + " current ProvisioningConfiguration:"); @@ -1676,6 +1703,11 @@ public class IpClient extends StateMachine { break; } + case EVENT_READ_PACKET_FILTER_COMPLETE: { + mApfDataSnapshot = (byte[]) msg.obj; + break; + } + case EVENT_DHCPACTION_TIMEOUT: stopDhcpAction(); break; |