Re: disable &/or activate wifi access point using libnm

On Wed, 2013-01-09 at 00:52 -0500, david feeney wrote:
> Hello,
> I have two questions:
> 1)  I would like to know how to disable an active Wifi Access Point;
> I do not want to disable the device, just the disconnect the Access
> Point.

You'd call the Disconnect() method of the Device object which you'd like
to disconnect from the AP.  This places the device into "manual" mode
where it will no longer autoconnect to any network unless it's told to
connect via the D-Bus API.  This function is nm_device_disconnect() in

You can also use the Manager object's DeactivateConnection() method,
which will terminate the network connection and then proceed to
determine the best available network to connect to, and reconnect.
That's likely to be the exact same network you were just connected to
however.  This function is nm_client_deactivate_connection() in

> for example, from the example get-ap-info-libnm-glib.c :
> ===================
>     /* Get active AP */
>     if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) {
>         if ((active_ap = nm_device_wifi_get_active_access_point
> (NM_DEVICE_WIFI (device)))) {
>             active_ssid = nm_access_point_get_ssid (active_ap);
>             active_ssid_str = nm_utils_ssid_to_utf8 (active_ssid);
>         }
>     }
> ===================
> How would I disable "active_ap"?

That code deals with a specific wifi AP; disconnecting from a specific
wifi AP is likely not what you want (though it could be?).  Instead I
assume you want to disconnect from the wifi network which that AP is a
part of (ie, disconnect from that SSID).  Is that correct?

If so, then the stuff I talked about above is how to do that.

Disconnecting from a specific WiFi AP isn't something that's generally
useful, though if that's what you're trying to do we can discuss that

> 2)  Similarly,  how would I active a different Access_point "xyz"?

Again, *access point* or wifi network (ie, SSID)?  If we're talking
about wifi network (ie, SSID), then there needs to be a Connection
object created for that.  Think of the Connection object as a bundle of
properties that describe a network, including the SSID, security
settings, etc.  This can be done either by:

a) building up the connection manually (via nm_connection_new(),
nm_connection_add_setting(), etc) and then calling
nm_remote_settings_add_connection() and finally
nm_client_activate_connection() on the returned object.

b) calling nm_client_add_and_activate_connection() with object path of
the NMAccessPoint object you'd like to use as a template for the final
Connection.  This will create the new connection, save it to disk, and
then attempt to connect to that wifi network.

See add-connection-libnm-glib.c for (a), and for (b) see in
conjunction with .


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