Skip to content
This repository has been archived by the owner on Mar 11, 2019. It is now read-only.

DHCP not working on Android 7.1 and later #10

Closed
compscidr opened this issue Dec 19, 2016 · 23 comments
Closed

DHCP not working on Android 7.1 and later #10

compscidr opened this issue Dec 19, 2016 · 23 comments
Labels

Comments

@compscidr
Copy link

Have noticed that in 7.1 it still creates the hotspot, but it appears the DHCP server is not starting correctly and IP addresses are not being given out correctly to clients trying to connect. They make it through the authentication phase but then are disconnected.

@mvdan
Copy link
Owner

mvdan commented Dec 19, 2016

Please provide more info.

  • What version of the library is this?

  • Does the hotspot work when started manually?

  • What code are you using to set up the hotspot?

  • Does it only happen in newer Android versions, or also on older ones?

  • Did you check the logcat?

@compscidr
Copy link
Author

compscidr commented Dec 19, 2016

Thanks for the quick feedback - here's the responses to your questions:
What version of the library is this?

  • version 0.2.0
    Does the hotspot work when started manually?
  • yes
    What code are you using to set up the hotspot?
if(!apControl.isEnabled()) {
                WifiConfiguration apConfig = getApConfig();
                wifiManager.setWifiEnabled(false);
                apControl.setEnabled(apConfig, true);
                apControl.enable();
}

Does it only happen in newer Android versions, or also on older ones?

  • Only happens on 7.1 (works on everything else from 4.x to 7.0)
    Did you check the logcat?
  • Logcat was reporting an error with dnsmasq a couple weeks ago, but they have since release another update and there is no longer an error. On the logcat when I create a hotspot manually I see some output from the DHCP server that I don't see when the hotspot is created with the library
  • After the client associates I see a message on logcat, but before it receives a dhcp offer there is a message saying the client disconnected.

@mvdan
Copy link
Owner

mvdan commented Dec 19, 2016

WifiConfiguration apConfig = getApConfig();
wifiManager.setWifiEnabled(false);
apControl.setEnabled(apConfig, true);
apControl.enable();

See what apControl.enable() does; the getApConfig and setEnabled lines are redundant.

Otherwise I can't see anything obviously broken here. Are you on an official 7.1 ROM, or a nightly like cyanogenmod? I am on a cm14.1 nightly as of a couple of days ago, so I will play with it tomorrow to see if it works on my nexus 6.

@mvdan mvdan changed the title Android 7.1 DHCP issues with Android 7.1 as host Dec 19, 2016
@compscidr
Copy link
Author

compscidr commented Dec 19, 2016

the getApConfig line just returns a filled in WifiConfiguration as follows:

WifiConfiguration config = new WifiConfiguration();
        config.SSID = "testnetwork";
        config.BSSID = "";
        config.hiddenSSID = false; 
        //the config, we do not do this.
        config.preSharedKey = "testwpa2key";
        config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
        //config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
        config.allowedKeyManagement.set(WPA_PSK2);
        config.status = WifiConfiguration.Status.ENABLED;
        config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
        config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
        config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
        config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
        config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
        config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);

I'll try removing the redundant enable lines and see if that makes a difference.

Using the stock 7.1 that ships with the pixel. I also have a nexus 6p with 7.0 - it seems to work well still on this device, but for some reason 7.1 is a bit different.

@mvdan
Copy link
Owner

mvdan commented Dec 19, 2016

Use triple backticks for multiline snippets; I've fixed your comments.

I'll try removing the redundant enable lines and see if that makes a difference.

Probably won't, but worth a try.

Using the stock 7.1 that ships with the pixel. I also have a nexus 6p with 7.0 - it seems to work well still on this device, but for some reason 7.1 is a bit different.

Would be helpful if we could see if this is a problem with 7.1 in general or not. Maybe the library needs tweaking to work with this new Android version.

@compscidr compscidr reopened this Jan 27, 2017
@cristeab
Copy link

Having the same problem, did anyone find a solution ?

@compscidr
Copy link
Author

Nothing yet - I tried reporting through the bug reporter on the pixel, turns out that's not a good place for submitting dev related bugs - they didn't know what I was talking about ;)

Probably worth filing a ticket somewhere on their development support but I haven't got around to it. I can't tell if its actually a bug or if they are trying to phase out the ability to create an AP with code.

@tk721
Copy link

tk721 commented Mar 3, 2017

Ran into the same issue (Android 7.1.1, Nexus 5X). The behavior of the underlying Android API seems to have changed in 7.1. It used to put the interface into Wi-Fi AP mode, configure it with an IP address, and run a DHCP server. Now it only puts the interface into Wi-Fi AP mode and nothing else.

@mvdan
Copy link
Owner

mvdan commented Mar 3, 2017

The code to start the DHCP server must be in AOSP somewhere. If anyone finds it or has a patch, I'll be happy to help. I'll try to have a look into it soon.

@mvdan
Copy link
Owner

mvdan commented Mar 17, 2017

For the record, lots of people have been looking into this for Tasker, which also has broken tethering on 7.1: https://groups.google.com/forum/#!topic/tasker/Rf75hoZjDTo

