public MFUsbConfigDialog( MFDevice device )
        {
            m_cfgHelper = new MFConfigHelper(device);
            m_cfg = new MFUsbConfiguration(device);

            InitializeComponent();
        }
示例#2
0
        public void Save()
        {
            Random      rand   = new Random();
            double      d      = rand.NextDouble();
            MFKeyConfig keyCfg = new MFKeyConfig();
            KeyPair     keys   = keyCfg.CreateKeyPair();

            MFConfigHelper cfgHelper = new MFConfigHelper(m_dev);

            m_cfg.Enabled = 1;
            m_cfg.Seed    = (UInt64)((double)UInt64.MaxValue * d);

            unsafe
            {
                fixed(byte *key = m_cfg.PrivateSslKey.SectorKey)
                {
                    for (int i = 0; i < keys.PrivateKey.Length && i < MFKeyConfig.PrivateKeySize; i++)
                    {
                        key[i++] = keys.PrivateKey[i];
                    }
                }
            }

            cfgHelper.WriteConfig(c_CfgName, m_cfg, true);

            cfgHelper.Dispose();
        }
示例#3
0
        public void Save()
        {
            Random      rand    = new Random();
            double      d       = rand.NextDouble();
            MFKeyConfig keyCfg  = new MFKeyConfig();
            KeyPair     keys    = keyCfg.CreateKeyPair();

            MFConfigHelper cfgHelper = new MFConfigHelper(m_dev);

            m_cfg.Enabled = 1;
            m_cfg.Seed = (UInt64)((double)UInt64.MaxValue * d);

            unsafe
            {
                fixed (byte* key = m_cfg.PrivateSslKey.SectorKey)
                {
                    for (int i = 0; i < keys.PrivateKey.Length && i < MFKeyConfig.PrivateKeySize; i++)
                    {
                        key[i++] = keys.PrivateKey[i];
                    }
                }
            }

            cfgHelper.WriteConfig(c_CfgName, m_cfg, true);

            cfgHelper.Dispose();
        }
示例#4
0
        public MFNetworkConfigDialog(MFDevice device)
        {
            m_cfg = new MFNetworkConfiguration(device);
            m_cfgHelper = new MFConfigHelper(device);
            m_wirelessCfg = new MFWirelessConfiguration(device);

            InitializeComponent();
        }
        public void Load()
        {
            byte[] data = m_cfgHelper.FindConfig(c_CfgName);

            if (data != null)
            {
                m_cfg = (HAL_WirelessConfiguration)MFConfigHelper.UnmarshalData(data, typeof(HAL_WirelessConfiguration));
            }
        }
示例#6
0
        public void Load()
        {
            byte[] data = m_cfgHelper.FindConfig(c_CfgName);

            if (data != null)
            {
                m_cfg = (HAL_NetworkConfigurationExtended)MFConfigHelper.UnmarshalData(data, typeof(HAL_NetworkConfigurationExtended));
            }
        }
        public void Load()
        {
            byte[] data = m_cfgHelper.FindConfig(c_name);

            if (data != null)
            {
                m_cfg = (USB_CONFIG)MFConfigHelper.UnmarshalData(data, typeof(USB_CONFIG));
            }
        }
示例#8
0
        public MFAppDeployConfigDialog(MFDevice device, ConfigDialogCommand command)
        {
            if (device != null)
            {
                m_cfgHelper = new MFConfigHelper(device);
                m_appDeploy = new MFApplicationDeployment(device);
            }
            m_command = command;
            m_device = device;

            InitializeComponent();
        }
示例#9
0
        public MFNetworkConfigurationExtended(MFDevice dev)
        {
            /* load default settings, in case extended settinsg are not available */
            m_cfg.flags                 = c_SOCK_NETWORKCONFIGURATION_FLAGS_IPV4_SUPPORTED; // default setting for backwards compatibility
            this.IPv6IpAddress          = new IPAddress(new byte[16]);
            this.IPv6Gateway            = new IPAddress(new byte[16]);
            this.IPv6SubnetPrefixLength = 0;
            this.IPv6PrimaryDns         = new IPAddress(new byte[16]);
            this.IPv6SecondaryDns       = new IPAddress(new byte[16]);

            m_cfgHelper = new MFConfigHelper(dev);
        }
