Files
m241Neelima/components/ip_net2-6.9/ipwps/src/ipwps_proto_adaptor.c
T
2026-07-30 11:19:44 +05:30

1984 lines
71 KiB
C

/* ipwps_proto_adaptor.c - IPWPS Protocol Adaptor implementation */
/*
* Copyright (c) 2008 Wind River Systems, Inc.
*
* The right to copy, distribute, modify, or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*
*/
/*
modification history
--------------------
01a,29Dec08,mry Created
*/
/* DESCRIPTION:
* ===========
* This library contains the IPWPS Protocol Adaptor implementation
* which provides an interface between the IPWPS main modules and other
* related modules (e.g. EAP-WSC, IP8021X).
*/
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
#include "ipwps_config.h"
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#define IPCOM_USE_CLIB_PROTO
#include <ipcom_type.h>
#include <ipcom_cstyle.h>
#include <ipcom_clib.h>
#include <ipcom_err.h>
#include <ipcom_syslog.h>
#include "ipwps_core.h"
#include "ipwps_private_api.h"
#include "ipwps_proto_adaptor.h"
#include "ipwps_protocol_handler.h"
#include "ip8021x.h"
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
typedef struct Ipwps_proto_adaptor_ctx_st {
Ipwps_proto_adaptor_state proto_adaptor_state; /* Tracks the state of the protocol adaptor as pertaining to ipd socket rcv/send */
Ipwps_proto_rcv_methods rcv_methods; /* Used to bind rcv methods of WPS app responsible for handling the WPS Protocol messages */
Ipwps_proto_ctx *proto_ctx; /* Protocol Handler context associated with the rcv_methods */
Ipwps_proto_data last_rcvd_proto_msg; /* Store for storing last received protocol msg for protocol cryptographic purposes */
Ipwps_proto_data last_sent_proto_msg; /* Store for encoding current protocol message to be sent
and also double as copy of last sent protocol msg for retransmission purposes */
} Ipwps_proto_adaptor_ctx;
/*
****************************************************************************
* 6 EXTERN PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 7 LOCAL PROTOTYPES
****************************************************************************
*/
/*
*
****************************************************************************
* 8 DATA
****************************************************************************
*/
/*
****************************************************************************
* 9 STATIC FUNCTIONS
****************************************************************************
*/
IP_STATIC Ip_err ipwps_proto_handle_eapol_notify(Ipwps_ctx* ctx);
IP_STATIC Ip_err ipwps_proto_handle_id_resp(Ipwps_ctx* ctx);
IP_STATIC Ip_err ipwps_proto_handle_wsc_start(Ipwps_ctx* ctx);
IP_STATIC Ip_err ipwps_proto_handle_wsc_ack(Ipwps_ctx* ctx);
IP_STATIC Ip_err ipwps_proto_handle_wsc_nack(Ipwps_ctx* ctx);
IP_STATIC Ip_err ipwps_proto_handle_wsc_msg(Ipwps_ctx* ctx);
IP_STATIC Ip_err ipwps_proto_handle_wsc_done(Ipwps_ctx* ctx);
IP_STATIC Ip_err ipwps_proto_handle_eap_fail(Ipwps_ctx* ctx);
IP_STATIC Ip_err ipwps_proto_adaptor_timeout_handler(struct Ipwps_ctx_st* ctx);
IP_STATIC Ip_err ipwps_proto_adaptor_send_response(Ipwps_ctx* ctx, Ip_err rc,
int event_or_rc, Ip_u32 len, Ip_u8 *data);
/*
****************************************************************************
* 10 GLOBAL FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* ipwps_proto_adaptor_init
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err
ipwps_proto_adaptor_init(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
ip_assert(ctx);
if (ctx->public.daemon_status < IPWPSD_STATUS_CONFIGURED) {
IPCOM_LOG2(CRIT, "ipwps_proto_adaptor_init :: Error! Invalid daemon state %s (%d)",
ipwps_daemon_status(&ctx->public), ctx->public.daemon_status);
return IPCOM_ERR_FAILED;
}
/* Initialize our */
if (ctx->proto_adaptor_ctx == IP_NULL) {
ctx->proto_adaptor_ctx = ipcom_calloc(1, sizeof(Ipwps_proto_adaptor_ctx));
}
if (ctx->proto_adaptor_ctx == IP_NULL) {
IPCOM_LOG0(CRIT, "ipwps_proto_adaptor_init :: Failed to allocate context memory");
return IPCOM_ERR_NO_MEMORY;
}
rc = ipwps_register_timeout_handler(ctx, IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER, ipwps_proto_adaptor_timeout_handler);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_enrollee_init :: failed to register timeout handler for IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER");
return rc;
}
ctx->proto_adaptor_ctx->proto_adaptor_state = IPWPS_PROTO_ADAPTOR_IDLE;
ctx->public.coop_info.session_timedout = IP_FALSE;
return IPCOM_SUCCESS;
}
/*
*===========================================================================
* ipwps_proto_adaptor_shutdown
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err
ipwps_proto_adaptor_shutdown(Ipwps_ctx* ctx) {
ip_assert(ctx);
ip_assert(ctx->public.if_name);
(void)ipwps_register_timeout_handler(ctx, IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER, IP_NULL);
ctx->public.coop_info.session_timedout = IP_FALSE;
if (ctx->proto_adaptor_ctx) {
ipcom_free(ctx->proto_adaptor_ctx);
}
ctx->proto_adaptor_ctx = IP_NULL;
return IPCOM_SUCCESS;
}
/*
*===========================================================================
* ipwps_proto_adaptor_wps_on
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err
ipwps_proto_adaptor_wps_on(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_SUCCESS;
Ip_u32 instance = 0;
Ip_u8 mac_addr[6];
ip_assert(ctx);
ip_assert(ctx->public.if_name);
if (!ctx->proto_adaptor_ctx) {
IPCOM_LOG0(ERR, " ipwps_proto_adaptor_wps_on:: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
/* configure the IP8021X interface */
rc = ip8021x_set_wps_mode(ctx->public.if_name, ctx->public.enabled, ctx->public.wsc_identity, &instance, mac_addr);
if (rc == IPCOM_SUCCESS) {
ctx->public.ip8021x_inst = instance;
ctx->public.ip8021x_ok = IP_TRUE;
ipcom_memcpy(ctx->public.if_mac_addr, mac_addr, 6);
} else {
ctx->public.ip8021x_ok = IP_FALSE;
IPCOM_LOG4(ERR, "ipwps_proto_adaptor_wps_on :: ip8021x_set_wps_mode(%s, %s, %s) failed (%d).",
ctx->public.if_name, (ctx->public.enabled ? "ON" : "OFF"),
ctx->public.wsc_identity, rc);
}
return rc;
}
/*
*===========================================================================
* ipwps_proto_adaptor_wps_off
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err
ipwps_proto_adaptor_wps_off(Ipwps_ctx* ctx) {
Ipwps_proto_adaptor_ctx *my_ctx;
Ip_u32 instance = 0;
my_ctx = ctx->proto_adaptor_ctx;
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_wps_off :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
/* Before we turn wps off, we need to reply to avoid a race condition/deadlock */
if (my_ctx->proto_adaptor_state == IPWPS_PROTO_ADAPTOR_WSC_NOTIFY_RCVD)
(void)ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_OK, 0, IP_NULL);
/* turn off wps support in the IP8021X interface */
(void)ip8021x_set_wps_mode(ctx->public.if_name, IP_FALSE, IP_NULL, &instance, IP_NULL);
ctx->public.ip8021x_inst = 0;
ctx->public.ip8021x_ok = IP_FALSE;
return IPCOM_SUCCESS;
}
/*
*===========================================================================
* ipwps_proto_adaptor_set_methods
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err
ipwps_proto_adaptor_set_methods(Ipwps_ctx* ctx, Ipwps_proto_rcv_methods *methods,
Ipwps_proto_ctx *proto_ctx) {
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_set_methods :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
if (!methods) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_set_methods :: Error! null methods");
return IPCOM_ERR_INVALID_ARG;
}
ipcom_memcpy(&my_ctx->rcv_methods, methods , sizeof(Ipwps_proto_rcv_methods));
my_ctx->proto_ctx = proto_ctx;
if (proto_ctx) {
ctx->public.coop_info.proto_version = proto_ctx->version;
proto_ctx->last_rcvd_proto_msg = &my_ctx->last_rcvd_proto_msg;
proto_ctx->last_sent_proto_msg = &my_ctx->last_sent_proto_msg;
/* Starting a new protocol session so reset previous timeouts and stop timer */
ctx->public.coop_info.session_timedout = IP_FALSE;
ipwps_timer_request(ctx, IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER, IPWPS_TIMER_STOP, IPWPS_TIMER_DONTCARE, 0);
}
return IPCOM_SUCCESS;
}
/*
*===========================================================================
* ipwps_proto_adaptor_remove_methods
*===========================================================================
* Description:
* Set the protocol receive handlers that the protocol adaptor will call.
* Parameters:
* Ipwps_ctx* ctx - A valid configured wps context.
* Ipwps_proto_ctx *proto_ctx - A valid Protocol Handler context associated
* with the receive methods to remove.
* Returns:
* IPCOM_SUCCESS upon success, otherwise a failure indication
*/
IP_GLOBAL Ip_err
ipwps_proto_adaptor_remove_methods(Ipwps_ctx* ctx, Ipwps_proto_ctx *proto_ctx) {
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_remove_methods :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
if (proto_ctx != my_ctx->proto_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_remove_methods :: Error! proto handler context mismatch");
return IPCOM_ERR_FAILED;
}
ipcom_memset(&my_ctx->rcv_methods, 0 , sizeof(Ipwps_proto_rcv_methods));
my_ctx->proto_ctx = IP_NULL;
/* Ending a protocol session so stop timer */
ipwps_timer_request(ctx, IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER, IPWPS_TIMER_STOP, IPWPS_TIMER_DONTCARE, 0);
return IPCOM_SUCCESS;
}
/*
*===========================================================================
* ipwps_proto_adaptor_set_identity
*===========================================================================
* Description:
* Parameters:
* Returns:
*/
IP_GLOBAL Ip_err
ipwps_proto_adaptor_set_identity(Ipwps_ctx* ctx, char *identity) {
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
if (!identity) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_set_identity :: null identity");
return IPCOM_ERR_INVALID_ARG;
}
my_ctx = ctx->proto_adaptor_ctx;
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_set_identity :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
if (strlen(identity) >= IPWPS_MAX_WSC_ID_LEN) {
IPCOM_LOG3(ERR, "ipwps_proto_adaptor_set_identity :: Invalid identity length (%d, max %d, id: %s)",
strlen(identity), IPWPS_MAX_WSC_ID_LEN-1, identity);
return IPCOM_ERR_INVALID_ARG;
}
ipcom_strncpy(ctx->public.wsc_identity, identity, IPWPS_MAX_WSC_ID_LEN);
ctx->public.wsc_identity[IPWPS_MAX_WSC_ID_LEN-1] = '\0';
return IPCOM_SUCCESS;
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_response
*===========================================================================
* Description: For now only supports WSC.
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err
ipwps_proto_adaptor_send_response(Ipwps_ctx* ctx, Ip_err rc, int event_or_rc, Ip_u32 len, Ip_u8 *data) {
Ipwps_wsc_proto_msg *resp_proto_msg = IPWPS_CTX_RESP_PROTO_MSG(ctx);
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_response :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
/*if (len && !data) {
IPCOM_LOG1(ERR, "ipwps_proto_adaptor_send_response :: Error! null data for len %d", len);
return IPCOM_ERR_FAILED;
}*/
if (len && !data) {
IPCOM_LOG1(ERR, "ipwps_proto_adaptor_send_response :: Error! null data for len %d", len);
return IPCOM_ERR_FAILED;
}
if ((my_ctx->proto_adaptor_state != IPWPS_PROTO_ADAPTOR_WSC_NOTIFY_RCVD) &&
(my_ctx->proto_adaptor_state != IPWPS_PROTO_ADAPTOR_EAPOL_NOTIFY_RCVD)) {
IPCOM_LOG1(ERR, "ipwps_proto_adaptor_send_response :: Error! called in state %d",
my_ctx->proto_adaptor_state);
return IPCOM_ERR_FAILED;
}
if (my_ctx->proto_adaptor_state == IPWPS_PROTO_ADAPTOR_WSC_NOTIFY_RCVD) {
#ifdef IPWPS_PROTO_ADAPTOR_USE_DEBUG_LOOPBACK
/* Just now for testing */
if (rc == IPCOM_SUCCESS) {
IPWPS_PREPARE_RESPONSE_MSG_WITHTYPE(ctx, IPWPS_RC_DEBUG_LOOPBACK, IPWPS_MSG_TYPE_WPSPROTO_WSCRESPONSE);
} else
#endif
IPWPS_PREPARE_RESPONSE_MSG_WITHTYPE(ctx, rc, IPWPS_MSG_TYPE_WPSPROTO_WSCRESPONSE);
if (rc == IPCOM_SUCCESS) {
resp_proto_msg->event_or_rc = event_or_rc;
resp_proto_msg->proto_data.len = len;
if (len && data)
ipcom_memcpy(resp_proto_msg->proto_data.data, data, len);
}
} else {
IPWPS_PREPARE_RESPONSE_MSG(ctx, rc);
}
ipwps_send_response_msg(ctx);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG3(DEBUG2, "ipwps_proto_adaptor_send_response :: sent IPWPS_MSG_TYPE_WPSPROTO_WSCRESPONSE "
"with rc = %d (%s) event_or_rc = %d, ",
rc, ipcom_err_string(rc), resp_proto_msg->event_or_rc);
#endif
if (my_ctx->proto_adaptor_state == IPWPS_PROTO_ADAPTOR_WSC_NOTIFY_RCVD)
my_ctx->proto_adaptor_state = IPWPS_PROTO_ADAPTOR_WSC_RESPONSE_SENT;
else if (my_ctx->proto_adaptor_state == IPWPS_PROTO_ADAPTOR_EAPOL_NOTIFY_RCVD)
my_ctx->proto_adaptor_state = IPWPS_PROTO_ADAPTOR_EAPOL_RESPONSE_SENT;
return IPCOM_SUCCESS;
}
/*
*===========================================================================
* ipwps_proto_adaptor_handle_event
*===========================================================================
* Description: .
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err
ipwps_proto_adaptor_handle_event(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
Ipwps_wsc_proto_msg *rcv_proto_msg = IPWPS_CTX_RCVD_PROTO_MSG(ctx);
int event_or_rc = IPWPS_WSC_RC_NOT_SET;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_handle_event :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
if (ctx->event == IPWPS_IPD_EVENT_WPSPROTO) {
switch (ctx->rcvd_ipd_msg.wps_msg_type.wpsproto) {
case IPWPS_MSG_TYPE_WPSPROTO_WSCNOTIFY:
my_ctx->proto_adaptor_state = IPWPS_PROTO_ADAPTOR_WSC_NOTIFY_RCVD;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR_EVENTS
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_handle_event :: received IPWPS_IPD_EVENT_WPSPROTO, "
"IPWPS_MSG_TYPE_WPSPROTO_WSCNOTIFY, event %d, len %d",
rcv_proto_msg->event_or_rc, rcv_proto_msg->proto_data.len);
#endif
my_ctx->last_rcvd_proto_msg.len = rcv_proto_msg->proto_data.len;
if (rcv_proto_msg->proto_data.len) {
ipcom_memcpy(&my_ctx->last_rcvd_proto_msg.data , rcv_proto_msg->proto_data.data, rcv_proto_msg->proto_data.len);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR_EVENTS
ipwps_dump_data("event data", rcv_proto_msg->proto_data.data, rcv_proto_msg->proto_data.len);
#endif
}
switch (rcv_proto_msg->event_or_rc) {
case IPWPS_WSC_EVENT_RCV_ID_RESP:
rc = ipwps_proto_handle_id_resp(ctx);
break;
case IPWPS_WSC_EVENT_RCV_WSC_START:
rc = ipwps_proto_handle_wsc_start(ctx);
break;
case IPWPS_WSC_EVENT_RCV_WSC_ACK:
rc = ipwps_proto_handle_wsc_ack(ctx);
break;
case IPWPS_WSC_EVENT_RCV_WSC_NACK:
rc = ipwps_proto_handle_wsc_nack(ctx);
break;
case IPWPS_WSC_EVENT_RCV_WSC_MSG:
rc = ipwps_proto_handle_wsc_msg(ctx);
break;
case IPWPS_WSC_EVENT_RCV_WSC_DONE:
rc = ipwps_proto_handle_wsc_done(ctx);
break;
case IPWPS_WSC_EVENT_RCV_EAP_FAIL:
rc = ipwps_proto_handle_eap_fail(ctx);
break;
default:
rc = IPCOM_ERR_FAILED;
break;
}
break;
case IPWPS_MSG_TYPE_WPSPROTO_EAPOL_NOTIFY:
my_ctx->proto_adaptor_state = IPWPS_PROTO_ADAPTOR_EAPOL_NOTIFY_RCVD;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG2, "ipwps_proto_adaptor_handle_event :: received IPWPS_IPD_EVENT_WPSPROTO, "
"IPWPS_MSG_TYPE_WPSPROTO_EAPOL_NOTIFY");
#endif
rc = ipwps_proto_handle_eapol_notify(ctx);
break;
default:
rc = IPCOM_ERR_FAILED;
break;
}
}
if ((my_ctx->proto_adaptor_state != IPWPS_PROTO_ADAPTOR_WSC_RESPONSE_SENT) &&
(my_ctx->proto_adaptor_state != IPWPS_PROTO_ADAPTOR_EAPOL_RESPONSE_SENT)) {
if (my_ctx->proto_adaptor_state == IPWPS_PROTO_ADAPTOR_WSC_NOTIFY_RCVD) {
event_or_rc = ((rc == IPCOM_SUCCESS) ? IPWPS_WSC_RC_OK : IPWPS_WSC_RC_FAIL);
rc = ipwps_proto_adaptor_send_response(ctx, rc, event_or_rc, 0, IP_NULL);
} else if (my_ctx->proto_adaptor_state == IPWPS_PROTO_ADAPTOR_EAPOL_NOTIFY_RCVD) {
rc = ipwps_proto_adaptor_send_response(ctx, rc, 0, 0, IP_NULL);
}
}
my_ctx->proto_adaptor_state = IPWPS_PROTO_ADAPTOR_IDLE;
return rc;
}
/*
*===========================================================================
* ipwps_proto_adapor_wps_begin
*===========================================================================
* Description: .
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_wps_begin(Ipwps_ctx* ctx) {
Ip_err rc;
ip_assert(ctx);
if (ctx->public.daemon_status < IPWPSD_STATUS_READY) {
IPCOM_LOG2(ERR, "ipwps_proto_adaptor_wps_begin :: Error! Invalid daemon state %s (%d)",
ipwps_daemon_status(&ctx->public), ctx->public.daemon_status);
return IPCOM_ERR_FAILED;
}
if (!ctx->public.enabled) {
IPCOM_LOG0(ERR, "ipwps_proto_adapor_wps_begin :: FAILURE: WPS not enabled");
return IPCOM_ERR_FAILED;
}
if (!ctx->public.ip8021x_ok) {
IPCOM_LOG0(ERR, "ipwps_proto_adapor_wps_begin :: FAILURE: 8021X WPS interface not configured properly");
return IPCOM_ERR_FAILED;
}
rc = ip8021x_send_eapol_start(ctx->public.ip8021x_inst);
if (rc != IPCOM_SUCCESS)
return rc;
/* We started the WPS protocol exchange so start timer */
ctx->public.coop_info.session_timedout = IP_FALSE;
rc = ipwps_timer_request(ctx, IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER,
IPWPS_TIMER_START, IPWPS_TIMER_ONE_SHOT,
IPWPS_TIMEOUT_VAL_SEC_TO_MSEC(IPWPS_PROTO_COMPLETE_SECONDS));
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_proto_adapor_wps_begin :: Failed to start monitor timer");
}
return rc;
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_START
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_START(struct Ipwps_ctx_st* ctx) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_START :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_START, 0, IP_NULL);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: START",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_START, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_START :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_START :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_M1
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_M1(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_M1* m1) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M1 :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the M1 protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)m1 ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: M1");
return rc;
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_MSG,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: M1",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_M1, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_M1 :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_M1 :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_M2
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_M2(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_M2* m2) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M2 :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the M2 protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)m2 ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: M2");
return rc;
}
if (m2->authenticator.len == 0) {
if (!my_ctx->proto_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M2 :: Error! null protocol context");
return IPCOM_ERR_FAILED;
}
if (ipwps_proto_calc_msgauth(my_ctx->proto_ctx, &my_ctx->last_rcvd_proto_msg,
&my_ctx->last_sent_proto_msg) != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M2 :: failed to calculate message auth");
return IPCOM_ERR_FAILED;
}
/*if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to update authenticator for WPS protocol Message: M2");
return rc;
}*/
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_MSG,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: M2",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_M2, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_M2 :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_M2 :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_M2D
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_M2D(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_M2D* m2d) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M2D :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the M2D protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)m2d ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: M2D");
return rc;
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_MSG,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: M2D",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_M2D, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_M2D :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_M2D :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_M3
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_M3(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_M3* m3) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M3 :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the M3 protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)m3 ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: M3");
return rc;
}
if (m3->authenticator.len == 0) {
if (!my_ctx->proto_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M3 :: Error! null protocol context");
return IPCOM_ERR_FAILED;
}
if (ipwps_proto_calc_msgauth(my_ctx->proto_ctx, &my_ctx->last_rcvd_proto_msg,
&my_ctx->last_sent_proto_msg) != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M3 :: failed to calculate message auth");
return IPCOM_ERR_FAILED;
}
/*if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to update authenticator for WPS protocol Message: M3");
return rc;
}*/
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_MSG,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: M3",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_M3, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_M3 :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_M3 :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_M4
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_M4(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_M4* m4) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M4 :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the M4 protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)m4 ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: M4");
return rc;
}
if (m4->authenticator.len == 0) {
if (!my_ctx->proto_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M4 :: Error! null protocol context");
return IPCOM_ERR_FAILED;
}
if (ipwps_proto_calc_msgauth(my_ctx->proto_ctx, &my_ctx->last_rcvd_proto_msg,
&my_ctx->last_sent_proto_msg) != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M4 :: failed to calculate message auth");
return IPCOM_ERR_FAILED;
}
/*if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to update authenticator for WPS protocol Message: M4");
return rc;
}*/
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_MSG,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: M4",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_M4, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_M4 :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_M4 :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_M5
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_M5(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_M5* m5) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M5 :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the M5 protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)m5 ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: M5");
return rc;
}
if (m5->authenticator.len == 0) {
if (!my_ctx->proto_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M5 :: Error! null protocol context");
return IPCOM_ERR_FAILED;
}
if (ipwps_proto_calc_msgauth(my_ctx->proto_ctx, &my_ctx->last_rcvd_proto_msg,
&my_ctx->last_sent_proto_msg) != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M5 :: failed to calculate message auth");
return IPCOM_ERR_FAILED;
}
/*if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to update authenticator for WPS protocol Message: M5");
return rc;
}*/
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_MSG,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: M5",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_M5, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_M5 :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_M5 :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_M6
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_M6(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_M6* m6) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M6 :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the M6 protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)m6 ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: M6");
return rc;
}
if (m6->authenticator.len == 0) {
if (!my_ctx->proto_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M6 :: Error! null protocol context");
return IPCOM_ERR_FAILED;
}
if (ipwps_proto_calc_msgauth(my_ctx->proto_ctx, &my_ctx->last_rcvd_proto_msg,
&my_ctx->last_sent_proto_msg) != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M6 :: failed to calculate message auth");
return IPCOM_ERR_FAILED;
}
/*if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to update authenticator for WPS protocol Message: M6");
return rc;
}*/
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_MSG,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: M6",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_M6, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_M6 :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_M6 :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_M7
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_M7(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_M7* m7) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M7 :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the M7 protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)m7 ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: M7");
return rc;
}
if (m7->authenticator.len == 0) {
if (!my_ctx->proto_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M7 :: Error! null protocol context");
return IPCOM_ERR_FAILED;
}
if (ipwps_proto_calc_msgauth(my_ctx->proto_ctx, &my_ctx->last_rcvd_proto_msg,
&my_ctx->last_sent_proto_msg) != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M7 :: failed to calculate message auth");
return IPCOM_ERR_FAILED;
}
/*if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to update authenticator for WPS protocol Message: M7");
return rc;
}*/
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_MSG,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: M7",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_M7, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_M7 :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_M7 :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_M8
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_M8(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_M8* m8) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M8 :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the M8 protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)m8 ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: M8");
return rc;
}
if (m8->authenticator.len == 0) {
if (!my_ctx->proto_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M8 :: Error! null protocol context");
return IPCOM_ERR_FAILED;
}
if (ipwps_proto_calc_msgauth(my_ctx->proto_ctx, &my_ctx->last_rcvd_proto_msg,
&my_ctx->last_sent_proto_msg) != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_M8 :: failed to calculate message auth");
return IPCOM_ERR_FAILED;
}
/*if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to update authenticator for WPS protocol Message: M8");
return rc;
}*/
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_MSG,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: M8",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_M8, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_M8 :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_M8 :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_ACK
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_ACK(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_ACK* ack) {
Ip_err rc = IPCOM_ERR_FAILED;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
Ip_err rc1 = IPCOM_ERR_FAILED;
#endif
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_ACK :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the ACK protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)ack ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: ACK");
return rc;
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_ACK,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: ACK",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
rc1 =
#else
(void)
#endif
ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_ACK, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_ACK :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_ACK :: ");
#endif
}
return rc;
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_NACK
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_NACK(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_NACK* nack) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_NACK :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the NACK protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)nack ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: NACK");
return rc;
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_NACK,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: NACK",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_NACK, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_NACK :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_NACK :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_DONE
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_DONE(struct Ipwps_ctx_st* ctx, Ipwps_protomsg_DONE* done) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx = ctx->proto_adaptor_ctx;
ip_assert(ctx);
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_DONE :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
my_ctx->last_sent_proto_msg.len = IPWPS_PROTO_MSG_DATALEN_MAX;
/* create the DONE protocol message */
rc = ipwps_protocol_format_message((Ipwps_protomsg_overlay *)done ,
my_ctx->last_sent_proto_msg.data,
&my_ctx->last_sent_proto_msg.len);
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(DEBUG, "Failed to format WPS protocol Message: DONE");
return rc;
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_SEND_WSC_DONE,
my_ctx->last_sent_proto_msg.len,
my_ctx->last_sent_proto_msg.data);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: DONE",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_DONE, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_DONE :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_DONE :: ");
#endif
}
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_adaptor_send_WPS_FIN
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipwps_proto_adaptor_send_WPS_FIN(struct Ipwps_ctx_st* ctx) {
Ip_err rc = IPCOM_ERR_FAILED, rc1 = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_send_WPS_FIN :: Error! null proto adaptor context");
return IPCOM_ERR_FAILED;
}
/* send the response message */
rc = ipwps_proto_adaptor_send_response(ctx, IPCOM_SUCCESS, IPWPS_WSC_RC_TERMINATE_EAP, 0, IP_NULL);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR: %s WPS protocol Message: WPS FIN",
((rc == IPCOM_SUCCESS) ? "Successfully sent" : "Failed to send"));
#endif
if (my_ctx->proto_ctx) {
rc1 = ipwps_proto_handler_send_notify(ctx, my_ctx->proto_ctx, IPWPS_PROTO_SENDNOTIFY_WPS_FIN, (rc == IPCOM_SUCCESS));
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_adaptor_send_WPS_FIN :: ipwps_proto_handler_send_notify() rc = %d (%s)",
rc1, ipcom_err_string(rc1));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_adaptor_send_WPS_FIN :: ");
#endif
}
/* WPS protocol exchange is completed once we send the WPS FIN (EAP FAIL), so stop timer */
ipwps_timer_request(ctx, IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER, IPWPS_TIMER_STOP, IPWPS_TIMER_DONTCARE, 0);
return (((rc == IPCOM_SUCCESS) && (rc1 == IPCOM_SUCCESS)) ? IPCOM_SUCCESS : IPCOM_ERR_FAILED);
}
/*
*===========================================================================
* ipwps_proto_handle_eapol_notify
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err ipwps_proto_handle_eapol_notify(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
Ipwps_eapol_notification *wps_eapol_notify;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
ip_assert(my_ctx);
wps_eapol_notify = &ctx->rcvd_ipd_msg.wps_msg_data.wps_eapol_notify;
if (wps_eapol_notify->eapol_event != IPWPS_EAPOL_EVENT_RCV_START) {
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(ERR, "ipwps_proto_handle_eapol_notify :: EAPOL NOTIFICATION with invalid eapol_event %d",
wps_eapol_notify->eapol_event);
#endif
return IPCOM_ERR_NOT_SUPPORTED;
}
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG8(ERR, "ipwps_proto_handle_eapol_notify :: EAPOL NOTIFICATION "
"(IPWPS_EAPOL_EVENT_RCV_START, wls_if: %s, ip8021x_inst: %d, peeraddr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x)",
wps_eapol_notify->if_name, wps_eapol_notify->ip8021x_inst, wps_eapol_notify->peeraddr[0],
wps_eapol_notify->peeraddr[1], wps_eapol_notify->peeraddr[2], wps_eapol_notify->peeraddr[3],
wps_eapol_notify->peeraddr[4], wps_eapol_notify->peeraddr[5]);
#endif
if (wps_eapol_notify->ip8021x_inst != ctx->public.ip8021x_inst) {
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(ERR, "ipwps_proto_handle_eapol_notify :: EAPOL NOTIFICATION ip8021x_inst mismatch (act %d, exp %d)",
wps_eapol_notify->ip8021x_inst, ctx->public.ip8021x_inst);
#endif
return IPCOM_ERR_FAILED;
}
if (ipcom_strcmp(wps_eapol_notify->if_name, ctx->public.if_name) != 0) {
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(ERR, "ipwps_proto_handle_eapol_notify :: EAPOL NOTIFICATION if_name mismatch (act: %s, exp: %s)",
wps_eapol_notify->if_name, ctx->public.if_name);
#endif
return IPCOM_ERR_FAILED;
}
if (!my_ctx->rcv_methods.notify_EAPOL_START) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for EAPOL NOTIFICATION");
return IPCOM_ERR_NOT_SUPPORTED;
}
rc = my_ctx->rcv_methods.notify_EAPOL_START(ctx, wps_eapol_notify->peeraddr);
/* We received EAPOL START which indicated the beginnign of the WPS protocol exchange so start timer */
rc = ipwps_timer_request(ctx, IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER,
IPWPS_TIMER_START, IPWPS_TIMER_ONE_SHOT,
IPWPS_TIMEOUT_VAL_SEC_TO_MSEC(IPWPS_PROTO_COMPLETE_SECONDS));
if (rc != IPCOM_SUCCESS) {
IPCOM_LOG0(ERR, "ipwps_proto_handle_eapol_notify :: Failed to start monitor timer");
}
return rc;
}
/*
*===========================================================================
* ipwps_proto_handle_id_resp
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err ipwps_proto_handle_id_resp(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
char *identity;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
ip_assert(my_ctx);
identity = (my_ctx->last_rcvd_proto_msg.len ? (char *)my_ctx->last_rcvd_proto_msg.data : IP_NULL);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG1(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: ID RESPONSE (%s)", identity);
#endif
if (!my_ctx->rcv_methods.rcv_ID_RESP) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for ID RESPONSE. Dropping.");
return IPCOM_ERR_NOT_SUPPORTED;
}
rc = my_ctx->rcv_methods.rcv_ID_RESP(ctx, identity);
return rc;
}
/*
*===========================================================================
* ipwps_proto_handle_wsc_start
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err ipwps_proto_handle_wsc_start(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
ip_assert(my_ctx);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: START msg");
#endif
if (!my_ctx->rcv_methods.rcv_START) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for START msg. Dropping.");
return IPCOM_ERR_NOT_SUPPORTED;
}
if (my_ctx->proto_ctx) {
/* No need to call the handler when no protocol context is present.
* This is to support test apps that use predefined vectors.
*/
rc = ipwps_proto_handler_process_START(ctx, my_ctx->proto_ctx);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_start :: ipwps_proto_handler_process_START() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_start :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_START(ctx);
return rc;
}
/*
*===========================================================================
* ipwps_proto_handle_wsc_msg
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err ipwps_proto_handle_wsc_msg(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
Ipwps_protomsg_overlay *msg;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
ip_assert(my_ctx);
msg = ipwps_protocol_decode_message(my_ctx->last_rcvd_proto_msg.data,
my_ctx->last_rcvd_proto_msg.len);
if (!msg)
return IPCOM_ERR_FAILED;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
ipwps_protocol_display_msg("IPWPS PROTOCOL ADAPTOR Received:", (Ipwps_protomsg_overlay *)msg);
#endif
switch (msg->common_hdr.msg_type.val) {
case IPWPS_PROTO_MSGTYPE_M1:
{
Ipwps_protomsg_M1 *m1 = (Ipwps_protomsg_M1 *)msg;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: M1 msg");
#endif
if (!my_ctx->rcv_methods.rcv_M1) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for M1 msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
break;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_M1(ctx, my_ctx->proto_ctx, m1);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_msg :: ipwps_proto_handler_process_M1() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_msg :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_M1(ctx, m1);
break;
}
case IPWPS_PROTO_MSGTYPE_M2:
{
Ipwps_protomsg_M2 *m2 = (Ipwps_protomsg_M2 *)msg;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: M2 msg");
#endif
if (!my_ctx->rcv_methods.rcv_M2) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for M2 msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
break;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_M2(ctx, my_ctx->proto_ctx, m2);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_msg :: ipwps_proto_handler_process_M2() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_msg :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_M2(ctx, m2);
break;
}
case IPWPS_PROTO_MSGTYPE_M2D:
{
Ipwps_protomsg_M2D *m2d = (Ipwps_protomsg_M2D *)msg;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: M2D msg");
#endif
if (!my_ctx->rcv_methods.rcv_M2D) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for M2D msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
break;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_M2D(ctx, my_ctx->proto_ctx, m2d);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_msg :: ipwps_proto_handler_process_M2D() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_msg :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_M2D(ctx, m2d);
break;
}
case IPWPS_PROTO_MSGTYPE_M3:
{
Ipwps_protomsg_M3 *m3 = (Ipwps_protomsg_M3 *)msg;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: M3 msg");
#endif
if (!my_ctx->rcv_methods.rcv_M3) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for M3 msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
break;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_M3(ctx, my_ctx->proto_ctx, m3);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_msg :: ipwps_proto_handler_process_M3() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_msg :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_M3(ctx, m3);
break;
}
case IPWPS_PROTO_MSGTYPE_M4:
{
Ipwps_protomsg_M4 *m4 = (Ipwps_protomsg_M4 *)msg;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: M4 msg");
#endif
if (!my_ctx->rcv_methods.rcv_M4) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for M4 msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
break;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_M4(ctx, my_ctx->proto_ctx, m4);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_msg :: ipwps_proto_handler_process_M4() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_msg :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_M4(ctx, m4);
break;
}
case IPWPS_PROTO_MSGTYPE_M5:
{
Ipwps_protomsg_M5 *m5 = (Ipwps_protomsg_M5 *)msg;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: M5 msg");
#endif
if (!my_ctx->rcv_methods.rcv_M5) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for M5 msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
break;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_M5(ctx, my_ctx->proto_ctx, m5);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_msg :: ipwps_proto_handler_process_M5() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_msg :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_M5(ctx, m5);
break;
}
case IPWPS_PROTO_MSGTYPE_M6:
{
Ipwps_protomsg_M6 *m6 = (Ipwps_protomsg_M6 *)msg;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: M6 msg");
#endif
if (!my_ctx->rcv_methods.rcv_M6) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for M6 msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
break;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_M6(ctx, my_ctx->proto_ctx, m6);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_msg :: ipwps_proto_handler_process_M6() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_msg :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_M6(ctx, m6);
break;
}
case IPWPS_PROTO_MSGTYPE_M7:
{
Ipwps_protomsg_M7 *m7 = (Ipwps_protomsg_M7 *)msg;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: M7 msg");
#endif
if (!my_ctx->rcv_methods.rcv_M7) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for M7 msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
break;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_M7(ctx, my_ctx->proto_ctx, m7);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_msg :: ipwps_proto_handler_process_M7() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_msg :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_M7(ctx, m7);
break;
}
case IPWPS_PROTO_MSGTYPE_M8:
{
Ipwps_protomsg_M8 *m8 = (Ipwps_protomsg_M8 *)msg;
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: M8 msg");
#endif
if (!my_ctx->rcv_methods.rcv_M8) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for M8 msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
break;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_M8(ctx, my_ctx->proto_ctx, m8);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_msg :: ipwps_proto_handler_process_M8() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_msg :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_M8(ctx, m8);
break;
}
default:
IPCOM_LOG1(ERR, "ipwps_proto_handle_wsc_msg :: Received invalid wps msgtype %d", msg->common_hdr.msg_type.val);
break;
}
if (msg)
ipcom_free(msg);
return rc;
}
/*
*===========================================================================
* ipwps_proto_handle_wsc_done
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err ipwps_proto_handle_wsc_done(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
Ipwps_protomsg_DONE *done;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
ip_assert(my_ctx);
done = (Ipwps_protomsg_DONE *)ipwps_protocol_decode_message(my_ctx->last_rcvd_proto_msg.data,
my_ctx->last_rcvd_proto_msg.len);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
ipwps_protocol_display_msg("IPWPS PROTOCOL ADAPTOR Received:", (Ipwps_protomsg_overlay *)done);
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: DONE msg");
#endif
if (!my_ctx->rcv_methods.rcv_DONE) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for DONE msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
goto done_done;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_DONE(ctx, my_ctx->proto_ctx, done);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_done :: ipwps_proto_handler_process_DONE() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_done :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_DONE(ctx, done);
done_done:
if (done)
ipcom_free(done);
return rc;
}
/*
*===========================================================================
* ipwps_proto_handle_wsc_ack
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err ipwps_proto_handle_wsc_ack(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
Ipwps_protomsg_ACK *ack;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
ip_assert(my_ctx);
ack = (Ipwps_protomsg_ACK *)ipwps_protocol_decode_message(my_ctx->last_rcvd_proto_msg.data,
my_ctx->last_rcvd_proto_msg.len);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
ipwps_protocol_display_msg("IPWPS PROTOCOL ADAPTOR Received:", (Ipwps_protomsg_overlay *)ack);
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: ACK msg");
#endif
if (!my_ctx->rcv_methods.rcv_ACK) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for ACK msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
goto ack_done;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_ACK(ctx, my_ctx->proto_ctx, ack);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_ack :: ipwps_proto_handler_process_ACK() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_ack :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_ACK(ctx, ack);
ack_done:
if (ack)
ipcom_free(ack);
return rc;
}
/*
*===========================================================================
* ipwps_proto_handle_wsc_nack
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err ipwps_proto_handle_wsc_nack(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
Ipwps_protomsg_NACK *nack;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
ip_assert(my_ctx);
nack = (Ipwps_protomsg_NACK *)ipwps_protocol_decode_message(my_ctx->last_rcvd_proto_msg.data,
my_ctx->last_rcvd_proto_msg.len);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
ipwps_protocol_display_msg("IPWPS PROTOCOL ADAPTOR Received:", (Ipwps_protomsg_overlay *)nack);
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: NACK msg");
#endif
if (!my_ctx->rcv_methods.rcv_NACK) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for NACK msg. Dropping.");
rc = IPCOM_ERR_NOT_SUPPORTED;
goto nack_done;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_NACK(ctx, my_ctx->proto_ctx, nack);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_wsc_nack :: ipwps_proto_handler_process_NACK() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_wsc_nack :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
rc = my_ctx->rcv_methods.rcv_NACK(ctx, nack);
nack_done:
if (nack)
ipcom_free(nack);
return rc;
}
/*
*===========================================================================
* ipwps_proto_handle_eap_fail
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err ipwps_proto_handle_eap_fail(Ipwps_ctx* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
my_ctx = ctx->proto_adaptor_ctx;
ip_assert(my_ctx);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: EAP FAIL notification");
#endif
if (!my_ctx->rcv_methods.notify_wps_fin) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for WPS FIN NOTIFICATION. Dropping.");
return IPCOM_ERR_NOT_SUPPORTED;
}
if (my_ctx->proto_ctx) {
rc = ipwps_proto_handler_process_WPS_FIN(ctx, my_ctx->proto_ctx);
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG2(DEBUG2, "ipwps_proto_handle_eap_fail :: ipwps_proto_handler_process_WPS_FIN() rc = %d (%s)",
rc, ipcom_err_string(rc));
ipwps_proto_log_sm_state_info(my_ctx->proto_ctx, "ipwps_proto_handle_eap_fail :: ");
#endif
if (rc != IPCOM_SUCCESS) {
ip_assert(IPWPS_PROTO_SM_STATE_ERROR(my_ctx->proto_ctx));
}
}
/* WPS protocol exchange is completed once we receive the WPS FIN (EAP FAIL), so stop timer */
ipwps_timer_request(ctx, IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER, IPWPS_TIMER_STOP, IPWPS_TIMER_DONTCARE, 0);
rc = my_ctx->rcv_methods.notify_wps_fin(ctx);
return rc;
}
/*
*===========================================================================
* ipwps_proto_adaptor_timeout_handler
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC Ip_err
ipwps_proto_adaptor_timeout_handler(struct Ipwps_ctx_st* ctx) {
Ip_err rc = IPCOM_ERR_FAILED;
Ipwps_msg_type_wpstimeout tmo_evtype;
Ipwps_proto_adaptor_ctx *my_ctx;
ip_assert(ctx);
tmo_evtype = IPWPS_GET_TIMEOUT_EVENT_TYPE(ctx);
if (tmo_evtype != IPWPS_MSG_TYPE_WPSTIMEOUT_PROTO_STE_TIMER) {
IPCOM_LOG1(ERR, "Ipwps_enrollee_timeout_handler :: Unexpected timeout event type %d", tmo_evtype);
return IPCOM_ERR_INVALID_ARG;
}
#ifdef IPWPS_DEBUG_PROTO_ADAPTOR
IPCOM_LOG0(DEBUG, "IPWPS PROTOCOL ADAPTOR Received: PROTOCOL TIMEOUT");
#endif
my_ctx = ctx->proto_adaptor_ctx;
if (!my_ctx) {
IPCOM_LOG0(ERR, "ipwps_proto_adaptor_timeout_handler :: null protocol adaptor context");
return IPCOM_ERR_FAILED;
}
ctx->public.coop_info.session_timedout = IP_TRUE;
if (!my_ctx->rcv_methods.notify_wps_timeout) {
IPCOM_LOG0(ERR, "IPWPS PROTO ADAPTOR has no handler registered for WPS TIMEOUT NOTIFICATION.");
return IPCOM_ERR_NOT_SUPPORTED;
}
rc = my_ctx->rcv_methods.notify_wps_timeout(ctx);
return rc;
}