Skip to content

Commit 196e9eb

Browse files
krish2718rlubos
authored andcommitted
net: lib: wifi_prov_core: Fix Unicode encoding issues on Windows
Fix Windows build failures caused by Unicode characters in Python scripts that cannot be encoded in cp1252 codec. Root cause: Python scripts used Unicode emoji characters (✅, ❌, 📄, 🔧, 📊) that are not supported in Windows' default cp1252 encoding. Fix: Replace all Unicode characters with ASCII alternatives: - ✅ → [OK] - ❌ → [ERROR] - 📄 → [JSON] - �� → [PROTO] - 📊 → [INFO] This ensures cross-platform compatibility while maintaining clear status messages. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 3dd0926 commit 196e9eb

File tree

2 files changed

+30
-40
lines changed

2 files changed

+30
-40
lines changed

subsys/net/lib/wifi_prov_core/proto/generate_wifi_prov_config.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def check_required_files(cert_dir):
7878
print(f"Error: Missing required certificate files: {missing_files}")
7979
return False
8080

81-
print(f" All required certificate files found in {cert_dir}")
81+
print(f"[OK] All required certificate files found in {cert_dir}")
8282
return True
8383

8484
def generate_wifi_config(ssid, bssid, channel=6, band=1, auth_mode=5,
@@ -142,6 +142,7 @@ def generate_wifi_config(ssid, bssid, channel=6, band=1, auth_mode=5,
142142

143143
# Handle EAP-TLS mode
144144
if cert_dir is not None:
145+
# Check if all required files exist
145146
if not check_required_files(cert_dir):
146147
return None
147148

@@ -155,10 +156,10 @@ def generate_wifi_config(ssid, bssid, channel=6, band=1, auth_mode=5,
155156
client_cert2_data = read_cert_file(os.path.join(cert_dir, 'client2.pem'))
156157
private_key2_data = read_cert_file(os.path.join(cert_dir, 'client-key2.pem'))
157158

158-
print(" Successfully read all certificate files")
159+
print("[OK] Successfully read all certificate files")
159160

160161
# Create EnterpriseCertConfig
161-
# MbedTLS uses null-terminator to distinguis b/w PEM and DER formats
162+
# MbedTLS uses null-terminator to distinguish b/w PEM and DER formats
162163
def add_null_terminator(data):
163164
if data and not data.endswith(b'\0'):
164165
return data + b'\0'
@@ -177,30 +178,30 @@ def add_null_terminator(data):
177178
cert_config.password = password
178179

179180
wifi_config.certs.CopyFrom(cert_config)
180-
print(" EAP-TLS mode configured")
181+
print("[OK] EAP-TLS mode configured")
181182

182183
# Handle Personal mode
183184
elif passphrase is not None:
184185
wifi_config.passphrase = passphrase.encode('utf-8')
185-
print(" Personal mode configured")
186+
print("[OK] Personal mode configured")
186187

187188
else:
188-
print(" Error: Must specify either --cert-dir (EAP-TLS) or --passphrase (Personal)")
189+
print("[ERROR] Error: Must specify either --cert-dir (EAP-TLS) or --passphrase (Personal)")
189190
return None
190191

191192
# Create Request
192193
request = Request()
193194
request.op_code = OpCode.SET_CONFIG
194195
request.config.CopyFrom(wifi_config)
195196

196-
print(" Successfully created protobuf message")
197+
print("[OK] Successfully created protobuf message")
197198
return request
198199

199200
except ValueError as e:
200-
print(f" Error creating configuration: {e}")
201+
print(f"[ERROR] Error creating configuration: {e}")
201202
raise # Re-raise ValueError to be caught by caller
202203
except Exception as e:
203-
print(f" Error creating configuration: {e}")
204+
print(f"[ERROR] Error creating configuration: {e}")
204205
return None
205206

206207
def main():
@@ -291,12 +292,12 @@ def main():
291292
from google.protobuf.json_format import MessageToDict
292293

293294
json_data = MessageToDict(request, preserving_proto_field_name=True)
294-
print("📄 JSON Configuration:")
295+
print("[JSON] JSON Configuration:")
295296
print(json.dumps(json_data, indent=2))
296297
print()
297298

298299
# Always show encoded protobuf string
299-
print("🔧 Encoded Protobuf (Base64):")
300+
print("[PROTO] Encoded Protobuf (Base64):")
300301
print(base64.b64encode(serialized).decode('utf-8'))
301302
print()
302303

@@ -309,14 +310,14 @@ def main():
309310
json_data = MessageToDict(request, preserving_proto_field_name=True)
310311
with open(args.output, 'w') as f:
311312
json.dump(json_data, f, indent=2)
312-
print(f" JSON configuration written to: {args.output}")
313+
print(f"[OK] JSON configuration written to: {args.output}")
313314
else:
314315
# Save as binary protobuf
315316
with open(args.output, 'wb') as f:
316317
f.write(serialized)
317-
print(f" Binary protobuf written to: {args.output}")
318+
print(f"[OK] Binary protobuf written to: {args.output}")
318319

319-
print(f"📊 Protobuf size: {len(serialized)} bytes")
320+
print(f"[INFO] Protobuf size: {len(serialized)} bytes")
320321

321322
# Get auth mode name based on proto AuthMode enum (backward compatible)
322323
auth_names = {

subsys/net/lib/wifi_prov_core/proto/test_auth_modes.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,32 @@ def test_auth_mode_validation():
3030

3131
for mode in valid_modes:
3232
try:
33-
result = generate_wifi_config(
34-
ssid="TestWiFi",
35-
bssid="00:11:22:33:44:55",
36-
auth_mode=mode,
37-
passphrase="testpass"
38-
)
33+
result = generate_wifi_config("TestSSID", "AA:BB:CC:DD:EE:FF", auth_mode=mode)
3934
if result is not None:
40-
print(f" Auth mode {mode} is valid")
35+
print(f"[OK] Auth mode {mode} is valid")
4136
else:
42-
print(f" Auth mode {mode} returned None")
37+
print(f"[ERROR] Auth mode {mode} returned None")
4338
except ValueError as e:
44-
print(f" Auth mode {mode} failed: {e}")
39+
print(f"[ERROR] Auth mode {mode} failed: {e}")
4540
except Exception as e:
46-
print(f" Auth mode {mode} unexpected error: {e}")
41+
print(f"[ERROR] Auth mode {mode} unexpected error: {e}")
4742

4843
# Test invalid auth modes
49-
invalid_modes = [-1, 24, 100, 999]
50-
44+
invalid_modes = [-1, 100, 999]
5145
for mode in invalid_modes:
5246
try:
53-
result = generate_wifi_config(
54-
ssid="TestWiFi",
55-
bssid="00:11:22:33:44:55",
56-
auth_mode=mode,
57-
passphrase="testpass"
58-
)
59-
print(f"❌ Auth mode {mode} should have failed but didn't")
60-
except ValueError as e:
61-
if "invalid enumerator" in str(e):
62-
print(f"✅ Auth mode {mode} correctly rejected: {e}")
47+
result = generate_wifi_config("TestSSID", "AA:BB:CC:DD:EE:FF", auth_mode=mode)
48+
if result is not None:
49+
print(f"[ERROR] Auth mode {mode} should have failed but didn't")
6350
else:
64-
print(f"❌ Auth mode {mode} unexpected ValueError: {e}")
51+
print(f"[OK] Auth mode {mode} correctly rejected")
52+
except ValueError as e:
53+
print(f"[OK] Auth mode {mode} correctly rejected: {e}")
6554
except Exception as e:
66-
if "invalid enumerator" in str(e):
67-
print(f" Auth mode {mode} correctly rejected: {e}")
55+
if isinstance(e, ValueError):
56+
print(f"[ERROR] Auth mode {mode} unexpected ValueError: {e}")
6857
else:
69-
print(f" Auth mode {mode} unexpected error: {e}")
58+
print(f"[OK] Auth mode {mode} correctly rejected: {e}")
7059

7160
if __name__ == "__main__":
7261
test_auth_mode_validation()

0 commit comments

Comments
 (0)