public bool CheckAccessPasswordIsLocked()
        {
            try
            {
                string reservedBankData = string.Empty;
                //Read access password
                var op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 2, 2);
                var reservedData = (ushort[])_reader.ExecuteTagOp(op, null);

                if (null != reservedData)
                {
                    reservedBankData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                }

                var accessPassword = reservedBankData.Trim(' ');
                return(false);
            }
            catch (Exception ex)
            {
                if (ex is FAULT_GEN2_PROTOCOL_MEMORY_LOCKED_Exception)
                {
                    return(true);
                }
                Trace.TraceError("Error checking access password. " + ex.Message + ex.StackTrace);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Insert keys into tag
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnInsertKeys_Click(object sender, RoutedEventArgs e)
        {
            TagOp op;

            try
            {
                if (txtbxKeyOne.Text.Replace(" ", "").Length == 32 && txtbxKeyZero.Text.Replace(" ", "").Length == 32)
                {
                    byte[]   KeytoWrite = ByteFormat.FromHex(txtbxKeyZero.Text.Replace(" ", ""));
                    ushort[] Key0       = new ushort[KeytoWrite.Length / 2];
                    Key0 = ByteConv.ToU16s(KeytoWrite);
                    op   = new Gen2.WriteData(Gen2.Bank.USER, 0xC0, Key0);
                    objReader.ExecuteTagOp(op, searchSelect);

                    KeytoWrite = ByteFormat.FromHex(txtbxKeyOne.Text.Replace(" ", ""));
                    ushort[] Key1 = new ushort[KeytoWrite.Length / 2];
                    Key1 = ByteConv.ToU16s(KeytoWrite);
                    op   = new Gen2.WriteData(Gen2.Bank.USER, 0xD0, Key1);
                    objReader.ExecuteTagOp(op, searchSelect);
                    MessageBox.Show("Insert keys operation success", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Please input valid Keys to insert ", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #3
0
        public static void embeddedRead(TagProtocol protocol, TagFilter filter, TagOp tagop)
        {
            TagReadData[]  tagReads = null;
            SimpleReadPlan plan     = new SimpleReadPlan(antennaList, protocol, filter, tagop, 1000);

            r.ParamSet("/reader/read/plan", plan);
            tagReads = r.Read(1000);
            // Print tag reads
            foreach (TagReadData tr in tagReads)
            {
                Console.WriteLine(tr.ToString());
                if (tr.isErrorData)
                {
                    // In case of error, show the error to user. Extract error code.
                    int errorCode = ByteConv.ToU16(tr.Data, 0);
                    Console.WriteLine("Embedded Tag operation failed. Error: " + ReaderCodeException.faultCodeToMessage(errorCode));
                }
                else
                {
                    if (tagop is Gen2.EMMicro.EM4325.GetSensorData)
                    {
                        if (tr.Data.Length > 0)
                        {
                            GetSensorDataResponse rData = new GetSensorDataResponse(tr.Data);
                            Console.WriteLine("Data:" + rData.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("  Data:" + ByteFormat.ToHex(tr.Data, "", " "));
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Write Untraceable operation to tag
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btmWriteToTag_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (((bool)rdBtnShowSpecificEpc.IsChecked) && (txtbxEpcLen.Text == ""))
         {
             MessageBox.Show("Please Enter length of EPC to Show", "Universal Reader Assistant Message", MessageBoxButton.OK, MessageBoxImage.Warning);
             return;
         }
         else
         {
             epcLen = 6;
         }
         antenna = ((null != GetSelectedAntennaList()) ? (GetSelectedAntennaList()[0]) : antenna);
         objReader.ParamSet("/reader/tagop/antenna", antenna);
         if ((bool)rdBtnShowSpecificEpc.IsChecked)
         {
             epcLen = Convert.ToInt32(txtbxEpcLen.Text);
         }
         Gen2.Password    accessPassWord = new Gen2.Password(ByteConv.ToU32(ByteFormat.FromHex(txtbxAccesspaasword.Text.Replace(" ", "")), 0));
         Gen2.Untraceable tagOp          = new Gen2.NXP.AES.Untraceable(epc, epcLen, tid, user, range, accessPassWord.Value);
         objReader.ExecuteTagOp(tagOp, searchSelect);
         MessageBox.Show("Write operation is successfull", "Universal Reader Assistant Message", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Beispiel #5
0
        private void PerformReadAllMemOperation(TagFilter filter, TagOp op)
        {
            TagReadData[]  tagReads = null;
            SimpleReadPlan plan     = new SimpleReadPlan(null, TagProtocol.GEN2, filter, op, 1000);

            reader.ParamSet("/reader/read/plan", plan);
            Console.WriteLine("Embedded tag operation - ");
            // Read tags
            tagReads = reader.Read(500);
            foreach (TagReadData tr in tagReads)
            {
                Console.WriteLine(tr.ToString());
                if (0 < tr.Data.Length)
                {
                    Console.WriteLine(" Embedded read data: " + ByteFormat.ToHex(tr.Data, "", " "));
                    Console.WriteLine(" User memory: " + ByteFormat.ToHex(tr.USERMemData, "", " "));
                    Console.WriteLine(" Reserved memory: " + ByteFormat.ToHex(tr.RESERVEDMemData, "", " "));
                    Console.WriteLine(" Tid memory: " + ByteFormat.ToHex(tr.TIDMemData, "", " "));
                    Console.WriteLine(" EPC memory: " + ByteFormat.ToHex(tr.EPCMemData, "", " "));
                }
                Console.WriteLine(" Embedded read data length:" + tr.Data.Length);
            }
            Console.WriteLine();
            Console.WriteLine("Standalone tag operation - ");
            ushort[] data = (ushort[])reader.ExecuteTagOp(op, filter);
            //// Print tag reads
            if (0 < data.Length)
            {
                Console.WriteLine(" Standalone read data:" + ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(data), "", " "));
                Console.WriteLine(" Standalone read data length:" + ByteConv.ConvertFromUshortArray(data).Length);
            }
            data = null;
            Console.WriteLine();
        }
        public uint?ReadTagSync()
        {
            var action = new Action <Exception>(exception =>
            {
                var error = "Error reading tags. " + exception.Message;
                MessageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Trace.TraceError(error + exception.StackTrace);
            });

            uint?tag = null;

            try
            {
                CheckParams();

                // Create a simplereadplan which uses the antenna list created above
                SimpleReadPlan plan = new SimpleReadPlan(new[] { 1 }, TagProtocol.GEN2, null, null, 1000);
                // Set the created readplan
                _reader.ParamSet("/reader/read/plan", plan);

                // Create and add tag listener
                _reader.TagRead += delegate(Object sender, TagReadDataEventArgs e)
                {
                    var data = e.TagReadData;

                    tag = ByteConv.ToU32(data.Epc, 0);
                    Trace.TraceInformation("Tag " + tag + " has been read.");
                };

                // Create and add read exception listener
                _reader.ReadException += delegate(object sender, ReaderExceptionEventArgs reea)
                {
                    if (reea.ReaderException != null)
                    {
                        action(reea.ReaderException);
                    }
                };

                // Search for tags in the background
                _reader.StartReading();

                do
                {
                    Thread.Sleep(200);

                    // do events
                    Application.Current.Dispatcher.Invoke(() => { });
                } while (!tag.HasValue || _cancelReading);

                _reader.StopReading();
                _cancelReading = false;
            }
            catch (Exception exception)
            {
                action(exception);
            }

            return(tag);
        }
Beispiel #7
0
        public static void parseGetSystemInfoResponse(byte[] systemInfo)
        {
            int readIndex = 0;
            // Extract 1 byte of Information Flags from response
            byte infoFlags = systemInfo[readIndex++];

            //Extract UID - 8 bytes for Iso15693
            int uidLength = 8;

            byte[] uid = new byte[uidLength];
            Array.Copy(systemInfo, readIndex, uid, 0, uidLength);
            Console.WriteLine("UID: " + ByteFormat.ToHex(uid));
            readIndex += uidLength;
            if (infoFlags == 0)
            {
                Console.WriteLine("No information flags are enabled");
            }
            else
            {
                // Checks Information flags are supported or not and then extracts respective fields information.
                if ((infoFlags & 0x0001) == 0x0001)
                {
                    Console.WriteLine("DSFID is supported and DSFID field is present in the response");
                    //Extract 1 byte of DSFID
                    byte dsfid = systemInfo[readIndex++];
                    Console.WriteLine("DSFID: " + dsfid.ToString());
                }
                if ((infoFlags & 0x0002) == 0x0002)
                {
                    Console.WriteLine("AFI is supported and AFI field is present in the response");
                    //Extract 1 byte of AFI
                    byte afi = systemInfo[readIndex++];
                    Console.WriteLine("AFI: " + afi.ToString());
                }
                if ((infoFlags & 0x0004) == 0x0004)
                {
                    Console.WriteLine("VICC memory size is supported and VICC field is present in the response");
                    //Extract 2 bytes of VICC information
                    UInt16 viccInfo      = ByteConv.ToU16(systemInfo, readIndex);
                    byte   maxBlockCount = (byte)(viccInfo & 0xFF);    // holds the number of blocks
                    Console.WriteLine("Max Block count: " + maxBlockCount);
                    byte blocksize = (byte)((viccInfo & 0x1F00) >> 8); // holds blocksize
                    Console.WriteLine("Block Size: " + blocksize);
                    readIndex += 2;
                }
                if ((infoFlags & 0x0008) == 0x0008)
                {
                    Console.WriteLine("IC reference is supported and IC reference is present in the response");
                    // Extract 1 byte of IC reference
                    byte icRef = systemInfo[readIndex++];
                    Console.WriteLine("IC Reference: " + icRef.ToString());
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Parse user memory data and populate the user mem textboxes
        /// </summary>
        /// <param name="userData">accepts read user memory data</param>
        private void ParseUserMemData(ushort[] userData)
        {
            string userMemData = string.Empty;

            if (null != userData)
            {
                userMemData           = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(userData), "", "");
                txtUserDataValue.Text = ReplaceSpecialCharInAsciiData(Utilities.HexStringToAsciiString(userMemData).ToCharArray());
                txtUserMemData.Text   = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(userData), "", " ");
            }
        }
Beispiel #9
0
 /// <summary>
 /// getUTCTimestamp - retrieves the UTC timestamp from the response
 /// </summary>
 public UInt32 getUTCTimestamp(byte[] response, int readIndex, int uidLen)
 {
     if (uidLen > 0)
     {
         readIndex = uidLen + 2 + 4; // exclude uidLength(2 bytes), uidBits(uidLen bytes) and sensorData(4 bytes)
     }
     else
     {
         readIndex = 4; //exclude sensor data
     }
     // Extract utc timestamp(4 bytes)
     byte[] utcTimeArray = new byte[4];
     Array.Copy(response, readIndex, utcTimeArray, 0, 4);
     return(ByteConv.ToU32(utcTimeArray, 0));;
 }
 /// <summary>
 /// Write the kill password in the reserved memory
 /// </summary>
 public void WriteKillPassword(string killPassword)
 {
     try
     {
         _reader.ParamSet("/reader/tagop/protocol", TagProtocol.GEN2);
         ushort[] dataToBeWritten = null;
         dataToBeWritten = ByteConv.ToU16s(ByteFormat.FromHex(killPassword.Replace(" ", "")));
         _reader.ExecuteTagOp(new Gen2.WriteData(Gen2.Bank.RESERVED, 0, dataToBeWritten), null);
         //MessageBox.Show("Access Password has successfully been set to 0x" + txtbxAccesspaasword.Text.Replace(" ", ""), "Info", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        /// <summary>
        /// Apply lock action on the tag
        /// </summary>
        public bool ApplyLockAction(Gen2.LockAction action, string accessPassword)
        {
            try
            {
                _reader.ParamSet("/reader/tagop/protocol", TagProtocol.GEN2);

                _reader.ExecuteTagOp(new Gen2.Lock(ByteConv.ToU32(
                                                       ByteFormat.FromHex(accessPassword.Replace(" ", "")), 0), action), null);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
        }
Beispiel #12
0
            /// <summary>
            /// getSensorData - retrieves the sensor data from the response
            /// </summary>
            public SensorData getSensorData(byte[] response, int readIndex, int uidLen)
            {
                // Extract sensor data(4 bytes)
                byte[] sensorDataArray = new byte[4];
                if (uidLen > 0)
                {
                    readIndex = uidLen + 2;// exclude uidLength(2 bytes) and uid bits(uidLen bytes)
                }
                else
                {
                    readIndex = 0;
                }
                Array.Copy(response, readIndex, sensorDataArray, 0, 4);
                UInt32 sData = ByteConv.ToU32(sensorDataArray, 0);

                return(new SensorData(sData));
            }
Beispiel #13
0
        /// <summary>
        /// Parse reserved memory data and populate the reserved mem textboxes
        /// </summary>
        /// <param name="reservedData">accepts read reserved memory data</param>
        private void ParseReservedMemData(ushort[] reservedData)
        {
            string reservedMemData = string.Empty;

            if (null != reservedData)
            {
                reservedMemData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
            }

            if (reservedMemData.Length > 0)
            {
                if (reservedMemData.Length > 11)
                {
                    // Extract kill pwd
                    txtKillPassword.Text = reservedMemData.Substring(0, 11).TrimStart(' ');
                    string tempData = reservedMemData.Substring(12).TrimStart(' ');
                    // Check if reserved memory has additional data
                    if (tempData.Length > 11)
                    {
                        // Extract access pwd
                        txtAcessPassword.Text = reservedMemData.Substring(12, 11).TrimStart(' ');
                        // Extract additional reserved memory
                        txtReservedMemUnusedValue.Text = reservedMemData.Substring(24).TrimStart(' ');

                        // Visible additional memory textboxes
                        lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Visible;
                        txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Visible;
                        lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        // Extract access pwd
                        txtAcessPassword.Text = reservedMemData.Substring(12).TrimStart(' ');

                        // Hide additional memory textboxes
                        lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Collapsed;
                        txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Collapsed;
                        lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Collapsed;
                    }
                }
                else
                {
                    txtKillPassword.Text = reservedMemData.Substring(0, reservedData.Length).TrimStart(' ');
                }
            }
        }
        public bool CheckEpcIsLocked(string accessPassword)
        {
            try
            {
                _reader.ParamSet("/reader/tagop/protocol", TagProtocol.GEN2);

                _reader.ExecuteTagOp(new Gen2.Lock(ByteConv.ToU32(
                                                       ByteFormat.FromHex(accessPassword.Replace(" ", "")), 0), new Gen2.LockAction(Gen2.LockAction.EPC_UNLOCK)), null);
                return(false);
            }
            catch (Exception ex)
            {
                if (ex is FAULT_GEN2_PROTOCOL_MEMORY_LOCKED_Exception)
                {
                    return(true);
                }
                Trace.TraceError("Error checking EPC. " + ex.Message + ex.StackTrace);
                return(false);
            }
        }
        public bool WriteTag(uint tag)
        {
            try
            {
                CheckParams();

                var data = ByteConv.EncodeU32(tag);
                //_reader.WriteTag(null, new TagData(epcTag));
                _reader.ExecuteTagOp(new Gen2.WriteTag(new Gen2.TagData(data)), null);
                Trace.TraceInformation("Tag " + tag + " has been written.");
                return(true);
            }
            catch (Exception exception)
            {
                var error = "Error encoding the tag " + tag + ". " + exception.Message;
                MessageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Trace.TraceError(error + exception.StackTrace);
                return(false);
            }
        }
 // seems like the wrong method
 private uint?ReadTag(int timeout)
 {
     try
     {
         CheckParams();
         var data = _reader.Read(timeout);
         if (data.Length > 0)
         {
             var tag = ByteConv.ToU32(data[0].Epc, 0);
             Trace.TraceInformation("Tag " + tag + " has been read.");
             return(tag);
         }
         return(null);
     }
     catch (Exception exception)
     {
         var error = "Error reading tags. " + exception.Message;
         MessageBox.Show(error, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         Trace.TraceError(error + exception.StackTrace);
         return(null);
     }
 }
Beispiel #17
0
        /// <summary>
        /// Parse tid memory data and populate the tid mem textboxes
        /// </summary>
        /// <param name="tidData">accepts read tid memory data</param>
        private void ParseTIDMemData(ushort[] tidData)
        {
            string tidBankData = string.Empty;

            if (null != tidData)
            {
                tidBankData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(tidData), "", " ");
            }

            if (tidBankData.Length > 0)
            {
                txtClsID.Text    = tidBankData.Substring(0, 2).TrimStart(' ');
                txtVendorID.Text = tidBankData.Substring(3, 4).Replace(" ", string.Empty);
                string tagModel = string.Empty;
                txtVendorValue.Text   = GetVendor(txtVendorID.Text, tidBankData.Substring(7, 4).Replace(" ", string.Empty), out tagModel);
                txtModelID.Text       = tidBankData.Substring(7, 4).Replace(" ", string.Empty);
                txtModeldIDValue.Text = tagModel;
                if (tidBankData.Length >= 12)
                {
                    txtUniqueIDValue.Text = tidBankData.Substring(12).TrimStart(' ');
                }
            }
        }
Beispiel #18
0
 public void Kill()
 {
     try
     {
         DateTime timeBeforeRead = DateTime.Now;
         using (Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
         {
             reader.Connect();
             uint           killPassword = ByteConv.ToU32(ByteFormat.FromHex(textBox3.Text), 0);
             TagOp          tagOp        = new Gen2.Kill(killPassword);
             SimpleReadPlan plan         = new SimpleReadPlan(null, TagProtocol.GEN2, null, tagOp, 1000);
             reader.ParamSet("/reader/read/plan", plan);
             reader.ExecuteTagOp(tagOp, tagData);
         }
         DateTime timeAfterRead = DateTime.Now;
         TimeSpan timeElapsed   = timeAfterRead - timeBeforeRead;
         commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #19
0
 public void WritePassword(uint byteIndex, string password)
 {
     try
     {
         DateTime timeBeforeRead = DateTime.Now;
         ushort[] data           = ByteConv.ToU16s(ByteFormat.FromHex(password));
         using (Reader reader = Reader.Create("tmr:///" + Vars.comport.ToLower()))
         {
             reader.Connect();
             TagOp          tagOp = new Gen2.WriteData(Gen2.Bank.RESERVED, byteIndex, data);
             SimpleReadPlan plan  = new SimpleReadPlan(null, TagProtocol.GEN2, null, tagOp, 1000);
             reader.ParamSet("/reader/read/plan", plan);
             reader.ExecuteTagOp(tagOp, tagData);
         }
         DateTime timeAfterRead = DateTime.Now;
         TimeSpan timeElapsed   = timeAfterRead - timeBeforeRead;
         commandTotalTimeTextBox.Text = timeElapsed.TotalSeconds.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #20
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }

            for (int nextarg = 1; nextarg < args.Length; nextarg++)
            {
                string arg = args[nextarg];
                if (arg.Equals("--ant"))
                {
                    if (null != antennaList)
                    {
                        Console.WriteLine("Duplicate argument: --ant specified more than once");
                        Usage();
                    }
                    antennaList = ParseAntennaList(args, nextarg);
                    nextarg++;
                }
                else
                {
                    Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
                    Usage();
                }
            }

            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        r.ParamSet("/reader/region/id", supportedRegions[0]);
                    }
                    if (r.isAntDetectEnabled(antennaList))
                    {
                        Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                        Usage();
                    }

                    // Create a simplereadplan which uses the antenna list created above
                    SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000);
                    // Set the created readplan
                    r.ParamSet("/reader/read/plan", plan);

                    //Use first antenna for operation
                    if (antennaList != null)
                    {
                        r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                    }


                    ushort[] Key0 = new ushort[] { 0x0123, 0x4567, 0x89AB, 0xCDEF, 0x0123, 0x4567, 0x89AB, 0xCDEF };
                    ushort[] Key1 = new ushort[] { 0x1122, 0x3344, 0x5566, 0x7788, 0x1122, 0x3344, 0x5566, 0x7788 };

                    // Change enable filter to true inorder to enable filter.
                    bool        enableFilter = false;
                    Gen2.Select filter       = null;
                    if (enableFilter)
                    {
                        filter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 96,
                                                 new byte[] { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF });
                    }

                    bool   SendRawData = true;
                    bool   _isNMV2DTag = false;
                    byte[] Response;
                    Gen2.NXP.AES.Tam1Authentication tam1Auth;
                    Gen2.NXP.AES.Tam2Authentication tam2Auth;

                    //Uncomment this to enable Authenticate with TAM1 with key0 for NXPUCODE AES tag

                    //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, SendRawData);
                    //Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    //Response = (byte[])r.ExecuteTagOp(auth, filter);
                    //if (SendRawData)
                    //{
                    //    parseTAM1Response(Response, ByteConv.ConvertFromUshortArray(Key0));
                    //}
                    //else
                    //{
                    //    Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(Response, "", " "));
                    //}

                    //Uncomment this to enable Authenticate with TAM1 with Key1

                    //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, SendRawData);
                    //Gen2.NXP.AES.Authenticate tam1AuthKey1 = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    //Response = (byte[])r.ExecuteTagOp(tam1AuthKey1, filter);
                    //if (SendRawData)
                    //{
                    //    parseTAM1Response(Response, ByteConv.ConvertFromUshortArray(Key1));
                    //}
                    //else
                    //{
                    //    Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(Response, "", " "));
                    //}

                    //Uncomment this to enable Authenticate with TAM2 with key1

                    ushort Offset     = 0;
                    ushort BlockCount = 1;
                    //supported protMode value is 1 for NXPUCODE AES
                    ushort ProtMode = 1;
                    tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Gen2.NXP.AES.Profile.EPC,
                                                                   Offset, BlockCount, ProtMode, SendRawData);
                    Gen2.NXP.AES.Authenticate tam2AuthKey1 = new Gen2.NXP.AES.Authenticate(tam2Auth);
                    Response = (byte[])r.ExecuteTagOp(tam2AuthKey1, filter);
                    if (SendRawData)
                    {
                        parseTAM2Response(Response, ByteConv.ConvertFromUshortArray(Key1), ProtMode);
                    }
                    else
                    {
                        byte[] generatedIChallenge = new byte[10];
                        byte[] dataRequested       = new byte[16];
                        Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                        Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(generatedIChallenge, "", " "));
                        Array.Copy(Response, 10, dataRequested, 0, 16);
                        Console.WriteLine("Data :" + ByteFormat.ToHex(dataRequested, "", " "));
                    }

                    // Embedded tag operations

                    #region EmbeddedTagOperations
                    {
                        //Uncomment this to execute embedded tagop for TAM1 Authentication using Key0
                        //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, SendRawData);
                        //Gen2.NXP.AES.Authenticate embeddedauth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                        //Response = performEmbeddedOperation(filter, embeddedauth);
                        //if (SendRawData)
                        //{
                        //parseTAM1Response(Response, ByteConv.ConvertFromUshortArray(Key0));
                        //}
                        //else
                        //{
                        //Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(Response, "", " "));
                        //}

                        //Uncomment this to execute embedded tagop for Authenticate with TAM1 using Key1
                        //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, SendRawData);
                        //Gen2.NXP.AES.Authenticate embeddedtam1AuthKey1 = new Gen2.NXP.AES.Authenticate(tam1Auth);
                        //Response = performEmbeddedOperation(filter, embeddedtam1AuthKey1);
                        //if (SendRawData)
                        //{
                        //    parseTAM1Response(Response, ByteConv.ConvertFromUshortArray(Key1));
                        //}
                        //else
                        //{
                        //    Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(Response, "", " "));
                        //}

                        //Uncomment this to execute embedded tagop for Authenticate with TAM2 with key1
                        //ushort EmbeddedOffset = 0;
                        //ushort EmbeddedBlockCount = 1;
                        ////supported protMode value is 1 for NXPUCODE AES
                        //ushort EmbeddedProtMode = 1;
                        //tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Gen2.NXP.AES.Profile.EPC,
                        //   EmbeddedOffset, EmbeddedBlockCount, EmbeddedProtMode, SendRawData);
                        //Gen2.NXP.AES.Authenticate embeddedtam2AuthKey1 = new Gen2.NXP.AES.Authenticate(tam2Auth);
                        //Response = performEmbeddedOperation(filter, embeddedtam2AuthKey1);
                        //if (SendRawData)
                        //{
                        //    parseTAM2Response(Response, ByteConv.ConvertFromUshortArray(Key1), EmbeddedProtMode);
                        //}
                        //else
                        //{
                        //    byte[] generatedIChallenge = new byte[10];
                        //    byte[] dataRequested = new byte[16];
                        //    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                        //    Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(generatedIChallenge, "", " "));
                        //    Array.Copy(Response, 10, dataRequested, 0, 16);
                        //    Console.WriteLine("Data :" + ByteFormat.ToHex(dataRequested, "", " "));
                        //}
                    }
                    #endregion EmbeddedTagOperations

                    //Enable flag _isNMV2DTag for TAM1/TAM2 Authentication with KEY0 for NMV2D Tag
                    if (_isNMV2DTag)
                    {
                        // NMV2D tag only supports KEY0
                        // Uncomment this to enable TAM1 Authentication with KEY0
                        //ushort[] Key0_NMV2D = new ushort[] { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };
                        //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0_NMV2D, SendRawData);
                        //Gen2.NXP.AES.Authenticate tam1AuthKey0 = new Gen2.NXP.AES.Authenticate(tam1Auth);
                        //Response = (byte[])r.ExecuteTagOp(tam1AuthKey0, filter);
                        //if (SendRawData)
                        //{
                        //    parseTAM1Response(Response, ByteConv.ConvertFromUshortArray(Key0_NMV2D));
                        //}
                        //else
                        //{
                        //    Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(Response, "", " "));
                        //}

                        //TAM2 Authentication with KEY0
                        //ushort offset = 0;
                        //ushort blockCount = 1;
                        ////supported protMode values are 0x00, 0x01, 0x02, 0x03
                        //ushort protMode = 0;
                        //tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0_NMV2D, Gen2.NXP.AES.Profile.EPC,
                        // offset, blockCount, protMode, SendRawData);
                        //Gen2.NXP.AES.Authenticate tam2AuthKey0 = new Gen2.NXP.AES.Authenticate(tam2Auth);
                        //Response = (byte[])r.ExecuteTagOp(tam2AuthKey0, filter);
                        //if (SendRawData)
                        //{
                        //    parseTAM2Response(Response, ByteConv.ConvertFromUshortArray(Key0_NMV2D), protMode);
                        //}
                        //else
                        //{
                        //    byte[] generatedIChallenge = new byte[10];
                        //    byte[] dataRequested = new byte[16];
                        //    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                        //    Console.WriteLine("Generated Ichallenge:" + ByteFormat.ToHex(generatedIChallenge, "", " "));
                        //    Array.Copy(Response, 10, dataRequested, 0, 16);
                        //    Console.WriteLine("Data :" + ByteFormat.ToHex(dataRequested, "", " "));
                        // }
                    }
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Beispiel #21
0
        /// <summary>
        /// Parse epc memory data and populate the epc mem textboxes
        /// </summary>
        /// <param name="epcData">accepts read epc memory data</param>
        private void ParseEPCMemData(ushort[] epcData, TagFilter filter)
        {
            unUsedEpcData = string.Empty;
            byte[] epcBankData = null;
            if (null != epcData)
            {
                epcBankData = ByteConv.ConvertFromUshortArray(epcData);
                int    readOffset = 0;
                byte[] epc, crc, pc, unusedEpc = null, additionalMemData = null;
                int    lengthCounter           = 2;
                crc            = SubArray(epcBankData, ref readOffset, lengthCounter);
                pc             = SubArray(epcBankData, ref readOffset, lengthCounter);
                lengthCounter += 2;

                // Extract the epc length from pc word
                int epclength = Convert.ToInt32(((pc[0] & 0xf8) >> 3)) * 2;

                epc = SubArray(epcBankData, ref readOffset, epclength);

                List <byte> xpc = new List <byte>();

                /* Add support for XPC bits
                 * XPC_W1 is present, when the 6th most significant bit of PC word is set
                 */
                if ((pc[0] & 0x02) == 0x02)
                {
                    /* When this bit is set, the XPC_W1 word will follow the PC word
                     * Our TMR_Gen2_TagData::pc has enough space, so copying to the same.
                     */
                    try
                    {
                        ushort[] xpcW1 = (ushort[])objReader.ExecuteTagOp(new Gen2.ReadData(Gen2.Bank.EPC, 0x21, 1), filter);
                        spXPC.Visibility          = System.Windows.Visibility.Visible;
                        lblXPC1MemAddress.Content = "33";
                        xpc.AddRange(ByteConv.ConvertFromUshortArray(xpcW1));
                        lengthCounter  += 2;
                        txtXPC1.Text    = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(xpcW1), "", " ");
                        lblXPC1.Content = "XPC";
                    }
                    catch (Exception ex)
                    {
                        spXPC.Visibility = System.Windows.Visibility.Visible;
                        txtXPC1.Text     = ex.Message;
                        lblXPC1.Content  = "XPC";
                    }

                    /* If the most siginificant bit of XPC_W1 is set, then there exists
                     * XPC_W2. A total of 6  (PC + XPC_W1 + XPC_W2 bytes)
                     */
                    if ((xpc[0] & 0x80) == 0x80)
                    {
                        try
                        {
                            ushort[] xpcW2 = (ushort[])objReader.ExecuteTagOp(new Gen2.ReadData(Gen2.Bank.EPC, 0x22, 1), filter);
                            spXPC2.Visibility         = System.Windows.Visibility.Visible;
                            lblXPC2MemAddress.Content = "34";
                            lengthCounter            += 2;
                            txtXPC2.Text = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(xpcW2), "", " ");
                            // Change the name of XPC to XPC1
                            lblXPC1.Content = "XPC1";
                        }
                        catch (Exception ex)
                        {
                            spXPC2.Visibility = System.Windows.Visibility.Visible;
                            txtXPC2.Text      = ex.Message;
                            // Change the name of XPC to XPC1
                            lblXPC1.Content = "XPC1";
                        }
                    }
                }
                // Read extended epc memory
                if (epcBankData.Length > (lengthCounter + epclength))
                {
                    lblExtdEPCMemAddress.Content = Convert.ToString(readOffset / 2);
                    bool          isExtendedEPCMemover   = true;
                    uint          startExtdEPCMemAddress = (uint)readOffset / 2;
                    List <ushort> data = new List <ushort>();
                    try
                    {
                        while (isExtendedEPCMemover)
                        {
                            // Make sure reading of memory word by word doesn't override XPC1 data
                            if (startExtdEPCMemAddress < 33)
                            {
                                data.AddRange((ushort[])objReader.ExecuteTagOp(new Gen2.ReadData(Gen2.Bank.EPC, startExtdEPCMemAddress, 1), filter));
                                startExtdEPCMemAddress += 1;
                            }
                            else
                            {
                                // Read of memory should not exceed XPC bytes
                                isExtendedEPCMemover = false;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        // If more then once the below exceptions are recieved then come out of the loop.
                        if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception || (-1 != ex.Message.IndexOf("Non-specific reader error")) || (-1 != ex.Message.IndexOf("General Tag Error")) || (-1 != ex.Message.IndexOf("Tag data access failed")))
                        {
                            if (data.Count > 0)
                            {
                                // Just skip the exception and move on. So as not to lose the already read data.
                                isExtendedEPCMemover = false;
                            }
                        }
                    }

                    if (data.Count > 0)
                    {
                        unusedEpc = ByteConv.ConvertFromUshortArray(data.ToArray());
                    }
                }

                // Read additional memory
                if (epcBankData.Length > (lengthCounter + epclength))
                {
                    lblAddMemAddress.Content = "35";
                    bool          isAdditionalMemover       = true;
                    uint          startAdditionalMemAddress = 0x23;
                    List <ushort> dataAdditionalMem         = new List <ushort>();
                    try
                    {
                        while (isAdditionalMemover)
                        {
                            dataAdditionalMem.AddRange((ushort[])objReader.ExecuteTagOp(new Gen2.ReadData(Gen2.Bank.EPC, startAdditionalMemAddress, 1), filter));
                            startAdditionalMemAddress += 1;
                        }
                    }
                    catch (Exception ex)
                    {
                        // If more then once the below exceptions are recieved then come out of the loop.
                        if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception || (-1 != ex.Message.IndexOf("Non-specific reader error")) || (-1 != ex.Message.IndexOf("General Tag Error")) || (-1 != ex.Message.IndexOf("Tag data access failed")))
                        {
                            if (dataAdditionalMem.Count > 0)
                            {
                                // Just skip the exception and move on. So as not to lose the already read data.
                                isAdditionalMemover = false;
                            }
                        }
                    }
                    if (dataAdditionalMem.Count > 0)
                    {
                        additionalMemData = ByteConv.ConvertFromUshortArray(dataAdditionalMem.ToArray());
                    }
                }

                if (txtXPC1.Text != "")
                {
                    spXPC.Visibility = System.Windows.Visibility.Visible;
                }
                if (txtXPC2.Text != "")
                {
                    spXPC2.Visibility = System.Windows.Visibility.Visible;
                }

                txtCRC.Text = ByteFormat.ToHex(crc, "", " ");
                txtPC.Text  = ByteFormat.ToHex(pc, "", " ");
                if (epc.Length == epclength)
                {
                    txtEPCData.Text = ByteFormat.ToHex(epc, "", " ");
                }
                else
                {
                    txtEPCData.Text = currentEPC;
                }
                if (null != unusedEpc)
                {
                    txtEPCUnused.Text = ByteFormat.ToHex(unusedEpc, "", " ");
                    unUsedEpcData     = ByteFormat.ToHex(unusedEpc, "", "");
                    // Visible additional memory
                    spUnused.Visibility = System.Windows.Visibility.Visible;
                }

                if (null != additionalMemData)
                {
                    txtAdditionalMem.Text = ByteFormat.ToHex(additionalMemData, "", " ");
                    unadditionalMemData   = ByteFormat.ToHex(additionalMemData, "", "");
                    // Visible additional memory
                    spAddMemory.Visibility = System.Windows.Visibility.Visible;
                }

                if ((bool)rbEPCAscii.IsChecked)
                {
                    txtEPCValue.Text           = Utilities.HexStringToAsciiString(currentEPC);
                    txtEPCUnusedValue.Text     = Utilities.HexStringToAsciiString(unUsedEpcData);
                    txtadditionalMemValue.Text = Utilities.HexStringToAsciiString(unadditionalMemData);
                }
                else if ((bool)rbEPCBase36.IsChecked)
                {
                    txtEPCValue.Text           = Utilities.ConvertHexToBase36(currentEPC);
                    txtEPCUnusedValue.Text     = Utilities.ConvertHexToBase36(unUsedEpcData);
                    txtadditionalMemValue.Text = Utilities.ConvertHexToBase36(unadditionalMemData);
                }

                #region 0 length read

                //if (model.Equals("M5e") || model.Equals("M5e EU") || model.Equals("M5e Compact"))
                //{
                //    ReadData(Gen2.Bank.EPC, searchSelect, out epcData);
                //}
                //else
                //{
                //    op = new Gen2.ReadData(Gen2.Bank.EPC, 0, 0);
                //    epcData = (ushort[])objReader.ExecuteTagOp(op, searchSelect);
                //}

                //if(null!= epcData)
                //    epcBankData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(epcData), "", " ");

                //if (epcBankData.Length > 0)
                //{
                //    int epcLen = txtEpc.Text.Length;
                //    txtCRC.Text = epcBankData.Substring(0, 5).TrimStart(' ');
                //    txtPC.Text = epcBankData.Substring(6, 5).TrimStart(' ');
                //    int epcstringLength = epcLen+((epcLen/2)-1);
                //    txtEPCData.Text = epcBankData.Substring(11, epcstringLength).TrimStart(' ');

                //    //string epcDataString = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(epcData), "", "");
                //    txtEPCUnused.Text = epcBankData.Substring(11 + epcstringLength).TrimStart(' '); //String.Join(" ", (epcDataString.Substring(8 + epcLen)).ToArray());
                #endregion
            }
        }
Beispiel #22
0
        /// <summary>
        /// Authenticate with key1
        /// </summary>
        private void btnAuthKeyOne_Click(object sender, RoutedEventArgs e)
        {
            Gen2.NXP.AES.Tam2Authentication tam2Auth;
            Gen2.NXP.AES.Tam1Authentication tam1Auth;
            ushort[] Key1, Ichallenge, returnedIchallenge;
            byte[]   Response, Challenge;
            lblDataValue.Content       = "";
            lblTam2DataValue.Content   = "";
            lblChallenge1Value.Content = "";
            switch (cbxReadDataBank.Text)
            {
            case "TID":
                MemoryProfile = Gen2.NXP.AES.Profile.TID;
                break;

            case "User":
                MemoryProfile = Gen2.NXP.AES.Profile.USER;
                break;

            case "EPC":
                MemoryProfile = Gen2.NXP.AES.Profile.EPC;
                break;
            }

            if (txtbxVerifyKeyOne.Text.Length == 32)
            {
                byte[] KeytoWrite = ByteFormat.FromHex(txtbxVerifyKeyOne.Text);
                Key1 = new ushort[KeytoWrite.Length / 2];
                Key1 = ByteConv.ToU16s(KeytoWrite);
            }
            else
            {
                MessageBox.Show("Please input valid Key1", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            byte[] randmNumber = ByteFormat.FromHex(lblRandomChallengeValue.Content.ToString().Replace(" ", ""));
            Ichallenge = new ushort[randmNumber.Length / 2];
            Ichallenge = ByteConv.ToU16s(randmNumber);

            try
            {
                if ((bool)chkReadData.IsChecked && (bool)chkReadBuffer.IsChecked)
                {
                    //ReadBuffer with Tam2
                    tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, MemoryProfile,
                                                                   (ushort)Convert.ToUInt32(txtReadStartAddr.Text), (ushort)Convert.ToUInt32(txtReadLength.Text), false);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 256, tam2Auth);

                    Response = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    //swap the bytes
                    for (int i = 0; i < Response.Length; i += 2)
                    {
                        SwapBytes(ref Response, i, i + 1);
                    }
                    Challenge                  = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblDataValue.Content       = DecryptCustomData(Response.Skip(16).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1), Response.Skip(0).Take(16).ToArray());
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == false)
                {
                    //Auth with tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == true)
                {
                    //Readbuffer with Tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, false);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    Response = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    //swap the bytes
                    for (int i = 0; i < Response.Length; i += 2)
                    {
                        SwapBytes(ref Response, i, i + 1);
                    }
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    lblDataValue.Content       = "";
                }
                else
                {
                    //Authenticate with tam2
                    tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, MemoryProfile,
                                                                   (ushort)Convert.ToUInt32(txtReadStartAddr.Text), (ushort)Convert.ToUInt32(txtReadLength.Text), true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam2Auth);
                    Response = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    if (Response != null)
                    {
                        lblTam2DataValue.Content = ByteFormat.ToHex(Response, "", " ");
                    }
                    lblTam2DataValue.Content = DecryptCustomData(Response.Skip(16).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1), Response.Skip(0).Take(16).ToArray());
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                returnedIchallenge = new ushort[Challenge.Length / 2];
                returnedIchallenge = ByteConv.ToU16s(Challenge);
                if (returnedIchallenge.SequenceEqual(Ichallenge))
                {
                    MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
Beispiel #23
0
        /// <summary>
        /// Populate keys of the tag
        /// </summary>
        private void PopulateAuthenticateData()
        {
            try
            {
                Mouse.SetCursor(Cursors.Wait);
                ResetUntraceableFields();
                if ((bool)rbFirstTagAuthenticateTb.IsChecked)
                {
                    antenna = GetSelectedAntennaList()[0];
                }
                objReader.ParamSet("/reader/tagop/antenna", antenna);

                if ((bool)rbSelectedTagAuthenticateTb.IsChecked)
                {
                    if (lblSelectFilter.Content.ToString().Contains("EPC ID"))
                    {
                        searchSelect = new TagData(currentEPC);
                    }
                    else
                    {
                        int    dataLength       = 0;
                        byte[] SearchSelectData = ByteFormat.FromHex(txtData.Text);
                        if (null != SearchSelectData)
                        {
                            dataLength = SearchSelectData.Length;
                        }

                        searchSelect = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(startAddress * 16), Convert.ToUInt16(dataLength * 8), SearchSelectData);
                    }
                }
                else
                {
                    searchSelect = new TagData(currentEPC);
                }


                TagOp op;
                try
                {
                    ushort[] Key0           = null;
                    string   CurrentKeyZero = string.Empty;
                    op   = new Gen2.ReadData(Gen2.Bank.USER, 0xC0, 8);
                    Key0 = (ushort[])objReader.ExecuteTagOp(op, searchSelect);

                    if (null != Key0)
                    {
                        CurrentKeyZero = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(Key0), "", " ");
                    }

                    crntKey0Value.Content  = CurrentKeyZero;
                    txtbxKeyZero.IsEnabled = true;
                    txtbxKeyZero.Text      = CurrentKeyZero;
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        crntKey0Value.Content  = "Key0 is inserted and activated";
                        txtbxKeyZero.IsEnabled = false;
                    }
                }
                try
                {
                    ushort[] Key1          = null;
                    string   CurrentKeyOne = string.Empty;
                    op   = new Gen2.ReadData(Gen2.Bank.USER, 0xD0, 8);
                    Key1 = (ushort[])objReader.ExecuteTagOp(op, searchSelect);

                    if (null != Key1)
                    {
                        CurrentKeyOne = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(Key1), "", " ");
                    }

                    crntKey1Value.Content = CurrentKeyOne;
                    txtbxKeyOne.IsEnabled = true;
                    txtbxKeyOne.Text      = CurrentKeyOne;
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        crntKey1Value.Content = "Key1 is inserted and activated";
                        txtbxKeyOne.IsEnabled = false;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.SetCursor(Cursors.Arrow);
            }
        }
Beispiel #24
0
        private void ReadReservedMemData(Gen2.Bank bank, TagFilter filter)
        {
            ushort [] reservedData;
            TagOp     op;

            try
            {
                try
                {
                    // Read kill password
                    op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 0, 2);
                    reservedData = (ushort[])objReader.ExecuteTagOp(op, filter);
                    if (null != reservedData)
                    {
                        txtKillPassword.Text = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                    }
                    else
                    {
                        txtKillPassword.Text = "";
                    }
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        txtKillPassword.Text = "Read Error";
                    }
                    else
                    {
                        txtKillPassword.Text = ex.Message;
                    }
                }

                try
                {
                    // Read access password
                    reservedData = null;
                    op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 2, 2);
                    reservedData = (ushort[])objReader.ExecuteTagOp(op, filter);
                    if (null != reservedData)
                    {
                        txtAcessPassword.Text = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                    }
                    else
                    {
                        txtAcessPassword.Text = "";
                    }
                }
                catch (Exception ex)
                {
                    if (ex is FAULT_GEN2_PROTOCOL_MEMORY_OVERRUN_BAD_PC_Exception)
                    {
                        txtAcessPassword.Text = "Read Error";
                    }
                    else
                    {
                        txtAcessPassword.Text = ex.Message;
                    }
                }

                // Read additional memory password
                try
                {
                    reservedData = null;
                    if (model.Equals("M5e") || model.Equals("M5e EU") || model.Equals("M5e Compact") || model.Equals("M5e PRC") || model.Equals("Astra"))
                    {
                        ReadAdditionalReservedMemDataM5eVariants(Gen2.Bank.RESERVED, 4, filter, out reservedData);
                    }
                    else
                    {
                        op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 4, 0);
                        reservedData = (ushort[])objReader.ExecuteTagOp(op, filter);
                    }

                    if (null != reservedData)
                    {
                        txtReservedMemUnusedValue.Text = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                        // Visible additional memory textboxes
                        lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Visible;
                        txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Visible;
                        lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        txtReservedMemUnusedValue.Text = "";
                    }
                }
                catch
                {
                    // catch the exception and move on. Only some tags has aditional memory
                    txtReservedMemUnusedValue.Text = "";
                    // Hide additional memory textboxes
                    lblAdditionalReservedMem.Visibility    = System.Windows.Visibility.Collapsed;
                    txtReservedMemUnusedValue.Visibility   = System.Windows.Visibility.Collapsed;
                    lblAdditionalReservedMemAdd.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            // Program setup
            if (1 > args.Length)
            {
                Usage();
            }

            for (int nextarg = 1; nextarg < args.Length; nextarg++)
            {
                string arg = args[nextarg];
                if (arg.Equals("--ant"))
                {
                    if (null != antennaList)
                    {
                        Console.WriteLine("Duplicate argument: --ant specified more than once");
                        Usage();
                    }
                    antennaList = ParseAntennaList(args, nextarg);
                    nextarg++;
                }
                else
                {
                    Console.WriteLine("Argument {0}:\"{1}\" is not recognized", nextarg, arg);
                    Usage();
                }
            }

            try
            {
                // Create Reader object, connecting to physical device.
                // Wrap reader in a "using" block to get automatic
                // reader shutdown (using IDisposable interface).
                using (r = Reader.Create(args[0]))
                {
                    //Uncomment this line to add default transport listener.
                    //r.Transport += r.SimpleTransportListener;

                    r.Connect();
                    if (Reader.Region.UNSPEC == (Reader.Region)r.ParamGet("/reader/region/id"))
                    {
                        Reader.Region[] supportedRegions = (Reader.Region[])r.ParamGet("/reader/region/supportedRegions");
                        if (supportedRegions.Length < 1)
                        {
                            throw new FAULT_INVALID_REGION_Exception();
                        }
                        r.ParamSet("/reader/region/id", supportedRegions[0]);
                    }
                    string model = r.ParamGet("/reader/version/model").ToString();
                    if ((model.Equals("M6e Micro") || model.Equals("M6e Nano") || model.Equals("Sargas")) && antennaList == null)
                    {
                        Console.WriteLine("Module doesn't has antenna detection support please provide antenna list");
                        Usage();
                    }

                    // Create a simplereadplan which uses the antenna list created above
                    SimpleReadPlan plan = new SimpleReadPlan(antennaList, TagProtocol.GEN2, null, null, 1000);
                    // Set the created readplan
                    r.ParamSet("/reader/read/plan", plan);

                    //Use first antenna for operation
                    if (antennaList != null)
                    {
                        r.ParamSet("/reader/tagop/antenna", antennaList[0]);
                    }

                    ushort[] Key0       = new ushort[] { 0x0123, 0x4567, 0x89AB, 0xCDEF, 0x0123, 0x4567, 0x89AB, 0xCDEF };
                    ushort[] Key1       = new ushort[] { 0x1122, 0x3344, 0x5566, 0x7788, 0x1122, 0x3344, 0x5566, 0x7788 };
                    ushort[] Ichallenge = new ushort[] { 0x0123, 0x4567, 0x89AB, 0xCDEF, 0xABCD };

                    Gen2.Select filter = new Gen2.Select(false, Gen2.Bank.EPC, 32, 96,
                                                         new byte[] { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF });

                    bool SendRawData = false;
                    bool _isNMV2DTag = false;
                    Gen2.NXP.AES.Tam1Authentication tam1Auth;
                    Gen2.NXP.AES.Tam2Authentication tam2Auth;
                    byte[] Response;
                    byte[] Challenge;

                    //ReadBuffer with TAM1 using Key0
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, Ichallenge, SendRawData);
                    Gen2.ReadBuffer tagOp = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    Response = (byte[])r.ExecuteTagOp(tagOp, null);
                    if (SendRawData)
                    {
                        Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key0));
                        Array.Copy(Challenge, 6, Challenge, 0, 10);
                        Array.Resize(ref Challenge, 10);
                        Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        Console.WriteLine("Returned Response:" + ByteFormat.ToHex(Response, "", " "));
                    }

                    // Uncomment this to enable ReadBuffer with TAM1 using Key1

                    //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, SendRawData);
                    //Gen2.ReadBuffer Tam1RdBufWithKey0 = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    //Response = (byte[])r.ExecuteTagOp(Tam1RdBufWithKey0, null);
                    //if (SendRawData)
                    //{
                    //    Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key1));
                    //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                    //    Array.Resize(ref Challenge, 10);
                    //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                    //    Console.WriteLine("Returned Response:" + ByteFormat.ToHex(Response, "", " "));
                    //}

                    //Uncomment this to enable ReadBuffer with TAM2 using key1

                    //ushort Offset = 0;
                    //ushort BlockCount = 1;
                    // supported protMode value is 1 for NXPUCODE AES tag
                    //ushort ProtMode = 1;
                    //tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge,
                    //           Gen2.NXP.AES.Profile.EPC, Offset, BlockCount, ProtMode, SendRawData);
                    //Gen2.ReadBuffer Tam2RdBufWithKey1 = new Gen2.NXP.AES.ReadBuffer(0, 256, tam2Auth);
                    //Response = (byte[])r.ExecuteTagOp(Tam2RdBufWithKey1, null);
                    //if (SendRawData)
                    //{
                    //    byte[] CipherData = new byte[16];
                    //    byte[] IV = new byte[16];
                    //    Array.Copy(Response, IV, 16);
                    //    Array.Copy(Response, 0, IV, 0, 16);
                    //    Array.Copy(Response, 16, CipherData, 0, 16);
                    //    if (ProtMode == 1 || ProtMode == 3)
                    //    {
                    //        Console.WriteLine("Custom Data: " + DecryptCustomData(CipherData, ByteConv.ConvertFromUshortArray(Key1), (byte[])IV.Clone()));
                    //    }
                    //    Challenge = DecryptIchallenge(IV, ByteConv.ConvertFromUshortArray(Key1));
                    //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                    //    Array.Resize(ref Challenge, 10);
                    //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                    //}
                    //else
                    //{
                    //    Console.WriteLine("Returned Response: " + ByteFormat.ToHex(Response, "", " "));
                    //}

                    // Embedded tag operations

                    #region EmbeddedTagOperations
                    {
                        //Uncomment this to execute embedded tagop for ReadBuffer with TAM1 using Key0
                        //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, Ichallenge, SendRawData);
                        //Gen2.ReadBuffer embeddedTagOp = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                        //Response = performEmbeddedOperation(null, embeddedTagOp);
                        //if (SendRawData)
                        //{
                        //    Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key0));
                        //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                        //    Array.Resize(ref Challenge, 10);
                        //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        //    Console.WriteLine("Returned Response:" + ByteFormat.ToHex(Response, "", " "));
                        //}

                        //Uncomment this to execute embedded tagop for ReadBuffer with TAM1 using Key1
                        //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, SendRawData);
                        //Gen2.ReadBuffer embeddedTam1RdBufWithKey0 = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                        //Response = performEmbeddedOperation(null, embeddedTam1RdBufWithKey0);
                        //if (SendRawData)
                        //{
                        //    Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key1));
                        //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                        //    Array.Resize(ref Challenge, 10);
                        //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        //    Console.WriteLine("Returned Response:" + ByteFormat.ToHex(Response, "", " "));
                        //}

                        //Uncomment this to execute embedded tagop for ReadBuffer with TAM2 using key1
                        //ushort EmbeddedOffset = 0;
                        //ushort EmbeddedBlockCount = 1;
                        //// supported protMode value is 1 for NXPUCODE AES tag
                        //ushort EmbeddedProtMode = 1;
                        //tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge,
                        //           Gen2.NXP.AES.Profile.EPC, EmbeddedOffset, EmbeddedBlockCount, EmbeddedProtMode, SendRawData);
                        //Gen2.ReadBuffer embeddedTam2RdBufWithKey1 = new Gen2.NXP.AES.ReadBuffer(0, 256, tam2Auth);
                        //Response = performEmbeddedOperation(null, embeddedTam2RdBufWithKey1);
                        //if (SendRawData)
                        //{
                        //    byte[] data = new byte[16];
                        //    Array.Copy(Response, data, 16);
                        //    Challenge = DecryptIchallenge(data, ByteConv.ConvertFromUshortArray(Key1));
                        //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                        //    Array.Resize(ref Challenge, 10);
                        //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        //    Console.WriteLine("Returned Response:" + ByteFormat.ToHex(Response, "", " "));
                        //}
                        //else
                        //{
                        //    Console.WriteLine("Data: " + ByteFormat.ToHex(Response, "", " "));
                        //}
                    }
                    #endregion EmbeddedTagOperations

                    //Enable flag _isNMV2DTag for ReadBuffer with TAM1/TAM2 Authentication using KEY0 for NMV2D Tag
                    if (_isNMV2DTag)
                    {
                        // NMV2D tag only supports KEY0
                        ushort[] Key0_NMV2D = new ushort[] { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 };
                        //Uncomment this to enable ReadBuffer with TAM1 with Key0
                        //tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0_NMV2D, Ichallenge, SendRawData);
                        //// Pass bitCount value as 128 for TAM1
                        //Gen2.ReadBuffer tagOp = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                        //Response = (byte[])r.ExecuteTagOp(tagOp, null);
                        //if (SendRawData)
                        //{
                        //    Challenge = DecryptIchallenge(Response, ByteConv.ConvertFromUshortArray(Key0_NMV2D));
                        //    Array.Copy(Challenge, 6, Challenge, 0, 10);
                        //    Array.Resize(ref Challenge, 10);
                        //    Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        //    Console.WriteLine("Returned Response:" + ByteFormat.ToHex(Response, "", " "));
                        //}

                        //ReadBuffer with TAM2 with key0
                        ushort offset     = 0;
                        ushort blockCount = 1;
                        //supported protMode values are 0,1,2,3
                        ushort protMode = 0;
                        ushort bitCount = 0;
                        tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0_NMV2D, Ichallenge,
                                                                       Gen2.NXP.AES.Profile.EPC, offset, blockCount, protMode, SendRawData);
                        // Pass bitCount value as 256 for protModes = 0, 1 and 352 for protModes = 2, 3 for TAM2
                        if (protMode == 0 || protMode == 1)
                        {
                            bitCount = 256;
                        }
                        else if (protMode == 2 || protMode == 3)
                        {
                            bitCount = 352;
                        }
                        Gen2.ReadBuffer Tam2RdBufWithKey0 = new Gen2.NXP.AES.ReadBuffer(0, bitCount, tam2Auth);
                        Response = (byte[])r.ExecuteTagOp(Tam2RdBufWithKey0, null);
                        if (SendRawData)
                        {
                            byte[] CipherData = new byte[16];
                            byte[] IV         = new byte[16];
                            Array.Copy(Response, IV, 16);
                            Array.Copy(Response, 0, IV, 0, 16);
                            Array.Copy(Response, 16, CipherData, 0, 16);
                            if (protMode == 1 || protMode == 3)
                            {
                                Console.WriteLine("Custom Data: " + DecryptCustomData(CipherData, ByteConv.ConvertFromUshortArray(Key0_NMV2D), (byte[])IV.Clone()));
                            }
                            Challenge = DecryptIchallenge(IV, ByteConv.ConvertFromUshortArray(Key0_NMV2D));
                            Array.Copy(Challenge, 6, Challenge, 0, 10);
                            Array.Resize(ref Challenge, 10);
                            Console.WriteLine("Returned Ichallenge:" + ByteFormat.ToHex(Challenge, "", " "));
                        }
                        else
                        {
                            Console.WriteLine("Returned Response: " + ByteFormat.ToHex(Response, "", " "));
                        }
                    }
                }
            }
            catch (ReaderException re)
            {
                Console.WriteLine("Error: " + re.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Beispiel #26
0
        /// <summary>
        /// Authenticate with key0
        /// </summary>
        private void btnAuthKeyZero_Click(object sender, RoutedEventArgs e)
        {
            //Gen2.NXP.AES.Tam2Authentication tam2Auth;
            Gen2.NXP.AES.Tam1Authentication tam1Auth;
            ushort[] Key0, Ichallenge, returnedIchallenge;
            byte[]   Response, Challenge;
            lblDataValue.Content       = "";
            lblTam2DataValue.Content   = "";
            lblChallenge1Value.Content = "";

            switch (cbxReadDataBank.Text)
            {
            case "TID":
                MemoryProfile = Gen2.NXP.AES.Profile.TID;
                break;

            case "User":
                MemoryProfile = Gen2.NXP.AES.Profile.USER;
                break;

            case "EPC":
                MemoryProfile = Gen2.NXP.AES.Profile.EPC;
                break;
            }

            if (txtbxVerifyKeyZero.Text.Length == 32)
            {
                byte[] KeytoWrite = ByteFormat.FromHex(txtbxVerifyKeyZero.Text);
                Key0 = new ushort[KeytoWrite.Length / 2];
                Key0 = ByteConv.ToU16s(KeytoWrite);
            }
            else
            {
                MessageBox.Show("Please input valid Key0", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            byte[] randmNumber = ByteFormat.FromHex(lblRandomChallengeValue.Content.ToString().Replace(" ", ""));
            Ichallenge = new ushort[randmNumber.Length / 2];
            Ichallenge = ByteConv.ToU16s(randmNumber);
            try
            {
                if ((bool)chkReadData.IsChecked && (bool)chkReadBuffer.IsChecked)
                {
                    //ReadBuffer with Tam2
                    MessageBox.Show("Operation is not supported", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == false)
                {
                    //Authentication with tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key0)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    returnedIchallenge         = new ushort[Challenge.Length / 2];
                    returnedIchallenge         = ByteConv.ToU16s(Challenge);
                    byte[] generatedIChallenge = new byte[10];
                    byte[] tempBuffer          = new byte[16];
                    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                    Array.Copy(Response, 10, tempBuffer, 0, 16);
                    byte[] receivedIChallenge = DecryptIchallenge(tempBuffer, ByteConv.ConvertFromUshortArray(Key0).ToArray());
                    Array.Copy(receivedIChallenge, 6, receivedIChallenge, 0, 10);
                    Array.Resize(ref receivedIChallenge, 10);
                    if (generatedIChallenge.SequenceEqual(receivedIChallenge))
                    {
                        MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == true)
                {
                    //Read Buffer with Tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, true);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key0)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    lblDataValue.Content       = "";
                    byte[] generatedIChallenge = new byte[10];
                    byte[] tempBuffer          = new byte[16];
                    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                    Array.Copy(Response, 10, tempBuffer, 0, 16);
                    byte[] receivedIChallenge = DecryptIchallenge(tempBuffer, ByteConv.ConvertFromUshortArray(Key0));
                    Array.Copy(receivedIChallenge, 6, receivedIChallenge, 0, 10);
                    Array.Resize(ref receivedIChallenge, 10);
                    if (generatedIChallenge.SequenceEqual(receivedIChallenge))
                    {
                        MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    //Authenticate with tam2
                    MessageBox.Show("Operation is not supported", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
Beispiel #27
0
        /// <summary>
        /// Populate access password of the tag
        /// </summary>
        private void PopulateUntraceableData()
        {
            try
            {
                Mouse.SetCursor(Cursors.Wait);
                spUntraceableFields.IsEnabled = true;
                ResetUntraceableActionCheckBoxes();
                if ((bool)rbFirstTagUntraceableTb.IsChecked)
                {
                    antenna = GetSelectedAntennaList()[0];
                }

                objReader.ParamSet("/reader/tagop/antenna", antenna);


                if ((bool)rbSelectedTagUntraceableTb.IsChecked)
                {
                    if (lblSelectFilter.Content.ToString().Contains("EPC ID"))
                    {
                        searchSelect = new TagData(currentEPC);
                    }
                    else
                    {
                        int    dataLength       = 0;
                        byte[] SearchSelectData = ByteFormat.FromHex(txtData.Text);
                        if (null != SearchSelectData)
                        {
                            dataLength = SearchSelectData.Length;
                        }

                        searchSelect = new Gen2.Select(false, selectMemBank, Convert.ToUInt16(accessPwddStartAddress * 16), Convert.ToUInt16(dataLength * 8), SearchSelectData);
                    }
                }
                else
                {
                    searchSelect = new TagData(currentEPC);
                }

                //Read Reserved memory bank data
                TagOp    op;
                ushort[] reservedData = null;
                txtbxAccesspaasword.Text = "";
                try
                {
                    string reservedBankData = string.Empty;
                    //Read access password
                    op           = new Gen2.ReadData(Gen2.Bank.RESERVED, 2, 2);
                    reservedData = (ushort[])objReader.ExecuteTagOp(op, searchSelect);

                    if (null != reservedData)
                    {
                        reservedBankData = ByteFormat.ToHex(ByteConv.ConvertFromUshortArray(reservedData), "", " ");
                    }

                    txtbxAccesspaasword.Text = reservedBankData.Trim(' ');
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }