tripflex / wifi-captive-portal

Mongoose OS WiFi Captive Portal Library
https://forum.mongoose-os.com/discussion/2702/library-wifi-captive-portal-web-ui-list-ssids-test-configure-rpc-gzip-support
Other
24 stars 9 forks source link

Samsung Android devices do not prompt to Login to Network #7

Open tripflex opened 6 years ago

tripflex commented 6 years ago

Testing on Samsung Galaxy S7, does not show "Login to Network" prompt, even though 302 redirect is sent when querying /generate_204 ...

On device it shows "Testing internet connection...." and then when editing wifi network shows "Manage router" but never shows login prompt.

Wondering if these devices expect a different kind of response to the /generate_204, or maybe the "Testing internet connection..." has something to do with it (since we reply with DNS query for anything) and maybe it thinks there "might" be internet connection since it's able to get a DNS response ... need to do more testing

[Aug 31 11:18:09.637] I (341188) tcpip_adapter: softAP assign IP to station,IP is: 192.168.4.2
[Aug 31 11:18:09.645] event_handler        event: 17
[Aug 31 11:18:12.293] dns_ev_handler       DNS A Query for connectivitycheck.gstatic.com sending IP 192.168.4.1
[Aug 31 11:18:12.301] dns_ev_handler       DNS A Query for connectivitycheck.gstatic.com sending IP 192.168.4.1
[Aug 31 11:18:12.311] dns_ev_handler       DNS A Query for epdg.epc.att.net sending IP 192.168.4.1
[Aug 31 11:18:12.320] dns_ev_handler       DNS A Query for clients3.google.com sending IP 192.168.4.1
[Aug 31 11:18:12.805] dns_ev_handler       DNS A Query for www.google.com sending IP 192.168.4.1
[Aug 31 11:18:13.265] dns_ev_handler       DNS A Query for connectivitycheck.gstatic.com sending IP 192.168.4.1
[Aug 31 11:18:13.274] dns_ev_handler       DNS A Query for connectivitycheck.gstatic.com sending IP 192.168.4.1
[Aug 31 11:18:13.713] dns_ev_handler       DNS A Query for www.google.com sending IP 192.168.4.1
[Aug 31 11:18:17.301] dns_ev_handler       DNS A Query for epdg.epc.att.net sending IP 192.168.4.1
[Aug 31 11:18:17.319] dns_ev_handler       DNS A Query for clients3.google.com sending IP 192.168.4.1
[Aug 31 11:18:17.356] mg_lwip_accept_cb    0x3ffb70f8 conn 0x3ffb8c18 from 192.168.4.2:33058
[Aug 31 11:18:17.363] mg_if_accept_new_con 0x3ffb70f8 0x3ffb8ce4 1073450764 0
[Aug 31 11:18:17.369] mg_if_accept_tcp_cb  0x3ffb8ce4 tcp://192.168.4.2:33058
[Aug 31 11:18:17.375] mgos_http_ev         0x3ffb8ce4 HTTP connection from 192.168.4.2:33058
[Aug 31 11:18:17.383] mg_http_is_authorize /generate_204  2 1
[Aug 31 11:18:17.387] redirect_ev_handler  Redirecting to http://setup.device.portal for Captive Portal
[Aug 31 11:18:17.458] mg_lwip_accept_cb    0x3ffb70f8 conn 0x3ffb8ce4 from 192.168.4.2:33059
[Aug 31 11:18:17.465] mg_if_accept_new_con 0x3ffb70f8 0x3ffdfe3c 1073450736 0
[Aug 31 11:18:17.471] mg_if_accept_tcp_cb  0x3ffdfe3c tcp://192.168.4.2:33059
[Aug 31 11:18:17.477] mgos_http_ev         0x3ffdfe3c HTTP connection from 192.168.4.2:33059
[Aug 31 11:18:17.485] mg_http_is_authorize /generate_204  2 1
[Aug 31 11:18:17.489] redirect_ev_handler  Redirecting to http://setup.device.portal for Captive Portal
[Aug 31 11:18:19.222] dns_ev_handler       DNS A Query for connectivitycheck.gstatic.com sending IP 192.168.4.1
[Aug 31 11:18:19.232] dns_ev_handler       DNS A Query for connectivitycheck.gstatic.com sending IP 192.168.4.1
[Aug 31 11:18:19.584] dns_ev_handler       DNS A Query for www.google.com sending IP 192.168.4.1
[Aug 31 11:18:25.279] dns_ev_handler       DNS A Query for connectivitycheck.gstatic.com sending IP 192.168.4.1
[Aug 31 11:18:25.289] dns_ev_handler       DNS A Query for connectivitycheck.gstatic.com sending IP 192.168.4.1
[Aug 31 11:18:25.571] dns_ev_handler       DNS A Query for www.google.com sending IP 192.168.4.1
tripflex commented 5 years ago

