forked from PeterCxy/OpenEUICC
Compare commits
2 commits
36ca0d3b79
...
a48e44436a
Author | SHA1 | Date | |
---|---|---|---|
a48e44436a | |||
626839977e |
1 changed files with 43 additions and 55 deletions
|
@ -52,6 +52,8 @@ 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);
|
||||||
|
@ -63,52 +65,36 @@ Java_net_typeblog_lpac_1jni_LpacJni_downloadProfile(
|
||||||
|
|
||||||
ctx->http.server_address = _smdp;
|
ctx->http.server_address = _smdp;
|
||||||
|
|
||||||
if (IS_CANCELLED) {
|
// region preparing
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
CHECK_INVOKE_FAILED(IS_CANCELLED)
|
||||||
goto out;
|
EMIT_STATE_UPDATE(preparing);
|
||||||
}
|
|
||||||
(*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);
|
||||||
if (ret < 0) {
|
CHECK_INVOKE_FAILED(ret < 0)
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
// endregion
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IS_CANCELLED) {
|
// region connecting
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
CHECK_INVOKE_FAILED(IS_CANCELLED)
|
||||||
goto out;
|
EMIT_STATE_UPDATE(connecting);
|
||||||
}
|
|
||||||
(*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);
|
||||||
if (ret < 0) {
|
CHECK_INVOKE_FAILED(ret < 0)
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
// endregion
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IS_CANCELLED) {
|
// region authenticating
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
CHECK_INVOKE_FAILED(IS_CANCELLED)
|
||||||
goto out;
|
EMIT_STATE_UPDATE(authenticating);
|
||||||
}
|
|
||||||
(*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);
|
||||||
if (ret < 0) {
|
CHECK_INVOKE_FAILED(ret < 0)
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IS_CANCELLED) {
|
CHECK_INVOKE_FAILED(IS_CANCELLED)
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
ret = es9p_authenticate_client(ctx);
|
ret = es9p_authenticate_client(ctx);
|
||||||
if (ret < 0) {
|
syslog(LOG_INFO, "es9p_authenticate_client %d", ret);
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
CHECK_INVOKE_FAILED(ret < 0)
|
||||||
goto out;
|
// endregion
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
@ -118,33 +104,29 @@ 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) {
|
||||||
|
|
||||||
if (IS_CANCELLED) {
|
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
(*env)->CallVoidMethod(env, callback, on_state_update, download_state_downloading);
|
}
|
||||||
|
// endregion
|
||||||
|
|
||||||
|
// region downloading
|
||||||
|
CHECK_INVOKE_FAILED(IS_CANCELLED)
|
||||||
|
EMIT_STATE_UPDATE(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);
|
||||||
if (ret < 0) {
|
CHECK_INVOKE_FAILED(ret < 0)
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IS_CANCELLED) {
|
CHECK_INVOKE_FAILED(IS_CANCELLED)
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
ret = es9p_get_bound_profile_package(ctx);
|
ret = es9p_get_bound_profile_package(ctx);
|
||||||
if (ret < 0)
|
syslog(LOG_INFO, "es9p_get_bound_profile_package %d", ret);
|
||||||
goto out;
|
if (ret < 0) goto out;
|
||||||
|
// endregion
|
||||||
|
|
||||||
if (IS_CANCELLED) {
|
// region finalizing
|
||||||
ret = -ES10B_ERROR_REASON_UNDEFINED;
|
CHECK_INVOKE_FAILED(IS_CANCELLED)
|
||||||
goto out;
|
EMIT_STATE_UPDATE(finalizing);
|
||||||
}
|
|
||||||
(*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);
|
||||||
|
@ -152,15 +134,21 @@ 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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue