Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:bs2_setcustomcardconfig [2023/08/31 21:16]
kkshin [Sample Code(C#)]
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.primaryKey0x0, sizeof(config.desfire.primaryKey)); + msg = "​Please enter a operation mode for desfire ​card(0: Legacy1: 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(""​);​ + if (config.useSecondaryKey) 
- oss << "​Please enter the hexadecimal " << sizeof(config.desfire.appID) << "​-bytes ​appID for desfire card." << endl; +
- oss << " [Like 12 34 EF]" << endl; + memset(&​config.desfire.secondaryKey,​ 0x0, sizeof(config.desfire.secondaryKey));​ 
- Utility::​getLineHexaString<​uint8_t>​(oss.str(),​ config.desfire.appID, sizeof(config.desfire.appID)); + oss.str(""​);​ 
- + oss << "​Please enter the hexadecimal " << sizeof(config.desfire.secondaryKey) << "​-bytes ​secondary key for desfire card." << endl; 
- msg = "​Please enter the fileID for desfire card.";​ + oss << " [Like 12 34 56 ... EF]" << endl; 
- config.desfire.fileID = (uint8_t)Utility::​getInput<​uint32_t>​(msg);​ + Utility::​getLineHexaString<​uint8_t>​(oss.str(),​ config.desfire.secondaryKey, sizeof(config.desfire.secondaryKey)); 
- 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 a operation mode for desfire card. (0: Legacy, 1: Advanced(AppLevelKey))";​ + else // DESFIRECARD_OPERATION_MODE_APPLEVELKEY
- config.desfire.operationMode = (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);​ +
- +
- 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>​
  
Line 248: Line 292:
                     Console.Write(">>>>​ ");                     Console.Write(">>>>​ ");
                     config.desfire.desfireAppKey.fileReadKeyNumber = Util.GetInput((byte)0);​                     config.desfire.desfireAppKey.fileReadKeyNumber = Util.GetInput((byte)0);​
- 
-#if DO_NOT_NEED 
-                    tempStr = String.Format("​Please enter the hexadecimal {0}-bytes fileWriteKey for desfire card. [KEY1-KEY2-...-KEY16]",​ sizeOfFileWriteKey);​ 
-                    Util.HighlightLineMulti(tempStr,​ "​fileWriteKey",​ "​desfire card"​);​ 
-                    Console.Write(">>>>​ "); 
-                    enterSmartcardKey(config.desfire.desfireAppKey.fileWriteKey);​ 
-                    Util.HighlightLineMulti("​Please enter the fileWriteKeyNumber of desfire card.",​ "​fileWriteKeyNumber",​ "​desfire card"​);​ 
-                    Console.Write(">>>>​ "); 
-                    config.desfire.desfireAppKey.fileWriteKeyNumber = Util.GetInput((byte)0);​ 
-#endif 
                 }                 }