Example #1
0
        private void readMac()
        {
            byte[] macBytes = new byte[6];
            int    macLen   = 6;
            bool   _result  = true;

            try
            {
                macLoc = MACADD_Location.NV4678;
                if (macLoc == MACADD_Location.AP_PERSIST)
                {
                    macBytes = phone.FTM_WLAN_GEN6_GET_MAC_ADDRESS();
                }

                // Read WLAN MAC address in NV 4678
                else if (macLoc == MACADD_Location.NV4678)
                {
                    phone.NVRead(nv_items_enum_type.NV_WLAN_MAC_ADDRESS_I, macBytes, 128);
                }
            }
            catch (Exception ex)
            {
                _result = false;
                throw new Exception(ex.ToString());
            }
            if (_result)
            {
                ConvertByteArrayToHexString(macBytes, macLen, out mac);
            }
        }
Example #2
0
        private void WriteMac(string NewMac)
        {
            byte[] macBytes = new byte[6];
            byte[] mac      = new byte[6];
            try
            {
                macBytes = ConvertStringToByteArray(NewMac, NewMac.Length);
                macLoc   = MACADD_Location.NV4678;
                if (macLoc == MACADD_Location.AP_PERSIST)
                {
                    int j = 11;
                    for (int i = 0; i < mac.Length; i++)
                    {
                        mac[i]  = (byte)(macBytes[j] << 4);
                        mac[i] += (byte)(macBytes[j - 1]);

                        j -= 2;
                    }

                    phone.FTM_WLAN_GEN6_SET_MAC_ADDRESS(mac);
                }
                else if (macLoc == MACADD_Location.NV4678)
                {
                    int j = 0;
                    for (int i = 0; i < mac.Length; i++)
                    {
                        mac[i]  = (byte)(macBytes[j + 1] << 4);
                        mac[i] += (byte)macBytes[j];

                        j += 2;
                    }

                    phone.NVWrite(nv_items_enum_type.NV_WLAN_MAC_ADDRESS_I, mac, 128);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
Example #3
0
        /// <summary>
        /// Writes WLAN MAC Address to either NV or to APQ space using FTM commands
        /// </summary>
        /// <returns></returns>
        public bool WriteMAC_ADV()
        {
            byte[] macBytes = new byte[6];
            byte[] mac = new byte[6];
            bool macExists = false;

            if (!phone.IsPhoneConnected())
            {
                DebugMessage.Write("Error", "Phone not connected", System.Diagnostics.TraceLevel.Verbose);
                return false;
            }

            MACIn = MACIn.ToUpper();

            // Read to see if MAC already written
            ReadMAC_ADV();

            if (MAC != "000000000000")
                macExists = true;

            if (MAC == MACIn)
            {
                DebugMessage.Write("Debug", "WLAN MAC already exists", System.Diagnostics.TraceLevel.Verbose);
                DebugMessage.Write("Debug", "and matches desired value.  Skipping write.", System.Diagnostics.TraceLevel.Verbose);
                return true;
            }

            if (macExists && writeOnce)
            {
                DebugMessage.Write("Debug", "WLAN MAC already exists", System.Diagnostics.TraceLevel.Error);
                DebugMessage.Write("Debug", "and does NOT match desired value.", System.Diagnostics.TraceLevel.Error);
                return false;
            }

            if (!writeOnce)
            {
                macBytes = util.ConvertStringToByteArray(MACIn, MACIn.Length);

                // example of how writes should look
                //nv_write_item 4678 0 0x38 0x02 0x13 0x2B 0x24 0x00   ["00242B130238"]



                if (!phone.IsPhoneConnected())
                {
                    DebugMessage.Write("Error", "Phone not connected", System.Diagnostics.TraceLevel.Verbose);
                    return false;
                }

                try
                {
                    macLoc = MACADD_Location.NV4678;
                    // Write WLAN MAC address in persist partition
                    if (macLoc == MACADD_Location.AP_PERSIST)
                    {
                        int j = 11;
                        for (int i = 0; i < mac.Length; i++)
                        {
                            //                            mac[i] = (byte)(macBytes[j - 1] << 4);
                            //                            mac[i] += (byte)macBytes[j];
                            mac[i] = (byte)(macBytes[j] << 4);
                            mac[i] += (byte)(macBytes[j - 1]);

                            j -= 2;
                        }

                        phone.FTM_WLAN_GEN6_SET_MAC_ADDRESS(mac);
                    }
                    // Write WLAN MAC address in NV 4678
                    else if (macLoc == MACADD_Location.NV4678)
                    {
                        int j = 0;
                        for (int i = 0; i < mac.Length; i++)
                        {
                            mac[i] = (byte)(macBytes[j + 1] << 4);
                            mac[i] += (byte)macBytes[j];

                            j += 2;
                        }

                        phone.NVWrite(nv_items_enum_type.NV_WLAN_MAC_ADDRESS_I, mac, 128);
                    }
                    else
                    {
                        DebugMessage.Write("Error", "Please select WLAN MAC address location(Persist or NV) first!", System.Diagnostics.TraceLevel.Verbose);
                    }
                }
                catch (Exception ex)
                {
                    DebugMessage.Write("Error", ex.Message, System.Diagnostics.TraceLevel.Verbose);
                    MAC = "";
                    return false;
                }

                if (validate)
                {
                    // if failed to read NV, return
                    if (!ReadMAC_ADV())
                        return false;

                    if (MAC != MACIn)
                    {
                        DebugMessage.Write("Error", "Desired WLAN MAC to be written does not match what is in the phone", System.Diagnostics.TraceLevel.Error);
                        return false;
                    }
                }
                else
                    MAC = MACIn;


            }

            return true;

        }
Example #4
0
        /// <summary>
        /// Reads WLAN MAC Address from APQ file location using FTM commands
        /// </summary>
        /// <returns></returns>
        public bool ReadMAC_ADV()
        {
            bool _result = true;
            byte[] macBytes = new byte[6];
            byte[] macSwappedBytes = new byte[6];
            string[] macString = new string[6];
            // MAC is 48 bits long (6 bytes)
            int macLen = 6;
            string temp = "";

            if (!phone.IsPhoneConnected())
            {
                DebugMessage.Write("Error", "Phone not connected", System.Diagnostics.TraceLevel.Verbose);
                return false;
            }

            try
            {
                macLoc = MACADD_Location.NV4678;
                if (macLoc == MACADD_Location.AP_PERSIST)
                {
                    macBytes = phone.FTM_WLAN_GEN6_GET_MAC_ADDRESS();
                }

                // Read WLAN MAC address in NV 4678
                else if (macLoc == MACADD_Location.NV4678)
                {
                    phone.NVRead(nv_items_enum_type.NV_WLAN_MAC_ADDRESS_I, macBytes, 128);
                }
                else
                {
                    DebugMessage.Write("Error", "Please select WLAN MAC address location(Persist or NV) first!", System.Diagnostics.TraceLevel.Verbose);
                }
            }
            catch (Exception ex)
            {
                DebugMessage.Write("Error", ex.Message, System.Diagnostics.TraceLevel.Verbose);
                _result = false;
            }

            if (_result)
            {

                // clear old MAC out
                MAC = "";

                // convert byte array to string so can fill in out param and save
                util.ConvertByteArrayToHexString(macBytes, macLen, out temp);
            }
            else
            {
                DebugMessage.Write("Error", "Failed to read WLAN MAC ", System.Diagnostics.TraceLevel.Verbose);
            }

            MAC = temp.ToUpper();

            return _result;

        }
Example #5
0
        /// <summary>
        /// Writes WLAN MAC Address to either NV or to APQ space using FTM commands
        /// </summary>
        /// <returns></returns>
        public bool WriteMAC_ADV()
        {
            byte[] macBytes = new byte[6];
            byte[] mac = new byte[6];
            byte[] tmp = new byte[2];
            bool macExists = false;
            string addr;
            util = new Utilities();
            writeOnce = false;
            validate = false;
            Random ro = new Random();
            IniFiles fop = new IniFiles("Settings.ini");
            if (!phone.IsPhoneConnected())
            {
                this.SetText("Phone not connected");
                return false;
            }
            MACIn = fop.ReadString("TEST", "WLANADDR", "");
            MACIn = MACIn.ToUpper();

            // Read to see if MAC already written
            ReadMAC_ADV();
            string temp = "";
            if (MAC != "000000000000")
            {
                //temp= ReverseA(MAC);
                macExists = true;
            }

            if (MAC == MACIn)
            {
                this.SetText("WLAN MAC already exists");
                this.SetText("and matches desired value.  Skipping write.");
                return true;
            }

            if (macExists && writeOnce)
            {
                this.SetText("WLAN MAC already exists");
                this.SetText("and does NOT match desired value.");
                return false;
            }

            if (!writeOnce)
            {
                tmp = util.ConvertStringToByteArray(MACIn, MACIn.Length);
                macBytes[0] = (byte)((tmp[0] & 0x0f) << 4);
                macBytes[0] += (byte)(tmp[1] & 0x0f);
                for (int i = 1; i < macBytes.Length; i++)
                {
                    macBytes[i] = (byte)ro.Next(0, 255);
                }
                /*MAC MUST NOT THE SAME*/
                // example of how writes should look
                //nv_write_item 4678 0 0x38 0x02 0x13 0x2B 0x24 0x00   ["00242B130238"]
                if (!phone.IsPhoneConnected())
                {
                    this.SetText("Phone not connected");
                    return false;
                }

                try
                {
                    macLoc = MACADD_Location.NV4678;
                    // Write WLAN MAC address in persist partition
                    if (macLoc == MACADD_Location.AP_PERSIST)
                    {
                        phone.FTM_WLAN_GEN6_SET_MAC_ADDRESS(macBytes);
                    }
                    // Write WLAN MAC address in NV 4678
                    else if (macLoc == MACADD_Location.NV4678)
                    {
                        util.ConvertByteArrayToHexString(macBytes, macBytes.Length, out addr);
                        this.SetText("Write WIFI MAC address :" + addr + "to glass...");
                        phone.NVWrite(nv_items_enum_type.NV_WLAN_MAC_ADDRESS_I, macBytes, 128);
                    }
                    else
                    {
                        this.SetText("Please select WLAN MAC address location(Persist or NV) first!");
                    }
                }
                catch (Exception ex)
                {
                    this.SetText(ex.Message);
                    MAC = "";
                    return false;
                }

                if (validate)
                {
                    // if failed to read NV, return
                    if (!ReadMAC_ADV())
                        return false;

                    temp = ReverseA(MAC);
                    if (temp != MACIn)
                    {
                        this.SetText("Desired WLAN MAC to be written does not match what is in the phone");
                        return false;
                    }
                }
                else
                {
                    //temp = MACIn;
                    this.SetText("Write WIFI MAC address successfully...");
                }
            }
            return true;

        }