TianoCore EDK2 master
Loading...
Searching...
No Matches
UsbRndisFunction.c
Go to the documentation of this file.
1
9#include "UsbRndis.h"
10
11UINT16 gStopBulkInCnt = 0;
12UINT16 gBlockBulkInCnt = 0;
13
32 )
33{
34 EFI_STATUS Status;
35 UINT32 TransStatus;
37
38 Status = UsbIo->UsbGetConfigDescriptor (UsbIo, &Tmp);
39 if (EFI_ERROR (Status)) {
40 DEBUG ((DEBUG_ERROR, "%a:UsbGetConfigDescriptor status = %r\n", __func__, Status));
41 return Status;
42 }
43
44 Status = gBS->AllocatePool (
46 Tmp.TotalLength,
47 (VOID **)ConfigDesc
48 );
49 if (EFI_ERROR (Status)) {
50 DEBUG ((DEBUG_ERROR, "%a: AllocatePool status = %r\n", __func__, Status));
51 return Status;
52 }
53
54 Status = UsbGetDescriptor (
55 UsbIo,
56 USB_DESC_TYPE_CONFIG << 8 | (Tmp.ConfigurationValue - 1), // zero based
57 0,
58 Tmp.TotalLength,
59 *ConfigDesc,
60 &TransStatus
61 );
62 return Status;
63}
64
76BOOLEAN
79 IN OUT UINTN *Offset
80 )
81{
82 if ((Desc == NULL) || (*Offset >= Desc->TotalLength)) {
83 return FALSE;
84 }
85
86 if (((EFI_USB_CONFIG_DESCRIPTOR *)((char *)Desc+*Offset))->Length == 0) {
87 return FALSE;
88 }
89
90 *Offset += ((EFI_USB_CONFIG_DESCRIPTOR *)((char *)Desc+*Offset))->Length;
91 if ( *Offset >= Desc->TotalLength ) {
92 return FALSE;
93 }
94
95 return TRUE;
96}
97
114 IN UINT8 FunDescriptorType,
115 OUT VOID *DataBuffer
116 )
117{
118 EFI_STATUS Status;
119 UINTN Offset;
121
122 Status = EFI_NOT_FOUND;
123
124 for (Offset = 0; NextDescriptor (Config, &Offset);) {
125 Interface = (EFI_USB_INTERFACE_DESCRIPTOR *)((UINT8 *)Config + Offset);
126 if (Interface->DescriptorType == USB_DESC_TYPE_CS_INTERFACE) {
127 if (((USB_HEADER_FUN_DESCRIPTOR *)Interface)->DescriptorSubtype == FunDescriptorType) {
128 switch (FunDescriptorType) {
129 case HEADER_FUN_DESCRIPTOR:
130 CopyMem (
131 DataBuffer,
132 (USB_HEADER_FUN_DESCRIPTOR *)Interface,
134 );
135 return EFI_SUCCESS;
136 case UNION_FUN_DESCRIPTOR:
137 CopyMem (
138 DataBuffer,
139 (USB_UNION_FUN_DESCRIPTOR *)Interface,
140 ((USB_UNION_FUN_DESCRIPTOR *)Interface)->FunctionLength
141 );
142 return EFI_SUCCESS;
143 case ETHERNET_FUN_DESCRIPTOR:
144 CopyMem (
145 DataBuffer,
146 (USB_ETHERNET_FUN_DESCRIPTOR *)Interface,
148 );
149 return EFI_SUCCESS;
150 default:
151 Status = EFI_UNSUPPORTED;
152 break;
153 }
154 }
155 }
156 }
157
158 return Status;
159}
160
168VOID
170 IN EFI_USB_IO_PROTOCOL *UsbIo,
171 IN OUT USB_RNDIS_DEVICE *UsbRndisDevice
172 )
173{
174 EFI_STATUS Status;
175 UINT8 Index;
176 UINT32 Result;
179
180 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);
181 if (EFI_ERROR (Status)) {
182 DEBUG ((DEBUG_ERROR, "%a:UsbGetInterfaceDescriptor status = %r\n", __func__, Status));
183 return;
184 }
185
186 if (Interface.NumEndpoints == 0 ) {
187 Status = UsbSetInterface (UsbIo, 1, 0, &Result);
188 if (EFI_ERROR (Status)) {
189 DEBUG ((DEBUG_ERROR, "%a:UsbSetInterface status = %r\n", __func__, Status));
190 return;
191 }
192
193 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface);
194 if (EFI_ERROR (Status)) {
195 DEBUG ((DEBUG_ERROR, "%a:UsbGetInterfaceDescriptor status = %r\n", __func__, Status));
196 return;
197 }
198 }
199
200 for (Index = 0; Index < Interface.NumEndpoints; Index++) {
201 Status = UsbIo->UsbGetEndpointDescriptor (UsbIo, Index, &Endpoint);
202 if (EFI_ERROR (Status)) {
203 DEBUG ((DEBUG_ERROR, "%a:UsbGetEndpointDescriptor status = %r\n", __func__, Status));
204 return;
205 }
206
207 switch ((Endpoint.Attributes & (BIT0 | BIT1))) {
208 case USB_ENDPOINT_BULK:
209 if (Endpoint.EndpointAddress & BIT7) {
210 UsbRndisDevice->BulkInEndpoint = Endpoint.EndpointAddress;
211 } else {
212 UsbRndisDevice->BulkOutEndpoint = Endpoint.EndpointAddress;
213 }
214
215 break;
216 case USB_ENDPOINT_INTERRUPT:
217 UsbRndisDevice->InterrupEndpoint = Endpoint.EndpointAddress;
218 break;
219 }
220 }
221}
222
238EFIAPI
240 IN VOID *Data,
241 IN UINTN DataLength,
242 IN VOID *Context,
243 IN UINT32 Status
244 )
245{
246 if ((Data == NULL) || (Context == NULL)) {
247 return EFI_INVALID_PARAMETER;
248 }
249
250 if (((EFI_USB_DEVICE_REQUEST *)Data)->Request == 0) {
251 CopyMem (
252 (EFI_USB_DEVICE_REQUEST *)Context,
255 );
256 }
257
258 return EFI_SUCCESS;
259}
260
279EFIAPI
282 IN BOOLEAN IsNewTransfer,
283 IN UINTN PollingInterval,
285 )
286{
287 EFI_STATUS Status;
288 USB_RNDIS_DEVICE *UsbRndisDevice;
289 UINTN DataLength;
290
291 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
292 DataLength = 0;
293
294 if (IsNewTransfer) {
295 DataLength = sizeof (EFI_USB_DEVICE_REQUEST) + sizeof (USB_CONNECT_SPEED_CHANGE);
296 Status = UsbRndisDevice->UsbIo->UsbAsyncInterruptTransfer (
297 UsbRndisDevice->UsbIo,
298 UsbRndisDevice->InterrupEndpoint,
299 IsNewTransfer,
300 PollingInterval,
301 DataLength,
303 Requst
304 );
305
306 if (Status == EFI_INVALID_PARAMETER) {
307 // Because of Stacked AsyncInterrupt request are not supported
308 Status = UsbRndisDevice->UsbIo->UsbAsyncInterruptTransfer (
309 UsbRndisDevice->UsbIo,
310 UsbRndisDevice->InterrupEndpoint,
311 0,
312 0,
313 0,
314 NULL,
315 NULL
316 );
317 }
318 } else {
319 Status = UsbRndisDevice->UsbIo->UsbAsyncInterruptTransfer (
320 UsbRndisDevice->UsbIo,
321 UsbRndisDevice->InterrupEndpoint,
322 IsNewTransfer,
323 0,
324 0,
325 NULL,
326 NULL
327 );
328 }
329
330 return Status;
331}
332
343EFIAPI
345 IN USB_RNDIS_DEVICE *UsbRndisDevice
346 )
347{
348 EFI_STATUS Status;
349 UINT32 Data[2];
350 UINT32 UsbStatus;
351 UINTN DataLength;
352
353 DataLength = 8;
354
355 ZeroMem (Data, sizeof (Data));
356
357 Status = UsbRndisDevice->UsbIo->UsbSyncInterruptTransfer (
358 UsbRndisDevice->UsbIo,
359 UsbRndisDevice->InterrupEndpoint,
360 &Data,
361 &DataLength,
362 0x20,
363 &UsbStatus
364 );
365
366 return Status;
367}
368
381EFIAPI
384 OUT EFI_MAC_ADDRESS *MacAddress
385 )
386{
387 EFI_STATUS Status;
388 USB_RNDIS_DEVICE *UsbRndisDevice;
389 USB_ETHERNET_FUN_DESCRIPTOR UsbEthDescriptor;
390 CHAR16 *Data;
391 CHAR16 *DataPtr;
392 CHAR16 TmpStr[1];
393 UINT8 Index;
394 UINT8 Hi;
395 UINT8 Low;
396
397 REMOTE_NDIS_QUERY_MAC_MSG RndisQueryMsg;
398 REMOTE_NDIS_QUERY_MAC_CMPLT RndisQueryMsgCmplt;
399
400 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
401
402 ZeroMem (&RndisQueryMsg, sizeof (REMOTE_NDIS_QUERY_MAC_MSG));
403 ZeroMem (&RndisQueryMsgCmplt, sizeof (REMOTE_NDIS_QUERY_MAC_CMPLT));
404
405 RndisQueryMsg.QueryMsg.MessageType = RNDIS_QUERY_MSG;
406 RndisQueryMsg.QueryMsg.MessageLength = sizeof (REMOTE_NDIS_QUERY_MAC_MSG);
407 RndisQueryMsg.QueryMsg.RequestID = UsbRndisDevice->RequestId;
408 RndisQueryMsg.QueryMsg.Oid = OID_802_3_CURRENT_ADDRESS;
409
410 RndisQueryMsgCmplt.QueryCmplt.MessageType = RNDIS_QUERY_CMPLT;
411 RndisQueryMsgCmplt.QueryCmplt.MessageLength = sizeof (REMOTE_NDIS_QUERY_MAC_CMPLT);
412
413 Status = RndisControlMsg (
414 UsbRndisDevice,
415 (REMOTE_NDIS_MSG_HEADER *)&RndisQueryMsg,
416 (REMOTE_NDIS_MSG_HEADER *)&RndisQueryMsgCmplt
417 );
418 if (!EFI_ERROR (Status)) {
419 DEBUG ((DEBUG_INFO, "Success to get Mac address from RNDIS message.\n"));
420 for (Index = 0; Index < PXE_HWADDR_LEN_ETHER; Index++) {
421 MacAddress->Addr[Index] = RndisQueryMsgCmplt.Addr[Index];
422 }
423
424 UsbRndisDevice->RequestId++;
425 return Status;
426 }
427
428 // If it is not support the OID_802_3_CURRENT_ADDRESS.
429 // To check USB Ethernet functional Descriptor
430 Status = This->UsbEthFunDescriptor (This, &UsbEthDescriptor);
431 if (EFI_ERROR (Status)) {
432 DEBUG ((DEBUG_ERROR, "%a:UsbEthFunDescriptor status = %r\n", __func__, Status));
433 return Status;
434 }
435
436 Status = UsbRndisDevice->UsbIo->UsbGetStringDescriptor (
437 UsbRndisDevice->UsbIo,
438 0x409, // English-US Language ID
439 UsbEthDescriptor.MacAddress,
440 &Data
441 );
442 if (EFI_ERROR (Status)) {
443 DEBUG ((DEBUG_ERROR, "%a:UsbGetStringDescriptor status = %r\n", __func__, Status));
444 return Status;
445 }
446
447 DataPtr = Data;
448 for (Index = 0; Index < PXE_HWADDR_LEN_ETHER; Index++) {
449 CopyMem (TmpStr, DataPtr, sizeof (CHAR16));
450 DataPtr++;
451 Hi = (UINT8)StrHexToUintn (TmpStr);
452 CopyMem (TmpStr, DataPtr, sizeof (CHAR16));
453 DataPtr++;
454 Low = (UINT8)StrHexToUintn (TmpStr);
455 MacAddress->Addr[Index] = (Hi << 4) | Low;
456 }
457
458 return Status;
459}
460
472EFIAPI
475 OUT UINTN *BulkSize
476 )
477{
478 EFI_STATUS Status;
479 USB_ETHERNET_FUN_DESCRIPTOR UsbEthFunDescriptor;
480 USB_RNDIS_DEVICE *UsbRndisDevice;
481
484
485 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
486
487 ZeroMem (&RndisQueryMsg, sizeof (REMOTE_NDIS_QUERY_MAX_TOTAL_SIZE_MSG));
488 ZeroMem (&RndisQueryMsgCmplt, sizeof (REMOTE_NDIS_QUERY_MAX_TOTAL_SIZE_CMPLT));
489
490 RndisQueryMsg.QueryMsg.MessageType = RNDIS_QUERY_MSG;
491 RndisQueryMsg.QueryMsg.MessageLength = sizeof (REMOTE_NDIS_QUERY_MAX_TOTAL_SIZE_MSG);
492 RndisQueryMsg.QueryMsg.RequestID = UsbRndisDevice->RequestId;
493 RndisQueryMsg.QueryMsg.Oid = OID_GEN_MAXIMUM_TOTAL_SIZE;
494
495 RndisQueryMsgCmplt.QueryCmplt.MessageType = RNDIS_QUERY_CMPLT;
496 RndisQueryMsgCmplt.QueryCmplt.MessageLength = sizeof (REMOTE_NDIS_QUERY_MAX_TOTAL_SIZE_CMPLT);
497
498 Status = RndisControlMsg (
499 UsbRndisDevice,
500 (REMOTE_NDIS_MSG_HEADER *)&RndisQueryMsg,
501 (REMOTE_NDIS_MSG_HEADER *)&RndisQueryMsgCmplt
502 );
503 if (!EFI_ERROR (Status)) {
504 DEBUG ((DEBUG_INFO, "Success to get Max Total size : %X \n", RndisQueryMsgCmplt.MaxTotalSize));
505 *BulkSize = RndisQueryMsgCmplt.MaxTotalSize;
506 UsbRndisDevice->RequestId++;
507 return Status;
508 }
509
510 Status = This->UsbEthFunDescriptor (This, &UsbEthFunDescriptor);
511 if (EFI_ERROR (Status)) {
512 return Status;
513 }
514
515 *BulkSize = (UINTN)UsbEthFunDescriptor.MaxSegmentSize;
516 return Status;
517}
518
531EFIAPI
534 OUT USB_HEADER_FUN_DESCRIPTOR *UsbHeaderFunDescriptor
535 )
536{
537 EFI_STATUS Status;
538 USB_RNDIS_DEVICE *UsbRndisDevice;
539
540 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
541
542 if (UsbHeaderFunDescriptor == NULL) {
543 return EFI_INVALID_PARAMETER;
544 }
545
546 Status = GetFunctionalDescriptor (
547 UsbRndisDevice->Config,
548 HEADER_FUN_DESCRIPTOR,
549 UsbHeaderFunDescriptor
550 );
551 return Status;
552}
553
566EFIAPI
569 OUT USB_UNION_FUN_DESCRIPTOR *UsbUnionFunDescriptor
570 )
571{
572 EFI_STATUS Status;
573 USB_RNDIS_DEVICE *UsbRndisDevice;
574
575 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
576
577 if (UsbUnionFunDescriptor == NULL) {
578 return EFI_INVALID_PARAMETER;
579 }
580
581 Status = GetFunctionalDescriptor (
582 UsbRndisDevice->Config,
583 UNION_FUN_DESCRIPTOR,
584 UsbUnionFunDescriptor
585 );
586 return Status;
587}
588
605EFIAPI
608 OUT USB_ETHERNET_FUN_DESCRIPTOR *UsbEthFunDescriptor
609 )
610{
611 EFI_STATUS Status;
612 USB_RNDIS_DEVICE *UsbRndisDevice;
613
614 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
615
616 if (UsbEthFunDescriptor == NULL) {
617 return EFI_INVALID_PARAMETER;
618 }
619
620 Status = GetFunctionalDescriptor (
621 UsbRndisDevice->Config,
622 ETHERNET_FUN_DESCRIPTOR,
623 UsbEthFunDescriptor
624 );
625 return Status;
626}
627
644EFIAPI
647 IN UINT16 Value,
648 IN VOID *McastAddr
649 )
650{
651 EFI_STATUS Status;
653 UINT32 TransStatus;
654 USB_ETHERNET_FUN_DESCRIPTOR UsbEthFunDescriptor;
655 USB_RNDIS_DEVICE *UsbRndisDevice;
656
657 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
658
659 Status = This->UsbEthFunDescriptor (This, &UsbEthFunDescriptor);
660 if (EFI_ERROR (Status)) {
661 return Status;
662 }
663
664 if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) == 0) {
665 return EFI_UNSUPPORTED;
666 }
667
668 Request.RequestType = USB_ETHERNET_SET_REQ_TYPE;
669 Request.Request = SET_ETH_MULTICAST_FILTERS_REQ;
670 Request.Value = Value;
671 Request.Index = UsbRndisDevice->NumOfInterface;
672 Request.Length = Value * 6;
673
674 return UsbRndisDevice->UsbIo->UsbControlTransfer (
675 UsbRndisDevice->UsbIo,
676 &Request,
677 EfiUsbDataOut,
678 USB_ETHERNET_TRANSFER_TIMEOUT,
679 McastAddr,
680 Request.Length,
681 &TransStatus
682 );
683}
684
702EFIAPI
705 IN UINT16 Value,
706 IN UINT16 Length,
707 IN VOID *PatternFilter
708 )
709{
711 UINT32 TransStatus;
712 USB_RNDIS_DEVICE *UsbRndisDevice;
713
714 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
715
716 Request.RequestType = USB_ETHERNET_SET_REQ_TYPE;
717 Request.Request = SET_ETH_POWER_MANAGEMENT_PATTERN_FILTER_REQ;
718 Request.Value = Value;
719 Request.Index = UsbRndisDevice->NumOfInterface;
720 Request.Length = Length;
721
722 return UsbRndisDevice->UsbIo->UsbControlTransfer (
723 UsbRndisDevice->UsbIo,
724 &Request,
725 EfiUsbDataOut,
726 USB_ETHERNET_TRANSFER_TIMEOUT,
727 PatternFilter,
728 Length,
729 &TransStatus
730 );
731}
732
749EFIAPI
752 IN UINT16 Value,
753 OUT BOOLEAN *PatternActive
754 )
755{
757 UINT32 TransStatus;
758 USB_RNDIS_DEVICE *UsbRndisDevice;
759
760 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
761
762 Request.RequestType = USB_ETHERNET_GET_REQ_TYPE;
763 Request.Request = GET_ETH_POWER_MANAGEMENT_PATTERN_FILTER_REQ;
764 Request.Value = Value;
765 Request.Index = UsbRndisDevice->NumOfInterface;
766 Request.Length = USB_ETH_POWER_FILTER_LENGTH;
767
768 return UsbRndisDevice->UsbIo->UsbControlTransfer (
769 UsbRndisDevice->UsbIo,
770 &Request,
771 EfiUsbDataIn,
772 USB_ETHERNET_TRANSFER_TIMEOUT,
773 PatternActive,
774 USB_ETH_POWER_FILTER_LENGTH,
775 &TransStatus
776 );
777}
778
779BIT_MAP gTable[] = {
780 { PXE_OPFLAGS_RECEIVE_FILTER_UNICAST, NDIS_PACKET_TYPE_DIRECTED },
781 { PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST, NDIS_PACKET_TYPE_BROADCAST },
782 { PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST, NDIS_PACKET_TYPE_MULTICAST },
783 { PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS, NDIS_PACKET_TYPE_PROMISCUOUS },
784 { PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST, NDIS_PACKET_TYPE_ALL_MULTICAST },
785};
786
795VOID
797 IN UINT16 Value,
798 OUT UINT16 *CdcFilter
799 )
800{
801 UINT32 Index;
802 UINT32 Count;
803
804 Count = sizeof (gTable)/sizeof (gTable[0]);
805
806 for (Index = 0; (Index < Count) && (gTable[Index].Src != 0); Index++) {
807 if (gTable[Index].Src & Value) {
808 *CdcFilter |= gTable[Index].Dst;
809 }
810 }
811}
812
824EFIAPI
826 IN PXE_CDB *Cdb,
827 IN NIC_DATA *Nic
828 )
829{
830 EFI_STATUS Status;
831 UINT8 *McastList;
832 UINT8 Count;
833 UINT8 Index1;
834 UINT8 Index2;
835 UINT64 CpbAddr;
836 UINT32 CpbSize;
837 UINT16 SetFilter;
839 USB_ETHERNET_FUN_DESCRIPTOR UsbEthFunDescriptor;
840
841 Count = 0;
842 CpbAddr = Cdb->CPBaddr;
843 CpbSize = Cdb->CPBsize;
844 SetFilter = (UINT16)(Cdb->OpFlags & 0x1F);
845 Cpb = (PXE_CPB_RECEIVE_FILTERS *)(UINTN)CpbAddr;
846
847 // The Cpb could be NULL.(ref:PXE_CPBADDR_NOT_USED)
848 Nic->RxFilter = (UINT8)SetFilter;
849
851 if (Cpb != NULL) {
852 Nic->McastCount = (UINT8)(CpbSize / PXE_MAC_LENGTH);
853 CopyMem (&Nic->McastList, Cpb, Nic->McastCount);
854 } else {
855 Nic->McastCount = 0;
856 }
857
858 Nic->UsbEth->UsbEthFunDescriptor (Nic->UsbEth, &UsbEthFunDescriptor);
859 if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) == 0) {
861 DEBUG ((DEBUG_INFO, "SetUsbEthPacketFilter Nic %lx Nic->UsbEth %lx ", Nic, Nic->UsbEth));
862 Nic->UsbEth->SetUsbEthPacketFilter (Nic->UsbEth, Nic->RxFilter);
863 } else {
864 Status = gBS->AllocatePool (EfiBootServicesData, Nic->McastCount * 6, (VOID **)&McastList);
865 if (EFI_ERROR (Status)) {
866 return PXE_STATCODE_INVALID_PARAMETER;
867 }
868
869 if (Cpb != NULL) {
870 for (Index1 = 0; Index1 < Nic->McastCount; Index1++) {
871 for (Index2 = 0; Index2 < 6; Index2++) {
872 McastList[Count++] = Cpb->MCastList[Index1][Index2];
873 }
874 }
875 }
876
878 if (Cpb != NULL) {
879 Nic->UsbEth->SetUsbEthMcastFilter (Nic->UsbEth, Nic->McastCount, McastList);
880 }
881
882 Nic->UsbEth->SetUsbEthPacketFilter (Nic->UsbEth, Nic->RxFilter);
883 FreePool (McastList);
884 }
885 }
886
887 return EFI_SUCCESS;
888}
889
904EFIAPI
907 IN UINT16 Value
908 )
909{
910 return EFI_SUCCESS;
911}
912
928EFIAPI
931 IN UINT16 FeatureSelector,
932 OUT VOID *Statistic
933 )
934{
935 return EFI_SUCCESS;
936}
937
948EFIAPI
950 IN PXE_CDB *Cdb,
951 IN NIC_DATA *Nic
952 )
953{
954 EFI_STATUS Status;
955
956 DEBUG ((DEBUG_INFO, "RndisUndiStart Nic %lx Cdb %lx Nic State %x\n", Nic, Cdb, Nic->State));
957
958 // Issue Rndis Reset and bring the device to RNDIS_BUS_INITIALIZED state
959 Status = RndisUndiReset (Cdb, Nic);
960 if (EFI_ERROR (Status)) {
961 RndisUndiReset (Cdb, Nic);
962 }
963
964 Status = RndisUndiInitialize (Cdb, Nic);
965 if (EFI_ERROR (Status)) {
966 RndisUndiInitialize (Cdb, Nic);
967 }
968
969 RndisUndiShutdown (Cdb, Nic);
970
971 return EFI_SUCCESS;
972}
973
983EFIAPI
985 IN PXE_CDB *Cdb,
986 IN NIC_DATA *Nic
987 )
988{
989 DEBUG ((DEBUG_INFO, "RndisUndiStop State %x\n", Nic->State));
990 return EFI_SUCCESS;
991}
992
1003EFIAPI
1005 IN PXE_CDB *Cdb,
1006 IN NIC_DATA *Nic
1007 )
1008{
1009 EDKII_USB_ETHERNET_PROTOCOL *UsbEthDevice;
1010 USB_RNDIS_DEVICE *UsbRndisDevice;
1012
1013 DEBUG ((DEBUG_INFO, "RndisUndiGetInitInfo\n"));
1014
1015 UsbEthDevice = Nic->UsbEth;
1016 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (UsbEthDevice);
1017
1018 Db = (PXE_DB_GET_INIT_INFO *)(UINTN)Cdb->DBaddr;
1019
1020 Db->FrameDataLen = UsbRndisDevice->MaxTransferSize - sizeof (REMOTE_NDIS_PACKET_MSG) - PXE_MAC_HEADER_LEN_ETHER;
1021 // Limit Max MTU size to 1500 bytes as RNDIS spec.
1022 if (Db->FrameDataLen > PXE_MAX_TXRX_UNIT_ETHER) {
1023 Db->FrameDataLen = PXE_MAX_TXRX_UNIT_ETHER;
1024 }
1025
1026 DEBUG ((DEBUG_INFO, "Db->FrameDataLen %x\n", Db->FrameDataLen));
1027
1028 return EFI_SUCCESS;
1029}
1030
1041EFIAPI
1043 IN PXE_CDB *Cdb,
1044 IN NIC_DATA *Nic
1045 )
1046{
1047 DEBUG ((DEBUG_INFO, "RndisUndiGetConfigInfo\n"));
1048 return EFI_SUCCESS;
1049}
1050
1062EFIAPI
1064 IN PXE_CDB *Cdb,
1065 IN NIC_DATA *Nic
1066 )
1067{
1068 EDKII_USB_ETHERNET_PROTOCOL *UsbEthDriver;
1069 USB_RNDIS_DEVICE *UsbRndisDevice;
1070 REMOTE_NDIS_INITIALIZE_MSG RndisInitMsg;
1071 REMOTE_NDIS_INITIALIZE_CMPLT RndisInitMsgCmplt;
1072 EFI_STATUS Status;
1073
1074 DEBUG ((DEBUG_INFO, "RndisUndiInitialize\n"));
1075
1076 UsbEthDriver = Nic->UsbEth;
1077 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (UsbEthDriver);
1078
1079 ZeroMem (&RndisInitMsg, sizeof (REMOTE_NDIS_INITIALIZE_MSG));
1080 ZeroMem (&RndisInitMsgCmplt, sizeof (REMOTE_NDIS_INITIALIZE_CMPLT));
1081
1082 RndisInitMsg.MessageType = RNDIS_INITIALIZE_MSG;
1083 RndisInitMsg.MessageLength = sizeof (REMOTE_NDIS_INITIALIZE_MSG);
1084 RndisInitMsg.RequestID = UsbRndisDevice->RequestId;
1085 RndisInitMsg.MajorVersion = RNDIS_MAJOR_VERSION;
1086 RndisInitMsg.MinorVersion = RNDIS_MINOR_VERSION;
1087 RndisInitMsg.MaxTransferSize = RNDIS_MAX_TRANSFER_SIZE;
1088
1089 RndisInitMsgCmplt.MessageType = RNDIS_INITIALIZE_CMPLT;
1090 RndisInitMsgCmplt.MessageLength = sizeof (REMOTE_NDIS_INITIALIZE_CMPLT);
1091
1092 Status = RndisControlMsg (UsbRndisDevice, (REMOTE_NDIS_MSG_HEADER *)&RndisInitMsg, (REMOTE_NDIS_MSG_HEADER *)&RndisInitMsgCmplt);
1093
1094 UsbRndisDevice->RequestId++;
1095
1096 if (EFI_ERROR (Status) || (RndisInitMsgCmplt.Status & 0x80000000)) {
1097 return Status;
1098 }
1099
1100 // Only Wired Medium is supported
1101 if (RndisInitMsgCmplt.Medium) {
1102 return EFI_UNSUPPORTED;
1103 }
1104
1105 UsbRndisDevice->Medium = RndisInitMsgCmplt.Medium;
1106 UsbRndisDevice->MaxPacketsPerTransfer = RndisInitMsgCmplt.MaxPacketsPerTransfer;
1107 UsbRndisDevice->MaxTransferSize = RndisInitMsgCmplt.MaxTransferSize;
1108 UsbRndisDevice->PacketAlignmentFactor = RndisInitMsgCmplt.PacketAlignmentFactor;
1109
1110 DEBUG ((DEBUG_INFO, "Medium : %x \n", RndisInitMsgCmplt.Medium));
1111 DEBUG ((DEBUG_INFO, "MaxPacketsPerTransfer : %x \n", RndisInitMsgCmplt.MaxPacketsPerTransfer));
1112 DEBUG ((DEBUG_INFO, "MaxTransferSize : %x\n", RndisInitMsgCmplt.MaxTransferSize));
1113 DEBUG ((DEBUG_INFO, "PacketAlignmentFactor : %x\n", RndisInitMsgCmplt.PacketAlignmentFactor));
1114
1115 return Status;
1116}
1117
1129EFIAPI
1131 IN PXE_CDB *Cdb,
1132 IN NIC_DATA *Nic
1133 )
1134{
1135 EDKII_USB_ETHERNET_PROTOCOL *UsbEthDriver;
1136 USB_RNDIS_DEVICE *UsbRndisDevice;
1137 REMOTE_NDIS_RESET_MSG RndisResetMsg;
1138 REMOTE_NDIS_RESET_CMPLT RndisResetCmplt;
1139 EFI_STATUS Status;
1140
1141 DEBUG ((DEBUG_INFO, "RndisUndiReset\n"));
1142
1143 UsbEthDriver = Nic->UsbEth;
1144 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (UsbEthDriver);
1145
1146 ZeroMem (&RndisResetMsg, sizeof (REMOTE_NDIS_RESET_MSG));
1147 ZeroMem (&RndisResetCmplt, sizeof (REMOTE_NDIS_RESET_CMPLT));
1148
1149 RndisResetMsg.MessageType = RNDIS_RESET_MSG;
1150 RndisResetMsg.MessageLength = sizeof (REMOTE_NDIS_RESET_MSG);
1151
1152 RndisResetCmplt.MessageType = RNDIS_RESET_CMPLT;
1153 RndisResetCmplt.MessageLength = sizeof (REMOTE_NDIS_RESET_CMPLT);
1154
1155 Status = RndisControlMsg (UsbRndisDevice, (REMOTE_NDIS_MSG_HEADER *)&RndisResetMsg, (REMOTE_NDIS_MSG_HEADER *)&RndisResetCmplt);
1156
1157 UsbRndisDevice->RequestId = 1; // Let's start with 1
1158
1159 if (EFI_ERROR (Status) || (RndisResetCmplt.Status & 0x80000000)) {
1160 return EFI_DEVICE_ERROR;
1161 }
1162
1163 return EFI_SUCCESS;
1164}
1165
1176EFIAPI
1178 IN PXE_CDB *Cdb,
1179 IN NIC_DATA *Nic
1180 )
1181{
1182 EDKII_USB_ETHERNET_PROTOCOL *UsbEthDriver;
1183 USB_RNDIS_DEVICE *UsbRndisDevice;
1184 REMOTE_NDIS_HALT_MSG RndisHltMsg;
1185 EFI_STATUS Status;
1186
1187 DEBUG ((DEBUG_INFO, "RndisUndiShutdown\n"));
1188
1189 UsbEthDriver = Nic->UsbEth;
1190 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (UsbEthDriver);
1191
1192 ZeroMem (&RndisHltMsg, sizeof (REMOTE_NDIS_HALT_MSG));
1193
1194 RndisHltMsg.MessageType = RNDIS_HLT_MSG;
1195 RndisHltMsg.MessageLength = sizeof (REMOTE_NDIS_HALT_MSG);
1196
1197 Status = RndisControlMsg (UsbRndisDevice, (REMOTE_NDIS_MSG_HEADER *)&RndisHltMsg, NULL);
1198
1199 if (Status == EFI_DEVICE_ERROR) {
1200 Status = EFI_SUCCESS;
1201 }
1202
1203 UsbRndisDevice->RequestId = 1;
1204 return Status;
1205}
1206
1217EFIAPI
1219 IN PXE_CDB *Cdb,
1220 IN NIC_DATA *Nic
1221 )
1222{
1223 Cdb->StatFlags &= ~(PXE_STATFLAGS_GET_STATUS_NO_MEDIA);
1224 return EFI_SUCCESS;
1225}
1226
1240EFIAPI
1242 IN PXE_CDB *Cdb,
1244 IN VOID *BulkOutData,
1245 IN OUT UINTN *DataLength
1246 )
1247{
1248 EFI_STATUS Status;
1249 USB_RNDIS_DEVICE *UsbRndisDevice;
1250 REMOTE_NDIS_PACKET_MSG *RndisPacketMsg;
1251 UINTN TransferLength;
1252
1253 DEBUG ((DEBUG_INFO, "RndisUndiTransmit DataLength : %x\n", *DataLength));
1254
1255 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
1256
1257 RndisPacketMsg = AllocateZeroPool (sizeof (REMOTE_NDIS_PACKET_MSG) + *DataLength);
1258 if (RndisPacketMsg == NULL) {
1259 return EFI_OUT_OF_RESOURCES;
1260 }
1261
1262 RndisPacketMsg->MessageType = RNDIS_PACKET_MSG;
1263 RndisPacketMsg->MessageLength = sizeof (REMOTE_NDIS_PACKET_MSG) + (UINT32)*DataLength;
1264 RndisPacketMsg->DataOffset = sizeof (REMOTE_NDIS_PACKET_MSG) - 8;
1265 RndisPacketMsg->DataLength = (UINT32)*DataLength;
1266
1267 CopyMem (
1268 ((UINT8 *)RndisPacketMsg) + sizeof (REMOTE_NDIS_PACKET_MSG),
1269 BulkOutData,
1270 *DataLength
1271 );
1272
1273 TransferLength = RndisPacketMsg->MessageLength;
1274
1275 Status = RndisTransmitDataMsg (
1276 UsbRndisDevice,
1277 (REMOTE_NDIS_MSG_HEADER *)RndisPacketMsg,
1278 &TransferLength
1279 );
1280
1281 DEBUG ((DEBUG_INFO, "\nRndisUndiTransmit TransferLength %lx\n", TransferLength));
1282
1283 FreePool (RndisPacketMsg);
1284
1285 return Status;
1286}
1287
1303EFIAPI
1305 IN PXE_CDB *Cdb,
1307 IN OUT VOID *BulkInData,
1308 IN OUT UINTN *DataLength
1309 )
1310{
1311 EFI_STATUS Status;
1312 USB_RNDIS_DEVICE *UsbRndisDevice;
1313 REMOTE_NDIS_PACKET_MSG *RndisPacketMsg;
1314 UINTN TransferLength;
1315 VOID *Buffer;
1316 PACKET_LIST *HeadPacket;
1317 PACKET_LIST *PacketList;
1318
1319 // Check if there is any outstanding packet to receive
1320 // The buffer allocated has a linked List followed by the packet.
1321
1322 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (This);
1323 Buffer = NULL;
1324 HeadPacket = NULL;
1325
1326 while (1) {
1327 Buffer = AllocateZeroPool (sizeof (PACKET_LIST) + sizeof (REMOTE_NDIS_PACKET_MSG) + UsbRndisDevice->MaxTransferSize);
1328 if (Buffer == NULL) {
1329 return EFI_OUT_OF_RESOURCES;
1330 }
1331
1332 RndisPacketMsg = (REMOTE_NDIS_PACKET_MSG *)(sizeof (PACKET_LIST) + (UINT8 *)Buffer);
1333 PacketList = (PACKET_LIST *)Buffer;
1334 PacketList->PacketStartBuffer = (UINT8 *)Buffer + sizeof (PACKET_LIST);
1335 // Save the original address for freeing it up
1336 PacketList->OrgBuffer = (UINT8 *)Buffer;
1337 TransferLength = UsbRndisDevice->MaxTransferSize;
1338
1339 Status = RndisReceiveDataMsg (
1340 UsbRndisDevice,
1341 (REMOTE_NDIS_MSG_HEADER *)RndisPacketMsg,
1342 &TransferLength
1343 );
1344
1345 if (EFI_ERROR (Status) || (TransferLength == 0)) {
1346 FreePool (Buffer);
1347 break;
1348 }
1349
1350 // Collect all the RNDIS packet in Linked list.
1351 if ((RndisPacketMsg->MessageType == RNDIS_PACKET_MSG) &&
1352 (RndisPacketMsg->DataOffset == sizeof (REMOTE_NDIS_PACKET_MSG) - RNDIS_RESERVED_BYTE_LENGTH) &&
1353 (TransferLength >= RndisPacketMsg->MessageLength))
1354 {
1355 // Insert Packet
1356 PacketList->RemainingLength = TransferLength;
1357 InsertTailList (&UsbRndisDevice->ReceivePacketList, Buffer);
1358 } else {
1359 FreePool (Buffer);
1360 }
1361 }
1362
1363 while (!IsListEmpty (&UsbRndisDevice->ReceivePacketList)) {
1364 HeadPacket = (PACKET_LIST *)GetFirstNode (&UsbRndisDevice->ReceivePacketList);
1365
1366 RndisPacketMsg = (REMOTE_NDIS_PACKET_MSG *)(UINT8 *)HeadPacket->PacketStartBuffer;
1367
1368 PrintRndisMsg ((REMOTE_NDIS_MSG_HEADER *)RndisPacketMsg);
1369
1370 // Check whether the packet is valid RNDIS packet.
1371 if ((HeadPacket->RemainingLength > sizeof (REMOTE_NDIS_PACKET_MSG)) && (RndisPacketMsg->MessageType == RNDIS_PACKET_MSG) &&
1372 (RndisPacketMsg->DataOffset == (sizeof (REMOTE_NDIS_PACKET_MSG) - RNDIS_RESERVED_BYTE_LENGTH)) &&
1373 (HeadPacket->RemainingLength >= RndisPacketMsg->MessageLength))
1374 {
1375 if (*DataLength >= RndisPacketMsg->DataLength) {
1376 CopyMem (
1377 BulkInData,
1378 (UINT8 *)RndisPacketMsg + (RndisPacketMsg->DataOffset + RNDIS_RESERVED_BYTE_LENGTH),
1379 RndisPacketMsg->DataLength
1380 );
1381
1382 *DataLength = RndisPacketMsg->DataLength;
1383
1384 HeadPacket->RemainingLength = HeadPacket->RemainingLength - RndisPacketMsg->MessageLength;
1385 HeadPacket->PacketStartBuffer = (UINT8 *)RndisPacketMsg + RndisPacketMsg->MessageLength;
1386
1387 return EFI_SUCCESS;
1388 } else {
1389 *DataLength = RndisPacketMsg->DataLength;
1390 return EFI_BUFFER_TOO_SMALL;
1391 }
1392 }
1393
1394 RemoveEntryList (&HeadPacket->PacketList);
1395 FreePool ((PACKET_LIST *)HeadPacket->OrgBuffer);
1396 }
1397
1398 return EFI_NOT_FOUND;
1399}
1400
1412EFIAPI
1414 IN PXE_CDB *Cdb,
1415 IN NIC_DATA *Nic
1416 )
1417{
1418 DEBUG ((DEBUG_INFO, "RndisDummyReturn called\n"));
1419 return EFI_SUCCESS;
1420}
1421
1434 IN USB_RNDIS_DEVICE *UsbRndisDevice,
1435 IN REMOTE_NDIS_MSG_HEADER *RndisMsg,
1436 OUT REMOTE_NDIS_MSG_HEADER *RndisMsgResponse
1437 )
1438{
1439 EFI_USB_IO_PROTOCOL *UsbIo;
1441 UINT32 UsbStatus;
1442 EFI_STATUS Status;
1443 UINT32 SaveResponseType;
1444 UINT32 SaveResponseLength;
1445 UINT32 Index;
1446 REMOTE_NDIS_INITIALIZE_CMPLT *RndisInitCmplt;
1447
1448 UsbIo = UsbRndisDevice->UsbIo;
1449 SaveResponseType = 0;
1450 SaveResponseLength = 0;
1451 RndisInitCmplt = (REMOTE_NDIS_INITIALIZE_CMPLT *)RndisMsgResponse;
1452
1453 if (RndisMsgResponse != NULL) {
1454 SaveResponseType = RndisMsgResponse->MessageType;
1455 SaveResponseLength = RndisMsgResponse->MessageLength;
1456 }
1457
1458 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
1459
1460 DevReq.RequestType = USB_REQ_TYPE_CLASS | USB_TARGET_INTERFACE;
1461 DevReq.Request = SEND_ENCAPSULATED_COMMAND;
1462 DevReq.Value = 0;
1463 DevReq.Index = 0;
1464 DevReq.Length = (UINT16)RndisMsg->MessageLength;
1465
1466 PrintRndisMsg (RndisMsg);
1467
1468 Status = UsbIo->UsbControlTransfer (
1469 UsbIo,
1470 &DevReq,
1471 EfiUsbDataOut,
1472 USB_ETHERNET_TRANSFER_TIMEOUT,
1473 RndisMsg,
1474 RndisMsg->MessageLength,
1475 &UsbStatus
1476 );
1477
1478 DEBUG ((DEBUG_INFO, "RndisControlMsg: UsbStatus : %x Status : %r RndisMsgResponse : %lx\n", UsbStatus, Status, RndisMsgResponse));
1479
1480 // Error or no response expected
1481 if ((EFI_ERROR (Status)) || (RndisMsgResponse == NULL)) {
1482 DEBUG ((DEBUG_INFO, "RndisControlMsg: UsbStatus : %x Status : %r\n", UsbStatus, Status));
1483 return Status;
1484 }
1485
1486 for (Index = 0; Index < (RNDIS_CONTROL_TIMEOUT/100); Index++) {
1487 ReadRndisResponseInterrupt (UsbRndisDevice);
1488 ZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
1489
1490 DevReq.RequestType = USB_ENDPOINT_DIR_IN | USB_REQ_TYPE_CLASS | USB_TARGET_INTERFACE;
1491 DevReq.Request = GET_ENCAPSULATED_RESPONSE;
1492 DevReq.Value = 0;
1493 DevReq.Index = 0;
1494 DevReq.Length = (UINT16)RndisMsgResponse->MessageLength;
1495
1496 Status = UsbIo->UsbControlTransfer (
1497 UsbIo,
1498 &DevReq,
1499 EfiUsbDataIn,
1500 USB_ETHERNET_TRANSFER_TIMEOUT,
1501 RndisMsgResponse,
1502 RndisMsgResponse->MessageLength,
1503 &UsbStatus
1504 );
1505
1506 DEBUG ((DEBUG_INFO, "RndisControlMsg Response: UsbStatus : %x Status : %r \n", UsbStatus, Status));
1507
1508 PrintRndisMsg (RndisMsgResponse);
1509
1510 if (!EFI_ERROR (Status)) {
1511 if ((RndisInitCmplt->RequestID != ((REMOTE_NDIS_INITIALIZE_CMPLT *)RndisMsg)->RequestID) || (RndisInitCmplt->MessageType != SaveResponseType)) {
1512 DEBUG ((DEBUG_INFO, "Retry the response\n"));
1513
1514 RndisMsgResponse->MessageType = SaveResponseType;
1515 RndisMsgResponse->MessageLength = SaveResponseLength;
1516 continue;
1517 }
1518 }
1519
1520 return Status;
1521 }
1522
1523 DEBUG ((DEBUG_INFO, "RndisControlMsg: TimeOut\n"));
1524
1525 return EFI_TIMEOUT;
1526}
1527
1540 IN USB_RNDIS_DEVICE *UsbRndisDevice,
1541 IN REMOTE_NDIS_MSG_HEADER *RndisMsg,
1542 IN OUT UINTN *TransferLength
1543 )
1544{
1545 EFI_STATUS Status;
1546 UINT32 UsbStatus;
1547
1548 if (UsbRndisDevice->BulkInEndpoint == 0) {
1549 GetEndpoint (UsbRndisDevice->UsbIoCdcData, UsbRndisDevice);
1550 }
1551
1552 PrintRndisMsg (RndisMsg);
1553
1554 Status = UsbRndisDevice->UsbIoCdcData->UsbBulkTransfer (
1555 UsbRndisDevice->UsbIoCdcData,
1556 UsbRndisDevice->BulkOutEndpoint,
1557 RndisMsg,
1558 TransferLength,
1559 USB_TX_ETHERNET_BULK_TIMEOUT,
1560 &UsbStatus
1561 );
1562
1563 if (Status == EFI_SUCCESS) {
1564 gStopBulkInCnt = MAXIMUM_STOPBULKIN_CNT; // After sending cmd ,we will polling receive package for MAXIMUM_STOPBULKIN_CNT times
1565 }
1566
1567 return Status;
1568}
1569
1582 IN USB_RNDIS_DEVICE *UsbRndisDevice,
1583 IN OUT REMOTE_NDIS_MSG_HEADER *RndisMsg,
1584 IN OUT UINTN *TransferLength
1585 )
1586{
1587 EFI_STATUS Status;
1588 UINT32 UsbStatus;
1589
1590 UsbStatus = 0;
1591
1592 if (UsbRndisDevice->BulkInEndpoint == 0) {
1593 GetEndpoint (UsbRndisDevice->UsbIoCdcData, UsbRndisDevice);
1594 }
1595
1596 // Use gStopBulkInCnt to stop BulkIn command
1597 if ((gStopBulkInCnt != 0) || LAN_BULKIN_CMD_CONTROL) {
1598 Status = UsbRndisDevice->UsbIoCdcData->UsbBulkTransfer (
1599 UsbRndisDevice->UsbIoCdcData,
1600 UsbRndisDevice->BulkInEndpoint,
1601 RndisMsg,
1602 TransferLength,
1603 USB_RX_ETHERNET_BULK_TIMEOUT,
1604 &UsbStatus
1605 );
1606
1607 if (!EFI_ERROR (Status)) {
1608 gStopBulkInCnt = MINIMUM_STOPBULKIN_CNT;
1609 } else {
1610 gStopBulkInCnt--;
1611 }
1612 } else {
1613 Status = EFI_TIMEOUT;
1614 *TransferLength = 0;
1615 gBlockBulkInCnt++;
1616 }
1617
1618 if (gBlockBulkInCnt > BULKIN_CMD_POLLING_CNT) {
1619 gStopBulkInCnt = MINIMUM_STOPBULKIN_CNT;
1620 gBlockBulkInCnt = 0;
1621 }
1622
1623 PrintRndisMsg (RndisMsg);
1624
1625 return Status;
1626}
1627
1634VOID
1636 IN REMOTE_NDIS_MSG_HEADER *RndisMsg
1637 )
1638{
1639 UINTN Length;
1640 REMOTE_NDIS_QUERY_CMPLT *RndisQueryCmplt;
1641
1642 Length = 0;
1643
1644 switch (RndisMsg->MessageType) {
1645 case RNDIS_PACKET_MSG:
1646 DEBUG ((DEBUG_INFO, "RNDIS_PACKET_MSG:\n"));
1647 Length = sizeof (REMOTE_NDIS_PACKET_MSG) + 0x14;
1648 break;
1649 case RNDIS_INITIALIZE_MSG:
1650 DEBUG ((DEBUG_INFO, "RNDIS_INITIALIZE_MSG:\n"));
1651 Length = sizeof (REMOTE_NDIS_INITIALIZE_MSG);
1652 break;
1653 case RNDIS_INITIALIZE_CMPLT:
1654 DEBUG ((DEBUG_INFO, "RNDIS_INITIALIZE_CMPLT:\n"));
1655 Length = sizeof (REMOTE_NDIS_INITIALIZE_CMPLT);
1656 break;
1657 case RNDIS_HLT_MSG:
1658 DEBUG ((DEBUG_INFO, "RNDIS_HLT_MSG:\n"));
1659 Length = sizeof (REMOTE_NDIS_HALT_MSG);
1660 break;
1661 case RNDIS_QUERY_MSG:
1662 DEBUG ((DEBUG_INFO, "RNDIS_QUERY_MSG:\n"));
1663 Length = sizeof (REMOTE_NDIS_QUERY_MSG);
1664 break;
1665 case RNDIS_QUERY_CMPLT:
1666 DEBUG ((DEBUG_INFO, "RNDIS_QUERY_CMPLT:\n"));
1667 RndisQueryCmplt = (REMOTE_NDIS_QUERY_CMPLT *)RndisMsg;
1668 Length = sizeof (REMOTE_NDIS_QUERY_CMPLT) + RndisQueryCmplt->InformationBufferLength;
1669 break;
1670 case RNDIS_SET_MSG:
1671 DEBUG ((DEBUG_INFO, "RNDIS_SET_MSG:\n"));
1672 Length = sizeof (REMOTE_NDIS_SET_MSG);
1673 break;
1674 case RNDIS_SET_CMPLT:
1675 DEBUG ((DEBUG_INFO, "RNDIS_SET_CMPLT:\n"));
1676 Length = sizeof (REMOTE_NDIS_SET_CMPLT);
1677 break;
1678 case RNDIS_RESET_MSG:
1679 DEBUG ((DEBUG_INFO, "RNDIS_RESET_MSG:\n"));
1680 Length = sizeof (REMOTE_NDIS_RESET_MSG);
1681 break;
1682 case RNDIS_RESET_CMPLT:
1683 DEBUG ((DEBUG_INFO, "RNDIS_RESET_CMPLT:\n"));
1684 Length = sizeof (REMOTE_NDIS_RESET_CMPLT);
1685 break;
1686 case RNDIS_INDICATE_STATUS_MSG:
1687 DEBUG ((DEBUG_INFO, "RNDIS_INDICATE_STATUS_MSG:\n"));
1688 Length = sizeof (REMOTE_NDIS_INDICATE_STATUS_MSG);
1689 break;
1690 case RNDIS_KEEPALIVE_MSG:
1691 DEBUG ((DEBUG_INFO, "RNDIS_KEEPALIVE_MSG:\n"));
1692 Length = sizeof (REMOTE_NDIS_KEEPALIVE_MSG);
1693 break;
1694 case RNDIS_KEEPALIVE_CMPLT:
1695 DEBUG ((DEBUG_INFO, "RNDIS_KEEPALIVE_CMPLT:\n"));
1696 Length = sizeof (REMOTE_NDIS_KEEPALIVE_CMPLT);
1697 }
1698
1699 if (Length) {
1700 UINTN Index;
1701 Index = 0;
1702 for ( ; Length; Length -= 4, Index++) {
1703 DEBUG ((DEBUG_INFO, "%8X\t", *((UINT32 *)RndisMsg + Index)));
1704 if (((Index % 4) == 3) && (Index != 0)) {
1705 DEBUG ((DEBUG_INFO, "\n"));
1706 }
1707
1708 if ((Length < 8) && (Length > 4)) {
1709 UINT32 Data32;
1710 Index++;
1711 Data32 = *((UINT32 *)RndisMsg + Index);
1712 DEBUG ((DEBUG_INFO, "%8X\t", Data32));
1713 break;
1714 }
1715 }
1716
1717 if ((Index % 4) != 0) {
1718 DEBUG ((DEBUG_INFO, "\n"));
1719 }
1720 }
1721}
UINT64 UINTN
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
UINTN EFIAPI StrHexToUintn(IN CONST CHAR16 *String)
Definition: String.c:508
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINT16 SetFilter(IN NIC_DATA *Nic, IN UINT16 SetFilter, IN UINT64 CpbAddr, IN UINT32 CpbSize)
Definition: PxeFunction.c:804
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ EfiBootServicesData
#define PXE_OPFLAGS_RECEIVE_FILTER_UNICAST
Definition: UefiPxe.h:284
#define PXE_STATFLAGS_GET_STATUS_NO_MEDIA
Definition: UefiPxe.h:574
#define PXE_OPFLAGS_RECEIVE_FILTER_PROMISCUOUS
Definition: UefiPxe.h:302
#define PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST
Definition: UefiPxe.h:297
#define PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST
Definition: UefiPxe.h:308
#define PXE_OPFLAGS_RECEIVE_FILTER_BROADCAST
Definition: UefiPxe.h:290
EFI_STATUS EFIAPI UsbSetInterface(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Interface, IN UINT16 AlternateSetting, OUT UINT32 *Status)
Definition: UsbDxeLib.c:212
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)
Definition: UsbDxeLib.c:41
EFI_STATUS EFIAPI GetUsbEthMacAddress(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT EFI_MAC_ADDRESS *MacAddress)
EFI_STATUS EFIAPI InterruptCallback(IN VOID *Data, IN UINTN DataLength, IN VOID *Context, IN UINT32 Status)
EFI_STATUS GetFunctionalDescriptor(IN EFI_USB_CONFIG_DESCRIPTOR *Config, IN UINT8 FunDescriptorType, OUT VOID *DataBuffer)
EFI_STATUS EFIAPI GetUsbRndisFunDescriptor(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT USB_ETHERNET_FUN_DESCRIPTOR *UsbEthFunDescriptor)
EFI_STATUS EFIAPI RndisUndiShutdown(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS EFIAPI GetUsbRndisPowerFilter(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 Value, OUT BOOLEAN *PatternActive)
EFI_STATUS EFIAPI GetRndisStatistic(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 FeatureSelector, OUT VOID *Statistic)
EFI_STATUS EFIAPI RndisUndiReceiveFilter(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS EFIAPI RndisUndiStop(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS EFIAPI RndisUndiReceive(IN PXE_CDB *Cdb, IN EDKII_USB_ETHERNET_PROTOCOL *This, IN OUT VOID *BulkInData, IN OUT UINTN *DataLength)
EFI_STATUS EFIAPI ReadRndisResponseInterrupt(IN USB_RNDIS_DEVICE *UsbRndisDevice)
EFI_STATUS EFIAPI SetUsbRndisPacketFilter(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 Value)
EFI_STATUS EFIAPI RndisUndiReset(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS EFIAPI RndisUndiGetConfigInfo(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS LoadAllDescriptor(IN EFI_USB_IO_PROTOCOL *UsbIo, OUT EFI_USB_CONFIG_DESCRIPTOR **ConfigDesc)
EFI_STATUS EFIAPI SetUsbRndisMcastFilter(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 Value, IN VOID *McastAddr)
EFI_STATUS RndisReceiveDataMsg(IN USB_RNDIS_DEVICE *UsbRndisDevice, IN OUT REMOTE_NDIS_MSG_HEADER *RndisMsg, IN OUT UINTN *TransferLength)
EFI_STATUS EFIAPI UsbRndisInterrupt(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN BOOLEAN IsNewTransfer, IN UINTN PollingInterval, IN EFI_USB_DEVICE_REQUEST *Requst)
EFI_STATUS EFIAPI UsbEthBulkSize(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT UINTN *BulkSize)
EFI_STATUS EFIAPI RndisDummyReturn(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS EFIAPI RndisUndiGetStatus(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS EFIAPI RndisUndiInitialize(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS EFIAPI GetUsbHeaderFunDescriptor(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT USB_HEADER_FUN_DESCRIPTOR *UsbHeaderFunDescriptor)
EFI_STATUS RndisTransmitDataMsg(IN USB_RNDIS_DEVICE *UsbRndisDevice, IN REMOTE_NDIS_MSG_HEADER *RndisMsg, IN OUT UINTN *TransferLength)
EFI_STATUS EFIAPI RndisUndiGetInitInfo(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS RndisControlMsg(IN USB_RNDIS_DEVICE *UsbRndisDevice, IN REMOTE_NDIS_MSG_HEADER *RndisMsg, OUT REMOTE_NDIS_MSG_HEADER *RndisMsgResponse)
EFI_STATUS EFIAPI RndisUndiStart(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
EFI_STATUS EFIAPI RndisUndiTransmit(IN PXE_CDB *Cdb, IN EDKII_USB_ETHERNET_PROTOCOL *This, IN VOID *BulkOutData, IN OUT UINTN *DataLength)
EFI_STATUS EFIAPI SetUsbRndisPowerFilter(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 Value, IN UINT16 Length, IN VOID *PatternFilter)
VOID PrintRndisMsg(IN REMOTE_NDIS_MSG_HEADER *RndisMsg)
VOID GetEndpoint(IN EFI_USB_IO_PROTOCOL *UsbIo, IN OUT USB_RNDIS_DEVICE *UsbRndisDevice)
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)
PXE_MAC_ADDR MCastList[MAX_MCAST_ADDRESS_CNT]
Definition: UefiPxe.h:1321
PXE_UINT32 FrameDataLen
Definition: UefiPxe.h:1105