Exemplo n.º 1
0
        internal IEnumerable <SmartcardReader> GetReaders()
        {
            IntPtr readerPtr;
            int    len = 0;
            List <SmartcardReader> readerList = new List <SmartcardReader>();

            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);
            }

            IntPtr tempPtr = readerPtr;

            for (int i = 0; i < len; i++)
            {
                int readerID = Marshal.ReadInt32(tempPtr);

                SmartcardReader readerItem = new SmartcardReader(readerID);
                readerList.Add(readerItem);
                tempPtr += sizeof(int);
            }

            if (len > 0)
            {
                Interop.Libc.Free(readerPtr);
            }

            return(readerList);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Closes the connection with the secure element.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <exception cref="NotSupportedException">Thrown when the Smartcard is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
        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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Closes all the sessions opened on the given reader.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <exception cref="NotSupportedException">Thrown when the Smartcard is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
        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.Close();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Open a logical channel with the secure element, selecting the Applet represented by the given application ID (AID).
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <returns>The SmartcardChannel object for the logical channel.</returns>
        /// <param name="aid">The 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>
        /// <exception cref="NotSupportedException">Thrown when the Smartcard is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
        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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets an access to the basic channel, as defined in the ISO/IEC 7816-4 specification (the one that has number 0).
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <returns>The SmartcardChannel object for the basic channel.</returns>
        /// <param name="aid">The 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>
        /// <exception cref="NotSupportedException">Thrown when the Smartcard is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
        public SmartcardChannel OpenBasicChannel(byte[] aid, byte p2)
        {
            int aidLen = (aid == null ? 0 : aid.Length);
            int ret    = Interop.Smartcard.Session.SessionOpenBasicChannel(_sessionHandle, aid, aidLen, 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);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Closes any channel opened on the given session.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <exception cref="NotSupportedException">Thrown when the Smartcard is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
        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.Close();
            }

            foreach (SmartcardChannel channel in _logicalChannelList)
            {
                channel.Close();
            }
        }