Version 2.2.4:

upgraded fix_brcmf_plugin.py to look for firmware halted or crashed log
Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>

Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
Jeroen Oudshoorn
2023-09-04 07:54:57 +02:00
parent 38eb395d19
commit 3cde788c65

View File

@ -15,8 +15,8 @@ import pwnagotchi.ui.fonts as fonts
class Fix_BRCMF(plugins.Plugin): class Fix_BRCMF(plugins.Plugin):
__author__ = 'xBITS' __author__ = 'xBits'
__version__ = '0.1.2' __version__ = '0.1.1'
__license__ = 'GPL3' __license__ = 'GPL3'
__description__ = 'Reload brcmfmac module when blindbug is detected, instead of rebooting. Adapted from WATCHDOG.' __description__ = 'Reload brcmfmac module when blindbug is detected, instead of rebooting. Adapted from WATCHDOG.'
__name__ = 'Fix_BRCMF' __name__ = 'Fix_BRCMF'
@ -34,7 +34,6 @@ class Fix_BRCMF(plugins.Plugin):
self.options = dict() self.options = dict()
self.pattern = re.compile(r'brcmf_cfg80211_nexmon_set_channel.*?Set Channel failed') self.pattern = re.compile(r'brcmf_cfg80211_nexmon_set_channel.*?Set Channel failed')
self.pattern2 = re.compile(r'wifi error while hopping to channel') self.pattern2 = re.compile(r'wifi error while hopping to channel')
self.pattern3 = re.compile(r'Firmware has halted or crashed')
self.isReloadingMon = False self.isReloadingMon = False
self.connection = None self.connection = None
self.LASTTRY = 0 self.LASTTRY = 0
@ -45,6 +44,7 @@ class Fix_BRCMF(plugins.Plugin):
""" """
Gets called when the plugin gets loaded Gets called when the plugin gets loaded
""" """
self.pattern = re.compile(r'brcmf_cfg80211_nexmon_set_channel.*?Set Channel failed')
self._status = "ld" self._status = "ld"
logging.info("[FixBRCMF] plugin loaded.") logging.info("[FixBRCMF] plugin loaded.")
@ -93,8 +93,8 @@ class Fix_BRCMF(plugins.Plugin):
logging.info("[FixBRCMF] wifi.recon flip: success!") logging.info("[FixBRCMF] wifi.recon flip: success!")
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view() display = agent.view()
if display: if display: display.update(force=True, new_data={"status": "Wifi recon flipped!",
display.update(force=True, new_data={"status": "Wifi recon flipped!", "face": faces.COOL}) "face": faces.COOL})
else: else:
print("Wifi recon flipped") print("Wifi recon flipped")
else: else:
@ -113,8 +113,6 @@ class Fix_BRCMF(plugins.Plugin):
other_last_lines = ''.join(list(TextIOWrapper(subprocess.Popen(['journalctl', '-n10'], other_last_lines = ''.join(list(TextIOWrapper(subprocess.Popen(['journalctl', '-n10'],
stdout=subprocess.PIPE).stdout))[-10:]) stdout=subprocess.PIPE).stdout))[-10:])
logging.debug("[FixBRCMF]**** checking") logging.debug("[FixBRCMF]**** checking")
# Find pattern 1
if len(self.pattern.findall(last_lines)) >= 3: if len(self.pattern.findall(last_lines)) >= 3:
logging.info("[FixBRCMF]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines) logging.info("[FixBRCMF]**** Should trigger a reload of the wlan0mon device:\n%s" % last_lines)
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
@ -126,8 +124,6 @@ class Fix_BRCMF(plugins.Plugin):
self._tryTurningItOffAndOnAgain(agent) self._tryTurningItOffAndOnAgain(agent)
except Exception as err: except Exception as err:
logging.warning("[FixBRCMF] TTOAOA: %s" % repr(err)) logging.warning("[FixBRCMF] TTOAOA: %s" % repr(err))
# Find pattern 2
elif len(self.pattern2.findall(other_last_lines)) >= 5: elif len(self.pattern2.findall(other_last_lines)) >= 5:
if hasattr(agent, 'view'): if hasattr(agent, 'view'):
display = agent.view() display = agent.view()
@ -150,8 +146,9 @@ class Fix_BRCMF(plugins.Plugin):
except Exception as err: except Exception as err:
logging.error("[FixBRCMF wifi.recon flip] %s" % repr(err)) logging.error("[FixBRCMF wifi.recon flip] %s" % repr(err))
else: else:
logging.info("Logs are fine") print("logs look good")
def logPrintView(self, level, message, ui=None, displayData=None, force=True): def logPrintView(self, level, message, ui=None, displayData=None, force=True):
try: try:
@ -185,8 +182,7 @@ class Fix_BRCMF(plugins.Plugin):
self._status = "BL" self._status = "BL"
if hasattr(connection, 'view'): if hasattr(connection, 'view'):
display = connection.view() display = connection.view()
if display: if display: display.update(force=True, new_data={"status": "I'm blind! Try turning it off and on again",
display.update(force=True, new_data={"status": "I'm blind! Try turning it off and on again",
"brcmfmac_status": self._status, "brcmfmac_status": self._status,
"face": faces.BORED}) "face": faces.BORED})
else: else:
@ -250,7 +246,7 @@ class Fix_BRCMF(plugins.Plugin):
# unload the module # unload the module
cmd_output = subprocess.check_output("sudo modprobe -r brcmfmac", shell=True) cmd_output = subprocess.check_output("sudo modprobe -r brcmfmac", shell=True)
self.logPrintView("info", "[FixBRCMF] unloaded brcmfmac", display, self.logPrintView("info", "[FixBRCMF] unloaded brcmfmac", display,
{"status": "Turning it off #%d" % tries+1, "face": faces.SMART}) {"status": "Turning it off #%d" % tries, "face": faces.SMART})
self._status = "ul" self._status = "ul"
time.sleep(1 + tries) time.sleep(1 + tries)
@ -263,9 +259,11 @@ class Fix_BRCMF(plugins.Plugin):
self._status = "rl" self._status = "rl"
time.sleep(10 + 4 * tries) # give it some time for wlan device to stabilize, or whatever time.sleep(10 + 4 * tries) # give it some time for wlan device to stabilize, or whatever
# success! now make the wlan0mon # success! now make the mon0
try: try:
cmd_output = subprocess.check_output("monstart", shell=True) cmd_output = subprocess.check_output(
"monstart",
shell=True)
self.logPrintView("info", self.logPrintView("info",
"[FixBRCMF interface add wlan0mon] worked #%d: %s" % (tries, cmd_output)) "[FixBRCMF interface add wlan0mon] worked #%d: %s" % (tries, cmd_output))
self._status = "up" self._status = "up"
@ -368,7 +366,6 @@ class Fix_BRCMF(plugins.Plugin):
logging.info("[FixBRCMF] unload err %s " % repr(err)) logging.info("[FixBRCMF] unload err %s " % repr(err))
pass pass
# run from command line to brute force a reload # run from command line to brute force a reload
if __name__ == "__main__": if __name__ == "__main__":
print("Performing brcmfmac reload and restart wlan0mon in 5 seconds...") print("Performing brcmfmac reload and restart wlan0mon in 5 seconds...")