Skip to content

Commit

Permalink
Add Halow source files for multiradio
Browse files Browse the repository at this point in the history
Jira-Id: SCDI-43

Signed-off-by: Mika Joenpera <[email protected]>
  • Loading branch information
joenpera committed Oct 16, 2023
1 parent 8d90c72 commit 3c25682
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 55 deletions.
124 changes: 81 additions & 43 deletions common/scripts/mesh-11s_nats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,22 @@ mode_execute() {
# parameters:
# $1 = mode
case "$mode" in
"halow") # TODO: implement, currently copy of "mesh"
"halow")
cat <<EOF >/var/run/wpa_supplicant-11s_"$INDEX"_"$wifidev".conf
ctrl_interface=DIR=/var/run/wpa_supplicant
# use 'ap_scan=2' on all devices connected to the network
# this is unnecessary if you only want the network to be created when no other networks..
ctrl_interface=DIR=/var/run/wpa_supplicant_"$INDEX"
ap_scan=1
country=$cc
p2p_disabled=1
mesh_max_inactivity=50
p2p_disabled=1
network={
ssid="$ssid"
bssid=$mac
mode=5
frequency=$freq
psk="$psk"
key_mgmt=SAE
ieee80211w=2
beacon_int=1000
mesh_fwding=0
# 11b rates dropped (for better performance)
mesh_basic_rates=60 90 120 180 240 360 480 540
ssid="$ssid"
bssid=$mac
mode=5
ieee80211w=2
frequency=$freq
key_mgmt=SAE
psk="$psk"
mesh_fwding=0
}
EOF

Expand All @@ -168,22 +163,34 @@ EOF

echo "$wifidev down.."
iw dev "$wifidev" del
iw phy "$phyname" interface add "$wifidev" type mp

echo "Longer range tweak.."
if [ "$priority" == "long_range" ]; then
iw phy "$phyname" set distance 8000
elif [ "$priority" == "low_latency" ]; then
iw phy "$phyname" set distance 0
else
iw phy "$phyname" set distance 1000
modprobe mac80211

