Refactor connecting to SAP service and sending messages in queue

Sending and receiving works correctly, however establishing an SAP connection takes too long
This commit is contained in:
Jan-Christopher Pien
2016-10-07 16:39:02 +02:00
committed by Frank Morgner
parent 023550ac11
commit f2a68c95c1
15 changed files with 217 additions and 117 deletions

View File

@@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -32,12 +32,14 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/apt/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
@@ -88,7 +90,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.2.1/jars" />
@@ -103,6 +104,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-verifier" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-resources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
@@ -118,18 +120,19 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-23.2.1" level="project" />
<orderEntry type="library" exported="" name="sdk-v1.0.0" level="project" />
<orderEntry type="library" exported="" name="design-23.2.1" level="project" />
<orderEntry type="library" exported="" name="zxing-android-embedded-3.2.0" level="project" />
<orderEntry type="library" exported="" name="accessory-v2.3.2" level="project" />
<orderEntry type="library" exported="" name="jcardsim-3.0.4-SNAPSHOT-android" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-23.2.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.2.1" level="project" />
<orderEntry type="library" exported="" name="design-23.2.1" level="project" />
<orderEntry type="library" exported="" name="core-3.2.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.2.1" level="project" />
<orderEntry type="library" exported="" name="accessory-v2.3.2" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-23.2.1" level="project" />
<orderEntry type="library" exported="" name="zxing-android-embedded-3.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.2.1" level="project" />
<orderEntry type="library" exported="" name="core-1.51.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.2.1" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-23.2.1" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-23.2.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.2.1" level="project" />
<orderEntry type="library" exported="" name="android-android-23" level="project" />
</component>
</module>

View File

@@ -120,6 +120,9 @@ public class MainActivity extends AppCompatActivity {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(EmulatorSingleton.TAG);
bManager.registerReceiver(bReceiver, intentFilter);
Intent serviceIntent = new Intent(this.getApplicationContext(), SmartcardProviderService.class);
startService(serviceIntent);
}
@Override

View File

