-
Notifications
You must be signed in to change notification settings - Fork 1.2k
networkmanager: Add Wi-Fi support #22884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
2e4f4d5
2049f72
8a159d9
ea1ad34
2a84d4f
712d534
199d199
f11562d
d59eec8
8f7f610
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -610,6 +610,13 @@ export function NetworkManagerModel() { | |
| }; | ||
| } | ||
|
|
||
| if (settings["802-11-wireless"]) { | ||
| result["802-11-wireless"] = { | ||
| ssid: get("802-11-wireless", "ssid"), | ||
| mode: get("802-11-wireless", "mode"), | ||
| }; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -784,6 +791,20 @@ export function NetworkManagerModel() { | |
| delete result.wireguard; | ||
| } | ||
|
|
||
| if (settings["802-11-wireless"]) { | ||
| set("802-11-wireless", "ssid", 'ay', settings["802-11-wireless"].ssid); | ||
| set("802-11-wireless", "mode", 's', settings["802-11-wireless"].mode); | ||
| } else { | ||
| delete result["802-11-wireless"]; | ||
| } | ||
|
|
||
| if (settings["802-11-wireless-security"]) { | ||
| set("802-11-wireless-security", "key-mgmt", 's', settings["802-11-wireless-security"]["key-mgmt"]); | ||
| set("802-11-wireless-security", "psk", 's', settings["802-11-wireless-security"].psk); | ||
| } else { | ||
| delete result["802-11-wireless-security"]; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -860,6 +881,21 @@ export function NetworkManagerModel() { | |
| } | ||
| } | ||
|
|
||
| function access_point_mode_to_text(mode) { | ||
| switch (mode) { | ||
| // NM_802_11_MODE_ADHOC | ||
| case 1: return _("Adhoc"); | ||
| // NM_802_11_MODE_INFRA | ||
| case 2: return _("Infra"); | ||
| // NM_802_11_MODE_AP | ||
| case 3: return _("AP"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This added line is not executed by any test. Details |
||
| // NM_802_11_MODE_MESH | ||
| case 4: return _("Mesh"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This added line is not executed by any test. Details |
||
| // subsumes NM_802_11_MODE_UNKNOWN | ||
| default: return _("Unknown"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This added line is not executed by any test. Details |
||
| } | ||
| } | ||
|
|
||
| const connections_by_uuid = { }; | ||
|
|
||
| function set_settings(obj, settings) { | ||
|
|
@@ -942,6 +978,37 @@ export function NetworkManagerModel() { | |
| } | ||
| }; | ||
|
|
||
| const type_AccessPoint = { | ||
| interfaces: [ | ||
| "org.freedesktop.NetworkManager.AccessPoint" | ||
| ], | ||
|
|
||
| props: { | ||
| Flags: { def: 0 }, | ||
| WpaFlags: { def: 0 }, | ||
| RsnFlags: { def: 0 }, | ||
| Ssid: { conv: utils.ssid_from_nm, def: "" }, | ||
| Frequency: { def: 0 }, // MHz | ||
| HwAddress: { def: "" }, | ||
| Mode: { conv: access_point_mode_to_text, def: "" }, | ||
| MaxBitrate: { def: 0 }, // Kbit/s | ||
| Bandwidth: { def: 0 }, // MHz | ||
| Strength: { def: 0 }, | ||
| LastSeen: { def: -1 }, // CLOCK_BOOTTIME seconds, -1 if never seen | ||
| }, | ||
|
|
||
| exporters: [ | ||
| function (obj) { | ||
| // Find connection for this SSID (undefined if none exists) | ||
| obj.Connection = (self.get_settings()?.Connections || []).find(con => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This added line is not executed by any test. Details |
||
| if (con.Settings?.["802-11-wireless"]?.ssid) | ||
| return utils.ssid_from_nm(con.Settings["802-11-wireless"].ssid) == obj.Ssid; | ||
| return false; | ||
| }); | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| const type_Connection = { | ||
| interfaces: [ | ||
| "org.freedesktop.NetworkManager.Settings.Connection" | ||
|
|
@@ -1052,7 +1119,8 @@ export function NetworkManagerModel() { | |
| props: { | ||
| Connection: { conv: conv_Object(type_Connection) }, | ||
| Ip4Config: { conv: conv_Object(type_Ipv4Config) }, | ||
| Ip6Config: { conv: conv_Object(type_Ipv6Config) } | ||
| Ip6Config: { conv: conv_Object(type_Ipv6Config) }, | ||
| State: { def: 0 } | ||
| // See below for "Group" | ||
| }, | ||
|
|
||
|
|
@@ -1073,7 +1141,8 @@ export function NetworkManagerModel() { | |
| "org.freedesktop.NetworkManager.Device.Bond", | ||
| "org.freedesktop.NetworkManager.Device.Team", | ||
| "org.freedesktop.NetworkManager.Device.Bridge", | ||
| "org.freedesktop.NetworkManager.Device.Vlan" | ||
| "org.freedesktop.NetworkManager.Device.Vlan", | ||
| "org.freedesktop.NetworkManager.Device.Wireless" | ||
| ], | ||
|
|
||
| props: { | ||
|
|
@@ -1093,6 +1162,9 @@ export function NetworkManagerModel() { | |
| Carrier: { def: true }, | ||
| Speed: { }, | ||
| Managed: { def: false }, | ||
| // WiFi-specific properties | ||
| AccessPoints: { conv: conv_Array(conv_Object(type_AccessPoint)), def: [] }, | ||
| ActiveAccessPoint: { conv: conv_Object(type_AccessPoint) }, | ||
| // See below for "Members" | ||
| }, | ||
|
|
||
|
|
@@ -1109,7 +1181,10 @@ export function NetworkManagerModel() { | |
| return call_object_method(get_object("/org/freedesktop/NetworkManager", type_Manager), | ||
| "org.freedesktop.NetworkManager", "AddAndActivateConnection", | ||
| settings_to_nm(settings), objpath(this), objpath(specific_object)) | ||
| .then(([path, active_connection]) => active_connection); | ||
| .then(([path, active_connection_path]) => ({ | ||
| connection: get_object(path, type_Connection), | ||
| active_connection: get_object(active_connection_path, type_ActiveConnection) | ||
| })); | ||
| } catch (e) { | ||
| return Promise.reject(e); | ||
| } | ||
|
|
@@ -1118,6 +1193,16 @@ export function NetworkManagerModel() { | |
| disconnect: function () { | ||
| return call_object_method(this, 'org.freedesktop.NetworkManager.Device', 'Disconnect') | ||
| .then(() => undefined); | ||
| }, | ||
|
|
||
| // Request a WiFi scan to populate this.AccessPoints | ||
| request_scan: function() { | ||
| utils.debug("request_scan: requesting scan for", this.Interface); | ||
| call_object_method(this, 'org.freedesktop.NetworkManager.Device.Wireless', 'RequestScan', {}) | ||
| .catch(error => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This added line is not executed by any test. Details |
||
| // RequestScan can fail if a scan was recently done, that's OK | ||
| console.warn("request_scan: scan failed for", this.Interface + ":", error.toString()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This added line is not executed by any test. Details |
||
| }); | ||
| } | ||
| } | ||
| }; | ||
|
|
@@ -1362,7 +1447,8 @@ export function NetworkManagerModel() { | |
| type_Ipv4Config, | ||
| type_Ipv6Config, | ||
| type_Connection, | ||
| type_ActiveConnection | ||
| type_ActiveConnection, | ||
| type_AccessPoint | ||
| ]); | ||
|
|
||
| get_object("/org/freedesktop/NetworkManager", type_Manager); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added line is not executed by any test. Details