On 11/05/13 10:59, Michael Lorer wrote:
> Hello,
>
>
>
> I’m working on an application that is using the UEFI networkstack to
> communicate with a TFTP server.
>
> That is working just fine on a mainboard with only one network interface.
>
> But now I have a problem on a mainboard with two Intel network interfaces.
>
>
>
> At first I’m doing something like that to decide on which interface a
> network cable is attached:
>
> // Locate all network device handles
>
> Status = gBS->LocateHandleBuffer (ByProtocol,
> &gEfiManagedNetworkServiceBindingProtocolGuid,
>
> NULL, &HandleCount,
> &Handles);
>
>
>
> // Try to configure one of all handles
>
> for (Index = 0; Index < HandleCount; Index++) {
>
> // Get media status
>
> GetNicMediaStatus (Handles[Index],
> &TempNicInfo->MediaPresentSupported, &TempNicInfo->MediaPresent);
>
>
>
> if (TempNicInfo->MediaPresent == 1) {
>
> NicInfo->Handle = Handles[Index];
>
> NicInfo->MediaPresentSupported =
> TempNicInfo->MediaPresentSupported;
>
> NicInfo->MediaPresent = TempNicInfo->MediaPresent;
>
> InsertTailList (NicInfoList, &NicInfo->Link);
>
> }
>
> }
>
>
>
> Depending on the MediaPresent-Flag I chose what NIC to use.
>
> Later on in my source code I have to open the MTFTP4-protocol. I’m doing
> it this way:
>
> // Search available handles for MTFTP4 protocol
>
> Status = gBS->LocateHandleBuffer (
>
> ByProtocol,
>
> &gEfiMtftp4ProtocolGuid,
>
> NULL,
>
> &HandleNum,
>
> &HandleBuffer
>
> );
>
>
>
> // Chose the right protocol here
>
> Status = gBS->OpenProtocol (
>
> HandleBuffer[0], //
> Index 0 is hardcoded here. How can I chose which handle to use?
>
> &gEfiMtftp4ProtocolGuid,
>
> &This->Mtftp4,
>
> This->ImageHandle,
>
> NULL,
>
> EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
>
> );
>
>
>
> As you can see right now I always chose HandleBuffer[0] although
> HandleNum is returning that there are 2 handles available. Depending on
> where a network cable is connected I must use Index ‘0’ or ‘1’. But how
> can I determine which one to use automatically?
>
> Does the index number for the MTFTP4 protocol always match the index
> number of the EfiManagedNetworkServiceBindingProtocol? Or is there a
> better way to do this?
You're calling LocateHandleBuffer() twice, with different protocols,
independently of each other. You need their intersection. I'd recommend
keeping one call only, and then to narrow down the results:
- get all handles supporting
gEfiManagedNetworkServiceBindingProtocolGuid (like now)
- for each handle returned:
- if link status is not supported, you might want to assume media
present, and proceed with the open below
- if link status is supported, and media is present,
proceed with the open below
- if link status is supported, but media isn't present, continue with
the next handle
- simply try to open the handle with gEfiMtftp4ProtocolGuid. If it
succeeds, use it to transfer data.
You want to filter handles for the simultaneous presence of two
protocols. AFAIK there's no direct UEFI service providing this, you need
to start with a simple search, and narrow down the results.
Regarding the Attribute parameter of the OpenProtocol() call: only
EFI_OPEN_PROTOCOL_GET_PROTOCOL seems appropriate (you mentioned working
on an application).
Hopefully others will chime in too...
Laszlo
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel