summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSudha Bheemanna <b.sudha@samsung.com>2016-12-20 15:43:00 +0530
committerSudha Bheemanna <b.sudha@samsung.com>2016-12-20 15:43:00 +0530
commita7a6966184bf5eda9e71e29fe9c4ac01102dfd12 (patch)
treebcd2dcd421082726b6ced7decf8e808c4a373eda
parentd600197c9246521746b24e06a111e6f327d7f42e (diff)
downloadsmartcard-a7a6966184bf5eda9e71e29fe9c4ac01102dfd12.tar.gz
smartcard-a7a6966184bf5eda9e71e29fe9c4ac01102dfd12.tar.bz2
smartcard-a7a6966184bf5eda9e71e29fe9c4ac01102dfd12.zip
[C# Smartcard] Adding code for Smartcard
Adding initial code for Smartcard. This code to be used as base for further development Change-Id: I06fdbd390cf94b5753bbe2fa1b5a41b75c5c8905 Signed-off-by: Sudha Bheemanna <b.sudha@samsung.com>
-rw-r--r--LICENSE202
-rw-r--r--Tizen.Smartcard/Interop/Interop.Glib.cs30
-rw-r--r--Tizen.Smartcard/Interop/Interop.Libc.cs27
-rw-r--r--Tizen.Smartcard/Interop/Interop.Libraries.cs25
-rw-r--r--Tizen.Smartcard/Interop/Interop.Smartcard.cs83
-rw-r--r--Tizen.Smartcard/Properties/AssemblyInfo.cs36
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard.Net45.csproj75
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard.Net45.project.json11
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard.csproj85
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard.nuspec21
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard.project.json9
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard.snkbin0 -> 596 bytes
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard/SmartcardChannel.cs241
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard/SmartcardErrorFactory.cs70
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard/SmartcardManager.cs38
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard/SmartcardManagerImpl.cs122
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard/SmartcardReader.cs150
-rw-r--r--Tizen.Smartcard/Tizen.Smartcard/SmartcardSession.cs229
-rw-r--r--packaging/csapi-smartcard.manifest5
-rw-r--r--packaging/csapi-smartcard.spec76
20 files changed, 1535 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/Tizen.Smartcard/Interop/Interop.Glib.cs b/Tizen.Smartcard/Interop/Interop.Glib.cs
new file mode 100644
index 0000000..576a6e2
--- /dev/null
+++ b/Tizen.Smartcard/Interop/Interop.Glib.cs
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Glib
+ {
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate bool GSourceFunc(IntPtr userData);
+
+ [DllImport(Libraries.Glib, EntryPoint = "g_idle_add", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern uint IdleAdd(GSourceFunc d, IntPtr data);
+ }
+}
diff --git a/Tizen.Smartcard/Interop/Interop.Libc.cs b/Tizen.Smartcard/Interop/Interop.Libc.cs
new file mode 100644
index 0000000..825599e
--- /dev/null
+++ b/Tizen.Smartcard/Interop/Interop.Libc.cs
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Libc
+ {
+ [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int Free(IntPtr ptr);
+ }
+}
diff --git a/Tizen.Smartcard/Interop/Interop.Libraries.cs b/Tizen.Smartcard/Interop/Interop.Libraries.cs
new file mode 100644
index 0000000..f231ed1
--- /dev/null
+++ b/Tizen.Smartcard/Interop/Interop.Libraries.cs
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+internal static partial class Interop
+{
+ internal static partial class Libraries
+ {
+ public const string Smartcard = "libcapi-network-smartcard.so.0";
+ public const string Glib = "libglib-2.0.so.0";
+ public const string Libc = "libc.so.6";
+ }
+}
diff --git a/Tizen.Smartcard/Interop/Interop.Smartcard.cs b/Tizen.Smartcard/Interop/Interop.Smartcard.cs
new file mode 100644
index 0000000..234de80
--- /dev/null
+++ b/Tizen.Smartcard/Interop/Interop.Smartcard.cs
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+ internal static partial class Smartcard
+ {
+ //capi-network-smartcard-0.0.6-2.1.armv7l.rpm
+ //Smartcard Manager
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_initialize")]
+ internal static extern int Initialize();
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_deinitialize")]
+ internal static extern int Deinitialize();
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_get_readers")]
+ internal static extern int GetReaders(out IntPtr readers, out int len);
+
+ internal static class Reader
+ {
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_reader_get_name")]
+ internal static extern int ReaderGetName(int reader, out IntPtr readerName);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_reader_is_secure_element_present")]
+ internal static extern int ReaderIsSecureElementPresent(int reader, out bool present);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_reader_open_session")]
+ internal static extern int ReaderOpenSession(int reader, out int session);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_reader_close_sessions")]
+ internal static extern int ReaderCloseSessions(int reader);
+ }
+
+ internal static class Session
+ {
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_session_get_reader")]
+ internal static extern int SessionGetReader(int session, out int reader);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_session_get_atr")]
+ internal static extern int SessionGetAtr(int session, out IntPtr atr, out int len);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_session_close")]
+ internal static extern int SessionClose(int session);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_session_is_closed")]
+ internal static extern int SessionIsClosed(int session, out bool closed);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_session_close_channels")]
+ internal static extern int SessionCloseChannels(int session);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_session_open_basic_channel")]
+ internal static extern int SessionOpenBasicChannel(int session, byte[] aid, int aidLen, byte p2, out int channel);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_session_open_logical_channel")]
+ internal static extern int SessionOpenLogicalChannel(int session, byte[] aid, int aidLen, byte p2, out int channel);
+ }
+
+ internal static class Channel
+ {
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_channel_close")]
+ internal static extern int ChannelClose(int channel);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_channel_is_basic_channel")]
+ internal static extern int ChannelIsBasicChannel(int channel, out bool basicChannel);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_channel_is_closed")]
+ internal static extern int ChannelIsClosed(int channel, out bool closed);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_channel_get_select_response")]
+ internal static extern int ChannelGetSelectResponse(int channel, out IntPtr selectResp, out int len);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_channel_get_session")]
+ internal static extern int ChannelGetSession(int channel, out int session);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_channel_transmit")]
+ internal static extern int ChannelTransmit(int channel, byte[] cmd, int cmdLen, out IntPtr resp, out int len);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_channel_transmit_retrieve_response")]
+ internal static extern int ChannelTransmitRetrieveResponse(int channel, out IntPtr name, out int len);
+ [DllImport(Libraries.Smartcard, EntryPoint = "smartcard_channel_select_next")]
+ internal static extern int ChannelSelectNext(int channel, out bool success);
+ }
+ }
+}
diff --git a/Tizen.Smartcard/Properties/AssemblyInfo.cs b/Tizen.Smartcard/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..d19c003
--- /dev/null
+++ b/Tizen.Smartcard/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Tizen.Smartcard")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Tizen.Smartcard")]
+[assembly: AssemblyCopyright("Copyright \u00A9 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("99a90243-7db1-4704-a078-3529c2da4e81")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Tizen.Smartcard/Tizen.Smartcard.Net45.csproj b/Tizen.Smartcard/Tizen.Smartcard.Net45.csproj
new file mode 100644
index 0000000..bd6b371
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard.Net45.csproj
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{BF719F11-CDEA-4D04-A85B-4521A69E3614}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Tizen.Smartcard</RootNamespace>
+ <AssemblyName>Tizen.Smartcard</AssemblyName>
+ <FileAlignment>512</FileAlignment>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\Net45\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\Net45\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup>
+ <SignAssembly>true</SignAssembly>
+ </PropertyGroup>
+ <PropertyGroup>
+ <AssemblyOriginatorKeyFile>Tizen.Smartcard.snk</AssemblyOriginatorKeyFile>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Interop\Interop.Glib.cs" />
+ <Compile Include="Interop\Interop.Libc.cs" />
+ <Compile Include="Interop\Interop.Libraries.cs" />
+ <Compile Include="Interop\Interop.Smartcard.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardChannel.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardErrorFactory.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardManager.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardManagerImpl.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardReader.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardSession.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Tizen.Smartcard.nuspec" />
+ <None Include="Tizen.Smartcard.Net45.project.json" />
+ <None Include="Tizen.Smartcard.snk" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project> \ No newline at end of file
diff --git a/Tizen.Smartcard/Tizen.Smartcard.Net45.project.json b/Tizen.Smartcard/Tizen.Smartcard.Net45.project.json
new file mode 100644
index 0000000..1ec1af2
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard.Net45.project.json
@@ -0,0 +1,11 @@
+{
+ "dependencies": {
+ "Tizen": "1.0.2"
+ },
+ "frameworks": {
+ "net45": {}
+ },
+ "runtimes": {
+ "win": {}
+ }
+}
diff --git a/Tizen.Smartcard/Tizen.Smartcard.csproj b/Tizen.Smartcard/Tizen.Smartcard.csproj
new file mode 100644
index 0000000..b3127c7
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard.csproj
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{3EE5842E-7004-43BC-825B-29FFDEC18D4E}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Tizen.Smartcard</RootNamespace>
+ <AssemblyName>Tizen.Smartcard</AssemblyName>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup>
+ <TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
+ <TargetFrameworkVersion>v1.3</TargetFrameworkVersion>
+ <NuGetTargetMoniker>.NETStandard,Version=v1.3</NuGetTargetMoniker>
+ <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
+ <NoStdLib>true</NoStdLib>
+ <NoWarn>$(NoWarn);1701;1702</NoWarn>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
+ </PropertyGroup>
+ <PropertyGroup>
+ <SignAssembly>true</SignAssembly>
+ </PropertyGroup>
+ <PropertyGroup>
+ <AssemblyOriginatorKeyFile>Tizen.Smartcard.snk</AssemblyOriginatorKeyFile>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="Interop\Interop.Glib.cs" />
+ <Compile Include="Interop\Interop.Libc.cs" />
+ <Compile Include="Interop\Interop.Libraries.cs" />
+ <Compile Include="Interop\Interop.Smartcard.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardChannel.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardErrorFactory.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardManager.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardManagerImpl.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardReader.cs" />
+ <Compile Include="Tizen.Smartcard\SmartcardSession.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Tizen.Smartcard.nuspec" />
+ <None Include="Tizen.Smartcard.project.json" />
+ <None Include="Tizen.Smartcard.snk" />
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath)\Tizen\Tizen.CSharp.GBS.targets" Condition="Exists('$(MSBuildExtensionsPath)\Tizen\Tizen.CSharp.GBS.targets')" />
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+ <PropertyGroup>
+ <!-- https://github.com/dotnet/corefxlab/tree/master/samples/NetCoreSample and
+ https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/target-dotnetcore-with-msbuild
+ -->
+ <!-- We don't use any of MSBuild's resolution logic for resolving the framework, so just set these two
+ properties to any folder that exists to skip the GetReferenceAssemblyPaths task (not target) and
+ to prevent it from outputting a warning (MSB3644).
+ -->
+ <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory)</_TargetFrameworkDirectories>
+ <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>
+ <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
+ </PropertyGroup>
+</Project> \ No newline at end of file
diff --git a/Tizen.Smartcard/Tizen.Smartcard.nuspec b/Tizen.Smartcard/Tizen.Smartcard.nuspec
new file mode 100644
index 0000000..b37f61d
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard.nuspec
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<package>
+ <metadata>
+ <id>Tizen.Smartcard</id>
+ <version>$version$</version>
+ <authors>Samsung Electronics</authors>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
+ <projectUrl>https://www.tizen.org/</projectUrl>
+ <iconUrl>https://developer.tizen.org/sites/default/files/images/tizen-pinwheel-on-light-rgb_64_64.png</iconUrl>
+ <copyright>© Samsung Electronics Co., Ltd All Rights Reserved</copyright>
+ <description>Provides the Smartcard API for Tizen.Net</description>
+ <dependencies>
+ <dependency id="Tizen" version="1.0.2" />
+ </dependencies>
+ </metadata>
+ <files>
+ <file src="bin/$Configuration$/Tizen.Smartcard.dll" target="lib/netstandard1.3" />
+ <file src="bin/$Configuration$/Net45/Tizen.Smartcard.dll" target="lib/net45" />
+ </files>
+</package>
diff --git a/Tizen.Smartcard/Tizen.Smartcard.project.json b/Tizen.Smartcard/Tizen.Smartcard.project.json
new file mode 100644
index 0000000..a4c6be0
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard.project.json
@@ -0,0 +1,9 @@
+{
+ "dependencies": {
+ "NETStandard.Library": "1.6.0",
+ "Tizen": "1.0.2"
+ },
+ "frameworks": {
+ "netstandard1.3": {}
+ }
+} \ No newline at end of file
diff --git a/Tizen.Smartcard/Tizen.Smartcard.snk b/Tizen.Smartcard/Tizen.Smartcard.snk
new file mode 100644
index 0000000..f3d151d
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard.snk
Binary files differ
diff --git a/Tizen.Smartcard/Tizen.Smartcard/SmartcardChannel.cs b/Tizen.Smartcard/Tizen.Smartcard/SmartcardChannel.cs
new file mode 100644
index 0000000..05d6455
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard/SmartcardChannel.cs
@@ -0,0 +1,241 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+using Tizen.Network;
+
+namespace Tizen.Network.Smartcard
+{
+ /// <summary>
+ /// A class for Smartcard channel informations. It allows applications to handle channel informations.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/secureelement</privilege>
+ public class SmartcardChannel : IDisposable
+ {
+ private int _channelHandle = -1;
+ private bool disposed = false;
+ private SmartcardSession _sessionObject;
+
+ /// <summary>
+ /// Whether the kind of channel is basic.
+ /// </summary>
+ public bool IsBasicChannel
+ {
+ get
+ {
+ bool isBasicChannel;
+ int ret = Interop.Smartcard.Channel.ChannelIsBasicChannel(_channelHandle, out isBasicChannel);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get basic channel, Error - " + (SmartcardError)ret);
+ }
+ return isBasicChannel;
+ }
+ }
+
+ /// <summary>
+ /// Whether the kind of channel is logical.
+ /// </summary>
+ public bool IsLogicalChannel
+ {
+ get
+ {
+ bool isBasicChannel;
+ int ret = Interop.Smartcard.Channel.ChannelIsBasicChannel(_channelHandle, out isBasicChannel);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get logical channel, Error - " + (SmartcardError)ret);
+ }
+ return !isBasicChannel;
+ }
+ }
+
+ /// <summary>
+ /// Whether the channel is closed.
+ /// </summary>
+ public bool IsClosed
+ {
+ get
+ {
+ bool isClosed;
+ int ret = Interop.Smartcard.Channel.ChannelIsClosed(_channelHandle, out isClosed);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get closed, Error - " + (SmartcardError)ret);
+ }
+ return isClosed;
+ }
+ }
+
+ /// <summary>
+ /// The session that has opened the given channel.
+ /// </summary>
+ public SmartcardSession Session
+ {
+ get
+ {
+ int session;
+ int ret = Interop.Smartcard.Channel.ChannelGetSession(_channelHandle, out session);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get session, Error - " + (SmartcardError)ret);
+ }
+
+ if (_sessionObject.GetHandle() != session)
+ {
+ Log.Error(Globals.LogTag, "Does not correspond with session, Error - " + _sessionObject.GetHandle() + " " + session);
+ }
+
+ return _sessionObject;
+ }
+ }
+
+ internal SmartcardChannel(SmartcardSession sessionHandle, int channelHandle)
+ {
+ _sessionObject = sessionHandle;
+ _channelHandle = channelHandle;
+ }
+
+ ~SmartcardChannel()
+ {
+ Dispose(false);
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private void Dispose(bool disposing)
+ {
+ if (disposed)
+ return;
+
+ if (disposing)
+ {
+ // Free managed objects.
+ }
+ //Free unmanaged objects
+ disposed = true;
+ }
+
+ /// <summary>
+ /// Closes the given channel to the Secure Element.
+ /// </summary>
+ public void Close()
+ {
+ int ret = Interop.Smartcard.Channel.ChannelClose(_channelHandle);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to channel close, Error - " + (SmartcardError)ret);
+ SmartcardErrorFactory.ThrowSmartcardException(ret);
+ }
+ Dispose(true);
+ }
+
+ /// <summary>
+ /// Gets the response to the select command.
+ /// </summary>
+ /// <returns>Byte array to retrieve the SELECT response.</returns>
+ public byte[] GetSelectedResponse()
+ {
+ byte[] respList;
+ IntPtr strAtr;
+ int len;
+ int ret = Interop.Smartcard.Channel.ChannelGetSelectResponse(_channelHandle, out strAtr, out len);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get select response, Error - " + (SmartcardError)ret);
+ }
+
+ respList = new byte[len];
+ for (int i = 0; i < len; i++)
+ {
+ respList[i] = Marshal.ReadByte(strAtr);
+ strAtr += sizeof(byte);
+ }
+ return respList;
+ }
+
+ /// <summary>
+ /// Transmits an APDU command (as per ISO/IEC 7816-4) to the Secure Element.
+ /// </summary>
+ /// <returns>Byte array for the response APDU plus status words.</returns>
+ /// <param name="cmd">Command APDU to be send to the secure element.</param>
+ public byte[] Transmit(byte[] cmd)
+ {
+ byte[] atrList;
+ IntPtr strAtr;
+ int len;
+ int ret = Interop.Smartcard.Channel.ChannelTransmit(_channelHandle, cmd, cmd.Length, out strAtr, out len);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to transmit, Error - " + (SmartcardError)ret);
+ }
+
+ atrList = new byte[len];
+ for (int i = 0; i < len; i++)
+ {
+ atrList[i] = Marshal.ReadByte(strAtr);
+ strAtr += sizeof(byte);
+ }
+
+ return atrList;
+ }
+
+ /// <summary>
+ /// Helper function to retrieves the response APDU of the previous transmit() call.
+ /// </summary>
+ /// <returns>Byte array for the response APDU plus status words.</returns>
+ public byte[] GetTransmittedResponse()
+ {
+ byte[] respList;
+ IntPtr strAtr;
+ int len;
+ int ret = Interop.Smartcard.Channel.ChannelTransmitRetrieveResponse(_channelHandle, out strAtr, out len);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get trasmit retrieve response, Error - " + (SmartcardError)ret);
+ }
+
+ respList = new byte[len];
+ for (int i = 0; i < len; i++)
+ {
+ respList[i] = Marshal.ReadByte(strAtr);
+ strAtr += sizeof(byte);
+ }
+ return respList;
+ }
+
+ /// <summary>
+ /// Performs a selection of the next Applet on the given channel that matches to the partial Application ID(AID).
+ /// </summary>
+ /// <returns>True or false depending whether another applet with the partial Application ID(AID).</returns>
+ public bool SelectNext()
+ {
+ bool selectNext;
+ int ret = Interop.Smartcard.Channel.ChannelSelectNext(_channelHandle, out selectNext);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to select next, Error - " + (SmartcardError)ret);
+ }
+ return selectNext;
+ }
+ }
+}
diff --git a/Tizen.Smartcard/Tizen.Smartcard/SmartcardErrorFactory.cs b/Tizen.Smartcard/Tizen.Smartcard/SmartcardErrorFactory.cs
new file mode 100644
index 0000000..70fafb9
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard/SmartcardErrorFactory.cs
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using Tizen.Internals.Errors;
+
+namespace Tizen.Network.Smartcard
+{
+ internal enum SmartcardError
+ {
+ None = ErrorCode.None,
+ IoError = ErrorCode.IoError,
+ InvalidParameterError = ErrorCode.InvalidParameter,
+ PermissionDeniedError = ErrorCode.PermissionDenied,
+ NotSupportedError = ErrorCode.NotSupported,
+ GeneralError = -0x01C70000 | 0x01,
+ NoSuchElementError = -0x01C70000 | 0x02,
+ IllegalStateError = -0x01C70000 | 0x03,
+ IllegalReferenceError = -0x01C70000 | 0x04,
+ OperationNotSupportError = -0x01C70000 | 0x05,
+ ChannelNotAvailableError = -0x01C70000 | 0x06,
+ NotInitializedError = -0x01C70000 | 0x07
+ }
+
+ internal static class SmartcardErrorFactory
+ {
+ static internal void ThrowSmartcardException(int e)
+ {
+ ThrowException(e, false);
+ }
+
+ static internal void ThrowSmartcardException(int e, int handle)
+ {
+ ThrowException(e, (handle < 0));
+ }
+
+ static private void ThrowException(int e, bool isHandleNull)
+ {
+ SmartcardError err = (SmartcardError)e;
+
+ if (isHandleNull)
+ {
+ throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
+ }
+
+ if (err == SmartcardError.InvalidParameterError)
+ {
+ throw new ArgumentException(err.ToString());
+ }
+ else
+ {
+ throw new InvalidOperationException(err.ToString());
+ }
+ }
+
+ }
+}
diff --git a/Tizen.Smartcard/Tizen.Smartcard/SmartcardManager.cs b/Tizen.Smartcard/Tizen.Smartcard/SmartcardManager.cs
new file mode 100644
index 0000000..b5d1903
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard/SmartcardManager.cs
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace Tizen.Network.Smartcard
+{
+ /// <summary>
+ /// A class for Smartcard management. It allows applications to use Smartcard service.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/secureelement</privilege>
+ static public class SmartcardManager
+ {
+ /// <summary>
+ /// Gets the list of available Secure Element readers.
+ /// </summary>
+ /// <returns>List of SmartcardReader objects.</returns>
+ static public IEnumerable<SmartcardReader> GetReaders()
+ {
+ return SmartcardManagerImpl.Instance.GetReaders();
+ }
+ }
+}
diff --git a/Tizen.Smartcard/Tizen.Smartcard/SmartcardManagerImpl.cs b/Tizen.Smartcard/Tizen.Smartcard/SmartcardManagerImpl.cs
new file mode 100644
index 0000000..e7a0f9c
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard/SmartcardManagerImpl.cs
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using System.Threading.Tasks;
+
+namespace Tizen.Network.Smartcard
+{
+ static internal class Globals
+ {
+ internal const string LogTag = "Tizen.Network.Smartcard";
+ }
+
+ internal class SmartcardManagerImpl : IDisposable
+ {
+ private static readonly SmartcardManagerImpl _instance = new SmartcardManagerImpl();
+ private List<SmartcardReader> _readerList = new List<SmartcardReader>();
+ private bool disposed = false;
+
+ internal static SmartcardManagerImpl Instance
+ {
+ get
+ {
+ return _instance;
+ }
+ }
+
+ private SmartcardManagerImpl()
+ {
+ initialize();
+ }
+
+ ~SmartcardManagerImpl()
+ {
+ Dispose(false);
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private void Dispose(bool disposing)
+ {
+ if (disposed)
+ return;
+
+ if (disposing)
+ {
+ // Free managed objects.
+ foreach (SmartcardReader reader in _readerList)
+ {
+ reader.Dispose();
+ _readerList.Remove(reader);
+ }
+ }
+ //Free unmanaged objects
+ deinitialize();
+ disposed = true;
+ }
+
+ private void initialize()
+ {
+ int ret = Interop.Smartcard.Initialize();
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to initialize smartcard, Error - " + (SmartcardError)ret);
+ SmartcardErrorFactory.ThrowSmartcardException(ret);
+ }
+ }
+
+ private void deinitialize()
+ {
+ int ret = Interop.Smartcard.Deinitialize();
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to deinitialize smartcard, Error - " + (SmartcardError)ret);
+ SmartcardErrorFactory.ThrowSmartcardException(ret);
+ }
+ }
+
+ internal IEnumerable<SmartcardReader> GetReaders()
+ {
+ IntPtr readerPtr;
+ int len = 0;
+
+ int ret = Interop.Smartcard.GetReaders(out readerPtr, out len);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to remove with AP, Error - " + (SmartcardError)ret);
+ SmartcardErrorFactory.ThrowSmartcardException(ret);
+ }
+
+ for (int i = 0; i < len; i++)
+ {
+ int readerID = Marshal.ReadInt32(readerPtr);
+
+ SmartcardReader readerItem = new SmartcardReader(readerID);
+ _readerList.Add(readerItem);
+ readerPtr += sizeof(int);
+ }
+
+ return _readerList;
+ }
+ }
+}
diff --git a/Tizen.Smartcard/Tizen.Smartcard/SmartcardReader.cs b/Tizen.Smartcard/Tizen.Smartcard/SmartcardReader.cs
new file mode 100644
index 0000000..5c0f542
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard/SmartcardReader.cs
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+using Tizen.Network;
+
+namespace Tizen.Network.Smartcard
+{
+ /// <summary>
+ /// A class for Smartcard reader informations. It allows applications to handle reader informations.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/secureelement</privilege>
+ public class SmartcardReader : IDisposable
+ {
+ private int _readerHandle = -1;
+ private int _session;
+ private bool disposed = false;
+ private List<SmartcardSession> _sessionList = new List<SmartcardSession>();
+
+ /// <summary>
+ /// The name of reader.
+ /// </summary>
+ public string Name
+ {
+ get
+ {
+ IntPtr strPtr;
+ int ret = Interop.Smartcard.Reader.ReaderGetName(_readerHandle, out strPtr);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get reader name, Error - " + (SmartcardError)ret);
+ return "";
+ }
+ return Marshal.PtrToStringAnsi(strPtr);
+ }
+ }
+
+ /// <summary>
+ /// The existence of secure element.
+ /// </summary>
+ public bool IsSecureElementPresent
+ {
+ get
+ {
+ bool isPresent;
+ int ret = Interop.Smartcard.Reader.ReaderIsSecureElementPresent(_readerHandle, out isPresent);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get present, Error - " + (SmartcardError)ret);
+ }
+ return isPresent;
+ }
+ }
+
+ internal SmartcardReader(int handle)
+ {
+ _readerHandle = handle;
+ }
+
+ ~SmartcardReader()
+ {
+ Dispose(false);
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private void Dispose(bool disposing)
+ {
+ if (disposed)
+ return;
+
+ if (disposing)
+ {
+ // Free managed objects.
+ foreach (SmartcardSession session in _sessionList)
+ {
+ session.Dispose();
+ _sessionList.Remove(session);
+ }
+ }
+ //Free unmanaged objects
+ disposed = true;
+ }
+
+ internal int GetHandle()
+ {
+ return _readerHandle;
+ }
+
+ internal int GetSession()
+ {
+ return _session;
+ }
+
+ /// <summary>
+ /// Connects to a Secure Element in the given reader.
+ /// </summary>
+ /// <returns>The SmartcardSession object.</returns>
+ public SmartcardSession OpenSession()
+ {
+ int ret = Interop.Smartcard.Reader.ReaderOpenSession(_readerHandle, out _session);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get session handle, Error - " + (SmartcardError)ret);
+ }
+
+ SmartcardSession session = new SmartcardSession(this, _session);
+ _sessionList.Add(session);
+ return session;
+ }
+
+ /// <summary>
+ /// Closes all the sessions opened on the given reader.
+ /// </summary>
+ public void CloseSessions()
+ {
+ int ret = Interop.Smartcard.Reader.ReaderCloseSessions(_readerHandle);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to close sessions, Error - " + (SmartcardError)ret);
+ SmartcardErrorFactory.ThrowSmartcardException(ret);
+ }
+
+ foreach (SmartcardSession session in _sessionList)
+ {
+ session.Dispose();
+ _sessionList.Remove(session);
+ }
+ }
+ }
+}
diff --git a/Tizen.Smartcard/Tizen.Smartcard/SmartcardSession.cs b/Tizen.Smartcard/Tizen.Smartcard/SmartcardSession.cs
new file mode 100644
index 0000000..a6a4f3a
--- /dev/null
+++ b/Tizen.Smartcard/Tizen.Smartcard/SmartcardSession.cs
@@ -0,0 +1,229 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+using System.Collections.Generic;
+using Tizen.Network;
+
+namespace Tizen.Network.Smartcard
+{
+ /// <summary>
+ /// A class for Smartcard session informations. It allows applications to handle session informations.
+ /// </summary>
+ /// <privilege>http://tizen.org/privilege/secureelement</privilege>
+ public class SmartcardSession : IDisposable
+ {
+ private int _sessionHandle = -1;
+ private bool disposed = false;
+ private List<SmartcardChannel> _basicChannelList = new List<SmartcardChannel>();
+ private List<SmartcardChannel> _logicalChannelList = new List<SmartcardChannel>();
+ private SmartcardReader _readerObject;
+ private int _basicChannel = 0;
+ private int _logicalChannel = 0;
+
+ /// <summary>
+ /// The reader object that provides the given session.
+ /// </summary>
+ public SmartcardReader Reader
+ {
+ get
+ {
+ int reader;
+ int ret = Interop.Smartcard.Session.SessionGetReader(_sessionHandle, out reader);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get reader, Error - " + (SmartcardError)ret);
+ }
+
+ if (_readerObject.GetHandle() != reader)
+ {
+ Log.Error(Globals.LogTag, "Does not correspond with reader, Error - " + _readerObject.GetHandle() + " " + reader);
+ }
+
+ return _readerObject;
+ }
+ }
+
+ /// <summary>
+ /// The Answer to Reset(ATR) of this Secure Element.
+ /// </summary>
+ public byte[] Atr
+ {
+ get
+ {
+ byte[] atrList;
+ IntPtr strAtr;
+ int len;
+ int ret = Interop.Smartcard.Session.SessionGetAtr(_sessionHandle, out strAtr, out len);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get atr, Error - " + (SmartcardError)ret);
+ }
+
+ atrList = new byte[len];
+ for (int i = 0; i < len; i++)
+ {
+ atrList[i] = Marshal.ReadByte(strAtr);
+ strAtr += sizeof(byte);
+ }
+ return atrList;
+ }
+ }
+
+ /// <summary>
+ /// Whether the session is closed.
+ /// </summary>
+ public bool IsClosed
+ {
+ get
+ {
+ bool isClosed;
+ int ret = Interop.Smartcard.Session.SessionIsClosed(_sessionHandle, out isClosed);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to get present, Error - " + (SmartcardError)ret);
+ }
+ return isClosed;
+ }
+ }
+
+ internal SmartcardSession(SmartcardReader readerHandle, int sessionHandle)
+ {
+ _readerObject = readerHandle;
+ _sessionHandle = sessionHandle;
+ }
+
+ ~SmartcardSession()
+ {
+ Dispose(false);
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ private void Dispose(bool disposing)
+ {
+ if (disposed)
+ return;
+
+ if (disposing)
+ {
+ // Free managed objects.
+ foreach (SmartcardChannel channel in _basicChannelList)
+ {
+ channel.Dispose();
+ _basicChannelList.Remove(channel);
+ }
+
+ foreach (SmartcardChannel channel in _logicalChannelList)
+ {
+ channel.Dispose();
+ _logicalChannelList.Remove(channel);
+ }
+ }
+ //Free unmanaged objects
+ disposed = true;
+ }
+
+ internal int GetHandle()
+ {
+ return _sessionHandle;
+ }
+
+ /// <summary>
+ /// Closes the connection with the Secure Element.
+ /// </summary>
+ public void Close()
+ {
+ int ret = Interop.Smartcard.Session.SessionClose(_sessionHandle);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to close, Error - " + (SmartcardError)ret);
+ SmartcardErrorFactory.ThrowSmartcardException(ret);
+ }
+ Dispose(true);
+ }
+
+ /// <summary>
+ /// Closes any channel opened on the given session.
+ /// </summary>
+ public void CloseChannels()
+ {
+ int ret = Interop.Smartcard.Session.SessionCloseChannels(_sessionHandle);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to close, Error - " + (SmartcardError)ret);
+ SmartcardErrorFactory.ThrowSmartcardException(ret);
+ }
+
+ foreach (SmartcardChannel channel in _basicChannelList)
+ {
+ channel.Dispose();
+ _basicChannelList.Remove(channel);
+ }
+
+ foreach (SmartcardChannel channel in _logicalChannelList)
+ {
+ channel.Dispose();
+ _logicalChannelList.Remove(channel);
+ }
+ }
+
+ /// <summary>
+ /// Gets an access to the basic channel, as defined in the ISO/IEC 7816-4 specification (the one that has number 0).
+ /// </summary>
+ /// <returns>The SmartcardChannel object for basic channel.</returns>
+ /// <param name="aid">Byte array containing the Application ID(AID) to be selected on the given channel.</param>
+ /// <param name="p2">P2 byte of the SELECT command if executed.</param>
+ public SmartcardChannel OpenBasicChannel(byte[] aid, byte p2)
+ {
+ int ret = Interop.Smartcard.Session.SessionOpenBasicChannel(_sessionHandle, aid, aid.Length, p2, out _basicChannel);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to open basic channel, Error - " + (SmartcardError)ret);
+ SmartcardErrorFactory.ThrowSmartcardException(ret);
+ }
+ SmartcardChannel basicChannel = new SmartcardChannel(this, _basicChannel);
+ _basicChannelList.Add(basicChannel);
+
+ return basicChannel;
+ }
+
+ /// <summary>
+ /// Open a logical channel with the Secure Element, selecting the Applet represented by the given Application ID(AID).
+ /// </summary>
+ /// <returns>The SmartcardChannel object for logical channel.</returns>
+ /// <param name="aid">Byte array containing the Application ID(AID) to be selected on the given channel.</param>
+ /// <param name="p2">P2 byte of the SELECT command if executed.</param>
+ public SmartcardChannel OpenLogicalChannel(byte[] aid, byte p2)
+ {
+ int ret = Interop.Smartcard.Session.SessionOpenLogicalChannel(_sessionHandle, aid, aid.Length, p2, out _logicalChannel);
+ if (ret != (int)SmartcardError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to open logical channel, Error - " + (SmartcardError)ret);
+ SmartcardErrorFactory.ThrowSmartcardException(ret);
+ }
+ SmartcardChannel logicalChannel = new SmartcardChannel(this, _logicalChannel);
+ _logicalChannelList.Add(logicalChannel);
+
+ return logicalChannel;
+ }
+ }
+}
diff --git a/packaging/csapi-smartcard.manifest b/packaging/csapi-smartcard.manifest
new file mode 100644
index 0000000..75b0fa5
--- /dev/null
+++ b/packaging/csapi-smartcard.manifest
@@ -0,0 +1,5 @@
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
diff --git a/packaging/csapi-smartcard.spec b/packaging/csapi-smartcard.spec
new file mode 100644
index 0000000..b1c2e0b
--- /dev/null
+++ b/packaging/csapi-smartcard.spec
@@ -0,0 +1,76 @@
+%{!?dotnet_assembly_path: %define dotnet_assembly_path /opt/usr/share/dotnet.tizen/framework}
+
+%if 0%{?tizen_build_devel_mode}
+%define BUILDCONF Debug
+%else
+%define BUILDCONF Release
+%endif
+
+Name: csapi-smartcard
+Summary: Tizen Smartcard API for C#
+Version: 1.0.2
+Release: 1
+Group: Development/Libraries
+License: Apache-2.0
+URL: https://www.tizen.org
+Source0: %{name}-%{version}.tar.gz
+Source1: %{name}.manifest
+
+AutoReqProv: no
+ExcludeArch: %{ix86} aarch64
+
+BuildRequires: mono-compiler
+BuildRequires: mono-devel
+
+BuildRequires: dotnet-build-tools
+
+# C# API Requries
+BuildRequires: csapi-tizen-nuget
+
+%description
+Tizen Smartcard API for C#
+
+%prep
+%setup -q
+cp %{SOURCE1} .
+
+%define Assemblies Tizen.Smartcard
+
+%build
+for ASM in %{Assemblies}; do
+# NuGet Restore
+find $ASM/*.project.json -exec nuget restore {} \;
+# Build
+find $ASM/*.csproj -exec xbuild {} /p:Configuration=%{BUILDCONF} \;
+# NuGet Pack
+nuget pack $ASM/$ASM.nuspec -Version %{version} -Properties Configuration=%{BUILDCONF}
+done
+
+%install
+# Runtime Binary
+mkdir -p %{buildroot}%{dotnet_assembly_path}
+for ASM in %{Assemblies}; do
+%if 0%{?_with_corefx}
+ install -p -m 644 $ASM/bin/%{BUILDCONF}/$ASM.dll %{buildroot}%{dotnet_assembly_path}
+%else
+ install -p -m 644 $ASM/bin/%{BUILDCONF}/Net45/$ASM.dll %{buildroot}%{dotnet_assembly_path}
+%endif
+done
+# NuGet
+mkdir -p %{buildroot}/nuget
+install -p -m 644 *.nupkg %{buildroot}/nuget
+
+%files
+%manifest %{name}.manifest
+%license LICENSE
+%attr(644,root,root) %{dotnet_assembly_path}/*.dll
+
+%package nuget
+Summary: NuGet package for %{name}
+Group: Development/Libraries
+
+%description nuget
+NuGet package for %{name}
+
+%files nuget
+/nuget/*.nupkg