Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Sets the VLAN mask for the specified port.
- /// </summary>
- public void SetVlanMask(Port port, Byte[] mask) {
- if (mask.Length != 2)
- throw new ArgumentException("mask must be exactly 2 bytes.");
- try {
- lock (objLock) {
- if (blnConnected || Connect()) {
- Log("Set VLAN data for port: " + port + "Value: " + BitConverter.ToString(mask));
- Int32 intReturn = 0;
- // enable MDIO
- Byte[] writeBytes = new Byte[] { 0x02, 0x01 };
- intReturn = WriteRequest((Byte)Device.Switch, writeBytes, 2);
- if (intReturn != CP2112_DLL.HID_SMBUS_SUCCESS) {
- LogUtility.Log.Error("SetVlanMask error: WriteRequest(" + ((Byte)Device.Switch).ToString("X2") + ", " + BitConverter.ToString(writeBytes) + ", 2) == " + intReturn.ToString() + " (Enable MDIO)");
- return;
- }
- // address switch
- writeBytes = new Byte[] { 0x5F, GetSwitchPortDevice(port) }; // GetSwitchPortDevice() returns either 0x01 or 0x02 depending on which switch that port is on
- intReturn = WriteRequest((Byte)Device.Switch, writeBytes, 2);
- if (intReturn != CP2112_DLL.HID_SMBUS_SUCCESS) {
- LogUtility.Log.Error("SetVlanMask error: WriteRequest(" + ((Byte)Device.Switch).ToString("X2") + ", " + BitConverter.ToString(writeBytes) + ", 2) (address switch)");
- return;
- }
- byte bytPort = (byte)(GetSwitchPortRegister(port) + 0x10);
- ushort smiCommand = (ushort)(1 << 15 | 1 << 12 | 1 << 10 | bytPort << 5 | 0x06); // 0x06 is the VLAN register
- writeBytes = new Byte[3];
- writeBytes[0] = 0x61;
- writeBytes[1] = mask[1];
- writeBytes[2] = mask[0];
- intReturn = WriteRequest((Byte)Device.Switch, writeBytes, 3); // write mask first
- if (intReturn != CP2112_DLL.HID_SMBUS_SUCCESS) {
- LogUtility.Log.Error("SetVlanMask error: WriteRequest(" + ((Byte)Device.Switch).ToString("X2") + ", " + BitConverter.ToString(writeBytes) + ", 3) (write port vlan data)");
- return;
- }
- writeBytes[0] = 0x60;
- writeBytes[1] = (byte)(smiCommand & 0xFF); // lsb
- writeBytes[2] = (byte)(smiCommand >> 8); // msb
- intReturn = WriteRequest((Byte)Device.Switch, writeBytes, 3); // write SMI command
- if (intReturn != CP2112_DLL.HID_SMBUS_SUCCESS) {
- LogUtility.Log.Error("SetVlanMask error: WriteRequest(" + ((Byte)Device.Switch).ToString("X2") + ", " + BitConverter.ToString(writeBytes) + ", 3) (write port vlan data)");
- return;
- }
- }
- }
- } catch (Exception ex) {
- LogUtility.Log.Error("SetVlanMask exception", ex);
- } finally { Disconnect(); }
- }
- /// <summary>
- /// Sets the VLAN scenario 0 (No VLANs). All ports will be able to
- /// communicate with all other ports.
- /// </summary>
- public Boolean SetVlanScenario0() {
- try {
- lock (objLock) {
- SetVlanMask(Port.Port01, new Byte[] { 0x07, 0xBF });
- SetVlanMask(Port.Port02, new Byte[] { 0x07, 0x7F });
- SetVlanMask(Port.Port03, new Byte[] { 0x07, 0xEF });
- SetVlanMask(Port.Port04, new Byte[] { 0x07, 0xDF });
- SetVlanMask(Port.Port05, new Byte[] { 0x07, 0xFB });
- SetVlanMask(Port.Port06, new Byte[] { 0x07, 0xF7 });
- SetVlanMask(Port.Port07, new Byte[] { 0x07, 0xFE });
- SetVlanMask(Port.Port08, new Byte[] { 0x07, 0xFD });
- SetVlanMask(Port.Port09, new Byte[] { 0x07, 0xBF });
- SetVlanMask(Port.Port10, new Byte[] { 0x07, 0x7F });
- SetVlanMask(Port.Port11, new Byte[] { 0x07, 0xEF });
- SetVlanMask(Port.Port12, new Byte[] { 0x07, 0xDF });
- SetVlanMask(Port.Port13, new Byte[] { 0x07, 0xFB });
- SetVlanMask(Port.Port14, new Byte[] { 0x07, 0xF7 });
- SetVlanMask(Port.Port15, new Byte[] { 0x07, 0xFE });
- SetVlanMask(Port.Port16, new Byte[] { 0x07, 0xFD });
- SetVlanMask(Port.Uplink1, new Byte[] { 0x06, 0xFF });
- SetVlanMask(Port.Uplink2, new Byte[] { 0x06, 0xFF });
- SetVlanMask(Port.Switch1, new Byte[] { 0x05, 0xFF });
- SetVlanMask(Port.Switch2, new Byte[] { 0x03, 0xFF });
- SetVlanMask(Port.COM_X, new Byte[] { 0x05, 0xFF });
- SetVlanMask(Port.DSP, new Byte[] { 0x03, 0xFF });
- }
- } catch {
- return false;
- }
- return true;
- }
- /// <summary>
- /// Sets the VLAN scenario 1. Uplink 2 is WAN port, all others
- /// are on the same VLAN.
- /// </summary>
- public Boolean SetVlanScenario1() {
- try {
- lock (objLock) {
- SetVlanMask(Port.Port01, new Byte[] { 0x07, 0xBF });
- SetVlanMask(Port.Port02, new Byte[] { 0x07, 0x7F });
- SetVlanMask(Port.Port03, new Byte[] { 0x07, 0xEF });
- SetVlanMask(Port.Port04, new Byte[] { 0x07, 0xDF });
- SetVlanMask(Port.Port05, new Byte[] { 0x07, 0xFB });
- SetVlanMask(Port.Port06, new Byte[] { 0x07, 0xF7 });
- SetVlanMask(Port.Port07, new Byte[] { 0x07, 0xFE });
- SetVlanMask(Port.Port08, new Byte[] { 0x07, 0xFD });
- SetVlanMask(Port.Port09, new Byte[] { 0x07, 0xBF });
- SetVlanMask(Port.Port10, new Byte[] { 0x07, 0x7F });
- SetVlanMask(Port.Port11, new Byte[] { 0x07, 0xEF });
- SetVlanMask(Port.Port12, new Byte[] { 0x07, 0xDF });
- SetVlanMask(Port.Port13, new Byte[] { 0x07, 0xFB });
- SetVlanMask(Port.Port14, new Byte[] { 0x07, 0xF7 });
- SetVlanMask(Port.Port15, new Byte[] { 0x07, 0xFE });
- SetVlanMask(Port.Port16, new Byte[] { 0x07, 0xFD });
- SetVlanMask(Port.Uplink1, new Byte[] { 0x06, 0xFF });
- SetVlanMask(Port.Uplink2, new Byte[] { 0x02, 0x00 }); // uplink 2 can only communicate with COM X
- SetVlanMask(Port.Switch1, new Byte[] { 0x05, 0xFF });
- SetVlanMask(Port.Switch2, new Byte[] { 0x03, 0xFF });
- SetVlanMask(Port.COM_X, new Byte[] { 0x05, 0xFF });
- SetVlanMask(Port.DSP, new Byte[] { 0x03, 0xFF });
- }
- } catch {
- return false;
- }
- return true;
- }
- /// <summary>
- /// Sets the VLAN scenario 2. Uplink 1 is on a VLAN with ports 9-16
- /// and Uplink 2 is on a VLAN with ports 1-8.
- /// </summary>
- public Boolean SetVlanScenario2() {
- try {
- lock (objLock) {
- // ports 1-8 can only talk to ComX and Switch2 and each other, but not Uplink2
- SetVlanMask(Port.Port01, new Byte[] { 0x06, 0xBF }); // 0110-1011-1111 (06-BF)
- SetVlanMask(Port.Port02, new Byte[] { 0x06, 0x7F });
- SetVlanMask(Port.Port03, new Byte[] { 0x06, 0xEF });
- SetVlanMask(Port.Port04, new Byte[] { 0x06, 0xDF });
- SetVlanMask(Port.Port05, new Byte[] { 0x06, 0xFB });
- SetVlanMask(Port.Port06, new Byte[] { 0x06, 0xF7 });
- SetVlanMask(Port.Port07, new Byte[] { 0x06, 0xFE });
- SetVlanMask(Port.Port08, new Byte[] { 0x06, 0xFD });
- SetVlanMask(Port.Port09, new Byte[] { 0x06, 0xBF });
- SetVlanMask(Port.Port10, new Byte[] { 0x06, 0x7F });
- SetVlanMask(Port.Port11, new Byte[] { 0x06, 0xEF });
- SetVlanMask(Port.Port12, new Byte[] { 0x06, 0xDF });
- SetVlanMask(Port.Port13, new Byte[] { 0x06, 0xFB });
- SetVlanMask(Port.Port14, new Byte[] { 0x06, 0xF7 });
- SetVlanMask(Port.Port15, new Byte[] { 0x06, 0xFE });
- SetVlanMask(Port.Port16, new Byte[] { 0x06, 0xFD });
- SetVlanMask(Port.Uplink1, new Byte[] { 0x06, 0x00 }); // uplink 1 can only talk to Switch1
- SetVlanMask(Port.Uplink2, new Byte[] { 0x06, 0x00 }); // 0110-0000-0000 (06-00) uplink 2 can only talk to COM X and Switch2
- SetVlanMask(Port.Switch1, new Byte[] { 0x05, 0xFF });
- SetVlanMask(Port.Switch2, new Byte[] { 0x03, 0xFF });
- SetVlanMask(Port.COM_X, new Byte[] { 0x05, 0xFF });
- SetVlanMask(Port.DSP, new Byte[] { 0x03, 0xFF });
- }
- } catch {
- return false;
- }
- return true;
- }
Add Comment
Please, Sign In to add comment