Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to start hotspot when the USB Tethering hotspot type is used. #351

Closed
brlin-tw opened this issue Nov 5, 2024 · 9 comments
Closed
Labels
bug Something isn't working enhancement New feature or request next release This Feature will go out with the next release

Comments

@brlin-tw
Copy link
Contributor

brlin-tw commented Nov 5, 2024

The phone is connected to the PC, and the USB network sharing mode is enabled, but the hotspot failed to start with the following error:

java.lang.IllegalStateException: Missing USB Tethering connection
 at com.pyamsoft.tetherfi.server.broadcast.rndis.RNDISServer$resolveRNDISNetwork$2.invokeSuspend(SourceFile:93)
 at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(SourceFile:9)
 at kotlinx.coroutines.DispatchedTask.run(SourceFile:107)
 at com.google.android.gms.tasks.zzi.run(SourceFile:11)
 at kotlinx.coroutines.scheduling.TaskImpl.run(SourceFile:3)
 at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:93)
 Missing USB Tethering connection

Developer log:

[D] Starting Proxy! 
[D] Stopping runner! 
[D] #################################### 
[D] Acquire CPU wakelock: com.pyamsoft.tetherfi:PROXY_WAKE_LOCK 
[D] #################################### 
[D] Create new wake lock with PARTIAL_WAKE_LOCK 
[D] #################################### 
[D] Acquire WiFi wakelock: com.pyamsoft.tetherfi:PROXY_WIFI_LOCK 
[D] #################################### 
[D] Starting Wifi Network... 
[D] WiDi Status Changed: Starting 
[D] START NEW NETWORK 
[D] Updated foreground notification: NotifyId(id=42069): ServerNotificationData(status=Starting, clientCount=0, blockCount=0) 
[D] Starting broadcast network 
[W] Error during broadcast startup, stop network 
[D] Reset last info refresh times 
[W] Stopping network after startup failed 
[D] WiDi Status Changed: HotspotError(throwable=java.lang.IllegalStateException: Missing USB Tethering connection) 
[D] Shutdown event received! 
[D] Shutdown event received! 
[D] Stopping Wifi Network... 
[D] STOP NETWORK 
[D] Shutting down network 
[D] Reset last info refresh times 
[E] Error running WiDi network
java.lang.IllegalStateException: Missing USB Tethering connection
 at com.pyamsoft.tetherfi.server.broadcast.rndis.RNDISServer$resolveRNDISNetwork$2.invokeSuspend(SourceFile:93)
 at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(SourceFile:9)
 at kotlinx.coroutines.DispatchedTask.run(SourceFile:107)
 at com.google.android.gms.tasks.zzi.run(SourceFile:11)
 at kotlinx.coroutines.scheduling.TaskImpl.run(SourceFile:3)
 at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(SourceFile:93)
 Missing USB Tethering connection
[D] Updated foreground notification: NotifyId(id=42069): ServerNotificationData(status=HotspotError(throwable=java.lang.IllegalStateException: Missing USB Tethering connection), clientCount=0, blockCount=0) 
[D] Stop Foreground Service! 
[D] Shutdown event received! 
[D] Shutdown event received! 
[D] Network was stopped 
[D] #################################### 
[D] Release CPU wakelock: com.pyamsoft.tetherfi:PROXY_WAKE_LOCK 
[D] #################################### 
[D] #################################### 
[D] Release WIFI wakelock: com.pyamsoft.tetherfi:PROXY_WIFI_LOCK 
[D] #################################### 
[D] Destroying service 
[D] Execute prepareStop() before cancelling service scope 
[D] Stop Foreground Service! 
[D] Mark hotspot stopping 
[D] Unhandled Proxy status event Stopping 
[D] Broadcast stop-request 
[D] Proxy Status Changed: Stopping 
[D] Cancel Service Scope 
[D] Notification scope is done, cancel notification! 
[D] Stop foreground notification 

Additional information

TetherFi

49 from Google Play

Android

14 (AP2A.240905.003)

Phone

Google Pixel 8 Pro

@pyamsoft
Copy link
Owner

pyamsoft commented Nov 5, 2024

The USB tethering mode is looking for an interface identified as RNDIS.

Do you have access to an Android Studio environment?

If you do, you can build a simple test app and copy the code from RNDISServer.kt in the function resolveRNDISNetwork

This function goes through all of the various internet devices and attempts to pick the one labelled RNDIS, maybe yours is something different that I also need to look for?

@pyamsoft pyamsoft added bug Something isn't working next release This Feature will go out with the next release labels Nov 5, 2024
@brlin-tw
Copy link
Contributor Author

brlin-tw commented Nov 5, 2024

@pyamsoft

This function goes through all of the various internet devices and attempts to pick the one labelled RNDIS, maybe yours is something different that I also need to look for?

I hooked up a debugger and it seems that the NetworkInterface.getNetworkInterfaces() call returns null on my phone.

I'm going to rebuild the app and try to verify it again just to be sure, after building ktor which took ages for some reason:

Screenshot

@pyamsoft
Copy link
Owner

pyamsoft commented Nov 6, 2024

You can use the upstream ktor if you don't need to use the preferred network feature.

If you change the ktor dep back to upstream, I think you just have to change the 2 lines where I call connectWithConfiguration to connect

Thanks for getting deep in the code here!

If you device is returning null for this, I'll need a different API to enumerated the devices

@brlin-tw
Copy link
Contributor Author

brlin-tw commented Nov 6, 2024

@pyamsoft

If you device is returning null for this, I'll need a different API to enumerated the devices

After successfully building TetherFi from the source I can verify that the NetworkInterface.getNetworkInterfaces() call returns proper results, just not the ones we were expecting:

Screenshot

The ncm0 interface seems to be the one that is responsible for USB network sharing.

@brlin-tw
Copy link
Contributor Author

brlin-tw commented Nov 6, 2024

I can verify that changing the "EXPECTED_RNDIS_NAME_PREFIX" string value to "ncm" I can successfully launch the hotspot.

@pyamsoft
Copy link
Owner

pyamsoft commented Nov 6, 2024

Awesome find, thank you

I will patch the code to look for both interface name prefixes

@brlin-tw
Copy link
Contributor Author

brlin-tw commented Nov 6, 2024

I hooked up a debugger and it seems that the NetworkInterface.getNetworkInterfaces() call returns null on my phone.

No longer reproduced on either emulator/phone, likely a false alarm.

pyamsoft added a commit that referenced this issue Nov 7, 2024
According to #351, its not just "RNDIS", but some devices
also appear to use "ncm" as their USB tethering device prefix.

I have no idea what the difference is, but whatever, if it works it
works :)
@pyamsoft
Copy link
Owner

pyamsoft commented Nov 7, 2024

I have added support for the ncm prefix, and will look at making another production release hopefully sometime next week.

Thank you for your contribution to the project!

@pyamsoft
Copy link
Owner

pyamsoft commented Nov 9, 2024

Version 51 is in production testing and includes the ncm change.

@pyamsoft pyamsoft closed this as completed Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request next release This Feature will go out with the next release
Projects
None yet
Development

No branches or pull requests

2 participants