[Networkmanager] Creating, enabling, disabling wifi access point using libnm-glib

VT102 VT102 at protonmail.com
Tue Jan 24 04:06:22 UTC 2023


Ben,

YOu can disregard my previous email about the callbacks failing to occur - after investigating more I understand I need to properly use Glib to achieve the callbacks.

Thanks,
Greg




Sent with Proton Mail secure email.

------- Original Message -------
On Monday, January 23rd, 2023 at 10:11 AM, VT102 <VT102 at protonmail.com> wrote:


> Thanks again Ben,
> 
> Unfortunately I am having issues getting the callbacks to fire for either the creation or the deletetion. I dont really have a way to do the deletion appropriately because I cant get a NMActiveConncetion without the callback completing. Either way, I cant think of why the completion callback is not occuring. I will post the entirety of this dirty code, which is just copied and stripped down from the nmcli example you provided. Im not sure if the callbacks are dependent upon the g_main_loop or something like that?
> 
> The basic code flow is below. Basically in checkAllWifiAccessPoints, there is a while loop for about 20 seconds to wait in case the callback was delayed for some reason, but debug logging never seems to catch it occuring.
> 
> main
> checkAllWifiAccessPoints // finds a wifi device, creates connection
> save_and_activate_connection // calls nm_client_add_and_activate_connection_async()
> 
> 
> 
> Thanks again,
> Greg
> 
> 
> 
> 
> 
> 
> 
> Sent with Proton Mail secure email.
> 
> 
> ------- Original Message -------
> On Monday, January 23rd, 2023 at 7:49 AM, Beniamino Galvani bgalvani at redhat.com wrote:
> 
> 
> 
> > On Mon, Jan 23, 2023 at 11:19:07AM +0000, VT102 wrote:
> > 
> > > Ben,
> > > 
> > > Thank you for taking the time to respond. I have been able to get some C code working to create a hot spot on the wlan0 device, however it is not clear to me how to close/delete the connection from the nmlib API.
> > > 
> > > I see that nmcli deletes connections using the nm_remote_connection_delete_aysnc api, however this does not work with the NMConnection that I created. Can you provide any guidance on this?
> > 
> > To disable the AP, you can either deactivate the connection profile
> > (for example, if you plan to use it again), or delete it.
> > 
> > To deactivate the profile use nm_client_deactivate_connection() and
> > pass the NMActiveConnection returned by
> > nm_client_add_and_activate_connection_finish().
> > 
> > To delete the profile, use nm_remote_connection_delete_async() on the
> > NMRemoteConnection associated with the NMActiveConnection; you can get
> > it using function "nm_active_connection_get_connection(active_con)".
> > 
> > Beniamino
> > 
> > > ------- Original Message -------
> > > On Friday, January 20th, 2023 at 3:23 AM, Beniamino Galvani bgalvani at redhat.com wrote:
> > > 
> > > > On Thu, Jan 19, 2023 at 12:07:11AM +0000, VT102 wrote:
> > > > 
> > > > > Hello,
> > > > 
> > > > > I have been looking through the source code documentation and
> > > > > examples but I'm not clear on if it would be possible to create,
> > > > > enable, and disable a wifi access point using the libnm-glib API?
> > > > 
> > > > Yes, it's possible. Note that "libnm-glib" is the name of an old
> > > > library to control NM that has been replaced by "libnm". What you want
> > > > to use really is libnm.
> > > > 
> > > > > I see that there is an example showing how to see existing AP's
> > > > > https://github.com/lcp/NetworkManager/blob/master/examples/C/glib/get-ap-info-libnm-glib.c
> > > > 
> > > > This git repo contains very old code, please check out the official
> > > > repository at
> > > > https://gitlab.freedesktop.org/NetworkManager/NetworkManager .
> > > > 
> > > > > I also see there is an NMAccessPoint data type from which I can get
> > > > > access point information, but I dont see any way to set it.
> > > > > https://developer-old.gnome.org/libnm-glib/stable/NMAccessPoint.html
> > > > 
> > > > You need to add new connection profile that contains the hotspot
> > > > parameters, and then call nm_client_add_and_activate_connection_async().
> > > > 
> > > > You can use the implementation of the "nmcli device wifi hotspot" as a
> > > > reference:
> > > > 
> > > > https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/1.40.10/src/nmcli/devices.c#L4475
> > > > 
> > > > This article also explain the basic concepts of libnm and how to use
> > > > it from Python:
> > > > 
> > > > https://fedoramagazine.org/using-python-and-networkmanager-to-control-the-network/
> > > > 
> > > > Beniamino


More information about the Networkmanager mailing list