MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / create_hotspot_connection_file

Function create_hotspot_connection_file

OpenHD/ohd_interface/src/wifi_hotspot.cpp:42–73  ·  view source on GitHub ↗

NOTE: This creates the proper NM connection, but does not start it yet.

Source from the content-addressed store, hash-verified

40
41// NOTE: This creates the proper NM connection, but does not start it yet.
42static bool create_hotspot_connection_file(const WiFiCard& card,
43 const bool is_air,
44 const bool use_5g_channel) {
45 // delete any previous connection that might exist. This might fail if no
46 // connection of that name exists - aka an error here can be ignored. We
47 // re-create it just to be sure, since for example, the wifi card might have
48 // been changed during re-boots.
49 if (OHDFilesystemUtil::exists(
50 get_ohd_wifi_hotspot_connection_nm_filename())) {
51 OHDUtil::run_command("nmcli",
52 {"con", "delete", OHD_WIFI_HOTSPOT_CONNECTION_NAME});
53 }
54 // and create the hotspot one
55 OHDUtil::run_command(
56 "nmcli",
57 {"con add type wifi ifname", card.device_name, "con-name",
58 OHD_WIFI_HOTSPOT_CONNECTION_NAME, "autoconnect no",
59 fmt::format("ssid {}", is_air ? "openhd_air" : "openhd_ground")});
60 OHDUtil::run_command("nmcli",
61 {"con modify ", OHD_WIFI_HOTSPOT_CONNECTION_NAME,
62 " 802-11-wireless.mode ap", "802-11-wireless.band",
63 use_5g_channel ? "a" : "bg", "ipv4.method shared"});
64 OHDUtil::run_command("nmcli",
65 {"con modify ", OHD_WIFI_HOTSPOT_CONNECTION_NAME,
66 " wifi-sec.key-mgmt wpa-psk"});
67 OHDUtil::run_command("nmcli",
68 {"con modify ", OHD_WIFI_HOTSPOT_CONNECTION_NAME,
69 " wifi-sec.psk \"openhdopenhd\""});
70 OHDUtil::run_command("nmcli", {"con modify", OHD_WIFI_HOTSPOT_CONNECTION_NAME,
71 "ipv4.addresses 192.168.3.1/24"});
72 return true;
73}
74
75bool WifiHotspot::util_delete_nm_file() {
76 // cleanup - proper stop of openhd, do not leave any traces behind.

Callers 1

WifiHotspotMethod · 0.85

Tested by

no test coverage detected