# Radio spi bus number
BUSNO=$(for i in /sys/class/spi_master/*/; do
if [ -e "$i/device" ] && [ "$(basename "$(readlink "$i/device")")" == "spi-ft232h.0" ]; then
echo "${i//[^0-9]/}"
fi
done)

echo "$wifidev create 11s.."
ifconfig "$wifidev" mtu 1560
iw reg set "$cc"
insmod /lib/modules/"$KERNEL_VERSION"/kernel/drivers/staging/nrc/nrc.ko fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat spi_bus_num="$BUSNO" spi_polling_interval=3 hifspeed=20000000 spi_gpio_irq=-1 power_save=0 sw_enc=1

# Bring up halow interface
echo "$wifidev up.."
ip link set "$wifidev" up
ifconfig "$wifidev" up

# Check the return code of halow bring up
if [ $? -eq 255 ]; then
# If return code is 255, reload the nrc.ko module
rmmod nrc.ko
insmod /lib/modules/"$KERNEL_VERSION"/kernel/drivers/staging/nrc/nrc.ko fw_name=nrc7292_cspi.bin bd_name=nrc7292_bd.dat spi_bus_num="$BUSNO" spi_polling_interval=3 hifspeed=20000000 spi_gpio_irq=-1 power_save=0 sw_enc=1
fi

echo "$wifidev create 11s.."
ifconfig "$wifidev" mtu 1460

sleep 1

if [ "$routing_algo" == "batman-adv" ]; then
batctl if add "$wifidev"
Expand All @@ -196,22 +203,22 @@ EOF
echo
ifconfig "$batman_iface"

sleep 3

# for visualisation
(alfred -i "$batman_iface" -m)&
echo "started alfred"
(batadv-vis -i "$batman_iface" -s)&
echo "started batadv-vis"

if ps aux | grep -q "[b]atadv-vis -i $batman_iface -s"; then
echo "batadv-vis is already running."
else
(batadv-vis -i "$batman_iface" -s) &
echo "batadv-vis started."
fi
elif [ "$routing_algo" == "olsr" ]; then
ifconfig "$wifidev" "$ipaddr" netmask "$nmask"
# Enable debug level as necessary
(olsrd -i "$wifidev" -d 0)&
fi

# Radio parameters
iw dev "$wifidev" set txpower limit "$txpwr"00

add_network_intf_to_bridge "$bridge_name" "$bridge_interfaces"
ifconfig "$bridge_name" "$br_lan_ip" netmask "$nmask"
ifconfig "$bridge_name" up
Expand All @@ -224,7 +231,22 @@ EOF
iptables -A FORWARD --in-interface "$_mesh_vif" -j ACCEPT
iptables --table nat -A POSTROUTING --out-interface "$br_lan_ip" -j MASQUERADE

wpa_supplicant -i "$wifidev" -c /var/run/wpa_supplicant-11s_"$INDEX"_"$wifidev".conf -D nl80211 -C /var/run/wpa_supplicant/ -f /tmp/wpa_supplicant_11s_"$INDEX".log
sleep 5

# Radio parameters
echo "set radio parameters"
# /usr/local/bin/cli_app set txpwr fixed 23

echo "Longer range tweak.."
#if [ "$priority" == "long_range" ]; then
# /usr/local/bin/cli_app ...
#elif [ "$priority" == "low_latency" ]; then
# /usr/local/bin/cli_app ...
#else
# /usr/local/bin/cli_app ...
#fi

wpa_supplicant -i "$wifidev" -c /var/run/wpa_supplicant-11s_"$INDEX"_"$wifidev".conf -D nl80211 -C /var/run/wpa_supplicant_"$INDEX"/ -f /tmp/wpa_supplicant_11s_"$INDEX".log
;;
"mesh")

Expand Down Expand Up @@ -298,8 +320,13 @@ EOF
# for visualisation
(alfred -i "$batman_iface" -m)&
echo "started alfred"
(batadv-vis -i "$batman_iface" -s)&
echo "started batadv-vis"
if ps aux | grep -q "[b]atadv-vis -i $batman_iface -s"; then
echo "batadv-vis is already running."
else
(batadv-vis -i "$batman_iface" -s) &
echo "batadv-vis started."
fi

elif [ "$routing_algo" == "olsr" ]; then
ifconfig "$wifidev" "$ipaddr" netmask "$nmask"
# Enable debug level as necessary
Expand Down Expand Up @@ -456,11 +483,18 @@ EOF
### MAIN ######################################################################
main () {
# $1 = mode
# $2 = index
# $2 = index number

source /opt/mesh-helper.sh

echo "index=$2 mode=$1"
INDEX=$2

# sources mesh configuration
source_configuration "${2:2}"
source_configuration "${INDEX:2}"

# linux kernel release
KERNEL_VERSION=$(uname -r)

# Modes: mesh, ap+mesh_scc, ap+mesh_mcc, halow
# mesh 1.0 with NATS communication setup
Expand Down Expand Up @@ -491,9 +525,6 @@ main () {
# to get eth_port warning free
eth_port=$eth_port

echo "index=$2 mode=$1"
INDEX=$2

# default mesh handling and power off radio
if [ "$1" == "mesh" ]; then
mode=$1
Expand Down Expand Up @@ -561,7 +592,14 @@ main () {
# e.g. BRIDGE=br-mesh eth0 eth1 lan1
bridge_name=$(echo "$BRIDGE" | cut -d' ' -f1)
bridge_interfaces=$(echo "$BRIDGE" | cut -d' ' -f2-)
brctl addbr "$bridge_name" 2>/dev/null

if brctl show "$bridge_name" &>/dev/null; then
echo "Bridge $bridge_name already exists."
else
# Create the bridge if it doesn't exist
brctl addbr "$bridge_name" 2>/dev/null
echo "Bridge $bridge_name created."
fi

calculate_network_address "$br_lan_ip" "$nmask"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ PIDFILE="/var/run/$DAEMON.pid"
LOG_FILE=/opt/comms_discovery.log

source /opt/mesh-helper.sh
source_configuration
# for ROLE
source_configuration "0"

KEY_FILE="/etc/ssl/private/comms_auth_private_key.pem"
CERT_FILE="/etc/ssl/certs/comms_auth_cert.pem"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ async def main():
# Connect to NATS!
nc = await client.connect_nats()

cmd_dict = {"api_version": 1, "cmd": "APPLY", "radio_index": "0"}
cmd_dict = {"api_version": 1, "cmd": "APPLY", "radio_index": "2"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(
f"comms.command.{config.MODULE_IDENTITY}", cmd.encode(), timeout=10
)
parameters = json.loads(rep.data)
print(parameters)
print(json.dumps(parameters, indent=2))

await nc.close()
exit(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def main():
"ssid": "test_mesh",
"key": "1234567890",
"ap_mac": "00:11:22:33:44:55",
"country": "FI",
"country": "US",
"frequency": "5220",
"frequency_mcc": "2412",
"routing": "batman-adv",
Expand All @@ -25,7 +25,7 @@ async def main():
"subnet": "255.255.255.0",
"tx_power": "5",
"mode": "mesh",
"mesh_vif": "wlp1s0",
"mesh_vif": "wlp2s0",
"phy": "phy0",
"batman_iface": "bat0",
},
Expand All @@ -34,16 +34,34 @@ async def main():
"ssid": "test_mesh2",
"key": "1234567890",
"ap_mac": "00:11:22:33:44:55",
"country": "FI",
"frequency": "5220",
"country": "US",
"frequency": "2412",
"frequency_mcc": "2412",
"routing": "batman-adv",
"priority": "long_range",
"ip": "192.168.1.2",
"subnet": "255.255.255.0",
"tx_power": "5",
"mode": "mesh",
"mesh_vif": "wlp1s2",
"mesh_vif": "wlp3s0",
"phy": "phy2",
"batman_iface": "bat0",
},
{
"radio_index": "2",
"ssid": "test_mesh3",
"key": "1234567890",
"ap_mac": "00:11:22:33:44:55",
"country": "US",
"frequency": "5190",
"frequency_mcc": "2412",
"routing": "batman-adv",
"priority": "long_range",
"ip": "192.168.1.2",
"subnet": "255.255.255.0",
"tx_power": "5",
"mode": "halow",
"mesh_vif": "halow1",
"phy": "phy2",
"batman_iface": "bat0",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MODULE_IDENTITY="04f0219e6a01100000001e8cac33"
MODULE_IDENTITY="e45f012a19ae100000001e8cac33"
4 changes: 2 additions & 2 deletions modules/sc-mesh-secure-deployment/src/nats/src/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def validate_mode(mode: str) -> bool:
Validates a given wifi mode.
Returns True if the mode is valid, False otherwise.
"""
if mode in ("mesh", "ap+mesh_scc", "ap+mesh_mcc"):
if mode in ("mesh", "ap+mesh_scc", "ap+mesh_mcc", "halow"):
return True
return False

Expand Down Expand Up @@ -265,7 +265,7 @@ def validate_mesh_vif(mesh_vif: str) -> bool:
Returns True if the mesh vif is valid, False otherwise.
"""
# todo add more checks
if mesh_vif.startswith("wl"):
if mesh_vif.startswith("wl") or mesh_vif.startswith("halow"):
return True
return False

Expand Down
2 changes: 1 addition & 1 deletion modules/utils/docker/entrypoint_nats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source /opt/mesh-helper.sh

# sources mesh configuration and sets start_opts
source_configuration "id0"
source_configuration "0"

if [ "$MSVERSION" != "nats" ]; then
if [ -f "/usr/local/bin/entrypoint.sh" ]; then
Expand Down

0 comments on commit 3c25682

Please sign in to comment.