It includes people trying static IPs and ipv4 forwarding (which doesn't seem to work) and system-level permission usage (which does seem to work).

We won't use system-level permissions though, as that would mean the library would be useless unless the app using it is a privileged system app.

@mvdan
Copy link
Owner

mvdan commented Apr 5, 2017

Some bits of info:

  • The example seems to look OK on my 7.1 device, but as you guys say, devices won't connect to the AP even though they see it.
  • The WiFi tethering icon is visible in the status bar, but if I go to "Tethering & portable hotspot" the "Portable Wi-Fi hotspot" is off. I don't know if this used to be like this on older Android versions, and can't check.
  • Funnily enough, I can't properly set up a Wi-Fi AP on the phone after trying out the example app. Not even a full reboot on the phone fixes it. On my laptop, I see:
wlp3s0: authenticate with 92:68:c3:f5:49:97
wlp3s0: send auth to xx:xx:xx:xx:xx:xx (try 1/3)
wlp3s0: authenticated
wlp3s0: associate with xx:xx:xx:xx:xx:xx (try 1/3)
wlp3s0: RX AssocResp from xx:xx:xx:xx:xx:xx (capab=0x11 status=0 aid=1)
wlp3s0: associated
wlp3s0: deauthenticating from 92:68:c3:f8:a3:ac by local choice (Reason: 1=UNSPECIFIED)

The same three times, until it gives up. Pretty sure it's not the laptop, as I've used Wi-Fi tethering with my phone before, and it connects to the home network just fine.

@mvdan
Copy link
Owner

mvdan commented Apr 5, 2017

Also, this is a shot in the dark, but please try a build from master: library.zip

I bumped the target SDK from 23 to 25 and updated a couple of other things. I don't expect this to fix the issue, but worth a try.

@ariqbanihardi
Copy link

Hey guys. Is there any solution about this issue,. I have a same problem and have not found it's solution

@mvdan
Copy link
Owner

mvdan commented Jan 6, 2018

I'm afraid noone here has found the solution either. As far as we know, there isn't a way to achieve the old behavior in newer Android versions unless you have root or install the app as a system app.

@ariqbanihardi
Copy link

Hi @mvdan . Thank's for your great library. when I creat AP and I try to setup some parameter like SSID, channel, security, it really created with that parameters setted too. But the AP didn't give IP address. In some forum they said maybe this was issue on AOSP 7.1. if I have root my device, how can I solve this problem?

@Sachin-Radhakrishnan
Copy link

Hi @mvdan : I'm trying to use your library to enable the HotSpot on Nexus 6.

I'm able to turn on the hotspot with the specific ssid and password but then when I try to connect another device to my AP it's impossible to establish a connection.It got stuck at "Obtaining IP address ..."

When i manually go and change the toggle status of the hotspot,it works fine...

@mvdan
Copy link
Owner

mvdan commented Feb 27, 2018

Yes, that is exactly what this issue is about. Please only post here if you have any new information about the issue or how to fix it.

@mvdan mvdan changed the title DHCP issues with Android 7.1 as host DHCP not working on Android 7.1 and later Feb 27, 2018
@mvdan
Copy link
Owner

mvdan commented Mar 6, 2018

Again, please don't comment on this thread unless you have something to add. Repeating that DHCP doesn't work is just going to spam and annoy everyone subscribed to the issue. I'm going to start deleting comments if it keeps happening.

@mvdan
Copy link
Owner

mvdan commented Mar 6, 2018

A couple of people had already mentioned that manually starting the hotspot did work. They didn't mention the system interface nor the settings though, so perhaps that's why you didn't find it.

The original poster reported that it worked on a 7.0 device, so I'm not going to change the title for now - at least not until we have more information.

@geekywoman
Copy link

Hi everyone,

I ran into this problem as many of you here, and after many (painful) days of investigation I have found something that might be of some help. The solution is to actually completely ignore the hotspot feature from the Android SDK :) Who would have guessed? Well apparently shinilms is part of the people who figured this out. Huge thanks to him!

Here is a no-root solution from shinilms:
https://github.com/shinilms/direct-net-share
(it enables the hotspot and requires the user to setup a proxy on his phone)

And here is my small contribution:
https://github.com/geekywoman/direct-net-share
We take advantage of the root rights to do the magic with the DHCP so the user does not need to setup any proxy manually.

Hope it helps!

@mvdan
Copy link
Owner

mvdan commented May 25, 2018

Thanks for the information, @geekywoman! I'll gladly deprecate this project in favor of a newer one that actually works on newer Android versions. Does that method work on older versions too?

Which one should I link to at the top of the README here - the original repo, or your fork? I presume that you'd want to upstream the root capabilities, as an optional feature.

@geekywoman
Copy link

I tested my fork on 7.1.1 and on 6.0.0 versions, everything works fine :)

For the link on top of the README, it is up to you, whatever you think is best! I guess you would like to advertise the original repo from shinilms has there is no need for root.
My fork works with both actually. Without root, one will need to setup the proxy into settings manually as advertised in shinilms repo. If root rights are granted, one will be connected to this alternative hotspot right away ;)

Another alternative that could interest people: https://github.com/aegis1980/WifiHotSpot I have tested on Oreo and it works great! Unfortunately it is not working on 7.1.1. This is why I ended with the previous solution I shared with you. But I am sharing it here just in case people are looking for another alternative.

@mvdan mvdan closed this as completed in a015d78 Jun 3, 2018
@mvdan
Copy link
Owner

mvdan commented Jun 3, 2018

@geekywoman thank you - I've clarified that the project is abandoned, and linked to all three projects in the README. If the list ever needs updating, just send a pull request to update the markdown file.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants