*/
#include "imc_android_state.h"
+#include "../android_jni.h"
#include <tnc/tnc.h>
#include <libpts.h>
static imc_agent_t *imc_android;
+/**
+ * AndroidImc object accessed via JNI
+ */
+static jobject android_imc;
+
+/**
+ * AndroidImc class object
+ */
+static jclass android_imc_cls;
+
/**
* see section 3.8.1 of TCG TNC IF-IMC Specification 1.3
*/
bool imc_android_register(plugin_t *plugin, plugin_feature_t *feature,
bool reg, void *data)
{
+ JNIEnv *env;
+ jmethodID method_id;
+ jobject obj, context = (jobject)data;
+ jclass cls;
+ bool success = TRUE;
+
+ androidjni_attach_thread(&env);
if (reg)
{
- return tnc->imcs->load_from_functions(tnc->imcs, "android",
+ cls = (*env)->FindClass(env, JNI_PACKAGE_STRING "/imc/AndroidImc");
+ if (!cls)
+ {
+ goto failed;
+ }
+ android_imc_cls = (*env)->NewGlobalRef(env, cls);
+ method_id = (*env)->GetMethodID(env, cls, "<init>",
+ "(Landroid/content/Context;)V");
+ if (!method_id)
+ {
+ goto failed;
+ }
+ obj = (*env)->NewObject(env, cls, method_id, context);
+ if (!obj)
+ {
+ goto failed;
+ }
+ android_imc = (*env)->NewGlobalRef(env, obj);
+ androidjni_detach_thread();
+
+ if (tnc->imcs->load_from_functions(tnc->imcs, "Android",
TNC_IMC_Initialize, TNC_IMC_NotifyConnectionChange,
TNC_IMC_BeginHandshake, TNC_IMC_ReceiveMessage,
TNC_IMC_ReceiveMessageLong, TNC_IMC_BatchEnding,
- TNC_IMC_Terminate, TNC_IMC_ProvideBindFunction);
+ TNC_IMC_Terminate, TNC_IMC_ProvideBindFunction))
+ {
+ return TRUE;
+ }
+failed:
+ DBG1(DBG_IMC, "initialization of Android IMC failed");
+ androidjni_exception_occurred(env);
+ success = FALSE;
+ }
+
+ if (android_imc)
+ {
+ (*env)->DeleteGlobalRef(env, android_imc);
+ android_imc = NULL;
+ }
+ if (android_imc_cls)
+ {
+ (*env)->DeleteGlobalRef(env, android_imc_cls);
+ android_imc_cls = NULL;
}
- return TRUE;
+ androidjni_detach_thread();
+ return success;
}
PLUGIN_PROVIDE(CUSTOM, "android-backend"),
PLUGIN_DEPENDS(CUSTOM, "libcharon"),
};
-#ifdef USE_BYOD
- static plugin_feature_t byod_features[] = {
- PLUGIN_CALLBACK(imc_android_register, NULL),
- PLUGIN_PROVIDE(CUSTOM, "android-imc"),
- PLUGIN_DEPENDS(CUSTOM, "android-backend"),
- PLUGIN_DEPENDS(CUSTOM, "imc-manager"),
- };
-#endif
INIT(this,
.public = {
countof(features), TRUE);
#ifdef USE_BYOD
- lib->plugins->add_static_features(lib->plugins, "android-byod",
+ {
+ plugin_feature_t byod_features[] = {
+ PLUGIN_CALLBACK(imc_android_register, this->vpn_service),
+ PLUGIN_PROVIDE(CUSTOM, "android-imc"),
+ PLUGIN_DEPENDS(CUSTOM, "android-backend"),
+ PLUGIN_DEPENDS(CUSTOM, "imc-manager"),
+ };
+
+ lib->plugins->add_static_features(lib->plugins, "android-byod",
byod_features, countof(byod_features), TRUE);
+ }
#endif
}
--- /dev/null
+/*
+ * Copyright (C) 2013 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+package org.strongswan.android.logic.imc;
+
+import android.content.Context;
+
+public class AndroidImc
+{
+ private final Context mContext;
+
+ public AndroidImc(Context context)
+ {
+ mContext = context;
+ }
+}