From 01c7b80de2bc5f0d07bbef7b3f568c9c5a2e98bf Mon Sep 17 00:00:00 2001 From: Fernando Fontes Date: Fri, 20 Mar 2026 14:37:45 +0000 Subject: [PATCH 1/5] adds iccid, u-sim and firmware commands --- .../generate/esp_modem_command_declare.inc | 38 ++++++++++++ components/esp_modem/src/esp_modem_c_api.cpp | 49 +++++++++++++++ .../src/esp_modem_command_library.cpp | 60 ++++++++++++++++++- 3 files changed, 146 insertions(+), 1 deletion(-) diff --git a/components/esp_modem/include/generate/esp_modem_command_declare.inc b/components/esp_modem/include/generate/esp_modem_command_declare.inc index 0f7b122f35..69fd8e43ef 100644 --- a/components/esp_modem/include/generate/esp_modem_command_declare.inc +++ b/components/esp_modem/include/generate/esp_modem_command_declare.inc @@ -23,6 +23,30 @@ */ \ ESP_MODEM_DECLARE_DCE_COMMAND(sync, command_result, 0) \ \ +/** + * @brief Read the Restricted (U)SIM Access + * @param[out] data response from the command + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(get_restricted_usim_access, command_result, 6, STRING_OUT(p1, data), INT_IN(p2, command), INT_IN(p3, file_id), INT_IN(p4, p1), INT_IN(p5, p2), INT_IN(p6, p3)) \ + \ +/** + * @brief Write the Restricted (U)SIM Access + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @param[in] data data to write + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(set_restricted_usim_access, command_result, 6, INT_IN(p1, command), INT_IN(p2, file_id), INT_IN(p3, p1), INT_IN(p4, p2), INT_IN(p5, p3), STRING_IN(p6, data)) \ + \ /** * @brief Reads the operator name * @param[out] name operator name @@ -131,6 +155,13 @@ ESP_MODEM_DECLARE_DCE_COMMAND(set_cmux, command_result, 0) \ */ \ ESP_MODEM_DECLARE_DCE_COMMAND(get_imsi, command_result, 1, STRING_OUT(p1, imsi)) \ \ +/** + * @brief Reads the ICCID number + * @param[out] iccid Module's IMEI number + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(get_iccid, command_result, 1, STRING_OUT(p1, iccid)) \ + \ /** * @brief Reads the IMEI number * @param[out] imei Module's IMEI number @@ -145,6 +176,13 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_imei, command_result, 1, STRING_OUT(p1, imei)) */ \ ESP_MODEM_DECLARE_DCE_COMMAND(get_module_name, command_result, 1, STRING_OUT(p1, name)) \ \ +/** + * @brief Reads the module firmware + * @param[out] name module firmware + * @return OK, FAIL or TIMEOUT + */ \ +ESP_MODEM_DECLARE_DCE_COMMAND(get_module_firmware, command_result, 1, STRING_OUT(p1, firmware)) \ + \ /** * @brief Sets the modem to data mode * @return OK, FAIL or TIMEOUT diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index e9698995e1..7a83006c20 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -235,6 +235,19 @@ extern "C" esp_err_t esp_modem_get_imsi(esp_modem_dce_t *dce_wrap, char *p_imsi) return ret; } +extern "C" esp_err_t esp_modem_get_iccid(esp_modem_dce_t *dce_wrap, char *p_iccid) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + std::string iccid; + auto ret = command_response_to_esp_err(dce_wrap->dce->get_iccid(iccid)); + if (ret == ESP_OK && !iccid.empty()) { + strlcpy(p_iccid, iccid.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX); + } + return ret; +} + extern "C" esp_err_t esp_modem_at_raw(esp_modem_dce_t *dce_wrap, const char *cmd, char *p_out, const char *pass, const char *fail, int timeout) { if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { @@ -278,6 +291,29 @@ extern "C" esp_err_t esp_modem_get_imei(esp_modem_dce_t *dce_wrap, char *p_imei) return ret; } +extern "C" esp_err_t esp_modem_get_restricted_usim_access(esp_modem_dce_t *dce_wrap, char *p_data, int command, int file_id, int p1, int p2, int p3) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr || p_data == nullptr) { + return ESP_ERR_INVALID_ARG; + } + std::string data; + auto ret = command_response_to_esp_err(dce_wrap->dce->get_restricted_usim_access(data, command, file_id, p1, p2, p3)); + if (ret == ESP_OK && !data.empty()) { + strlcpy(p_data, data.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX); + } + return ret; +} + +extern "C" esp_err_t esp_modem_set_restricted_usim_access(esp_modem_dce_t *dce_wrap, int command, int file_id, int p1, int p2, int p3, const char *data) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr || data == nullptr) { + return ESP_ERR_INVALID_ARG; + } + std::string data_str(data); + auto ret = command_response_to_esp_err(dce_wrap->dce->set_restricted_usim_access(command, file_id, p1, p2, p3, data_str)); + return ret; +} + extern "C" esp_err_t esp_modem_get_operator_name(esp_modem_dce_t *dce_wrap, char *p_name, int *p_act) { if (dce_wrap == nullptr || dce_wrap->dce == nullptr || p_name == nullptr || p_act == nullptr) { @@ -306,6 +342,19 @@ extern "C" esp_err_t esp_modem_get_module_name(esp_modem_dce_t *dce_wrap, char * return ret; } +extern "C" esp_err_t esp_modem_get_module_firmware(esp_modem_dce_t *dce_wrap, char *p_firmware) +{ + if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + return ESP_ERR_INVALID_ARG; + } + std::string firmware; + auto ret = command_response_to_esp_err(dce_wrap->dce->get_module_firmware(firmware)); + if (ret == ESP_OK && !firmware.empty()) { + strlcpy(p_firmware, firmware.c_str(), CONFIG_ESP_MODEM_C_API_STR_MAX); + } + return ret; +} + extern "C" esp_err_t esp_modem_get_battery_status(esp_modem_dce_t *dce_wrap, int *p_volt, int *p_bcs, int *p_bcl) { if (dce_wrap == nullptr || dce_wrap->dce == nullptr || p_bcs == nullptr || p_bcl == nullptr || p_volt == nullptr) { diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 6f06bb7bd2..63cd2dc92f 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -270,6 +270,35 @@ command_result get_operator_name(CommandableIf *t, std::string &operator_name, i return command_result::FAIL; } +command_result get_restricted_usim_access(CommandableIf *t, std::string &out, int command, int file_id, int p1, int p2, int p3) +{ + ESP_LOGV(TAG, "%s", __func__ ); + std::string aux; + auto ret = generic_get_string(t, "AT+CRSM=" + std::to_string(command) + + "," + std::to_string(file_id) + "," + std::to_string(p1) + "," + + std::to_string(p2) + "," + std::to_string(p3) + "\r", aux, 5000); + if (ret != command_result::OK) { + return ret; + } + constexpr std::string_view pattern = "+CRSM: "; + constexpr int crsm_pos = pattern.size(); + if (aux.find(pattern) == std::string::npos) { + return command_result::FAIL; + } + out = aux.substr(crsm_pos); + out.erase(out.find_last_not_of(" \r\n\t") + 1); + return command_result::OK; +} + +command_result set_restricted_usim_access(CommandableIf *t, int command, int file_id, int p1, int p2, int p3, const std::string &data) +{ + ESP_LOGV(TAG, "%s", __func__ ); + std::string aux; + std::string cmd = "AT+CRSM=" + std::to_string(command) + "," + std::to_string(file_id) + "," + std::to_string(p1) + "," + + std::to_string(p2) + "," + std::to_string(p3) + ",\"" + data + "\"\r"; + return generic_command_common(t, cmd, 5000); +} + command_result set_echo(CommandableIf *t, bool on) { ESP_LOGV(TAG, "%s", __func__ ); @@ -330,12 +359,36 @@ command_result get_imei(CommandableIf *t, std::string &out) return generic_get_string(t, "AT+CGSN\r", out, 5000); } +command_result get_iccid(CommandableIf *t, std::string &out) +{ + ESP_LOGV(TAG, "%s", __func__ ); + std::string aux; + auto ret = generic_get_string(t, "AT+QCCID\r", aux, 5000); + if (ret != command_result::OK) { + return ret; + } + constexpr std::string_view pattern = "+QCCID: "; + constexpr int iccid_pos = pattern.size(); + if (aux.find(pattern) == std::string::npos) { + return command_result::FAIL; + } + out = aux.substr(iccid_pos); + out.erase(out.find_last_not_of(" \r\n\t") + 1); + return command_result::OK; +} + command_result get_module_name(CommandableIf *t, std::string &out) { ESP_LOGV(TAG, "%s", __func__ ); return generic_get_string(t, "AT+CGMM\r", out, 5000); } +command_result get_module_firmware(CommandableIf *t, std::string &out) +{ + ESP_LOGV(TAG, "%s", __func__ ); + return generic_get_string(t, "AT+QGMR\r", out, 5000); +} + command_result sms_txt_mode(CommandableIf *t, bool txt = true) { ESP_LOGV(TAG, "%s", __func__ ); @@ -457,7 +510,12 @@ command_result get_signal_quality(CommandableIf *t, int &rssi, int &ber) command_result set_operator(CommandableIf *t, int mode, int format, const std::string &oper) { ESP_LOGV(TAG, "%s", __func__ ); - return generic_command_common(t, "AT+COPS=" + std::to_string(mode) + "," + std::to_string(format) + ",\"" + oper + "\"\r", 90000); + if (oper.length() == 0) { + return generic_command_common(t, "AT+COPS=" + std::to_string(mode) + "\r", 90000); + } + else { + return generic_command_common(t, "AT+COPS=" + std::to_string(mode) + "," + std::to_string(format) + ",\"" + oper + "\"\r", 90000); + } } command_result set_network_attachment_state(CommandableIf *t, int state) From 8bf7fd8001c23a421dc17db66c5328ad12fa68e3 Mon Sep 17 00:00:00 2001 From: Fernando Fontes Date: Fri, 20 Mar 2026 21:50:10 +0000 Subject: [PATCH 2/5] fix compile errors due to architecture changes --- .../cxx_include/esp_modem_command_library.hpp | 34 ++++++++++++++ .../cxx_include/esp_modem_dce_generic.hpp | 46 +++++++++++++++++++ .../cxx_include/esp_modem_dce_module.hpp | 34 ++++++++++++++ .../esp_modem/command/include/esp_modem_api.h | 34 ++++++++++++++ .../command/src/esp_modem_modules.cpp | 46 +++++++++++++++++++ .../main/command/my_module_dce.cpp | 46 +++++++++++++++++++ .../main/command/my_module_dce.hpp | 34 ++++++++++++++ .../include/esp_modem_command_declare.inc | 24 +++++----- .../src/esp_modem_command_library.cpp | 6 +-- 9 files changed, 289 insertions(+), 15 deletions(-) diff --git a/components/esp_modem/command/include/cxx_include/esp_modem_command_library.hpp b/components/esp_modem/command/include/cxx_include/esp_modem_command_library.hpp index 28d922d68b..674c930732 100644 --- a/components/esp_modem/command/include/cxx_include/esp_modem_command_library.hpp +++ b/components/esp_modem/command/include/cxx_include/esp_modem_command_library.hpp @@ -46,6 +46,28 @@ command_result sync(CommandableIf *t); * @return OK, FAIL or TIMEOUT */ command_result get_operator_name(CommandableIf *t, std::string &name, int &act); +/** + * @brief Read the Restricted (U)SIM Access + * @param[out] data response from the command + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @return OK, FAIL or TIMEOUT + */ +command_result get_restricted_usim_access(CommandableIf *t, std::string &data, int command, int file_id, int p1, int p2, int p3); +/** + * @brief Write the Restricted (U)SIM Access + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @param[in] data data to write + * @return OK, FAIL or TIMEOUT + */ +command_result set_restricted_usim_access(CommandableIf *t, int command, int file_id, int p1, int p2, int p3, const std::string &data); /** * @brief Stores current user profile * @return OK, FAIL or TIMEOUT @@ -138,12 +160,24 @@ command_result get_imsi(CommandableIf *t, std::string &imsi); * @return OK, FAIL or TIMEOUT */ command_result get_imei(CommandableIf *t, std::string &imei); +/** + * @brief Reads the ICCID number + * @param[out] iccid SIM's ICCID number + * @return OK, FAIL or TIMEOUT + */ +command_result get_iccid(CommandableIf *t, std::string &iccid); /** * @brief Reads the module name * @param[out] name module name * @return OK, FAIL or TIMEOUT */ command_result get_module_name(CommandableIf *t, std::string &name); +/** + * @brief Reads the module firmware version + * @param[out] firmware module firmware version + * @return OK, FAIL or TIMEOUT + */ +command_result get_module_firmware(CommandableIf *t, std::string &firmware); /** * @brief Sets the modem to data mode * @return OK, FAIL or TIMEOUT diff --git a/components/esp_modem/command/include/cxx_include/esp_modem_dce_generic.hpp b/components/esp_modem/command/include/cxx_include/esp_modem_dce_generic.hpp index 0b61008139..7c2dfc5d0a 100644 --- a/components/esp_modem/command/include/cxx_include/esp_modem_dce_generic.hpp +++ b/components/esp_modem/command/include/cxx_include/esp_modem_dce_generic.hpp @@ -25,6 +25,34 @@ class DCE : public DCE_T { return device->get_operator_name(name); } using DCE_T::DCE_T; + /** + * @brief Read the Restricted (U)SIM Access + * @param[out] data response from the command + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @return OK, FAIL or TIMEOUT + */ + command_result get_restricted_usim_access(std::string &data, int command, int file_id, int p1, int p2, int p3) + { + return device->get_restricted_usim_access(data, command, file_id, p1, p2, p3); + } + /** + * @brief Write the Restricted (U)SIM Access + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @param[in] data data to write + * @return OK, FAIL or TIMEOUT + */ + command_result set_restricted_usim_access(int command, int file_id, int p1, int p2, int p3, const std::string &data) + { + return device->set_restricted_usim_access(command, file_id, p1, p2, p3, data); + } /** * @brief Sends the initial AT sequence to sync up with the device * @return OK, FAIL or TIMEOUT @@ -180,6 +208,15 @@ class DCE : public DCE_T { { return device->get_imei(imei); } + /** + * @brief Reads the ICCID number + * @param[out] iccid SIM's ICCID number + * @return OK, FAIL or TIMEOUT + */ + command_result get_iccid(std::string &iccid) + { + return device->get_iccid(iccid); + } /** * @brief Reads the module name * @param[out] name module name @@ -189,6 +226,15 @@ class DCE : public DCE_T { { return device->get_module_name(name); } + /** + * @brief Reads the module firmware version + * @param[out] firmware module firmware version + * @return OK, FAIL or TIMEOUT + */ + command_result get_module_firmware(std::string &firmware) + { + return device->get_module_firmware(firmware); + } /** * @brief Sets the modem to data mode * @return OK, FAIL or TIMEOUT diff --git a/components/esp_modem/command/include/cxx_include/esp_modem_dce_module.hpp b/components/esp_modem/command/include/cxx_include/esp_modem_dce_module.hpp index c145dc85dd..6e3c7d9e01 100644 --- a/components/esp_modem/command/include/cxx_include/esp_modem_dce_module.hpp +++ b/components/esp_modem/command/include/cxx_include/esp_modem_dce_module.hpp @@ -101,6 +101,28 @@ class GenericModule: public ModuleIf { int dummy_act; return get_operator_name(name, dummy_act); } + /** + * @brief Read the Restricted (U)SIM Access + * @param[out] data response from the command + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @return OK, FAIL or TIMEOUT + */ + virtual command_result get_restricted_usim_access(std::string &data, int command, int file_id, int p1, int p2, int p3); + /** + * @brief Write the Restricted (U)SIM Access + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @param[in] data data to write + * @return OK, FAIL or TIMEOUT + */ + virtual command_result set_restricted_usim_access(int command, int file_id, int p1, int p2, int p3, const std::string &data); /** * @brief Common DCE commands generated from the API AT list */ @@ -209,12 +231,24 @@ class GenericModule: public ModuleIf { * @return OK, FAIL or TIMEOUT */ virtual command_result get_imei(std::string &imei); + /** + * @brief Reads the ICCID number + * @param[out] iccid SIM's ICCID number + * @return OK, FAIL or TIMEOUT + */ + virtual command_result get_iccid(std::string &iccid); /** * @brief Reads the module name * @param[out] name module name * @return OK, FAIL or TIMEOUT */ virtual command_result get_module_name(std::string &name); + /** + * @brief Reads the module firmware version + * @param[out] firmware module firmware version + * @return OK, FAIL or TIMEOUT + */ + virtual command_result get_module_firmware(std::string &firmware); /** * @brief Sets the modem to data mode * @return OK, FAIL or TIMEOUT diff --git a/components/esp_modem/command/include/esp_modem_api.h b/components/esp_modem/command/include/esp_modem_api.h index 5ec951fd87..0fa22e7b52 100644 --- a/components/esp_modem/command/include/esp_modem_api.h +++ b/components/esp_modem/command/include/esp_modem_api.h @@ -112,18 +112,52 @@ esp_err_t esp_modem_set_cmux(esp_modem_dce_t *dce); * @return OK, FAIL or TIMEOUT */ esp_err_t esp_modem_get_imsi(esp_modem_dce_t *dce, char *imsi); +/** + * @brief Reads the ICCID number + * @param[out] iccid SIM's ICCID number + * @return OK, FAIL or TIMEOUT + */ +esp_err_t esp_modem_get_iccid(esp_modem_dce_t *dce_wrap, char *p_iccid); /** * @brief Reads the IMEI number * @param[out] imei Module's IMEI number * @return OK, FAIL or TIMEOUT */ esp_err_t esp_modem_get_imei(esp_modem_dce_t *dce, char *imei); +/** + * @brief Read the Restricted (U)SIM Access + * @param[out] data response from the command + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @return OK, FAIL or TIMEOUT + */ +esp_err_t esp_modem_get_restricted_usim_access(esp_modem_dce_t *dce_wrap, char *p_data, int command, int file_id, int p1, int p2, int p3); +/** + * @brief Write the Restricted (U)SIM Access + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @param[in] data data to write + * @return OK, FAIL or TIMEOUT + */ +esp_err_t esp_modem_set_restricted_usim_access(esp_modem_dce_t *dce_wrap, int command, int file_id, int p1, int p2, int p3, const char *data); /** * @brief Reads the module name * @param[out] name module name * @return OK, FAIL or TIMEOUT */ esp_err_t esp_modem_get_module_name(esp_modem_dce_t *dce, char *name); +/** + * @brief Reads the module firmware version + * @param[out] firmware module firmware version + * @return OK, FAIL or TIMEOUT + */ +esp_err_t esp_modem_get_module_firmware(esp_modem_dce_t *dce_wrap, char *p_firmware); /** * @brief Sets the modem to data mode * @return OK, FAIL or TIMEOUT diff --git a/components/esp_modem/command/src/esp_modem_modules.cpp b/components/esp_modem/command/src/esp_modem_modules.cpp index 2bc39f9b2e..d31f673220 100644 --- a/components/esp_modem/command/src/esp_modem_modules.cpp +++ b/components/esp_modem/command/src/esp_modem_modules.cpp @@ -167,6 +167,52 @@ command_result GenericModule::get_imei(std::string &imei) { return esp_modem::dce_commands::get_imei(dte.get(), imei); } +/** + * @brief Reads the ICCID number + * @param[out] iccid SIM's ICCID number + * @return OK, FAIL or TIMEOUT + */ +command_result GenericModule::get_iccid(std::string &iccid) +{ + return esp_modem::dce_commands::get_iccid(dte.get(), iccid); +} +/** + * @brief Reads the module firmware version + * @param[out] firmware module firmware version + * @return OK, FAIL or TIMEOUT + */ +command_result GenericModule::get_module_firmware(std::string &firmware) +{ + return esp_modem::dce_commands::get_module_firmware(dte.get(), firmware); +} +/** + * @brief Read the Restricted (U)SIM Access + * @param[out] data response from the command + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @return OK, FAIL or TIMEOUT + */ +command_result GenericModule::get_restricted_usim_access(std::string &data, int command, int file_id, int p1, int p2, int p3) +{ + return esp_modem::dce_commands::get_restricted_usim_access(dte.get(), data, command, file_id, p1, p2, p3); +} +/** + * @brief Write the Restricted (U)SIM Access + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @param[in] data data to write + * @return OK, FAIL or TIMEOUT + */ +command_result GenericModule::set_restricted_usim_access(int command, int file_id, int p1, int p2, int p3, const std::string &data) +{ + return esp_modem::dce_commands::set_restricted_usim_access(dte.get(), command, file_id, p1, p2, p3, data); +} /** * @brief Reads the module name * @param[out] name module name diff --git a/components/esp_modem/examples/modem_console/main/command/my_module_dce.cpp b/components/esp_modem/examples/modem_console/main/command/my_module_dce.cpp index 9af8603eff..dc63c9382a 100644 --- a/components/esp_modem/examples/modem_console/main/command/my_module_dce.cpp +++ b/components/esp_modem/examples/modem_console/main/command/my_module_dce.cpp @@ -44,6 +44,34 @@ command_result Shiny::DCE::get_operator_name(std::string &name, int &act) { return esp_modem::dce_commands::get_operator_name(this, name, act); } +/** + * @brief Read the Restricted (U)SIM Access + * @param[out] data response from the command + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @return OK, FAIL or TIMEOUT + */ +command_result Shiny::DCE::get_restricted_usim_access(std::string &data, int command, int file_id, int p1, int p2, int p3) +{ + return esp_modem::dce_commands::get_restricted_usim_access(this, data, command, file_id, p1, p2, p3); +} +/** + * @brief Write the Restricted (U)SIM Access + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @param[in] data data to write + * @return OK, FAIL or TIMEOUT + */ +command_result Shiny::DCE::set_restricted_usim_access(int command, int file_id, int p1, int p2, int p3, const std::string &data) +{ + return esp_modem::dce_commands::set_restricted_usim_access(this, command, file_id, p1, p2, p3, data); +} /** * @brief Stores current user profile * @return OK, FAIL or TIMEOUT @@ -181,6 +209,15 @@ command_result Shiny::DCE::get_imei(std::string &imei) { return esp_modem::dce_commands::get_imei(this, imei); } +/** + * @brief Reads the ICCID number + * @param[out] iccid SIM's ICCID number + * @return OK, FAIL or TIMEOUT + */ +command_result Shiny::DCE::get_iccid(std::string &iccid) +{ + return esp_modem::dce_commands::get_iccid(this, iccid); +} /** * @brief Reads the module name * @param[out] name module name @@ -190,6 +227,15 @@ command_result Shiny::DCE::get_module_name(std::string &name) { return esp_modem::dce_commands::get_module_name(this, name); } +/** + * @brief Reads the module firmware version + * @param[out] firmware module firmware version + * @return OK, FAIL or TIMEOUT + */ +command_result Shiny::DCE::get_module_firmware(std::string &name) +{ + return esp_modem::dce_commands::get_module_firmware(this, firmware); +} /** * @brief Sets the modem to data mode * @return OK, FAIL or TIMEOUT diff --git a/components/esp_modem/examples/modem_console/main/command/my_module_dce.hpp b/components/esp_modem/examples/modem_console/main/command/my_module_dce.hpp index 9a1da23b93..9526479ec6 100644 --- a/components/esp_modem/examples/modem_console/main/command/my_module_dce.hpp +++ b/components/esp_modem/examples/modem_console/main/command/my_module_dce.hpp @@ -57,6 +57,28 @@ class DCE : public esp_modem::DCE_T, public CommandableIf { * @return OK, FAIL or TIMEOUT */ esp_modem::command_result get_operator_name(std::string &name, int &act); + /** + * @brief Read the Restricted (U)SIM Access + * @param[out] data response from the command + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @return OK, FAIL or TIMEOUT + */ + esp_modem::command_result get_restricted_usim_access(std::string &data, int command, int file_id, int p1, int p2, int p3); + /** + * @brief Write the Restricted (U)SIM Access + * @param[in] command command to run + * @param[in] file_id file identifier + * @param[in] p1 param 1 + * @param[in] p2 param 2 + * @param[in] p3 param 3 + * @param[in] data data to write + * @return OK, FAIL or TIMEOUT + */ + esp_modem::command_result set_restricted_usim_access(int command, int file_id, int p1, int p2, int p3, const std::string &data); /** * @brief Stores current user profile * @return OK, FAIL or TIMEOUT @@ -149,12 +171,24 @@ class DCE : public esp_modem::DCE_T, public CommandableIf { * @return OK, FAIL or TIMEOUT */ esp_modem::command_result get_imei(std::string &imei); + /** + * @brief Reads the ICCID number + * @param[out] iccid SIM's ICCID number + * @return OK, FAIL or TIMEOUT + */ + esp_modem::command_result get_iccid(std::string &iccid); /** * @brief Reads the module name * @param[out] name module name * @return OK, FAIL or TIMEOUT */ esp_modem::command_result get_module_name(std::string &name); + /** + * @brief Reads the module firmware version + * @param[out] firmware module firmware version + * @return OK, FAIL or TIMEOUT + */ + esp_modem::command_result get_module_firmware(std::string &firmware); /** * @brief Sets the modem to data mode * @return OK, FAIL or TIMEOUT diff --git a/components/esp_modem/generate/include/esp_modem_command_declare.inc b/components/esp_modem/generate/include/esp_modem_command_declare.inc index 1467c28ce6..d635bc3098 100644 --- a/components/esp_modem/generate/include/esp_modem_command_declare.inc +++ b/components/esp_modem/generate/include/esp_modem_command_declare.inc @@ -13,9 +13,9 @@ ESP_MODEM_DECLARE_DCE_COMMAND(sync, command_result) * @param[in] p2 param 2 * @param[in] p3 param 3 * @return OK, FAIL or TIMEOUT - */ \ -ESP_MODEM_DECLARE_DCE_COMMAND(get_restricted_usim_access, command_result, 6, STRING_OUT(p1, data), INT_IN(p2, command), INT_IN(p3, file_id), INT_IN(p4, p1), INT_IN(p5, p2), INT_IN(p6, p3)) \ - \ + */ +ESP_MODEM_DECLARE_DCE_COMMAND(get_restricted_usim_access, command_result, 6, STRING_OUT(p1, data), INT_IN(p2, command), INT_IN(p3, file_id), INT_IN(p4, p1), INT_IN(p5, p2), INT_IN(p6, p3)) + /** * @brief Write the Restricted (U)SIM Access * @param[in] command command to run @@ -25,9 +25,9 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_restricted_usim_access, command_result, 6, STR * @param[in] p3 param 3 * @param[in] data data to write * @return OK, FAIL or TIMEOUT - */ \ -ESP_MODEM_DECLARE_DCE_COMMAND(set_restricted_usim_access, command_result, 6, INT_IN(p1, command), INT_IN(p2, file_id), INT_IN(p3, p1), INT_IN(p4, p2), INT_IN(p5, p3), STRING_IN(p6, data)) \ - \ + */ +ESP_MODEM_DECLARE_DCE_COMMAND(set_restricted_usim_access, command_result, 6, INT_IN(p1, command), INT_IN(p2, file_id), INT_IN(p3, p1), INT_IN(p4, p2), INT_IN(p5, p3), STRING_IN(p6, data)) + /** * @brief Reads the operator name * @param[out] name operator name @@ -140,9 +140,9 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_imsi, command_result, STR_OUT(imsi)) * @brief Reads the ICCID number * @param[out] iccid Module's IMEI number * @return OK, FAIL or TIMEOUT - */ \ -ESP_MODEM_DECLARE_DCE_COMMAND(get_iccid, command_result, 1, STRING_OUT(p1, iccid)) \ - \ + */ +ESP_MODEM_DECLARE_DCE_COMMAND(get_iccid, command_result, 1, STRING_OUT(p1, iccid)) + /** * @brief Reads the IMEI number * @param[out] imei Module's IMEI number @@ -161,9 +161,9 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_module_name, command_result, STR_OUT(name)) * @brief Reads the module firmware * @param[out] name module firmware * @return OK, FAIL or TIMEOUT - */ \ -ESP_MODEM_DECLARE_DCE_COMMAND(get_module_firmware, command_result, 1, STRING_OUT(p1, firmware)) \ - \ + */ +ESP_MODEM_DECLARE_DCE_COMMAND(get_module_firmware, command_result, 1, STRING_OUT(p1, firmware)) + /** * @brief Sets the modem to data mode * @return OK, FAIL or TIMEOUT diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 192fab1695..011082d8f8 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -276,9 +276,9 @@ command_result get_restricted_usim_access(CommandableIf *t, std::string &out, in { ESP_LOGV(TAG, "%s", __func__ ); std::string aux; - auto ret = generic_get_string(t, "AT+CRSM=" + std::to_string(command) + - "," + std::to_string(file_id) + "," + std::to_string(p1) + "," + - std::to_string(p2) + "," + std::to_string(p3) + "\r", aux, 5000); + std::string cmd = "AT+CRSM=" + std::to_string(command) + "," + std::to_string(file_id) + "," + + std::to_string(p1) + "," + std::to_string(p2) + "," + std::to_string(p3) + "\r"; + auto ret = generic_get_string(t, cmd, aux, 5000); if (ret != command_result::OK) { return ret; } From 327b7acb099de2c24aa63071d3853a79babde62e Mon Sep 17 00:00:00 2001 From: Fernando Fontes Date: Fri, 20 Mar 2026 22:20:24 +0000 Subject: [PATCH 3/5] fix inc files --- .../modem_console/main/command/my_module_dce.cpp | 2 +- .../generate/include/esp_modem_command_declare.inc | 12 ++++++------ .../include/esp_modem_command_declare_helper.inc | 7 +++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/components/esp_modem/examples/modem_console/main/command/my_module_dce.cpp b/components/esp_modem/examples/modem_console/main/command/my_module_dce.cpp index dc63c9382a..af2ad9cb5c 100644 --- a/components/esp_modem/examples/modem_console/main/command/my_module_dce.cpp +++ b/components/esp_modem/examples/modem_console/main/command/my_module_dce.cpp @@ -232,7 +232,7 @@ command_result Shiny::DCE::get_module_name(std::string &name) * @param[out] firmware module firmware version * @return OK, FAIL or TIMEOUT */ -command_result Shiny::DCE::get_module_firmware(std::string &name) +command_result Shiny::DCE::get_module_firmware(std::string &firmware) { return esp_modem::dce_commands::get_module_firmware(this, firmware); } diff --git a/components/esp_modem/generate/include/esp_modem_command_declare.inc b/components/esp_modem/generate/include/esp_modem_command_declare.inc index d635bc3098..68d7a3d0a8 100644 --- a/components/esp_modem/generate/include/esp_modem_command_declare.inc +++ b/components/esp_modem/generate/include/esp_modem_command_declare.inc @@ -14,7 +14,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(sync, command_result) * @param[in] p3 param 3 * @return OK, FAIL or TIMEOUT */ -ESP_MODEM_DECLARE_DCE_COMMAND(get_restricted_usim_access, command_result, 6, STRING_OUT(p1, data), INT_IN(p2, command), INT_IN(p3, file_id), INT_IN(p4, p1), INT_IN(p5, p2), INT_IN(p6, p3)) +ESP_MODEM_DECLARE_DCE_COMMAND(get_restricted_usim_access, command_result, STR_OUT(data), INT_IN(command), INT_IN(file_id), INT_IN(p1), INT_IN(p2), INT_IN(p3)) /** * @brief Write the Restricted (U)SIM Access @@ -26,7 +26,7 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_restricted_usim_access, command_result, 6, STR * @param[in] data data to write * @return OK, FAIL or TIMEOUT */ -ESP_MODEM_DECLARE_DCE_COMMAND(set_restricted_usim_access, command_result, 6, INT_IN(p1, command), INT_IN(p2, file_id), INT_IN(p3, p1), INT_IN(p4, p2), INT_IN(p5, p3), STRING_IN(p6, data)) +ESP_MODEM_DECLARE_DCE_COMMAND(set_restricted_usim_access, command_result, INT_IN(command), INT_IN(file_id), INT_IN(p1), INT_IN(p2), INT_IN(p3), STR_IN(data)) /** * @brief Reads the operator name @@ -138,10 +138,10 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_imsi, command_result, STR_OUT(imsi)) /** * @brief Reads the ICCID number - * @param[out] iccid Module's IMEI number + * @param[out] iccid SIM's ICCID number * @return OK, FAIL or TIMEOUT */ -ESP_MODEM_DECLARE_DCE_COMMAND(get_iccid, command_result, 1, STRING_OUT(p1, iccid)) +ESP_MODEM_DECLARE_DCE_COMMAND(get_iccid, command_result, STR_OUT(iccid)) /** * @brief Reads the IMEI number @@ -159,10 +159,10 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_module_name, command_result, STR_OUT(name)) /** * @brief Reads the module firmware - * @param[out] name module firmware + * @param[out] firmware module firmware * @return OK, FAIL or TIMEOUT */ -ESP_MODEM_DECLARE_DCE_COMMAND(get_module_firmware, command_result, 1, STRING_OUT(p1, firmware)) +ESP_MODEM_DECLARE_DCE_COMMAND(get_module_firmware, command_result, STR_OUT(firmware)) /** * @brief Sets the modem to data mode diff --git a/components/esp_modem/generate/include/esp_modem_command_declare_helper.inc b/components/esp_modem/generate/include/esp_modem_command_declare_helper.inc index dbd6c0fe84..76120c54e4 100644 --- a/components/esp_modem/generate/include/esp_modem_command_declare_helper.inc +++ b/components/esp_modem/generate/include/esp_modem_command_declare_helper.inc @@ -56,3 +56,10 @@ ESP_MODEM_HELPER_GENERIC(prefix, p3), \ ESP_MODEM_HELPER_GENERIC(prefix, p4), \ ESP_MODEM_HELPER_GENERIC(prefix, p5) trail_comma +#define ESP_MODEM_HELPER6(prefix, lead_comma, trail_comma, p1, p2, p3, p4, p5, p6) lead_comma \ + ESP_MODEM_HELPER_GENERIC(prefix, p1), \ + ESP_MODEM_HELPER_GENERIC(prefix, p2), \ + ESP_MODEM_HELPER_GENERIC(prefix, p3), \ + ESP_MODEM_HELPER_GENERIC(prefix, p4), \ + ESP_MODEM_HELPER_GENERIC(prefix, p5), \ + ESP_MODEM_HELPER_GENERIC(prefix, p6) trail_comma From 170d8e618a855c55fb870b8f1fa1f4318c699711 Mon Sep 17 00:00:00 2001 From: Fernando Fontes Date: Fri, 27 Mar 2026 18:01:23 +0000 Subject: [PATCH 4/5] ran pre-commit hooks --- .../src/esp_modem_command_library.cpp | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 011082d8f8..f7fd600156 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -274,10 +274,10 @@ command_result get_operator_name(CommandableIf *t, std::string &operator_name, i command_result get_restricted_usim_access(CommandableIf *t, std::string &out, int command, int file_id, int p1, int p2, int p3) { - ESP_LOGV(TAG, "%s", __func__ ); + ESP_LOGV(TAG, "%s", __func__); std::string aux; - std::string cmd = "AT+CRSM=" + std::to_string(command) + "," + std::to_string(file_id) + "," + - std::to_string(p1) + "," + std::to_string(p2) + "," + std::to_string(p3) + "\r"; + std::string cmd = "AT+CRSM=" + std::to_string(command) + "," + std::to_string(file_id) + "," + + std::to_string(p1) + "," + std::to_string(p2) + "," + std::to_string(p3) + "\r"; auto ret = generic_get_string(t, cmd, aux, 5000); if (ret != command_result::OK) { return ret; @@ -294,10 +294,10 @@ command_result get_restricted_usim_access(CommandableIf *t, std::string &out, in command_result set_restricted_usim_access(CommandableIf *t, int command, int file_id, int p1, int p2, int p3, const std::string &data) { - ESP_LOGV(TAG, "%s", __func__ ); + ESP_LOGV(TAG, "%s", __func__); std::string aux; - std::string cmd = "AT+CRSM=" + std::to_string(command) + "," + std::to_string(file_id) + "," + std::to_string(p1) + "," + - std::to_string(p2) + "," + std::to_string(p3) + ",\"" + data + "\"\r"; + std::string cmd = "AT+CRSM=" + std::to_string(command) + "," + std::to_string(file_id) + "," + std::to_string(p1) + "," + + std::to_string(p2) + "," + std::to_string(p3) + ",\"" + data + "\"\r"; return generic_command_common(t, cmd, 5000); } @@ -363,7 +363,7 @@ command_result get_imei(CommandableIf *t, std::string &out) command_result get_iccid(CommandableIf *t, std::string &out) { - ESP_LOGV(TAG, "%s", __func__ ); + ESP_LOGV(TAG, "%s", __func__); std::string aux; auto ret = generic_get_string(t, "AT+QCCID\r", aux, 5000); if (ret != command_result::OK) { @@ -387,7 +387,7 @@ command_result get_module_name(CommandableIf *t, std::string &out) command_result get_module_firmware(CommandableIf *t, std::string &out) { - ESP_LOGV(TAG, "%s", __func__ ); + ESP_LOGV(TAG, "%s", __func__); return generic_get_string(t, "AT+QGMR\r", out, 5000); } @@ -511,11 +511,10 @@ command_result get_signal_quality(CommandableIf *t, int &rssi, int &ber) command_result set_operator(CommandableIf *t, int mode, int format, const std::string &oper) { - ESP_LOGV(TAG, "%s", __func__ ); + ESP_LOGV(TAG, "%s", __func__); if (oper.length() == 0) { return generic_command_common(t, "AT+COPS=" + std::to_string(mode) + "\r", 90000); - } - else { + } else { return generic_command_common(t, "AT+COPS=" + std::to_string(mode) + "," + std::to_string(format) + ",\"" + oper + "\"\r", 90000); } } From 5d9f86fecdf3178fec3d9adcf8b54eb487a89ae7 Mon Sep 17 00:00:00 2001 From: Fernando Fontes Date: Fri, 27 Mar 2026 20:38:18 +0000 Subject: [PATCH 5/5] fix missing null checks --- components/esp_modem/src/esp_modem_c_api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index 7a933ed9ec..1fb2e13703 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -256,7 +256,7 @@ extern "C" esp_err_t esp_modem_get_imsi(esp_modem_dce_t *dce_wrap, char *p_imsi) extern "C" esp_err_t esp_modem_get_iccid(esp_modem_dce_t *dce_wrap, char *p_iccid) { - if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + if (dce_wrap == nullptr || dce_wrap->dce == nullptr || p_iccid == nullptr) { return ESP_ERR_INVALID_ARG; } std::string iccid; @@ -367,7 +367,7 @@ extern "C" esp_err_t esp_modem_get_module_name(esp_modem_dce_t *dce_wrap, char * extern "C" esp_err_t esp_modem_get_module_firmware(esp_modem_dce_t *dce_wrap, char *p_firmware) { - if (dce_wrap == nullptr || dce_wrap->dce == nullptr) { + if (dce_wrap == nullptr || dce_wrap->dce == nullptr || p_firmware == nullptr) { return ESP_ERR_INVALID_ARG; } std::string firmware;