add NetX default IO context handling

This commit is contained in:
toddouska 2013-06-24 14:00:48 -07:00
parent 17ab84eb07
commit b51d6f3b8f
7 changed files with 171 additions and 3 deletions

View File

@ -6,7 +6,7 @@
# #
# #
AC_INIT([cyassl],[2.7.0],[http://www.yassl.com]) AC_INIT([cyassl],[2.7.1],[http://www.yassl.com])
AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])

View File

@ -82,10 +82,29 @@
#define SIZEOF_LONG_LONG 8 #define SIZEOF_LONG_LONG 8
#endif #endif
#ifdef COMVERGE
#define THREADX
#define HAVE_NETX
#define CYASSL_USER_IO
#define NO_WRITEV
#define NO_DEV_RANDOM
#define NO_FILESYSTEM
#define NO_SHA512
#define NO_DH
#define NO_DSA
#define NO_HC128
#endif
#ifdef THREADX #ifdef THREADX
#define SIZEOF_LONG_LONG 8 #define SIZEOF_LONG_LONG 8
#endif #endif
#ifdef HAVE_NETX
#include "nx_api.h"
#endif
#ifdef MICROCHIP_PIC32 #ifdef MICROCHIP_PIC32
#define SIZEOF_LONG_LONG 8 #define SIZEOF_LONG_LONG 8
#define SINGLE_THREADED #define SINGLE_THREADED

View File

