Exemplo n.º 1
0
        /// <inheritdoc />
        public ErrorCode SCardStatus(IntPtr card, ref State status, ref Protocol protocol)
        {
            ErrorCode ret;

            unsafe
            {
                var   ustatus        = (ulong)status;
                var   uprotocol      = (ulong)protocol;
                ulong readerNameSize = 0;
                ulong atrSize        = 0;
                ret      = UnsafePrimitives.SCardStatus((void *)card, null, &readerNameSize, &ustatus, &uprotocol, null, &atrSize);
                status   = (State)ustatus;
                protocol = (Protocol)uprotocol;
            }

            return(ret);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public ErrorCode SCardStatus(IntPtr card, ref IntPtr readerName, ref uint readerNameSize, ref State status, ref Protocol protocol, ref IntPtr atr, ref uint atrSize)
        {
            ErrorCode ret;

            ulong ulreaderNameSize = readerNameSize;
            ulong ulatrSize        = atrSize;

            unsafe
            {
                var ustatus   = (ulong)status;
                var uprotocol = (ulong)protocol;
                fixed(uint *preaderNameSize = &readerNameSize)
                {
                    fixed(uint *patrSize = &atrSize)
                    {
                        if (readerNameSize != AutoAllocate && atrSize != AutoAllocate)
                        {
                            ret = UnsafePrimitives.SCardStatus(
                                (void *)card,
                                (char *)readerName,
                                &ulreaderNameSize,
                                &ustatus,
                                &uprotocol,
                                (byte *)atr,
                                &ulatrSize
                                );
                        }
                        else
                        {
                            //TODO
                            throw new NotImplementedException();
                        }
                        status         = (State)ustatus;
                        protocol       = (Protocol)uprotocol;
                        readerNameSize = *preaderNameSize;
                        atrSize        = *patrSize;
                    }
                }
            }

            readerNameSize = (uint)ulreaderNameSize;
            atrSize        = (uint)ulatrSize;

            return(ret);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public ErrorCode SCardStatus(IntPtr card, ref string readerName, ref State state, ref Protocol protocol, ref byte[] atr)
        {
            var   atrPtr          = IntPtr.Zero;
            ulong zReaderNameSize = AutoAllocate;
            var   zReaderNamePtr  = new IntPtr();
            ulong atrSize         = AutoAllocate;
            var   ret             = UnsafePrimitives.SCardStatus(
                card,
                ref zReaderNamePtr,
                ref zReaderNameSize,
                ref state,
                ref protocol,
                ref atrPtr,
                ref atrSize
                );

            if (zReaderNamePtr == IntPtr.Zero)
            {
                readerName = "";
            }
            else
            {
                var readerStr = Marshal.PtrToStringAuto(zReaderNamePtr, (int)zReaderNameSize - 2);
                readerName = readerStr.Split('\0')[0];
            }
            if (atrPtr == IntPtr.Zero)
            {
                atr = new byte[0];
            }
            else
            {
                atr = new byte[atrSize];
                Marshal.Copy(atrPtr, atr, 0, (int)atrSize);
            }
            return(ret);
        }