public PanasonicDiscovery(PhysicalAddress macAddress, IPAddress _ip)
            {
                byte[] ipBytes;
                UInt32 ipUInt32;

                _uint32_04 = NetworkUtils.bigEndian32(0x000d0000);
                _uint32_08 = NetworkUtils.bigEndian32(0x00000000);

                headerMagic = NetworkUtils.bigEndian32(0x00010000);

                mac = macAddress.GetAddressBytes().GetStruct <MacAddress>();

                ipBytes  = _ip.GetAddressBytes();
                ipUInt32 = (UInt32)((ipBytes[0] << 24) |
                                    (ipBytes[1] << 16) |
                                    (ipBytes[2] << 8) |
                                    (ipBytes[3]));
                ip = NetworkUtils.bigEndian32(ipUInt32);

                _uint32_16 = NetworkUtils.bigEndian32(0x00012011);
                _uint32_1A = NetworkUtils.bigEndian32(0x1e11231f);
                _uint32_1E = NetworkUtils.bigEndian32(0x1e191300);
                _uint32_22 = NetworkUtils.bigEndian32(0x00020000);
                _uint32_26 = NetworkUtils.bigEndian32(0x00000000);
                _uint32_2A = NetworkUtils.bigEndian32(0x00000000);
                _uint32_2E = NetworkUtils.bigEndian32(0x0000ffff);
                checksum   = NetworkUtils.bigEndian16(0x0000);
            }
Exemple #2
0
 public NiceVisionRequest(UInt16 transactionId, UInt16 answerToPort)
 {
     magic       = NetworkUtils.bigEndian32(NiceVision.magic);
     transaction = NetworkUtils.bigEndian16(transactionId);
     payload     = NetworkUtils.bigEndian32(NiceVision.payload);
     answerPort  = NetworkUtils.bigEndian16((UInt16)answerToPort);
 }
        public override void reciever(IPEndPoint from, byte[] data)
        {
            UbiquitiHeader header;
            int            headerSize;
            int            position;
            IPAddress      IPv4;

            byte[] mac;
            string macAddress;
            string model;

            headerSize = typeof(UbiquitiHeader).StructLayoutAttribute.Size;

            if (data.Length < headerSize)
            {
                Logger.LogWarning(String.Format("Warning: Ubiquiti.reciever(): Invalid size packet recieved from {0}", from.ToString()));
                return;
            }

            header = data.GetStruct <UbiquitiHeader>();
            if (NetworkUtils.bigEndian16(header.magic) != anwserMagic)
            {
                Logger.LogWarning(String.Format("Warning: Ubiquiti.reciever(): Invalid magic value from {0}", from.ToString()));
                /* not enougth tested Ubiquiti answer to say it is always this magic, so disabling return for now */
                // return;
            }

            if (NetworkUtils.bigEndian16(header.packetSize) != data.Length - 4)
            {
                Logger.LogWarning(String.Format("Warning: Ubiquiti.reciever(): Invalid packet size value (got value {0} while value {1} was expected) from {2}",
                                                NetworkUtils.bigEndian16(header.packetSize), data.Length - 4, from.ToString()));
                return;
            }

            position = headerSize;
            IPv4     = null;
            mac      = null;
            model    = "";

            while (position < data.Length)
            {
                UInt16 variable;
                byte[] value;

                variable = readNextValue(data, ref position, out value);
                switch (variable)
                {
                case (byte)UbiquitiValue.typeNull:
                    Logger.LogWarning("Warning: Ubiquiti.reciever(): Invalid packet, variable type null");
                    return;

                case (byte)UbiquitiValue.macAddress1:     // binary: 4 bytes
                case (byte)UbiquitiValue.macAddress2:     // binary: 4 bytes
                    if (value.Length != 6)
                    {
                        Logger.LogWarning(String.Format("Warning: Ubiquiti.reciever(): invalid size of variable 0x{0:X4} (expected={1}, found={2})",
                                                        (UInt16)variable, 6, value.Length));
                        break;
                    }
                    if (mac == null)
                    {
                        mac = value;
                    }
                    break;

                case (byte)UbiquitiValue.macIPv4:     // binary: 10 bytes
                    if (value.Length != 10)
                    {
                        Logger.LogWarning(String.Format("Warning: Ubiquiti.reciever(): invalid size of variable 0x{0:X4} (expected={1}, found={2})",
                                                        (UInt16)variable, 10, value.Length));
                        break;
                    }
                    if (mac == null)
                    {
                        mac = new byte[6];
                        Array.Copy(value, 0, mac, 0, 6);
                    }
                    if (IPv4 == null)
                    {
                        var IPv4Bytes = new byte[4];
                        Array.Copy(value, 6, IPv4Bytes, 0, 4);
                        IPv4 = new IPAddress(IPv4Bytes);
                    }
                    break;

                case (byte)UbiquitiValue.model1:     // string
                case (byte)UbiquitiValue.model2:     // string
                    if (model == "")
                    {
                        model = Encoding.UTF8.GetString(value);
                    }
                    break;
                }
            }

            if (IPv4 == null)
            {
                IPv4 = from.Address;
            }
            if (mac != null && IPv4 != null)
            {
                macAddress = String.Format("{0:X2}:{1:X2}:{2:X2}:{3:X2}:{4:X2}:{5:X2}", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
                if (model == "")
                {
                    model = "unknown";
                }

                viewer.deviceFound(name, 1, IPv4, model, macAddress);
            }
        }