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 6b41a3a..be490fd 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 @@ -14,30 +14,21 @@ static jmethodID method_http_transmit; static jfieldID field_resp_rcode; static jfieldID field_resp_data; -#define APDU_INTERFACE_CLASS PACKAGE_NAME "/ApduInterface" -#define HTTP_INTERFACE_CLASS PACKAGE_NAME "/HttpInterface" -#define HTTP_RESPONSE_CLASS HTTP_INTERFACE_CLASS "$HttpResponse" - void interface_wrapper_init(JNIEnv *env) { - jclass apdu_class = (*env)->FindClass(env, APDU_INTERFACE_CLASS); + 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_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, HTTP_INTERFACE_CLASS); - method_http_transmit = (*env)->GetMethodID( - env, http_class, "transmit", - "(" - "Ljava/lang/String;" // url - "[B" // byte array - "Ljava/util/List;" // headers - ")" - "L" HTTP_RESPONSE_CLASS ";" - ); + jclass http_class = (*env)->FindClass(env, "net/typeblog/lpac_jni/HttpInterface"); + method_http_transmit = (*env)->GetMethodID(env, http_class, "transmit", + "(Ljava/lang/String;[BLjava/util/List;)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_data = (*env)->GetFieldID(env, resp_class, "data", "[B"); } @@ -45,7 +36,7 @@ void interface_wrapper_init(JNIEnv *env) { 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; } @@ -61,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); 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; } @@ -80,13 +71,13 @@ apdu_interface_transmit(struct euicc_ctx *ctx, uint8_t **rx, uint32_t *rx_len, c uint32_t tx_len) { const int logic_channel = LPAC_JNI_CTX(ctx)->logical_channel_id; LPAC_JNI_SETUP_ENV; - jbyteArray txArr = (*env)->NewByteArray(env, (jsize) tx_len); - (*env)->SetByteArrayRegion(env, txArr, 0, (jsize) tx_len, (const jbyte *) tx); + jbyteArray txArr = (*env)->NewByteArray(env, tx_len); + (*env)->SetByteArrayRegion(env, txArr, 0, 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, (jsize) *rx_len, (jbyte *) *rx); @@ -108,7 +99,7 @@ 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, header_list); - 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); 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 0562995..b1ab73e 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 @@ -174,25 +174,18 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile( } JNIEXPORT void JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_cancelSessions( - __attribute__((unused)) JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle -) { +Java_net_typeblog_lpac_1jni_LpacJni_cancelSessions(JNIEnv *env, jobject thiz, jlong handle) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; es9p_cancel_session(ctx); es10b_cancel_session(ctx, ES10B_CANCEL_SESSION_REASON_UNDEFINED); euicc_http_cleanup(ctx); } -#define ERRCODE_ENUM_TO_STRING(VARIANT) case VARIANT: return toJString(env, #VARIANT) +#define QUOTE(S) #S +#define ERRCODE_ENUM_TO_STRING(VARIANT) case VARIANT: return toJString(env, QUOTE(VARIANT)) JNIEXPORT jstring JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_downloadErrCodeToString( - JNIEnv *env, - __attribute__((unused)) jobject thiz, - jint code -) { +Java_net_typeblog_lpac_1jni_LpacJni_downloadErrCodeToString(JNIEnv *env, jobject thiz, jint code) { switch (code) { ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INCORRECT_INPUT_VALUES); ERRCODE_ENUM_TO_STRING(ES10B_ERROR_REASON_INVALID_SIGNATURE); 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 d4fddd0..9196ff7 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 @@ -16,7 +16,7 @@ JavaVM *jvm = NULL; #define LOCAL_PROFILE_INFO_CLASS "net/typeblog/lpac_jni/LocalProfileInfo" -jint JNI_OnLoad(JavaVM *vm, __attribute__((unused)) void *reserved) { +jint JNI_OnLoad(JavaVM *vm, void *reserved) { jvm = vm; LPAC_JNI_SETUP_ENV; @@ -30,7 +30,7 @@ jint JNI_OnLoad(JavaVM *vm, __attribute__((unused)) void *reserved) { JNIEXPORT jlong JNICALL Java_net_typeblog_lpac_1jni_LpacJni_createContext( JNIEnv *env, - __attribute__((unused)) jobject thiz, + jobject thiz, jbyteArray isdr_aid, jobject apdu_interface, jobject http_interface @@ -61,11 +61,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_createContext( } JNIEXPORT void JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_destroyContext( - JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle -) { +Java_net_typeblog_lpac_1jni_LpacJni_destroyContext(JNIEnv *env, jobject thiz, jlong handle) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; struct lpac_jni_ctx *jni_ctx = LPAC_JNI_CTX(ctx); @@ -77,42 +73,26 @@ Java_net_typeblog_lpac_1jni_LpacJni_destroyContext( } JNIEXPORT jint JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_euiccInit( - __attribute__((unused)) JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle -) { +Java_net_typeblog_lpac_1jni_LpacJni_euiccInit(JNIEnv *env, jobject thiz, jlong handle) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; return euicc_init(ctx); } JNIEXPORT void JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_euiccFini( - __attribute__((unused)) JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle -) { +Java_net_typeblog_lpac_1jni_LpacJni_euiccFini(JNIEnv *env, jobject thiz, jlong handle) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; euicc_fini(ctx); } JNIEXPORT void JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_euiccSetMss( - __attribute__((unused)) JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle, - jbyte mss -) { +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; } JNIEXPORT jstring JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_es10cGetEid( - __attribute__((unused)) JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle -) { +Java_net_typeblog_lpac_1jni_LpacJni_es10cGetEid(JNIEnv *env, jobject thiz, jlong handle) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; char *buf = NULL; @@ -175,13 +155,8 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10cGetProfilesInfo( } JNIEXPORT jint JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_es10cEnableProfile( - JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle, - jstring iccid, - jboolean refresh -) { +Java_net_typeblog_lpac_1jni_LpacJni_es10cEnableProfile(JNIEnv *env, jobject thiz, jlong handle, + jstring iccid, jboolean refresh) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; const char *_iccid = NULL; int ret; @@ -193,13 +168,8 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10cEnableProfile( } JNIEXPORT jint JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_es10cDisableProfile( - JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle, - jstring iccid, - jboolean refresh -) { +Java_net_typeblog_lpac_1jni_LpacJni_es10cDisableProfile(JNIEnv *env, jobject thiz, jlong handle, + jstring iccid, jboolean refresh) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; const char *_iccid = NULL; int ret; @@ -211,13 +181,8 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10cDisableProfile( } JNIEXPORT jint JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_es10cSetNickname( - JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle, - jstring iccid, - jbyteArray nick -) { +Java_net_typeblog_lpac_1jni_LpacJni_es10cSetNickname(JNIEnv *env, jobject thiz, jlong handle, + jstring iccid, jbyteArray nick) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; const char *_iccid = NULL; jbyte *_nick = NULL; @@ -232,12 +197,8 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10cSetNickname( } JNIEXPORT jint JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_es10cDeleteProfile( - JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle, - jstring iccid -) { +Java_net_typeblog_lpac_1jni_LpacJni_es10cDeleteProfile(JNIEnv *env, jobject thiz, jlong handle, + jstring iccid) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; const char *_iccid = NULL; int ret; @@ -249,11 +210,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10cDeleteProfile( } JNIEXPORT jobject JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_es10cexGetEuiccInfo2( - JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle -) { +Java_net_typeblog_lpac_1jni_LpacJni_es10cexGetEuiccInfo2(JNIEnv *env, jobject thiz, jlong handle) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; struct es10c_ex_euiccinfo2 *info = malloc(sizeof(struct es10c_ex_euiccinfo2)); jobject ret = NULL; @@ -296,11 +253,7 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10cexGetEuiccInfo2( } JNIEXPORT jint JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_es10cEuiccMemoryReset( - __attribute__((unused)) JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle -) { +Java_net_typeblog_lpac_1jni_LpacJni_es10cEuiccMemoryReset(JNIEnv *env, jobject thiz, jlong handle) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; return es10c_euicc_memory_reset(ctx); } 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 085074d..a581d40 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 @@ -52,12 +52,8 @@ Java_net_typeblog_lpac_1jni_LpacJni_es10bListNotification( } JNIEXPORT jint JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_handleNotification( - __attribute__((unused)) JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle, - jlong seq_number -) { +Java_net_typeblog_lpac_1jni_LpacJni_handleNotification(JNIEnv *env, jobject thiz, jlong handle, + jlong seq_number) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; struct es10b_pending_notification notification; int res; @@ -80,12 +76,8 @@ Java_net_typeblog_lpac_1jni_LpacJni_handleNotification( } JNIEXPORT jint JNICALL -Java_net_typeblog_lpac_1jni_LpacJni_es10bDeleteNotification( - __attribute__((unused)) JNIEnv *env, - __attribute__((unused)) jobject thiz, - jlong handle, - jlong seq_number -) { +Java_net_typeblog_lpac_1jni_LpacJni_es10bDeleteNotification(JNIEnv *env, jobject thiz, jlong handle, + jlong seq_number) { struct euicc_ctx *ctx = (struct euicc_ctx *) handle; return es10b_remove_notification_from_list(ctx, (unsigned long) seq_number); }