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)
 
 FILE_SECBOOT (PERMITTED)
 
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  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ chained_locate()

static void chained_locate ( struct chained_protocol chained)
static

Locate chainloaded protocol.

Parameters
chainedChainloaded protocol

Definition at line 93 of file snponly.c.

93  {
96  void *match = NULL;
97  void *interface;
98  unsigned int skip;
99  int rc;
100 
101  /* Identify target device handle */
102  for ( skip = 0 ; ; skip++ ) {
103 
104  /* Locate handle supporting this protocol */
105  if ( ( rc = efi_locate_device ( device, chained->protocol,
106  &handle, skip ) ) != 0 ) {
107  if ( skip == 0 ) {
108  DBGC ( device, "CHAINED %s does not support "
109  "%s: %s\n", efi_handle_name ( device ),
110  efi_guid_ntoa ( chained->protocol ),
111  strerror ( rc ) );
112  }
113  break;
114  }
115 
116  /* Get protocol instance */
117  if ( ( rc = efi_open ( handle, chained->protocol,
118  &interface ) ) != 0 ) {
119  DBGC ( device, "CHAINED %s could not open %s on ",
121  efi_guid_ntoa ( chained->protocol ) );
122  DBGC ( device, "%s: %s\n",
123  efi_handle_name ( handle ), strerror ( rc ) );
124  break;
125  }
126 
127  /* Stop if we reach a non-matching protocol instance */
128  if ( match && ( match != interface ) ) {
129  DBGC ( device, "CHAINED %s found non-matching %s on ",
131  efi_guid_ntoa ( chained->protocol ) );
132  DBGC ( device, "%s\n", efi_handle_name ( handle ) );
133  break;
134  }
135 
136  /* Record this handle */
137  chained->device = handle;
138  match = interface;
139  DBGC ( device, "CHAINED %s found %s on ",
141  efi_guid_ntoa ( chained->protocol ) );
142  DBGC ( device, "%s\n", efi_handle_name ( chained->device ) );
143  }
144 }
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition: efi_init.c:39
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
EFI_HANDLE device
Target device handle.
Definition: snponly.c:66
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:77
An object interface.
Definition: interface.h:125
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:79
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition: efi.h:444
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:46
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:726
EFI_GUID * protocol
Protocol GUID.
Definition: snponly.c:48
uint16_t handle
Handle.
Definition: smbios.h:17
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
Definition: efi.h:62
EFI_HANDLE DeviceHandle
The device handle that the EFI Image was loaded from.
Definition: LoadedImage.h:56

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 153 of file snponly.c.

154  {
155  void *interface;
156  int rc;
157 
158  /* Get protocol */
159  if ( ( rc = efi_open ( device, chained->protocol,
160  &interface ) ) != 0 ) {
161  DBGCP ( device, "CHAINED %s is not a %s device\n",
163  efi_guid_ntoa ( chained->protocol ) );
164  return rc;
165  }
166 
167  /* Ignore non-matching handles */
168  if ( device != chained->device ) {
169  DBGC2 ( device, "CHAINED %s is not the chainloaded %s\n",
171  efi_guid_ntoa ( chained->protocol ) );
172  return -ENOTTY;
173  }
174  DBGC ( device, "CHAINED %s is the chainloaded %s\n",
176  efi_guid_ntoa ( chained->protocol ) );
177 
178  /* Check for wireless devices, if applicable */
179  if ( chained->inhibit_wifi &&
180  ( ( efi_test ( device, &efi_wifi2_protocol_guid ) ) == 0 ) ) {
181  DBGC ( device, "CHAINED %s is wireless: assuming vendor %s "
182  "driver is too unreliable to use\n",
184  efi_guid_ntoa ( chained->protocol ) );
185  return -ENOTTY;
186  }
187 
188  return 0;
189 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
EFI_HANDLE device
Target device handle.
Definition: snponly.c:66
int inhibit_wifi
Assume wireless devices are unusable.
Definition: snponly.c:68
#define efi_test(handle, protocol)
Test protocol existence.
Definition: efi.h:433
#define DBGC(...)
Definition: compiler.h:505
A hardware device.
Definition: device.h:77
An object interface.
Definition: interface.h:125
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:444
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition: efi_guid.c:726
EFI_GUID * protocol
Protocol GUID.
Definition: snponly.c:48
EFI_GUID efi_wifi2_protocol_guid
WiFi 2 protocol GUID.
Definition: efi_guid.c:437
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:595
#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 197 of file snponly.c.

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

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 208 of file snponly.c.

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

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 219 of file snponly.c.

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

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 254 of file snponly.c.

254  {
255 
259 }
static struct chained_protocol chained_nii
Chainloaded NII protocol.
Definition: snponly.c:78
static struct chained_protocol chained_snp
Chainloaded SNP protocol.
Definition: snponly.c:72
static void chained_locate(struct chained_protocol *chained)
Locate chainloaded protocol.
Definition: snponly.c:93
static struct chained_protocol chained_mnp
Chainloaded MNP protocol.
Definition: snponly.c:84

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:341

Chainloaded SNP protocol.

Definition at line 72 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:309

Chainloaded NII protocol.

Definition at line 78 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:285

Chainloaded MNP protocol.

Definition at line 84 of file snponly.c.

Referenced by chained_init(), and mnponly_supported().