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

Add support to set static IPs, gateway, DNS to wired/wireless networks #5

Open
wants to merge 26 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0ca6a42
Removed logic to disable ethernet
nikeflight Jan 16, 2025
79a1f9a
Add support for wireless:
nikeflight Jan 16, 2025
f437299
Added support for wired networks: setting static ip, gateway, netmask…
nikeflight Jan 17, 2025
afeb7b9
remove dhcpd in piaware_config.py
nikeflight Jan 20, 2025
531a9d0
Add start-network.service, start_network.py to up the connections aft…
nikeflight Jan 20, 2025
a07dffa
Merge pull request #6 from flightaware/wifi-reboot-fix
nikeflight Jan 20, 2025
9ca90ee
Revert network-manager to dhcp in wireless/wired-type
nikeflight Jan 21, 2025
e821e38
Add test commands to README
nikeflight Jan 21, 2025
c0140e6
Add in logic to `ip addr show` then | to `grep`. Makes parsing for br…
nikeflight Jan 22, 2025
885d14a
manually upping wireless connections is not needed. Because we create…
nikeflight Jan 22, 2025
3d3f25a
Change network manager back to dhcp in debian-bookworm/piaware-config…
nikeflight Jan 22, 2025
4d7474c
Merge branch 'wired-network-change' of https://github.com/flightaware…
nikeflight Jan 22, 2025
9bff625
Add an ignore_list field to MetadataSetting. Adding a file to this li…
nikeflight Jan 22, 2025
4b14afe
updated .gitignore
nikeflight Jan 22, 2025
5ca30df
Addressing PR comments
nikeflight Jan 23, 2025
ccda2fa
PR comments
nikeflight Jan 23, 2025
5389a40
Merge branch 'wired-network-change' of https://github.com/flightaware…
nikeflight Jan 23, 2025
b7e6b0a
PR comments
nikeflight Jan 23, 2025
69ecfef
Add shebang to generate_network_config_bookworm.py
nikeflight Jan 23, 2025
a930fbd
Merge pull request #7 from flightaware/verify-brd-address
nikeflight Jan 24, 2025
9d5f156
PR comments
nikeflight Jan 24, 2025
41cebad
drop .py extension from generate_network_config_bookworm
nikeflight Jan 27, 2025
eb6fdf5
Change ignore_list to deprecated field
nikeflight Jan 27, 2025
2a566ab
Clean up dict init
nikeflight Jan 27, 2025
12512bb
Chnage netmask to be dotted decimal format
nikeflight Jan 27, 2025
1c13391
Add in default netmask for class A,B,C static IPs
nikeflight Jan 28, 2025
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
81 changes: 81 additions & 0 deletions debian-bookworm/piaware-config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#
# This file configures the Piaware sdcard image
# configuration. Whenever the system boots, this
# file is read and its contents are used to
# configure the system.
#
# Lines beginning with a '#' are comment lines
# and are ignored. Blank lines are also ignored.
# All other lines specify configuration settings.
#

# For simplicity, this file only shows the most common options.
# For a complete list of options, see
# https://flightaware.com/adsb/piaware/advanced_configuration

#
# NETWORK CONFIGURATION
#

# By default, PiAware will use NetworkManager when connecting to your network.
nikeflight marked this conversation as resolved.
Show resolved Hide resolved
# For other configurations, see the Advanced Configuration page
# linked at the top of this file.

# For the latest Bookworm image, if an ethernet cable is inserted, wired-network will be enabled.
# If not, the wired-network will be disabled.

# Should piaware use a wifi adaptor for network access?
# If you are using a Pi 3, this will use the built-in wifi.
# Otherwise, you will need to attach a supported USB wifi adaptor.

wireless-network yes

# Wifi SSID and password.
# This should be changed to match your wireless
# network SSID and, for networks that require
# a passphrase, the passphrase.
#
# If your SSID or password contains characters other than
# numbers and letters, such as the # character or whitespace,
# you should enclose the value in quotation marks. For example,
# "pass word" or "pass#word".
#
# To include quotation marks (") in a quoted value, use \"
# To include a backslash (\) in a quoted value, use \\