示例#10
0
        public void UpdateDeviceKey(MFDevice device, PublicKeyUpdateInfo.KeyIndex index, byte[] publicKey, byte[] publicKeySignature)
        {
            MFConfigHelper cfg = new MFConfigHelper(device);

            PublicKeyUpdateInfo pku = new PublicKeyUpdateInfo();

            pku.NewPublicKey          = publicKey;
            pku.NewPublicKeySignature = publicKeySignature;
            pku.PublicKeyIndex        = index;

            cfg.UpdatePublicKey(pku);

            cfg.Dispose();
            cfg = null;
        }
示例#11
0
        internal void SwapAllConfigData(MFConfigHelper srcConfigHelper)
        {
            byte[] newAllConfigData = srcConfigHelper.m_all_cfg_data;

            if (newAllConfigData == null)
            {
                throw new ArgumentNullException();
            }

            if (m_all_cfg_data != null)
            {
                if (m_all_cfg_data.Length != newAllConfigData.Length)
                {
                    throw new ArgumentException("Invalid swap target");
                }
            }

            m_all_cfg_data = newAllConfigData;
        }
示例#12
0
 public void SwapConfigBuffer(MFConfigHelper srcConfig)
 {
     m_cfgHelper.SwapAllConfigData(srcConfig);
 }
示例#13
0
        public MFNetworkConfiguration(MFDevice dev)
        {
            m_cfg.networkInterfaceType = c_SOCK_NETWORKCONFIGURATION_INTERFACETYPE_ETHERNET;

            m_cfgHelper = new MFConfigHelper(dev);
        }
        public MFNetworkConfiguration(MFDevice dev)
        {
            m_cfg.networkInterfaceType = c_SOCK_NETWORKCONFIGURATION_INTERFACETYPE_ETHERNET;

            m_cfgHelper = new MFConfigHelper(dev);
        }
示例#15
0
 private Guid GetDeviceId(MFDevice device)
 {
     var result = Guid.Empty;
     try
     {
         var config = new MFConfigHelper(device);
         if (!config.IsValidConfig)
             throw new Exception("Invalid config");
         if (config.IsFirmwareKeyLocked)
             throw new Exception("Firmware locked");
         if (config.IsDeploymentKeyLocked)
             throw new Exception("Deployment locked");
         var data = config.FindConfig("S4NID");
         if (data.Length>16)
         {
             var temp = new byte[16];
             Array.Copy(data, data.Length - 16, temp, 0, 16);
             data = temp;
         }
         if (data==null)
         {
             result = Guid.Empty;
         }
         else
         {
             result = new Guid(data);
         }
     }
     catch
     {
         result = Guid.Empty;
     }
     return result;
 }
 public MFWirelessConfiguration(MFDevice dev)
 {
     m_cfgHelper = new MFConfigHelper(dev);
 }
示例#17
0
        public MFNetworkConfigurationExtended(MFDevice dev)
        {
            /* load default settings, in case extended settinsg are not available */
            m_cfg.flags = c_SOCK_NETWORKCONFIGURATION_FLAGS_IPV4_SUPPORTED; // default setting for backwards compatibility
            this.IPv6IpAddress = new IPAddress(new byte[16]);
            this.IPv6Gateway = new IPAddress(new byte[16]);
            this.IPv6SubnetPrefixLength = 0;
            this.IPv6PrimaryDns = new IPAddress(new byte[16]);
            this.IPv6SecondaryDns = new IPAddress(new byte[16]);

            m_cfgHelper = new MFConfigHelper(dev);
        }
示例#18
0
 public MFUsbConfiguration(MFDevice dev)
 {
     m_cfgHelper = new MFConfigHelper(dev);
 }
示例#19
0
 private void WriteConfiguration(byte[] cfg)
 {
     var config = new MFConfigHelper(_device);
     if (!config.IsValidConfig)
         throw new Exception("Invalid config");
     if (config.IsFirmwareKeyLocked)
         throw new Exception("Firmware locked");
     if (config.IsDeploymentKeyLocked)
         throw new Exception("Deployment locked");
     config.WriteConfig("S4NCFG", cfg);
 }
