diff --git a/addons/BSD/nxd_bsd.c b/addons/BSD/nxd_bsd.c index c14740fe..168b5689 100644 --- a/addons/BSD/nxd_bsd.c +++ b/addons/BSD/nxd_bsd.c @@ -105,7 +105,7 @@ TX_BLOCK_POOL nx_bsd_addrinfo_block_pool; * 3 blocks for addrinfo) + 1 block for IP adddress = 4 blocks */ static ULONG nx_bsd_addrinfo_pool_memory[(NX_BSD_IPV4_ADDR_MAX_NUM + NX_BSD_IPV6_ADDR_MAX_NUM) * 4 - *(sizeof(struct addrinfo) + sizeof(VOID *)) / sizeof(ULONG)]; + *(sizeof(struct nx_bsd_addrinfo) + sizeof(VOID *)) / sizeof(ULONG)]; #ifdef NX_BSD_ENABLE_DNS @@ -169,13 +169,13 @@ static ULONG _nx_bsd_string_length(CHAR * string); #ifdef NX_BSD_RAW_PPPOE_SUPPORT static INT nx_bsd_pppoe_internal_sendto(NX_BSD_SOCKET *bsd_socket_ptr, CHAR *msg, INT msgLength, - INT flags, struct sockaddr* destAddr, INT destAddrLen); + INT flags, struct nx_bsd_sockaddr* destAddr, INT destAddrLen); static UINT nx_bsd_socket_create_id = 0; #endif /* NX_BSD_RAW_PPPOE_SUPPORT */ #ifdef NX_BSD_RAW_SUPPORT static INT _nx_bsd_hardware_internal_sendto(NX_BSD_SOCKET *bsd_socket_ptr, CHAR *msg, INT msgLength, - INT flags, struct sockaddr* destAddr, INT destAddrLen); + INT flags, struct nx_bsd_sockaddr* destAddr, INT destAddrLen); static VOID _nx_bsd_hardware_packet_received(NX_PACKET *packet_ptr, UCHAR *consumed); #endif /* NX_BSD_RAW_SUPPORT */ static VOID _nx_bsd_fast_periodic_timer_entry(ULONG id); @@ -205,7 +205,7 @@ static struct NX_BSD_SERVICE_LIST *_nx_bsd_serv_list_ptr; /* FUNCTION RELEASE */ /* */ /* bsd_initialize PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -255,9 +255,12 @@ static struct NX_BSD_SERVICE_LIST *_nx_bsd_serv_list_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT bsd_initialize(NX_IP *default_ip, NX_PACKET_POOL *default_pool, CHAR *bsd_thread_stack_area, +INT nx_bsd_initialize(NX_IP *default_ip, NX_PACKET_POOL *default_pool, CHAR *bsd_thread_stack_area, ULONG bsd_thread_stack_size, UINT bsd_thread_priority) { @@ -287,7 +290,7 @@ ULONG info; } /* Create a block pool for dynamically allocating addrinfo. */ - status = tx_block_pool_create(&nx_bsd_addrinfo_block_pool, "NetX BSD Addrinfo Block Pool", sizeof(struct addrinfo), + status = tx_block_pool_create(&nx_bsd_addrinfo_block_pool, "NetX BSD Addrinfo Block Pool", sizeof(struct nx_bsd_addrinfo), nx_bsd_addrinfo_pool_memory, sizeof(nx_bsd_addrinfo_pool_memory)); /* Determine if the pool was created. */ @@ -664,7 +667,7 @@ VOID nx_bsd_thread_entry(ULONG info) /* FUNCTION RELEASE */ /* */ /* socket PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -709,9 +712,12 @@ VOID nx_bsd_thread_entry(ULONG info) /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT socket(INT protocolFamily, INT type, INT protocol) +INT nx_bsd_socket(INT protocolFamily, INT type, INT protocol) { INT i; @@ -750,7 +756,7 @@ UINT index; { /* Set the socket error. */ - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -765,7 +771,7 @@ UINT index; { /* Set the socket error. */ - set_errno(EPROTOTYPE); + nx_bsd_set_errno(EPROTOTYPE); /* Invalid type. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -778,7 +784,7 @@ UINT index; if((protocolFamily == AF_PACKET) && (type != SOCK_RAW)) { /* Set the socket error. */ - set_errno(EPROTOTYPE); + nx_bsd_set_errno(EPROTOTYPE); /* Invalid type. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -795,7 +801,7 @@ UINT index; { /* Set the socket error. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Error getting the protection mutex. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -859,7 +865,7 @@ UINT index; /* No, set the error status and return. */ /* Set the socket error. */ - set_errno(ENFILE); + nx_bsd_set_errno(ENFILE); /* Release the mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -899,7 +905,7 @@ UINT index; { /* Set the socket error. */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* Clear the allocated internal BSD socket. */ bsd_socket_ptr -> nx_bsd_socket_status_flags &= (ULONG)(~NX_BSD_SOCKET_IN_USE); @@ -951,7 +957,7 @@ UINT index; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the allocated socket memory block. */ tx_block_release(socket_memory); @@ -1033,7 +1039,7 @@ UINT index; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error getting NetX socket memory. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1066,7 +1072,7 @@ UINT index; /* Release the mutex. */ tx_mutex_put(nx_bsd_protection_ptr); - set_errno(EPROTONOSUPPORT); + nx_bsd_set_errno(EPROTONOSUPPORT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -1089,7 +1095,7 @@ UINT index; /* Release the mutex. */ tx_mutex_put(nx_bsd_protection_ptr); - set_errno(EPROTONOSUPPORT); + nx_bsd_set_errno(EPROTONOSUPPORT); /* No, return error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1145,7 +1151,7 @@ UINT index; else { /* Not a supported socket type. */ - set_errno(EOPNOTSUPP); + nx_bsd_set_errno(EOPNOTSUPP); /* Invalid type. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1181,7 +1187,7 @@ UINT index; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error present, return error code. */ NX_BSD_ERROR(status, __LINE__); @@ -1201,7 +1207,7 @@ UINT index; /* FUNCTION RELEASE */ /* */ /* connect PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -1259,9 +1265,12 @@ UINT index; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT connect(INT sockID, struct sockaddr *remoteAddress, INT addressLength) +INT nx_bsd_connect(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT addressLength) { UINT status; NX_TCP_SOCKET *tcp_socket_ptr; @@ -1275,7 +1284,7 @@ ULONG actual_status; { /* Set the socket error. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1293,7 +1302,7 @@ ULONG actual_status; { /* Set the socket error. */ - set_errno(EFAULT); + nx_bsd_set_errno(EFAULT); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1310,7 +1319,7 @@ ULONG actual_status; /* Socket is no longer in use. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1325,7 +1334,7 @@ ULONG actual_status; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -1362,7 +1371,7 @@ ULONG actual_status; /* Release the mutex. */ tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1373,8 +1382,8 @@ ULONG actual_status; /* Check if the remote address family matches the local BSD socket address family. */ if((remoteAddress -> sa_family != bsd_socket_ptr -> nx_bsd_socket_family) || - ((remoteAddress -> sa_family == AF_INET) && (addressLength != sizeof(struct sockaddr_in))) || - ((remoteAddress -> sa_family == AF_INET6) && (addressLength != sizeof(struct sockaddr_in6)))) + ((remoteAddress -> sa_family == AF_INET) && (addressLength != sizeof(struct nx_bsd_sockaddr_in))) || + ((remoteAddress -> sa_family == AF_INET6) && (addressLength != sizeof(struct nx_bsd_sockaddr_in6)))) { /* Mismatch! */ @@ -1383,7 +1392,7 @@ ULONG actual_status; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(ERROR); @@ -1401,8 +1410,8 @@ ULONG actual_status; /* NetX API expects multi byte values to be in host byte order. Therefore ntohl/s are used to make the conversion. */ bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_version = NX_IP_VERSION_V4; - bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v4 = htonl(((struct sockaddr_in *) remoteAddress ) -> sin_addr.s_addr); - bsd_socket_ptr -> nx_bsd_socket_peer_port = htons(((struct sockaddr_in *) remoteAddress ) -> sin_port); + bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v4 = htonl(((struct nx_bsd_sockaddr_in *) remoteAddress ) -> sin_addr.s_addr); + bsd_socket_ptr -> nx_bsd_socket_peer_port = htons(((struct nx_bsd_sockaddr_in *) remoteAddress ) -> sin_port); } else #endif /* NX_DISABLE_IPV4 */ @@ -1416,12 +1425,12 @@ ULONG actual_status; /* NetX API expects multi byte values to be in host byte order. Therefore ntohl/s are used to make the conversion. */ /* Get remote address and port. */ - bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v6[0] = htonl(((struct sockaddr_in6*)remoteAddress) -> sin6_addr._S6_un._S6_u32[0]); - bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v6[1] = htonl(((struct sockaddr_in6*)remoteAddress) -> sin6_addr._S6_un._S6_u32[1]); - bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v6[2] = htonl(((struct sockaddr_in6*)remoteAddress) -> sin6_addr._S6_un._S6_u32[2]); - bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v6[3] = htonl(((struct sockaddr_in6*)remoteAddress) -> sin6_addr._S6_un._S6_u32[3]); + bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v6[0] = htonl(((struct nx_bsd_sockaddr_in6*)remoteAddress) -> sin6_addr._S6_un._S6_u32[0]); + bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v6[1] = htonl(((struct nx_bsd_sockaddr_in6*)remoteAddress) -> sin6_addr._S6_un._S6_u32[1]); + bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v6[2] = htonl(((struct nx_bsd_sockaddr_in6*)remoteAddress) -> sin6_addr._S6_un._S6_u32[2]); + bsd_socket_ptr -> nx_bsd_socket_peer_ip.nxd_ip_address.v6[3] = htonl(((struct nx_bsd_sockaddr_in6*)remoteAddress) -> sin6_addr._S6_un._S6_u32[3]); - bsd_socket_ptr -> nx_bsd_socket_peer_port = htons(((struct sockaddr_in6 *) remoteAddress ) -> sin6_port); + bsd_socket_ptr -> nx_bsd_socket_peer_port = htons(((struct nx_bsd_sockaddr_in6 *) remoteAddress ) -> sin6_port); } else @@ -1434,7 +1443,7 @@ ULONG actual_status; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(ERROR); @@ -1523,7 +1532,7 @@ ULONG actual_status; } /* Already connected. */ - set_errno(EISCONN); + nx_bsd_set_errno(EISCONN); tx_mutex_put(nx_bsd_protection_ptr); @@ -1538,7 +1547,7 @@ ULONG actual_status; { - set_errno(EALREADY); + nx_bsd_set_errno(EALREADY); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1560,7 +1569,7 @@ ULONG actual_status; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & ((ULONG)(~NX_BSD_SOCKET_ERROR)); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1652,7 +1661,7 @@ ULONG actual_status; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1745,7 +1754,7 @@ ULONG actual_status; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error. */ - set_errno(EINTR); + nx_bsd_set_errno(EINTR); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1757,7 +1766,7 @@ ULONG actual_status; /* FUNCTION RELEASE */ /* */ /* bind PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -1801,9 +1810,12 @@ ULONG actual_status; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT bind(INT sockID, struct sockaddr *localAddress, INT addressLength) +INT nx_bsd_bind(INT sockID, const struct nx_bsd_sockaddr *localAddress, INT addressLength) { INT local_port = 0; @@ -1820,7 +1832,7 @@ INT address_conflict; { /* Set the socket error. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Error, invalid socket ID. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1832,17 +1844,17 @@ INT address_conflict; { /* Set the socket error if extended socket options enabled. */ - set_errno(EFAULT); + nx_bsd_set_errno(EFAULT); /* Error, invalid local address. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - if (((localAddress -> sa_family == AF_INET) && (addressLength != sizeof(struct sockaddr_in))) || - ((localAddress -> sa_family == AF_INET6) && (addressLength != sizeof(struct sockaddr_in6)))) + if (((localAddress -> sa_family == AF_INET) && (addressLength != sizeof(struct nx_bsd_sockaddr_in))) || + ((localAddress -> sa_family == AF_INET6) && (addressLength != sizeof(struct nx_bsd_sockaddr_in6)))) { - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1860,7 +1872,7 @@ INT address_conflict; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -1879,7 +1891,7 @@ INT address_conflict; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -1894,7 +1906,7 @@ INT address_conflict; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(bsd_socket_ptr -> nx_bsd_socket_error_code); + nx_bsd_set_errno(bsd_socket_ptr -> nx_bsd_socket_error_code); /* Clear the error code. */ bsd_socket_ptr -> nx_bsd_socket_error_code = 0; @@ -1916,7 +1928,7 @@ INT address_conflict; /* Check the address family. */ if (bsd_socket_ptr -> nx_bsd_socket_family != localAddress -> sa_family) { - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1932,7 +1944,7 @@ INT address_conflict; /* It is. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -1953,10 +1965,10 @@ INT address_conflict; INT if_index; /* Pickup the local port. */ - local_port = ntohs(((struct sockaddr_in *) localAddress) -> sin_port); + local_port = ntohs(((struct nx_bsd_sockaddr_in *) localAddress) -> sin_port); /* Pick up the local IP address */ - local_addr = ntohl(((struct sockaddr_in*)localAddress) -> sin_addr.s_addr); + local_addr = ntohl(((struct nx_bsd_sockaddr_in*)localAddress) -> sin_addr.s_addr); if(local_addr == INADDR_ANY) { @@ -1990,12 +2002,12 @@ INT address_conflict; INT if_index; /* Pickup the local port. */ - local_port = ntohs(((struct sockaddr_in6 *) localAddress) -> sin6_port); + local_port = ntohs(((struct nx_bsd_sockaddr_in6 *) localAddress) -> sin6_port); - ipv6_addr[0] = ntohl((((struct sockaddr_in6*)localAddress)) -> sin6_addr._S6_un._S6_u32[0]); - ipv6_addr[1] = ntohl((((struct sockaddr_in6*)localAddress)) -> sin6_addr._S6_un._S6_u32[1]); - ipv6_addr[2] = ntohl((((struct sockaddr_in6*)localAddress)) -> sin6_addr._S6_un._S6_u32[2]); - ipv6_addr[3] = ntohl((((struct sockaddr_in6*)localAddress)) -> sin6_addr._S6_un._S6_u32[3]); + ipv6_addr[0] = ntohl((((struct nx_bsd_sockaddr_in6*)localAddress)) -> sin6_addr._S6_un._S6_u32[0]); + ipv6_addr[1] = ntohl((((struct nx_bsd_sockaddr_in6*)localAddress)) -> sin6_addr._S6_un._S6_u32[1]); + ipv6_addr[2] = ntohl((((struct nx_bsd_sockaddr_in6*)localAddress)) -> sin6_addr._S6_un._S6_u32[2]); + ipv6_addr[3] = ntohl((((struct nx_bsd_sockaddr_in6*)localAddress)) -> sin6_addr._S6_un._S6_u32[3]); if((ipv6_addr[0] | ipv6_addr[1] | ipv6_addr[2] | ipv6_addr[3]) == 0) { @@ -2025,7 +2037,7 @@ INT address_conflict; } #endif #ifdef NX_BSD_RAW_SUPPORT - if ((localAddress -> sa_family == AF_PACKET) && (addressLength == sizeof(struct sockaddr_ll))) + if ((localAddress -> sa_family == AF_PACKET) && (addressLength == sizeof(struct nx_bsd_sockaddr_ll))) { UINT if_index; @@ -2043,7 +2055,7 @@ INT address_conflict; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EADDRNOTAVAIL); + nx_bsd_set_errno(EADDRNOTAVAIL); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -2268,7 +2280,7 @@ INT address_conflict; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EADDRINUSE); + nx_bsd_set_errno(EADDRINUSE); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -2355,7 +2367,7 @@ INT address_conflict; /* FUNCTION RELEASE */ /* */ /* listen PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -2400,9 +2412,12 @@ INT address_conflict; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT listen(INT sockID, INT backlog) +INT nx_bsd_listen(INT sockID, INT backlog) { UINT status; @@ -2417,7 +2432,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2435,7 +2450,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -2450,7 +2465,7 @@ INT ret; { /* The underlying protocol is not TCP, therefore it does not support the listen operation. */ - set_errno(EOPNOTSUPP); + nx_bsd_set_errno(EOPNOTSUPP); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2465,7 +2480,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2487,7 +2502,7 @@ INT ret; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2513,7 +2528,7 @@ INT ret; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2530,7 +2545,7 @@ INT ret; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EOPNOTSUPP); + nx_bsd_set_errno(EOPNOTSUPP); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2545,7 +2560,7 @@ INT ret; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error code. */ - set_errno(EDESTADDRREQ); + nx_bsd_set_errno(EDESTADDRREQ); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2602,7 +2617,7 @@ INT ret; /* FUNCTION RELEASE */ /* */ /* accept PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -2654,9 +2669,12 @@ INT ret; /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT accept(INT sockID, struct sockaddr *ClientAddress, INT *addressLength) +INT nx_bsd_accept(INT sockID, struct nx_bsd_sockaddr *ClientAddress, INT *addressLength) { /* Define the accept function if NetX BSD accept() is not set to asynchronous (on automatic callback). */ @@ -2669,10 +2687,12 @@ INT connected = 0; ULONG requested_events; INT secondary_socket_id = 0; #ifndef NX_DISABLE_IPV4 -struct sockaddr_in peer4_address; +struct nx_bsd_sockaddr_in + peer4_address; #endif /* NX_DISABLE_IPV4 */ #ifdef FEATURE_NX_IPV6 -struct sockaddr_in6 peer6_address; +struct nx_bsd_sockaddr_in6 + peer6_address; #endif @@ -2681,7 +2701,7 @@ struct sockaddr_in6 peer6_address; { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error.*/ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2702,7 +2722,7 @@ struct sockaddr_in6 peer6_address; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error.*/ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -2717,7 +2737,7 @@ struct sockaddr_in6 peer6_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2737,7 +2757,7 @@ struct sockaddr_in6 peer6_address; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2764,7 +2784,7 @@ struct sockaddr_in6 peer6_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EOPNOTSUPP); + nx_bsd_set_errno(EOPNOTSUPP); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2781,7 +2801,7 @@ struct sockaddr_in6 peer6_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2799,7 +2819,7 @@ struct sockaddr_in6 peer6_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2867,7 +2887,7 @@ struct sockaddr_in6 peer6_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EWOULDBLOCK); + nx_bsd_set_errno(EWOULDBLOCK); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2889,7 +2909,7 @@ struct sockaddr_in6 peer6_address; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -2913,7 +2933,7 @@ struct sockaddr_in6 peer6_address; bsd_secondary_socket -> nx_bsd_socket_status_flags = bsd_secondary_socket -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -2974,11 +2994,11 @@ struct sockaddr_in6 peer6_address; /* Copy the peer address/port info to the ClientAddress. Truncate if addressLength is smaller than the size of struct sockaddr_in */ - if(*addressLength > (INT)sizeof(struct sockaddr_in)) + if(*addressLength > (INT)sizeof(struct nx_bsd_sockaddr_in)) { - memcpy(ClientAddress, &peer4_address, sizeof(struct sockaddr_in)); /* Use case of memcpy is verified. */ - *addressLength = sizeof(struct sockaddr_in); + memcpy(ClientAddress, &peer4_address, sizeof(struct nx_bsd_sockaddr_in)); /* Use case of memcpy is verified. */ + *addressLength = sizeof(struct nx_bsd_sockaddr_in); } else { @@ -3021,7 +3041,7 @@ struct sockaddr_in6 peer6_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Make sure this thread is still the owner. */ if (bsd_socket_ptr -> nx_bsd_socket_busy == tx_thread_identify()) @@ -3208,7 +3228,7 @@ ULONG data_sent = (ULONG)msgLength; if(packet_type == 0) { /* Set the socket error. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error status.*/ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3240,7 +3260,7 @@ ULONG data_sent = (ULONG)msgLength; { /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -3257,7 +3277,7 @@ ULONG data_sent = (ULONG)msgLength; nx_packet_release(packet_ptr); /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -3276,7 +3296,7 @@ ULONG data_sent = (ULONG)msgLength; nx_packet_release(packet_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error status.*/ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -3291,7 +3311,7 @@ ULONG data_sent = (ULONG)msgLength; nx_packet_release(packet_ptr); /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -3469,20 +3489,20 @@ ULONG data_sent = (ULONG)msgLength; { case NX_IP_ADDRESS_ERROR: - set_errno(EDESTADDRREQ); + nx_bsd_set_errno(EDESTADDRREQ); break; case NX_NOT_ENABLED: - set_errno(EPROTONOSUPPORT); + nx_bsd_set_errno(EPROTONOSUPPORT); break; case NX_NOT_CONNECTED: - set_errno(ENOTCONN); + nx_bsd_set_errno(ENOTCONN); break; case NX_NO_PACKET: case NX_UNDERFLOW: - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); break; case NX_WINDOW_OVERFLOW: @@ -3490,16 +3510,16 @@ ULONG data_sent = (ULONG)msgLength; case NX_TX_QUEUE_DEPTH: if ((bsd_socket_ptr -> nx_bsd_socket_option_flags & NX_BSD_SOCKET_ENABLE_OPTION_NON_BLOCKING) || (flags & MSG_DONTWAIT)) - set_errno( EWOULDBLOCK); + nx_bsd_set_errno( EWOULDBLOCK); else - set_errno(ETIMEDOUT); + nx_bsd_set_errno(ETIMEDOUT); break; default: /* NX_NOT_BOUND */ /* NX_PTR_ERROR */ /* NX_INVALID_PACKET */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); break; } @@ -3523,7 +3543,7 @@ ULONG data_sent = (ULONG)msgLength; /* FUNCTION RELEASE */ /* */ /* send PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -3581,9 +3601,12 @@ ULONG data_sent = (ULONG)msgLength; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT send(INT sockID, const CHAR *msg, INT msgLength, INT flags) +INT nx_bsd_send(INT sockID, const CHAR *msg, INT msgLength, INT flags) { NX_BSD_SOCKET *bsd_socket_ptr; @@ -3594,7 +3617,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error status.*/ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3619,7 +3642,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3641,7 +3664,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; if(bsd_socket_ptr -> nx_bsd_socket_family == AF_PACKET) { /* Set the socket error */ - set_errno(ENOTCONN); + nx_bsd_set_errno(ENOTCONN); /* Return an error status.*/ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3654,7 +3677,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; if(!(bsd_socket_ptr -> nx_bsd_socket_status_flags & NX_BSD_SOCKET_TX_HDR_INCLUDE)) { /* Set the socket error */ - set_errno(ENOTCONN); + nx_bsd_set_errno(ENOTCONN); /* Return an error status.*/ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3675,7 +3698,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* FUNCTION RELEASE */ /* */ /* sendto PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -3729,9 +3752,12 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT sendto(INT sockID, CHAR *msg, INT msgLength, INT flags, struct sockaddr *destAddr, INT destAddrLen) +INT nx_bsd_sendto(INT sockID, CHAR *msg, INT msgLength, INT flags, struct nx_bsd_sockaddr *destAddr, INT destAddrLen) { UINT status; NX_BSD_SOCKET *bsd_socket_ptr; @@ -3743,7 +3769,7 @@ USHORT peer_port = 0; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3765,7 +3791,7 @@ USHORT peer_port = 0; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3782,7 +3808,7 @@ USHORT peer_port = 0; { if((bsd_socket_ptr -> nx_bsd_socket_status_flags & NX_BSD_SOCKET_CONNECTED) == 0) { - set_errno(ENOTCONN); + nx_bsd_set_errno(ENOTCONN); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3825,7 +3851,7 @@ USHORT peer_port = 0; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -3834,7 +3860,7 @@ USHORT peer_port = 0; /* Validate the destination address. */ if(bsd_socket_ptr -> nx_bsd_socket_family != destAddr -> sa_family) { - set_errno(EAFNOSUPPORT); + nx_bsd_set_errno(EAFNOSUPPORT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3850,7 +3876,7 @@ USHORT peer_port = 0; status = nx_udp_socket_bind(bsd_socket_ptr -> nx_bsd_socket_udp_socket, NX_ANY_PORT, NX_NO_WAIT); if((status != NX_SUCCESS) && (status != NX_ALREADY_BOUND)) { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -3876,8 +3902,8 @@ USHORT peer_port = 0; /* This is for an IPv4 packet. */ peer_ip_address.nxd_ip_version = NX_IP_VERSION_V4; - peer_ip_address.nxd_ip_address.v4 = htonl(((struct sockaddr_in *) destAddr) -> sin_addr.s_addr); - peer_port = htons(((struct sockaddr_in *) destAddr) -> sin_port); + peer_ip_address.nxd_ip_address.v4 = htonl(((struct nx_bsd_sockaddr_in *) destAddr) -> sin_addr.s_addr); + peer_port = htons(((struct nx_bsd_sockaddr_in *) destAddr) -> sin_port); /* Local interface ID is set to invalid value, so the send routine needs to find the best interface to send the packet based on destination IP address. */ @@ -3891,12 +3917,12 @@ USHORT peer_port = 0; /* This is for an IPv6 packet. Set the NetX Duo IP address version. */ peer_ip_address.nxd_ip_version = NX_IP_VERSION_V6; - peer_ip_address.nxd_ip_address.v6[0] = ntohl(((struct sockaddr_in6*)destAddr) -> sin6_addr._S6_un._S6_u32[0]); - peer_ip_address.nxd_ip_address.v6[1] = ntohl(((struct sockaddr_in6*)destAddr) -> sin6_addr._S6_un._S6_u32[1]); - peer_ip_address.nxd_ip_address.v6[2] = ntohl(((struct sockaddr_in6*)destAddr) -> sin6_addr._S6_un._S6_u32[2]); - peer_ip_address.nxd_ip_address.v6[3] = ntohl(((struct sockaddr_in6*)destAddr) -> sin6_addr._S6_un._S6_u32[3]); + peer_ip_address.nxd_ip_address.v6[0] = ntohl(((struct nx_bsd_sockaddr_in6*)destAddr) -> sin6_addr._S6_un._S6_u32[0]); + peer_ip_address.nxd_ip_address.v6[1] = ntohl(((struct nx_bsd_sockaddr_in6*)destAddr) -> sin6_addr._S6_un._S6_u32[1]); + peer_ip_address.nxd_ip_address.v6[2] = ntohl(((struct nx_bsd_sockaddr_in6*)destAddr) -> sin6_addr._S6_un._S6_u32[2]); + peer_ip_address.nxd_ip_address.v6[3] = ntohl(((struct nx_bsd_sockaddr_in6*)destAddr) -> sin6_addr._S6_un._S6_u32[3]); - peer_port = htons(((struct sockaddr_in6 *) destAddr) -> sin6_port); + peer_port = htons(((struct nx_bsd_sockaddr_in6 *) destAddr) -> sin6_port); } #endif @@ -3918,7 +3944,7 @@ USHORT peer_port = 0; /* FUNCTION RELEASE */ /* */ /* recv PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -3980,9 +4006,12 @@ USHORT peer_port = 0; /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT recv(INT sockID, VOID *rcvBuffer, INT bufferLength, INT flags) +INT nx_bsd_recv(INT sockID, VOID *rcvBuffer, INT bufferLength, INT flags) { UINT status; @@ -4003,7 +4032,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4044,7 +4073,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -4064,7 +4093,7 @@ ULONG start_time = nx_bsd_system_clock; bsd_socket_ptr -> nx_bsd_socket_status_flags = bsd_socket_ptr -> nx_bsd_socket_status_flags & (ULONG)(~NX_BSD_SOCKET_ERROR); - set_errno(errcode); + nx_bsd_set_errno(errcode); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -4092,7 +4121,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -4140,7 +4169,7 @@ ULONG start_time = nx_bsd_system_clock; } /* Set the socket status (not really an error). */ - set_errno(ENOTCONN); + nx_bsd_set_errno(ENOTCONN); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4199,9 +4228,9 @@ ULONG start_time = nx_bsd_system_clock; if ((bsd_socket_ptr -> nx_bsd_socket_option_flags & NX_BSD_SOCKET_ENABLE_OPTION_NON_BLOCKING) || (wait_option == NX_WAIT_FOREVER) || (flags & MSG_DONTWAIT)) - set_errno(EWOULDBLOCK); + nx_bsd_set_errno(EWOULDBLOCK); else - set_errno (EAGAIN); + nx_bsd_set_errno(EAGAIN); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4211,7 +4240,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4226,7 +4255,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -4238,7 +4267,7 @@ ULONG start_time = nx_bsd_system_clock; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -4270,7 +4299,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -4400,7 +4429,7 @@ ULONG start_time = nx_bsd_system_clock; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -4474,7 +4503,7 @@ ULONG start_time = nx_bsd_system_clock; /* FUNCTION RELEASE */ /* */ /* recvfrom PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4525,18 +4554,23 @@ ULONG start_time = nx_bsd_system_clock; /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT recvfrom(INT sockID, CHAR *rcvBuffer, INT bufferLength, INT flags, struct sockaddr *fromAddr, INT *fromAddrLen) +INT nx_bsd_recvfrom(INT sockID, CHAR *rcvBuffer, INT bufferLength, INT flags, struct nx_bsd_sockaddr *fromAddr, INT *fromAddrLen) { INT bytes_received; NX_BSD_SOCKET *bsd_socket_ptr; #ifndef NX_DISABLE_IPV4 -struct sockaddr_in peer4_address; +struct nx_bsd_sockaddr_in + peer4_address; #endif /* NX_DISABLE_IPV4 */ #ifdef FEATURE_NX_IPV6 -struct sockaddr_in6 peer6_address; +struct nx_bsd_sockaddr_in6 + peer6_address; #endif /* Check for a valid socket ID. */ @@ -4544,7 +4578,7 @@ struct sockaddr_in6 peer6_address; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -4556,7 +4590,7 @@ struct sockaddr_in6 peer6_address; /* Socket error checking is done inside recv() call. */ /* Call the equivalent recv() function. */ - bytes_received = recv(sockID, rcvBuffer, bufferLength, flags); + bytes_received = nx_bsd_recv(sockID, rcvBuffer, bufferLength, flags); /* Check for error. */ if (bytes_received < 0) @@ -4598,9 +4632,9 @@ struct sockaddr_in6 peer6_address; } /* Copy the peer address/port info to the ClientAddress. Truncate if addressLength is smaller than the size of struct sockaddr_in */ - if(*fromAddrLen > (INT)sizeof(struct sockaddr_in)) + if(*fromAddrLen > (INT)sizeof(struct nx_bsd_sockaddr_in)) { - *fromAddrLen = sizeof(struct sockaddr_in); + *fromAddrLen = sizeof(struct nx_bsd_sockaddr_in); } memcpy(fromAddr, &peer4_address, (UINT)(*fromAddrLen)); /* Use case of memcpy is verified. */ } @@ -4647,9 +4681,9 @@ struct sockaddr_in6 peer6_address; #if defined(NX_BSD_RAW_PPPOE_SUPPORT) || defined(NX_BSD_RAW_SUPPORT) if(bsd_socket_ptr -> nx_bsd_socket_family == AF_PACKET) { - if(*fromAddrLen >= (INT)sizeof(struct sockaddr_ll)) + if(*fromAddrLen >= (INT)sizeof(struct nx_bsd_sockaddr_ll)) { - struct sockaddr_ll *sockaddr = (struct sockaddr_ll*)fromAddr; + struct nx_bsd_sockaddr_ll *sockaddr = (struct nx_bsd_sockaddr_ll*)fromAddr; INT i; sockaddr -> sll_family = AF_PACKET; sockaddr -> sll_protocol = bsd_socket_ptr -> nx_bsd_socket_sll_protocol; @@ -4659,7 +4693,7 @@ struct sockaddr_in6 peer6_address; sockaddr -> sll_halen = 6; for(i = 0; i < 6; i++) sockaddr -> sll_addr[i] = bsd_socket_ptr -> nx_bsd_socket_sll_addr[i]; - *fromAddrLen = sizeof(struct sockaddr_ll); + *fromAddrLen = sizeof(struct nx_bsd_sockaddr_ll); } } @@ -4671,7 +4705,7 @@ struct sockaddr_in6 peer6_address; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error, IPv6 support is not enabled. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -4689,7 +4723,7 @@ struct sockaddr_in6 peer6_address; /* FUNCTION RELEASE */ /* */ /* soc_close PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4746,9 +4780,12 @@ struct sockaddr_in6 peer6_address; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT soc_close(INT sockID) +INT nx_bsd_soc_close(INT sockID) { NX_BSD_SOCKET *bsd_socket_ptr; @@ -4770,7 +4807,7 @@ UINT index; { /* Set the socket error. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Error, invalid socket ID. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4806,7 +4843,7 @@ UINT index; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -4871,7 +4908,7 @@ UINT index; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -4968,7 +5005,7 @@ UINT index; /* The socket is no longer in use. */ /* Set the socket error code. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -5150,7 +5187,7 @@ UINT index; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -5165,7 +5202,7 @@ UINT index; /* FUNCTION RELEASE */ /* */ /* fcntl PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5204,9 +5241,12 @@ UINT index; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT fcntl(INT sockID, UINT flag_type, UINT f_options) +INT nx_bsd_fcntl(INT sockID, UINT flag_type, UINT f_options) { NX_BSD_SOCKET *bsd_socket_ptr; @@ -5216,7 +5256,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -5258,7 +5298,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* Flag_type is not the one we support */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -5275,7 +5315,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* FUNCTION RELEASE */ /* */ /* ioctl PORTABLE C */ -/* 6.2.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5320,9 +5360,12 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* 03-08-2023 Wenhui Xie Modified comment(s), corrected*/ /* the result of FIONREAD, */ /* resulting in version 6.2.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT ioctl(INT sockID, INT command, INT *result) +INT nx_bsd_ioctl(INT sockID, INT command, INT *result) { NX_BSD_SOCKET *bsd_socket_ptr; @@ -5374,7 +5417,7 @@ UINT status; { tx_mutex_put(nx_bsd_protection_ptr); - set_errno(EFAULT); + nx_bsd_set_errno(EFAULT); /* Error, invalid address. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -5401,7 +5444,7 @@ UINT status; else { *result += (INT)(bsd_socket_ptr -> nx_bsd_socket_received_byte_count); - } + } } else if (udp_socket_ptr) { @@ -5421,7 +5464,7 @@ UINT status; { tx_mutex_put(nx_bsd_protection_ptr); - set_errno(EFAULT); + nx_bsd_set_errno(EFAULT); /* Error, invalid address. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -5467,7 +5510,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* inet_ntoa PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5504,9 +5547,12 @@ UINT status; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -CHAR *inet_ntoa(struct in_addr address_to_convert) +CHAR *nx_bsd_inet_ntoa(struct nx_bsd_in_addr address_to_convert) { UINT status; @@ -5634,7 +5680,7 @@ UINT size; /* FUNCTION RELEASE */ /* */ /* inet_aton PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5672,9 +5718,12 @@ UINT size; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT inet_aton(const CHAR *address_buffer_ptr, struct in_addr *addr) +INT nx_bsd_inet_aton(const CHAR *address_buffer_ptr, struct nx_bsd_in_addr *addr) { ULONG value; INT base = 10, ip_address_index; @@ -5915,7 +5964,7 @@ UINT dot_flag; /* FUNCTION RELEASE */ /* */ /* inet_addr PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5950,15 +5999,18 @@ UINT dot_flag; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -in_addr_t inet_addr(const CHAR *buffer) +nx_bsd_in_addr_t nx_bsd_inet_addr(const CHAR *buffer) { -struct in_addr ip_address; +struct nx_bsd_in_addr ip_address; UINT status; - status = (UINT)inet_aton(buffer, &ip_address); + status = (UINT)nx_bsd_inet_aton(buffer, &ip_address); if (status == 0) { @@ -5974,7 +6026,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* getsockopt PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -6014,21 +6066,24 @@ UINT status; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getsockopt(INT sockID, INT option_level, INT option_name, VOID *option_value, INT *option_length) +INT nx_bsd_getsockopt(INT sockID, INT option_level, INT option_name, VOID *option_value, INT *option_length) { TX_INTERRUPT_SAVE_AREA -INT status; -NX_BSD_SOCKET *bsd_socket_ptr; -struct sock_errno *so_errno; -struct sock_keepalive *so_keepalive; -struct sock_reuseaddr *so_reuseaddr; -struct timeval *so_rcvtimeval; -struct sock_winsize *soc_window_size; -ULONG ticks; +INT status; +NX_BSD_SOCKET *bsd_socket_ptr; +struct nx_bsd_sock_errno *so_errno; +struct nx_bsd_sock_keepalive *so_keepalive; +struct nx_bsd_sock_reuseaddr *so_reuseaddr; +struct nx_bsd_timeval *so_rcvtimeval; +struct nx_bsd_sock_winsize *soc_window_size; +ULONG ticks; /* Check for valid socket ID/descriptor. */ @@ -6036,7 +6091,7 @@ ULONG ticks; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -6047,7 +6102,7 @@ ULONG ticks; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6062,7 +6117,7 @@ ULONG ticks; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6077,7 +6132,7 @@ ULONG ticks; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6089,7 +6144,7 @@ ULONG ticks; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6106,7 +6161,7 @@ ULONG ticks; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -6129,13 +6184,13 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - so_errno = (struct sock_errno *)option_value; + so_errno = (struct nx_bsd_sock_errno *)option_value; TX_DISABLE if(bsd_socket_ptr -> nx_bsd_socket_status_flags & NX_BSD_SOCKET_ERROR) @@ -6153,7 +6208,7 @@ ULONG ticks; TX_RESTORE /* Set the actual size of the data returned. */ - *option_length = sizeof(struct sock_errno); + *option_length = sizeof(struct nx_bsd_sock_errno); } @@ -6170,19 +6225,19 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - so_keepalive = (struct sock_keepalive *)option_value; + so_keepalive = (struct nx_bsd_sock_keepalive *)option_value; #ifndef NX_ENABLE_TCP_KEEPALIVE so_keepalive -> keepalive_enabled = NX_FALSE; #else so_keepalive -> keepalive_enabled = (INT)(bsd_socket_ptr -> nx_bsd_socket_tcp_socket -> nx_tcp_socket_keepalive_enabled); #endif /* NX_ENABLE_TCP_KEEPALIVE */ - *option_length = sizeof(struct sock_keepalive); + *option_length = sizeof(struct nx_bsd_sock_keepalive); break; @@ -6194,27 +6249,27 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - so_rcvtimeval = (struct timeval *)option_value; + so_rcvtimeval = (struct nx_bsd_timeval *)option_value; ticks = bsd_socket_ptr -> nx_bsd_option_receive_timeout; - so_rcvtimeval -> tv_usec = (suseconds_t)(ticks * NX_MICROSECOND_PER_CPU_TICK) % 1000000; - so_rcvtimeval -> tv_sec = (time_t)((ticks * NX_MICROSECOND_PER_CPU_TICK) / 1000000); + so_rcvtimeval -> tv_usec = (nx_bsd_suseconds_t)(ticks * NX_MICROSECOND_PER_CPU_TICK) % 1000000; + so_rcvtimeval -> tv_sec = (nx_bsd_time_t)((ticks * NX_MICROSECOND_PER_CPU_TICK) / 1000000); *option_length = sizeof(so_rcvtimeval); break; case SO_RCVBUF: - soc_window_size = (struct sock_winsize *)option_value; + soc_window_size = (struct nx_bsd_sock_winsize *)option_value; soc_window_size -> winsize = (INT)(bsd_socket_ptr -> nx_bsd_socket_tcp_socket -> nx_tcp_socket_rx_window_default); *option_length = sizeof(soc_window_size); @@ -6229,15 +6284,15 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - so_reuseaddr= (struct sock_reuseaddr *)option_value; + so_reuseaddr= (struct nx_bsd_sock_reuseaddr *)option_value; so_reuseaddr -> reuseaddr_enabled = bsd_socket_ptr -> nx_bsd_socket_option_flags & NX_BSD_SOCKET_ENABLE_OPTION_REUSEADDR; - *option_length = sizeof(struct sock_reuseaddr); + *option_length = sizeof(struct nx_bsd_sock_reuseaddr); break; @@ -6250,7 +6305,7 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6263,7 +6318,7 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6276,7 +6331,7 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6291,7 +6346,7 @@ ULONG ticks; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); /* Unsupported or unknown option. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6309,7 +6364,7 @@ ULONG ticks; /* FUNCTION RELEASE */ /* */ /* setsockopt PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -6348,20 +6403,24 @@ ULONG ticks; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT setsockopt(INT sockID, INT option_level, INT option_name, const VOID *option_value, INT option_length) +INT nx_bsd_setsockopt(INT sockID, INT option_level, INT option_name, const VOID *option_value, INT option_length) { -UINT reuse_enabled; -NX_BSD_SOCKET *bsd_socket_ptr; -ULONG window_size; -ULONG timer_ticks; -struct timeval *time_val; +UINT reuse_enabled; +NX_BSD_SOCKET *bsd_socket_ptr; +ULONG window_size; +ULONG timer_ticks; +struct nx_bsd_timeval *time_val; #if defined(NX_ENABLE_IP_RAW_PACKET_FILTER) || !defined(NX_DISABLE_IPV4) INT i; #endif /* defined(NX_ENABLE_IP_RAW_PACKET_FILTER) || !defined(NX_DISABLE_IPV4) */ #ifndef NX_DISABLE_IPV4 -struct ip_mreq *mreq; +struct nx_bsd_ip_mreq + *mreq; UINT mcast_interface; UINT status; #endif /* NX_DISABLE_IPV4 */ @@ -6374,7 +6433,7 @@ UINT status; /* Error, invalid socket ID. */ /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -6387,7 +6446,7 @@ UINT status; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6402,7 +6461,7 @@ UINT status; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6417,18 +6476,33 @@ UINT status; /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; } } + else if (option_level == IPPROTO_TCP) + { + + if ((option_name > TCP_NOOPT) || + (option_name < TCP_NODELAY)) + { + /* Error, one or more invalid arguments. */ + + /* Set the socket error if extended socket options enabled. */ + nx_bsd_set_errno(ENOPROTOOPT); + + NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); + return NX_SOC_ERROR; + } + } else { /* Error, one or more invalid arguments. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6458,7 +6532,7 @@ UINT status; #ifndef NX_ENABLE_TCP_KEEPALIVE /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6468,7 +6542,7 @@ UINT status; /* Update the BSD socket with this attribute. */ bsd_socket_ptr -> nx_bsd_socket_tcp_socket -> nx_tcp_socket_keepalive_enabled = - (UINT)(((struct sock_keepalive *)option_value) -> keepalive_enabled); + (UINT)(((struct nx_bsd_sock_keepalive *)option_value) -> keepalive_enabled); if (bsd_socket_ptr -> nx_bsd_socket_tcp_socket -> nx_tcp_socket_keepalive_enabled == NX_TRUE) { @@ -6489,7 +6563,7 @@ UINT status; /* Not a TCP socket. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6506,7 +6580,7 @@ UINT status; case SO_SNDTIMEO: - time_val = (struct timeval *)option_value; + time_val = (struct nx_bsd_timeval *)option_value; /* Calculate ticks for the ThreadX Timer. */ timer_ticks = (ULONG)(time_val -> tv_usec)/NX_MICROSECOND_PER_CPU_TICK + (ULONG)(time_val -> tv_sec) * NX_IP_PERIODIC_RATE; @@ -6517,7 +6591,7 @@ UINT status; case SO_RCVTIMEO: - time_val = (struct timeval *)option_value; + time_val = (struct nx_bsd_timeval *)option_value; /* Calculate ticks for the ThreadX Timer. */ timer_ticks = (ULONG)(time_val -> tv_usec)/NX_MICROSECOND_PER_CPU_TICK + (ULONG)(time_val -> tv_sec) * NX_IP_PERIODIC_RATE; @@ -6533,7 +6607,7 @@ UINT status; { /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6541,7 +6615,7 @@ UINT status; } - window_size = (ULONG)(((struct sock_winsize *)option_value) -> winsize); + window_size = (ULONG)(((struct nx_bsd_sock_winsize *)option_value) -> winsize); #ifdef NX_ENABLE_TCP_WINDOW_SCALING @@ -6563,7 +6637,7 @@ UINT status; case SO_REUSEADDR: - reuse_enabled = (UINT)(((struct sock_reuseaddr *)option_value) -> reuseaddr_enabled); + reuse_enabled = (UINT)(((struct nx_bsd_sock_reuseaddr *)option_value) -> reuseaddr_enabled); if(reuse_enabled) bsd_socket_ptr -> nx_bsd_socket_option_flags |= NX_BSD_SOCKET_ENABLE_OPTION_REUSEADDR; @@ -6582,11 +6656,11 @@ UINT status; case IP_MULTICAST_TTL: /* Validate the option length. */ - if(option_length != sizeof(UCHAR)) + if(option_length != sizeof(UCHAR) && option_length != sizeof(INT)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6597,7 +6671,7 @@ UINT status; { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6607,13 +6681,33 @@ UINT status; if(bsd_socket_ptr -> nx_bsd_socket_udp_socket == NX_NULL) { /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; } + /* Set the TTL value. */ - bsd_socket_ptr -> nx_bsd_socket_udp_socket -> nx_udp_socket_time_to_live = *(UCHAR*)option_value; + if (option_length == sizeof(UCHAR)) + { + bsd_socket_ptr -> nx_bsd_socket_udp_socket -> nx_udp_socket_time_to_live = *(UCHAR*)option_value; + } + else + { + bsd_socket_ptr -> nx_bsd_socket_udp_socket -> nx_udp_socket_time_to_live = (UCHAR)(*(INT*)option_value); + } + break; + + case IP_MULTICAST_LOOP: + + /* This is not supported yet. */ + + break; + + case IP_MULTICAST_IF: + + /* This is not supported yet. */ + break; @@ -6641,7 +6735,7 @@ UINT status; #endif /* NX_ENABLE_IP_RAW_PACKET_FILTER */ { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6680,7 +6774,7 @@ UINT status; #endif /* NX_ENABLE_IP_RAW_PACKET_FILTER */ { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6697,23 +6791,23 @@ UINT status; case IP_DROP_MEMBERSHIP: /* Validate the option length */ - if(option_length != sizeof(struct ip_mreq)) + if(option_length != sizeof(struct nx_bsd_ip_mreq)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; } - mreq = (struct ip_mreq*)option_value; + mreq = (struct nx_bsd_ip_mreq*)option_value; /* Make sure the multicast group address is valid. */ if((mreq -> imr_multiaddr.s_addr & ntohl(NX_IP_CLASS_D_TYPE)) != ntohl(NX_IP_CLASS_D_TYPE)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6723,7 +6817,7 @@ UINT status; if (!(bsd_socket_ptr -> nx_bsd_socket_status_flags & NX_BSD_SOCKET_IN_USE)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6733,7 +6827,7 @@ UINT status; if(bsd_socket_ptr -> nx_bsd_socket_udp_socket == NX_NULL) { /* Set the socket error if extended socket options enabled. */ - set_errno(ENOPROTOOPT); + nx_bsd_set_errno(ENOPROTOOPT); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6773,7 +6867,7 @@ UINT status; { /* Did not find a matching interface. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6801,7 +6895,7 @@ UINT status; if(status != NX_SUCCESS) { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return NX_SOC_ERROR; @@ -6838,7 +6932,7 @@ UINT status; #endif /* NX_ENABLE_IP_RAW_PACKET_FILTER */ { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6853,7 +6947,7 @@ UINT status; default: /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error status. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6870,7 +6964,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* getsockname PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -6911,16 +7005,19 @@ UINT status; /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getsockname(INT sockID, struct sockaddr *localAddress, INT *addressLength) +INT nx_bsd_getsockname(INT sockID, struct nx_bsd_sockaddr *localAddress, INT *addressLength) { #ifndef NX_DISABLE_IPV4 -struct sockaddr_in soc_struct; +struct nx_bsd_sockaddr_in soc_struct; #endif /* NX_DISABLE_IPV4 */ #ifdef FEATURE_NX_IPV6 -struct sockaddr_in6 soc6_struct; +struct nx_bsd_sockaddr_in6 soc6_struct; #endif UINT status; NX_BSD_SOCKET *bsd_socket_ptr; @@ -6931,7 +7028,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -6941,7 +7038,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -6962,7 +7059,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -6973,7 +7070,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; { /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -7004,7 +7101,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; else if(bsd_socket_ptr -> nx_bsd_socket_local_bind_interface == 0) { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -7022,9 +7119,9 @@ NX_BSD_SOCKET *bsd_socket_ptr; soc_struct.sin_family = AF_INET; - if((*addressLength) > (INT)sizeof(struct sockaddr_in)) + if((*addressLength) > (INT)sizeof(struct nx_bsd_sockaddr_in)) { - *addressLength = sizeof(struct sockaddr_in); + *addressLength = sizeof(struct nx_bsd_sockaddr_in); } memcpy(localAddress, &soc_struct, (UINT)(*addressLength)); /* Use case of memcpy is verified. */ } @@ -7045,7 +7142,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; else if(bsd_socket_ptr -> nx_bsd_socket_local_bind_interface == 0) { - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); @@ -7068,9 +7165,9 @@ NX_BSD_SOCKET *bsd_socket_ptr; soc6_struct.sin6_family = AF_INET6; - if((*addressLength) > (INT)sizeof(struct sockaddr_in6)) + if((*addressLength) > (INT)sizeof(struct nx_bsd_sockaddr_in6)) { - *addressLength = sizeof(struct sockaddr_in6); + *addressLength = sizeof(struct nx_bsd_sockaddr_in6); } memcpy(localAddress, &soc6_struct, (UINT)(*addressLength)); /* Use case of memcpy is verified. */ @@ -7082,7 +7179,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* Release the protection mutex. */ tx_mutex_put(nx_bsd_protection_ptr); - set_errno(EPROTONOSUPPORT); + nx_bsd_set_errno(EPROTONOSUPPORT); /* Return error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -7104,7 +7201,7 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* FUNCTION RELEASE */ /* */ /* getpeername PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -7141,18 +7238,21 @@ NX_BSD_SOCKET *bsd_socket_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getpeername(INT sockID, struct sockaddr *remoteAddress, INT *addressLength) +INT nx_bsd_getpeername(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT *addressLength) { UINT status; NX_BSD_SOCKET *bsd_socket_ptr; #ifndef NX_DISABLE_IPV4 -struct sockaddr_in *soc_struct_ptr = NX_NULL; +struct nx_bsd_sockaddr_in *soc_struct_ptr = NX_NULL; #endif /* NX_DISABLE_IPV4 */ #ifdef FEATURE_NX_IPV6 -struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; +struct nx_bsd_sockaddr_in6 *soc6_struct_ptr = NX_NULL; #endif @@ -7161,7 +7261,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error, invalid socket ID. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -7176,7 +7276,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -7192,7 +7292,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Error getting the protection mutex. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -7209,7 +7309,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; /* This is an IPv4 only socket. */ /* Now validate the size of remoteAddress structure. */ - if(*addressLength < (INT)sizeof(struct sockaddr_in)) + if(*addressLength < (INT)sizeof(struct nx_bsd_sockaddr_in)) { /* User supplied buffer is too small .*/ @@ -7218,15 +7318,15 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error, if socket enabled with extended BSD features. */ - set_errno(ESOCKTNOSUPPORT); + nx_bsd_set_errno(ESOCKTNOSUPPORT); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); return(ERROR); } - soc_struct_ptr = (struct sockaddr_in*)remoteAddress; - *addressLength = sizeof(struct sockaddr_in); + soc_struct_ptr = (struct nx_bsd_sockaddr_in*)remoteAddress; + *addressLength = sizeof(struct nx_bsd_sockaddr_in); } else #endif /* NX_DISABLE_IPV4 */ @@ -7237,7 +7337,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; /* IPv6 socket */ /* Now validate the size of remoteAddress structure. */ - if(*addressLength < (INT)sizeof(struct sockaddr_in6)) + if(*addressLength < (INT)sizeof(struct nx_bsd_sockaddr_in6)) { /* User supplied buffer is too small .*/ @@ -7246,15 +7346,15 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error, if socket enabled with extended BSD features. */ - set_errno(ESOCKTNOSUPPORT); + nx_bsd_set_errno(ESOCKTNOSUPPORT); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); return(ERROR); } - soc6_struct_ptr = (struct sockaddr_in6*)remoteAddress; - *addressLength = sizeof(struct sockaddr_in6); + soc6_struct_ptr = (struct nx_bsd_sockaddr_in6*)remoteAddress; + *addressLength = sizeof(struct nx_bsd_sockaddr_in6); } else #endif /* FEATURE_NX_IPV6 */ @@ -7265,7 +7365,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error, if socket enabled with extended BSD features. */ - set_errno(ESOCKTNOSUPPORT); + nx_bsd_set_errno(ESOCKTNOSUPPORT); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -7282,7 +7382,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -7323,7 +7423,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error if extended options enabled. */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -7358,7 +7458,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error, if socket enabled with extended BSD features. */ - set_errno(ESOCKTNOSUPPORT); + nx_bsd_set_errno(ESOCKTNOSUPPORT); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -7373,7 +7473,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; tx_mutex_put(nx_bsd_protection_ptr); /* Set the socket error, if socket enabled with extended BSD features. */ - set_errno(ESOCKTNOSUPPORT); + nx_bsd_set_errno(ESOCKTNOSUPPORT); /* Return error. */ NX_BSD_ERROR(ERROR, __LINE__); @@ -7393,7 +7493,7 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; /* FUNCTION RELEASE */ /* */ /* select PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -7473,18 +7573,21 @@ struct sockaddr_in6 *soc6_struct_ptr = NX_NULL; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT select(INT nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) +INT nx_bsd_select(INT nfds, nx_bsd_fd_set *readfds, nx_bsd_fd_set *writefds, nx_bsd_fd_set *exceptfds, struct nx_bsd_timeval *timeout) { INT i; UINT status; NX_BSD_SOCKET_SUSPEND suspend_request; NX_PACKET *packet_ptr; -fd_set readfds_found; -fd_set writefds_found; -fd_set exceptfds_found; +nx_bsd_fd_set readfds_found; +nx_bsd_fd_set writefds_found; +nx_bsd_fd_set exceptfds_found; INT readfds_left; INT writefds_left; INT exceptfds_left; @@ -7499,7 +7602,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -7511,7 +7614,7 @@ INT ret; { /* Set the socket error */ - set_errno(EBADF); + nx_bsd_set_errno(EBADF); /* Return an error. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -7519,9 +7622,9 @@ INT ret; } /* Clear the read and the write selector set. */ - FD_ZERO(&readfds_found); - FD_ZERO(&writefds_found); - FD_ZERO(&exceptfds_found); + NX_BSD_FD_ZERO(&readfds_found); + NX_BSD_FD_ZERO(&writefds_found); + NX_BSD_FD_ZERO(&exceptfds_found); if(readfds) readfds_left = readfds -> fd_count; @@ -7572,7 +7675,7 @@ INT ret; { /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Set the socket error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -7587,7 +7690,7 @@ INT ret; break; /* Is this socket selected for read? */ - if (FD_ISSET((i + NX_BSD_SOCKFD_START), readfds)) + if (NX_BSD_FD_ISSET((i + NX_BSD_SOCKFD_START), readfds)) { /* Yes, decrement the number of read selectors left to search for. */ @@ -7598,7 +7701,7 @@ INT ret; { /* There is; add this socket to the read ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } /* Check to see if there is a disconnection request pending. */ @@ -7606,7 +7709,7 @@ INT ret; { /* There is; add this socket to the read ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } /* Check to see if there is a receive packet pending. */ @@ -7614,7 +7717,7 @@ INT ret; { /* Therer is; add this socket to the read ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } /* Is this a TCP socket? */ else if (nx_bsd_socket_array[i].nx_bsd_socket_tcp_socket) @@ -7639,13 +7742,13 @@ INT ret; { /* Mark the FD set so the application could be notified. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } } if(nx_bsd_socket_array[i].nx_bsd_socket_status_flags & NX_BSD_SOCKET_CONNECTED) { - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } } } @@ -7670,7 +7773,7 @@ INT ret; nx_bsd_socket_array[i].nx_bsd_socket_received_packet_count++; /* Add this socket to the read ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } } } @@ -7696,7 +7799,7 @@ INT ret; nx_bsd_socket_array[i].nx_bsd_socket_received_packet_offset = 0; /* Add this socket to the read ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &readfds_found); } } #endif /* NX_ENABLE_IP_RAW_PACKET_FILTER */ @@ -7711,7 +7814,7 @@ INT ret; break; /* Is this socket selected for write? */ - if (FD_ISSET(i + NX_BSD_SOCKFD_START, writefds)) + if (NX_BSD_FD_ISSET(i + NX_BSD_SOCKFD_START, writefds)) { /* Yes, decrement the number of read selectors left to search for. */ @@ -7722,7 +7825,7 @@ INT ret; { /* Yes, add this socket to the write ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); } /* Check to see if there is a connection request pending. */ @@ -7730,14 +7833,14 @@ INT ret; { /* Yes, add this socket to the write ready list. */ - FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); } /* Check to see if there is an error.*/ else if (nx_bsd_socket_array[i].nx_bsd_socket_status_flags & NX_BSD_SOCKET_ERROR) { - FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &writefds_found); } } } @@ -7750,7 +7853,7 @@ INT ret; break; /* Is this socket selected for exceptions? */ - if (FD_ISSET(i + NX_BSD_SOCKFD_START, exceptfds)) + if (NX_BSD_FD_ISSET(i + NX_BSD_SOCKFD_START, exceptfds)) { /* Yes, decrement the number of read selectors left to search for. */ @@ -7760,14 +7863,14 @@ INT ret; if (!(nx_bsd_socket_array[i].nx_bsd_socket_status_flags & NX_BSD_SOCKET_IN_USE)) { - FD_SET(i + NX_BSD_SOCKFD_START, &exceptfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &exceptfds_found); } /* Check to see if there is an error.*/ else if(nx_bsd_socket_array[i].nx_bsd_socket_status_flags & NX_BSD_SOCKET_ERROR) { - FD_SET(i + NX_BSD_SOCKFD_START, &exceptfds_found); + NX_BSD_FD_SET(i + NX_BSD_SOCKFD_START, &exceptfds_found); } } } @@ -7807,17 +7910,17 @@ INT ret; if(readfds) suspend_request.nx_bsd_socket_suspend_read_fd_set = *readfds; else - FD_ZERO(&suspend_request.nx_bsd_socket_suspend_read_fd_set); + NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_read_fd_set); if(writefds) suspend_request.nx_bsd_socket_suspend_write_fd_set = *writefds; else - FD_ZERO(&suspend_request.nx_bsd_socket_suspend_write_fd_set); + NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_write_fd_set); if(exceptfds) suspend_request.nx_bsd_socket_suspend_exception_fd_set = *exceptfds; else - FD_ZERO(&suspend_request.nx_bsd_socket_suspend_exception_fd_set); + NX_BSD_FD_ZERO(&suspend_request.nx_bsd_socket_suspend_exception_fd_set); /* Temporarily disable preemption. */ tx_thread_preemption_change(current_thread_ptr, 0, &original_threshold); @@ -7843,9 +7946,9 @@ INT ret; /* Determine if the effected sockets are non blocking (zero ticks for the wait option). */ if (ticks == 0) - set_errno(EWOULDBLOCK); + nx_bsd_set_errno(EWOULDBLOCK); else - set_errno(ETIMEDOUT); + nx_bsd_set_errno(ETIMEDOUT); /* Do not handle as an error; just a timeout so return 0. */ return(0); @@ -7855,7 +7958,7 @@ INT ret; /* Actual error. */ /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); /* Error getting the protection mutex. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -8323,7 +8426,7 @@ NX_UDP_SOCKET *udp_socket_ptr; /* FUNCTION RELEASE */ /* */ /* FD_SET PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -8356,9 +8459,12 @@ NX_UDP_SOCKET *udp_socket_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID FD_SET(INT fd, fd_set *fdset) +VOID NX_BSD_FD_SET(INT fd, nx_bsd_fd_set *fdset) { UINT index; @@ -8400,7 +8506,7 @@ UINT index; /* FUNCTION RELEASE */ /* */ /* FD_CLR PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -8433,9 +8539,12 @@ UINT index; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID FD_CLR(INT fd, fd_set *fdset) +VOID NX_BSD_FD_CLR(INT fd, nx_bsd_fd_set *fdset) { UINT index; @@ -8514,7 +8623,7 @@ UINT index; /* resulting in version 6.1 */ /* */ /**************************************************************************/ -INT FD_ISSET(INT fd, fd_set *fdset) +INT NX_BSD_FD_ISSET(INT fd, nx_bsd_fd_set *fdset) { UINT index; @@ -8557,7 +8666,7 @@ UINT index; /* FUNCTION RELEASE */ /* */ /* FD_ZERO PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -8589,9 +8698,12 @@ UINT index; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID FD_ZERO(fd_set *fdset) +VOID NX_BSD_FD_ZERO(nx_bsd_fd_set *fdset) { INT i; @@ -8829,7 +8941,7 @@ VOID nx_bsd_raw_receive_notify(NX_IP *ip_ptr, UINT bsd_socket_index) /* FUNCTION RELEASE */ /* */ /* nx_bsd_raw_packet_receive PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -8867,6 +8979,9 @@ VOID nx_bsd_raw_receive_notify(NX_IP *ip_ptr, UINT bsd_socket_index) /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ UINT nx_bsd_raw_packet_receive(NX_BSD_SOCKET *bsd_socket_ptr, NX_PACKET **packet_ptr) @@ -8877,7 +8992,7 @@ UINT nx_bsd_raw_packet_receive(NX_BSD_SOCKET *bsd_socket_ptr, NX_PACKET **packet if (!(bsd_socket_ptr -> nx_bsd_socket_option_flags & NX_BSD_SOCKET_ENABLE_RAW_SOCKET)) { /* Set the socket error. */ - set_errno(EPROTOTYPE); + nx_bsd_set_errno(EPROTOTYPE); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_NOT_ENABLED); @@ -9637,7 +9752,7 @@ static UINT nx_bsd_isxdigit(UCHAR c) /* FUNCTION RELEASE */ /* */ /* set_errno PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -9671,9 +9786,12 @@ static UINT nx_bsd_isxdigit(UCHAR c) /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID set_errno(INT tx_errno) +VOID nx_bsd_set_errno(INT tx_errno) { TX_INTERRUPT_SAVE_AREA @@ -9755,7 +9873,7 @@ TX_THREAD *current_thread_ptr; /* FUNCTION RELEASE */ /* */ /* nx_bsd_select_wakeup PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -9798,12 +9916,15 @@ TX_THREAD *current_thread_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ static VOID nx_bsd_select_wakeup(UINT sock_id, UINT fd_sets) { TX_INTERRUPT_SAVE_AREA -fd_set local_fd; +nx_bsd_fd_set local_fd; TX_THREAD *suspended_thread; ULONG suspended_count; ULONG original_suspended_count; @@ -9814,8 +9935,8 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; BSD mutex. */ - FD_ZERO(&local_fd); - FD_SET((INT)sock_id + NX_BSD_SOCKFD_START, &local_fd); + NX_BSD_FD_ZERO(&local_fd); + NX_BSD_FD_SET((INT)sock_id + NX_BSD_SOCKFD_START, &local_fd); /* Disable interrupts temporarily. */ TX_DISABLE @@ -9841,7 +9962,7 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; suspend_info = (NX_BSD_SOCKET_SUSPEND *) suspended_thread -> tx_thread_additional_suspend_info; /* Now determine if this thread was waiting for this socket. */ - if ((fd_sets & FDSET_READ) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set))) + if ((fd_sets & FDSET_READ) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set))) { /* Copy the local fd over so that the return shows the receive socket. */ @@ -9853,7 +9974,7 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; } /* Now determine if this thread was waiting for this socket. */ - if ((fd_sets & FDSET_WRITE) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set))) + if ((fd_sets & FDSET_WRITE) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set))) { /* Copy the local fd over so that the return shows the receive socket. */ @@ -9865,7 +9986,7 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; } /* Now determine if this thread was waiting for this socket. */ - if ((fd_sets & FDSET_EXCEPTION) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set))) + if ((fd_sets & FDSET_EXCEPTION) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set))) { /* Copy the local fd over so that the return shows the receive socket. */ @@ -9879,25 +10000,25 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; /* Clear FD that is not set. */ if (suspended_thread -> tx_thread_suspend_info == NX_BSD_RECEIVE_EVENT) { - if (!(fd_sets & FDSET_READ) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set))) + if (!(fd_sets & FDSET_READ) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set))) { /* Clear read FD. */ - FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set); + NX_BSD_FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_read_fd_set); } - if (!(fd_sets & FDSET_WRITE) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set))) + if (!(fd_sets & FDSET_WRITE) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set))) { /* Clear write FD. */ - FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set); + NX_BSD_FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_write_fd_set); } - if (!(fd_sets & FDSET_EXCEPTION) && (FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set))) + if (!(fd_sets & FDSET_EXCEPTION) && (NX_BSD_FD_ISSET((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set))) { /* Clear exception FD. */ - FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set); + NX_BSD_FD_CLR((INT)sock_id + NX_BSD_SOCKFD_START, &suspend_info -> nx_bsd_socket_suspend_exception_fd_set); } } } @@ -9942,7 +10063,7 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; /* FUNCTION RELEASE */ /* */ /* nx_bsd_set_error_code PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -9976,6 +10097,9 @@ NX_BSD_SOCKET_SUSPEND *suspend_info; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ static VOID nx_bsd_set_error_code(NX_BSD_SOCKET *bsd_socket_ptr, UINT status_code) @@ -9984,35 +10108,35 @@ static VOID nx_bsd_set_error_code(NX_BSD_SOCKET *bsd_socket_ptr, UINT status_cod { case NX_NOT_CLOSED: /* TCP connection is not closed state. */ - set_errno(EISCONN); + nx_bsd_set_errno(EISCONN); break; case NX_PTR_ERROR: case NX_INVALID_PORT: /* Invalid arguement. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); break; case NX_MAX_LISTEN: - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); break; case NX_PORT_UNAVAILABLE: case NX_NO_FREE_PORTS: - set_errno(EADDRNOTAVAIL); + nx_bsd_set_errno(EADDRNOTAVAIL); break; case NX_ALREADY_BOUND: - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); break; case NX_WAIT_ABORTED: - set_errno(ETIMEDOUT); + nx_bsd_set_errno(ETIMEDOUT); break; case NX_NOT_CONNECTED: /* NX TCP connect service may return NX_NOT_CONNECTED if the timeout is WAIT_FOREVER. */ - set_errno(ECONNREFUSED); + nx_bsd_set_errno(ECONNREFUSED); break; case NX_IN_PROGRESS: @@ -10021,25 +10145,25 @@ static VOID nx_bsd_set_error_code(NX_BSD_SOCKET *bsd_socket_ptr, UINT status_cod if (bsd_socket_ptr -> nx_bsd_socket_option_flags & NX_BSD_SOCKET_ENABLE_OPTION_NON_BLOCKING) { bsd_socket_ptr -> nx_bsd_socket_status_flags |= NX_BSD_SOCKET_CONNECTION_INPROGRESS; - set_errno(EINPROGRESS); + nx_bsd_set_errno(EINPROGRESS); } else - set_errno(EINTR); + nx_bsd_set_errno(EINTR); break; case NX_INVALID_INTERFACE: case NX_IP_ADDRESS_ERROR: - set_errno(ENETUNREACH); + nx_bsd_set_errno(ENETUNREACH); break; case NX_NOT_ENABLED: - set_errno(EPROTONOSUPPORT); + nx_bsd_set_errno(EPROTONOSUPPORT); break; case NX_NOT_BOUND: case NX_DUPLICATE_LISTEN: default: - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); break; } @@ -10429,7 +10553,7 @@ NX_INTERFACE *interface_ptr; /* FUNCTION RELEASE */ /* */ /* nx_bsd_tcp_create_listen_socket PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -10467,6 +10591,9 @@ NX_INTERFACE *interface_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ static INT nx_bsd_tcp_create_listen_socket(INT master_sockid, INT backlog) @@ -10535,7 +10662,7 @@ INT secondary_sockID = NX_BSD_MAX_SOCKETS; /* Error, invalid backlog. */ /* Set the socket error if extended socket options enabled. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -10544,14 +10671,14 @@ INT secondary_sockID = NX_BSD_MAX_SOCKETS; } /* Now create a dedicated secondary socket to listen for next client connection. */ - secondary_sockID = socket((INT)(master_socket_ptr -> nx_bsd_socket_family), SOCK_STREAM, IPPROTO_TCP); + secondary_sockID = nx_bsd_socket((INT)(master_socket_ptr -> nx_bsd_socket_family), SOCK_STREAM, IPPROTO_TCP); /* Determine if there was an error. */ if (secondary_sockID == NX_SOC_ERROR) { /* Secondary socket create failed. Note: The socket thread error is set in socket(). */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* Return error code. */ NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); @@ -12379,7 +12506,7 @@ NX_IPV6_HEADER_OPTION *option; /* FUNCTION RELEASE */ /* */ /* nx_bsd_pppoe_internal_sendto PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -12421,12 +12548,16 @@ NX_IPV6_HEADER_OPTION *option; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -static INT nx_bsd_pppoe_internal_sendto(NX_BSD_SOCKET *bsd_socket_ptr, CHAR *msg, INT msgLength, INT flags, struct sockaddr* destAddr, INT destAddrLen) +static INT nx_bsd_pppoe_internal_sendto(NX_BSD_SOCKET *bsd_socket_ptr, CHAR *msg, INT msgLength, INT flags, struct nx_bsd_sockaddr* destAddr, INT destAddrLen) { UINT if_index; -struct sockaddr_ll *destAddr_ll; +struct nx_bsd_sockaddr_ll + *destAddr_ll; #if 0 ULONG src_mac_msw; ULONG src_mac_lsw; @@ -12442,7 +12573,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(destAddr == NX_NULL) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -12451,27 +12582,27 @@ NX_PACKET *packet_ptr = NX_NULL; if(destAddr -> sa_family != AF_PACKET) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - if(destAddrLen != sizeof(struct sockaddr_ll)) + if(destAddrLen != sizeof(struct nx_bsd_sockaddr_ll)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - destAddr_ll = (struct sockaddr_ll*)destAddr; + destAddr_ll = (struct nx_bsd_sockaddr_ll*)destAddr; if((destAddr_ll -> sll_protocol != ETHERTYPE_PPPOE_SESS) && (destAddr_ll -> sll_protocol != ETHERTYPE_PPPOE_DISC)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -12482,7 +12613,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(if_index >= NX_MAX_IP_INTERFACES) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -12491,7 +12622,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(nx_bsd_default_ip -> nx_ip_interface[if_index].nx_interface_valid == 0) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -12509,7 +12640,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(msgLength > (INT)(nx_bsd_default_ip -> nx_ip_interface[if_index].nx_interface_ip_mtu_size + 14)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -12523,7 +12654,7 @@ NX_PACKET *packet_ptr = NX_NULL; { /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -12542,7 +12673,7 @@ NX_PACKET *packet_ptr = NX_NULL; nx_packet_release(packet_ptr); /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -12568,7 +12699,7 @@ NX_PACKET *packet_ptr = NX_NULL; nx_packet_release(packet_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -12742,10 +12873,11 @@ NX_BSD_SOCKET *bsd_ptr; /* resulting in version 6.1 */ /* */ /**************************************************************************/ -static INT _nx_bsd_hardware_internal_sendto(NX_BSD_SOCKET *bsd_socket_ptr, CHAR *msg, INT msgLength, INT flags, struct sockaddr* destAddr, INT destAddrLen) +static INT _nx_bsd_hardware_internal_sendto(NX_BSD_SOCKET *bsd_socket_ptr, CHAR *msg, INT msgLength, INT flags, struct nx_bsd_sockaddr* destAddr, INT destAddrLen) { UINT if_index; -struct sockaddr_ll *destAddr_ll; +struct nx_bsd_sockaddr_ll + *destAddr_ll; UINT status; NX_PACKET *packet_ptr = NX_NULL; @@ -12756,7 +12888,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(destAddr == NX_NULL) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -12765,29 +12897,29 @@ NX_PACKET *packet_ptr = NX_NULL; if(destAddr -> sa_family != AF_PACKET) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - if(destAddrLen != sizeof(struct sockaddr_ll)) + if(destAddrLen != sizeof(struct nx_bsd_sockaddr_ll)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); } - destAddr_ll = (struct sockaddr_ll*)destAddr; + destAddr_ll = (struct nx_bsd_sockaddr_ll*)destAddr; /* Validate the interface ID */ if_index = (UINT)(destAddr_ll -> sll_ifindex); if(if_index >= NX_MAX_IP_INTERFACES) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -12796,7 +12928,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(nx_bsd_default_ip -> nx_ip_interface[if_index].nx_interface_valid == 0) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -12806,7 +12938,7 @@ NX_PACKET *packet_ptr = NX_NULL; if(msgLength > (INT)(nx_bsd_default_ip -> nx_ip_interface[if_index].nx_interface_ip_mtu_size + 18)) { /* Set the socket error if extended socket options enabled. */ - set_errno(EINVAL); + nx_bsd_set_errno(EINVAL); NX_BSD_ERROR(NX_SOC_ERROR, __LINE__); return(NX_SOC_ERROR); @@ -12819,7 +12951,7 @@ NX_PACKET *packet_ptr = NX_NULL; { /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -12839,7 +12971,7 @@ NX_PACKET *packet_ptr = NX_NULL; nx_packet_release(packet_ptr); /* Set the socket error. */ - set_errno(ENOBUFS); + nx_bsd_set_errno(ENOBUFS); /* Return an error status.*/ NX_BSD_ERROR(status, __LINE__); @@ -12860,7 +12992,7 @@ NX_PACKET *packet_ptr = NX_NULL; nx_packet_release(packet_ptr); /* Set the socket error if extended socket options enabled. */ - set_errno(EACCES); + nx_bsd_set_errno(EACCES); /* Return an error. */ NX_BSD_ERROR(NX_BSD_MUTEX_ERROR, __LINE__); @@ -12991,7 +13123,7 @@ NX_BSD_SOCKET *bsd_ptr; /* FUNCTION RELEASE */ /* */ /* inet_pton PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -13030,9 +13162,12 @@ NX_BSD_SOCKET *bsd_ptr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT inet_pton(INT af, const CHAR *src, VOID *dst) +INT nx_bsd_inet_pton(INT af, const CHAR *src, VOID *dst) { CHAR ch; USHORT value; @@ -13051,12 +13186,12 @@ ULONG *dst_long_ptr; const CHAR *ipv4_addr_start = src; UINT n, i; -struct in_addr ipv4_addr; +struct nx_bsd_in_addr ipv4_addr; if(af == AF_INET) { /* Convert IPv4 address from presentation to numeric. */ - if(inet_aton(src, &ipv4_addr)) + if(nx_bsd_inet_aton(src, &ipv4_addr)) { /* Copy the IPv4 address to the destination. */ *((ULONG *)dst) = ipv4_addr.s_addr; @@ -13165,7 +13300,7 @@ struct in_addr ipv4_addr; } /* Convert the ipv4 address from presentation to numeric. */ - if(inet_aton(ipv4_addr_start, &ipv4_addr)) + if(nx_bsd_inet_aton(ipv4_addr_start, &ipv4_addr)) { /* Make sure the result is in network byte order. */ @@ -13258,7 +13393,7 @@ struct in_addr ipv4_addr; /* FUNCTION RELEASE */ /* */ /* inet_ntop PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -13297,9 +13432,12 @@ struct in_addr ipv4_addr; /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -const CHAR *inet_ntop(INT af, const VOID *src, CHAR *dst, socklen_t size) +const CHAR *nx_bsd_inet_ntop(INT af, const VOID *src, CHAR *dst, nx_bsd_socklen_t size) { INT shorthand_index; @@ -13593,7 +13731,7 @@ UINT index = 0; /* FUNCTION RELEASE */ /* */ /* getaddrinfo PORTABLE C */ -/* 6.1.12 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -13657,9 +13795,12 @@ UINT index = 0; /* 07-29-2022 Yuxin Zhou Modified comment(s), and */ /* fixed compiler warnings, */ /* resulting in version 6.1.12 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getaddrinfo(const CHAR *node, const CHAR *service, const struct addrinfo *hints, struct addrinfo **res) +INT nx_bsd_getaddrinfo(const CHAR *node, const CHAR *service, const struct nx_bsd_addrinfo *hints, struct nx_bsd_addrinfo **res) { UINT status; @@ -13675,14 +13816,18 @@ UINT ipv6_addr_count = 0; UINT match_service_count; UINT match_service_socktype[3]; UINT match_service_protocol[3]; -struct addrinfo *addrinfo_cur_ptr = NX_NULL; -struct addrinfo *addrinfo_head_ptr = NX_NULL; -struct addrinfo *addrinfo_tail_ptr = NX_NULL; -struct sockaddr *sockaddr_ptr = NX_NULL; +struct nx_bsd_addrinfo + *addrinfo_cur_ptr = NX_NULL; +struct nx_bsd_addrinfo + *addrinfo_head_ptr = NX_NULL; +struct nx_bsd_addrinfo + *addrinfo_tail_ptr = NX_NULL; +struct nx_bsd_sockaddr + *sockaddr_ptr = NX_NULL; UCHAR *cname_buffer = NX_NULL; /* When hints is a null pointer, use the default value below. */ -static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, NX_NULL}; +static struct nx_bsd_addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, NX_NULL}; @@ -13858,7 +14003,7 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, { /* Convert node from a string presentation to a numeric address. */ - if(inet_pton(addr_family, node, &(nx_bsd_ipv4_addr_buffer[0])) == 1) + if(nx_bsd_inet_pton(addr_family, node, &(nx_bsd_ipv4_addr_buffer[0])) == 1) { /* pton has successful completion. */ pton_flag = 1; @@ -13875,7 +14020,7 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, { /* Convert node from a string presentation to a numeric address. */ - if(inet_pton(addr_family, node, &(nx_bsd_ipv6_addr_buffer[0])) == 1) + if(nx_bsd_inet_pton(addr_family, node, &(nx_bsd_ipv6_addr_buffer[0])) == 1) { /* pton completed successfully. */ pton_flag = 1; @@ -13909,7 +14054,7 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, if (status != TX_SUCCESS) { /* Set the error. */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* Error getting NetX socket memory. */ NX_BSD_ERROR(NX_BSD_BLOCK_POOL_ERROR, __LINE__); @@ -14079,11 +14224,11 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, { /* Set the error. */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* If head is not null, free the memory. */ if(addrinfo_head_ptr) - freeaddrinfo(addrinfo_head_ptr); + nx_bsd_freeaddrinfo(addrinfo_head_ptr); #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES if(hints -> ai_flags & AI_CANONNAME) @@ -14098,30 +14243,30 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, } /* Clear the memory. */ - memset((VOID*)sockaddr_ptr, 0, sizeof(struct addrinfo)); + memset((VOID*)sockaddr_ptr, 0, sizeof(struct nx_bsd_addrinfo)); if(i < ipv4_addr_count) { /* Process IPv4 address. */ - ((struct sockaddr_in*)sockaddr_ptr) -> sin_family = AF_INET; - ((struct sockaddr_in*)sockaddr_ptr) -> sin_port = (USHORT)port; - ((struct sockaddr_in*)sockaddr_ptr) -> sin_addr.s_addr = nx_bsd_ipv4_addr_buffer[i]; + ((struct nx_bsd_sockaddr_in*)sockaddr_ptr) -> sin_family = AF_INET; + ((struct nx_bsd_sockaddr_in*)sockaddr_ptr) -> sin_port = (USHORT)port; + ((struct nx_bsd_sockaddr_in*)sockaddr_ptr) -> sin_addr.s_addr = nx_bsd_ipv4_addr_buffer[i]; - NX_CHANGE_ULONG_ENDIAN(((struct sockaddr_in*)sockaddr_ptr) -> sin_addr.s_addr); + NX_CHANGE_ULONG_ENDIAN(((struct nx_bsd_sockaddr_in*)sockaddr_ptr) -> sin_addr.s_addr); } else { /* Process IPv6 address. */ - ((struct sockaddr_in6*)sockaddr_ptr) -> sin6_family = AF_INET6; - ((struct sockaddr_in6*)sockaddr_ptr) -> sin6_port = (USHORT)port; - memcpy(&(((struct sockaddr_in6*)sockaddr_ptr) -> sin6_addr), &nx_bsd_ipv6_addr_buffer[(i - ipv4_addr_count)*4], 16); /* Use case of memcpy is verified. */ + ((struct nx_bsd_sockaddr_in6*)sockaddr_ptr) -> sin6_family = AF_INET6; + ((struct nx_bsd_sockaddr_in6*)sockaddr_ptr) -> sin6_port = (USHORT)port; + memcpy(&(((struct nx_bsd_sockaddr_in6*)sockaddr_ptr) -> sin6_addr), &nx_bsd_ipv6_addr_buffer[(i - ipv4_addr_count)*4], 16); /* Use case of memcpy is verified. */ - NX_CHANGE_ULONG_ENDIAN(*(ULONG*)&(((struct sockaddr_in6*)sockaddr_ptr) -> sin6_addr.s6_addr32[0])); - NX_CHANGE_ULONG_ENDIAN(*(ULONG*)&(((struct sockaddr_in6*)sockaddr_ptr) -> sin6_addr.s6_addr32[1])); - NX_CHANGE_ULONG_ENDIAN(*(ULONG*)&(((struct sockaddr_in6*)sockaddr_ptr) -> sin6_addr.s6_addr32[2])); - NX_CHANGE_ULONG_ENDIAN(*(ULONG*)&(((struct sockaddr_in6*)sockaddr_ptr) -> sin6_addr.s6_addr32[3])); + NX_CHANGE_ULONG_ENDIAN(*(ULONG*)&(((struct nx_bsd_sockaddr_in6*)sockaddr_ptr) -> sin6_addr.s6_addr32[0])); + NX_CHANGE_ULONG_ENDIAN(*(ULONG*)&(((struct nx_bsd_sockaddr_in6*)sockaddr_ptr) -> sin6_addr.s6_addr32[1])); + NX_CHANGE_ULONG_ENDIAN(*(ULONG*)&(((struct nx_bsd_sockaddr_in6*)sockaddr_ptr) -> sin6_addr.s6_addr32[2])); + NX_CHANGE_ULONG_ENDIAN(*(ULONG*)&(((struct nx_bsd_sockaddr_in6*)sockaddr_ptr) -> sin6_addr.s6_addr32[3])); } @@ -14136,11 +14281,11 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, { /* Set the error. */ - set_errno(ENOMEM); + nx_bsd_set_errno(ENOMEM); /* If head is not null, free the memory. */ if(addrinfo_head_ptr) - freeaddrinfo(addrinfo_head_ptr); + nx_bsd_freeaddrinfo(addrinfo_head_ptr); tx_block_release((VOID *)sockaddr_ptr); @@ -14157,21 +14302,21 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, } /* Clear the socket memory. */ - memset((VOID*)addrinfo_cur_ptr, 0, sizeof(struct addrinfo)); + memset((VOID*)addrinfo_cur_ptr, 0, sizeof(struct nx_bsd_addrinfo)); if(i < ipv4_addr_count) { /* IPv4 */ addrinfo_cur_ptr -> ai_family = AF_INET; - addrinfo_cur_ptr -> ai_addrlen = sizeof(struct sockaddr_in); + addrinfo_cur_ptr -> ai_addrlen = sizeof(struct nx_bsd_sockaddr_in); } else { /* IPv6 */ addrinfo_cur_ptr -> ai_family = AF_INET6; - addrinfo_cur_ptr -> ai_addrlen = sizeof(struct sockaddr_in6); + addrinfo_cur_ptr -> ai_addrlen = sizeof(struct nx_bsd_sockaddr_in6); } addrinfo_cur_ptr -> ai_socktype = (INT)(match_service_socktype[j]); @@ -14204,7 +14349,7 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, /* FUNCTION RELEASE */ /* */ /* freeaddrinfo PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -14236,13 +14381,16 @@ static struct addrinfo default_hints = {0, AF_UNSPEC, 0, 0, 0, NX_NULL, NX_NULL, /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -VOID freeaddrinfo(struct addrinfo *res) +VOID nx_bsd_freeaddrinfo(struct nx_bsd_addrinfo *res) { -struct addrinfo *next_addrinfo; -struct sockaddr *ai_addr_ptr = NX_NULL; +struct nx_bsd_addrinfo *next_addrinfo; +struct nx_bsd_sockaddr *ai_addr_ptr = NX_NULL; #ifdef NX_DNS_ENABLE_EXTENDED_RR_TYPES CHAR *ai_canonname_ptr = NX_NULL; #endif @@ -14347,7 +14495,7 @@ static INT bsd_string_to_number(const CHAR *string, UINT *number) /* FUNCTION RELEASE */ /* */ /* getnameinfo PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -14390,9 +14538,12 @@ static INT bsd_string_to_number(const CHAR *string, UINT *number) /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* used new API/structs naming,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -INT getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) +INT nx_bsd_getnameinfo(const struct nx_bsd_sockaddr *sa, nx_bsd_socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) { UINT i = 0; @@ -14422,8 +14573,8 @@ const CHAR *rt_ptr; /* sa isn't NULL, but family type is invalid. */ return EAI_FAMILY; } - else if((sa -> sa_family == AF_INET && salen != sizeof(struct sockaddr_in)) || - (sa -> sa_family == AF_INET6 && salen != sizeof(struct sockaddr_in6))) + else if((sa -> sa_family == AF_INET && salen != sizeof(struct nx_bsd_sockaddr_in)) || + (sa -> sa_family == AF_INET6 && salen != sizeof(struct nx_bsd_sockaddr_in6))) { /* Address length is invalid. */ @@ -14515,7 +14666,7 @@ const CHAR *rt_ptr; #ifndef NX_DISABLE_IPV4 /* Get host name by IPv4 address via DNS. */ - status = nx_dns_host_by_address_get(_nx_dns_instance_ptr, ntohl(((struct sockaddr_in *)sa) -> sin_addr.s_addr), + status = nx_dns_host_by_address_get(_nx_dns_instance_ptr, ntohl(((struct nx_bsd_sockaddr_in *)sa) -> sin_addr.s_addr), (UCHAR *)host, hostlen, NX_BSD_TIMEOUT); #else status = NX_DNS_NO_SERVER; @@ -14526,10 +14677,10 @@ const CHAR *rt_ptr; #ifdef FEATURE_NX_IPV6 /* copy data from sockaddr structure to NXD_ADDRESS structure. */ nxd_ipv6_addr.nxd_ip_version = NX_IP_VERSION_V6; - nxd_ipv6_addr.nxd_ip_address.v6[0] = ntohl(((struct sockaddr_in6 *)sa) -> sin6_addr.s6_addr32[0]); - nxd_ipv6_addr.nxd_ip_address.v6[1] = ntohl(((struct sockaddr_in6 *)sa) -> sin6_addr.s6_addr32[1]); - nxd_ipv6_addr.nxd_ip_address.v6[2] = ntohl(((struct sockaddr_in6 *)sa) -> sin6_addr.s6_addr32[2]); - nxd_ipv6_addr.nxd_ip_address.v6[3] = ntohl(((struct sockaddr_in6 *)sa) -> sin6_addr.s6_addr32[3]); + nxd_ipv6_addr.nxd_ip_address.v6[0] = ntohl(((struct nx_bsd_sockaddr_in6 *)sa) -> sin6_addr.s6_addr32[0]); + nxd_ipv6_addr.nxd_ip_address.v6[1] = ntohl(((struct nx_bsd_sockaddr_in6 *)sa) -> sin6_addr.s6_addr32[1]); + nxd_ipv6_addr.nxd_ip_address.v6[2] = ntohl(((struct nx_bsd_sockaddr_in6 *)sa) -> sin6_addr.s6_addr32[2]); + nxd_ipv6_addr.nxd_ip_address.v6[3] = ntohl(((struct nx_bsd_sockaddr_in6 *)sa) -> sin6_addr.s6_addr32[3]); /* Get host name by IPv6 address via DNS. */ status = nxd_dns_host_by_address_get(_nx_dns_instance_ptr, &nxd_ipv6_addr, @@ -14566,9 +14717,9 @@ const CHAR *rt_ptr; /* Host must be numeric string. Convert IP address from numeric to presentation. */ if(sa -> sa_family == AF_INET) - rt_ptr = inet_ntop(AF_INET, &((struct sockaddr_in*)sa) -> sin_addr, (CHAR *)host, hostlen); + rt_ptr = nx_bsd_inet_ntop(AF_INET, &((struct nx_bsd_sockaddr_in*)sa) -> sin_addr, (CHAR *)host, hostlen); else - rt_ptr = inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa) -> sin6_addr, (CHAR *)host, hostlen); + rt_ptr = nx_bsd_inet_ntop(AF_INET6, &((struct nx_bsd_sockaddr_in6*)sa) -> sin6_addr, (CHAR *)host, hostlen); if(!rt_ptr) return EAI_OVERFLOW; @@ -14730,3 +14881,195 @@ static VOID _nx_bsd_fast_periodic_timer_entry(ULONG id) /* Call default IP fast periodic timer entry. */ nx_bsd_ip_fast_periodic_timer_entry(id); } + + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* poll PORTABLE C */ +/* 6.x */ +/* AUTHOR */ +/* */ +/* Chaoqiong Xiao, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function allows for list of sockets to be checked for incoming */ +/* events. */ +/* */ +/* Before invoked, each item inside fds array should be initialized, */ +/* pollfd::fd must be the descriptor ID to check and pollfd::events */ +/* must be the events (bits) to check. */ +/* */ +/* Returned, the pollfd::revents of each item is updated, to indicate */ +/* if the checked events happen. */ +/* */ +/* The event (bit) currently supported: */ +/* - POLLIN : checking socket read FD */ +/* - POLLOUT: checking socket write FD */ +/* - POLLPRI: checking socket exception FD */ +/* */ +/* NOTE: ****** When select returns NX_SOC_ERROR it won't update */ +/* the fds descriptor. */ +/* */ +/* INPUT */ +/* */ +/* fds Socket descriptor list to poll */ +/* and report actual status */ +/* nfds Number of socket descriptors */ +/* timeOut Timeout in microseconds, set */ +/* to below 0 to wait infinitely */ +/* */ +/* OUTPUT */ +/* */ +/* NX_SUCCESS Descriptors check ends */ +/* (successful completion) */ +/* NX_SOC_ERROR (-1) Error occured */ +/* */ +/* CALLS */ +/* */ +/* FD_ZERO Clear a socket ready list */ +/* FD_ISSET Check a socket is ready */ +/* FD_SET Set a socket */ +/* select Perform checks, see select() */ +/* set_errno Set the error code */ +/* */ +/* CALLED BY */ +/* */ +/* Application Code */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* */ +/**************************************************************************/ +INT nx_bsd_poll(struct nx_bsd_pollfd *fds, ULONG nfds, INT timeout) +{ +nx_bsd_fd_set read_fds; +nx_bsd_fd_set write_fds; +nx_bsd_fd_set except_fds; +struct nx_bsd_timeval stime; +struct nx_bsd_timeval *ptime; +INT n_ready_fds; +INT max_fd; +ULONG i; +struct nx_bsd_pollfd *poll_fd; + + /* Check input parameter. */ + if (fds == NX_NULL) + { + nx_bsd_set_errno(EFAULT); + return(NX_SOC_ERROR); + } + if (nfds == 0) + { + nx_bsd_set_errno(EFAULT); + return(NX_SOC_ERROR); + } + + /* Initialize local FDs. */ + NX_BSD_FD_ZERO(&read_fds); + NX_BSD_FD_ZERO(&write_fds); + NX_BSD_FD_ZERO(&except_fds); + + /* Map the poll() FD to select() FDs. */ + max_fd = 0; + for(i = 0; i < nfds; i ++) + { + poll_fd = &fds[i]; + + /* Skip bad FDs. */ + if (poll_fd -> fd < 0) + continue; + + /* POLLIN. */ + if (poll_fd -> events & POLLIN) + { + NX_BSD_FD_SET(poll_fd -> fd, &read_fds); + } + + /* POLLOUT. */ + if (poll_fd -> events & POLLOUT) + { + NX_BSD_FD_SET(poll_fd -> fd, &write_fds); + } + + /* POLLPRI. */ + if (poll_fd -> events & POLLPRI) + { + NX_BSD_FD_SET(poll_fd -> fd, &except_fds); + } + + /* Update max FD. */ + if (poll_fd -> fd > max_fd) + max_fd = poll_fd -> fd; + } + + /* Map the select() timeout. */ + if (timeout < 0) + { + + /* select() wait infinitely. */ + ptime = NX_NULL; + } + else + { + + /* select() uses timeval option. */ + ptime = &stime; + + if (timeout == 0) + { + + /* select() no wait. */ + ptime -> tv_sec = 0; + ptime -> tv_usec = 0; + } + else + { + + /* select() wait specific time in ms. */ + ptime -> tv_sec = (timeout / 1000); + ptime -> tv_usec = (timeout % 1000); + } + + } + + /* Invoke select(). */ + n_ready_fds = nx_bsd_select(max_fd + 1, &read_fds, &write_fds, &except_fds, ptime); + + /* Parse result events if FDs updated. */ + if (n_ready_fds) + { + + for (i = 0; i < nfds; i ++) + { + poll_fd = &fds[i]; + + /* Skip bad FDs. */ + if (poll_fd -> fd < 0) + continue; + + /* Exceptions. */ + if (NX_BSD_FD_ISSET(poll_fd -> fd, &except_fds)) + poll_fd -> revents |= POLLPRI; + + else + { + + /* Inputs. */ + if (NX_BSD_FD_ISSET(poll_fd -> fd, &read_fds)) + poll_fd -> revents |= POLLIN; + } + + /* Outputs. */ + if (NX_BSD_FD_ISSET(poll_fd -> fd, &write_fds)) + poll_fd -> revents |= POLLOUT; + } + } + + return(n_ready_fds); +} diff --git a/addons/BSD/nxd_bsd.h b/addons/BSD/nxd_bsd.h index ba4ef7a3..6d1e2629 100644 --- a/addons/BSD/nxd_bsd.h +++ b/addons/BSD/nxd_bsd.h @@ -11,33 +11,33 @@ /**************************************************************************/ /**************************************************************************/ -/** */ -/** NetX Component */ /** */ -/** BSD 4.3 Socket API Compatible Interface to NetX Duo */ +/** NetX Component */ +/** */ +/** BSD 4.3 Socket API Compatible Interface to NetX Duo */ /** */ /** */ /**************************************************************************/ /**************************************************************************/ -/**************************************************************************/ -/* */ -/* BSD DEFINITIONS RELEASE */ -/* */ -/* nxd_bsd.h PORTABLE C */ -/* 6.1.9 */ +/**************************************************************************/ +/* */ +/* BSD DEFINITIONS RELEASE */ +/* */ +/* nxd_bsd.h PORTABLE C */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ -/* DESCRIPTION */ -/* */ -/* This file defines the constants, structures, etc... needed to */ +/* DESCRIPTION */ +/* */ +/* This file defines the constants, structures, etc... needed to */ /* implement the BSD 4.3 Socket API Compatible Interface to NetX Duo. */ -/* */ -/* */ -/* RELEASE HISTORY */ -/* */ +/* */ +/* */ +/* RELEASE HISTORY */ +/* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ @@ -50,6 +50,10 @@ /* defined IP protocols for */ /* ICMP, IGMP and ICMPv6, */ /* resulting in version 6.1.9 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), and */ +/* added option to enable */ +/* native APIs with prefix, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ @@ -74,7 +78,7 @@ extern "C" { #include "nx_api.h" -/* Define the print error macro for reporting source line number. +/* Define the print error macro for reporting source line number. #define NX_BSD_PRINT_ERRORS */ @@ -104,8 +108,8 @@ extern "C" { */ -/* - Define the BSD socket timeout process to execute in the timer context. +/* + Define the BSD socket timeout process to execute in the timer context. If this option is not defined, application needs to create stack space for the BSD timeout process thread, and passes the stack to the BSD layer through the bsd_initialize() call. In this configuration, the BSD timeout process is all done in the BSD timeout process thread context. @@ -122,62 +126,157 @@ extern "C" { * If the timer is executed in ISR context (ThreadX library is built with TX_TIMER_PROCESS_IN_ISR), the BSD timeout process is now executing in the ISR context; - By default NX_BSD_TIMEOUT_PROCESS_IN_TIMER is NOT defined. + By default NX_BSD_TIMEOUT_PROCESS_IN_TIMER is NOT defined. */ /* #define NX_BSD_TIMEOUT_PROCESS_IN_TIMER */ - + + +/* Defined, APIs are natively named with nx_bsd_ prefix to avoid conflicting/overriding OS BSD APIs. */ +/* +#define NX_BSD_ENABLE_NATIVE_API +*/ + + /* Define configuration constants for the BSD compatibility layer. Note that these can be overridden via -D or a #define somewhere else. */ #ifndef NX_BSD_TCP_WINDOW #define NX_BSD_TCP_WINDOW 65535 /* 64k is typical window size for 100Mb ethernet. */ -#endif +#endif #ifndef NX_BSD_SOCKFD_START -#define NX_BSD_SOCKFD_START 32 /* Logical FD starting value. */ +#define NX_BSD_SOCKFD_START 32 /* Logical FD starting value. */ #endif -#ifndef NX_BSD_MAX_SOCKETS +#ifndef NX_BSD_MAX_SOCKETS #define NX_BSD_MAX_SOCKETS 32 /* Maximum number of total sockets available in the BSD layer. Note */ -#endif /* NOTE: Must be multiple of 32! */ +#endif /* NOTE: Must be multiple of 32! */ #ifndef NX_BSD_MAX_LISTEN_BACKLOG -#define NX_BSD_MAX_LISTEN_BACKLOG 5 /* Maximum listen backlog. */ +#define NX_BSD_MAX_LISTEN_BACKLOG 5 /* Maximum listen backlog. */ #endif #ifndef NX_MICROSECOND_PER_CPU_TICK -#define NX_MICROSECOND_PER_CPU_TICK (1000000/NX_IP_PERIODIC_RATE) /* Number of microseconds per timer interrupt, default 10ms. */ +#define NX_MICROSECOND_PER_CPU_TICK (1000000/NX_IP_PERIODIC_RATE) /* Number of microseconds per timer interrupt, default 10ms. */ #endif #ifndef NX_BSD_TIMEOUT -#define NX_BSD_TIMEOUT (20*NX_IP_PERIODIC_RATE) +#define NX_BSD_TIMEOUT (20*NX_IP_PERIODIC_RATE) /* By default all internal NetX calls wait and block for 20 seconds. */ #endif #ifndef NX_BSD_TCP_SOCKET_DISCONNECT_TIMEOUT -#define NX_BSD_TCP_SOCKET_DISCONNECT_TIMEOUT 1 /* Timeout in timer ticks for internal NetX to disconnect the socket. - The default value of 1 tick is so NetX BSD emulates native BSD - socket and performs an immediate socket close without sending an RST - packet. */ +#define NX_BSD_TCP_SOCKET_DISCONNECT_TIMEOUT 1 /* Timeout in timer ticks for internal NetX to disconnect the socket. + The default value of 1 tick is so NetX BSD emulates native BSD + socket and performs an immediate socket close without sending an RST + packet. */ #endif /* Define configurable options for BSD extended options. */ - -#ifndef NX_BSD_TIMER_RATE + +#ifndef NX_BSD_TIMER_RATE #define NX_BSD_TIMER_RATE (1 * NX_IP_PERIODIC_RATE) /* Rate at which BSD timer runs. */ -#endif +#endif + - /* Define BSD events */ -#define NX_BSD_RECEIVE_EVENT ((ULONG) 0x00000001) /* Event flag to signal a receive packet event */ -#define NX_BSD_SELECT_EVENT ((ULONG) 0x00008000) /* Event flag to signal a thread is waiting in select */ +#define NX_BSD_RECEIVE_EVENT ((ULONG) 0x00000001) /* Event flag to signal a receive packet event */ +#define NX_BSD_SELECT_EVENT ((ULONG) 0x00008000) /* Event flag to signal a thread is waiting in select */ #define NX_BSD_ALL_EVENTS ((ULONG) 0xFFFFFFFF) /* All event flag */ #define NX_BSD_CONNECT_EVENT ((ULONG) 0x00000002) #define NX_BSD_LINGER_EVENT ((ULONG) 0x00000004) /* Event flag to signal a timed linger state has expired on a socket */ #define NX_BSD_TIMED_WAIT_EVENT ((ULONG) 0x00000008) /* Event flag to signal a timed wait state has expired on a socket */ #define NX_BSD_TIMER_EVENT ((ULONG) 0x00000010) /* Event flag to singal a BSD 1 sec timer */ + +/* For BSD APIs overriding. */ + +#if !defined(NX_BSD_ENABLE_NATIVE_API) + + +/* Overriding struct names. */ + +#define nx_bsd_time_t time_t +#define nx_bsd_suseconds_t suseconds_t + +#define nx_bsd_timeval timeval + +#define nx_bsd_sockaddr_storage sockaddr_storage + +#define nx_bsd_sockaddr sockaddr + +#define nx_bsd_in6_addr in6_addr + +#define nx_bsd_sockaddr_in6 sockaddr_in6 + +#define nx_bsd_in_addr in_addr +#define nx_bsd_in_addr_t in_addr_t +#define nx_bsd_socklen_t socklen_t + +#define nx_bsd_sockaddr_in sockaddr_in + +#define nx_bsd_fd_set fd_set + +#define nx_bsd_ip_mreq ip_mreq + +#define nx_bsd_sock_errno sock_errno + +#define nx_bsd_linger linger + +#define nx_bsd_sock_keepalive sock_keepalive + +#define nx_bsd_sock_reuseaddr sock_reuseaddr + +#define nx_bsd_sock_winsize sock_winsize + +#define nx_bsd_addrinfo addrinfo + +#define nx_bsd_pollfd pollfd + +#define nx_bsd_sockaddr_ll sockaddr_ll + + +/* Overriding function names. */ + +#define nx_bsd_accept accept +#define nx_bsd_initialize bsd_initialize +#define nx_bsd_bind bind +#define nx_bsd_connect connect +#define nx_bsd_getpeername getpeername +#define nx_bsd_getsockname getsockname +#define nx_bsd_ioctl ioctl +#define nx_bsd_inet_addr inet_addr +#define nx_bsd_inet_ntoa inet_ntoa +#define nx_bsd_inet_aton inet_aton +#define nx_bsd_inet_pton inet_pton +#define nx_bsd_inet_ntop inet_ntop +#define nx_bsd_listen listen +#define nx_bsd_recvfrom recvfrom +#define nx_bsd_recv recv +#define nx_bsd_sendto sendto +#define nx_bsd_send send +#define nx_bsd_select select +#define nx_bsd_soc_close soc_close +#define nx_bsd_socket socket +#define nx_bsd_fcntl fcntl +#define nx_bsd_getsockopt getsockopt +#define nx_bsd_setsockopt setsockopt +#define nx_bsd_getaddrinfo getaddrinfo +#define nx_bsd_freeaddrinfo freeaddrinfo +#define nx_bsd_getnameinfo getnameinfo +#define nx_bsd_set_errno set_errno +#define nx_bsd_poll poll + +#define NX_BSD_FD_SET FD_SET +#define NX_BSD_FD_CLR FD_CLR +#define NX_BSD_FD_ISSET FD_ISSET +#define NX_BSD_FD_ZERO FD_ZERO + + + +#endif + /* For compatibility undefine the fd_set. Then define the FD set size. */ #ifdef fd_set @@ -264,7 +363,7 @@ extern "C" { #ifdef NX_BSD_PRINT_ERRORS #define NX_BSD_ERROR(status, line) printf(" NX BSD debug error message:, NX status: %x source line: %i \n", status, line) #else -#define NX_BSD_ERROR(status, line) +#define NX_BSD_ERROR(status, line) #endif @@ -290,14 +389,14 @@ extern "C" { #endif /* Define the maximum number of packets that can be queued on a UDP socket or RAW socket. */ -#ifndef NX_BSD_SOCKET_QUEUE_MAX +#ifndef NX_BSD_SOCKET_QUEUE_MAX #define NX_BSD_SOCKET_QUEUE_MAX 5 #endif -/* Define the constants that determine how big the hash table is for raw socket Protocol. The +/* Define the constants that determine how big the hash table is for raw socket Protocol. The value must be a power of two, so subtracting one gives us the mask. */ -#ifndef NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE +#ifndef NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE #define NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE 32 #endif /* NX_BSD_SOCKET_RAW_PROTOCOL_TABLE_SIZE */ @@ -445,7 +544,7 @@ extern "C" { /* List of BSD sock options from socket.h in /usr/include/asm/socket.h and asm-generic/socket.h. - Note: not all of these are implemented in NetX Duo Extended socket options. + Note: not all of these are implemented in NetX Duo Extended socket options. The first set of socket options take the socket level (category) SOL_SOCKET. */ @@ -490,7 +589,7 @@ extern "C" { #define IP_ADD_MEMBERSHIP 32 /* Join IPv4 multicast membership */ #define IP_DROP_MEMBERSHIP 33 /* Leave IPv4 multicast membership */ #define IP_HDRINCL 34 /* Raw socket IPv4 header included. */ -#define IP_RAW_RX_NO_HEADER 35 /* NetX proprietary socket option that does not include +#define IP_RAW_RX_NO_HEADER 35 /* NetX proprietary socket option that does not include IPv4/IPv6 header (and extension headers) on received raw sockets.*/ #define IP_RAW_IPV6_HDRINCL 36 /* Transmitted buffer over IPv6 socket contains IPv6 header. */ #define IP_OPTION_MAX IP_RAW_IPV6_HDRINCL @@ -508,34 +607,35 @@ extern "C" { /* Define data types used in structure timeval. */ -#ifdef __CCRX__ -typedef LONG time_t; -#endif /* __CCRX__ */ -typedef LONG suseconds_t; +#if defined(__CCRX__) || defined(NX_BSD_ENABLE_NATIVE_API) +typedef LONG nx_bsd_time_t; +#endif /* __CCRX__ || NX_BSD_ENABLE_NATIVE_API */ +typedef LONG nx_bsd_suseconds_t; #ifndef __SES_ARM -struct timeval +struct nx_bsd_timeval { - time_t tv_sec; /* Seconds */ - suseconds_t tv_usec; /* Microseconds */ + nx_bsd_time_t tv_sec; /* Seconds */ + nx_bsd_suseconds_t + tv_usec; /* Microseconds */ }; #endif /* __SES_ARM */ -struct sockaddr_storage +struct nx_bsd_sockaddr_storage { USHORT ss_len; USHORT ss_family; }; -struct sockaddr +struct nx_bsd_sockaddr { USHORT sa_family; /* Address family (e.g. , AF_INET). */ UCHAR sa_data[14]; /* Protocol- specific address information. */ }; -struct in6_addr +struct nx_bsd_in6_addr { - union + union { UCHAR _S6_u8[16]; ULONG _S6_u32[4]; @@ -545,89 +645,93 @@ struct in6_addr #define s6_addr _S6_un._S6_u8 #define s6_addr32 _S6_un._S6_u32 -struct sockaddr_in6 +struct nx_bsd_sockaddr_in6 { USHORT sin6_family; /* AF_INET6 */ USHORT sin6_port; /* Transport layer port. */ ULONG sin6_flowinfo; /* IPv6 flow information. */ - struct in6_addr sin6_addr; /* IPv6 address. */ + struct nx_bsd_in6_addr + sin6_addr; /* IPv6 address. */ ULONG sin6_scope_id; /* set of interafces for a scope. */ }; /* Internet address (a structure for historical reasons). */ -struct in_addr +struct nx_bsd_in_addr { - ULONG s_addr; /* Internet address (32 bits). */ + ULONG s_addr; /* Internet address (32 bits). */ }; -typedef ULONG in_addr_t; -typedef ULONG socklen_t; +typedef ULONG nx_bsd_in_addr_t; +typedef ULONG nx_bsd_socklen_t; + - /* Socket address, Internet style. */ -struct sockaddr_in +struct nx_bsd_sockaddr_in { USHORT sin_family; /* Internet Protocol (AF_INET). */ USHORT sin_port; /* Address port (16 bits). */ - struct in_addr sin_addr; /* Internet address (32 bits). */ + struct nx_bsd_in_addr + sin_addr; /* Internet address (32 bits). */ CHAR sin_zero[8]; /* Not used. */ }; typedef struct FD_SET_STRUCT /* The select socket array manager. */ -{ +{ INT fd_count; /* How many are SET? */ ULONG fd_array[(NX_BSD_MAX_SOCKETS + 31)/32]; /* Bit map of SOCKET Descriptors. */ -} fd_set; +} nx_bsd_fd_set; typedef struct NX_BSD_SOCKET_SUSPEND_STRUCT { ULONG nx_bsd_socket_suspend_actual_flags; - fd_set nx_bsd_socket_suspend_read_fd_set; - fd_set nx_bsd_socket_suspend_write_fd_set; - fd_set nx_bsd_socket_suspend_exception_fd_set; + nx_bsd_fd_set nx_bsd_socket_suspend_read_fd_set; + nx_bsd_fd_set nx_bsd_socket_suspend_write_fd_set; + nx_bsd_fd_set nx_bsd_socket_suspend_exception_fd_set; } NX_BSD_SOCKET_SUSPEND; -struct ip_mreq +struct nx_bsd_ip_mreq { - struct in_addr imr_multiaddr; /* The IPv4 multicast address to join. */ - struct in_addr imr_interface; /* The interface to use for this group. */ + struct nx_bsd_in_addr + imr_multiaddr; /* The IPv4 multicast address to join. */ + struct nx_bsd_in_addr + imr_interface; /* The interface to use for this group. */ }; /* Define additional BSD data structures for supporting socket options. */ -struct sock_errno +struct nx_bsd_sock_errno { INT error; /* default = 0; */ }; -struct linger +struct nx_bsd_linger { INT l_onoff; /* 0 = disabled; 1 = enabled; default = 0;*/ INT l_linger; /* linger time in seconds; default = 0;*/ }; -struct sock_keepalive +struct nx_bsd_sock_keepalive { INT keepalive_enabled; /* 0 = disabled; 1 = enabled; default = 0;*/ }; -struct sock_reuseaddr +struct nx_bsd_sock_reuseaddr { INT reuseaddr_enabled; /* 0 = disabled; 1 = enabled; default = 1; */ }; -struct sock_winsize +struct nx_bsd_sock_winsize { INT winsize; /* receive window size for TCP sockets ; */ }; @@ -640,16 +744,17 @@ union UNION_ID }; -struct addrinfo +struct nx_bsd_addrinfo { INT ai_flags; INT ai_family; INT ai_socktype; INT ai_protocol; - socklen_t ai_addrlen; - struct sockaddr *ai_addr; + nx_bsd_socklen_t ai_addrlen; + struct nx_bsd_sockaddr *ai_addr; CHAR *ai_canonname; - struct addrinfo *ai_next; + struct nx_bsd_addrinfo + *ai_next; }; struct NX_BSD_SERVICE_LIST @@ -663,7 +768,7 @@ struct NX_BSD_SERVICE_LIST /* Define the Errors return by getaddrinfo. */ /* The specified host doesn't have addresses in the specified address family. */ -#define EAI_ADDRFAMILY 40 +#define EAI_ADDRFAMILY 40 /* Name server temporary failure. */ #define EAI_AGAIN 41 /* hints.si_flags contains invalid flag. */ @@ -686,7 +791,7 @@ struct NX_BSD_SERVICE_LIST /* Define ai_flags value. */ -#define AI_PASSIVE 0x0001 +#define AI_PASSIVE 0x0001 /* request CNAME. */ #define AI_CANONNAME 0x0002 /* host must be a address string. */ @@ -698,7 +803,7 @@ struct NX_BSD_SERVICE_LIST #define AI_ADDRCONFIG 0x0040 /* Return numeric string for hostname. */ -#define NI_NUMERICHOST 0x0001 +#define NI_NUMERICHOST 0x0001 /* Return numeric string for service name. */ #define NI_NUMERICSERV 0x0002 /* Return only hostname portion of FQDN. */ @@ -709,13 +814,37 @@ struct NX_BSD_SERVICE_LIST #define NI_DGRAM 0x0010 +/* Define the struct used by poll. */ +struct nx_bsd_pollfd +{ + INT fd; /* file descriptor. */ + SHORT events; /* requested events. */ + SHORT revents; /* returned events. */ +}; + +/* Define the options used by poll. */ + +#define POLLRDNORM 0x0100 +#define POLLRDBAND 0x0200 /* Not supported. */ +#define POLLIN (POLLRDNORM) +#define POLLPRI 0x0400 + +#define POLLWRNORM 0x0010 +#define POLLOUT (POLLWRNORM) +#define POLLWRBAND 0x0020 /* Not supported. */ + +#define POLLERR 0x0001 +#define POLLHUP 0x0002 +#define POLLNVAL 0x0004 + + /* Defines maximum IPv4 addresses for getaddrinfo. */ -#ifndef NX_BSD_IPV4_ADDR_MAX_NUM +#ifndef NX_BSD_IPV4_ADDR_MAX_NUM #define NX_BSD_IPV4_ADDR_MAX_NUM 5 #endif /* NX_BSD_IPV4_ADDR_MAX_NUM */ /* Defines maximum IPv6 addresses for getaddrinfo. */ -#ifndef NX_BSD_IPV6_ADDR_MAX_NUM +#ifndef NX_BSD_IPV6_ADDR_MAX_NUM #define NX_BSD_IPV6_ADDR_MAX_NUM 5 #endif /* NX_BSD_IPV6_ADDR_MAX_NUM */ @@ -734,7 +863,7 @@ struct NX_BSD_SERVICE_LIST #define NX_BSD_SOCKET_ERROR (1 << 1) #define NX_BSD_SOCKET_CONNECTED (1 << 2) /* Disconnected from the stack. */ -#define NX_BSD_SOCKET_DISCONNECT_FROM_STACK (1 << 3) +#define NX_BSD_SOCKET_DISCONNECT_FROM_STACK (1 << 3) #define NX_BSD_SOCKET_SERVER_MASTER_SOCKET (1 << 4) #define NX_BSD_SOCKET_SERVER_SECONDARY_SOCKET (1 << 5) #define NX_BSD_SOCKET_TX_HDR_INCLUDE (1 << 6) @@ -753,7 +882,7 @@ struct NX_BSD_SERVICE_LIST #define NX_BSD_SOCKET_ENABLE_OPTION_REUSEADDR (1 << 2) #define NX_BSD_SOCKET_ENABLE_OPTION_NON_BLOCKING (1 << 3) -/* Define the internal management structure for the BSD layer. */ +/* Define the internal management structure for the BSD layer. */ typedef struct NX_BSD_SOCKET_STRUCT { @@ -778,24 +907,24 @@ typedef struct NX_BSD_SOCKET_STRUCT NXD_ADDRESS nx_bsd_socket_source_ip_address; NXD_ADDRESS nx_bsd_socket_peer_ip; - /* For TCP/UDP, the local port is the port number this socket receives on. + /* For TCP/UDP, the local port is the port number this socket receives on. For raw socket this field is not used. */ USHORT nx_bsd_socket_local_port; USHORT nx_bsd_socket_peer_port; INT nx_bsd_option_linger_time; - UINT nx_bsd_option_linger_time_closed; - UINT nx_bsd_option_linger_start_close; + UINT nx_bsd_option_linger_time_closed; + UINT nx_bsd_option_linger_start_close; UINT nx_bsd_socket_time_wait_remaining; - ULONG nx_bsd_option_receive_timeout; - ULONG nx_bsd_option_send_timeout; + ULONG nx_bsd_option_receive_timeout; + ULONG nx_bsd_option_send_timeout; INT nx_bsd_file_descriptor_flags; ULONG nx_bsd_socket_status_flags; ULONG nx_bsd_socket_option_flags; int nx_bsd_socket_error_code; - struct NX_BSD_SOCKET_STRUCT + struct NX_BSD_SOCKET_STRUCT *nx_bsd_socket_next; - struct NX_BSD_SOCKET_STRUCT + struct NX_BSD_SOCKET_STRUCT *nx_bsd_socket_previous; INT nx_bsd_socket_id; @@ -813,52 +942,63 @@ typedef struct NX_BSD_SOCKET_STRUCT /* Define the BSD function prototypes for use by the application. */ -INT accept(INT sockID, struct sockaddr *ClientAddress, INT *addressLength); -INT bsd_initialize(NX_IP *default_ip, NX_PACKET_POOL *default_pool, CHAR *bsd_thread_stack_area, ULONG bsd_thread_stack_size, UINT bsd_thread_priority); -INT bind(INT sockID, struct sockaddr *localAddress, INT addressLength); -INT connect(INT sockID, struct sockaddr *remoteAddress, INT addressLength); -INT getpeername(INT sockID, struct sockaddr *remoteAddress, INT *addressLength); -INT getsockname(INT sockID, struct sockaddr *localAddress, INT *addressLength); -INT ioctl(INT sockID, INT command, INT *result); -in_addr_t inet_addr(const CHAR *buffer); -CHAR *inet_ntoa(struct in_addr address_to_convert); -INT inet_aton(const CHAR *cp_arg, struct in_addr *addr); -INT inet_pton(INT af, const CHAR *src, VOID *dst); -const CHAR *inet_ntop(INT af, const VOID *src, CHAR *dst, socklen_t size); -INT listen(INT sockID, INT backlog); -#ifdef NX_ENABLE_IP_RAW_PACKET_FILTER + +INT nx_bsd_accept(INT sockID, struct nx_bsd_sockaddr *ClientAddress, INT *addressLength); +INT nx_bsd_initialize(NX_IP *default_ip, NX_PACKET_POOL *default_pool, CHAR *bsd_thread_stack_area, ULONG bsd_thread_stack_size, UINT bsd_thread_priority); +INT nx_bsd_bind(INT sockID, const struct nx_bsd_sockaddr *localAddress, INT addressLength); +INT nx_bsd_connect(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT addressLength); +INT nx_bsd_getpeername(INT sockID, struct nx_bsd_sockaddr *remoteAddress, INT *addressLength); +INT nx_bsd_getsockname(INT sockID, struct nx_bsd_sockaddr *localAddress, INT *addressLength); +INT nx_bsd_ioctl(INT sockID, INT command, INT *result); +nx_bsd_in_addr_t nx_bsd_inet_addr(const CHAR *buffer); +CHAR *nx_bsd_inet_ntoa(struct nx_bsd_in_addr address_to_convert); +INT nx_bsd_inet_aton(const CHAR *cp_arg, struct nx_bsd_in_addr *addr); +INT nx_bsd_inet_pton(INT af, const CHAR *src, VOID *dst); +const CHAR *nx_bsd_inet_ntop(INT af, const VOID *src, CHAR *dst, nx_bsd_socklen_t size); +INT nx_bsd_listen(INT sockID, INT backlog); +#ifdef NX_ENABLE_IP_RAW_PACKET_FILTER UINT nx_bsd_raw_packet_receive(NX_BSD_SOCKET *bsd_socket_ptr, NX_PACKET **packet_ptr); UINT nx_bsd_raw_packet_info_extract(NX_PACKET *packet_ptr, NXD_ADDRESS *nxd_address, UINT *interface_index); VOID nx_bsd_raw_receive_notify(NX_IP *ip_ptr, UINT bsd_socket_index); #endif UINT nx_bsd_socket_set_inherited_settings(UINT master_sock_id, UINT secondary_sock_id); -INT recvfrom(INT sockID, CHAR *buffer, INT buffersize, INT flags,struct sockaddr *fromAddr, INT *fromAddrLen); -INT recv(INT sockID, VOID *rcvBuffer, INT bufferLength, INT flags); -INT sendto(INT sockID, CHAR *msg, INT msgLength, INT flags, struct sockaddr *destAddr, INT destAddrLen); -INT send(INT sockID, const CHAR *msg, INT msgLength, INT flags); -INT select(INT nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); -INT soc_close( INT sockID); -INT socket(INT protocolFamily, INT type, INT protocol); -INT fcntl(INT sock_ID, UINT flag_type, UINT f_options); -INT getsockopt(INT sockID, INT option_level, INT option_name, VOID *option_value, INT *option_length); -INT setsockopt(INT sockID, INT option_level, INT option_name, const VOID *option_value, INT option_length); -INT getaddrinfo(const CHAR *node, const CHAR *service, const struct addrinfo *hints, struct addrinfo **res); -VOID freeaddrinfo(struct addrinfo *res); -INT getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); +INT nx_bsd_recvfrom(INT sockID, CHAR *buffer, INT buffersize, INT flags,struct nx_bsd_sockaddr *fromAddr, INT *fromAddrLen); +INT nx_bsd_recv(INT sockID, VOID *rcvBuffer, INT bufferLength, INT flags); +INT nx_bsd_sendto(INT sockID, CHAR *msg, INT msgLength, INT flags, struct nx_bsd_sockaddr *destAddr, INT destAddrLen); +INT nx_bsd_send(INT sockID, const CHAR *msg, INT msgLength, INT flags); +INT nx_bsd_select(INT nfds, nx_bsd_fd_set *readfds, nx_bsd_fd_set *writefds, nx_bsd_fd_set *exceptfds, struct nx_bsd_timeval *timeout); +INT nx_bsd_soc_close( INT sockID); +INT nx_bsd_socket(INT protocolFamily, INT type, INT protocol); +INT nx_bsd_fcntl(INT sock_ID, UINT flag_type, UINT f_options); +INT nx_bsd_getsockopt(INT sockID, INT option_level, INT option_name, VOID *option_value, INT *option_length); +INT nx_bsd_setsockopt(INT sockID, INT option_level, INT option_name, const VOID *option_value, INT option_length); +INT nx_bsd_getaddrinfo(const CHAR *node, const CHAR *service, const struct nx_bsd_addrinfo *hints, struct nx_bsd_addrinfo **res); +VOID nx_bsd_freeaddrinfo(struct nx_bsd_addrinfo *res); +INT nx_bsd_getnameinfo(const struct nx_bsd_sockaddr *sa, nx_bsd_socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); VOID nx_bsd_set_service_list(struct NX_BSD_SERVICE_LIST *serv_list_ptr, ULONG serv_list_len); +INT nx_bsd_poll(struct nx_bsd_pollfd *fds, ULONG nfds, INT timeout); +#if !defined(NX_BSD_ENABLE_NATIVE_API) #undef FD_SET #undef FD_CLR #undef FD_ISSET #undef FD_ZERO +#endif + +VOID NX_BSD_FD_SET(INT fd, nx_bsd_fd_set *fdset); +VOID NX_BSD_FD_CLR(INT fd, nx_bsd_fd_set *fdset); +INT NX_BSD_FD_ISSET(INT fd, nx_bsd_fd_set *fdset); +VOID NX_BSD_FD_ZERO(nx_bsd_fd_set *fdset); +VOID nx_bsd_set_errno(INT tx_errno); + +INT _nxd_get_errno(VOID); + +#if !defined(NX_BSD_ENABLE_NATIVE_API) +#define errno (tx_thread_identify() -> bsd_errno) +#else +#define nx_bsd_errno (tx_thread_identify() -> bsd_errno) +#endif -VOID FD_SET(INT fd, fd_set *fdset); -VOID FD_CLR(INT fd, fd_set *fdset); -INT FD_ISSET(INT fd, fd_set *fdset); -VOID FD_ZERO(fd_set *fdset); -VOID set_errno(INT tx_errno); -int _nxd_get_errno(VOID); -#define errno (_nxd_get_errno()) #ifdef NX_BSD_RAW_PPPOE_SUPPORT @@ -874,7 +1014,7 @@ UINT _nx_bsd_pppoe_packet_received(NX_PACKET *packet_ptr, UINT frame_type, UINT #if defined(NX_BSD_RAW_SUPPORT) || defined(NX_BSD_RAW_PPPOE_SUPPORT) /* Link Layer Socket Addressing */ -struct sockaddr_ll +struct nx_bsd_sockaddr_ll { USHORT sll_family; /* Address Family. Must be AF_PACKET */ USHORT sll_protocol; /* LL frame type */ diff --git a/addons/azure_iot/nx_azure_iot.c b/addons/azure_iot/nx_azure_iot.c index 1a3a34c0..eef8bf8a 100644 --- a/addons/azure_iot/nx_azure_iot.c +++ b/addons/azure_iot/nx_azure_iot.c @@ -32,6 +32,7 @@ NX_AZURE_IOT *_nx_azure_iot_created_ptr; /* Define the callback for logging. */ static VOID(*_nx_azure_iot_log_callback)(az_log_classification classification, UCHAR *msg, UINT msg_len); +extern UINT _nxd_mqtt_client_packet_allocate(NXD_MQTT_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option); extern UINT _nxd_mqtt_client_publish_packet_send(NXD_MQTT_CLIENT *client_ptr, NX_PACKET *packet_ptr, USHORT packet_id, UINT QoS, ULONG wait_option); @@ -360,9 +361,9 @@ UINT nx_azure_iot_publish_packet_get(NX_AZURE_IOT *nx_azure_iot_ptr, NXD_MQTT_CL { UINT status; - status = nx_secure_tls_packet_allocate(&(client_ptr -> nxd_mqtt_tls_session), - nx_azure_iot_ptr -> nx_azure_iot_pool_ptr, - packet_pptr, wait_option); + NX_PARAMETER_NOT_USED(nx_azure_iot_ptr); + + status = _nxd_mqtt_client_packet_allocate(client_ptr, packet_pptr, wait_option); if (status) { LogError(LogLiteralArgs("Create publish packet failed")); diff --git a/addons/azure_iot/nx_azure_iot_adu_agent.c b/addons/azure_iot/nx_azure_iot_adu_agent.c index e7bceab8..ed80ea63 100644 --- a/addons/azure_iot/nx_azure_iot_adu_agent.c +++ b/addons/azure_iot/nx_azure_iot_adu_agent.c @@ -43,13 +43,16 @@ static UINT nx_azure_iot_adu_agent_service_update_manifest_process(NX_AZURE_IOT_ UINT update_manifest_size, NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_CONTENT *update_manifest_content, UCHAR *update_manifest_content_buffer, - UINT update_manifest_content_buffer_size); + UINT *update_manifest_content_buffer_size); static UINT nx_azure_iot_adu_agent_service_reported_properties_send(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, UINT status_code, ULONG version, const CHAR *description, ULONG wait_option); static UINT nx_azure_iot_adu_agent_reported_properties_startup_send(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, UINT wait_option); static UINT nx_azure_iot_adu_agent_reported_properties_state_send(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr); static VOID nx_azure_iot_adu_agent_step_state_update(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, UINT step_state); +#if (NX_AZURE_IOT_ADU_AGENT_PROXY_UPDATE_COUNT >= 2) +static UINT nx_azure_iot_adu_agent_step_file_update(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, NX_AZURE_IOT_ADU_AGENT_STEP *step, NX_AZURE_IOT_ADU_AGENT_FILE *file); +#endif /* (NX_AZURE_IOT_ADU_AGENT_PROXY_UPDATE_COUNT >= 2) */ static UINT nx_azure_iot_adu_agent_file_find(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_CONTENT *manifest_content, UCHAR *file_id, UINT file_id_length, @@ -149,6 +152,13 @@ UINT component_added = NX_FALSE; return(NX_AZURE_IOT_NOT_ENABLED); } + /* Check if PnP is enabled (model ID is set). */ + if (!az_span_size(iothub_client_ptr -> iot_hub_client_core._internal.options.model_id)) + { + LogError(LogLiteralArgs("ADU agent start fail: PNP NOT ENABLED")); + return(NX_AZURE_IOT_NOT_ENABLED); + } + memset(adu_agent_ptr, 0, sizeof(NX_AZURE_IOT_ADU_AGENT)); /* Set iothub client pointer and azure iot pointer. */ @@ -528,12 +538,13 @@ NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr = (NX_AZURE_IOT_ADU_AGENT *)args; } /* Process deployable update manifest. */ + adu_agent_ptr -> nx_azure_iot_adu_agent_buffer_size = NX_AZURE_IOT_ADU_AGENT_BUFFER_SIZE; if (nx_azure_iot_adu_agent_service_update_manifest_process(adu_agent_ptr, adu_agent_ptr -> nx_azure_iot_adu_agent_update_manifest, adu_agent_ptr -> nx_azure_iot_adu_agent_update_manifest_size, &(adu_agent_ptr -> nx_azure_iot_adu_agent_update_manifest_content), adu_agent_ptr -> nx_azure_iot_adu_agent_buffer, - NX_AZURE_IOT_ADU_AGENT_BUFFER_SIZE)) + &(adu_agent_ptr -> nx_azure_iot_adu_agent_buffer_size))) { LogError(LogLiteralArgs("ADU agent component process fail: UPDATE MANIFEST PROCESS FAIL")); return(NX_AZURE_IOT_FAILURE); @@ -860,12 +871,13 @@ NX_AZURE_IOT_ADU_AGENT_DOWNLOADER *downloader_ptr = &(adu_agent_ptr -> nx_azure_ } /* Process proxy update manifest. */ + adu_agent_ptr -> nx_azure_iot_adu_agent_update_manifest_sjwk_size = NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_SJWK_SIZE; if (nx_azure_iot_adu_agent_service_update_manifest_process(adu_agent_ptr, proxy_update_manifest_ptr, proxy_update_manifest_size, proxy_update_manifest_content, adu_agent_ptr -> nx_azure_iot_adu_agent_update_manifest_sjwk, - NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_SJWK_SIZE)) + &(adu_agent_ptr -> nx_azure_iot_adu_agent_update_manifest_sjwk_size))) { LogError(LogLiteralArgs("Failed to process proxy update manifest")); nx_azure_iot_adu_agent_step_state_update(adu_agent_ptr, NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FAILED); @@ -908,8 +920,13 @@ NX_AZURE_IOT_ADU_AGENT_DOWNLOADER *downloader_ptr = &(adu_agent_ptr -> nx_azure_ return; } +#if (NX_AZURE_IOT_ADU_AGENT_PROXY_UPDATE_COUNT >= 2) + /* Update step file for multiple proxy updates. */ + nx_azure_iot_adu_agent_step_file_update(adu_agent_ptr, step, file); +#else /* Set the file as new update. */ step -> file = file; +#endif /* (NX_AZURE_IOT_ADU_AGENT_PROXY_UPDATE_COUNT >= 2) */ adu_agent_ptr -> nx_azure_iot_adu_agent_update_flag = NX_TRUE; nx_azure_iot_adu_agent_step_state_update(adu_agent_ptr, NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FIRMWARE_DOWNLOAD_STARTED); @@ -936,11 +953,19 @@ static VOID nx_azure_iot_adu_agent_download_install_event_process(NX_AZURE_IOT_A NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_CONTENT *update_manifest_content = &(adu_agent_ptr -> nx_azure_iot_adu_agent_update_manifest_content); NX_AZURE_IOT_ADU_AGENT_STEP *step; UINT i; +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP +UINT step_flag = 0x00; +UINT update_state; +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ /* Check if current step is completed or not. */ if ((adu_agent_ptr -> nx_azure_iot_adu_agent_current_step == NX_NULL) || (adu_agent_ptr -> nx_azure_iot_adu_agent_current_step -> state == NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FIRMWARE_INSTALL_SUCCEEDED) || - (adu_agent_ptr -> nx_azure_iot_adu_agent_current_step -> state == NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FIRMWARE_APPLY_SUCCEEDED)) + (adu_agent_ptr -> nx_azure_iot_adu_agent_current_step -> state == NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FIRMWARE_APPLY_SUCCEEDED) +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP + || (adu_agent_ptr -> nx_azure_iot_adu_agent_current_step -> state == NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FAILED) +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ + ) { /* Find next step to download and install the next firmware. */ @@ -950,6 +975,16 @@ UINT i; { break; } +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP + else if (update_manifest_content -> steps[i].state == NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FAILED) + { + step_flag |= 0x01; /* Failed step. */ + } + else if (update_manifest_content -> steps[i].state == NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FIRMWARE_INSTALL_SUCCEEDED) + { + step_flag |= 0x02; /* Succeeded step. */ + } +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ } if (i < update_manifest_content -> steps_count) @@ -960,6 +995,27 @@ UINT i; } else { +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP + if (step_flag == 0x01) /* All steps failed. */ + { + adu_agent_ptr -> nx_azure_iot_adu_agent_state = NX_AZURE_IOT_ADU_AGENT_STATE_FAILED; + + LogError(LogLiteralArgs("Failed to deploy update!")); + + /* Report state to server. */ + nx_azure_iot_adu_agent_reported_properties_state_send(adu_agent_ptr); + + update_state = NX_AZURE_IOT_ADU_AGENT_UPDATE_FAILED; + } + else if (step_flag == 0x02) /* All steps succeeded. */ + { + update_state = NX_AZURE_IOT_ADU_AGENT_UPDATE_INSTALLED; + } + else /* Partial step succeeded. */ + { + update_state = NX_AZURE_IOT_ADU_AGENT_UPDATE_PARTIAL_INSTALLED; + } +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ /* All updates are downloaded and installed. */ if (adu_agent_ptr -> nx_azure_iot_adu_agent_update_notify) @@ -967,7 +1023,11 @@ UINT i; /* Notify the user and let users control the update. */ adu_agent_ptr -> nx_azure_iot_adu_agent_update_notify(adu_agent_ptr, +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP + update_state, +#else /* !NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ NX_AZURE_IOT_ADU_AGENT_UPDATE_INSTALLED, +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ (UCHAR *)update_manifest_content -> update_id.provider, update_manifest_content -> update_id.provider_length, (UCHAR *)update_manifest_content -> update_id.name, @@ -975,7 +1035,11 @@ UINT i; (UCHAR *)update_manifest_content -> update_id.version, update_manifest_content -> update_id.version_length); } +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP + else if (update_state != NX_AZURE_IOT_ADU_AGENT_STATE_FAILED) +#else else +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ { /* Set event to apply update automatically. */ @@ -1072,7 +1136,9 @@ UINT step_fail = NX_FALSE; if (step -> state == NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FAILED) { step_fail = NX_TRUE; +#ifndef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP break; +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ } } @@ -1730,6 +1796,9 @@ UINT i = 0; static VOID nx_azure_iot_adu_agent_step_state_update(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, UINT step_state) { NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_CONTENT *update_manifest_content = &(adu_agent_ptr -> nx_azure_iot_adu_agent_update_manifest_content); +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP +UINT origin_state = adu_agent_ptr -> nx_azure_iot_adu_agent_current_step -> state; +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ /* Update state. */ adu_agent_ptr -> nx_azure_iot_adu_agent_current_step -> state = step_state; @@ -1737,27 +1806,44 @@ NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_CONTENT *update_manifest_content = &(adu_ /* Check the step state. */ if (step_state == NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FAILED) { - adu_agent_ptr -> nx_azure_iot_adu_agent_state = NX_AZURE_IOT_ADU_AGENT_STATE_FAILED; +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP + /* Check if the current state is download or install. */ + if ((origin_state >= NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FIRMWARE_DOWNLOAD_STARTED) && + (origin_state <= NX_AZURE_IOT_ADU_AGENT_STEP_STATE_FIRMWARE_INSTALL_STARTED)) + { - LogError(LogLiteralArgs("Failed to deploy update!")); + /* Continue to try next step. */ + nx_cloud_module_event_set(&(adu_agent_ptr -> nx_azure_iot_adu_agent_cloud_module), + NX_AZURE_IOT_ADU_AGENT_DOWNLOAD_INSTALL_EVENT); + } + else + { +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ - /* Report state to server. */ - nx_azure_iot_adu_agent_reported_properties_state_send(adu_agent_ptr); + adu_agent_ptr -> nx_azure_iot_adu_agent_state = NX_AZURE_IOT_ADU_AGENT_STATE_FAILED; - /* Check if set the update notify. */ - if (adu_agent_ptr -> nx_azure_iot_adu_agent_update_notify) - { + LogError(LogLiteralArgs("Failed to deploy update!")); + + /* Report state to server. */ + nx_azure_iot_adu_agent_reported_properties_state_send(adu_agent_ptr); - /* Notify the user and let users control the update. */ - adu_agent_ptr -> nx_azure_iot_adu_agent_update_notify(adu_agent_ptr, - NX_AZURE_IOT_ADU_AGENT_UPDATE_FAILED, - (UCHAR *)update_manifest_content -> update_id.provider, - update_manifest_content -> update_id.provider_length, - (UCHAR *)update_manifest_content -> update_id.name, - update_manifest_content -> update_id.name_length, - (UCHAR *)update_manifest_content -> update_id.version, - update_manifest_content -> update_id.version_length); + /* Check if set the update notify. */ + if (adu_agent_ptr -> nx_azure_iot_adu_agent_update_notify) + { + + /* Notify the user and let users control the update. */ + adu_agent_ptr -> nx_azure_iot_adu_agent_update_notify(adu_agent_ptr, + NX_AZURE_IOT_ADU_AGENT_UPDATE_FAILED, + (UCHAR *)update_manifest_content -> update_id.provider, + update_manifest_content -> update_id.provider_length, + (UCHAR *)update_manifest_content -> update_id.name, + update_manifest_content -> update_id.name_length, + (UCHAR *)update_manifest_content -> update_id.version, + update_manifest_content -> update_id.version_length); + } +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP } +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ } else if (step_state == NX_AZURE_IOT_ADU_AGENT_STEP_STATE_MANIFEST_DOWNLOAD_SUCCEEDED) { @@ -1774,6 +1860,62 @@ NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_CONTENT *update_manifest_content = &(adu_ } } +#if (NX_AZURE_IOT_ADU_AGENT_PROXY_UPDATE_COUNT >= 2) +static UINT nx_azure_iot_adu_agent_step_file_update(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, NX_AZURE_IOT_ADU_AGENT_STEP *step, NX_AZURE_IOT_ADU_AGENT_FILE *file) +{ +NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_CONTENT *update_manifest_content = &(adu_agent_ptr -> nx_azure_iot_adu_agent_update_manifest_content); +NX_AZURE_IOT_ADU_AGENT_FILE *file_entry; + + /* Update the file as some items (name and sha256) are stored in proxy manifest content, and the proxy manifest content may be re-used in multiple proxy updates. */ + + /* Find an available entry to store. */ + if (update_manifest_content -> files_count >= NX_AZURE_IOT_ADU_AGENT_FILES_MAX) + { + return(NX_AZURE_IOT_NO_MORE_ENTRIES); + } + + /* Set the file entry. */ + file_entry = &(update_manifest_content -> files[update_manifest_content -> files_count]); + update_manifest_content -> files_count++; + + /* Set the pointer of file id and file url. */ + file_entry -> file_id = file -> file_id; + file_entry -> file_id_length = file -> file_id_length; + file_entry -> file_url = file -> file_url; + file_entry -> file_url_length = file -> file_url_length; + file_entry -> file_size_in_bytes = file -> file_size_in_bytes; + + /* Copy file name to manifest content buffer as it will not be overwritten. */ + if (adu_agent_ptr -> nx_azure_iot_adu_agent_buffer_size + file -> file_name_length > NX_AZURE_IOT_ADU_AGENT_BUFFER_SIZE) + { + return(NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE); + } + file_entry -> file_name = adu_agent_ptr -> nx_azure_iot_adu_agent_buffer + adu_agent_ptr -> nx_azure_iot_adu_agent_buffer_size; + memcpy(file_entry -> file_name, file -> file_name, file -> file_name_length); /* Use case of memcpy is verified. */ + file_entry -> file_name_length = file -> file_name_length; + + /* Update buffer size. */ + adu_agent_ptr -> nx_azure_iot_adu_agent_buffer_size += file -> file_name_length; + + /* Copy file sha256 to manifest content buffer as it will not be overwritten. */ + if (adu_agent_ptr -> nx_azure_iot_adu_agent_buffer_size + file -> file_sha256_length > NX_AZURE_IOT_ADU_AGENT_BUFFER_SIZE) + { + return(NX_AZURE_IOT_INSUFFICIENT_BUFFER_SPACE); + } + file_entry -> file_sha256 = adu_agent_ptr -> nx_azure_iot_adu_agent_buffer + adu_agent_ptr -> nx_azure_iot_adu_agent_buffer_size; + memcpy(file_entry -> file_sha256, file -> file_sha256, file -> file_sha256_length); /* Use case of memcpy is verified. */ + file_entry -> file_sha256_length = file -> file_sha256_length; + + /* Update buffer size. */ + adu_agent_ptr -> nx_azure_iot_adu_agent_buffer_size += file -> file_sha256_length; + + /* Update the step file. */ + step -> file = file_entry; + + return(NX_AZURE_IOT_SUCCESS); +} +#endif /* (NX_AZURE_IOT_ADU_AGENT_PROXY_UPDATE_COUNT >= 2) */ + static UINT nx_azure_iot_adu_agent_file_find(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_CONTENT *manifest_content, UCHAR *file_id, UINT file_id_length, @@ -1813,7 +1955,11 @@ UINT i; (!memcmp(file_id, adu_agent_ptr -> nx_azure_iot_adu_agent_file_urls.file_urls[i].file_id, file_id_length))) { - /* Find the file url. */ + /* Update the file id pointer as the proxy manifest may be re-used for multiple proxy updates. */ + (*file) -> file_id = adu_agent_ptr -> nx_azure_iot_adu_agent_file_urls.file_urls[i].file_id; + (*file) -> file_id_length = adu_agent_ptr -> nx_azure_iot_adu_agent_file_urls.file_urls[i].file_id_length; + + /* Set the file url. */ (*file) -> file_url = adu_agent_ptr -> nx_azure_iot_adu_agent_file_urls.file_urls[i].file_url; (*file) -> file_url_length = adu_agent_ptr -> nx_azure_iot_adu_agent_file_urls.file_urls[i].file_url_length; break; @@ -1969,6 +2115,8 @@ NX_AZURE_IOT_ADU_AGENT_DRIVER driver_request; /* Send the preprocess request to the driver. */ driver_request.nx_azure_iot_adu_agent_driver_command = NX_AZURE_IOT_ADU_AGENT_DRIVER_PREPROCESS; driver_request.nx_azure_iot_adu_agent_driver_firmware_size = file -> file_size_in_bytes; + driver_request.nx_azure_iot_adu_agent_driver_firmware_sha256 = file -> file_sha256; + driver_request.nx_azure_iot_adu_agent_driver_firmware_sha256_length = file -> file_sha256_length; driver_request.nx_azure_iot_adu_agent_driver_status = NX_AZURE_IOT_SUCCESS; (downloader_ptr -> driver_entry)(&driver_request); @@ -2269,21 +2417,47 @@ NX_AZURE_IOT_ADU_AGENT_WORKFLOW *workflow = &(adu_agent_ptr -> nx_azure_iot_adu_ file_buffer_ptr, file_buffer_size); /* Get file url. */ - if (nx_azure_iot_json_reader_next_token(json_reader_ptr) || - nx_azure_iot_json_reader_token_string_get(json_reader_ptr, - file_buffer_ptr, - file_buffer_size, - &(file_urls -> file_urls[file_urls -> file_urls_count].file_url_length))) + if (nx_azure_iot_json_reader_next_token(json_reader_ptr)) { return(NX_NOT_SUCCESSFUL); } - /* Set file url pointer and update the buffer size. */ - NX_AZURE_IOT_ADU_AGENT_PTR_UPDATE(file_urls -> file_urls[file_urls -> file_urls_count].file_url, - file_urls -> file_urls[file_urls -> file_urls_count].file_url_length, - file_buffer_ptr, file_buffer_size); + /* Check the token type as null file url may be received. */ + switch (nx_azure_iot_json_reader_token_type(json_reader_ptr)) + { + case AZ_JSON_TOKEN_STRING: + { + if (nx_azure_iot_json_reader_token_string_get(json_reader_ptr, + file_buffer_ptr, + file_buffer_size, + &(file_urls -> file_urls[file_urls -> file_urls_count].file_url_length))) + { + return(NX_NOT_SUCCESSFUL); + } - file_urls -> file_urls_count++; + /* Set file url pointer and update the buffer size. */ + NX_AZURE_IOT_ADU_AGENT_PTR_UPDATE(file_urls -> file_urls[file_urls -> file_urls_count].file_url, + file_urls -> file_urls[file_urls -> file_urls_count].file_url_length, + file_buffer_ptr, file_buffer_size); + + file_urls -> file_urls_count++; + + break; + } + + case AZ_JSON_TOKEN_NULL: + { + + /* "null" file url, reset the buffer. */ + file_buffer_ptr -= file_urls -> file_urls[file_urls -> file_urls_count].file_id_length; + file_buffer_size += file_urls -> file_urls[file_urls -> file_urls_count].file_id_length; + break; + } + default: + { + return(NX_NOT_SUCCESSFUL); + } + } } else { @@ -2320,11 +2494,11 @@ static UINT nx_azure_iot_adu_agent_service_update_manifest_process(NX_AZURE_IOT_ UINT update_manifest_size, NX_AZURE_IOT_ADU_AGENT_UPDATE_MANIFEST_CONTENT *update_manifest_content, UCHAR *update_manifest_content_buffer, - UINT update_manifest_content_buffer_size) + UINT *update_manifest_content_buffer_size) { UCHAR *buffer_ptr = update_manifest_content_buffer; -UINT buffer_size = update_manifest_content_buffer_size; +UINT buffer_size = *update_manifest_content_buffer_size; UINT i = 0; NX_AZURE_IOT_JSON_READER json_reader; NX_AZURE_IOT_ADU_AGENT_COMPATIBILITY *compatibility = &(update_manifest_content -> compatibility); @@ -2953,6 +3127,8 @@ NX_AZURE_IOT_ADU_AGENT_COMPATIBILITY *compatibility = &(update_manifest_content } } + /* Set the real content size. */ + *update_manifest_content_buffer_size -= buffer_size; return(NX_AZURE_IOT_SUCCESS); } diff --git a/addons/azure_iot/nx_azure_iot_adu_agent.h b/addons/azure_iot/nx_azure_iot_adu_agent.h index 7137b4b8..9c7bb562 100644 --- a/addons/azure_iot/nx_azure_iot_adu_agent.h +++ b/addons/azure_iot/nx_azure_iot_adu_agent.h @@ -39,6 +39,12 @@ extern "C" { #define NX_AZURE_IOT_ADU_AGENT_PROXY_UPDATE_COUNT 0 #endif /* NX_AZURE_IOT_ADU_AGENT_PROXY_UPDATE_COUNT */ +/* For multiple updates. By default ADU agent stops processing next step (update) if there is an error. + To let agent continue all steps (updates), define NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP. */ +/* +#define NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP +*/ + /* Define the ADU agent component name. */ #define NX_AZURE_IOT_ADU_AGENT_COMPONENT_NAME "deviceUpdate" @@ -136,6 +142,9 @@ extern "C" { #define NX_AZURE_IOT_ADU_AGENT_UPDATE_RECEIVED 0 #define NX_AZURE_IOT_ADU_AGENT_UPDATE_DOWNLOADED 1 #define NX_AZURE_IOT_ADU_AGENT_UPDATE_INSTALLED 2 +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP +#define NX_AZURE_IOT_ADU_AGENT_UPDATE_PARTIAL_INSTALLED 3 +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ #define NX_AZURE_IOT_ADU_AGENT_UPDATE_FAILED 255 /* FIXME: status codes should be defined in iothub client. */ @@ -315,9 +324,15 @@ typedef struct NX_AZURE_IOT_ADU_AGENT_DRIVER_STRUCT /* Define the driver return status. */ UINT nx_azure_iot_adu_agent_driver_status; - /* Define the firmware size for the driver to preprocess. */ + /* Installed criteria for the driver to check update. */ + const UCHAR *nx_azure_iot_adu_agent_driver_installed_criteria; + UINT nx_azure_iot_adu_agent_driver_installed_criteria_length; + + /* Define the firmware size and integrity for the driver to preprocess. */ UINT nx_azure_iot_adu_agent_driver_firmware_size; - + const UCHAR *nx_azure_iot_adu_agent_driver_firmware_sha256; + UINT nx_azure_iot_adu_agent_driver_firmware_sha256_length; + /* Define the firmware data for the driver to write. */ UINT nx_azure_iot_adu_agent_driver_firmware_data_offset; UCHAR *nx_azure_iot_adu_agent_driver_firmware_data_ptr; @@ -326,10 +341,6 @@ typedef struct NX_AZURE_IOT_ADU_AGENT_DRIVER_STRUCT /* Define the return pointer for raw driver command requests. */ ULONG *nx_azure_iot_adu_agent_driver_return_ptr; - /* Installed criteria. */ - const UCHAR *nx_azure_iot_adu_agent_driver_installed_criteria; - UINT nx_azure_iot_adu_agent_driver_installed_criteria_length; - } NX_AZURE_IOT_ADU_AGENT_DRIVER; /** diff --git a/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_adu/sample_azure_iot_embedded_sdk_adu.c b/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_adu/sample_azure_iot_embedded_sdk_adu.c index 37ffe06c..0f872542 100644 --- a/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_adu/sample_azure_iot_embedded_sdk_adu.c +++ b/addons/azure_iot/samples/sample_azure_iot_embedded_sdk_adu/sample_azure_iot_embedded_sdk_adu.c @@ -66,7 +66,11 @@ static void adu_agent_update_notify(NX_AZURE_IOT_ADU_AGENT *adu_agent_ptr, /* Start to download and install update immediately for testing. */ nx_azure_iot_adu_agent_update_download_and_install(adu_agent_ptr); } - else if(update_state == NX_AZURE_IOT_ADU_AGENT_UPDATE_INSTALLED) + else if ((update_state == NX_AZURE_IOT_ADU_AGENT_UPDATE_INSTALLED) +#ifdef NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP + || (update_state == NX_AZURE_IOT_ADU_AGENT_UPDATE_PARTIAL_INSTALLED) +#endif /* NX_AZURE_IOT_ADU_AGENT_SKIP_FAILED_STEP */ + ) { /* Start to apply update immediately for testing. */ diff --git a/addons/mdns/nxd_mdns.h b/addons/mdns/nxd_mdns.h index 0d57abce..de1fb586 100644 --- a/addons/mdns/nxd_mdns.h +++ b/addons/mdns/nxd_mdns.h @@ -25,7 +25,7 @@ /* APPLICATION INTERFACE DEFINITION RELEASE */ /* */ /* nxd_mdns.h PORTABLE C */ -/* 6.1.11 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -52,6 +52,9 @@ /* 04-25-2022 Yuxin Zhou Modified comment(s), */ /* fixed the issue of timer, */ /* resulting in version 6.1.11 */ +/* xx-xx-xxxx Bo Chen Modified comment(s), and */ +/* corrected the symbols check,*/ +/* resulting in version 6.x */ /* */ /**************************************************************************/ @@ -130,9 +133,9 @@ extern "C" { #error "mDNS IPv6 is not supported if IPv6 is not enabled." #endif /* FEATURE_NX_IPV6 */ -#ifndef NX_IPV6_MULTICAST_ENABLE +#ifndef NX_ENABLE_IPV6_MULTICAST #error "mDNS IPv6 is not supported if IPv6 multicast is not enabled." -#endif /* NX_IPV6_MULTICAST_ENABLE */ +#endif /* NX_ENABLE_IPV6_MULTICAST */ #ifndef NX_MDNS_DISABLE_SERVER #ifndef NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY diff --git a/addons/mqtt/nxd_mqtt_client.c b/addons/mqtt/nxd_mqtt_client.c index 015e6750..b05124fa 100644 --- a/addons/mqtt/nxd_mqtt_client.c +++ b/addons/mqtt/nxd_mqtt_client.c @@ -52,7 +52,6 @@ static UINT _nxd_mqtt_client_create_internal(NXD_MQTT_CLIENT *client_ptr, CHAR * CHAR *client_id, UINT client_id_length, NX_IP *ip_ptr, NX_PACKET_POOL *pool_ptr, VOID *stack_ptr, ULONG stack_size, UINT mqtt_thread_priority); -static UINT _nxd_mqtt_packet_allocate(NXD_MQTT_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option); static UINT _nxd_mqtt_packet_send(NXD_MQTT_CLIENT *client_ptr, NX_PACKET *packet_ptr, UINT wait_option); static UINT _nxd_mqtt_packet_receive(NXD_MQTT_CLIENT *client_ptr, NX_PACKET **packet_ptr, UINT wait_option); static UINT _nxd_mqtt_copy_transmit_packet(NXD_MQTT_CLIENT *client_ptr, NX_PACKET *packet_ptr, NX_PACKET **new_packet_ptr, @@ -248,7 +247,7 @@ ULONG bytes_copied; /* FUNCTION RELEASE */ /* */ /* _nxd_mqtt_client_sub_unsub PORTABLE C */ -/* 6.2.0 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -280,7 +279,7 @@ ULONG bytes_copied; /* CALLS */ /* */ /* tx_mutex_get */ -/* _nxd_mqtt_packet_allocate */ +/* _nxd_mqtt_client_packet_allocate */ /* _nxd_mqtt_client_set_fixed_header */ /* _nxd_mqtt_client_append_message */ /* tx_mutex_put */ @@ -309,6 +308,9 @@ ULONG bytes_copied; /* 10-31-2022 Bo Chen Modified comment(s), improved */ /* the logic of sending packet,*/ /* resulting in version 6.2.0 */ +/* xx-xx-xxxx Haiqing Zhao Modified comment(s), improved */ +/* internal logic, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ UINT _nxd_mqtt_client_sub_unsub(NXD_MQTT_CLIENT *client_ptr, UINT op, @@ -339,7 +341,7 @@ UCHAR temp_data[2]; return(NXD_MQTT_NOT_CONNECTED); } - status = _nxd_mqtt_packet_allocate(client_ptr, &packet_ptr, NX_WAIT_FOREVER); + status = _nxd_mqtt_client_packet_allocate(client_ptr, &packet_ptr, NX_WAIT_FOREVER); if (status) { tx_mutex_put(client_ptr -> nxd_mqtt_client_mutex_ptr); @@ -486,8 +488,8 @@ UCHAR temp_data[2]; /* */ /* FUNCTION RELEASE */ /* */ -/* _nxd_mqtt_packet_allocate PORTABLE C */ -/* 6.2.0 */ +/* _nxd_mqtt_client_packet_allocate PORTABLE C */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -540,9 +542,12 @@ UCHAR temp_data[2]; /* 10-31-2022 Bo Chen Modified comment(s), supported*/ /* mqtt over websocket, */ /* resulting in version 6.2.0 */ +/* xx-xx-xxxx Haiqing Zhao Modified comment(s), improved */ +/* internal logic, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ -static UINT _nxd_mqtt_packet_allocate(NXD_MQTT_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option) +UINT _nxd_mqtt_client_packet_allocate(NXD_MQTT_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option) { UINT status = NXD_MQTT_SUCCESS; @@ -1346,7 +1351,7 @@ ULONG bytes_copied; /* FUNCTION RELEASE */ /* */ /* _nxd_mqtt_process_publish PORTABLE C */ -/* 6.2.0 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -1370,7 +1375,7 @@ ULONG bytes_copied; /* */ /* [receive_notify] User supplied receive */ /* callback function */ -/* _nxd_mqtt_packet_allocate */ +/* _nxd_mqtt_client_packet_allocate */ /* _nxd_mqtt_packet_send */ /* nx_packet_release */ /* nx_secure_tls_session_send */ @@ -1392,6 +1397,9 @@ ULONG bytes_copied; /* 10-31-2022 Bo Chen Modified comment(s), improved */ /* the logic of sending packet,*/ /* resulting in version 6.2.0 */ +/* xx-xx-xxxx Haiqing Zhao Modified comment(s), improved */ +/* internal logic, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ static UINT _nxd_mqtt_process_publish(NXD_MQTT_CLIENT *client_ptr, NX_PACKET *packet_ptr) @@ -1527,7 +1535,7 @@ ULONG bytes_copied; /* Send out proper ACKs for QoS 1 and 2 messages. */ /* Allocate a new packet so we can send out a response. */ - status = _nxd_mqtt_packet_allocate(client_ptr, &packet_ptr, NX_WAIT_FOREVER); + status = _nxd_mqtt_client_packet_allocate(client_ptr, &packet_ptr, NX_WAIT_FOREVER); if (status) { /* Packet allocation fails. */ @@ -1603,7 +1611,7 @@ ULONG bytes_copied; /* FUNCTION RELEASE */ /* */ /* _nxd_mqtt_process_publish_response PORTABLE C */ -/* 6.2.0 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -1628,6 +1636,7 @@ ULONG bytes_copied; /* callback function */ /* _nxd_mqtt_release_transmit_packet */ /* _nxd_mqtt_packet_send */ +/* _nxd_mqtt_client_packet_allocate */ /* */ /* */ /* CALLED BY */ @@ -1645,6 +1654,9 @@ ULONG bytes_copied; /* 10-31-2022 Bo Chen Modified comment(s), improved */ /* the logic of sending packet,*/ /* resulting in version 6.2.0 */ +/* xx-xx-xxxx Haiqing Zhao Modified comment(s), improved */ +/* internal logic, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ static UINT _nxd_mqtt_process_publish_response(NXD_MQTT_CLIENT *client_ptr, NX_PACKET *packet_ptr) @@ -1720,7 +1732,7 @@ USHORT transmit_packet_id; /* Send PUBCOMP */ /* Allocate a packet to send the response. */ - ret = _nxd_mqtt_packet_allocate(client_ptr, &response_packet, NX_WAIT_FOREVER); + ret = _nxd_mqtt_client_packet_allocate(client_ptr, &response_packet, NX_WAIT_FOREVER); if (ret) { return(1); @@ -3865,7 +3877,7 @@ UCHAR fixed_header; /* FUNCTION RELEASE */ /* */ /* _nxd_mqtt_client_connect PORTABLE C */ -/* 6.2.0 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -3902,7 +3914,6 @@ UCHAR fixed_header; /* nx_secure_tls_session_start */ /* nx_secure_tls_session_send */ /* nx_secure_tls_session_receive */ -/* _nxd_mqtt_packet_allocate */ /* _nxd_mqtt_client_set_fixed_header */ /* _nxd_mqtt_client_append_message */ /* nx_tcp_socket_send */ @@ -3938,6 +3949,8 @@ UCHAR fixed_header; /* 10-31-2022 Bo Chen Modified comment(s), supported*/ /* mqtt over websocket, */ /* resulting in version 6.2.0 */ +/* xx-xx-xxxx Haiqing Zhao Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ UINT _nxd_mqtt_client_connect(NXD_MQTT_CLIENT *client_ptr, NXD_ADDRESS *server_ip, UINT server_port, @@ -4221,7 +4234,7 @@ UINT old_priority; /* FUNCTION RELEASE */ /* */ /* _nxd_mqtt_client_connect_packet_send PORTABLE C */ -/* 6.2.0 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4246,7 +4259,7 @@ UINT old_priority; /* CALLS */ /* */ /* nx_packet_release */ -/* _nxd_mqtt_packet_allocate */ +/* _nxd_mqtt_client_packet_allocate */ /* _nxd_mqtt_release_transmit_packet */ /* _nxd_mqtt_client_connection_end */ /* _nxd_mqtt_client_set_fixed_header */ @@ -4272,6 +4285,9 @@ UINT old_priority; /* 10-31-2022 Bo Chen Modified comment(s), improved */ /* the logic of sending packet,*/ /* resulting in version 6.2.0 */ +/* xx-xx-xxxx Haiqing Zhao Modified comment(s), improved */ +/* internal logic, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ UINT _nxd_mqtt_client_connect_packet_send(NXD_MQTT_CLIENT *client_ptr, ULONG wait_option) @@ -4349,7 +4365,7 @@ UINT keepalive = (client_ptr -> nxd_mqtt_keepalive/NX_IP_PERIODI return(NXD_MQTT_INTERNAL_ERROR); } - status = _nxd_mqtt_packet_allocate(client_ptr, &packet_ptr, wait_option); + status = _nxd_mqtt_client_packet_allocate(client_ptr, &packet_ptr, wait_option); if (status) { @@ -4766,7 +4782,7 @@ UINT ret = NXD_MQTT_SUCCESS; /* FUNCTION RELEASE */ /* */ /* _nxd_mqtt_client_publish PORTABLE C */ -/* 6.1.12 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4797,7 +4813,7 @@ UINT ret = NXD_MQTT_SUCCESS; /* CALLS */ /* */ /* tx_mutex_get */ -/* _nxd_mqtt_packet_allocate */ +/* _nxd_mqtt_client_packet_allocate */ /* _nxd_mqtt_client_set_fixed_header */ /* _nxd_mqtt_client_append_message */ /* tx_mutex_put */ @@ -4818,6 +4834,9 @@ UINT ret = NXD_MQTT_SUCCESS; /* 07-29-2022 Spencer McDonough Modified comment(s), */ /* improved internal logic, */ /* resulting in version 6.1.12 */ +/* xx-xx-xxxx Haiqing Zhao Modified comment(s), improved */ +/* internal logic, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ UINT _nxd_mqtt_client_publish(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, UINT topic_name_length, @@ -4843,7 +4862,7 @@ UINT ret = NXD_MQTT_SUCCESS; return(NXD_MQTT_NOT_CONNECTED); } - status = _nxd_mqtt_packet_allocate(client_ptr, &packet_ptr, wait_option); + status = _nxd_mqtt_client_packet_allocate(client_ptr, &packet_ptr, wait_option); if (status != NXD_MQTT_SUCCESS) { @@ -5096,7 +5115,7 @@ UINT _nxd_mqtt_client_unsubscribe(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, /* FUNCTION RELEASE */ /* */ /* _nxd_mqtt_send_simple_message PORTABLE C */ -/* 6.2.0 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -5120,7 +5139,7 @@ UINT _nxd_mqtt_client_unsubscribe(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, /* CALLS */ /* */ /* tx_mutex_get */ -/* _nxd_mqtt_packet_allocate */ +/* _nxd_mqtt_client_packet_allocate */ /* tx_mutex_put */ /* _nxd_mqtt_packet_send */ /* nx_packet_release */ @@ -5143,6 +5162,9 @@ UINT _nxd_mqtt_client_unsubscribe(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, /* 10-31-2022 Bo Chen Modified comment(s), improved */ /* the logic of sending packet,*/ /* resulting in version 6.2.0 */ +/* xx-xx-xxxx Haiqing Zhao Modified comment(s), improved */ +/* internal logic, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ static UINT _nxd_mqtt_send_simple_message(NXD_MQTT_CLIENT *client_ptr, UCHAR header_value) @@ -5153,7 +5175,7 @@ UINT status; UINT status_mutex; UCHAR *byte; - status = _nxd_mqtt_packet_allocate(client_ptr, &packet_ptr, NX_WAIT_FOREVER); + status = _nxd_mqtt_client_packet_allocate(client_ptr, &packet_ptr, NX_WAIT_FOREVER); if (status) { return(NXD_MQTT_INTERNAL_ERROR); diff --git a/addons/mqtt/nxd_mqtt_client.h b/addons/mqtt/nxd_mqtt_client.h index 9327a779..78c9e416 100644 --- a/addons/mqtt/nxd_mqtt_client.h +++ b/addons/mqtt/nxd_mqtt_client.h @@ -26,7 +26,7 @@ /* APPLICATION INTERFACE DEFINITION RELEASE */ /* */ /* nxd_mqtt_client.h PORTABLE C */ -/* 6.2.0 */ +/* 6.x */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -58,6 +58,10 @@ /* 10-31-2022 Bo Chen Modified comment(s), supported*/ /* mqtt over websocket, */ /* resulting in version 6.2.0 */ +/* xx-xx-xxxx Haiqing Zhao Modified comment(s), added */ +/* the function prototype for */ +/* packet allocation, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ @@ -491,6 +495,7 @@ UINT _nxd_mqtt_client_login_set(NXD_MQTT_CLIENT *client_ptr, CHAR *username, UINT username_length, CHAR *password, UINT password_length); UINT _nxd_mqtt_client_message_get(NXD_MQTT_CLIENT *client_ptr, UCHAR *topic_buffer, UINT topic_buffer_size, UINT *actual_topic_length, UCHAR *message_buffer, UINT message_buffer_size, UINT *actual_message_length); +UINT _nxd_mqtt_client_packet_allocate(NXD_MQTT_CLIENT *client_ptr, NX_PACKET **packet_ptr, ULONG wait_option); UINT _nxd_mqtt_client_publish_packet_send(NXD_MQTT_CLIENT *client_ptr, NX_PACKET *packet_ptr, USHORT packet_id, UINT QoS, ULONG wait_option); UINT _nxd_mqtt_client_publish(NXD_MQTT_CLIENT *client_ptr, CHAR *topic_name, UINT topic_name_length, diff --git a/crypto_libraries/src/nx_crypto_3des.c b/crypto_libraries/src/nx_crypto_3des.c index 8411a555..111a59f2 100644 --- a/crypto_libraries/src/nx_crypto_3des.c +++ b/crypto_libraries/src/nx_crypto_3des.c @@ -223,7 +223,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_3des_decrypt(NX_CRYPTO_3DES *context, UCHAR sour /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_3des_init PORTABLE C */ -/* 6.1.11 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -265,6 +265,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_3des_decrypt(NX_CRYPTO_3DES *context, UCHAR sour /* warning supression for */ /* obsolete DES/3DES, */ /* resulting in version 6.1.11 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_3des_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -285,7 +287,7 @@ NX_CRYPTO_3DES *triple_des_context_ptr; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -374,7 +376,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_3des_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_3des_operation PORTABLE C */ -/* 6.1.11 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -425,6 +427,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_3des_cleanup(VOID *crypto_metadata) /* warning supression for */ /* obsolete DES/3DES, */ /* resulting in version 6.1.11 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_3des_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -465,7 +469,7 @@ NX_CRYPTO_3DES *context; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_aes.c b/crypto_libraries/src/nx_crypto_aes.c index d5103fac..bf7d5234 100644 --- a/crypto_libraries/src/nx_crypto_aes.c +++ b/crypto_libraries/src/nx_crypto_aes.c @@ -1702,7 +1702,7 @@ UINT i; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_aes_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -1739,6 +1739,8 @@ UINT i; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -1758,7 +1760,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_init(struct NX_CRYPTO_METHOD_STRUCT * return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -1846,7 +1848,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_aes_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -1896,6 +1898,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -1917,7 +1921,7 @@ UINT status; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); @@ -1994,7 +1998,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_aes_cbc_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -2041,6 +2045,8 @@ UINT status; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_cbc_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -2071,7 +2077,7 @@ UINT status; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); @@ -2167,7 +2173,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_aes_ccm_operation PORTABLE C */ -/* 6.2.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -2218,6 +2224,8 @@ UINT status; /* 03-08-2023 Tiejun Zhou Modified comment(s), and */ /* fixed compiler warnings, */ /* resulting in version 6.2.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_ccm_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -2248,7 +2256,7 @@ UINT status; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); @@ -2467,7 +2475,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_aes_gcm_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -2515,6 +2523,8 @@ UINT status; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_gcm_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -2547,7 +2557,7 @@ UINT status; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); @@ -2763,7 +2773,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_aes_ctr_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -2810,6 +2820,8 @@ UINT status; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_ctr_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -2839,7 +2851,7 @@ UINT status; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); @@ -2913,7 +2925,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_aes_xcbc_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -2960,6 +2972,8 @@ UINT status; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_aes_xcbc_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -2990,7 +3004,7 @@ UINT status; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (key == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_des.c b/crypto_libraries/src/nx_crypto_des.c index 2b0f9f7c..d6fd84fe 100644 --- a/crypto_libraries/src/nx_crypto_des.c +++ b/crypto_libraries/src/nx_crypto_des.c @@ -574,7 +574,7 @@ UINT round; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_des_init PORTABLE C */ -/* 6.1.11 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -616,6 +616,8 @@ UINT round; /* warning supression for */ /* obsolete DES/3DES, */ /* resulting in version 6.1.11 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_des_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -640,7 +642,7 @@ NX_CRYPTO_DES *des_context_ptr; return(NX_CRYPTO_SIZE_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -717,7 +719,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_des_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_des_operation PORTABLE C */ -/* 6.1.11 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -768,6 +770,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_des_cleanup(VOID *crypto_metadata) /* warning supression for */ /* obsolete DES/3DES, */ /* resulting in version 6.1.11 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_des_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -808,7 +812,7 @@ NX_CRYPTO_DES *context; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_drbg.c b/crypto_libraries/src/nx_crypto_drbg.c index aa690ae1..94f24342 100644 --- a/crypto_libraries/src/nx_crypto_drbg.c +++ b/crypto_libraries/src/nx_crypto_drbg.c @@ -921,7 +921,7 @@ VOID *handler = NX_CRYPTO_NULL; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_drbg_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -959,6 +959,8 @@ VOID *handler = NX_CRYPTO_NULL; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_drbg_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -979,7 +981,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_drbg_init(struct NX_CRYPTO_METHOD_STRUCT return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -1057,7 +1059,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_drbg_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_drbg_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -1101,6 +1103,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_drbg_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_drbg_operation(UINT op, @@ -1124,7 +1128,7 @@ UINT status = NX_CRYPTO_SUCCESS; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_ecdh.c b/crypto_libraries/src/nx_crypto_ecdh.c index 36826cde..a9fde0d0 100644 --- a/crypto_libraries/src/nx_crypto_ecdh.c +++ b/crypto_libraries/src/nx_crypto_ecdh.c @@ -447,7 +447,7 @@ NX_CRYPTO_EC_POINT public_key, shared_secret; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_ecdh_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -485,6 +485,8 @@ NX_CRYPTO_EC_POINT public_key, shared_secret; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdh_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -505,7 +507,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdh_init(struct NX_CRYPTO_METHOD_STRUCT return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -583,7 +585,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdh_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_ecdh_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -629,6 +631,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdh_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdh_operation(UINT op, @@ -655,7 +659,7 @@ NX_CRYPTO_EXTENDED_OUTPUT NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_ecdsa.c b/crypto_libraries/src/nx_crypto_ecdsa.c index ef4843d1..f1eceb16 100644 --- a/crypto_libraries/src/nx_crypto_ecdsa.c +++ b/crypto_libraries/src/nx_crypto_ecdsa.c @@ -481,7 +481,7 @@ UINT buffer_size = curve -> nx_crypto_ec_n.nx_crypto_huge_buffe /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_ecdsa_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -519,6 +519,8 @@ UINT buffer_size = curve -> nx_crypto_ec_n.nx_crypto_huge_buffe /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdsa_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -540,7 +542,7 @@ NX_CRYPTO_ECDSA *ecdsa; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -624,7 +626,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdsa_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_ecdsa_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -670,6 +672,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdsa_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecdsa_operation(UINT op, @@ -698,7 +702,7 @@ UCHAR *hash_output = NX_CRYPTO_NULL; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_ecjpake.c b/crypto_libraries/src/nx_crypto_ecjpake.c index 26bcf767..d1e4754c 100644 --- a/crypto_libraries/src/nx_crypto_ecjpake.c +++ b/crypto_libraries/src/nx_crypto_ecjpake.c @@ -1594,7 +1594,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_ecjpake_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -1631,6 +1631,8 @@ UINT status; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecjpake_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -1657,7 +1659,7 @@ UINT i; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -1751,7 +1753,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecjpake_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_ecjpake_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -1802,6 +1804,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecjpake_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_ecjpake_operation(UINT op, @@ -1829,7 +1833,7 @@ UINT status = NX_CRYPTO_SUCCESS; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_hkdf.c b/crypto_libraries/src/nx_crypto_hkdf.c index 254bbff5..18ed8e7e 100644 --- a/crypto_libraries/src/nx_crypto_hkdf.c +++ b/crypto_libraries/src/nx_crypto_hkdf.c @@ -28,7 +28,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hkdf_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -67,6 +67,8 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hkdf_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -87,7 +89,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hkdf_init(struct NX_CRYPTO_METHOD_STRUCT return(NX_CRYPTO_POINTER_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_METADATA_UNALIGNED); @@ -193,7 +195,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hkdf_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -242,6 +244,8 @@ UINT status; /* buffer length verification, */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hkdf_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -269,7 +273,7 @@ UINT status; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_POINTER_ERROR); diff --git a/crypto_libraries/src/nx_crypto_hmac.c b/crypto_libraries/src/nx_crypto_hmac.c index 2a7d6aab..8b694e6e 100644 --- a/crypto_libraries/src/nx_crypto_hmac.c +++ b/crypto_libraries/src/nx_crypto_hmac.c @@ -629,7 +629,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -668,6 +668,8 @@ UINT status; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -688,7 +690,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_init(struct NX_CRYPTO_METHOD_STRUCT return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -776,7 +778,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* */ /* AUTHOR */ /* */ @@ -821,6 +823,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -848,7 +852,7 @@ UINT status; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_hmac_md5.c b/crypto_libraries/src/nx_crypto_hmac_md5.c index 85ce0d7d..fdb4120c 100644 --- a/crypto_libraries/src/nx_crypto_hmac_md5.c +++ b/crypto_libraries/src/nx_crypto_hmac_md5.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_md5_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -68,6 +68,8 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_md5_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -87,7 +89,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_md5_init(struct NX_CRYPTO_METHOD_ST return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -165,7 +167,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_md5_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_md5_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -215,6 +217,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_md5_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_md5_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -242,7 +246,7 @@ NX_CRYPTO_HMAC *hmac_metadata; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_hmac_sha1.c b/crypto_libraries/src/nx_crypto_hmac_sha1.c index b7a91f2d..7d7617b6 100644 --- a/crypto_libraries/src/nx_crypto_hmac_sha1.c +++ b/crypto_libraries/src/nx_crypto_hmac_sha1.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_sha1_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -68,6 +68,8 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha1_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -87,7 +89,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha1_init(struct NX_CRYPTO_METHOD_S return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -165,7 +167,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha1_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_sha1_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -214,6 +216,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha1_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha1_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -241,7 +245,7 @@ NX_CRYPTO_HMAC *hmac_metadata; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_hmac_sha2.c b/crypto_libraries/src/nx_crypto_hmac_sha2.c index 39ec2c11..1310f99d 100644 --- a/crypto_libraries/src/nx_crypto_hmac_sha2.c +++ b/crypto_libraries/src/nx_crypto_hmac_sha2.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_sha256_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -68,6 +68,8 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha256_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -88,7 +90,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha256_init(struct NX_CRYPTO_METHOD return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -166,7 +168,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha256_cleanup(VOID *crypto_metadata /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_sha256_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -215,6 +217,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha256_cleanup(VOID *crypto_metadata /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha256_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -243,7 +247,7 @@ UINT icv_length; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_hmac_sha5.c b/crypto_libraries/src/nx_crypto_hmac_sha5.c index a0802133..eafb17fe 100644 --- a/crypto_libraries/src/nx_crypto_hmac_sha5.c +++ b/crypto_libraries/src/nx_crypto_hmac_sha5.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_sha512_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -68,6 +68,8 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha512_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -87,7 +89,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha512_init(struct NX_CRYPTO_METHOD return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -165,7 +167,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha512_cleanup(VOID *crypto_metadata /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_hmac_sha512_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -214,6 +216,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha512_cleanup(VOID *crypto_metadata /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_hmac_sha512_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -244,7 +248,7 @@ UINT icv_full_length; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_md5.c b/crypto_libraries/src/nx_crypto_md5.c index 2a80e78e..131f3abe 100644 --- a/crypto_libraries/src/nx_crypto_md5.c +++ b/crypto_libraries/src/nx_crypto_md5.c @@ -690,7 +690,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_md5_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_md5_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -740,6 +740,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_md5_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_md5_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -776,7 +778,7 @@ NX_CRYPTO_MD5 metadata; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if (crypto_metadata == NX_CRYPTO_NULL) { #ifdef NX_IPSEC_ENABLE diff --git a/crypto_libraries/src/nx_crypto_pkcs1_v1.5.c b/crypto_libraries/src/nx_crypto_pkcs1_v1.5.c index 9a545d55..41f01606 100644 --- a/crypto_libraries/src/nx_crypto_pkcs1_v1.5.c +++ b/crypto_libraries/src/nx_crypto_pkcs1_v1.5.c @@ -458,7 +458,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_pkcs1_v1_5_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -496,6 +496,8 @@ UINT status; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_pkcs1_v1_5_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -516,7 +518,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_pkcs1_v1_5_init(struct NX_CRYPTO_METHOD_ return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -593,7 +595,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_pkcs1_v1_5_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_pkcs1_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -639,6 +641,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_pkcs1_v1_5_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_pkcs1_v1_5_operation(UINT op, @@ -663,7 +667,7 @@ UINT status = NX_CRYPTO_SUCCESS; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_rsa.c b/crypto_libraries/src/nx_crypto_rsa.c index 6708f05f..2d6184ed 100644 --- a/crypto_libraries/src/nx_crypto_rsa.c +++ b/crypto_libraries/src/nx_crypto_rsa.c @@ -165,7 +165,7 @@ NX_CRYPTO_HUGE_NUMBER modulus_hn, exponent_hn, input_hn, output_hn, p_hn, q_hn; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_rsa_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -202,6 +202,8 @@ NX_CRYPTO_HUGE_NUMBER modulus_hn, exponent_hn, input_hn, output_hn, p_hn, q_hn; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_rsa_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -221,7 +223,7 @@ NX_CRYPTO_RSA *ctx; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -311,7 +313,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_rsa_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_rsa_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -357,6 +359,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_rsa_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_rsa_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -385,7 +389,7 @@ UINT return_value = NX_CRYPTO_SUCCESS; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_sha1.c b/crypto_libraries/src/nx_crypto_sha1.c index 5a89da3d..aa25f3be 100644 --- a/crypto_libraries/src/nx_crypto_sha1.c +++ b/crypto_libraries/src/nx_crypto_sha1.c @@ -667,7 +667,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha1_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_sha1_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -716,6 +716,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha1_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha1_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -753,7 +755,7 @@ NX_CRYPTO_SHA1 metadata; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if (crypto_metadata == NX_CRYPTO_NULL) { #ifdef NX_IPSEC_ENABLE diff --git a/crypto_libraries/src/nx_crypto_sha2.c b/crypto_libraries/src/nx_crypto_sha2.c index 452cd89c..21ddb622 100644 --- a/crypto_libraries/src/nx_crypto_sha2.c +++ b/crypto_libraries/src/nx_crypto_sha2.c @@ -588,7 +588,7 @@ ULONG a, b, c, d, e, f, g, h; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_sha256_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -626,6 +626,8 @@ ULONG a, b, c, d, e, f, g, h; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha256_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -646,7 +648,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha256_init(struct NX_CRYPTO_METHOD_STRU return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -724,7 +726,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha256_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_sha256_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -773,6 +775,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha256_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha256_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -806,7 +810,7 @@ NX_CRYPTO_SHA256 *ctx; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_sha5.c b/crypto_libraries/src/nx_crypto_sha5.c index 9e61acec..3bb86a71 100644 --- a/crypto_libraries/src/nx_crypto_sha5.c +++ b/crypto_libraries/src/nx_crypto_sha5.c @@ -580,7 +580,7 @@ ULONG64 a, b, c, d, e, f, g, h; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_sha512_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -618,6 +618,8 @@ ULONG64 a, b, c, d, e, f, g, h; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha512_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -638,7 +640,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha512_init(struct NX_CRYPTO_METHOD_STRU return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -716,7 +718,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha512_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_sha512_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -765,6 +767,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha512_cleanup(VOID *crypto_metadata) /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_sha512_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -799,7 +803,7 @@ NX_CRYPTO_SHA512 *ctx; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_tls_prf_1.c b/crypto_libraries/src/nx_crypto_tls_prf_1.c index 54da811e..d36f629d 100644 --- a/crypto_libraries/src/nx_crypto_tls_prf_1.c +++ b/crypto_libraries/src/nx_crypto_tls_prf_1.c @@ -28,7 +28,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_prf_1_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -65,6 +65,8 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_1_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -85,7 +87,7 @@ NX_CRYPTO_PHASH *phash; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -172,7 +174,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_1_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_prf_1_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -221,6 +223,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_1_cleanup(VOID *crypto_metadata) /* buffer length verification, */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_1_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -250,7 +254,7 @@ NX_CRYPTO_PHASH *phash; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (key == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_tls_prf_sha256.c b/crypto_libraries/src/nx_crypto_tls_prf_sha256.c index db03165a..81b308b6 100644 --- a/crypto_libraries/src/nx_crypto_tls_prf_sha256.c +++ b/crypto_libraries/src/nx_crypto_tls_prf_sha256.c @@ -28,7 +28,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_prf_sha_256_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -65,6 +65,8 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha_256_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -85,7 +87,7 @@ NX_CRYPTO_PHASH *phash; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -172,7 +174,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha_256_cleanup(VOID *crypto_metadata /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_prf_sha_256_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -221,6 +223,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha_256_cleanup(VOID *crypto_metadata /* buffer length verification, */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha_256_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -249,7 +253,7 @@ NX_CRYPTO_PHASH *phash; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (key == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_tls_prf_sha384.c b/crypto_libraries/src/nx_crypto_tls_prf_sha384.c index 2e375ac3..f6654448 100644 --- a/crypto_libraries/src/nx_crypto_tls_prf_sha384.c +++ b/crypto_libraries/src/nx_crypto_tls_prf_sha384.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_prf_sha384_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -66,6 +66,8 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha384_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -86,7 +88,7 @@ NX_CRYPTO_PHASH *phash; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -173,7 +175,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha384_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_prf_sha384_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -221,6 +223,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha384_cleanup(VOID *crypto_metadata) /* buffer length verification, */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha384_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -249,7 +253,7 @@ NX_CRYPTO_PHASH *phash; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (key == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/crypto_libraries/src/nx_crypto_tls_prf_sha512.c b/crypto_libraries/src/nx_crypto_tls_prf_sha512.c index 044db817..b47d48f4 100644 --- a/crypto_libraries/src/nx_crypto_tls_prf_sha512.c +++ b/crypto_libraries/src/nx_crypto_tls_prf_sha512.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_prf_sha512_init PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -66,6 +66,8 @@ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha512_init(struct NX_CRYPTO_METHOD_STRUCT *method, @@ -86,7 +88,7 @@ NX_CRYPTO_PHASH *phash; return(NX_CRYPTO_PTR_ERROR); } - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((((ULONG)crypto_metadata) & 0x3) != 0) { return(NX_CRYPTO_PTR_ERROR); @@ -173,7 +175,7 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha512_cleanup(VOID *crypto_metadata) /* FUNCTION RELEASE */ /* */ /* _nx_crypto_method_prf_sha512_operation PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -221,6 +223,8 @@ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha512_cleanup(VOID *crypto_metadata) /* buffer length verification, */ /* verified memcpy use cases, */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP UINT _nx_crypto_method_prf_sha512_operation(UINT op, /* Encrypt, Decrypt, Authenticate */ @@ -249,7 +253,7 @@ NX_CRYPTO_PHASH *phash; NX_CRYPTO_STATE_CHECK - /* Verify the metadata addrsss is 4-byte aligned. */ + /* Verify the metadata address is 4-byte aligned. */ if((method == NX_CRYPTO_NULL) || (key == NX_CRYPTO_NULL) || (crypto_metadata == NX_CRYPTO_NULL) || ((((ULONG)crypto_metadata) & 0x3) != 0)) { return(NX_CRYPTO_PTR_ERROR); diff --git a/nx_secure/src/nxe_secure_tls_session_send.c b/nx_secure/src/nxe_secure_tls_session_send.c index 63eba468..7609b5fb 100644 --- a/nx_secure/src/nxe_secure_tls_session_send.c +++ b/nx_secure/src/nxe_secure_tls_session_send.c @@ -36,7 +36,7 @@ NX_SECURE_CALLER_CHECKING_EXTERNS /* FUNCTION RELEASE */ /* */ /* _nxe_secure_tls_session_send PORTABLE C */ -/* 6.1 */ +/* 6.x */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -71,6 +71,9 @@ NX_SECURE_CALLER_CHECKING_EXTERNS /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 09-30-2020 Timothy Stapko Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Yanwu Cai Modified comment(s), added */ +/* record length checking, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ UINT _nxe_secure_tls_session_send(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *packet_ptr, @@ -94,11 +97,17 @@ UINT status; } /* Make sure the session is initialized. */ - if(tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID) + if (tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID) { return(NX_SECURE_TLS_SESSION_UNINITIALIZED); } + /* Check the plaintext length as the fragmentation is not supported currently. */ + if (packet_ptr -> nx_packet_length > NX_SECURE_TLS_MAX_PLAINTEXT_LENGTH) + { + return(NX_SECURE_TLS_RECORD_OVERFLOW); + } + /* Check for appropriate caller. */ NX_THREADS_ONLY_CALLER_CHECKING diff --git a/samples/demo_netx_secure_tls.c b/samples/demo_netx_secure_tls.c new file mode 100644 index 00000000..4f002ba9 --- /dev/null +++ b/samples/demo_netx_secure_tls.c @@ -0,0 +1,767 @@ +/* This is a small demo of the NetX Secure TLS API running on a + high-performance NetX TCP/IP stack. */ +/* This demo works for IPv4 only */ + +#include "tx_api.h" +#include "nx_api.h" + +#ifndef NX_DISABLE_IPV4 + +#include "nx_secure_tls_api.h" +#include "nx_secure_x509.h" + +#define DEMO_STACK_SIZE 4096 + +/* Replace the 'ram' driver with your Ethernet driver. */ +VOID _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req); + +/* Define packet pool for the demonstration. */ +#define NX_PACKET_SIZE (1536 + sizeof(NX_PACKET)) + +/* Set up the TLS client global variables. */ + +static TX_THREAD client_thread; +static NX_PACKET_POOL client_pool; +static NX_IP client_ip; +static NX_TCP_SOCKET client_tcp_socket; +static NX_SECURE_TLS_SESSION client_tls_session; +static NX_SECURE_X509_CERT trusted_certificate; +static UINT error_counter; + +/* Set up the TLS server global variables */ + +static TX_THREAD server_thread; +static NX_PACKET_POOL server_pool; +static NX_IP server_ip; +static NX_TCP_SOCKET server_tcp_socket; +static NX_SECURE_TLS_SESSION server_tls_session; + + +static void tls_client_thread_entry(ULONG thread_input); +static void tls_server_thread_entry(ULONG thread_input); + + +/* Define some demo certificates. First, the server/device certificate. */ +static unsigned char test_device_cert_der[] = { + 0x30, 0x82, 0x03, 0xd2, 0x30, 0x82, 0x02, 0xba, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x01, 0x01, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, + 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x7a, 0x31, 0x0b, 0x30, + 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0b, + 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x43, 0x41, 0x31, + 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x09, 0x53, 0x61, + 0x6e, 0x20, 0x44, 0x69, 0x65, 0x67, 0x6f, 0x31, 0x16, 0x30, 0x14, 0x06, + 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x0d, 0x45, 0x78, 0x70, 0x72, 0x65, 0x73, + 0x73, 0x20, 0x4c, 0x6f, 0x67, 0x69, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, + 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x4e, 0x65, 0x74, 0x58, 0x20, 0x53, + 0x65, 0x63, 0x75, 0x72, 0x65, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, + 0x04, 0x03, 0x0c, 0x13, 0x4e, 0x65, 0x74, 0x58, 0x20, 0x53, 0x65, 0x63, + 0x75, 0x72, 0x65, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, + 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x31, 0x31, 0x31, 0x31, 0x31, 0x39, 0x35, + 0x31, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x32, 0x36, 0x31, 0x31, 0x30, 0x39, + 0x31, 0x39, 0x35, 0x31, 0x30, 0x30, 0x5a, 0x30, 0x62, 0x31, 0x0b, 0x30, + 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0b, + 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x02, 0x43, 0x41, 0x31, + 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x0d, 0x45, 0x78, + 0x70, 0x72, 0x65, 0x73, 0x73, 0x20, 0x4c, 0x6f, 0x67, 0x69, 0x63, 0x31, + 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x0b, 0x4e, 0x65, + 0x74, 0x58, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x31, 0x18, 0x30, + 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f, 0x77, 0x77, 0x77, 0x2e, + 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, + 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, + 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, + 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xae, 0x03, 0x2c, 0xec, + 0xa2, 0x79, 0xd1, 0x15, 0x20, 0x88, 0x4d, 0xcd, 0xa2, 0x1b, 0x05, 0xe3, + 0xbd, 0x55, 0xad, 0xc6, 0x1f, 0x64, 0xe8, 0xb5, 0xc5, 0x0d, 0x67, 0xfc, + 0x7e, 0xda, 0xfb, 0x70, 0xf6, 0xc9, 0x47, 0x87, 0x3a, 0xaa, 0x88, 0x00, + 0xf1, 0xa7, 0xf7, 0xe1, 0xf5, 0x2c, 0x54, 0x0e, 0x33, 0xda, 0xbe, 0x9c, + 0x66, 0x30, 0xd9, 0x40, 0xeb, 0x1d, 0xce, 0xe1, 0x55, 0x15, 0x2b, 0x11, + 0x47, 0x6c, 0x7e, 0x88, 0xc6, 0x24, 0xcf, 0x87, 0x1b, 0xb5, 0x1f, 0x47, + 0xb9, 0xef, 0xad, 0x29, 0xd3, 0x2e, 0x43, 0xee, 0x39, 0xdd, 0x09, 0x54, + 0xba, 0xfc, 0xed, 0xbc, 0x2e, 0x0e, 0x53, 0x15, 0x37, 0xcb, 0xc5, 0xf5, + 0xee, 0x70, 0x2a, 0xe8, 0x01, 0x6d, 0xb1, 0x39, 0x94, 0x5a, 0xc2, 0x8a, + 0x00, 0x04, 0xa9, 0xff, 0xea, 0x56, 0xf7, 0xd7, 0xa8, 0x1b, 0xa4, 0x26, + 0xcd, 0x28, 0xaf, 0xfa, 0x52, 0x85, 0x1c, 0x26, 0x3e, 0x5e, 0x01, 0xf7, + 0xe1, 0x66, 0xff, 0xac, 0xad, 0x9c, 0x98, 0x2f, 0xe0, 0x7e, 0x9f, 0xf1, + 0x33, 0x31, 0xc3, 0x7f, 0xe6, 0x58, 0x5d, 0xd8, 0x5f, 0x7d, 0x2b, 0x5a, + 0x55, 0xcf, 0xb1, 0x91, 0x53, 0x41, 0x04, 0xac, 0x86, 0x5e, 0x01, 0x35, + 0x2b, 0x74, 0x8d, 0x46, 0x4d, 0x48, 0xc0, 0x5f, 0x83, 0x67, 0xb5, 0x6d, + 0x52, 0x3f, 0x3e, 0xe6, 0xec, 0xf8, 0x2e, 0x10, 0x28, 0xdb, 0x69, 0xa6, + 0x9d, 0x4b, 0xde, 0x19, 0x2e, 0xd2, 0x5f, 0xc8, 0xa9, 0x3b, 0x52, 0xe9, + 0xb2, 0xcd, 0x6e, 0x19, 0x22, 0xf9, 0x99, 0xa6, 0xcc, 0xf5, 0xd3, 0xec, + 0xff, 0x0c, 0x77, 0x6f, 0x25, 0x92, 0x07, 0x4c, 0x64, 0x7d, 0x34, 0x49, + 0x6f, 0xff, 0x0a, 0xa8, 0x15, 0x64, 0x72, 0x2d, 0x4f, 0x42, 0x05, 0xe8, + 0x2b, 0x01, 0xf1, 0xe3, 0x65, 0x94, 0x23, 0xd9, 0xdf, 0x5e, 0x3b, 0xb5, + 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x7b, 0x30, 0x79, 0x30, 0x09, 0x06, + 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x2c, 0x06, 0x09, + 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8, 0x42, 0x01, 0x0d, 0x04, 0x1f, 0x16, + 0x1d, 0x4f, 0x70, 0x65, 0x6e, 0x53, 0x53, 0x4c, 0x20, 0x47, 0x65, 0x6e, + 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x43, 0x65, 0x72, 0x74, 0x69, + 0x66, 0x69, 0x63, 0x61, 0x74, 0x65, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, + 0x0e, 0x04, 0x16, 0x04, 0x14, 0x8d, 0xb0, 0xee, 0x8f, 0x6b, 0x43, 0x52, + 0x29, 0xf4, 0x25, 0xff, 0x3c, 0xda, 0x5f, 0xb3, 0xce, 0x9b, 0x7b, 0x75, + 0xe1, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, + 0x80, 0x14, 0x1b, 0x8d, 0x06, 0xd9, 0x6b, 0xad, 0xee, 0x82, 0x24, 0x26, + 0x55, 0x9a, 0x1b, 0x03, 0x44, 0x92, 0x0a, 0x06, 0x92, 0x48, 0x30, 0x0d, + 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, + 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x75, 0x83, 0x89, 0xab, 0x84, 0x52, + 0x5f, 0xa4, 0x9e, 0x98, 0xca, 0xa3, 0xf9, 0xab, 0xd4, 0x04, 0x32, 0xa4, + 0x8c, 0x96, 0x90, 0x39, 0x88, 0x92, 0xc3, 0xcd, 0x51, 0xc3, 0x01, 0x35, + 0x03, 0x78, 0xfa, 0x0d, 0x1e, 0x7b, 0x79, 0xe9, 0x7d, 0xd8, 0x68, 0x7a, + 0x65, 0xc6, 0x00, 0x7c, 0xa1, 0x7a, 0x52, 0xc9, 0xa3, 0xf4, 0x0b, 0xbd, + 0x76, 0x24, 0xdf, 0xde, 0x22, 0x2d, 0x95, 0xc5, 0xb6, 0x54, 0xb1, 0xac, + 0xb6, 0x9a, 0xe4, 0x68, 0x0f, 0x97, 0x4a, 0x44, 0xa2, 0x87, 0x01, 0x82, + 0xd4, 0x25, 0xbd, 0x01, 0xbc, 0x35, 0x8a, 0x6d, 0xb7, 0x7c, 0x48, 0xaa, + 0x92, 0xd7, 0x57, 0x76, 0x6a, 0xb0, 0xc9, 0x46, 0xa6, 0xbe, 0xbf, 0x0f, + 0xf0, 0xea, 0x62, 0x57, 0x71, 0x42, 0xf6, 0x67, 0xa7, 0xa1, 0x50, 0x87, + 0x14, 0x8e, 0x32, 0xd0, 0x5e, 0xc9, 0x7b, 0x79, 0x7e, 0xfa, 0x17, 0xc7, + 0xad, 0xbd, 0xc3, 0x98, 0x79, 0x45, 0xfb, 0x7f, 0xf7, 0xe6, 0x9f, 0x77, + 0xb3, 0x44, 0xc3, 0xaf, 0x6b, 0x61, 0x6a, 0x04, 0x68, 0x24, 0x2d, 0x31, + 0xf1, 0x28, 0x2c, 0xf4, 0xf0, 0x07, 0xfe, 0xfd, 0x66, 0x98, 0x77, 0x37, + 0x7b, 0x80, 0x1f, 0xb2, 0x49, 0xe4, 0xa6, 0x24, 0x72, 0x42, 0xf4, 0xca, + 0x91, 0x80, 0xa1, 0xb2, 0x0a, 0xc9, 0xc0, 0x93, 0xa7, 0x22, 0x0b, 0x13, + 0x8a, 0xb2, 0x75, 0x4b, 0x66, 0xf9, 0x87, 0x3a, 0x51, 0x97, 0xc7, 0x1e, + 0x2b, 0x61, 0x81, 0x5c, 0xf0, 0xf8, 0x4c, 0xdb, 0x36, 0xc7, 0xba, 0x49, + 0xd9, 0x04, 0x6a, 0x95, 0xb0, 0x7f, 0xfc, 0xce, 0xca, 0x23, 0xad, 0xf9, + 0xaf, 0x8a, 0x72, 0x8e, 0xab, 0xb8, 0x8b, 0x7e, 0xf7, 0x39, 0xa6, 0x22, + 0x56, 0x03, 0x72, 0x06, 0xc3, 0x57, 0x1f, 0x32, 0xaa, 0xb5, 0xa6, 0x00, + 0x67, 0x88, 0x4b, 0x40, 0xe9, 0x5e, 0x4a, 0x6f, 0x76, 0xe8 +}; +static unsigned int test_device_cert_der_len = 982; + +/* Server private RSA key. */ +static unsigned char test_device_cert_key_der[] = { + 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, + 0xae, 0x03, 0x2c, 0xec, 0xa2, 0x79, 0xd1, 0x15, 0x20, 0x88, 0x4d, 0xcd, + 0xa2, 0x1b, 0x05, 0xe3, 0xbd, 0x55, 0xad, 0xc6, 0x1f, 0x64, 0xe8, 0xb5, + 0xc5, 0x0d, 0x67, 0xfc, 0x7e, 0xda, 0xfb, 0x70, 0xf6, 0xc9, 0x47, 0x87, + 0x3a, 0xaa, 0x88, 0x00, 0xf1, 0xa7, 0xf7, 0xe1, 0xf5, 0x2c, 0x54, 0x0e, + 0x33, 0xda, 0xbe, 0x9c, 0x66, 0x30, 0xd9, 0x40, 0xeb, 0x1d, 0xce, 0xe1, + 0x55, 0x15, 0x2b, 0x11, 0x47, 0x6c, 0x7e, 0x88, 0xc6, 0x24, 0xcf, 0x87, + 0x1b, 0xb5, 0x1f, 0x47, 0xb9, 0xef, 0xad, 0x29, 0xd3, 0x2e, 0x43, 0xee, + 0x39, 0xdd, 0x09, 0x54, 0xba, 0xfc, 0xed, 0xbc, 0x2e, 0x0e, 0x53, 0x15, + 0x37, 0xcb, 0xc5, 0xf5, 0xee, 0x70, 0x2a, 0xe8, 0x01, 0x6d, 0xb1, 0x39, + 0x94, 0x5a, 0xc2, 0x8a, 0x00, 0x04, 0xa9, 0xff, 0xea, 0x56, 0xf7, 0xd7, + 0xa8, 0x1b, 0xa4, 0x26, 0xcd, 0x28, 0xaf, 0xfa, 0x52, 0x85, 0x1c, 0x26, + 0x3e, 0x5e, 0x01, 0xf7, 0xe1, 0x66, 0xff, 0xac, 0xad, 0x9c, 0x98, 0x2f, + 0xe0, 0x7e, 0x9f, 0xf1, 0x33, 0x31, 0xc3, 0x7f, 0xe6, 0x58, 0x5d, 0xd8, + 0x5f, 0x7d, 0x2b, 0x5a, 0x55, 0xcf, 0xb1, 0x91, 0x53, 0x41, 0x04, 0xac, + 0x86, 0x5e, 0x01, 0x35, 0x2b, 0x74, 0x8d, 0x46, 0x4d, 0x48, 0xc0, 0x5f, + 0x83, 0x67, 0xb5, 0x6d, 0x52, 0x3f, 0x3e, 0xe6, 0xec, 0xf8, 0x2e, 0x10, + 0x28, 0xdb, 0x69, 0xa6, 0x9d, 0x4b, 0xde, 0x19, 0x2e, 0xd2, 0x5f, 0xc8, + 0xa9, 0x3b, 0x52, 0xe9, 0xb2, 0xcd, 0x6e, 0x19, 0x22, 0xf9, 0x99, 0xa6, + 0xcc, 0xf5, 0xd3, 0xec, 0xff, 0x0c, 0x77, 0x6f, 0x25, 0x92, 0x07, 0x4c, + 0x64, 0x7d, 0x34, 0x49, 0x6f, 0xff, 0x0a, 0xa8, 0x15, 0x64, 0x72, 0x2d, + 0x4f, 0x42, 0x05, 0xe8, 0x2b, 0x01, 0xf1, 0xe3, 0x65, 0x94, 0x23, 0xd9, + 0xdf, 0x5e, 0x3b, 0xb5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, + 0x01, 0x00, 0xa5, 0x22, 0x2c, 0x52, 0xd0, 0x09, 0x4c, 0x4a, 0x81, 0x59, + 0xf8, 0x83, 0xa9, 0x4f, 0x7d, 0xb2, 0x56, 0xad, 0xe5, 0x3f, 0xfb, 0xf0, + 0xf6, 0x09, 0xf1, 0x5b, 0x3c, 0x90, 0x58, 0x0e, 0x15, 0xc9, 0x68, 0xd9, + 0x30, 0x40, 0xfb, 0x82, 0x73, 0x98, 0x79, 0xbb, 0xcd, 0xb8, 0x27, 0xc3, + 0x8e, 0x6c, 0xff, 0xf6, 0x99, 0x26, 0xb0, 0xaf, 0xb0, 0xac, 0x33, 0xb3, + 0x50, 0xed, 0x73, 0xa1, 0xa8, 0x02, 0x38, 0xc6, 0x93, 0xf9, 0xd6, 0x17, + 0x7e, 0xbd, 0x97, 0xa4, 0xb5, 0x6f, 0x8a, 0xdb, 0x11, 0x78, 0x7c, 0x89, + 0x0e, 0x3c, 0x17, 0xbb, 0x54, 0x2c, 0x8d, 0x5a, 0x93, 0x7d, 0x1e, 0x33, + 0xc7, 0xd2, 0x7d, 0xe5, 0xaa, 0x12, 0x2d, 0xd9, 0x52, 0x4e, 0x63, 0x74, + 0xa6, 0x57, 0x9f, 0x1a, 0xd6, 0x3c, 0xc1, 0xb1, 0xab, 0x66, 0x4a, 0x0b, + 0x88, 0x1d, 0xa6, 0xd1, 0xbc, 0x60, 0x7a, 0x17, 0x1f, 0x8f, 0x9b, 0x35, + 0x57, 0xf8, 0xd0, 0x1c, 0xd3, 0xa6, 0x56, 0xc8, 0x03, 0x9c, 0x08, 0x3b, + 0x1b, 0x5b, 0xc2, 0x03, 0x3b, 0x3a, 0xa4, 0xe8, 0xed, 0x75, 0x66, 0xb0, + 0x85, 0x56, 0x40, 0xfe, 0xae, 0x97, 0x7e, 0xc0, 0x79, 0x49, 0x13, 0x8b, + 0x01, 0x0c, 0xae, 0x4c, 0x3d, 0x54, 0x47, 0xc5, 0x51, 0x40, 0x3d, 0xcc, + 0x4d, 0x17, 0xb3, 0x4e, 0x1d, 0x85, 0x1c, 0x41, 0x07, 0x03, 0x5e, 0xf9, + 0xfa, 0x17, 0x81, 0x24, 0x34, 0xaa, 0xbf, 0x67, 0x73, 0xb6, 0x9c, 0x67, + 0x36, 0xd9, 0xee, 0xf7, 0x86, 0x4c, 0x4d, 0x79, 0xca, 0xd7, 0xfd, 0x72, + 0xf9, 0xb3, 0x73, 0xc3, 0x57, 0xe5, 0x39, 0x72, 0x93, 0x56, 0xc2, 0xec, + 0xf8, 0x25, 0xe4, 0x8f, 0xba, 0xd0, 0x6f, 0x23, 0x8c, 0x39, 0x9e, 0x05, + 0x1a, 0x4e, 0xdc, 0x5e, 0xcd, 0x17, 0x59, 0x94, 0x37, 0x22, 0xb7, 0x39, + 0x50, 0x65, 0xdc, 0x91, 0x3c, 0xe1, 0x02, 0x81, 0x81, 0x00, 0xe4, 0xc6, + 0x42, 0xe5, 0xea, 0xe5, 0x32, 0xf3, 0x51, 0x36, 0x7b, 0x8c, 0x5b, 0x72, + 0x24, 0x1a, 0x4a, 0x44, 0x4f, 0x64, 0xe5, 0xa7, 0x74, 0xd9, 0xb2, 0x29, + 0x8a, 0x08, 0xcf, 0x9b, 0xd2, 0x9d, 0xc4, 0x20, 0x4c, 0xd3, 0x60, 0x4d, + 0xf7, 0xb7, 0xac, 0x92, 0x6b, 0x2b, 0x95, 0x73, 0x6e, 0x57, 0x00, 0x20, + 0x9d, 0xb2, 0xf6, 0xbd, 0x0b, 0xbb, 0xaa, 0x7e, 0x7e, 0x3e, 0x53, 0xfb, + 0x79, 0x7e, 0x45, 0xd5, 0x2e, 0xab, 0x5e, 0xff, 0x5c, 0x0a, 0x45, 0x2d, + 0x27, 0x19, 0xb0, 0x59, 0x0a, 0x39, 0x89, 0xf6, 0xae, 0xc6, 0xe2, 0xd1, + 0x07, 0x58, 0xbe, 0x95, 0x27, 0xaf, 0xf7, 0xa6, 0x2f, 0xaa, 0x37, 0x25, + 0x7c, 0x7b, 0xd3, 0xda, 0x13, 0x76, 0x0a, 0xb6, 0x6c, 0x99, 0x53, 0x5d, + 0xa5, 0x75, 0xfa, 0x10, 0x9b, 0x7f, 0xfe, 0xd7, 0xb4, 0x18, 0x95, 0xa8, + 0x65, 0x85, 0x07, 0xc5, 0xc4, 0xad, 0x02, 0x81, 0x81, 0x00, 0xc2, 0xb8, + 0x8e, 0xed, 0x9d, 0x4a, 0x1f, 0x9c, 0xda, 0x73, 0xf0, 0x2c, 0x35, 0x91, + 0xe4, 0x40, 0x78, 0xe1, 0x12, 0xf3, 0x08, 0xef, 0xdf, 0x97, 0xa0, 0xb0, + 0xdd, 0xea, 0xc2, 0xb9, 0x5b, 0xf8, 0xa1, 0xac, 0x32, 0xfd, 0xb8, 0xe9, + 0x0f, 0xed, 0xfd, 0xe0, 0xdc, 0x38, 0x90, 0x5e, 0xf5, 0x4c, 0x02, 0xc3, + 0x1a, 0x72, 0x18, 0xf7, 0xfe, 0xb7, 0xb8, 0x2a, 0xf8, 0x72, 0xbb, 0x99, + 0x56, 0xec, 0x85, 0x58, 0x31, 0x7e, 0x64, 0xdf, 0x02, 0x05, 0xe3, 0xb2, + 0xbb, 0xe2, 0x1b, 0xd6, 0x43, 0x73, 0xf8, 0x0f, 0xaf, 0x89, 0x57, 0x44, + 0x5f, 0x30, 0x1c, 0xe5, 0x78, 0xbf, 0x0b, 0xe7, 0x4b, 0xbe, 0x80, 0x2f, + 0x3d, 0x35, 0x44, 0xfc, 0x9e, 0x0d, 0x85, 0x5d, 0x94, 0x6e, 0xe9, 0x6a, + 0x72, 0xa7, 0x46, 0xd8, 0x64, 0x6c, 0xe9, 0x61, 0x92, 0xa0, 0xb6, 0xd1, + 0xee, 0xa6, 0xa6, 0xf4, 0x2c, 0x29, 0x02, 0x81, 0x81, 0x00, 0xb4, 0xa7, + 0x7b, 0x1c, 0x64, 0x29, 0x29, 0xda, 0xca, 0x3e, 0xe3, 0xc1, 0x2a, 0x55, + 0x2f, 0xfd, 0x32, 0xb8, 0x4e, 0x99, 0xb6, 0x60, 0x4d, 0xfd, 0xba, 0x9a, + 0xe2, 0xcd, 0xa2, 0x63, 0xc2, 0x25, 0xa3, 0x42, 0x7e, 0x68, 0x4c, 0x9c, + 0x45, 0x09, 0x5d, 0xd5, 0x21, 0x9c, 0x01, 0x20, 0x6d, 0xf9, 0x75, 0xb8, + 0x4b, 0xcf, 0x8e, 0xd8, 0x29, 0xf3, 0xbf, 0xe6, 0xb3, 0x7a, 0x34, 0x87, + 0x58, 0xa1, 0x46, 0x33, 0xd9, 0xee, 0xa9, 0xcd, 0xac, 0xb8, 0xcf, 0x77, + 0xa0, 0x70, 0xc0, 0xb9, 0x0f, 0x41, 0xf0, 0x98, 0x43, 0xdb, 0xfa, 0x30, + 0x66, 0x44, 0xc5, 0xfa, 0xb2, 0xa4, 0x5a, 0x43, 0x79, 0x50, 0x48, 0xcb, + 0xe9, 0x49, 0x3f, 0x39, 0xee, 0x34, 0x40, 0xb1, 0x5d, 0x80, 0x96, 0x3c, + 0x54, 0xf4, 0x9c, 0xcb, 0x90, 0x7f, 0xba, 0x96, 0x4b, 0x39, 0x3e, 0xb5, + 0x03, 0xb5, 0xd1, 0x35, 0x72, 0xe1, 0x02, 0x81, 0x80, 0x60, 0x14, 0xd5, + 0x61, 0xe6, 0x24, 0xf7, 0x28, 0x5c, 0x9a, 0xac, 0xbe, 0x03, 0xc8, 0xf3, + 0x49, 0xe4, 0xdb, 0x9a, 0x90, 0x15, 0xae, 0xd7, 0x33, 0x68, 0x75, 0x1d, + 0x6b, 0x83, 0x9e, 0x17, 0x05, 0xbe, 0x30, 0xcc, 0x10, 0x6a, 0x37, 0x86, + 0x46, 0xb6, 0xe9, 0x47, 0x81, 0x19, 0xab, 0xe1, 0x7a, 0x1a, 0x3a, 0xcf, + 0x47, 0xd1, 0x8e, 0x3d, 0x3f, 0xc6, 0x3e, 0x5d, 0xcd, 0xaf, 0x47, 0xe0, + 0x9e, 0x60, 0xc5, 0xbd, 0xd6, 0x52, 0x4b, 0xc0, 0x21, 0xcb, 0xd3, 0x1b, + 0xe6, 0x5c, 0x3a, 0x03, 0x9a, 0xab, 0xa2, 0x81, 0xc9, 0x51, 0x28, 0x49, + 0x97, 0xe2, 0x0a, 0x50, 0xe4, 0x64, 0x29, 0x43, 0x34, 0xc2, 0xe7, 0x8c, + 0x5a, 0x46, 0xaa, 0x28, 0x0b, 0x1f, 0xed, 0xa7, 0x1a, 0x7b, 0x4e, 0xad, + 0x38, 0x61, 0x3a, 0xd1, 0x82, 0xf4, 0x3d, 0xd3, 0x2e, 0x3e, 0x47, 0xa4, + 0x6c, 0xd3, 0x20, 0xd4, 0xd1, 0x02, 0x81, 0x80, 0x68, 0x1a, 0x8d, 0x3c, + 0x18, 0x3f, 0x42, 0x5e, 0x38, 0x6d, 0x0a, 0x1e, 0x52, 0xd5, 0x8f, 0xd6, + 0x32, 0xff, 0x7c, 0x1c, 0xf3, 0x20, 0x8b, 0x92, 0xa5, 0x44, 0xff, 0x08, + 0x21, 0xa1, 0xce, 0x68, 0x8b, 0x03, 0xe0, 0x90, 0xeb, 0x01, 0x4e, 0x85, + 0xf9, 0xc5, 0xb7, 0x86, 0xee, 0xd0, 0x59, 0x10, 0x73, 0x98, 0x2a, 0xcb, + 0xf6, 0xfe, 0x0d, 0xba, 0x07, 0x91, 0x18, 0xf6, 0xbc, 0x93, 0x8a, 0x91, + 0xdd, 0x80, 0x16, 0x37, 0xdf, 0x75, 0x46, 0x87, 0x68, 0xee, 0xf4, 0x76, + 0x0c, 0xc5, 0x87, 0x38, 0xf5, 0xb6, 0xda, 0x8a, 0xee, 0x62, 0xc8, 0xc0, + 0xa2, 0x8d, 0xbf, 0xd5, 0xf8, 0xba, 0xb5, 0x74, 0xf0, 0x07, 0xa6, 0x1c, + 0xcf, 0x76, 0x61, 0xbe, 0xa4, 0x88, 0x4a, 0x95, 0xb0, 0xa3, 0x70, 0x73, + 0xa1, 0x6f, 0x73, 0xf0, 0xe8, 0x38, 0x8d, 0xe8, 0xd0, 0x7e, 0x2c, 0x0c, + 0xdc, 0x21, 0xfa, 0xc1 +}; + +static unsigned int test_device_cert_key_der_len = 1192; + +/* Trusted CA certificate for Client. */ +static unsigned char test_ca_cert_der[] = { + 0x30, 0x82, 0x03, 0xc7, 0x30, 0x82, 0x02, 0xaf, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x09, 0x00, 0xa1, 0x79, 0xb0, 0x6a, 0x32, 0xbc, 0x48, 0x67, + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, + 0x0b, 0x05, 0x00, 0x30, 0x7a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, + 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, + 0x55, 0x04, 0x08, 0x0c, 0x02, 0x43, 0x41, 0x31, 0x12, 0x30, 0x10, 0x06, + 0x03, 0x55, 0x04, 0x07, 0x0c, 0x09, 0x53, 0x61, 0x6e, 0x20, 0x44, 0x69, + 0x65, 0x67, 0x6f, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, + 0x0c, 0x0d, 0x45, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x20, 0x4c, 0x6f, + 0x67, 0x69, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, + 0x0c, 0x0b, 0x4e, 0x65, 0x74, 0x58, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, + 0x65, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, + 0x4e, 0x65, 0x74, 0x58, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, + 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, + 0x36, 0x31, 0x31, 0x31, 0x31, 0x31, 0x39, 0x35, 0x30, 0x30, 0x38, 0x5a, + 0x17, 0x0d, 0x32, 0x36, 0x31, 0x31, 0x30, 0x39, 0x31, 0x39, 0x35, 0x30, + 0x30, 0x38, 0x5a, 0x30, 0x7a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, + 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, + 0x55, 0x04, 0x08, 0x0c, 0x02, 0x43, 0x41, 0x31, 0x12, 0x30, 0x10, 0x06, + 0x03, 0x55, 0x04, 0x07, 0x0c, 0x09, 0x53, 0x61, 0x6e, 0x20, 0x44, 0x69, + 0x65, 0x67, 0x6f, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, + 0x0c, 0x0d, 0x45, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x20, 0x4c, 0x6f, + 0x67, 0x69, 0x63, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0b, + 0x0c, 0x0b, 0x4e, 0x65, 0x74, 0x58, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, + 0x65, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x13, + 0x4e, 0x65, 0x74, 0x58, 0x20, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x20, + 0x54, 0x65, 0x73, 0x74, 0x20, 0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, + 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, + 0x82, 0x01, 0x01, 0x00, 0xd1, 0xdc, 0x3c, 0xe1, 0x1c, 0x7a, 0x3d, 0xb7, + 0x76, 0xcf, 0xab, 0xd7, 0x3c, 0x38, 0xb0, 0x81, 0xb6, 0x37, 0x52, 0xa3, + 0x3d, 0x6f, 0xcd, 0x89, 0xa6, 0xa2, 0xf3, 0xa8, 0xb0, 0x8d, 0xee, 0x0b, + 0x36, 0x94, 0x83, 0x0e, 0x7f, 0x39, 0x87, 0x6e, 0xee, 0x19, 0xe2, 0x1f, + 0x92, 0x3d, 0x01, 0x05, 0x4f, 0x11, 0xcd, 0xcb, 0xa0, 0x79, 0xfc, 0x9d, + 0x6e, 0x93, 0xb1, 0xb7, 0x03, 0xf3, 0xfe, 0xeb, 0x30, 0x67, 0x38, 0x85, + 0x28, 0xdf, 0x93, 0xdb, 0xcb, 0xcb, 0xb1, 0xbe, 0xd3, 0xe1, 0xc2, 0x7d, + 0x8d, 0xbb, 0x70, 0x76, 0x99, 0x08, 0x7c, 0x3f, 0x21, 0x2f, 0x37, 0x97, + 0xf7, 0xe8, 0x6e, 0x8c, 0x7e, 0xbc, 0x30, 0x5f, 0xbf, 0x32, 0x51, 0x1d, + 0x66, 0x76, 0xad, 0x39, 0xfc, 0x94, 0xd4, 0x65, 0xf6, 0xd2, 0x0b, 0x37, + 0xd3, 0x4a, 0xe6, 0xe1, 0xdf, 0x4a, 0x8f, 0x3b, 0x33, 0x16, 0xbe, 0xf7, + 0xd9, 0xbd, 0x73, 0x64, 0xdf, 0x34, 0xa3, 0x55, 0xe7, 0xac, 0xab, 0xa7, + 0xae, 0xc2, 0x20, 0x46, 0xc2, 0xd1, 0xe3, 0x25, 0x3a, 0x47, 0x68, 0x92, + 0xac, 0xd6, 0x12, 0xa4, 0x0a, 0xce, 0xdc, 0xe2, 0x24, 0x12, 0xee, 0xe1, + 0xb2, 0xcd, 0x09, 0xa8, 0xef, 0x36, 0xea, 0x76, 0xf9, 0xb6, 0x63, 0xaa, + 0xac, 0xdd, 0x46, 0x06, 0x6e, 0xd9, 0x1e, 0x08, 0xac, 0x57, 0x12, 0x6c, + 0x21, 0xef, 0x8e, 0xae, 0xf0, 0x27, 0xf1, 0x5c, 0x79, 0xb4, 0xb6, 0x26, + 0x92, 0x11, 0xda, 0xca, 0x80, 0x5e, 0x92, 0x4c, 0xb5, 0xd8, 0xb5, 0x84, + 0x95, 0xe3, 0xef, 0xbc, 0x7e, 0x7d, 0x68, 0x74, 0x4c, 0x34, 0x1a, 0x50, + 0x6d, 0x2d, 0x5f, 0x1b, 0x0e, 0xbe, 0xf5, 0xb4, 0xf1, 0x32, 0x16, 0x44, + 0x24, 0x7a, 0x0e, 0x4b, 0xcd, 0xfa, 0xa5, 0x03, 0x95, 0x2e, 0x44, 0x65, + 0xa8, 0x74, 0xea, 0x17, 0xdd, 0x99, 0xbd, 0xcb, 0x02, 0x03, 0x01, 0x00, + 0x01, 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, + 0x04, 0x16, 0x04, 0x14, 0x1b, 0x8d, 0x06, 0xd9, 0x6b, 0xad, 0xee, 0x82, + 0x24, 0x26, 0x55, 0x9a, 0x1b, 0x03, 0x44, 0x92, 0x0a, 0x06, 0x92, 0x48, + 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, + 0x14, 0x1b, 0x8d, 0x06, 0xd9, 0x6b, 0xad, 0xee, 0x82, 0x24, 0x26, 0x55, + 0x9a, 0x1b, 0x03, 0x44, 0x92, 0x0a, 0x06, 0x92, 0x48, 0x30, 0x0c, 0x06, + 0x03, 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, + 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, + 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x70, 0xc7, 0x6a, 0x75, 0x27, + 0x14, 0xa0, 0x1c, 0xe0, 0xe0, 0x84, 0x7c, 0x6c, 0x16, 0xa9, 0x0d, 0x4d, + 0xb1, 0xc3, 0x87, 0x37, 0xf6, 0x86, 0x89, 0x6f, 0x73, 0xf0, 0x59, 0x9b, + 0x8c, 0xa4, 0x83, 0x10, 0x2d, 0xb7, 0x8b, 0xd0, 0x9a, 0x81, 0xe0, 0x5c, + 0xd7, 0x20, 0x6f, 0xdc, 0xfc, 0xc8, 0xa0, 0xc2, 0x8e, 0x54, 0xe6, 0xfb, + 0x61, 0x85, 0x37, 0x4b, 0x22, 0x47, 0x09, 0x95, 0x44, 0x12, 0x75, 0xf0, + 0xcf, 0x0b, 0x90, 0x48, 0xb0, 0x02, 0x4c, 0xef, 0x3f, 0xde, 0x6a, 0xfd, + 0xb1, 0x8b, 0x88, 0xd7, 0x84, 0xe5, 0x34, 0x02, 0x96, 0x0a, 0x3f, 0xa8, + 0x8c, 0xbd, 0x1a, 0xd8, 0xf7, 0xf9, 0xe5, 0x49, 0x87, 0xd0, 0x20, 0x4f, + 0xd8, 0xcd, 0xc0, 0xb9, 0x11, 0x2a, 0xd9, 0x0f, 0x75, 0xa6, 0xee, 0x76, + 0x15, 0x9f, 0x12, 0x50, 0x68, 0x4c, 0xc0, 0x05, 0x46, 0x8d, 0xdd, 0x93, + 0x74, 0x31, 0x82, 0x20, 0x37, 0x24, 0x58, 0xb2, 0x88, 0x9b, 0x21, 0xc1, + 0x48, 0xc4, 0x8d, 0x68, 0x3b, 0x91, 0x2c, 0x34, 0xcb, 0x94, 0xd0, 0xbc, + 0xe3, 0x05, 0x24, 0x05, 0xcc, 0xea, 0x05, 0xb1, 0x52, 0x74, 0x4a, 0x23, + 0x65, 0xc4, 0x40, 0x04, 0x86, 0xb1, 0x80, 0x61, 0x97, 0xdc, 0x94, 0x16, + 0x4e, 0x63, 0x31, 0x72, 0x4e, 0x45, 0xe8, 0x3e, 0x3b, 0xb6, 0x99, 0xae, + 0xd8, 0x91, 0x25, 0x3d, 0x62, 0x92, 0x6d, 0x72, 0x01, 0x2c, 0xca, 0x67, + 0x0a, 0xec, 0x00, 0xeb, 0x10, 0xff, 0x6d, 0xac, 0x89, 0x19, 0x2c, 0xb7, + 0xb3, 0xa5, 0xf7, 0xa1, 0x4a, 0xc3, 0xc1, 0xdd, 0xaf, 0xb5, 0x1a, 0x16, + 0x44, 0xdc, 0xa8, 0xb5, 0xca, 0xd0, 0x30, 0xaa, 0x7e, 0x73, 0xd5, 0x2e, + 0x65, 0xd6, 0xf9, 0xbf, 0x5f, 0xda, 0x6f, 0x13, 0xe9, 0xd7, 0x12, 0x6c, + 0x3a, 0x6c, 0x50, 0x26, 0x78, 0x6e, 0xc6, 0xeb, 0x75, 0xe1, 0x3c +}; +static unsigned int test_ca_cert_der_len = 971; + +/* Define an request to be sent to the TLS server. */ +UCHAR http_request[] = { "GET /example.html HTTP/1.1" }; + +/* Define some HTML data (web page) with an HTTPS header to serve to connecting + clients. */ +UCHAR html_data[] = { "HTTP/1.1 200 OK\r\n" \ + "Date: Tue, 19 May 2020 23:59:59 GMT\r\n" \ + "Content-Type: text/html\r\n" \ + "Content-Length: 200\r\n\r\n" \ + "\r\n"\ + "
\r\n"\ + "Hello NetX Secure User!\r\n"\ + "This is a simple webpage\r\n"\ + "served up using NetX Secure!\r\n"\ + "\r\n"\ + "\r\n" }; + +/* Define the metadata area for TLS cryptography. The actual size needed can be + Ascertained by calling nx_secure_tls_metadata_size_calculate. +*/ +static CHAR crypto_metadata_server[18000]; +static CHAR crypto_metadata_client[18000]; + +/* TLS buffers and certificate containers. */ +static UCHAR tls_packet_buffer_server[40000]; +static UCHAR tls_packet_buffer_client[40000]; +static NX_SECURE_X509_CERT certificate; +static NX_SECURE_X509_CERT remote_certificate, remote_issuer; +static UCHAR remote_cert_buffer[2000]; +static UCHAR remote_issuer_buffer[2000]; + +/* Pointer to the TLS ciphersuite table that is included in the platform-specific + cryptography subdirectory. The table maps the cryptographic routines for the + platform to function pointers usable by the TLS library. + + For TLS Web servers, define NX_SECURE_ENABLE_AEAD_CIPHER in NetX Crypto to + allow web browsers to connect using AES_128_GCM cipher suites. +*/ +extern const NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers_ecc; +extern const USHORT nx_crypto_ecc_supported_groups[]; +extern const NX_CRYPTO_METHOD* nx_crypto_ecc_curves[]; +extern const UINT nx_crypto_ecc_supported_groups_size; + +/* Local IP address. */ +#define TLS_SERVER_ADDRESS IP_ADDRESS(192, 168, 1, 160) +#define TLS_CLIENT_ADDRESS IP_ADDRESS(192, 168, 1, 167) + +/* Define the server port.*/ +#define SERVER_PORT 443 + +int main() +{ + + /* Enter the ThreadX kernel. */ + tx_kernel_enter(); +} + + +/* Define what the initial system looks like. */ +void tx_application_define(void *first_unused_memory) +{ +CHAR *pointer; +UINT status; + + + error_counter = 0; + + /* Setup the working pointer. */ + pointer = (CHAR *) first_unused_memory; + + /* Create a helper thread for the server. */ + tx_thread_create(&server_thread, "TLS Server thread", tls_server_thread_entry, 0, + pointer, DEMO_STACK_SIZE, + 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START); + + pointer = pointer + DEMO_STACK_SIZE; + + /* Initialize the NetX system. */ + nx_system_initialize(); + + /* Create the server packet pool. */ + status = nx_packet_pool_create(&server_pool, "TLS Server Packet Pool", NX_PACKET_SIZE, + pointer, NX_PACKET_SIZE * 16); + pointer = pointer + NX_PACKET_SIZE * 16; + if (status) + error_counter++; + + /* Create an IP instance. */ + status = nx_ip_create(&server_ip, "TLS Server IP", TLS_SERVER_ADDRESS, + 0xFFFFFF00UL, &server_pool, _nx_ram_network_driver, + pointer, 4096, 1); + pointer = pointer + 4096; + if (status) + error_counter++; + + /* Enable ARP and supply ARP cache memory for the server IP instance. */ + status = nx_arp_enable(&server_ip, (void *) pointer, 1024); + pointer = pointer + 1024; + if (status) + error_counter++; + + /* Enable TCP traffic. */ + status = nx_tcp_enable(&server_ip); + if (status) + error_counter++; + + /* Create the TLS Client thread. */ + status = tx_thread_create(&client_thread, "TLS Client", tls_client_thread_entry, 0, + pointer, DEMO_STACK_SIZE, + 6, 6, TX_NO_TIME_SLICE, TX_AUTO_START); + pointer = pointer + DEMO_STACK_SIZE; + if (status) + error_counter++; + + /* Create the Client packet pool. */ + status = nx_packet_pool_create(&client_pool, "TLS Client Packet Pool", NX_PACKET_SIZE, + pointer, NX_PACKET_SIZE * 16); + pointer = pointer + NX_PACKET_SIZE * 16; + if (status) + error_counter++; + + /* Create an IP instance. */ + status = nx_ip_create(&client_ip, "TLS Client IP", TLS_CLIENT_ADDRESS, + 0xFFFFFF00UL, &client_pool, _nx_ram_network_driver, + pointer, 2048, 1); + pointer = pointer + 2048; + if (status) + error_counter++; + + status = nx_arp_enable(&client_ip, (void *) pointer, 1024); + pointer = pointer + 2048; + if (status) + error_counter++; + + /* Enable TCP traffic. */ + status = nx_tcp_enable(&client_ip); + if (status) + error_counter++; +} + +/* Thread entry for the TLS Client demo. */ +VOID tls_client_thread_entry(ULONG thread_input) +{ +UINT status; +ULONG actual_status; +NX_PACKET *send_packet; +NX_PACKET *receive_packet; +UCHAR receive_buffer[200]; +ULONG bytes; +ULONG server_ipv4_address; + + /* We are not using the thread input parameter so suppress compiler warning. */ + NX_PARAMETER_NOT_USED(thread_input); + + /* Ensure the IP instance has been initialized. */ + status = nx_ip_status_check(&client_ip, NX_IP_INITIALIZE_DONE, &actual_status, + NX_IP_PERIODIC_RATE); + if (status) + error_counter++; + + /* Create a TCP socket to use for our TLS session. */ + status = nx_tcp_socket_create(&client_ip, &client_tcp_socket, "TLS Client Socket", + NX_IP_NORMAL, NX_FRAGMENT_OKAY, + NX_IP_TIME_TO_LIVE, 8192, NX_NULL, NX_NULL); + if (status) + error_counter++; + + /* Create a TLS session for our socket. This sets up the TLS session object for + later use */ + status = nx_secure_tls_session_create(&client_tls_session, + &nx_crypto_tls_ciphers_ecc, + crypto_metadata_client, + sizeof(crypto_metadata_client)); + if (status) + error_counter++; + + /* Initialize ECC parameters for this session. */ + status = nx_secure_tls_ecc_initialize(&client_tls_session, + nx_crypto_ecc_supported_groups, + nx_crypto_ecc_supported_groups_size, + nx_crypto_ecc_curves); + if (status) + error_counter++; + + /* Set the packet reassembly buffer for this TLS session. */ + status = nx_secure_tls_session_packet_buffer_set(&client_tls_session, tls_packet_buffer_client, + sizeof(tls_packet_buffer_client)); + if (status) + error_counter++; + + /* Initialize an X.509 certificate with our CA root certificate data. */ + status = nx_secure_x509_certificate_initialize(&trusted_certificate, test_ca_cert_der, + test_ca_cert_der_len, NX_NULL, 0, NX_NULL, 0, + NX_SECURE_X509_KEY_TYPE_NONE); + if (status) + error_counter++; + + /* Add the initialized certificate as a trusted root certificate. */ + status = nx_secure_tls_trusted_certificate_add(&client_tls_session, &trusted_certificate); + if (status) + error_counter++; + + /* Bind the socket. */ + status = nx_tcp_client_socket_bind(&client_tcp_socket, 0, NX_WAIT_FOREVER); + if (status) + error_counter++; + + /* Setup this thread to open a connection on the TCP socket to a remote server. + The IP address can be used directly or it can be obtained via DNS or other + means.*/ + server_ipv4_address = TLS_SERVER_ADDRESS; + status = nx_tcp_client_socket_connect(&client_tcp_socket, server_ipv4_address, + SERVER_PORT, NX_WAIT_FOREVER); + if (status) + { + error_counter++; + return; + } + + /* Start the TLS Session using the connected TCP socket. This function will + ascertain from the TCP socket state that this is a TLS Client session. */ + status = nx_secure_tls_session_start(&client_tls_session, &client_tcp_socket, + NX_WAIT_FOREVER); + if (status) + { + error_counter++; + return; + } + + /* Allocate a TLS packet to send an HTTP request over TLS (HTTPS). */ + status = nx_secure_tls_packet_allocate(&client_tls_session, &client_pool, &send_packet, + NX_WAIT_FOREVER); + if (status) + error_counter++; + + /* Populate the packet with our HTTP request. */ + status = nx_packet_data_append(send_packet, http_request, sizeof(http_request), &client_pool, + NX_WAIT_FOREVER); + if (status) + error_counter++; + + /* Send the HTTP request over the TLS Session, turning it into HTTPS. */ + status = nx_secure_tls_session_send(&client_tls_session, send_packet, NX_WAIT_FOREVER); + + /* If the send fails, you must release the packet. */ + if (status != NX_SUCCESS) + { + + /* Release the packet since the packet was not sent. */ + nx_packet_release(send_packet); + } + + /* Receive the HTTP response and any data from the server. */ + status = nx_secure_tls_session_receive(&client_tls_session, &receive_packet, + NX_WAIT_FOREVER); + if (status == NX_SUCCESS) + { + + /* Extract the data we received from the remote server. */ + status = nx_packet_data_extract_offset(receive_packet, 0, receive_buffer, + sizeof(receive_buffer) - 1, &bytes); + + /* Display the response data. */ + receive_buffer[bytes] = 0; + printf("Received data: %s\n", receive_buffer); + + /* Release the packet when done with it. */ + nx_packet_release(receive_packet); + } + + /* End the TLS session now that we have received our HTTPS/HTML response. */ + status = nx_secure_tls_session_end(&client_tls_session, NX_WAIT_FOREVER); + if (status) + error_counter++; + + /* Check for errors to make sure the session ended cleanly. */ + + /* Disconnect the TCP socket. */ + status = nx_tcp_socket_disconnect(&client_tcp_socket, NX_WAIT_FOREVER); + +} + +/************* TLS Server *************************/ + +/* Define the TLS Server thread. */ +void tls_server_thread_entry(ULONG thread_input) +{ +UINT status; +ULONG actual_status; +NX_PACKET *send_packet; +NX_PACKET *receive_packet; +UCHAR receive_buffer[100]; +ULONG bytes; + + NX_PARAMETER_NOT_USED(thread_input); + + /* Ensure the IP instance has been initialized. */ + status = nx_ip_status_check(&server_ip, NX_IP_INITIALIZE_DONE, &actual_status, + NX_IP_PERIODIC_RATE); + if (status) + error_counter++; + + /* Create a TCP socket to use for our TLS session. */ + status = nx_tcp_socket_create(&server_ip, &server_tcp_socket, "TLS Server Socket", + NX_IP_NORMAL, NX_FRAGMENT_OKAY, + NX_IP_TIME_TO_LIVE, 8192, NX_NULL, NX_NULL); + if (status) + error_counter++; + + /* Create a TLS session for our socket. */ + status = nx_secure_tls_session_create(&server_tls_session, + &nx_crypto_tls_ciphers_ecc, + crypto_metadata_server, + sizeof(crypto_metadata_server)); + if (status) + error_counter++; + + status = nx_secure_tls_ecc_initialize(&server_tls_session, + nx_crypto_ecc_supported_groups, + nx_crypto_ecc_supported_groups_size, + nx_crypto_ecc_curves); + if (status) + error_counter++; + + /* Set the packet reassembly buffer for this TLS session. */ + status = nx_secure_tls_session_packet_buffer_set(&server_tls_session, tls_packet_buffer_server, + sizeof(tls_packet_buffer_server)); + if (status) + error_counter++; + + /* Initialize an X.509 certificate and private ECC key for our TLS Session. */ + status = nx_secure_x509_certificate_initialize(&certificate, test_device_cert_der, test_device_cert_der_len, NX_NULL, 0, + test_device_cert_key_der, test_device_cert_key_der_len, + NX_SECURE_X509_KEY_TYPE_RSA_PKCS1_DER); + if (status) + error_counter++; + + /* Add the initialized certificate as a local identity certificate. */ + status = nx_secure_tls_local_certificate_add(&server_tls_session, &certificate); + if (status) + error_counter++; + + /* Setup this thread to listen on the TCP socket. */ + status = nx_tcp_server_socket_listen(&server_ip, SERVER_PORT, &server_tcp_socket, 5, NX_NULL); + if (status) + error_counter++; + + while(1) + { + + /* Accept a client TCP socket connection. */ + status = nx_tcp_server_socket_accept(&server_tcp_socket, NX_WAIT_FOREVER); + if (status) + { + printf("Socket accept failure: %x\n", status); + error_counter++; + + /* Unaccept the server socket. */ + nx_tcp_server_socket_unaccept(&server_tcp_socket); + + /* Setup server socket for listening again. */ + nx_tcp_server_socket_relisten(&server_ip, SERVER_PORT, &server_tcp_socket); + + continue; + } + + /* Start the TLS Session using the connected TCP socket. */ + status = nx_secure_tls_session_start(&server_tls_session, &server_tcp_socket, + NX_WAIT_FOREVER); + + if (status == NX_SUCCESS) + { + /* Receive the HTTPS request. */ + status = nx_secure_tls_session_receive(&server_tls_session, &receive_packet, + NX_WAIT_FOREVER); + + if (status == NX_SUCCESS) + { + /* Extract the HTTP request information from the HTTPS request. */ + status = nx_packet_data_extract_offset(receive_packet, 0, receive_buffer, + sizeof(receive_buffer) - 1, &bytes); + if (status) + error_counter++; + + /* Display the HTTP request data. */ + receive_buffer[bytes] = 0; + printf("Received data: %s\n", receive_buffer); + + /* Release the packet when done with it */ + nx_packet_release(receive_packet); + } + + /* Allocate a TLS packet to send HTML data back to client. */ + status = nx_secure_tls_packet_allocate(&server_tls_session, &server_pool, &send_packet, + NX_WAIT_FOREVER); + if (status) + error_counter++; + + /* Populate the packet with our HTTP response and HTML web page data. */ + status = nx_packet_data_append(send_packet, html_data, sizeof(html_data), &server_pool, + NX_WAIT_FOREVER); + if (status) + error_counter++; + + /* Send the HTTP response over the TLS Session, turning it into HTTPS. */ + status = nx_secure_tls_session_send(&server_tls_session, send_packet, + NX_WAIT_FOREVER); + + /* If the send fails, you must release the packet. */ + if (status != NX_SUCCESS) + { + /* Release the packet since it was not sent. */ + nx_packet_release(send_packet); + error_counter++; + } + + } + + /* End the TLS session now that we have sent our HTTPS/HTML response. */ + status = nx_secure_tls_session_end(&server_tls_session, NX_WAIT_FOREVER); + + /* Check for errors to make sure the session ended cleanly! */ + if (status) + error_counter++; + + /* Disconnect the TCP socket so we can be ready for the next request. */ + status = nx_tcp_socket_disconnect(&server_tcp_socket, NX_WAIT_FOREVER); + if (status) + error_counter++; + + /* Unaccept the server socket. */ + status = nx_tcp_server_socket_unaccept(&server_tcp_socket); + if (status) + error_counter++; + + /* Setup server socket for listening again. */ + status = nx_tcp_server_socket_relisten(&server_ip, SERVER_PORT, &server_tcp_socket); + if (status) + error_counter++; + + } + +} + +#endif /* NX_DISABLE_IPV4 */