Exemple #1
0
 public byte[] GetDataControl(USBPacket packet)
 {
     return(controlPacket);
 }
Exemple #2
0
 public void WriteDataControl(USBPacket packet)
 {
 }
Exemple #3
0
 public byte[] ProcessClassGet(USBPacket packet, USBSetupPacket setupPacket)
 {
     throw new System.NotImplementedException();
 }
Exemple #4
0
 public byte[] GetStatus(USBPacket packet, USBSetupPacket setupPacket)
 {
     throw new NotImplementedException();
 }
Exemple #5
0
 public void SetFeature(USBPacket packet, USBSetupPacket setupPacket)
 {
 }
Exemple #6
0
        public byte[] GetDataBulk(USBPacket packet)
        {
            lock (sync)
            {
                if (packet.bytesToTransfer > 0)
                {
                    if (rxPacketQueue.Count > 0)
                    {
                        EthernetFrame receivedFrame = rxPacketQueue.Dequeue();

                        //byte frameBytes []= rxFifo.Dequeue();
                        var  size = receivedFrame.Bytes.Length;
                        uint packetSize;
                        //  var packetSize = Math.Max(64, size & ~1); //64 is the minimal length
                        packetSize  = (uint)size;
                        packetSize += 6;


                        packetSize += 6;

                        if (packetSize > 1514 + 12)
                        {
                            //Maybe we should react to overruns. Now we just drop.
                            return(null);
                        }

                        byte[] currentBuffer = new byte[(uint)packetSize];
                        currentBuffer[2] = (byte)((packetSize - 6) & 0xff);
                        currentBuffer[3] = (byte)((packetSize - 6) >> 8);
                        var    frameBytes = receivedFrame.Bytes;
                        ushort cksum      = 0;

                        byte[] tmp = new byte[(uint)frameBytes.Length - 14];
                        Array.Copy(frameBytes, 14, tmp, 0, tmp.Length);
                        cksum = CalculateChecksumRX(tmp);
                        if ((frameBytes[14] & 0xF0) == 0x40) //IP packet
                        {
                            if (frameBytes[23] == 0x06)      // TCP packet
                            {
                                uint   sa             = (uint)((frameBytes[MACHeaderLegth + 12 + 3] << 24) | (frameBytes[MACHeaderLegth + 12 + 2] << 16) | (frameBytes[MACHeaderLegth + 12 + 1] << 8) | (frameBytes[MACHeaderLegth + 12 + 0] << 0));
                                uint   da             = (uint)((frameBytes[MACHeaderLegth + 16 + 3] << 24) | (frameBytes[MACHeaderLegth + 16 + 2] << 16) | (frameBytes[MACHeaderLegth + 16 + 1] << 8) | (frameBytes[MACHeaderLegth + 16 + 0] << 0));
                                ushort protocol       = frameBytes[MACHeaderLegth + 9];
                                ushort IPHeaderLength = (ushort)((frameBytes[14] & 0x0F) * 4);
                                ushort packetLength   = (ushort)(System.Net.IPAddress.HostToNetworkOrder((ushort)(frameBytes.Length - (MACHeaderLegth + IPHeaderLength))) >> 16);
                                long   s = sa + da + (protocol << 8) + packetLength;
                                s    += (s >> 32);
                                s     = (s & 0xffff) + (s >> 16);
                                s     = (s & 0xffff) + (s >> 16);
                                cksum = (ushort)~s;
                            }
                        }

                        if ((frameBytes[14] & 0xF0) == 0x40) //IP packet
                        {
                            if (frameBytes[23] == 0x01)      // UDP packet
                            {
                                Array.Copy(frameBytes, 14, tmp, 0, tmp.Length);
                                ushort cksumm = CalculateChecksumRX(tmp);
                                frameBytes[36] = (byte)((cksumm >> 8) & 0xFF);
                                frameBytes[37] = (byte)((cksumm) & 0xFF);
                            }
                        }

                        for (int i = 0; i < size; i++)
                        {
                            currentBuffer[6 + i] = frameBytes[i];
                        }

                        if ((frameBytes[14] & 0xF0) == 0x40) //IP packet
                        {
                            if (frameBytes[23] == 0x06)
                            {
                                currentBuffer[packetSize - 1] = (byte)(((cksum) >> 8) & 0xFF);
                                currentBuffer[packetSize - 2] = (byte)((cksum) & 0xFF);
                            }
                            else if (frameBytes[23] == 0x11)
                            {
                                currentBuffer[packetSize - 1] = (byte)(((cksum) >> 8) & 0xFF);
                                currentBuffer[packetSize - 2] = (byte)((cksum) & 0xFF);
                            }
                        }
                        return(currentBuffer);
                    }
                }
                return(null);
            }
        }
