Skip to content

Commit

Permalink
Small wireless configuration fixes (#1753)
Browse files Browse the repository at this point in the history
## Problem

- https://trello.com/c/5PjJQ2Vq

There are various issues detected when working on this PBI:

1. The authentication method is not selected properly
2. The form reports that auhentication failed when it is already
connected.
3. Some times the labels and buttons for the selected wifi does not
correspond whith the current state.
4. After a sync with master branch the backend started failing when
reading wireless connections

## Solution

We have fixes some of the issues but the handle of state is quite
fragile and coupled to the websockets notification in the frontend and
the UI therefore we plan to do some changes in the UI (Drawer and
selection of the WiFi) as well as in the backend trying to store the
authentication state there being able to request the state from the
backend without lostling any information in case of not subscribed to
changes.

About the fixes in particular:

1. The authentication method is recognized again (removed method
probably by error).
2. In case that a wireless device is activated the needAuth is also
removed from the cached queries
3. To be better handled.
4. Get some of the wireless settings as optional (band, channel, bssid,
hidden, pmf)

...

## Testing

- Tested manually
  • Loading branch information
teclator authored Nov 14, 2024
2 parents 363a4b3 + a375470 commit 07d5dab
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
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();
}
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

0 comments on commit 07d5dab

Please sign in to comment.