Skip to content

Commit c2b9cc5

Browse files
authored
Merge pull request #10408 from hmohide/master
Add UDP support to NetX sockets for DTLS sessions
1 parent b4d51db commit c2b9cc5

7 files changed

Lines changed: 387 additions & 29 deletions

File tree

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ WOLFSSL_MONT_RED_CT
835835
WOLFSSL_MP_COND_COPY
836836
WOLFSSL_MP_INVMOD_CONSTANT_TIME
837837
WOLFSSL_MULTICIRCULATE_ALTNAMELIST
838+
WOLFSSL_NETX_DUO
838839
WOLFSSL_NEW_PRIME_CHECK
839840
WOLFSSL_NONBLOCK_OCSP
840841
WOLFSSL_NOSHA3_384

doc/dox_comments/header_files-ja/wolfio.h

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,22 +404,22 @@ void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
404404
/*!
405405
\ingroup IO
406406
407-
\brief この関数は、WOLFSSL構造体内のnxCtx構造体のnxSocketおよびnxWaitメンバーを設定します
407+
\brief この関数は、WOLFSSL構造体内のnxCtx構造体のnxTcpSocketおよびnxWaitメンバーを設定します
408408
409409
\return none 戻り値なし。
410410
411411
\param ssl wolfSSL_new()を使用して作成されたWOLFSSL構造体へのポインタ。
412-
\param nxSocket nxCTX構造体のnxSocketメンバーに設定されるNX_TCP_SOCKET型へのポインタ
413-
\param waitOption nxCtx構造体のnxWaitメンバーに設定されるULONG型。
412+
\param nxsocket nxCtx構造体のnxTcpSocketメンバーに設定されるNX_TCP_SOCKET型へのポインタ
413+
\param waitoption nxCtx構造体のnxWaitメンバーに設定されるULONG型。
414414
415415
_Example_
416416
\code
417417
WOLFSSL* ssl = wolfSSL_new(ctx);
418-
NX_TCP_SOCKET* nxSocket;
419-
ULONG waitOption;
418+
NX_TCP_SOCKET* nxsocket;
419+
ULONG waitoption;
420420
421-
if(ssl != NULL || nxSocket != NULL || waitOption <= 0){
422-
wolfSSL_SetIO_NetX(ssl, nxSocket, waitOption);
421+
if(ssl != NULL || nxsocket != NULL || waitoption <= 0){
422+
wolfSSL_SetIO_NetX(ssl, nxsocket, waitoption);
423423
} else {
424424
// 適切なパラメータを渡す必要があります。
425425
}
@@ -432,6 +432,40 @@ void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
432432
void wolfSSL_SetIO_NetX(WOLFSSL* ssl, NX_TCP_SOCKET* nxsocket,
433433
ULONG waitoption);
434434

435+
/*!
436+
\ingroup IO
437+
438+
\brief この関数は、DTLSセッション用のNetX Duo UDPコンテキストを設定します。
439+
UDPソケット、送信先IPアドレス(値渡し)、送信先ポート、待機オプションを
440+
WOLFSSL nxCtx構造体に格納します。WOLFSSL_NETX_DUOの定義が必要です(ThreadX NetX Duo SDK)。
441+
442+
\return none 戻り値なし。
443+
444+
\param ssl wolfSSL_new()を使用して作成されたWOLFSSL構造体へのポインタ。
445+
\param nxsocket 作成・バインド済みのNX_UDP_SOCKETへのポインタ。
446+
\param nxdip 送信先NXD_ADDRESS(値渡し;IPv4またはIPv6)。
447+
\param nxport 送信先UDPポート番号。
448+
\param waitoption NetX待機オプション(例:NX_WAIT_FOREVERまたはティック数)。
449+
450+
_Example_
451+
\code
452+
WOLFSSL* ssl = wolfSSL_new(ctx);
453+
NX_UDP_SOCKET udpsocket;
454+
NXD_ADDRESS peeraddr;
455+
USHORT peerport = 4433;
456+
ULONG wait = NX_WAIT_FOREVER;
457+
// … udpsocketとpeeraddrを初期化 …
458+
wolfSSL_SetIO_NetX_Dtls(ssl, &udpsocket, peeraddr, peerport, wait);
459+
\endcode
460+
461+
\sa wolfSSL_SetIO_NetX
462+
\sa NetX_SendTo
463+
\sa NetX_ReceiveFrom
464+
*/
465+
void wolfSSL_SetIO_NetX_Dtls(WOLFSSL* ssl, NX_UDP_SOCKET* nxsocket,
466+
NXD_ADDRESS nxdip, USHORT nxport,
467+
ULONG waitoption);
468+
435469
/*!
436470
\brief この関数は、WOLFSSL_CTX構造体のCBIOCookieメンバーのコールバックを設定します。
437471
CallbackGenCookie型は関数ポインタで、次のシグネチャを持ちます:

doc/dox_comments/header_files/wolfio.h

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,25 +450,25 @@ void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
450450
/*!
451451
\ingroup IO
452452
453-
\brief This function sets the nxSocket and nxWait members of the nxCtx
453+
\brief This function sets the nxTcpSocket and nxWait members of the nxCtx
454454
struct within the WOLFSSL structure.
455455
456456
\return none No returns.
457457
458458
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
459-
\param nxSocket a pointer to type NX_TCP_SOCKET that is set to the
460-
nxSocket member of the nxCTX structure.
461-
\param waitOption a ULONG type that is set to the nxWait member of
459+
\param nxsocket a pointer to type NX_TCP_SOCKET that is set to the
460+
nxTcpSocket member of the nxCtx structure.
461+
\param waitoption a ULONG type that is set to the nxWait member of
462462
the nxCtx structure.
463463
464464
_Example_
465465
\code
466466
WOLFSSL* ssl = wolfSSL_new(ctx);
467-
NX_TCP_SOCKET* nxSocket;
468-
ULONG waitOption;
467+
NX_TCP_SOCKET* nxsocket;
468+
ULONG waitoption;
469469
470-
if(ssl != NULL || nxSocket != NULL || waitOption <= 0){
471-
wolfSSL_SetIO_NetX(ssl, nxSocket, waitOption);
470+
if(ssl != NULL || nxsocket != NULL || waitoption <= 0){
471+
wolfSSL_SetIO_NetX(ssl, nxsocket, waitoption);
472472
} else {
473473
// You need to pass in good parameters.
474474
}
@@ -481,6 +481,41 @@ void wolfSSL_SetIOWriteFlags(WOLFSSL* ssl, int flags);
481481
void wolfSSL_SetIO_NetX(WOLFSSL* ssl, NX_TCP_SOCKET* nxsocket,
482482
ULONG waitoption);
483483

484+
/*!
485+
\ingroup IO
486+
487+
\brief This function configures the NetX Duo UDP context for a DTLS
488+
session. It stores the UDP socket, destination IP address (by value),
489+
destination port, and wait option into the WOLFSSL nxCtx structure.
490+
Requires WOLFSSL_NETX_DUO to be defined (ThreadX NetX Duo SDK).
491+
492+
\return none No returns.
493+
494+
\param ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
495+
\param nxsocket a pointer to an NX_UDP_SOCKET already created and bound.
496+
\param nxdip the destination NXD_ADDRESS (passed by value; IPv4 or IPv6).
497+
\param nxport the destination UDP port number.
498+
\param waitoption a ULONG NetX wait option (e.g. NX_WAIT_FOREVER or ticks).
499+
500+
_Example_
501+
\code
502+
WOLFSSL* ssl = wolfSSL_new(ctx);
503+
NX_UDP_SOCKET udpsocket;
504+
NXD_ADDRESS peeraddr;
505+
USHORT peerport = 4433;
506+
ULONG wait = NX_WAIT_FOREVER;
507+
// … initialise udpsocket and peeraddr …
508+
wolfSSL_SetIO_NetX_Dtls(ssl, &udpsocket, peeraddr, peerport, wait);
509+
\endcode
510+
511+
\sa wolfSSL_SetIO_NetX
512+
\sa NetX_SendTo
513+
\sa NetX_ReceiveFrom
514+
*/
515+
void wolfSSL_SetIO_NetX_Dtls(WOLFSSL* ssl, NX_UDP_SOCKET* nxsocket,
516+
NXD_ADDRESS nxdip, USHORT nxport,
517+
ULONG waitoption);
518+
484519
/*!
485520
\brief This function sets the callback for the CBIOCookie member of the
486521
WOLFSSL_CTX structure. The CallbackGenCookie type is a function pointer

src/internal.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,12 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap)
27062706
#ifdef HAVE_NETX
27072707
ctx->CBIORecv = NetX_Receive;
27082708
ctx->CBIOSend = NetX_Send;
2709+
#if defined(WOLFSSL_DTLS) && defined(WOLFSSL_NETX_DUO)
2710+
if (method->version.major == DTLS_MAJOR) {
2711+
ctx->CBIORecv = NetX_ReceiveFrom;
2712+
ctx->CBIOSend = NetX_SendTo;
2713+
}
2714+
#endif /* WOLFSSL_DTLS && WOLFSSL_NETX_DUO */
27092715
#elif defined(WOLFSSL_APACHE_MYNEWT) && !defined(WOLFSSL_LWIP)
27102716
ctx->CBIORecv = Mynewt_Receive;
27112717
ctx->CBIOSend = Mynewt_Send;
@@ -8110,9 +8116,13 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
81108116
if (wc_InitRwLock(&ssl->buffers.dtlsCtx.peerLock) != 0)
81118117
return BAD_MUTEX_E;
81128118
#endif
8113-
8119+
#ifdef HAVE_NETX
8120+
ssl->IOCB_ReadCtx = &ssl->nxCtx; /* default NetX IO ctx, same for read */
8121+
ssl->IOCB_WriteCtx = &ssl->nxCtx; /* and write */
8122+
#else
81148123
ssl->IOCB_ReadCtx = &ssl->buffers.dtlsCtx; /* prevent invalid pointer access if not */
81158124
ssl->IOCB_WriteCtx = &ssl->buffers.dtlsCtx; /* correctly set */
8125+
#endif
81168126
#else
81178127
#ifdef HAVE_NETX
81188128
ssl->IOCB_ReadCtx = &ssl->nxCtx; /* default NetX IO ctx, same for read */

0 commit comments

Comments
 (0)