Replace EapType typedef with enum eap_type

This cleans up coding style of the EAP implementation by avoiding
typedef of an enum hiding the type of the variables.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2019-08-17 11:36:20 +03:00
parent 542913943e
commit 5f2301a6da
21 changed files with 84 additions and 70 deletions

View File

@ -63,7 +63,7 @@ int eap_hdr_len_valid(const struct wpabuf *msg, size_t min_payload)
* the payload regardless of whether the packet used the expanded EAP header or
* not.
*/
const u8 * eap_hdr_validate(int vendor, EapType eap_type,
const u8 * eap_hdr_validate(int vendor, enum eap_type eap_type,
const struct wpabuf *msg, size_t *plen)
{
const struct eap_hdr *hdr;
@ -125,8 +125,8 @@ const u8 * eap_hdr_validate(int vendor, EapType eap_type,
* 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.
*/
struct wpabuf * eap_msg_alloc(int vendor, EapType type, size_t payload_len,
u8 code, u8 identifier)
struct wpabuf * eap_msg_alloc(int vendor, enum eap_type type,
size_t payload_len, u8 code, u8 identifier)
{
struct wpabuf *buf;
struct eap_hdr *hdr;
@ -196,7 +196,7 @@ u8 eap_get_id(const struct wpabuf *msg)
* @msg: Buffer starting with an EAP header
* Returns: The EAP Type after the EAP header
*/
EapType eap_get_type(const struct wpabuf *msg)
enum eap_type eap_get_type(const struct wpabuf *msg)
{
if (wpabuf_len(msg) < sizeof(struct eap_hdr) + 1)
return EAP_TYPE_NONE;

View File

@ -20,13 +20,13 @@ struct erp_tlvs {
};
int eap_hdr_len_valid(const struct wpabuf *msg, size_t min_payload);
const u8 * eap_hdr_validate(int vendor, EapType eap_type,
const u8 * eap_hdr_validate(int vendor, enum eap_type eap_type,
const struct wpabuf *msg, size_t *plen);
struct wpabuf * eap_msg_alloc(int vendor, EapType type, size_t payload_len,
u8 code, u8 identifier);
struct wpabuf * eap_msg_alloc(int vendor, enum eap_type type,
size_t payload_len, u8 code, u8 identifier);
void eap_update_len(struct wpabuf *msg);
u8 eap_get_id(const struct wpabuf *msg);
EapType eap_get_type(const struct wpabuf *msg);
enum eap_type eap_get_type(const struct wpabuf *msg);
int erp_parse_tlvs(const u8 *pos, const u8 *end, struct erp_tlvs *tlvs,
int stop_at_keyname);

View File

@ -64,7 +64,7 @@ enum eap_erp_cryptosuite {
* EAP Method Types as allocated by IANA:
* http://www.iana.org/assignments/eap-numbers
*/
typedef enum {
enum eap_type {
EAP_TYPE_NONE = 0,
EAP_TYPE_IDENTITY = 1 /* RFC 3748 */,
EAP_TYPE_NOTIFICATION = 2 /* RFC 3748 */,
@ -94,7 +94,7 @@ typedef enum {
EAP_TYPE_EKE = 53 /* RFC 6124 */,
EAP_TYPE_TEAP = 55 /* RFC 7170 */,
EAP_TYPE_EXPANDED = 254 /* RFC 3748 */
} EapType;
};
/* SMI Network Management Private Enterprise Code for vendor specific types */

View File

@ -37,7 +37,7 @@
static Boolean eap_sm_allowMethod(struct eap_sm *sm, int vendor,
EapType method);
enum eap_type method);
static struct wpabuf * eap_sm_buildNak(struct eap_sm *sm, int id);
static void eap_sm_processIdentity(struct eap_sm *sm,
const struct wpabuf *req);
@ -319,7 +319,7 @@ SM_STATE(EAP, RECEIVED)
SM_STATE(EAP, GET_METHOD)
{
int reinit;
EapType method;
enum eap_type method;
const struct eap_method *eap_method;
SM_ENTRY(EAP, GET_METHOD);
@ -815,7 +815,8 @@ struct wpabuf * eap_peer_build_erp_reauth_start(struct eap_sm *sm, u8 eap_id)
wpa_printf(MSG_DEBUG, "EAP: Valid ERP key found %s (SEQ=%u)",
erp->keyname_nai, erp->next_seq);
msg = eap_msg_alloc(EAP_VENDOR_IETF, (EapType) EAP_ERP_TYPE_REAUTH,
msg = eap_msg_alloc(EAP_VENDOR_IETF,
(enum eap_type) EAP_ERP_TYPE_REAUTH,
1 + 2 + 2 + os_strlen(erp->keyname_nai) + 1 + 16,
EAP_CODE_INITIATE, eap_id);
if (msg == NULL)
@ -1349,7 +1350,7 @@ SM_STEP(EAP)
static Boolean eap_sm_allowMethod(struct eap_sm *sm, int vendor,
EapType method)
enum eap_type method)
{
if (!eap_allowed_method(sm, vendor, method)) {
wpa_printf(MSG_DEBUG, "EAP: configuration does not allow: "

View File

@ -72,7 +72,7 @@ struct eap_method {
/**
* method - EAP type number (EAP_TYPE_*)
*/
EapType method;
enum eap_type method;
/**
* name - Name of the method (e.g., "TLS")
@ -312,7 +312,7 @@ struct eap_sm {
EAP_FAILURE
} EAP_state;
/* Long-term local variables */
EapType selectedMethod;
enum eap_type selectedMethod;
EapMethodState methodState;
int lastId;
struct wpabuf *lastRespData;
@ -322,7 +322,7 @@ struct eap_sm {
Boolean rxSuccess;
Boolean rxFailure;
int reqId;
EapType reqMethod;
enum eap_type reqMethod;
int reqVendor;
u32 reqVendorMethod;
Boolean ignore;

View File

@ -27,7 +27,8 @@ static void eap_peer_method_free(struct eap_method *method);
* @method: EAP type number
* Returns: Pointer to EAP method or %NULL if not found
*/
const struct eap_method * eap_peer_get_eap_method(int vendor, EapType method)
const struct eap_method * eap_peer_get_eap_method(int vendor,
enum eap_type method)
{
struct eap_method *m;
for (m = eap_methods; m; m = m->next) {
@ -47,7 +48,7 @@ const struct eap_method * eap_peer_get_eap_method(int vendor, EapType method)
* This function maps EAP type names into EAP type numbers based on the list of
* EAP methods included in the build.
*/
EapType eap_peer_get_type(const char *name, int *vendor)
enum eap_type eap_peer_get_type(const char *name, int *vendor)
{
struct eap_method *m;
for (m = eap_methods; m; m = m->next) {
@ -70,7 +71,7 @@ EapType eap_peer_get_type(const char *name, int *vendor)
* This function maps EAP type numbers into EAP type names based on the list of
* EAP methods included in the build.
*/
const char * eap_get_name(int vendor, EapType type)
const char * eap_get_name(int vendor, enum eap_type type)
{
struct eap_method *m;
if (vendor == EAP_VENDOR_IETF && type == EAP_TYPE_EXPANDED)
@ -279,7 +280,8 @@ int eap_peer_method_unload(struct eap_method *method)
* is not needed anymore.
*/
struct eap_method * eap_peer_method_alloc(int version, int vendor,
EapType method, const char *name)
enum eap_type method,
const char *name)
{
struct eap_method *eap;
eap = os_zalloc(sizeof(*eap));

View File

@ -11,31 +11,33 @@
#include "eap_common/eap_defs.h"
const struct eap_method * eap_peer_get_eap_method(int vendor, EapType method);
const struct eap_method * eap_peer_get_eap_method(int vendor,
enum eap_type method);
const struct eap_method * eap_peer_get_methods(size_t *count);
struct eap_method * eap_peer_method_alloc(int version, int vendor,
EapType method, const char *name);
enum eap_type method,
const char *name);
int eap_peer_method_register(struct eap_method *method);
#ifdef IEEE8021X_EAPOL
EapType eap_peer_get_type(const char *name, int *vendor);
const char * eap_get_name(int vendor, EapType type);
enum eap_type eap_peer_get_type(const char *name, int *vendor);
const char * eap_get_name(int vendor, enum eap_type type);
size_t eap_get_names(char *buf, size_t buflen);
char ** eap_get_names_as_string_array(size_t *num);
void eap_peer_unregister_methods(void);
#else /* IEEE8021X_EAPOL */
static inline EapType eap_peer_get_type(const char *name, int *vendor)
static inline enum eap_type eap_peer_get_type(const char *name, int *vendor)
{
*vendor = EAP_VENDOR_IETF;
return EAP_TYPE_NONE;
}
static inline const char * eap_get_name(int vendor, EapType type)
static inline const char * eap_get_name(int vendor, enum eap_type type)
{
return NULL;
}

View File

@ -16,7 +16,7 @@
#include "eap_config.h"
static struct wpabuf * eap_tls_msg_alloc(EapType type, size_t payload_len,
static struct wpabuf * eap_tls_msg_alloc(enum eap_type type, size_t payload_len,
u8 code, u8 identifier)
{
if (type == EAP_UNAUTH_TLS_TYPE)
@ -619,7 +619,8 @@ static int eap_tls_process_input(struct eap_sm *sm, struct eap_ssl_data *data,
* @out_data: Buffer for returning the allocated output buffer
* Returns: ret (0 or 1) on success, -1 on failure
*/
static int eap_tls_process_output(struct eap_ssl_data *data, EapType eap_type,
static int eap_tls_process_output(struct eap_ssl_data *data,
enum eap_type eap_type,
int peap_version, u8 id, int ret,
struct wpabuf **out_data)
{
@ -717,7 +718,7 @@ static int eap_tls_process_output(struct eap_ssl_data *data, EapType eap_type,
* the tunneled data is used.
*/
int eap_peer_tls_process_helper(struct eap_sm *sm, struct eap_ssl_data *data,
EapType eap_type, int peap_version,
enum eap_type eap_type, int peap_version,
u8 id, const struct wpabuf *in_data,
struct wpabuf **out_data)
{
@ -809,7 +810,7 @@ int eap_peer_tls_process_helper(struct eap_sm *sm, struct eap_ssl_data *data,
* @peap_version: Version number for EAP-PEAP/TTLS
* Returns: Pointer to the allocated ACK frame or %NULL on failure
*/
struct wpabuf * eap_peer_tls_build_ack(u8 id, EapType eap_type,
struct wpabuf * eap_peer_tls_build_ack(u8 id, enum eap_type eap_type,
int peap_version)
{
struct wpabuf *resp;
@ -899,7 +900,7 @@ int eap_peer_tls_status(struct eap_sm *sm, struct eap_ssl_data *data,
*/
const u8 * eap_peer_tls_process_init(struct eap_sm *sm,
struct eap_ssl_data *data,
EapType eap_type,
enum eap_type eap_type,
struct eap_method_ret *ret,
const struct wpabuf *reqData,
size_t *len, u8 *flags)
@ -1056,7 +1057,7 @@ int eap_peer_tls_decrypt(struct eap_sm *sm, struct eap_ssl_data *data,
* Returns: 0 on success, -1 on failure
*/
int eap_peer_tls_encrypt(struct eap_sm *sm, struct eap_ssl_data *data,
EapType eap_type, int peap_version, u8 id,
enum eap_type eap_type, int peap_version, u8 id,
const struct wpabuf *in_data,
struct wpabuf **out_data)
{

View File

@ -107,17 +107,17 @@ u8 * eap_peer_tls_derive_session_id(struct eap_sm *sm,
struct eap_ssl_data *data, u8 eap_type,
size_t *len);
int eap_peer_tls_process_helper(struct eap_sm *sm, struct eap_ssl_data *data,
EapType eap_type, int peap_version,
enum eap_type eap_type, int peap_version,
u8 id, const struct wpabuf *in_data,
struct wpabuf **out_data);
struct wpabuf * eap_peer_tls_build_ack(u8 id, EapType eap_type,
struct wpabuf * eap_peer_tls_build_ack(u8 id, enum eap_type eap_type,
int peap_version);
int eap_peer_tls_reauth_init(struct eap_sm *sm, struct eap_ssl_data *data);
int eap_peer_tls_status(struct eap_sm *sm, struct eap_ssl_data *data,
char *buf, size_t buflen, int verbose);
const u8 * eap_peer_tls_process_init(struct eap_sm *sm,
struct eap_ssl_data *data,
EapType eap_type,
enum eap_type eap_type,
struct eap_method_ret *ret,
const struct wpabuf *reqData,
size_t *len, u8 *flags);
@ -127,7 +127,7 @@ int eap_peer_tls_decrypt(struct eap_sm *sm, struct eap_ssl_data *data,
const struct wpabuf *in_data,
struct wpabuf **in_decrypted);
int eap_peer_tls_encrypt(struct eap_sm *sm, struct eap_ssl_data *data,
EapType eap_type, int peap_version, u8 id,
enum eap_type eap_type, int peap_version, u8 id,
const struct wpabuf *in_data,
struct wpabuf **out_data);
int eap_peer_select_phase2_methods(struct eap_peer_config *config,

View File

@ -23,7 +23,7 @@
*/
struct eap_method {
int vendor;
EapType method;
enum eap_type method;
const char *name;
void * (*init)(struct eap_sm *sm);
@ -128,7 +128,7 @@ struct eap_sm {
/* Full authenticator state machine local variables */
/* Long-term (maintained between packets) */
EapType currentMethod;
enum eap_type currentMethod;
int currentId;
enum {
METHOD_PROPOSED, METHOD_CONTINUE, METHOD_END
@ -141,7 +141,7 @@ struct eap_sm {
Boolean rxResp;
Boolean rxInitiate;
int respId;
EapType respMethod;
enum eap_type respMethod;
int respVendor;
u32 respVendorMethod;
Boolean ignore;

View File

@ -12,14 +12,15 @@
#include "eap_common/eap_defs.h"
const struct eap_method * eap_server_get_eap_method(int vendor,
EapType method);
enum eap_type method);
struct eap_method * eap_server_method_alloc(int version, int vendor,
EapType method, const char *name);
enum eap_type method,
const char *name);
int eap_server_method_register(struct eap_method *method);
EapType eap_server_get_type(const char *name, int *vendor);
enum eap_type eap_server_get_type(const char *name, int *vendor);
void eap_server_unregister_methods(void);
const char * eap_server_get_name(int vendor, EapType type);
const char * eap_server_get_name(int vendor, enum eap_type type);
/* EAP server method registration calls for statically linked in methods */
int eap_server_identity_register(void);

View File

@ -37,9 +37,10 @@ static struct wpabuf * eap_sm_buildFailure(struct eap_sm *sm, u8 id);
static int eap_sm_nextId(struct eap_sm *sm, int id);
static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
size_t len);
static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor);
static enum eap_type eap_sm_Policy_getNextMethod(struct eap_sm *sm,
int *vendor);
static int eap_sm_Policy_getDecision(struct eap_sm *sm);
static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method);
static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, enum eap_type method);
static int eap_get_erp_send_reauth_start(struct eap_sm *sm)
@ -94,7 +95,7 @@ static struct wpabuf * eap_sm_buildInitiateReauthStart(struct eap_sm *sm,
}
msg = eap_msg_alloc(EAP_VENDOR_IETF,
(EapType) EAP_ERP_TYPE_REAUTH_START, plen,
(enum eap_type) EAP_ERP_TYPE_REAUTH_START, plen,
EAP_CODE_INITIATE, id);
if (msg == NULL)
return NULL;
@ -541,7 +542,7 @@ SM_STATE(EAP, METHOD_RESPONSE)
SM_STATE(EAP, PROPOSE_METHOD)
{
int vendor;
EapType type;
enum eap_type type;
SM_ENTRY(EAP, PROPOSE_METHOD);
@ -720,7 +721,8 @@ static void erp_send_finish_reauth(struct eap_sm *sm,
plen = 1 + 2 + 2 + os_strlen(nai);
if (hash_len)
plen += 1 + hash_len;
msg = eap_msg_alloc(EAP_VENDOR_IETF, (EapType) EAP_ERP_TYPE_REAUTH,
msg = eap_msg_alloc(EAP_VENDOR_IETF,
(enum eap_type) EAP_ERP_TYPE_REAUTH,
plen, EAP_CODE_FINISH, id);
if (msg == NULL)
return;
@ -805,7 +807,8 @@ SM_STATE(EAP, INITIATE_RECEIVED)
sm->rxInitiate = FALSE;
pos = eap_hdr_validate(EAP_VENDOR_IETF, (EapType) EAP_ERP_TYPE_REAUTH,
pos = eap_hdr_validate(EAP_VENDOR_IETF,
(enum eap_type) EAP_ERP_TYPE_REAUTH,
sm->eap_if.eapRespData, &len);
if (pos == NULL) {
wpa_printf(MSG_INFO, "EAP-Initiate: Invalid frame");
@ -1669,9 +1672,9 @@ static void eap_sm_Policy_update(struct eap_sm *sm, const u8 *nak_list,
}
static EapType eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor)
static enum eap_type eap_sm_Policy_getNextMethod(struct eap_sm *sm, int *vendor)
{
EapType next;
enum eap_type next;
int idx = sm->user_eap_method_index;
/* In theory, there should be no problems with starting
@ -1783,7 +1786,7 @@ static int eap_sm_Policy_getDecision(struct eap_sm *sm)
}
static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, EapType method)
static Boolean eap_sm_Policy_doPickUp(struct eap_sm *sm, enum eap_type method)
{
return method == EAP_TYPE_IDENTITY ? TRUE : FALSE;
}

View File

@ -108,8 +108,8 @@ static void eap_fast_state(struct eap_fast_data *data, int state)
}
static EapType eap_fast_req_failure(struct eap_sm *sm,
struct eap_fast_data *data)
static enum eap_type eap_fast_req_failure(struct eap_sm *sm,
struct eap_fast_data *data)
{
/* TODO: send Result TLV(FAILURE) */
eap_fast_state(data, FAILURE);
@ -943,7 +943,7 @@ static Boolean eap_fast_check(struct eap_sm *sm, void *priv,
static int eap_fast_phase2_init(struct eap_sm *sm, struct eap_fast_data *data,
EapType eap_type)
enum eap_type eap_type)
{
if (data->phase2_priv && data->phase2_method) {
data->phase2_method->reset(sm, data->phase2_priv);

View File

@ -22,7 +22,8 @@ static struct eap_method *eap_methods;
* @method: EAP type number
* Returns: Pointer to EAP method or %NULL if not found
*/
const struct eap_method * eap_server_get_eap_method(int vendor, EapType method)
const struct eap_method * eap_server_get_eap_method(int vendor,
enum eap_type method)
{
struct eap_method *m;
for (m = eap_methods; m; m = m->next) {
@ -42,7 +43,7 @@ const struct eap_method * eap_server_get_eap_method(int vendor, EapType method)
* This function maps EAP type names into EAP type numbers based on the list of
* EAP methods included in the build.
*/
EapType eap_server_get_type(const char *name, int *vendor)
enum eap_type eap_server_get_type(const char *name, int *vendor)
{
struct eap_method *m;
for (m = eap_methods; m; m = m->next) {
@ -69,7 +70,8 @@ EapType eap_server_get_type(const char *name, int *vendor)
* is not needed anymore.
*/
struct eap_method * eap_server_method_alloc(int version, int vendor,
EapType method, const char *name)
enum eap_type method,
const char *name)
{
struct eap_method *eap;
eap = os_zalloc(sizeof(*eap));
@ -163,7 +165,7 @@ void eap_server_unregister_methods(void)
* This function maps EAP type numbers into EAP type names based on the list of
* EAP methods included in the build.
*/
const char * eap_server_get_name(int vendor, EapType type)
const char * eap_server_get_name(int vendor, enum eap_type type)
{
struct eap_method *m;
if (vendor == EAP_VENDOR_IETF && type == EAP_TYPE_EXPANDED)

View File

@ -585,7 +585,7 @@ static Boolean eap_peap_check(struct eap_sm *sm, void *priv,
static int eap_peap_phase2_init(struct eap_sm *sm, struct eap_peap_data *data,
int vendor, EapType eap_type)
int vendor, enum eap_type eap_type)
{
if (data->phase2_priv && data->phase2_method) {
data->phase2_method->reset(sm, data->phase2_priv);

View File

@ -121,8 +121,8 @@ static void eap_teap_state(struct eap_teap_data *data, int state)
}
static EapType eap_teap_req_failure(struct eap_teap_data *data,
enum teap_error_codes error)
static enum eap_type eap_teap_req_failure(struct eap_teap_data *data,
enum teap_error_codes error)
{
eap_teap_state(data, FAILURE_SEND_RESULT);
return EAP_TYPE_NONE;
@ -938,7 +938,7 @@ static Boolean eap_teap_check(struct eap_sm *sm, void *priv,
static int eap_teap_phase2_init(struct eap_sm *sm, struct eap_teap_data *data,
EapType eap_type)
enum eap_type eap_type)
{
if (data->phase2_priv && data->phase2_method) {
data->phase2_method->reset(sm, data->phase2_priv);

View File

@ -18,7 +18,7 @@
static void eap_server_tls_free_in_buf(struct eap_ssl_data *data);
struct wpabuf * eap_tls_msg_alloc(EapType type, size_t payload_len,
struct wpabuf * eap_tls_msg_alloc(enum eap_type type, size_t payload_len,
u8 code, u8 identifier)
{
if (type == EAP_UNAUTH_TLS_TYPE)

View File

@ -827,7 +827,7 @@ static void eap_ttls_process_phase2_mschapv2(struct eap_sm *sm,
static int eap_ttls_phase2_eap_init(struct eap_sm *sm,
struct eap_ttls_data *data,
EapType eap_type)
enum eap_type eap_type)
{
if (data->phase2_priv && data->phase2_method) {
data->phase2_method->reset(sm, data->phase2_priv);

View File

@ -73,7 +73,7 @@ struct eap_ssl_data {
#define EAP_WFA_UNAUTH_TLS_TYPE 254
struct wpabuf * eap_tls_msg_alloc(EapType type, size_t payload_len,
struct wpabuf * eap_tls_msg_alloc(enum eap_type type, size_t payload_len,
u8 code, u8 identifier);
int eap_server_tls_ssl_init(struct eap_sm *sm, struct eap_ssl_data *data,
int verify_peer, int eap_type);

View File

@ -20,7 +20,8 @@ struct eap_method * registered_eap_method = NULL;
struct eap_method * eap_peer_method_alloc(int version, int vendor,
EapType method, const char *name)
enum eap_type method,
const char *name)
{
struct eap_method *eap;
eap = os_zalloc(sizeof(*eap));

View File

@ -20,7 +20,8 @@ struct eap_method * registered_eap_method = NULL;
struct eap_method * eap_peer_method_alloc(int version, int vendor,
EapType method, const char *name)
enum eap_type method,
const char *name)
{
struct eap_method *eap;
eap = os_zalloc(sizeof(*eap));