Beispiel #1
0
        private void AssignIPAddressToNetDeviceService(NetworkDeviceService netDeviceService, ISystemRegistryHive systemRegistryHive, string ipAddress, string subnetMask, string defaultGateway)
        {
            string netCfgInstanceID = netDeviceService.NetCfgInstanceID;

            string adapterKeyName   = @"Parameters\Adapters\" + netCfgInstanceID;
            string adapterIPConfig  = @"Tcpip\Parameters\Interfaces\" + netCfgInstanceID;
            string interfaceKeyName = @"Parameters\Interfaces\" + netCfgInstanceID;

            // this is some kind of reference to where the actual TCP/IP configuration is located
            systemRegistryHive.SetServiceRegistryKey("Tcpip", adapterKeyName, "IpConfig", RegistryValueKind.MultiString, new string[] { adapterIPConfig });

            // DefaultGateway is not necessary for most people, but can ease the installation for people with complex networks
            systemRegistryHive.SetServiceRegistryKey("Tcpip", interfaceKeyName, "DefaultGateway", RegistryValueKind.MultiString, new string[] { defaultGateway });
            // Extracurricular note: it's possible to use more than one IP address, but you have to specify subnet mask for it as well.
            systemRegistryHive.SetServiceRegistryKey("Tcpip", interfaceKeyName, "IPAddress", RegistryValueKind.MultiString, new string[] { ipAddress });
            systemRegistryHive.SetServiceRegistryKey("Tcpip", interfaceKeyName, "SubnetMask", RegistryValueKind.MultiString, new string[] { subnetMask });

            // Note related to GUI mode:
            // We already bind the device class instance to NetCfgInstanceID, and that's all that's necessary for TCP/IP to work during text-mode.
            // However, TCP/IP must be bound to NetCfgInstanceID as well, TCP/IP will work in GUI mode without it, but setup will fail at T-39
            // with the following error: "setup was unable to initialize Network installation components. the specific error code is 2"
            // and in the subsequent screen: "LoadLibrary returned error 1114 (45a)" (related to netman.dll, netshell.dll)

            // The first component in one entry corresponds to the first component in the other entries:
            systemRegistryHive.SetServiceRegistryKey("Tcpip", "Linkage", "Bind", RegistryValueKind.MultiString, new string[] { @"\DEVICE\" + netCfgInstanceID });
            systemRegistryHive.SetServiceRegistryKey("Tcpip", "Linkage", "Export", RegistryValueKind.MultiString, new string[] { @"\DEVICE\TCPIP_" + netCfgInstanceID });
            // NetCfgInstanceID should be quoted, HiveSystemInf should take care of the use of quote characters (special character):
            systemRegistryHive.SetServiceRegistryKey("Tcpip", "Linkage", "Route", RegistryValueKind.MultiString, new string[] { QuotedStringUtils.Quote(netCfgInstanceID) });
        }
Beispiel #2
0
        private void AssignIPAddressToNetDeviceService(NetworkDeviceService netDeviceService, bool staticIP)
        {
            string ipAddress;
            string subnetMask;
            string defaultGateway;

            if (staticIP)
            {
                Console.WriteLine("Please select TCP/IP settings for '" + netDeviceService.DeviceDescription + "':");
                Console.WriteLine("* Pressing Enter will default to 192.168.1.50 / 255.255.255.0 / 192.168.1.1");
                ipAddress      = ReadValidIPv4Address("IP Address", "192.168.1.50");
                subnetMask     = ReadValidIPv4Address("Subnet Mask", "255.255.255.0");
                defaultGateway = ReadValidIPv4Address("Default Gateway", "192.168.1.1");
            }
            else
            {
                ipAddress      = "0.0.0.0";
                subnetMask     = "0.0.0.0";
                defaultGateway = String.Empty;
            }

            AssignIPAddressToNetDeviceService(netDeviceService, m_installation.SetupRegistryHive, ipAddress, subnetMask, defaultGateway);
            AssignIPAddressToNetDeviceService(netDeviceService, m_installation.HiveSystemInf, ipAddress, subnetMask, defaultGateway);
        }
        public void RegisterPhysicalDevice(PNPDriverINFFile pnpDriverInf)
        {
            if (m_preconfigure && pnpDriverInf.IsNetworkAdapter && (m_useLocalHardwareConfig || m_enumExportPath != String.Empty))
            {
                string deviceID;
                string deviceInstanceID;

                if (m_useLocalHardwareConfig)
                {
                    deviceInstanceID = PNPLocalHardwareDetector.DetectLocalDeviceInstanceID(this.HardwareID, out deviceID);
                    if (deviceInstanceID == String.Empty)
                    {
                        Console.WriteLine("Warning: Could not detect matching device installed locally, configuration will not be applied!");
                    }
                }
                else // m_enumExportPath != String.Empty
                {
                    deviceInstanceID = PNPExportedHardwareDetector.DetectExportedDeviceInstanceID(m_enumExportPath, this.HardwareID, out deviceID);
                    if (deviceInstanceID == String.Empty)
                    {
                        Console.WriteLine("Warning: Could not detect matching device in the exported registry, configuration will not be applied!");
                    }
                }

                if (deviceInstanceID != String.Empty)
                {
                    // m_netDeviceServices is now populated
                    if (this.NetworkDeviceServices.Count > 0)
                    {
                        // unlike other types of hardware (SCSI controllers etc.), it's not enough to add a NIC to the
                        // Criticla Device Database (CDDB) to make it usable during boot, as mentioned in the comments above RegisterNicAsCriticalDevice()
                        // at the very least, a CDDB entry and a "Device" registry value under Enum\Enumerator\DeviceID\DeviceInstanceID is required
                        // (as well as DeviceDesc if not automatically added by the kernel-PNP)
                        // here we manually register the hardware in advance, but it's better to use NICBootConf to do this during boot,
                        // NICBootConf will also work if the NIC has been moved to another PCI slot since creating the installation media.

                        // the first item in m_netDeviceServices should be the actual NIC (CHECKME: what about NIC / bus driver combination like nVIdia)
                        NetworkDeviceService deviceService = this.NetworkDeviceServices[0];
                        string enumerator = PNPDriverIntegratorUtils.GetEnumeratorNameFromHardwareID(this.HardwareID);
                        PreconfigureDeviceInstance(pnpDriverInf, enumerator, deviceID, deviceInstanceID, deviceService);
                    }
                    else
                    {
                        Console.WriteLine("Warning: failed to install '{0}', because the service for this network adapter has not been registered!", this.HardwareID);
                    }
                }
            }
            else
            {
                // if it's a NIC, We assume the user will integrate NICBootConf, which will configure the network adapter during boot.
                // we'll just add the device to the Criticla Device Database (CDDB), and let kernel-PNP and NICBootConf do the rest.
                if (pnpDriverInf.IsNetworkAdapter)
                {
                    // NICBootConf needs the ClassGUID in place for each DeviceInstance Key,
                    // if we put the ClassGUID in the CDDB, the ClassGUID will be applied to each DeviceInstance with matching hardwareID
                    m_installation.TextSetupInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName, PNPDriverINFFile.NetworkAdapterClassGUID);
                    m_installation.HiveSystemInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName, PNPDriverINFFile.NetworkAdapterClassGUID);
                }
                else
                {
                    m_installation.TextSetupInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName);
                    m_installation.HiveSystemInf.AddDeviceToCriticalDeviceDatabase(this.HardwareID, this.DeviceServices[0].ServiceName);
                }
            }
        }
