supplicant_procedures.c
Go to the documentation of this file.
1 /**
2  * @file supplicant_procedures.c
3  * @brief Supplicant state machine procedures
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneEAP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL SUPPLICANT_TRACE_LEVEL
33 
34 //Dependencies
35 #include "supplicant/supplicant.h"
38 #include "eap/eap_debug.h"
39 #include "debug.h"
40 
41 //Check EAP library configuration
42 #if (SUPPLICANT_SUPPORT == ENABLED)
43 
44 
45 /**
46  * @brief Transmit an EAPOL-Start packet (8.2.11.1.3 a)
47  * @param[in] context Pointer to the 802.1X supplicant context
48  **/
49 
51 {
52  size_t n;
53  EapolPdu *pdu;
54 
55  //Debug message
56  TRACE_DEBUG("txStart() procedure...\r\n");
57 
58  //Point to the buffer where to format the EAPOL packet
59  pdu = (EapolPdu *) context->txBuffer;
60 
61  //EAPOL-Start PDUs are transmitted with no Packet Body
62  pdu->protocolVersion = EAPOL_VERSION_2;
63  pdu->packetType = EAPOL_TYPE_START;
64  pdu->packetBodyLen = ntohs(0);
65 
66  //Total length of the EAPOL packet
67  n = sizeof(EapolPdu);
68 
69  //Debug message
70  TRACE_INFO("Sending EAPOL packet (%" PRIuSIZE " bytes)\r\n", n);
71  //Dump EAPOL header contents for debugging purpose
73 
74  //Send EAPOL PDU
75  supplicantSendEapolPdu(context, context->txBuffer, n);
76 }
77 
78 
79 /**
80  * @brief Transmit an EAPOL-Logoff packet (8.2.11.1.3 b)
81  * @param[in] context Pointer to the 802.1X supplicant context
82  **/
83 
85 {
86  size_t n;
87  EapolPdu *pdu;
88 
89  //Debug message
90  TRACE_DEBUG("txLogoff() procedure...\r\n");
91 
92  //Point to the buffer where to format the EAPOL packet
93  pdu = (EapolPdu *) context->txBuffer;
94 
95  //EAPOL-Start PDUs are transmitted with no Packet Body
96  pdu->protocolVersion = EAPOL_VERSION_2;
97  pdu->packetType = EAPOL_TYPE_LOGOFF;
98  pdu->packetBodyLen = ntohs(0);
99 
100  //Total length of the EAPOL packet
101  n = sizeof(EapolPdu);
102 
103  //Debug message
104  TRACE_INFO("Sending EAPOL packet (%" PRIuSIZE " bytes)\r\n", n);
105  //Dump EAPOL header contents for debugging purpose
107 
108  //Send EAPOL PDU
109  supplicantSendEapolPdu(context, context->txBuffer, n);
110 }
111 
112 
113 /**
114  * @brief Release any system resources (8.2.12.1.3 a)
115  * @param[in] context Pointer to the 802.1X supplicant context
116  **/
117 
119 {
120 }
121 
122 
123 /**
124  * @brief Get the information required in order to respond to the EAP request (8.2.12.1.3 b)
125  * @param[in] context Pointer to the 802.1X supplicant context
126  **/
127 
129 {
130  //Debug message
131  TRACE_DEBUG("getSuppRsp() procedure...\r\n");
132 }
133 
134 
135 /**
136  * @brief Transmit an EAPOL-Packet packet (8.2.12.1.3 c)
137  * @param[in] context Pointer to the 802.1X supplicant context
138  **/
139 
141 {
142  size_t length;
143  EapolPdu *pdu;
144 
145  //Debug message
146  TRACE_DEBUG("txSuppRsp() procedure...\r\n");
147 
148  //Point to the buffer where to format the EAPOL packet
149  pdu = (EapolPdu *) context->txBuffer;
150  //Retrieve the length of the EAP response
151  length = context->eapRespDataLen;
152 
153  //Valid EAP packet?
154  if(length >= sizeof(EapPacket))
155  {
156  //Format EAPOL packet
157  pdu->protocolVersion = EAPOL_VERSION_2;
158  pdu->packetType = EAPOL_TYPE_EAP;
159  pdu->packetBodyLen = ntohs(length);
160 
161  //Total length of the EAPOL packet
162  length += sizeof(EapolPdu);
163 
164  //Debug message
165  TRACE_INFO("Sending EAPOL packet (%" PRIuSIZE " bytes)\r\n", length);
166  //Dump EAPOL header contents for debugging purpose
168 
169  //Send EAPOL PDU
170  supplicantSendEapolPdu(context, context->txBuffer, length);
171  }
172 }
173 
174 
175 /**
176  * @brief Decrement timer value
177  * @param[in,out] x Actual timer value
178  **/
179 
181 {
182  //If the variable has a non-zero value, this procedure decrements the value
183  //of the variable by 1
184  if(*x > 0)
185  {
186  *x -= 1;
187  }
188 }
189 
190 #endif
Supplicant state machine procedures.
@ EAPOL_VERSION_2
IEEE 802.1X-2004.
Definition: eap.h:123
EapolPdu
Definition: eap.h:211
802.1X supplicant
uint8_t x
Definition: lldp_ext_med.h:211
#define SupplicantContext
Definition: supplicant.h:36
void supplicantTxStart(SupplicantContext *context)
Transmit an EAPOL-Start packet (8.2.11.1.3 a)
void eapolDumpHeader(const EapolPdu *header)
Dump EAPOL header for debugging purpose.
Definition: eap_debug.c:85
uint8_t pdu[]
@ EAPOL_TYPE_EAP
EAPOL-EAP.
Definition: eap.h:134
void supplicantTxSuppRsp(SupplicantContext *context)
Transmit an EAPOL-Packet packet (8.2.12.1.3 c)
#define TRACE_INFO(...)
Definition: debug.h:95
uint8_t length
Definition: tcp.h:368
error_t supplicantSendEapolPdu(SupplicantContext *context, const uint8_t *pdu, size_t length)
Send EAPOL PDU.
#define ntohs(value)
Definition: cpu_endian.h:421
#define TRACE_DEBUG(...)
Definition: debug.h:107
void supplicantAbortSupp(SupplicantContext *context)
Release any system resources (8.2.12.1.3 a)
Data logging functions for debugging purpose (EAP)
void supplicantGetSuppRsp(SupplicantContext *context)
Get the information required in order to respond to the EAP request (8.2.12.1.3 b)
uint8_t n
EapPacket
Definition: eap.h:224
@ EAPOL_TYPE_LOGOFF
EAPOL-Logoff.
Definition: eap.h:136
@ EAPOL_TYPE_START
EAPOL-Start.
Definition: eap.h:135
void supplicantDecrementTimer(uint_t *x)
Decrement timer value.
#define PRIuSIZE
unsigned int uint_t
Definition: compiler_port.h:50
Debugging facilities.
Helper functions for 802.1X supplicant.
void supplicantTxLogoff(SupplicantContext *context)
Transmit an EAPOL-Logoff packet (8.2.11.1.3 b)