Skip to content

Commit 8ef23c0

Browse files
author
Alex J Lennon
committed
improv: Explicitly set psk-flags=0 using nmcli connection modify
NetworkManager 1.46.0 may not write psk-flags=0 to the keyfile even when set in nmcli.connection.add(). The NetworkManager patch REQUIRES psk-flags=0 to be explicitly in the file to detect that secrets are stored. Add explicit 'nmcli connection modify' call after creating the connection to force psk-flags=0 to be written to the connection file. This ensures the NetworkManager patch will activate correctly. Applied to both: - Generic onboarding-server.py - imx93-jaguar-eink/onboarding-server-eink.py
1 parent e84934d commit 8ef23c0

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

recipes-devtools/python/python3-improv/imx93-jaguar-eink/onboarding-server-eink.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,29 @@ def wifi_connect(ssid: str, passwd: str) -> Optional[list[str]]:
172172
print(f'Could not add new connection {CON_NAME}: {e}')
173173
return None
174174

175+
# CRITICAL: Explicitly modify connection to ensure psk-flags=0 is written to file
176+
# NetworkManager 1.46.0 may not write psk-flags=0 to the keyfile if it's the default,
177+
# but the NetworkManager patch REQUIRES it to be explicitly in the file to detect
178+
# that secrets are stored. Use nmcli connection modify to force it to be written.
179+
try:
180+
subprocess.run(['nmcli', 'connection', 'modify', f"{CON_NAME}",
181+
'802-11-wireless-security.psk-flags', '0'],
182+
check=True, capture_output=True, timeout=5)
183+
logger.debug(f"Explicitly set psk-flags=0 for connection {CON_NAME}")
184+
except subprocess.CalledProcessError as e:
185+
logger.warning(f"Could not explicitly set psk-flags=0 (exit code {e.returncode}): {e.stderr.decode() if e.stderr else 'unknown error'}")
186+
# Continue - connection was created, but psk-flags may not be in file
187+
except subprocess.TimeoutExpired as e:
188+
logger.warning(f"Timeout setting psk-flags=0: {e}")
189+
except FileNotFoundError:
190+
logger.error(f"nmcli command not found - cannot set psk-flags=0")
191+
except Exception as e:
192+
logger.warning(f"Unexpected error setting psk-flags=0: {e}")
193+
175194
# NetworkManager automatically saves connections when created/modified
176195
# In NetworkManager 1.46.0+, connections are saved automatically to
177196
# /etc/NetworkManager/system-connections/ when created with nmcli.connection.add()
178-
# The psk-flags=0 setting is persisted automatically.
197+
# The explicit modify above ensures psk-flags=0 is written to the file.
179198
# Use 'reload' to ensure NetworkManager picks up the connection immediately
180199
try:
181200
subprocess.run(['nmcli', 'connection', 'reload'],

recipes-devtools/python/python3-improv/onboarding-server.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,29 @@ def wifi_connect(ssid: str, passwd: str) -> Optional[list[str]]:
128128
print(f'Could not add new connection {CON_NAME}: {e}')
129129
return None
130130

131+
# CRITICAL: Explicitly modify connection to ensure psk-flags=0 is written to file
132+
# NetworkManager 1.46.0 may not write psk-flags=0 to the keyfile if it's the default,
133+
# but the NetworkManager patch REQUIRES it to be explicitly in the file to detect
134+
# that secrets are stored. Use nmcli connection modify to force it to be written.
135+
try:
136+
subprocess.run(['nmcli', 'connection', 'modify', f"{CON_NAME}",
137+
'802-11-wireless-security.psk-flags', '0'],
138+
check=True, capture_output=True, timeout=5)
139+
logger.debug(f"Explicitly set psk-flags=0 for connection {CON_NAME}")
140+
except subprocess.CalledProcessError as e:
141+
logger.warning(f"Could not explicitly set psk-flags=0 (exit code {e.returncode}): {e.stderr.decode() if e.stderr else 'unknown error'}")
142+
# Continue - connection was created, but psk-flags may not be in file
143+
except subprocess.TimeoutExpired as e:
144+
logger.warning(f"Timeout setting psk-flags=0: {e}")
145+
except FileNotFoundError:
146+
logger.error(f"nmcli command not found - cannot set psk-flags=0")
147+
except Exception as e:
148+
logger.warning(f"Unexpected error setting psk-flags=0: {e}")
149+
131150
# NetworkManager automatically saves connections when created/modified
132151
# In NetworkManager 1.46.0+, connections are saved automatically to
133152
# /etc/NetworkManager/system-connections/ when created with nmcli.connection.add()
134-
# The psk-flags=0 setting is persisted automatically.
153+
# The explicit modify above ensures psk-flags=0 is written to the file.
135154
# Use 'reload' to ensure NetworkManager picks up the connection immediately
136155
try:
137156
subprocess.run(['nmcli', 'connection', 'reload'],

0 commit comments

Comments
 (0)