iPXE
Data Structures | Functions | Variables
snponly.c File Reference

EFI chainloaded-device-only driver. More...

#include <string.h>
#include <errno.h>
#include <ipxe/init.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_utils.h>
#include <ipxe/efi/mnpnet.h>
#include <ipxe/efi/Protocol/SimpleNetwork.h>
#include <ipxe/efi/Protocol/NetworkInterfaceIdentifier.h>
#include "snpnet.h"
#include "nii.h"

Go to the source code of this file.

Data Structures

struct  chained_protocol
 A chainloaded protocol. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void chained_locate (struct chained_protocol *chained)
 Locate chainloaded protocol. More...
 
static int chained_supported (EFI_HANDLE device, struct chained_protocol *chained)
 Check to see if driver supports a device. More...
 
static int snponly_supported (EFI_HANDLE device)
 Check to see if driver supports a device. More...
 
static int niionly_supported (EFI_HANDLE device)
 Check to see if driver supports a device. More...
 
static int mnponly_supported (EFI_HANDLE device)
 Check to see if driver supports a device. More...
 
struct efi_driver snponly_driver __efi_driver (EFI_DRIVER_SNP)
 EFI SNP chainloading-device-only driver. More...
 
struct efi_driver niionly_driver __efi_driver (EFI_DRIVER_NII)
 EFI NII chainloading-device-only driver. More...
 
struct efi_driver mnponly_driver __efi_driver (EFI_DRIVER_MNP)
 EFI MNP chainloading-device-only driver. More...
 
static void chained_init (void)
 Initialise EFI chainloaded-device-only driver. More...
 
struct init_fn chained_init_fn __init_fn (INIT_LATE)
 EFI chainloaded-device-only initialisation function. More...
 

Variables

static struct chained_protocol chained_snp
 Chainloaded SNP protocol. More...
 
static struct chained_protocol chained_nii
 Chainloaded NII protocol. More...
 
static struct chained_protocol chained_mnp
 Chainloaded MNP protocol. More...
 

Detailed Description

EFI chainloaded-device-only driver.

Definition in file snponly.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ chained_locate()

static void chained_locate ( struct chained_protocol chained)
static

Locate chainloaded protocol.

Parameters
chainedChainloaded protocol

Definition at line 92 of file snponly.c.

92  {
95  void *match = NULL;
96  void *interface;
97  unsigned int skip;
98  int rc;
99 
100  /* Identify target device handle */
101  for ( skip = 0 ; ; skip++ ) {
102 
103  /* Locate handle supporting this protocol */
104  if ( ( rc = efi_locate_device ( device, chained->protocol,
105  &handle, skip ) ) != 0 ) {
106  if ( skip == 0 ) {
107  DBGC ( device, "CHAINED %s does not support "
108  "%s: %s\n", efi_handle_name ( device ),
109  efi_guid_ntoa ( chained->protocol ),
110  strerror ( rc ) );
111  }
112  break;
113  }
114 
115  /* Get protocol instance */
116  if ( ( rc = efi_open ( handle, chained->protocol,
117  &interface ) ) != 0 ) {
118  DBGC ( device, "CHAINED %s could not open %s on ",
120  efi_guid_ntoa ( chained->protocol ) );
121  DBGC ( device, "%s: %s\n",
122  efi_handle_name ( handle ), strerror ( rc ) );
123  break;
124  }
125 
126  /* Stop if we reach a non-matching protocol instance */
127  if ( match && ( match != interface ) ) {
128  DBGC ( device, "CHAINED %s found non-matching %s on ",
130  efi_guid_ntoa ( chained->protocol ) );
131  DBGC ( device, "%s\n", efi_handle_name ( handle ) );
132  break;
133  }
134 
135  /* Record this handle */
136  chained->device = handle;
137  match = interface;
138  DBGC ( device, "CHAINED %s found %s on ",
140  efi_guid_ntoa ( chained->protocol ) );
141  DBGC ( device, "%s\n", efi_handle_name ( chained->device ) );
142  }
143 }
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition: efi_init.c:38
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
EFI_HANDLE device
Target device handle.
Definition: snponly.c:65
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:76
An object interface.
Definition: interface.h:124
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:443
int efi_locate_device(EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip)
Locate parent device supporting a given protocol.
Definition: efi_utils.c:45
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:725
EFI_GUID * protocol
Protocol GUID.
Definition: snponly.c:47
uint16_t handle
Handle.
Definition: smbios.h:16
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Definition: efi.h:61
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:55

References DBGC, chained_protocol::device, EFI_LOADED_IMAGE_PROTOCOL::DeviceHandle, efi_guid_ntoa(), efi_handle_name(), efi_loaded_image, efi_locate_device(), efi_open, handle, NULL, chained_protocol::protocol, rc, and strerror().

Referenced by chained_init().

◆ chained_supported()

static int chained_supported ( EFI_HANDLE  device,
struct chained_protocol chained 
)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
chainedChainloaded protocol
Return values
rcReturn status code

Definition at line 152 of file snponly.c.