示例#20
0
 private void SetDeviceId(Guid id)
 {
     var buffer = id.ToByteArray();
     var config = new MFConfigHelper(_device);
     config.WriteConfig("S4NID", buffer);
 }
 public MFUsbConfiguration(MFDevice dev)
 {
     m_cfgHelper = new MFConfigHelper(dev);
 }
示例#22
0
        public void UpdateDeviceKey(MFDevice device, PublicKeyUpdateInfo.KeyIndex index, byte[] publicKey, byte[] publicKeySignature)
        {
            MFConfigHelper cfg = new MFConfigHelper(device);

            PublicKeyUpdateInfo pku = new PublicKeyUpdateInfo();
            pku.NewPublicKey          = publicKey;
            pku.NewPublicKeySignature = publicKeySignature;
            pku.PublicKeyIndex        = index;

            cfg.UpdatePublicKey(pku);

            cfg.Dispose();
            cfg = null;
        }
示例#23
0
 public MFWirelessConfiguration(MFDevice dev)
 {
     m_cfgHelper = new MFConfigHelper(dev);
 }
        internal void SwapAllConfigData(MFConfigHelper srcConfigHelper)
        {
            byte[] newAllConfigData = srcConfigHelper.m_all_cfg_data;

            if (newAllConfigData == null)
                throw new ArgumentNullException();

            if (m_all_cfg_data != null)
            {
                if (m_all_cfg_data.Length != newAllConfigData.Length)
                    throw new ArgumentException("Invalid swap target");
            }

            m_all_cfg_data = newAllConfigData;
        }
 public void SwapConfigBuffer(MFConfigHelper srcConfig)
 {
     m_cfgHelper.SwapAllConfigData(srcConfig);
 }
示例#26
0
        private byte[] ReadConfiguration()
        {
            byte[] result = null;
            try
            {
                var config = new MFConfigHelper(_device);
                if (!config.IsValidConfig)
                    throw new Exception("Invalid config");
                if (config.IsFirmwareKeyLocked)
                    throw new Exception("Firmware locked");
                if (config.IsDeploymentKeyLocked)
                    throw new Exception("Deployment locked");

                var data = config.FindConfig("S4NCFG");
                //if (data.Length > 16)
                //{
                //    var temp = new byte[16];
                //    Array.Copy(data, data.Length - 16, temp, 0, 16);
                //    data = temp;
                //}
                if (data == null)
                {
                    result = null;
                }
                else
                {
                    //BUG: FindConfig returns a lot of garbage at the beginning of the config block
                    result = data; //TODO: copy only the config bytes
                }
            }
            catch
            {
                result = null;
            }
            return result;
        }
