Skip to content

Commit

Permalink
Fix for Android 15 Ip Provisioning Failure
Browse files Browse the repository at this point in the history
In Android 15, Wifi is not working due to ip provisioning
failure. This is because of DHCP Accept packet being filtered
out by DhcpFilter from jni level.

The DHCP handling logic from Android 14, which does not include
the problematic macros, has been reinstated to resolve the issue.
This ensures DHCP accept packets are not filtered and can reach
the router.

Tests Done:
1. Boot android image for both caas and base_aaos
   with this change
2. Go to settings and Connect to Wifi from router
   and from Mobile Hotspot
3. Wifi Connects successfully

Tracked-On: OAM-126105
Signed-off-by: Bhadouria, Aman <[email protected]>
Signed-off-by: Babu, Gowtham Anandha <[email protected]>
  • Loading branch information
AmanBh0709 authored and sysopenci committed Oct 4, 2024
1 parent 7af66cf commit 3d3c37f
Showing 1 changed file with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
From 3f76d97a8d138da4b96fa16c20508cea78a8f45a Mon Sep 17 00:00:00 2001
From: "Bhadouria, Aman" <[email protected]>
Date: Fri, 4 Oct 2024 08:06:13 +0000
Subject: [PATCH] Fix for Android 15 Ip Provisioning Failure

In Android 15, Wifi is not working due to ip provisioning
failure. This is because of DHCP Accept packet being filtered
out by DhcpFilter from jni level.

The DHCP handling logic from Android 14, which does not include
the problematic macros, has been reinstated to resolve the issue.
This ensures DHCP accept packets are not filtered and can reach
the router.

Tests Done:
1. Boot android image for both caas and base_aaos
with this change
2. Go to settings and Connect to Wifi from router
and from Mobile Hotspot
3. Wifi Connects Succesfully

Signed-off-by: Bhadouria, Aman <[email protected]>
Signed-off-by: Babu, Gowtham Anandha <[email protected]>
---
jni/network_stack_utils_jni.cpp | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/jni/network_stack_utils_jni.cpp b/jni/network_stack_utils_jni.cpp
index 6f47d7ef..674e1ba3 100644
--- a/jni/network_stack_utils_jni.cpp
+++ b/jni/network_stack_utils_jni.cpp
@@ -42,6 +42,10 @@ namespace android {
constexpr const char NETWORKSTACKUTILS_PKG_NAME[] =
"com/android/networkstack/util/NetworkStackUtils";

+static const uint32_t kEtherHeaderLen = sizeof(ether_header);
+static const uint32_t kIPv4Protocol = kEtherHeaderLen + offsetof(iphdr, protocol);
+static const uint32_t kIPv4FlagsOffset = kEtherHeaderLen + offsetof(iphdr, frag_off);
+static const uint32_t kUDPDstPortIndirectOffset = kEtherHeaderLen + offsetof(udphdr, dest);
static const uint16_t kDhcpClientPort = 68;

static bool checkLenAndCopy(JNIEnv* env, const jbyteArray& addr, int len, void* dst) {
@@ -96,21 +100,25 @@ static void network_stack_utils_addArpEntry(JNIEnv *env, jclass clazz, jbyteArra
static void network_stack_utils_attachDhcpFilter(JNIEnv *env, jclass clazz, jobject javaFd) {
static sock_filter filter_code[] = {
// Check the protocol is UDP.
- BPF_LOAD_IPV4_U8(protocol),
- BPF2_REJECT_IF_NOT_EQUAL(IPPROTO_UDP),
+ BPF_STMT(BPF_LD | BPF_B | BPF_ABS, kIPv4Protocol),
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_UDP, 0, 6),

// Check this is not a fragment.
- BPF_LOAD_IPV4_BE16(frag_off),
- BPF2_REJECT_IF_ANY_MASKED_BITS_SET(IP_MF | IP_OFFMASK),
+ BPF_STMT(BPF_LD | BPF_H | BPF_ABS, kIPv4FlagsOffset),
+ BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, IP_MF | IP_OFFMASK, 4, 0),

// Get the IP header length.
- BPF_LOADX_NET_RELATIVE_IPV4_HLEN,
+ BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, kEtherHeaderLen),

// Check the destination port.
- BPF_LOAD_NETX_RELATIVE_DST_PORT,
- BPF2_REJECT_IF_NOT_EQUAL(kDhcpClientPort),
+ BPF_STMT(BPF_LD | BPF_H | BPF_IND, kUDPDstPortIndirectOffset),
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, kDhcpClientPort, 0, 1),

- BPF_ACCEPT,
+ // Accept.
+ BPF_STMT(BPF_RET | BPF_K, 0xffff),
+
+ // Reject.
+ BPF_STMT(BPF_RET | BPF_K, 0)
};
const sock_fprog filter = {
sizeof(filter_code) / sizeof(filter_code[0]),
--
2.34.1

0 comments on commit 3d3c37f

Please sign in to comment.