Connecting the device to a wifi behind a captive

Hi,
We are building a device that a user will connect it to available wifi.
i saw the wifi-connect project, but one of our use cases is that the user will also be able to connect the device in a hotel, where there is a captive form when connecting to the wifi.
how do we by pass that? how can i enable the user to put the right captive for the raspberry pi ? (or any other HW)

and another question, related, are we able to provide a hotspot and simultaneously be connected using the same wifi to the network?

Hi
Right now this is not easily possible - see an in-depth discussion on this issue on GitHub here - https://github.com/balena-io/wifi-connect/issues/51
The gist of it is (as you have figured already) that we would need to have simultaneous station + AP mode, which is an open issue in NetworkManager which we depend on.

Thanks for your reply.
Regarding the captive, did you guys encounter a solution for that? (i saw in the thread you sent spoofing and than proxing might help), but did you get something to work, with a bypass?
Regarding the hotspot+ap - will configuration with hotspad might work? Without using network manager at all. (Or the whole networking of Balena will disable that since its working with Network manager)

Daniel

We have not worked on bypassing hotel’s captive portals in wifi-connect and probably won’t work on this in the future as it is a really complex task.

As for using simultaneous client+AP mode, it is possible with NetworkManager managing the client interface and hostapd managing the AP virtual interface, but it is bit tricky. I would not recommend not using NetworkManager for the client interface as managing this from a container may lead to connectivity loss, e.g. when the container is restarted or there is an application or other problem with it.

The solution with NetworkManager is to add an udev rule to the OS - https://github.com/balena-os/meta-balena#udevrules. The udev rule needs to tell NetworkManager not to manage the AP interface when it is created. It should be similar to this:
ACTION=="add", SUBSYSTEM=="net", KERNEL=="vap0", ENV{NM_UNMANAGED}="1".

Then from your container you need to run:
iw dev wlan0 interface add vap0 type __ap

That will create the virtual AP interface which you may use with hostapd. I have tried that before and it worked. You may need to tweak the commands if necessary as I am writing those down from memory. You may also need to bring the wlan0 interface down if necessary - you can experiment and see what will work.

Alternatively you may always use a WiFi dongle for the AP interface and most of our users who need a secondary AP interface use that instead.

Our balenaFin board provides a secondary uap0 interface, which is for this purpose and the AP interface there could be even managed from NetworkManager.

Thanks for the detailed answer.
i will try that and update, we might end up just putting another wifi on the board we are building.

Hi, i’ve tried as @majorz suggested.
its partly working, i’ve googled a lot, maybe you can help here from your experience.
i can see the hotspot created (i’ve created the hotspot using hostapd), but i cant login, it always returns wrong password although its the right one.
Few things i’m wondering:

  1. regarding dnsmasq, should i turn off dns in network manager? what will be the effect on balena OS if i do that?
  2. when you say bring down wlan0, you mean only when setup, right? (it misses the point of having an AP and wireless connection)

Thanks,

Daniel

and another question, related, are we able to provide a hotspot and simultaneously be connected using the same wifi to the network?

I don’t know if this is advisable, or possible, but it would be done via controlling NetworkManager.

Your setup is super confusing to me; are you trying to make a balenaOS device which uses wifi-connect to create an AP for the user to connect to, and configure the device to use a hotel wifi as it’s uplink. Then, to remain in AP mode and allow the user’s mobile device to connect to it, and pass it through?

i mixed two questions in 1 post and that is a mistake.
the more important scenario:
our device which runs balena os, needs both to serve as a hotspot and be able to connect to a wifi network that has internet.
that way, our device could talk directly to the mobile app with hotspot, while also be connected to the internet.

thats what i’m trying to achieve with @majorz answer, he said this is not possible solely from network manager.

I think that’s a fair statement; using the 1 interface to do both isn’t something that I have experience with and if @majorz says it’s not possible in network manager then I would say it’s not a path to go down.

Is there any reason not to add a secondary interface and use that for the clients, and reserve the internal interface for backhaul?

well, since we have a board already, it will be adding another module, and i’m not sure what will be the impact in terms of RF reception when working with the device.

Hi Daniel, I got a ping from a teammate about your follow up.

  1. regarding dnsmasq, should i turn off dns in network manager? what will be the effect on balena OS if i do that?

You do not have to stop dnsmasq running on the host OS. The one that has to be setup in the container will not interfere with the one running on the host OS. They serve different purposes as well.

For reference you may check how we run dnsmasq in wifi-connect and maybe take a similar strategy: https://github.com/balena-io/wifi-connect/blob/master/src/dnsmasq.rs

  1. when you say bring down wlan0, you mean only when setup, right? (it misses the point of having an AP and wireless connection)

Right, however that may not be needed. I just tried adding the secondary __ap interface here and it did not borked my main connection.

What I advise about the other problem you described is make sure you first launch hostapd without any password requirements. Have it all running with an open network (passwordless) model first. Enabling debug mode for hostapd and the device you are connecting to it could be helpful as well. E.g. I use a Linux laptop and if I cannot connect to a network I can diagnose it easier if I enable NetworkManager and wpa_supplicant debug logging - https://wiki.gnome.org/Projects/NetworkManager/Debugging

As a side note: we may release a modified NetworkManager soon in a next OS release which will support internally the dual STA+AP mode. I have been looking into this for the past week, trying to patch NetworkManager, but it is not still clear whether this will work. Currently chances are 80% it will work. If I am successful we should release that in a month or two, but I cannot promise anything for now as I do not have anything working yet. Fingers crossed.

Please let me know if you have any further questions. You may also ask for my direct attention, so that we make sure it gets answered by me directly.

Thanks,
Zahari

thank you, will try without any password first.
we are currently working in the staging enviorment, so i’m ready to do some QA to the NetworkManager feature :slight_smile: