Hi,
I am trying to create a wifi hotspot using C++ code and the libnm-dev library. The following is the code I am using to publish the hotspot.
static void add_and_activate_cb(GObject* client, GAsyncResult* result, gpointer user_data) {
GMainLoop* loop = (GMainLoop*)user_data;
GError* error = NULL;
NMActiveConnection* active_connection = nm_client_add_and_activate_connection_finish(NM_CLIENT(client), result, &error);
if (active_connection) {
g_object_unref(active_connection);
}
else {
std::cerr << "Error creating hotspot: " << error->message << std::endl;
g_error_free(error);
}
// Stop the main loop
if (loop && g_main_loop_is_running(loop)) {
g_main_loop_quit(loop);
}
}
// Create a Wi-Fi hotspot with the given SSID and passphrase
void WiFi::createHotspot(const std::string& ssid, const std::string& passphrase, GMainLoop* loop)
{
NMConnection* connection = nm_simple_connection_new();
NMSettingConnection* s_con = NM_SETTING_CONNECTION(nm_setting_connection_new());
g_object_set(G_OBJECT(s_con),
NM_SETTING_CONNECTION_ID, "Hotspot",
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
NULL);
nm_connection_add_setting(connection, NM_SETTING(s_con));
NMSettingWireless* s_wifi = NM_SETTING_WIRELESS(nm_setting_wireless_new());
GBytes* ssid_bytes = g_bytes_new(ssid.data(), ssid.size());
g_object_set(G_OBJECT(s_wifi),
NM_SETTING_WIRELESS_SSID, ssid_bytes,
NM_SETTING_WIRELESS_MODE, NM_SETTING_WIRELESS_MODE_AP,
NULL);
g_bytes_unref(ssid_bytes);
nm_connection_add_setting(connection, NM_SETTING(s_wifi));
NMSettingIPConfig* s_ip4 = NM_SETTING_IP_CONFIG(nm_setting_ip4_config_new());
g_object_set(G_OBJECT(s_ip4),
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
NULL);
// Specify the static IP address for the hotspot
nm_setting_ip_config_add_address(s_ip4, nm_ip_address_new(AF_INET, "10.42.0.1", 24, NULL));
nm_connection_add_setting(connection, NM_SETTING(s_ip4));
// NMSettingWirelessSecurity* s_wsec = NM_SETTING_WIRELESS_SECURITY(nm_setting_wireless_security_new());
// g_object_set(G_OBJECT(s_wsec),
// NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-psk",
// NM_SETTING_WIRELESS_SECURITY_PSK, passphrase.c_str(),
// NULL);
// nm_connection_add_setting(connection, NM_SETTING(s_wsec));
nm_client_add_and_activate_connection_async(client_, connection, NM_DEVICE(wifi_device_), NULL, NULL, add_and_activate_cb, loop);
g_object_unref(connection);
}
Current progress:
- Able to search for wifi networks and their properties,
- able to publish the hotspot with the requisite info but unable to connect to it.
There are a few errors that prop up, output of networkmanage journalctl is as follows:
Apr 25 13:56:24 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430984.9064] dhcp4 (ethernet0): state changed new lease, address=192.168.0.158
Apr 25 13:55:53 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430953.8101] device (vethd4e9e19): released from master device docker0
Apr 25 13:55:53 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430953.6927] manager: (veth9527c23): new Veth device (/org/freedesktop/NetworkManager/Devices/24)
Apr 25 13:52:43 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430763.3798] device (uap0): supplicant interface state: disconnected -> inactive
Apr 25 13:52:43 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430763.3756] device (uap0): supplicant interface state: inactive -> disconnected
Apr 25 13:52:43 verdin-imx8mm-14756428 NetworkManager[595]: <warn> [1682430763.2797] device (uap0): set-hw-addr: failed to set MAC address to 86:46:5E:A6:86:59 (scanning) (NME_UNSPEC)
Apr 25 13:52:43 verdin-imx8mm-14756428 NetworkManager[595]: <warn> [1682430763.2796] platform-linux: do-change-link[5]: failure changing link: failure 1 (Operation not permitted)
Apr 25 13:51:24 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430684.9061] dhcp4 (ethernet0): state changed new lease, address=192.168.0.158
Apr 25 13:46:24 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430384.9051] dhcp4 (ethernet0): state changed new lease, address=192.168.0.158
Apr 25 13:45:50 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430350.3757] device (uap0): supplicant interface state: interface_disabled -> inactive
Apr 25 13:45:50 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430350.2886] device (uap0): supplicant interface state: inactive -> interface_disabled
Apr 25 13:45:50 verdin-imx8mm-14756428 NetworkManager[595]: <warn> [1682430350.2782] device (uap0): set-hw-addr: failed to set MAC address to F6:0E:16:F5:05:A7 (scanning) (NME_UNSPEC)
Apr 25 13:45:50 verdin-imx8mm-14756428 NetworkManager[595]: <warn> [1682430350.2781] platform-linux: do-change-link[5]: failure changing link: failure 1 (Operation not permitted)
Apr 25 13:41:24 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682430084.9064] dhcp4 (ethernet0): state changed new lease, address=192.168.0.158
Apr 25 13:38:57 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429937.3792] device (uap0): supplicant interface state: disconnected -> inactive
Apr 25 13:38:57 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429937.3751] device (uap0): supplicant interface state: inactive -> disconnected
Apr 25 13:38:57 verdin-imx8mm-14756428 NetworkManager[595]: <warn> [1682429937.2800] device (uap0): set-hw-addr: failed to set MAC address to 32:95:20:79:BB:3D (scanning) (NME_UNSPEC)
Apr 25 13:38:57 verdin-imx8mm-14756428 NetworkManager[595]: <warn> [1682429937.2799] platform-linux: do-change-link[5]: failure changing link: failure 1 (Operation not permitted)
Apr 25 13:37:05 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429825.1585] device (mlan0): Activation: successful, device activated.
Apr 25 13:37:05 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429825.0609] device (mlan0): state change: secondaries -> activated (reason 'none', sys-iface-state: 'managed')
Apr 25 13:37:05 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429825.0601] device (mlan0): state change: ip-check -> secondaries (reason 'none', sys-iface-state: 'managed')
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.9866] device (mlan0): state change: ip-config -> ip-check (reason 'none', sys-iface-state: 'managed')
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.9786] device (mlan0): state change: config -> ip-config (reason 'none', sys-iface-state: 'managed')
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.9773] device (mlan0): Activation: (wifi) Stage 2 of 5 (Device Configure) successful. Started Wi-Fi Hotspot "testNetwork"
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.9772] device (mlan0): supplicant interface state: disconnected -> completed
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.9371] device (mlan0): supplicant interface state: interface_disabled -> disconnected
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.8256] device (mlan0): supplicant interface state: disconnected -> interface_disabled
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.8248] Config: added 'key_mgmt' value 'NONE'
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.8248] Config: added 'frequency' value '2412'
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.8247] Config: added 'mode' value '2'
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.8247] Config: added 'ssid' value 'testNetwork'
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.8244] device (mlan0): Activation: (wifi) connection 'Hotspot' requires no security. No secrets needed.
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.8235] device (mlan0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.8218] device (mlan0): set-hw-addr: reset MAC address to 34:6F:24:31:32:F3 (preserve)
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.5348] device (mlan0): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'managed')
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.5300] audit: op="connection-add-activate" uuid="98ce9356-77df-4348-9662-8bbd5f0e6ae6" name="Hotspot" pid=5305 uid=1000 result="success"
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.5296] device (mlan0): Activation: starting connection 'Hotspot' (98ce9356-77df-4348-9662-8bbd5f0e6ae6)
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.4923] audit: op="device-managed" interface="mlan0" ifindex=4 args="true" pid=5305 uid=1000 result="success"
Apr 25 13:37:04 verdin-imx8mm-14756428 NetworkManager[595]: <info> [1682429824.4872] audit: op="radio-control" arg="wireless-enabled:on" pid=5305 uid=1000 result="success"
Output of dmesg is as follows:
[ 1532.339325] audit: type=1006 audit(1682429806.869:149): pid=5192 uid=0 old-auid=4294967295 auid=1000 tty=(none) old-ses=4294967295 ses=12 res=1
[ 1532.339342] audit: type=1300 audit(1682429806.869:149): arch=c00000b7 syscall=64 success=yes exit=4 a0=7 a1=fffff1c052a0 a2=4 a3=ffff8c4e9920 items=0 ppid=1 pid=5192 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=12 comm="sshd" exe="/usr/sbin/sshd" key=(null)
[ 1532.339353] audit: type=1327 audit(1682429806.869:149): proctitle=737368643A20746F72697A6F6E205B707269765D
[ 1533.274434] docker0: port 1(vethd4e9e19) entered blocking state
[ 1533.274511] docker0: port 1(vethd4e9e19) entered disabled state
[ 1533.276009] device vethd4e9e19 entered promiscuous mode
[ 1533.276970] audit: type=1700 audit(1682429807.809:150): dev=vethd4e9e19 prom=256 old_prom=0 auid=4294967295 uid=0 gid=0 ses=4294967295
[ 1533.277864] audit: type=1300 audit(1682429807.809:150): arch=c00000b7 syscall=206 success=yes exit=40 a0=f a1=4000df15f0 a2=28 a3=0 items=0 ppid=1 pid=729 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="dockerd" exe="/usr/bin/dockerd" key=(null)
[ 1533.277956] audit: type=1327 audit(1682429807.809:150): proctitle=2F7573722F62696E2F646F636B657264002D480066643A2F2F002D48007463703A2F2F3132372E302E302E313A32333735
[ 1533.397102] audit: type=1325 audit(1682429807.929:151): table=nat family=2 entries=15 op=xt_replace pid=5226 comm="iptables"
[ 1533.397535] audit: type=1300 audit(1682429807.929:151): arch=c00000b7 syscall=208 success=yes exit=0 a0=4 a1=0 a2=40 a3=aaaae1d6aff0 items=0 ppid=729 pid=5226 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="iptables" exe="/usr/sbin/xtables-legacy-multi" key=(null)
[ 1533.397848] audit: type=1327 audit(1682429807.929:151): proctitle=2F7573722F7362696E2F69707461626C6573002D2D77616974002D74006E6174002D4100444F434B4552002D7000746370002D6400302F30002D2D64706F7274003439313536002D6A00444E4154002D2D746F2D64657374696E6174696F6E003137322E31372E302E323A363530320000002D6900646F636B657230
[ 1533.419944] audit: type=1325 audit(1682429807.949:152): table=filter family=2 entries=30 op=xt_replace pid=5228 comm="iptables"
[ 1534.144998] eth0: renamed from veth9527c23
[ 1534.182073] IPv6: ADDRCONF(NETDEV_CHANGE): vethd4e9e19: link becomes ready
[ 1534.182221] docker0: port 1(vethd4e9e19) entered blocking state
[ 1534.182231] docker0: port 1(vethd4e9e19) entered forwarding state
[ 1550.416973] IPv6: ADDRCONF(NETDEV_CHANGE): mlan0: link becomes ready
[ 1662.733809] mwifiex_sdio mmc2:0001:1: CMD_RESP: cmd 0x4d error, result=0x1
[ 1662.740506] mwifiex_sdio mmc2:0001:1: set mac address failed: ret=-1
[ 1706.119572] mwifiex_sdio mmc2:0001:1: do not receive mgmt frames on uninitialized intf
[ 1766.108003] mwifiex_sdio mmc2:0001:1: do not receive mgmt frames on uninitialized intf
[ 1772.151408] mwifiex_sdio mmc2:0001:1: do not receive mgmt frames on uninitialized intf
[ 1930.578099] mwifiex_sdio mmc2:0001:1: do not receive mgmt frames on uninitialized intf
[ 2075.741744] mwifiex_sdio mmc2:0001:1: CMD_RESP: cmd 0x4d error, result=0x1
[ 2075.741791] mwifiex_sdio mmc2:0001:1: set mac address failed: ret=-1
[ 2441.149329] mwifiex_sdio mmc2:0001:1: do not receive mgmt frames on uninitialized intf
[ 2442.175809] mwifiex_sdio mmc2:0001:1: do not receive mgmt frames on uninitialized intf
[ 2488.754776] mwifiex_sdio mmc2:0001:1: CMD_RESP: cmd 0x4d error, result=0x1
[ 2488.760273] mwifiex_sdio mmc2:0001:1: set mac address failed: ret=-1
[ 2594.688520] mwifiex_sdio mmc2:0001:1: do not receive mgmt frames on uninitialized intf
[ 2679.024451] kauditd_printk_skb: 5 callbacks suppressed
[ 2679.024463] audit: type=1325 audit(1682430953.524:154): table=nat family=2 entries=17 op=xt_replace pid=5941 comm="iptables"
[ 2679.024914] audit: type=1300 audit(1682430953.524:154): arch=c00000b7 syscall=208 success=yes exit=0 a0=4 a1=0 a2=40 a3=aaab0b557520 items=0 ppid=729 pid=5941 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="iptables" exe="/usr/sbin/xtables-legacy-multi" key=(null)
[ 2679.025235] audit: type=1327 audit(1682430953.524:154): proctitle=2F7573722F7362696E2F69707461626C6573002D2D77616974002D74006E6174002D4400444F434B4552002D7000746370002D6400302F30002D2D64706F7274003439313536002D6A00444E4154002D2D746F2D64657374696E6174696F6E003137322E31372E302E323A363530320000002D6900646F636B657230
[ 2679.034178] audit: type=1325 audit(1682430953.534:155): table=filter family=2 entries=31 op=xt_replace pid=5944 comm="iptables"
[ 2679.034571] audit: type=1300 audit(1682430953.534:155): arch=c00000b7 syscall=208 success=yes exit=0 a0=4 a1=0 a2=40 a3=aaaafacf15f0 items=0 ppid=729 pid=5944 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="iptables" exe="/usr/sbin/xtables-legacy-multi" key=(null)
[ 2679.034856] audit: type=1327 audit(1682430953.534:155): proctitle=2F7573722F7362696E2F69707461626C6573002D2D77616974002D740066696C746572002D4400444F434B45520000002D6900646F636B657230002D6F00646F636B657230002D7000746370002D64003137322E31372E302E32002D2D64706F72740036353032002D6A00414343455054
[ 2679.044988] audit: type=1325 audit(1682430953.544:156): table=nat family=2 entries=16 op=xt_replace pid=5946 comm="iptables"
[ 2679.045401] audit: type=1300 audit(1682430953.544:156): arch=c00000b7 syscall=208 success=yes exit=0 a0=4 a1=0 a2=40 a3=aaab172af190 items=0 ppid=729 pid=5946 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="iptables" exe="/usr/sbin/xtables-legacy-multi" key=(null)
[ 2679.045710] audit: type=1327 audit(1682430953.544:156): proctitle=2F7573722F7362696E2F69707461626C6573002D2D77616974002D74006E6174002D4400504F5354524F5554494E47002D7000746370002D73003137322E31372E302E32002D64003137322E31372E302E32002D2D64706F72740036353032002D6A004D415351554552414445
[ 2679.055075] docker0: port 1(vethd4e9e19) entered disabled state
[ 2679.067072] veth9527c23: renamed from eth0
[ 2679.207441] docker0: port 1(vethd4e9e19) entered disabled state
[ 2679.209135] device vethd4e9e19 left promiscuous mode
[ 2679.209203] audit: type=1700 audit(1682430953.684:157): dev=vethd4e9e19 prom=0 old_prom=256 auid=4294967295 uid=0 gid=0 ses=4294967295
[ 2679.209485] docker0: port 1(vethd4e9e19) entered disabled state
[ 2798.126574] mwifiex_sdio mmc2:0001:1: do not receive mgmt frames on uninitialized intf
I believe there is an issue related to the permissions of my application container.
Can someone please take a look and advise?
Also, when working with bluetooth, I am unable to get a stable connection until a compat flag is added as per the following post:
maybe wifi has a similar caveat. dont know.
one more thing, if the hotspot is advertised with a password, a warning is raised by networkmanager about dnsmasq not being present.
Kindly advise.