Exemplo n.º 1
0
        /// <summary>
        /// Writes Blue tooth Address from APQ space using HCI commands
        /// </summary>
        /// <param name="BDADD_location"></param>                   // APQ location ot write BT Address
        /// <param name="Retry_Count_For_HCI_RESET_CMD"></param>    // # retries allowed
        /// <returns></returns>

        public bool WriteBDA_ADV()
        {
            byte[] bdaBytes = new byte[6];
            byte[] addrtemp = new byte[2];
            string addr;
            bool bdaExists = false;
            util = new Utilities();
            writeOnce = false;
            validate = false;
            Random ro = new Random();
            IniFiles fop = new IniFiles("Settings.ini");

            if (!phone.IsPhoneConnected())
            {
                DebugMessage.Write("Error", "Phone not connected", System.Diagnostics.TraceLevel.Verbose);
                return false;
            }
            /*MAC ADRESS HEADER*/
            BDAIn = fop.ReadString("TEST", "BTADDR", "");
            BDAIn = BDAIn.ToUpper();

            ReadBDA_ADV(BDADD_Location.QCN_NV447, 3);

            if (BDA != "000000000000")
                bdaExists = true;

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

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

            if (!writeOnce)
            {
                addrtemp = util.ConvertStringToByteArray(BDAIn, BDAIn.Length);
                bdaBytes[5] = (byte)((addrtemp[0] & 0x0f) << 4);
                bdaBytes[5] += (byte)(addrtemp[1] & 0x0f);
                /*generate random num for mac addr*/
                for (int i = 0; i < bdaBytes.Length - 1; i++)
                { 
                    bdaBytes[i] = (byte)ro.Next(0, 255);                
                }
                /*MAC ADRESS MUST NOT THE SAME*/
                // example of how writes should look
                //nv_write_item 447 0 0x38 0x02 0x13 0x2B 0x24 0x00   ["00242B130238"]

                if (!phone.IsPhoneConnected())
                {
                    this.SetText("Phone not connected");
                    return false;
                }

                try
                {
                    util.ConvertByteArrayToHexString(bdaBytes, bdaBytes.Length, out addr);
                    this.SetText("set bluetooth mac:" + addr + "to glass......");
                    phone.NVWrite(nv_items_enum_type.NV_BD_ADDR_I, bdaBytes, 128);
                }
                catch (Exception ex)
                {
                    this.SetText(ex.Message);
                    BDA = "";
                    return false;
                }
                this.SetText("Bluetooth addr write success!");
            }
            return true;
        }
Exemplo n.º 2
0
 public QWMACForm()
 {
     InitializeComponent();
     util = new Utilities();
 }
Exemplo n.º 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];
            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;

        }