diff --git a/modules/sc-mesh-secure-deployment/src/nats/initd/S9011sNatsMesh b/modules/sc-mesh-secure-deployment/src/nats/initd/S9011sNatsMesh index 6f8968a16..760e28f57 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/initd/S9011sNatsMesh +++ b/modules/sc-mesh-secure-deployment/src/nats/initd/S9011sNatsMesh @@ -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" diff --git a/modules/sc-mesh-secure-deployment/src/nats/initd/S90APoint b/modules/sc-mesh-secure-deployment/src/nats/initd/S90APoint index c33da7783..2ee5e9d82 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/initd/S90APoint +++ b/modules/sc-mesh-secure-deployment/src/nats/initd/S90APoint @@ -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 diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_get_config_hostapd.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_get_config_hostapd.py index cfe38039f..b3f7539fa 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_get_config_hostapd.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_get_config_hostapd.py @@ -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(), diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_get_config_wpa.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_get_config_wpa.py index 1a22c0383..51e0b046a 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_get_config_wpa.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_get_config_wpa.py @@ -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(), diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_logs_hostapd.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_logs_hostapd.py index 9f572cab2..ea6dad762 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_logs_hostapd.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_logs_hostapd.py @@ -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(), diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_logs_wpa.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_logs_wpa.py index 70c79d57c..4314f9820 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_logs_wpa.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_command_logs_wpa.py @@ -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(), diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_radio_off.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_radio_off.py index 91c09a258..e55146f12 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_radio_off.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_radio_off.py @@ -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) diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_radio_on.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_radio_on.py index 7c875ac2d..8ee7e55a6 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_radio_on.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_radio_on.py @@ -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) diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_apply.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_apply.py index 8ba0a1f81..e02b91003 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_apply.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_apply.py @@ -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 diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py index 1750cb35a..c55502b08 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_settings_request.py @@ -3,7 +3,6 @@ import json import config - async def main(): # Connect to NATS! nc = await client.connect_nats() @@ -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" } diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_visual_start.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_visual_start.py index 3bc777a0b..2b1d07b0b 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_visual_start.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_visual_start.py @@ -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(), diff --git a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_visual_stop.py b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_visual_stop.py index 3a98f87a7..6e6d91e21 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_visual_stop.py +++ b/modules/sc-mesh-secure-deployment/src/nats/scripts/cli_visual_stop.py @@ -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(), diff --git a/modules/sc-mesh-secure-deployment/src/nats/src/comms_command.py b/modules/sc-mesh-secure-deployment/src/nats/src/comms_command.py index 54e8b262e..d089719e3 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/src/comms_command.py +++ b/modules/sc-mesh-secure-deployment/src/nats/src/comms_command.py @@ -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" @@ -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: @@ -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 diff --git a/modules/sc-mesh-secure-deployment/src/nats/src/comms_status.py b/modules/sc-mesh-secure-deployment/src/nats/src/comms_status.py index b8c4bac23..0d48f2b9b 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/src/comms_status.py +++ b/modules/sc-mesh-secure-deployment/src/nats/src/comms_status.py @@ -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}'] @@ -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):