From 0f3e51cd0626424ce129a3a7f3c17f3a5a3775e4 Mon Sep 17 00:00:00 2001 From: Arnaud Ferraris Date: Mon, 4 Oct 2021 18:20:46 +0200 Subject: [PATCH] at: clear command queue before configuring modem In some cases, there might be an issue with `eg25-manager` trying to reset the modem while it's being configured. This leads to infinite boot loops where the modem is constantly reset soon after it booted. Fixes #24 --- src/at.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/at.c b/src/at.c index b50ceea..16722c3 100644 --- a/src/at.c +++ b/src/at.c @@ -47,6 +47,21 @@ static int configure_serial(const char *tty) return fd; } +static void at_free_command(struct AtCommand *at_cmd, struct EG25Manager *manager) +{ + if (!at_cmd) + return; + + g_free(at_cmd->cmd); + g_free(at_cmd->subcmd); + g_free(at_cmd->value); + g_free(at_cmd->expected); + g_free(at_cmd); + + if (manager && manager->at_cmds) + manager->at_cmds = g_list_remove(manager->at_cmds, at_cmd); +} + gboolean at_send_command(struct EG25Manager *manager) { char command[256]; @@ -139,16 +154,7 @@ void at_next_command(struct EG25Manager *manager) { struct AtCommand *at_cmd = manager->at_cmds ? g_list_nth_data(manager->at_cmds, 0) : NULL; - if (!at_cmd) - return; - - g_free(at_cmd->cmd); - g_free(at_cmd->subcmd); - g_free(at_cmd->value); - g_free(at_cmd->expected); - g_free(at_cmd); - manager->at_cmds = g_list_remove(manager->at_cmds, at_cmd); - + at_free_command(at_cmd, manager); at_send_command(manager); } @@ -388,6 +394,13 @@ void at_destroy(struct EG25Manager *manager) void at_sequence_configure(struct EG25Manager *manager) { + /* + * When configuring a new modem we should avoid processing an old + * command queue, so let's first clear the whole list + */ + if (manager->at_cmds) + g_list_foreach(manager->at_cmds, at_free_command, manager); + for (guint i = 0; i < configure_commands->len; i++) { struct AtCommand *cmd = &g_array_index(configure_commands, struct AtCommand, i); at_append_command(manager, cmd->cmd, cmd->subcmd, cmd->value, cmd->expected, at_process_result);