Seems to also be an issue related to GZIP files .. when trying to access the gzip version of file on device it does not load, non-gzip version does

marciopamplona commented 5 years ago

Maybe, this is the solution: https://community.arubanetworks.com/t5/Wireless-Access/Samsung-Captive-Portal-Detection/m-p/405934#M78972

marciopamplona commented 5 years ago

The Samsung expect a 204 response, with no content against http://connectivitycheck.gstatic.com/generate_204, but the portal send an 302 redirect:

*   Trying 192.168.4.1...
* TCP_NODELAY set
* Connected to connectivitycheck.gstatic.com (192.168.4.1) port 80 (#0)
> GET /generate_204 HTTP/1.1
> Host: connectivitycheck.gstatic.com
> User-Agent: curl/7.63.0
> Accept: */*
> 
< HTTP/1.1 302 Found
< Server: Mongoose/6.13
< Location: http://connectivitycheck.gstatic.com
< Content-Type: text/html
< Content-Length: 67
< Cache-Control: no-cache
tripflex commented 5 years ago

@marciopamplona AHHHH okay awesome! Thanks for this info! So yeah everything else works perfectly fine with 302 redirect, EXCEPT for Samsung devices ... ugh ... which expect a valid 204 response but just not an empty response.

Need to think about this a bit and test to see best way to handle this, and see if just returning data in 204 works with other devices as well, or if we just have to come up with some compatibility handling for samsung devices on the 204, going to test this out here in a bit and see what I can come up with.

Thanks again for these details!

tripflex commented 5 years ago

https://en.wikipedia.org/wiki/Captive_portal

Even wikipedia on this says

If the device receives a HTTP 204 status code, it assumes it has unlimited internet access. Captive portal prompts are displayed when you are able to manipulate this first HTTP message to return a HTTP status code of 302 (redirect) to the captive portal of your choice.

Which is weird because that means that this is something samsung specific ... ugh

marciopamplona commented 5 years ago

I'm testing this myself. This information below make more sense:

https://socifi-doc.atlassian.net/wiki/spaces/SC/pages/94371841/DNS+Workaround+to+keep+Android+Splash+Page+and+the+Captive+Portal+Notification+active

tripflex commented 5 years ago

@marciopamplona yeah that gives a bit more information. So this library already handles all the DNS related stuff mentioned in that article, need to test if other devices still prompt the captive portal splash page when we return the HTML in the generate_204 will try and do it this week

tripflex commented 5 years ago

@marciopamplona please try out the new library, I think this should be fixed with my new handling .. i don't have a samsung device to test with .. but it should: https://github.com/tripflex/captive-portal-wifi-stack

IS a combination of all of these libs: https://github.com/tripflex/captive-portal https://github.com/tripflex/captive-portal-wifi-setup https://github.com/tripflex/captive-portal-wifi-rpc https://github.com/tripflex/captive-portal-wifi-web