wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Data Structures | Functions
eap_common.h File Reference

EAP common peer/server definitions. More...

#include "wpabuf.h"

Go to the source code of this file.

Data Structures

struct  erp_tlvs
 

Functions

int eap_hdr_len_valid (const struct wpabuf *msg, size_t min_payload)
 Validate EAP header length field. More...
 
const u8 * eap_hdr_validate (int vendor, EapType eap_type, const struct wpabuf *msg, size_t *plen)
 Validate EAP header. More...
 
struct wpabufeap_msg_alloc (int vendor, EapType type, size_t payload_len, u8 code, u8 identifier)
 Allocate a buffer for an EAP message. More...
 
void eap_update_len (struct wpabuf *msg)
 Update EAP header length. More...
 
u8 eap_get_id (const struct wpabuf *msg)
 Get EAP Identifier from wpabuf. More...
 
EapType eap_get_type (const struct wpabuf *msg)
 Get EAP Type from wpabuf. More...
 
int erp_parse_tlvs (const u8 *pos, const u8 *end, struct erp_tlvs *tlvs, int stop_at_keyname)
 

Detailed Description

EAP common peer/server definitions.

Function Documentation

u8 eap_get_id ( const struct wpabuf msg)

Get EAP Identifier from wpabuf.

Parameters
msgBuffer starting with an EAP header
Returns
The Identifier field from the EAP header
EapType eap_get_type ( const struct wpabuf msg)

Get EAP Type from wpabuf.

Parameters
msgBuffer starting with an EAP header
Returns
The EAP Type after the EAP header
int eap_hdr_len_valid ( const struct wpabuf msg,
size_t  min_payload 
)

Validate EAP header length field.

Parameters
msgEAP frame (starting with EAP header)
min_payloadMinimum payload length needed
Returns
1 for valid header, 0 for invalid

This is a helper function that does minimal validation of EAP messages. The length field is verified to be large enough to include the header and not too large to go beyond the end of the buffer.

const u8* eap_hdr_validate ( int  vendor,
EapType  eap_type,
const struct wpabuf msg,
size_t *  plen 
)

Validate EAP header.

Parameters
vendorExpected EAP Vendor-Id (0 = IETF)
eap_typeExpected EAP type number
msgEAP frame (starting with EAP header)
plenPointer to variable to contain the returned payload length
Returns
Pointer to EAP payload (after type field), or NULL on failure

This is a helper function for EAP method implementations. This is usually called in the beginning of struct eap_method::process() function to verify that the received EAP request packet has a valid header. This function is able to process both legacy and expanded EAP headers and in most cases, the caller can just use the returned payload pointer (into *plen) for processing the payload regardless of whether the packet used the expanded EAP header or not.

struct wpabuf* eap_msg_alloc ( int  vendor,
EapType  type,
size_t  payload_len,
u8  code,
u8  identifier 
)

Allocate a buffer for an EAP message.

Parameters
vendorVendor-Id (0 = IETF)
typeEAP type
payload_lenPayload length in bytes (data after Type)
codeMessage Code (EAP_CODE_*)
identifierIdentifier
Returns
Pointer to the allocated message buffer or NULL on error

This function can be used to allocate a buffer for an EAP message and fill in the EAP header. This function is automatically using expanded EAP header if the selected Vendor-Id is not IETF. In other words, most EAP methods do not need to separately select which header type to use when using this function to allocate the message buffers. The returned buffer has room for payload_len bytes and has the EAP header and Type field already filled in.

void eap_update_len ( struct wpabuf msg)

Update EAP header length.

Parameters
msgEAP message from eap_msg_alloc

This function updates the length field in the EAP header to match with the current length for the buffer. This allows eap_msg_alloc() to be used to allocate a larger buffer than the exact message length (e.g., if exact message length is not yet known).