Compare commits

..

No commits in common. "056f5a79df4d18c13a3b62d23b98181d757122b4" and "c8ecdee09546191550db0b1f292ed26e9894b39b" have entirely different histories.

5 changed files with 74 additions and 90 deletions

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidProjectSystem">
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
</component>
</project>

View file

@ -13,29 +13,22 @@ jmethodID method_http_transmit;
jfieldID field_resp_rcode; jfieldID field_resp_rcode;
jfieldID field_resp_data; jfieldID field_resp_data;
#define APDU_INTERFACE "net/typeblog/lpac_jni/ApduInterface"
#define HTTP_INTERFACE "net/typeblog/lpac_jni/HttpInterface"
#define HTTP_RESPONSE_CLASS HTTP_INTERFACE "$HttpResponse"
#define JSTR "Ljava/lang/String;"
void interface_wrapper_init() { void interface_wrapper_init() {
LPAC_JNI_SETUP_ENV; LPAC_JNI_SETUP_ENV;
jclass apdu_class = (*env)->FindClass(env, APDU_INTERFACE); jclass apdu_class = (*env)->FindClass(env, "net/typeblog/lpac_jni/ApduInterface");
method_apdu_connect = (*env)->GetMethodID( method_apdu_connect = (*env)->GetMethodID(env, apdu_class, "connect", "()V");
env, apdu_class, "connect", "()V"); method_apdu_disconnect = (*env)->GetMethodID(env, apdu_class, "disconnect", "()V");
method_apdu_disconnect = (*env)->GetMethodID( method_apdu_logical_channel_open = (*env)->GetMethodID(env, apdu_class, "logicalChannelOpen",
env, apdu_class, "disconnect", "()V"); "([B)I");
method_apdu_logical_channel_open = (*env)->GetMethodID( method_apdu_logical_channel_close = (*env)->GetMethodID(env, apdu_class, "logicalChannelClose",
env, apdu_class, "logicalChannelOpen", "([B)I"); "(I)V");
method_apdu_logical_channel_close = (*env)->GetMethodID( method_apdu_transmit = (*env)->GetMethodID(env, apdu_class, "transmit", "(I[B)[B");
env, apdu_class, "logicalChannelClose", "(I)V");
method_apdu_transmit = (*env)->GetMethodID(
env, apdu_class, "transmit", "(I[B)[B");
jclass http_class = (*env)->FindClass(env, HTTP_INTERFACE); jclass http_class = (*env)->FindClass(env, "net/typeblog/lpac_jni/HttpInterface");
method_http_transmit = (*env)->GetMethodID( method_http_transmit = (*env)->GetMethodID(env, http_class, "transmit",
env, http_class, "transmit", "(" JSTR "[B[" JSTR ")" "L" HTTP_RESPONSE_CLASS ";"); "(Ljava/lang/String;[B[Ljava/lang/String;)Lnet/typeblog/lpac_jni/HttpInterface$HttpResponse;");
jclass resp_class = (*env)->FindClass(env, HTTP_RESPONSE_CLASS);
jclass resp_class = (*env)->FindClass(env, "net/typeblog/lpac_jni/HttpInterface$HttpResponse");
field_resp_rcode = (*env)->GetFieldID(env, resp_class, "rcode", "I"); field_resp_rcode = (*env)->GetFieldID(env, resp_class, "rcode", "I");
field_resp_data = (*env)->GetFieldID(env, resp_class, "data", "[B"); field_resp_data = (*env)->GetFieldID(env, resp_class, "data", "[B");
} }
@ -43,7 +36,7 @@ void interface_wrapper_init() {
static int apdu_interface_connect(struct euicc_ctx *ctx) { static int apdu_interface_connect(struct euicc_ctx *ctx) {
LPAC_JNI_SETUP_ENV; LPAC_JNI_SETUP_ENV;
(*env)->CallVoidMethod(env, LPAC_JNI_CTX(ctx)->apdu_interface, method_apdu_connect); (*env)->CallVoidMethod(env, LPAC_JNI_CTX(ctx)->apdu_interface, method_apdu_connect);
LPAC_JNI_EXCEPTION_RETURN LPAC_JNI_EXCEPTION_RETURN;
return 0; return 0;
} }
@ -59,7 +52,7 @@ apdu_interface_logical_channel_open(struct euicc_ctx *ctx, const uint8_t *aid, u
(*env)->SetByteArrayRegion(env, jbarr, 0, aid_len, (const jbyte *) aid); (*env)->SetByteArrayRegion(env, jbarr, 0, aid_len, (const jbyte *) aid);
jint ret = (*env)->CallIntMethod(env, LPAC_JNI_CTX(ctx)->apdu_interface, jint ret = (*env)->CallIntMethod(env, LPAC_JNI_CTX(ctx)->apdu_interface,
method_apdu_logical_channel_open, jbarr); method_apdu_logical_channel_open, jbarr);
LPAC_JNI_EXCEPTION_RETURN LPAC_JNI_EXCEPTION_RETURN;
LPAC_JNI_CTX(ctx)->logical_channel_id = ret; LPAC_JNI_CTX(ctx)->logical_channel_id = ret;
return ret; return ret;
} }
@ -76,18 +69,18 @@ static void apdu_interface_logical_channel_close(struct euicc_ctx *ctx,
static int static int
apdu_interface_transmit(struct euicc_ctx *ctx, uint8_t **rx, uint32_t *rx_len, const uint8_t *tx, apdu_interface_transmit(struct euicc_ctx *ctx, uint8_t **rx, uint32_t *rx_len, const uint8_t *tx,
uint32_t tx_len) { uint32_t tx_len) {
jint logic_channel = LPAC_JNI_CTX(ctx)->logical_channel_id; const int logic_channel = LPAC_JNI_CTX(ctx)->logical_channel_id;
LPAC_JNI_SETUP_ENV; LPAC_JNI_SETUP_ENV;
jbyteArray txArr = (*env)->NewByteArray(env, (jsize) tx_len); jbyteArray txArr = (*env)->NewByteArray(env, tx_len);
(*env)->SetByteArrayRegion(env, txArr, 0, (jsize) tx_len, (const jbyte *) tx); (*env)->SetByteArrayRegion(env, txArr, 0, tx_len, (const jbyte *) tx);
jbyteArray ret = (jbyteArray) (*env)->CallObjectMethod( jbyteArray ret = (jbyteArray) (*env)->CallObjectMethod(
env, LPAC_JNI_CTX(ctx)->apdu_interface, env, LPAC_JNI_CTX(ctx)->apdu_interface,
method_apdu_transmit, logic_channel, txArr method_apdu_transmit, logic_channel, txArr
); );
LPAC_JNI_EXCEPTION_RETURN LPAC_JNI_EXCEPTION_RETURN;
*rx_len = (*env)->GetArrayLength(env, ret); *rx_len = (*env)->GetArrayLength(env, ret);
*rx = calloc(*rx_len, sizeof(uint8_t)); *rx = calloc(*rx_len, sizeof(uint8_t));
(*env)->GetByteArrayRegion(env, ret, 0, (jsize) *rx_len, (jbyte *) rx); (*env)->GetByteArrayRegion(env, ret, 0, *rx_len, *rx);
(*env)->DeleteLocalRef(env, txArr); (*env)->DeleteLocalRef(env, txArr);
(*env)->DeleteLocalRef(env, ret); (*env)->DeleteLocalRef(env, ret);
return 0; return 0;
@ -99,8 +92,8 @@ http_interface_transmit(struct euicc_ctx *ctx, const char *url, uint32_t *rcode,
const char **headers) { const char **headers) {
LPAC_JNI_SETUP_ENV; LPAC_JNI_SETUP_ENV;
jstring jurl = toJString(env, url); jstring jurl = toJString(env, url);
jbyteArray txArr = (*env)->NewByteArray(env, (jsize) tx_len); jbyteArray txArr = (*env)->NewByteArray(env, tx_len);
(*env)->SetByteArrayRegion(env, txArr, 0, (jsize) tx_len, (jbyte *) tx); (*env)->SetByteArrayRegion(env, txArr, 0, tx_len, (const jbyte *) tx);
int num_headers = 0; int num_headers = 0;
while (headers[num_headers] != NULL) { while (headers[num_headers] != NULL) {
@ -115,12 +108,12 @@ http_interface_transmit(struct euicc_ctx *ctx, const char *url, uint32_t *rcode,
jobject ret = (*env)->CallObjectMethod(env, LPAC_JNI_CTX(ctx)->http_interface, jobject ret = (*env)->CallObjectMethod(env, LPAC_JNI_CTX(ctx)->http_interface,
method_http_transmit, jurl, txArr, headersArr); method_http_transmit, jurl, txArr, headersArr);
LPAC_JNI_EXCEPTION_RETURN LPAC_JNI_EXCEPTION_RETURN;
*rcode = (*env)->GetIntField(env, ret, field_resp_rcode); *rcode = (*env)->GetIntField(env, ret, field_resp_rcode);
jbyteArray rxArr = (jbyteArray) (*env)->GetObjectField(env, ret, field_resp_data); jbyteArray rxArr = (jbyteArray) (*env)->GetObjectField(env, ret, field_resp_data);
*rx_len = (*env)->GetArrayLength(env, rxArr); *rx_len = (*env)->GetArrayLength(env, rxArr);
*rx = calloc(*rx_len, sizeof(uint8_t)); *rx = calloc(*rx_len, sizeof(uint8_t));
(*env)->GetByteArrayRegion(env, rxArr, 0, (jsize) *rx_len, (jbyte *) *rx); (*env)->GetByteArrayRegion(env, rxArr, 0, *rx_len, *rx);
(*env)->DeleteLocalRef(env, txArr); (*env)->DeleteLocalRef(env, txArr);
(*env)->DeleteLocalRef(env, rxArr); (*env)->DeleteLocalRef(env, rxArr);
(*env)->DeleteLocalRef(env, headersArr); (*env)->DeleteLocalRef(env, headersArr);

View file

@ -5,9 +5,6 @@
#include <syslog.h> #include <syslog.h>
#include "lpac-download.h" #include "lpac-download.h"
#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnusedParameter"
jobject download_state_preparing; jobject download_state_preparing;
jobject download_state_connecting; jobject download_state_connecting;
jobject download_state_authenticating; jobject download_state_authenticating;
@ -16,34 +13,47 @@ jobject download_state_finalizing;
jmethodID on_state_update; jmethodID on_state_update;
#define DOWNLOAD_CALLBACK_CLASS "net/typeblog/lpac_jni/ProfileDownloadCallback"
#define DOWNLOAD_STATE_CLASS DOWNLOAD_CALLBACK_CLASS "$DownloadState"
static jobject
bind_download_state_field(JNIEnv *env, const char *field_name) {
jclass download_state_class = (*env)->FindClass(env, DOWNLOAD_STATE_CLASS);
jfieldID field = (*env)->GetStaticFieldID(
env, download_state_class, field_name, "L" DOWNLOAD_STATE_CLASS ";");
jobject bound = (*env)->GetStaticObjectField(
env, download_state_class, field);
return (*env)->NewGlobalRef(env, bound);
}
void lpac_download_init() { void lpac_download_init() {
LPAC_JNI_SETUP_ENV; LPAC_JNI_SETUP_ENV;
{ jclass download_state_class = (*env)->FindClass(env,
download_state_preparing = bind_download_state_field(env, "Preparing"); "net/typeblog/lpac_jni/ProfileDownloadCallback$DownloadState");
download_state_connecting = bind_download_state_field(env, "Connecting"); jfieldID download_state_preparing_field = (*env)->GetStaticFieldID(env, download_state_class,
download_state_authenticating = bind_download_state_field(env, "Authenticating"); "Preparing",
download_state_downloading = bind_download_state_field(env, "Downloading"); "Lnet/typeblog/lpac_jni/ProfileDownloadCallback$DownloadState;");
download_state_finalizing = bind_download_state_field(env, "Finalizing"); download_state_preparing = (*env)->GetStaticObjectField(env, download_state_class,
} download_state_preparing_field);
{ download_state_preparing = (*env)->NewGlobalRef(env, download_state_preparing);
jclass download_callback_class = (*env)->FindClass(env, DOWNLOAD_CALLBACK_CLASS); jfieldID download_state_connecting_field = (*env)->GetStaticFieldID(env, download_state_class,
on_state_update = (*env)->GetMethodID(env, download_callback_class, "onStateUpdate", "Connecting",
"(L" DOWNLOAD_STATE_CLASS ";)V"); "Lnet/typeblog/lpac_jni/ProfileDownloadCallback$DownloadState;");
} download_state_connecting = (*env)->GetStaticObjectField(env, download_state_class,
download_state_connecting_field);
download_state_connecting = (*env)->NewGlobalRef(env, download_state_connecting);
jfieldID download_state_authenticating_field = (*env)->GetStaticFieldID(env,
download_state_class,
"Authenticating",
"Lnet/typeblog/lpac_jni/ProfileDownloadCallback$DownloadState;");
download_state_authenticating = (*env)->GetStaticObjectField(env, download_state_class,
download_state_authenticating_field);
download_state_authenticating = (*env)->NewGlobalRef(env, download_state_authenticating);
jfieldID download_state_downloading_field = (*env)->GetStaticFieldID(env, download_state_class,
"Downloading",
"Lnet/typeblog/lpac_jni/ProfileDownloadCallback$DownloadState;");
download_state_downloading = (*env)->GetStaticObjectField(env, download_state_class,
download_state_downloading_field);
download_state_downloading = (*env)->NewGlobalRef(env, download_state_downloading);
jfieldID download_state_finalizng_field = (*env)->GetStaticFieldID(env, download_state_class,
"Finalizing",
"Lnet/typeblog/lpac_jni/ProfileDownloadCallback$DownloadState;");
download_state_finalizing = (*env)->GetStaticObjectField(env, download_state_class,
download_state_finalizng_field);
download_state_finalizing = (*env)->NewGlobalRef(env, download_state_finalizing);
jclass download_callback_class = (*env)->FindClass(env,
"net/typeblog/lpac_jni/ProfileDownloadCallback");
on_state_update = (*env)->GetMethodID(env, download_callback_class, "onStateUpdate",
"(Lnet/typeblog/lpac_jni/ProfileDownloadCallback$DownloadState;)V");
} }
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
@ -154,16 +164,18 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadErrCodeToString(JNIEnv *env, jobject
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_UNSUPPORTED_PROFILE_CLASS); ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_UNSUPPORTED_PROFILE_CLASS);
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_SCP03T_STRUCTURE_ERROR); ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_SCP03T_STRUCTURE_ERROR);
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_SCP03T_SECURITY_ERROR); ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_SCP03T_SECURITY_ERROR);
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_ALREADY_EXISTS_ON_EUICC); ERRCODE_ENUM_TO_STRING(
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INSUFFICIENT_MEMORY_FOR_PROFILE); ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_ALREADY_EXISTS_ON_EUICC);
ERRCODE_ENUM_TO_STRING(
ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INSUFFICIENT_MEMORY_FOR_PROFILE);
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INTERRUPTION); ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INTERRUPTION);
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_PE_PROCESSING_ERROR); ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_PE_PROCESSING_ERROR);
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_MISMATCH); ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_ICCID_MISMATCH);
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_TEST_PROFILE_INSTALL_FAILED_DUE_TO_INVALID_NAA_KEY); ERRCODE_ENUM_TO_STRING(
ES10B_ERROR_REASON_TEST_PROFILE_INSTALL_FAILED_DUE_TO_INVALID_NAA_KEY);
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_PPR_NOT_ALLOWED); ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_PPR_NOT_ALLOWED);
ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_UNKNOWN_ERROR); ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_UNKNOWN_ERROR);
default: default:
return toJString(env, "ES10B_ERROR_REASON_UNDEFINED"); return toJString(env, "ES10B_ERROR_REASON_UNDEFINED");
} }
} }
#pragma clang diagnostic pop

