Skip to content
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

Small wireless configuration fixes #1753

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions rust/agama-server/src/network/nm/dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,18 +870,18 @@ fn wireless_config_from_dbus(conn: &OwnedNestedHash) -> Result<Option<WirelessCo
.iter()
.map(|u| u.downcast_ref::<u8>())
.collect::<Result<Vec<u8>, _>>()?;

let mut wireless_config = WirelessConfig {
mode: NmWirelessMode(mode).try_into()?,
ssid: SSID(ssid),
..Default::default()
};

if let Ok(band) = get_property::<String>(wireless, "band") {
if let Some(band) = get_optional_property::<String>(wireless, "band")? {
wireless_config.band = WirelessBand::try_from(band.as_str()).ok();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but I guess we could implement TryFrom<Value<'a>> and get rid of the if block.

}
wireless_config.channel = get_property(wireless, "channel")?;

if let Ok(bssid) = get_property::<zvariant::Array>(wireless, "bssid") {
if let Some(bssid) = get_optional_property::<zvariant::Array>(wireless, "bssid")? {
let bssid: Vec<u8> = bssid
.iter()
.map(|u| u.downcast_ref::<u8>())
Expand All @@ -897,7 +897,13 @@ fn wireless_config_from_dbus(conn: &OwnedNestedHash) -> Result<Option<WirelessCo
));
}

wireless_config.hidden = get_property(wireless, "hidden")?;
if let Some(channel) = get_optional_property(wireless, "channel")? {
wireless_config.channel = channel;
}

if let Some(hidden) = get_optional_property(wireless, "hidden")? {
wireless_config.hidden = hidden;
}

if let Some(security) = conn.get(WIRELESS_SECURITY_KEY) {
let key_mgmt: String = get_property(security, "key-mgmt")?;
Expand Down Expand Up @@ -961,7 +967,10 @@ fn wireless_config_from_dbus(conn: &OwnedNestedHash) -> Result<Option<WirelessCo
.collect::<Result<Vec<WPAProtocolVersion>, InvalidWPAProtocolVersion>>()?;
wireless_config.wpa_protocol_versions = wpa_protocol_versions
}
wireless_config.pmf = get_property(security, "pmf")?;

if let Some(pmf) = get_optional_property(security, "pmf")? {
wireless_config.pmf = pmf;
}
}

Ok(Some(wireless_config))
Expand Down
6 changes: 6 additions & 0 deletions rust/package/agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Nov 14 14:45:47 UTC 2024 - Knut Alejandro Anderssen González <[email protected]>

- Get some wireless settings as optional in order to not break the
connections reader (gh#agama-project/agama#1753).

-------------------------------------------------------------------
Wed Nov 13 12:03:02 UTC 2024 - Imobach Gonzalez Sosa <[email protected]>

Expand Down
9 changes: 8 additions & 1 deletion web/package/agama-web-ui.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Nov 14 14:42:46 UTC 2024 - Knut Anderssen <[email protected]>

- Fix wireless authentication initialization and
invalidate the cached query in case of connected
(gh#agama-project/agama#1753).

-------------------------------------------------------------------
Wed Nov 13 12:06:41 UTC 2024 - Imobach Gonzalez Sosa <[email protected]>

Expand All @@ -20,7 +27,7 @@ Tue Nov 5 11:33:12 UTC 2024 - Imobach Gonzalez Sosa <[email protected]>

- Fix a crash when editing a network connection containing an
additional IP address (gh#agama-project/agama#1728).

-------------------------------------------------------------------
Mon Nov 4 20:32:29 UTC 2024 - David Diaz <[email protected]>

Expand Down
10 changes: 9 additions & 1 deletion web/src/components/network/WifiConnectionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const selectorOptions = security_options.map((security) => (
<FormSelectOption key={security.value} value={security.value} label={security.label} />
));

const securityFrom = (supported) => {
if (supported.includes("WPA2")) return "wpa-psk";
if (supported.includes("WPA1")) return "wpa-psk";
return "";
};

// FIXME: improve error handling. The errors props should have a key/value error
// and the component should show all of them, if any
export default function WifiConnectionForm({
Expand All @@ -71,7 +77,9 @@ export default function WifiConnectionForm({
const { mutate: updateConnection } = useConnectionMutation();
const { mutate: updateSelectedNetwork } = useSelectedWifiChange();
const [ssid, setSsid] = useState<string>(network.ssid);
const [security, setSecurity] = useState<string>(settings.security);
const [security, setSecurity] = useState<string>(
settings?.security || securityFrom(network?.security || []),
);
const [password, setPassword] = useState<string>(settings.password);
const [showErrors, setShowErrors] = useState<boolean>(Object.keys(errors).length > 0);
const [isConnecting, setIsConnecting] = useState<boolean>(false);
Expand Down
6 changes: 4 additions & 2 deletions web/src/components/network/WifiNetworksListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
useRemoveConnectionMutation,
useSelectedWifi,
useSelectedWifiChange,
useNetworkConfigChanges,
useWifiNetworks,
} from "~/queries/network";
import { slugify } from "~/utils";
Expand Down Expand Up @@ -222,11 +223,12 @@ const NetworkListItem = ({ network }) => {
* Component for displaying a list of available Wi-Fi networks
*/
function WifiNetworksListPage() {
useNetworkConfigChanges();
const networks: WifiNetwork[] = useWifiNetworks();
const { ssid: selectedSsid, hidden } = useSelectedWifi();
// FIXME: improve below type casting, if possible
const selected = hidden
? // FIXME: improve below type casting, if possible
(HIDDEN_NETWORK as unknown as WifiNetwork)
? (HIDDEN_NETWORK as unknown as WifiNetwork)
: networks.find((n) => n.ssid === selectedSsid);
const { mutate: changeSelection } = useSelectedWifiChange();

Expand Down
1 change: 1 addition & 0 deletions web/src/queries/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ const useNetworkConfigChanges = () => {
) {
if (current_device.state !== data.state) {
queryClient.invalidateQueries({ queryKey: ["network"] });
return changeSelected.mutate({ needsAuth: false });
}
}
if ([DeviceState.NEEDAUTH, DeviceState.FAILED].includes(data.state)) {
Expand Down
Loading