public static void UpdateMainMemory3WbpExample(string readerName) { try { var threeWireBusProtocol = new Readers.AViatoR.Components.Synchronus3WBP(); ISmartCardReader smartCardReader = Connect(readerName); if (!smartCardReader.IsConnected) { return; } // Following code is commented to prevent usage of incorrect Pin code, which can lead to blocking the synchronus card if done several times in row // Verification with correct pin code is necessary to write any data into card memory // Be advice not to use VerifyUser2Wbp command if correct pin code is not known /* * string pin = "FFFF"; * * byte firstPinByte = byte.Parse(pin.Substring(0, 2), NumberStyles.HexNumber); * byte secondPinByte = byte.Parse(pin.Substring(2, 2), NumberStyles.HexNumber); * * VerifyUser3Wbp(reader, firstPinByte, secondPinByte); * * //*/ ushort address = 0x01FF; byte data = 0xAB; string command = threeWireBusProtocol.GetApdu(Synchronus3WBP.ControlByte.WriteAndEraseWithoutProtectBit, address, data); string response = smartCardReader.Transmit(command); PrintData($"Write Main Memory, address: 0x{address:X4}, data: 0x{data:X2}", command, response, response.Equals("9D009000") ? "Success" : "Error Response"); address = 0x01FF; data = 0xCC; command = threeWireBusProtocol.GetApdu(Synchronus3WBP.ControlByte.WriteAndEraseWithoutProtectBit, address, data); response = smartCardReader.Transmit(command); PrintData($"Write Main Memory, address: 0x{address:X4}, data: 0x{data:X2}", command, response, response.Equals("9D009000") ? "Success" : "Error Response"); smartCardReader.Disconnect(CardDisposition.Unpower); } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void ReadMainMemory3WbpExample(string readerName) { try { var threeWireBusProtocol = new Readers.AViatoR.Components.Synchronus3WBP(); ISmartCardReader smartCardReader = Connect(readerName); if (!smartCardReader.IsConnected) { return; } // address of first byte to be read ushort address = 0x00; byte notUsed = 0x00; string cardMemory = string.Empty; // read data from addresses 0x0000 - 0x03FF for (int i = 0x00; i < 0x0400; i++) { string command = threeWireBusProtocol.GetApdu(Synchronus3WBP.ControlByte.Read9BitsDataWithProtectBit, address, notUsed); string response = smartCardReader.Transmit(command); if (response.StartsWith("9D02") && response.EndsWith("9000")) { string data = response.Substring(4, 2); string protectionByte = response.Substring(6, 2); string bitSet = protectionByte != "00" ? "not set" : "set"; PrintData($"Read Main Memory, Address 0x{address:X4}", command, response, $"Value 0x{data}, {protectionByte} -> protection bit {bitSet}"); cardMemory += data; } else { PrintData($"Read Main Memory, Address 0x{address:X4}", command, response, "Error Response"); } address++; } Console.WriteLine($"\nMain Memory starting from address 0x0000 to address 0x03FF:\n{cardMemory}\n"); smartCardReader.Disconnect(CardDisposition.Unpower); } catch (Exception e) { Console.WriteLine(e.Message); } }