예제 #1
0
        public SCardError ListReaderGroups(IntPtr hContext, out string[] groups)
        {
            var dwGroups = 0;

            // determine the needed buffer size
            var rc = SCardHelper.ToSCardError(
                SCardListReaderGroups(
                    hContext,
                    null,
                    ref dwGroups));

            if (rc != SCardError.Success)
            {
                groups = null;
                return(rc);
            }

            // initialize array
            var mszGroups = new byte[dwGroups * sizeof(char)];

            rc = SCardHelper.ToSCardError(
                SCardListReaderGroups(
                    hContext,
                    mszGroups,
                    ref dwGroups));

            groups = (rc == SCardError.Success)
                ? SCardHelper.ConvertToStringArray(mszGroups, TextEncoding)
                : null;

            return(rc);
        }
예제 #2
0
        public SCardError ListReaderGroups(IntPtr hContext, out string[] groups)
        {
            var dwGroups = IntPtr.Zero;

            // determine the needed buffer size
            var rc = SCardHelper.ToSCardError(
                UnixNativeMethods.SCardListReaderGroups(
                    hContext,
                    null,
                    ref dwGroups));

            if (rc != SCardError.Success)
            {
                groups = null;
                return(rc);
            }

            // initialize array for returning group names
            var mszGroups = new byte[(int)dwGroups];

            rc = SCardHelper.ToSCardError(
                UnixNativeMethods.SCardListReaderGroups(
                    hContext,
                    mszGroups,
                    ref dwGroups));

            groups = (rc == SCardError.Success)
                ? SCardHelper.ConvertToStringArray(mszGroups, TextEncoding)
                : null;

            return(rc);
        }
        public SCardError ListReaders(IntPtr hContext, string[] groups, out string[] readers)
        {
            var dwReaders = 0;

            // initialize groups array
            byte[] mszGroups = null;
            if (groups != null)
            {
                mszGroups = SCardHelper.ConvertToByteArray(groups, TextEncoding);
            }

            // determine the needed buffer size

            var ctx = hContext.ToInt32();
            var rc  = SCardHelper.ToSCardError(
                MacOsxNativeMethods.SCardListReaders(
                    ctx,
                    mszGroups,
                    null,
                    ref dwReaders));

            if (rc != SCardError.Success)
            {
                readers = null;
                return(rc);
            }

            // initialize array for returning reader names
            var mszReaders = new byte[(int)dwReaders];

            rc = SCardHelper.ToSCardError(
                MacOsxNativeMethods.SCardListReaders(
                    ctx,
                    mszGroups,
                    mszReaders,
                    ref dwReaders));

            readers = (rc == SCardError.Success)
                ? SCardHelper.ConvertToStringArray(mszReaders, TextEncoding)
                : null;

            return(rc);
        }
예제 #4
0
        public SCardError ListReaders(IntPtr hContext, string[] groups, out string[] readers)
        {
            var dwReaders = 0;

            // initialize groups array
            byte[] mszGroups = null;
            if (groups != null)
            {
                mszGroups = SCardHelper.ConvertToByteArray(groups, _textEncoding);
            }

            // determine the needed buffer size
            var rc = SCardHelper.ToSCardError(
                SCardListReaders(hContext,
                                 mszGroups,
                                 null,
                                 ref dwReaders));

            if (rc != SCardError.Success)
            {
                readers = null;
                return(rc);
            }

            // initialize array
            byte[] mszReaders = new byte[dwReaders * sizeof(char)];

            rc = SCardHelper.ToSCardError(
                SCardListReaders(hContext,
                                 mszGroups,
                                 mszReaders,
                                 ref dwReaders));

            readers = (rc == SCardError.Success)
                ? SCardHelper.ConvertToStringArray(mszReaders, _textEncoding)
                : null;

            return(rc);
        }