wireless-ssid MyWifiNetwork
wireless-password s3cr3t99

#
# 1090MHZ RECEIVER CONFIGURATION
#

# For a complete list of receiver types and their associated settings,
# see the Advanced Configuration page linked at the top of this file.

# For a receiver type of 'rtlsdr', this setting controls the dongle gain.
# Use "max" for maximum gain. Other values are interpreted as a gain in dB.
rtlsdr-gain max

#
# OTHER CONFIGURATION
#

# Should automatic system updates (initiated by FlightAware) be allowed?
allow-auto-updates yes

# Should manual system updates (initiated by you from the website control
# panel) be allowed?
allow-manual-updates yes

# Should PiAware enable multilateration where possible?
# You may need to disable this if multilateration overloads your receiver.
allow-mlat yes

# Should PiAware enable reception of Mode A/C messages when requested?
# You may need to disable this if processing Mode A/C overloads your receiver.
allow-modeac yes


# Additional settings can be added below.

2 changes: 1 addition & 1 deletion debian-bookworm/piaware-support.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ scripts/set-rfkill usr/lib/piaware-support/
scripts/piaware-console-status usr/lib/piaware-support/
scripts/rpi-bootconfig usr/lib/piaware-support/
etc/modprobe.d/
piaware-config.txt boot/firmware
debian-bookworm/piaware-config.txt boot/firmware
debian/piaware-image-config.txt usr/share/piaware-support/
systemd/NetworkManager.service.d/restart.conf lib/systemd/system/NetworkManager.service.d/
systemd/config-ready.target lib/systemd/system/
Expand Down
85 changes: 52 additions & 33 deletions scripts/generate-network-config-bookworm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,79 @@
SYS_CON_DIR = "/etc/NetworkManager/system-connections"
FIRSTBOOT_PATH = "/run/firstboot"

def wireless_conn_file_template(new_uuid: str, ssid: str, psk: str):
return f"""[connection]
id=wireless
uuid={new_uuid}
type=wifi
def format_dns(dns_string: str) -> str:
names = dns_string.strip(" \n\t")
names = names.split(" ")
formatted = ";".join(names) + ";"
return formatted

[wifi]
mode=infrastructure
ssid={ssid}
def wireless_conn_file_template(new_uuid: str, config: ConfigGroup):
ssid = config.get("wireless-ssid")
psk = config.get("wireless-password")

[wifi-security]
key-mgmt=wpa-psk
psk={psk}
file = f"""
[connection]
id=wireless
uuid={new_uuid}
type=wifi

[ipv4]
method=auto
[wifi]
mode=infrastructure
ssid={ssid}

[ipv6]
addr-gen-mode=default
method=auto
[wifi-security]
key-mgmt=wpa-psk
psk={psk}
"""

[proxy]"""
ip = """
[ipv4]
"""
if config.get("wireless-type") == "static":
static_ip = config.get("wireless-address") + "/" + config.get("wireless-netmask")
gateway = config.get("wireless-gateway")
name_servers = format_dns(config.get("wireless-nameservers"))

def generate_network_config(config: ConfigGroup):
if config.get("wired-network"):
print("wired-network set to yes")
subprocess.run(["ip", "link", "set", "eth0", "up"])
if gateway is not None:
static_ip += f",{gateway}"
ip += f"""
address1={static_ip}
dns={name_servers}
method=manual
"""
else:
print("wired-network set to no")
subprocess.run(["ip", "link", "set", "eth0", "down"])
ip += """
method=auto
"""

ip += """
[ipv6]
addr-gen-mode=default
method=auto

[proxy]
"""
file += ip
return file

def generate_network_config(config: ConfigGroup):
if not config.get("wireless-network"):
print("wireless-network set to no")
subprocess.run(["nmcli", "radio", "wifi", "off"])
return

with open(f"{SYS_CON_DIR}/wireless.nmconnection", "w") as conn_file:
new_uuid = uuid4()
ssid = config.get("wireless-ssid")
psk = config.get("wireless-password")
conn_file.write(wireless_conn_file_template(new_uuid, config))

conn_file.write(wireless_conn_file_template(new_uuid, ssid, psk))
subprocess.run(["chmod", "600", f"{SYS_CON_DIR}/wireless.nmconnection"])
subprocess.run(["sync"])

