Skip to content

adds iccid, u-sim and firmware commands#1034

Open
fjuliofontes wants to merge 6 commits intoespressif:masterfrom
fjuliofontes:features/extend-esp-modem-commands
Open

adds iccid, u-sim and firmware commands#1034
fjuliofontes wants to merge 6 commits intoespressif:masterfrom
fjuliofontes:features/extend-esp-modem-commands

Conversation

@fjuliofontes
Copy link
Copy Markdown

@fjuliofontes fjuliofontes commented Mar 20, 2026

Description

This PR extends the esp_modem command library with new AT commands for SIM card and module information retrieval, as well as a fix for the operator selection command.

New commands added:

  • get_iccid — Reads the SIM card's ICCID number via AT+QCCID (Quectel modules). Parses the +QCCID: response prefix and returns the trimmed value.
  • get_module_firmware — Reads the module firmware version via AT+QGMR (Quectel modules).
  • get_restricted_usim_access — Reads data from the (U)SIM using the standard AT+CRSM command, exposing command, file ID, P1/P2/P3 parameters and returning the raw +CRSM: response payload.
  • set_restricted_usim_access — Writes data to the (U)SIM using AT+CRSM, accepting command, file ID, P1/P2/P3 parameters and a data string.

Bug fix:

  • set_operator — Fixed the command to support automatic operator selection (mode only, no format/operator string) when an empty oper string is passed, issuing AT+COPS=<mode> instead of a malformed command.

All new commands are declared in esp_modem_command_declare.inc, implemented in esp_modem_command_library.cpp, and exposed through the C API in esp_modem_c_api.cpp.

Related

N/A

Testing

Commands were tested on Quectel EC21/EC25 modules. get_iccid and get_module_firmware use Quectel-specific AT commands (AT+QCCID, AT+QGMR). get_restricted_usim_access / set_restricted_usim_access use the standard 3GPP AT+CRSM command, which is broadly supported across modem vendors.


Checklist

Before submitting a Pull Request, please ensure the following:

  • This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

Note

Medium Risk
Expands the public C/C++ modem APIs (including SIM read/write via AT+CRSM), which could affect compatibility and has potential for vendor/parameter edge cases, but changes are additive and localized.

Overview
Adds new esp-modem commands to retrieve SIM/module info and access the SIM filesystem: get_iccid (via AT+QCCID), get_module_firmware (via AT+QGMR), and get_restricted_usim_access/set_restricted_usim_access (via AT+CRSM). These are wired through the command library, GenericModule/DCE C++ wrappers, generated command declarations (adding a 6-arg helper macro), and exposed in the C API.

Also fixes set_operator to emit AT+COPS=<mode> when no operator string is provided, enabling proper automatic operator selection.

Written by Cursor Bugbot for commit 170d8e6. This will update automatically on new commits. Configure here.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 20, 2026

CLA assistant check
All committers have signed the CLA.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Mar 20, 2026
Comment thread components/esp_modem/generate/include/esp_modem_command_declare.inc Outdated
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread components/esp_modem/src/esp_modem_c_api.cpp
Comment thread components/esp_modem/src/esp_modem_c_api.cpp
@cursor
Copy link
Copy Markdown

cursor bot commented Mar 27, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Copy link
Copy Markdown
Collaborator

@david-cermak david-cermak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution and nice work overall!
The null-pointer hardening across the C API.
AT+CRSM (restricted USIM access) commands are a welcome addition, as well as tge set_operator fix.
And good catch on the free -> delete in ap_to_pppos.

A couple of small things I'd like to suggest before merging:

  1. Rebase and cleanup git history

  2. Update git commit messages according to the contribution guidelines (or just run pre-commit hook)

  3. Quectel-specific AT commands in the generic library
    get_iccid uses AT+QCCID and get_module_firmware uses AT+QGMR -- both are Quectel-proprietary commands. Since these live in the generic command library (and get added to GenericModule), they won't work on non-Quectel modems.

Use the standard AT commands: AT+CCID for ICCID and AT+CGMR for firmware version (these are supported broadly across vendors), or
If you specifically need the Quectel variants, add them as overrides in a Quectel-specific module (similar to how SIM7070_gnss extends the base module), keeping the generic library vendor-neutral.

  1. Regenerating the API files

I see you've edited both the generate/include/esp_modem_command_declare.inc (which is the source of truth) and the command/ directory files. Our development workflow asks that after modifying the .inc file, you run the generate.sh script to regenerate the production files, rather than editing them by hand. This ensures consistency and catches any subtle differences. See our development docs -- specifically the "Developer Workflow > Adding New AT Commands" section and "Generate Script Usage".

Could you re-run:

./scripts/generate.sh
and include any updated generated files? That way CI can also validate they stay in sync.

Everything else looks good -- the helper macro extension (ESP_MODEM_HELPER6), the IDF v6 compat fix, and the nullable output parameter improvements are all welcome changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants