Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="expected"></param>
        /// <param name="actual"></param>
        /// <returns></returns>
        private bool VerifyHash(byte[] expected, byte[] actual)
        {
            bool verified = FirmwareUpgrade.CompareMD5Hash(expected, actual);

            Log.Debug(string.Format("VerifyHash: expected=\"{0}\"", FirmwareUpgrade.MD5HashToString(expected)));
            Log.Debug(string.Format("VerifyHash: actual  =\"{0}\"", FirmwareUpgrade.MD5HashToString(actual)));
            Log.Debug(string.Format("VerifyHash: {0}", verified ? "PASSED" : "FAILED"));

            return(verified);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Download firmware zip file from iNet server.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <returns>
        /// true if call to iNet succeeds, and it returns us new firmware.
        ///
        /// false if call to iNet succeeds, but iNet purposely doesn't give us back any firmware.
        ///
        /// Throws an exception if we fail to download firmware due to download errors, etc.
        /// </returns>
        private bool DownloadFirmware()
        {
            string funcMsg = Name + ".DownloadFirmware: ";

            Log.Debug(string.Format("{0}Attempting to download firmware; the maximum number of tries is {1}", funcMsg, MAX_ATTEMPTS));

            string msg = string.Empty;

            for (int attempt = 1; attempt <= MAX_ATTEMPTS; attempt++)
            {
                Log.Debug(string.Format("{0}attempt {1} of {2}", funcMsg, attempt, MAX_ATTEMPTS));

                Master.Instance.ConsoleService.UpdateAction(ConsoleServiceResources.DOWNLOADING);

                //We don't need to consider SubType for DSX as of now, since the Firmware varies only for instrument's Subtype.
                string equipmentType = Configuration.DockingStation.Type.ToString();

                using (InetDownloader inetDownloader = new InetDownloader())
                {
                    FirmwareUpgrade = inetDownloader.DownloadFirmwareUpgrade(null, _firmwareUpgradeEvent.Errors, EquipmentTypeCode.VDS, equipmentType, null, equipmentType);
                }

                if (FirmwareUpgrade == null)
                {
                    Log.Debug(string.Format("{0}Nothing returned by iNet.", funcMsg));
                    return(false);
                }

                if (FirmwareUpgrade.Firmware == null)
                {
                    Log.Debug(string.Format("{0}No firmware returned by iNet.", funcMsg));
                    return(false);
                }

                Log.Debug(string.Format("{0}Firmware DeviceType: {1}.", funcMsg, FirmwareUpgrade.EquipmentCode));
                Log.Debug(string.Format("{0}Firmware Version: {1}.", funcMsg, FirmwareUpgrade.Version));
                Log.Debug(string.Format("{0}Firmware Size: {1} bytes.", funcMsg, FirmwareUpgrade.Firmware.Length));
                Log.Debug(string.Format("{0}Firmware iNet checksum: \"{1}\".", funcMsg, FirmwareUpgrade.MD5HashToString(FirmwareUpgrade.MD5Hash)));

                if (FirmwareUpgrade.EquipmentCode != Configuration.DockingStation.Type.ToString())
                {
                    msg = string.Format("Downloaded firmware is for wrong device type (\"{0}\").  Expected \"{1}\" ", FirmwareUpgrade.EquipmentCode, Configuration.DockingStation.Type.ToString());
                    Log.Error(msg);
                    throw new FirmwareUpgradeException(msg);
                }

                Master.Instance.ConsoleService.UpdateAction(ConsoleServiceResources.VERIFYING);

                byte[] hash = new MD5CryptoServiceProvider().ComputeHash(FirmwareUpgrade.Firmware);

                bool verified = VerifyHash(FirmwareUpgrade.MD5Hash, hash);

                if (verified)
                {
                    Log.Debug(string.Format("{0}Firmware successfully downloaded.", funcMsg));
                    return(true);
                }

                Log.Debug(string.Format("{0}Verification of MD5 hash failed.", funcMsg));
            }

            msg = string.Format("{0}Unable to download firwmare after {1} attempts.", funcMsg, MAX_ATTEMPTS);
            Log.Error(msg);
            throw new FirmwareUpgradeException(msg);
        }