예제 #1
0
 void print(IntPtr sdkContext, BS2CardConfig cardConfig)
 {
     Console.WriteLine(">>>> Card configuration formatID[{0}]", cardConfig.formatID);
     Console.WriteLine("     |--byteOrder[{0}]", (BS2CardByteOrderEnum)cardConfig.byteOrder);
     Console.WriteLine("     |--useWiegandFormat[{0}]", Convert.ToBoolean(cardConfig.useWiegandFormat));
     Console.WriteLine("     |--dataType[{0}]", (BS2CardDataTypeEnum)cardConfig.dataType);
     Console.WriteLine("     |--useSecondaryKey[{0}]", Convert.ToBoolean(cardConfig.useSecondaryKey));
     Console.WriteLine("     |--mifare");
     Console.WriteLine("     |  |--primaryKey[{0}]", BitConverter.ToString(cardConfig.mifare.primaryKey));
     Console.WriteLine("     |  |--secondaryKey[{0}]", BitConverter.ToString(cardConfig.mifare.secondaryKey));
     Console.WriteLine("     |  |--startBlockIndex[{0}]", cardConfig.mifare.startBlockIndex);
     Console.WriteLine("     |--iclass");
     Console.WriteLine("     |  |--primaryKey[{0}]", BitConverter.ToString(cardConfig.iclass.primaryKey));
     Console.WriteLine("     |  |--secondaryKey[{0}]", BitConverter.ToString(cardConfig.iclass.secondaryKey));
     Console.WriteLine("     |  |--startBlockIndex[{0}]", cardConfig.iclass.startBlockIndex);
     Console.WriteLine("     |--desfire");
     Console.WriteLine("     |  |--primaryKey[{0}]", BitConverter.ToString(cardConfig.desfire.primaryKey));
     Console.WriteLine("     |  |--secondaryKey[{0}]", BitConverter.ToString(cardConfig.desfire.secondaryKey));
     Console.WriteLine("     |  |--appID[{0}]", BitConverter.ToString(cardConfig.desfire.appID));
     Console.WriteLine("     |  |--fileID[{0}]", cardConfig.desfire.fileID);
     Console.WriteLine("     |  |--encryptionType[{0}]", cardConfig.desfire.encryptionType);
 }
예제 #2
0
        public void setCardConfig(IntPtr sdkContext, UInt32 deviceID, bool isMasterDevice)
        {
            BS2FactoryConfig factoryConfig;

            Console.WriteLine("Trying to get factory config");
            BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetFactoryConfig(sdkContext, deviceID, out factoryConfig);

            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
                return;
            }

            UInt16 cardModel = 0;
            IntPtr ptrModel  = Marshal.StringToHGlobalAnsi(Encoding.UTF8.GetString(factoryConfig.modelName).TrimEnd('\0'));

            result = (BS2ErrorCode)API.BS2_GetCardModel(ptrModel, out cardModel);
            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
                return;
            }

            BS2CardConfig cardConfig = Util.AllocateStructure <BS2CardConfig>();

            Console.WriteLine("Choose byte order: [0: MSB(default), 1: LSB]");
            Console.Write(">>>> ");
            cardConfig.byteOrder = Util.GetInput((byte)BS2CardByteOrderEnum.MSB);
            Console.WriteLine("Do you want to use wiegand format? [y/N]");
            Console.Write(">>>> ");
            if (Util.IsNo())
            {
                cardConfig.useWiegandFormat = 0;
            }
            else
            {
                cardConfig.useWiegandFormat = 1;
            }

            BS2CardModelEnum cardModelEnum = (BS2CardModelEnum)cardModel;

            if (cardModelEnum == BS2CardModelEnum.OMPW || cardModelEnum == BS2CardModelEnum.OIPW)
            {
                Console.WriteLine("Enter the card format id [0(default)]");
                Console.Write(">>>> ");
                cardConfig.formatID = Util.GetInput((UInt32)0);

                Console.WriteLine("Choose card data type: [0: Binary(default), 1: ASCII, 2: UTF16, 3: BCD]");
                Console.Write(">>>> ");
                cardConfig.dataType = Util.GetInput((byte)BS2CardDataTypeEnum.BINARY);
                Console.WriteLine("Do you want to use secondary key? [y/N]");
                Console.Write(">>>> ");
                if (Util.IsNo())
                {
                    cardConfig.useSecondaryKey = 0;
                }
                else
                {
                    cardConfig.useSecondaryKey = 1;
                }

                if (cardModelEnum == BS2CardModelEnum.OMPW) // mifare card
                {
                    Console.WriteLine("Enter the start block index for mifare card [0(default)]");
                    Console.Write(">>>> ");
                    cardConfig.mifare.startBlockIndex = Util.GetInput((UInt16)0);
                    Console.WriteLine("Enter the hexadecimal primary key for mifare card. [KEY1-KEY2-...-KEY6]");
                    Console.Write(">>>> ");
                    enterSmartcardKey(cardConfig.mifare.primaryKey);
                    Console.WriteLine("Enter the hexadecimal secondary key for mifare card. [KEY1-KEY2-...-KEY6]");
                    Console.Write(">>>> ");
                    enterSmartcardKey(cardConfig.mifare.secondaryKey);

                    Console.WriteLine("Enter the app id for desfire card. [ID1-ID2-ID3]");
                    Console.Write(">>>> ");
                    enterSmartcardKey(cardConfig.desfire.appID);
                    Console.WriteLine("Enter the file id for desfire card [0(default)]");
                    Console.Write(">>>> ");
                    cardConfig.desfire.fileID = Util.GetInput((byte)0);

#if false //Not yet implemented
                    Console.WriteLine("Enter the encryption type for desfire card [0: DES(default), 1: AES]");
                    Console.Write(">>>> ");
                    cardConfig.desfire.encryptionType = Util.GetInput((byte)0);
#else
                    cardConfig.desfire.encryptionType = 0;
#endif
                    Console.WriteLine("Enter the hexadecimal primary key for desfire card. [KEY1-KEY2-...-KEY16]");
                    Console.Write(">>>> ");
                    enterSmartcardKey(cardConfig.desfire.primaryKey);
                    Console.WriteLine("Enter the hexadecimal secondary key for desfire card. [KEY1-KEY2-...-KEY16]");
                    Console.Write(">>>> ");
                    enterSmartcardKey(cardConfig.desfire.secondaryKey);
                }
                else // iclass card
                {
                    Console.WriteLine("Enter the start block index for iclass card [0(default)]");
                    Console.Write(">>>> ");
                    cardConfig.iclass.startBlockIndex = Util.GetInput((UInt16)0);
                    Console.WriteLine("Enter the hexadecimal primary key for iclass card. [KEY1-KEY2-...-KEY8]");
                    Console.Write(">>>> ");
                    enterSmartcardKey(cardConfig.iclass.primaryKey);
                    Console.WriteLine("Enter the hexadecimal secondary key for iclass card. [KEY1-KEY2-...-KEY8]");
                    Console.Write(">>>> ");
                    enterSmartcardKey(cardConfig.iclass.secondaryKey);
                }
            }

            Console.WriteLine("Trying to set card configuration.");
            result = (BS2ErrorCode)API.BS2_SetCardConfig(sdkContext, deviceID, ref cardConfig);
            if (result != BS2ErrorCode.BS_SDK_SUCCESS)
            {
                Console.WriteLine("Got error({0}).", result);
            }
        }
예제 #3
0
 extern public static int BS2_SetCardConfig(IntPtr context, UInt32 deviceId, ref BS2CardConfig config);