Compare commits

..

No commits in common. "a48e44436aa51808ea86be5830e716d8bc5440f7" and "36ca0d3b79fc1b337412190d2644885d1b3a4060" have entirely different histories.

View file

@ -52,8 +52,6 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(
jmethodID set_cancelled = (*env)->GetMethodID(env, callback_class, "setCancelled", "(Z)V"); jmethodID set_cancelled = (*env)->GetMethodID(env, callback_class, "setCancelled", "(Z)V");
#define IS_CANCELLED (*env)->CallBooleanMethod(env, callback, is_cancelled) #define IS_CANCELLED (*env)->CallBooleanMethod(env, callback, is_cancelled)
#define CHECK_INVOKE_FAILED(COND) if (COND) { ret = -ES10B_ERROR_REASON_UNDEFINED; goto out; }
#define EMIT_STATE_UPDATE(STATE) (*env)->CallVoidMethod(env, callback, on_state_update, download_state_##STATE)
if (confirmation_code != NULL) if (confirmation_code != NULL)
_confirmation_code = (*env)->GetStringUTFChars(env, confirmation_code, NULL); _confirmation_code = (*env)->GetStringUTFChars(env, confirmation_code, NULL);
@ -65,36 +63,52 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(
ctx->http.server_address = _smdp; ctx->http.server_address = _smdp;
// region preparing if (IS_CANCELLED) {
CHECK_INVOKE_FAILED(IS_CANCELLED) ret = -ES10B_ERROR_REASON_UNDEFINED;
EMIT_STATE_UPDATE(preparing); goto out;
}
(*env)->CallVoidMethod(env, callback, on_state_update, download_state_preparing);
ret = es10b_get_euicc_challenge_and_info(ctx); ret = es10b_get_euicc_challenge_and_info(ctx);
syslog(LOG_INFO, "es10b_get_euicc_challenge_and_info %d", ret); syslog(LOG_INFO, "es10b_get_euicc_challenge_and_info %d", ret);
CHECK_INVOKE_FAILED(ret < 0) if (ret < 0) {
// endregion ret = -ES10B_ERROR_REASON_UNDEFINED;
goto out;
}
// region connecting if (IS_CANCELLED) {
CHECK_INVOKE_FAILED(IS_CANCELLED) ret = -ES10B_ERROR_REASON_UNDEFINED;
EMIT_STATE_UPDATE(connecting); goto out;
}
(*env)->CallVoidMethod(env, callback, on_state_update, download_state_connecting);
ret = es9p_initiate_authentication(ctx); ret = es9p_initiate_authentication(ctx);
syslog(LOG_INFO, "es9p_initiate_authentication %d", ret); syslog(LOG_INFO, "es9p_initiate_authentication %d", ret);
CHECK_INVOKE_FAILED(ret < 0) if (ret < 0) {
// endregion ret = -ES10B_ERROR_REASON_UNDEFINED;
goto out;
}
// region authenticating if (IS_CANCELLED) {
CHECK_INVOKE_FAILED(IS_CANCELLED) ret = -ES10B_ERROR_REASON_UNDEFINED;
EMIT_STATE_UPDATE(authenticating); goto out;
}
(*env)->CallVoidMethod(env, callback, on_state_update, download_state_authenticating);
ret = es10b_authenticate_server(ctx, _matching_id, _imei); ret = es10b_authenticate_server(ctx, _matching_id, _imei);
syslog(LOG_INFO, "es10b_authenticate_server %d", ret); syslog(LOG_INFO, "es10b_authenticate_server %d", ret);
CHECK_INVOKE_FAILED(ret < 0) if (ret < 0) {
ret = -ES10B_ERROR_REASON_UNDEFINED;
goto out;
}
CHECK_INVOKE_FAILED(IS_CANCELLED) if (IS_CANCELLED) {
ret = -ES10B_ERROR_REASON_UNDEFINED;
goto out;
}
ret = es9p_authenticate_client(ctx); ret = es9p_authenticate_client(ctx);
syslog(LOG_INFO, "es9p_authenticate_client %d", ret); if (ret < 0) {
CHECK_INVOKE_FAILED(ret < 0) ret = -ES10B_ERROR_REASON_UNDEFINED;
// endregion goto out;
}
// region emit profile metadata
const char *b64_profileMetadata = ctx->http._internal.prepare_download_param->b64_profileMetadata; const char *b64_profileMetadata = ctx->http._internal.prepare_download_param->b64_profileMetadata;
if (b64_profileMetadata != NULL) { if (b64_profileMetadata != NULL) {
ret = es8p_metadata_parse(&profile_metadata, b64_profileMetadata); ret = es8p_metadata_parse(&profile_metadata, b64_profileMetadata);
@ -104,29 +118,33 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(
} }
(*env)->CallVoidMethod(env, callback, on_profile_metadata, (*env)->CallVoidMethod(env, callback, on_profile_metadata,
build_profile_metadata(env, profile_metadata)); build_profile_metadata(env, profile_metadata));
if ((*env)->ExceptionCheck(env) == JNI_TRUE) {
ret = -ES10B_ERROR_REASON_UNDEFINED;
goto out;
}
} }
// endregion
// region downloading if (IS_CANCELLED) {
CHECK_INVOKE_FAILED(IS_CANCELLED) ret = -ES10B_ERROR_REASON_UNDEFINED;
EMIT_STATE_UPDATE(downloading); goto out;
}
(*env)->CallVoidMethod(env, callback, on_state_update, download_state_downloading);
ret = es10b_prepare_download(ctx, _confirmation_code); ret = es10b_prepare_download(ctx, _confirmation_code);
syslog(LOG_INFO, "es10b_prepare_download %d", ret); syslog(LOG_INFO, "es10b_prepare_download %d", ret);
CHECK_INVOKE_FAILED(ret < 0) if (ret < 0) {
ret = -ES10B_ERROR_REASON_UNDEFINED;
goto out;
}
CHECK_INVOKE_FAILED(IS_CANCELLED) if (IS_CANCELLED) {
ret = -ES10B_ERROR_REASON_UNDEFINED;
goto out;
}
ret = es9p_get_bound_profile_package(ctx); ret = es9p_get_bound_profile_package(ctx);
syslog(LOG_INFO, "es9p_get_bound_profile_package %d", ret); if (ret < 0)
if (ret < 0) goto out; goto out;
// endregion
// region finalizing if (IS_CANCELLED) {
CHECK_INVOKE_FAILED(IS_CANCELLED) ret = -ES10B_ERROR_REASON_UNDEFINED;
EMIT_STATE_UPDATE(finalizing); goto out;
}
(*env)->CallVoidMethod(env, callback, on_state_update, download_state_finalizing);
ret = es10b_load_bound_profile_package(ctx, &es10b_load_bound_profile_package_result); ret = es10b_load_bound_profile_package(ctx, &es10b_load_bound_profile_package_result);
syslog(LOG_INFO, "es10b_load_bound_profile_package %d, reason %d", ret, syslog(LOG_INFO, "es10b_load_bound_profile_package %d, reason %d", ret,
es10b_load_bound_profile_package_result.errorReason); es10b_load_bound_profile_package_result.errorReason);
@ -134,21 +152,15 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(
ret = -(int) es10b_load_bound_profile_package_result.errorReason; ret = -(int) es10b_load_bound_profile_package_result.errorReason;
goto out; goto out;
} }
// endregion
euicc_http_cleanup(ctx); euicc_http_cleanup(ctx);
out: out:
// isCancelled() == false, but ret is an error, the set to cancelled
if (IS_CANCELLED == 0 && ret == -ES10B_ERROR_REASON_UNDEFINED) { if (IS_CANCELLED == 0 && ret == -ES10B_ERROR_REASON_UNDEFINED) {
(*env)->CallVoidMethod(env, callback, set_cancelled, JNI_TRUE); (*env)->CallVoidMethod(env, callback, set_cancelled, JNI_TRUE);
} }
es8p_metadata_free(&profile_metadata); es8p_metadata_free(&profile_metadata);
#undef IS_CANCELLED #undef IS_CANCELLED
#undef CHECK_INVOKE_FAILED
#undef EMIT_STATE_UPDATE
// We expect Java side to call cancelSessions after any error -- thus, `euicc_http_cleanup` is done there // We expect Java side to call cancelSessions after any error -- thus, `euicc_http_cleanup` is done there
// This is so that Java side can access the last HTTP and/or APDU errors when we return. // This is so that Java side can access the last HTTP and/or APDU errors when we return.
if (_confirmation_code != NULL) if (_confirmation_code != NULL)