36 Status = UsbIo->UsbGetConfigDescriptor (UsbIo, &Tmp);
44 USB_DESC_TYPE_CONFIG << 8 | (Tmp.ConfigurationValue - 1),
70 if ((Desc ==
NULL) || (*Offset >= Desc->TotalLength)) {
79 if ( *Offset >= Desc->TotalLength ) {
102 IN UINT8 FunDescriptorType,
110 Status = EFI_NOT_FOUND;
114 if (Interface->DescriptorType == USB_DESC_TYPE_CS_INTERFACE) {
116 switch (FunDescriptorType) {
117 case HEADER_FUN_DESCRIPTOR:
124 case UNION_FUN_DESCRIPTOR:
131 case ETHERNET_FUN_DESCRIPTOR:
139 Status = EFI_UNSUPPORTED;
168 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);
171 if (Interface.NumEndpoints == 0) {
172 Status =
UsbSetInterface (UsbIo, Interface.InterfaceNumber, 1, &Result);
175 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);
179 for (Index = 0; Index < Interface.NumEndpoints; Index++) {
180 Status = UsbIo->UsbGetEndpointDescriptor (UsbIo, Index, &Endpoint);
183 switch ((Endpoint.Attributes & (BIT0 | BIT1))) {
184 case USB_ENDPOINT_BULK:
185 if (Endpoint.EndpointAddress & BIT7) {
186 UsbEthDriver->BulkInEndpoint = Endpoint.EndpointAddress;
188 UsbEthDriver->BulkOutEndpoint = Endpoint.EndpointAddress;
192 case USB_ENDPOINT_INTERRUPT:
193 UsbEthDriver->InterruptEndpoint = Endpoint.EndpointAddress;
229 UINTN BulkDataLength;
235 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
238 if (UsbEthDriver->TotalDatagram == UsbEthDriver->NowDatagram) {
239 Status =
gBS->HandleProtocol (
240 UsbEthDriver->UsbCdcDataHandle,
241 &gEfiUsbIoProtocolGuid,
244 if (EFI_ERROR (Status)) {
248 if (UsbEthDriver->BulkInEndpoint == 0) {
252 BulkDataLength = USB_NCM_MAX_NTB_SIZE;
253 SetMem (UsbEthDriver->BulkBuffer, BulkDataLength, 0);
254 UsbEthDriver->NowDatagram = 0;
255 UsbEthDriver->TotalDatagram = 0;
257 Status = UsbIo->UsbBulkTransfer (
259 UsbEthDriver->BulkInEndpoint,
260 UsbEthDriver->BulkBuffer,
262 USB_ETHERNET_BULK_TIMEOUT,
265 if (EFI_ERROR (Status)) {
272 UsbEthDriver->TotalDatagram = (UINT8)((Ndp->Length - 8) / 4 - 1);
274 for (Index = 0; Index < UsbEthDriver->TotalDatagram; Index++) {
275 TotalLength += Datagram->DatagramLength;
279 if (TotalLength < USB_ETHERNET_FRAME_SIZE) {
283 for (Index = 0; Index < UsbEthDriver->TotalDatagram; Index++) {
284 CopyMem ((UINT8 *)Packet + TotalLength, (UINT8 *)UsbEthDriver->BulkBuffer + Datagram->DatagramIndex, Datagram->DatagramLength);
285 TotalLength += Datagram->DatagramLength;
289 *PacketLength = TotalLength;
290 UsbEthDriver->NowDatagram = UsbEthDriver->TotalDatagram;
292 UsbEthDriver->NowDatagram++;
295 CopyMem (Packet, (UINT8 *)UsbEthDriver->BulkBuffer + Datagram->DatagramIndex, Datagram->DatagramLength);
296 *PacketLength = Datagram->DatagramLength;
301 UsbEthDriver->NowDatagram++;
308 CopyMem (Packet, (UINT8 *)UsbEthDriver->BulkBuffer + Datagram->DatagramIndex, Datagram->DatagramLength);
309 *PacketLength = Datagram->DatagramLength;
350 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
352 Status =
gBS->HandleProtocol (
353 UsbEthDriver->UsbCdcDataHandle,
354 &gEfiUsbIoProtocolGuid,
357 if (EFI_ERROR (Status)) {
361 if (UsbEthDriver->BulkOutEndpoint == 0) {
365 TotalLength = (
UINTN)(USB_NCM_NTH_LENGTH + USB_NCM_NDP_LENGTH + (*PacketLength));
368 if (EFI_ERROR (Status)) {
372 SetMem (TotalPacket, TotalLength, 0);
375 Nth->Signature = USB_NCM_NTH_SIGN_16;
376 Nth->HeaderLength = USB_NCM_NTH_LENGTH;
377 Nth->Sequence = UsbEthDriver->BulkOutSequence++;
378 Nth->BlockLength = (UINT16)TotalLength;
379 Nth->NdpIndex = Nth->HeaderLength;
382 Ndp->Signature = USB_NCM_NDP_SIGN_16;
383 Ndp->Length = USB_NCM_NDP_LENGTH;
384 Ndp->NextNdpIndex = 0x00;
387 Datagram->DatagramIndex = Nth->HeaderLength + Ndp->Length;
388 Datagram->DatagramLength = (UINT16)*PacketLength;
390 CopyMem (TotalPacket + Datagram->DatagramIndex, Packet, *PacketLength);
392 *PacketLength = TotalLength;
394 Status = UsbIo->UsbBulkTransfer (
396 UsbEthDriver->BulkOutEndpoint,
399 USB_ETHERNET_BULK_TIMEOUT,
429 if ((Data ==
NULL) || (Context ==
NULL)) {
430 return EFI_INVALID_PARAMETER;
465 IN BOOLEAN IsNewTransfer,
474 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
479 Status = UsbEthDriver->UsbIo->UsbAsyncInterruptTransfer (
481 UsbEthDriver->InterruptEndpoint,
489 Status = UsbEthDriver->UsbIo->UsbAsyncInterruptTransfer (
491 UsbEthDriver->InterruptEndpoint,
531 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
533 Status = This->UsbEthFunDescriptor (This, &UsbEthDescriptor);
534 if (EFI_ERROR (Status)) {
535 DEBUG ((DEBUG_ERROR,
"%a:UsbEthFunDescriptor status = %r\n", __func__, Status));
539 Status = UsbEthDriver->UsbIo->UsbGetStringDescriptor (
542 UsbEthDescriptor.MacAddress,
545 if (EFI_ERROR (Status)) {
546 DEBUG ((DEBUG_ERROR,
"%a:UsbGetStringDescriptor status = %r\n", __func__, Status));
551 for (Index = 0; Index < PXE_HWADDR_LEN_ETHER; Index++) {
552 CopyMem (TmpStr, DataPtr,
sizeof (CHAR16));
555 CopyMem (TmpStr, DataPtr,
sizeof (CHAR16));
558 MacAddress->Addr[Index] = (Hi << 4) | Low;
580 *BulkSize = USB_NCM_MAX_NTB_SIZE;
605 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
607 if (UsbHeaderFunDescriptor ==
NULL) {
608 return EFI_INVALID_PARAMETER;
636 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
638 if (UsbUnionFunDescriptor ==
NULL) {
639 return EFI_INVALID_PARAMETER;
671 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
673 if (UsbEthFunDescriptor ==
NULL) {
674 return EFI_INVALID_PARAMETER;
710 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
712 Status = This->UsbEthFunDescriptor (This, &UsbEthFunDescriptor);
713 if (EFI_ERROR (Status)) {
717 if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) == 0) {
718 return EFI_UNSUPPORTED;
721 Request.RequestType = USB_ETHERNET_SET_REQ_TYPE;
722 Request.Request = SET_ETH_MULTICAST_FILTERS_REQ;
723 Request.Value = Value;
724 Request.Index = UsbEthDriver->NumOfInterface;
725 Request.Length = Value * 6;
727 return UsbEthDriver->UsbIo->UsbControlTransfer (
731 USB_ETHERNET_TRANSFER_TIMEOUT,
760 IN VOID *PatternFilter
767 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
769 Request.RequestType = USB_ETHERNET_SET_REQ_TYPE;
770 Request.Request = SET_ETH_POWER_MANAGEMENT_PATTERN_FILTER_REQ;
771 Request.Value = Value;
772 Request.Index = UsbEthDriver->NumOfInterface;
773 Request.Length = Length;
775 return UsbEthDriver->UsbIo->UsbControlTransfer (
779 USB_ETHERNET_TRANSFER_TIMEOUT,
806 OUT BOOLEAN *PatternActive
813 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
815 Request.RequestType = USB_ETHERNET_GET_REQ_TYPE;
816 Request.Request = GET_ETH_POWER_MANAGEMENT_PATTERN_FILTER_REQ;
817 Request.Value = Value;
818 Request.Index = UsbEthDriver->NumOfInterface;
819 Request.Length = USB_ETH_POWER_FILTER_LENGTH;
821 return UsbEthDriver->UsbIo->UsbControlTransfer (
825 USB_ETHERNET_TRANSFER_TIMEOUT,
827 USB_ETH_POWER_FILTER_LENGTH,
850 OUT UINT16 *CdcFilter
856 Count =
sizeof (gTable)/
sizeof (gTable[0]);
858 for (Index = 0; (Index < Count) && (gTable[Index].Src != 0); Index++) {
859 if (gTable[Index].Src & Value) {
860 *CdcFilter |= gTable[Index].Dst;
888 UINT16 CommandFilter;
890 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
895 Request.RequestType = USB_ETHERNET_SET_REQ_TYPE;
896 Request.Request = SET_ETH_PACKET_FILTER_REQ;
897 Request.Value = CommandFilter;
898 Request.Index = UsbEthDriver->NumOfInterface;
899 Request.Length = USB_ETH_PACKET_FILTER_LENGTH;
901 return UsbEthDriver->UsbIo->UsbControlTransfer (
905 USB_ETHERNET_TRANSFER_TIMEOUT,
907 USB_ETH_PACKET_FILTER_LENGTH,
930 IN UINT16 FeatureSelector,
940 UsbEthDriver = USB_ETHERNET_DEV_FROM_THIS (This);
942 Status = This->UsbEthFunDescriptor (This, &UsbEthFunDescriptor);
943 if (EFI_ERROR (Status)) {
947 if (UsbEthFunDescriptor.EthernetStatistics == 0) {
948 return EFI_UNSUPPORTED;
951 Request.RequestType = USB_ETHERNET_GET_REQ_TYPE;
952 Request.Request = GET_ETH_STATISTIC_REQ;
953 Request.Value = FeatureSelector;
954 Request.Index = UsbEthDriver->NumOfInterface;
955 Request.Length = USB_ETH_STATISTIC;
957 return UsbEthDriver->UsbIo->UsbControlTransfer (
961 USB_ETHERNET_TRANSFER_TIMEOUT,
UINTN EFIAPI StrHexToUintn(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
EFI_STATUS(EFIAPI * EFI_ASYNC_USB_TRANSFER_CALLBACK)(IN VOID *Data, IN UINTN DataLength, IN VOID *Context, IN UINT32 Status)
#define PXE_OPFLAGS_RECEIVE_FILTER_UNICAST
#define PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS
#define PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST
#define PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST
#define PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST
EFI_STATUS EFIAPI UsbSetInterface(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Interface, IN UINT16 AlternateSetting, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbGetDescriptor(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Value, IN UINT16 Index, IN UINT16 DescriptorLength, OUT VOID *Descriptor, OUT UINT32 *Status)
EFI_STATUS EFIAPI GetUsbEthMacAddress(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT EFI_MAC_ADDRESS *MacAddress)
EFI_STATUS EFIAPI SetUsbEthPowerFilter(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 Value, IN UINT16 Length, IN VOID *PatternFilter)
EFI_STATUS EFIAPI SetUsbEthPacketFilter(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 Value)
EFI_STATUS EFIAPI InterruptCallback(IN VOID *Data, IN UINTN DataLength, IN VOID *Context, IN UINT32 Status)
VOID GetEndpoint(IN EFI_USB_IO_PROTOCOL *UsbIo, IN OUT USB_ETHERNET_DRIVER *UsbEthDriver)
EFI_STATUS GetFunctionalDescriptor(IN EFI_USB_CONFIG_DESCRIPTOR *Config, IN UINT8 FunDescriptorType, OUT VOID *DataBuffer)
EFI_STATUS EFIAPI UsbEthNcmTransmit(IN PXE_CDB *Cdb, IN EDKII_USB_ETHERNET_PROTOCOL *This, IN VOID *Packet, IN OUT UINTN *PacketLength)
EFI_STATUS EFIAPI UsbEthNcmReceive(IN PXE_CDB *Cdb, IN EDKII_USB_ETHERNET_PROTOCOL *This, IN OUT VOID *Packet, IN OUT UINTN *PacketLength)
EFI_STATUS EFIAPI GetUsbEthFunDescriptor(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT USB_ETHERNET_FUN_DESCRIPTOR *UsbEthFunDescriptor)
EFI_STATUS EFIAPI GetUsbEthPowerFilter(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 Value, OUT BOOLEAN *PatternActive)
EFI_STATUS LoadAllDescriptor(IN EFI_USB_IO_PROTOCOL *UsbIo, OUT EFI_USB_CONFIG_DESCRIPTOR **ConfigDesc)
EFI_STATUS EFIAPI GetUsbEthStatistic(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 FeatureSelector, OUT VOID *Statistic)
EFI_STATUS EFIAPI SetUsbEthMcastFilter(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 Value, IN VOID *McastAddr)
EFI_STATUS EFIAPI GetUsbHeaderFunDescriptor(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT USB_HEADER_FUN_DESCRIPTOR *UsbHeaderFunDescriptor)
EFI_STATUS EFIAPI UsbEthNcmBulkSize(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT UINTN *BulkSize)
EFI_STATUS EFIAPI UsbEthNcmInterrupt(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN BOOLEAN IsNewTransfer, IN UINTN PollingInterval, IN EFI_USB_DEVICE_REQUEST *Request)
EFI_STATUS EFIAPI GetUsbUnionFunDescriptor(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT USB_UNION_FUN_DESCRIPTOR *UsbUnionFunDescriptor)
VOID ConvertFilter(IN UINT16 Value, OUT UINT16 *CdcFilter)
BOOLEAN NextDescriptor(IN EFI_USB_CONFIG_DESCRIPTOR *Desc, IN OUT UINTN *Offset)