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..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 @@ -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 &firmware) +{ + 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 922b0e67a3..68d7a3d0a8 100644 --- a/components/esp_modem/generate/include/esp_modem_command_declare.inc +++ b/components/esp_modem/generate/include/esp_modem_command_declare.inc @@ -4,6 +4,30 @@ */ ESP_MODEM_DECLARE_DCE_COMMAND(sync, command_result) +/** + * @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, 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 + * @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, INT_IN(command), INT_IN(file_id), INT_IN(p1), INT_IN(p2), INT_IN(p3), STR_IN(data)) + /** * @brief Reads the operator name * @param[out] name operator name @@ -112,6 +136,13 @@ ESP_MODEM_DECLARE_DCE_COMMAND(set_cmux, command_result) */ ESP_MODEM_DECLARE_DCE_COMMAND(get_imsi, command_result, STR_OUT(imsi)) +/** + * @brief Reads the ICCID number + * @param[out] iccid SIM's ICCID number + * @return OK, FAIL or TIMEOUT + */ +ESP_MODEM_DECLARE_DCE_COMMAND(get_iccid, command_result, STR_OUT(iccid)) + /** * @brief Reads the IMEI number * @param[out] imei Module's IMEI number @@ -126,6 +157,13 @@ ESP_MODEM_DECLARE_DCE_COMMAND(get_imei, command_result, STR_OUT(imei)) */ ESP_MODEM_DECLARE_DCE_COMMAND(get_module_name, command_result, STR_OUT(name)) +/** + * @brief Reads the module firmware + * @param[out] firmware module firmware + * @return OK, FAIL or TIMEOUT + */ +ESP_MODEM_DECLARE_DCE_COMMAND(get_module_firmware, command_result, STR_OUT(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_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 diff --git a/components/esp_modem/src/esp_modem_c_api.cpp b/components/esp_modem/src/esp_modem_c_api.cpp index 869a17c6c1..1fb2e13703 100644 --- a/components/esp_modem/src/esp_modem_c_api.cpp +++ b/components/esp_modem/src/esp_modem_c_api.cpp @@ -254,6 +254,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 || p_iccid == 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 || cmd == nullptr || pass == nullptr || fail == nullptr) { @@ -297,6 +310,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)) { @@ -329,6 +365,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 || p_firmware == 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 || diff --git a/components/esp_modem/src/esp_modem_command_library.cpp b/components/esp_modem/src/esp_modem_command_library.cpp index 9d69bbe809..f7fd600156 100644 --- a/components/esp_modem/src/esp_modem_command_library.cpp +++ b/components/esp_modem/src/esp_modem_command_library.cpp @@ -272,6 +272,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; + 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; + } + 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__); @@ -332,12 +361,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__); @@ -459,7 +512,11 @@ 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)