diff --git a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx9/bluetooth-init b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx9/bluetooth-init index 687b8cff2..e2ea10d99 100644 --- a/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx9/bluetooth-init +++ b/meta-digi-dey/recipes-connectivity/bluez/bluez5-init/ccimx9/bluetooth-init @@ -1,7 +1,7 @@ #!/bin/sh #=============================================================================== # -# Copyright (C) 2023 by Digi International Inc. +# Copyright (C) 2023,2024, Digi International Inc. # All rights reserved. # # This program is free software; you can redistribute it and/or modify it @@ -65,16 +65,31 @@ bluetooth_start() { log "[ERROR] Cannot initialize Bluetooth correctly" && return 1 } +is_system_running() { + state=$(systemctl is-system-running 2>/dev/null) + case "$state" in + running|degraded) + return 0 ;; # System is operational + *) + return 1 ;; # Assume not running + esac +} + bluetooth_stop() { # # The btnxpuart driver hits a null pointer dereference on module # unloading when the interface is down. So as a workaround, make # sure the interface is UP before unloading the module. # - hciconfig "${HCI_IFACE}" up && rmmod "${MODULE_NAME}" - power 0 + if is_system_running; then + hciconfig "${HCI_IFACE}" up && rmmod "${MODULE_NAME}" + power 0 + else + log "System rebooting... not taking any action" + fi } + case "$1" in start) bluetooth_start