I want to create a hotspot network using libnm in C. I tried following the following steps:
- Connect to NetworkManager using
nm_client_new(NULL, NULL); - Get the wlan device
nm_client_get_device_by_iface(client, "wlan0"); - Create the connection
nm_simple_connection_new(): nm_setting_connection_new()withg_object_set("type", "802-11-wireless", "uuid", HOTSPOT_UUID, "id", "MyHotspot", "autoconnect", FALSE);and added to connectionnm_setting_wireless_new()with mode=adhoc, ssid=MyHotspotSSIDnm_setting_ip4_config_new()with method=sharednm_setting_ip6_config_new()with method=ignorenm_setting_wireless_security_new()with key-mgmt=none, wep-key0=key_str, wep-key-type=NM_WEP_KEY_TYPE_KEYnm_client_add_and_activate_connection_async(client, connection, wlan_device, NULL, NULL, on_connection_added, loop);, loop being a GMainLoop.g_main_loop_run(loop);
After those steps are done, it seemingly finishes instantly, but for some reason, there is no new connection and is not activated. Callback of nm_client_add_and_activate_connection_async never getting called. I also tried without wep-key0 or the loop, just waiting for the callback, none of which worked.
Am I missing some steps? What am I doing wrong?
Edit: In the on_connection_added, I am calling nm_client_add_and_activate_connection_finish(NM_CLIENT(source_object), res, &error) but may not matter since the callback is never reached. I also call g_main_loop_quit(user_data); after the _finish function.
I have found out the issue, I did take the correct steps, but the actual code was unreachable. This took a genuinly long timr to figure out what was wrong. Sorry for spamming the forum!