예제 #5
0
        public SCardError Status(IntPtr hCard, out string[] szReaderName, out IntPtr pdwState, out IntPtr pdwProtocol, out byte[] pbAtr)
        {
            var readerName     = new byte[MAX_READER_NAME * CharSize];
            var readerNameSize = MAX_READER_NAME;

            pbAtr = new byte[MAX_ATR_SIZE];
            var atrlen = pbAtr.Length;

            int state, proto;

            var rc = SCardHelper.ToSCardError(SCardStatus(
                                                  hCard,
                                                  readerName,
                                                  ref readerNameSize,
                                                  out state,
                                                  out proto,
                                                  pbAtr,
                                                  ref atrlen));

            if (rc == SCardError.InsufficientBuffer || (MAX_READER_NAME < readerNameSize) || (pbAtr.Length < atrlen))
            {
                // second try

                if (MAX_READER_NAME < readerNameSize)
                {
                    // readername byte array was too short
                    readerName = new byte[readerNameSize * CharSize];
                }

                if (pbAtr.Length < atrlen)
                {
                    // ATR byte array was too short
                    pbAtr = new byte[atrlen];
                }

                rc = SCardHelper.ToSCardError(SCardStatus(
                                                  hCard,
                                                  readerName,
                                                  ref readerNameSize,
                                                  out state,
                                                  out proto,
                                                  pbAtr,
                                                  ref atrlen));
            }

            pdwProtocol = (IntPtr)proto;

            if (rc == SCardError.Success)
            {
                pdwState = (IntPtr)state.ConvertToSCardState();
                if (atrlen < pbAtr.Length)
                {
                    Array.Resize(ref pbAtr, atrlen);
                }

                if (readerNameSize < (readerName.Length / CharSize))
                {
                    Array.Resize(ref readerName, readerNameSize * CharSize);
                }

                szReaderName = SCardHelper.ConvertToStringArray(readerName, TextEncoding);
            }
            else
            {
                pdwState     = (IntPtr)SCardState.Unknown;
                szReaderName = null;
            }

            return(rc);
        }
예제 #6
0
        public SCardError Status(IntPtr hCard, out string[] szReaderName, out IntPtr pdwState, out IntPtr pdwProtocol,
                                 out byte[] pbAtr)
        {
            var readerName     = new byte[MAX_READER_NAME * CharSize];
            var readerNameSize = (IntPtr)MAX_READER_NAME;

            pbAtr = new byte[MAX_ATR_SIZE];
            var atrlen = (IntPtr)pbAtr.Length;
            var rc     = SCardHelper.ToSCardError(UnixNativeMethods.SCardStatus(
                                                      hCard,
                                                      readerName,
                                                      ref readerNameSize,
                                                      out var state,
                                                      out var proto,
                                                      pbAtr,
                                                      ref atrlen));

            if (rc == SCardError.InsufficientBuffer || (MAX_READER_NAME < ((int)readerNameSize)) ||
                (pbAtr.Length < (int)atrlen))
            {
                // second try

                if (MAX_READER_NAME < ((int)readerNameSize))
                {
                    // readername byte array was too short
                    readerName = new byte[(int)readerNameSize * CharSize];
                }

                if (pbAtr.Length < (int)atrlen)
                {
                    // ATR byte array was too short
                    pbAtr = new byte[(int)atrlen];
                }

                rc = SCardHelper.ToSCardError(UnixNativeMethods.SCardStatus(
                                                  hCard,
                                                  readerName,
                                                  ref readerNameSize,
                                                  out state,
                                                  out proto,
                                                  pbAtr,
                                                  ref atrlen));
            }

            pdwState    = state;
            pdwProtocol = proto;

            if (rc == SCardError.Success)
            {
                state = state.Mask(STATUS_MASK);
                if ((int)atrlen < pbAtr.Length)
                {
                    Array.Resize(ref pbAtr, (int)atrlen);
                }

                if (((int)readerNameSize) < (readerName.Length / CharSize))
                {
                    Array.Resize(ref readerName, (int)readerNameSize * CharSize);
                }

                szReaderName = SCardHelper.ConvertToStringArray(readerName, TextEncoding);
            }
            else
            {
                szReaderName = null;
            }

            return(rc);
        }