Skip to content

Commit

Permalink
core: services: wifi: Add support for unsecure networks
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric committed May 22, 2023
1 parent 538c245 commit 94d39be
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions core/services/wifi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,31 @@ async def connect(credentials: WifiCredentials, hidden: bool = False) -> Any:
logger.info("Network is not known.")
is_new_network = True

if credentials.password == "" and network_id is None:
is_secure = False
try:
available_networks = await wifi_manager.get_wifi_available()
scanned_network = next(filter(lambda network: network.ssid == credentials.ssid, available_networks))
flags_for_passwords = ["WPA", "WEP", "WSN"]
for candidate in flags_for_passwords:
if candidate in scanned_network.flags:
is_secure = True
break
except StopIteration:
logger.info("Could not find wifi network around.")

if credentials.password == "" and network_id is None and is_secure:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="No password received and network not found among saved ones.",
)

try:
if credentials.password != "":
if network_id:
logger.info("Removing old entry for known network.")
await wifi_manager.remove_network(network_id)
else:
logger.info("Saving new network entry.")
network_id = await wifi_manager.add_network(credentials, hidden)
if network_id:
logger.info("Removing old entry for known network.")
await wifi_manager.remove_network(network_id)
else:
logger.info("Saving new network entry.")
network_id = await wifi_manager.add_network(credentials, hidden)

logger.info("Performing network connection.")
if network_id is None:
Expand Down

0 comments on commit 94d39be

Please sign in to comment.