Skip to content

Process eSIM notifications after profile operations per SGP.22 spec#38241

Open
fangli wants to merge 2 commits into
commaai:masterfrom
fangli:esim-process-notifications
Open

Process eSIM notifications after profile operations per SGP.22 spec#38241
fangli wants to merge 2 commits into
commaai:masterfrom
fangli:esim-process-notifications

Conversation

@fangli

@fangli fangli commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Process pending eSIM notifications after profile-changing operations and send the correct pending notification payload to the SM-DP+.

Without this PR, the pending notification will accumulate on the eUICC, and lead to inconsistency between the eUICC and SM-DP+ server.

Why

GSMA SGP.22 defines notification handling as part of the consumer RSP flow. Profile operations such as install, enable/disable, and delete can leave pending notifications on the eUICC that should be delivered to the notification receiver using ES9+ HandleNotification, then removed from the eUICC with ES10b NotificationSent / RemoveNotificationFromList.

This matters especially after profile download failures and profile switches. The eUICC can generate pending notifications for install results and profile management operations. Leaving those queued can confuse later eSIM operations and carrier-side state.

References:

Changes

  • After download, switch, and confirmed delete, attempt to process pending eSIM notifications.
  • Wait 1 second before processing notifications to give the eUICC/modem a short settle window after the profile operation.
  • Keep notification processing best-effort: failures are printed to stderr and do not change the main operation result.
  • process_notifications() was sending only the value of the pending notification TLV to handleNotification, not the full TLV. For the pending Simlessly install notification:
    • value-only payload: HTTP 200 with GSMA failure 0.0/0.0.0 - Unknown error
    • full BF37 TLV payload: HTTP 204 accepted, then NotificationSent returned 0

Testing

  • Verified on a comma device with an equivalent eSIM implementation:
    • A value-only install notification payload was rejected by the SM-DP+ with 0.0/0.0.0 - Unknown error.
    • Sending the full BF37 Profile Installation Result TLV was accepted with HTTP 204.
    • For profile switch notifications, the eUICC returned a signed 0x30 pending notification object, which was accepted by HandleNotification and removed successfully with NotificationSent.
    • Immediate post-switch notification processing could hit APDU failed with SW=6881 or see no notifications yet, so this adds a short settle delay before the best-effort notification pass.

@fangli fangli changed the title Process eSIM notifications after profile operations Process eSIM notifications after profile operations for GSMA SPG.22 compliance Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Process replay diff report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

✅ 0 changed, 66 passed, 0 errors

@fangli fangli changed the title Process eSIM notifications after profile operations for GSMA SPG.22 compliance Process eSIM notifications after profile operations Jun 25, 2026
@fangli fangli force-pushed the esim-process-notifications branch from 96af772 to 70e4547 Compare June 25, 2026 06:16
@fangli fangli changed the title Process eSIM notifications after profile operations Process eSIM notifications after profile operations per SGP.22 spec Jun 25, 2026
Comment thread openpilot/common/esim/lpa.py
@fangli fangli marked this pull request as ready for review June 25, 2026 06:27
…tions

Added comment to clarify the purpose of the sleep.
@fangli

fangli commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

I have verified the PR on my comma 4 device manually.

Since I don't have comma 3, comma 3 is not manually verified.

try:
operation()
finally:
time.sleep(1) # Need to wait for 1s after the operation is finished so the eUICC/modem can settle down.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can't we check some status? we should never have indiscriminate sleeps like this, especially for so long

@adeebshihadeh

Copy link
Copy Markdown
Contributor

@greatgitsby any other comments?

@fangli

fangli commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@adeebshihadeh @greatgitsby

Downloading/deleting have no problem without sleep.

However, according to my test, the notification processing will hit APDU failed with SW=6881 if we don't wait for a short period of time after SWITCH operation.

It turns out that the switch operation returns before the APDU is ready.

A better solution would be re-attempt processing notification every xx milliseconds until X second timeout (which is a bit overengineering and unnecessary IMHO).

The best approach would be ensuring switch operation doesn't return until the switch complete and APDU fully ready - but is this possible in terms of a clean design/implementation? I doubt it.

The current PR made a tradeoff between complexity and reliability, considering how frequent the esim.py will be used in real scenarios. But please suggest if you prefer different flavors.

@greatgitsby

Copy link
Copy Markdown
Contributor

notifications are per spec best effort. we can rip out this behavior from the critical path and have a daemon in modem.py handle async notif procesing.

we get 1) perf improvements and 2) better reliability in this path if notif fails

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants