Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:bs2_setcustomcardconfig [2023/08/31 18:56] kkshin |
en:bs2_setcustomcardconfig [2023/08/31 21:38] (current) kkshin [Sample Code(C++)] |
||
---|---|---|---|
Line 31: | Line 31: | ||
<file cpp sample_setcustomcardconfig.cpp> | <file cpp sample_setcustomcardconfig.cpp> | ||
ConfigControl cc(context); | ConfigControl cc(context); | ||
+ | DeviceControl dc(context); | ||
+ | BS2DeviceCapabilities capabilies = { 0, }; | ||
BS2CustomCardConfig config = { 0, }; | BS2CustomCardConfig config = { 0, }; | ||
BS2_DEVICE_ID id = Utility::getSelectedDeviceID(device); | BS2_DEVICE_ID id = Utility::getSelectedDeviceID(device); | ||
- | int sdkResult = cc.getCustomCardConfig(id, config); | + | |
+ | int sdkResult = dc.getDeviceCapabilities(id, capabilies); | ||
+ | if (BS_SDK_SUCCESS != sdkResult) | ||
+ | return sdkResult; | ||
+ | |||
+ | if (!capabilies.customSmartCardSupported) | ||
+ | { | ||
+ | TRACE("Not supported function."); | ||
+ | return BS_SDK_ERROR_NOT_SUPPORTED; | ||
+ | } | ||
+ | |||
+ | sdkResult = cc.getCustomCardConfig(id, config); | ||
if (BS_SDK_SUCCESS != sdkResult) | if (BS_SDK_SUCCESS != sdkResult) | ||
return sdkResult; | return sdkResult; | ||
Line 70: | Line 83: | ||
if (Utility::isYes("Do you want to change desfire custom card settings?")) | if (Utility::isYes("Do you want to change desfire custom card settings?")) | ||
{ | { | ||
- | memset(&config.desfire.primaryKey, 0x0, sizeof(config.desfire.primaryKey)); | + | msg = "Please enter a operation mode for desfire card. (0: Legacy, 1: Advanced(AppLevelKey))"; |
- | oss << "Please enter the hexadecimal " << sizeof(config.desfire.primaryKey) << "-bytes primary key for desfire card." << endl; | + | config.desfire.operationMode = (uint8_t)Utility::getInput<uint32_t>(msg); |
- | oss << " [Like 12 34 56 ... EF]" << endl; | + | |
- | Utility::getLineHexaString<uint8_t>(oss.str(), config.desfire.primaryKey, sizeof(config.desfire.primaryKey)); | + | |
- | if (config.useSecondaryKey) | + | if (DESFIRECARD_OPERATION_MODE_LEGACY == config.desfire.operationMode) |
{ | { | ||
- | memset(&config.desfire.secondaryKey, 0x0, sizeof(config.desfire.secondaryKey)); | + | memset(&config.desfire.primaryKey, 0x0, sizeof(config.desfire.primaryKey)); |
oss.str(""); | oss.str(""); | ||
- | oss << "Please enter the hexadecimal " << sizeof(config.desfire.secondaryKey) << "-bytes secondary key for desfire card." << endl; | + | oss << "Please enter the hexadecimal " << sizeof(config.desfire.primaryKey) << "-bytes primary key for desfire card." << endl; |
oss << " [Like 12 34 56 ... EF]" << endl; | oss << " [Like 12 34 56 ... EF]" << endl; | ||
- | Utility::getLineHexaString<uint8_t>(oss.str(), config.desfire.secondaryKey, sizeof(config.desfire.secondaryKey)); | + | Utility::getLineHexaString<uint8_t>(oss.str(), config.desfire.primaryKey, sizeof(config.desfire.primaryKey)); |
- | } | + | |
- | + | ||
- | oss.str(""); | + | |
- | oss << "Please enter the hexadecimal " << sizeof(config.desfire.appID) << "-bytes appID for desfire card." << endl; | + | |
- | oss << " [Like 12 34 EF]" << endl; | + | |
- | Utility::getLineHexaString<uint8_t>(oss.str(), config.desfire.appID, sizeof(config.desfire.appID)); | + | |
- | msg = "Please enter the fileID for desfire card."; | + | if (config.useSecondaryKey) |
- | config.desfire.fileID = (uint8_t)Utility::getInput<uint32_t>(msg); | + | { |
- | msg = "Please enter a encryption type for desfire card. (0: DES/3DES, 1: AES)"; | + | memset(&config.desfire.secondaryKey, 0x0, sizeof(config.desfire.secondaryKey)); |
- | config.desfire.encryptionType = (uint8_t)Utility::getInput<uint32_t>(msg); | + | oss.str(""); |
- | msg = "Please enter a operation mode for desfire card. (0: Legacy, 1: Advanced(AppLevelKey))"; | + | oss << "Please enter the hexadecimal " << sizeof(config.desfire.secondaryKey) << "-bytes secondary key for desfire card." << endl; |
- | config.desfire.operationMode = (uint8_t)Utility::getInput<uint32_t>(msg); | + | oss << " [Like 12 34 56 ... EF]" << endl; |
- | msg = "Please enter the card data size of desfire card."; | + | Utility::getLineHexaString<uint8_t>(oss.str(), config.desfire.secondaryKey, sizeof(config.desfire.secondaryKey)); |
- | config.desfire.dataSize = (uint8_t)Utility::getInput<uint32_t>(msg); | + | } |
- | msg = "Please enter the skip bytes of desfire card."; | + | } |
- | config.desfire.skipBytes = (uint8_t)Utility::getInput<uint32_t>(msg); | + | else // DESFIRECARD_OPERATION_MODE_APPLEVELKEY |
- | + | ||
- | if (config.desfire.operationMode == DESFIRECARD_OPERATION_MODE_APPLEVELKEY) | + | |
{ | { | ||
memset(&config.desfire.desfireAppKey.appMasterKey, 0x0, sizeof(config.desfire.desfireAppKey.appMasterKey)); | memset(&config.desfire.desfireAppKey.appMasterKey, 0x0, sizeof(config.desfire.desfireAppKey.appMasterKey)); | ||
Line 115: | Line 118: | ||
oss << " [Like 12 34 56 ... EF]" << endl; | oss << " [Like 12 34 56 ... EF]" << endl; | ||
Utility::getLineHexaString<uint8_t>(oss.str(), config.desfire.desfireAppKey.fileReadKey, sizeof(config.desfire.desfireAppKey.fileReadKey)); | Utility::getLineHexaString<uint8_t>(oss.str(), config.desfire.desfireAppKey.fileReadKey, sizeof(config.desfire.desfireAppKey.fileReadKey)); | ||
- | |||
- | oss.str(""); | ||
- | oss << "Please enter the hexadecimal " << sizeof(config.desfire.desfireAppKey.fileWriteKey) << "-bytes fileWriteKey for desfire card." << endl; | ||
- | oss << " [Like 12 34 56 ... EF]" << endl; | ||
- | Utility::getLineHexaString<uint8_t>(oss.str(), config.desfire.desfireAppKey.fileWriteKey, sizeof(config.desfire.desfireAppKey.fileWriteKey)); | ||
msg = "Please enter the fileReadKeyNumber of desfire card."; | msg = "Please enter the fileReadKeyNumber of desfire card."; | ||
config.desfire.desfireAppKey.fileReadKeyNumber = (uint8_t)Utility::getInput<uint32_t>(msg); | config.desfire.desfireAppKey.fileReadKeyNumber = (uint8_t)Utility::getInput<uint32_t>(msg); | ||
- | msg = "Please enter the fileWriteKeyNumber of desfire card."; | ||
- | config.desfire.desfireAppKey.fileWriteKeyNumber = (uint8_t)Utility::getInput<uint32_t>(msg); | ||
} | } | ||
+ | |||
+ | oss.str(""); | ||
+ | oss << "Please enter the hexadecimal " << sizeof(config.desfire.appID) << "-bytes appID for desfire card." << endl; | ||
+ | oss << " [Like 12 34 EF]" << endl; | ||
+ | Utility::getLineHexaString<uint8_t>(oss.str(), config.desfire.appID, sizeof(config.desfire.appID)); | ||
+ | |||
+ | msg = "Please enter the fileID for desfire card."; | ||
+ | config.desfire.fileID = (uint8_t)Utility::getInput<uint32_t>(msg); | ||
+ | msg = "Please enter a encryption type for desfire card. (0: DES/3DES, 1: AES)"; | ||
+ | config.desfire.encryptionType = (uint8_t)Utility::getInput<uint32_t>(msg); | ||
+ | msg = "Please enter the card data size of desfire card."; | ||
+ | config.desfire.dataSize = (uint8_t)Utility::getInput<uint32_t>(msg); | ||
+ | msg = "Please enter the skip bytes of desfire card."; | ||
+ | config.desfire.skipBytes = (uint8_t)Utility::getInput<uint32_t>(msg); | ||
} | } | ||
Line 133: | Line 143: | ||
config.formatID = (BS2_UID)Utility::getInput<uint32_t>(msg); | config.formatID = (BS2_UID)Utility::getInput<uint32_t>(msg); | ||
- | return cc.setCustomCardConfig(id, config); | + | sdkResult = cc.setCustomCardConfig(id, config); |
+ | if (BS_SDK_SUCCESS != sdkResult) | ||
+ | return sdkResult; | ||
+ | |||
+ | oss.str(""); | ||
+ | oss << "To use the custom smart card function, you must turn off the Suprema smart card function." << endl; | ||
+ | oss << "Do you want to change the card operation mode?"; | ||
+ | if (Utility::isYes(oss.str())) | ||
+ | { | ||
+ | BS2SystemConfig sysConfig = { 0, }; | ||
+ | sdkResult = cc.getSystemConfig(id, sysConfig); | ||
+ | if (BS_SDK_SUCCESS != sdkResult) | ||
+ | return sdkResult; | ||
+ | |||
+ | uint32_t preMask = sysConfig.useCardOperationMask; | ||
+ | |||
+ | // Turn off Suprema smart card | ||
+ | sysConfig.useCardOperationMask &= ~(uint32_t)CARD_OPERATION_MASK_CLASSIC_PLUS; | ||
+ | sysConfig.useCardOperationMask &= ~(uint32_t)CARD_OPERATION_MASK_DESFIRE_EV1; | ||
+ | sysConfig.useCardOperationMask &= ~(uint32_t)CARD_OPERATION_MASK_SR_SE; | ||
+ | sysConfig.useCardOperationMask &= ~(uint32_t)CARD_OPERATION_MASK_SEOS; | ||
+ | |||
+ | // Turn on Custom smart card | ||
+ | sysConfig.useCardOperationMask |= (uint32_t)CARD_OPERATION_MASK_CUSTOM_CLASSIC_PLUS; | ||
+ | sysConfig.useCardOperationMask |= (uint32_t)CARD_OPERATION_MASK_CUSTOM_DESFIRE_EV1; | ||
+ | |||
+ | // Apply | ||
+ | sysConfig.useCardOperationMask |= (uint32_t)CARD_OPERATION_USE; | ||
+ | |||
+ | sdkResult = cc.setSystemConfig(id, sysConfig); | ||
+ | if (BS_SDK_SUCCESS == sdkResult) | ||
+ | TRACE("Card operation mode was changed 0x08d => 0x08d", preMask, sysConfig.useCardOperationMask); | ||
+ | } | ||
+ | |||
+ | return sdkResult; | ||
</file> | </file> | ||
==== Sample Code(C#) ==== | ==== Sample Code(C#) ==== | ||
<file csharp sample_setcustomcardconfig.cs> | <file csharp sample_setcustomcardconfig.cs> | ||
- | BS2CustomCardConfig config; | + | BS2DeviceCapabilities capa; |
- | Console.WriteLine("Try to get CustomCardConfig"); | + | if (!CommonControl.getDeviceCapabilities(sdkContext, deviceID, out capa)) |
- | BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetCustomCardConfig(sdkContext, deviceID, out config); | + | return; |
- | if (BS2ErrorCode.BS_SDK_SUCCESS != result) | + | |
- | return; | + | |
- | Util.HighlightLine("Please enter a data type of cards. (0: Binary, 1: ASCII, 2: UTF16, 3: BCS)", "data type"); | + | if (!Convert.ToBoolean(capa.functionExSupported & (byte)BS2CapabilityFunctionExSupport.FUNCTIONEX_SUPPORT_CUSTOMSMARTCARD)) |
- | Console.Write(">>>> "); | + | { |
- | config.dataType = Util.GetInput((byte)0); | + | Console.WriteLine("Not supported function."); |
+ | return; | ||
+ | } | ||
- | Util.HighlightLine("Do you want to use secondary key?", "use secondary key"); | + | BS2CustomCardConfig config; |
- | Console.Write(">>>> "); | + | Console.WriteLine("Try to get CustomCardConfig"); |
- | bool useSecondaryKey = Util.IsYes(); | + | BS2ErrorCode result = (BS2ErrorCode)API.BS2_GetCustomCardConfig(sdkContext, deviceID, out config); |
- | config.useSecondaryKey = Convert.ToByte(useSecondaryKey); | + | if (BS2ErrorCode.BS_SDK_SUCCESS != result) |
+ | return; | ||
- | Util.HighlightLine("Do you want to change mifare custom card settings? [Y/n]", "mifare custom card"); | + | Util.HighlightLine("Please enter a data type of cards. (0: Binary, 1: ASCII, 2: UTF16, 3: BCS)", "data type"); |
- | Console.Write(">>>> "); | + | Console.Write(">>>> "); |
- | if (Util.IsYes()) | + | config.dataType = Util.GetInput((byte)0); |
- | { | + | |
- | int sizeOfKey = config.mifare.primaryKey.Length; | + | |
- | Array.Clear(config.mifare.primaryKey, 0, sizeOfKey); | + | |
- | string tempStr = String.Format("Please enter the hexadecimal {0}-bytes primary key for mifare card. [KEY1-KEY2-...-KEY6]", sizeOfKey); | + | |
- | Util.HighlightLineMulti(tempStr, "primary key", "mifare card"); | + | |
- | Console.Write(">>>> "); | + | |
- | enterSmartcardKey(config.mifare.primaryKey); | + | |
- | if (useSecondaryKey) | + | Util.HighlightLine("Do you want to use secondary key?", "use secondary key"); |
- | { | + | Console.Write(">>>> "); |
- | sizeOfKey = config.mifare.secondaryKey.Length; | + | bool useSecondaryKey = Util.IsYes(); |
- | Array.Clear(config.mifare.secondaryKey, 0, sizeOfKey); | + | config.useSecondaryKey = Convert.ToByte(useSecondaryKey); |
- | tempStr = String.Format("Please enter the hexadecimal {0}-bytes secondary key for mifare card. [KEY1-KEY2-...-KEY6]", sizeOfKey); | + | |
- | Util.HighlightLineMulti(tempStr, "secondary key", "mifare card"); | + | |
- | Console.Write(">>>> "); | + | |
- | enterSmartcardKey(config.mifare.secondaryKey); | + | |
- | } | + | |
- | Util.HighlightLineMulti("Please enter the start block index of mifare card.", "start block index", "mifare card"); | + | Util.HighlightLine("Do you want to change mifare custom card settings? [Y/n]", "mifare custom card"); |
- | Console.Write(">>>> "); | + | Console.Write(">>>> "); |
- | config.mifare.startBlockIndex = Util.GetInput((UInt16)0); | + | if (Util.IsYes()) |
+ | { | ||
+ | int sizeOfKey = config.mifare.primaryKey.Length; | ||
+ | Array.Clear(config.mifare.primaryKey, 0, sizeOfKey); | ||
+ | string tempStr = String.Format("Please enter the hexadecimal {0}-bytes primary key for mifare card. [KEY1-KEY2-...-KEY6]", sizeOfKey); | ||
+ | Util.HighlightLineMulti(tempStr, "primary key", "mifare card"); | ||
+ | Console.Write(">>>> "); | ||
+ | enterSmartcardKey(config.mifare.primaryKey); | ||
- | Util.HighlightLineMulti("Please enter the card data size of mifare card.", "card data size", "mifare card"); | + | if (useSecondaryKey) |
- | Console.Write(">>>> "); | + | { |
- | config.mifare.dataSize = Util.GetInput((byte)0); | + | sizeOfKey = config.mifare.secondaryKey.Length; |
+ | Array.Clear(config.mifare.secondaryKey, 0, sizeOfKey); | ||
+ | tempStr = String.Format("Please enter the hexadecimal {0}-bytes secondary key for mifare card. [KEY1-KEY2-...-KEY6]", sizeOfKey); | ||
+ | Util.HighlightLineMulti(tempStr, "secondary key", "mifare card"); | ||
+ | Console.Write(">>>> "); | ||
+ | enterSmartcardKey(config.mifare.secondaryKey); | ||
+ | } | ||
- | Util.HighlightLineMulti("Please enter the skip bytes of mifare card.", "skip bytes", "mifare card"); | + | Util.HighlightLineMulti("Please enter the start block index of mifare card.", "start block index", "mifare card"); |
- | Console.Write(">>>> "); | + | Console.Write(">>>> "); |
- | config.mifare.skipBytes = Util.GetInput((byte)0); | + | config.mifare.startBlockIndex = Util.GetInput((UInt16)0); |
- | } | + | |
- | Util.HighlightLine("Do you want to change desfire custom card settings? [Y/n]", "desfire custom card"); | + | Util.HighlightLineMulti("Please enter the card data size of mifare card.", "card data size", "mifare card"); |
- | Console.Write(">>>> "); | + | Console.Write(">>>> "); |
- | if (Util.IsYes()) | + | config.mifare.dataSize = Util.GetInput((byte)0); |
- | { | + | |
- | int sizeOfKey = config.desfire.primaryKey.Length; | + | |
- | Array.Clear(config.desfire.primaryKey, 0, sizeOfKey); | + | |
- | string tempStr = String.Format("Please enter the hexadecimal {0}-bytes primary key for desfire card. [KEY1-KEY2-...-KEY6]", sizeOfKey); | + | |
- | Util.HighlightLineMulti(tempStr, "primary key", "desfire card"); | + | |
- | Console.Write(">>>> "); | + | |
- | enterSmartcardKey(config.desfire.primaryKey); | + | |
- | if (useSecondaryKey) | + | Util.HighlightLineMulti("Please enter the skip bytes of mifare card.", "skip bytes", "mifare card"); |
- | { | + | Console.Write(">>>> "); |
- | sizeOfKey = config.desfire.secondaryKey.Length; | + | config.mifare.skipBytes = Util.GetInput((byte)0); |
- | Array.Clear(config.desfire.secondaryKey, 0, sizeOfKey); | + | } |
- | tempStr = String.Format("Please enter the hexadecimal {0}-bytes secondary key for desfire card. [KEY1-KEY2-...-KEY6]", sizeOfKey); | + | |
- | Util.HighlightLineMulti(tempStr, "secondary key", "desfire card"); | + | |
- | Console.Write(">>>> "); | + | |
- | enterSmartcardKey(config.desfire.secondaryKey); | + | |
- | } | + | |
- | sizeOfKey = config.desfire.appID.Length; | + | Util.HighlightLine("Do you want to change desfire custom card settings? [Y/n]", "desfire custom card"); |
- | Array.Clear(config.desfire.appID, 0, sizeOfKey); | + | Console.Write(">>>> "); |
- | tempStr = String.Format("Please enter the hexadecimal {0}-bytes appID for desfire card. [KEY1-KEY2-...-KEY6]", sizeOfKey); | + | if (Util.IsYes()) |
- | Util.HighlightLineMulti(tempStr, "appID", "desfire card"); | + | { |
- | Console.Write(">>>> "); | + | Util.HighlightLineMulti("Please enter a operationMode of desfire card. (0: Legacy, 1: Advanced(AppLevelKey))", "operationMode", "desfire card"); |
- | enterSmartcardKey(config.desfire.appID); | + | Console.Write(">>>> "); |
+ | config.desfire.operationMode = Util.GetInput((byte)0); | ||
- | Util.HighlightLineMulti("Please enter the fileID of desfire card.", "fileID", "desfire card"); | + | string tempStr; |
- | Console.Write(">>>> "); | + | int sizeOfKey; |
- | config.desfire.fileID = Util.GetInput((byte)0); | + | if (config.desfire.operationMode == Convert.ToByte(BS2DesfireCardOperation.BS2_DESFIRECARD_OPERATION_MODE_LEGACY)) |
+ | { | ||
+ | sizeOfKey = config.desfire.primaryKey.Length; | ||
+ | Array.Clear(config.desfire.primaryKey, 0, sizeOfKey); | ||
+ | tempStr = String.Format("Please enter the hexadecimal {0}-bytes primary key for desfire card. [KEY1-KEY2-...-KEY6]", sizeOfKey); | ||
+ | Util.HighlightLineMulti(tempStr, "primary key", "desfire card"); | ||
+ | Console.Write(">>>> "); | ||
+ | enterSmartcardKey(config.desfire.primaryKey); | ||
- | Util.HighlightLineMulti("Please enter a encryptionType of desfire card. (0: DES/3DES, 1: AES)", "encryptionType", "desfire card"); | + | if (useSecondaryKey) |
- | Console.Write(">>>> "); | + | { |
- | config.desfire.encryptionType = Util.GetInput((byte)0); | + | sizeOfKey = config.desfire.secondaryKey.Length; |
+ | Array.Clear(config.desfire.secondaryKey, 0, sizeOfKey); | ||
+ | tempStr = String.Format("Please enter the hexadecimal {0}-bytes secondary key for desfire card. [KEY1-KEY2-...-KEY6]", sizeOfKey); | ||
+ | Util.HighlightLineMulti(tempStr, "secondary key", "desfire card"); | ||
+ | Console.Write(">>>> "); | ||
+ | enterSmartcardKey(config.desfire.secondaryKey); | ||
+ | } | ||
+ | } | ||
+ | else // BS2DesfireCardOperation.BS2_DESFIRECARD_OPERATION_MODE_APPLEVELKEY | ||
+ | { | ||
+ | int sizeOfAppMasterKey = config.desfire.desfireAppKey.appMasterKey.Length; | ||
+ | int sizeOfFileReadKey = config.desfire.desfireAppKey.fileReadKey.Length; | ||
+ | int sizeOfFileWriteKey = config.desfire.desfireAppKey.fileWriteKey.Length; | ||
+ | Array.Clear(config.desfire.desfireAppKey.appMasterKey, 0, sizeOfAppMasterKey); | ||
+ | Array.Clear(config.desfire.desfireAppKey.fileReadKey, 0, sizeOfFileReadKey); | ||
+ | Array.Clear(config.desfire.desfireAppKey.fileWriteKey, 0, sizeOfFileWriteKey); | ||
- | Util.HighlightLineMulti("Please enter a operationMode of desfire card. (0: Legacy, 1: Advanced(AppLevelKey))", "operationMode", "desfire card"); | + | tempStr = String.Format("Please enter the hexadecimal {0}-bytes appMasterKey for desfire card. [KEY1-KEY2-...-KEY16]", sizeOfAppMasterKey); |
- | Console.Write(">>>> "); | + | Util.HighlightLineMulti(tempStr, "appMasterKey", "desfire card"); |
- | config.desfire.operationMode = Util.GetInput((byte)0); | + | Console.Write(">>>> "); |
+ | enterSmartcardKey(config.desfire.desfireAppKey.appMasterKey); | ||
- | Util.HighlightLineMulti("Please enter the card data size of desfire card.", "card data size", "desfire card"); | + | tempStr = String.Format("Please enter the hexadecimal {0}-bytes fileReadKey for desfire card. [KEY1-KEY2-...-KEY16]", sizeOfFileReadKey); |
- | Console.Write(">>>> "); | + | Util.HighlightLineMulti(tempStr, "fileReadKey", "desfire card"); |
- | config.desfire.dataSize = Util.GetInput((byte)0); | + | Console.Write(">>>> "); |
+ | enterSmartcardKey(config.desfire.desfireAppKey.fileReadKey); | ||
- | Util.HighlightLineMulti("Please enter the skip bytes of desfire card.", "skip bytes", "desfire card"); | + | Util.HighlightLineMulti("Please enter the fileReadKeyNumber of desfire card.", "fileReadKeyNumber", "desfire card"); |
- | Console.Write(">>>> "); | + | Console.Write(">>>> "); |
- | config.desfire.skipBytes = Util.GetInput((byte)0); | + | config.desfire.desfireAppKey.fileReadKeyNumber = Util.GetInput((byte)0); |
+ | } | ||
- | if (config.desfire.operationMode == Convert.ToByte(BS2DesfireCardOperation.BS2_DESFIRECARD_OPERATION_MODE_APPLEVELKEY)) | + | sizeOfKey = config.desfire.appID.Length; |
- | { | + | Array.Clear(config.desfire.appID, 0, sizeOfKey); |
- | int sizeOfAppMasterKey = config.desfire.desfireAppKey.appMasterKey.Length; | + | tempStr = String.Format("Please enter the hexadecimal {0}-bytes appID for desfire card. [KEY1-KEY2-...-KEY6]", sizeOfKey); |
- | int sizeOfFileReadKey = config.desfire.desfireAppKey.fileReadKey.Length; | + | Util.HighlightLineMulti(tempStr, "appID", "desfire card"); |
- | int sizeOfFileWriteKey = config.desfire.desfireAppKey.fileWriteKey.Length; | + | Console.Write(">>>> "); |
- | Array.Clear(config.desfire.desfireAppKey.appMasterKey, 0, sizeOfAppMasterKey); | + | enterSmartcardKey(config.desfire.appID); |
- | Array.Clear(config.desfire.desfireAppKey.fileReadKey, 0, sizeOfFileReadKey); | + | |
- | Array.Clear(config.desfire.desfireAppKey.fileWriteKey, 0, sizeOfFileWriteKey); | + | |
- | tempStr = String.Format("Please enter the hexadecimal {0}-bytes appMasterKey for desfire card. [KEY1-KEY2-...-KEY6]", sizeOfAppMasterKey); | + | Util.HighlightLineMulti("Please enter the fileID of desfire card.", "fileID", "desfire card"); |
- | Util.HighlightLineMulti(tempStr, "appMasterKey", "desfire card"); | + | Console.Write(">>>> "); |
- | Console.Write(">>>> "); | + | config.desfire.fileID = Util.GetInput((byte)0); |
- | enterSmartcardKey(config.desfire.desfireAppKey.appMasterKey); | + | |
- | tempStr = String.Format("Please enter the hexadecimal {0}-bytes fileReadKey for desfire card. [KEY1-KEY2-...-KEY6]", sizeOfFileReadKey); | + | Util.HighlightLineMulti("Please enter a encryptionType of desfire card. (0: DES/3DES, 1: AES)", "encryptionType", "desfire card"); |
- | Util.HighlightLineMulti(tempStr, "fileReadKey", "desfire card"); | + | Console.Write(">>>> "); |
- | Console.Write(">>>> "); | + | config.desfire.encryptionType = Util.GetInput((byte)0); |
- | enterSmartcardKey(config.desfire.desfireAppKey.fileReadKey); | + | |
- | tempStr = String.Format("Please enter the hexadecimal {0}-bytes fileWriteKey for desfire card. [KEY1-KEY2-...-KEY6]", sizeOfFileWriteKey); | + | Util.HighlightLineMulti("Please enter the card data size of desfire card.", "card data size", "desfire card"); |
- | Util.HighlightLineMulti(tempStr, "fileWriteKey", "desfire card"); | + | Console.Write(">>>> "); |
- | Console.Write(">>>> "); | + | config.desfire.dataSize = Util.GetInput((byte)0); |
- | enterSmartcardKey(config.desfire.desfireAppKey.fileWriteKey); | + | |
- | Util.HighlightLineMulti("Please enter the fileReadKeyNumber of desfire card.", "fileReadKeyNumber", "desfire card"); | + | Util.HighlightLineMulti("Please enter the skip bytes of desfire card.", "skip bytes", "desfire card"); |
- | Console.Write(">>>> "); | + | Console.Write(">>>> "); |
- | config.desfire.desfireAppKey.fileReadKeyNumber = Util.GetInput((byte)0); | + | config.desfire.skipBytes = Util.GetInput((byte)0); |
+ | } | ||
- | Util.HighlightLineMulti("Please enter the fileWriteKeyNumber of desfire card.", "fileWriteKeyNumber", "desfire card"); | + | Util.HighlightLine("Please enter a smart card byte order. (0: MSB, 1: LSB)", "smart card byte order"); |
- | Console.Write(">>>> "); | + | Console.Write(">>>> "); |
- | config.desfire.desfireAppKey.fileWriteKeyNumber = Util.GetInput((byte)0); | + | config.smartCardByteOrder = Util.GetInput((byte)0); |
- | } | + | |
- | } | + | |
- | Util.HighlightLine("Please enter a smart card byte order. (0: MSB, 1: LSB)", "smart card byte order"); | + | Util.HighlightLine("Please enter a formatID.", "formatID"); |
- | Console.Write(">>>> "); | + | Console.Write(">>>> "); |
- | config.smartCardByteOrder = Util.GetInput((byte)0); | + | config.formatID = Util.GetInput((UInt32)0); |
- | Util.HighlightLine("Please enter a formatID.", "formatID"); | + | Console.WriteLine("Trying to set CustomCardConfig."); |
- | Console.Write(">>>> "); | + | result = (BS2ErrorCode)API.BS2_SetCustomCardConfig(sdkContext, deviceID, ref config); |
- | config.formatID = Util.GetInput((UInt32)0); | + | if (result != BS2ErrorCode.BS_SDK_SUCCESS) |
+ | Console.WriteLine("Got error({0}).", result); | ||
+ | else | ||
+ | Console.WriteLine("Card config set success"); | ||
- | Console.WriteLine("Trying to set CustomCardConfig."); | + | Util.HighlightLineMulti("To use the custom smart card function, you must turn off the Suprema smart card function. Do you want to change the card operation mode? [Y/n]", |
- | result = (BS2ErrorCode)API.BS2_SetCustomCardConfig(sdkContext, deviceID, ref config); | + | "turn off the Suprema smart card function", "change the card operation mode?"); |
- | if (result != BS2ErrorCode.BS_SDK_SUCCESS) | + | Console.Write(">>>> "); |
- | { | + | if (Util.IsYes()) |
- | Console.WriteLine("Got error({0}).", result); | + | { |
- | } | + | BS2SystemConfig sysConfig; |
+ | result = (BS2ErrorCode)API.BS2_GetSystemConfig(sdkContext, deviceID, out sysConfig); | ||
+ | if (result != BS2ErrorCode.BS_SDK_SUCCESS) | ||
+ | { | ||
+ | Console.WriteLine("Got error({0}).", result); | ||
+ | } | ||
+ | |||
+ | UInt32 preMask = sysConfig.useCardOperationMask; | ||
+ | |||
+ | // Turn off Suprema smart card | ||
+ | sysConfig.useCardOperationMask &= ~(UInt32)BS2SystemConfigCardOperationMask.CARD_OPERATION_MASK_CLASSIC_PLUS; | ||
+ | sysConfig.useCardOperationMask &= ~(UInt32)BS2SystemConfigCardOperationMask.CARD_OPERATION_MASK_DESFIRE_EV1; | ||
+ | sysConfig.useCardOperationMask &= ~(UInt32)BS2SystemConfigCardOperationMask.CARD_OPERATION_MASK_SR_SE; | ||
+ | sysConfig.useCardOperationMask &= ~(UInt32)BS2SystemConfigCardOperationMask.CARD_OPERATION_MASK_SEOS; | ||
+ | |||
+ | // Turn on Custom smart card | ||
+ | sysConfig.useCardOperationMask |= (UInt32)BS2SystemConfigCardOperationMask.CARD_OPERATION_MASK_CUSTOM_CLASSIC_PLUS; | ||
+ | sysConfig.useCardOperationMask |= (UInt32)BS2SystemConfigCardOperationMask.CARD_OPERATION_MASK_CUSTOM_DESFIRE_EV1; | ||
+ | |||
+ | // Apply | ||
+ | sysConfig.useCardOperationMask |= (UInt32)BS2SystemConfigCardOperationMask.CARD_OPERATION_USE; | ||
+ | |||
+ | result = (BS2ErrorCode)API.BS2_SetSystemConfig(sdkContext, deviceID, ref sysConfig); | ||
+ | if (result != BS2ErrorCode.BS_SDK_SUCCESS) | ||
+ | Console.WriteLine("Card operation mode update failed ({0}).", result); | ||
+ | else | ||
+ | Console.WriteLine("Card operation mode was changed 0x{0:x8} => 0x{1:x8}", preMask, sysConfig.useCardOperationMask); | ||
+ | } | ||
</file> | </file> |