public static DL_STATUS AIS_ReadLog( HND_AIS device, out UInt32 log_index, out UInt32 log_action, out UInt32 log_reader_id, out UInt32 log_card_id, out UInt32 log_system_id, [In, Out] byte[] nfc_uid, // NFC_UID_MAX_LEN = 10 out UInt32 nfc_uid_len, out DateTime date_time ) { DL_STATUS status = DL_STATUS.DL_OK; UInt32 i = 0; DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0); UInt64 unixTime; do { status = ReadLog(device, out log_index, out log_action, out log_reader_id, out log_card_id, out log_system_id, nfc_uid, out nfc_uid_len, out unixTime); }while ((status == DL_STATUS.RESOURCE_BUSY) && (i++ < MAX_RETRY_IF_BUSY)); date_time = epoch.AddSeconds(unixTime); return(status); }
private void bWritePage_Click(object sender, EventArgs e) { unsafe { byte[] WriteData = new byte[4]; String DataStr = PGWByte1.Text + PGWByte2.Text + PGWByte3.Text + PGWByte4.Text; String AddressToWrite = PageNumberWriteTB.Text; UInt16 WriteAddress = UInt16.Parse(AddressToWrite); WriteData = ToByteArray(DataStr); if (RB_NO_AUTH.Checked == true) { status = uFCoder.BlockWrite(WriteData, WriteAddress, 0x60, 0); LabelStatus.Text = uFCoder.status2str(status); } else if (RB_RKA_AUTH.Checked == true) { String IndexStr = IndexTB.Text; byte KeyIndex = Byte.Parse(IndexStr); status = uFCoder.BlockWrite(WriteData, WriteAddress, 0x61, KeyIndex); LabelStatus.Text = uFCoder.status2str(status); } else if (RB_PK_AUTH.Checked == true) { String key_str = Byte1TB.Text + Byte2TB.Text + Byte3TB.Text + Byte4TB.Text + Byte5TB.Text + Byte6TB.Text; byte[] key = new byte[6]; key = ToByteArray(key_str); status = uFCoder.BlockWrite_PK(WriteData, WriteAddress, 0x61, key); LabelStatus.Text = uFCoder.status2str(status); } } }
public static DL_STATUS AIS_MainLoop( HND_AIS hnd_device, out UInt32 RealTimeEvents, // indicate new RealTimeEvent(s) out bool LogEvent, // indicate new data in log buffer out bool CmdFinished, // indicate command finish out UInt32 CmdPercent, // indicate percent of command execution out bool TimeoutOccurred, // debug only out DL_STATUS Status // additional status ) { DL_STATUS status = DL_STATUS.DL_OK; UInt32 i = 0, uiLogEvent, uiCmdFinished, uiTimeoutOccurred; do { status = MainLoop( hnd_device, out RealTimeEvents, out uiLogEvent, out uiCmdFinished, out CmdPercent, out uiTimeoutOccurred, out Status); LogEvent = uiLogEvent != 0; CmdFinished = uiCmdFinished != 0; TimeoutOccurred = uiTimeoutOccurred != 0; }while ((status == DL_STATUS.RESOURCE_BUSY) && (i++ < MAX_RETRY_IF_BUSY)); return(status); }
private DL_STATUS ndef_write_mirroring(int TNF, string Type, string ID, byte[] Payload, UInt32 mirror_pos) { DL_STATUS result = DL_STATUS.UNKNOWN_ERROR; byte card_formated; byte tnf = (byte)TNF; int use_counter_ascii_mirror = chkCounterAsciiMirror.Checked ? 1 : 0; int use_uid_ascii_mirror = chkUidAsciiMirror.Checked ? 1 : 0; byte[] type = System.Text.Encoding.UTF8.GetBytes(Type); byte type_length = (byte)type.Length; byte[] id = System.Text.Encoding.UTF8.GetBytes(ID); byte id_length = (byte)ID.Length; byte[] payload = Payload; uint payload_length = (uint)payload.Length; unsafe { fixed(byte *f_type = type) fixed(byte *f_id = id) fixed(byte *f_payload = payload) result = uFCoder.write_ndef_record_mirroring(1, &tnf, f_type, &type_length, f_id, &id_length, f_payload, &payload_length, &card_formated, use_uid_ascii_mirror, use_counter_ascii_mirror, mirror_pos); } return(result); }
private DL_STATUS ndef_write(int TNF, string Type, string ID, byte[] Payload) { DL_STATUS result = DL_STATUS.UNKNOWN_ERROR; byte card_formated; byte tnf = (byte)TNF; byte[] type = System.Text.Encoding.UTF8.GetBytes(Type); byte type_length = (byte)type.Length; byte[] id = System.Text.Encoding.UTF8.GetBytes(ID); byte id_length = (byte)ID.Length; byte[] payload = Payload; uint payload_length = (uint)payload.Length; unsafe { fixed(byte *f_type = type) fixed(byte *f_id = id) fixed(byte *f_payload = payload) result = uFCoder.write_ndef_record(1, &tnf, f_type, &type_length, f_id, &id_length, f_payload, &payload_length, &card_formated); } return(result); }
private void bWrAAR_Click(object sender, EventArgs e) { DL_STATUS result = DL_STATUS.UNKNOWN_ERROR; int tnf; string type; string id; byte[] payload; if (eAAR.Text.Length == 0) { MessageBox.Show("URL field is mandatory!"); eURL.Focus(); return; } // URL TNF=4, Type= "android.com:pkg", Type Length= 15, payload[0]=1 payload = System.Text.Encoding.UTF8.GetBytes(eAAR.Text); tnf = 4; type = "android.com:pkg"; id = ""; result = ndef_write(tnf, type, id, payload); prn_status(result, "AAR Written"); }
private DL_STATUS write_emulation_ndef(int TNF, string Type, string ID, byte[] Payload) { DL_STATUS result = DL_STATUS.UNKNOWN_ERROR; byte tnf = (byte)TNF; byte[] type = System.Text.Encoding.UTF8.GetBytes(Type); byte type_length = (byte)type.Length; byte[] id = System.Text.Encoding.UTF8.GetBytes(ID); byte id_length = (byte)ID.Length; byte[] payload = Payload; byte payload_length = (byte)payload.Length; unsafe { fixed(byte *f_type = type) fixed(byte *f_id = id) fixed(byte *f_payload = payload) result = uFCoder.WriteEmulationNdef(tnf, f_type, type_length, f_id, id_length, f_payload, payload_length); } return(result); }
private void bGetCardInfo_Click(object sender, EventArgs e) { unsafe { byte CardType = 0; byte[] Uid = new byte[10]; byte UidSize = 0; status = uFCoder.GetCardIdEx(&CardType, Uid, &UidSize); uFCoder.GetDlogicCardType(&CardType); LabelStatus.Text = uFCoder.status2str(status); if (status == 0) { UIDTextBox.TextAlign = HorizontalAlignment.Center; UidLengthTextBox.TextAlign = HorizontalAlignment.Center; CardTypeTextBox.TextAlign = HorizontalAlignment.Center; UIDTextBox.Text = "[" + BitConverter.ToString(Uid).Replace("-", ":") + "]"; UidLengthTextBox.Text = "[" + UidSize.ToString() + " bytes]"; CardTypeTextBox.Text = "[" + GetDlTypeName(CardType) + "]"; } else { UIDTextBox.Clear(); CardTypeTextBox.Clear(); UidLengthTextBox.Clear(); } } }
private void button1_Click(object sender, EventArgs e) { DL_STATUS result = DL_STATUS.UNKNOWN_ERROR; int tnf = 2; // media type string type = "application/vnd.bluetooth.ep.oob"; string id = ""; byte[] payload = new byte[8]; String hexStr = maskedTextBox1.Text.Replace(" ", "").Replace("::", "").Replace(':', '-'); if (hexStr.Length != BLUETOOTH_ADDRESS_SIZE_WITH_DELIMITERS) { MessageBox.Show("You must enter 6 hexadecimal numbers!" /* + "\nDebug: >" + hexStr + "< " + hexStr.Length */); maskedTextBox1.Focus(); return; } byte[] payload_addr_fragment = CnvHexStr2ByteArr(hexStr); payload[1] = 0; // ... payload[0] = 8; // payload length - fixed for this purpose for (int i = 0; i < 6; i++) { payload[2 + i] = payload_addr_fragment[5 - i]; // indexes: [2 + i] where 2 is offset } // MessageBox.Show("Debug: Written value is: " + BitConverter.ToString(payload)); result = ndef_write(tnf, type, id, payload); prn_status(result, "Bluetooth address written"); }
public void format_scheda() { if (status == DL_STATUS.UFR_OK) { byte[] LWData = new byte[2048]; String LinAddr = "0"; String LWData_Str = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; ushort linear_address = 0; try { linear_address = ushort.Parse(LinAddr); } catch (System.FormatException) { MessageBox.Show("Byte di partenza sbagliato!"); } ushort byte_written = 0; LWData = ToByteArray(LWData_Str); Int32 data_len = LWData_Str.Length / 2; status = uFCoder.LinearWrite(LWData, linear_address, (ushort)data_len, ref byte_written, 0x60, 0); textBox2.Text = uFCoder.status2str(status); MessageBox.Show("Formattazione Eseguita!"); } else { MessageBox.Show("Scheda non pronta!"); } }
private void bEnumCards_Click(object sender, EventArgs e) { EnumTextBox.Clear(); CardComboBox.Items.Clear(); BlockDataTextBox.Clear(); SelectedCardTextBox.Text = "Card not selected"; TempCardsNumber = 0; byte CardsNumber = 0; byte ListSize = 0; byte index = 0; byte[] list = new byte[44]; unsafe { status = uFCoder.EnumCards(&CardsNumber, &ListSize); TempCardsNumber = CardsNumber; if (status == 0) { EnumTextBox.AppendText("There is " + CardsNumber.ToString() + " card(s) in the reader field."); if (CardsNumber > 0) { status = uFCoder.ListCards(list, ListSize); if (status != 0) { MessageBox.Show("Unable to enumerate cards!"); } else { index = 0; EnumTextBox.AppendText("\n\nUid list of the cards in the reader field:\n"); for (byte i = 0; i < CardsNumber; i++) { EnumTextBox.AppendText("\n" + (i + 1).ToString() + ". "); EnumTextBox.AppendText(ByteArrayToString(list, (byte)(index + 1), (byte)(list[index] + index + 1))); index += 11; CardComboBox.Items.Add((i + 1).ToString()); } CardComboBox.SelectedIndex = CardComboBox.Items.IndexOf("1"); } TempUid = list.ToArray(); } } else { MessageBox.Show("Error while trying to enumerate cards!"); } } }
private void bOpenReader_Click(object sender, EventArgs e) { tReaderInfo.Clear(); unsafe { byte bHWVerMajor = 0; byte bHWVerMinor = 0; byte bFWVerMajor = 0; byte bFWVerMinor = 0; byte build_number = 0; byte[] serial_description = new byte[8]; status = uFCoder.ReaderOpen(); if (status == DL_OK) { uFCoder.ReaderUISignal(1, 1); } uFCoder.GetReaderHardwareVersion(&bHWVerMajor, &bHWVerMinor); uFCoder.GetReaderFirmwareVersion(&bFWVerMajor, &bFWVerMinor); uFCoder.GetBuildNumber(&build_number); uFCoder.GetReaderSerialDescription(serial_description); tReaderInfo.AppendText("Reader serial: " + Encoding.ASCII.GetString(serial_description) + " | " + "Hardware version: " + bHWVerMajor + "." + bHWVerMinor + " | " + "Firmware version: " + bFWVerMajor + "." + bFWVerMinor + "." + build_number); } }
private void bSelect_Click(object sender, EventArgs e) { unsafe { byte CardType = 0; byte[] SelectedUid = new byte[10]; String selected_str = null; byte selected = 0; try { selected_str = CardComboBox.SelectedItem.ToString(); } catch (Exception) { } try { selected = byte.Parse(selected_str); } catch (System.ArgumentNullException) { MessageBox.Show("Nothing to select!"); } if (selected == 1) { Array.Copy(TempUid, 1, SelectedUid, 0, TempUid[0]); TempUidSize = TempUid[0]; } else if (selected == 2) { Array.Copy(TempUid, 12, SelectedUid, 0, TempUid[11]); TempUidSize = TempUid[11]; } else if (selected == 3) { Array.Copy(TempUid, 23, SelectedUid, 0, TempUid[22]); TempUidSize = TempUid[22]; } else if (selected == 4) { Array.Copy(TempUid, 34, SelectedUid, 0, TempUid[33]); TempUidSize = TempUid[33]; } byte[] Uid = new byte[TempUidSize]; Array.Copy(SelectedUid, 0, Uid, 0, TempUidSize); status = uFCoder.SelectCard(Uid, TempUidSize, &CardType); if (status == 0) { SelectedCardTextBox.Text = "Selected UID : [" + BitConverter.ToString(Uid).Replace("-", ":") + "] " + ",uid size : [" + TempUidSize.ToString() + " bytes]\n" + "Card type : [" + GetDlTypeName(CardType) + "]"; } } }
private void btLock_Click(object sender, EventArgs e) { DL_STATUS status = DL_STATUS.UNKNOWN_ERROR; status = uFCoder.EE_Lock(tbPasswd.Text, 1); prn_status(status, "NV Locked"); }
private static extern DL_STATUS MainLoop( HND_AIS hnd_device, out UInt32 RealTimeEvents, // indicate new RealTimeEvent(s) out UInt32 LogEvent, // indicate new data in log buffer out UInt32 cmdFinished, // indicate command finish out UInt32 cmdPercent, // indicate percent of command execution out UInt32 TimeoutOccurred, // debug only out DL_STATUS Status // additional status );
private void bDisableAntiColl_Click(object sender, EventArgs e) { status = uFCoder.DisableAntiCollision(); if (status > 0) { MessageBox.Show("Anti collision not disabled!"); } }
private void bReaderClose_Click(object sender, EventArgs e) { status = uFCoder.ReaderClose(); if (status > 0) { MessageBox.Show("Error while trying to close reader!"); } }
private void wr_status(string pre_text, DL_STATUS status) { string out_text = pre_text + ": "; out_text += status; out_text += Environment.NewLine; richTextBox1.AppendText(out_text); }
public dlgStoreNDEFEmulation(int TNF, string Type, string ID, byte[] Payload) { tnf = TNF; type = Type; id = ID; payload = Payload; _status = DL_STATUS.UNKNOWN_ERROR; InitializeComponent(); }
private void bCardInfo_Click(object sender, EventArgs e) { tCardInfo.Clear(); byte bCardType = 0; byte[] bCardUID = new byte[9]; byte bUidSize = 0; String sBuffer = null; log_name = ""; unsafe { card_info = ""; fixed(byte *uid = bCardUID) status = uFCoder.GetCardIdEx(&bCardType, uid, &bUidSize); status = uFCoder.GetDlogicCardType(&bCardType); if (status != 0) { tInfo.Text = "Error has occured, Error code: " + "0x" + status.ToString("X2"); } for (byte bCounter = 0; bCounter < bUidSize; bCounter++) { sBuffer += bCardUID[bCounter].ToString("X2"); } card_info += "Card type: " + "0x" + bCardType.ToString("X2") + " - " + GetDlTypeName(bCardType) + "\n"; card_info += "Card UID: " + sBuffer + " --- UID Length: " + bUidSize + " Bytes\n"; card_info += MaxBlocks(bCardType) + " blocks," + BytesPerBlock(bCardType) + " bytes per block, total " + MaxBytes(bCardType) + " Bytes\n"; tCardInfo.Text = card_info; log_name += sBuffer; if (bCardType != GlobalCardType) { GlobalCardType = bCardType; } } if (MaxBlocks(bCardType) == 0) { bReadCard.Enabled = false; } else { bReadCard.Enabled = true; } }
private void btnSetTime_Click(object sender, EventArgs e) { DateTime now = DateTime.Now; richTextBox1.AppendText("TRY TO SET TIME: " + now.ToString() + Environment.NewLine); result = ais.TimeSet(id, password, now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); wr_status("TimeSet()", result); }
public bool writeShared(int adr, byte[] data) { unsafe { fixed(byte *p = data) status = uFCoder.WriteShareRam(p, (byte)adr, (byte)data.Length); } return(status == DL_STATUS.DL_OK); }
public DL_STATUS GetECPublicKeyFromCard() { DL_STATUS status = DL_STATUS.UFR_OK; byte key_index = 0; UInt16 k, key_size_bits, key_designator; byte[] keyW, field, a, b, g, r; try { if (!uFR_Opened) { throw new Exception(uFR_NotOpenedMessage); } Cursor.Current = Cursors.WaitCursor; byte[] aid = Hex.Decode(uFCoder.JCDL_AID); byte[] selection_respone = new byte[16]; /* status = uFCoder.SetISO14443_4_Mode(); * if (status != DL_STATUS.UFR_OK) * throw new Exception(uFCoder.GetErrorDescription(status)); * else * uFR_Selected = true; * * status = uFCoder.JCAppSelectByAid(aid, (byte)aid.Length, selection_respone); * if (status != DL_STATUS.UFR_OK) * throw new Exception(uFCoder.GetErrorDescription(status));*/ status = uFCoder.JCAppGetEcPublicKey(key_index, out keyW, out field, out a, out b, out g, out r, out k, out key_size_bits, out key_designator); if (status != DL_STATUS.UFR_OK) { throw new Exception(uFCoder.GetErrorDescription(status)); } ECPubKeyStr = Hex.ToHexString(keyW); return(DL_STATUS.UFR_OK); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(status); } finally { if (uFR_Selected) { uFCoder.s_block_deselect(100); uFR_Selected = false; } Cursor.Current = Cursors.Default; } }
private void bReaderReset_Click(object sender, EventArgs e) { status = uFCoder.ReaderReset(); LabelStatus.Text = uFCoder.status2str(status); if (status > 0) { MessageBox.Show("Error while trying to reset reader!"); } }
public static DL_STATUS AIS_Restart(HND_AIS hnd_device) { DL_STATUS status = DL_STATUS.DL_OK; UInt32 i = 0; do { status = Restart(hnd_device); }while ((status == DL_STATUS.RESOURCE_BUSY) && (i++ < MAX_RETRY_IF_BUSY)); return(status); }
public static DL_STATUS AIS_Blacklist_GetSize(HND_AIS device, string str_password, out Int32 size) { DL_STATUS status = DL_STATUS.DL_OK; UInt32 i = 0; StringBuilder password = new StringBuilder(str_password); do { status = Blacklist_GetSize(device, password, out size); }while ((status == DL_STATUS.RESOURCE_BUSY) && (i++ < MAX_RETRY_IF_BUSY)); return(status); }
public bool stopEmulation() { DL_STATUS stat1; stat1 = uFCoder.ExitShareRamCommMode(); System.Threading.Thread.Sleep(100); status = uFCoder.TagEmulationStop(); return(status == DL_STATUS.DL_OK); }
public bool readShared(int adr, byte[] data) { Array.Clear(data, 0, data.Length); unsafe { fixed(byte *p = data) status = uFCoder.ReadShareRam(p, (byte)adr, (byte)data.Length); } return(status == DL_STATUS.DL_OK); }
public static DL_STATUS AIS_GetLog_Set(HND_AIS device, string str_password) { DL_STATUS status = DL_STATUS.DL_OK; UInt32 i = 0; StringBuilder password = new StringBuilder(str_password); do { status = GetLog_Set(device, password); }while ((status == DL_STATUS.RESOURCE_BUSY) && (i++ < MAX_RETRY_IF_BUSY)); return(status); }
private void bReaderClose_Click(object sender, EventArgs e) { status = uFCoder.ReaderClose(); if (status == 0) { uFCoder.ReaderUISignal(1, 1); } else { MessageBox.Show(uFCoder.status2str(status)); } }