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

Beniamino Galvani bgalvani at redhat.com
Mon Jan 23 12:49:52 UTC 2023


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
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/networkmanager/attachments/20230123/f6d9a647/attachment.sig>


More information about the Networkmanager mailing list