View file

@ -10,9 +10,6 @@
#include "lpac-notifications.h" #include "lpac-notifications.h"
#include "interface-wrapper.h" #include "interface-wrapper.h"
#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnusedParameter"
JavaVM *jvm = NULL; JavaVM *jvm = NULL;
jstring empty_string; jstring empty_string;
@ -28,8 +25,9 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
LPAC_JNI_SETUP_ENV; LPAC_JNI_SETUP_ENV;
string_class = (*env)->FindClass(env, "java/lang/String"); string_class = (*env)->FindClass(env, "java/lang/String");
string_class = (*env)->NewGlobalRef(env, string_class); string_class = (*env)->NewGlobalRef(env, string_class);
string_constructor = (*env)->GetMethodID( string_constructor = (*env)->GetMethodID(env, string_class, "<init>",
env, string_class, "<init>", "([BLjava/lang/String;)V"); "([BLjava/lang/String;)V");
const jchar _unused[1]; const jchar _unused[1];
empty_string = (*env)->NewString(env, _unused, 0); empty_string = (*env)->NewString(env, _unused, 0);
empty_string = (*env)->NewGlobalRef(env, empty_string); empty_string = (*env)->NewGlobalRef(env, empty_string);
@ -48,18 +46,12 @@ Java_net_typeblog_lpac_1jni_LpacJni_createContext(JNIEnv *env, jobject thiz,
uint32_t isdr_len = 0; uint32_t isdr_len = 0;
uint8_t *isdr_c = NULL; uint8_t *isdr_c = NULL;
#pragma clang diagnostic push
#pragma ide diagnostic ignored "MemoryLeak"
ctx = calloc(1, sizeof(struct euicc_ctx)); ctx = calloc(1, sizeof(struct euicc_ctx));
jni_ctx = calloc(1, sizeof(struct lpac_jni_ctx)); jni_ctx = calloc(1, sizeof(struct lpac_jni_ctx));
#pragma clang diagnostic pop
isdr_java = (*env)->GetByteArrayElements(env, isdr_aid, JNI_FALSE); isdr_java = (*env)->GetByteArrayElements(env, isdr_aid, JNI_FALSE);
isdr_len = (*env)->GetArrayLength(env, isdr_aid); isdr_len = (*env)->GetArrayLength(env, isdr_aid);
#pragma clang diagnostic push
#pragma ide diagnostic ignored "MemoryLeak"
isdr_c = calloc(isdr_len, sizeof(uint8_t)); isdr_c = calloc(isdr_len, sizeof(uint8_t));
#pragma clang diagnostic pop
memcpy(isdr_c, isdr_java, isdr_len); memcpy(isdr_c, isdr_java, isdr_len);
(*env)->ReleaseByteArrayElements(env, isdr_aid, isdr_java, JNI_ABORT); (*env)->ReleaseByteArrayElements(env, isdr_aid, isdr_java, JNI_ABORT);
@ -108,12 +100,12 @@ jstring toJString(JNIEnv *env, const char *pat) {
jbyteArray bytes = NULL; jbyteArray bytes = NULL;
jstring encoding = NULL; jstring encoding = NULL;
jstring jstr = NULL; jstring jstr = NULL;
jsize len; int len;
if (pat == NULL) if (pat == NULL)
return (*env)->NewLocalRef(env, empty_string); return (*env)->NewLocalRef(env, empty_string);
len = (jsize) strlen(pat); len = strlen(pat);
bytes = (*env)->NewByteArray(env, len); bytes = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte *) pat); (*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte *) pat);
encoding = (*env)->NewStringUTF(env, "utf-8"); encoding = (*env)->NewStringUTF(env, "utf-8");
@ -299,5 +291,3 @@ LPAC_JNI_STRUCT_GETTER_LONG(struct es10c_ex_euiccinfo2, euiccInfo2, extCardResou
LPAC_JNI_STRUCT_GETTER_LONG(struct es10c_ex_euiccinfo2, euiccInfo2, euiccCiPKIdListForSigning, EuiccCiPKIdListForSigning) LPAC_JNI_STRUCT_GETTER_LONG(struct es10c_ex_euiccinfo2, euiccInfo2, euiccCiPKIdListForSigning, EuiccCiPKIdListForSigning)
LPAC_JNI_STRUCT_GETTER_LONG(struct es10c_ex_euiccinfo2, euiccInfo2, euiccCiPKIdListForVerification, EuiccCiPKIdListForVerification) LPAC_JNI_STRUCT_GETTER_LONG(struct es10c_ex_euiccinfo2, euiccInfo2, euiccCiPKIdListForVerification, EuiccCiPKIdListForVerification)
#pragma clang diagnostic pop

View file

@ -4,9 +4,6 @@
#include <malloc.h> #include <malloc.h>
#include <syslog.h> #include <syslog.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnusedParameter"
JNIEXPORT jlong JNICALL JNIEXPORT jlong JNICALL
Java_net_typeblog_lpac_1jni_LpacJni_es10bListNotification(JNIEnv *env, jobject thiz, jlong handle) { Java_net_typeblog_lpac_1jni_LpacJni_es10bListNotification(JNIEnv *env, jobject thiz, jlong handle) {
struct euicc_ctx *ctx = (struct euicc_ctx *) handle; struct euicc_ctx *ctx = (struct euicc_ctx *) handle;
@ -80,5 +77,3 @@ LPAC_JNI_STRUCT_FREE(struct es10b_notification_metadata_list, notifications, es1
LPAC_JNI_STRUCT_GETTER_LONG(struct es10b_notification_metadata_list, notification, seqNumber, Seq) LPAC_JNI_STRUCT_GETTER_LONG(struct es10b_notification_metadata_list, notification, seqNumber, Seq)
LPAC_JNI_STRUCT_GETTER_STRING(struct es10b_notification_metadata_list, notification, notificationAddress, Address) LPAC_JNI_STRUCT_GETTER_STRING(struct es10b_notification_metadata_list, notification, notificationAddress, Address)
LPAC_JNI_STRUCT_GETTER_STRING(struct es10b_notification_metadata_list, notification, iccid, Iccid) LPAC_JNI_STRUCT_GETTER_STRING(struct es10b_notification_metadata_list, notification, iccid, Iccid)
#pragma clang diagnostic pop