if not os.path.exists(FIRSTBOOT_PATH):
print("Upping wireless")
subprocess.run(["nmcli", "radio", "wifi", "on"])
subprocess.run(["nmcli", "con", "up", "wireless"])
with open(FIRSTBOOT_PATH, "w") as f:
f.write("Used by generate-network-config-bookworm.py to determine if it's being run for the first time after a bootup.")
print("Upping wireless")
subprocess.run(["nmcli", "radio", "wifi", "on"])
subprocess.run(["nmcli", "con", "up", "wireless"])

def main(dryrun=False, extra_file_path: str = None):

config_group = get_standard_config_group(extra_file_path)
generate_network_config(config_group)

Expand Down
14 changes: 7 additions & 7 deletions scripts/piaware_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

PIAWARE_CONFIG_ENUMS["receiver"] = ["rtlsdr", "sdr", "bladerf", "beast", "relay", "radarcape", "radarcape-local", "other", "none"]
PIAWARE_CONFIG_ENUMS["uat_receiver"] = ["sdr", "stratuxv3", "other", "none"]
PIAWARE_CONFIG_ENUMS["network_type"] = ["static", "dhcp"]
PIAWARE_CONFIG_ENUMS["network_type"] = ["static", "dhcp", "network-manager"]
nikeflight marked this conversation as resolved.
Show resolved Hide resolved
PIAWARE_CONFIG_ENUMS["slow_cpu"] = ["yes", "no", "auto"]
PIAWARE_CONFIG_ENUMS["network_config_style"] = ["default", "buster", "jessie"]

Expand Down Expand Up @@ -61,16 +61,16 @@ def __init__(self, **kwargs):
self.settings["wired-netmask"] = MetadataSettings(sdonly=True, network=True)
self.settings["wired-broadcast"] = MetadataSettings(sdonly=True, network=True)
self.settings["wired-gateway"] = MetadataSettings(sdonly=True, network=True)
self.settings["wired-nameservers"] = MetadataSettings(default= ["8.8.8.8", "8.8.4.4"], sdonly=True, network=True)
self.settings["wired-nameservers"] = MetadataSettings(default= "8.8.8.8 8.8.4.4", sdonly=True, network=True)
self.settings["wireless-network"] = MetadataSettings(setting_type="bool", default=False, sdonly=True, network=True)
self.settings["wireless-ssid"] = MetadataSettings(sdonly=True, network=True, setting_type="str")
self.settings["wireless-password"] = MetadataSettings(protect=True, sdonly=True, network=True, setting_type="str")
self.settings["wireless-type"] = MetadataSettings(setting_type="network_type", default="dhcp", sdonly=True, network=True)
self.settings["wireless-address"] = MetadataSettings(sdonly=True, network=True)
self.settings["wireless-broadcast"] = MetadataSettings(sdonly=True, network=True)
self.settings["wireless-netmask"] = MetadataSettings(sdonly=True, network=True)
self.settings["wireless-gateway"] = MetadataSettings(sdonly=True, network=True)
self.settings["wireless-nameservers"] = MetadataSettings(default = ["8.8.8.8", "8.8.4.4"], sdonly=True, network=True)
self.settings["wireless-address"] = MetadataSettings(sdonly=True, network=True, setting_type="str")
self.settings["wireless-broadcast"] = MetadataSettings(sdonly=True, network=True, setting_type="str")
self.settings["wireless-netmask"] = MetadataSettings(sdonly=True, network=True, setting_type="str")
self.settings["wireless-gateway"] = MetadataSettings(sdonly=True, network=True, setting_type="str")
self.settings["wireless-nameservers"] = MetadataSettings(default = "8.8.8.8 8.8.4.4", sdonly=True, network=True, setting_type="str")
self.settings["wireless-country"] = MetadataSettings(default = "00", setting_type="country", sdonly=True, network=True)
self.settings["allow-dhcp-duic"] = MetadataSettings(default=True, setting_type="bool", sdonly=True, network=True)
self.settings["http-proxy-host"] = MetadataSettings(network=True)
Expand Down