iPXE
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.
static int chained_supported (EFI_HANDLE device, struct chained_protocol *chained)
 Check to see if driver supports a device.
static int snponly_supported (EFI_HANDLE device)
 Check to see if driver supports a device.
static int niionly_supported (EFI_HANDLE device)
 Check to see if driver supports a device.
static int mnponly_supported (EFI_HANDLE device)
 Check to see if driver supports a device.
struct efi_driver snponly_driver __efi_driver (EFI_DRIVER_SNP)
 EFI SNP chainloading-device-only driver.
struct efi_driver niionly_driver __efi_driver (EFI_DRIVER_NII)
 EFI NII chainloading-device-only driver.
struct efi_driver mnponly_driver __efi_driver (EFI_DRIVER_MNP)
 EFI MNP chainloading-device-only driver.
static void chained_init (void)
 Initialise EFI chainloaded-device-only driver.
struct init_fn chained_init_fn __init_fn (INIT_LATE)
 EFI chainloaded-device-only initialisation function.

Variables

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

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

void chained_locate ( struct chained_protocol * chained)
static

Locate chainloaded protocol.

Parameters
chainedChainloaded protocol

Definition at line 93 of file snponly.c.

93 {
94 EFI_HANDLE device = efi_loaded_image->DeviceHandle;
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",
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}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition efi_debug.c:652
const char * efi_guid_ntoa(CONST EFI_GUID *guid)
Convert GUID to a printable string.
Definition efi_guid.c:726
EFI_LOADED_IMAGE_PROTOCOL * efi_loaded_image
Loaded image protocol for this image.
Definition efi_init.c:39
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
#define DBGC(...)
Definition compiler.h:505
#define efi_open(handle, protocol, interface)
Open protocol for ephemeral use.
Definition efi.h:444
#define EFI_HANDLE
Definition efi.h:53
uint16_t handle
Handle.
Definition smbios.h:5
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI_HANDLE device
Target device handle.
Definition snponly.c:66
EFI_GUID * protocol
Protocol GUID.
Definition snponly.c:48
A hardware device.
Definition device.h:77
An object interface.
Definition interface.h:125

References DBGC, chained_protocol::device, efi_guid_ntoa(), EFI_HANDLE, 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()

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}
EFI_GUID efi_wifi2_protocol_guid
WiFi 2 protocol GUID.
Definition efi_guid.c:437
#define DBGC2(...)
Definition compiler.h:522
#define DBGCP(...)
Definition compiler.h:539
#define ENOTTY
Inappropriate I/O control operation.
Definition errno.h:595
#define efi_test(handle, protocol)
Test protocol existence.
Definition efi.h:433
int inhibit_wifi
Assume wireless devices are unusable.
Definition snponly.c:68

References DBGC, DBGC2, DBGCP, chained_protocol::device, efi_guid_ntoa(), EFI_HANDLE, 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()

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
200}
static struct chained_protocol chained_snp
Chainloaded SNP protocol.
Definition snponly.c:72
static int chained_supported(EFI_HANDLE device, struct chained_protocol *chained)
Check to see if driver supports a device.
Definition snponly.c:153

References chained_snp, chained_supported(), and EFI_HANDLE.

Referenced by __efi_driver().

◆ niionly_supported()

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
211}
static struct chained_protocol chained_nii
Chainloaded NII protocol.
Definition snponly.c:78

References chained_nii, chained_supported(), and EFI_HANDLE.

Referenced by __efi_driver().

◆ mnponly_supported()

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
222}
static struct chained_protocol chained_mnp
Chainloaded MNP protocol.
Definition snponly.c:84

References chained_mnp, chained_supported(), and EFI_HANDLE.

Referenced by __efi_driver().

◆ __efi_driver() [1/3]

struct efi_driver snponly_driver __efi_driver ( EFI_DRIVER_SNP )

EFI SNP chainloading-device-only driver.

References __efi_driver, EFI_DRIVER_SNP, snpnet_exclude(), snpnet_start(), snpnet_stop(), and snponly_supported().

◆ __efi_driver() [2/3]

struct efi_driver niionly_driver __efi_driver ( EFI_DRIVER_NII )

EFI NII chainloading-device-only driver.

References __efi_driver, EFI_DRIVER_NII, nii_exclude(), nii_start(), nii_stop(), and niionly_supported().

◆ __efi_driver() [3/3]

struct efi_driver mnponly_driver __efi_driver ( EFI_DRIVER_MNP )

EFI MNP chainloading-device-only driver.

References __efi_driver, EFI_DRIVER_MNP, mnpnet_start(), mnpnet_stop(), and mnponly_supported().

◆ chained_init()

void chained_init ( void )
static

Initialise EFI chainloaded-device-only driver.

Definition at line 254 of file snponly.c.

254 {
255
259}
static void chained_locate(struct chained_protocol *chained)
Locate chainloaded protocol.
Definition snponly.c:93

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

Referenced by __init_fn().

◆ __init_fn()

struct init_fn chained_init_fn __init_fn ( INIT_LATE )

EFI chainloaded-device-only initialisation function.

References __init_fn, chained_init(), and INIT_LATE.

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.

72 {
74 .inhibit_wifi = 1,
75};

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.

78 {
79 .protocol = &efi_nii31_protocol_guid,
80 .inhibit_wifi = 1,
81};

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().