mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
fix(android,radxa): bind TRANSPORT_ETHERNET on Android 12+ and add pure CDC-ECM eth0 gadget script
This commit is contained in:
1 parent
5b2b40d079
commit
d2b41bbc66
3 files changed
+103
No files matched your search
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package com.steamframe.fpv
|
package com.steamframe.fpv
|
||||||
|
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.Network
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
import android.net.NetworkRequest
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.Surface
|
import android.view.Surface
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
@@ -20,6 +25,8 @@ import java.util.Locale
|
|||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
private lateinit var decoder: LowLatencyVideoDecoder
|
private lateinit var decoder: LowLatencyVideoDecoder
|
||||||
|
private lateinit var connectivityManager: ConnectivityManager
|
||||||
|
private var ethCallback: ConnectivityManager.NetworkCallback? = null
|
||||||
private var nativeHandle: Long = 0L
|
private var nativeHandle: Long = 0L
|
||||||
private var currentSurface: Surface? = null
|
private var currentSurface: Surface? = null
|
||||||
|
|
||||||
@@ -65,6 +72,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
hideSystemBars()
|
hideSystemBars()
|
||||||
|
|
||||||
decoder = LowLatencyVideoDecoder(applicationContext)
|
decoder = LowLatencyVideoDecoder(applicationContext)
|
||||||
|
connectivityManager = getSystemService(ConnectivityManager::class.java)
|
||||||
|
bindEthernetNetwork()
|
||||||
restartNativeEngine()
|
restartNativeEngine()
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
@@ -175,7 +184,47 @@ class MainActivity : ComponentActivity() {
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun bindEthernetNetwork() {
|
||||||
|
try {
|
||||||
|
// Sur Android 12+, une interface Ethernet USB sans Internet n'est pas routée par défaut :
|
||||||
|
// on force le processus sur TRANSPORT_ETHERNET pour que les sockets UDP Rust joignent 192.168.1.1 même Wi-Fi allumé.
|
||||||
|
val req = NetworkRequest.Builder()
|
||||||
|
.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
|
||||||
|
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
.build()
|
||||||
|
val cb = object : ConnectivityManager.NetworkCallback() {
|
||||||
|
override fun onAvailable(network: Network) {
|
||||||
|
val ok = connectivityManager.bindProcessToNetwork(network)
|
||||||
|
Log.i("SteamFrameFPV", "Ethernet USB lié au processus (bindProcessToNetwork=$ok)")
|
||||||
|
runOnUiThread {
|
||||||
|
pingStatus = if (ok) "ETH USB OK" else "ETH bind fail"
|
||||||
|
restartNativeEngine()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLost(network: Network) {
|
||||||
|
connectivityManager.bindProcessToNetwork(null)
|
||||||
|
Log.i("SteamFrameFPV", "Ethernet USB déconnecté")
|
||||||
|
runOnUiThread {
|
||||||
|
pingStatus = "ETH déconnecté"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ethCallback = cb
|
||||||
|
connectivityManager.requestNetwork(req, cb)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w("SteamFrameFPV", "Impossible de lier TRANSPORT_ETHERNET : ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
ethCallback?.let {
|
||||||
|
try {
|
||||||
|
connectivityManager.unregisterNetworkCallback(it)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connectivityManager.bindProcessToNetwork(null)
|
||||||
stopNativeEngine()
|
stopNativeEngine()
|
||||||
decoder.release()
|
decoder.release()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
|
|||||||
Executable
+53
@@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Configure un gadget USB Ethernet CDC-ECM pur (0525:a4a1, sans port série ACM)
|
||||||
|
# avec une MAC administrée globalement (00:1a:11:f0:00:02) afin que le noyau
|
||||||
|
# Samsung / Android nomme l'interface `eth0` (reconnue nativement par One UI)
|
||||||
|
# tout en restant 100 % compatible Linux / SteamOS (Steam Frame).
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
GADGET_DIR="/sys/kernel/config/usb_gadget/steamframe_ecm"
|
||||||
|
UDC_NAME="$(ls /sys/class/udc | head -n 1 || true)"
|
||||||
|
|
||||||
|
setup_configfs_ecm() {
|
||||||
|
[ -n "${UDC_NAME}" ] || return 1
|
||||||
|
modprobe usb_f_ecm || return 1
|
||||||
|
mountpoint -q /sys/kernel/config || mount -t configfs none /sys/kernel/config
|
||||||
|
|
||||||
|
if [ -d "${GADGET_DIR}" ] && [ -s "${GADGET_DIR}/UDC" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "${GADGET_DIR}"
|
||||||
|
cd "${GADGET_DIR}"
|
||||||
|
echo 0x0525 > idVendor
|
||||||
|
echo 0xa4a1 > idProduct
|
||||||
|
echo 0x0100 > bcdDevice
|
||||||
|
echo 0x0200 > bcdUSB
|
||||||
|
echo 0x00 > bDeviceClass
|
||||||
|
echo 0x00 > bDeviceSubClass
|
||||||
|
echo 0x00 > bDeviceProtocol
|
||||||
|
|
||||||
|
mkdir -p strings/0x409
|
||||||
|
echo "SF-RADXA-001" > strings/0x409/serialnumber
|
||||||
|
echo "SteamFrame FPV" > strings/0x409/manufacturer
|
||||||
|
echo "Radxa VRX USB Ethernet" > strings/0x409/product
|
||||||
|
|
||||||
|
mkdir -p configs/c.1/strings/0x409
|
||||||
|
echo "CDC-ECM Ethernet" > configs/c.1/strings/0x409/configuration
|
||||||
|
echo 250 > configs/c.1/MaxPower
|
||||||
|
|
||||||
|
mkdir -p functions/ecm.usb0
|
||||||
|
# Bit 1 du 1er octet = 0 (MAC globale) : indispensable pour que cdc_ether sur Android nomme l'interface eth0
|
||||||
|
echo "00:1a:11:f0:00:02" > functions/ecm.usb0/host_addr
|
||||||
|
echo "00:1a:11:f0:00:01" > functions/ecm.usb0/dev_addr
|
||||||
|
|
||||||
|
ln -sf functions/ecm.usb0 configs/c.1/ecm.usb0
|
||||||
|
echo "${UDC_NAME}" > UDC
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! setup_configfs_ecm; then
|
||||||
|
echo "[usb0-gadget] Fallback vers g_cdc" >&2
|
||||||
|
modprobe g_cdc || true
|
||||||
|
fi
|
||||||
Reference in new issue
Block a user