Re: Can anyone suggest an end-to-end example of how to establish wifi connection in C++



On Mon, 2021-08-02 at 09:44 -0700, Michael Uman wrote:
Hello,

I appreciate the answer I received the other day but unfortunately I
was unable to figure out how to accomplish this. I am looking for an
example of how to establish a new wifi connection to an AP using C++. I
will be using Qt 5.14 and qtdbus to access NM.... But I dont know what
steps are necessary to establish the connection. I will have the AP
SSID and the password, and need to create the network connnection.


Hi,


NetworkManager is about having connection profiles and activating them.

So, first you create a suitable profile (or, find it, if you already
have one). You can crate profile with "AddConnection2" D-Bus API. That
is basically what `nmcli connection add type wifi` does.
You can also use "AddAndActivateConnection2". That way, you can provide
an incomplete profile and an access point, and NetworkManager will
complete the missing values of the profile that gets created. Then it
will proceed to activate it. That is what `nmcli device wifi connect`
does (if you don't have a profile yet).

If you have a profile, then you can activate it by calling
"ActivateConnection".

Check the docs here:
https://networkmanager.dev/docs/api/latest/spec.html

In the simplest case, the profile already contains all secrets, and
"802-11-wireless-security.psk-flags" is set to zero (see `man nm-
settings` for "Secret flag types"). Otherwise, a program needs to run
which can provide the secret. That's a "secret agent". How to run a
secret agent was alluded by the mail by Andrei.


best,
Thomas



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]