diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml
new file mode 100644
index 0000000..4a53bee
--- /dev/null
+++ b/.idea/AndroidProjectSystem.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/libs/lpac-jni/src/main/jni/lpac-jni/interface-wrapper.c b/libs/lpac-jni/src/main/jni/lpac-jni/interface-wrapper.c
index a61fc96..47f481b 100644
--- a/libs/lpac-jni/src/main/jni/lpac-jni/interface-wrapper.c
+++ b/libs/lpac-jni/src/main/jni/lpac-jni/interface-wrapper.c
@@ -13,22 +13,29 @@ jmethodID method_http_transmit;
jfieldID field_resp_rcode;
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() {
LPAC_JNI_SETUP_ENV;
- jclass apdu_class = (*env)->FindClass(env, "net/typeblog/lpac_jni/ApduInterface");
- method_apdu_connect = (*env)->GetMethodID(env, apdu_class, "connect", "()V");
- method_apdu_disconnect = (*env)->GetMethodID(env, apdu_class, "disconnect", "()V");
- method_apdu_logical_channel_open = (*env)->GetMethodID(env, apdu_class, "logicalChannelOpen",
- "([B)I");
- method_apdu_logical_channel_close = (*env)->GetMethodID(env, apdu_class, "logicalChannelClose",
- "(I)V");
- method_apdu_transmit = (*env)->GetMethodID(env, apdu_class, "transmit", "(I[B)[B");
+ jclass apdu_class = (*env)->FindClass(env, APDU_INTERFACE);
+ method_apdu_connect = (*env)->GetMethodID(
+ env, apdu_class, "connect", "()V");
+ method_apdu_disconnect = (*env)->GetMethodID(
+ env, apdu_class, "disconnect", "()V");
+ method_apdu_logical_channel_open = (*env)->GetMethodID(
+ env, apdu_class, "logicalChannelOpen", "([B)I");
+ method_apdu_logical_channel_close = (*env)->GetMethodID(
+ env, apdu_class, "logicalChannelClose", "(I)V");
+ method_apdu_transmit = (*env)->GetMethodID(
+ env, apdu_class, "transmit", "(I[B)[B");
- jclass http_class = (*env)->FindClass(env, "net/typeblog/lpac_jni/HttpInterface");
- method_http_transmit = (*env)->GetMethodID(env, http_class, "transmit",
- "(Ljava/lang/String;[B[Ljava/lang/String;)Lnet/typeblog/lpac_jni/HttpInterface$HttpResponse;");
-
- jclass resp_class = (*env)->FindClass(env, "net/typeblog/lpac_jni/HttpInterface$HttpResponse");
+ jclass http_class = (*env)->FindClass(env, HTTP_INTERFACE);
+ method_http_transmit = (*env)->GetMethodID(
+ env, http_class, "transmit", "(" JSTR "[B[" JSTR ")" "L" HTTP_RESPONSE_CLASS ";");
+ jclass resp_class = (*env)->FindClass(env, HTTP_RESPONSE_CLASS);
field_resp_rcode = (*env)->GetFieldID(env, resp_class, "rcode", "I");
field_resp_data = (*env)->GetFieldID(env, resp_class, "data", "[B");
}
@@ -36,7 +43,7 @@ void interface_wrapper_init() {
static int apdu_interface_connect(struct euicc_ctx *ctx) {
LPAC_JNI_SETUP_ENV;
(*env)->CallVoidMethod(env, LPAC_JNI_CTX(ctx)->apdu_interface, method_apdu_connect);
- LPAC_JNI_EXCEPTION_RETURN;
+ LPAC_JNI_EXCEPTION_RETURN
return 0;
}
@@ -52,7 +59,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);
jint ret = (*env)->CallIntMethod(env, LPAC_JNI_CTX(ctx)->apdu_interface,
method_apdu_logical_channel_open, jbarr);
- LPAC_JNI_EXCEPTION_RETURN;
+ LPAC_JNI_EXCEPTION_RETURN
LPAC_JNI_CTX(ctx)->logical_channel_id = ret;
return ret;
}
@@ -69,18 +76,18 @@ static void apdu_interface_logical_channel_close(struct euicc_ctx *ctx,
static int
apdu_interface_transmit(struct euicc_ctx *ctx, uint8_t **rx, uint32_t *rx_len, const uint8_t *tx,
uint32_t tx_len) {
- const int logic_channel = LPAC_JNI_CTX(ctx)->logical_channel_id;
+ jint logic_channel = LPAC_JNI_CTX(ctx)->logical_channel_id;
LPAC_JNI_SETUP_ENV;
- jbyteArray txArr = (*env)->NewByteArray(env, tx_len);
- (*env)->SetByteArrayRegion(env, txArr, 0, tx_len, (const jbyte *) tx);
+ jbyteArray txArr = (*env)->NewByteArray(env, (jsize) tx_len);
+ (*env)->SetByteArrayRegion(env, txArr, 0, (jsize) tx_len, (const jbyte *) tx);
jbyteArray ret = (jbyteArray) (*env)->CallObjectMethod(
env, LPAC_JNI_CTX(ctx)->apdu_interface,
method_apdu_transmit, logic_channel, txArr
);
- LPAC_JNI_EXCEPTION_RETURN;
+ LPAC_JNI_EXCEPTION_RETURN
*rx_len = (*env)->GetArrayLength(env, ret);
*rx = calloc(*rx_len, sizeof(uint8_t));
- (*env)->GetByteArrayRegion(env, ret, 0, *rx_len, *rx);
+ (*env)->GetByteArrayRegion(env, ret, 0, (jsize) *rx_len, (jbyte *) rx);
(*env)->DeleteLocalRef(env, txArr);
(*env)->DeleteLocalRef(env, ret);
return 0;
@@ -92,8 +99,8 @@ http_interface_transmit(struct euicc_ctx *ctx, const char *url, uint32_t *rcode,
const char **headers) {
LPAC_JNI_SETUP_ENV;
jstring jurl = toJString(env, url);
- jbyteArray txArr = (*env)->NewByteArray(env, tx_len);
- (*env)->SetByteArrayRegion(env, txArr, 0, tx_len, (const jbyte *) tx);
+ jbyteArray txArr = (*env)->NewByteArray(env, (jsize) tx_len);
+ (*env)->SetByteArrayRegion(env, txArr, 0, (jsize) tx_len, (jbyte *) tx);
int num_headers = 0;
while (headers[num_headers] != NULL) {
@@ -108,12 +115,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,
method_http_transmit, jurl, txArr, headersArr);
- LPAC_JNI_EXCEPTION_RETURN;
+ LPAC_JNI_EXCEPTION_RETURN
*rcode = (*env)->GetIntField(env, ret, field_resp_rcode);
jbyteArray rxArr = (jbyteArray) (*env)->GetObjectField(env, ret, field_resp_data);
*rx_len = (*env)->GetArrayLength(env, rxArr);
*rx = calloc(*rx_len, sizeof(uint8_t));
- (*env)->GetByteArrayRegion(env, rxArr, 0, *rx_len, *rx);
+ (*env)->GetByteArrayRegion(env, rxArr, 0, (jsize) *rx_len, (jbyte *) *rx);
(*env)->DeleteLocalRef(env, txArr);
(*env)->DeleteLocalRef(env, rxArr);
(*env)->DeleteLocalRef(env, headersArr);
diff --git a/libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c b/libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c
index 028e30d..450a727 100644
--- a/libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c
+++ b/libs/lpac-jni/src/main/jni/lpac-jni/lpac-download.c
@@ -5,6 +5,9 @@
#include
#include "lpac-download.h"
+#pragma clang diagnostic push
+#pragma ide diagnostic ignored "UnusedParameter"
+
jobject download_state_preparing;
jobject download_state_connecting;
jobject download_state_authenticating;
@@ -13,47 +16,34 @@ jobject download_state_finalizing;
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() {
LPAC_JNI_SETUP_ENV;
- jclass download_state_class = (*env)->FindClass(env,
- "net/typeblog/lpac_jni/ProfileDownloadCallback$DownloadState");
- jfieldID download_state_preparing_field = (*env)->GetStaticFieldID(env, download_state_class,
- "Preparing",
- "Lnet/typeblog/lpac_jni/ProfileDownloadCallback$DownloadState;");
- download_state_preparing = (*env)->GetStaticObjectField(env, download_state_class,
- download_state_preparing_field);
- download_state_preparing = (*env)->NewGlobalRef(env, download_state_preparing);
- jfieldID download_state_connecting_field = (*env)->GetStaticFieldID(env, download_state_class,
- "Connecting",
- "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");
+ {
+ download_state_preparing = bind_download_state_field(env, "Preparing");
+ download_state_connecting = bind_download_state_field(env, "Connecting");
+ download_state_authenticating = bind_download_state_field(env, "Authenticating");
+ download_state_downloading = bind_download_state_field(env, "Downloading");
+ download_state_finalizing = bind_download_state_field(env, "Finalizing");
+ }
+ {
+ jclass download_callback_class = (*env)->FindClass(env, DOWNLOAD_CALLBACK_CLASS);
+ on_state_update = (*env)->GetMethodID(env, download_callback_class, "onStateUpdate",
+ "(L" DOWNLOAD_STATE_CLASS ";)V");
+ }
}
JNIEXPORT jint JNICALL
@@ -164,18 +154,16 @@ 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_SCP03T_STRUCTURE_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(
- ES10B_ERROR_REASON_INSTALL_FAILED_DUE_TO_INSUFFICIENT_MEMORY_FOR_PROFILE);
+ ERRCODE_ENUM_TO_STRING(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_PE_PROCESSING_ERROR);
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_INSTALL_FAILED_DUE_TO_UNKNOWN_ERROR);
default:
return toJString(env, "ES10B_ERROR_REASON_UNDEFINED");
}
-}
\ No newline at end of file
+}
+#pragma clang diagnostic pop
\ No newline at end of file
diff --git a/libs/lpac-jni/src/main/jni/lpac-jni/lpac-jni.c b/libs/lpac-jni/src/main/jni/lpac-jni/lpac-jni.c
index ca319db..2fd5323 100644
--- a/libs/lpac-jni/src/main/jni/lpac-jni/lpac-jni.c
+++ b/libs/lpac-jni/src/main/jni/lpac-jni/lpac-jni.c
@@ -10,6 +10,9 @@
#include "lpac-notifications.h"
#include "interface-wrapper.h"
+#pragma clang diagnostic push
+#pragma ide diagnostic ignored "UnusedParameter"
+
JavaVM *jvm = NULL;
jstring empty_string;
@@ -25,9 +28,8 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
LPAC_JNI_SETUP_ENV;
string_class = (*env)->FindClass(env, "java/lang/String");
string_class = (*env)->NewGlobalRef(env, string_class);
- string_constructor = (*env)->GetMethodID(env, string_class, "",
- "([BLjava/lang/String;)V");
-
+ string_constructor = (*env)->GetMethodID(
+ env, string_class, "", "([BLjava/lang/String;)V");
const jchar _unused[1];
empty_string = (*env)->NewString(env, _unused, 0);
empty_string = (*env)->NewGlobalRef(env, empty_string);
@@ -46,12 +48,18 @@ Java_net_typeblog_lpac_1jni_LpacJni_createContext(JNIEnv *env, jobject thiz,
uint32_t isdr_len = 0;
uint8_t *isdr_c = NULL;
+#pragma clang diagnostic push
+#pragma ide diagnostic ignored "MemoryLeak"
ctx = calloc(1, sizeof(struct euicc_ctx));
jni_ctx = calloc(1, sizeof(struct lpac_jni_ctx));
+#pragma clang diagnostic pop
isdr_java = (*env)->GetByteArrayElements(env, isdr_aid, JNI_FALSE);
isdr_len = (*env)->GetArrayLength(env, isdr_aid);
+#pragma clang diagnostic push
+#pragma ide diagnostic ignored "MemoryLeak"
isdr_c = calloc(isdr_len, sizeof(uint8_t));
+#pragma clang diagnostic pop
memcpy(isdr_c, isdr_java, isdr_len);
(*env)->ReleaseByteArrayElements(env, isdr_aid, isdr_java, JNI_ABORT);
@@ -100,12 +108,12 @@ jstring toJString(JNIEnv *env, const char *pat) {
jbyteArray bytes = NULL;
jstring encoding = NULL;
jstring jstr = NULL;
- int len;
+ jsize len;
if (pat == NULL)
return (*env)->NewLocalRef(env, empty_string);
- len = strlen(pat);
+ len = (jsize) strlen(pat);
bytes = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, bytes, 0, len, (jbyte *) pat);
encoding = (*env)->NewStringUTF(env, "utf-8");
@@ -291,3 +299,5 @@ 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, euiccCiPKIdListForVerification, EuiccCiPKIdListForVerification)
+
+#pragma clang diagnostic pop
\ No newline at end of file
diff --git a/libs/lpac-jni/src/main/jni/lpac-jni/lpac-notifications.c b/libs/lpac-jni/src/main/jni/lpac-jni/lpac-notifications.c
index cf402cf..f031398 100644
--- a/libs/lpac-jni/src/main/jni/lpac-jni/lpac-notifications.c
+++ b/libs/lpac-jni/src/main/jni/lpac-jni/lpac-notifications.c
@@ -4,6 +4,9 @@
#include
#include
+#pragma clang diagnostic push
+#pragma ide diagnostic ignored "UnusedParameter"
+
JNIEXPORT jlong JNICALL
Java_net_typeblog_lpac_1jni_LpacJni_es10bListNotification(JNIEnv *env, jobject thiz, jlong handle) {
struct euicc_ctx *ctx = (struct euicc_ctx *) handle;
@@ -77,3 +80,5 @@ 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_STRING(struct es10b_notification_metadata_list, notification, notificationAddress, Address)
LPAC_JNI_STRUCT_GETTER_STRING(struct es10b_notification_metadata_list, notification, iccid, Iccid)
+
+#pragma clang diagnostic pop
\ No newline at end of file