瀏覽代碼

omapi: Retry on 0x6601 checksum errors

Some removable eUICCs don't play nicely with some modems. When they emit
0x6601 checksum errors, retry at least a few times before giving up.

This fixes support for eSTK.me / JMP eSIM Adapters on Pixel 7 Pro.
Peter Cai 1 年之前
父節點
當前提交
ddc421dae7
共有 1 個文件被更改,包括 12 次插入3 次删除
  1. 12 3
      app-common/src/main/java/im/angry/openeuicc/core/OmapiApduInterface.kt

+ 12 - 3
app-common/src/main/java/im/angry/openeuicc/core/OmapiApduInterface.kt

@@ -59,16 +59,25 @@ class OmapiApduInterface(
         }
 
         try {
-            return lastChannel.transmit(tx).also {
+            for (i in 0..10) {
+                val res = lastChannel.transmit(tx)
                 if (runBlocking { verboseLoggingFlow.first() }) {
-                    Log.d(TAG, "OMAPI APDU response: ${it.encodeHex()}")
+                    Log.d(TAG, "OMAPI APDU response: ${res.encodeHex()}")
                 }
+
+                if (res.size == 2 && res[0] == 0x66.toByte() && res[1] == 0x01.toByte()) {
+                    Log.d(TAG, "Received checksum error 0x6601, retrying (count = $i)")
+                    continue
+                }
+
+                return res
             }
+
+            throw RuntimeException("Retransmit attempts exhausted; this was likely caused by checksum errors")
         } catch (e: Exception) {
             Log.e(TAG, "OMAPI APDU exception")
             e.printStackTrace()
             throw e
         }
     }
-
 }