示例#27
0
        private void OnMenuItem_Click(System.Object sender, System.EventArgs e)
        {
            ToolStripMenuItem mi = sender as ToolStripMenuItem;
            Form dlg = null;

            if( mi == null ) return;

            MFDevice device = null;
            MFConfigHelper cfgHelper = null;

            Cursor old = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                if (mi != signDeploymentFileToolStripMenuItem1)
                {
                    device = ConnectToSelectedDevice();

                    if (device == null)
                    {
                        MessageBox.Show(this, string.Format(Properties.Resources.ErrorDeviceNotResponding, comboBoxDevice.Text), Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    cfgHelper = new MFConfigHelper(device);

                    if (!cfgHelper.IsValidConfig)
                    {
                        MessageBox.Show(this, Properties.Resources.ErrorUnsupportedConfiguration, Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }

                if (mi == signDeploymentFileToolStripMenuItem1)
                {
                    dlg = new MFAppDeployConfigDialog(MFAppDeployConfigDialog.ConfigDialogCommand.SignDeployment);
                }
                else if (mi == updateDeviceKeysToolStripMenuItem)
                {
                    dlg = new MFAppDeployConfigDialog(device, MFAppDeployConfigDialog.ConfigDialogCommand.Configure);
                }
                else if (mi == createApplicationDeploymentToolStripMenuItem1)
                {
                    dlg = new MFAppDeployConfigDialog(device, MFAppDeployConfigDialog.ConfigDialogCommand.CreateDeployment);
                }
                else if (mi == uSBToolStripMenuItem)
                {
                    dlg = new MFUsbConfigDialog(device);
                }
                else if (mi == networkToolStripMenuItem)
                {
                    dlg = new MFNetworkConfigDialog(device);
                }

                if (dlg != null)
                {
                    dlg.StartPosition = FormStartPosition.CenterParent;
                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        if (dlg is MFUsbConfigDialog)
                        {
                            cfgHelper.Dispose();
                            cfgHelper = null;
                            while (!DisconnectFromSelectedDevice()) ;
                            Thread.Sleep(500); // wait for device to reset
                            OnDeviceListUpdate(null, null);
                        }
                    }
                }

                else if (mi == uSBConfigurationToolStripMenuItem)
                {
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Title = "Load USB Config File";
                    ofd.DefaultExt = "*.xml";
                    ofd.Filter = "USB Config File (*.xml)|*.xml";
                    ofd.CheckFileExists = true;
                    ofd.Multiselect = false;

                    cfgHelper.MaintainConnection = true;

                    if (DialogResult.OK == ofd.ShowDialog())
                    {
                        UsbXMLConfigSet xmlConfig = new UsbXMLConfigSet(ofd.FileName);
                        byte[] nativeConfig = xmlConfig.Read();
                        if (nativeConfig != null)
                        {
                            ofd.DefaultExt = "*.txt";
                            ofd.CheckFileExists = false;
                            ofd.CheckPathExists = true;
                            ofd.FileName = "USB Hex dump.txt";
                            ofd.Title = "Dump file for native config data";
                            if (DialogResult.OK == ofd.ShowDialog())
                            {
                                FileStream dumpFile;
                                try
                                {
                                    dumpFile = File.Create(ofd.FileName);
                                }
                                catch (Exception e2)
                                {
                                    MessageBox.Show("Text dump file could not be opened due to exception: " + e2.Message);
                                    return;
                                }

                                // Dump byte array to text file for review
                                byte[] buffer = new byte[16 * 3 + 2];
                                int blockSize = 0;
                                int bufIndex = 0;
                                for (int index = 0; index < nativeConfig.Length; index += blockSize)
                                {
                                    blockSize = nativeConfig.Length - index;
                                    if (blockSize > 16)
                                    {
                                        blockSize = 16;
                                    }
                                    bufIndex = 0;
                                    for (int i = 0; i < blockSize; i++)
                                    {
                                        byte c;

                                        c = (byte)((nativeConfig[index + i] >> 4) & 0x0F);
                                        c += (byte)'0';       // Convert to ASCII
                                        if (c > '9')
                                        {
                                            c += (byte)('A' - '9' - 1);
                                        }
                                        buffer[bufIndex++] = c;
                                        c = (byte)(nativeConfig[index + i] & 0x0F);
                                        c += (byte)'0';       // Convert to ASCII
                                        if (c > '9')
                                        {
                                            c += (byte)('A' - '9' - 1);
                                        }
                                        buffer[bufIndex++] = c;
                                        buffer[bufIndex++] = (byte)' ';
                                    }
                                    buffer[bufIndex++] = (byte)'\r';
                                    buffer[bufIndex++] = (byte)'\n';
                                    dumpFile.Write(buffer, 0, bufIndex);
                                }
                                dumpFile.Close();
                                MessageBox.Show("Written " + nativeConfig.Length.ToString() + " configuration bytes to '" + ofd.FileName + "'.");
                            }

                            try
                            {
                                if (!cfgHelper.IsValidConfig)
                                {
                                    MessageBox.Show(null, Properties.Resources.ErrorUnsupportedConfiguration, Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                // NOTE:
                                // This assumes there is only one USB controller:  controller 0.  In the future, if
                                // support is needed for multiple USB controllers, the user must be allowed to select
                                // which controller the XML configuration is for.  Then, the correct configuration
                                // name needs to be used for the selected controller.  "USB1" is used for controller 0,
                                // "USB2" is used for controller 1, etc.
                                cfgHelper.WriteConfig("USB1", nativeConfig);
                            }
                            catch (Exception ex2)
                            {
                                MessageBox.Show(null, string.Format(Properties.Resources.ErrorX, ex2.Message), Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, string.Format(Properties.Resources.ErrorX, ex.Message), Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                Cursor.Current = old;

                if (cfgHelper != null)
                {
                    cfgHelper.Dispose();
                }

                DisconnectFromSelectedDevice();

                if (dlg != null)
                {
                    dlg.Dispose();
                }
            }
        }