Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 40b43542 authored by Bernie Innocenti's avatar Bernie Innocenti
Browse files

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
Merged-In: Ia0923d71cf3ee4128fb1c381557316300adac1a3
Merged-In: I3b940f5a3b795f85d244882eaa7eca56bd9e167d
Merged-In: I283fd5fb71f8a679911e58c487a4ac12a5190049
(cherry picked from commit bb2193bf)
parent 7e8c166d
Loading
Loading
Loading
Loading
+32 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package android.net.ip;
package android.net.ip;


import com.android.internal.util.HexDump;
import com.android.internal.util.MessageUtils;
import com.android.internal.util.MessageUtils;
import com.android.internal.util.WakeupMessage;
import com.android.internal.util.WakeupMessage;


@@ -174,6 +175,12 @@ public class IpClient extends StateMachine {
        // Install an APF program to filter incoming packets.
        // Install an APF program to filter incoming packets.
        public void installPacketFilter(byte[] filter) {}
        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
        // If multicast filtering cannot be accomplished with APF, this function will be called to
        // actuate multicast filtering using another means.
        // actuate multicast filtering using another means.
        public void setFallbackMulticastFilter(boolean enabled) {}
        public void setFallbackMulticastFilter(boolean enabled) {}
@@ -280,6 +287,11 @@ public class IpClient extends StateMachine {
            log("installPacketFilter(byte[" + filter.length + "])");
            log("installPacketFilter(byte[" + filter.length + "])");
        }
        }
        @Override
        @Override
        public void startReadPacketFilter() {
            mCallback.startReadPacketFilter();
            log("startReadPacketFilter()");
        }
        @Override
        public void setFallbackMulticastFilter(boolean enabled) {
        public void setFallbackMulticastFilter(boolean enabled) {
            mCallback.setFallbackMulticastFilter(enabled);
            mCallback.setFallbackMulticastFilter(enabled);
            log("setFallbackMulticastFilter(" + enabled + ")");
            log("setFallbackMulticastFilter(" + enabled + ")");
@@ -591,6 +603,7 @@ public class IpClient extends StateMachine {
    private static final int CMD_SET_MULTICAST_FILTER             = 9;
    private static final int CMD_SET_MULTICAST_FILTER             = 9;
    private static final int EVENT_PROVISIONING_TIMEOUT           = 10;
    private static final int EVENT_PROVISIONING_TIMEOUT           = 10;
    private static final int EVENT_DHCPACTION_TIMEOUT             = 11;
    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_LOG_RECORDS = 500;
    private static final int MAX_PACKET_RECORDS = 100;
    private static final int MAX_PACKET_RECORDS = 100;
@@ -643,6 +656,7 @@ public class IpClient extends StateMachine {
    private ApfFilter mApfFilter;
    private ApfFilter mApfFilter;
    private boolean mMulticastFiltering;
    private boolean mMulticastFiltering;
    private long mStartTimeMillis;
    private long mStartTimeMillis;
    private byte[] mApfDataSnapshot;


    public static class Dependencies {
    public static class Dependencies {
        public INetworkManagementService getNMS() {
        public INetworkManagementService getNMS() {
@@ -857,6 +871,10 @@ public class IpClient extends StateMachine {
        sendMessage(EVENT_PRE_DHCP_ACTION_COMPLETE);
        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.
     * Set the TCP buffer sizes to use.
     *
     *
@@ -897,6 +915,7 @@ public class IpClient extends StateMachine {
        final ProvisioningConfiguration provisioningConfig = mConfiguration;
        final ProvisioningConfiguration provisioningConfig = mConfiguration;
        final ApfCapabilities apfCapabilities = (provisioningConfig != null)
        final ApfCapabilities apfCapabilities = (provisioningConfig != null)
                ? provisioningConfig.mApfCapabilities : null;
                ? provisioningConfig.mApfCapabilities : null;
        final byte[] apfDataSnapshot = mApfDataSnapshot;


        IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
        IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
        pw.println(mTag + " APF dump:");
        pw.println(mTag + " APF dump:");
@@ -914,6 +933,14 @@ public class IpClient extends StateMachine {
            }
            }
        }
        }
        pw.decreaseIndent();
        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();
        pw.println(mTag + " current ProvisioningConfiguration:");
        pw.println(mTag + " current ProvisioningConfiguration:");
@@ -1710,6 +1737,11 @@ public class IpClient extends StateMachine {
                    break;
                    break;
                }
                }


                case EVENT_READ_PACKET_FILTER_COMPLETE: {
                    mApfDataSnapshot = (byte[]) msg.obj;
                    break;
                }

                case EVENT_DHCPACTION_TIMEOUT:
                case EVENT_DHCPACTION_TIMEOUT:
                    stopDhcpAction();
                    stopDhcpAction();
                    break;
                    break;