Exemple #7
0
        public void ProcessClassSet(USBPacket packet, USBSetupPacket setupPacket)
        {
            //MessageRecipient recipient = (MessageRecipient)(setupPacket.requestType & 0x3);
            ushort index   = setupPacket.index;
            byte   request = setupPacket.request;
            ushort value   = setupPacket.value;

            switch ((HUBRequestCode)request)
            {
            case HUBRequestCode.ClearHubFeature:
                if (index > 0)
                {
                    switch ((PortFeature)value)
                    {
                    case PortFeature.CPortSuspend:
                        ports[index - 1] = (uint)(ports[index - 1] & (~((uint)PortStatus.CPortSuspend)));
                        break;

                    case PortFeature.CPortOverCurrent:
                        ports[index - 1] = (uint)(ports[index - 1] & (~((uint)PortStatus.CPortOverCurrent)));
                        break;

                    case PortFeature.CPortEnable:
                        ports[index - 1] = (uint)(ports[index - 1] & (~((uint)PortStatus.CPortEnable)));
                        break;

                    case PortFeature.PortEnable:
                        ports[index - 1] = (uint)(ports[index - 1] & (uint)PortStatus.PortEnable);
                        break;

                    case PortFeature.PortSuspend:
                        ports[index - 1] = (uint)(ports[index - 1] & (uint)PortStatus.PortSuspend);
                        break;

                    case PortFeature.CPortConnection:
                        ports[index - 1] = (uint)(ports[index - 1] & (~((uint)PortStatus.CPortConnection)));
                        break;

                    case PortFeature.CPortReset:
                        ActiveDevice(this.GetDevice((byte)(index)));
                        ports[index - 1] = (uint)(ports[index - 1] & (~((uint)PortStatus.CPortReset)));
                        break;

                    default:
                        this.Log(LogLevel.Warning, "Unsupported ClearHubFeature request!!!");
                        break;
                    }
                }
                break;

            case HUBRequestCode.SetHubFeature:
                if (index > 0)
                {
                    if ((PortFeature)value == PortFeature.PortReset)
                    {
                        IUSBPeripheral device = GetDevice((byte)(index));
                        ports[index - 1] |= (uint)PortStatus.CPortReset;
                        ports[index - 1] |= (uint)PortStatus.PortEnable;
                        if (device != null)
                        {
                            device.SetAddress(0);
                            device.Reset();
                        }
                    }
                    else if ((PortFeature)value == PortFeature.PortSuspend)
                    {
                        ports[index - 1] |= (uint)PortStatus.PortSuspend;
                    }
                }

                break;

            default:
                this.Log(LogLevel.Warning, "Unsupported HUB ProcessClassSet request!!!");
                break;
            }
        }
Exemple #8
0
 public void SetConfiguration(USBPacket packet, USBSetupPacket setupPacket)
 {
 }
Exemple #9
0
 public byte[] GetDescriptor(USBPacket packet, USBSetupPacket setupPacket)
 {
     return(null);
 }
Exemple #10
0
 public byte[] WriteInterrupt(USBPacket packet)
 {
     return(null);
 }
Exemple #11
0
 public byte[] GetDataControl(USBPacket packet)
 {
     return(null);
 }
Exemple #12
0
 public void WriteDataBulk(USBPacket packet)
 {
 }
Exemple #13
0
 public byte[] GetDataBulk(USBPacket packet)
 {
     return(null);
 }
Exemple #14
0
 public void ClearFeature(USBPacket packet, USBSetupPacket setupPacket)
 {
     throw new System.NotImplementedException();
 }
Exemple #15
0
 public void SetConfiguration(USBPacket packet, USBSetupPacket setupPacket)
 {
     //throw new NotImplementedException();
 }
Exemple #16
0
 public byte[] GetInterface(USBPacket packet, USBSetupPacket setupPacket)
 {
     throw new System.NotImplementedException();
 }
Exemple #17
0
 public void SetInterface(USBPacket packet, USBSetupPacket setupPacket)
 {
     throw new NotImplementedException();
 }
Exemple #18
0
 public void SetDescriptor(USBPacket packet, USBSetupPacket setupPacket)
 {
     throw new System.NotImplementedException();
 }
Exemple #19
0
 public void ProcessVendorSet(USBPacket packet, USBSetupPacket setupPacket)
 {
     throw new NotImplementedException();
 }
Exemple #20
0
 public void SetInterface(USBPacket packet, USBSetupPacket setupPacket)
 {
 }
Exemple #21
0
 public void WriteDataBulk(USBPacket packet)
 {
     // throw new System.NotImplementedException();
 }
