private void AuthenticationCB_DrawItem(object sender, DrawItemEventArgs e) { // If the index is invalid then simply exit. if (e.Index == -1 || e.Index >= AuthenticationCB.Items.Count) { return; } // Draw the background of the item. e.DrawBackground(); // Should we draw the focus rectangle? if ((e.State & DrawItemState.Focus) != 0) { e.DrawFocusRectangle(); } Font f = new Font(e.Font, FontStyle.Regular); // Create a new background brush. Brush b = new SolidBrush(e.ForeColor); // Draw the item. GXAuthentication authentication = (GXAuthentication)AuthenticationCB.Items[e.Index]; if (authentication == null) { return; } string name = authentication.Type.ToString(); SizeF s = e.Graphics.MeasureString(name, f); e.Graphics.DrawString(name, f, b, e.Bounds); }
public AuthenticationForm(GXAuthentication target) { InitializeComponent(); Target = target; this.Text = Target.Type.ToString() + " authentication settings"; this.SecretTB.Text = GXCommon.ToHex(target.SharedSecret, true); }
public AuthenticationGmacForm(GXAuthentication target) { InitializeComponent(); SecurityCB.Items.AddRange(new object[] { Security.None, Security.Authentication, Security.Encryption, Security.AuthenticationEncryption }); Target = target; this.Text = Target.Type.ToString() + " authentication settings"; this.SecurityCB.SelectedItem = target.Security; this.SystemTitleTB.Text = GXCommon.ToHex(target.SystemTitle, true); this.BlockCipherKeyTB.Text = GXCommon.ToHex(target.BlockCipherKey, true); this.AuthenticationKeyTB.Text = GXCommon.ToHex(target.AuthenticationKey, true); }
void RefreshAuthentication(GXAuthentication authentication) { if (authentication.ClientID != null) { ClientAddTypeCB.SelectedItem = authentication.ClientID.GetType(); ClientAddTB.Value = Convert.ToDecimal(authentication.ClientID); } else { ClientAddTypeCB.SelectedItem = typeof(byte); } }
private void OKBtn_Click(object sender, EventArgs e) { try { if (NameTB.Text.Length == 0) { throw new Exception("Invalid manufacturer name."); } if (ManufacturerIdTB.Text.Length != 3) { throw new Exception("Invalid manufacturer identification."); } if (ManufacturerIdTB.Enabled && Manufacturers.FindByIdentification(ManufacturerIdTB.Text) != null) { throw new Exception("Manufacturer identification already exists."); } if (!SerialNumberFormulaTB.ReadOnly && SerialNumberFormulaTB.Text.Length == 0) { throw new Exception("Invalid Serial Number."); } Manufacturer.Name = NameTB.Text; Manufacturer.Identification = ManufacturerIdTB.Text; Manufacturer.UseLogicalNameReferencing = UseLNCB.Checked; Manufacturer.UseIEC47 = UseIEC47CB.Checked; Manufacturer.StartProtocol = (StartProtocolType)StartProtocolCB.SelectedItem; Manufacturer.Standard = (Standard)StandardCb.SelectedItem; GXAuthentication authentication = Manufacturer.GetActiveAuthentication(); authentication.ClientAddress = Convert.ToInt32(this.ClientAddTB.Value); //Save server values. UpdateServer((GXServerAddress)ServerAddressTypeCB.SelectedItem); Manufacturer.WebAddress = WebAddressTB.Text; if (!string.IsNullOrEmpty(InfoTB.Text)) { Manufacturer.Info = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(InfoTB.Text)); } else { Manufacturer.Info = null; } Manufacturer.Security = (Security)SecurityCB.SelectedItem; Manufacturer.SystemTitle = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(SystemTitleTB.Text, SystemTitleAsciiCb.Checked)); Manufacturer.BlockCipherKey = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(BlockCipherKeyTB.Text, BlockCipherKeyAsciiCb.Checked)); Manufacturer.AuthenticationKey = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(AuthenticationKeyTB.Text, AuthenticationKeyAsciiCb.Checked)); } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); this.DialogResult = DialogResult.None; } }
private void AuthenticationCB_SelectedIndexChanged(object sender, EventArgs e) { try { GXAuthentication authentication = (GXAuthentication)AuthenticationCB.SelectedItem; PasswordTB.Enabled = authentication.Type != Authentication.None; this.ClientAddTB.Value = authentication.ClientAddress; } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); } }
private void AuthenticationCB_SelectedIndexChanged(object sender, EventArgs e) { try { GXAuthentication authentication = (GXAuthentication)AuthenticationCB.SelectedItem; PasswordTB.Enabled = authentication.Type != Authentication.None && authentication.Type != Authentication.HighGMAC && authentication.Type != Authentication.HighECDSA; this.ClientAddTB.Value = authentication.ClientAddress; } catch (Exception Ex) { MessageBox.Show(this, Ex.Message, Properties.Resources.CTT, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OKBtn_Click(object sender, EventArgs e) { try { if (NameTB.Text.Length == 0) { throw new Exception("Invalid manufacturer name."); } if (ManufacturerIdTB.Text.Length != 3) { throw new Exception("Invalid manufacturer identification."); } if (ManufacturerIdTB.Enabled && Manufacturers.FindByIdentification(ManufacturerIdTB.Text) != null) { throw new Exception("Manufacturer identification already exists."); } if (!SerialNumberFormulaTB.ReadOnly && SerialNumberFormulaTB.Text.Length == 0) { throw new Exception("Invalid Serial Number."); } Manufacturer.Name = NameTB.Text; Manufacturer.Identification = ManufacturerIdTB.Text; Manufacturer.UseLogicalNameReferencing = UseLNCB.Checked; Manufacturer.UseIEC47 = UseIEC47CB.Checked; Manufacturer.StartProtocol = (StartProtocolType)StartProtocolCB.SelectedItem; Manufacturer.InactivityMode = (InactivityMode)InactivityModeCB.SelectedItem; Manufacturer.ForceInactivity = ForceKeepAliveCB.Checked; GXAuthentication authentication = Manufacturer.GetActiveAuthentication(); Manufacturer.KeepAliveInterval = Convert.ToInt32(KeepAliveIntervalTB.Value) * 1000; authentication.ClientAddress = Convert.ToInt32(this.ClientAddTB.Value); //Save server values. UpdateServer((GXServerAddress)ServerAddressTypeCB.SelectedItem); Manufacturer.WebAddress = WebAddressTB.Text; if (!string.IsNullOrEmpty(InfoTB.Text)) { Manufacturer.Info = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(InfoTB.Text)); } else { Manufacturer.Info = null; } } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); this.DialogResult = DialogResult.None; } }
private void AuthenticationCB_SelectedIndexChanged(object sender, EventArgs e) { try { GXAuthentication authentication = Manufacturer.GetActiveAuthentication(); authentication.Selected = false; //Save old values. authentication.ClientAddress = Convert.ToInt32(this.ClientAddTB.Value); authentication = ((GXAuthentication)AuthenticationCB.SelectedItem); authentication.Selected = true; ClientAddTB.Value = authentication.ClientAddress; } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); } }
public void UpdateManufactureSettings(string id) { if (Manufacturer.Identification == "LGZ") //TW { Manufacturer.UseIEC47 = true; Manufacturer.UseLogicalNameReferencing = true; } if (Manufacturer != null && string.Compare(Manufacturer.Identification, id, true) != 0) { throw new Exception(string.Format("Manufacturer type does not match. Manufacturer is {0} and it should be {1}.", id, Manufacturer.Identification)); } Client.InterfaceType = InterfaceType.General; Client.UseLogicalNameReferencing = Manufacturer.UseLogicalNameReferencing; //If network media is used check is manufacturer supporting IEC 62056-47 GXServerAddress server = Manufacturer.GetServer(HDLCAddressing); if (this.Media is GXNet && Manufacturer.UseIEC47) { Client.InterfaceType = InterfaceType.Net; Client.ClientID = Convert.ToUInt16(Manufacturer.GetAuthentication(Client.Authentication).ClientID); //Client.ServerID = Convert.ToUInt16(server.PhysicalAddress); Client.ServerID = 1; } else { if (HDLCAddressing == HDLCAddressType.Custom) { Client.ClientID = Manufacturer.GetAuthentication(Client.Authentication).ClientID; } else { GXAuthentication auth = Manufacturer.GetAuthentication(Client.Authentication); if (auth == null) { Client.ClientID = (byte)41; } else { Client.ClientID = (byte)(Convert.ToByte(auth.ClientID) << 1 | 0x1); } } Client.ServerID = GXManufacturer.CountServerAddress(HDLCAddressing, server.Formula, server.PhysicalAddress, server.LogicalAddress); } }
/// <summary> /// SHow advanced authentication settings. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AdvancedBtn_Click(object sender, EventArgs e) { GXAuthentication authentication = Manufacturer.GetActiveAuthentication(); if (authentication.Type == Gurux.DLMS.Authentication.HighGMAC) { AuthenticationGmacForm dlg = new AuthenticationGmacForm(authentication); dlg.ShowDialog(this); } else if (authentication.Type > Gurux.DLMS.Authentication.Low) { AuthenticationForm dlg = new AuthenticationForm(authentication); dlg.ShowDialog(this); } else { throw new ArgumentOutOfRangeException("Invalid authentication type."); } }
private void AuthenticationCB_SelectedIndexChanged(object sender, EventArgs e) { try { GXAuthentication authentication = Manufacturer.GetActiveAuthentication(); authentication.Selected = false; //Save old values. UpdateAuthentication(authentication); authentication = ((GXAuthentication)AuthenticationCB.SelectedItem); AdvancedBtn.Enabled = authentication.Type == Gurux.DLMS.Authentication.High || authentication.Type == Gurux.DLMS.Authentication.HighSHA1 || authentication.Type == Gurux.DLMS.Authentication.HighGMAC; authentication.Selected = true; this.RefreshAuthentication(authentication); } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); } }
void UpdateAuthentication(GXAuthentication authentication) { object value = Convert.ChangeType(this.ClientAddTB.Value, (Type)this.ClientAddTypeCB.SelectedItem); authentication.ClientID = value; }
private void OKBtn_Click(object sender, EventArgs e) { try { //Check security settings. if ((Security)SecurityCB.SelectedItem != Security.None || ((GXAuthentication)AuthenticationCB.SelectedItem).Type == Authentication.HighGMAC) { if (SystemTitleTB.Text.Trim().Length == 0) { throw new ArgumentException("Invalid system title."); } if (AuthenticationKeyTB.Text.Trim().Length == 0) { throw new ArgumentException("Invalid authentication key."); } if (BlockCipherKeyTB.Text.Trim().Length == 0) { throw new ArgumentException("Invalid block cipher key."); } } GXServerAddress server = (GXServerAddress)ServerAddressTypeCB.SelectedItem; if (server.HDLCAddress == HDLCAddressType.SerialNumber && PhysicalServerAddressTB.Value == 0) { throw new Exception("Invalid Serial Number."); } GXManufacturer man = (GXManufacturer)ManufacturerCB.SelectedItem; Target.client.Authentication = ((GXAuthentication)this.AuthenticationCB.SelectedItem).Type; if (Target.client.Authentication != Authentication.None) { if (PasswordAsciiCb.Checked) { Target.client.Password = ASCIIEncoding.ASCII.GetBytes(PasswordTB.Text); } else { Target.client.Password = GXDLMSTranslator.HexToBytes(this.PasswordTB.Text); } } else { Target.client.Password = null; } Target.media = SelectedMedia; if (SelectedMedia is GXSerial) { if (this.SerialPortCB.Text.Length == 0) { throw new Exception("Invalid serial port."); } ((GXSerial)SelectedMedia).PortName = this.SerialPortCB.Text; } else if (SelectedMedia is GXNet) { if (this.HostNameTB.Text.Length == 0) { throw new Exception("Invalid host name."); } ((GXNet)SelectedMedia).HostName = this.HostNameTB.Text; int port; if (!Int32.TryParse(this.PortTB.Text, out port)) { throw new Exception("Invalid port number."); } ((GXNet)SelectedMedia).Port = port; ((GXNet)SelectedMedia).Protocol = (NetworkType)NetProtocolCB.SelectedItem; } Properties.Settings.Default.Media = SelectedMedia.MediaType; Properties.Settings.Default.MediaSettings = SelectedMedia.Settings; Properties.Settings.Default.SelectedManufacturer = man.Identification; Properties.Settings.Default.WaitTime = Convert.ToInt32(WaitTimeTB.Value); Target.WaitTime = Properties.Settings.Default.WaitTime * 1000; GXAuthentication authentication = (GXAuthentication)AuthenticationCB.SelectedItem; HDLCAddressType HDLCAddressing = ((GXServerAddress)ServerAddressTypeCB.SelectedItem).HDLCAddress; Properties.Settings.Default.HDLCAddressing = (int)HDLCAddressing; Properties.Settings.Default.ClientAddress = Target.client.ClientAddress = Convert.ToInt32(ClientAddTB.Value); if (HDLCAddressing == HDLCAddressType.SerialNumber) { int address = Convert.ToInt32(PhysicalServerAddressTB.Value); Properties.Settings.Default.PhysicalServerAddress = address; Target.client.ServerAddress = GXDLMSClient.GetServerAddress(address); } else if (HDLCAddressing == HDLCAddressType.Default) { Properties.Settings.Default.PhysicalServerAddress = Convert.ToInt32(PhysicalServerAddressTB.Value); Properties.Settings.Default.LogicalServerAddress = Convert.ToInt32(LogicalServerAddressTB.Value); Target.client.ServerAddress = GXDLMSClient.GetServerAddress(Properties.Settings.Default.LogicalServerAddress, Properties.Settings.Default.PhysicalServerAddress); } Target.client.UseLogicalNameReferencing = this.UseLNCB.Checked; Target.iec = (StartProtocolType)this.StartProtocolCB.SelectedItem == StartProtocolType.IEC; Target.client.Ciphering.Security = (Security)SecurityCB.SelectedItem; Target.client.Ciphering.SystemTitle = GetAsHex(SystemTitleTB.Text, SystemTitleAsciiCb.Checked); Target.client.Ciphering.BlockCipherKey = GetAsHex(BlockCipherKeyTB.Text, BlockCipherKeyAsciiCb.Checked); Target.client.Ciphering.AuthenticationKey = GetAsHex(AuthenticationKeyTB.Text, AuthenticationKeyAsciiCb.Checked); Target.client.Ciphering.InvocationCounter = UInt32.Parse(InvocationCounterTB.Text); Target.client.CtoSChallenge = GXCommon.HexToBytes(ChallengeTB.Text); if (man.UseIEC47) { Target.client.InterfaceType = InterfaceType.WRAPPER; } UpdateConformance(); Properties.Settings.Default.Save(); } catch (Exception Ex) { this.DialogResult = DialogResult.None; MessageBox.Show(this, Ex.Message, Properties.Resources.CTT, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OKBtn_Click(object sender, EventArgs e) { try { if (NameTB.Text.Length == 0) { throw new Exception("Invalid manufacturer name."); } if (ManufacturerIdTB.Text.Length != 3) { throw new Exception("Invalid manufacturer identification."); } if (ManufacturerIdTB.Enabled && Manufacturers.FindByIdentification(ManufacturerIdTB.Text) != null) { throw new Exception("Manufacturer identification already exists."); } if (!SerialNumberFormulaTB.ReadOnly && SerialNumberFormulaTB.Text.Length == 0) { throw new Exception("Invalid Serial Number."); } Manufacturer.Name = NameTB.Text; Manufacturer.Identification = ManufacturerIdTB.Text; Manufacturer.UseLogicalNameReferencing = UseLNCB.Checked; Manufacturer.Standard = (Standard)StandardCb.SelectedItem; Manufacturer.UtcTimeZone = UseUtcTimeZone.Checked; GXAuthentication authentication = Manufacturer.GetActiveAuthentication(); authentication.ClientAddress = Convert.ToInt32(this.ClientAddTB.Value); //Save server values. UpdateServer((GXServerAddress)ServerAddressTypeCB.SelectedItem); Manufacturer.WebAddress = WebAddressTB.Text; if (!string.IsNullOrEmpty(InfoTB.Text)) { Manufacturer.Info = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(InfoTB.Text)); } else { Manufacturer.Info = null; } Manufacturer.Security = (Security)SecurityCB.SelectedItem; Manufacturer.SystemTitle = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(SystemTitleTB.Text, SystemTitleAsciiCb.Checked)); Manufacturer.BlockCipherKey = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(BlockCipherKeyTB.Text, BlockCipherKeyAsciiCb.Checked)); Manufacturer.AuthenticationKey = GXCommon.HexToBytes(DevicePropertiesForm.GetAsHex(AuthenticationKeyTB.Text, AuthenticationKeyAsciiCb.Checked)); Manufacturer.SupporterdInterfaces = 0; if (HdlcCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.HDLC; } if (HdlcWithModeECb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.HdlcWithModeE; } if (WrapperCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.WRAPPER; } if (WirelessMBusCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.WirelessMBus; } if (PlcCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.Plc; } if (PlcHdlcCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.PlcHdlc; } if (LpWanCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.LPWAN; } if (WiSunCb.Checked) { Manufacturer.SupporterdInterfaces |= 1 << (int)InterfaceType.WiSUN; } if (Manufacturer.SupporterdInterfaces == 0) { throw new Exception("Supporterd interfaces are not selected."); } } catch (Exception Ex) { GXDLMS.Common.Error.ShowError(this, Ex); this.DialogResult = DialogResult.None; } }
public ManufacturerForm(GXManufacturerCollection manufacturers, GXManufacturer manufacturer) { InitializeComponent(); foreach (object it in Enum.GetValues(typeof(Standard))) { StandardCb.Items.Add(it); } StandardCb.SelectedItem = manufacturer.Standard; SecurityCB.Items.AddRange(new object[] { Security.None, Security.Authentication, Security.Encryption, Security.AuthenticationEncryption }); Manufacturers = manufacturers; Manufacturer = manufacturer; if (manufacturer.Settings.Count == 0) { manufacturer.Settings.Add(new GXAuthentication(Authentication.None, (byte)0x10)); manufacturer.Settings.Add(new GXAuthentication(Authentication.Low, (byte)0x11)); manufacturer.Settings.Add(new GXAuthentication(Authentication.High, (byte)0x12)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighMD5, (byte)0x13)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA1, (byte)0x14)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighGMAC, (byte)0x14)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA256, (byte)0x14)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighECDSA, (byte)0x14)); GXAuthentication gmac = new GXAuthentication(Authentication.HighGMAC, (byte)0x15); } GXAuthentication authentication = manufacturer.GetActiveAuthentication(); foreach (GXAuthentication it in manufacturer.Settings) { AuthenticationCB.Items.Add(it); } AuthenticationCB.SelectedItem = authentication; this.AuthenticationCB.SelectedIndexChanged += new System.EventHandler(this.AuthenticationCB_SelectedIndexChanged); if (manufacturer.ServerSettings.Count == 0) { manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Default, (byte)1, true)); manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.SerialNumber, (byte)1, false)); manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Custom, (byte)1, false)); } foreach (GXServerAddress it in manufacturer.ServerSettings) { ServerAddressTypeCB.Items.Add(it); } GXServerAddress server = manufacturer.GetActiveServer(); ServerAddressTypeCB.SelectedItem = server; RefreshServer(server); this.ServerAddressTypeCB.SelectedIndexChanged += new System.EventHandler(this.ServerAddressTypeCB_SelectedIndexChanged); ServerAddressTypeCB.DrawMode = AuthenticationCB.DrawMode = DrawMode.OwnerDrawFixed; ClientAddTB.Value = authentication.ClientAddress; StartProtocolCB.Items.Add(StartProtocolType.IEC); StartProtocolCB.Items.Add(StartProtocolType.DLMS); NameTB.Text = manufacturer.Name; ManufacturerIdTB.Text = manufacturer.Identification; UseLNCB.Checked = manufacturer.UseLogicalNameReferencing; UseIEC47CB.Checked = manufacturer.UseIEC47; StartProtocolCB.SelectedItem = manufacturer.StartProtocol; //Manufacturer ID can not change after creation. ManufacturerIdTB.Enabled = string.IsNullOrEmpty(manufacturer.Identification); WebAddressTB.Text = Manufacturer.WebAddress; if (!string.IsNullOrEmpty(Manufacturer.Info)) { try { InfoTB.Text = ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(Manufacturer.Info)); } catch (Exception) { InfoTB.Text = ""; } } SecurityCB.SelectedItem = manufacturer.Security; if (DevicePropertiesForm.IsAscii(manufacturer.SystemTitle)) { SystemTitleAsciiCb.Checked = true; SystemTitleTB.Text = ASCIIEncoding.ASCII.GetString((manufacturer.SystemTitle)); } else { SystemTitleTB.Text = GXCommon.ToHex(manufacturer.SystemTitle, true); } if (DevicePropertiesForm.IsAscii(manufacturer.BlockCipherKey)) { BlockCipherKeyAsciiCb.Checked = true; BlockCipherKeyTB.Text = ASCIIEncoding.ASCII.GetString(manufacturer.BlockCipherKey); } else { BlockCipherKeyTB.Text = GXCommon.ToHex(manufacturer.BlockCipherKey, true); } if (DevicePropertiesForm.IsAscii(manufacturer.AuthenticationKey)) { AuthenticationKeyAsciiCb.Checked = true; AuthenticationKeyTB.Text = ASCIIEncoding.ASCII.GetString(manufacturer.AuthenticationKey); } else { AuthenticationKeyTB.Text = GXCommon.ToHex(manufacturer.AuthenticationKey, true); } }
public ManufacturerForm(GXManufacturerCollection manufacturers, GXManufacturer manufacturer) { InitializeComponent(); #if !GURUX_LPWAN LpWanCb.Visible = WiSunCb.Visible = false; #endif //GURUX_LPWAN foreach (object it in Enum.GetValues(typeof(Standard))) { StandardCb.Items.Add(it); } StandardCb.SelectedItem = manufacturer.Standard; SecurityCB.Items.AddRange(new object[] { Security.None, Security.Authentication, Security.Encryption, Security.AuthenticationEncryption }); Manufacturers = manufacturers; Manufacturer = manufacturer; if (manufacturer.Settings.Count == 0) { manufacturer.Settings.Add(new GXAuthentication(Authentication.None, (byte)0x10)); manufacturer.Settings.Add(new GXAuthentication(Authentication.Low, (byte)0x11)); manufacturer.Settings.Add(new GXAuthentication(Authentication.High, (byte)0x12)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighMD5, (byte)0x13)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA1, (byte)0x14)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighGMAC, (byte)0x14)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA256, (byte)0x14)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighECDSA, (byte)0x14)); GXAuthentication gmac = new GXAuthentication(Authentication.HighGMAC, (byte)0x15); } GXAuthentication authentication = manufacturer.GetActiveAuthentication(); foreach (GXAuthentication it in manufacturer.Settings) { AuthenticationCB.Items.Add(it); } AuthenticationCB.SelectedItem = authentication; this.AuthenticationCB.SelectedIndexChanged += new System.EventHandler(this.AuthenticationCB_SelectedIndexChanged); if (manufacturer.ServerSettings.Count == 0) { manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Default, (byte)1, true)); manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.SerialNumber, (byte)1, false)); manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Custom, (byte)1, false)); } foreach (GXServerAddress it in manufacturer.ServerSettings) { ServerAddressTypeCB.Items.Add(it); } GXServerAddress server = manufacturer.GetActiveServer(); ServerAddressTypeCB.SelectedItem = server; RefreshServer(server); this.ServerAddressTypeCB.SelectedIndexChanged += new System.EventHandler(this.ServerAddressTypeCB_SelectedIndexChanged); ServerAddressTypeCB.DrawMode = AuthenticationCB.DrawMode = DrawMode.OwnerDrawFixed; ClientAddTB.Value = authentication.ClientAddress; NameTB.Text = manufacturer.Name; ManufacturerIdTB.Text = manufacturer.Identification; UseLNCB.Checked = manufacturer.UseLogicalNameReferencing; //Manufacturer ID can not change after creation. ManufacturerIdTB.Enabled = string.IsNullOrEmpty(manufacturer.Identification); WebAddressTB.Text = Manufacturer.WebAddress; if (!string.IsNullOrEmpty(Manufacturer.Info)) { try { InfoTB.Text = ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(Manufacturer.Info)); } catch (Exception) { InfoTB.Text = ""; } } SecurityCB.SelectedItem = manufacturer.Security; if (DevicePropertiesForm.IsAscii(manufacturer.SystemTitle)) { SystemTitleAsciiCb.Checked = true; SystemTitleTB.Text = ASCIIEncoding.ASCII.GetString((manufacturer.SystemTitle)); } else { SystemTitleTB.Text = GXCommon.ToHex(manufacturer.SystemTitle, true); } if (DevicePropertiesForm.IsAscii(manufacturer.BlockCipherKey)) { BlockCipherKeyAsciiCb.Checked = true; BlockCipherKeyTB.Text = ASCIIEncoding.ASCII.GetString(manufacturer.BlockCipherKey); } else { BlockCipherKeyTB.Text = GXCommon.ToHex(manufacturer.BlockCipherKey, true); } if (DevicePropertiesForm.IsAscii(manufacturer.AuthenticationKey)) { AuthenticationKeyAsciiCb.Checked = true; AuthenticationKeyTB.Text = ASCIIEncoding.ASCII.GetString(manufacturer.AuthenticationKey); } else { AuthenticationKeyTB.Text = GXCommon.ToHex(manufacturer.AuthenticationKey, true); } UseUtcTimeZone.Checked = manufacturer.UtcTimeZone; if (manufacturer.SupporterdInterfaces != 0) { HdlcCb.Checked = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.HDLC)) != 0; HdlcWithModeECb.Checked = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.HdlcWithModeE)) != 0; WrapperCb.Checked = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.WRAPPER)) != 0; WirelessMBusCb.Checked = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.WirelessMBus)) != 0; PlcCb.Checked = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.Plc)) != 0; PlcHdlcCb.Checked = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.PlcHdlc)) != 0; LpWanCb.Checked = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.LPWAN)) != 0; WiSunCb.Checked = (manufacturer.SupporterdInterfaces & (1 << (int)InterfaceType.WiSUN)) != 0; } else { //Select default interfaces. HdlcCb.Checked = HdlcWithModeECb.Checked = WrapperCb.Checked = true; } }
public ManufacturerForm(GXManufacturerCollection manufacturers, GXManufacturer manufacturer) { InitializeComponent(); Manufacturers = manufacturers; Manufacturer = manufacturer; if (manufacturer.Settings.Count == 0) { manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.None, (byte)0x10)); manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.Low, (byte)0x11)); manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.High, (byte)0x12)); manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.HighMD5, (byte)0x13)); manufacturer.Settings.Add(new GXAuthentication(Gurux.DLMS.Authentication.HighSHA1, (byte)0x14)); GXAuthentication gmac = new GXAuthentication(Gurux.DLMS.Authentication.HighGMAC, (byte)0x15); gmac.BlockCipherKey = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; gmac.AuthenticationKey = new byte[] { 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF }; manufacturer.Settings.Add(gmac); } GXAuthentication authentication = manufacturer.GetActiveAuthentication(); foreach (GXAuthentication it in manufacturer.Settings) { AuthenticationCB.Items.Add(it); } AuthenticationCB.SelectedItem = authentication; if (authentication.Type == Gurux.DLMS.Authentication.High || authentication.Type == Gurux.DLMS.Authentication.HighSHA1 || authentication.Type == Gurux.DLMS.Authentication.HighGMAC) { AdvancedBtn.Enabled = true; } this.AuthenticationCB.SelectedIndexChanged += new System.EventHandler(this.AuthenticationCB_SelectedIndexChanged); if (manufacturer.ServerSettings.Count == 0) { manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Default, (byte)1, true)); manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.SerialNumber, (byte)1, false)); manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Custom, (byte)1, false)); } foreach (GXServerAddress it in manufacturer.ServerSettings) { ServerAddressTypeCB.Items.Add(it); } ServerAddTypeCB.Items.Add(typeof(byte)); ServerAddTypeCB.Items.Add(typeof(ushort)); ServerAddTypeCB.Items.Add(typeof(uint)); GXServerAddress server = manufacturer.GetActiveServer(); ServerAddressTypeCB.SelectedItem = server; RefreshServer(server); this.ServerAddressTypeCB.SelectedIndexChanged += new System.EventHandler(this.ServerAddressTypeCB_SelectedIndexChanged); ServerAddressTypeCB.DrawMode = AuthenticationCB.DrawMode = ClientAddTypeCB.DrawMode = ServerAddTypeCB.DrawMode = DrawMode.OwnerDrawFixed; ClientAddTypeCB.Items.Add(typeof(byte)); ClientAddTypeCB.Items.Add(typeof(ushort)); ClientAddTypeCB.Items.Add(typeof(uint)); if (authentication.ClientID != null) { ClientAddTB.Value = Convert.ToDecimal(authentication.ClientID); ClientAddTypeCB.SelectedItem = authentication.ClientID.GetType(); } RefreshAuthentication(authentication); InactivityModeCB.Items.Add(InactivityMode.None); InactivityModeCB.Items.Add(InactivityMode.KeepAlive); InactivityModeCB.Items.Add(InactivityMode.Reopen); InactivityModeCB.Items.Add(InactivityMode.ReopenActive); InactivityModeCB.Items.Add(InactivityMode.Disconnect); StartProtocolCB.Items.Add(StartProtocolType.IEC); StartProtocolCB.Items.Add(StartProtocolType.DLMS); NameTB.Text = manufacturer.Name; ManufacturerIdTB.Text = manufacturer.Identification; ForceKeepAliveCB.Checked = manufacturer.ForceInactivity; UseLNCB.Checked = manufacturer.UseLogicalNameReferencing; UseIEC47CB.Checked = manufacturer.UseIEC47; StartProtocolCB.SelectedItem = manufacturer.StartProtocol; InactivityModeCB.SelectedItem = Manufacturer.InactivityMode; //Manufacturer ID can not change after creation. ManufacturerIdTB.Enabled = string.IsNullOrEmpty(manufacturer.Identification); KeepAliveIntervalTB.Value = Manufacturer.KeepAliveInterval / 1000; }
public ManufacturerForm(GXManufacturerCollection manufacturers, GXManufacturer manufacturer) { InitializeComponent(); Manufacturers = manufacturers; Manufacturer = manufacturer; if (manufacturer.Settings.Count == 0) { manufacturer.Settings.Add(new GXAuthentication(Authentication.None, (byte)0x10)); manufacturer.Settings.Add(new GXAuthentication(Authentication.Low, (byte)0x11)); manufacturer.Settings.Add(new GXAuthentication(Authentication.High, (byte)0x12)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighMD5, (byte)0x13)); manufacturer.Settings.Add(new GXAuthentication(Authentication.HighSHA1, (byte)0x14)); GXAuthentication gmac = new GXAuthentication(Authentication.HighGMAC, (byte)0x15); } GXAuthentication authentication = manufacturer.GetActiveAuthentication(); foreach (GXAuthentication it in manufacturer.Settings) { AuthenticationCB.Items.Add(it); } AuthenticationCB.SelectedItem = authentication; AdvancedBtn.Enabled = authentication.Type == Authentication.HighGMAC; this.AuthenticationCB.SelectedIndexChanged += new System.EventHandler(this.AuthenticationCB_SelectedIndexChanged); if (manufacturer.ServerSettings.Count == 0) { manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Default, (byte)1, true)); manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.SerialNumber, (byte)1, false)); manufacturer.ServerSettings.Add(new GXServerAddress(HDLCAddressType.Custom, (byte)1, false)); } foreach (GXServerAddress it in manufacturer.ServerSettings) { ServerAddressTypeCB.Items.Add(it); } GXServerAddress server = manufacturer.GetActiveServer(); ServerAddressTypeCB.SelectedItem = server; RefreshServer(server); this.ServerAddressTypeCB.SelectedIndexChanged += new System.EventHandler(this.ServerAddressTypeCB_SelectedIndexChanged); ServerAddressTypeCB.DrawMode = AuthenticationCB.DrawMode = DrawMode.OwnerDrawFixed; ClientAddTB.Value = authentication.ClientAddress; InactivityModeCB.Items.Add(InactivityMode.None); InactivityModeCB.Items.Add(InactivityMode.KeepAlive); InactivityModeCB.Items.Add(InactivityMode.Reopen); InactivityModeCB.Items.Add(InactivityMode.ReopenActive); InactivityModeCB.Items.Add(InactivityMode.Disconnect); StartProtocolCB.Items.Add(StartProtocolType.IEC); StartProtocolCB.Items.Add(StartProtocolType.DLMS); NameTB.Text = manufacturer.Name; ManufacturerIdTB.Text = manufacturer.Identification; ForceKeepAliveCB.Checked = manufacturer.ForceInactivity; UseLNCB.Checked = manufacturer.UseLogicalNameReferencing; UseIEC47CB.Checked = manufacturer.UseIEC47; StartProtocolCB.SelectedItem = manufacturer.StartProtocol; InactivityModeCB.SelectedItem = Manufacturer.InactivityMode; //Manufacturer ID can not change after creation. ManufacturerIdTB.Enabled = string.IsNullOrEmpty(manufacturer.Identification); KeepAliveIntervalTB.Value = Manufacturer.KeepAliveInterval / 1000; AdvancedBtn.Enabled = SecuredConnectionCB.Checked = manufacturer.SystemTitle != null; WebAddressTB.Text = Manufacturer.WebAddress; if (!string.IsNullOrEmpty(Manufacturer.Info)) { try { InfoTB.Text = ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(Manufacturer.Info)); } catch (Exception) { InfoTB.Text = ""; } } }
/// <summary> /// Apply new settings from property pages. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OKBtn_Click(object sender, EventArgs e) { try { string name = NameTB.Text.Trim(); if (name.Length == 0) { throw new Exception("Invalid name."); } GXServerAddress server = (GXServerAddress)ServerAddressTypeCB.SelectedItem; if (server.HDLCAddress == HDLCAddressType.SerialNumber && PhysicalServerAddressTB.Value == 0) { throw new Exception("Invalid Serial Number."); } GXManufacturer man = (GXManufacturer)ManufacturerCB.SelectedItem; Device.Authentication = ((GXAuthentication)this.AuthenticationCB.SelectedItem).Type; if (Device.Authentication != Authentication.None) { Device.Password = CryptHelper.Encrypt(this.PasswordTB.Text, Password.Key); } else { Device.Password = ""; } Device.Name = name; Device.Media = SelectedMedia; Device.Manufacturer = man.Identification; Device.WaitTime = Convert.ToInt32(WaitTimeTB.Value); Device.Verbose = VerboseModeCB.Checked; Device.MaximumBaudRate = 0; Device.UtcTimeZone = UseUtcTimeZone.Checked; if (SelectedMedia is GXSerial) { Device.UseRemoteSerial = false; if (this.SerialPortCB.Text.Length == 0) { throw new Exception("Invalid serial port."); } ((GXSerial)SelectedMedia).PortName = this.SerialPortCB.Text; if (UseMaximumBaudRateCB.Checked) { Device.MaximumBaudRate = (int)MaximumBaudRateCB.SelectedItem; } } else if (SelectedMedia is GXNet) { if (this.HostNameTB.Text.Length == 0) { throw new Exception("Invalid host name."); } ((GXNet)SelectedMedia).HostName = this.HostNameTB.Text; int port; if (!Int32.TryParse(this.PortTB.Text, out port)) { throw new Exception("Invalid port number."); } ((GXNet)SelectedMedia).Port = port; Device.UseRemoteSerial = UseRemoteSerialCB.Checked; ((GXNet)SelectedMedia).Protocol = (NetworkType)NetProtocolCB.SelectedItem; } else if (SelectedMedia is Gurux.Terminal.GXTerminal) { if (this.TerminalPortCB.Text.Length == 0) { throw new Exception("Invalid serial port."); } if (this.TerminalPhoneNumberTB.Text.Length == 0) { throw new Exception("Invalid phone number."); } Gurux.Terminal.GXTerminal terminal = SelectedMedia as Gurux.Terminal.GXTerminal; terminal.ConfigurableSettings = Gurux.Terminal.AvailableMediaSettings.All & ~Gurux.Terminal.AvailableMediaSettings.Server; Device.UseRemoteSerial = false; terminal.PortName = this.TerminalPortCB.Text; terminal.PhoneNumber = this.TerminalPhoneNumberTB.Text; } GXAuthentication authentication = (GXAuthentication)AuthenticationCB.SelectedItem; Device.HDLCAddressing = ((GXServerAddress)ServerAddressTypeCB.SelectedItem).HDLCAddress; Device.ClientAddress = Convert.ToInt32(ClientAddTB.Value); if (Device.HDLCAddressing == HDLCAddressType.SerialNumber) { Device.PhysicalAddress = PhysicalServerAddressTB.Value; } else { Device.PhysicalAddress = Convert.ChangeType(PhysicalServerAddressTB.Value, server.PhysicalAddress.GetType()); } Device.UseLogicalNameReferencing = this.UseLNCB.Checked; Device.LogicalAddress = Convert.ToInt32(LogicalServerAddressTB.Value); Device.StartProtocol = (StartProtocolType)this.StartProtocolCB.SelectedItem; GXDLMSDirector.Properties.Settings.Default.SelectedManufacturer = man.Name; Device.Security = (Security)SecurityCB.SelectedItem; Device.SystemTitle = SystemTitleTB.Text; Device.BlockCipherKey = BlockCipherKeyTB.Text; Device.AuthenticationKey = AuthenticationKeyTB.Text; } catch (Exception Ex) { this.DialogResult = DialogResult.None; GXDLMS.Common.Error.ShowError(this, Ex); } }