TianoCore EDK2 master
Loading...
Searching...
No Matches
UsbRndis.c
Go to the documentation of this file.
1
9#include "UsbRndis.h"
10
11EFI_DRIVER_BINDING_PROTOCOL gUsbRndisDriverBinding = {
15 USB_RNDIS_DRIVER_VERSION,
16 NULL,
17 NULL
18};
19
29BOOLEAN
32 )
33{
34 EFI_STATUS Status;
35 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
36
37 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &InterfaceDescriptor);
38 if (EFI_ERROR (Status)) {
39 return FALSE;
40 }
41
42 // Check specific device/RNDIS and CDC-DATA
43 if (((InterfaceDescriptor.InterfaceClass == USB_CDC_CLASS) &&
44 (InterfaceDescriptor.InterfaceSubClass == USB_CDC_ACM_SUBCLASS) &&
45 (InterfaceDescriptor.InterfaceProtocol == USB_VENDOR_PROTOCOL)) || \
46 ((InterfaceDescriptor.InterfaceClass == USB_MISC_CLASS) &&
47 (InterfaceDescriptor.InterfaceSubClass == USB_RNDIS_SUBCLASS) &&
48 (InterfaceDescriptor.InterfaceProtocol == USB_RNDIS_ETHERNET_PROTOCOL)) || \
49 ((InterfaceDescriptor.InterfaceClass == USB_CDC_DATA_CLASS) &&
50 (InterfaceDescriptor.InterfaceSubClass == USB_CDC_DATA_SUBCLASS) &&
51 (InterfaceDescriptor.InterfaceProtocol == USB_NO_CLASS_PROTOCOL))
52 )
53 {
54 return TRUE;
55 }
56
57 return FALSE;
58}
59
68BOOLEAN
71 )
72{
73 EFI_STATUS Status;
74 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
75
76 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &InterfaceDescriptor);
77 if (EFI_ERROR (Status)) {
78 return FALSE;
79 }
80
81 // Check for specific device/RNDIS and CDC-DATA
82 if (((InterfaceDescriptor.InterfaceClass == USB_CDC_CLASS) &&
83 (InterfaceDescriptor.InterfaceSubClass == USB_CDC_ACM_SUBCLASS) &&
84 (InterfaceDescriptor.InterfaceProtocol == USB_VENDOR_PROTOCOL)) || \
85 ((InterfaceDescriptor.InterfaceClass == USB_MISC_CLASS) &&
86 (InterfaceDescriptor.InterfaceSubClass == USB_RNDIS_SUBCLASS) &&
87 (InterfaceDescriptor.InterfaceProtocol == USB_RNDIS_ETHERNET_PROTOCOL))
88 )
89 {
90 return TRUE;
91 }
92
93 return FALSE;
94}
95
108 IN EFI_DEVICE_PATH_PROTOCOL *UsbRndisDataPath,
109 IN EFI_DEVICE_PATH_PROTOCOL *UsbCdcDataPath
110 )
111{
112 DEBUG ((DEBUG_VERBOSE, "IsSameDevice Entry \n"));
113 while (1) {
114 if (IsDevicePathEnd (NextDevicePathNode (UsbRndisDataPath))) {
115 if (((USB_DEVICE_PATH *)UsbRndisDataPath)->ParentPortNumber ==
116 ((USB_DEVICE_PATH *)UsbCdcDataPath)->ParentPortNumber)
117 {
118 return EFI_SUCCESS;
119 } else {
120 return EFI_UNSUPPORTED;
121 }
122 } else {
123 if (CompareMem (UsbCdcDataPath, UsbRndisDataPath, sizeof (EFI_DEVICE_PATH_PROTOCOL)) != 0) {
124 return EFI_UNSUPPORTED;
125 }
126
127 UsbRndisDataPath = NextDevicePathNode (UsbRndisDataPath);
128 UsbCdcDataPath = NextDevicePathNode (UsbCdcDataPath);
129 }
130 }
131
132 DEBUG ((DEBUG_VERBOSE, "IsSameDevice Exit \n"));
133}
134
144BOOLEAN
147 )
148{
149 EFI_STATUS Status;
150 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
151
152 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &InterfaceDescriptor);
153 if (EFI_ERROR (Status)) {
154 return FALSE;
155 }
156
157 // Check for CDC-DATA
158 if ((InterfaceDescriptor.InterfaceClass == USB_CDC_DATA_CLASS) &&
159 (InterfaceDescriptor.InterfaceSubClass == USB_CDC_DATA_SUBCLASS) &&
160 (InterfaceDescriptor.InterfaceProtocol == USB_NO_CLASS_PROTOCOL))
161 {
162 return TRUE;
163 }
164
165 return FALSE;
166}
167
177BOOLEAN
180 )
181{
182 EFI_STATUS Status;
183 EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
184
185 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &InterfaceDescriptor);
186 if (EFI_ERROR (Status)) {
187 return FALSE;
188 }
189
190 // Check for Rndis
191 if ((InterfaceDescriptor.InterfaceClass == USB_CDC_CLASS) &&
192 (InterfaceDescriptor.InterfaceSubClass == USB_CDC_ACM_SUBCLASS) &&
193 (InterfaceDescriptor.InterfaceProtocol == USB_VENDOR_PROTOCOL))
194 {
195 return TRUE;
196 }
197
198 return FALSE;
199}
200
214 IN EFI_DEVICE_PATH_PROTOCOL *UsbCdcDataPath,
215 OUT USB_RNDIS_DEVICE **UsbRndisDevice
216 )
217{
218 EFI_STATUS Status;
219 UINTN Index;
220 UINTN HandleCount;
221 EFI_HANDLE *HandleBuffer;
222 EDKII_USB_ETHERNET_PROTOCOL *UsbEthDevice;
223 EFI_DEVICE_PATH_PROTOCOL *UsbRndisDataPath;
224 EFI_USB_IO_PROTOCOL *UsbIo;
225 BOOLEAN IsRndisInterfaceFlag;
226
227 IsRndisInterfaceFlag = FALSE;
228
229 Status = gBS->LocateHandleBuffer (
231 &gEdkIIUsbEthProtocolGuid,
232 NULL,
233 &HandleCount,
234 &HandleBuffer
235 );
236 if (EFI_ERROR (Status)) {
237 return Status;
238 }
239
240 for (Index = 0; Index < HandleCount; Index++) {
241 Status = gBS->HandleProtocol (
242 HandleBuffer[Index],
243 &gEdkIIUsbEthProtocolGuid,
244 (VOID **)&UsbEthDevice
245 );
246 if (EFI_ERROR (Status)) {
247 continue;
248 }
249
250 Status = gBS->HandleProtocol (
251 HandleBuffer[Index],
252 &gEfiUsbIoProtocolGuid,
253 (VOID **)&UsbIo
254 );
255 if (EFI_ERROR (Status)) {
256 continue;
257 }
258
259 IsRndisInterfaceFlag = IsRndisInterface (UsbIo);
260 if (IsRndisInterfaceFlag == FALSE) {
261 continue;
262 }
263
264 Status = gBS->HandleProtocol (
265 HandleBuffer[Index],
266 &gEfiDevicePathProtocolGuid,
267 (VOID **)&UsbRndisDataPath
268 );
269 if (EFI_ERROR (Status)) {
270 continue;
271 }
272
273 Status = IsSameDevice (UsbRndisDataPath, UsbCdcDataPath);
274
275 DEBUG ((DEBUG_VERBOSE, "Rndis IsSameDevice %r\n", Status));
276
277 if (!EFI_ERROR (Status)) {
278 *UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (UsbEthDevice);
279 FreePool (HandleBuffer);
280 return EFI_SUCCESS;
281 }
282 } // End of For loop
283
284 FreePool (HandleBuffer);
285 return EFI_NOT_FOUND;
286}
287
296VOID
298 IN USB_RNDIS_DEVICE *UsbRndisDevice
299 )
300{
301 EFI_STATUS Status;
302 UINTN Index;
303 UINTN HandleCount;
304 EFI_HANDLE *HandleBuffer;
305 EFI_USB_IO_PROTOCOL *UsbIo;
306 EFI_DEVICE_PATH_PROTOCOL *UsbRndisDataPath;
307 EFI_DEVICE_PATH_PROTOCOL *UsbCdcDataPath;
308
309 // Find the parent RNDIS and update the UsbIo for the CDC device
310 Status = gBS->HandleProtocol (
311 UsbRndisDevice->UsbRndisHandle,
312 &gEfiDevicePathProtocolGuid,
313 (VOID **)&UsbRndisDataPath
314 );
315
316 if (EFI_ERROR (Status)) {
317 return;
318 }
319
320 Status = gBS->LocateHandleBuffer (
322 &gEfiUsbIoProtocolGuid,
323 NULL,
324 &HandleCount,
325 &HandleBuffer
326 );
327 if (EFI_ERROR (Status)) {
328 return;
329 }
330
331 for (Index = 0; Index < HandleCount; Index++) {
332 Status = gBS->HandleProtocol (
333 HandleBuffer[Index],
334 &gEfiUsbIoProtocolGuid,
335 (VOID **)&UsbIo
336 );
337 ASSERT_EFI_ERROR (Status);
338
339 if (IsUsbCdcData (UsbIo)) {
340 DEBUG ((DEBUG_VERBOSE, "Rndis FindMatchingCdcData CDCData interface found\n"));
341
342 Status = gBS->HandleProtocol (
343 HandleBuffer[Index],
344 &gEfiDevicePathProtocolGuid,
345 (VOID **)&UsbCdcDataPath
346 );
347 if (EFI_ERROR (Status)) {
348 DEBUG ((DEBUG_VERBOSE, "Rndis CDCData DevicePath not found\n"));
349 FreePool (HandleBuffer);
350 return;
351 }
352
353 Status = IsSameDevice (UsbRndisDataPath, UsbCdcDataPath);
354 DEBUG ((DEBUG_VERBOSE, "Rndis IsSameDevice %r\n", Status));
355 if (!EFI_ERROR (Status)) {
356 UsbRndisDevice->UsbCdcDataHandle = HandleBuffer[Index];
357 UsbRndisDevice->UsbIoCdcData = UsbIo;
358 GetEndpoint (UsbRndisDevice->UsbIoCdcData, UsbRndisDevice);
359 FreePool (HandleBuffer);
360 return;
361 }
362 }
363 } // End of For loop
364
365 FreePool (HandleBuffer);
366}
367
381EFIAPI
383 IN EFI_HANDLE CdcHandle,
384 OUT EFI_USB_IO_PROTOCOL **CdcUsbIo,
385 OUT EFI_HANDLE *RndisHandle
386 )
387{
388 EFI_STATUS Status;
389 UINTN Index;
390 UINTN HandleCount;
391 EFI_HANDLE *HandleBuffer;
392 EFI_USB_IO_PROTOCOL *UsbIo;
393 EFI_DEVICE_PATH_PROTOCOL *UsbRndisDataPath;
394 EFI_DEVICE_PATH_PROTOCOL *UsbCdcDataPath;
395
396 // Find the parent RNDIS and update the UsbIo for the CDC device
397 Status = gBS->HandleProtocol (
398 CdcHandle,
399 &gEfiDevicePathProtocolGuid,
400 (VOID **)&UsbCdcDataPath
401 );
402
403 if (EFI_ERROR (Status)) {
404 return Status;
405 }
406
407 Status = gBS->LocateHandleBuffer (
409 &gEfiUsbIoProtocolGuid,
410 NULL,
411 &HandleCount,
412 &HandleBuffer
413 );
414 if (EFI_ERROR (Status)) {
415 return Status;
416 }
417
418 for (Index = 0; Index < HandleCount; Index++) {
419 Status = gBS->HandleProtocol (
420 HandleBuffer[Index],
421 &gEfiUsbIoProtocolGuid,
422 (VOID **)&UsbIo
423 );
424 if (EFI_ERROR (Status)) {
425 return Status;
426 }
427
428 if (IsUsbRndis (UsbIo)) {
429 Status = gBS->HandleProtocol (
430 HandleBuffer[Index],
431 &gEfiDevicePathProtocolGuid,
432 (VOID **)&UsbRndisDataPath
433 );
434 if (EFI_ERROR (Status)) {
435 DEBUG ((DEBUG_ERROR, "Usb Rndis DevicePath not found\n"));
436 break;
437 }
438
439 Status = IsSameDevice (UsbRndisDataPath, UsbCdcDataPath);
440
441 if (!EFI_ERROR (Status)) {
442 *RndisHandle = HandleBuffer[Index];
443 *CdcUsbIo = UsbIo;
444 FreePool (HandleBuffer);
445 return Status;
446 }
447 }
448 } // End of For loop
449
450 FreePool (HandleBuffer);
451
452 return EFI_NOT_FOUND;
453}
454
469EFIAPI
472 IN EFI_HANDLE ControllerHandle,
473 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
474 )
475{
476 EFI_STATUS Status;
477 EFI_USB_IO_PROTOCOL *UsbIo;
478
479 Status = gBS->OpenProtocol (
480 ControllerHandle,
481 &gEfiUsbIoProtocolGuid,
482 (VOID **)&UsbIo,
483 This->DriverBindingHandle,
484 ControllerHandle,
485 EFI_OPEN_PROTOCOL_BY_DRIVER
486 );
487 if (EFI_ERROR (Status)) {
488 return Status;
489 }
490
491 Status = IsSupportedDevice (UsbIo) ? EFI_SUCCESS : EFI_UNSUPPORTED;
492
493 gBS->CloseProtocol (
494 ControllerHandle,
495 &gEfiUsbIoProtocolGuid,
496 This->DriverBindingHandle,
497 ControllerHandle
498 );
499 return Status;
500}
501
517EFIAPI
520 IN EFI_HANDLE ControllerHandle,
521 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
522 )
523{
524 EFI_STATUS Status;
525 USB_RNDIS_DEVICE *UsbRndisDevice;
526 EFI_DEVICE_PATH_PROTOCOL *UsbEthPath;
527 EFI_USB_IO_PROTOCOL *UsbIo;
529 EFI_HANDLE RndisHandle;
530
531 RndisHandle = ControllerHandle;
532
533 Status = gBS->OpenProtocol (
534 ControllerHandle,
535 &gEfiUsbIoProtocolGuid,
536 (VOID **)&UsbIo,
537 This->DriverBindingHandle,
538 ControllerHandle,
539 EFI_OPEN_PROTOCOL_BY_DRIVER
540 );
541 if (EFI_ERROR (Status)) {
542 return Status;
543 }
544
545 Status = gBS->OpenProtocol (
546 ControllerHandle,
547 &gEfiDevicePathProtocolGuid,
548 (VOID **)&UsbEthPath,
549 This->DriverBindingHandle,
550 ControllerHandle,
551 EFI_OPEN_PROTOCOL_BY_DRIVER
552 );
553 if (EFI_ERROR (Status)) {
554 gBS->CloseProtocol (
555 ControllerHandle,
556 &gEfiUsbIoProtocolGuid,
557 This->DriverBindingHandle,
558 ControllerHandle
559 );
560 return Status;
561 }
562
563 gBS->CloseProtocol (
564 ControllerHandle,
565 &gEfiDevicePathProtocolGuid,
566 This->DriverBindingHandle,
567 ControllerHandle
568 );
569
570 // Controls come here for RNDIS and CDC. If it is CDC, check whether RNDIS is present on the same controller or not.
571 if (IsUsbCdcData (UsbIo)) {
572 DEBUG ((DEBUG_INFO, "Rndis CDCData interface found\n"));
573
574 // Find the parent RNDIS and update the UsbIo for the CDC device
575 Status = UpdateRndisDevice (
576 UsbEthPath,
577 &UsbRndisDevice
578 );
579
580 if (!EFI_ERROR (Status)) {
581 DEBUG ((DEBUG_INFO, "Rndis Matching interface found\n"));
582 UsbRndisDevice->UsbCdcDataHandle = ControllerHandle;
583 UsbRndisDevice->UsbIoCdcData = UsbIo;
584 GetEndpoint (UsbRndisDevice->UsbIoCdcData, UsbRndisDevice);
585 return Status;
586 } else {
587 // Check if RnDis exist
588 Status = FindMatchingRndisDev (
589 ControllerHandle,
590 &UsbIo,
591 &RndisHandle
592 );
593
594 if (EFI_ERROR (Status)) {
595 gBS->CloseProtocol (
596 ControllerHandle,
597 &gEfiUsbIoProtocolGuid,
598 This->DriverBindingHandle,
599 ControllerHandle
600 );
601 return Status;
602 }
603 }
604 }
605
606 UsbRndisDevice = AllocateZeroPool (sizeof (USB_RNDIS_DEVICE));
607
608 if (!UsbRndisDevice) {
609 DEBUG ((DEBUG_ERROR, "AllocateZeroPool Fail\n"));
610
611 gBS->CloseProtocol (
612 ControllerHandle,
613 &gEfiUsbIoProtocolGuid,
614 This->DriverBindingHandle,
615 ControllerHandle
616 );
617 return EFI_OUT_OF_RESOURCES;
618 }
619
620 Status = LoadAllDescriptor (
621 UsbIo,
622 &UsbRndisDevice->Config
623 );
624 if (EFI_ERROR (Status)) {
625 DEBUG ((DEBUG_ERROR, "%a:LoadAllDescriptor status = %r\n", __func__, Status));
626 gBS->CloseProtocol (
627 ControllerHandle,
628 &gEfiUsbIoProtocolGuid,
629 This->DriverBindingHandle,
630 ControllerHandle
631 );
632 FreePool (UsbRndisDevice);
633 return Status;
634 }
635
636 Status = UsbIo->UsbGetInterfaceDescriptor (
637 UsbIo,
638 &Interface
639 );
640 if (EFI_ERROR (Status)) {
641 DEBUG ((DEBUG_ERROR, "%a:UsbGetInterfaceDescriptor status = %r\n", __func__, Status));
642 gBS->CloseProtocol (
643 ControllerHandle,
644 &gEfiUsbIoProtocolGuid,
645 This->DriverBindingHandle,
646 ControllerHandle
647 );
648 FreePool (UsbRndisDevice->Config);
649 FreePool (UsbRndisDevice);
650 return Status;
651 }
652
653 UsbRndisDevice->Signature = USB_RNDIS_SIGNATURE;
654 UsbRndisDevice->NumOfInterface = Interface.InterfaceNumber;
655 UsbRndisDevice->UsbRndisHandle = RndisHandle;
656 UsbRndisDevice->UsbCdcDataHandle = 0;
657 UsbRndisDevice->UsbIo = UsbIo;
658 UsbRndisDevice->UsbEth.UsbEthReceive = RndisUndiReceive;
659 UsbRndisDevice->UsbEth.UsbEthTransmit = RndisUndiTransmit;
660 UsbRndisDevice->UsbEth.UsbEthInterrupt = UsbRndisInterrupt;
661 UsbRndisDevice->UsbEth.UsbEthMacAddress = GetUsbEthMacAddress;
662 UsbRndisDevice->UsbEth.UsbEthMaxBulkSize = UsbEthBulkSize;
663 UsbRndisDevice->UsbEth.UsbHeaderFunDescriptor = GetUsbHeaderFunDescriptor;
664 UsbRndisDevice->UsbEth.UsbUnionFunDescriptor = GetUsbUnionFunDescriptor;
665 UsbRndisDevice->UsbEth.UsbEthFunDescriptor = GetUsbRndisFunDescriptor;
666 UsbRndisDevice->UsbEth.SetUsbEthMcastFilter = SetUsbRndisMcastFilter;
667 UsbRndisDevice->UsbEth.SetUsbEthPowerPatternFilter = SetUsbRndisPowerFilter;
668 UsbRndisDevice->UsbEth.GetUsbEthPowerPatternFilter = GetUsbRndisPowerFilter;
669 UsbRndisDevice->UsbEth.SetUsbEthPacketFilter = SetUsbRndisPacketFilter;
670 UsbRndisDevice->UsbEth.GetUsbEthStatistic = GetRndisStatistic;
671
672 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiGetState = RndisDummyReturn;
673 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiStart = RndisUndiStart;
674 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiStop = RndisUndiStop;
675 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiGetInitInfo = RndisUndiGetInitInfo;
676 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiGetConfigInfo = RndisUndiGetConfigInfo;
677 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiInitialize = RndisUndiInitialize;
678 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiReset = RndisUndiReset;
679 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiShutdown = RndisUndiShutdown;
680 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiInterruptEnable = RndisDummyReturn;
681 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiReceiveFilter = RndisUndiReceiveFilter;
682 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiStationAddress = RndisDummyReturn;
683 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiStatistics = NULL;
684 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiMcastIp2Mac = RndisDummyReturn;
685 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiNvData = RndisDummyReturn;
686 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiGetStatus = RndisUndiGetStatus;
687 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiFillHeader = RndisDummyReturn;
688 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiTransmit = NULL;
689 UsbRndisDevice->UsbEth.UsbEthUndi.UsbEthUndiReceive = NULL;
690
691 UsbRndisDevice->MaxTransferSize = RNDIS_MAX_TRANSFER_SIZE;
692 UsbRndisDevice->MaxPacketsPerTransfer = 1;
693 UsbRndisDevice->PacketAlignmentFactor = 0;
694
695 InitializeListHead (&UsbRndisDevice->ReceivePacketList);
696
697 // This is a RNDIS interface. See whether CDC-DATA interface has already been connected or not
698 FindMatchingCdcData (UsbRndisDevice);
699
700 if (UsbRndisDevice->UsbIoCdcData) {
701 Status = gBS->InstallProtocolInterface (
702 &ControllerHandle,
703 &gEdkIIUsbEthProtocolGuid,
705 &(UsbRndisDevice->UsbEth)
706 );
707 if (EFI_ERROR (Status)) {
708 gBS->CloseProtocol (
709 ControllerHandle,
710 &gEfiUsbIoProtocolGuid,
711 This->DriverBindingHandle,
712 ControllerHandle
713 );
714
715 FreePool (UsbRndisDevice->Config);
716 FreePool (UsbRndisDevice);
717 return Status;
718 }
719
720 GetEndpoint (UsbRndisDevice->UsbIo, UsbRndisDevice);
721
722 DEBUG ((DEBUG_INFO, "Rndis DeviceHandle %r\n", UsbRndisDevice->UsbRndisHandle));
723 DEBUG ((DEBUG_INFO, "CDC DeviceHandle %r\n", UsbRndisDevice->UsbCdcDataHandle));
724 return EFI_SUCCESS;
725 }
726
727 FreePool (UsbRndisDevice->Config);
728 FreePool (UsbRndisDevice);
729
730 return EFI_SUCCESS;
731}
732
745EFIAPI
748 IN EFI_HANDLE ControllerHandle
749 )
750{
751 EFI_STATUS Status;
752 EFI_USB_IO_PROTOCOL *UsbIo;
753
754 Status = gBS->OpenProtocol (
755 ControllerHandle,
756 &gEfiUsbIoProtocolGuid,
757 (VOID **)&UsbIo,
758 This->DriverBindingHandle,
759 ControllerHandle,
760 EFI_OPEN_PROTOCOL_GET_PROTOCOL
761 );
762 if (EFI_ERROR (Status)) {
763 return Status;
764 }
765
766 if (IsUsbRndis (UsbIo)) {
767 Status = gBS->CloseProtocol (
768 ControllerHandle,
769 &gEfiUsbIoProtocolGuid,
770 This->DriverBindingHandle,
771 ControllerHandle
772 );
773 DEBUG ((DEBUG_ERROR, "Rndis ControllerHandle Stop %r\n", Status));
774 return Status;
775 }
776
777 return EFI_UNSUPPORTED;
778}
779
794EFIAPI
797 IN EFI_HANDLE ControllerHandle,
798 IN UINTN NumberOfChildren,
799 IN EFI_HANDLE *ChildHandleBuffer
800 )
801{
802 EFI_STATUS Status;
803 EDKII_USB_ETHERNET_PROTOCOL *UsbEthProtocol;
804 USB_RNDIS_DEVICE *UsbRndisDevice;
805
806 DEBUG ((DEBUG_INFO, "UsbRndisDriverStop ControllerHandle %lx\n", ControllerHandle));
807
808 Status = gBS->OpenProtocol (
809 ControllerHandle,
810 &gEdkIIUsbEthProtocolGuid,
811 (VOID **)&UsbEthProtocol,
812 This->DriverBindingHandle,
813 ControllerHandle,
814 EFI_OPEN_PROTOCOL_GET_PROTOCOL
815 );
816 if (EFI_ERROR (Status)) {
817 Status = CheckandStopRndisDevice (This, ControllerHandle);
818 return Status;
819 }
820
821 UsbRndisDevice = USB_RNDIS_DEVICE_FROM_THIS (UsbEthProtocol);
822
823 Status = gBS->CloseProtocol (
824 UsbRndisDevice->UsbCdcDataHandle,
825 &gEfiUsbIoProtocolGuid,
826 This->DriverBindingHandle,
827 UsbRndisDevice->UsbCdcDataHandle
828 );
829 if (EFI_ERROR (Status)) {
830 DEBUG ((DEBUG_ERROR, "%a:CloseProtocol status = %r\n", __func__, Status));
831 }
832
833 Status = gBS->UninstallProtocolInterface (
834 ControllerHandle,
835 &gEdkIIUsbEthProtocolGuid,
836 UsbEthProtocol
837 );
838 if (EFI_ERROR (Status)) {
839 return Status;
840 }
841
842 Status = gBS->CloseProtocol (
843 ControllerHandle,
844 &gEfiUsbIoProtocolGuid,
845 This->DriverBindingHandle,
846 ControllerHandle
847 );
848
849 FreePool (UsbRndisDevice->Config);
850 FreePool (UsbRndisDevice);
851
852 DEBUG ((DEBUG_INFO, "UsbRndisDriverStop %r\n", Status));
853 return Status;
854}
855
869EFIAPI
871 IN EFI_HANDLE ImageHandle,
872 IN EFI_SYSTEM_TABLE *SystemTable
873 )
874{
875 gUsbRndisDriverBinding.DriverBindingHandle = ImageHandle;
876 gUsbRndisDriverBinding.ImageHandle = ImageHandle;
877
878 return gBS->InstallMultipleProtocolInterfaces (
879 &gUsbRndisDriverBinding.DriverBindingHandle,
880 &gEfiDriverBindingProtocolGuid,
881 &gUsbRndisDriverBinding,
882 &gEfiComponentName2ProtocolGuid,
883 &gUsbRndisComponentName2,
884 NULL
885 );
886}
UINT64 UINTN
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#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 ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
@ ByProtocol
Definition: UefiSpec.h:1518
EFI_STATUS EFIAPI GetUsbEthMacAddress(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT EFI_MAC_ADDRESS *MacAddress)
VOID GetEndpoint(IN EFI_USB_IO_PROTOCOL *UsbIo, IN OUT USB_ETHERNET_DRIVER *UsbEthDriver)
EFI_STATUS LoadAllDescriptor(IN EFI_USB_IO_PROTOCOL *UsbIo, OUT EFI_USB_CONFIG_DESCRIPTOR **ConfigDesc)
EFI_STATUS EFIAPI GetUsbHeaderFunDescriptor(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT USB_HEADER_FUN_DESCRIPTOR *UsbHeaderFunDescriptor)
EFI_STATUS EFIAPI GetUsbUnionFunDescriptor(IN EDKII_USB_ETHERNET_PROTOCOL *This, OUT USB_UNION_FUN_DESCRIPTOR *UsbUnionFunDescriptor)
BOOLEAN IsUsbRndis(IN EFI_USB_IO_PROTOCOL *UsbIo)
Definition: UsbRndis.c:178
EFI_STATUS EFIAPI UsbRndisEntry(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: UsbRndis.c:870
EFI_STATUS EFIAPI UsbRndisDriverSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: UsbRndis.c:470
EFI_STATUS EFIAPI CheckandStopRndisDevice(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle)
Definition: UsbRndis.c:746
BOOLEAN IsRndisInterface(IN EFI_USB_IO_PROTOCOL *UsbIo)
Definition: UsbRndis.c:69
BOOLEAN IsSupportedDevice(IN EFI_USB_IO_PROTOCOL *UsbIo)
Definition: UsbRndis.c:30
EFI_STATUS EFIAPI UsbRndisDriverStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: UsbRndis.c:518
VOID FindMatchingCdcData(IN USB_RNDIS_DEVICE *UsbRndisDevice)
Definition: UsbRndis.c:297
EFI_STATUS UpdateRndisDevice(IN EFI_DEVICE_PATH_PROTOCOL *UsbCdcDataPath, OUT USB_RNDIS_DEVICE **UsbRndisDevice)
Definition: UsbRndis.c:213
EFI_STATUS IsSameDevice(IN EFI_DEVICE_PATH_PROTOCOL *UsbRndisDataPath, IN EFI_DEVICE_PATH_PROTOCOL *UsbCdcDataPath)
Definition: UsbRndis.c:107
BOOLEAN IsUsbCdcData(IN EFI_USB_IO_PROTOCOL *UsbIo)
Definition: UsbRndis.c:145
EFI_STATUS EFIAPI FindMatchingRndisDev(IN EFI_HANDLE CdcHandle, OUT EFI_USB_IO_PROTOCOL **CdcUsbIo, OUT EFI_HANDLE *RndisHandle)
Definition: UsbRndis.c:382
EFI_STATUS EFIAPI UsbRndisDriverStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
Definition: UsbRndis.c:795
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 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 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 EFIAPI SetUsbRndisMcastFilter(IN EDKII_USB_ETHERNET_PROTOCOL *This, IN UINT16 Value, IN VOID *McastAddr)
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 RndisUndiGetInitInfo(IN PXE_CDB *Cdb, IN NIC_DATA *Nic)
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)