Exemple #22
0
        public byte[] ProcessVendorGet(USBPacket packet, USBSetupPacket setupPacket)
        {
            ushort index   = setupPacket.index;
            byte   request = setupPacket.request;
            ushort value   = setupPacket.value;

            if (request == (byte)vendorRequest.ReadRegister)
            {
                switch ((SCSR)index)
                {
                case SCSR.MACAddressLo:

                    break;

                case SCSR.MACAddressHi:

                    break;

                case SCSR.E2PData:
                    if ((e2pCommand & 0x000001FF) >= 0x1 && (e2pCommand & 0x000001FF) <= 0x6)
                    {
                        controlPacket    = new byte[1];
                        controlPacket[0] = MAC.Bytes[(e2pCommand & 0x000001FF) - 1];
                        return(controlPacket);
                    }
                    else
                    {
                        controlPacket = BitConverter.GetBytes((uint)0);
                        return(BitConverter.GetBytes((uint)0));
                    }

                case SCSR.MACControl:
                    controlPacket = BitConverter.GetBytes(macControlRegister);
                    return(BitConverter.GetBytes(macControlRegister));

                case SCSR.E2PCommand:
                    controlPacket = BitConverter.GetBytes(e2pCommand);
                    return(BitConverter.GetBytes(e2pCommand));

                case SCSR.HwConfig:
                    controlPacket = BitConverter.GetBytes(hardwareConfigurationRegister & (~0x00000008));
                    return(BitConverter.GetBytes(hardwareConfigurationRegister & (~0x00000008)));

                case SCSR.PmControl:
                    controlPacket = BitConverter.GetBytes(powerMenagementConfigurationRegister & (~0x00000010));
                    return(BitConverter.GetBytes(powerMenagementConfigurationRegister & (~0x00000010)));

                case SCSR.MediaIndependentInterfaceData:
                    controlPacket = BitConverter.GetBytes(miiData & (~0x8000) | 0x0004 | 0x0100);
                    return(BitConverter.GetBytes(miiData & (~0x8000) | 0x0004 | 0x0100));

                case SCSR.MediaIndependentInterfaceAddress:
                    controlPacket     = BitConverter.GetBytes(miiAddress);
                    controlPacket[0] &= ((byte)(0xFEu));
                    return(controlPacket);

                default:
                    this.Log(LogLevel.Warning, "Unknown register read request (request=0x{0:X}, value=0x{1:X}, index=0x{2:X})", request, value, index);
                    break;
                }
            }
            var arr = new byte[] { 0 };

            controlPacket = arr;
            return(arr);
        }
Exemple #23
0
 public byte[] GetDataBulk(USBPacket packet)
 {
     throw new System.NotImplementedException();
     // return
 }
Exemple #24
0
        public void ProcessVendorSet(USBPacket packet, USBSetupPacket setupPacket)
        {
            ushort index   = setupPacket.index;
            byte   request = setupPacket.request;
            ushort value   = setupPacket.value;

            if (request == (byte)vendorRequest.WriteRegister)
            {
                switch ((SCSR)index)
                {
                case SCSR.HwConfig:
                    if (packet.data != null)
                    {
                        hardwareConfigurationRegister = BitConverter.ToUInt32(packet.data, 0);
                    }
                    break;

                case SCSR.PmControl:
                    if (packet.data != null)
                    {
                        powerMenagementConfigurationRegister = BitConverter.ToUInt32(packet.data, 0);
                    }
                    break;

                case SCSR.MACAddressLo:
                    break;

                case SCSR.MACAddressHi:
                    break;

                case SCSR.MACControl:
                    if (packet.data != null)
                    {
                        macControlRegister = BitConverter.ToUInt32(packet.data, 0);
                    }
                    this.Log(LogLevel.Warning, "macControlRegister=0x{0:X}", macControlRegister);
                    break;

                case SCSR.E2PData:
                    break;

                case SCSR.E2PCommand:
                    if (packet.data != null)
                    {
                        e2pCommand = BitConverter.ToUInt32(packet.data, 0) & (~(0x80000000 | 0x00000400));
                    }
                    break;

                case SCSR.MediaIndependentInterfaceAddress:
                    if (packet.data != null)
                    {
                        miiAddress = BitConverter.ToUInt32(packet.data, 0);
                    }
                    break;

                case SCSR.MediaIndependentInterfaceData:
                    if (packet.data != null)
                    {
                        miiData = BitConverter.ToUInt32(packet.data, 0);
                    }
                    break;

                default:
                    this.Log(LogLevel.Warning, "Unknown register write request  (request=0x{0:X}, value=0x{1:X}, index=0x{2:X})", request, value, index);
                    break;
                }
            }
        }
Exemple #25
0
 public void ClearFeature(USBPacket packet, USBSetupPacket setupPacket)
 {
     throw new USBRequestException();
 }