iPXE
eap.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <errno.h>
27 #include <ipxe/netdevice.h>
28 #include <ipxe/eap.h>
29 
30 /** @file
31  *
32  * Extensible Authentication Protocol
33  *
34  */
35 
36 /**
37  * Handle EAP Request-Identity
38  *
39  * @v netdev Network device
40  * @ret rc Return status code
41  */
42 static int eap_rx_request_identity ( struct net_device *netdev ) {
43 
44  /* Treat Request-Identity as blocking the link */
45  DBGC ( netdev, "EAP %s Request-Identity blocking link\n",
46  netdev->name );
48 
49  return 0;
50 }
51 
52 /**
53  * Handle EAP Request
54  *
55  * @v netdev Network device
56  * @v req EAP request
57  * @v len Length of EAP request
58  * @ret rc Return status code
59  */
60 static int eap_rx_request ( struct net_device *netdev,
61  const struct eap_request *req, size_t len ) {
62 
63  /* Sanity check */
64  if ( len < sizeof ( *req ) ) {
65  DBGC ( netdev, "EAP %s underlength request:\n", netdev->name );
66  DBGC_HDA ( netdev, 0, req, len );
67  return -EINVAL;
68  }
69 
70  /* Handle according to type */
71  switch ( req->type ) {
72  case EAP_TYPE_IDENTITY:
74  default:
75  DBGC ( netdev, "EAP %s requested type %d unknown:\n",
76  netdev->name, req->type );
77  DBGC_HDA ( netdev, 0, req, len );
78  return -ENOTSUP;
79  }
80 }
81 
82 /**
83  * Handle EAP Success
84  *
85  * @v netdev Network device
86  * @ret rc Return status code
87  */
88 static int eap_rx_success ( struct net_device *netdev ) {
89 
90  /* Mark link as unblocked */
91  DBGC ( netdev, "EAP %s Success\n", netdev->name );
93 
94  return 0;
95 }
96 
97 /**
98  * Handle EAP Failure
99  *
100  * @v netdev Network device
101  * @ret rc Return status code
102  */
103 static int eap_rx_failure ( struct net_device *netdev ) {
104 
105  /* Record error */
106  DBGC ( netdev, "EAP %s Failure\n", netdev->name );
107  return -EPERM;
108 }
109 
110 /**
111  * Handle EAP packet
112  *
113  * @v netdev Network device
114  * @v data EAP packet
115  * @v len Length of EAP packet
116  * @ret rc Return status code
117  */
118 int eap_rx ( struct net_device *netdev, const void *data, size_t len ) {
119  const union eap_packet *eap = data;
120 
121  /* Sanity check */
122  if ( len < sizeof ( eap->hdr ) ) {
123  DBGC ( netdev, "EAP %s underlength header:\n", netdev->name );
124  DBGC_HDA ( netdev, 0, eap, len );
125  return -EINVAL;
126  }
127 
128  /* Handle according to code */
129  switch ( eap->hdr.code ) {
130  case EAP_CODE_REQUEST:
131  return eap_rx_request ( netdev, &eap->req, len );
132  case EAP_CODE_SUCCESS:
133  return eap_rx_success ( netdev );
134  case EAP_CODE_FAILURE:
135  return eap_rx_failure ( netdev );
136  default:
137  DBGC ( netdev, "EAP %s unsupported code %d\n",
138  netdev->name, eap->hdr.code );
139  DBGC_HDA ( netdev, 0, eap, len );
140  return -ENOTSUP;
141  }
142 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
static int eap_rx_request(struct net_device *netdev, const struct eap_request *req, size_t len)
Handle EAP Request.
Definition: eap.c:60
int eap_rx(struct net_device *netdev, const void *data, size_t len)
Handle EAP packet.
Definition: eap.c:118
Error codes.
struct eap_request req
Request.
Definition: eap.h:51
#define EAP_CODE_REQUEST
EAP request.
Definition: eap.h:27
struct eap_header hdr
Header.
Definition: eap.h:49
#define DBGC(...)
Definition: compiler.h:505
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
uint8_t type
Type.
Definition: eap.h:34
#define EAP_CODE_FAILURE
EAP failure.
Definition: eap.h:44
EAP packet.
Definition: eap.h:47
void netdev_link_block(struct net_device *netdev, unsigned long timeout)
Mark network device link as being blocked.
Definition: netdevice.c:203
#define DBGC_HDA(...)
Definition: compiler.h:506
void netdev_link_unblock(struct net_device *netdev)
Mark network device link as being unblocked.
Definition: netdevice.c:218
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static struct net_device * netdev
Definition: gdbudp.c:52
static int eap_rx_success(struct net_device *netdev)
Handle EAP Success.
Definition: eap.c:88
static int eap_rx_request_identity(struct net_device *netdev)
Handle EAP Request-Identity.
Definition: eap.c:42
A network device.
Definition: netdevice.h:352
#define EAP_TYPE_IDENTITY
EAP identity.
Definition: eap.h:38
#define EAP_CODE_SUCCESS
EAP success.
Definition: eap.h:41
static int eap_rx_failure(struct net_device *netdev)
Handle EAP Failure.
Definition: eap.c:103
#define EPERM
Operation not permitted.
Definition: errno.h:614
Network device management.
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
uint32_t len
Length.
Definition: ena.h:14
uint8_t code
Code.
Definition: eap.h:19
#define EAP_BLOCK_TIMEOUT
Link block timeout.
Definition: eap.h:65
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
EAP request.
Definition: eap.h:30
Extensible Authentication Protocol.