diff --git a/.vs/mifare_plus_c_sharp/v15/.suo b/.vs/mifare_plus_c_sharp/v15/.suo index 9d1b82bebad521ee4739020bc3e2d3b3c8a53c9a..a60b998e87452a2054af798dbd2a7dd529a9c712 100644 Binary files a/.vs/mifare_plus_c_sharp/v15/.suo and b/.vs/mifare_plus_c_sharp/v15/.suo differ diff --git a/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide b/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide index 3902c6a5c49737e7ba59fb180ae21b047f108219..75e67b3d57119fe65a87ff312ba29121b961f41b 100644 Binary files a/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide and b/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide-shm b/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide-shm index d1c8f9549fffc28617bbebe630ea0a32e2e5d35d..0f3448c7bf222675f0f382fa2ea7cbcffdd08ec2 100644 Binary files a/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide-shm and b/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide-wal b/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide-wal index 11b8868d0d644d7bbd909e9b4e19fd4845249503..cda4880cbf84b600029a3d65090bef20d4338605 100644 Binary files a/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide-wal and b/.vs/mifare_plus_c_sharp/v15/Server/sqlite3/storage.ide-wal differ diff --git a/mifare_plus_c_sharp/Form1.cs b/mifare_plus_c_sharp/Form1.cs index 2f478332fa7d61af6872f7e960b4fca5627d0072..637fc05a0456272821bb8fca3ca8fda5211dd6fd 100644 --- a/mifare_plus_c_sharp/Form1.cs +++ b/mifare_plus_c_sharp/Form1.cs @@ -1,2519 +1,2519 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using uFR; - - - -namespace mifare_plus_c_sharp -{ - - using DL_STATUS = System.UInt32; - - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - - - - public static byte[] StringToByteArray(string hex) - { - return Enumerable.Range(0, hex.Length) - .Where(x => x % 2 == 0) - .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) - .ToArray(); - } - - private void timer2_Tick(object sender, EventArgs e) - { - DL_STATUS status = 0; - - byte cardtype_val = 0, sak = 0, uid_size = 0; - byte[] uid = new byte[10]; - - status = (UInt32)uFCoder.GetDlogicCardType(out cardtype_val); - - if (status > 0) - { - //toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - txtCardType.Text = uFCoder.status2str((uFR.DL_STATUS)status); - txtCardUID.Text = BitConverter.ToString(uid).Replace("-", ":"); - return; - } - - txtCardType.Text = Enum.GetName(typeof(DLOGIC_CARD_TYPE), cardtype_val); - - status = (UInt32)uFCoder.GetCardIdEx(out sak, uid, out uid_size); - - txtCardUID.Text = BitConverter.ToString(uid).Replace("-", ":"); - - //toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - - - - private void btnPersonalizeCard_Click(object sender, EventArgs e) - { - DL_STATUS status; - - byte[] master_key = new byte[16]; - byte[] config_key = new byte[16]; - byte[] l2_sw_key = new byte[16]; - byte[] l3_sw_key = new byte[16]; - byte[] l1_auth_key = new byte[16]; - byte[] sel_vc_key = new byte[16]; - byte[] prox_chk_key = new byte[16]; - byte[] vc_poll_enc_key = new byte[16]; - byte[] vc_poll_mac_key = new byte[16]; - byte dl_card_type = 0; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "No card in RF field found for Personalization"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - //check if card type S in SL0 - if (!((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL0 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_X_4K_SL0)) - { - txtStatus.Text = "Card is not in security level 0 mode."; - return; - } - - /* if (dl_card_type == DL_MIFARE_PLUS_S_2K_SL0 || dl_card_type == DL_MIFARE_PLUS_S_4K_SL0) - { - } */ - - if (txtPersonalizeCardMasterKey.TextLength != 32) - { - txtStatus.Text = "Master key must be 16 bytes long!"; - return; - } - - if (txtPersonalizeConfigurationKey.TextLength != 32) - { - txtStatus.Text = "Card configuration key must be 16 bytes long!"; - return; - } - - if (txtPersonalizeLevel2Key.TextLength != 32) - { - txtStatus.Text = "Level 2 switch key must be 16 bytes long!"; - return; - } - - if (txtPersonalizeLevel3Key.TextLength != 32) - { - txtStatus.Text = "Level 3 switch key must be 16 bytes long!"; - return; - } - - if (txtPersonalizeLevel1Key.TextLength != 32) - { - txtStatus.Text = "SL1 card authentication key must be 16 bytes long!"; - return; - } - - if ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_X_2K_SL0 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_X_4K_SL0) - { - if (txtPersonalizeSelectVCKey.TextLength != 32) - { - txtStatus.Text = "Select VC key must be 16 bytes long!"; - return; - } - - if (txtPersonalizeProximityCheckKey.TextLength != 32) - { - txtStatus.Text = "Proximity check key must be 16 bytes long!"; - return; - } - } - - if (txtPersonalizeVCENCKey.TextLength != 32) - { - txtStatus.Text = "VC polling ENC key key must be 16 bytes long!"; - return; - } - - if (txtPersonalizeVCMACKey.TextLength != 32) - { - txtStatus.Text = "VC polling MAC key key must be 16 bytes long!"; - return; - } - - - // StringToByteArray(AESkeyTB.Text); - - master_key = StringToByteArray(txtPersonalizeCardMasterKey.Text); - - config_key = StringToByteArray(txtPersonalizeConfigurationKey.Text); - - l1_auth_key = StringToByteArray(txtPersonalizeLevel1Key.Text); - - l2_sw_key = StringToByteArray(txtPersonalizeLevel2Key.Text); - - l3_sw_key = StringToByteArray(txtPersonalizeLevel3Key.Text); - - sel_vc_key = StringToByteArray(txtPersonalizeSelectVCKey.Text); - - prox_chk_key = StringToByteArray(txtPersonalizeProximityCheckKey.Text); - - vc_poll_enc_key = StringToByteArray(txtPersonalizeVCENCKey.Text); - - vc_poll_mac_key = StringToByteArray(txtPersonalizeVCMACKey.Text); - - - status = (UInt32)uFCoder.MFP_PersonalizationMinimal(master_key, config_key, l2_sw_key, l3_sw_key, l1_auth_key, - sel_vc_key, prox_chk_key, vc_poll_enc_key, vc_poll_mac_key); - - if (status > 0) - { - txtStatus.Text = "Card personalization was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Card personalization successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnAuthSL1_Click(object sender, EventArgs e) - { - DL_STATUS status; - - byte[] sl1_auth_key = new byte[16]; - - byte key_index = 0; - - if (rbChangeAuthPK.Checked) - { - if (txtAuthSL1AuthKey.TextLength != 32) - { - txtStatus.Text = "SL1 card authentication key must be 16 bytes long"; - return; - } - - sl1_auth_key = StringToByteArray(txtAuthSL1AuthKey.Text); - status = (UInt32)uFCoder.MFP_AesAuthSecurityLevel1_PK(sl1_auth_key); - - if (status > 0) - { - txtStatus.Text = "AES authentication on SL1 was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "AES authentication on SL1 successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - else - { - key_index = Byte.Parse(cbAuthSL1ReaderKeyIndex.Text); - - status = (UInt32)uFCoder.MFP_AesAuthSecurityLevel1(key_index); - - if (status > 0) - { - txtStatus.Text = "AES authentication on SL1 was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "AES authentication on SL1 successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - } - - private void btnSwitchSL3_Click(object sender, EventArgs e) - { - DL_STATUS status; - - byte[] sl3_sw_key = new byte[16]; - byte key_index = 0; - - if (rbChangeAuthPK.Checked) - { - if (txtSwitchSL3AESkey.TextLength != 32) - { - txtStatus.Text = "Level 3 switch key must be 16 bytes long"; - return; - } - - sl3_sw_key = StringToByteArray(txtSwitchSL3AESkey.Text); - - status = (UInt32)uFCoder.MFP_SwitchToSecurityLevel3_PK(sl3_sw_key); - - if (status > 0) - { - txtStatus.Text = "Switch to SL3 was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Switch to SL3 successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - else - { - key_index = Byte.Parse(cbSwitchSL3ReaderKeyIndex.Text); - - status = (UInt32)uFCoder.MFP_SwitchToSecurityLevel3(key_index); - - if (status > 0) - { - txtStatus.Text = "Switch to SL3 was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Switch to SL3 successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - } - - private void btnChangeMasterKey_Click(object sender, EventArgs e) - { - DL_STATUS status; - - byte[] old_master_key = new byte[16]; - byte[] new_master_key = new byte[16]; - byte key_index = 0; - - if (rbChangeAuthPK.Checked) - { - if (txtChangeMasterOldKey.TextLength != 32) - { - txtStatus.Text = "Old master key must be 16 bytes long"; - return; - } - - if (txtChangeMasterNewKey.TextLength != 32) - { - txtStatus.Text = "New master key must be 16 bytes long"; - return; - } - - old_master_key = StringToByteArray(txtChangeMasterOldKey.Text); - - new_master_key = StringToByteArray(txtChangeMasterNewKey.Text); - - status = (UInt32)uFCoder.MFP_ChangeMasterKey_PK(old_master_key, new_master_key); - - if (status > 0) - { - txtStatus.Text = "Master key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Master key change successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - else - { - if (txtChangeMasterNewKeyRK.TextLength != 32) - { - txtStatus.Text = "New master key must be 16 bytes long"; - return; - } - - new_master_key = StringToByteArray(txtChangeMasterNewKeyRK.Text); - - key_index = Byte.Parse(cbChangeMasterReaderKeyIndex.Text); - - status = (UInt32)uFCoder.MFP_ChangeMasterKey(key_index, new_master_key); - - if (status > 0) - { - txtStatus.Text = "Master key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Master key change successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - } - - private void btnChangeConfigurationKey_Click(object sender, EventArgs e) - { - DL_STATUS status; - - byte[] old_config_key = new byte[16]; - byte[] new_config_key = new byte[16]; - byte key_index = 0; - - if (rbChangeAuthPK.Checked) - { - if (txtChangeMasterOldKey.TextLength != 32) - { - txtStatus.Text = "Old configuration key must be 16 bytes long"; - return; - } - - if (txtChangeMasterNewKey.TextLength != 32) - { - txtStatus.Text = "New configuration key must be 16 bytes long"; - return; - } - - old_config_key = StringToByteArray(txtChangeConfigOldKey.Text); - - new_config_key = StringToByteArray(txtChangeConfigNewKey.Text); - - status = (UInt32)uFCoder.MFP_ChangeConfigurationKey_PK(old_config_key, new_config_key); - - if (status > 0) - { - txtStatus.Text = "Configuration key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Configuration key change successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - else - { - if (txtChangeConfigNewKeyRK.TextLength != 32) - { - txtStatus.Text = "New configuration key must be 16 bytes long"; - return; - } - - new_config_key = StringToByteArray(txtChangeConfigNewKeyRK.Text); - - key_index = Byte.Parse(cbChangeMasterReaderKeyIndex.Text); - - status = (UInt32)uFCoder.MFP_ChangeConfigurationKey(key_index, new_config_key); - - if (status > 0) - { - txtStatus.Text = "Configuration key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Configuration key change successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - } - - private void btnChangeAESSectorKey_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] old_sector_key = new byte[16]; - byte[] new_sector_key = new byte[16]; - byte key_index = 0, sector_nr = 0, auth_mode = 0; - - sector_nr = Byte.Parse(cbChangeSectorSectorNumber.Text); - - if (rbChangeSectorKeyA.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; - } - else if (rbChangeSectorKeyB.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; - } - else - { - txtStatus.Text = "You should select settings AES KEY A or B"; - return; - } - - if (rbChangeAuthPK.Checked) - { - if (txtChangeSectorOldKey.TextLength != 32) - { - txtStatus.Text = "Old sector key must be 16 bytes long"; - return; - } - - if (txtChangeSectorNewKey.TextLength != 32) - { - txtStatus.Text = "New sector key must be 16 bytes long"; - return; - } - - old_sector_key = StringToByteArray(txtChangeSectorOldKey.Text); - - new_sector_key = StringToByteArray(txtChangeSectorNewKey.Text); - - status = (UInt32)uFCoder.MFP_ChangeSectorKey_PK(sector_nr, auth_mode, old_sector_key, new_sector_key); - - if (status > 0) - { - txtStatus.Text = "Sector key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Sector key change successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - else if (rbChangeAuthRK.Checked) - { - if (txtChangeSectorNewKeyRK.TextLength != 32) - { - txtStatus.Text = "New sector key must be 16 bytes long"; - return; - } - - new_sector_key = StringToByteArray(txtChangeConfigNewKeyRK.Text); - - key_index = Byte.Parse(cbChangeSectorKeyReaderIndex.Text); - - status = (UInt32)uFCoder.MFP_ChangeSectorKey(sector_nr, auth_mode, key_index, new_sector_key); - - if (status > 0) - { - txtStatus.Text = "Sector key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Sector key change successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - } - - private void btnFieldConfigurationSet_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] config_key = new byte[16]; - byte key_index = 0, rid_use = 0, prox_check_use = 0; - - //Proximity check for X and EV1 card is not implemented yet - prox_check_use = 0; - - //setting usage of random id or uid - if (rbFieldConfigUseRandomID.Checked) - { - rid_use = 1; - } - else if (rbFieldConfigUseUID.Checked) - { - rid_use = 0; - } - - if (rbChangeAuthPK.Checked) - { - - if (txtFieldConfigKey.TextLength != 32) - { - txtStatus.Text = "Field configuration key must be 16 bytes long"; - return; - } - - config_key = StringToByteArray(txtFieldConfigKey.Text); - - status = (UInt32)uFCoder.MFP_FieldConfigurationSet_PK(config_key, rid_use, prox_check_use); - - if (status > 0) - { - txtStatus.Text = "Field configuration set was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Field configuration set successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - else if (rbChangeAuthRK.Checked) - { - key_index = Byte.Parse(cbFieldConfigReaderKeyIndex.Text); - - status = (UInt32)uFCoder.MFP_FieldConfigurationSet(key_index, rid_use, prox_check_use); - - if (status > 0) - { - txtStatus.Text = "Field configuration set was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Field configuration set successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - } - - private void btnGetCardUID_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] vc_enc_key = new byte[16]; - byte[] vc_mac_key = new byte[16]; - byte key_index_enc = 0, key_index_mac = 0, uid_len = 0; - byte[] uid = new byte[10]; - - if (rbChangeAuthPK.Checked) - { - if (txtGetCardUIDENCKey.TextLength != 32) - { - txtStatus.Text = "VC polling ENC key must be 16 bytes long"; - return; - } - - if (txtGetCardUIDMACKey.TextLength != 32) - { - txtStatus.Text = "VC polling MAC key must be 16 bytes long"; - return; - } - - vc_enc_key = StringToByteArray(txtGetCardUIDENCKey.Text); - - vc_mac_key = StringToByteArray(txtGetCardUIDMACKey.Text); - - status = (UInt32)uFCoder.MFP_GetUid_PK(vc_enc_key, vc_mac_key, uid, out uid_len); - - if (status > 0) - { - txtStatus.Text = "Get UID was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - txtStatus.Text = "Get UID was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - txtUID_Get.Text = BitConverter.ToString(uid).Replace("-", ":"); - - } - else if (rbChangeAuthRK.Checked) - { - key_index_enc = Byte.Parse(cbGetCardUIDENCKeyRK.Text); - - key_index_mac = Byte.Parse(cbGetCardUIDMACKeyRK.Text); - - status = (UInt32)uFCoder.MFP_GetUid(key_index_enc, key_index_mac, uid, out uid_len); - - if (status > 0) - { - txtStatus.Text = "Get UID was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - txtStatus.Text = "Get UID was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - txtUID_Get.Text = BitConverter.ToString(uid).Replace("-", ":"); - - } - } - - private void btnChangeVCPollingENCKey_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] config_key = new byte[16]; - byte[] new_vc_enc_key = new byte[16]; - byte key_index = 0; - - if (rbChangeAuthPK.Checked) - { - if (txtChangeVCPollingENCConfigKey.TextLength != 32) - { - txtStatus.Text = "Card configuration key must be 16 bytes long"; - return; - } - - if (txtChangeVCPollingENCNewKey.TextLength != 32) - { - txtStatus.Text = "New VC polling ENC key must be 16 bytes long"; - return; - } - - config_key = StringToByteArray(txtChangeVCPollingENCConfigKey.Text); - - new_vc_enc_key = StringToByteArray(txtChangeVCPollingENCNewKey.Text); - - status = (UInt32)uFCoder.MFP_ChangeVcPollingEncKey_PK(config_key, new_vc_enc_key); - - if (status > 0) - { - txtStatus.Text = "VC polling ENC key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "VC polling ENC key change was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - else if (rbChangeAuthRK.Checked) - { - key_index = Byte.Parse(cbChangeVCPollingENCReaderKeyIndex.Text); - - if (txtChangeVCPollingENCNewKeyRK.TextLength != 32) - { - txtStatus.Text = "New VC polling ENC key must be 16 bytes long"; - return; - } - - new_vc_enc_key = StringToByteArray(txtChangeVCPollingENCNewKeyRK.Text); - - status = (UInt32)uFCoder.MFP_ChangeVcPollingEncKey(key_index, new_vc_enc_key); - - if (status > 0) - { - txtStatus.Text = "VC polling ENC key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "VC polling ENC key change was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - } - - private void btnChangeVCPollingMACKey_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] config_key = new byte[16]; - byte[] new_vc_mac_key = new byte[16]; - byte key_index = 0; - - if (rbChangeAuthPK.Checked) - { - if (txtChangeVCPollingMACConfigKey.TextLength != 32) - { - txtStatus.Text = "Card configuration key must be 16 bytes long"; - return; - } - - if (txtChangeVCPollingMACNewKey.TextLength != 32) - { - txtStatus.Text = "New VC polling MAC key must be 16 bytes long"; - return; - } - - config_key = StringToByteArray(txtChangeVCPollingMACConfigKey.Text); - - new_vc_mac_key = StringToByteArray(txtChangeVCPollingMACNewKey.Text); - - status = (UInt32)uFCoder.MFP_ChangeVcPollingMacKey_PK(config_key, new_vc_mac_key); - - if (status > 0) - { - txtStatus.Text = "VC polling MAC key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "VC polling MAC key change was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - else if (rbChangeAuthRK.Checked) - { - key_index = Byte.Parse(cbChangeVCPollingMACReaderKeyIndex.Text); - - if (txtChangeVCPollingMACNewKeyRK.TextLength != 32) - { - txtStatus.Text = "New VC polling MAC key must be 16 bytes long"; - return; - } - - new_vc_mac_key = StringToByteArray(txtChangeVCPollingMACNewKeyRK.Text); - - status = (UInt32)uFCoder.MFP_ChangeVcPollingMacKey(key_index, new_vc_mac_key); - - if (status > 0) - { - txtStatus.Text = "VC polling MAC key change was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "VC polling MAC key change was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - } - - private void btnCrypto1KeyInput_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] crypto_key = new byte[6]; - byte key_index = 0; - - if (txtCrypto1Key.TextLength != 12) - { - txtStatus.Text = "Crypto key must be 6 bytes long"; - return; - } - - crypto_key = StringToByteArray(txtCrypto1Key.Text); - - key_index = Byte.Parse(cbCrpytoReaderIndex.Text); - - status = (UInt32)uFCoder.ReaderKeyWrite(crypto_key, key_index); - if (status > 0) - { - txtStatus.Text = "CRYPTO 1 key writing was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "CRYPTO 1 key writing was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - - } - - private void btnAesKeyInput_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] aes_key = new byte[16]; - byte key_index = 0; - - if (txtAESKey.TextLength != 32) - { - txtStatus.Text = "AES key must be 16 bytes long"; - return; - } - - aes_key = StringToByteArray(txtAESKey.Text); - - key_index = Byte.Parse(cbAESIndex.Text); - - status = (UInt32)uFCoder.uFR_int_DesfireWriteAesKey(key_index, aes_key); - - if (status > 0) - { - txtStatus.Text = "AES key writing was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "AES key writing was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnUnlockReader_Click(object sender, EventArgs e) - { - DL_STATUS status; - String password = ""; - - if (txtUnlockPassword.TextLength != 8) - { - txtStatus.Text = "Password must be 8 characters long"; - return; - } - - password = txtUnlockPassword.Text; - - status = (UInt32)uFCoder.ReaderKeysUnlock(password.ToCharArray()); - - if (status > 0) - { - txtStatus.Text = "Reader unlocking was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Reader unlocking was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - - } - - private void btnLockReader_Click(object sender, EventArgs e) - { - DL_STATUS status; - String password = ""; - - if (txtLockPassword.TextLength != 8) - { - txtStatus.Text = "Password must be 8 characters long"; - return; - } - - password = txtLockPassword.Text; - - status = (UInt32)uFCoder.ReaderKeysLock(password.ToCharArray()); - - if (status > 0) - { - txtStatus.Text = "Reader locking was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Reader locking was successful"; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void TabPage6_Click(object sender, EventArgs e) - { - - } - - private void btnBlockReadPK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0; - byte auth_mode = 0, block_address = 0; - byte[] crypto_key = new byte[6]; - byte[] aes_key = new byte[16]; - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - //Using AES or CRYPTO key depending on following check of card type - - if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) - { - //" (1) - Provided CRYPTO 1 key\n PK" - if (rbBlockReadKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; // auth mode check - - } - else if (rbBlockReadKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - if (txtBlockReadKeyPK.TextLength != 12) - { - txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; - return; - } - - crypto_key = StringToByteArray(txtBlockReadKeyPK.Text); - - block_address = Byte.Parse(cbBlockReadBlockNrPK.Text); - - status = (UInt32)uFCoder.BlockRead_PK(block_data, block_address, auth_mode, crypto_key); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - else - { - //" (2) - Provided AES key\n PK" - if (rbBlockReadKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; // auth mode check - } - else if (rbBlockReadKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; - } - - if (txtBlockReadKeyPK.TextLength != 32) - { - txtStatus.Text = "This card uses AES key that should be 16 bytes long"; - return; - } - - aes_key = StringToByteArray(txtBlockReadKeyPK.Text); - - block_address = Byte.Parse(cbBlockReadBlockNrPK.Text); - - status = (UInt32)uFCoder.BlockRead_PK(block_data, block_address, auth_mode, aes_key); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - } - - private void btnBlockReadRK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0; - byte auth_mode = 0, block_address = 0; - byte crypto_key_nr = 0; - byte aes_key_nr = 0; - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - //Using AES or CRYPTO key depending on following check of card type - - if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) - { - //" (1) - Reader CRYPTO 1 key\n RK" - if (rbBlockReadKeyARK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; // auth mode check - - } - else if (rbBlockReadKeyBRK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - crypto_key_nr = Byte.Parse(cbBlockReadKeyRK.Text); - - block_address = Byte.Parse(cbBlockReadBlockNrRK.Text); - - status = (UInt32)uFCoder.BlockRead(block_data, block_address, auth_mode, crypto_key_nr); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - else - { - //" (2) - Reader AES key\n RK" - if (rbBlockReadKeyARK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; ; // auth mode check - } - else if (rbBlockReadKeyBRK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - aes_key_nr = Byte.Parse(cbBlockReadKeyRK.Text); - - block_address = Byte.Parse(cbBlockReadBlockNrRK.Text); - - status = (UInt32)uFCoder.BlockRead(block_data, block_address, auth_mode, aes_key_nr); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - } - - private void btnBlockReadAKM1_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0; - byte auth_mode = 0, block_address = 0; - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - //" (1) - Provided CRYPTO 1 key\n AKM1" - if (rbBlockReadKeyAAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; // auth mode check - - } - else if (rbBlockReadKeyBAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - block_address = Byte.Parse(cbBlockReadBlockNrAKM1.Text); - - status = (UInt32)uFCoder.BlockRead_AKM1(block_data, block_address, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnBlockReadAKM2_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0; - byte auth_mode = 0, block_address = 0; - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - ////////////////AKM2/////////////////////" - if (rbBlockReadKeyAAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; // auth mode check - - } - else if (rbBlockReadKeyBAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - block_address = Byte.Parse(cbBlockReadBlockNrAKM2.Text); - - status = (UInt32)uFCoder.BlockRead_AKM2(block_data, block_address, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - - private void btnBlockInSectorReadPK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] block_data = new byte[16]; - byte[] sector_key = new byte[16]; - byte sector_nr = 0, block_nr = 0, auth_mode = 0; - byte dl_card_type = 0; - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) - { - if (txtBlockInSectorReadKeyPK.TextLength != 12) - { - txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; - return; - } - - sector_key = StringToByteArray(txtBlockInSectorReadKeyPK.Text); - - if (rbBlockInSectorReadKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbBlockInSectorReadKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - } - else - { - if (txtBlockInSectorReadKeyPK.TextLength != 32) - { - txtStatus.Text = "This card uses AES key that should be 16 bytes long"; - return; - } - - sector_key = StringToByteArray(txtBlockInSectorReadKeyPK.Text); - - if (rbBlockInSectorReadKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; - } - else if (rbBlockInSectorReadKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; - } - } - - sector_nr = Byte.Parse(cbBlockInSectorSectorNrPK.Text); - - block_nr = Byte.Parse(cbBlockInSectorBlockNrPK.Text); - - - status = (UInt32)uFCoder.BlockInSectorRead_PK(block_data, sector_nr, block_nr, auth_mode, sector_key); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - private void bnBlockInSectorReadRK_Click(object sender, EventArgs e) - { - //RK - DL_STATUS status; - byte[] block_data = new byte[16]; - byte sector_nr = 0, block_nr = 0, auth_mode = 0, key_nr = 0; - byte dl_card_type = 0; - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - - if (rbBlockInSectorReadKeyARK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - } - else if (rbBlockInSectorReadKeyBRK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - key_nr = Byte.Parse(cbBlockInSectorReadKeyRK.Text); - - sector_nr = Byte.Parse(cbBlockInSectorSectorNrRK.Text); - - block_nr = Byte.Parse(cbBlockInSectorBlockNrRK.Text); - - status = (UInt32)uFCoder.BlockInSectorRead(block_data, sector_nr, block_nr, auth_mode, key_nr); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnBlockInSectoReadAKM1_Click(object sender, EventArgs e) - { - //AKM1 - DL_STATUS status; - byte[] block_data = new byte[16]; - byte sector_nr = 0, block_nr = 0, auth_mode = 0; - byte dl_card_type = 0; - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbBlockInSectorReadKeyAAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - } - else if (rbBlockInSectorReadKeyBAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - sector_nr = Byte.Parse(cbBlockInSectorSectorNrAKM1.Text); - - block_nr = Byte.Parse(cbBlockInSectorBlockNrAKM1.Text); - - status = (UInt32)uFCoder.BlockInSectorRead_AKM1(block_data, sector_nr, block_nr, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - - private void btnBlockInSectorReadAKM2_Click(object sender, EventArgs e) - { - //AKM2 - DL_STATUS status; - byte[] block_data = new byte[16]; - byte sector_nr = 0, block_nr = 0, auth_mode = 0; - byte dl_card_type = 0; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbBlockInSectorReadKeyAAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - } - else if (rbBlockInSectorReadKeyBAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - sector_nr = Byte.Parse(cbBlockInSectorSectorNrAKM2.Text); - - block_nr = Byte.Parse(cbBlockInSectorBlockNrAKM2.Text); - - status = (UInt32)uFCoder.BlockInSectorRead_AKM2(block_data, sector_nr, block_nr, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Block read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block read was successful.\nBlock data: "; - txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnLinearReadPK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] linear_data = new byte[3440]; - byte[] sector_key = new byte[16]; - ushort linear_address = 0, linear_length = 0, ret_bytes = 0; - byte dl_card_type = 0, auth_mode = 0; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - - if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) - { - if (txtLinearReadKeyPK.TextLength != 12) - { - txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; - return; - } - - sector_key = StringToByteArray(txtLinearReadKeyPK.Text); - - if (rbLinearReadKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbLinearReadKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - } - else - { - if (txtLinearReadKeyPK.TextLength != 32) - { - txtStatus.Text = "This card uses AES key that should be 16 bytes long"; - return; - } - - sector_key = StringToByteArray(txtLinearReadKeyPK.Text); - - if (rbLinearReadKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; - } - else if (rbLinearReadKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; - } - } - - linear_address = Convert.ToUInt16(txtLinearAddressPK.Text); - - linear_length = Convert.ToUInt16(txtBytesForReadPK.Text); - - status = (UInt32)uFCoder.LinearRead_PK(linear_data, linear_address, linear_length, out ret_bytes, auth_mode, sector_key); - - if (status > 0) - { - txtStatus.Text = "Linear read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Linear read was successful.\nBlock data: "; - - byte[] write_data = new byte[ret_bytes]; - - Array.Copy(linear_data, write_data, ret_bytes); - - txtStatus.Text += BitConverter.ToString(write_data).Replace("-", ":"); - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnLinearReadRK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] linear_data = new byte[3440]; - byte sector_key_index = 0; - ushort linear_address = 0, linear_length = 0, ret_bytes = 0; - byte dl_card_type = 0, auth_mode = 0; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbLinearReadKeyARK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbLinearReadKeyBRK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - sector_key_index = Byte.Parse(cbLinearReadReaderKeyRK.Text); - - linear_address = Convert.ToUInt16(txtLinearAddressRK.Text); - - linear_length = Convert.ToUInt16(txtBytesForReadRK.Text); - - status = (UInt32)uFCoder.LinearRead(linear_data, linear_address, linear_length, out ret_bytes, auth_mode, sector_key_index); - - if (status > 0) - { - txtStatus.Text = "Linear read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Linear read was successful.\nBlock data: "; - - byte[] write_data = new byte[ret_bytes]; - - Array.Copy(linear_data, write_data, ret_bytes); - - txtStatus.Text += BitConverter.ToString(write_data).Replace("-", ":"); - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnLinearReadAKM1_Click(object sender, EventArgs e) - { - //AKM1 - - DL_STATUS status; - byte[] linear_data = new byte[3440]; - ushort linear_address = 0, linear_length = 0, ret_bytes = 0; - byte dl_card_type = 0, auth_mode = 0; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbLinearReadKeyAAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbLinearReadKeyBAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - linear_address = Convert.ToUInt16(txtLinearAddressAKM1.Text); - - linear_length = Convert.ToUInt16(txtBytesForReadAKM1.Text); - - status = (UInt32)uFCoder.LinearRead_AKM1(linear_data, linear_address, linear_length, out ret_bytes, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Linear read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Linear read was successful.\nBlock data: "; - - byte[] write_data = new byte[ret_bytes]; - - Array.Copy(linear_data, write_data, ret_bytes); - - txtStatus.Text += BitConverter.ToString(write_data).Replace("-", ":"); - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - private void btnLinearReadAKM2_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] linear_data = new byte[3440]; - ushort linear_address = 0, linear_length = 0, ret_bytes = 0; - byte dl_card_type = 0, auth_mode = 0; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbLinearReadKeyAAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbLinearReadKeyBAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - linear_address = Convert.ToUInt16(txtLinearAddressAKM2.Text); - - linear_length = Convert.ToUInt16(txtBytesForReadAKM2.Text); - - status = (UInt32)uFCoder.LinearRead_AKM2(linear_data, linear_address, linear_length, out ret_bytes, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Linear read was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Linear read was successful.\nBlock data: "; - - byte[] write_data = new byte[ret_bytes]; - - Array.Copy(linear_data, write_data, ret_bytes); - - txtStatus.Text += BitConverter.ToString(write_data).Replace("-", ":"); - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnBlockWritePK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0, auth_mode = 0, block_nr = 0; - byte[] sector_key = new byte[16]; - byte[] block_data = new byte[16]; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) - { - if (txtBlockWriteKeyPK.TextLength != 12) - { - txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; - return; - } - - sector_key = StringToByteArray(txtBlockWriteKeyPK.Text); - - if (rbBlockWriteKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbBlockWriteKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - } - else - { - if (txtBlockWriteKeyPK.TextLength != 32) - { - txtStatus.Text = "This card uses AES key that should be 16 bytes long"; - return; - } - - sector_key = StringToByteArray(txtBlockWriteKeyPK.Text); - - if (rbBlockWriteKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; - } - else if (rbBlockWriteKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; - } - } - - - if (txtBlockData.TextLength > 32 || txtBlockData.TextLength < 1) - { - txtStatus.Text = "Data for Block Write must be max 16 bytes long"; - return; - } - - block_data = StringToByteArray(txtBlockData.Text); - - block_nr = Byte.Parse(cbBlockWriteBlockNrPK.Text); - - - status = (UInt32)uFCoder.BlockWrite_PK(block_data, block_nr, auth_mode, sector_key); - - if (status > 0) - { - txtStatus.Text = "Block write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - private void btnBlockWriteRK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0, auth_mode = 0, block_nr = 0; - byte key_nr = 0; - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbBlockWriteKeyARK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbBlockWriteKeyBRK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - if (txtBlockData.TextLength > 32 || txtBlockData.TextLength < 1) - { - txtStatus.Text = "Data for Block Write must be max 16 bytes long"; - return; - } - - block_data = StringToByteArray(txtBlockData.Text); - - block_nr = Byte.Parse(cbBlockWriteBlockNrRK.Text); - - key_nr = Byte.Parse(cbBlockWriteKeyIndexRK.Text); - - status = (UInt32)uFCoder.BlockWrite(block_data, block_nr, auth_mode, key_nr); - - if (status > 0) - { - txtStatus.Text = "Block write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - private void btnBlockWriteAKM1_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0, auth_mode = 0, block_nr = 0; - - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbBlockWriteKeyAAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbBlockWriteKeyBAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - if (txtBlockData.TextLength > 32 || txtBlockData.TextLength < 1) - { - txtStatus.Text = "Data for Block Write must be max 16 bytes long"; - return; - } - - block_data = StringToByteArray(txtBlockData.Text); - - block_nr = Byte.Parse(cbBlockWriteBlockNrAKM1.Text); - - status = (UInt32)uFCoder.BlockWrite_AKM1(block_data, block_nr, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Block write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnBlockWriteAKM2_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0, auth_mode = 0, block_nr = 0; - - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbBlockWriteKeyAAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbBlockWriteKeyBAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - if (txtBlockData.TextLength > 32 || txtBlockData.TextLength < 1) - { - txtStatus.Text = "Data for Block Write must be max 16 bytes long"; - return; - } - - block_data = StringToByteArray(txtBlockData.Text); - - block_nr = Byte.Parse(cbBlockWriteBlockNrAKM2.Text); - - status = (UInt32)uFCoder.BlockWrite_AKM2(block_data, block_nr, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Block write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnBlockInSectorWritePK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0, auth_mode = 0, block_nr = 0, sector_nr = 0; - byte[] sector_key = new byte[16]; - byte[] block_data = new byte[16]; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) - { - if (txtBlockInSectorWriteKeyPK.TextLength != 12) - { - txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; - return; - } - - sector_key = StringToByteArray(txtBlockInSectorWriteKeyPK.Text); - - if (rbBlockInSectorWriteKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbBlockInSectorWriteKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - } - else - { - if (txtBlockInSectorWriteKeyPK.TextLength != 32) - { - txtStatus.Text = "This card uses AES key that should be 16 bytes long"; - return; - } - - sector_key = StringToByteArray(txtBlockInSectorWriteKeyPK.Text); - - if (rbBlockInSectorWriteKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; - } - else if (rbBlockInSectorWriteKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; - } - } - - - if (txtBlockInSectorData.TextLength > 32 || txtBlockInSectorData.TextLength < 1) - { - txtStatus.Text = "Data for Block in sector Write must be max 16 bytes long"; - return; - } - - block_data = StringToByteArray(txtBlockInSectorData.Text); - - block_nr = Byte.Parse(cbBlockInSectorWriteBlockNrPK.Text); - - sector_nr = Byte.Parse(cbBlockInSectorWriteSectorNrPK.Text); - - - status = (UInt32)uFCoder.BlockInSectorWrite_PK(block_data, sector_nr, block_nr, auth_mode, sector_key); - - if (status > 0) - { - txtStatus.Text = "Block in sector write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block in sector write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - private void btnBlockInSectorWriteRK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0, auth_mode = 0, block_nr = 0, sector_nr = 0; - byte key_nr = 0; - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbBlockInSectorWriteKeyARK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbBlockInSectorWriteKeyBRK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - if (txtBlockInSectorData.TextLength > 32 || txtBlockInSectorData.TextLength < 1) - { - txtStatus.Text = "Data for Block in sector Write must be max 16 bytes long"; - return; - } - - block_data = StringToByteArray(txtBlockInSectorData.Text); - - sector_nr = Byte.Parse(cbBlockInSectorWriteSectorNrRK.Text); - - block_nr = Byte.Parse(cbBlockInSectorWriteBlockNrRK.Text); - - key_nr = Byte.Parse(cbBlockInSectorWriteKeyIndexRK.Text); - - status = (UInt32)uFCoder.BlockInSectorWrite(block_data, sector_nr, block_nr, auth_mode, key_nr); - - if (status > 0) - { - txtStatus.Text = "Block in sector write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block in sector write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - - } - - private void btnBlockInSectorWriteAKM1_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0, auth_mode = 0, block_nr = 0, sector_nr = 0; - - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbBlockInSectorWriteKeyAAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbBlockInSectorWriteKeyBAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - if (txtBlockInSectorData.TextLength > 32 || txtBlockInSectorData.TextLength < 1) - { - txtStatus.Text = "Data for Block in sector Write must be max 16 bytes long"; - return; - } - - block_data = StringToByteArray(txtBlockInSectorData.Text); - - sector_nr = Byte.Parse(cbBlockInSectorWriteSectorNrAKM1.Text); - - block_nr = Byte.Parse(cbBlockInSectorWriteBlockNrAKM1.Text); - - status = (UInt32)uFCoder.BlockInSectorWrite_AKM1(block_data, sector_nr, block_nr, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Block in sector write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block in sector write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnBlockInSectorWriteAKM2_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte dl_card_type = 0, auth_mode = 0, block_nr = 0, sector_nr = 0; - - byte[] block_data = new byte[16]; - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbBlockInSectorWriteKeyAAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbBlockInSectorWriteKeyBAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - if (txtBlockInSectorData.TextLength > 32 || txtBlockInSectorData.TextLength < 1) - { - txtStatus.Text = "Data for Block in sector Write must be max 16 bytes long"; - return; - } - - block_data = StringToByteArray(txtBlockInSectorData.Text); - - sector_nr = Byte.Parse(cbBlockInSectorWriteSectorNrAKM2.Text); - - block_nr = Byte.Parse(cbBlockInSectorWriteBlockNrAKM2.Text); - - status = (UInt32)uFCoder.BlockInSectorWrite_AKM1(block_data, sector_nr, block_nr, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Block in sector write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Block in sector write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnLinearWritePK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] linear_data = new byte[3440]; - byte[] sector_key = new byte[16]; - ushort linear_address = 0, linear_length = 0, ret_bytes = 0; - byte dl_card_type = 0, auth_mode = 0; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - - if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) - { - if (txtLinearWriteKeyPK.TextLength != 12) - { - txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; - return; - } - - sector_key = StringToByteArray(txtLinearWriteKeyPK.Text); - - if (rbLinearWriteKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbLinearWriteKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - } - else - { - if (txtLinearWriteKeyPK.TextLength != 32) - { - txtStatus.Text = "This card uses AES key that should be 16 bytes long"; - return; - } - - sector_key = StringToByteArray(txtLinearWriteKeyPK.Text); - - if (rbLinearWriteKeyAPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; - } - else if (rbLinearWriteKeyBPK.Checked) - { - auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; - } - } - - linear_address = Convert.ToUInt16(txtLinearWriteAddressPK.Text); - - linear_data = StringToByteArray(txtLinearWriteData.Text); - - linear_length = Convert.ToUInt16(linear_data.Length); - - status = (UInt32)uFCoder.LinearWrite_PK(linear_data, linear_address, linear_length, out ret_bytes, auth_mode, sector_key); - - if (status > 0) - { - txtStatus.Text = "Linear write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Linear write was successful."; - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnLinearWriteRK_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] linear_data = new byte[3440]; - byte sector_key_index = 0; - ushort linear_address = 0, linear_length = 0, ret_bytes = 0; - byte dl_card_type = 0, auth_mode = 0; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbLinearWriteKeyARK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbLinearWriteKeyBRK.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - linear_data = StringToByteArray(txtLinearWriteData.Text); - - sector_key_index = Byte.Parse(cbLinearWriteKeyIndexRK.Text); - - linear_address = Convert.ToUInt16(txtLinearWriteAddressRK.Text); - - linear_length = Convert.ToUInt16(txtLinearWriteData.TextLength); - - status = (UInt32)uFCoder.LinearWrite(linear_data, linear_address, linear_length, out ret_bytes, auth_mode, sector_key_index); - - if (status > 0) - { - txtStatus.Text = "Linear write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Linear write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnLinearWriteAKM1_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] linear_data = new byte[3440]; - - ushort linear_address = 0, linear_length = 0, ret_bytes = 0; - byte dl_card_type = 0, auth_mode = 0; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbLinearWriteKeyAAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbLinearWriteKeyBAKM1.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - linear_data = StringToByteArray(txtLinearWriteData.Text); - - linear_address = Convert.ToUInt16(txtLinearWriteAddressAKM1.Text); - - linear_length = Convert.ToUInt16(txtLinearWriteData.TextLength); - - status = (UInt32)uFCoder.LinearWrite_AKM1(linear_data, linear_address, linear_length, out ret_bytes, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Linear write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Linear write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); - } - - private void btnLinearWriteAKM2_Click(object sender, EventArgs e) - { - DL_STATUS status; - byte[] linear_data = new byte[3440]; - - ushort linear_address = 0, linear_length = 0, ret_bytes = 0; - byte dl_card_type = 0, auth_mode = 0; - - - status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); - - if (status > 0) - { - txtStatus.Text = "Communication with card failed."; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || - ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) - { - txtStatus.Text = "Card is not in security level 1 or 3 mode"; - return; - } - - if (rbLinearWriteKeyAAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; - - } - else if (rbLinearWriteKeyBAKM2.Checked) - { - auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; - } - - linear_data = StringToByteArray(txtLinearWriteData.Text); - - linear_address = Convert.ToUInt16(txtLinearWriteAddressAKM2.Text); - - linear_length = Convert.ToUInt16(txtLinearWriteData.TextLength); - - status = (UInt32)uFCoder.LinearWrite_AKM2(linear_data, linear_address, linear_length, out ret_bytes, auth_mode); - - if (status > 0) - { - txtStatus.Text = "Linear write was NOT successful"; - toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - return; - } - - txtStatus.Text = "Linear write was successful. "; - - toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using uFR; + + + +namespace mifare_plus_c_sharp +{ + + using DL_STATUS = System.UInt32; + + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + + + public static byte[] StringToByteArray(string hex) + { + return Enumerable.Range(0, hex.Length) + .Where(x => x % 2 == 0) + .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) + .ToArray(); + } + + private void timer2_Tick(object sender, EventArgs e) + { + DL_STATUS status = 0; + + byte cardtype_val = 0, sak = 0, uid_size = 0; + byte[] uid = new byte[10]; + + status = (UInt32)uFCoder.GetDlogicCardType(out cardtype_val); + + if (status > 0) + { + //toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + txtCardType.Text = uFCoder.status2str((uFR.DL_STATUS)status); + txtCardUID.Text = BitConverter.ToString(uid).Replace("-", ":"); + return; + } + + txtCardType.Text = Enum.GetName(typeof(DLOGIC_CARD_TYPE), cardtype_val); + + status = (UInt32)uFCoder.GetCardIdEx(out sak, uid, out uid_size); + + txtCardUID.Text = BitConverter.ToString(uid).Replace("-", ":"); + + //toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + + + + private void btnPersonalizeCard_Click(object sender, EventArgs e) + { + DL_STATUS status; + + byte[] master_key = new byte[16]; + byte[] config_key = new byte[16]; + byte[] l2_sw_key = new byte[16]; + byte[] l3_sw_key = new byte[16]; + byte[] l1_auth_key = new byte[16]; + byte[] sel_vc_key = new byte[16]; + byte[] prox_chk_key = new byte[16]; + byte[] vc_poll_enc_key = new byte[16]; + byte[] vc_poll_mac_key = new byte[16]; + byte dl_card_type = 0; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "No card in RF field found for Personalization"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + //check if card type S in SL0 + if (!((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL0 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_X_4K_SL0)) + { + txtStatus.Text = "Card is not in security level 0 mode."; + return; + } + + /* if (dl_card_type == DL_MIFARE_PLUS_S_2K_SL0 || dl_card_type == DL_MIFARE_PLUS_S_4K_SL0) + { + } */ + + if (txtPersonalizeCardMasterKey.TextLength != 32) + { + txtStatus.Text = "Master key must be 16 bytes long!"; + return; + } + + if (txtPersonalizeConfigurationKey.TextLength != 32) + { + txtStatus.Text = "Card configuration key must be 16 bytes long!"; + return; + } + + if (txtPersonalizeLevel2Key.TextLength != 32) + { + txtStatus.Text = "Level 2 switch key must be 16 bytes long!"; + return; + } + + if (txtPersonalizeLevel3Key.TextLength != 32) + { + txtStatus.Text = "Level 3 switch key must be 16 bytes long!"; + return; + } + + if (txtPersonalizeLevel1Key.TextLength != 32) + { + txtStatus.Text = "SL1 card authentication key must be 16 bytes long!"; + return; + } + + if ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_X_2K_SL0 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_X_4K_SL0) + { + if (txtPersonalizeSelectVCKey.TextLength != 32) + { + txtStatus.Text = "Select VC key must be 16 bytes long!"; + return; + } + + if (txtPersonalizeProximityCheckKey.TextLength != 32) + { + txtStatus.Text = "Proximity check key must be 16 bytes long!"; + return; + } + } + + if (txtPersonalizeVCENCKey.TextLength != 32) + { + txtStatus.Text = "VC polling ENC key key must be 16 bytes long!"; + return; + } + + if (txtPersonalizeVCMACKey.TextLength != 32) + { + txtStatus.Text = "VC polling MAC key key must be 16 bytes long!"; + return; + } + + + // StringToByteArray(AESkeyTB.Text); + + master_key = StringToByteArray(txtPersonalizeCardMasterKey.Text); + + config_key = StringToByteArray(txtPersonalizeConfigurationKey.Text); + + l1_auth_key = StringToByteArray(txtPersonalizeLevel1Key.Text); + + l2_sw_key = StringToByteArray(txtPersonalizeLevel2Key.Text); + + l3_sw_key = StringToByteArray(txtPersonalizeLevel3Key.Text); + + sel_vc_key = StringToByteArray(txtPersonalizeSelectVCKey.Text); + + prox_chk_key = StringToByteArray(txtPersonalizeProximityCheckKey.Text); + + vc_poll_enc_key = StringToByteArray(txtPersonalizeVCENCKey.Text); + + vc_poll_mac_key = StringToByteArray(txtPersonalizeVCMACKey.Text); + + + status = (UInt32)uFCoder.MFP_PersonalizationMinimal(master_key, config_key, l2_sw_key, l3_sw_key, l1_auth_key, + sel_vc_key, prox_chk_key, vc_poll_enc_key, vc_poll_mac_key); + + if (status > 0) + { + txtStatus.Text = "Card personalization was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Card personalization successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnAuthSL1_Click(object sender, EventArgs e) + { + DL_STATUS status; + + byte[] sl1_auth_key = new byte[16]; + + byte key_index = 0; + + if (rbChangeAuthPK.Checked) + { + if (txtAuthSL1AuthKey.TextLength != 32) + { + txtStatus.Text = "SL1 card authentication key must be 16 bytes long"; + return; + } + + sl1_auth_key = StringToByteArray(txtAuthSL1AuthKey.Text); + status = (UInt32)uFCoder.MFP_AesAuthSecurityLevel1_PK(sl1_auth_key); + + if (status > 0) + { + txtStatus.Text = "AES authentication on SL1 was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "AES authentication on SL1 successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + else + { + key_index = Byte.Parse(cbAuthSL1ReaderKeyIndex.Text); + + status = (UInt32)uFCoder.MFP_AesAuthSecurityLevel1(key_index); + + if (status > 0) + { + txtStatus.Text = "AES authentication on SL1 was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "AES authentication on SL1 successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + } + + private void btnSwitchSL3_Click(object sender, EventArgs e) + { + DL_STATUS status; + + byte[] sl3_sw_key = new byte[16]; + byte key_index = 0; + + if (rbChangeAuthPK.Checked) + { + if (txtSwitchSL3AESkey.TextLength != 32) + { + txtStatus.Text = "Level 3 switch key must be 16 bytes long"; + return; + } + + sl3_sw_key = StringToByteArray(txtSwitchSL3AESkey.Text); + + status = (UInt32)uFCoder.MFP_SwitchToSecurityLevel3_PK(sl3_sw_key); + + if (status > 0) + { + txtStatus.Text = "Switch to SL3 was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Switch to SL3 successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + else + { + key_index = Byte.Parse(cbSwitchSL3ReaderKeyIndex.Text); + + status = (UInt32)uFCoder.MFP_SwitchToSecurityLevel3(key_index); + + if (status > 0) + { + txtStatus.Text = "Switch to SL3 was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Switch to SL3 successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + } + + private void btnChangeMasterKey_Click(object sender, EventArgs e) + { + DL_STATUS status; + + byte[] old_master_key = new byte[16]; + byte[] new_master_key = new byte[16]; + byte key_index = 0; + + if (rbChangeAuthPK.Checked) + { + if (txtChangeMasterOldKey.TextLength != 32) + { + txtStatus.Text = "Old master key must be 16 bytes long"; + return; + } + + if (txtChangeMasterNewKey.TextLength != 32) + { + txtStatus.Text = "New master key must be 16 bytes long"; + return; + } + + old_master_key = StringToByteArray(txtChangeMasterOldKey.Text); + + new_master_key = StringToByteArray(txtChangeMasterNewKey.Text); + + status = (UInt32)uFCoder.MFP_ChangeMasterKey_PK(old_master_key, new_master_key); + + if (status > 0) + { + txtStatus.Text = "Master key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Master key change successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + else + { + if (txtChangeMasterNewKeyRK.TextLength != 32) + { + txtStatus.Text = "New master key must be 16 bytes long"; + return; + } + + new_master_key = StringToByteArray(txtChangeMasterNewKeyRK.Text); + + key_index = Byte.Parse(cbChangeMasterReaderKeyIndex.Text); + + status = (UInt32)uFCoder.MFP_ChangeMasterKey(key_index, new_master_key); + + if (status > 0) + { + txtStatus.Text = "Master key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Master key change successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + } + + private void btnChangeConfigurationKey_Click(object sender, EventArgs e) + { + DL_STATUS status; + + byte[] old_config_key = new byte[16]; + byte[] new_config_key = new byte[16]; + byte key_index = 0; + + if (rbChangeAuthPK.Checked) + { + if (txtChangeMasterOldKey.TextLength != 32) + { + txtStatus.Text = "Old configuration key must be 16 bytes long"; + return; + } + + if (txtChangeMasterNewKey.TextLength != 32) + { + txtStatus.Text = "New configuration key must be 16 bytes long"; + return; + } + + old_config_key = StringToByteArray(txtChangeConfigOldKey.Text); + + new_config_key = StringToByteArray(txtChangeConfigNewKey.Text); + + status = (UInt32)uFCoder.MFP_ChangeConfigurationKey_PK(old_config_key, new_config_key); + + if (status > 0) + { + txtStatus.Text = "Configuration key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Configuration key change successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + else + { + if (txtChangeConfigNewKeyRK.TextLength != 32) + { + txtStatus.Text = "New configuration key must be 16 bytes long"; + return; + } + + new_config_key = StringToByteArray(txtChangeConfigNewKeyRK.Text); + + key_index = Byte.Parse(cbChangeMasterReaderKeyIndex.Text); + + status = (UInt32)uFCoder.MFP_ChangeConfigurationKey(key_index, new_config_key); + + if (status > 0) + { + txtStatus.Text = "Configuration key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Configuration key change successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + } + + private void btnChangeAESSectorKey_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] old_sector_key = new byte[16]; + byte[] new_sector_key = new byte[16]; + byte key_index = 0, sector_nr = 0, auth_mode = 0; + + sector_nr = Byte.Parse(cbChangeSectorSectorNumber.Text); + + if (rbChangeSectorKeyA.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; + } + else if (rbChangeSectorKeyB.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; + } + else + { + txtStatus.Text = "You should select settings AES KEY A or B"; + return; + } + + if (rbChangeAuthPK.Checked) + { + if (txtChangeSectorOldKey.TextLength != 32) + { + txtStatus.Text = "Old sector key must be 16 bytes long"; + return; + } + + if (txtChangeSectorNewKey.TextLength != 32) + { + txtStatus.Text = "New sector key must be 16 bytes long"; + return; + } + + old_sector_key = StringToByteArray(txtChangeSectorOldKey.Text); + + new_sector_key = StringToByteArray(txtChangeSectorNewKey.Text); + + status = (UInt32)uFCoder.MFP_ChangeSectorKey_PK(sector_nr, auth_mode, old_sector_key, new_sector_key); + + if (status > 0) + { + txtStatus.Text = "Sector key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Sector key change successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + else if (rbChangeAuthRK.Checked) + { + if (txtChangeSectorNewKeyRK.TextLength != 32) + { + txtStatus.Text = "New sector key must be 16 bytes long"; + return; + } + + new_sector_key = StringToByteArray(txtChangeConfigNewKeyRK.Text); + + key_index = Byte.Parse(cbChangeSectorKeyReaderIndex.Text); + + status = (UInt32)uFCoder.MFP_ChangeSectorKey(sector_nr, auth_mode, key_index, new_sector_key); + + if (status > 0) + { + txtStatus.Text = "Sector key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Sector key change successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + } + + private void btnFieldConfigurationSet_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] config_key = new byte[16]; + byte key_index = 0, rid_use = 0, prox_check_use = 0; + + //Proximity check for X and EV1 card is not implemented yet + prox_check_use = 0; + + //setting usage of random id or uid + if (rbFieldConfigUseRandomID.Checked) + { + rid_use = 1; + } + else if (rbFieldConfigUseUID.Checked) + { + rid_use = 0; + } + + if (rbChangeAuthPK.Checked) + { + + if (txtFieldConfigKey.TextLength != 32) + { + txtStatus.Text = "Field configuration key must be 16 bytes long"; + return; + } + + config_key = StringToByteArray(txtFieldConfigKey.Text); + + status = (UInt32)uFCoder.MFP_FieldConfigurationSet_PK(config_key, rid_use, prox_check_use); + + if (status > 0) + { + txtStatus.Text = "Field configuration set was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Field configuration set successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + else if (rbChangeAuthRK.Checked) + { + key_index = Byte.Parse(cbFieldConfigReaderKeyIndex.Text); + + status = (UInt32)uFCoder.MFP_FieldConfigurationSet(key_index, rid_use, prox_check_use); + + if (status > 0) + { + txtStatus.Text = "Field configuration set was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Field configuration set successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + } + + private void btnGetCardUID_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] vc_enc_key = new byte[16]; + byte[] vc_mac_key = new byte[16]; + byte key_index_enc = 0, key_index_mac = 0, uid_len = 0; + byte[] uid = new byte[10]; + + if (rbChangeAuthPK.Checked) + { + if (txtGetCardUIDENCKey.TextLength != 32) + { + txtStatus.Text = "VC polling ENC key must be 16 bytes long"; + return; + } + + if (txtGetCardUIDMACKey.TextLength != 32) + { + txtStatus.Text = "VC polling MAC key must be 16 bytes long"; + return; + } + + vc_enc_key = StringToByteArray(txtGetCardUIDENCKey.Text); + + vc_mac_key = StringToByteArray(txtGetCardUIDMACKey.Text); + + status = (UInt32)uFCoder.MFP_GetUid_PK(vc_enc_key, vc_mac_key, uid, out uid_len); + + if (status > 0) + { + txtStatus.Text = "Get UID was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + txtStatus.Text = "Get UID was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + txtUID_Get.Text = BitConverter.ToString(uid).Replace("-", ":"); + + } + else if (rbChangeAuthRK.Checked) + { + key_index_enc = Byte.Parse(cbGetCardUIDENCKeyRK.Text); + + key_index_mac = Byte.Parse(cbGetCardUIDMACKeyRK.Text); + + status = (UInt32)uFCoder.MFP_GetUid(key_index_enc, key_index_mac, uid, out uid_len); + + if (status > 0) + { + txtStatus.Text = "Get UID was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + txtStatus.Text = "Get UID was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + txtUID_Get.Text = BitConverter.ToString(uid).Replace("-", ":"); + + } + } + + private void btnChangeVCPollingENCKey_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] config_key = new byte[16]; + byte[] new_vc_enc_key = new byte[16]; + byte key_index = 0; + + if (rbChangeAuthPK.Checked) + { + if (txtChangeVCPollingENCConfigKey.TextLength != 32) + { + txtStatus.Text = "Card configuration key must be 16 bytes long"; + return; + } + + if (txtChangeVCPollingENCNewKey.TextLength != 32) + { + txtStatus.Text = "New VC polling ENC key must be 16 bytes long"; + return; + } + + config_key = StringToByteArray(txtChangeVCPollingENCConfigKey.Text); + + new_vc_enc_key = StringToByteArray(txtChangeVCPollingENCNewKey.Text); + + status = (UInt32)uFCoder.MFP_ChangeVcPollingEncKey_PK(config_key, new_vc_enc_key); + + if (status > 0) + { + txtStatus.Text = "VC polling ENC key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "VC polling ENC key change was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + else if (rbChangeAuthRK.Checked) + { + key_index = Byte.Parse(cbChangeVCPollingENCReaderKeyIndex.Text); + + if (txtChangeVCPollingENCNewKeyRK.TextLength != 32) + { + txtStatus.Text = "New VC polling ENC key must be 16 bytes long"; + return; + } + + new_vc_enc_key = StringToByteArray(txtChangeVCPollingENCNewKeyRK.Text); + + status = (UInt32)uFCoder.MFP_ChangeVcPollingEncKey(key_index, new_vc_enc_key); + + if (status > 0) + { + txtStatus.Text = "VC polling ENC key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "VC polling ENC key change was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + } + + private void btnChangeVCPollingMACKey_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] config_key = new byte[16]; + byte[] new_vc_mac_key = new byte[16]; + byte key_index = 0; + + if (rbChangeAuthPK.Checked) + { + if (txtChangeVCPollingMACConfigKey.TextLength != 32) + { + txtStatus.Text = "Card configuration key must be 16 bytes long"; + return; + } + + if (txtChangeVCPollingMACNewKey.TextLength != 32) + { + txtStatus.Text = "New VC polling MAC key must be 16 bytes long"; + return; + } + + config_key = StringToByteArray(txtChangeVCPollingMACConfigKey.Text); + + new_vc_mac_key = StringToByteArray(txtChangeVCPollingMACNewKey.Text); + + status = (UInt32)uFCoder.MFP_ChangeVcPollingMacKey_PK(config_key, new_vc_mac_key); + + if (status > 0) + { + txtStatus.Text = "VC polling MAC key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "VC polling MAC key change was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + else if (rbChangeAuthRK.Checked) + { + key_index = Byte.Parse(cbChangeVCPollingMACReaderKeyIndex.Text); + + if (txtChangeVCPollingMACNewKeyRK.TextLength != 32) + { + txtStatus.Text = "New VC polling MAC key must be 16 bytes long"; + return; + } + + new_vc_mac_key = StringToByteArray(txtChangeVCPollingMACNewKeyRK.Text); + + status = (UInt32)uFCoder.MFP_ChangeVcPollingMacKey(key_index, new_vc_mac_key); + + if (status > 0) + { + txtStatus.Text = "VC polling MAC key change was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "VC polling MAC key change was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + } + + private void btnCrypto1KeyInput_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] crypto_key = new byte[6]; + byte key_index = 0; + + if (txtCrypto1Key.TextLength != 12) + { + txtStatus.Text = "Crypto key must be 6 bytes long"; + return; + } + + crypto_key = StringToByteArray(txtCrypto1Key.Text); + + key_index = Byte.Parse(cbCrpytoReaderIndex.Text); + + status = (UInt32)uFCoder.ReaderKeyWrite(crypto_key, key_index); + if (status > 0) + { + txtStatus.Text = "CRYPTO 1 key writing was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "CRYPTO 1 key writing was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + + } + + private void btnAesKeyInput_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] aes_key = new byte[16]; + byte key_index = 0; + + if (txtAESKey.TextLength != 32) + { + txtStatus.Text = "AES key must be 16 bytes long"; + return; + } + + aes_key = StringToByteArray(txtAESKey.Text); + + key_index = Byte.Parse(cbAESIndex.Text); + + status = (UInt32)uFCoder.uFR_int_DesfireWriteAesKey(key_index, aes_key); + + if (status > 0) + { + txtStatus.Text = "AES key writing was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "AES key writing was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnUnlockReader_Click(object sender, EventArgs e) + { + DL_STATUS status; + String password = ""; + + if (txtUnlockPassword.TextLength != 8) + { + txtStatus.Text = "Password must be 8 characters long"; + return; + } + + password = txtUnlockPassword.Text; + + status = (UInt32)uFCoder.ReaderKeysUnlock(password.ToCharArray()); + + if (status > 0) + { + txtStatus.Text = "Reader unlocking was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Reader unlocking was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + + } + + private void btnLockReader_Click(object sender, EventArgs e) + { + DL_STATUS status; + String password = ""; + + if (txtLockPassword.TextLength != 8) + { + txtStatus.Text = "Password must be 8 characters long"; + return; + } + + password = txtLockPassword.Text; + + status = (UInt32)uFCoder.ReaderKeysLock(password.ToCharArray()); + + if (status > 0) + { + txtStatus.Text = "Reader locking was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Reader locking was successful"; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void TabPage6_Click(object sender, EventArgs e) + { + + } + + private void btnBlockReadPK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0; + byte auth_mode = 0, block_address = 0; + byte[] crypto_key = new byte[6]; + byte[] aes_key = new byte[16]; + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + //Using AES or CRYPTO key depending on following check of card type + + if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) + { + //" (1) - Provided CRYPTO 1 key\n PK" + if (rbBlockReadKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; // auth mode check + + } + else if (rbBlockReadKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + if (txtBlockReadKeyPK.TextLength != 12) + { + txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; + return; + } + + crypto_key = StringToByteArray(txtBlockReadKeyPK.Text); + + block_address = Byte.Parse(cbBlockReadBlockNrPK.Text); + + status = (UInt32)uFCoder.BlockRead_PK(block_data, block_address, auth_mode, crypto_key); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + else + { + //" (2) - Provided AES key\n PK" + if (rbBlockReadKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; // auth mode check + } + else if (rbBlockReadKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; + } + + if (txtBlockReadKeyPK.TextLength != 32) + { + txtStatus.Text = "This card uses AES key that should be 16 bytes long"; + return; + } + + aes_key = StringToByteArray(txtBlockReadKeyPK.Text); + + block_address = Byte.Parse(cbBlockReadBlockNrPK.Text); + + status = (UInt32)uFCoder.BlockRead_PK(block_data, block_address, auth_mode, aes_key); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + } + + private void btnBlockReadRK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0; + byte auth_mode = 0, block_address = 0; + byte crypto_key_nr = 0; + byte aes_key_nr = 0; + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + //Using AES or CRYPTO key depending on following check of card type + + if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) + { + //" (1) - Reader CRYPTO 1 key\n RK" + if (rbBlockReadKeyARK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; // auth mode check + + } + else if (rbBlockReadKeyBRK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + crypto_key_nr = Byte.Parse(cbBlockReadKeyRK.Text); + + block_address = Byte.Parse(cbBlockReadBlockNrRK.Text); + + status = (UInt32)uFCoder.BlockRead(block_data, block_address, auth_mode, crypto_key_nr); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + else + { + //" (2) - Reader AES key\n RK" + if (rbBlockReadKeyARK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; ; // auth mode check + } + else if (rbBlockReadKeyBRK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + aes_key_nr = Byte.Parse(cbBlockReadKeyRK.Text); + + block_address = Byte.Parse(cbBlockReadBlockNrRK.Text); + + status = (UInt32)uFCoder.BlockRead(block_data, block_address, auth_mode, aes_key_nr); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + } + + private void btnBlockReadAKM1_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0; + byte auth_mode = 0, block_address = 0; + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + //" (1) - Provided CRYPTO 1 key\n AKM1" + if (rbBlockReadKeyAAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; // auth mode check + + } + else if (rbBlockReadKeyBAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + block_address = Byte.Parse(cbBlockReadBlockNrAKM1.Text); + + status = (UInt32)uFCoder.BlockRead_AKM1(block_data, block_address, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnBlockReadAKM2_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0; + byte auth_mode = 0, block_address = 0; + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + ////////////////AKM2/////////////////////" + if (rbBlockReadKeyAAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; // auth mode check + + } + else if (rbBlockReadKeyBAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + block_address = Byte.Parse(cbBlockReadBlockNrAKM2.Text); + + status = (UInt32)uFCoder.BlockRead_AKM2(block_data, block_address, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + + private void btnBlockInSectorReadPK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] block_data = new byte[16]; + byte[] sector_key = new byte[16]; + byte sector_nr = 0, block_nr = 0, auth_mode = 0; + byte dl_card_type = 0; + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) + { + if (txtBlockInSectorReadKeyPK.TextLength != 12) + { + txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; + return; + } + + sector_key = StringToByteArray(txtBlockInSectorReadKeyPK.Text); + + if (rbBlockInSectorReadKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbBlockInSectorReadKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + } + else + { + if (txtBlockInSectorReadKeyPK.TextLength != 32) + { + txtStatus.Text = "This card uses AES key that should be 16 bytes long"; + return; + } + + sector_key = StringToByteArray(txtBlockInSectorReadKeyPK.Text); + + if (rbBlockInSectorReadKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; + } + else if (rbBlockInSectorReadKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; + } + } + + sector_nr = Byte.Parse(cbBlockInSectorSectorNrPK.Text); + + block_nr = Byte.Parse(cbBlockInSectorBlockNrPK.Text); + + + status = (UInt32)uFCoder.BlockInSectorRead_PK(block_data, sector_nr, block_nr, auth_mode, sector_key); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + private void bnBlockInSectorReadRK_Click(object sender, EventArgs e) + { + //RK + DL_STATUS status; + byte[] block_data = new byte[16]; + byte sector_nr = 0, block_nr = 0, auth_mode = 0, key_nr = 0; + byte dl_card_type = 0; + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + + if (rbBlockInSectorReadKeyARK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + } + else if (rbBlockInSectorReadKeyBRK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + key_nr = Byte.Parse(cbBlockInSectorReadKeyRK.Text); + + sector_nr = Byte.Parse(cbBlockInSectorSectorNrRK.Text); + + block_nr = Byte.Parse(cbBlockInSectorBlockNrRK.Text); + + status = (UInt32)uFCoder.BlockInSectorRead(block_data, sector_nr, block_nr, auth_mode, key_nr); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnBlockInSectoReadAKM1_Click(object sender, EventArgs e) + { + //AKM1 + DL_STATUS status; + byte[] block_data = new byte[16]; + byte sector_nr = 0, block_nr = 0, auth_mode = 0; + byte dl_card_type = 0; + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbBlockInSectorReadKeyAAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + } + else if (rbBlockInSectorReadKeyBAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + sector_nr = Byte.Parse(cbBlockInSectorSectorNrAKM1.Text); + + block_nr = Byte.Parse(cbBlockInSectorBlockNrAKM1.Text); + + status = (UInt32)uFCoder.BlockInSectorRead_AKM1(block_data, sector_nr, block_nr, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + + private void btnBlockInSectorReadAKM2_Click(object sender, EventArgs e) + { + //AKM2 + DL_STATUS status; + byte[] block_data = new byte[16]; + byte sector_nr = 0, block_nr = 0, auth_mode = 0; + byte dl_card_type = 0; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbBlockInSectorReadKeyAAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + } + else if (rbBlockInSectorReadKeyBAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + sector_nr = Byte.Parse(cbBlockInSectorSectorNrAKM2.Text); + + block_nr = Byte.Parse(cbBlockInSectorBlockNrAKM2.Text); + + status = (UInt32)uFCoder.BlockInSectorRead_AKM2(block_data, sector_nr, block_nr, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Block read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block read was successful.\nBlock data: "; + txtStatus.Text += BitConverter.ToString(block_data).Replace("-", ":"); + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnLinearReadPK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] linear_data = new byte[3440]; + byte[] sector_key = new byte[16]; + ushort linear_address = 0, linear_length = 0, ret_bytes = 0; + byte dl_card_type = 0, auth_mode = 0; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + + if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) + { + if (txtLinearReadKeyPK.TextLength != 12) + { + txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; + return; + } + + sector_key = StringToByteArray(txtLinearReadKeyPK.Text); + + if (rbLinearReadKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbLinearReadKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + } + else + { + if (txtLinearReadKeyPK.TextLength != 32) + { + txtStatus.Text = "This card uses AES key that should be 16 bytes long"; + return; + } + + sector_key = StringToByteArray(txtLinearReadKeyPK.Text); + + if (rbLinearReadKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; + } + else if (rbLinearReadKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; + } + } + + linear_address = Convert.ToUInt16(txtLinearAddressPK.Text); + + linear_length = Convert.ToUInt16(txtBytesForReadPK.Text); + + status = (UInt32)uFCoder.LinearRead_PK(linear_data, linear_address, linear_length, out ret_bytes, auth_mode, sector_key); + + if (status > 0) + { + txtStatus.Text = "Linear read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Linear read was successful.\nBlock data: "; + + byte[] write_data = new byte[ret_bytes]; + + Array.Copy(linear_data, write_data, ret_bytes); + + txtStatus.Text += BitConverter.ToString(write_data).Replace("-", ":"); + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnLinearReadRK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] linear_data = new byte[3440]; + byte sector_key_index = 0; + ushort linear_address = 0, linear_length = 0, ret_bytes = 0; + byte dl_card_type = 0, auth_mode = 0; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbLinearReadKeyARK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbLinearReadKeyBRK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + sector_key_index = Byte.Parse(cbLinearReadReaderKeyRK.Text); + + linear_address = Convert.ToUInt16(txtLinearAddressRK.Text); + + linear_length = Convert.ToUInt16(txtBytesForReadRK.Text); + + status = (UInt32)uFCoder.LinearRead(linear_data, linear_address, linear_length, out ret_bytes, auth_mode, sector_key_index); + + if (status > 0) + { + txtStatus.Text = "Linear read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Linear read was successful.\nBlock data: "; + + byte[] write_data = new byte[ret_bytes]; + + Array.Copy(linear_data, write_data, ret_bytes); + + txtStatus.Text += BitConverter.ToString(write_data).Replace("-", ":"); + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnLinearReadAKM1_Click(object sender, EventArgs e) + { + //AKM1 + + DL_STATUS status; + byte[] linear_data = new byte[3440]; + ushort linear_address = 0, linear_length = 0, ret_bytes = 0; + byte dl_card_type = 0, auth_mode = 0; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbLinearReadKeyAAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbLinearReadKeyBAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + linear_address = Convert.ToUInt16(txtLinearAddressAKM1.Text); + + linear_length = Convert.ToUInt16(txtBytesForReadAKM1.Text); + + status = (UInt32)uFCoder.LinearRead_AKM1(linear_data, linear_address, linear_length, out ret_bytes, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Linear read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Linear read was successful.\nBlock data: "; + + byte[] write_data = new byte[ret_bytes]; + + Array.Copy(linear_data, write_data, ret_bytes); + + txtStatus.Text += BitConverter.ToString(write_data).Replace("-", ":"); + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + private void btnLinearReadAKM2_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] linear_data = new byte[3440]; + ushort linear_address = 0, linear_length = 0, ret_bytes = 0; + byte dl_card_type = 0, auth_mode = 0; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbLinearReadKeyAAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbLinearReadKeyBAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + linear_address = Convert.ToUInt16(txtLinearAddressAKM2.Text); + + linear_length = Convert.ToUInt16(txtBytesForReadAKM2.Text); + + status = (UInt32)uFCoder.LinearRead_AKM2(linear_data, linear_address, linear_length, out ret_bytes, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Linear read was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Linear read was successful.\nBlock data: "; + + byte[] write_data = new byte[ret_bytes]; + + Array.Copy(linear_data, write_data, ret_bytes); + + txtStatus.Text += BitConverter.ToString(write_data).Replace("-", ":"); + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnBlockWritePK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0, auth_mode = 0, block_nr = 0; + byte[] sector_key = new byte[16]; + byte[] block_data = new byte[16]; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) + { + if (txtBlockWriteKeyPK.TextLength != 12) + { + txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; + return; + } + + sector_key = StringToByteArray(txtBlockWriteKeyPK.Text); + + if (rbBlockWriteKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbBlockWriteKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + } + else + { + if (txtBlockWriteKeyPK.TextLength != 32) + { + txtStatus.Text = "This card uses AES key that should be 16 bytes long"; + return; + } + + sector_key = StringToByteArray(txtBlockWriteKeyPK.Text); + + if (rbBlockWriteKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; + } + else if (rbBlockWriteKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; + } + } + + + if (txtBlockData.TextLength > 32 || txtBlockData.TextLength < 1) + { + txtStatus.Text = "Data for Block Write must be max 16 bytes long"; + return; + } + + block_data = StringToByteArray(txtBlockData.Text); + + block_nr = Byte.Parse(cbBlockWriteBlockNrPK.Text); + + + status = (UInt32)uFCoder.BlockWrite_PK(block_data, block_nr, auth_mode, sector_key); + + if (status > 0) + { + txtStatus.Text = "Block write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + private void btnBlockWriteRK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0, auth_mode = 0, block_nr = 0; + byte key_nr = 0; + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbBlockWriteKeyARK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbBlockWriteKeyBRK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + if (txtBlockData.TextLength > 32 || txtBlockData.TextLength < 1) + { + txtStatus.Text = "Data for Block Write must be max 16 bytes long"; + return; + } + + block_data = StringToByteArray(txtBlockData.Text); + + block_nr = Byte.Parse(cbBlockWriteBlockNrRK.Text); + + key_nr = Byte.Parse(cbBlockWriteKeyIndexRK.Text); + + status = (UInt32)uFCoder.BlockWrite(block_data, block_nr, auth_mode, key_nr); + + if (status > 0) + { + txtStatus.Text = "Block write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + private void btnBlockWriteAKM1_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0, auth_mode = 0, block_nr = 0; + + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbBlockWriteKeyAAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbBlockWriteKeyBAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + if (txtBlockData.TextLength > 32 || txtBlockData.TextLength < 1) + { + txtStatus.Text = "Data for Block Write must be max 16 bytes long"; + return; + } + + block_data = StringToByteArray(txtBlockData.Text); + + block_nr = Byte.Parse(cbBlockWriteBlockNrAKM1.Text); + + status = (UInt32)uFCoder.BlockWrite_AKM1(block_data, block_nr, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Block write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnBlockWriteAKM2_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0, auth_mode = 0, block_nr = 0; + + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbBlockWriteKeyAAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbBlockWriteKeyBAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + if (txtBlockData.TextLength > 32 || txtBlockData.TextLength < 1) + { + txtStatus.Text = "Data for Block Write must be max 16 bytes long"; + return; + } + + block_data = StringToByteArray(txtBlockData.Text); + + block_nr = Byte.Parse(cbBlockWriteBlockNrAKM2.Text); + + status = (UInt32)uFCoder.BlockWrite_AKM2(block_data, block_nr, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Block write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnBlockInSectorWritePK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0, auth_mode = 0, block_nr = 0, sector_nr = 0; + byte[] sector_key = new byte[16]; + byte[] block_data = new byte[16]; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) + { + if (txtBlockInSectorWriteKeyPK.TextLength != 12) + { + txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; + return; + } + + sector_key = StringToByteArray(txtBlockInSectorWriteKeyPK.Text); + + if (rbBlockInSectorWriteKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbBlockInSectorWriteKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + } + else + { + if (txtBlockInSectorWriteKeyPK.TextLength != 32) + { + txtStatus.Text = "This card uses AES key that should be 16 bytes long"; + return; + } + + sector_key = StringToByteArray(txtBlockInSectorWriteKeyPK.Text); + + if (rbBlockInSectorWriteKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; + } + else if (rbBlockInSectorWriteKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; + } + } + + + if (txtBlockInSectorData.TextLength > 32 || txtBlockInSectorData.TextLength < 1) + { + txtStatus.Text = "Data for Block in sector Write must be max 16 bytes long"; + return; + } + + block_data = StringToByteArray(txtBlockInSectorData.Text); + + block_nr = Byte.Parse(cbBlockInSectorWriteBlockNrPK.Text); + + sector_nr = Byte.Parse(cbBlockInSectorWriteSectorNrPK.Text); + + + status = (UInt32)uFCoder.BlockInSectorWrite_PK(block_data, sector_nr, block_nr, auth_mode, sector_key); + + if (status > 0) + { + txtStatus.Text = "Block in sector write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block in sector write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + private void btnBlockInSectorWriteRK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0, auth_mode = 0, block_nr = 0, sector_nr = 0; + byte key_nr = 0; + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbBlockInSectorWriteKeyARK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbBlockInSectorWriteKeyBRK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + if (txtBlockInSectorData.TextLength > 32 || txtBlockInSectorData.TextLength < 1) + { + txtStatus.Text = "Data for Block in sector Write must be max 16 bytes long"; + return; + } + + block_data = StringToByteArray(txtBlockInSectorData.Text); + + sector_nr = Byte.Parse(cbBlockInSectorWriteSectorNrRK.Text); + + block_nr = Byte.Parse(cbBlockInSectorWriteBlockNrRK.Text); + + key_nr = Byte.Parse(cbBlockInSectorWriteKeyIndexRK.Text); + + status = (UInt32)uFCoder.BlockInSectorWrite(block_data, sector_nr, block_nr, auth_mode, key_nr); + + if (status > 0) + { + txtStatus.Text = "Block in sector write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block in sector write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + + } + + private void btnBlockInSectorWriteAKM1_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0, auth_mode = 0, block_nr = 0, sector_nr = 0; + + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbBlockInSectorWriteKeyAAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbBlockInSectorWriteKeyBAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + if (txtBlockInSectorData.TextLength > 32 || txtBlockInSectorData.TextLength < 1) + { + txtStatus.Text = "Data for Block in sector Write must be max 16 bytes long"; + return; + } + + block_data = StringToByteArray(txtBlockInSectorData.Text); + + sector_nr = Byte.Parse(cbBlockInSectorWriteSectorNrAKM1.Text); + + block_nr = Byte.Parse(cbBlockInSectorWriteBlockNrAKM1.Text); + + status = (UInt32)uFCoder.BlockInSectorWrite_AKM1(block_data, sector_nr, block_nr, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Block in sector write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block in sector write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnBlockInSectorWriteAKM2_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte dl_card_type = 0, auth_mode = 0, block_nr = 0, sector_nr = 0; + + byte[] block_data = new byte[16]; + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbBlockInSectorWriteKeyAAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbBlockInSectorWriteKeyBAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + if (txtBlockInSectorData.TextLength > 32 || txtBlockInSectorData.TextLength < 1) + { + txtStatus.Text = "Data for Block in sector Write must be max 16 bytes long"; + return; + } + + block_data = StringToByteArray(txtBlockInSectorData.Text); + + sector_nr = Byte.Parse(cbBlockInSectorWriteSectorNrAKM2.Text); + + block_nr = Byte.Parse(cbBlockInSectorWriteBlockNrAKM2.Text); + + status = (UInt32)uFCoder.BlockInSectorWrite_AKM1(block_data, sector_nr, block_nr, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Block in sector write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Block in sector write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnLinearWritePK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] linear_data = new byte[3440]; + byte[] sector_key = new byte[16]; + ushort linear_address = 0, linear_length = 0, ret_bytes = 0; + byte dl_card_type = 0, auth_mode = 0; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + + if (((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1)) + { + if (txtLinearWriteKeyPK.TextLength != 12) + { + txtStatus.Text = "This card uses CRYPTO 1 key that should be 6 bytes long"; + return; + } + + sector_key = StringToByteArray(txtLinearWriteKeyPK.Text); + + if (rbLinearWriteKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbLinearWriteKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + } + else + { + if (txtLinearWriteKeyPK.TextLength != 32) + { + txtStatus.Text = "This card uses AES key that should be 16 bytes long"; + return; + } + + sector_key = StringToByteArray(txtLinearWriteKeyPK.Text); + + if (rbLinearWriteKeyAPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1A; + } + else if (rbLinearWriteKeyBPK.Checked) + { + auth_mode = (byte)MIFARE_PLUS_AES_AUTHENTICATION.MIFARE_PLUS_AES_AUTHENT1B; + } + } + + linear_address = Convert.ToUInt16(txtLinearWriteAddressPK.Text); + + linear_data = StringToByteArray(txtLinearWriteData.Text); + + linear_length = Convert.ToUInt16(linear_data.Length); + + status = (UInt32)uFCoder.LinearWrite_PK(linear_data, linear_address, linear_length, out ret_bytes, auth_mode, sector_key); + + if (status > 0) + { + txtStatus.Text = "Linear write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Linear write was successful."; + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnLinearWriteRK_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] linear_data = new byte[3440]; + byte sector_key_index = 0; + ushort linear_address = 0, linear_length = 0, ret_bytes = 0; + byte dl_card_type = 0, auth_mode = 0; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbLinearWriteKeyARK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbLinearWriteKeyBRK.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + linear_data = StringToByteArray(txtLinearWriteData.Text); + + sector_key_index = Byte.Parse(cbLinearWriteKeyIndexRK.Text); + + linear_address = Convert.ToUInt16(txtLinearWriteAddressRK.Text); + + linear_length = Convert.ToUInt16(txtLinearWriteData.TextLength); + + status = (UInt32)uFCoder.LinearWrite(linear_data, linear_address, linear_length, out ret_bytes, auth_mode, sector_key_index); + + if (status > 0) + { + txtStatus.Text = "Linear write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Linear write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnLinearWriteAKM1_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] linear_data = new byte[3440]; + + ushort linear_address = 0, linear_length = 0, ret_bytes = 0; + byte dl_card_type = 0, auth_mode = 0; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbLinearWriteKeyAAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbLinearWriteKeyBAKM1.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + linear_data = StringToByteArray(txtLinearWriteData.Text); + + linear_address = Convert.ToUInt16(txtLinearWriteAddressAKM1.Text); + + linear_length = Convert.ToUInt16(txtLinearWriteData.TextLength); + + status = (UInt32)uFCoder.LinearWrite_AKM1(linear_data, linear_address, linear_length, out ret_bytes, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Linear write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Linear write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); + } + + private void btnLinearWriteAKM2_Click(object sender, EventArgs e) + { + DL_STATUS status; + byte[] linear_data = new byte[3440]; + + ushort linear_address = 0, linear_length = 0, ret_bytes = 0; + byte dl_card_type = 0, auth_mode = 0; + + + status = (UInt32)uFCoder.GetDlogicCardType(out dl_card_type); + + if (status > 0) + { + txtStatus.Text = "Communication with card failed."; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + if (!(((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_4K_SL1 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL1) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_2K_SL3) || + ((DLOGIC_CARD_TYPE)dl_card_type >= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_S_2K_SL3 && (DLOGIC_CARD_TYPE)dl_card_type <= DLOGIC_CARD_TYPE.DL_MIFARE_PLUS_EV1_4K_SL3))) + { + txtStatus.Text = "Card is not in security level 1 or 3 mode"; + return; + } + + if (rbLinearWriteKeyAAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1A; + + } + else if (rbLinearWriteKeyBAKM2.Checked) + { + auth_mode = (byte)MIFARE_AUTHENTICATION.MIFARE_AUTHENT1B; + } + + linear_data = StringToByteArray(txtLinearWriteData.Text); + + linear_address = Convert.ToUInt16(txtLinearWriteAddressAKM2.Text); + + linear_length = Convert.ToUInt16(txtLinearWriteData.TextLength); + + status = (UInt32)uFCoder.LinearWrite_AKM2(linear_data, linear_address, linear_length, out ret_bytes, auth_mode); + + if (status > 0) + { + txtStatus.Text = "Linear write was NOT successful"; + toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); + return; + } + + txtStatus.Text = "Linear write was successful. "; + + toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); } private void chkAdvanced_CheckedChanged(object sender, EventArgs e) @@ -2539,21 +2539,17 @@ namespace mifare_plus_c_sharp string port_interface = txtPortInterface.Text; string arg = txtArg.Text; - - StringBuilder port_name_build = new StringBuilder(port_name.Length); - port_name_build.Append(port_name); + try { UInt32 reader_type_int = Convert.ToUInt32(reader_type); UInt32 port_interface_int = (UInt32)port_interface[0]; - StringBuilder arg_str = new StringBuilder(arg.Length); - arg_str.Append(arg); - status = (UInt32)uFCoder.ReaderOpenEx(reader_type_int, port_name_build, port_interface_int, arg_str); + status = (UInt32)uFCoder.ReaderOpenEx(reader_type_int, port_name, port_interface_int, arg); if (status > 0) { txtStatus.Text = "ReaderOpenEx was NOT successful."; toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); //return; - } + } else { txtStatus.Text = "ReaderOpenEx was successful. "; @@ -2562,8 +2558,12 @@ namespace mifare_plus_c_sharp uFCoder.ReaderUISignal(1, 1); tmrCardReading.Start(); - - + } + } + catch (Exception er) + { + MessageBox.Show("Invalid Advanced options parameters, please check your input and try again!"); + } } else { DL_STATUS status = 0; @@ -2572,19 +2572,22 @@ namespace mifare_plus_c_sharp if (status > 0) { - txtStatus.Text = "ReaderOpenEx was NOT successful."; + txtStatus.Text = "ReaderOpen was NOT successful."; toolStripStatusLabel1.Text = "Error: " + uFCoder.status2str((uFR.DL_STATUS)status); - } + } else { - txtStatus.Text = "ReaderOpenEx was successful. "; + txtStatus.Text = "ReaderOpen was successful. "; toolStripStatusLabel1.Text = "Success: " + uFCoder.status2str((uFR.DL_STATUS)status); uFCoder.ReaderUISignal(1, 1); tmrCardReading.Start(); + } } + + } - } + } } \ No newline at end of file diff --git a/mifare_plus_c_sharp/bin/Debug/mifare_plus_c_sharp.exe b/mifare_plus_c_sharp/bin/Debug/mifare_plus_c_sharp.exe index 7a66900a297288fd9b249d06f83b2a573dd70b16..8719f12cd8b8fab610c7bb2be1aede7149df8d97 100644 Binary files a/mifare_plus_c_sharp/bin/Debug/mifare_plus_c_sharp.exe and b/mifare_plus_c_sharp/bin/Debug/mifare_plus_c_sharp.exe differ diff --git a/mifare_plus_c_sharp/bin/Debug/mifare_plus_c_sharp.pdb b/mifare_plus_c_sharp/bin/Debug/mifare_plus_c_sharp.pdb index 819ac8ed590edb42d7e8e0c8e4a3b8d3c4400f7f..14def4a024555112d8af1165f885625b7de80b39 100644 Binary files a/mifare_plus_c_sharp/bin/Debug/mifare_plus_c_sharp.pdb and b/mifare_plus_c_sharp/bin/Debug/mifare_plus_c_sharp.pdb differ diff --git a/mifare_plus_c_sharp/bin/Release/mifare_plus_c_sharp.exe b/mifare_plus_c_sharp/bin/Release/mifare_plus_c_sharp.exe index 2e89d67b9c6a2ee3ff01e162ec94758713699700..5b89fd5533fcb268081172e62624388f5eeb24a4 100644 Binary files a/mifare_plus_c_sharp/bin/Release/mifare_plus_c_sharp.exe and b/mifare_plus_c_sharp/bin/Release/mifare_plus_c_sharp.exe differ diff --git a/mifare_plus_c_sharp/bin/Release/mifare_plus_c_sharp.pdb b/mifare_plus_c_sharp/bin/Release/mifare_plus_c_sharp.pdb index 3f53e7798450145255b5647f43a8749e5f1310bd..4615d149300866b6cc581b3137891e6b687d7366 100644 Binary files a/mifare_plus_c_sharp/bin/Release/mifare_plus_c_sharp.pdb and b/mifare_plus_c_sharp/bin/Release/mifare_plus_c_sharp.pdb differ diff --git a/mifare_plus_c_sharp/obj/Debug/mifare_plus_c_sharp.exe b/mifare_plus_c_sharp/obj/Debug/mifare_plus_c_sharp.exe index 7a66900a297288fd9b249d06f83b2a573dd70b16..8719f12cd8b8fab610c7bb2be1aede7149df8d97 100644 Binary files a/mifare_plus_c_sharp/obj/Debug/mifare_plus_c_sharp.exe and b/mifare_plus_c_sharp/obj/Debug/mifare_plus_c_sharp.exe differ diff --git a/mifare_plus_c_sharp/obj/Debug/mifare_plus_c_sharp.pdb b/mifare_plus_c_sharp/obj/Debug/mifare_plus_c_sharp.pdb index 819ac8ed590edb42d7e8e0c8e4a3b8d3c4400f7f..14def4a024555112d8af1165f885625b7de80b39 100644 Binary files a/mifare_plus_c_sharp/obj/Debug/mifare_plus_c_sharp.pdb and b/mifare_plus_c_sharp/obj/Debug/mifare_plus_c_sharp.pdb differ diff --git a/mifare_plus_c_sharp/obj/Release/mifare_plus_c_sharp.exe b/mifare_plus_c_sharp/obj/Release/mifare_plus_c_sharp.exe index 2e89d67b9c6a2ee3ff01e162ec94758713699700..5b89fd5533fcb268081172e62624388f5eeb24a4 100644 Binary files a/mifare_plus_c_sharp/obj/Release/mifare_plus_c_sharp.exe and b/mifare_plus_c_sharp/obj/Release/mifare_plus_c_sharp.exe differ diff --git a/mifare_plus_c_sharp/obj/Release/mifare_plus_c_sharp.pdb b/mifare_plus_c_sharp/obj/Release/mifare_plus_c_sharp.pdb index 3f53e7798450145255b5647f43a8749e5f1310bd..4615d149300866b6cc581b3137891e6b687d7366 100644 Binary files a/mifare_plus_c_sharp/obj/Release/mifare_plus_c_sharp.pdb and b/mifare_plus_c_sharp/obj/Release/mifare_plus_c_sharp.pdb differ diff --git a/mifare_plus_c_sharp/uFCoder.cs b/mifare_plus_c_sharp/uFCoder.cs index 2d2123ed43f603a105644c78c77fd8ac5091e6c5..e1bc4964f1a44efa4b4b26f26b2efbbecd3ca345 100644 --- a/mifare_plus_c_sharp/uFCoder.cs +++ b/mifare_plus_c_sharp/uFCoder.cs @@ -1,2086 +1,2096 @@ -using System; -using System.Text; - -namespace uFR -{ - using System.Runtime.InteropServices; - using UFR_HANDLE = System.UIntPtr; - - enum CARD_SAK - { - UNKNOWN = 0x00, - MIFARE_CLASSIC_1k = 0x08, - MF1ICS50 = 0x08, - SLE66R35 = 0x88, - MIFARE_CLASSIC_4k = 0x18, - MF1ICS70 = 0x18, - MIFARE_CLASSIC_MINI = 0x09, - MF1ICS20 = 0x09, - } - - enum DLOGIC_CARD_TYPE - { - DL_NO_CARD = 0x00, - DL_MIFARE_ULTRALIGHT = 0x01, - DL_MIFARE_ULTRALIGHT_EV1_11 = 0x02, - DL_MIFARE_ULTRALIGHT_EV1_21 = 0x03, - DL_MIFARE_ULTRALIGHT_C = 0x04, - DL_NTAG_203 = 0x05, - DL_NTAG_210 = 0x06, - DL_NTAG_212 = 0x07, - DL_NTAG_213 = 0x08, - DL_NTAG_215 = 0x09, - DL_NTAG_216 = 0x0A, - DL_MIKRON_MIK640D = 0x0B, - NFC_T2T_GENERIC = 0x0C, - DL_MIFARE_MINI = 0x20, - DL_MIFARE_CLASSIC_1K = 0x21, - DL_MIFARE_CLASSIC_4K = 0x22, - DL_MIFARE_PLUS_S_2K_SL0 = 0x23, - DL_MIFARE_PLUS_S_4K_SL0 = 0x24, - DL_MIFARE_PLUS_X_2K_SL0 = 0x25, - DL_MIFARE_PLUS_X_4K_SL0 = 0x26, - DL_MIFARE_DESFIRE = 0x27, - DL_MIFARE_DESFIRE_EV1_2K = 0x28, - DL_MIFARE_DESFIRE_EV1_4K = 0x29, - DL_MIFARE_DESFIRE_EV1_8K = 0x2A, - DL_MIFARE_DESFIRE_EV2_2K = 0x2B, - DL_MIFARE_DESFIRE_EV2_4K = 0x2C, - DL_MIFARE_DESFIRE_EV2_8K = 0x2D, - DL_MIFARE_PLUS_S_2K_SL1 = 0x2E, - DL_MIFARE_PLUS_X_2K_SL1 = 0x2F, - DL_MIFARE_PLUS_EV1_2K_SL1 = 0x30, - DL_MIFARE_PLUS_X_2K_SL2 = 0x31, - DL_MIFARE_PLUS_S_2K_SL3 = 0x32, - DL_MIFARE_PLUS_X_2K_SL3 = 0x33, - DL_MIFARE_PLUS_EV1_2K_SL3 = 0x34, - DL_MIFARE_PLUS_S_4K_SL1 = 0x35, - DL_MIFARE_PLUS_X_4K_SL1 = 0x36, - DL_MIFARE_PLUS_EV1_4K_SL1 = 0x37, - DL_MIFARE_PLUS_X_4K_SL2 = 0x38, - DL_MIFARE_PLUS_S_4K_SL3 = 0x39, - DL_MIFARE_PLUS_X_4K_SL3 = 0x3A, - DL_MIFARE_PLUS_EV1_4K_SL3 = 0x3B, - DL_UNKNOWN_ISO_14443_4 = 0x40, - DL_GENERIC_ISO14443_4 = 0x40, - DL_GENERIC_ISO14443_4_TYPE_B = 0x41, - DL_GENERIC_ISO14443_3_TYPE_B = 0x42, - DL_IMEI_UID = 0x80 - -} - // MIFARE CLASSIC Authentication Modes: - enum MIFARE_AUTHENTICATION - { - MIFARE_AUTHENT1A = 0x60, - MIFARE_AUTHENT1B = 0x61 - } - - //MIFARE PLUS AES Authentication Modes: - enum MIFARE_PLUS_AES_AUTHENTICATION - { - MIFARE_PLUS_AES_AUTHENT1A = 0x80, - MIFARE_PLUS_AES_AUTHENT1B = 0x81 - } - - // DLJavaCardSignerCardTypes: - enum JCDL_SIGNER_CARDS - { - DLSigner81 = 0xA0, - DLSigner22 = 0xA1, - DLSigner30 = 0xA2, - DLSigner10 = 0xA3, - DLSigner145 = 0xAA - } - // DLJavaCardSignerAlgorithmTypes: - enum JCDL_SIGNER_CIPHERS - { - SIG_CIPHER_RSA = 0, - SIG_CIPHER_ECDSA - }; - enum JCDL_SIGNER_PADDINGS - { - PAD_NULL = 0, - PAD_PKCS1 - }; - enum JCDL_SIGNER_DIGESTS - { - ALG_NULL = 0, - ALG_SHA, - ALG_SHA_256, - ALG_SHA_384, - ALG_SHA_512, - ALG_SHA_224 - }; - enum JCDL_KEY_TYPES - { - TYPE_RSA_PRIVATE = 0, - TYPE_RSA_CRT_PRIVATE, - TYPE_EC_F2M_PRIVATE, - TYPE_EC_FP_PRIVATE - }; - enum JCDS_EC_KEY_DESIGNATOR - { - EC_KEY_DSG_K1 = 0, - EC_KEY_DSG_R1, - EC_KEY_DSG_R2, - EC_KEY_DSG_RFU - } - // API Status Codes Type: - public enum DL_STATUS - { - UFR_OK = 0x00, - - UFR_COMMUNICATION_ERROR = 0x01, - UFR_CHKSUM_ERROR = 0x02, - UFR_READING_ERROR = 0x03, - UFR_WRITING_ERROR = 0x04, - UFR_BUFFER_OVERFLOW = 0x05, - UFR_MAX_ADDRESS_EXCEEDED = 0x06, - UFR_MAX_KEY_INDEX_EXCEEDED = 0x07, - UFR_NO_CARD = 0x08, - UFR_COMMAND_NOT_SUPPORTED = 0x09, - UFR_FORBIDEN_DIRECT_WRITE_IN_SECTOR_TRAILER = 0x0A, - UFR_ADDRESSED_BLOCK_IS_NOT_SECTOR_TRAILER = 0x0B, - UFR_WRONG_ADDRESS_MODE = 0x0C, - UFR_WRONG_ACCESS_BITS_VALUES = 0x0D, - UFR_AUTH_ERROR = 0x0E, - UFR_PARAMETERS_ERROR = 0x0F, - UFR_MAX_SIZE_EXCEEDED = 0x10, - UFR_UNSUPPORTED_CARD_TYPE = 0x11, - - UFR_WRITE_VERIFICATION_ERROR = 0x70, - UFR_BUFFER_SIZE_EXCEEDED = 0x71, - UFR_VALUE_BLOCK_INVALID = 0x72, - UFR_VALUE_BLOCK_ADDR_INVALID = 0x73, - UFR_VALUE_BLOCK_MANIPULATION_ERROR = 0x74, - UFR_WRONG_UI_MODE = 0x75, - UFR_KEYS_LOCKED = 0x76, - UFR_KEYS_UNLOCKED = 0x77, - UFR_WRONG_PASSWORD = 0x78, - UFR_CAN_NOT_LOCK_DEVICE = 0x79, - UFR_CAN_NOT_UNLOCK_DEVICE = 0x7A, - UFR_DEVICE_EEPROM_BUSY = 0x7B, - UFR_RTC_SET_ERROR = 0x7C, - - ANTI_COLLISION_DISABLED = 0x7D, - - UFR_COMMUNICATION_BREAK = 0x50, - UFR_NO_MEMORY_ERROR = 0x51, - UFR_CAN_NOT_OPEN_READER = 0x52, - UFR_READER_NOT_SUPPORTED = 0x53, - UFR_READER_OPENING_ERROR = 0x54, - UFR_READER_PORT_NOT_OPENED = 0x55, - UFR_CANT_CLOSE_READER_PORT = 0x56, - - UFR_TIMEOUT_ERR = 0x90, - - UFR_FT_STATUS_ERROR_1 = 0xA0, - UFR_FT_STATUS_ERROR_2 = 0xA1, - UFR_FT_STATUS_ERROR_3 = 0xA2, - UFR_FT_STATUS_ERROR_4 = 0xA3, - UFR_FT_STATUS_ERROR_5 = 0xA4, - UFR_FT_STATUS_ERROR_6 = 0xA5, - UFR_FT_STATUS_ERROR_7 = 0xA6, - UFR_FT_STATUS_ERROR_8 = 0xA7, - UFR_FT_STATUS_ERROR_9 = 0xA8, - - //NDEF error codes - UFR_WRONG_NDEF_CARD_FORMAT = 0x80, - UFR_NDEF_MESSAGE_NOT_FOUND = 0x81, - UFR_NDEF_UNSUPPORTED_CARD_TYPE = 0x82, - UFR_NDEF_CARD_FORMAT_ERROR = 0x83, - UFR_MAD_NOT_ENABLED = 0x84, - UFR_MAD_VERSION_NOT_SUPPORTED = 0x85, - - - // multiple units - return from the functions with ReaderList_ prefix in name - UFR_DEVICE_WRONG_HANDLE = 0x100, - UFR_DEVICE_INDEX_OUT_OF_BOUND, - UFR_DEVICE_ALREADY_OPENED, - UFR_DEVICE_ALREADY_CLOSED, - UFR_DEVICE_IS_NOT_CONNECTED, - - // Originality Check Error Codes: - UFR_NOT_NXP_GENUINE = 0x200, - UFR_OPEN_SSL_DYNAMIC_LIB_FAILED, - UFR_OPEN_SSL_DYNAMIC_LIB_NOT_FOUND, - - UFR_NOT_IMPLEMENTED = 0x1000, - UFR_COMMAND_FAILED, - - //MIFARE PLUS error codes - UFR_MFP_COMMAND_OVERFLOW = 0xB0, - UFR_MFP_INVALID_MAC = 0xB1, - UFR_MFP_INVALID_BLOCK_NR = 0xB2, - UFR_MFP_NOT_EXIST_BLOCK_NR = 0xB3, - UFR_MFP_COND_OF_USE_ERROR = 0xB4, - UFR_MFP_LENGTH_ERROR = 0xB5, - UFR_MFP_GENERAL_MANIP_ERROR = 0xB6, - UFR_MFP_SWITCH_TO_ISO14443_4_ERROR = 0xB7, - UFR_MFP_ILLEGAL_STATUS_CODE = 0xB8, - UFR_MFP_MULTI_BLOCKS_READ = 0xB9, - - // APDU Error Codes: - UFR_APDU_TRANSCEIVE_ERROR = 0xAE, - UFR_APDU_JC_APP_NOT_SELECTED = 0x6000, - UFR_APDU_JC_APP_BUFF_EMPTY, - UFR_APDU_WRONG_SELECT_RESPONSE, - UFR_APDU_WRONG_KEY_TYPE, - UFR_APDU_WRONG_KEY_SIZE, - UFR_APDU_WRONG_KEY_PARAMS, - UFR_APDU_WRONG_SIGNING_ALGORITHM, - UFR_APDU_PLAIN_TEXT_SIZE_EXCEEDED, - UFR_APDU_UNSUPPORTED_KEY_SIZE, - UFR_APDU_UNSUPPORTED_ALGORITHMS, - UFR_APDU_PKI_OBJECT_NOT_FOUND, - UFR_APDU_SW_TAG = 0x0A0000, - - MAX_UFR_STATUS = 0x7FFFFFFF - }; - - public enum DL_SECURE_CODE - { - USER_PIN = 0, - SO_PIN, - USER_PUK, - SO_PUK - }; - - public enum DESFIRE_CARD_STATUS_CODES - { - READER_ERROR = 2999, - CARD_OPERATION_OK = 3001, - WRONG_KEY_TYPE = 3002, - KEY_AUTH_ERROR = 3003, - CARD_CRYPTO_ERROR = 3004, - READER_CARD_COMM_ERROR = 3005, - PC_READER_COMM_ERROR = 3006, - COMMIT_TRANSACTION_NO_REPLY = 3007, - COMMIT_TRANSACTION_ERROR = 3008, - DESFIRE_CARD_NO_CHANGES = 0x0C0C, - DESFIRE_CARD_OUT_OF_EEPROM_ERROR = 0x0C0E, - DESFIRE_CARD_ILLEGAL_COMMAND_CODE = 0x0C1C, - DESFIRE_CARD_INTEGRITY_ERROR = 0x0C1E, - DESFIRE_CARD_NO_SUCH_KEY = 0x0C40, - DESFIRE_CARD_LENGTH_ERROR = 0x0C7E, - DESFIRE_CARD_PERMISSION_DENIED = 0x0C9D, - DESFIRE_CARD_PARAMETER_ERROR = 0x0C9E, - DESFIRE_CARD_APPLICATION_NOT_FOUND = 0x0CA0, - DESFIRE_CARD_APPL_INTEGRITY_ERROR = 0x0CA1, - DESFIRE_CARD_AUTHENTICATION_ERROR = 0x0CAE, - DESFIRE_CARD_ADDITIONAL_FRAME = 0x0CAF, - DESFIRE_CARD_BOUNDARY_ERROR = 0x0CBE, - DESFIRE_CARD_PICC_INTEGRITY_ERROR = 0x0CC1, - DESFIRE_CARD_COMMAND_ABORTED = 0x0CCA, - DESFIRE_CARD_PICC_DISABLED_ERROR = 0x0CCD, - DESFIRE_CARD_COUNT_ERROR = 0x0CCE, - DESFIRE_CARD_DUPLICATE_ERROR = 0x0CDE, - DESFIRE_CARD_EEPROM_ERROR_DES = 0x0CEE, - DESFIRE_CARD_FILE_NOT_FOUND = 0x0CF0, - DESFIRE_CARD_FILE_INTEGRITY_ERROR = 0x0CF1 - }; - - public enum DESFIRE_KEY_SETTINGS - { - DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_CHANGE_KEY_CHANGE = 0x09, - DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_CHANGE_KEY_CHANGE = 0x0F, - DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_NOT_CHANGE_KEY_CHANGE = 0x01, - DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_NOT_CHANGE_KEY_CHANGE = 0x07, - DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_CHANGE_KEY_NOT_CHANGE = 0x08, - DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_CHANGE_KEY_NOT_CHANGE = 0x0E, - DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_NOT_CHANGE_KEY_NOT_CHANGE = 0x00, - DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_NOT_CHANGE_KEY_NOT_CHANGE = 0x06 - }; - - public static class uFCoder - { - public const uint JCAPP_MIN_PIN_LENGTH = 4; - public const uint JCAPP_MAX_PIN_LENGTH = 8; - public const uint JCAPP_PUK_LENGTH = 8; - public const uint SIG_MAX_PLAIN_DATA_LEN = 255; - public const string JCDL_AID_RID_PLUS = "F0 44 4C 6F 67 69 63"; - public const string JCDL_AID_PIX = "00 01"; - public const string JCDL_AID = JCDL_AID_RID_PLUS + JCDL_AID_PIX; - - const UInt32 MIN_UFR_LIB_VERSION = 0x05000003; // bytes from left to right: MSB=MajorVer, MidSB_H=MinorVer, MidSB_L=0, LSB=BuildNum - const UInt32 MIN_UFR_FW_VERSION = 0x05000007; // bytes from left to right: MSB=MajorVer, MidSB_H=MinorVer, MidSB_L=0, LSB=BuildNum - - //... - //... - //... - [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool SetDllDirectory(string lpPathName); - -#if WIN64 - const string DLL_PATH = @"..\..\..\ufr-lib\windows\x86_64\"; - const string NAME_DLL = "uFCoder-x86_64.dll"; - -#else - const string DLL_PATH = @"..\..\ufr-lib\windows\x86\"; - const string NAME_DLL = "uFCoder-x86.dll"; -#endif - const string DLL_NAME = DLL_PATH + NAME_DLL; - - public static void uFrOpen() - { - DL_STATUS status; - UInt32 version = 0; - byte version_major; - byte version_minor; - UInt16 lib_build; - byte fw_build; - String uFR_NotOpenedMessage; - - -#if WIN64 - string DllPath = @"lib\windows\x86_64"; // for x64 target - string name = "uFCoder-x86_64.dll"; -#else - string DllPath = @"lib\windows\x86"; // for x86 target - string name = "uFCoder-x86.dll"; -#endif - string dll_name = DllPath + name; - int repeat_cnt = 0; - bool repeat = true; - do - { - DllPath = @"..\" + DllPath; - SetDllDirectory(DllPath); - try - { - version = uFCoder.GetDllVersion(); - repeat = false; - } - catch (System.Exception) - { - ++repeat_cnt; - } - - } while (repeat && repeat_cnt < 3); // relative path upper folders level search - - if (repeat) - throw new Exception("Can't find " + dll_name + ".\r\nYou will not be able to work with DL Signer cards."); - - // Check lib version: - version_major = (byte)version; - version_minor = (byte)(version >> 8); - lib_build = (ushort)(version >> 16); - - version = ((UInt32)version_major << 24) | ((UInt32)version_minor << 16) | (UInt32)lib_build; - if (version < MIN_UFR_LIB_VERSION) - { - uFR_NotOpenedMessage = "Wrong uFCoder library version.\r\n" - + "You can't work with DL Signer cards.\r\n\r\nUse uFCoder library " - + (MIN_UFR_LIB_VERSION >> 24) + "." + ((MIN_UFR_LIB_VERSION >> 16) & 0xFF) - + "." + (MIN_UFR_LIB_VERSION & 0xFFFF) + " or higher."; - throw new Exception("Wrong uFCoder library version.\r\n" - + "You can't work with DL Signer cards.\r\n\r\nUse uFCoder library " - + (MIN_UFR_LIB_VERSION >> 24) + "." + ((MIN_UFR_LIB_VERSION >> 16) & 0xFF) - + "." + (MIN_UFR_LIB_VERSION & 0xFFFF) + " or higher."); - } - - status = ReaderOpen(); - if (status != (UInt32)uFR.DL_STATUS.UFR_OK) - { - uFR_NotOpenedMessage = "uFR reader not opened.\r\nYou can't work with Desfire cards." - + "\r\n\r\nTry to connect uFR reader and restart application."; - throw new Exception("Can't open uFR reader.\r\nYou will not be able to work with Desfire cards."); - } - - // Check firmware version: - status = GetReaderFirmwareVersion(out version_major, out version_minor); - if (status != (UInt32)uFR.DL_STATUS.UFR_OK) - { - uFCoder.ReaderClose(); - throw new Exception("Can't open uFR reader.\r\nYou will not be able to work with Desfire cards."); - } - status = GetBuildNumber(out fw_build); - if (status != (UInt32)uFR.DL_STATUS.UFR_OK) - { - uFCoder.ReaderClose(); - throw new Exception("Can't open uFR reader.\r\nYou will not be able to work with Desfire cards."); - } - - version = ((UInt32)version_major << 24) | ((UInt32)version_minor << 16) | (UInt32)fw_build; - if (version < MIN_UFR_FW_VERSION) - { - uFCoder.ReaderClose(); - uFR_NotOpenedMessage = "Wrong uFR firmware version.\r\n" - + "You can't work with Desfire cards.\r\n\r\nPlease update firmware to " - + (MIN_UFR_FW_VERSION >> 24) + "." + ((MIN_UFR_FW_VERSION >> 16) & 0xFF) - + "." + (MIN_UFR_FW_VERSION & 0xFFFF) + " or higher."; - throw new Exception("Wrong uFR firmware version.\r\n" - + "Some functions with DESFIRE CARDS will be unavailable.\r\n\r\nPlease update firmware to " - + (MIN_UFR_FW_VERSION >> 24) + "." + ((MIN_UFR_FW_VERSION >> 16) & 0xFF) - + "." + (MIN_UFR_FW_VERSION & 0xFFFF) + " or higher and restart application."); - } - - - } - - //-------------------------------------------------------------------------------------------------- - //-------------------------------------------------------------------------------------------------- - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpen")] - public static extern DL_STATUS ReaderOpen(); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpenEx")] - public static extern DL_STATUS ReaderOpenEx(UInt32 reader_type, - [MarshalAs(UnmanagedType.LPStr)] - StringBuilder port_name, - UInt32 port_interface, - [MarshalAs(UnmanagedType.LPStr)] - StringBuilder arg); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderClose")] - public static extern DL_STATUS ReaderClose(); - - //-------------------------------------------------------------------------------------------------- - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderType")] - public static extern DL_STATUS GetReaderType(out UInt32 lpulReaderType); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderSerialDescription")] - private static extern DL_STATUS getReaderSerialDescription(StringBuilder pSerialDescription); - public static DL_STATUS GetReaderSerialDescription(out string SerialDescription) - { - StringBuilder pSerialDescription = new StringBuilder(7); - DL_STATUS status = DL_STATUS.UFR_OK; - - status = getReaderSerialDescription(pSerialDescription); - if (status == DL_STATUS.UFR_OK) - SerialDescription = pSerialDescription.ToString(); - else - SerialDescription = ""; - return status; - } - - //--------------------------------------------------------------------- - // Card emulation: - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "TagEmulationStart")] - public static extern DL_STATUS TagEmulationStart(); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "TagEmulationStop")] - public static extern DL_STATUS TagEmulationStop(); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "CombinedModeEmulationStart")] - public static extern DL_STATUS CombinedModeEmulationStart(); - //--------------------------------------------------------------------- - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDlogicCardType")] - public static extern DL_STATUS GetDlogicCardType(out byte lpucCardType); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_UpdateAndGetCount")] - public static extern DL_STATUS ReaderList_UpdateAndGetCount(out UInt32 NumberOfDevices); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialByIndex")] - public static extern DL_STATUS ReaderList_GetSerialByIndex(Int32 DeviceIndex, out UInt32 lpulSerialNumber); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialDesByIndex")] - public static extern DL_STATUS ReaderList_GetSerialDescriptionByIndex(Int32 DeviceIndex, out byte pSerialDescription); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetTypeByIndex")] - public static extern DL_STATUS ReaderList_GetTypeByIndex(Int32 DeviceIndex, out UInt32 lpulReaderType); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDISerialByIndex")] - private static extern DL_STATUS GetFTDISerialByIndex(UInt32 DeviceIndex, out IntPtr DeviceSerial); - public static DL_STATUS ReaderList_GetFTDISerialByIndex(UInt32 DeviceIndex, out string DeviceSerial) - { - IntPtr ptr; - DL_STATUS status = DL_STATUS.UFR_OK; - - status = GetFTDISerialByIndex(DeviceIndex, out ptr); - DeviceSerial = Marshal.PtrToStringAnsi(ptr); - return status; - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDIDescriptionByIndex")] - private static extern DL_STATUS GetFTDIDescriptionByIndex(UInt32 DeviceIndex, out IntPtr DeviceDescription); - public static DL_STATUS ReaderList_GetFTDIDescriptionByIndex(UInt32 DeviceIndex, out string DeviceDescription) - { - IntPtr ptr; - DL_STATUS status = DL_STATUS.UFR_OK; - - status = GetFTDIDescriptionByIndex(DeviceIndex, out ptr); - DeviceDescription = Marshal.PtrToStringAnsi(ptr); - return status; - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_OpenByIndex")] - public static extern DL_STATUS ReaderList_OpenByIndex(Int32 DeviceIndex, out UFR_HANDLE hndUFR); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDllVersion")] - public static extern UInt32 GetDllVersion(); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderHardwareVersion")] - public static extern DL_STATUS GetReaderHardwareVersion(out byte version_major, out byte version_minor); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderFirmwareVersion")] - public static extern DL_STATUS GetReaderFirmwareVersion(out byte version_major, out byte version_minor); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetBuildNumber")] - public static extern DL_STATUS GetBuildNumber(out byte build); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "SectorTrailerWriteUnsafe_PK")] - public static extern DL_STATUS SectorTrailerWriteUnsafe_PK(byte addressing_mode, byte address, out byte sector_trailer, - byte auth_mode, ref byte key); - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "LinearWrite_PK")] - public static extern DL_STATUS LinearWrite_PK([In] byte[] data, ushort linear_address, ushort length, out ushort bytes_written, - byte auth_mode, [In] byte[] key); - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "EE_Lock")] - private static extern DL_STATUS Linkage_EE_Lock(StringBuilder password, UInt32 locked); - public static DL_STATUS EE_Lock(String password, UInt32 locked) - { - if (password.Length != 8) - return DL_STATUS.UFR_PARAMETERS_ERROR; - - StringBuilder ptr_password = new StringBuilder(password); - return Linkage_EE_Lock(ptr_password, locked); - } - - //-------------------------------------------------------------------------------------------------------------- - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpen")] - //public static extern DL_STATUS ReaderOpen(); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderClose")] - //public static extern DL_STATUS ReaderClose(); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderReset")] - public static extern DL_STATUS ReaderReset(); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderSoftRestart")] - public static extern DL_STATUS ReaderSoftRestart(); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "UfrEnterSleepMode")] - public static extern DL_STATUS UfrEnterSleepMode(); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "UfrLeaveSleepMode")] - public static extern DL_STATUS UfrLeaveSleepMode(); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "AutoSleepSet")] - public static extern DL_STATUS AutoSleepSet(byte seconds_wait); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "AutoSleepGet")] - public static extern DL_STATUS AutoSleepGet(out byte seconds_wait); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderType")] - //public static extern DL_STATUS GetReaderType(out UInt32 get_reader_type); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderSerialDescription")] - //public static extern DL_STATUS GetReaderSerialDescription(out byte pSerialDescription); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderSerialNumber")] - public static extern DL_STATUS GetReaderSerialNumber(out UInt32 serial_number); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderKeyWrite")] - public static extern DL_STATUS ReaderKeyWrite([In] byte[] aucKey, byte ucKeyIndex); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderUISignal")] - public static extern DL_STATUS ReaderUISignal(int light_mode, int sound_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReadUserData")] - public static extern DL_STATUS ReadUserData(out byte aucData); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "WriteUserData")] - public static extern DL_STATUS WriteUserData(out byte aucData); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderHardwareVersion")] - //public static extern DL_STATUS GetReaderHardwareVersion(out byte bVerMajor, - // out byte bVerMinor); - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderFirmwareVersion")] - //public static extern DL_STATUS GetReaderFirmwareVersion(out byte bVerMajor, - // out byte bVerMinor); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetDisplayData")] - public static extern DL_STATUS SetDisplayData(out byte display_data, byte data_length); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetSpeakerFrequency")] - public static extern DL_STATUS SetSpeakerFrequency(short fhz); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetDisplayIntensity")] - public static extern DL_STATUS SetDisplayIntensity(Byte intensity); // 0 to 100 [%] - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetDisplayIntensity")] - public static extern DL_STATUS GetDisplayIntensity(out Byte intensity); // 0 to 100 [%] - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetCardIdEx")] - public static extern DL_STATUS GetCardIdEx(out byte bCardType, - [In, Out] byte[] nfc_uid, // NFC_UID_MAX_LEN = 10 - out byte bUidSize); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDlogicCardType")] - //public static extern DL_STATUS GetDlogicCardType(out byte lpucCardType); - - //-------------------------------------------------------------------------------------------------------------- - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_UpdateAndGetCount")] - //public static extern DL_STATUS ReaderList_UpdateAndGetCount(Int32* NumberOfDevices); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialByIndex")] - //public static extern DL_STATUS ReaderList_GetSerialByIndex(Int32 DeviceIndex, UInt32* lpulSerialNumber); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialDesByIndex")] - //public static extern DL_STATUS ReaderList_GetSerialDescriptionByIndex(Int32 DeviceIndex, char* pSerialDescription); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetTypeByIndex")] - //public static extern DL_STATUS ReaderList_GetTypeByIndex(Int32 DeviceIndex, UInt32* lpulReaderType); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDISerialByIndex")] - //public static extern DL_STATUS ReaderList_GetFTDISerialByIndex(Int32 DeviceIndex, char** Device_Serial); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDIDescriptionByIndex")] - //public static extern DL_STATUS ReaderList_GetFTDIDescriptionByIndex(Int32 DeviceIndex, char** Device_Description); - - //-------------------------------------------------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead")] - public static extern DL_STATUS LinearRead([Out] byte[] aucData, - ushort linear_address, - ushort data_len, - out UInt16 bytes_written, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead_AKM1")] - public static extern DL_STATUS LinearRead_AKM1([Out] byte[] aucData, - ushort linear_address, - ushort data_len, - out UInt16 bytes_written, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead_AKM2")] - public static extern DL_STATUS LinearRead_AKM2([Out] byte[] aucData, - ushort linear_address, - ushort data_len, - out UInt16 bytes_written, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead_PK")] - public static extern DL_STATUS LinearRead_PK([Out] byte[] aucData, - ushort linear_address, - ushort data_len, - out UInt16 bytes_written, - byte auth_mode, - [In] byte[] pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite")] - public static extern DL_STATUS LinearWrite([In] byte[] aucData, - ushort linear_address, - ushort data_len, - out UInt16 bytes_written, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite_AKM1")] - public static extern DL_STATUS LinearWrite_AKM1([In] byte[] aucData, - ushort linear_address, - ushort data_len, - out UInt16 bytes_written, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite_AKM2")] - public static extern DL_STATUS LinearWrite_AKM2([In] byte[] aucData, - ushort linear_address, - ushort data_len, - out UInt16 bytes_written, - byte auth_mode); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite_PK")] - //public static extern DL_STATUS LinearWrite_PK(out byte aucData, - // ushort linear_address, - // ushort data_len, - // out UInt16 bytes_written, - // byte key_mode, - // out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead")] - public static extern DL_STATUS BlockRead([Out] byte[] data, - UInt16 block_address, - byte auth_mode, - UInt16 key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead_AKM1")] - public static extern DL_STATUS BlockRead_AKM1([Out] byte[] data, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead_AKM2")] - public static extern DL_STATUS BlockRead_AKM2([Out] byte[] data, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead_PK")] - public static extern DL_STATUS BlockRead_PK([Out] byte[] data, - UInt16 block_address, - byte auth_mode, - [In] byte[] pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite")] - public static extern DL_STATUS BlockWrite([In] byte[] data, - UInt16 block_address, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite_AKM1")] - public static extern DL_STATUS BlockWrite_AKM1([In] byte[] data, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite_AKM2")] - public static extern DL_STATUS BlockWrite_AKM2([In] byte[] data, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite_PK")] - public static extern DL_STATUS BlockWrite_PK([In] byte[] data, - UInt16 block_address, - byte auth_mode, - [In] byte[] pk_key); - - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead")] - public static extern DL_STATUS BlockInSectorRead([Out] byte[] data, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, byte key_index); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead_AKM1")] - public static extern DL_STATUS BlockInSectorRead_AKM1([Out] byte[] data, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead_AKM2")] - public static extern DL_STATUS BlockInSectorRead_AKM2([Out] byte[] data, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead_PK")] - public static extern DL_STATUS BlockInSectorRead_PK([Out] byte[] data, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - [In] byte[] pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite")] - public static extern DL_STATUS BlockInSectorWrite([In] byte[] data, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite_AKM1")] - public static extern DL_STATUS BlockInSectorWrite_AKM1([In] byte[] data, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite_AKM2")] - public static extern DL_STATUS BlockInSectorWrite_AKM2([In] byte[] data, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite_PK")] - public static extern DL_STATUS BlockInSectorWrite_PK([In] byte[] data, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - [In] byte[] pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead")] - public static extern DL_STATUS ValueBlockRead(out Int32 value, - out byte value_addr, - UInt16 block_address, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead_AKM1")] - public static extern DL_STATUS ValueBlockRead_AKM1(out Int32 value, - out byte value_addr, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead_AKM2")] - public static extern DL_STATUS ValueBlockRead_AKM2(out Int32 value, - out byte value_addr, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead_PK")] - public static extern DL_STATUS ValueBlockRead_PK(out Int32 value, - out byte value_addr, - UInt16 block_address, - byte auth_mode, - out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite")] - public static extern DL_STATUS ValueBlockWrite(int value, - byte value_addr, - UInt16 block_address, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite_AKM1")] - public static extern DL_STATUS ValueBlockWrite_AKM1(int value, - byte value_addr, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite_AKM2")] - public static extern DL_STATUS ValueBlockWrite_AKM2(int value, - byte value_addr, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite_PK")] - public static extern DL_STATUS ValueBlockWrite_PK(int value, - byte value_addr, - UInt16 block_address, - byte auth_mode, - out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement")] - public static extern DL_STATUS ValueBlockIncrement(int increment_value, - UInt16 block_address, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement_AKM1")] - public static extern DL_STATUS ValueBlockIncrement_AKM1(int increment_value, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement_AKM2")] - public static extern DL_STATUS ValueBlockIncrement_AKM2(int increment_value, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement_PK")] - public static extern DL_STATUS ValueBlockIncrement_PK(int increment_value, - UInt16 block_address, - byte auth_mode, - out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement")] - public static extern DL_STATUS ValueBlockDecrement(int increment_value, - UInt16 block_address, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement_AKM1")] - public static extern DL_STATUS ValueBlockDecrement_AKM1(int increment_value, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement_AKM2")] - public static extern DL_STATUS ValueBlockDecrement_AKM2(int increment_value, - UInt16 block_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement_PK")] - public static extern DL_STATUS ValueBlockDecrement_PK(int increment_value, - UInt16 block_address, - byte auth_mode, - out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead")] - public static extern DL_STATUS ValueBlockInSectorRead(out Int32 value, - out byte value_addr, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead_AKM1")] - public static extern DL_STATUS ValueBlockInSectorRead_AKM1(out Int32 value, - out byte value_addr, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead_AKM2")] - public static extern DL_STATUS ValueBlockInSectorRead_AKM2(out Int32 value, - out byte value_addr, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead_PK")] - public static extern DL_STATUS ValueBlockInSectorRead_PK(out Int32 value, - out byte value_addr, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite")] - public static extern DL_STATUS ValueBlockInSectorWrite(Int32 value, - byte value_addr, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite_AKM1")] - public static extern DL_STATUS ValueBlockInSectorWrite_AKM1(Int32 value, - byte value_addr, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite_AKM2")] - public static extern DL_STATUS ValueBlockInSectorWrite_AKM2(Int32 value, - byte value_addr, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite_PK")] - public static extern DL_STATUS ValueBlockInSectorWrite_PK(Int32 value, - byte value_addr, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement")] - public static extern DL_STATUS ValueBlockInSectorIncrement(Int32 increment_value, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement_AKM1")] - public static extern DL_STATUS ValueBlockInSectorIncrement_AKM1(Int32 increment_value, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement_AKM2")] - public static extern DL_STATUS ValueBlockInSectorIncrement_AKM2(Int32 increment_value, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement_PK")] - public static extern DL_STATUS ValueBlockInSectorIncrement_PK(Int32 increment_value, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement")] - public static extern DL_STATUS ValueBlockInSectorDecrement(Int32 decrement_value, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement_AKM1")] - public static extern DL_STATUS ValueBlockInSectorDecrement_AKM1(Int32 decrement_value, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement_AKM2")] - public static extern DL_STATUS ValueBlockInSectorDecrement_AKM2(Int32 decrement_value, - byte sector_address, - byte block_in_sector_address, - byte auth_mode); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement_PK")] - public static extern DL_STATUS ValueBlockInSectorDecrement_PK(Int32 decrement_value, - byte sector_address, - byte block_in_sector_address, - byte auth_mode, - out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite")] - public static extern DL_STATUS SectorTrailerWrite(byte addressing_mode, - byte address, - out byte new_key_A, - byte block0_access_bits, - byte block1_access_bits, - byte block2_access_bits, - byte sector_trailer_access_bits, - byte sector_trailer_byte9, - out byte new_key_B, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite_AKM1")] - public static extern DL_STATUS SectorTrailerWrite_AKM1(byte addressing_mode, - byte address, - out byte new_key_A, - byte block0_access_bits, - byte block1_access_bits, - byte block2_access_bits, - byte sector_trailer_access_bits, - byte sector_trailer_byte9, - out byte new_key_B, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite_AKM2")] - public static extern DL_STATUS SectorTrailerWrite_AKM2(byte addressing_mode, - byte address, - out byte new_key_A, - byte block0_access_bits, - byte block1_access_bits, - byte block2_access_bits, - byte sector_trailer_access_bits, - byte sector_trailer_byte9, - out byte new_key_B, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite_PK")] - public static extern DL_STATUS SectorTrailerWrite_PK(byte addressing_mode, - byte address, - out byte new_key_A, - byte block0_access_bits, - byte block1_access_bits, - byte block2_access_bits, - byte sector_trailer_access_bits, - byte sector_trailer_byte9, - out byte new_key_B, - byte auth_mode, - out byte pk_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearFormatCard")] - public static extern DL_STATUS LinearFormatCard(out byte new_key_A, - byte blocks_access_bits, - byte sector_trailers_access_bits, - byte sector_trailers_byte9, - out byte new_key_B, - out byte sectors_formatted, - byte auth_mode, - byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearFormatCard_AKM1")] - public static extern DL_STATUS LinearFormatCard_AKM1(out byte new_key_A, - byte blocks_access_bits, - byte sector_trailers_access_bits, - byte sector_trailers_byte9, - out byte new_key_B, - out byte sectors_formatted, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearFormatCard_AKM2")] - public static extern DL_STATUS LinearFormatCard_AKM2(out byte new_key_A, - byte blocks_access_bits, - byte sector_trailers_access_bits, - byte sector_trailers_byte9, - out byte new_key_B, - out byte sectors_formatted, - byte auth_mode); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearFormatCard_PK")] - public static extern DL_STATUS LinearFormatCard_PK(out byte new_key_A, - byte blocks_access_bits, - byte sector_trailers_access_bits, - byte sector_trailers_byte9, - out byte new_key_B, - out byte sectors_formatted, - byte auth_mode, - out byte pk_key); - - //---------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetISO14443_4_Mode")] - public static extern DL_STATUS SetISO14443_4_Mode(); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "s_block_deselect")] - public static extern DL_STATUS s_block_deselect(byte timeout); - //---------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppSelectByAid")] - public static extern DL_STATUS JCAppSelectByAid([In] byte[] aid, byte aid_len, [Out] byte[] selection_response); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPutPrivateKey")] - public static extern DL_STATUS JCAppPutPrivateKey(byte key_type, byte key_index, - [In] byte[] key, UInt16 key_bit_len, - [In] byte[] key_param, UInt16 key_parm_len); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGenerateKeyPair")] - public static extern DL_STATUS JCAppGenerateKeyPair(byte key_type, byte key_index, byte key_designator, - UInt16 key_bit_len, [In] byte[] param, UInt16 param_size); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppDeleteRsaKeyPair")] - public static extern DL_STATUS JCAppDeleteRsaKeyPair(byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppDeleteEcKeyPair")] - public static extern DL_STATUS JCAppDeleteEcKeyPair(byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppSignatureBegin")] - public static extern DL_STATUS JCAppSignatureBegin(byte cipher, byte digest, byte padding, byte key_index, - [In] byte[] chunk, UInt16 chunk_len, - [In] byte[] alg_param, UInt16 alg_parm_len); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppSignatureUpdate")] - public static extern DL_STATUS JCAppSignatureUpdate([In] byte[] chunk, UInt16 chunk_len); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppSignatureEnd")] - private static extern DL_STATUS JCAppSignatureEnd(out UInt16 sig_len); - public static DL_STATUS JCAppSignatureEnd(out byte[] sig) - { - DL_STATUS status; - UInt16 sig_len; - - status = JCAppSignatureEnd(out sig_len); - if (status != DL_STATUS.UFR_OK) - { - sig = null; - return status; - } - - sig = new byte[sig_len]; - return JCAppGetSignature(sig, sig_len); - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGenerateSignature")] - private static extern DL_STATUS JCAppGenerateSignature(byte cipher, byte digest, byte padding, byte key_index, - [In] byte[] plain_data, UInt16 plain_data_len, - out UInt16 sig_len, - [In] byte[] alg_param, UInt16 alg_parm_len); - - public static DL_STATUS JCAppGenerateSignature(byte cipher, byte digest, byte padding, byte key_index, - [In] byte[] plain_data, UInt16 plain_data_len, - out byte[] sig, - [In] byte[] alg_param, UInt16 alg_parm_len) - { - DL_STATUS status; - UInt16 sig_len; - - status = JCAppGenerateSignature(cipher, digest, padding, key_index, plain_data, plain_data_len, out sig_len, alg_param, alg_parm_len); - if (status != DL_STATUS.UFR_OK) - { - sig = null; - return status; - } - - sig = new byte[sig_len]; - return JCAppGetSignature(sig, sig_len); - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetSignature")] - private static extern DL_STATUS JCAppGetSignature([Out] byte[] sig, UInt16 sig_len); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPutObj")] - public static extern DL_STATUS JCAppPutObj(byte obj_type, byte obj_index, [In] byte[] obj, UInt16 obj_size, [In] byte[] id, byte id_size); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPutObjSubject")] - public static extern DL_STATUS JCAppPutObjSubject(byte obj_type, byte obj_index, [In] byte[] subject, byte size); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppInvalidateCert")] - public static extern DL_STATUS JCAppInvalidateCert(byte obj_type, byte obj_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetObjId")] - private static extern DL_STATUS JCAppGetObjId(byte obj_type, byte obj_index, [Out] byte[] id, out UInt16 id_size); - public static DL_STATUS JCAppGetObjId(byte obj_type, byte obj_index, out byte[] id, out UInt16 size) - { - DL_STATUS status; - - size = 0; - id = null; - status = JCAppGetObjId(obj_type, obj_index, id, out size); - if (status == DL_STATUS.UFR_OK) - { - id = new byte[size]; - status = JCAppGetObjId(obj_type, obj_index, id, out size); - } - return status; - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetObjSubject")] - private static extern DL_STATUS JCAppGetObjSubject(byte obj_type, byte obj_index, [Out] byte[] subject, out byte subject_size); - public static DL_STATUS JCAppGetObjSubject(byte obj_type, byte obj_index, out byte[] subject, out byte size) - { - DL_STATUS status; - - size = 0; - subject = null; - status = JCAppGetObjSubject(obj_type, obj_index, subject, out size); - if (status == DL_STATUS.UFR_OK) - { - subject = new byte[size]; - status = JCAppGetObjSubject(obj_type, obj_index, subject, out size); - } - return status; - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetObj")] - private static extern DL_STATUS JCAppGetObj(byte obj_type, byte obj_index, [Out] byte[] obj, UInt16 size); - public static DL_STATUS JCAppGetObj(byte obj_type, byte obj_index, byte[] obj) - { - return JCAppGetObj(obj_type, obj_index, obj, (UInt16) obj.Length); - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetErrorDescription")] - private static extern IntPtr GetErrorDescription(UInt32 apdu_error_status); - public static string JCAppGetErrorDescription(UInt32 apdu_error_status) - { - IntPtr str_ret = GetErrorDescription(apdu_error_status); - return Marshal.PtrToStringAnsi(str_ret); - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppLogin")] - public static extern DL_STATUS JCAppLogin(byte SO, [In] byte[] pin, byte pinSize); - public static DL_STATUS JCAppLogin(bool SO, string pin) - { - if (pin.Length > byte.MaxValue) - return DL_STATUS.UFR_PARAMETERS_ERROR; - - byte[] pin_param = Encoding.ASCII.GetBytes(pin); - return JCAppLogin(SO ? (byte)1 : (byte)0, pin_param, (byte)pin_param.Length); - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetPinTriesRemaining")] - public static extern DL_STATUS JCAppGetPinTriesRemaining(DL_SECURE_CODE secureCodeType, out UInt16 triesRemaining); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPinChange")] - public static extern DL_STATUS JCAppPinChange(DL_SECURE_CODE secureCodeType, [In] byte[] newPin, byte newPinSize); - public static DL_STATUS JCAppPinChange(DL_SECURE_CODE secureCodeType, string newPin) - { - if (newPin.Length > byte.MaxValue) - return DL_STATUS.UFR_PARAMETERS_ERROR; - - byte[] newPin_param = Encoding.ASCII.GetBytes(newPin); - return JCAppPinChange(secureCodeType, newPin_param, (byte)newPin_param.Length); - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPinUnblock")] - public static extern DL_STATUS JCAppPinUnblock(byte SO, [In] byte[] puk, byte pukSize); - public static DL_STATUS JCAppPinUnblock(bool SO, string puk) +using System; +using System.Text; + +namespace uFR +{ + using System.Runtime.InteropServices; + using UFR_HANDLE = System.UIntPtr; + + enum CARD_SAK + { + UNKNOWN = 0x00, + MIFARE_CLASSIC_1k = 0x08, + MF1ICS50 = 0x08, + SLE66R35 = 0x88, + MIFARE_CLASSIC_4k = 0x18, + MF1ICS70 = 0x18, + MIFARE_CLASSIC_MINI = 0x09, + MF1ICS20 = 0x09, + } + + enum DLOGIC_CARD_TYPE + { + DL_NO_CARD = 0x00, + DL_MIFARE_ULTRALIGHT = 0x01, + DL_MIFARE_ULTRALIGHT_EV1_11 = 0x02, + DL_MIFARE_ULTRALIGHT_EV1_21 = 0x03, + DL_MIFARE_ULTRALIGHT_C = 0x04, + DL_NTAG_203 = 0x05, + DL_NTAG_210 = 0x06, + DL_NTAG_212 = 0x07, + DL_NTAG_213 = 0x08, + DL_NTAG_215 = 0x09, + DL_NTAG_216 = 0x0A, + DL_MIKRON_MIK640D = 0x0B, + NFC_T2T_GENERIC = 0x0C, + DL_MIFARE_MINI = 0x20, + DL_MIFARE_CLASSIC_1K = 0x21, + DL_MIFARE_CLASSIC_4K = 0x22, + DL_MIFARE_PLUS_S_2K_SL0 = 0x23, + DL_MIFARE_PLUS_S_4K_SL0 = 0x24, + DL_MIFARE_PLUS_X_2K_SL0 = 0x25, + DL_MIFARE_PLUS_X_4K_SL0 = 0x26, + DL_MIFARE_DESFIRE = 0x27, + DL_MIFARE_DESFIRE_EV1_2K = 0x28, + DL_MIFARE_DESFIRE_EV1_4K = 0x29, + DL_MIFARE_DESFIRE_EV1_8K = 0x2A, + DL_MIFARE_DESFIRE_EV2_2K = 0x2B, + DL_MIFARE_DESFIRE_EV2_4K = 0x2C, + DL_MIFARE_DESFIRE_EV2_8K = 0x2D, + DL_MIFARE_PLUS_S_2K_SL1 = 0x2E, + DL_MIFARE_PLUS_X_2K_SL1 = 0x2F, + DL_MIFARE_PLUS_EV1_2K_SL1 = 0x30, + DL_MIFARE_PLUS_X_2K_SL2 = 0x31, + DL_MIFARE_PLUS_S_2K_SL3 = 0x32, + DL_MIFARE_PLUS_X_2K_SL3 = 0x33, + DL_MIFARE_PLUS_EV1_2K_SL3 = 0x34, + DL_MIFARE_PLUS_S_4K_SL1 = 0x35, + DL_MIFARE_PLUS_X_4K_SL1 = 0x36, + DL_MIFARE_PLUS_EV1_4K_SL1 = 0x37, + DL_MIFARE_PLUS_X_4K_SL2 = 0x38, + DL_MIFARE_PLUS_S_4K_SL3 = 0x39, + DL_MIFARE_PLUS_X_4K_SL3 = 0x3A, + DL_MIFARE_PLUS_EV1_4K_SL3 = 0x3B, + DL_UNKNOWN_ISO_14443_4 = 0x40, + DL_GENERIC_ISO14443_4 = 0x40, + DL_GENERIC_ISO14443_4_TYPE_B = 0x41, + DL_GENERIC_ISO14443_3_TYPE_B = 0x42, + DL_IMEI_UID = 0x80 + +} + // MIFARE CLASSIC Authentication Modes: + enum MIFARE_AUTHENTICATION + { + MIFARE_AUTHENT1A = 0x60, + MIFARE_AUTHENT1B = 0x61 + } + + //MIFARE PLUS AES Authentication Modes: + enum MIFARE_PLUS_AES_AUTHENTICATION + { + MIFARE_PLUS_AES_AUTHENT1A = 0x80, + MIFARE_PLUS_AES_AUTHENT1B = 0x81 + } + + // DLJavaCardSignerCardTypes: + enum JCDL_SIGNER_CARDS + { + DLSigner81 = 0xA0, + DLSigner22 = 0xA1, + DLSigner30 = 0xA2, + DLSigner10 = 0xA3, + DLSigner145 = 0xAA + } + // DLJavaCardSignerAlgorithmTypes: + enum JCDL_SIGNER_CIPHERS + { + SIG_CIPHER_RSA = 0, + SIG_CIPHER_ECDSA + }; + enum JCDL_SIGNER_PADDINGS + { + PAD_NULL = 0, + PAD_PKCS1 + }; + enum JCDL_SIGNER_DIGESTS + { + ALG_NULL = 0, + ALG_SHA, + ALG_SHA_256, + ALG_SHA_384, + ALG_SHA_512, + ALG_SHA_224 + }; + enum JCDL_KEY_TYPES + { + TYPE_RSA_PRIVATE = 0, + TYPE_RSA_CRT_PRIVATE, + TYPE_EC_F2M_PRIVATE, + TYPE_EC_FP_PRIVATE + }; + enum JCDS_EC_KEY_DESIGNATOR + { + EC_KEY_DSG_K1 = 0, + EC_KEY_DSG_R1, + EC_KEY_DSG_R2, + EC_KEY_DSG_RFU + } + // API Status Codes Type: + public enum DL_STATUS + { + UFR_OK = 0x00, + + UFR_COMMUNICATION_ERROR = 0x01, + UFR_CHKSUM_ERROR = 0x02, + UFR_READING_ERROR = 0x03, + UFR_WRITING_ERROR = 0x04, + UFR_BUFFER_OVERFLOW = 0x05, + UFR_MAX_ADDRESS_EXCEEDED = 0x06, + UFR_MAX_KEY_INDEX_EXCEEDED = 0x07, + UFR_NO_CARD = 0x08, + UFR_COMMAND_NOT_SUPPORTED = 0x09, + UFR_FORBIDEN_DIRECT_WRITE_IN_SECTOR_TRAILER = 0x0A, + UFR_ADDRESSED_BLOCK_IS_NOT_SECTOR_TRAILER = 0x0B, + UFR_WRONG_ADDRESS_MODE = 0x0C, + UFR_WRONG_ACCESS_BITS_VALUES = 0x0D, + UFR_AUTH_ERROR = 0x0E, + UFR_PARAMETERS_ERROR = 0x0F, + UFR_MAX_SIZE_EXCEEDED = 0x10, + UFR_UNSUPPORTED_CARD_TYPE = 0x11, + + UFR_WRITE_VERIFICATION_ERROR = 0x70, + UFR_BUFFER_SIZE_EXCEEDED = 0x71, + UFR_VALUE_BLOCK_INVALID = 0x72, + UFR_VALUE_BLOCK_ADDR_INVALID = 0x73, + UFR_VALUE_BLOCK_MANIPULATION_ERROR = 0x74, + UFR_WRONG_UI_MODE = 0x75, + UFR_KEYS_LOCKED = 0x76, + UFR_KEYS_UNLOCKED = 0x77, + UFR_WRONG_PASSWORD = 0x78, + UFR_CAN_NOT_LOCK_DEVICE = 0x79, + UFR_CAN_NOT_UNLOCK_DEVICE = 0x7A, + UFR_DEVICE_EEPROM_BUSY = 0x7B, + UFR_RTC_SET_ERROR = 0x7C, + + ANTI_COLLISION_DISABLED = 0x7D, + + UFR_COMMUNICATION_BREAK = 0x50, + UFR_NO_MEMORY_ERROR = 0x51, + UFR_CAN_NOT_OPEN_READER = 0x52, + UFR_READER_NOT_SUPPORTED = 0x53, + UFR_READER_OPENING_ERROR = 0x54, + UFR_READER_PORT_NOT_OPENED = 0x55, + UFR_CANT_CLOSE_READER_PORT = 0x56, + + UFR_TIMEOUT_ERR = 0x90, + + UFR_FT_STATUS_ERROR_1 = 0xA0, + UFR_FT_STATUS_ERROR_2 = 0xA1, + UFR_FT_STATUS_ERROR_3 = 0xA2, + UFR_FT_STATUS_ERROR_4 = 0xA3, + UFR_FT_STATUS_ERROR_5 = 0xA4, + UFR_FT_STATUS_ERROR_6 = 0xA5, + UFR_FT_STATUS_ERROR_7 = 0xA6, + UFR_FT_STATUS_ERROR_8 = 0xA7, + UFR_FT_STATUS_ERROR_9 = 0xA8, + + //NDEF error codes + UFR_WRONG_NDEF_CARD_FORMAT = 0x80, + UFR_NDEF_MESSAGE_NOT_FOUND = 0x81, + UFR_NDEF_UNSUPPORTED_CARD_TYPE = 0x82, + UFR_NDEF_CARD_FORMAT_ERROR = 0x83, + UFR_MAD_NOT_ENABLED = 0x84, + UFR_MAD_VERSION_NOT_SUPPORTED = 0x85, + + + // multiple units - return from the functions with ReaderList_ prefix in name + UFR_DEVICE_WRONG_HANDLE = 0x100, + UFR_DEVICE_INDEX_OUT_OF_BOUND, + UFR_DEVICE_ALREADY_OPENED, + UFR_DEVICE_ALREADY_CLOSED, + UFR_DEVICE_IS_NOT_CONNECTED, + + // Originality Check Error Codes: + UFR_NOT_NXP_GENUINE = 0x200, + UFR_OPEN_SSL_DYNAMIC_LIB_FAILED, + UFR_OPEN_SSL_DYNAMIC_LIB_NOT_FOUND, + + UFR_NOT_IMPLEMENTED = 0x1000, + UFR_COMMAND_FAILED, + + //MIFARE PLUS error codes + UFR_MFP_COMMAND_OVERFLOW = 0xB0, + UFR_MFP_INVALID_MAC = 0xB1, + UFR_MFP_INVALID_BLOCK_NR = 0xB2, + UFR_MFP_NOT_EXIST_BLOCK_NR = 0xB3, + UFR_MFP_COND_OF_USE_ERROR = 0xB4, + UFR_MFP_LENGTH_ERROR = 0xB5, + UFR_MFP_GENERAL_MANIP_ERROR = 0xB6, + UFR_MFP_SWITCH_TO_ISO14443_4_ERROR = 0xB7, + UFR_MFP_ILLEGAL_STATUS_CODE = 0xB8, + UFR_MFP_MULTI_BLOCKS_READ = 0xB9, + + // APDU Error Codes: + UFR_APDU_TRANSCEIVE_ERROR = 0xAE, + UFR_APDU_JC_APP_NOT_SELECTED = 0x6000, + UFR_APDU_JC_APP_BUFF_EMPTY, + UFR_APDU_WRONG_SELECT_RESPONSE, + UFR_APDU_WRONG_KEY_TYPE, + UFR_APDU_WRONG_KEY_SIZE, + UFR_APDU_WRONG_KEY_PARAMS, + UFR_APDU_WRONG_SIGNING_ALGORITHM, + UFR_APDU_PLAIN_TEXT_SIZE_EXCEEDED, + UFR_APDU_UNSUPPORTED_KEY_SIZE, + UFR_APDU_UNSUPPORTED_ALGORITHMS, + UFR_APDU_PKI_OBJECT_NOT_FOUND, + UFR_APDU_SW_TAG = 0x0A0000, + + MAX_UFR_STATUS = 0x7FFFFFFF + }; + + public enum DL_SECURE_CODE + { + USER_PIN = 0, + SO_PIN, + USER_PUK, + SO_PUK + }; + + public enum DESFIRE_CARD_STATUS_CODES + { + READER_ERROR = 2999, + CARD_OPERATION_OK = 3001, + WRONG_KEY_TYPE = 3002, + KEY_AUTH_ERROR = 3003, + CARD_CRYPTO_ERROR = 3004, + READER_CARD_COMM_ERROR = 3005, + PC_READER_COMM_ERROR = 3006, + COMMIT_TRANSACTION_NO_REPLY = 3007, + COMMIT_TRANSACTION_ERROR = 3008, + DESFIRE_CARD_NO_CHANGES = 0x0C0C, + DESFIRE_CARD_OUT_OF_EEPROM_ERROR = 0x0C0E, + DESFIRE_CARD_ILLEGAL_COMMAND_CODE = 0x0C1C, + DESFIRE_CARD_INTEGRITY_ERROR = 0x0C1E, + DESFIRE_CARD_NO_SUCH_KEY = 0x0C40, + DESFIRE_CARD_LENGTH_ERROR = 0x0C7E, + DESFIRE_CARD_PERMISSION_DENIED = 0x0C9D, + DESFIRE_CARD_PARAMETER_ERROR = 0x0C9E, + DESFIRE_CARD_APPLICATION_NOT_FOUND = 0x0CA0, + DESFIRE_CARD_APPL_INTEGRITY_ERROR = 0x0CA1, + DESFIRE_CARD_AUTHENTICATION_ERROR = 0x0CAE, + DESFIRE_CARD_ADDITIONAL_FRAME = 0x0CAF, + DESFIRE_CARD_BOUNDARY_ERROR = 0x0CBE, + DESFIRE_CARD_PICC_INTEGRITY_ERROR = 0x0CC1, + DESFIRE_CARD_COMMAND_ABORTED = 0x0CCA, + DESFIRE_CARD_PICC_DISABLED_ERROR = 0x0CCD, + DESFIRE_CARD_COUNT_ERROR = 0x0CCE, + DESFIRE_CARD_DUPLICATE_ERROR = 0x0CDE, + DESFIRE_CARD_EEPROM_ERROR_DES = 0x0CEE, + DESFIRE_CARD_FILE_NOT_FOUND = 0x0CF0, + DESFIRE_CARD_FILE_INTEGRITY_ERROR = 0x0CF1 + }; + + public enum DESFIRE_KEY_SETTINGS + { + DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_CHANGE_KEY_CHANGE = 0x09, + DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_CHANGE_KEY_CHANGE = 0x0F, + DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_NOT_CHANGE_KEY_CHANGE = 0x01, + DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_NOT_CHANGE_KEY_CHANGE = 0x07, + DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_CHANGE_KEY_NOT_CHANGE = 0x08, + DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_CHANGE_KEY_NOT_CHANGE = 0x0E, + DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_NOT_CHANGE_KEY_NOT_CHANGE = 0x00, + DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_NOT_CHANGE_KEY_NOT_CHANGE = 0x06 + }; + + public static class uFCoder + { + public const uint JCAPP_MIN_PIN_LENGTH = 4; + public const uint JCAPP_MAX_PIN_LENGTH = 8; + public const uint JCAPP_PUK_LENGTH = 8; + public const uint SIG_MAX_PLAIN_DATA_LEN = 255; + public const string JCDL_AID_RID_PLUS = "F0 44 4C 6F 67 69 63"; + public const string JCDL_AID_PIX = "00 01"; + public const string JCDL_AID = JCDL_AID_RID_PLUS + JCDL_AID_PIX; + + const UInt32 MIN_UFR_LIB_VERSION = 0x05000003; // bytes from left to right: MSB=MajorVer, MidSB_H=MinorVer, MidSB_L=0, LSB=BuildNum + const UInt32 MIN_UFR_FW_VERSION = 0x05000007; // bytes from left to right: MSB=MajorVer, MidSB_H=MinorVer, MidSB_L=0, LSB=BuildNum + + //... + //... + //... + [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetDllDirectory(string lpPathName); + +#if WIN64 + const string DLL_PATH = @"..\..\..\ufr-lib\windows\x86_64\"; + const string NAME_DLL = "uFCoder-x86_64.dll"; + +#else + const string DLL_PATH = @"..\..\ufr-lib\windows\x86\"; + const string NAME_DLL = "uFCoder-x86.dll"; +#endif + const string DLL_NAME = DLL_PATH + NAME_DLL; + + public static void uFrOpen() + { + DL_STATUS status; + UInt32 version = 0; + byte version_major; + byte version_minor; + UInt16 lib_build; + byte fw_build; + String uFR_NotOpenedMessage; + + +#if WIN64 + string DllPath = @"lib\windows\x86_64"; // for x64 target + string name = "uFCoder-x86_64.dll"; +#else + string DllPath = @"lib\windows\x86"; // for x86 target + string name = "uFCoder-x86.dll"; +#endif + string dll_name = DllPath + name; + int repeat_cnt = 0; + bool repeat = true; + do + { + DllPath = @"..\" + DllPath; + SetDllDirectory(DllPath); + try + { + version = uFCoder.GetDllVersion(); + repeat = false; + } + catch (System.Exception) + { + ++repeat_cnt; + } + + } while (repeat && repeat_cnt < 3); // relative path upper folders level search + + if (repeat) + throw new Exception("Can't find " + dll_name + ".\r\nYou will not be able to work with DL Signer cards."); + + // Check lib version: + version_major = (byte)version; + version_minor = (byte)(version >> 8); + lib_build = (ushort)(version >> 16); + + version = ((UInt32)version_major << 24) | ((UInt32)version_minor << 16) | (UInt32)lib_build; + if (version < MIN_UFR_LIB_VERSION) + { + uFR_NotOpenedMessage = "Wrong uFCoder library version.\r\n" + + "You can't work with DL Signer cards.\r\n\r\nUse uFCoder library " + + (MIN_UFR_LIB_VERSION >> 24) + "." + ((MIN_UFR_LIB_VERSION >> 16) & 0xFF) + + "." + (MIN_UFR_LIB_VERSION & 0xFFFF) + " or higher."; + throw new Exception("Wrong uFCoder library version.\r\n" + + "You can't work with DL Signer cards.\r\n\r\nUse uFCoder library " + + (MIN_UFR_LIB_VERSION >> 24) + "." + ((MIN_UFR_LIB_VERSION >> 16) & 0xFF) + + "." + (MIN_UFR_LIB_VERSION & 0xFFFF) + " or higher."); + } + + status = ReaderOpen(); + if (status != (UInt32)uFR.DL_STATUS.UFR_OK) + { + uFR_NotOpenedMessage = "uFR reader not opened.\r\nYou can't work with Desfire cards." + + "\r\n\r\nTry to connect uFR reader and restart application."; + throw new Exception("Can't open uFR reader.\r\nYou will not be able to work with Desfire cards."); + } + + // Check firmware version: + status = GetReaderFirmwareVersion(out version_major, out version_minor); + if (status != (UInt32)uFR.DL_STATUS.UFR_OK) + { + uFCoder.ReaderClose(); + throw new Exception("Can't open uFR reader.\r\nYou will not be able to work with Desfire cards."); + } + status = GetBuildNumber(out fw_build); + if (status != (UInt32)uFR.DL_STATUS.UFR_OK) + { + uFCoder.ReaderClose(); + throw new Exception("Can't open uFR reader.\r\nYou will not be able to work with Desfire cards."); + } + + version = ((UInt32)version_major << 24) | ((UInt32)version_minor << 16) | (UInt32)fw_build; + if (version < MIN_UFR_FW_VERSION) + { + uFCoder.ReaderClose(); + uFR_NotOpenedMessage = "Wrong uFR firmware version.\r\n" + + "You can't work with Desfire cards.\r\n\r\nPlease update firmware to " + + (MIN_UFR_FW_VERSION >> 24) + "." + ((MIN_UFR_FW_VERSION >> 16) & 0xFF) + + "." + (MIN_UFR_FW_VERSION & 0xFFFF) + " or higher."; + throw new Exception("Wrong uFR firmware version.\r\n" + + "Some functions with DESFIRE CARDS will be unavailable.\r\n\r\nPlease update firmware to " + + (MIN_UFR_FW_VERSION >> 24) + "." + ((MIN_UFR_FW_VERSION >> 16) & 0xFF) + + "." + (MIN_UFR_FW_VERSION & 0xFFFF) + " or higher and restart application."); + } + + + } + + //-------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------- + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpen")] + public static extern DL_STATUS ReaderOpen(); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpenEx")] + private static extern DL_STATUS ReaderOpenEx(UInt32 reader_type, [In] byte[] port_name, UInt32 port_interface, [In] byte[] arg); + public static DL_STATUS ReaderOpenEx(UInt32 reader_type, string port_name, UInt32 port_interface, string arg) { - if (puk.Length > byte.MaxValue) - return DL_STATUS.UFR_PARAMETERS_ERROR; - - byte[] puk_param = Encoding.ASCII.GetBytes(puk); - return JCAppPinUnblock(SO ? (byte)1 : (byte)0, puk_param, (byte)puk_param.Length); - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetRsaPublicKey")] - private static extern DL_STATUS JCAppGetRsaPublicKey(byte key_index, [Out] byte[] modulus, out UInt16 modulus_size, - [Out] byte[] exponent, out UInt16 exponent_size); - public static DL_STATUS JCAppGetRsaPublicKey(byte key_index, out byte[] modulus, out byte[] exponent) - { - DL_STATUS status; - - UInt16 modulus_size = 0; - UInt16 exponent_size = 0; - modulus = null; - exponent = null; - status = JCAppGetRsaPublicKey(key_index, modulus, out modulus_size, exponent, out exponent_size); - if (status == DL_STATUS.UFR_OK) - { - modulus = new byte[modulus_size]; - exponent = new byte[exponent_size]; - status = JCAppGetRsaPublicKey(key_index, modulus, out modulus_size, exponent, out exponent_size); - } - return status; - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetEcPublicKey")] - private static extern DL_STATUS JCAppGetEcPublicKey(byte key_index, [Out] byte[] keyW, out UInt16 keyW_size, - [Out] byte[] field, out UInt16 field_size, [Out] byte[] ab, out UInt16 ab_size, - [Out] byte[] g, out UInt16 g_size, [Out] byte[] r, out UInt16 r_size, out UInt16 k, out UInt16 key_size_bits, out UInt16 key_designator); - public static DL_STATUS JCAppGetEcPublicKey(byte key_index, out byte[] keyW, out byte[] field, out byte[] a, out byte[] b, out byte[] g, out byte[] r, - out UInt16 k, out UInt16 key_size_bits, out UInt16 key_designator) - { - DL_STATUS status; - - UInt16 keyW_size = 0; - UInt16 field_size = 0; - UInt16 ab_size = 0; - UInt16 g_size = 0; - UInt16 r_size = 0; - byte[] ab = null; - keyW = field = a = b = g = r = null; - k = key_size_bits = key_designator = 0; - status = JCAppGetEcPublicKey(key_index, keyW, out keyW_size, field, out field_size, ab, out ab_size, g, out g_size, - r, out r_size, out k, out key_size_bits, out key_designator); - if (status == DL_STATUS.UFR_OK) - { - keyW = new byte[keyW_size]; - field = new byte[field_size]; - ab = new byte[ab_size]; - g = new byte[g_size]; - r = new byte[r_size]; - status = JCAppGetEcPublicKey(key_index, keyW, out keyW_size, field, out field_size, ab, out ab_size, g, out g_size, - r, out r_size, out k, out key_size_bits, out key_designator); - - if (keyW_size != (UInt16)(((key_size_bits + 7) / 8) * 2 + 1)) - return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; - if ((field_size != (UInt16)((key_size_bits + 7) / 8)) && (field_size != 6) && (field_size != 2)) - return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; - if (ab_size != (UInt16)(((key_size_bits + 7) / 8) * 2)) - return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; - if (g_size != (UInt16)(((key_size_bits + 7) / 8) * 2 + 1)) - return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; - if ((r_size != (UInt16)((key_size_bits + 7) / 8)) && (r_size != (UInt16)(((key_size_bits + 7) / 8) + 1))) - return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; - a = new byte[(key_size_bits + 7) / 8]; - b = new byte[(key_size_bits + 7) / 8]; - Array.Copy(ab, 0, a, 0, (key_size_bits + 7) / 8); - Array.Copy(ab, (key_size_bits + 7) / 8, b, 0, (key_size_bits + 7) / 8); - } - return status; - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "UFR_Status2String")] - private static extern IntPtr UFR_Status2String(DL_STATUS status); - public static string status2str(DL_STATUS status) - { - IntPtr str_ret = UFR_Status2String(status); - return Marshal.PtrToStringAnsi(str_ret); - } - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetEcKeySizeBits")] - public static extern DL_STATUS JCAppGetEcKeySizeBits(byte key_index, out UInt16 key_size_bits, out UInt16 key_designator); - //---------------------------------------------------------------------- - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "UfrXrcLockOn")] - public static extern DL_STATUS UfrXrcLockOn(UInt16 pulse_duration); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "UfrXrcRelayState")] - public static extern DL_STATUS UfrXrcRelayState(byte state); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "UfrXrcGetIoState")] - public static extern DL_STATUS UfrXrcGetIoState(out byte intercom, out byte dig_in, out byte relay_state); - - //---------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpenM")] - public static extern DL_STATUS ReaderOpenM(UFR_HANDLE hndUFR); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderCloseM")] - public static extern DL_STATUS ReaderCloseM(UFR_HANDLE hndUFR); - - //---------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCardIdExM")] - public static extern DL_STATUS GetCardIdExM(UFR_HANDLE hndUFR, - out byte bCardType, - [Out] byte nfc_uid, // NFC_UID_MAX_LEN = 10 - out byte bUidSize); - - //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderTypeM")] - //public static extern DL_STATUS GetReaderTypeM(UInt32* get_reader_type); - - //---------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "BlockRead_PKM")] - public static extern DL_STATUS BlockRead_PKM(UFR_HANDLE hndUFR, - out byte data, - byte block_address, - byte auth_mode, - ref byte key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "BlockWrite_PKM")] - public static extern DL_STATUS BlockWrite_PKM(UFR_HANDLE hndUFR, - out byte data, - byte block_address, - byte auth_mode, - ref byte key); - //---------------------------------------------------------------------- - - //Desfire - //---------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireWriteAesKey")] - public static extern DL_STATUS uFR_int_DesfireWriteAesKey(byte aes_key_no, - [In] byte[] aes_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_GetDesfireUid")] - public static extern DL_STATUS uFR_int_GetDesfireUid(byte aes_key_nr, - UInt32 aid, - byte aid_key_nr, - [Out] byte[] card_uid, - out byte card_uid_len, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_GetDesfireUid_PK")] - public static extern DL_STATUS uFR_int_GetDesfireUid_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte aid_key_nr, - [Out] byte[] card_uid, - out byte card_uid_len, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireFreeMem")] - public static extern DL_STATUS uFR_int_DesfireFreeMem(out UInt32 free_mem_byte, - out UInt16 card_status, - out UInt16 exec_time); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireFormatCard")] - public static extern DL_STATUS uFR_int_DesfireFormatCard(byte aes_key_nr, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireFormatCard_PK")] - public static extern DL_STATUS uFR_int_DesfireFormatCard_PK([In] byte[] aes_key_ext, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireSetConfiguration")] - public static extern DL_STATUS uFR_int_DesfireSetConfiguration(byte aes_key_nr, - byte random_uid, - byte format_disable, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireSetConfiguration_PK")] - public static extern DL_STATUS uFR_int_DesfireSetConfiguration_PK([In] byte[] aes_key_ext, - byte random_uid, - byte format_disable, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireGetKeySettings")] - public static extern DL_STATUS uFR_int_DesfireGetKeySettings(byte aes_key_nr, - UInt32 aid, - out byte settings, - out byte max_key_no, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireGetKeySettings_PK")] - public static extern DL_STATUS uFR_int_DesfireGetKeySettings_PK([In] byte[] aes_key_ext, - UInt32 aid, - out byte settings, - out byte max_key_no, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireChangeKeySettings")] - public static extern DL_STATUS uFR_int_DesfireChangeKeySettings(byte aes_key_nr, - UInt32 aid, - byte settings, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireChangeKeySettings_PK")] - public static extern DL_STATUS uFR_int_DesfireChangeKeySettings_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte settings, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireChangeAesKey")] - public static extern DL_STATUS uFR_int_DesfireChangeAesKey(byte aes_key_nr, - UInt32 aid, - byte aid_key_nr_auth, - [In] byte[] new_aes_key, - byte aid_key_no, - [In] byte[] old_aes_key, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireChangeAesKey_PK")] - public static extern DL_STATUS uFR_int_DesfireChangeAesKey_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte aid_key_nr_auth, - [In] byte[] new_aes_key, - byte aid_key_no, - [In] byte[] old_aes_key, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateAesApplication")] - public static extern DL_STATUS uFR_int_DesfireCreateAesApplication(byte aes_key_nr, - UInt32 aid_nr, - byte setting, - byte max_key_no, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateAesApplication_PK")] - public static extern DL_STATUS uFR_int_DesfireCreateAesApplication_PK([In] byte[] aes_key_ext, - UInt32 aid_nr, - byte setting, - byte max_key_no, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateAesApplication_no_auth")] - public static extern DL_STATUS uFR_int_DesfireCreateAesApplication_no_auth(UInt32 aid_nr, - byte setting, - byte max_key_no, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteApplication")] - public static extern DL_STATUS uFR_int_DesfireDeleteApplication(byte aes_key_nr, - UInt32 aid_nr, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteApplication_PK")] - public static extern DL_STATUS uFR_int_DesfireDeleteApplication_PK([In] byte[] aes_key_ext, - UInt32 aid_nr, - out UInt16 card_status, - out UInt16 exec_time); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateStdDataFile")] - public static extern DL_STATUS uFR_int_DesfireCreateStdDataFile(byte aes_key_nr, - UInt32 aid, - byte file_id, - UInt32 file_size, - byte read_key_no, - byte write_key_no, - byte read_write_key_no, - byte change_key_no, - byte communication_settings, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateStdDataFile_PK")] - public static extern DL_STATUS uFR_int_DesfireCreateStdDataFile_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte file_id, - UInt32 file_size, - byte read_key_no, - byte write_key_no, - byte read_write_key_no, - byte change_key_no, - byte communication_settings, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateStdDataFile_no_auth")] - public static extern DL_STATUS uFR_int_DesfireCreateStdDataFile_no_auth(UInt32 aid, - byte file_id, - UInt32 file_size, - byte read_key_no, - byte write_key_no, - byte read_write_key_no, - byte change_key_no, - byte communication_settings, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteFile")] - public static extern DL_STATUS uFR_int_DesfireDeleteFile(byte aes_key_nr, - UInt32 aid, - byte file_id, - out UInt16 card_status, - out UInt16 exec_time); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteFile_PK")] - public static extern DL_STATUS uFR_int_DesfireDeleteFile_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte file_id, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteFile_no_auth")] - public static extern DL_STATUS uFR_int_DesfireDeleteFile_no_auth(UInt32 aid, - byte file_id, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadStdDataFile")] - public static extern DL_STATUS uFR_int_DesfireReadStdDataFile(byte aes_key_nr, - UInt32 aid, - byte aid_key_nr, - byte file_id, - UInt16 offset, - UInt16 data_length, - byte communication_settings, - [Out] byte[] data, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadStdDataFile_PK")] - public static extern DL_STATUS uFR_int_DesfireReadStdDataFile_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte aid_key_nr, - byte file_id, - UInt16 offset, - UInt16 data_length, - byte communication_settings, - [Out] byte[] data, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadStdDataFile_no_auth")] - public static extern DL_STATUS uFR_int_DesfireReadStdDataFile_no_auth(UInt32 aid, - byte aid_key_nr, - byte file_id, - UInt16 offset, - UInt16 data_length, - byte communication_settings, - [Out] byte[] data, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireWriteStdDataFile")] - public static extern DL_STATUS uFR_int_DesfireWriteStdDataFile(byte aes_key_nr, - UInt32 aid, - byte aid_key_nr, - byte file_id, - UInt16 offset, - UInt16 data_length, - byte communication_settings, - [In] byte[] data, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireWriteStdDataFile_PK")] - public static extern DL_STATUS uFR_int_DesfireWriteStdDataFile_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte aid_key_nr, - byte file_id, - UInt16 offset, - UInt16 data_length, - byte communication_settings, - [In] byte[] data, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireWriteStdDataFile_no_auth")] - public static extern DL_STATUS uFR_int_DesfireWriteStdDataFile_no_auth(UInt32 aid, - byte aid_key_nr, - byte file_id, - UInt16 offset, - UInt16 data_length, - byte communication_settings, - [In] byte[] data, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "DES_to_AES_key_type")] - public static extern DL_STATUS DES_to_AES_key_type(); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "AES_to_DES_key_type")] - public static extern DL_STATUS AES_to_DES_key_type(); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "SetSpeedPermanently")] - public static extern DL_STATUS SetSpeedPermanently(byte tx_speed, byte rx_speed); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetSpeedParameters")] - public static extern DL_STATUS GetSpeedParameters(out byte tx_speed, out byte rx_speed); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateValueFile")] - public static extern DL_STATUS uFR_int_DesfireCreateValueFile(byte aes_key_nr, - UInt32 aid, - byte file_id, - Int32 lower_limit, - Int32 upper_limit, - Int32 value, - byte limited_credit_enabled, - byte read_key_no, - byte write_key_no, - byte read_write_key_no, - byte change_key_no, - byte communication_settings, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateValueFile_PK")] - public static extern DL_STATUS uFR_int_DesfireCreateValueFile_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte file_id, - Int32 lower_limit, - Int32 upper_limit, - Int32 value, - byte limited_credit_enabled, - byte read_key_no, - byte write_key_no, - byte read_write_key_no, - byte change_key_no, - byte communication_settings, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateValueFile_no_auth")] - public static extern DL_STATUS uFR_int_DesfireCreateValueFile_no_auth(UInt32 aid, - byte file_id, - Int32 lower_limit, - Int32 upper_limit, - Int32 value, - byte limited_credit_enabled, - byte read_key_no, - byte write_key_no, - byte read_write_key_no, - byte change_key_no, - byte communication_settings, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadValueFile")] - public static extern DL_STATUS uFR_int_DesfireReadValueFile(byte aes_key_nr, - UInt32 aid, - byte aid_key_nr, - byte file_id, - byte communication_settings, - out Int32 value, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadValueFile_PK")] - public static extern DL_STATUS uFR_int_DesfireReadValueFile_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte aid_key_nr, - byte file_id, - byte communication_settings, - out Int32 value, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadValueFile_no_auth")] - public static extern DL_STATUS uFR_int_DesfireReadValueFile_no_auth(UInt32 aid, - byte aid_key_nr, - byte file_id, - byte communication_settings, - out Int32 value, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireIncreaseValueFile")] - public static extern DL_STATUS uFR_int_DesfireIncreaseValueFile(byte aes_key_nr, - UInt32 aid, - byte aid_key_nr, - byte file_id, - byte communication_settings, - Int32 value, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireIncreaseValueFile_PK")] - public static extern DL_STATUS uFR_int_DesfireIncreaseValueFile_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte aid_key_nr, - byte file_id, - byte communication_settings, - Int32 value, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireIncreaseValueFile_no_auth")] - public static extern DL_STATUS uFR_int_DesfireIncreaseValueFile_no_auth(UInt32 aid, - byte aid_key_nr, - byte file_id, - byte communication_settings, - Int32 value, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDecreaseValueFile")] - public static extern DL_STATUS uFR_int_DesfireDecreaseValueFile(byte aes_key_nr, - UInt32 aid, - byte aid_key_nr, - byte file_id, - byte communication_settings, - Int32 value, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDecreaseValueFile_PK")] - public static extern DL_STATUS uFR_int_DesfireDecreaseValueFile_PK([In] byte[] aes_key_ext, - UInt32 aid, - byte aid_key_nr, - byte file_id, - byte communication_settings, - Int32 value, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDecreaseValueFile_no_auth")] - public static extern DL_STATUS uFR_int_DesfireDecreaseValueFile_no_auth(UInt32 aid, - byte aid_key_nr, - byte file_id, - byte communication_settings, - Int32 value, - out UInt16 card_status, - out UInt16 exec_time); - - //--------------------------------------------------------------------- - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderKeysLock")] - public static extern DL_STATUS ReaderKeysLock([In] char[] password); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderKeysUnlock")] - public static extern DL_STATUS ReaderKeysUnlock([In] char[] password); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderDescription")] - private static extern IntPtr GetReaderDescription(); - public static string GetDescription() - { - IntPtr str_ret = GetReaderDescription(); - return Marshal.PtrToStringAnsi(str_ret); - } - - //-------------------------------------------- MIFARE PLUS -------------------------------------------------// - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_PersonalizationMinimal")] - public static extern DL_STATUS MFP_PersonalizationMinimal([In] byte[] master_key, [In] byte[] config_key, [In] byte[] l2_sw_key, [In] byte[] l3_sw_key, - [In] byte[] l1_auth_key, [In] byte[] sel_vc_key, [In] byte[] prox_chk_key, [In] byte[] vc_poll_enc_key, - [In] byte[] vc_poll_mac_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_AesAuthSecurityLevel1_PK")] - public static extern DL_STATUS MFP_AesAuthSecurityLevel1_PK([In] byte[] sl1_auth_key); - - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_AesAuthSecurityLevel1")] - public static extern DL_STATUS MFP_AesAuthSecurityLevel1(byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_SwitchToSecurityLevel3_PK")] - public static extern DL_STATUS MFP_SwitchToSecurityLevel3_PK([In] byte[] sl3_auth_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_SwitchToSecurityLevel3")] - public static extern DL_STATUS MFP_SwitchToSecurityLevel3(byte key_index); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeMasterKey_PK")] - public static extern DL_STATUS MFP_ChangeMasterKey_PK([In] byte[] old_master_key, [In] byte[] new_master_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeMasterKey")] - public static extern DL_STATUS MFP_ChangeMasterKey(byte key_index, [In] byte[] new_master_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeConfigurationKey_PK")] - public static extern DL_STATUS MFP_ChangeConfigurationKey_PK([In] byte[] old_config_key, [In] byte[] new_config_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeConfigurationKey")] - public static extern DL_STATUS MFP_ChangeConfigurationKey(byte key_index, [In] byte[] new_config_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeSectorKey_PK")] - public static extern DL_STATUS MFP_ChangeSectorKey_PK(byte sector_nr, byte auth_mode, [In] byte[] old_sector_key, [In] byte[] new_sector_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeSectorKey")] - public static extern DL_STATUS MFP_ChangeSectorKey(byte sector_nr, byte auth_mode, byte key_index, [In] byte[] new_sector_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_FieldConfigurationSet_PK")] - public static extern DL_STATUS MFP_FieldConfigurationSet_PK([In] byte[] configuration_key, byte rid_use, byte prox_check_use); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_FieldConfigurationSet")] - public static extern DL_STATUS MFP_FieldConfigurationSet(byte configuration_key_index, byte rid_use, byte prox_check_use); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_GetUid_PK")] - public static extern DL_STATUS MFP_GetUid_PK([In] byte[] vc_poll_enc_key, [In] byte[] vc_poll_mac_key, [In,Out] byte[] nfc_uid,out byte uid_len); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_GetUid")] - public static extern DL_STATUS MFP_GetUid(byte key_index_vc_poll_enc_key, byte key_index_vc_poll_mac_key, [In, Out] byte[] nfc_uid, out byte uid_len); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeVcPollingEncKey_PK")] - public static extern DL_STATUS MFP_ChangeVcPollingEncKey_PK([In] byte[] configuration_key, [In] byte[] new_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeVcPollingEncKey")] - public static extern DL_STATUS MFP_ChangeVcPollingEncKey(byte configuration_key_index, [In] byte[] new_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeVcPollingMacKey_PK")] - public static extern DL_STATUS MFP_ChangeVcPollingMacKey_PK([In] byte[] configuration_key, [In] byte[] new_key); - - //--------------------------------------------------------------------- - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeVcPollingMacKey")] - public static extern DL_STATUS MFP_ChangeVcPollingMacKey(byte configuration_key_index, [In] byte[] new_key); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "write_ndef_record")] - private static extern DL_STATUS write_ndef_record(byte message_nr, [In] byte[] tnf, [In] byte[] type_record, [In] byte[] type_length, [In] byte[] id, [In] byte[] id_length, [In] byte[] payload, [In] UInt32[] payload_length, out byte[] card_formated); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "write_ndef_record_mirroring")] - private static extern DL_STATUS write_ndef_record_mirroring(byte message_nr, [In] byte[] tnf, [In] byte[] type_record, [In] byte[] type_length, [In] byte[] id, [In] byte[] id_length, [In] byte[] payload, [In] UInt32[] payload_length, out byte[] card_formated, int use_uid_ascii_mirror, int use_counter_ascii_mirror, UInt32 payload_mirroring_pos); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "write_ndef_recordM")] - private static extern DL_STATUS write_ndef_recordM(UFR_HANDLE hndUFR, byte message_nr, [In] byte[] tnf, [In] byte[] type_record, [In] byte[] type_length, [In] byte[] id, [In] byte[] id_length, [In] byte[] payload, [In] UInt32[] payload_length, out byte[] card_formated); - - [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "write_ndef_record_mirroringM")] - private static extern DL_STATUS write_ndef_record_mirroringM(UFR_HANDLE hndUFR, byte message_nr, [In] byte[] tnf, [In] byte[] type_record, [In] byte[] type_length, [In] byte[] id, [In] byte[] id_length, [In] byte[] payload, [In] UInt32[] payload_length, out byte[] card_formated, int use_uid_ascii_mirror, int use_counter_ascii_mirror, UInt32 payload_mirroring_pos); - } -} + byte[] port_name_p = Encoding.ASCII.GetBytes(port_name); + byte[] port_name_param = new byte[port_name_p.Length + 1]; + Array.Copy(port_name_p, 0, port_name_param, 0, port_name_p.Length); + port_name_param[port_name_p.Length] = 0; + + byte[] arg_p = Encoding.ASCII.GetBytes(arg); + byte[] arg_param = new byte[arg_p.Length + 1]; + Array.Copy(arg_p, 0, arg_param, 0, arg_p.Length); + arg_param[arg_p.Length] = 0; + + return ReaderOpenEx(reader_type, port_name_param, port_interface, arg_param); + } + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderClose")] + public static extern DL_STATUS ReaderClose(); + + //-------------------------------------------------------------------------------------------------- + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderType")] + public static extern DL_STATUS GetReaderType(out UInt32 lpulReaderType); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderSerialDescription")] + private static extern DL_STATUS getReaderSerialDescription(StringBuilder pSerialDescription); + public static DL_STATUS GetReaderSerialDescription(out string SerialDescription) + { + StringBuilder pSerialDescription = new StringBuilder(7); + DL_STATUS status = DL_STATUS.UFR_OK; + + status = getReaderSerialDescription(pSerialDescription); + if (status == DL_STATUS.UFR_OK) + SerialDescription = pSerialDescription.ToString(); + else + SerialDescription = ""; + return status; + } + + //--------------------------------------------------------------------- + // Card emulation: + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "TagEmulationStart")] + public static extern DL_STATUS TagEmulationStart(); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "TagEmulationStop")] + public static extern DL_STATUS TagEmulationStop(); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "CombinedModeEmulationStart")] + public static extern DL_STATUS CombinedModeEmulationStart(); + //--------------------------------------------------------------------- + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDlogicCardType")] + public static extern DL_STATUS GetDlogicCardType(out byte lpucCardType); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_UpdateAndGetCount")] + public static extern DL_STATUS ReaderList_UpdateAndGetCount(out UInt32 NumberOfDevices); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialByIndex")] + public static extern DL_STATUS ReaderList_GetSerialByIndex(Int32 DeviceIndex, out UInt32 lpulSerialNumber); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialDesByIndex")] + public static extern DL_STATUS ReaderList_GetSerialDescriptionByIndex(Int32 DeviceIndex, out byte pSerialDescription); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetTypeByIndex")] + public static extern DL_STATUS ReaderList_GetTypeByIndex(Int32 DeviceIndex, out UInt32 lpulReaderType); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDISerialByIndex")] + private static extern DL_STATUS GetFTDISerialByIndex(UInt32 DeviceIndex, out IntPtr DeviceSerial); + public static DL_STATUS ReaderList_GetFTDISerialByIndex(UInt32 DeviceIndex, out string DeviceSerial) + { + IntPtr ptr; + DL_STATUS status = DL_STATUS.UFR_OK; + + status = GetFTDISerialByIndex(DeviceIndex, out ptr); + DeviceSerial = Marshal.PtrToStringAnsi(ptr); + return status; + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDIDescriptionByIndex")] + private static extern DL_STATUS GetFTDIDescriptionByIndex(UInt32 DeviceIndex, out IntPtr DeviceDescription); + public static DL_STATUS ReaderList_GetFTDIDescriptionByIndex(UInt32 DeviceIndex, out string DeviceDescription) + { + IntPtr ptr; + DL_STATUS status = DL_STATUS.UFR_OK; + + status = GetFTDIDescriptionByIndex(DeviceIndex, out ptr); + DeviceDescription = Marshal.PtrToStringAnsi(ptr); + return status; + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_OpenByIndex")] + public static extern DL_STATUS ReaderList_OpenByIndex(Int32 DeviceIndex, out UFR_HANDLE hndUFR); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDllVersion")] + public static extern UInt32 GetDllVersion(); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderHardwareVersion")] + public static extern DL_STATUS GetReaderHardwareVersion(out byte version_major, out byte version_minor); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderFirmwareVersion")] + public static extern DL_STATUS GetReaderFirmwareVersion(out byte version_major, out byte version_minor); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetBuildNumber")] + public static extern DL_STATUS GetBuildNumber(out byte build); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "SectorTrailerWriteUnsafe_PK")] + public static extern DL_STATUS SectorTrailerWriteUnsafe_PK(byte addressing_mode, byte address, out byte sector_trailer, + byte auth_mode, ref byte key); + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "LinearWrite_PK")] + public static extern DL_STATUS LinearWrite_PK([In] byte[] data, ushort linear_address, ushort length, out ushort bytes_written, + byte auth_mode, [In] byte[] key); + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "EE_Lock")] + private static extern DL_STATUS Linkage_EE_Lock(StringBuilder password, UInt32 locked); + public static DL_STATUS EE_Lock(String password, UInt32 locked) + { + if (password.Length != 8) + return DL_STATUS.UFR_PARAMETERS_ERROR; + + StringBuilder ptr_password = new StringBuilder(password); + return Linkage_EE_Lock(ptr_password, locked); + } + + //-------------------------------------------------------------------------------------------------------------- + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpen")] + //public static extern DL_STATUS ReaderOpen(); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderClose")] + //public static extern DL_STATUS ReaderClose(); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderReset")] + public static extern DL_STATUS ReaderReset(); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderSoftRestart")] + public static extern DL_STATUS ReaderSoftRestart(); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "UfrEnterSleepMode")] + public static extern DL_STATUS UfrEnterSleepMode(); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "UfrLeaveSleepMode")] + public static extern DL_STATUS UfrLeaveSleepMode(); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "AutoSleepSet")] + public static extern DL_STATUS AutoSleepSet(byte seconds_wait); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "AutoSleepGet")] + public static extern DL_STATUS AutoSleepGet(out byte seconds_wait); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderType")] + //public static extern DL_STATUS GetReaderType(out UInt32 get_reader_type); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderSerialDescription")] + //public static extern DL_STATUS GetReaderSerialDescription(out byte pSerialDescription); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderSerialNumber")] + public static extern DL_STATUS GetReaderSerialNumber(out UInt32 serial_number); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderKeyWrite")] + public static extern DL_STATUS ReaderKeyWrite([In] byte[] aucKey, byte ucKeyIndex); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderUISignal")] + public static extern DL_STATUS ReaderUISignal(int light_mode, int sound_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReadUserData")] + public static extern DL_STATUS ReadUserData(out byte aucData); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "WriteUserData")] + public static extern DL_STATUS WriteUserData(out byte aucData); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderHardwareVersion")] + //public static extern DL_STATUS GetReaderHardwareVersion(out byte bVerMajor, + // out byte bVerMinor); + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderFirmwareVersion")] + //public static extern DL_STATUS GetReaderFirmwareVersion(out byte bVerMajor, + // out byte bVerMinor); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetDisplayData")] + public static extern DL_STATUS SetDisplayData(out byte display_data, byte data_length); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetSpeakerFrequency")] + public static extern DL_STATUS SetSpeakerFrequency(short fhz); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetDisplayIntensity")] + public static extern DL_STATUS SetDisplayIntensity(Byte intensity); // 0 to 100 [%] + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetDisplayIntensity")] + public static extern DL_STATUS GetDisplayIntensity(out Byte intensity); // 0 to 100 [%] + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetCardIdEx")] + public static extern DL_STATUS GetCardIdEx(out byte bCardType, + [In, Out] byte[] nfc_uid, // NFC_UID_MAX_LEN = 10 + out byte bUidSize); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDlogicCardType")] + //public static extern DL_STATUS GetDlogicCardType(out byte lpucCardType); + + //-------------------------------------------------------------------------------------------------------------- + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_UpdateAndGetCount")] + //public static extern DL_STATUS ReaderList_UpdateAndGetCount(Int32* NumberOfDevices); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialByIndex")] + //public static extern DL_STATUS ReaderList_GetSerialByIndex(Int32 DeviceIndex, UInt32* lpulSerialNumber); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialDesByIndex")] + //public static extern DL_STATUS ReaderList_GetSerialDescriptionByIndex(Int32 DeviceIndex, char* pSerialDescription); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetTypeByIndex")] + //public static extern DL_STATUS ReaderList_GetTypeByIndex(Int32 DeviceIndex, UInt32* lpulReaderType); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDISerialByIndex")] + //public static extern DL_STATUS ReaderList_GetFTDISerialByIndex(Int32 DeviceIndex, char** Device_Serial); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDIDescriptionByIndex")] + //public static extern DL_STATUS ReaderList_GetFTDIDescriptionByIndex(Int32 DeviceIndex, char** Device_Description); + + //-------------------------------------------------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead")] + public static extern DL_STATUS LinearRead([Out] byte[] aucData, + ushort linear_address, + ushort data_len, + out UInt16 bytes_written, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead_AKM1")] + public static extern DL_STATUS LinearRead_AKM1([Out] byte[] aucData, + ushort linear_address, + ushort data_len, + out UInt16 bytes_written, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead_AKM2")] + public static extern DL_STATUS LinearRead_AKM2([Out] byte[] aucData, + ushort linear_address, + ushort data_len, + out UInt16 bytes_written, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead_PK")] + public static extern DL_STATUS LinearRead_PK([Out] byte[] aucData, + ushort linear_address, + ushort data_len, + out UInt16 bytes_written, + byte auth_mode, + [In] byte[] pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite")] + public static extern DL_STATUS LinearWrite([In] byte[] aucData, + ushort linear_address, + ushort data_len, + out UInt16 bytes_written, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite_AKM1")] + public static extern DL_STATUS LinearWrite_AKM1([In] byte[] aucData, + ushort linear_address, + ushort data_len, + out UInt16 bytes_written, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite_AKM2")] + public static extern DL_STATUS LinearWrite_AKM2([In] byte[] aucData, + ushort linear_address, + ushort data_len, + out UInt16 bytes_written, + byte auth_mode); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite_PK")] + //public static extern DL_STATUS LinearWrite_PK(out byte aucData, + // ushort linear_address, + // ushort data_len, + // out UInt16 bytes_written, + // byte key_mode, + // out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead")] + public static extern DL_STATUS BlockRead([Out] byte[] data, + UInt16 block_address, + byte auth_mode, + UInt16 key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead_AKM1")] + public static extern DL_STATUS BlockRead_AKM1([Out] byte[] data, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead_AKM2")] + public static extern DL_STATUS BlockRead_AKM2([Out] byte[] data, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead_PK")] + public static extern DL_STATUS BlockRead_PK([Out] byte[] data, + UInt16 block_address, + byte auth_mode, + [In] byte[] pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite")] + public static extern DL_STATUS BlockWrite([In] byte[] data, + UInt16 block_address, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite_AKM1")] + public static extern DL_STATUS BlockWrite_AKM1([In] byte[] data, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite_AKM2")] + public static extern DL_STATUS BlockWrite_AKM2([In] byte[] data, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite_PK")] + public static extern DL_STATUS BlockWrite_PK([In] byte[] data, + UInt16 block_address, + byte auth_mode, + [In] byte[] pk_key); + + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead")] + public static extern DL_STATUS BlockInSectorRead([Out] byte[] data, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, byte key_index); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead_AKM1")] + public static extern DL_STATUS BlockInSectorRead_AKM1([Out] byte[] data, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead_AKM2")] + public static extern DL_STATUS BlockInSectorRead_AKM2([Out] byte[] data, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead_PK")] + public static extern DL_STATUS BlockInSectorRead_PK([Out] byte[] data, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + [In] byte[] pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite")] + public static extern DL_STATUS BlockInSectorWrite([In] byte[] data, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite_AKM1")] + public static extern DL_STATUS BlockInSectorWrite_AKM1([In] byte[] data, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite_AKM2")] + public static extern DL_STATUS BlockInSectorWrite_AKM2([In] byte[] data, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite_PK")] + public static extern DL_STATUS BlockInSectorWrite_PK([In] byte[] data, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + [In] byte[] pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead")] + public static extern DL_STATUS ValueBlockRead(out Int32 value, + out byte value_addr, + UInt16 block_address, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead_AKM1")] + public static extern DL_STATUS ValueBlockRead_AKM1(out Int32 value, + out byte value_addr, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead_AKM2")] + public static extern DL_STATUS ValueBlockRead_AKM2(out Int32 value, + out byte value_addr, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead_PK")] + public static extern DL_STATUS ValueBlockRead_PK(out Int32 value, + out byte value_addr, + UInt16 block_address, + byte auth_mode, + out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite")] + public static extern DL_STATUS ValueBlockWrite(int value, + byte value_addr, + UInt16 block_address, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite_AKM1")] + public static extern DL_STATUS ValueBlockWrite_AKM1(int value, + byte value_addr, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite_AKM2")] + public static extern DL_STATUS ValueBlockWrite_AKM2(int value, + byte value_addr, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite_PK")] + public static extern DL_STATUS ValueBlockWrite_PK(int value, + byte value_addr, + UInt16 block_address, + byte auth_mode, + out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement")] + public static extern DL_STATUS ValueBlockIncrement(int increment_value, + UInt16 block_address, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement_AKM1")] + public static extern DL_STATUS ValueBlockIncrement_AKM1(int increment_value, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement_AKM2")] + public static extern DL_STATUS ValueBlockIncrement_AKM2(int increment_value, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement_PK")] + public static extern DL_STATUS ValueBlockIncrement_PK(int increment_value, + UInt16 block_address, + byte auth_mode, + out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement")] + public static extern DL_STATUS ValueBlockDecrement(int increment_value, + UInt16 block_address, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement_AKM1")] + public static extern DL_STATUS ValueBlockDecrement_AKM1(int increment_value, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement_AKM2")] + public static extern DL_STATUS ValueBlockDecrement_AKM2(int increment_value, + UInt16 block_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement_PK")] + public static extern DL_STATUS ValueBlockDecrement_PK(int increment_value, + UInt16 block_address, + byte auth_mode, + out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead")] + public static extern DL_STATUS ValueBlockInSectorRead(out Int32 value, + out byte value_addr, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead_AKM1")] + public static extern DL_STATUS ValueBlockInSectorRead_AKM1(out Int32 value, + out byte value_addr, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead_AKM2")] + public static extern DL_STATUS ValueBlockInSectorRead_AKM2(out Int32 value, + out byte value_addr, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead_PK")] + public static extern DL_STATUS ValueBlockInSectorRead_PK(out Int32 value, + out byte value_addr, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite")] + public static extern DL_STATUS ValueBlockInSectorWrite(Int32 value, + byte value_addr, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite_AKM1")] + public static extern DL_STATUS ValueBlockInSectorWrite_AKM1(Int32 value, + byte value_addr, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite_AKM2")] + public static extern DL_STATUS ValueBlockInSectorWrite_AKM2(Int32 value, + byte value_addr, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite_PK")] + public static extern DL_STATUS ValueBlockInSectorWrite_PK(Int32 value, + byte value_addr, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement")] + public static extern DL_STATUS ValueBlockInSectorIncrement(Int32 increment_value, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement_AKM1")] + public static extern DL_STATUS ValueBlockInSectorIncrement_AKM1(Int32 increment_value, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement_AKM2")] + public static extern DL_STATUS ValueBlockInSectorIncrement_AKM2(Int32 increment_value, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement_PK")] + public static extern DL_STATUS ValueBlockInSectorIncrement_PK(Int32 increment_value, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement")] + public static extern DL_STATUS ValueBlockInSectorDecrement(Int32 decrement_value, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement_AKM1")] + public static extern DL_STATUS ValueBlockInSectorDecrement_AKM1(Int32 decrement_value, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement_AKM2")] + public static extern DL_STATUS ValueBlockInSectorDecrement_AKM2(Int32 decrement_value, + byte sector_address, + byte block_in_sector_address, + byte auth_mode); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement_PK")] + public static extern DL_STATUS ValueBlockInSectorDecrement_PK(Int32 decrement_value, + byte sector_address, + byte block_in_sector_address, + byte auth_mode, + out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite")] + public static extern DL_STATUS SectorTrailerWrite(byte addressing_mode, + byte address, + out byte new_key_A, + byte block0_access_bits, + byte block1_access_bits, + byte block2_access_bits, + byte sector_trailer_access_bits, + byte sector_trailer_byte9, + out byte new_key_B, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite_AKM1")] + public static extern DL_STATUS SectorTrailerWrite_AKM1(byte addressing_mode, + byte address, + out byte new_key_A, + byte block0_access_bits, + byte block1_access_bits, + byte block2_access_bits, + byte sector_trailer_access_bits, + byte sector_trailer_byte9, + out byte new_key_B, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite_AKM2")] + public static extern DL_STATUS SectorTrailerWrite_AKM2(byte addressing_mode, + byte address, + out byte new_key_A, + byte block0_access_bits, + byte block1_access_bits, + byte block2_access_bits, + byte sector_trailer_access_bits, + byte sector_trailer_byte9, + out byte new_key_B, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite_PK")] + public static extern DL_STATUS SectorTrailerWrite_PK(byte addressing_mode, + byte address, + out byte new_key_A, + byte block0_access_bits, + byte block1_access_bits, + byte block2_access_bits, + byte sector_trailer_access_bits, + byte sector_trailer_byte9, + out byte new_key_B, + byte auth_mode, + out byte pk_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearFormatCard")] + public static extern DL_STATUS LinearFormatCard(out byte new_key_A, + byte blocks_access_bits, + byte sector_trailers_access_bits, + byte sector_trailers_byte9, + out byte new_key_B, + out byte sectors_formatted, + byte auth_mode, + byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearFormatCard_AKM1")] + public static extern DL_STATUS LinearFormatCard_AKM1(out byte new_key_A, + byte blocks_access_bits, + byte sector_trailers_access_bits, + byte sector_trailers_byte9, + out byte new_key_B, + out byte sectors_formatted, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearFormatCard_AKM2")] + public static extern DL_STATUS LinearFormatCard_AKM2(out byte new_key_A, + byte blocks_access_bits, + byte sector_trailers_access_bits, + byte sector_trailers_byte9, + out byte new_key_B, + out byte sectors_formatted, + byte auth_mode); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearFormatCard_PK")] + public static extern DL_STATUS LinearFormatCard_PK(out byte new_key_A, + byte blocks_access_bits, + byte sector_trailers_access_bits, + byte sector_trailers_byte9, + out byte new_key_B, + out byte sectors_formatted, + byte auth_mode, + out byte pk_key); + + //---------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetISO14443_4_Mode")] + public static extern DL_STATUS SetISO14443_4_Mode(); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "s_block_deselect")] + public static extern DL_STATUS s_block_deselect(byte timeout); + //---------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppSelectByAid")] + public static extern DL_STATUS JCAppSelectByAid([In] byte[] aid, byte aid_len, [Out] byte[] selection_response); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPutPrivateKey")] + public static extern DL_STATUS JCAppPutPrivateKey(byte key_type, byte key_index, + [In] byte[] key, UInt16 key_bit_len, + [In] byte[] key_param, UInt16 key_parm_len); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGenerateKeyPair")] + public static extern DL_STATUS JCAppGenerateKeyPair(byte key_type, byte key_index, byte key_designator, + UInt16 key_bit_len, [In] byte[] param, UInt16 param_size); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppDeleteRsaKeyPair")] + public static extern DL_STATUS JCAppDeleteRsaKeyPair(byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppDeleteEcKeyPair")] + public static extern DL_STATUS JCAppDeleteEcKeyPair(byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppSignatureBegin")] + public static extern DL_STATUS JCAppSignatureBegin(byte cipher, byte digest, byte padding, byte key_index, + [In] byte[] chunk, UInt16 chunk_len, + [In] byte[] alg_param, UInt16 alg_parm_len); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppSignatureUpdate")] + public static extern DL_STATUS JCAppSignatureUpdate([In] byte[] chunk, UInt16 chunk_len); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppSignatureEnd")] + private static extern DL_STATUS JCAppSignatureEnd(out UInt16 sig_len); + public static DL_STATUS JCAppSignatureEnd(out byte[] sig) + { + DL_STATUS status; + UInt16 sig_len; + + status = JCAppSignatureEnd(out sig_len); + if (status != DL_STATUS.UFR_OK) + { + sig = null; + return status; + } + + sig = new byte[sig_len]; + return JCAppGetSignature(sig, sig_len); + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGenerateSignature")] + private static extern DL_STATUS JCAppGenerateSignature(byte cipher, byte digest, byte padding, byte key_index, + [In] byte[] plain_data, UInt16 plain_data_len, + out UInt16 sig_len, + [In] byte[] alg_param, UInt16 alg_parm_len); + + public static DL_STATUS JCAppGenerateSignature(byte cipher, byte digest, byte padding, byte key_index, + [In] byte[] plain_data, UInt16 plain_data_len, + out byte[] sig, + [In] byte[] alg_param, UInt16 alg_parm_len) + { + DL_STATUS status; + UInt16 sig_len; + + status = JCAppGenerateSignature(cipher, digest, padding, key_index, plain_data, plain_data_len, out sig_len, alg_param, alg_parm_len); + if (status != DL_STATUS.UFR_OK) + { + sig = null; + return status; + } + + sig = new byte[sig_len]; + return JCAppGetSignature(sig, sig_len); + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetSignature")] + private static extern DL_STATUS JCAppGetSignature([Out] byte[] sig, UInt16 sig_len); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPutObj")] + public static extern DL_STATUS JCAppPutObj(byte obj_type, byte obj_index, [In] byte[] obj, UInt16 obj_size, [In] byte[] id, byte id_size); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPutObjSubject")] + public static extern DL_STATUS JCAppPutObjSubject(byte obj_type, byte obj_index, [In] byte[] subject, byte size); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppInvalidateCert")] + public static extern DL_STATUS JCAppInvalidateCert(byte obj_type, byte obj_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetObjId")] + private static extern DL_STATUS JCAppGetObjId(byte obj_type, byte obj_index, [Out] byte[] id, out UInt16 id_size); + public static DL_STATUS JCAppGetObjId(byte obj_type, byte obj_index, out byte[] id, out UInt16 size) + { + DL_STATUS status; + + size = 0; + id = null; + status = JCAppGetObjId(obj_type, obj_index, id, out size); + if (status == DL_STATUS.UFR_OK) + { + id = new byte[size]; + status = JCAppGetObjId(obj_type, obj_index, id, out size); + } + return status; + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetObjSubject")] + private static extern DL_STATUS JCAppGetObjSubject(byte obj_type, byte obj_index, [Out] byte[] subject, out byte subject_size); + public static DL_STATUS JCAppGetObjSubject(byte obj_type, byte obj_index, out byte[] subject, out byte size) + { + DL_STATUS status; + + size = 0; + subject = null; + status = JCAppGetObjSubject(obj_type, obj_index, subject, out size); + if (status == DL_STATUS.UFR_OK) + { + subject = new byte[size]; + status = JCAppGetObjSubject(obj_type, obj_index, subject, out size); + } + return status; + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetObj")] + private static extern DL_STATUS JCAppGetObj(byte obj_type, byte obj_index, [Out] byte[] obj, UInt16 size); + public static DL_STATUS JCAppGetObj(byte obj_type, byte obj_index, byte[] obj) + { + return JCAppGetObj(obj_type, obj_index, obj, (UInt16) obj.Length); + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetErrorDescription")] + private static extern IntPtr GetErrorDescription(UInt32 apdu_error_status); + public static string JCAppGetErrorDescription(UInt32 apdu_error_status) + { + IntPtr str_ret = GetErrorDescription(apdu_error_status); + return Marshal.PtrToStringAnsi(str_ret); + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppLogin")] + public static extern DL_STATUS JCAppLogin(byte SO, [In] byte[] pin, byte pinSize); + public static DL_STATUS JCAppLogin(bool SO, string pin) + { + if (pin.Length > byte.MaxValue) + return DL_STATUS.UFR_PARAMETERS_ERROR; + + byte[] pin_param = Encoding.ASCII.GetBytes(pin); + return JCAppLogin(SO ? (byte)1 : (byte)0, pin_param, (byte)pin_param.Length); + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetPinTriesRemaining")] + public static extern DL_STATUS JCAppGetPinTriesRemaining(DL_SECURE_CODE secureCodeType, out UInt16 triesRemaining); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPinChange")] + public static extern DL_STATUS JCAppPinChange(DL_SECURE_CODE secureCodeType, [In] byte[] newPin, byte newPinSize); + public static DL_STATUS JCAppPinChange(DL_SECURE_CODE secureCodeType, string newPin) + { + if (newPin.Length > byte.MaxValue) + return DL_STATUS.UFR_PARAMETERS_ERROR; + + byte[] newPin_param = Encoding.ASCII.GetBytes(newPin); + return JCAppPinChange(secureCodeType, newPin_param, (byte)newPin_param.Length); + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppPinUnblock")] + public static extern DL_STATUS JCAppPinUnblock(byte SO, [In] byte[] puk, byte pukSize); + public static DL_STATUS JCAppPinUnblock(bool SO, string puk) + { + if (puk.Length > byte.MaxValue) + return DL_STATUS.UFR_PARAMETERS_ERROR; + + byte[] puk_param = Encoding.ASCII.GetBytes(puk); + return JCAppPinUnblock(SO ? (byte)1 : (byte)0, puk_param, (byte)puk_param.Length); + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetRsaPublicKey")] + private static extern DL_STATUS JCAppGetRsaPublicKey(byte key_index, [Out] byte[] modulus, out UInt16 modulus_size, + [Out] byte[] exponent, out UInt16 exponent_size); + public static DL_STATUS JCAppGetRsaPublicKey(byte key_index, out byte[] modulus, out byte[] exponent) + { + DL_STATUS status; + + UInt16 modulus_size = 0; + UInt16 exponent_size = 0; + modulus = null; + exponent = null; + status = JCAppGetRsaPublicKey(key_index, modulus, out modulus_size, exponent, out exponent_size); + if (status == DL_STATUS.UFR_OK) + { + modulus = new byte[modulus_size]; + exponent = new byte[exponent_size]; + status = JCAppGetRsaPublicKey(key_index, modulus, out modulus_size, exponent, out exponent_size); + } + return status; + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetEcPublicKey")] + private static extern DL_STATUS JCAppGetEcPublicKey(byte key_index, [Out] byte[] keyW, out UInt16 keyW_size, + [Out] byte[] field, out UInt16 field_size, [Out] byte[] ab, out UInt16 ab_size, + [Out] byte[] g, out UInt16 g_size, [Out] byte[] r, out UInt16 r_size, out UInt16 k, out UInt16 key_size_bits, out UInt16 key_designator); + public static DL_STATUS JCAppGetEcPublicKey(byte key_index, out byte[] keyW, out byte[] field, out byte[] a, out byte[] b, out byte[] g, out byte[] r, + out UInt16 k, out UInt16 key_size_bits, out UInt16 key_designator) + { + DL_STATUS status; + + UInt16 keyW_size = 0; + UInt16 field_size = 0; + UInt16 ab_size = 0; + UInt16 g_size = 0; + UInt16 r_size = 0; + byte[] ab = null; + keyW = field = a = b = g = r = null; + k = key_size_bits = key_designator = 0; + status = JCAppGetEcPublicKey(key_index, keyW, out keyW_size, field, out field_size, ab, out ab_size, g, out g_size, + r, out r_size, out k, out key_size_bits, out key_designator); + if (status == DL_STATUS.UFR_OK) + { + keyW = new byte[keyW_size]; + field = new byte[field_size]; + ab = new byte[ab_size]; + g = new byte[g_size]; + r = new byte[r_size]; + status = JCAppGetEcPublicKey(key_index, keyW, out keyW_size, field, out field_size, ab, out ab_size, g, out g_size, + r, out r_size, out k, out key_size_bits, out key_designator); + + if (keyW_size != (UInt16)(((key_size_bits + 7) / 8) * 2 + 1)) + return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; + if ((field_size != (UInt16)((key_size_bits + 7) / 8)) && (field_size != 6) && (field_size != 2)) + return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; + if (ab_size != (UInt16)(((key_size_bits + 7) / 8) * 2)) + return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; + if (g_size != (UInt16)(((key_size_bits + 7) / 8) * 2 + 1)) + return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; + if ((r_size != (UInt16)((key_size_bits + 7) / 8)) && (r_size != (UInt16)(((key_size_bits + 7) / 8) + 1))) + return DL_STATUS.UFR_APDU_WRONG_KEY_SIZE; + a = new byte[(key_size_bits + 7) / 8]; + b = new byte[(key_size_bits + 7) / 8]; + Array.Copy(ab, 0, a, 0, (key_size_bits + 7) / 8); + Array.Copy(ab, (key_size_bits + 7) / 8, b, 0, (key_size_bits + 7) / 8); + } + return status; + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "UFR_Status2String")] + private static extern IntPtr UFR_Status2String(DL_STATUS status); + public static string status2str(DL_STATUS status) + { + IntPtr str_ret = UFR_Status2String(status); + return Marshal.PtrToStringAnsi(str_ret); + } + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "JCAppGetEcKeySizeBits")] + public static extern DL_STATUS JCAppGetEcKeySizeBits(byte key_index, out UInt16 key_size_bits, out UInt16 key_designator); + //---------------------------------------------------------------------- + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "UfrXrcLockOn")] + public static extern DL_STATUS UfrXrcLockOn(UInt16 pulse_duration); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "UfrXrcRelayState")] + public static extern DL_STATUS UfrXrcRelayState(byte state); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "UfrXrcGetIoState")] + public static extern DL_STATUS UfrXrcGetIoState(out byte intercom, out byte dig_in, out byte relay_state); + + //---------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpenM")] + public static extern DL_STATUS ReaderOpenM(UFR_HANDLE hndUFR); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderCloseM")] + public static extern DL_STATUS ReaderCloseM(UFR_HANDLE hndUFR); + + //---------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetCardIdExM")] + public static extern DL_STATUS GetCardIdExM(UFR_HANDLE hndUFR, + out byte bCardType, + [Out] byte nfc_uid, // NFC_UID_MAX_LEN = 10 + out byte bUidSize); + + //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderTypeM")] + //public static extern DL_STATUS GetReaderTypeM(UInt32* get_reader_type); + + //---------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "BlockRead_PKM")] + public static extern DL_STATUS BlockRead_PKM(UFR_HANDLE hndUFR, + out byte data, + byte block_address, + byte auth_mode, + ref byte key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "BlockWrite_PKM")] + public static extern DL_STATUS BlockWrite_PKM(UFR_HANDLE hndUFR, + out byte data, + byte block_address, + byte auth_mode, + ref byte key); + //---------------------------------------------------------------------- + + //Desfire + //---------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireWriteAesKey")] + public static extern DL_STATUS uFR_int_DesfireWriteAesKey(byte aes_key_no, + [In] byte[] aes_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_GetDesfireUid")] + public static extern DL_STATUS uFR_int_GetDesfireUid(byte aes_key_nr, + UInt32 aid, + byte aid_key_nr, + [Out] byte[] card_uid, + out byte card_uid_len, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_GetDesfireUid_PK")] + public static extern DL_STATUS uFR_int_GetDesfireUid_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte aid_key_nr, + [Out] byte[] card_uid, + out byte card_uid_len, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireFreeMem")] + public static extern DL_STATUS uFR_int_DesfireFreeMem(out UInt32 free_mem_byte, + out UInt16 card_status, + out UInt16 exec_time); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireFormatCard")] + public static extern DL_STATUS uFR_int_DesfireFormatCard(byte aes_key_nr, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireFormatCard_PK")] + public static extern DL_STATUS uFR_int_DesfireFormatCard_PK([In] byte[] aes_key_ext, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireSetConfiguration")] + public static extern DL_STATUS uFR_int_DesfireSetConfiguration(byte aes_key_nr, + byte random_uid, + byte format_disable, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireSetConfiguration_PK")] + public static extern DL_STATUS uFR_int_DesfireSetConfiguration_PK([In] byte[] aes_key_ext, + byte random_uid, + byte format_disable, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireGetKeySettings")] + public static extern DL_STATUS uFR_int_DesfireGetKeySettings(byte aes_key_nr, + UInt32 aid, + out byte settings, + out byte max_key_no, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireGetKeySettings_PK")] + public static extern DL_STATUS uFR_int_DesfireGetKeySettings_PK([In] byte[] aes_key_ext, + UInt32 aid, + out byte settings, + out byte max_key_no, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireChangeKeySettings")] + public static extern DL_STATUS uFR_int_DesfireChangeKeySettings(byte aes_key_nr, + UInt32 aid, + byte settings, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireChangeKeySettings_PK")] + public static extern DL_STATUS uFR_int_DesfireChangeKeySettings_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte settings, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireChangeAesKey")] + public static extern DL_STATUS uFR_int_DesfireChangeAesKey(byte aes_key_nr, + UInt32 aid, + byte aid_key_nr_auth, + [In] byte[] new_aes_key, + byte aid_key_no, + [In] byte[] old_aes_key, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireChangeAesKey_PK")] + public static extern DL_STATUS uFR_int_DesfireChangeAesKey_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte aid_key_nr_auth, + [In] byte[] new_aes_key, + byte aid_key_no, + [In] byte[] old_aes_key, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateAesApplication")] + public static extern DL_STATUS uFR_int_DesfireCreateAesApplication(byte aes_key_nr, + UInt32 aid_nr, + byte setting, + byte max_key_no, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateAesApplication_PK")] + public static extern DL_STATUS uFR_int_DesfireCreateAesApplication_PK([In] byte[] aes_key_ext, + UInt32 aid_nr, + byte setting, + byte max_key_no, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateAesApplication_no_auth")] + public static extern DL_STATUS uFR_int_DesfireCreateAesApplication_no_auth(UInt32 aid_nr, + byte setting, + byte max_key_no, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteApplication")] + public static extern DL_STATUS uFR_int_DesfireDeleteApplication(byte aes_key_nr, + UInt32 aid_nr, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteApplication_PK")] + public static extern DL_STATUS uFR_int_DesfireDeleteApplication_PK([In] byte[] aes_key_ext, + UInt32 aid_nr, + out UInt16 card_status, + out UInt16 exec_time); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateStdDataFile")] + public static extern DL_STATUS uFR_int_DesfireCreateStdDataFile(byte aes_key_nr, + UInt32 aid, + byte file_id, + UInt32 file_size, + byte read_key_no, + byte write_key_no, + byte read_write_key_no, + byte change_key_no, + byte communication_settings, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateStdDataFile_PK")] + public static extern DL_STATUS uFR_int_DesfireCreateStdDataFile_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte file_id, + UInt32 file_size, + byte read_key_no, + byte write_key_no, + byte read_write_key_no, + byte change_key_no, + byte communication_settings, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateStdDataFile_no_auth")] + public static extern DL_STATUS uFR_int_DesfireCreateStdDataFile_no_auth(UInt32 aid, + byte file_id, + UInt32 file_size, + byte read_key_no, + byte write_key_no, + byte read_write_key_no, + byte change_key_no, + byte communication_settings, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteFile")] + public static extern DL_STATUS uFR_int_DesfireDeleteFile(byte aes_key_nr, + UInt32 aid, + byte file_id, + out UInt16 card_status, + out UInt16 exec_time); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteFile_PK")] + public static extern DL_STATUS uFR_int_DesfireDeleteFile_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte file_id, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDeleteFile_no_auth")] + public static extern DL_STATUS uFR_int_DesfireDeleteFile_no_auth(UInt32 aid, + byte file_id, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadStdDataFile")] + public static extern DL_STATUS uFR_int_DesfireReadStdDataFile(byte aes_key_nr, + UInt32 aid, + byte aid_key_nr, + byte file_id, + UInt16 offset, + UInt16 data_length, + byte communication_settings, + [Out] byte[] data, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadStdDataFile_PK")] + public static extern DL_STATUS uFR_int_DesfireReadStdDataFile_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte aid_key_nr, + byte file_id, + UInt16 offset, + UInt16 data_length, + byte communication_settings, + [Out] byte[] data, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadStdDataFile_no_auth")] + public static extern DL_STATUS uFR_int_DesfireReadStdDataFile_no_auth(UInt32 aid, + byte aid_key_nr, + byte file_id, + UInt16 offset, + UInt16 data_length, + byte communication_settings, + [Out] byte[] data, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireWriteStdDataFile")] + public static extern DL_STATUS uFR_int_DesfireWriteStdDataFile(byte aes_key_nr, + UInt32 aid, + byte aid_key_nr, + byte file_id, + UInt16 offset, + UInt16 data_length, + byte communication_settings, + [In] byte[] data, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireWriteStdDataFile_PK")] + public static extern DL_STATUS uFR_int_DesfireWriteStdDataFile_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte aid_key_nr, + byte file_id, + UInt16 offset, + UInt16 data_length, + byte communication_settings, + [In] byte[] data, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireWriteStdDataFile_no_auth")] + public static extern DL_STATUS uFR_int_DesfireWriteStdDataFile_no_auth(UInt32 aid, + byte aid_key_nr, + byte file_id, + UInt16 offset, + UInt16 data_length, + byte communication_settings, + [In] byte[] data, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "DES_to_AES_key_type")] + public static extern DL_STATUS DES_to_AES_key_type(); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "AES_to_DES_key_type")] + public static extern DL_STATUS AES_to_DES_key_type(); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "SetSpeedPermanently")] + public static extern DL_STATUS SetSpeedPermanently(byte tx_speed, byte rx_speed); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetSpeedParameters")] + public static extern DL_STATUS GetSpeedParameters(out byte tx_speed, out byte rx_speed); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateValueFile")] + public static extern DL_STATUS uFR_int_DesfireCreateValueFile(byte aes_key_nr, + UInt32 aid, + byte file_id, + Int32 lower_limit, + Int32 upper_limit, + Int32 value, + byte limited_credit_enabled, + byte read_key_no, + byte write_key_no, + byte read_write_key_no, + byte change_key_no, + byte communication_settings, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateValueFile_PK")] + public static extern DL_STATUS uFR_int_DesfireCreateValueFile_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte file_id, + Int32 lower_limit, + Int32 upper_limit, + Int32 value, + byte limited_credit_enabled, + byte read_key_no, + byte write_key_no, + byte read_write_key_no, + byte change_key_no, + byte communication_settings, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireCreateValueFile_no_auth")] + public static extern DL_STATUS uFR_int_DesfireCreateValueFile_no_auth(UInt32 aid, + byte file_id, + Int32 lower_limit, + Int32 upper_limit, + Int32 value, + byte limited_credit_enabled, + byte read_key_no, + byte write_key_no, + byte read_write_key_no, + byte change_key_no, + byte communication_settings, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadValueFile")] + public static extern DL_STATUS uFR_int_DesfireReadValueFile(byte aes_key_nr, + UInt32 aid, + byte aid_key_nr, + byte file_id, + byte communication_settings, + out Int32 value, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadValueFile_PK")] + public static extern DL_STATUS uFR_int_DesfireReadValueFile_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte aid_key_nr, + byte file_id, + byte communication_settings, + out Int32 value, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireReadValueFile_no_auth")] + public static extern DL_STATUS uFR_int_DesfireReadValueFile_no_auth(UInt32 aid, + byte aid_key_nr, + byte file_id, + byte communication_settings, + out Int32 value, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireIncreaseValueFile")] + public static extern DL_STATUS uFR_int_DesfireIncreaseValueFile(byte aes_key_nr, + UInt32 aid, + byte aid_key_nr, + byte file_id, + byte communication_settings, + Int32 value, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireIncreaseValueFile_PK")] + public static extern DL_STATUS uFR_int_DesfireIncreaseValueFile_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte aid_key_nr, + byte file_id, + byte communication_settings, + Int32 value, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireIncreaseValueFile_no_auth")] + public static extern DL_STATUS uFR_int_DesfireIncreaseValueFile_no_auth(UInt32 aid, + byte aid_key_nr, + byte file_id, + byte communication_settings, + Int32 value, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDecreaseValueFile")] + public static extern DL_STATUS uFR_int_DesfireDecreaseValueFile(byte aes_key_nr, + UInt32 aid, + byte aid_key_nr, + byte file_id, + byte communication_settings, + Int32 value, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDecreaseValueFile_PK")] + public static extern DL_STATUS uFR_int_DesfireDecreaseValueFile_PK([In] byte[] aes_key_ext, + UInt32 aid, + byte aid_key_nr, + byte file_id, + byte communication_settings, + Int32 value, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "uFR_int_DesfireDecreaseValueFile_no_auth")] + public static extern DL_STATUS uFR_int_DesfireDecreaseValueFile_no_auth(UInt32 aid, + byte aid_key_nr, + byte file_id, + byte communication_settings, + Int32 value, + out UInt16 card_status, + out UInt16 exec_time); + + //--------------------------------------------------------------------- + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderKeysLock")] + public static extern DL_STATUS ReaderKeysLock([In] char[] password); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderKeysUnlock")] + public static extern DL_STATUS ReaderKeysUnlock([In] char[] password); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderDescription")] + private static extern IntPtr GetReaderDescription(); + public static string GetDescription() + { + IntPtr str_ret = GetReaderDescription(); + return Marshal.PtrToStringAnsi(str_ret); + } + + //-------------------------------------------- MIFARE PLUS -------------------------------------------------// + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_PersonalizationMinimal")] + public static extern DL_STATUS MFP_PersonalizationMinimal([In] byte[] master_key, [In] byte[] config_key, [In] byte[] l2_sw_key, [In] byte[] l3_sw_key, + [In] byte[] l1_auth_key, [In] byte[] sel_vc_key, [In] byte[] prox_chk_key, [In] byte[] vc_poll_enc_key, + [In] byte[] vc_poll_mac_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_AesAuthSecurityLevel1_PK")] + public static extern DL_STATUS MFP_AesAuthSecurityLevel1_PK([In] byte[] sl1_auth_key); + + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_AesAuthSecurityLevel1")] + public static extern DL_STATUS MFP_AesAuthSecurityLevel1(byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_SwitchToSecurityLevel3_PK")] + public static extern DL_STATUS MFP_SwitchToSecurityLevel3_PK([In] byte[] sl3_auth_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_SwitchToSecurityLevel3")] + public static extern DL_STATUS MFP_SwitchToSecurityLevel3(byte key_index); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeMasterKey_PK")] + public static extern DL_STATUS MFP_ChangeMasterKey_PK([In] byte[] old_master_key, [In] byte[] new_master_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeMasterKey")] + public static extern DL_STATUS MFP_ChangeMasterKey(byte key_index, [In] byte[] new_master_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeConfigurationKey_PK")] + public static extern DL_STATUS MFP_ChangeConfigurationKey_PK([In] byte[] old_config_key, [In] byte[] new_config_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeConfigurationKey")] + public static extern DL_STATUS MFP_ChangeConfigurationKey(byte key_index, [In] byte[] new_config_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeSectorKey_PK")] + public static extern DL_STATUS MFP_ChangeSectorKey_PK(byte sector_nr, byte auth_mode, [In] byte[] old_sector_key, [In] byte[] new_sector_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeSectorKey")] + public static extern DL_STATUS MFP_ChangeSectorKey(byte sector_nr, byte auth_mode, byte key_index, [In] byte[] new_sector_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_FieldConfigurationSet_PK")] + public static extern DL_STATUS MFP_FieldConfigurationSet_PK([In] byte[] configuration_key, byte rid_use, byte prox_check_use); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_FieldConfigurationSet")] + public static extern DL_STATUS MFP_FieldConfigurationSet(byte configuration_key_index, byte rid_use, byte prox_check_use); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_GetUid_PK")] + public static extern DL_STATUS MFP_GetUid_PK([In] byte[] vc_poll_enc_key, [In] byte[] vc_poll_mac_key, [In,Out] byte[] nfc_uid,out byte uid_len); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_GetUid")] + public static extern DL_STATUS MFP_GetUid(byte key_index_vc_poll_enc_key, byte key_index_vc_poll_mac_key, [In, Out] byte[] nfc_uid, out byte uid_len); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeVcPollingEncKey_PK")] + public static extern DL_STATUS MFP_ChangeVcPollingEncKey_PK([In] byte[] configuration_key, [In] byte[] new_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeVcPollingEncKey")] + public static extern DL_STATUS MFP_ChangeVcPollingEncKey(byte configuration_key_index, [In] byte[] new_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeVcPollingMacKey_PK")] + public static extern DL_STATUS MFP_ChangeVcPollingMacKey_PK([In] byte[] configuration_key, [In] byte[] new_key); + + //--------------------------------------------------------------------- + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "MFP_ChangeVcPollingMacKey")] + public static extern DL_STATUS MFP_ChangeVcPollingMacKey(byte configuration_key_index, [In] byte[] new_key); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "write_ndef_record")] + private static extern DL_STATUS write_ndef_record(byte message_nr, [In] byte[] tnf, [In] byte[] type_record, [In] byte[] type_length, [In] byte[] id, [In] byte[] id_length, [In] byte[] payload, [In] UInt32[] payload_length, out byte[] card_formated); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "write_ndef_record_mirroring")] + private static extern DL_STATUS write_ndef_record_mirroring(byte message_nr, [In] byte[] tnf, [In] byte[] type_record, [In] byte[] type_length, [In] byte[] id, [In] byte[] id_length, [In] byte[] payload, [In] UInt32[] payload_length, out byte[] card_formated, int use_uid_ascii_mirror, int use_counter_ascii_mirror, UInt32 payload_mirroring_pos); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "write_ndef_recordM")] + private static extern DL_STATUS write_ndef_recordM(UFR_HANDLE hndUFR, byte message_nr, [In] byte[] tnf, [In] byte[] type_record, [In] byte[] type_length, [In] byte[] id, [In] byte[] id_length, [In] byte[] payload, [In] UInt32[] payload_length, out byte[] card_formated); + + [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "write_ndef_record_mirroringM")] + private static extern DL_STATUS write_ndef_record_mirroringM(UFR_HANDLE hndUFR, byte message_nr, [In] byte[] tnf, [In] byte[] type_record, [In] byte[] type_length, [In] byte[] id, [In] byte[] id_length, [In] byte[] payload, [In] UInt32[] payload_length, out byte[] card_formated, int use_uid_ascii_mirror, int use_counter_ascii_mirror, UInt32 payload_mirroring_pos); + + } +}