Skip to content

Commit

Permalink
Merge pull request espressif#343 from victorrar/dev/IDFGH-10845
Browse files Browse the repository at this point in the history
Fix LoadProhibited after failed CMUX initialization
  • Loading branch information
david-cermak authored Aug 28, 2023
2 parents 27303d2 + 60c87dd commit 86f7a8b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ repos:
hooks:
- id: eradicate
- repo: https://github.com/espressif/check-copyright/
rev: v1.0.1
rev: v1.0.3
hooks:
- id: check-copyright
args: ['--ignore', 'ci/check_copyright_ignore.txt', '--config', 'ci/check_copyright_config.yaml']
Expand Down
3 changes: 2 additions & 1 deletion components/esp_modem/include/cxx_include/esp_modem_dte.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class DTE : public CommandableIf {
static const size_t GOT_LINE = SignalGroup::bit0; /*!< Bit indicating response available */

[[nodiscard]] bool setup_cmux(); /*!< Internal setup of CMUX mode */
[[nodiscard]] bool exit_cmux(); /*!< Exit of CMUX mode */
[[nodiscard]] bool exit_cmux(); /*!< Exit of CMUX mode and cleanup */
void exit_cmux_internal(); /*!< Cleanup CMUX */

Lock internal_lock{}; /*!< Locks DTE operations */
unique_buffer buffer; /*!< DTE buffer */
Expand Down
24 changes: 20 additions & 4 deletions components/esp_modem/src/esp_modem_dte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,21 @@ bool DTE::exit_cmux()
if (!cmux_term->deinit()) {
return false;
}
exit_cmux_internal();
return true;
}

void DTE::exit_cmux_internal()
{
if (!cmux_term) {
return;
}

auto ejected = cmux_term->detach();
// return the ejected terminal and buffer back to this DTE
primary_term = std::move(ejected.first);
buffer = std::move(ejected.second);
secondary_term = primary_term;
return true;
}

bool DTE::setup_cmux()
Expand All @@ -90,14 +99,21 @@ bool DTE::setup_cmux()
if (cmux_term == nullptr) {
return false;
}

if (!cmux_term->init()) {
exit_cmux_internal();
cmux_term = nullptr;
return false;
}
primary_term = std::make_unique<CMuxInstance>(cmux_term, 0);
if (primary_term == nullptr) {

primary_term = std::make_unique<CMuxInstance>(cmux_term, 0);
secondary_term = std::make_unique<CMuxInstance>(cmux_term, 1);
if (primary_term == nullptr || secondary_term == nullptr) {
exit_cmux_internal();
cmux_term = nullptr;
return false;
}
secondary_term = std::make_unique<CMuxInstance>(cmux_term, 1);

return true;
}

Expand Down

0 comments on commit 86f7a8b

Please sign in to comment.