@ -100,6 +100,7 @@
#endif #endif
#endif #endif
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
#include "zlib.h" #include "zlib.h"
#endif #endif
@ -942,6 +943,11 @@ int SetCipherList(Suites*, const char* list);
#endif /* CYASSL_DTLS */ #endif /* CYASSL_DTLS */
#endif /* CYASSL_USER_IO */ #endif /* CYASSL_USER_IO */
#ifdef HAVE_NETX
CYASSL_LOCAL int NetX_Receive(CYASSL *ssl, char *buf, int sz, void *ctx);
CYASSL_LOCAL int NetX_Send(CYASSL *ssl, char *buf, int sz, void *ctx);
#endif /* HAVE_NETX */
/* CyaSSL Cipher type just points back to SSL */ /* CyaSSL Cipher type just points back to SSL */
struct CYASSL_CIPHER { struct CYASSL_CIPHER {
@ -1692,6 +1698,19 @@ typedef struct DtlsMsg {
} DtlsMsg; } DtlsMsg;
#ifdef HAVE_NETX
/* NETX I/O Callback default */
typedef struct NetX_Ctx {
NX_TCP_SOCKET* nxSocket; /* send/recv socket handle */
NX_PACKET* nxPacket; /* incoming packet handle for short reads */
ULONG nxOffset; /* offset already read from nxPacket */
ULONG nxWait; /* wait option flag */
} NetX_Ctx;
#endif
/* CyaSSL ssl type */ /* CyaSSL ssl type */
struct CYASSL { struct CYASSL {
CYASSL_CTX* ctx; CYASSL_CTX* ctx;
@ -1794,6 +1813,9 @@ struct CYASSL {
#ifdef HAVE_MAX_FRAGMENT #ifdef HAVE_MAX_FRAGMENT
word16 max_fragment; word16 max_fragment;
#endif #endif
#endif
#ifdef HAVE_NETX
NetX_Ctx nxCtx; /* NetX IO Context */
#endif #endif
CYASSL_ALERT_HISTORY alert_history; CYASSL_ALERT_HISTORY alert_history;
}; };

View File

@ -838,6 +838,11 @@ CYASSL_API void CyaSSL_SetIOWriteCtx(CYASSL* ssl, void *ctx);
CYASSL_API void CyaSSL_SetIOReadFlags( CYASSL* ssl, int flags); CYASSL_API void CyaSSL_SetIOReadFlags( CYASSL* ssl, int flags);
CYASSL_API void CyaSSL_SetIOWriteFlags(CYASSL* ssl, int flags); CYASSL_API void CyaSSL_SetIOWriteFlags(CYASSL* ssl, int flags);
#ifdef HAVE_NETX
CYASSL_API void CyaSSL_SetIO_NetX(CYASSL* ssl, NX_TCP_SOCKET* nxsocket,
ULONG waitoption);
#endif
typedef int (*CallbackGenCookie)(CYASSL* ssl, unsigned char* buf, int sz, typedef int (*CallbackGenCookie)(CYASSL* ssl, unsigned char* buf, int sz,
void* ctx); void* ctx);
CYASSL_API void CyaSSL_CTX_SetGenCookie(CYASSL_CTX*, CallbackGenCookie); CYASSL_API void CyaSSL_CTX_SetGenCookie(CYASSL_CTX*, CallbackGenCookie);

View File

@ -26,8 +26,8 @@
extern "C" { extern "C" {
#endif #endif
#define LIBCYASSL_VERSION_STRING "2.7.0" #define LIBCYASSL_VERSION_STRING "2.7.1"
#define LIBCYASSL_VERSION_HEX 0x02007000 #define LIBCYASSL_VERSION_HEX 0x02007001
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -385,6 +385,10 @@ int InitSSL_Ctx(CYASSL_CTX* ctx, CYASSL_METHOD* method)
#ifdef CYASSL_DTLS #ifdef CYASSL_DTLS
ctx->CBIOCookie = NULL; ctx->CBIOCookie = NULL;
#endif #endif
#endif /* CYASSL_USER_IO */
#ifdef HAVE_NETX
ctx->CBIORecv = NetX_Receive;
ctx->CBIOSend = NetX_Send;
#endif #endif
ctx->partialWrite = 0; ctx->partialWrite = 0;
ctx->verifyCallback = 0; ctx->verifyCallback = 0;
@ -1290,6 +1294,14 @@ int InitSSL(CYASSL* ssl, CYASSL_CTX* ctx)
ssl->IOCB_ReadCtx = &ssl->rfd; /* prevent invalid pointer access if not */ ssl->IOCB_ReadCtx = &ssl->rfd; /* prevent invalid pointer access if not */
ssl->IOCB_WriteCtx = &ssl->wfd; /* correctly set */ ssl->IOCB_WriteCtx = &ssl->wfd; /* correctly set */
#ifdef HAVE_NETX
ssl->nxCtx.nxSocket = NULL;
ssl->nxCtx.nxPacket = NULL;
ssl->nxCtx.nxOffset = 0;
ssl->nxCtx.nxWait = 0;
ssl->IOCB_ReadCtx = &ssl->nxCtx; /* default NetX IO ctx, same for read */
ssl->IOCB_WriteCtx = &ssl->nxCtx; /* and write */
#endif
#ifdef CYASSL_DTLS #ifdef CYASSL_DTLS
ssl->IOCB_CookieCtx = NULL; /* we don't use for default cb */ ssl->IOCB_CookieCtx = NULL; /* we don't use for default cb */
ssl->dtls_expected_rx = MAX_MTU; ssl->dtls_expected_rx = MAX_MTU;

110
src/io.c
View File

@ -845,3 +845,113 @@ CYASSL_API void CyaSSL_SetIOOcspCtx(CYASSL_CTX* ctx, void *octx)
} }
#endif #endif
#ifdef HAVE_NETX
/* The NetX receive callback
* return : bytes read, or error
*/
int NetX_Receive(CYASSL *ssl, char *buf, int sz, void *ctx)
{
NetX_Ctx* nxCtx = (NetX_Ctx*)ctx;
ULONG left;
ULONG total;
ULONG copied = 0;
UINT status;
if (nxCtx == NULL || nxCtx->nxSocket == NULL) {
CYASSL_MSG("NetX Recv NULL parameters");
return CYASSL_CBIO_ERR_GENERAL;
}
if (nxCtx->nxPacket == NULL) {
status = nx_tcp_socket_receive(nxCtx->nxSocket, &nxCtx->nxPacket,
nxCtx->nxWait);
if (status != NX_SUCCESS) {
CYASSL_MSG("NetX Recv receive error");
return CYASSL_CBIO_ERR_GENERAL;
}
}
if (nxCtx->nxPacket) {
status = nx_packet_length_get(nxCtx->nxPacket, &total);
if (status != NX_SUCCESS) {
CYASSL_MSG("NetX Recv length get error");
return CYASSL_CBIO_ERR_GENERAL;
}
left = total - nxCtx->nxOffset;
status = nx_packet_data_extract_offset(nxCtx->nxPacket, nxCtx->nxOffset,
buf, sz, &copied);
if (status != NX_SUCCESS) {
CYASSL_MSG("NetX Recv data extract offset error");
return CYASSL_CBIO_ERR_GENERAL;
}
nxCtx->nxOffset += copied;
if (copied == left) {
CYASSL_MSG("NetX Recv Drained packet");
nx_packet_release(nxCtx->nxPacket);
nxCtx->nxPacket = NULL;
nxCtx->nxOffset = 0;
}
}
return copied;
}
/* The NetX send callback
* return : bytes sent, or error
*/
int NetX_Send(CYASSL* ssl, char *buf, int sz, void *ctx)
{
NetX_Ctx* nxCtx = (NetX_Ctx*)ctx;
NX_PACKET* packet;
NX_PACKET_POOL* pool; /* shorthand */
UINT status;
if (nxCtx == NULL || nxCtx->nxSocket == NULL) {
CYASSL_MSG("NetX Send NULL parameters");
return CYASSL_CBIO_ERR_GENERAL;
}
pool = nxCtx->nxSocket->nx_tcp_socket_ip_ptr->nx_ip_default_packet_pool;
status = nx_packet_allocate(pool, &packet, NX_TCP_PACKET,
nxCtx->nxWait);
if (status != NX_SUCCESS) {
CYASSL_MSG("NetX Send packet alloc error");
return CYASSL_CBIO_ERR_GENERAL;
}
status = nx_packet_data_append(packet, buf, sz, pool, nxCtx->nxWait);
if (status != NX_SUCCESS) {
nx_packet_release(packet);
CYASSL_MSG("NetX Send data append error");
return CYASSL_CBIO_ERR_GENERAL;
}
status = nx_tcp_socket_send(nxCtx->nxSocket, packet, nxCtx->nxWait);
if (status != NX_SUCCESS) {
nx_packet_release(packet);
CYASSL_MSG("NetX Send socket send error");
return CYASSL_CBIO_ERR_GENERAL;
}
return sz;
}
/* like set_fd, but for default NetX context */
void CyaSSL_SetIO_NetX(CYASSL* ssl, NX_TCP_SOCKET* nxSocket, ULONG waitOption)
{
if (ssl) {
ssl->nxCtx.nxSocket = nxSocket;
ssl->nxCtx.nxWait = waitOption;
}
}
#endif /* HAVE_NETX */