Skip to content

Commit

Permalink
Add more multiradio command supports
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 17, 2023
1 parent 1652696 commit 4e8a832
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ start() {
stop() {
printf 'Stopping %s: ' "$DAEMON"
kill -9 "$(cat "$PIDFILE")"
kill -9 "$(ps ax | grep -E "wpa_supplicant\-11s_$RADIO_INDEX" | awk {'print $1'})"
kill -9 "$(ps ax | grep -E "[w]pa_supplicant\-11s_$RADIO_INDEX" | awk {'print $1'})"
rm -fr /var/run/wpa_supplicant_"${RADIO_INDEX}" 2>/dev/null
ifconfig "${!_WIFI}" down 2>/dev/null
start-stop-daemon -K -o -q -p "$PIDFILE"
Expand Down
2 changes: 1 addition & 1 deletion modules/sc-mesh-secure-deployment/src/nats/initd/S90APoint
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ start() {
stop() {
printf 'Stopping %s: ' "$DAEMON"
# shellcheck disable=SC2009 #pgrep is not available
NEW_PID=$(ps ax | grep -E '[h]ostapd' | awk {'print $1'})
NEW_PID=$(ps ax | grep -E "[h]ostapd-$RADIO_INDEX" | awk {'print $1'})
kill -9 "$NEW_PID"
start-stop-daemon -K -o -q -p "$PIDFILE"
rm -fr /var/run/hostapd/* 2>/dev/null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main():
# Connect to NATS!
nc = await client.connect_nats()

cmd_dict = {"api_version": 1, "cmd": "GET_CONFIG", "param": "HOSTAPD_CONFIG"}
cmd_dict = {"api_version": 1, "cmd": "GET_CONFIG", "param": "HOSTAPD_CONFIG", "radio_index": "0"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(f"comms.command.{config.MODULE_IDENTITY}",
cmd.encode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main():
# Connect to NATS!
nc = await client.connect_nats()

cmd_dict = {"api_version": 1, "cmd": "GET_CONFIG", "param": "WPA_CONFIG"}
cmd_dict = {"api_version": 1, "cmd": "GET_CONFIG", "param": "WPA_CONFIG", "radio_index": "0"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(f"comms.command.{config.MODULE_IDENTITY}",
cmd.encode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main():
# Connect to NATS!
nc = await client.connect_nats()

cmd_dict = {"api_version": 1, "cmd": "LOGS", "param": "HOSTAPD"}
cmd_dict = {"api_version": 1, "cmd": "LOGS", "param": "HOSTAPD", "radio_index": "0"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(f"comms.command.{config.MODULE_IDENTITY}",
cmd.encode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main():
# Connect to NATS!
nc = await client.connect_nats()

cmd_dict = {"api_version": 1, "cmd": "LOGS", "param": "WPA"}
cmd_dict = {"api_version": 1, "cmd": "LOGS", "param": "WPA", "radio_index": "0"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(f"comms.command.{config.MODULE_IDENTITY}",
cmd.encode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main():
# Connect to NATS!
nc = await client.connect_nats()

cmd_dict = {"api_version": 1, "cmd": "DOWN"}
cmd_dict = {"api_version": 1, "cmd": "DOWN", "radio_index": "0"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(f"comms.command.{config.MODULE_IDENTITY}",
cmd.encode(), timeout=2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main():
# Connect to NATS!
nc = await client.connect_nats()

cmd_dict = {"api_version": 1, "cmd": "UP"}
cmd_dict = {"api_version": 1, "cmd": "UP", "radio_index": "0"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(f"comms.command.{config.MODULE_IDENTITY}",
cmd.encode(), timeout=2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async def main():
# Connect to NATS!
nc = await client.connect_nats()

cmd_dict = {"api_version": 1, "cmd": "APPLY", "radio_index": "2"}
cmd_dict = {"api_version": 1, "cmd": "APPLY", "radio_index": "1"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(
f"comms.command.{config.MODULE_IDENTITY}", cmd.encode(), timeout=10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import config


async def main():
# Connect to NATS!
nc = await client.connect_nats()
Expand Down Expand Up @@ -47,24 +46,24 @@ async def main():
"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",
},
# {
# "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",
# },
],
"bridge": "br-lan bat0 eth1 lan1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
async def main():
# Connect to NATS!
nc = await client.connect_nats()
cmd_dict = {"api_version": 1, "cmd": "ENABLE_VISUALISATION", "interval": "1000"}
cmd_dict = {"api_version": 1, "cmd": "ENABLE_VISUALISATION", "interval": "1000", "radio_index": "0"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(f"comms.command.{config.MODULE_IDENTITY}",
cmd.encode(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
async def main():
# Connect to NATS!
nc = await client.connect_nats()
cmd_dict = {"api_version": 1, "cmd": "DISABLE_VISUALISATION", "interval": "1000"}
cmd_dict = {"api_version": 1, "cmd": "DISABLE_VISUALISATION", "interval": "1000", "radio_index": "0"}
cmd = json.dumps(cmd_dict)
rep = await nc.request(f"comms.command.{config.MODULE_IDENTITY}",
cmd.encode(),
Expand Down
12 changes: 6 additions & 6 deletions modules/sc-mesh-secure-deployment/src/nats/src/comms_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class LogFiles: # pylint: disable=too-few-public-methods

# Log files
CONTROLLER_LOG = "/opt/comms_controller.log"
WPA_LOG = "/var/log/wpa_supplicant_11s.log"
HOSTAPD_LOG = "/var/log/hostapd.log"
WPA_LOG = "/var/log/wpa_supplicant_11s" # e.g. _id0.log
HOSTAPD_LOG = "/var/log/hostapd" # e.g. _id0.log
DMESG_CMD = "dmesg"


Expand Down Expand Up @@ -292,9 +292,9 @@ def __get_logs(self, param) -> (str, str, str):
try:
files = LogFiles()
if param == files.WPA:
file_b64 = self.__read_log_file(files.WPA_LOG)
file_b64 = self.__read_log_file(files.WPA_LOG + "_id" + self.radio_index + ".log")
elif param == files.HOSTAPD:
file_b64 = self.__read_log_file(files.HOSTAPD_LOG)
file_b64 = self.__read_log_file(files.HOSTAPD_LOG + "_id" + self.radio_index + ".log")
elif param == files.CONTROLLER:
file_b64 = self.__read_log_file(files.CONTROLLER_LOG)
elif param == files.DMESG:
Expand Down Expand Up @@ -322,12 +322,12 @@ def __get_configs(self, param) -> (str, str, str):
if_name = self.comms_status[int(self.radio_index)].mesh_interface_name
if if_name:
file_b64 = self.__read_log_file(
f"/var/run/wpa_supplicant-11s_{if_name}.conf")
f"/var/run/wpa_supplicant-11s_id{self.radio_index}_{if_name}.conf")
elif param == files.HOSTAPD:
if_name = self.comms_status[int(self.radio_index)].ap_interface_name
if if_name:
file_b64 = self.__read_log_file(
f"/var/run/hostapd-{if_name}.conf")
f"/var/run/hostapd-{self.radio_index}_{if_name}.conf")
else:
return "FAIL", "Parameter not supported", None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ def __get_wpa_supplicant_pid(self) -> str:
grep_command = ["grep", "-E",
f"[w]pa_supplicant-11s_id{str(self.index)}_{self.wifi_interface}.conf"]
except IndexError:
self.__logger.error("IndexError: wifi_interface=%s index=%s", self.wifi_interface, str(self.index))
return ""
awk_command = ["awk", '{print $1}']

Expand All @@ -313,7 +314,9 @@ def __get_wpa_supplicant_pid(self) -> str:
# Wait for completion and store the output
output, error = awk_process.communicate()
if error:
raise RuntimeError("Error getting wpa_supplicant PID: {}".format(error))
raise RuntimeError(f"Error getting wpa_supplicant PID: {error}")

self.__logger.debug("wpa_supplicant PID: %s", output.decode().strip())
return output.decode()

def __get_wpa_cli_status(self):
Expand Down

0 comments on commit 4e8a832

Please sign in to comment.