153  {
154  void *interface;
155  int rc;
156 
157  /* Get protocol */
158  if ( ( rc = efi_open ( device, chained->protocol,
159  &interface ) ) != 0 ) {
160  DBGCP ( device, "CHAINED %s is not a %s device\n",
162  efi_guid_ntoa ( chained->protocol ) );
163  return rc;
164  }
165 
166  /* Ignore non-matching handles */
167  if ( device != chained->device ) {
168  DBGC2 ( device, "CHAINED %s is not the chainloaded %s\n",
170  efi_guid_ntoa ( chained->protocol ) );
171  return -ENOTTY;
172  }
173  DBGC ( device, "CHAINED %s is the chainloaded %s\n",
175  efi_guid_ntoa ( chained->protocol ) );
176 
177  /* Check for wireless devices, if applicable */
178  if ( chained->inhibit_wifi &&
179  ( ( efi_test ( device, &efi_wifi2_protocol_guid ) ) == 0 ) ) {
180  DBGC ( device, "CHAINED %s is wireless: assuming vendor %s "
181  "driver is too unreliable to use\n",
183  efi_guid_ntoa ( chained->protocol ) );
184  return -ENOTTY;
185  }
186 
187  return 0;
188 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
EFI_HANDLE device
Target device handle.
Definition: snponly.c:65
int inhibit_wifi
Assume wireless devices are unusable.
Definition: snponly.c:67
#define efi_test(handle, protocol)
Test protocol existence.
Definition: efi.h:432
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:76
An object interface.
Definition: interface.h:124
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:443
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:725
EFI_GUID * protocol
Protocol GUID.
Definition: snponly.c:47
EFI_GUID efi_wifi2_protocol_guid
WiFi 2 protocol GUID.
Definition: efi_guid.c:436
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
#define DBGCP(...)
Definition: compiler.h:539

References DBGC, DBGC2, DBGCP, chained_protocol::device, efi_guid_ntoa(), efi_handle_name(), efi_open, efi_test, efi_wifi2_protocol_guid, ENOTTY, chained_protocol::inhibit_wifi, chained_protocol::protocol, and rc.

Referenced by mnponly_supported(), niionly_supported(), and snponly_supported().

◆ snponly_supported()

static int snponly_supported ( EFI_HANDLE  device)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 196 of file snponly.c.

196  {
197 
198  return chained_supported ( device, &chained_snp );
199 }
static int chained_supported(EFI_HANDLE device, struct chained_protocol *chained)
Check to see if driver supports a device.
Definition: snponly.c:152
A hardware device.
Definition: device.h:76
static struct chained_protocol chained_snp
Chainloaded SNP protocol.
Definition: snponly.c:71

References chained_snp, and chained_supported().

◆ niionly_supported()

static int niionly_supported ( EFI_HANDLE  device)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 207 of file snponly.c.

207  {
208 
209  return chained_supported ( device, &chained_nii );
210 }
static int chained_supported(EFI_HANDLE device, struct chained_protocol *chained)
Check to see if driver supports a device.
Definition: snponly.c:152
A hardware device.
Definition: device.h:76
static struct chained_protocol chained_nii
Chainloaded NII protocol.
Definition: snponly.c:77

References chained_nii, and chained_supported().

◆ mnponly_supported()

static int mnponly_supported ( EFI_HANDLE  device)
static

Check to see if driver supports a device.

Parameters
deviceEFI device handle
Return values
rcReturn status code

Definition at line 218 of file snponly.c.

218  {
219 
220  return chained_supported ( device, &chained_mnp );
221 }
static int chained_supported(EFI_HANDLE device, struct chained_protocol *chained)
Check to see if driver supports a device.
Definition: snponly.c:152
A hardware device.
Definition: device.h:76
static struct chained_protocol chained_mnp
Chainloaded MNP protocol.
Definition: snponly.c:83

References chained_mnp, and chained_supported().

◆ __efi_driver() [1/3]

struct efi_driver snponly_driver __efi_driver ( EFI_DRIVER_SNP  )

EFI SNP chainloading-device-only driver.

◆ __efi_driver() [2/3]

struct efi_driver niionly_driver __efi_driver ( EFI_DRIVER_NII  )

EFI NII chainloading-device-only driver.

◆ __efi_driver() [3/3]

struct efi_driver mnponly_driver __efi_driver ( EFI_DRIVER_MNP  )

EFI MNP chainloading-device-only driver.

◆ chained_init()

static void chained_init ( void  )
static

Initialise EFI chainloaded-device-only driver.

Definition at line 253 of file snponly.c.

253  {
254 
258 }
static struct chained_protocol chained_nii
Chainloaded NII protocol.
Definition: snponly.c:77
static struct chained_protocol chained_snp
Chainloaded SNP protocol.
Definition: snponly.c:71
static void chained_locate(struct chained_protocol *chained)
Locate chainloaded protocol.
Definition: snponly.c:92
static struct chained_protocol chained_mnp
Chainloaded MNP protocol.
Definition: snponly.c:83

References chained_locate(), chained_mnp, chained_nii, and chained_snp.

◆ __init_fn()

struct init_fn chained_init_fn __init_fn ( INIT_LATE  )

EFI chainloaded-device-only initialisation function.

Variable Documentation

◆ chained_snp

struct chained_protocol chained_snp
static
Initial value:
= {
.inhibit_wifi = 1,
}
EFI_GUID efi_simple_network_protocol_guid
Simple network protocol GUID.
Definition: efi_guid.c:340

Chainloaded SNP protocol.

Definition at line 71 of file snponly.c.

Referenced by chained_init(), and snponly_supported().

◆ chained_nii

struct chained_protocol chained_nii
static
Initial value:
= {
.inhibit_wifi = 1,
}
EFI_GUID efi_nii31_protocol_guid
Network interface identifier protocol GUID (new version)
Definition: efi_guid.c:308

Chainloaded NII protocol.

Definition at line 77 of file snponly.c.

Referenced by chained_init(), and niionly_supported().

◆ chained_mnp

struct chained_protocol chained_mnp
static
Initial value:
= {
}
EFI_GUID efi_managed_network_service_binding_protocol_guid
Managed network service binding protocol GUID.
Definition: efi_guid.c:284

Chainloaded MNP protocol.

Definition at line 83 of file snponly.c.

Referenced by chained_init(), and mnponly_supported().