@@ -60,7 +60,7 @@ public class SmartcardProviderService extends SAAgent {
EmulatorSingleton.createEmulator(this);
} catch (SsdkUnsupportedException e) {
// try to handle SsdkUnsupportedException
if (processUnsupportedException(e) == true) {
if (processUnsupportedException(e)) {
EmulatorSingleton.createEmulator(this);
return;
}
@@ -73,6 +73,7 @@ public class SmartcardProviderService extends SAAgent {
*/
stopSelf();
}
findPeerAgents();
}
@Override
@@ -82,13 +83,23 @@ public class SmartcardProviderService extends SAAgent {
@Override
protected void onFindPeerAgentsResponse(SAPeerAgent[] peerAgents, int result) {
switch (result) {
case PEER_AGENT_FOUND:
break;
case FINDPEER_SERVICE_NOT_FOUND:
break;
case FINDPEER_DEVICE_NOT_CONNECTED:
break;
default:
break;
}
Log.d(TAG, "onFindPeerAgentResponse : result =" + result);
}
@Override
protected void onServiceConnectionRequested(SAPeerAgent peerAgent) {
if (peerAgent != null) {
Toast.makeText(getBaseContext(), "connection accepted", Toast.LENGTH_SHORT).show();
//TODO: Check for keys and everything
acceptServiceConnectionRequest(peerAgent);
}
}
@@ -98,6 +109,7 @@ public class SmartcardProviderService extends SAAgent {
if (result == SAAgent.CONNECTION_SUCCESS) {
if (socket != null) {
mConnectionHandler = (ServiceConnection) socket;
Toast.makeText(getBaseContext(), "connection established", Toast.LENGTH_SHORT).show();
}
} else if (result == SAAgent.CONNECTION_ALREADY_EXIST) {
Log.e(TAG, "onServiceConnectionResponse, CONNECTION_ALREADY_EXIST");

View File

@@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.vsmartcard.smartcardemulator.MainActivity">
tools:context="com.vsmartcard.acardemulator.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"

View File

@@ -27,10 +27,10 @@
]>
<resources>
<application name="HelloAccessoryProvider" >
<application name="VirtualSmartCardReader" >
<serviceProfile
id="/sample/hello"
name="helloaccessory"
id="/com/vsmcartcard"
name="VirtualSmartCardReaderProvider"
role="provider"
serviceImpl="com.vsmartcard.acardemulator.SmartcardProviderService"
version="1.0"

View File

@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@@ -1,6 +1,6 @@
#Thu May 12 09:46:58 CEST 2016
#Tue Oct 04 22:11:09 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

View File

@@ -5,6 +5,7 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="org.tizen.nativecore.config.sbi.gcc45.app.debug.1329109068" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.tizen.nativecore.NativeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
@@ -12,17 +13,16 @@
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="com.vsmartcard.tcardemulator" buildArtefactType="org.tizen.nativecore.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.tizen.nativecore.buildArtefactType.app" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;" id="org.tizen.nativecore.config.sbi.gcc45.app.debug.1329109068" name="Debug" parent="org.tizen.nativecore.config.sbi.gcc45.app.debug">
<configuration artifactName="com.vsmartcard.tcardemulator" buildArtefactType="org.tizen.nativecore.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.tizen.nativecore.buildArtefactType.app,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;" id="org.tizen.nativecore.config.sbi.gcc45.app.debug.1329109068" name="Debug" parent="org.tizen.nativecore.config.sbi.gcc45.app.debug">
<folderInfo id="org.tizen.nativecore.config.sbi.gcc45.app.debug.1329109068." name="/" resourcePath="">
<toolChain id="org.tizen.nativecore.toolchain.sbi.gcc45.app.debug.1756955423" name="Tizen Native Toolchain" superClass="org.tizen.nativecore.toolchain.sbi.gcc45.app.debug">
<targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="org.tizen.nativeide.target.sbi.gnu.platform.base.1425984353" osList="linux,win32" superClass="org.tizen.nativeide.target.sbi.gnu.platform.base"/>
<builder autoBuildTarget="all" buildPath="${workspace_loc:/TCardEmulator}/Debug" enableAutoBuild="true" id="org.tizen.nativecore.target.sbi.gnu.builder.1787680921" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Tizen Application Builder" superClass="org.tizen.nativecore.target.sbi.gnu.builder"/>
<tool id="org.tizen.nativecore.tool.sbi.gnu.archiver.1781797598" name="Archiver" superClass="org.tizen.nativecore.tool.sbi.gnu.archiver"/>
<tool command="clang++" id="org.tizen.nativecore.tool.sbi.gnu.cpp.compiler.992648229" name="C++ Compiler" superClass="org.tizen.nativecore.tool.sbi.gnu.cpp.compiler">
<tool command="clang++.exe" id="org.tizen.nativecore.tool.sbi.gnu.cpp.compiler.992648229" name="C++ Compiler" superClass="org.tizen.nativecore.tool.sbi.gnu.cpp.compiler">
<option id="gnu.cpp.compiler.option.optimization.level.1129520531" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option defaultValue="gnu.cpp.compiler.debugging.level.max" id="sbi.gnu.cpp.compiler.option.debugging.level.core.2010611735" name="Debug level" superClass="sbi.gnu.cpp.compiler.option.debugging.level.core" valueType="enumerated"/>
<option defaultValue="false" id="sbi.gnu.cpp.compiler.option.misc.pic.core.1018206821" name="-fPIC option" superClass="sbi.gnu.cpp.compiler.option.misc.pic.core" valueType="boolean"/>
@@ -98,7 +98,7 @@
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.975801712" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool command="clang" id="org.tizen.nativecore.tool.sbi.gnu.c.compiler.136102720" name="C Compiler" superClass="org.tizen.nativecore.tool.sbi.gnu.c.compiler">
<tool command="clang.exe" id="org.tizen.nativecore.tool.sbi.gnu.c.compiler.136102720" name="C Compiler" superClass="org.tizen.nativecore.tool.sbi.gnu.c.compiler">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.88517044" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" valueType="enumerated"/>
<option defaultValue="gnu.c.debugging.level.max" id="sbi.gnu.c.compiler.option.debugging.level.core.1660527581" name="Debug level" superClass="sbi.gnu.c.compiler.option.debugging.level.core" valueType="enumerated"/>
<option defaultValue="false" id="sbi.gnu.c.compiler.option.misc.pic.core.785296696" name="-fPIC option" superClass="sbi.gnu.c.compiler.option.misc.pic.core" valueType="boolean"/>
@@ -175,14 +175,13 @@
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1649884941" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="org.tizen.nativeide.tool.sbi.gnu.c.linker.base.631588111" name="C Linker" superClass="org.tizen.nativeide.tool.sbi.gnu.c.linker.base"/>
<tool command="clang++" id="org.tizen.nativecore.tool.sbi.gnu.cpp.linker.274416099" name="C++ Linker" superClass="org.tizen.nativecore.tool.sbi.gnu.cpp.linker">
<tool command="clang++.exe" id="org.tizen.nativecore.tool.sbi.gnu.cpp.linker.274416099" name="C++ Linker" superClass="org.tizen.nativecore.tool.sbi.gnu.cpp.linker">
<option defaultValue="false" id="sbi.gnu.cpp.linker.option.shared_flag.core.26915008" name="Linker.Shared" superClass="sbi.gnu.cpp.linker.option.shared_flag.core" valueType="boolean"/>
<option defaultValue="false" id="sbi.gnu.cpp.linker.option.noundefined.core.1831689991" name="Report unresolved symbol references (-Wl,--no-undefined)" superClass="sbi.gnu.cpp.linker.option.noundefined.core" valueType="boolean"/>
<option id="sbi.gnu.cpp.linker.option.frameworks_lflags.core.1614788795" name="Tizen-Frameworks-Other-Lflags" superClass="sbi.gnu.cpp.linker.option.frameworks_lflags.core" valueType="stringList">
<listOptionValue builtIn="false" value="${TC_LINKER_MISC}"/>
<listOptionValue builtIn="false" value="${RS_LINKER_MISC}"/>
<listOptionValue builtIn="false" value="-pie -lpthread "/>
<listOptionValue builtIn="false" value="-Xlinker -rpath=&quot;/home/developer/sdk_tools/lib&quot;"/>
<listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
<listOptionValue builtIn="false" value="-Xlinker --version-script=&quot;${PROJ_PATH}/.exportMap&quot;"/>
<listOptionValue builtIn="false" value="-L&quot;${SBI_SYSROOT}/usr/lib&quot;"/>
@@ -197,7 +196,7 @@
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool command="arm-linux-gnueabi-as" id="org.tizen.nativeapp.tool.sbi.gnu.assembler.base.548583527" name="Assembler" superClass="org.tizen.nativeapp.tool.sbi.gnu.assembler.base">
<tool command="arm-linux-gnueabi-as.exe" id="org.tizen.nativeapp.tool.sbi.gnu.assembler.base.548583527" name="Assembler" superClass="org.tizen.nativeapp.tool.sbi.gnu.assembler.base">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1033719303" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
<tool id="org.tizen.nativecore.tool.fnmapgen.1575192993" name="C FN-Map Generator" superClass="org.tizen.nativecore.tool.fnmapgen"/>
@@ -223,6 +222,7 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="org.tizen.nativecore.config.sbi.gcc45.app.release.1757677484" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.tizen.nativecore.NativeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
@@ -230,17 +230,16 @@
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="com.vsmartcard.tcardemulator" buildArtefactType="org.tizen.nativecore.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.tizen.nativecore.buildArtefactType.app" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;" id="org.tizen.nativecore.config.sbi.gcc45.app.release.1757677484" name="Release" parent="org.tizen.nativecore.config.sbi.gcc45.app.release">
<configuration artifactName="com.vsmartcard.tcardemulator" buildArtefactType="org.tizen.nativecore.buildArtefactType.app" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.tizen.nativecore.buildArtefactType.app,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" description="" errorParsers="org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;" id="org.tizen.nativecore.config.sbi.gcc45.app.release.1757677484" name="Release" parent="org.tizen.nativecore.config.sbi.gcc45.app.release">
<folderInfo id="org.tizen.nativecore.config.sbi.gcc45.app.release.1757677484." name="/" resourcePath="">
<toolChain id="org.tizen.nativecore.toolchain.sbi.gcc45.app.release.589413647" name="Tizen Native Toolchain" superClass="org.tizen.nativecore.toolchain.sbi.gcc45.app.release">
<targetPlatform binaryParser="org.eclipse.cdt.core.ELF" id="org.tizen.nativeide.target.sbi.gnu.platform.base.251744671" osList="linux,win32" superClass="org.tizen.nativeide.target.sbi.gnu.platform.base"/>
<builder buildPath="${workspace_loc:/TCardEmulator}/Release" id="org.tizen.nativecore.target.sbi.gnu.builder.1951900405" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Tizen Application Builder" superClass="org.tizen.nativecore.target.sbi.gnu.builder"/>
<tool id="org.tizen.nativecore.tool.sbi.gnu.archiver.2072693820" name="Archiver" superClass="org.tizen.nativecore.tool.sbi.gnu.archiver"/>
<tool command="clang++" id="org.tizen.nativecore.tool.sbi.gnu.cpp.compiler.1078127376" name="C++ Compiler" superClass="org.tizen.nativecore.tool.sbi.gnu.cpp.compiler">
<tool command="clang++.exe" id="org.tizen.nativecore.tool.sbi.gnu.cpp.compiler.1078127376" name="C++ Compiler" superClass="org.tizen.nativecore.tool.sbi.gnu.cpp.compiler">
<option id="gnu.cpp.compiler.option.optimization.level.508218667" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
<option defaultValue="gnu.cpp.compiler.debugging.level.default" id="sbi.gnu.cpp.compiler.option.debugging.level.core.1054111679" name="Debug level" superClass="sbi.gnu.cpp.compiler.option.debugging.level.core" valueType="enumerated"/>
<option defaultValue="false" id="sbi.gnu.cpp.compiler.option.misc.pic.core.178297827" name="-fPIC option" superClass="sbi.gnu.cpp.compiler.option.misc.pic.core" valueType="boolean"/>
@@ -313,7 +312,7 @@
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1974288354" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool command="clang" id="org.tizen.nativecore.tool.sbi.gnu.c.compiler.1627185536" name="C Compiler" superClass="org.tizen.nativecore.tool.sbi.gnu.c.compiler">
<tool command="clang.exe" id="org.tizen.nativecore.tool.sbi.gnu.c.compiler.1627185536" name="C Compiler" superClass="org.tizen.nativecore.tool.sbi.gnu.c.compiler">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.839760477" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" valueType="enumerated"/>
<option defaultValue="gnu.c.debugging.level.default" id="sbi.gnu.c.compiler.option.debugging.level.core.1452382994" name="Debug level" superClass="sbi.gnu.c.compiler.option.debugging.level.core" valueType="enumerated"/>
<option defaultValue="false" id="sbi.gnu.c.compiler.option.misc.pic.core.1405555431" name="-fPIC option" superClass="sbi.gnu.c.compiler.option.misc.pic.core" valueType="boolean"/>
@@ -387,14 +386,13 @@
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.2137682856" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="org.tizen.nativeide.tool.sbi.gnu.c.linker.base.1895617564" name="C Linker" superClass="org.tizen.nativeide.tool.sbi.gnu.c.linker.base"/>
<tool command="clang++" id="org.tizen.nativecore.tool.sbi.gnu.cpp.linker.417969963" name="C++ Linker" superClass="org.tizen.nativecore.tool.sbi.gnu.cpp.linker">
<tool command="clang++.exe" id="org.tizen.nativecore.tool.sbi.gnu.cpp.linker.417969963" name="C++ Linker" superClass="org.tizen.nativecore.tool.sbi.gnu.cpp.linker">
<option defaultValue="false" id="sbi.gnu.cpp.linker.option.shared_flag.core.45803718" name="Linker.Shared" superClass="sbi.gnu.cpp.linker.option.shared_flag.core" valueType="boolean"/>
<option defaultValue="false" id="sbi.gnu.cpp.linker.option.noundefined.core.1705005837" name="Report unresolved symbol references (-Wl,--no-undefined)" superClass="sbi.gnu.cpp.linker.option.noundefined.core" valueType="boolean"/>
<option id="sbi.gnu.cpp.linker.option.frameworks_lflags.core.1487027321" superClass="sbi.gnu.cpp.linker.option.frameworks_lflags.core" valueType="stringList">
<listOptionValue builtIn="false" value="${TC_LINKER_MISC}"/>
<listOptionValue builtIn="false" value="${RS_LINKER_MISC}"/>
<listOptionValue builtIn="false" value="-pie -lpthread "/>
<listOptionValue builtIn="false" value="-Xlinker -rpath=&quot;/home/developer/sdk_tools/lib&quot;"/>
<listOptionValue builtIn="false" value="--sysroot=&quot;${SBI_SYSROOT}&quot;"/>
<listOptionValue builtIn="false" value="-Xlinker --version-script=&quot;${PROJ_PATH}/.exportMap&quot;"/>
<listOptionValue builtIn="false" value="-L&quot;${SBI_SYSROOT}/usr/lib&quot;"/>
@@ -408,7 +406,7 @@
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool command="i386-linux-gnueabi-as" id="org.tizen.nativeapp.tool.sbi.gnu.assembler.base.267643016" name="Assembler" superClass="org.tizen.nativeapp.tool.sbi.gnu.assembler.base">
<tool command="i386-linux-gnueabi-as.exe" id="org.tizen.nativeapp.tool.sbi.gnu.assembler.base.267643016" name="Assembler" superClass="org.tizen.nativeapp.tool.sbi.gnu.assembler.base">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1669348827" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
<tool id="org.tizen.nativecore.tool.fnmapgen.1204270433" name="C FN-Map Generator" superClass="org.tizen.nativecore.tool.fnmapgen"/>

View File

@@ -0,0 +1,8 @@
#ifndef __sap_H__
#define __sap_H__
#include <nfc.h>
void send_apdu_response(nfc_se_h handle, unsigned char *resp, unsigned int resp_len);
#endif /* __tcardemulator_H__ */

View File

@@ -9,18 +9,19 @@
#include <stddef.h>
#include <glib.h>
#include <nfc.h>
extern unsigned char *rapdu;
extern size_t rapdu_length;
extern gboolean rapdu_received;
//extern unsigned char *rapdu;
//extern size_t rapdu_length;
//extern gboolean rapdu_received;
#define HELLO_ACC_ASPID "/sample/hello"
#define HELLO_ACC_ASPID "/com/vsmcartcard"
#define HELLO_ACC_CHANNELID 104
void initialize_sap();
gboolean find_peers();
gboolean request_service_connection(void);
gboolean terminate_service_connection(void);
gboolean send_data(void *message, unsigned int message_len);
gboolean send_data(nfc_se_h nfc_handle, void *message, unsigned int message_len);
#endif /* __tcardemulator_H__ */

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<application name="com.vsmartcard.tcardemulator">
<serviceProfile id="/sample/hello" name="HelloAccessoryConsumer"
<application name="VirtualSmartCardReader">
<serviceProfile id="/com/vsmcartcard" name="VirtualSmartCardReaderConsumer"
role="consumer" version="1.0">
<supportedTransports>
<transport type="TRANSPORT_BT" />

View File

@@ -1,20 +1,32 @@
#include "tcardemulator.h"
#include <sap.h>
#include "sap_app.h"
#include <dlog.h>
#include <unistd.h>
#include <stdlib.h>
#include <nfc.h>
#include <sap.h>
#define HELLO_ACCESSORY_PROFILE_ID "/sample/hello"
#define HELLO_ACCESSORY_PROFILE_ID "/com/vsmcartcard"
#define HELLO_ACCESSORY_CHANNELID 104
struct priv {
typedef struct priv {
sap_agent_h agent;
sap_socket_h socket;
sap_peer_agent_h peer_agent;
};
nfc_se_h nfc_handle;
} priv_s;
typedef struct message_queue {
void *message;
unsigned int message_len;
struct message_queue *next;
} message_queue_s;
static gboolean agent_created = FALSE;
static gboolean agent_connected = FALSE;
static struct priv priv_data = { 0 };
static priv_s priv_data = { 0 };
static message_queue_s *m_queue = NULL;
void on_peer_agent_updated(sap_peer_agent_h peer_agent,
sap_peer_agent_status_e peer_status,
@@ -54,7 +66,7 @@ void on_peer_agent_updated(sap_peer_agent_h peer_agent,
static void on_service_connection_terminated(sap_peer_agent_h peer_agent,
sap_socket_h socket,
sap_service_connection_result_e result,
sap_service_connection_terminated_reason_e result,
void *user_data)
{
switch (result) {
@@ -75,6 +87,7 @@ static void on_service_connection_terminated(sap_peer_agent_h peer_agent,
sap_socket_destroy(priv_data.socket);
priv_data.socket = NULL;
agent_connected = FALSE;
}
@@ -85,28 +98,77 @@ static void on_data_recieved(sap_socket_h socket,
void *user_data)
{
dlog_print(DLOG_INFO, LOG_TAG, "received data: %p, len:%d", buffer, payload_length);
unsigned char *p = realloc(rapdu, payload_length);
if (p) {
rapdu = p;
rapdu_length = payload_length;
} else {
dlog_print(DLOG_ERROR, LOG_TAG, "not enough for storing data");
if (rapdu && rapdu_length >= 2) {
dlog_print(DLOG_ERROR, LOG_TAG,
"not enough memory, returning 0x6D00 as R-APDU");
rapdu[0] = 0x6D;
rapdu[1] = 0x00;
rapdu_length = 2;
} else {
dlog_print(DLOG_ERROR, LOG_TAG,
"not enough memory, setting R-APDU to nothing");
rapdu_length = 0;
}
}
//unsigned char *p = realloc(rapdu, payload_length);
// if (p) {
// rapdu = p;
// rapdu_length = payload_length;
// } else {
// dlog_print(DLOG_ERROR, LOG_TAG, "not enough for storing data");
// if (rapdu && rapdu_length >= 2) {
// dlog_print(DLOG_ERROR, LOG_TAG,
// "not enough memory, returning 0x6D00 as R-APDU");
// rapdu[0] = 0x6D;
// rapdu[1] = 0x00;
// rapdu_length = 2;
// } else {
// dlog_print(DLOG_ERROR, LOG_TAG,
// "not enough memory, setting R-APDU to nothing");
// rapdu_length = 0;
// }
// }
rapdu_received = TRUE;
// rapdu_received = TRUE;
send_apdu_response(priv_data.nfc_handle, buffer, payload_length);
}
message_queue_s *read_message() {
if (m_queue != NULL) {
message_queue_s *message = m_queue;
m_queue = message->next;
return message;
}
return NULL;
}
gboolean add_message(void *message, unsigned int message_len) {
message_queue_s *message_pointer = m_queue;
message_queue_s *prev = message_pointer;
while (message_pointer != NULL) {
prev = message_pointer;
message_pointer = message_pointer->next;
}
message_pointer = malloc(sizeof (message_queue_s));
if (message_pointer != NULL) {
if (m_queue == NULL) {
m_queue = message_pointer;
} else {
prev->next = message_pointer;
}
message_pointer->message = message;
message_pointer->message_len = message_len;
message_pointer->next = NULL;
return TRUE;
}
return FALSE;
}
gboolean send_data(nfc_se_h nfc_handle, void *message, unsigned int message_len) {
gboolean result;
if (agent_connected) {
priv_data.nfc_handle = nfc_handle;
result = sap_socket_send_data(priv_data.socket,
HELLO_ACCESSORY_CHANNELID, message_len, message);
if (result != SAP_RESULT_SUCCESS) {
}
} else {
result = add_message(message, message_len);
}
return result;
}
static void on_service_connection_created(sap_peer_agent_h peer_agent,
sap_socket_h socket,
@@ -122,6 +184,13 @@ static void on_service_connection_created(sap_peer_agent_h peer_agent,
sap_socket_set_data_received_cb(socket, on_data_recieved, peer_agent);
priv_data.socket = socket;
agent_connected = TRUE;
// read messages in queue and send them
message_queue_s *message_queue = read_message();
while (message_queue != NULL) {
send_data(priv_data.nfc_handle, message_queue->message, message_queue->message_len);
message_queue = read_message();
}
break;
case SAP_CONNECTION_ALREADY_EXIST:
@@ -197,9 +266,12 @@ static gboolean _terminate_service_connection(gpointer user_data)
}
if (result == SAP_RESULT_SUCCESS) {
dlog_print(DLOG_DEBUG, LOG_TAG, "req service conn call succeeded");
dlog_print(DLOG_DEBUG, LOG_TAG, "terminate service conn call succeeded");
priv->socket = NULL;
agent_connected = FALSE;
} else {
dlog_print(DLOG_ERROR, LOG_TAG, "req service conn call is failed (%d)", result);
dlog_print(DLOG_ERROR, LOG_TAG, "terminate service conn call is failed (%d)", result);
}
return FALSE;
@@ -237,18 +309,6 @@ gboolean find_peers()
return TRUE;
}
gboolean send_data(void *message, unsigned int message_len)
{
int result;
if (priv_data.socket) {
result = sap_socket_send_data(priv_data.socket,
HELLO_ACCESSORY_CHANNELID, message_len, message);
} else {
return FALSE;
}
return TRUE;
}
static void on_agent_initialized(sap_agent_h agent,
sap_agent_initialized_result_e result,
void *user_data)

View File

@@ -5,9 +5,13 @@
#include <unistd.h>
#include <stdlib.h>
unsigned char *rapdu = NULL;
size_t rapdu_length = 0;
gboolean rapdu_received = FALSE;
typedef struct appdata {
} appdata_s;
//unsigned char *rapdu = NULL;
//size_t rapdu_length = 0;
//gboolean rapdu_received = FALSE;
static void
hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event,
@@ -17,26 +21,29 @@ hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event,
case NFC_HCE_EVENT_DEACTIVATED:
// Do something when NFC_HCE_EVENT_DEACTIVATED event arrives
// When the event arrives, apdu and apdu len is NULL and 0
dlog_print(DLOG_DEBUG, LOG_TAG, "received NFC_HCE_EVENT_DEACTIVATED event on NFC handle %d", handle);
terminate_service_connection();
break;
case NFC_HCE_EVENT_ACTIVATED:
// Do something when NFC_HCE_EVENT_ACTIVATED event arrives
// When the event arrives, apdu and apdu len is NULL and 0
dlog_print(DLOG_DEBUG, LOG_TAG, "received NFC_HCE_EVENT_ACTIVATED event on NFC handle %d", handle);
find_peers();
break;
case NFC_HCE_EVENT_APDU_RECEIVED:
rapdu_received = FALSE;
send_data(apdu, apdu_len);
size_t count = 0;
while (!rapdu_received && count < 10) {
dlog_print(DLOG_INFO, LOG_TAG, "waiting for response");
usleep(100);
count++;
}
nfc_hce_send_apdu_response(handle, rapdu, rapdu_length);
rapdu_received = FALSE;
// rapdu_received = FALSE;
dlog_print(DLOG_DEBUG, LOG_TAG, "received NFC_HCE_EVENT_APDU_RECEIVED event on NFC handle %d", handle);
send_data(handle, apdu, apdu_len);
// size_t count_apdu = 0;
// while (!rapdu_received && count_apdu < 10) {
// dlog_print(DLOG_INFO, LOG_TAG, "waiting for response");
// usleep(100);
// count_apdu++;
// }
// nfc_hce_send_apdu_response(handle, rapdu, rapdu_length);
// rapdu_received = FALSE;
break;
default:
@@ -45,6 +52,11 @@ hce_event_cb(nfc_se_h handle, nfc_hce_event_type_e event,
}
}
void send_apdu_response(nfc_se_h handle, unsigned char *resp, unsigned int resp_len) {
dlog_print(DLOG_DEBUG, LOG_TAG, "sending data to nfc handle: %d", handle);
nfc_hce_send_apdu_response(handle, resp, resp_len);
}
bool
service_app_create(void *data)
{
@@ -76,6 +88,8 @@ service_app_create(void *data)
if (ret != NFC_ERROR_NONE) {
dlog_print(DLOG_ERROR, LOG_TAG, "nfc_manager_set_hce_event_cb failed : %d", ret);
goto err;
} else {
dlog_print(DLOG_DEBUG, LOG_TAG, "nfc_manager_set_hce_event_cb succeeded");
}
initialize_sap();
@@ -101,10 +115,10 @@ service_app_terminate(void *data)
terminate_service_connection();
free(rapdu);
rapdu = NULL;
rapdu_length = 0;
rapdu_received = FALSE;
// free(rapdu);
// rapdu = NULL;
// rapdu_length = 0;
// rapdu_received = FALSE;
return;
}
@@ -118,19 +132,19 @@ service_app_control(app_control_h app_control, void *data)
}
void
service_app_low_memory_callback(void *data)
service_app_low_memory(void *data)
{
// Todo: add your code here
service_app_exit();
service_app_terminate(&data);
return;
}
void
service_app_low_battery_callback(void *data)
service_app_low_battery(void *data)
{
// Todo: add your code here
service_app_exit();
service_app_terminate(&data);
return;
}
@@ -138,29 +152,30 @@ service_app_low_battery_callback(void *data)
int
main(int argc, char* argv[])
{
char ad[50] = {0,};
appdata_s ad = {};
service_app_event_callback_s event_callback;
event_callback.create = service_app_create;
event_callback.terminate = service_app_terminate;
event_callback.app_control = service_app_control;
event_callback.low_memory = service_app_low_memory_callback;
event_callback.low_battery = service_app_low_battery_callback;
event_callback.low_memory = service_app_low_memory;
event_callback.low_battery = service_app_low_battery;
#if 1
initialize_sap();
find_peers();
rapdu_received = FALSE;
unsigned char apdu[] = {0x00, 0xa4, 0x00, 0x00};
send_data(apdu, sizeof apdu);
size_t count = 0;
while (!rapdu_received && count < 10) {
dlog_print(DLOG_INFO, LOG_TAG, "waiting for response");
usleep(100);
count++;
}
#endif
return svc_app_main(argc, argv, &event_callback, ad);
//#if 1
// initialize_sap();
// find_peers();
// rapdu_received = FALSE;
// unsigned char apdu[] = {0x00, 0xa4, 0x00, 0x00};
// send_data(apdu, sizeof apdu);
// size_t count = 0;
// while (!rapdu_received && count < 10) {
// dlog_print(DLOG_INFO, LOG_TAG, "waiting for response");
// usleep(100);
// count++;
// }
//#endif
return svc_app_main(argc, argv, &event_callback, &ad);
}

View File

@@ -8,8 +8,8 @@
<metadata key="accessory-services-location" value="/res/accessoryservices.xml"/>
</service-application>
<privileges>
<privilege>http://developer.samsung.com/tizen/privilege/accessoryprotocol</privilege>
<privilege>http://tizen.org/privilege/nfc.cardemulation</privilege>
<privilege>http://developer.samsung.com/tizen/privilege/accessoryprotocol</privilege>
</privileges>
<feature name="http://tizen.org/feature/network.nfc.card_emulation.hce">true</feature>
</manifest>