Browse Source

Set MSS on es10x commands to 60 for OMAPI channels

This seems to help a LOT with 6601 checksum errors on phones like Pixel
7 Pro. I am seeing virtually none with MSS = 60.
Peter Cai 1 year ago
parent
commit
d3a04b94a9

+ 4 - 1
app-common/src/main/java/im/angry/openeuicc/core/DefaultEuiccChannelFactory.kt

@@ -41,7 +41,10 @@ open class DefaultEuiccChannelFactory(protected val context: Context) : EuiccCha
                     context.preferenceRepository.verboseLoggingFlow
                 ),
                 context.preferenceRepository.verboseLoggingFlow
-            )
+            ).also {
+                Log.i(DefaultEuiccChannelManager.TAG, "Is OMAPI channel, setting MSS to 60")
+                it.lpa.setEs10xMss(60)
+            }
         } catch (e: IllegalArgumentException) {
             // Failed
             Log.w(

+ 7 - 0
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LocalProfileAssistant.kt

@@ -8,6 +8,13 @@ interface LocalProfileAssistant {
     // Extended EuiccInfo for use with LUIs, containing information such as firmware version
     val euiccInfo2: EuiccInfo2?
 
+    /**
+     * Set the max segment size (mss) for all es10x commands. This can help with removable
+     * eUICCs that may run at a baud rate too fast for the modem.
+     * By default, this is set to 60 by libeuicc.
+     */
+    fun setEs10xMss(mss: Byte)
+
     // All blocking functions in this class assume that they are executed on non-Main threads
     // The IO context in Kotlin's coroutine library is recommended.
     fun enableProfile(iccid: String, refresh: Boolean = true): Boolean

+ 1 - 0
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/LpacJni.kt

@@ -9,6 +9,7 @@ internal object LpacJni {
     external fun destroyContext(handle: Long)
 
     external fun euiccInit(handle: Long): Int
+    external fun euiccSetMss(handle: Long, mss: Byte)
     external fun euiccFini(handle: Long)
 
     // es10c

+ 4 - 0
libs/lpac-jni/src/main/java/net/typeblog/lpac_jni/impl/LocalProfileAssistantImpl.kt

@@ -30,6 +30,10 @@ class LocalProfileAssistantImpl(
         httpInterface.usePublicKeyIds(pkids)
     }
 
+    override fun setEs10xMss(mss: Byte) {
+        LpacJni.euiccSetMss(contextHandle, mss)
+    }
+
     override val valid: Boolean
         get() = !finalized && apduInterface.valid && try {
             // If we can read both eID and euiccInfo2 properly, we are likely looking at

+ 7 - 0
libs/lpac-jni/src/main/jni/lpac-jni/lpac-jni.c

@@ -75,6 +75,13 @@ Java_net_typeblog_lpac_1jni_LpacJni_euiccFini(JNIEnv *env, jobject thiz, jlong h
     euicc_fini(ctx);
 }
 
+JNIEXPORT void JNICALL
+Java_net_typeblog_lpac_1jni_LpacJni_euiccSetMss(JNIEnv *env, jobject thiz, jlong handle,
+                                                jbyte mss) {
+    struct euicc_ctx *ctx = (struct euicc_ctx *) handle;
+    ctx->es10x_mss = (uint8_t) mss;
+}
+
 jstring toJString(JNIEnv *env, const char *pat) {
     jbyteArray bytes = NULL;
     jstring encoding = NULL;