|
@@ -1,6 +1,8 @@
|
|
|
package im.angry.openeuicc.core
|
|
package im.angry.openeuicc.core
|
|
|
|
|
|
|
|
|
|
+import android.telephony.IccOpenLogicalChannelResponse
|
|
|
import android.telephony.TelephonyManager
|
|
import android.telephony.TelephonyManager
|
|
|
|
|
+import im.angry.openeuicc.util.*
|
|
|
import net.typeblog.lpac_jni.LocalProfileAssistant
|
|
import net.typeblog.lpac_jni.LocalProfileAssistant
|
|
|
import net.typeblog.lpac_jni.ApduInterface
|
|
import net.typeblog.lpac_jni.ApduInterface
|
|
|
import net.typeblog.lpac_jni.impl.HttpInterfaceImpl
|
|
import net.typeblog.lpac_jni.impl.HttpInterfaceImpl
|
|
@@ -10,24 +12,42 @@ class TelephonyManagerApduInterface(
|
|
|
private val info: EuiccChannelInfo,
|
|
private val info: EuiccChannelInfo,
|
|
|
private val tm: TelephonyManager
|
|
private val tm: TelephonyManager
|
|
|
): ApduInterface {
|
|
): ApduInterface {
|
|
|
|
|
+ private var lastChannel: Int = -1
|
|
|
|
|
+
|
|
|
override fun connect() {
|
|
override fun connect() {
|
|
|
- TODO("Not yet implemented")
|
|
|
|
|
|
|
+ // Do nothing
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun disconnect() {
|
|
override fun disconnect() {
|
|
|
- TODO("Not yet implemented")
|
|
|
|
|
|
|
+ // Do nothing
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun logicalChannelOpen(aid: ByteArray): Int {
|
|
override fun logicalChannelOpen(aid: ByteArray): Int {
|
|
|
- TODO("Not yet implemented")
|
|
|
|
|
|
|
+ check(lastChannel == -1) { "Already initialized" }
|
|
|
|
|
+ val hex = aid.encodeHex()
|
|
|
|
|
+ val channel = tm.iccOpenLogicalChannelBySlot(info.slotId, hex, 0)
|
|
|
|
|
+ if (channel.status != IccOpenLogicalChannelResponse.STATUS_NO_ERROR || channel.channel == IccOpenLogicalChannelResponse.INVALID_CHANNEL) {
|
|
|
|
|
+ throw IllegalArgumentException("Cannot open logical channel " + hex + " via TelephonManager on slot " + info.slotId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return channel.channel
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun logicalChannelClose(handle: Int) {
|
|
override fun logicalChannelClose(handle: Int) {
|
|
|
- TODO("Not yet implemented")
|
|
|
|
|
|
|
+ tm.iccCloseLogicalChannelBySlot(info.slotId, handle)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
override fun transmit(tx: ByteArray): ByteArray {
|
|
override fun transmit(tx: ByteArray): ByteArray {
|
|
|
- TODO("Not yet implemented")
|
|
|
|
|
|
|
+ check(lastChannel != -1) { "Uninitialized" }
|
|
|
|
|
+
|
|
|
|
|
+ val cla = tx[0].toInt()
|
|
|
|
|
+ val instruction = tx[1].toInt()
|
|
|
|
|
+ val p1 = tx[2].toInt()
|
|
|
|
|
+ val p2 = tx[3].toInt()
|
|
|
|
|
+ val p3 = tx[4].toInt()
|
|
|
|
|
+ val p4 = tx.drop(5).toByteArray().encodeHex()
|
|
|
|
|
+
|
|
|
|
|
+ return tm.iccTransmitApduLogicalChannelBySlot(info.slotId, lastChannel,
|
|
|
|
|
+ cla, instruction, p1, p2, p3, p4)?.decodeHex() ?: byteArrayOf()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -36,36 +56,10 @@ class TelephonyManagerChannel(
|
|
|
info: EuiccChannelInfo,
|
|
info: EuiccChannelInfo,
|
|
|
private val tm: TelephonyManager
|
|
private val tm: TelephonyManager
|
|
|
) : EuiccChannel(info) {
|
|
) : EuiccChannel(info) {
|
|
|
- companion object {
|
|
|
|
|
- private const val TAG = "TelephonyManagerApduChannel"
|
|
|
|
|
- private const val EUICC_APP_ID = "A0000005591010FFFFFFFF8900000100"
|
|
|
|
|
-
|
|
|
|
|
- // TODO: On Tiramisu, we need to specify the portId also if we want MEP support
|
|
|
|
|
- /*fun tryConnect(tm: TelephonyManager, info: EuiccChannelInfo): TelephonyManagerChannel? {
|
|
|
|
|
- try {
|
|
|
|
|
- val channel = tm.iccOpenLogicalChannelBySlot(info.slotId, EUICC_APP_ID, 0)
|
|
|
|
|
- if (channel.status != IccOpenLogicalChannelResponse.STATUS_NO_ERROR || channel.channel == IccOpenLogicalChannelResponse.INVALID_CHANNEL) {
|
|
|
|
|
- Log.e(TAG, "Unable to open eUICC channel for slot ${info.slotId} via TelephonyManager: ${channel.status}")
|
|
|
|
|
- return null
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- Log.d(TAG, "channel: ${channel.channel}")
|
|
|
|
|
-
|
|
|
|
|
- return TelephonyManagerChannel(info, tm, channel.channel)
|
|
|
|
|
- } catch (e: Exception) {
|
|
|
|
|
- Log.e(TAG, "Unable to open eUICC channel for slot ${info.slotId} via TelephonyManager")
|
|
|
|
|
- Log.e(TAG, Log.getStackTraceString(e))
|
|
|
|
|
- return null
|
|
|
|
|
- }
|
|
|
|
|
- }*/
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
override val lpa: LocalProfileAssistant = LocalProfileAssistantImpl(
|
|
override val lpa: LocalProfileAssistant = LocalProfileAssistantImpl(
|
|
|
TelephonyManagerApduInterface(info, tm),
|
|
TelephonyManagerApduInterface(info, tm),
|
|
|
HttpInterfaceImpl()
|
|
HttpInterfaceImpl()
|
|
|
)
|
|
)
|
|
|
- override val valid: Boolean
|
|
|
|
|
- get() = true // TODO: Fix this
|
|
|
|
|
|
|
|
|
|
override fun close() = lpa.close()
|
|
override fun close() = lpa.close()
|
|
|
}
|
|
}
|