Beispiel #4
0
        private void ProcessServiceInstallSection(PNPDriverINFFile pnpDriverInf, string sectionName, string serviceName)
        {
            Console.WriteLine("Registering service '" + serviceName + "'");
            List <string> serviceInstallSection = pnpDriverInf.GetSection(sectionName);

            string displayName        = String.Empty;
            string serviceBinary      = String.Empty;
            string serviceTypeString  = String.Empty;
            string errorControlString = String.Empty;
            string loadOrderGroup     = String.Empty;

            //string guiModeRelativeRoot = @"Services\" + serviceName;
            foreach (string line in serviceInstallSection)
            {
                KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line);
                switch (keyAndValues.Key)
                {
                case "AddReg":
                    // http://msdn.microsoft.com/en-us/library/ff546326%28v=vs.85%29.aspx
                    // AddReg will always come after ServiceBinaryServiceBinary

                    string relativeRoot = @"Services\" + serviceName;

                    foreach (string registrySectionName in keyAndValues.Value)
                    {
                        ProcessAddRegSection(pnpDriverInf, registrySectionName, relativeRoot);
                    }
                    break;

                case "DisplayName":
                    displayName = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                case "ServiceBinary":
                    serviceBinary = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                case "ServiceType":
                    serviceTypeString = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                case "ErrorControl":
                    errorControlString = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                case "LoadOrderGroup":
                    loadOrderGroup = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;

                default:
                    break;
                }
            }

            displayName = pnpDriverInf.ExpandToken(displayName);
            displayName = INIFile.Unquote(displayName);

            string fileName  = serviceBinary.Replace(@"%12%\", String.Empty);
            string imagePath = pnpDriverInf.ExpandDirID(serviceBinary);

            int serviceType  = PNPDriverINFFile.ConvertFromIntStringOrHexString(serviceTypeString);
            int errorControl = PNPDriverINFFile.ConvertFromIntStringOrHexString(errorControlString);

            string deviceDescription = pnpDriverInf.GetDeviceDescription(m_hardwareID, m_architectureIdentifier, m_minorOSVersion, m_productType);

            DeviceService deviceService;

            if (pnpDriverInf.IsNetworkAdapter)
            {
                // this is a nic, we are binding TCP/IP to it
                // we need a unique NetCfgInstanceID that will be used with Tcpip service and the nic's class
                string netCfgInstanceID = "{" + Guid.NewGuid().ToString().ToUpper() + "}";
                deviceService = new NetworkDeviceService(deviceDescription, serviceName, displayName, loadOrderGroup, serviceType, errorControl, fileName, imagePath, netCfgInstanceID);
                m_deviceServices.Add(deviceService);
            }
            else
            {
                deviceService = new DeviceService(deviceDescription, serviceName, displayName, loadOrderGroup, serviceType, errorControl, fileName, imagePath);
                m_deviceServices.Add(deviceService);
            }
        }