diff options
104 files changed, 9696 insertions, 795 deletions
diff --git a/addons/CMakeLists.txt b/addons/CMakeLists.txt index 1b666404..1d5c82ea 100644 --- a/addons/CMakeLists.txt +++ b/addons/CMakeLists.txt @@ -36,6 +36,13 @@ set(SOURCES # {{END_TARGET_SOURCES}} ) +# Append BSD file if the user wants it +if(NXD_ENABLE_FILE_BSD) + list(APPEND SOURCES + ${CMAKE_CURRENT_LIST_DIR}/BSD/nxd_bsd.c + ) +endif() + # Remove the file server files if the user doesn't want them if(NOT NXD_ENABLE_FILE_SERVERS) list(REMOVE_ITEM SOURCES diff --git a/addons/ftp/nxd_ftp_client.c b/addons/ftp/nxd_ftp_client.c index e85ed09e..eb7a32bf 100644 --- a/addons/ftp/nxd_ftp_client.c +++ b/addons/ftp/nxd_ftp_client.c @@ -4832,7 +4832,7 @@ UINT status; /* FUNCTION RELEASE */ /* */ /* _nx_ftp_client_active_transfer_setup PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -4877,6 +4877,9 @@ UINT status; /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* fixed packet leak, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_ftp_client_active_transfer_setup(NX_FTP_CLIENT *ftp_client_ptr, ULONG wait_option) @@ -5132,6 +5135,9 @@ UINT ipduo_size; return(NX_FTP_EXPECTED_2XX_CODE); } + /* Release the packet. */ + nx_packet_release(packet_ptr); + return(NX_SUCCESS); } diff --git a/addons/pppoe/nx_pppoe_client.h b/addons/pppoe/nx_pppoe_client.h index 170e69a4..1baf7bdb 100644 --- a/addons/pppoe/nx_pppoe_client.h +++ b/addons/pppoe/nx_pppoe_client.h @@ -349,4 +349,4 @@ VOID _nx_pppoe_client_packet_deferred_receive(NX_PACKET *packet_ptr); } #endif -#endif /* NX_PPP_CLIENT_H */ +#endif /* NX_PPPOE_CLIENT_H */ diff --git a/addons/pppoe/nx_pppoe_server.h b/addons/pppoe/nx_pppoe_server.h index acc8db97..a324a883 100644 --- a/addons/pppoe/nx_pppoe_server.h +++ b/addons/pppoe/nx_pppoe_server.h @@ -373,4 +373,4 @@ VOID _nx_pppoe_server_packet_deferred_receive(NX_PACKET *packet_ptr); } #endif -#endif /* NX_PPP_SERVER_H */ +#endif /* NX_PPPOE_SERVER_H */ diff --git a/common/inc/nx_api.h b/common/inc/nx_api.h index 49bbc8f7..4f021258 100644 --- a/common/inc/nx_api.h +++ b/common/inc/nx_api.h @@ -26,7 +26,7 @@ /* APPLICATION INTERFACE DEFINITION RELEASE */ /* */ /* nx_api.h PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -49,6 +49,9 @@ /* ThreadX version check, */ /* updated product constants, */ /* resulting in version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* updated product constants, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -456,7 +459,7 @@ VOID _nx_trace_event_update(TX_TRACE_BUFFER_ENTRY *event, ULONG timestamp, ULONG #define AZURE_RTOS_NETXDUO #define NETXDUO_MAJOR_VERSION 6 #define NETXDUO_MINOR_VERSION 0 -#define NETXDUO_PATCH_VERSION 1 +#define NETXDUO_PATCH_VERSION 2 /* Define the following symbols for backward compatibility */ #define EL_PRODUCT_NETXDUO diff --git a/common/src/nx_icmpv6_process_ra.c b/common/src/nx_icmpv6_process_ra.c index 47528d0e..6d067297 100644 --- a/common/src/nx_icmpv6_process_ra.c +++ b/common/src/nx_icmpv6_process_ra.c @@ -37,7 +37,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_icmpv6_process_ra PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -76,6 +76,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), improved */ +/* option length verification, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ VOID _nx_icmpv6_process_ra(NX_IP *ip_ptr, NX_PACKET *packet_ptr) @@ -237,6 +240,19 @@ UINT interface_index; if (option_ptr -> nx_icmpv6_option_type == ICMPV6_OPTION_TYPE_PREFIX_INFO) { + /* Validate packet length before cast to avoid OOB access. */ + if (packet_length < (INT)sizeof(NX_ICMPV6_OPTION_PREFIX)) + { +#ifndef NX_DISABLE_ICMP_INFO + + /* Increment the ICMP invalid packet error. */ + ip_ptr -> nx_ip_icmp_invalid_packets++; +#endif /* NX_DISABLE_ICMP_INFO */ + + _nx_packet_release(packet_ptr); + return; + } + /* Yes, set a local pointer to the option. */ /*lint -e{929} -e{826} -e{740} suppress cast of pointer to pointer, since it is necessary */ prefix_ptr = (NX_ICMPV6_OPTION_PREFIX *)option_ptr; diff --git a/common/src/nx_ipv6_process_fragment_option.c b/common/src/nx_ipv6_process_fragment_option.c index a856443d..7a7e7db6 100644 --- a/common/src/nx_ipv6_process_fragment_option.c +++ b/common/src/nx_ipv6_process_fragment_option.c @@ -41,7 +41,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_ipv6_process_fragment_option PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -77,6 +77,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), improved */ +/* packet length verification, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_ipv6_process_fragment_option(NX_IP *ip_ptr, NX_PACKET *packet_ptr) @@ -103,6 +106,12 @@ NX_IPV6_HEADER_FRAGMENT_OPTION *fragment_option; return(NX_OPTION_HEADER_ERROR); } + /* Check packet length is at least sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION). */ + if (packet_ptr -> nx_packet_length < sizeof(NX_IPV6_HEADER_FRAGMENT_OPTION)) + { + return(NX_OPTION_HEADER_ERROR); + } + /* Set a pointer to the starting of the fragment option. */ /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ fragment_option = (NX_IPV6_HEADER_FRAGMENT_OPTION *)packet_ptr -> nx_packet_prepend_ptr; diff --git a/common/src/nx_ipv6_process_routing_option.c b/common/src/nx_ipv6_process_routing_option.c index 3ca2b24b..984cef74 100644 --- a/common/src/nx_ipv6_process_routing_option.c +++ b/common/src/nx_ipv6_process_routing_option.c @@ -38,7 +38,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_ipv6_process_routing_option PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ @@ -70,6 +70,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), improved */ +/* packet length verification, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_ipv6_process_routing_option(NX_IP *ip_ptr, NX_PACKET *packet_ptr) @@ -84,6 +87,12 @@ UINT base_offset; /* Add debug information. */ NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr); + /* Check packet length is at least sizeof(NX_IPV6_HEADER_ROUTING_OPTION). */ + if (packet_ptr -> nx_packet_length < sizeof(NX_IPV6_HEADER_ROUTING_OPTION)) + { + return(NX_OPTION_HEADER_ERROR); + } + /* Set a pointer to the routing header. */ /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ option = (NX_IPV6_HEADER_ROUTING_OPTION *)(packet_ptr -> nx_packet_prepend_ptr); diff --git a/crypto_libraries/inc/nx_crypto_huge_number.h b/crypto_libraries/inc/nx_crypto_huge_number.h index 2d338ff6..5a7b0894 100644 --- a/crypto_libraries/inc/nx_crypto_huge_number.h +++ b/crypto_libraries/inc/nx_crypto_huge_number.h @@ -26,7 +26,7 @@ /* APPLICATION INTERFACE DEFINITION RELEASE */ /* */ /* nx_crypto_huge_number.h PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -41,6 +41,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), and */ +/* fixed number initialization,*/ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -146,7 +149,7 @@ typedef struct NX_CRYPTO_HUGE_NUMBER_STRUCT /* Initialize the buffer of huge number to variable between 0 and (HN_RADIX - 1). */ #define NX_CRYPTO_HUGE_NUMBER_INITIALIZE_DIGIT(hn, buff, val) \ (hn) -> nx_crypto_huge_number_data = (HN_UBASE *)(buff); \ - (hn) -> nx_crypto_huge_buffer_size = sizeof(buff); \ + (hn) -> nx_crypto_huge_buffer_size = sizeof(HN_UBASE); \ NX_CRYPTO_HUGE_NUMBER_SET_DIGIT(hn, val) /* Copy huge number from src to dst. */ diff --git a/crypto_libraries/src/nx_crypto_generic_ciphersuites.c b/crypto_libraries/src/nx_crypto_generic_ciphersuites.c index d62de2ce..a2606505 100644 --- a/crypto_libraries/src/nx_crypto_generic_ciphersuites.c +++ b/crypto_libraries/src/nx_crypto_generic_ciphersuites.c @@ -28,7 +28,7 @@ /* FUNCTION RELEASE */ /* */ /* nx_crypto_generic_ciphersuites PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -61,6 +61,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), added */ +/* curves in the crypto array, */ +/* added TLS ciphersuite entry,*/ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -336,6 +340,24 @@ const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_rsa_with_aes_128_cbc_sha256 = (NX_SECURE_TLS_BITFIELD_VERSIONS_PRE_1_3 | NX_SECURE_DTLS_BITFIELD_VERSIONS_PRE_1_3) }; +const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_ecdhe_rsa_with_aes_128_cbc_sha256 = +/* TLS ciphersuite entry. */ +{ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, /* Ciphersuite ID. */ + NX_SECURE_APPLICATION_TLS, /* Internal application label. */ + 16, /* Symmetric key size. */ + { /* Cipher role array. */ + {NX_CRYPTO_KEY_EXCHANGE_ECDHE, NX_CRYPTO_ROLE_KEY_EXCHANGE}, + {NX_CRYPTO_KEY_EXCHANGE_RSA, NX_CRYPTO_ROLE_SIGNATURE_CRYPTO}, + {NX_CRYPTO_ENCRYPTION_AES_CBC, NX_CRYPTO_ROLE_SYMMETRIC}, + {NX_CRYPTO_AUTHENTICATION_HMAC_SHA2_256, NX_CRYPTO_ROLE_MAC_HASH}, + {NX_CRYPTO_HASH_SHA256, NX_CRYPTO_ROLE_RAW_HASH}, + {NX_CRYPTO_HASH_HMAC, NX_CRYPTO_ROLE_HMAC}, + {NX_CRYPTO_PRF_HMAC_SHA2_256, NX_CRYPTO_ROLE_PRF}, + {NX_CRYPTO_NONE, NX_CRYPTO_ROLE_NONE} + }, + /* TLS/DTLS Versions supported. */ + (NX_SECURE_TLS_BITFIELD_VERSIONS_PRE_1_3 | NX_SECURE_DTLS_BITFIELD_VERSIONS_PRE_1_3) +}; const NX_CRYPTO_CIPHERSUITE nx_crypto_tls_ecdhe_rsa_with_aes_128_gcm_sha256 = /* TLS ciphersuite entry. */ @@ -554,17 +576,17 @@ const NX_CRYPTO_METHOD *supported_crypto[] = &crypto_method_none, &crypto_method_rsa, &crypto_method_pkcs1, - &crypto_method_ecdhe, + &crypto_method_ecdhe, &crypto_method_ecdsa, - &crypto_method_aes_ccm_8, - &crypto_method_aes_cbc_128, - &crypto_method_aes_cbc_256, - &crypto_method_aes_128_gcm_16, - &crypto_method_aes_256_gcm_16, + &crypto_method_aes_ccm_8, + &crypto_method_aes_cbc_128, + &crypto_method_aes_cbc_256, + &crypto_method_aes_128_gcm_16, + &crypto_method_aes_256_gcm_16, &crypto_method_hmac, - &crypto_method_hmac_md5, - &crypto_method_hmac_sha1, - &crypto_method_hmac_sha256, + &crypto_method_hmac_md5, + &crypto_method_hmac_sha1, + &crypto_method_hmac_sha256, &crypto_method_md5, &crypto_method_sha1, &crypto_method_sha224, @@ -574,6 +596,9 @@ const NX_CRYPTO_METHOD *supported_crypto[] = &crypto_method_tls_prf_1, &crypto_method_tls_prf_sha256, &crypto_method_hkdf, + &crypto_method_ec_secp256, + &crypto_method_ec_secp384, + &crypto_method_ec_secp521, }; const UINT supported_crypto_size = sizeof(supported_crypto) / sizeof(NX_CRYPTO_METHOD*); diff --git a/crypto_libraries/src/nx_crypto_huge_number.c b/crypto_libraries/src/nx_crypto_huge_number.c index 061251e9..156a3e39 100644 --- a/crypto_libraries/src/nx_crypto_huge_number.c +++ b/crypto_libraries/src/nx_crypto_huge_number.c @@ -1310,7 +1310,7 @@ UINT i, j; /* FUNCTION RELEASE */ /* */ /* _nx_crypto_huge_number_modulus PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -1377,6 +1377,9 @@ UINT i, j; /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), and */ +/* fixed variable type issue, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ NX_CRYPTO_KEEP VOID _nx_crypto_huge_number_modulus(NX_CRYPTO_HUGE_NUMBER *dividend, NX_CRYPTO_HUGE_NUMBER *divisor) @@ -1476,7 +1479,7 @@ NX_CRYPTO_HUGE_NUMBER *result; } else { - scale = (dividend_msb / divisor_msb) << (HN_SHIFT >> 1); + scale = ((HN_UBASE2)(dividend_msb / divisor_msb)) << (HN_SHIFT >> 1); } } else if (shift) diff --git a/nx_secure/CMakeLists.txt b/nx_secure/CMakeLists.txt index a7e51223..b225f781 100644 --- a/nx_secure/CMakeLists.txt +++ b/nx_secure/CMakeLists.txt @@ -98,6 +98,7 @@ target_sources(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/src/nx_secure_tls_metadata_size_calculate.c ${CMAKE_CURRENT_LIST_DIR}/src/nx_secure_tls_newest_supported_version.c ${CMAKE_CURRENT_LIST_DIR}/src/nx_secure_tls_packet_allocate.c + ${CMAKE_CURRENT_LIST_DIR}/src/nx_secure_tls_packet_release.c ${CMAKE_CURRENT_LIST_DIR}/src/nx_secure_tls_process_certificate_request.c ${CMAKE_CURRENT_LIST_DIR}/src/nx_secure_tls_process_certificate_verify.c ${CMAKE_CURRENT_LIST_DIR}/src/nx_secure_tls_process_changecipherspec.c diff --git a/nx_secure/inc/nx_secure_tls.h b/nx_secure/inc/nx_secure_tls.h index b8b7cdc8..64dc3e1c 100644 --- a/nx_secure/inc/nx_secure_tls.h +++ b/nx_secure/inc/nx_secure_tls.h @@ -26,7 +26,7 @@ /* COMPONENT DEFINITION RELEASE */ /* */ /* nx_secure_tls.h PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -48,6 +48,12 @@ /* curve logic, updated product*/ /* constants, */ /* resulting in version 6.0.1 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), and */ +/* supported chained packet, */ +/* fixed renegotiation bug, */ +/* added new API on tls */ +/* protocol version negotiation*/ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -108,7 +114,7 @@ extern "C" { #define AZURE_RTOS_NETX_SECURE #define NETX_SECURE_MAJOR_VERSION 6 #define NETX_SECURE_MINOR_VERSION 0 -#define NETX_SECURE_PATCH_VERSION 1 +#define NETX_SECURE_PATCH_VERSION 2 /* The following symbols are defined for backward compatibility reasons. */ #define EL_PRODUCT_NETX_SECURE @@ -148,8 +154,13 @@ extern "C" { /* Configuration macro: allow self-signed certificates to be used to identify a remote host. */ /* #define NX_SECURE_ALLOW_SELF_SIGNED_CERTIFICATES */ -/* Configuration macro: enable secure session renegotiation extension (RFC 5746). */ -#define NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +/* Configuration macro: disable secure session renegotiation extension (RFC 5746). + #define NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION + */ +/* Configuration macro: terminate the connection immediately upon failure to receive the + secure renegotiation extension during the initial handshake. + #define NX_SECURE_TLS_REQUIRE_RENEGOTIATION_EXT + */ /* API return values. */ @@ -1055,9 +1066,7 @@ typedef struct NX_SECURE_TLS_SESSION_STRUCT /* Queue the incoming packets for one record. */ NX_PACKET *nx_secure_record_queue_header; - NX_PACKET *nx_secure_record_queue_tail; NX_PACKET *nx_secure_record_decrypted_packet; - ULONG nx_secure_record_queue_length; /* Packet pool used by TLS stack to allocate outgoing packets used in TLS handshake. */ NX_PACKET_POOL *nx_secure_tls_packet_pool; @@ -1086,6 +1095,9 @@ typedef struct NX_SECURE_TLS_SESSION_STRUCT /* This field overrides the version returned by _nx_secure_tls_newest_supported_version. */ USHORT nx_secure_tls_protocol_version_override; + /* The highest supported protocol version obtained through negotiation. */ + USHORT nx_secure_tls_negotiated_highest_protocol_version; + /* State of local and remote encryption - post ChangeCipherSpec. */ UCHAR nx_secure_tls_remote_session_active; UCHAR nx_secure_tls_local_session_active; @@ -1105,17 +1117,21 @@ typedef struct NX_SECURE_TLS_SESSION_STRUCT /* Session ID used for session re-negotiation. */ UCHAR nx_secure_tls_session_id[NX_SECURE_TLS_SESSION_ID_SIZE]; -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION /* This flag indicates whether the remote host supports secure renegotiation as indicated in the initial Hello messages (SCSV or the renegotiation extension were provided). */ USHORT nx_secure_tls_secure_renegotiation; + /* This flag indicates whether the renegotiation_info extension is present and + the data in the extension is verified during secure renegotiation. */ + USHORT nx_secure_tls_secure_renegotiation_verified; + /* The verify data is named "remote" and "local" since it can be used by both TLS Client and TLS Server instances. */ UCHAR nx_secure_tls_remote_verify_data[NX_SECURE_TLS_FINISHED_HASH_SIZE]; UCHAR nx_secure_tls_local_verify_data[NX_SECURE_TLS_FINISHED_HASH_SIZE]; -#endif +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ /* Sequence number for the current TLS session - local host. */ @@ -1144,12 +1160,14 @@ typedef struct NX_SECURE_TLS_SESSION_STRUCT /* This mutex used for TLS session while transmitting packets. */ TX_MUTEX nx_secure_tls_session_transmit_mutex; +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION /* If we receive a hello message from the remote server during a session, we have a re-negotiation handshake we need to process. */ USHORT nx_secure_tls_renegotiation_handshake; /* Flag to enable/disable session renegotiation at application's choosing. */ USHORT nx_secure_tls_renegotation_enabled; +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ #ifndef NX_SECURE_TLS_SERVER_DISABLED /* The state of the server handshake if this is a server socket. */ @@ -1222,8 +1240,10 @@ typedef struct NX_SECURE_TLS_SESSION_STRUCT by the application before being accepted. */ ULONG (*nx_secure_tls_session_certificate_callback)(struct NX_SECURE_TLS_SESSION_STRUCT *session, NX_SECURE_X509_CERT *certificate); +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION /* Function (set by user) to call when TLS receives a re-negotiation request from the remote host. */ ULONG (*nx_secure_tls_session_renegotiation_callback)(struct NX_SECURE_TLS_SESSION_STRUCT *session); +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ /* Function (set by user) to call when a TLS Client receives a ServerHello message containing extensions that require specific actions. */ @@ -1286,6 +1306,11 @@ typedef struct NX_SECURE_TLS_SESSION_STRUCT /* Declare internal functions. */ +#ifdef NX_SECURE_KEY_CLEAR +#define nx_secure_tls_packet_release _nx_secure_tls_packet_release +#else +#define nx_secure_tls_packet_release nx_packet_release +#endif /* NX_SECURE_KEY_CLEAR */ #if (NX_SECURE_TLS_TLS_1_3_ENABLED) UINT _nx_secure_tls_1_3_crypto_init(NX_SECURE_TLS_SESSION *tls_session); @@ -1329,15 +1354,19 @@ UINT _nx_secure_tls_handshake_hash_init(NX_SECURE_TLS_SESSION *tls_session); UINT _nx_secure_tls_handshake_hash_update(NX_SECURE_TLS_SESSION *tls_session, UCHAR *data, UINT length); UINT _nx_secure_tls_handshake_process(NX_SECURE_TLS_SESSION *tls_session, UINT wait_option); -UINT _nx_secure_tls_hash_record(NX_SECURE_TLS_SESSION * tls_session, +UINT _nx_secure_tls_hash_record(NX_SECURE_TLS_SESSION *tls_session, ULONG sequence_num[NX_SECURE_TLS_SEQUENCE_NUMBER_SIZE], - UCHAR * header, UINT header_length, UCHAR * data, UINT length, - UCHAR * record_hash, UINT * hash_length, UCHAR * mac_secret); + UCHAR *header, UINT header_length, NX_PACKET *packet_ptr, + ULONG offset, UINT length, UCHAR *record_hash, UINT *hash_length, + UCHAR *mac_secret); UINT _nx_secure_tls_key_material_init(NX_SECURE_TLS_KEY_MATERIAL *key_material); VOID _nx_secure_tls_map_error_to_alert(UINT error_number, UINT *alert_number, UINT *alert_level); VOID _nx_secure_tls_newest_supported_version(NX_SECURE_TLS_SESSION *session_ptr, USHORT *protocol_version, UINT id); +VOID _nx_secure_tls_highest_supported_version_negotiate(NX_SECURE_TLS_SESSION *session_ptr, + USHORT *protocol_version, UINT id); +UINT _nx_secure_tls_packet_release(NX_PACKET *packet_ptr); VOID _nx_secure_tls_protocol_version_get(NX_SECURE_TLS_SESSION *session_ptr, USHORT *protocol_version, UINT id); UINT _nx_secure_tls_process_certificate_request(NX_SECURE_TLS_SESSION *tls_session, @@ -1383,10 +1412,10 @@ UINT _nx_secure_tls_record_hash_initialize(NX_SECURE_TLS_SESSION *tls_session, UCHAR *mac_secret); UINT _nx_secure_tls_record_hash_update(NX_SECURE_TLS_SESSION *tls_session, UCHAR *data, UINT length); -UINT _nx_secure_tls_record_payload_decrypt(NX_SECURE_TLS_SESSION *tls_session, UCHAR *data, - UINT *length, +UINT _nx_secure_tls_record_payload_decrypt(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *encrypted_packet, + UINT offset, UINT message_length, NX_PACKET **decrypted_packet, ULONG sequence_num[NX_SECURE_TLS_SEQUENCE_NUMBER_SIZE], - UCHAR record_type); + UCHAR record_type, UINT wait_option); UINT _nx_secure_tls_record_payload_encrypt(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *send_packet, ULONG sequence_num[NX_SECURE_TLS_SEQUENCE_NUMBER_SIZE], @@ -1435,7 +1464,7 @@ UINT _nx_secure_tls_session_keys_set(NX_SECURE_TLS_SESSION *tls_session, USHORT UINT _nx_secure_tls_session_receive_records(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET **packet_ptr_ptr, ULONG wait_option); UINT _nx_secure_tls_verify_mac(NX_SECURE_TLS_SESSION *tls_session, UCHAR *header_data, - USHORT header_length, UCHAR *data, UINT *length); + USHORT header_length, NX_PACKET *packet_ptr, ULONG offset, UINT *length); #ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE UINT _nx_secure_tls_ecc_generate_keys(NX_SECURE_TLS_SESSION *tls_session, UINT ecc_named_curve, USHORT sign_key, UCHAR *public_key, UINT *public_key_size, NX_SECURE_TLS_ECDHE_HANDSHAKE_DATA *ecc_data); diff --git a/nx_secure/inc/nx_secure_user_sample.h b/nx_secure/inc/nx_secure_user_sample.h index 6d97f72b..2087e512 100644 --- a/nx_secure/inc/nx_secure_user_sample.h +++ b/nx_secure/inc/nx_secure_user_sample.h @@ -26,7 +26,7 @@ /* PORT SPECIFIC C INFORMATION RELEASE */ /* */ /* nx_secure_user.h PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* */ /* AUTHOR */ /* */ @@ -46,6 +46,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), and */ +/* added new macros for TLS */ +/* protocol version negotiation*/ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -272,6 +276,19 @@ #define NX_SECURE_TLS_USE_SCSV_CIPHPERSUITE */ +/* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION disables secure session renegotiation extension (RFC 5746). + By default this feature is enabled. */ +/* + #define NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION +*/ + +/* NX_SECURE_TLS_REQUIRE_RENEGOTIATION_EXT defines whether or not the connection should be terminated immediately + upon failure to receive the secure renegotiation extension during the initial handshake. + By default the connection is not terminated. */ +/* + #define NX_SECURE_TLS_REQUIRE_RENEGOTIATION_EXT +*/ + /* NX_SECURE_X509_DISABLE_CRL disables X509 Certificate Revocation List check. By default this feature is enabled. */ /* diff --git a/nx_secure/src/nx_secure_dtls_client_handshake.c b/nx_secure/src/nx_secure_dtls_client_handshake.c index 1fc92be8..c6250173 100644 --- a/nx_secure/src/nx_secure_dtls_client_handshake.c +++ b/nx_secure/src/nx_secure_dtls_client_handshake.c @@ -32,7 +32,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_client_handshake PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -90,7 +90,7 @@ /* Send ClientKeyExchange */ /* _nx_secure_tls_send_finished Send Finished message */ /* _nx_secure_tls_session_keys_set Set session keys */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -103,6 +103,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), and */ +/* supported chained packet, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_client_handshake(NX_SECURE_DTLS_SESSION *dtls_session, UCHAR *packet_buffer, @@ -516,7 +519,7 @@ NX_SECURE_TLS_SESSION *tls_session; if (status != NX_SUCCESS) { /* Release packet on send error. */ - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); break; } /* The local session is now active since we sent the changecipherspec message. diff --git a/nx_secure/src/nx_secure_dtls_process_clienthello.c b/nx_secure/src/nx_secure_dtls_process_clienthello.c index c68c00d9..8fc8fe91 100644 --- a/nx_secure/src/nx_secure_dtls_process_clienthello.c +++ b/nx_secure/src/nx_secure_dtls_process_clienthello.c @@ -40,7 +40,7 @@ static UINT _nx_secure_dtls_check_ciphersuite(const NX_SECURE_TLS_CIPHERSUITE_IN /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_process_clienthello PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -87,6 +87,10 @@ static UINT _nx_secure_dtls_check_ciphersuite(const NX_SECURE_TLS_CIPHERSUITE_IN /* that would result in */ /* compiler error, */ /* resulting in version 6.0.1 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* improved negotiation logic, */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_process_clienthello(NX_SECURE_DTLS_SESSION *dtls_session, UCHAR *packet_buffer, @@ -145,6 +149,14 @@ NX_SECURE_TLS_ECDHE_HANDSHAKE_DATA *ecdhe_data; /* Get a reference to TLS state. */ tls_session = &dtls_session -> nx_secure_dtls_tls_session; + /* If we are currently in a session, we have a renegotiation handshake. */ + if (tls_session -> nx_secure_tls_local_session_active) + { + + /* Session renegotiation is disabled, send a "no_renegotiation" alert! */ + return(NX_SECURE_TLS_NO_RENEGOTIATION_ERROR); + } + /* Client is establishing a TLS session with our server. */ /* Extract the protocol version - only part of the ClientHello message. */ protocol_version = (USHORT)(((USHORT)packet_buffer[0] << 8) | packet_buffer[1]); @@ -161,9 +173,9 @@ NX_SECURE_TLS_ECDHE_HANDSHAKE_DATA *ecdhe_data; if (status == NX_SECURE_TLS_UNSUPPORTED_TLS_VERSION || tls_session -> nx_secure_tls_local_session_active) { /* If the version isn't supported, it's not an issue - TLS is backward-compatible, - * so pick the highest version we do support. If the version isn't recognized, + * so negotiate the highest supported version. If the version isn't recognized, * flag an error. */ - _nx_secure_tls_newest_supported_version(tls_session, &protocol_version, NX_SECURE_DTLS); + _nx_secure_tls_highest_supported_version_negotiate(tls_session, &protocol_version, NX_SECURE_DTLS); if (protocol_version == 0x0) { diff --git a/nx_secure/src/nx_secure_dtls_process_record.c b/nx_secure/src/nx_secure_dtls_process_record.c index 4f9ad032..4cd6e1e5 100644 --- a/nx_secure/src/nx_secure_dtls_process_record.c +++ b/nx_secure/src/nx_secure_dtls_process_record.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_process_record PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -63,6 +63,7 @@ /* _nx_secure_tls_process_changecipherspec */ /* Process ChangeCipherSpec */ /* _nx_secure_tls_record_payload_decrypt Decrypt record data */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -75,12 +76,17 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* adjusted logic for TLS */ +/* modifications, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_process_record(NX_SECURE_DTLS_SESSION *dtls_session, NX_PACKET *packet_ptr, ULONG record_offset, ULONG *bytes_processed, ULONG wait_option) { UINT status; +UINT error_status; USHORT header_length; UCHAR header_data[NX_SECURE_DTLS_RECORD_HEADER_SIZE]; /* DTLS record header is larger than TLS. Allocate enough space for both. */ USHORT message_type; @@ -88,6 +94,7 @@ UINT message_length; UCHAR *packet_data; NX_SECURE_TLS_SESSION *tls_session; UCHAR epoch_seq_num[8]; +NX_PACKET *decrypted_packet; /* Basic state machine: * 1. Process header, which will set the state and return some data. @@ -156,15 +163,56 @@ UCHAR epoch_seq_num[8]; epoch_seq_num[7] = header_data[3]; /* Decrypt the record data. */ - status = _nx_secure_tls_record_payload_decrypt(tls_session, packet_data, &message_length, (ULONG *)epoch_seq_num, (UCHAR)message_type); + status = _nx_secure_tls_record_payload_decrypt(tls_session, packet_ptr, header_length, message_length, + &decrypted_packet, (ULONG *)epoch_seq_num, (UCHAR)message_type, + wait_option); - /* Check the MAC hash if we were able to decrypt the record. */ + /* Check the MAC hash. */ if (status == NX_SECURE_TLS_SUCCESS) { + /* Verify the hash MAC in the decrypted record. */ - status = _nx_secure_dtls_verify_mac(dtls_session, header_data, header_length, packet_data, &message_length); + packet_data = decrypted_packet -> nx_packet_prepend_ptr; + message_length = (UINT)decrypted_packet -> nx_packet_length; + error_status = NX_SECURE_TLS_SUCCESS; + } + else + { + + /* Save off the error status so we can return it after the mac check. */ + error_status = status; + } + + /* !!! NOTE - the MAC check MUST always be performed regardless of the error state of + the payload decryption operation. Skipping the MAC check on padding failures + could enable a timing-based attack allowing an attacker to determine whether + padding was valid or not, causing an information leak. */ + status = _nx_secure_dtls_verify_mac(dtls_session, header_data, header_length, packet_data, &message_length); + + /* Check to see if decryption or verification failed. */ + if(error_status != NX_SECURE_TLS_SUCCESS) + { + /* Decryption failed. */ + return(error_status); + } + + /* Check to see if decryption or verification failed. */ + if (status == NX_SECURE_TLS_SUCCESS) + { + + /* Copy data to original packet to keep IP header available. */ + /* Note: At the point of this memcpy the plaintext should never be larger than the cipher. + Assertion check is to protect against future changes inadvertently causing an overflow. */ + NX_ASSERT((ULONG)(packet_ptr -> nx_packet_data_end - packet_ptr -> nx_packet_prepend_ptr) >= message_length); + NX_SECURE_MEMCPY(packet_ptr -> nx_packet_prepend_ptr, packet_data, message_length); /* Use case of memcpy is verified. */ + packet_data = packet_ptr -> nx_packet_prepend_ptr; + packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + message_length; + packet_ptr -> nx_packet_length = message_length; } + /* Release decrypted packet. */ + nx_secure_tls_packet_release(decrypted_packet); + /* Check to see if decryption or verification failed. */ if (status != NX_SECURE_TLS_SUCCESS) { @@ -220,19 +268,6 @@ UCHAR epoch_seq_num[8]; { status = NX_CONTINUE; } - else - { - - /* Release the protection before suspending on nx_packet_data_append. */ - tx_mutex_put(&_nx_secure_tls_protection); - - packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr; - packet_ptr -> nx_packet_length = message_length; - NX_SECURE_MEMMOVE(packet_ptr -> nx_packet_append_ptr, packet_data, message_length); - packet_ptr -> nx_packet_append_ptr += message_length; - /* Get the protection after nx_packet_data_append. */ - tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER); - } break; default: /* An unrecognized message was received, likely an error, possibly an attack. */ diff --git a/nx_secure/src/nx_secure_dtls_receive_callback.c b/nx_secure/src/nx_secure_dtls_receive_callback.c index ee93e999..67aede9c 100644 --- a/nx_secure/src/nx_secure_dtls_receive_callback.c +++ b/nx_secure/src/nx_secure_dtls_receive_callback.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_receive_callback PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -60,7 +60,7 @@ /* _nx_udp_socket_port_get Get local port */ /* nx_secure_dtls_session_cache_find Check DTLS session cache */ /* nx_secure_dtls_session_cache_get_new Get new DTLS session */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* nx_packet_allocate Allocate packet */ /* _nxd_udp_socket_send Send UDP packet */ /* nx_udp_socket_receive Receive packet */ @@ -80,6 +80,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ VOID _nx_secure_dtls_receive_callback(NX_UDP_SOCKET *socket_ptr) @@ -127,7 +130,7 @@ NX_SECURE_DTLS_SESSION *dtls_session; /* Check session cache for existing DTLS session. */ status = nx_secure_dtls_session_cache_find(dtls_server, &dtls_session, &ip_address, remote_port, local_port); - /* Do we have an establised session? */ + /* Do we have an established session? */ if(status == NX_SECURE_DTLS_SESSION_NOT_FOUND) { @@ -157,7 +160,7 @@ NX_SECURE_DTLS_SESSION *dtls_session; TX_RESTORE /* Release the packet. */ - nx_packet_release(packet_ptr); + nx_secure_tls_packet_release(packet_ptr); return; } @@ -194,7 +197,7 @@ NX_SECURE_DTLS_SESSION *dtls_session; TX_RESTORE /* Release the packet. */ - nx_packet_release(packet_ptr); + nx_secure_tls_packet_release(packet_ptr); /* Get a packet to send the alert to the client. */ if (ip_address.nxd_ip_version == NX_IP_VERSION_V4) @@ -217,7 +220,7 @@ NX_SECURE_DTLS_SESSION *dtls_session; { /* Packet buffer too small. */ - nx_packet_release(packet_ptr); + nx_secure_tls_packet_release(packet_ptr); return; } diff --git a/nx_secure/src/nx_secure_dtls_retransmit_queue_flush.c b/nx_secure/src/nx_secure_dtls_retransmit_queue_flush.c index 00dc0154..14091a8d 100644 --- a/nx_secure/src/nx_secure_dtls_retransmit_queue_flush.c +++ b/nx_secure/src/nx_secure_dtls_retransmit_queue_flush.c @@ -32,7 +32,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_retransmit_queue_flush PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -53,7 +53,7 @@ /* */ /* CALLS */ /* */ -/* nx_packet_release Release the packet */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -68,6 +68,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ VOID _nx_secure_dtls_retransmit_queue_flush(NX_SECURE_DTLS_SESSION *dtls_session) @@ -113,7 +116,7 @@ NX_PACKET *next_packet_ptr; TX_RESTORE /* Release the packet. */ - nx_packet_release(packet_ptr); + nx_secure_tls_packet_release(packet_ptr); } else { diff --git a/nx_secure/src/nx_secure_dtls_send_handshake_record.c b/nx_secure/src/nx_secure_dtls_send_handshake_record.c index 0390b3ff..2b9062ed 100644 --- a/nx_secure/src/nx_secure_dtls_send_handshake_record.c +++ b/nx_secure/src/nx_secure_dtls_send_handshake_record.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_send_handshake_record PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -58,7 +58,7 @@ /* */ /* _nx_secure_dtls_send_record Send the DTLS record */ /* _nx_secure_tls_handshake_hash_update Update Finished message hash */ -/* nx_packet_release Release the packet */ +/* nx_secure_tls_packet_release Release packet */ /* */ /* CALLED BY */ /* */ @@ -71,6 +71,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_send_handshake_record(NX_SECURE_DTLS_SESSION *dtls_session, @@ -161,7 +164,7 @@ ULONG fragment_length; if (status != NX_SUCCESS) { /* Release packet on send error. */ - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); } return(status); diff --git a/nx_secure/src/nx_secure_dtls_send_record.c b/nx_secure/src/nx_secure_dtls_send_record.c index 92cf1d9a..8bf44b05 100644 --- a/nx_secure/src/nx_secure_dtls_send_record.c +++ b/nx_secure/src/nx_secure_dtls_send_record.c @@ -33,7 +33,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_send_record PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -64,7 +64,7 @@ /* _nxd_udp_socket_send Send UDP packet */ /* _nxd_udp_socket_source_send Send UDP packet with specific */ /* source address */ -/* nx_packet_release Release packet (on error) */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -82,6 +82,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_send_record(NX_SECURE_DTLS_SESSION *dtls_session, NX_PACKET *send_packet, @@ -295,7 +298,7 @@ UCHAR epoch_seq_num[8]; if (status != NX_SUCCESS) { - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); return(NX_SECURE_TLS_TCP_SEND_FAILED); } diff --git a/nx_secure/src/nx_secure_dtls_server_handshake.c b/nx_secure/src/nx_secure_dtls_server_handshake.c index e367d142..772f614f 100644 --- a/nx_secure/src/nx_secure_dtls_server_handshake.c +++ b/nx_secure/src/nx_secure_dtls_server_handshake.c @@ -33,7 +33,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_server_handshake PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -103,6 +103,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_server_handshake(NX_SECURE_DTLS_SESSION *dtls_session, UCHAR *packet_buffer, @@ -255,12 +258,6 @@ UCHAR *fragment_buffer; { /* Initialize the handshake hashes used for the Finished message. */ _nx_secure_tls_handshake_hash_init(tls_session); - - /* At this point, the remote session is not active - that is, incoming records are not encrypted. */ - tls_session -> nx_secure_tls_remote_session_active = 0; - - /* Since we are establishing a new session, we start in non-encrypted mode. */ - tls_session -> nx_secure_tls_local_session_active = 0; } /* Process the message itself information from the header. */ diff --git a/nx_secure/src/nx_secure_dtls_session_end.c b/nx_secure/src/nx_secure_dtls_session_end.c index 75f75a11..400d72e1 100644 --- a/nx_secure/src/nx_secure_dtls_session_end.c +++ b/nx_secure/src/nx_secure_dtls_session_end.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_session_end PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -57,7 +57,7 @@ /* _nx_secure_dtls_send_record Send the CloseNotify */ /* _nx_secure_dtls_session_reset Clear out the session */ /* _nx_secure_dtls_session_receive Receive DTLS data */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -70,6 +70,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_session_end(NX_SECURE_DTLS_SESSION *dtls_session, UINT wait_option) @@ -94,19 +97,11 @@ NX_SECURE_TLS_SESSION *tls_session; tmp_ptr = tls_session -> nx_secure_record_queue_header; tls_session -> nx_secure_record_queue_header = tmp_ptr -> nx_packet_queue_next; tmp_ptr -> nx_packet_queue_next = NX_NULL; -#ifdef NX_SECURE_KEY_CLEAR - NX_SECURE_MEMSET(tmp_ptr -> nx_packet_prepend_ptr, 0, ((ULONG)(tmp_ptr -> nx_packet_append_ptr) - (ULONG)(tmp_ptr -> nx_packet_prepend_ptr))); -#endif /* NX_SECURE_KEY_CLEAR */ - nx_packet_release(tmp_ptr); + nx_secure_tls_packet_release(tmp_ptr); } if (tls_session -> nx_secure_record_decrypted_packet) { -#ifdef NX_SECURE_KEY_CLEAR - NX_SECURE_MEMSET((tls_session -> nx_secure_record_decrypted_packet) -> nx_packet_prepend_ptr, 0, - ((ULONG)(tls_session -> nx_secure_record_decrypted_packet -> nx_packet_append_ptr) - - (ULONG)(tls_session -> nx_secure_record_decrypted_packet -> nx_packet_prepend_ptr))); -#endif /* NX_SECURE_KEY_CLEAR */ - nx_packet_release(tls_session -> nx_secure_record_decrypted_packet); + nx_secure_tls_packet_release(tls_session -> nx_secure_record_decrypted_packet); tls_session -> nx_secure_record_decrypted_packet = NX_NULL; } @@ -152,12 +147,8 @@ NX_SECURE_TLS_SESSION *tls_session; if (status == NX_SUCCESS) { -#ifdef NX_SECURE_KEY_CLEAR - NX_SECURE_MEMSET(incoming_packet -> nx_packet_prepend_ptr, 0, ((ULONG)(incoming_packet -> nx_packet_append_ptr) - (ULONG)(incoming_packet -> nx_packet_prepend_ptr))); -#endif /* NX_SECURE_KEY_CLEAR */ - /* Release the alert packet. */ - nx_packet_release(incoming_packet); + nx_secure_tls_packet_release(incoming_packet); } else if ((status == NX_NO_PACKET) || (status == NX_SECURE_TLS_SESSION_UNINITIALIZED)) { diff --git a/nx_secure/src/nx_secure_dtls_session_receive.c b/nx_secure/src/nx_secure_dtls_session_receive.c index 908d2e75..5614c61d 100644 --- a/nx_secure/src/nx_secure_dtls_session_receive.c +++ b/nx_secure/src/nx_secure_dtls_session_receive.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_session_receive PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -58,7 +58,7 @@ /* _nx_secure_dtls_send_record Send the DTLS record */ /* _nx_secure_tls_map_error_to_alert Map internal error to alert */ /* _nx_secure_tls_send_alert Send TLS alert */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* nx_udp_socket_receive Receive UDP data */ /* nxd_udp_source_extract Extract UDP information */ /* tx_mutex_get Get protection mutex */ @@ -77,6 +77,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_session_receive(NX_SECURE_DTLS_SESSION *dtls_session, @@ -253,7 +256,7 @@ UINT source_port; { /* This packet is from unkown address or port. Ignore it. */ - nx_packet_release(packet_ptr); + nx_secure_tls_packet_release(packet_ptr); status = NX_CONTINUE; continue; } @@ -326,12 +329,8 @@ UINT source_port; if (status != NX_SUCCESS) { -#ifdef NX_SECURE_KEY_CLEAR - NX_SECURE_MEMSET(packet_ptr -> nx_packet_prepend_ptr, 0, ((ULONG)(packet_ptr -> nx_packet_append_ptr) - (ULONG)(packet_ptr -> nx_packet_prepend_ptr))); -#endif /* NX_SECURE_KEY_CLEAR */ - /* Clear out the packet, we don't want any of the data in it. */ - nx_packet_release(packet_ptr); + nx_secure_tls_packet_release(packet_ptr); if (status != NX_CONTINUE) { diff --git a/nx_secure/src/nx_secure_dtls_session_reset.c b/nx_secure/src/nx_secure_dtls_session_reset.c index 405ffdc2..9b2e3076 100644 --- a/nx_secure/src/nx_secure_dtls_session_reset.c +++ b/nx_secure/src/nx_secure_dtls_session_reset.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_session_reset PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -53,7 +53,7 @@ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* _nx_secure_tls_session_reset Clear out the session */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* */ /* CALLED BY */ /* */ @@ -68,6 +68,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_session_reset(NX_SECURE_DTLS_SESSION *dtls_session) @@ -132,7 +135,7 @@ NX_PACKET *next_packet_ptr; while (packet_ptr) { next_packet_ptr = packet_ptr -> nx_packet_queue_next; - nx_packet_release(packet_ptr); + nx_secure_tls_packet_release(packet_ptr); packet_ptr = next_packet_ptr; } diff --git a/nx_secure/src/nx_secure_dtls_session_start.c b/nx_secure/src/nx_secure_dtls_session_start.c index 435c848e..75c41122 100644 --- a/nx_secure/src/nx_secure_dtls_session_start.c +++ b/nx_secure/src/nx_secure_dtls_session_start.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_dtls_session_start PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -59,7 +59,7 @@ /* _nx_secure_dtls_send_clienthello Send ClientHello */ /* _nx_secure_dtls_send_handshake_record Send DTLS handshake record */ /* _nx_secure_dtls_session_receive Receive DTLS data */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -74,6 +74,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_dtls_session_start(NX_SECURE_DTLS_SESSION *dtls_session, NX_UDP_SOCKET *udp_socket, @@ -103,14 +107,18 @@ NX_PACKET *send_packet; /* Make sure we are starting with a fresh session. */ tls_session -> nx_secure_tls_received_remote_credentials = NX_FALSE; +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION + + /* Renegotiation is not enabled in DTLS session. */ + tls_session -> nx_secure_tls_renegotation_enabled = NX_FALSE; +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ + /* Assign the TCP socket to the TLS session. */ dtls_session -> nx_secure_dtls_udp_socket = udp_socket; /* Reset the record queue. */ tls_session -> nx_secure_record_queue_header = NX_NULL; - tls_session -> nx_secure_record_queue_tail = NX_NULL; tls_session -> nx_secure_record_decrypted_packet = NX_NULL; - tls_session -> nx_secure_record_queue_length = 0; /* See if this is a TCP server started with listen/accept, or a TCP client started with connect. */ if (is_client) @@ -159,7 +167,7 @@ NX_PACKET *send_packet; /* Release the protection. */ tx_mutex_put(&_nx_secure_tls_protection); - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); return(status); } } @@ -235,12 +243,8 @@ NX_PACKET *send_packet; else { -#ifdef NX_SECURE_KEY_CLEAR - NX_SECURE_MEMSET(incoming_packet -> nx_packet_prepend_ptr, 0, ((ULONG)(incoming_packet -> nx_packet_append_ptr) - (ULONG)(incoming_packet -> nx_packet_prepend_ptr))); -#endif /* NX_SECURE_KEY_CLEAR */ - /* On any error, the handshake has failed so break out of our processing loop and return. */ - nx_packet_release(incoming_packet); + nx_secure_tls_packet_release(incoming_packet); } } diff --git a/nx_secure/src/nx_secure_tls_1_3_client_handshake.c b/nx_secure/src/nx_secure_tls_1_3_client_handshake.c index 02cf7c15..79cf5fb4 100644 --- a/nx_secure/src/nx_secure_tls_1_3_client_handshake.c +++ b/nx_secure/src/nx_secure_tls_1_3_client_handshake.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_1_3_client_handshake PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -88,7 +88,7 @@ /* _nx_secure_tls_send_handshake_record Send TLS handshake record */ /* _nx_secure_tls_send_record Send TLS records */ /* _nx_secure_tls_session_keys_set Set session keys */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* [nx_secure_tls_session_renegotiation_callback] */ /* Renegotiation callback */ /* tx_mutex_get Get protection mutex */ @@ -103,6 +103,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -381,7 +384,7 @@ const UCHAR *server_random; if (status != NX_SUCCESS) { - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); } } return(error_number); @@ -448,7 +451,7 @@ const UCHAR *server_random; { /* Release the protection. */ - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); return(status); } break; @@ -685,7 +688,7 @@ const UCHAR *server_random; if (status != NX_SUCCESS) { - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); } } diff --git a/nx_secure/src/nx_secure_tls_1_3_server_handshake.c b/nx_secure/src/nx_secure_tls_1_3_server_handshake.c index c7fade95..98b68ef7 100644 --- a/nx_secure/src/nx_secure_tls_1_3_server_handshake.c +++ b/nx_secure/src/nx_secure_tls_1_3_server_handshake.c @@ -31,7 +31,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_server_handshake PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -81,7 +81,7 @@ /* Send ServerKeyExchange */ /* _nx_secure_tls_send_serverhello Send TLS ServerHello */ /* _nx_secure_tls_session_keys_set Set session keys */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -94,6 +94,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ #if (NX_SECURE_TLS_TLS_1_3_ENABLED) @@ -607,7 +610,7 @@ NX_SECURE_TLS_SERVER_STATE old_server_state; if (status != NX_SECURE_TLS_SUCCESS) { - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); } } diff --git a/nx_secure/src/nx_secure_tls_client_handshake.c b/nx_secure/src/nx_secure_tls_client_handshake.c index c7df9709..5168c9c8 100644 --- a/nx_secure/src/nx_secure_tls_client_handshake.c +++ b/nx_secure/src/nx_secure_tls_client_handshake.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_client_handshake PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -86,7 +86,7 @@ /* _nx_secure_tls_send_handshake_record Send TLS handshake record */ /* _nx_secure_tls_send_record Send TLS records */ /* _nx_secure_tls_session_keys_set Set session keys */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* [nx_secure_tls_session_renegotiation_callback] */ /* Renegotiation callback */ /* tx_mutex_get Get protection mutex */ @@ -101,6 +101,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_client_handshake(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, @@ -240,10 +244,11 @@ const NX_CRYPTO_METHOD * send a ClientHello (start the handshake again) or send a no_renegotiation alert. */ if (tls_session -> nx_secure_tls_local_session_active) { +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION /* A HelloRequest does not contain any data - it simply changes state. */ tls_session -> nx_secure_tls_client_state = NX_SECURE_TLS_CLIENT_STATE_HELLO_REQUEST; - if (tls_session -> nx_secure_tls_renegotation_enabled) + if (tls_session -> nx_secure_tls_renegotation_enabled && tls_session -> nx_secure_tls_secure_renegotiation) { tls_session -> nx_secure_tls_renegotiation_handshake = NX_TRUE; @@ -258,6 +263,7 @@ const NX_CRYPTO_METHOD } } else +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ { /* Session renegotiation is disabled, so this is an error! */ return(NX_SECURE_TLS_NO_RENEGOTIATION_ERROR); @@ -299,7 +305,7 @@ const NX_CRYPTO_METHOD if (status != NX_SUCCESS) { - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); } } return(error_number); @@ -318,12 +324,13 @@ const NX_CRYPTO_METHOD the alert was sent, so just return a status indicating as much. */ return(NX_SECURE_TLS_HANDSHAKE_FAILURE); break; +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION case NX_SECURE_TLS_CLIENT_STATE_HELLO_REQUEST: /* Server sent a hello request, indicating it wants to restart the handshake process with a new ClientHello. */ if (tls_session -> nx_secure_tls_local_session_active) { /* See if renegotiation is enabled. */ - if (tls_session -> nx_secure_tls_renegotation_enabled) + if (tls_session -> nx_secure_tls_renegotation_enabled && tls_session -> nx_secure_tls_secure_renegotiation) { /* Invoke user callback to notify application of renegotiation request. */ if (tls_session -> nx_secure_tls_session_renegotiation_callback != NX_NULL) @@ -366,6 +373,7 @@ const NX_CRYPTO_METHOD } /* If we are still in a handshake (session is not active) then ignore the message. */ break; +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ case NX_SECURE_TLS_CLIENT_STATE_SERVERHELLO: /* We received a serverhello above. It is time to update the hash for the handshake. */ @@ -522,7 +530,7 @@ const NX_CRYPTO_METHOD if (status != NX_SUCCESS) { /* Release packet on send error. */ - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); break; } @@ -585,7 +593,7 @@ const NX_CRYPTO_METHOD if (status != NX_SUCCESS) { - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); } } diff --git a/nx_secure/src/nx_secure_tls_handshake_process.c b/nx_secure/src/nx_secure_tls_handshake_process.c index cd4fd6ee..cbf2d5f8 100644 --- a/nx_secure/src/nx_secure_tls_handshake_process.c +++ b/nx_secure/src/nx_secure_tls_handshake_process.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_handshake_process PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -55,7 +55,7 @@ /* */ /* _nx_secure_tls_session_receive_records */ /* Receive TLS records */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* */ /* CALLED BY */ /* */ @@ -67,15 +67,16 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* fixed compiler warnings, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_handshake_process(NX_SECURE_TLS_SESSION *tls_session, UINT wait_option) { UINT status = NX_NOT_SUCCESSFUL; -NX_PACKET *incoming_packet; -#ifdef NX_SECURE_KEY_CLEAR -NX_PACKET *current_packet; -#endif /* NX_SECURE_KEY_CLEAR */ +NX_PACKET *incoming_packet = NX_NULL; /* Process the handshake depending on the TLS session type. */ #ifndef NX_SECURE_TLS_CLIENT_DISABLED @@ -93,21 +94,13 @@ NX_PACKET *current_packet; { break; } + } -#ifdef NX_SECURE_KEY_CLEAR - /* Clear all data in chained packet. */ - current_packet = incoming_packet; - while (current_packet) - { - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - (ULONG)current_packet -> nx_packet_append_ptr - - (ULONG)current_packet -> nx_packet_prepend_ptr); - current_packet = current_packet -> nx_packet_next; - } -#endif /* NX_SECURE_KEY_CLEAR */ + if (tls_session -> nx_secure_tls_client_state == NX_SECURE_TLS_CLIENT_STATE_HANDSHAKE_FINISHED) + { /* Release the incoming packet if we do receive it. */ - nx_packet_release(incoming_packet); + nx_secure_tls_packet_release(incoming_packet); } } #endif @@ -129,21 +122,13 @@ NX_PACKET *current_packet; { break; } + } -#ifdef NX_SECURE_KEY_CLEAR - /* Clear all data in chained packet. */ - current_packet = incoming_packet; - while (current_packet) - { - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - (ULONG)current_packet -> nx_packet_append_ptr - - (ULONG)current_packet -> nx_packet_prepend_ptr); - current_packet = current_packet -> nx_packet_next; - } -#endif /* NX_SECURE_KEY_CLEAR */ + if (tls_session -> nx_secure_tls_server_state == NX_SECURE_TLS_SERVER_STATE_HANDSHAKE_FINISHED) + { /* Release the incoming packet if we do receive it. */ - nx_packet_release(incoming_packet); + nx_secure_tls_packet_release(incoming_packet); } } #endif diff --git a/nx_secure/src/nx_secure_tls_hash_record.c b/nx_secure/src/nx_secure_tls_hash_record.c index 17e7ecd6..16d837b1 100644 --- a/nx_secure/src/nx_secure_tls_hash_record.c +++ b/nx_secure/src/nx_secure_tls_hash_record.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_hash_record PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -46,8 +46,9 @@ /* sequence_num Record sequence number */ /* header Record header */ /* header_length Length of record header */ -/* data Record payload */ -/* length Length of record payload */ +/* packet_ptr TLS record packet */ +/* offset Offset to TLS record in packet*/ +/* length Length of payload data */ /* record_hash Pointer to output hash buffer */ /* hash_length Length of hash */ /* mac_secret Key used for MAC generation */ @@ -69,12 +70,16 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* supported chained packet, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_hash_record(NX_SECURE_TLS_SESSION *tls_session, ULONG sequence_num[NX_SECURE_TLS_SEQUENCE_NUMBER_SIZE], - UCHAR *header, UINT header_length, UCHAR *data, UINT length, - UCHAR *record_hash, UINT *hash_length, UCHAR *mac_secret) + UCHAR *header, UINT header_length, NX_PACKET *packet_ptr, + ULONG offset, UINT length, UCHAR *record_hash, UINT *hash_length, + UCHAR *mac_secret) { UINT hash_size; UINT status = NX_SECURE_TLS_MISSING_CRYPTO_ROUTINE;; @@ -83,6 +88,7 @@ UCHAR adjusted_sequence_num[8]; VOID *metadata; UINT metadata_size; VOID *handler = NX_NULL; +ULONG current_length; NX_PARAMETER_NOT_USED(header_length); @@ -133,7 +139,7 @@ VOID *handler = NX_NULL; if(status != NX_CRYPTO_SUCCESS) { return(status); - } + } } /* TLS header type, version, and length are in the proper order. */ @@ -157,7 +163,7 @@ VOID *handler = NX_NULL; if(status != NX_CRYPTO_SUCCESS) { return(status); - } + } status = authentication_method -> nx_crypto_operation(NX_CRYPTO_HASH_UPDATE, handler, @@ -177,7 +183,7 @@ VOID *handler = NX_NULL; if(status != NX_CRYPTO_SUCCESS) { return(status); - } + } status = authentication_method -> nx_crypto_operation(NX_CRYPTO_HASH_UPDATE, handler, @@ -197,27 +203,67 @@ VOID *handler = NX_NULL; if(status != NX_CRYPTO_SUCCESS) { return(status); - } + } - status = authentication_method -> nx_crypto_operation(NX_CRYPTO_HASH_UPDATE, - handler, - (NX_CRYPTO_METHOD*)authentication_method, - NX_NULL, - 0, - data, - length, - NX_NULL, - NX_NULL, - 0, - metadata, - metadata_size, - NX_NULL, - NX_NULL); + /* Locate to start packet of TLS record payload. */ + while (packet_ptr) + { + current_length = (ULONG)(packet_ptr -> nx_packet_append_ptr - packet_ptr -> nx_packet_prepend_ptr); + if (offset >= current_length) + { - if(status != NX_CRYPTO_SUCCESS) + /* Move to next packet. */ + offset -= current_length; + packet_ptr = packet_ptr -> nx_packet_next; + } + else + { + + /* Found offset in current packet. */ + break; + } + } + + /* Hash TLS record payload. */ + while ((length > 0) && packet_ptr) { - return(status); - } + current_length = (ULONG)(packet_ptr -> nx_packet_append_ptr - packet_ptr -> nx_packet_prepend_ptr); + current_length -= offset; + offset = 0; + if (current_length > length) + { + current_length = length; + } + status = authentication_method -> nx_crypto_operation(NX_CRYPTO_HASH_UPDATE, + handler, + (NX_CRYPTO_METHOD*)authentication_method, + NX_NULL, + 0, + &packet_ptr -> nx_packet_prepend_ptr[offset], + current_length, + NX_NULL, + NX_NULL, + 0, + metadata, + metadata_size, + NX_NULL, + NX_NULL); + + if(status != NX_CRYPTO_SUCCESS) + { + return(status); + } + + length -= current_length; + packet_ptr = packet_ptr -> nx_packet_next; + } + + if (length > 0) + { + + /* Not all TLS record payload is hashed. */ + return(NX_SECURE_TLS_INVALID_PACKET); + } status = authentication_method -> nx_crypto_operation(NX_CRYPTO_HASH_CALCULATE, handler, @@ -237,7 +283,7 @@ VOID *handler = NX_NULL; if(status != NX_CRYPTO_SUCCESS) { return(status); - } + } #ifdef NX_SECURE_KEY_CLEAR NX_SECURE_MEMSET(adjusted_sequence_num, 0, 8); #endif /* NX_SECURE_KEY_CLEAR */ @@ -250,7 +296,7 @@ VOID *handler = NX_NULL; if(status != NX_CRYPTO_SUCCESS) { return(status); - } + } } /* Return how many bytes our hash is since the caller doesn't necessarily know. */ diff --git a/nx_secure/src/nx_secure_tls_map_error_to_alert.c b/nx_secure/src/nx_secure_tls_map_error_to_alert.c index 22083c06..007b71e1 100644 --- a/nx_secure/src/nx_secure_tls_map_error_to_alert.c +++ b/nx_secure/src/nx_secure_tls_map_error_to_alert.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_map_error_to_alert PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -68,6 +68,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ VOID _nx_secure_tls_map_error_to_alert(UINT error_number, UINT *alert_number, UINT *alert_level) @@ -115,7 +118,9 @@ VOID _nx_secure_tls_map_error_to_alert(UINT error_number, UINT *alert_number, UI case NX_SECURE_TLS_SNI_EXTENSION_INVALID: case NX_SECURE_TLS_EMPTY_EC_GROUP: case NX_SECURE_TLS_EMPTY_EC_POINT_FORMAT: - case NX_SECURE_TLS_UNSUPPORTED_SIGNATURE_ALGORITHM: /* Deliberate fall-through. */ + case NX_SECURE_TLS_UNSUPPORTED_SIGNATURE_ALGORITHM: + case NX_SECURE_TLS_RENEGOTIATION_SESSION_INACTIVE: + case NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR: /* Deliberate fall-through. */ *alert_number = NX_SECURE_TLS_ALERT_HANDSHAKE_FAILURE; *alert_level = NX_SECURE_TLS_ALERT_LEVEL_FATAL; break; @@ -201,7 +206,6 @@ VOID _nx_secure_tls_map_error_to_alert(UINT error_number, UINT *alert_number, UI /* Re-negotiation issues - the client may opt to decline a Hello Request message. */ case NX_SECURE_TLS_NO_RENEGOTIATION_ERROR: - case NX_SECURE_TLS_RENEGOTIATION_SESSION_INACTIVE: case NX_SECURE_TLS_RENEGOTIATION_FAILURE: *alert_number = NX_SECURE_TLS_ALERT_NO_RENEGOTIATION; *alert_level = NX_SECURE_TLS_ALERT_LEVEL_WARNING; diff --git a/nx_secure/src/nx_secure_tls_newest_supported_version.c b/nx_secure/src/nx_secure_tls_newest_supported_version.c index f3f434bb..9264c789 100644 --- a/nx_secure/src/nx_secure_tls_newest_supported_version.c +++ b/nx_secure/src/nx_secure_tls_newest_supported_version.c @@ -105,3 +105,128 @@ INT i; return; } +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _nx_secure_tls_highest_supported_version_negotiate PORTABLE C */ +/* 6.0.2 */ +/* AUTHOR */ +/* */ +/* Timothy Stapko, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* Negotiate the highested supported and enabled TLS/DTLS protocol */ +/* version, if the protocol version in clientHello is not supported */ +/* by the server. */ +/* */ +/* INPUT */ +/* */ +/* session_ptr TLS session */ +/* protocol_version Pointer to version variable */ +/* id TLS or DTLS */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* _nx_secure_dtls_process_clienthello Send ClientHello */ +/* _nx_secure_tls_process_clienthello Process ClientHello */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 08-14-2020 Timothy Stapko Initial Version 6.0.2 */ +/* */ +/**************************************************************************/ +void _nx_secure_tls_highest_supported_version_negotiate(NX_SECURE_TLS_SESSION *session_ptr, + USHORT *protocol_version, UINT id) +{ +INT i; +USHORT highest_version = 0; +USHORT lowest_version = 0xFF; +USHORT highest_version_not_greater_than_client_version = 0; + + NX_PARAMETER_NOT_USED(session_ptr); + +#ifndef NX_SECURE_TLS_SERVER_DISABLED + if(session_ptr -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_SERVER && + session_ptr -> nx_secure_tls_negotiated_highest_protocol_version != 0) + { + /* If this is a server and the user has the negotiated highest version, + return it directly. */ + (*protocol_version) = session_ptr -> nx_secure_tls_negotiated_highest_protocol_version; + return; + } +#endif + + /* Find the highest and the lowest supported server version. */ + + for (i = (INT)(nx_secure_supported_versions_list[id].nx_secure_versions_list_count - 1); i >= 0; --i) + { + /* If the version is supported, return it. */ + if (nx_secure_supported_versions_list[id].nx_secure_versions_list[i].nx_secure_tls_is_supported) + { + if (highest_version < nx_secure_supported_versions_list[id].nx_secure_versions_list[i].nx_secure_tls_protocol_version) + { + highest_version = nx_secure_supported_versions_list[id].nx_secure_versions_list[i].nx_secure_tls_protocol_version; + } + + if (lowest_version > nx_secure_supported_versions_list[id].nx_secure_versions_list[i].nx_secure_tls_protocol_version) + { + lowest_version = nx_secure_supported_versions_list[id].nx_secure_versions_list[i].nx_secure_tls_protocol_version; + } + + if (!highest_version_not_greater_than_client_version && + (*protocol_version) >= nx_secure_supported_versions_list[id].nx_secure_versions_list[i].nx_secure_tls_protocol_version) + { + highest_version_not_greater_than_client_version = nx_secure_supported_versions_list[id].nx_secure_versions_list[i].nx_secure_tls_protocol_version; + } + + } + } + + /* No versions of TLS have been enabled. Set protocol to 0 to indicate failure. */ + if (highest_version == 0) + { + (*protocol_version) = 0; + session_ptr -> nx_secure_tls_negotiated_highest_protocol_version = 0; + return; + } + + /* According to RFC 5246 E.1, + if protocol_version > highest_version, set protocol_version to highest_version to indicate to send "server_hello" with highest_version; + if lowest_version < protocol_version < highest_version, set protocol_version to the highest server version not greater than protocol_version; + if protocol_version < lowest_version, set protocol_version to 0 to indicate to send a "protocol_version" alert message. + */ + + if ((*protocol_version) > highest_version) + { + (*protocol_version) = highest_version; + } + else + { + if ((*protocol_version) < highest_version && (*protocol_version) > lowest_version) + { + (*protocol_version) = highest_version_not_greater_than_client_version; + } + else + { + (*protocol_version) = 0; + } + } + + session_ptr -> nx_secure_tls_negotiated_highest_protocol_version = (*protocol_version); + return; +} + + + diff --git a/nx_secure/src/nx_secure_tls_packet_release.c b/nx_secure/src/nx_secure_tls_packet_release.c new file mode 100644 index 00000000..208e451a --- /dev/null +++ b/nx_secure/src/nx_secure_tls_packet_release.c @@ -0,0 +1,103 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Secure Component */ +/** */ +/** Transport Layer Security (TLS) */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + +#define NX_SECURE_SOURCE_CODE + +#include "nx_secure_tls.h" + +#ifdef NX_SECURE_KEY_CLEAR +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _nx_secure_tls_packet_release PORTABLE C */ +/* 6.0.2 */ +/* AUTHOR */ +/* */ +/* Timothy Stapko, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function releases packet with all data in the packet cleared. */ +/* */ +/* INPUT */ +/* */ +/* packet_ptr NX_PACKET to release */ +/* */ +/* OUTPUT */ +/* */ +/* status Completion status */ +/* */ +/* CALLS */ +/* */ +/* nx_packet_release Release packet */ +/* */ +/* CALLED BY */ +/* */ +/* nx_secure_dtls_client_handshake.c */ +/* nx_secure_dtls_process_record.c */ +/* nx_secure_dtls_receive_callback.c */ +/* nx_secure_dtls_retransmit_queue_flush.c */ +/* nx_secure_dtls_send_handshake_record.c */ +/* nx_secure_dtls_send_record.c */ +/* nx_secure_dtls_session_end.c */ +/* nx_secure_dtls_session_receive.c */ +/* nx_secure_dtls_session_reset.c */ +/* nx_secure_dtls_session_start.c */ +/* nx_secure_tls_1_3_client_handshake.c */ +/* nx_secure_tls_1_3_server_handshake.c */ +/* nx_secure_tls_client_handshake.c */ +/* nx_secure_tls_handshake_process.c */ +/* nx_secure_tls_packet_release.c */ +/* nx_secure_tls_process_record.c */ +/* nx_secure_tls_record_payload_decrypt.c */ +/* nx_secure_tls_send_handshake_record.c */ +/* nx_secure_tls_server_handshake.c */ +/* nx_secure_tls_session_end.c */ +/* nx_secure_tls_session_receive_records.c */ +/* nx_secure_tls_session_renegotiate.c */ +/* nx_secure_tls_session_start.c */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 08-14-2020 Timothy Stapko Initial Version 6.0.2 */ +/* */ +/**************************************************************************/ +UINT _nx_secure_tls_packet_release(NX_PACKET *packet_ptr) +{ +NX_PACKET *current_packet; + + /* Clear all data in chained packet. */ + current_packet = packet_ptr; + while (current_packet) + { + NX_SECURE_MEMSET(current_packet -> nx_packet_data_start, 0, + (ULONG)current_packet -> nx_packet_data_end - + (ULONG)current_packet -> nx_packet_data_start); + current_packet = current_packet -> nx_packet_next; + } + return(nx_packet_release(packet_ptr)); +} +#endif /* NX_SECURE_KEY_CLEAR */ + diff --git a/nx_secure/src/nx_secure_tls_process_clienthello.c b/nx_secure/src/nx_secure_tls_process_clienthello.c index deaf3b49..5e7ae1a4 100644 --- a/nx_secure/src/nx_secure_tls_process_clienthello.c +++ b/nx_secure/src/nx_secure_tls_process_clienthello.c @@ -36,7 +36,7 @@ static UINT _nx_secure_tls_check_ciphersuite(const NX_SECURE_TLS_CIPHERSUITE_INF /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_process_clienthello PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -88,6 +88,10 @@ static UINT _nx_secure_tls_check_ciphersuite(const NX_SECURE_TLS_CIPHERSUITE_INF /* 06-30-2020 Timothy Stapko Modified comment(s), added */ /* priority ciphersuite logic, */ /* resulting in version 6.0.1 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* improved negotiation logic, */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_process_clienthello(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, @@ -139,7 +143,7 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 if (tls_session -> nx_secure_tls_local_session_active) { #if (NX_SECURE_TLS_TLS_1_3_ENABLED) - if(tls_session->nx_secure_tls_1_3 == NX_TRUE) + if (tls_session->nx_secure_tls_1_3 == NX_TRUE) { /* RFC 8446, section 4.1.2, page 27. @@ -148,7 +152,9 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 return(NX_SECURE_TLS_UNEXPECTED_CLIENTHELLO); } #endif - if (tls_session -> nx_secure_tls_renegotation_enabled) + +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION + if (tls_session -> nx_secure_tls_renegotation_enabled && tls_session -> nx_secure_tls_secure_renegotiation) { tls_session -> nx_secure_tls_renegotiation_handshake = NX_TRUE; @@ -174,6 +180,7 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 } } else +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ { /* Session renegotiation is disabled, so this is an error! */ return(NX_SECURE_TLS_NO_RENEGOTIATION_ERROR); @@ -186,7 +193,7 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 length += 2; #if (NX_SECURE_TLS_TLS_1_3_ENABLED) - if(tls_session->nx_secure_tls_1_3 == NX_FALSE) + if (tls_session->nx_secure_tls_1_3 == NX_FALSE) #endif { @@ -200,9 +207,9 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 if (status == NX_SECURE_TLS_UNSUPPORTED_TLS_VERSION || tls_session -> nx_secure_tls_local_session_active) { /* If the version isn't supported, it's not an issue - TLS is backward-compatible, - * so pick the highest version we do support. If the version isn't recognized, + * so negotiate the highest supported version. If the version isn't recognized, * flag an error. */ - _nx_secure_tls_newest_supported_version(tls_session, &protocol_version, NX_SECURE_TLS); + _nx_secure_tls_highest_supported_version_negotiate(tls_session, &protocol_version, NX_SECURE_TLS); if (protocol_version == 0x0) { @@ -334,6 +341,17 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 } } +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION + if ((tls_session -> nx_secure_tls_renegotiation_handshake) && (!tls_session -> nx_secure_tls_secure_renegotiation_verified)) + { + + /* The server did not receive the "renegotiation_info" extension, the handshake must be aborted. */ + return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); + } + + tls_session -> nx_secure_tls_secure_renegotiation_verified = NX_FALSE; +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ + #ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE /* Get the local certificate. */ @@ -393,7 +411,7 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 #endif /* NX_SECURE_ENABLE_ECC_CIPHERSUITE */ /* Set our initial priority to the maximum value - the size of our ciphersuite crypto table. */ - ciphersuite_priority = (USHORT)(0xFFFFFFFF); + ciphersuite_priority = (USHORT)(0xFFFFFFFF); for (i = 0; i < ciphersuite_list_length; i += 2) { @@ -401,7 +419,7 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 cipher_entry = (USHORT)((ciphersuite_list[i] << 8) + ciphersuite_list[i + 1]); #if (NX_SECURE_TLS_TLS_1_3_ENABLED) - if ((tls_session -> nx_secure_tls_1_3 == NX_TRUE) ^ (ciphersuite_list[i] == 0x13)) + if ((tls_session -> nx_secure_tls_1_3 == NX_TRUE) ^ (ciphersuite_list[i] == 0x13)) { /* Ciphersuites for TLS 1.3 can not be used by TLS 1.2. */ @@ -426,23 +444,34 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 } } -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION if (cipher_entry == TLS_EMPTY_RENEGOTIATION_INFO_SCSV) { - /* Secure Renegotiation signalling ciphersuite value was encountered. - This indicates that the Client supports secure renegotiation. */ - tls_session -> nx_secure_tls_secure_renegotiation = NX_TRUE; + if (tls_session -> nx_secure_tls_renegotiation_handshake) + { + + /* When secure renegotiating, the server MUST verify that it + does not contain the TLS_EMPTY_RENEGOTIATION_INFO_SCSV SCSV. */ + return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); + } + else + { + + /* Secure Renegotiation signalling ciphersuite value was encountered. + This indicates that the Client supports secure renegotiation. */ + tls_session -> nx_secure_tls_secure_renegotiation = NX_TRUE; + } } -#endif /* NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION */ +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ /* Check for the fallback notification SCSV. */ - if(cipher_entry == TLS_FALLBACK_NOTIFY_SCSV) + if (cipher_entry == TLS_FALLBACK_NOTIFY_SCSV) { /* A fallback is indicated by the Client, check the TLS version. */ _nx_secure_tls_newest_supported_version(tls_session, &newest_version, NX_SECURE_TLS); - + if (protocol_version != newest_version) { return(NX_SECURE_TLS_INAPPROPRIATE_FALLBACK); @@ -451,6 +480,20 @@ USHORT tls_1_3 = tls_session -> nx_secure_tls_1_3 /* Continue searching client ciphersuite list to get highest-priority selection. */ } +#if !defined(NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION) && defined(NX_SECURE_TLS_REQUIRE_RENEGOTIATION_EXT) +#if (NX_SECURE_TLS_TLS_1_3_ENABLED) + if (!tls_session -> nx_secure_tls_1_3) +#endif /* NX_SECURE_TLS_TLS_1_3_ENABLED */ + { + if ((tls_session -> nx_secure_tls_renegotation_enabled) && (!tls_session -> nx_secure_tls_secure_renegotiation)) + { + + /* No "renegotiation_info" extension present, some servers may want to terminate the handshake. */ + return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); + } + } +#endif /* !NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION && NX_SECURE_TLS_REQUIRE_RENEGOTIATION_EXT */ + /* See if we found an acceptable ciphersuite. */ if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL) { diff --git a/nx_secure/src/nx_secure_tls_process_clienthello_extensions.c b/nx_secure/src/nx_secure_tls_process_clienthello_extensions.c index d3ffa3a2..56245e76 100644 --- a/nx_secure/src/nx_secure_tls_process_clienthello_extensions.c +++ b/nx_secure/src/nx_secure_tls_process_clienthello_extensions.c @@ -24,7 +24,7 @@ #include "nx_secure_tls.h" -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION static UINT _nx_secure_tls_proc_clienthello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, UINT extension_length); @@ -54,7 +54,7 @@ static UINT _nx_secure_tls_process_clienthello_psk_extension(NX_SECURE_TLS_SESSI /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_process_clienthello_extensions PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -97,6 +97,9 @@ static UINT _nx_secure_tls_process_clienthello_psk_extension(NX_SECURE_TLS_SESSI /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_process_clienthello_extensions(NX_SECURE_TLS_SESSION *tls_session, @@ -113,9 +116,9 @@ UINT extension_length; USHORT supported_version = tls_session -> nx_secure_tls_protocol_version; #endif -#ifndef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifdef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION NX_PARAMETER_NOT_USED(tls_session); -#endif /* NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION */ +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ #if !(NX_SECURE_TLS_TLS_1_3_ENABLED) || !defined(NX_SECURE_ENABLE_PSK_CIPHERSUITES) NX_PARAMETER_NOT_USED(client_hello_buffer); @@ -154,7 +157,7 @@ USHORT supported_version = tls_session -> nx_secure_tls_protocol_version; /* Parse the extension. */ switch (extension_id) { -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION case NX_SECURE_TLS_EXTENSION_SECURE_RENEGOTIATION: status = _nx_secure_tls_proc_clienthello_sec_reneg_extension(tls_session, &packet_buffer[offset], @@ -165,7 +168,7 @@ USHORT supported_version = tls_session -> nx_secure_tls_protocol_version; return(status); } break; -#endif /* NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION */ +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ #if (NX_SECURE_TLS_TLS_1_3_ENABLED) case NX_SECURE_TLS_EXTENSION_KEY_SHARE: @@ -257,7 +260,9 @@ USHORT supported_version = tls_session -> nx_secure_tls_protocol_version; if (tls_session -> nx_secure_tls_protocol_version_override == 0) { tls_session -> nx_secure_tls_1_3 = NX_FALSE; +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION tls_session -> nx_secure_tls_renegotation_enabled = NX_TRUE; +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ tls_session -> nx_secure_tls_protocol_version = supported_version; } else @@ -279,7 +284,7 @@ USHORT supported_version = tls_session -> nx_secure_tls_protocol_version; /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_proc_clienthello_sec_reneg_extension PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -314,9 +319,12 @@ USHORT supported_version = tls_session -> nx_secure_tls_protocol_version; /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION static UINT _nx_secure_tls_proc_clienthello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, UINT extension_length) @@ -403,6 +411,8 @@ INT compare_value; /* Session verify data did not match what we expect - error. */ return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); } + + tls_session -> nx_secure_tls_secure_renegotiation_verified = NX_TRUE; } else { @@ -419,7 +429,7 @@ INT compare_value; return(NX_SUCCESS); } -#endif +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ /**************************************************************************/ /* */ diff --git a/nx_secure/src/nx_secure_tls_process_finished.c b/nx_secure/src/nx_secure_tls_process_finished.c index 9559fbf8..2d77ecf7 100644 --- a/nx_secure/src/nx_secure_tls_process_finished.c +++ b/nx_secure/src/nx_secure_tls_process_finished.c @@ -31,7 +31,7 @@ static UCHAR generated_hash[NX_SECURE_TLS_MAX_HASH_SIZE]; /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_process_finished PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -70,6 +70,9 @@ static UCHAR generated_hash[NX_SECURE_TLS_MAX_HASH_SIZE]; /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_process_finished(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, @@ -150,11 +153,11 @@ UINT is_server; return(status); } -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION /* If we are doing secure renegotiation as per RFC 5746, we need to save off the generated verify data now. For TLS 1.0-1.2 this is 12 bytes. If SSLv3 is ever used, it will be 36 bytes. */ NX_SECURE_MEMCPY(tls_session -> nx_secure_tls_remote_verify_data, generated_hash, NX_SECURE_TLS_FINISHED_HASH_SIZE); -#endif +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ /* The finished verify data is always 12 bytes (*except for SSLv3) - compare to see if the Finished hash matches the recevied hash. */ compare_result = (UINT)NX_SECURE_MEMCMP(generated_hash, packet_buffer, NX_SECURE_TLS_FINISHED_HASH_SIZE); diff --git a/nx_secure/src/nx_secure_tls_process_header.c b/nx_secure/src/nx_secure_tls_process_header.c index 51a82ff3..ec58188e 100644 --- a/nx_secure/src/nx_secure_tls_process_header.c +++ b/nx_secure/src/nx_secure_tls_process_header.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_process_header PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -38,7 +38,7 @@ /* DESCRIPTION */ /* */ /* This function processes an NX_PACKET data structure, extracting */ -/* and parsing a TLS header recevied from a remote host. */ +/* and parsing a TLS header received from a remote host. */ /* */ /* INPUT */ /* */ @@ -68,6 +68,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* supported chained packet, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_process_header(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *packet_ptr, @@ -77,38 +80,33 @@ UINT _nx_secure_tls_process_header(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET ULONG bytes_copied; UINT status; USHORT protocol_version; -ULONG remaining_bytes = 5; - *header_length = 5; - - while (remaining_bytes) + /* Check the packet. */ + if (packet_ptr == NX_NULL) { - /* Check the packet. */ - if (packet_ptr == NX_NULL) - { - - /* There was an error in extracting the header from the supplied packet. */ - return(NX_SECURE_TLS_INVALID_PACKET); - } + /* There was an error in extracting the header from the supplied packet. */ + return(NX_SECURE_TLS_INVALID_PACKET); + } - /* Process the TLS record header, which will set the state. */ - status = nx_packet_data_extract_offset(packet_ptr, record_offset, &header_data[5 - remaining_bytes], - remaining_bytes, &bytes_copied); + /* Process the TLS record header, which will set the state. */ + status = nx_packet_data_extract_offset(packet_ptr, record_offset, header_data, + NX_SECURE_TLS_RECORD_HEADER_SIZE, &bytes_copied); - /* Make sure we actually got a header. */ - if (status != NX_SUCCESS) - { + /* Make sure we actually got a header. */ + if (status != NX_SUCCESS) + { - /* There was an error in extracting the header from the supplied packet. */ - return(NX_SECURE_TLS_INVALID_PACKET); - } + /* There was an error in extracting the header from the supplied packet. */ + return(NX_SECURE_TLS_INVALID_PACKET); + } - record_offset = 0; - remaining_bytes -= bytes_copied; + if (bytes_copied != NX_SECURE_TLS_RECORD_HEADER_SIZE) + { - packet_ptr = packet_ptr -> nx_packet_queue_next; + /* Wait more TCP packets for this one record. */ + return(NX_CONTINUE); } /* Extract message type from packet/record. */ @@ -120,6 +118,9 @@ ULONG remaining_bytes = 5; /* Get the length of the TLS data. */ *length = (UINT)(((UINT)header_data[3] << 8) + header_data[4]); + /* Set header length. */ + *header_length = NX_SECURE_TLS_RECORD_HEADER_SIZE; + /* Check the protocol version, except when we haven't established a version yet */ if (tls_session -> nx_secure_tls_protocol_version != 0) { diff --git a/nx_secure/src/nx_secure_tls_process_record.c b/nx_secure/src/nx_secure_tls_process_record.c index 9c35c214..3b950328 100644 --- a/nx_secure/src/nx_secure_tls_process_record.c +++ b/nx_secure/src/nx_secure_tls_process_record.c @@ -24,12 +24,14 @@ #include "nx_secure_tls.h" +static VOID _nx_secure_tls_packet_trim(NX_PACKET *packet_ptr); + /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_process_record PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -64,6 +66,7 @@ /* nx_packet_allocate NetX Packet allocation call */ /* nx_packet_data_append Append data to packet */ /* nx_packet_data_extract_offset Extract data from NX_PACKET */ +/* _nx_secure_tls_packet_trim Trim TLS packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -77,6 +80,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* supported chained packet, */ +/* fixed compiler warnings, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_process_record(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *packet_ptr, @@ -85,15 +92,14 @@ UINT _nx_secure_tls_process_record(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET UINT status; UINT error_status; USHORT header_length; -UCHAR header_data[NX_SECURE_TLS_RECORD_HEADER_SIZE]; /* DTLS record header is larger than TLS. Allocate enough space for both. */ +UCHAR header_data[NX_SECURE_TLS_RECORD_HEADER_SIZE] = {0}; /* DTLS record header is larger than TLS. Allocate enough space for both. */ USHORT message_type; UINT message_length; -UINT total_bytes; ULONG bytes_copied; -NX_PACKET *tmp_ptr; -UCHAR *packet_data; -UINT skip_bytes; +UCHAR *packet_data = NX_NULL; ULONG record_offset = 0; +ULONG record_offset_next = 0; +NX_PACKET *decrypted_packet; /* Basic state machine: * 1. Process header, which will set the state and return some data. @@ -123,37 +129,42 @@ ULONG record_offset = 0; /* Process the packet. */ if (packet_ptr != NX_NULL) { + if (packet_ptr -> nx_packet_last == NX_NULL) + { + + /* The logic below requires nx_packet_last is set which is always TRUE + for chained packets coming from NetX. However, this packet is not chained + so set the nx_packet_last pointer to itself. */ + packet_ptr -> nx_packet_last = packet_ptr; + } /* Chain the packet. */ - if (tls_session -> nx_secure_record_queue_tail == NX_NULL) + if (tls_session -> nx_secure_record_queue_header == NX_NULL) { tls_session -> nx_secure_record_queue_header = packet_ptr; } else { - tls_session -> nx_secure_record_queue_tail -> nx_packet_queue_next = packet_ptr; - } - - /* Place the new packet at the end of the session record queue - we have to process everything in order. */ - tls_session -> nx_secure_record_queue_tail = packet_ptr; - - packet_ptr -> nx_packet_queue_next = NX_NULL; - tls_session -> nx_secure_record_queue_length += packet_ptr -> nx_packet_length; - } - header_length = NX_SECURE_TLS_RECORD_HEADER_SIZE; - - /* Is the header of one record received? */ - if (tls_session -> nx_secure_record_queue_length < header_length) - { - - /* Wait more TCP packets for this one record. */ - return(NX_CONTINUE); + /* Link current packet. */ + tls_session -> nx_secure_record_queue_header -> nx_packet_last -> nx_packet_next = packet_ptr; + tls_session -> nx_secure_record_queue_header -> nx_packet_last = packet_ptr -> nx_packet_last; + tls_session -> nx_secure_record_queue_header -> nx_packet_length += packet_ptr -> nx_packet_length; + } } /* Process multiple records per packet. */ while (status == NX_CONTINUE) { + + /* Make sure the decrypted packet is NULL. */ + if (tls_session -> nx_secure_record_decrypted_packet) + { + nx_secure_tls_packet_release(tls_session -> nx_secure_record_decrypted_packet); + tls_session -> nx_secure_record_decrypted_packet = NX_NULL; + } + decrypted_packet = NX_NULL; + /* Get packet from record queue. */ packet_ptr = tls_session -> nx_secure_record_queue_header; @@ -170,49 +181,22 @@ ULONG record_offset = 0; { /* Update the number of bytes we processed. */ - *bytes_processed = (ULONG)header_length + message_length; + *bytes_processed += (ULONG)header_length; return(NX_SUCCESS); } /* Is the entire payload of the current record received? */ - if ((header_length + record_offset + message_length) > tls_session -> nx_secure_record_queue_length) + if ((header_length + record_offset + message_length) > packet_ptr -> nx_packet_length) { /* Wait more TCP packets for this one record. */ return(NX_CONTINUE); } - /* Check available area of buffer. */ - if (message_length > tls_session -> nx_secure_tls_packet_buffer_size) - { - return(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL); - } - - /* Now extract the the record payload into the TLS packet buffer. */ - total_bytes = 0; - skip_bytes = header_length + record_offset; /* Make sure we account for previous records. */ - tmp_ptr = packet_ptr; - packet_data = tls_session -> nx_secure_tls_packet_buffer; - while (total_bytes < message_length) - { - if (nx_packet_data_extract_offset(tmp_ptr, skip_bytes, packet_data + total_bytes, - (message_length - total_bytes), &bytes_copied)) - { - - /* Skip the whole packet. */ - skip_bytes -= tmp_ptr -> nx_packet_length; - } - else - { - total_bytes += bytes_copied; - skip_bytes = 0; - } - tmp_ptr = tmp_ptr -> nx_packet_queue_next; - } - /* Update the number of bytes we processed. */ *bytes_processed += (ULONG)header_length + message_length; - record_offset += *bytes_processed; + record_offset += (ULONG)header_length; + record_offset_next = record_offset + message_length; /* Check for active encryption of incoming records. If encrypted, decrypt before further processing. */ if (tls_session -> nx_secure_tls_remote_session_active @@ -241,9 +225,11 @@ ULONG record_offset = 0; } /* Decrypt the record data. */ - status = _nx_secure_tls_record_payload_decrypt(tls_session, packet_data, &message_length, - tls_session -> nx_secure_tls_remote_sequence_number, (UCHAR)message_type); - + status = _nx_secure_tls_record_payload_decrypt(tls_session, packet_ptr, record_offset, + message_length, &decrypted_packet, + tls_session -> nx_secure_tls_remote_sequence_number, + (UCHAR)message_type, wait_option); + /* Set the error status to something appropriate. */ error_status = NX_SECURE_TLS_SUCCESS; @@ -253,47 +239,84 @@ ULONG record_offset = 0; /* Save off the error status so we can return it after the mac check. */ error_status = status; } + else + { + + /* Record it so it can be release in case it is not returned to user application. */ + tls_session -> nx_secure_record_decrypted_packet = decrypted_packet; + message_length = decrypted_packet -> nx_packet_length; + } + #if (NX_SECURE_TLS_TLS_1_3_ENABLED) /* TLS 1.3 uses AEAD for all authentication and encryption. Therefore the MAC verification is only needed for older TLS versions. */ if(tls_session->nx_secure_tls_1_3) { - /* In TLS 1.3, encrypted records have a single byte at the - record that contains the message type (e.g. application data, - ect.), which is now the ACTUAL message type. */ - message_type = packet_data[message_length - 1]; - - /* Remove the content type byte from the data length to process. */ - message_length = message_length - 1; - - /* Increment the sequence number. This is done in the MAC verify - step for 1.2 and eariler, but AEAD includes the MAC so we don't - check the MAC and need to increment here. */ - if ((tls_session -> nx_secure_tls_remote_sequence_number[0] + 1) == 0) + + if (status == NX_SECURE_TLS_SUCCESS) { - /* Check for overflow of the 32-bit unsigned number. */ - tls_session -> nx_secure_tls_remote_sequence_number[1]++; + + /* In TLS 1.3, encrypted records have a single byte at the + record that contains the message type (e.g. application data, + ect.), which is now the ACTUAL message type. */ + status = nx_packet_data_extract_offset(decrypted_packet, + decrypted_packet -> nx_packet_length - 1, + &message_type, 1, &bytes_copied); + if (status || (bytes_copied != 1)) + { + error_status = NX_SECURE_TLS_INVALID_PACKET; + } + + /* Remove the content type byte from the data length to process. */ + message_length = message_length - 1; + + /* Adjust packet length. */ + decrypted_packet -> nx_packet_length = message_length; + + /* Increment the sequence number. This is done in the MAC verify + step for 1.2 and earlier, but AEAD includes the MAC so we don't + check the MAC and need to increment here. */ + if ((tls_session -> nx_secure_tls_remote_sequence_number[0] + 1) == 0) + { + /* Check for overflow of the 32-bit unsigned number. */ + tls_session -> nx_secure_tls_remote_sequence_number[1]++; + } + tls_session -> nx_secure_tls_remote_sequence_number[0]++; } - tls_session -> nx_secure_tls_remote_sequence_number[0]++; } else #endif { - /* Verify the hash MAC in the decrypted record. - !!! NOTE - the MAC check MUST always be performed regardless of the error state of - the payload decryption operation. Skipping the MAC check on padding failures - could enable a timing-based attack allowing an attacker to determine whether - padding was valid or not, causing an information leak. */ - status = _nx_secure_tls_verify_mac(tls_session, header_data, header_length, packet_data, &message_length); + /* Verify the hash MAC in the decrypted record. */ + if (status) + { + + /* !!! NOTE - the MAC check MUST always be performed regardless of the error state of + the payload decryption operation. Skipping the MAC check on padding failures + could enable a timing-based attack allowing an attacker to determine whether + padding was valid or not, causing an information leak. */ + status = _nx_secure_tls_verify_mac(tls_session, header_data, header_length, packet_ptr, record_offset, &message_length); + } + else + { + status = _nx_secure_tls_verify_mac(tls_session, header_data, header_length, decrypted_packet, 0, &message_length); + + if (status == NX_SECURE_TLS_SUCCESS) + { + + /* Adjust packet length. */ + decrypted_packet -> nx_packet_length = message_length; + } + } } - + /* Check to see if decryption or verification failed. */ if(error_status != NX_SECURE_TLS_SUCCESS) { /* Decryption failed. */ return(error_status); } - + if (status != NX_SECURE_TLS_SUCCESS) { /* MAC verification failed. */ @@ -304,25 +327,38 @@ ULONG record_offset = 0; { return(NX_SECURE_TLS_RECORD_OVERFLOW); } + + /* Trim packet. */ + _nx_secure_tls_packet_trim(decrypted_packet); } - /* Make sure we have a buffer packet. */ - if (tls_session -> nx_secure_record_decrypted_packet == NX_NULL) + if (message_type != NX_SECURE_TLS_APPLICATION_DATA) { - /* Release the protection before suspending on nx_packet_allocate. */ - tx_mutex_put(&_nx_secure_tls_protection); - - status = nx_packet_allocate(tls_session -> nx_secure_tls_packet_pool, - &tls_session -> nx_secure_record_decrypted_packet, - 0, wait_option); + /* For message other than application data, extract to packet buffer to make sure all data are in contiguous memory. */ + /* Check available area of buffer. */ + packet_data = tls_session -> nx_secure_tls_packet_buffer; + if (message_length > tls_session -> nx_secure_tls_packet_buffer_size) + { + return(NX_SECURE_TLS_PACKET_BUFFER_TOO_SMALL); + } - /* Get the protection after nx_packet_allocate. */ - tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER); + if (decrypted_packet == NX_NULL) + { + status = nx_packet_data_extract_offset(packet_ptr, record_offset, + tls_session -> nx_secure_tls_packet_buffer, + message_length, &bytes_copied); + } + else + { + status = nx_packet_data_extract_offset(decrypted_packet, 0, + tls_session -> nx_secure_tls_packet_buffer, + message_length, &bytes_copied); + } - if (status) + if (status || (bytes_copied != message_length)) { - return(status); + return(NX_SECURE_TLS_INVALID_PACKET); } } @@ -425,26 +461,12 @@ ULONG record_offset = 0; mitigation by some TLS implementations (notably OpenSSL). */ if (message_length == 0) { + record_offset = record_offset_next; status = NX_CONTINUE; } else { - - /* Handshake is complete, send message to application. */ - /* Release the protection before suspending on nx_packet_data_append. */ - tx_mutex_put(&_nx_secure_tls_protection); - - status = nx_packet_data_append(tls_session -> nx_secure_record_decrypted_packet, packet_data, message_length, - tls_session -> nx_secure_tls_packet_pool, wait_option); - - /* Get the protection after nx_packet_data_append. */ - tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER); - -#ifdef NX_SECURE_KEY_CLEAR - tx_mutex_put(&_nx_secure_tls_protection); - NX_SECURE_MEMSET(packet_data, 0, message_length); - tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER); -#endif /* NX_SECURE_KEY_CLEAR */ + status = NX_SECURE_TLS_SUCCESS; } break; default: @@ -452,8 +474,96 @@ ULONG record_offset = 0; status = NX_SECURE_TLS_UNRECOGNIZED_MESSAGE_TYPE; break; } + +#ifdef NX_SECURE_KEY_CLEAR + if (message_type != NX_SECURE_TLS_APPLICATION_DATA) + { + NX_SECURE_MEMSET(packet_data, 0, message_length); + } +#endif /* NX_SECURE_KEY_CLEAR */ } return(status); } +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _nx_secure_tls_packet_trim PORTABLE C */ +/* 6.0.2 */ +/* AUTHOR */ +/* */ +/* Timothy Stapko, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function trims TLS packet after decryption and hash verify. */ +/* */ +/* INPUT */ +/* */ +/* packet_ptr NX_PACKET containing a record */ +/* */ +/* OUTPUT */ +/* */ +/* status Completion status */ +/* */ +/* CALLS */ +/* */ +/* nx_secure_tls_packet_release Release packet */ +/* */ +/* CALLED BY */ +/* */ +/* _nx_secure_tls_process_record Process TLS records */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 08-14-2020 Timothy Stapko Initial Version 6.0.2 */ +/* */ +/**************************************************************************/ +static VOID _nx_secure_tls_packet_trim(NX_PACKET *packet_ptr) +{ +ULONG payload_length; +ULONG message_length = packet_ptr -> nx_packet_length; +NX_PACKET *current_ptr; + + if (message_length == 0) + { + + /* Make sure the head packet is not released when the length is zero. */ + if (packet_ptr -> nx_packet_next) + { + + /* Release packet if remaining data are in chained packet. */ + nx_secure_tls_packet_release(packet_ptr -> nx_packet_next); + packet_ptr -> nx_packet_next = NX_NULL; + packet_ptr -> nx_packet_last = packet_ptr; + } + packet_ptr -> nx_packet_prepend_ptr = packet_ptr -> nx_packet_data_start; + packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_data_start; + return; + } + + for (current_ptr = packet_ptr; current_ptr; current_ptr = current_ptr -> nx_packet_next) + { + payload_length = (ULONG)(current_ptr -> nx_packet_append_ptr - current_ptr -> nx_packet_prepend_ptr); + if (message_length < payload_length) + { + + /* Trim data from this packet. */ + current_ptr -> nx_packet_append_ptr = current_ptr -> nx_packet_prepend_ptr + message_length; + if (current_ptr -> nx_packet_next) + { + + /* Release packet if remaining data are in chained packet. */ + nx_secure_tls_packet_release(current_ptr -> nx_packet_next); + current_ptr -> nx_packet_next = NX_NULL; + packet_ptr -> nx_packet_last = current_ptr; + } + break; + } + message_length -= (ULONG)(current_ptr -> nx_packet_append_ptr - current_ptr -> nx_packet_prepend_ptr); + } +} diff --git a/nx_secure/src/nx_secure_tls_process_serverhello.c b/nx_secure/src/nx_secure_tls_process_serverhello.c index d7a264d7..9248348c 100644 --- a/nx_secure/src/nx_secure_tls_process_serverhello.c +++ b/nx_secure/src/nx_secure_tls_process_serverhello.c @@ -32,7 +32,7 @@ extern const UCHAR _nx_secure_tls_hello_retry_request_random[32]; /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_process_serverhello PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -76,6 +76,9 @@ extern const UCHAR _nx_secure_tls_hello_retry_request_random[32]; /* 06-30-2020 Timothy Stapko Modified comment(s), added */ /* priority ciphersuite logic, */ /* resulting in version 6.0.1 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), added */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_process_serverhello(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, @@ -111,6 +114,16 @@ NX_SECURE_TLS_SERVER_STATE old_client_state = tls_session -> nx_secur /* Use our length as an index into the buffer. */ length = 0; +#if (NX_SECURE_TLS_TLS_1_3_ENABLED) + if (tls_session -> nx_secure_tls_1_3 && tls_session -> nx_secure_tls_local_session_active) + { + + /* Client has negotiated TLS 1.3 and receives a ServerHello again. + * Send an unexpected message alert. */ + return(NX_SECURE_TLS_UNEXPECTED_MESSAGE); + } +#endif + /* First two bytes of the server hello following the header are the TLS major and minor version numbers. */ version = (USHORT)((packet_buffer[length] << 8) + packet_buffer[length + 1]); length += 2; @@ -244,6 +257,31 @@ NX_SECURE_TLS_SERVER_STATE old_client_state = tls_session -> nx_secur } } +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION +#ifdef NX_SECURE_TLS_REQUIRE_RENEGOTIATION_EXT +#if (NX_SECURE_TLS_TLS_1_3_ENABLED) + if (!tls_session -> nx_secure_tls_1_3) +#endif /* NX_SECURE_TLS_TLS_1_3_ENABLED */ + { + if ((tls_session -> nx_secure_tls_renegotation_enabled) && (!tls_session -> nx_secure_tls_secure_renegotiation)) + { + + /* No "renegotiation_info" extension present, some clients may want to terminate the handshake. */ + return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); + } + } +#endif /* NX_SECURE_TLS_REQUIRE_RENEGOTIATION_EXT */ + + if ((tls_session -> nx_secure_tls_local_session_active) && (!tls_session -> nx_secure_tls_secure_renegotiation_verified)) + { + + /* The client did not receive the "renegotiation_info" extension, the handshake must be aborted. */ + return(NX_SECURE_TLS_RENEGOTIATION_EXTENSION_ERROR); + } + + tls_session -> nx_secure_tls_secure_renegotiation_verified = NX_FALSE; +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ + #ifdef NX_SECURE_TLS_CLIENT_DISABLED /* If TLS Client is disabled and we have processed a ServerHello, something is wrong... */ tls_session -> nx_secure_tls_server_state = NX_SECURE_TLS_SERVER_STATE_ERROR; diff --git a/nx_secure/src/nx_secure_tls_process_serverhello_extensions.c b/nx_secure/src/nx_secure_tls_process_serverhello_extensions.c index 007313f3..f6acc4dc 100644 --- a/nx_secure/src/nx_secure_tls_process_serverhello_extensions.c +++ b/nx_secure/src/nx_secure_tls_process_serverhello_extensions.c @@ -24,7 +24,7 @@ #include "nx_secure_tls.h" -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION static UINT _nx_secure_tls_proc_serverhello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, USHORT *extension_length, UINT message_length); @@ -56,7 +56,7 @@ static UINT _nx_secure_tls_proc_serverhello_ecjpake_key_kp_pair(NX_SECURE_TLS_SE /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_process_serverhello_extensions PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -99,6 +99,9 @@ static UINT _nx_secure_tls_proc_serverhello_ecjpake_key_kp_pair(NX_SECURE_TLS_SE /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_process_serverhello_extensions(NX_SECURE_TLS_SESSION *tls_session, @@ -118,7 +121,7 @@ USHORT extension_length; USHORT supported_version = tls_session -> nx_secure_tls_protocol_version; #endif -#ifndef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifdef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION #ifndef NX_SECURE_ENABLE_ECJPAKE_CIPHERSUITE NX_PARAMETER_NOT_USED(tls_session); #endif @@ -158,7 +161,7 @@ USHORT supported_version = tls_session -> nx_secu /* Parse the extension. */ switch (extension_id) { -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION case NX_SECURE_TLS_EXTENSION_SECURE_RENEGOTIATION: status = _nx_secure_tls_proc_serverhello_sec_reneg_extension(tls_session, &packet_buffer[offset], &extension_length, message_length - offset); @@ -167,7 +170,7 @@ USHORT supported_version = tls_session -> nx_secu return(status); } break; -#endif /* NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION */ +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ #if (NX_SECURE_TLS_TLS_1_3_ENABLED) #ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE case NX_SECURE_TLS_EXTENSION_KEY_SHARE: @@ -336,7 +339,9 @@ USHORT supported_version = tls_session -> nx_secu if (tls_session -> nx_secure_tls_protocol_version_override == 0) { tls_session -> nx_secure_tls_1_3 = NX_FALSE; +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION tls_session -> nx_secure_tls_renegotation_enabled = NX_TRUE; +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ } else { @@ -557,7 +562,7 @@ NX_CRYPTO_METHOD *crypto_method; /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_proc_serverhello_sec_reneg_extension PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -593,9 +598,12 @@ NX_CRYPTO_METHOD *crypto_method; /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION static UINT _nx_secure_tls_proc_serverhello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, USHORT *extension_length, UINT message_length) @@ -703,6 +711,7 @@ INT compare_value; } /* If we get here, the verification data is good! */ + tls_session -> nx_secure_tls_secure_renegotiation_verified = NX_TRUE; } else { diff --git a/nx_secure/src/nx_secure_tls_record_payload_decrypt.c b/nx_secure/src/nx_secure_tls_record_payload_decrypt.c index 50f71e29..18081416 100644 --- a/nx_secure/src/nx_secure_tls_record_payload_decrypt.c +++ b/nx_secure/src/nx_secure_tls_record_payload_decrypt.c @@ -28,12 +28,28 @@ static UCHAR save_iv[20]; /* Must be large enough to hold the block size for session ciphers! */ #endif +static UINT _nx_secure_tls_record_chained_packet_decrypt(NX_SECURE_TLS_SESSION *tls_session, + NX_PACKET *encrypted_packet, UINT offset, + UINT message_length, NX_PACKET **decrypted_packet, + UCHAR *additional_data, UINT additional_data_size, + UCHAR *iv, UINT wait_option); +static UINT _nx_secure_tls_record_packet_decrypt(NX_SECURE_TLS_SESSION *tls_session, + const NX_CRYPTO_METHOD *session_cipher_method, + NX_PACKET *encrypted_packet, UINT offset, UINT message_length, + NX_PACKET *decrypted_packet, UINT *bytes_processed, + UINT wait_option); +static UINT _nx_secure_tls_data_decrypt(NX_SECURE_TLS_SESSION *tls_session, + UCHAR *input, UCHAR *output, UINT length); + +/* Defined in nx_secure_tls_record_payload_encrypt.c */ +extern UCHAR _nx_secure_tls_record_block_buffer[NX_SECURE_TLS_MAX_CIPHER_BLOCK_SIZE]; + /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_record_payload_decrypt PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -47,10 +63,17 @@ static UCHAR save_iv[20]; /* Must be large enough to hold the block size for ses /* INPUT */ /* */ /* tls_session TLS control block */ -/* data Pointer to message data */ -/* length Length of message data (bytes)*/ +/* encrypted_packet Pointer to packet containing */ +/* encrypted_packet */ +/* offset Offset of message data in */ +/* encrypted_packet */ +/* message_length Length of message data in */ +/* encrypted_packet */ +/* decrypted_packet Pointer to packet containing */ +/* decrypted_packet */ /* sequence_num Record sequence number */ /* record_type Record type */ +/* wait_option Control timeout options */ /* */ /* OUTPUT */ /* */ @@ -59,6 +82,9 @@ static UCHAR save_iv[20]; /* Must be large enough to hold the block size for ses /* CALLS */ /* */ /* [nx_crypto_operation] Crypto operation */ +/* nx_secure_tls_packet_release Release packet */ +/* _nx_secure_tls_record_chained_packet_decrypt */ +/* Decrypt chained packet */ /* */ /* CALLED BY */ /* */ @@ -73,29 +99,29 @@ static UCHAR save_iv[20]; /* Must be large enough to hold the block size for ses /* 06-30-2020 Timothy Stapko Modified comment(s), fixed */ /* AES-CBC padding oracle, */ /* resulting in version 6.0.1 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), fixed */ +/* supported chained packet, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ -UINT _nx_secure_tls_record_payload_decrypt(NX_SECURE_TLS_SESSION *tls_session, UCHAR *data, - UINT *length, +UINT _nx_secure_tls_record_payload_decrypt(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *encrypted_packet, + UINT offset, UINT message_length, NX_PACKET **decrypted_packet, ULONG sequence_num[NX_SECURE_TLS_SEQUENCE_NUMBER_SIZE], - UCHAR record_type) + UCHAR record_type, UINT wait_option) { UINT status; -VOID *crypto_method_metadata; -VOID *handler = NX_NULL; UCHAR *iv; UCHAR padding_length; +UCHAR copy_size; const NX_CRYPTO_METHOD *session_cipher_method; USHORT iv_size; -UCHAR *encrypted_data; -UCHAR *key = NX_NULL; UINT i; +ULONG bytes_copied; #ifdef NX_SECURE_ENABLE_AEAD_CIPHER UINT icv_size; UCHAR additional_data[13]; UINT additional_data_size; UCHAR nonce[13]; -UINT data_offset; #else NX_PARAMETER_NOT_USED(sequence_num); NX_PARAMETER_NOT_USED(record_type); @@ -109,8 +135,8 @@ UINT data_offset; return(NX_SECURE_TLS_UNKNOWN_CIPHERSUITE); } - /* Select the encryption algorithm based on the ciphersuite. Then, using the session keys and the chosen - cipher, encrypt the data in place. */ + /* Select the decryption algorithm based on the ciphersuite. Then, using the session keys and the chosen + cipher, decrypt the data. */ session_cipher_method = tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_session_cipher; /* Get the size of the IV used by the session cipher. */ @@ -119,25 +145,15 @@ UINT data_offset; /* Select our proper data structures. */ if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_SERVER) { + /* The socket is a TLS server, so use the *CLIENT* cipher to decrypt. */ - crypto_method_metadata = tls_session -> nx_secure_session_cipher_metadata_area_client; - handler = tls_session -> nx_secure_session_cipher_handler_client; iv = tls_session -> nx_secure_tls_key_material.nx_secure_tls_client_iv; - if (session_cipher_method -> nx_crypto_init == NX_NULL) - { - key = tls_session -> nx_secure_tls_key_material.nx_secure_tls_client_write_key; - } } else { + /* The socket is a TLS client, so use the *SERVER* cipher to decrypt. */ - crypto_method_metadata = tls_session -> nx_secure_session_cipher_metadata_area_server; - handler = tls_session -> nx_secure_session_cipher_handler_server; iv = tls_session -> nx_secure_tls_key_material.nx_secure_tls_server_iv; - if (session_cipher_method -> nx_crypto_init == NX_NULL) - { - key = tls_session -> nx_secure_tls_key_material.nx_secure_tls_server_write_key; - } } #ifdef NX_SECURE_ENABLE_AEAD_CIPHER @@ -204,17 +220,12 @@ UINT data_offset; additional_data[0] = record_type; additional_data[1] = (UCHAR)(0x03); additional_data[2] = (UCHAR)(0x03); - additional_data[3] = (UCHAR)((*length) >> 8); - additional_data[4] = (UCHAR)(*length); - //additional_data[3] = (UCHAR)((*length - icv_size) >> 8); - //additional_data[4] = (UCHAR)(*length - icv_size); + additional_data[3] = (UCHAR)((message_length) >> 8); + additional_data[4] = (UCHAR)(message_length); + - /* We have 5 bytes of additional data. */ additional_data_size = 5; - - /* Decrypt from beginning of data. */ - data_offset = 0; } else #endif @@ -242,13 +253,13 @@ UINT data_offset; icv_size = (session_cipher_method -> nx_crypto_ICV_size_in_bits >> 3); - if (*length < (8 + icv_size)) + if (message_length < (8 + icv_size)) { return(NX_SECURE_TLS_AEAD_DECRYPT_FAIL); } /* Remove length of nonce_explicit. */ - *length = *length - 8; + message_length -= 8; /* The length of CCMClientNonce or CCMServerNonce is 12 bytes. */ nonce[0] = 12; @@ -267,7 +278,12 @@ UINT data_offset; additional_data[7] = (UCHAR)(sequence_num[0]); /* Copy nonce_explicit from the data. */ - NX_SECURE_MEMCPY(&nonce[5], data, 8); + status = nx_packet_data_extract_offset(encrypted_packet, offset, + &nonce[5], 8, &bytes_copied); + if (status || (bytes_copied != 8)) + { + return(NX_SECURE_TLS_AEAD_DECRYPT_FAIL); + } /* additional_data = seq_num + TLSCompressed.type + TLSCompressed.version + TLSCompressed.length; @@ -275,59 +291,32 @@ UINT data_offset; additional_data[8] = record_type; additional_data[9] = (UCHAR)(tls_session -> nx_secure_tls_protocol_version >> 8); additional_data[10] = (UCHAR)(tls_session -> nx_secure_tls_protocol_version); - additional_data[11] = (UCHAR)((*length - icv_size) >> 8); - additional_data[12] = (UCHAR)(*length - icv_size); + additional_data[11] = (UCHAR)((message_length - icv_size) >> 8); + additional_data[12] = (UCHAR)(message_length - icv_size); /* We have 13 bytes of additional data (8 bytes seq num + 5 bytes header). */ additional_data_size = 13; /* Decrypt data following the nonce_explicit. */ - data_offset = 8; + offset += 8; } - if (*length < icv_size) + if (message_length < icv_size) { return(NX_SECURE_TLS_AEAD_DECRYPT_FAIL); } /* Decrypt the message payload using the session crypto method, and move the decrypted data to the beginning of the buffer. */ - if (session_cipher_method -> nx_crypto_operation != NX_NULL) + if (session_cipher_method -> nx_crypto_operation) { - /* Set additional data pointer and length. */ - status = session_cipher_method -> nx_crypto_operation(NX_CRYPTO_SET_ADDITIONAL_DATA, - handler, - (NX_CRYPTO_METHOD*)session_cipher_method, - NX_NULL, - NX_NULL, - additional_data, - additional_data_size, - NX_NULL, - NX_NULL, - NX_NULL, - crypto_method_metadata, - tls_session -> nx_secure_session_cipher_metadata_size, - NX_NULL, NX_NULL); - - if(status != NX_CRYPTO_SUCCESS) - { - return(status); - } - - /* Decrypt the payload. */ - status = session_cipher_method -> nx_crypto_operation(NX_CRYPTO_DECRYPT, - handler, - (NX_CRYPTO_METHOD*)session_cipher_method, - key, - session_cipher_method -> nx_crypto_key_size_in_bits, - &data[data_offset], - *length, + /* Decrypt the message payload using the session crypto method, and move the decrypted data to the beginning of the buffer. */ + status = _nx_secure_tls_record_chained_packet_decrypt(tls_session, encrypted_packet, offset, + message_length, decrypted_packet, + additional_data, + additional_data_size, nonce, - &data[data_offset], - *length, - crypto_method_metadata, - tls_session -> nx_secure_session_cipher_metadata_size, - NX_NULL, NX_NULL); + wait_option); #ifdef NX_SECURE_KEY_CLEAR NX_SECURE_MEMSET(additional_data, 0, sizeof(additional_data)); NX_SECURE_MEMSET(nonce, 0, sizeof(nonce)); @@ -343,15 +332,6 @@ UINT data_offset; return(status); } } - - /* Remove ICV length of the CCM cipher. */ - *length = *length - icv_size; - - /* Move the decrypted data. */ - if(data_offset != 0) - { - NX_SECURE_MEMMOVE(data, &data[data_offset], *length); - } } else #endif /* NX_SECURE_ENABLE_AEAD_CIPHER */ @@ -366,19 +346,11 @@ UINT data_offset; } GenericBlockCipher; */ - if (session_cipher_method -> nx_crypto_operation == NX_NULL) - { - return(NX_SECURE_TLS_SUCCESS); - } - - /* Pointer to our encrypted data. */ - encrypted_data = data; - #if (NX_SECURE_TLS_TLS_1_0_ENABLED) - if ((iv_size > *length) || + if ((iv_size > message_length) || (iv_size > sizeof(save_iv))) #else - if (iv_size > *length) + if (iv_size > message_length) #endif { @@ -388,67 +360,105 @@ UINT data_offset; #if (NX_SECURE_TLS_TLS_1_0_ENABLED) /* TLS 1.0 does not include the IV in the record, so use the one from the session.*/ - if (tls_session -> nx_secure_tls_protocol_version == NX_SECURE_TLS_VERSION_TLS_1_0) - { - if (session_cipher_method -> nx_crypto_algorithm == NX_CRYPTO_ENCRYPTION_AES_CBC) - { - /* New IV is the last encrypted block of the output. */ - NX_SECURE_MEMCPY(save_iv, &encrypted_data[*length - iv_size], iv_size); - } - } - else /* TLS 1.1, 1.2 */ + if (tls_session -> nx_secure_tls_protocol_version != NX_SECURE_TLS_VERSION_TLS_1_0) #endif { /* Copy IV from the beginning of the payload into our session buffer. */ - NX_SECURE_MEMCPY(iv, data, iv_size); + status = nx_packet_data_extract_offset(encrypted_packet, offset, + iv, iv_size, &bytes_copied); + if (status || (bytes_copied != iv_size)) + { + return(status); + } + offset += iv_size; /* Adjust payload length to account for IV that we saved off above. */ - *length -= iv_size; - - /* Adjust our encrypted data pointer to account for the IV. */ - encrypted_data = &data[iv_size]; + message_length -= iv_size; } /* Decrypt the message payload using the session crypto method, and move the decrypted data to the beginning of the buffer. */ - status = session_cipher_method -> nx_crypto_operation(NX_CRYPTO_DECRYPT, - handler, - (NX_CRYPTO_METHOD*)session_cipher_method, - key, - session_cipher_method -> nx_crypto_key_size_in_bits, - encrypted_data, - *length, - iv, - data, - *length, - crypto_method_metadata, - tls_session -> nx_secure_session_cipher_metadata_size, - NX_NULL, NX_NULL); + status = _nx_secure_tls_record_chained_packet_decrypt(tls_session, encrypted_packet, offset, + message_length, decrypted_packet, + NX_NULL, 0, iv, + wait_option); if(status != NX_CRYPTO_SUCCESS) { return(status); - } + } + + if (session_cipher_method -> nx_crypto_operation == NX_NULL) + { + return(NX_SECURE_TLS_SUCCESS); + } + +#if (NX_SECURE_TLS_TLS_1_0_ENABLED) + /* Update our IV for CBC mode. */ + if (tls_session -> nx_secure_tls_protocol_version == NX_SECURE_TLS_VERSION_TLS_1_0) + { + if (session_cipher_method -> nx_crypto_algorithm == NX_CRYPTO_ENCRYPTION_AES_CBC) + { + + /* New IV is the last encrypted block of the output. */ + status = nx_packet_data_extract_offset(encrypted_packet, (offset + message_length) - iv_size, + iv, iv_size, &bytes_copied); + if (status || (bytes_copied != iv_size)) + { + nx_secure_tls_packet_release(*decrypted_packet); + return(status); + } + } + } +#endif /* Get padding length from the final byte - CBC padding consists of a number of bytes each with a value equal to the padding length (e.g. 0x3 0x3 0x3 for 3 bytes of padding). */ - padding_length = data[*length - 1]; + message_length = (*decrypted_packet) -> nx_packet_length; + status = nx_packet_data_extract_offset(*decrypted_packet, message_length - 1, + &padding_length, 1, &bytes_copied); + if (status || (bytes_copied != 1)) + { + nx_secure_tls_packet_release(*decrypted_packet); + return(NX_SECURE_TLS_PADDING_CHECK_FAILED); + } /* If padding length is greater than our length, we have an error - don't check padding. */ - if (padding_length <= *length) + if (padding_length < message_length) { + status = NX_SUCCESS; + /* Check all padding values. */ - for(i = 0; i < padding_length; ++i) + offset = (UINT)(message_length - (UINT)(1 + padding_length)); + while ((offset < (message_length - 1)) && (status == NX_SUCCESS)) { - if(data[*length - 1 - i] != padding_length) + copy_size = (UCHAR)(((message_length - 1) - offset) & 0xFF); + if (copy_size > sizeof(_nx_secure_tls_record_block_buffer)) + { + copy_size = sizeof(_nx_secure_tls_record_block_buffer); + } + status = nx_packet_data_extract_offset(*decrypted_packet, + offset, _nx_secure_tls_record_block_buffer, + copy_size, &bytes_copied); + if (status) { - /* Padding byte is incorrect! */ - status = NX_SECURE_TLS_PADDING_CHECK_FAILED; - break; + nx_secure_tls_packet_release(*decrypted_packet); + return(NX_SECURE_TLS_PADDING_CHECK_FAILED); + } + + offset += bytes_copied; + + for(i = 0; i < bytes_copied; i++) + { + if(_nx_secure_tls_record_block_buffer[i] != padding_length) + { + + /* Padding byte is incorrect! */ + status = NX_SECURE_TLS_PADDING_CHECK_FAILED; + break; + } } } - /* If we get here, the padding checks out. */ - status = NX_SUCCESS; } else { @@ -456,31 +466,534 @@ UINT data_offset; status = NX_SECURE_TLS_PADDING_CHECK_FAILED; } - if(status == NX_SUCCESS) + /* Adjust length to remove padding. */ + /* Simply set packet length. The packet will be adjusted by caller. */ + message_length -= (UINT)(padding_length + 1); + (*decrypted_packet) -> nx_packet_length = message_length; + + /* Return error status if appropriate. */ + if(status != NX_SUCCESS) { - /* Adjust length to remove padding. */ - *length = (UINT)(*length - (UINT)(padding_length + 1)); + nx_secure_tls_packet_release(*decrypted_packet); + return(status); + } + } + return(NX_SUCCESS); +} + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _nx_secure_tls_record_chained_packet_decrypt PORTABLE C */ +/* 6.0.2 */ +/* AUTHOR */ +/* */ +/* Timothy Stapko, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function decrypts the payload of an incoming TLS record in */ +/* chained packet using the session keys generated and ciphersuite */ +/* determined during the TLS handshake. */ +/* */ +/* INPUT */ +/* */ +/* tls_session TLS control block */ +/* encrypted_packet Pointer to packet containing */ +/* encrypted_packet */ +/* offset Offset of message data in */ +/* encrypted_packet */ +/* message_length Length of message data in */ +/* encrypted_packet */ +/* decrypted_packet Pointer to packet containing */ +/* decrypted_packet */ +/* additional_data Pointer to additional data */ +/* additional_data_size Size of additional data */ +/* iv Pointer to initial vector */ +/* wait_option Control timeout options */ +/* */ +/* OUTPUT */ +/* */ +/* status Completion status */ +/* */ +/* CALLS */ +/* */ +/* [nx_crypto_operation] Crypto operation */ +/* _nx_secure_tls_record_packet_decrypt Decrypt packet in one packet */ +/* nx_secure_tls_packet_release Release packet */ +/* */ +/* CALLED BY */ +/* */ +/* _nx_secure_tls_record_payload_decrypt Decrypt TLS record payload */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 08-14-2020 Timothy Stapko Initial Version 6.0.2 */ +/* */ +/**************************************************************************/ +static UINT _nx_secure_tls_record_chained_packet_decrypt(NX_SECURE_TLS_SESSION *tls_session, + NX_PACKET *encrypted_packet, UINT offset, + UINT message_length, NX_PACKET **decrypted_packet, + UCHAR *additional_data, UINT additional_data_size, + UCHAR *iv, UINT wait_option) +{ +UINT status; +UCHAR *icv_ptr; +UINT icv_size; +UINT bytes_processed; +ULONG bytes_copied; +NX_PACKET *packet_ptr; +UINT icv_offset = offset; +VOID *handler = NX_NULL; +VOID *crypto_method_metadata; +const NX_CRYPTO_METHOD *session_cipher_method; + + /* Get ICV size. It is zero for CBC mode and non zero for AEAD mode. */ + session_cipher_method = tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_session_cipher; + icv_size = session_cipher_method -> nx_crypto_ICV_size_in_bits >> 3; + if ((icv_size > message_length) || (icv_size > sizeof(_nx_secure_tls_record_block_buffer))) + { + + /* Invalid packet. */ + return(NX_SECURE_TLS_INVALID_PACKET); + } + message_length -= icv_size; + icv_offset += message_length; + + /* Select our proper data structures. */ + if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_SERVER) + { + + /* The socket is a TLS server, so use the *CLIENT* cipher to decrypt. */ + crypto_method_metadata = tls_session -> nx_secure_session_cipher_metadata_area_client; + handler = tls_session -> nx_secure_session_cipher_handler_client; + } + else + { + + /* The socket is a TLS client, so use the *SERVER* cipher to decrypt. */ + crypto_method_metadata = tls_session -> nx_secure_session_cipher_metadata_area_server; + handler = tls_session -> nx_secure_session_cipher_handler_server; + } + + /* Set additional data pointer and length. */ + if (session_cipher_method -> nx_crypto_operation) + { + + /* Set additional data pointer and length. */ + status = session_cipher_method -> nx_crypto_operation(NX_CRYPTO_DECRYPT_INITIALIZE, + handler, + (NX_CRYPTO_METHOD*)session_cipher_method, + NX_NULL, 0, + additional_data, + additional_data_size, + iv, + NX_NULL, + message_length, + crypto_method_metadata, + tls_session -> nx_secure_session_cipher_metadata_size, + NX_NULL, NX_NULL); + + if(status != NX_CRYPTO_SUCCESS) + { + return(status); } + } -#if (NX_SECURE_TLS_TLS_1_0_ENABLED) - /* Update our IV for CBC mode. */ - if (tls_session -> nx_secure_tls_protocol_version == NX_SECURE_TLS_VERSION_TLS_1_0) + /* Allocate another packet for decryption. */ + status = nx_packet_allocate(tls_session -> nx_secure_tls_packet_pool, &packet_ptr, 0, wait_option); + if (status) + { + return(status); + } + packet_ptr -> nx_packet_last = packet_ptr; + + /* Loop to decrypt data in chained packet. */ + while (message_length > 0) + { + status = _nx_secure_tls_record_packet_decrypt(tls_session, session_cipher_method, encrypted_packet, + offset, message_length, packet_ptr, &bytes_processed, wait_option); + if (status) { - if (session_cipher_method -> nx_crypto_algorithm == NX_CRYPTO_ENCRYPTION_AES_CBC) - { - NX_SECURE_MEMCPY(iv, save_iv, iv_size); - } + nx_secure_tls_packet_release(packet_ptr); + return(status); } -#endif - /* Return error status if appropriate. */ - if(status != NX_SUCCESS) + if (bytes_processed > message_length) { + + /* Error. We should never hit here. */ + nx_secure_tls_packet_release(packet_ptr); + return(NX_SECURE_TLS_INVALID_PACKET); + } + + offset += bytes_processed; + message_length -= bytes_processed; + } + + if (session_cipher_method -> nx_crypto_operation == NX_NULL) + { + + /* Nothing to do for null encryption. */ + *decrypted_packet = packet_ptr; + return(NX_SECURE_TLS_SUCCESS); + } + + /* Extract ICV. */ + icv_ptr = _nx_secure_tls_record_block_buffer; + if (icv_size > 0) + { + status = nx_packet_data_extract_offset(encrypted_packet, icv_offset, + icv_ptr, icv_size, &bytes_copied); + if (status || (bytes_copied != icv_size)) + { + nx_secure_tls_packet_release(packet_ptr); return(status); } } - return(NX_SUCCESS); + status = session_cipher_method -> nx_crypto_operation(NX_CRYPTO_DECRYPT_CALCULATE, + handler, + (NX_CRYPTO_METHOD*)session_cipher_method, + NX_NULL, 0, + icv_ptr, + icv_size, + NX_NULL, + NX_NULL, + 0, + crypto_method_metadata, + tls_session -> nx_secure_session_cipher_metadata_size, + NX_NULL, NX_NULL); + + if (status) + { + nx_secure_tls_packet_release(packet_ptr); + if (status == NX_CRYPTO_AUTHENTICATION_FAILED) + { + return(NX_SECURE_TLS_AEAD_DECRYPT_FAIL); + } + else + { + return(status); + } + } + + *decrypted_packet = packet_ptr; + return(NX_SECURE_TLS_SUCCESS); } +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _nx_secure_tls_record_packet_decrypt PORTABLE C */ +/* 6.0.2 */ +/* AUTHOR */ +/* */ +/* Timothy Stapko, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function decrypts the payload of an incoming TLS record in */ +/* one packet using the session keys generated and ciphersuite */ +/* determined during the TLS handshake. */ +/* */ +/* INPUT */ +/* */ +/* tls_session TLS control block */ +/* session_cipher_method Pointer to cipher method */ +/* encrypted_packet Pointer to packet containing */ +/* encrypted_packet */ +/* offset Offset of message data in */ +/* encrypted_packet */ +/* message_length Length of message data in */ +/* encrypted_packet */ +/* decrypted_packet Pointer to packet containing */ +/* decrypted_packet */ +/* bytes_processed Output bytes processed */ +/* wait_option Control timeout options */ +/* */ +/* OUTPUT */ +/* */ +/* status Completion status */ +/* */ +/* CALLS */ +/* */ +/* [nx_crypto_operation] Crypto operation */ +/* _nx_secure_tls_data_decrypt Decrypt data */ +/* */ +/* CALLED BY */ +/* */ +/* _nx_secure_tls_record_chained_packet_decrypt */ +/* Decrypt chained packet */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 08-14-2020 Timothy Stapko Initial Version 6.0.2 */ +/* */ +/**************************************************************************/ +static UINT _nx_secure_tls_record_packet_decrypt(NX_SECURE_TLS_SESSION *tls_session, + const NX_CRYPTO_METHOD *session_cipher_method, + NX_PACKET *encrypted_packet, UINT offset, UINT message_length, + NX_PACKET *decrypted_packet, UINT *bytes_processed, + UINT wait_option) +{ +UINT status; +UCHAR *input; +UCHAR *output; +NX_PACKET *original_encrypted_packet = encrypted_packet; +NX_PACKET *packet_ptr; +UINT length; +UINT block_size; +UINT encrypted_length; +UINT decrypted_length; +ULONG bytes_copied; +UINT remainder_length; +UINT original_offset = offset; + + /* Total packet length is no less than message length from nx_secure_tls_process_record.c. + * We don't need to validate packet error in this function. */ + + /* block_size must be no larger than NX_SECURE_TLS_MAX_CIPHER_BLOCK_SIZE. */ + block_size = session_cipher_method -> nx_crypto_block_size_in_bytes; + NX_ASSERT(block_size <= sizeof(_nx_secure_tls_record_block_buffer)); + + /* Locate input data. */ + while (offset) + { + encrypted_length = (UINT)(encrypted_packet -> nx_packet_append_ptr - encrypted_packet -> nx_packet_prepend_ptr); + if (encrypted_length > offset) + { + + /* Input data are in current packet*/ + break; + } + + /* Go to next packet. */ + offset -= encrypted_length; + encrypted_packet = encrypted_packet -> nx_packet_next; + } + + /* Get actual encrypted_length in current packet. */ + encrypted_length = (UINT)(encrypted_packet -> nx_packet_append_ptr - encrypted_packet -> nx_packet_prepend_ptr); + encrypted_length -= offset; + if (encrypted_length < block_size) + { + + /* Use _nx_secure_tls_record_block_buffer for decryption. */ + status = nx_packet_data_extract_offset(original_encrypted_packet, original_offset, + _nx_secure_tls_record_block_buffer, block_size, &bytes_copied); + if (status) + { + return(status); + } + input = _nx_secure_tls_record_block_buffer; + length = bytes_copied; + } + else + { + input = encrypted_packet -> nx_packet_prepend_ptr + offset; + length = encrypted_length; + + if (block_size) + { + + /* Get rounded length. */ + remainder_length = length % block_size; + } + else + { + remainder_length = 0; + } + + length -= remainder_length; + } + if (length > message_length) + { + length = message_length; + } + + /* decrypted_packet can not be NULL. */ + NX_ASSERT(decrypted_packet != NX_NULL); + + /* decrypted_packet -> nx_packet_last is set by caller. */ + /* Get available size of decrypted_packet. */ + packet_ptr = decrypted_packet -> nx_packet_last; + decrypted_length = (UINT)(packet_ptr -> nx_packet_data_end - packet_ptr -> nx_packet_append_ptr); + + if (decrypted_length == 0) + { + + /* Allocate another packet for decryption. */ + status = nx_packet_allocate(tls_session -> nx_secure_tls_packet_pool, &packet_ptr, 0, wait_option); + if (status) + { + return(status); + } + + /* Link to decrypted_packet. */ + decrypted_packet -> nx_packet_last -> nx_packet_next = packet_ptr; + decrypted_packet -> nx_packet_last = packet_ptr; + decrypted_length = (UINT)(packet_ptr -> nx_packet_data_end - packet_ptr -> nx_packet_append_ptr); + } + + if ((decrypted_length < block_size) && (decrypted_length < length)) + { + + /* Use _nx_secure_tls_record_block_buffer for decryption output. */ + output = _nx_secure_tls_record_block_buffer; + decrypted_length = block_size; + } + else + { + + /* Decrypt output to packet directly. */ + output = packet_ptr -> nx_packet_append_ptr; + + if (block_size) + { + + /* Get rounded length. */ + remainder_length = decrypted_length % block_size; + } + else + { + remainder_length = 0; + } + + decrypted_length -= remainder_length; + } + if (length > decrypted_length) + { + length = decrypted_length; + } + + if (session_cipher_method -> nx_crypto_operation == NX_NULL) + { + NX_SECURE_MEMCPY(output, input, length); + } + else + { + + /* Decrypt data. */ + status = _nx_secure_tls_data_decrypt(tls_session, input, output, length); + if (status) + { + return(status); + } + } + + if (output == _nx_secure_tls_record_block_buffer) + { + + /* Append decrypted data. */ + status = nx_packet_data_append(decrypted_packet, output, length, + tls_session -> nx_secure_tls_packet_pool, wait_option); + if (status) + { + return(status); + } + } + else + { + + /* Adjust decrypted packet. */ + packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_append_ptr + length; + decrypted_packet -> nx_packet_length += length; + } + + *bytes_processed = length; + + return(NX_SECURE_TLS_SUCCESS); +} + +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _nx_secure_tls_data_decrypt PORTABLE C */ +/* 6.0.2 */ +/* AUTHOR */ +/* */ +/* Timothy Stapko, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function decrypts partial incoming TLS record data using the */ +/* session keys generated and ciphersuite determined during the TLS */ +/* handshake. */ +/* */ +/* INPUT */ +/* */ +/* tls_session TLS control block */ +/* input Pointer to cipher data */ +/* output Output of plain data */ +/* length Length of message data */ +/* */ +/* OUTPUT */ +/* */ +/* status Completion status */ +/* */ +/* CALLS */ +/* */ +/* [nx_crypto_operation] Crypto operation */ +/* */ +/* CALLED BY */ +/* */ +/* _nx_secure_tls_record_packet_decrypt Decrypt data in packet */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 08-14-2020 Timothy Stapko Initial Version 6.0.2 */ +/* */ +/**************************************************************************/ +static UINT _nx_secure_tls_data_decrypt(NX_SECURE_TLS_SESSION *tls_session, + UCHAR *input, UCHAR *output, UINT length) +{ +UINT status; +VOID *handler = NX_NULL; +VOID *crypto_method_metadata; +const NX_CRYPTO_METHOD *session_cipher_method; + + /* Select our proper data structures. */ + if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_SERVER) + { + + /* The socket is a TLS server, so use the *CLIENT* cipher to decrypt. */ + crypto_method_metadata = tls_session -> nx_secure_session_cipher_metadata_area_client; + handler = tls_session -> nx_secure_session_cipher_handler_client; + } + else + { + + /* The socket is a TLS client, so use the *SERVER* cipher to decrypt. */ + crypto_method_metadata = tls_session -> nx_secure_session_cipher_metadata_area_server; + handler = tls_session -> nx_secure_session_cipher_handler_server; + } + + session_cipher_method = tls_session -> nx_secure_tls_session_ciphersuite -> nx_secure_tls_session_cipher; + + /* Decrypt data. */ + status = session_cipher_method -> nx_crypto_operation(NX_CRYPTO_DECRYPT_UPDATE, + handler, + (NX_CRYPTO_METHOD*)session_cipher_method, + NX_NULL, 0, + input, + length, + NX_NULL, + output, + length, + crypto_method_metadata, + tls_session -> nx_secure_session_cipher_metadata_size, + NX_NULL, NX_NULL); + + return(status); +} diff --git a/nx_secure/src/nx_secure_tls_record_payload_encrypt.c b/nx_secure/src/nx_secure_tls_record_payload_encrypt.c index 87e704d4..f279e636 100644 --- a/nx_secure/src/nx_secure_tls_record_payload_encrypt.c +++ b/nx_secure/src/nx_secure_tls_record_payload_encrypt.c @@ -29,14 +29,14 @@ static UINT _nx_secure_tls_record_data_encrypt_init(NX_SECURE_TLS_SESSION *tls_s UCHAR record_type, UINT *data_offset, const NX_CRYPTO_METHOD *session_cipher_method); -static UCHAR _nx_secure_tls_record_block_buffer[NX_SECURE_TLS_MAX_CIPHER_BLOCK_SIZE]; +UCHAR _nx_secure_tls_record_block_buffer[NX_SECURE_TLS_MAX_CIPHER_BLOCK_SIZE]; /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_record_payload_encrypt PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -72,6 +72,10 @@ static UCHAR _nx_secure_tls_record_block_buffer[NX_SECURE_TLS_MAX_CIPHER_BLOCK_S /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed data copy in chained */ +/* packet, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_record_payload_encrypt(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *send_packet, @@ -86,6 +90,7 @@ USHORT iv_size; NX_PACKET *current_packet; ULONG current_length; ULONG rounded_length; +ULONG copy_length; ULONG remainder_length; UINT data_offset = 0; VOID *handler = NX_NULL; @@ -133,7 +138,8 @@ VOID *crypto_method_metadata; iv_size = session_cipher_method -> nx_crypto_IV_size_in_bits >> 3; /* Make sure our block size is small enough to fit into our buffer. */ - NX_ASSERT(iv_size <= NX_SECURE_TLS_MAX_CIPHER_BLOCK_SIZE); + NX_ASSERT((iv_size <= NX_SECURE_TLS_MAX_CIPHER_BLOCK_SIZE) && + (block_size <= NX_SECURE_TLS_MAX_CIPHER_BLOCK_SIZE)); status = _nx_secure_tls_record_data_encrypt_init(tls_session, send_packet, sequence_num, record_type, &data_offset, session_cipher_method); if (status) @@ -206,27 +212,30 @@ VOID *crypto_method_metadata; } rounded_length = current_length - remainder_length; - /* Encrypt remaining data in the current packet from our previous offset to evenly-divisible block boundary. */ - status = session_cipher_method -> nx_crypto_operation(NX_CRYPTO_ENCRYPT_UPDATE, - handler, - (NX_CRYPTO_METHOD *)session_cipher_method, - NX_NULL, - 0, - ¤t_packet -> nx_packet_prepend_ptr[data_offset], - rounded_length, - NX_NULL, - ¤t_packet -> nx_packet_prepend_ptr[data_offset], - rounded_length, - crypto_method_metadata, - tls_session -> nx_secure_session_cipher_metadata_size, - NX_NULL, NX_NULL); - - if (status != NX_SUCCESS) + if (rounded_length > 0) { + /* Encrypt remaining data in the current packet from our previous offset to evenly-divisible block boundary. */ + status = session_cipher_method -> nx_crypto_operation(NX_CRYPTO_ENCRYPT_UPDATE, + handler, + (NX_CRYPTO_METHOD *)session_cipher_method, + NX_NULL, + 0, + ¤t_packet -> nx_packet_prepend_ptr[data_offset], + rounded_length, + NX_NULL, + ¤t_packet -> nx_packet_prepend_ptr[data_offset], + rounded_length, + crypto_method_metadata, + tls_session -> nx_secure_session_cipher_metadata_size, + NX_NULL, NX_NULL); + + if (status != NX_SUCCESS) + { #ifdef NX_SECURE_KEY_CLEAR - NX_SECURE_MEMSET(_nx_secure_tls_record_block_buffer, 0, block_size); + NX_SECURE_MEMSET(_nx_secure_tls_record_block_buffer, 0, block_size); #endif /* NX_SECURE_KEY_CLEAR */ - return(status); + return(status); + } } if (remainder_length) @@ -243,9 +252,15 @@ VOID *crypto_method_metadata; NX_SECURE_MEMCPY(&_nx_secure_tls_record_block_buffer[0], ¤t_packet -> nx_packet_prepend_ptr[rounded_length + data_offset], remainder_length); + copy_length = (ULONG)(current_packet -> nx_packet_next -> nx_packet_append_ptr - + current_packet -> nx_packet_next -> nx_packet_prepend_ptr); + if (copy_length > (ULONG)(block_size - remainder_length)) + { + copy_length = (ULONG)(block_size - remainder_length); + } NX_SECURE_MEMCPY(&_nx_secure_tls_record_block_buffer[remainder_length], current_packet -> nx_packet_next -> nx_packet_prepend_ptr, - block_size - remainder_length); + copy_length); /* Encrypt the remainder block. */ status = session_cipher_method -> nx_crypto_operation(NX_CRYPTO_ENCRYPT_UPDATE, @@ -254,10 +269,10 @@ VOID *crypto_method_metadata; NX_NULL, 0, _nx_secure_tls_record_block_buffer, - block_size, + (remainder_length + copy_length), NX_NULL, _nx_secure_tls_record_block_buffer, - block_size, + (remainder_length + copy_length), crypto_method_metadata, tls_session -> nx_secure_session_cipher_metadata_size, NX_NULL, NX_NULL); @@ -276,7 +291,7 @@ VOID *crypto_method_metadata; &_nx_secure_tls_record_block_buffer[0], remainder_length); NX_SECURE_MEMCPY(current_packet -> nx_packet_next -> nx_packet_prepend_ptr, &_nx_secure_tls_record_block_buffer[remainder_length], - block_size - remainder_length); + copy_length); /* CBC-mode ciphers need to have their IV's updated after encryption. */ if (session_cipher_method -> nx_crypto_algorithm == NX_CRYPTO_ENCRYPTION_AES_CBC) @@ -292,7 +307,7 @@ VOID *crypto_method_metadata; /* Finally, our new offset for the next round is the number of bytes we already encrypted (along with the remainder bytes) in the next packet. */ - data_offset = block_size - remainder_length; + data_offset = copy_length; } else { @@ -349,7 +364,7 @@ VOID *crypto_method_metadata; /* */ /* FUNCTION RELEASE */ /* */ -/* _nx_secure_tls_record_data_encrypt PORTABLE C */ +/* _nx_secure_tls_record_data_encrypt_init PORTABLE C */ /* 6.0 */ /* AUTHOR */ /* */ diff --git a/nx_secure/src/nx_secure_tls_remote_certificate_free.c b/nx_secure/src/nx_secure_tls_remote_certificate_free.c index e878cdd5..3b461c00 100644 --- a/nx_secure/src/nx_secure_tls_remote_certificate_free.c +++ b/nx_secure/src/nx_secure_tls_remote_certificate_free.c @@ -32,7 +32,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_remote_certificate_free PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -71,6 +71,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), fixed */ +/* certificate allocation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_remote_certificate_free(NX_SECURE_TLS_SESSION *tls_session, @@ -98,12 +101,17 @@ NX_SECURE_X509_CERT *certificate; /* Remove the certificate from the remote store. */ _nx_secure_x509_store_certificate_remove(store, name, NX_SECURE_X509_CERT_LOCATION_REMOTE, 0); - /* Add the certificate back to the free store. */ - status = _nx_secure_x509_store_certificate_add(certificate, store, NX_SECURE_X509_CERT_LOCATION_FREE); - - if (status != NX_SUCCESS) + /* Only user allocated certificate is added back to the free store. */ + if (certificate -> nx_secure_x509_user_allocated_cert) { - return(status); + + /* Add the certificate back to the free store. */ + status = _nx_secure_x509_store_certificate_add(certificate, store, NX_SECURE_X509_CERT_LOCATION_FREE); + + if (status != NX_SUCCESS) + { + return(status); + } } /* Return completion status. */ diff --git a/nx_secure/src/nx_secure_tls_send_clienthello_extensions.c b/nx_secure/src/nx_secure_tls_send_clienthello_extensions.c index a09f7321..7fa2775e 100644 --- a/nx_secure/src/nx_secure_tls_send_clienthello_extensions.c +++ b/nx_secure/src/nx_secure_tls_send_clienthello_extensions.c @@ -68,7 +68,7 @@ UINT _nx_secure_tls_send_clienthello_psk_extension(NX_SECURE_TLS_SESSION *tls_se ULONG available_size); #endif -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION static UINT _nx_secure_tls_send_clienthello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, ULONG *packet_offset, @@ -82,7 +82,7 @@ static UINT _nx_secure_tls_send_clienthello_sec_reneg_extension(NX_SECURE_TLS_SE /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_send_clienthello_extensions PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -127,6 +127,9 @@ static UINT _nx_secure_tls_send_clienthello_sec_reneg_extension(NX_SECURE_TLS_SE /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_send_clienthello_extensions(NX_SECURE_TLS_SESSION *tls_session, @@ -149,7 +152,7 @@ UINT status; total_extensions_length = (USHORT)(total_extensions_length + extension_length); #endif -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION /* We have to add renegotiation extensions in both initial sessions and renegotiating sessions. */ if (tls_session -> nx_secure_tls_renegotation_enabled == NX_TRUE) { @@ -1405,7 +1408,7 @@ UINT data_length; /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_send_clienthello_sec_reneg_extension PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -1443,9 +1446,12 @@ UINT data_length; /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION static UINT _nx_secure_tls_send_clienthello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, ULONG *packet_offset, diff --git a/nx_secure/src/nx_secure_tls_send_finished.c b/nx_secure/src/nx_secure_tls_send_finished.c index 63e15615..fc295b05 100644 --- a/nx_secure/src/nx_secure_tls_send_finished.c +++ b/nx_secure/src/nx_secure_tls_send_finished.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_send_finished PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -66,6 +66,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_send_finished(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *send_packet) @@ -112,7 +115,7 @@ UINT is_server; we have collected. Place the result directly into the packet buffer. */ status = _nx_secure_tls_finished_hash_generate(tls_session, finished_label, send_packet -> nx_packet_append_ptr); -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION /* If we are doing secure renegotiation as per RFC 5746, we need to save off the generated verify data now. For TLS 1.0-1.2 this is 12 bytes. If SSLv3 is ever used, it will be 36 bytes. */ NX_SECURE_MEMCPY(tls_session -> nx_secure_tls_local_verify_data, send_packet -> nx_packet_append_ptr, NX_SECURE_TLS_FINISHED_HASH_SIZE); diff --git a/nx_secure/src/nx_secure_tls_send_handshake_record.c b/nx_secure/src/nx_secure_tls_send_handshake_record.c index e0eda93f..e61c5e9f 100644 --- a/nx_secure/src/nx_secure_tls_send_handshake_record.c +++ b/nx_secure/src/nx_secure_tls_send_handshake_record.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_send_handshake_record PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -56,7 +56,7 @@ /* */ /* _nx_secure_tls_handshake_hash_update Update Finished message hash */ /* _nx_secure_tls_send_record Send the TLS record */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* */ /* CALLED BY */ /* */ @@ -70,6 +70,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_send_handshake_record(NX_SECURE_TLS_SESSION *tls_session, @@ -159,7 +162,7 @@ UINT buffer_offset; if (status != NX_SUCCESS) { /* Release packet on send error. */ - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); } return(status); diff --git a/nx_secure/src/nx_secure_tls_send_hellorequest.c b/nx_secure/src/nx_secure_tls_send_hellorequest.c index 33f876e2..a7a0ec0e 100644 --- a/nx_secure/src/nx_secure_tls_send_hellorequest.c +++ b/nx_secure/src/nx_secure_tls_send_hellorequest.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_send_hellorequest PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -64,8 +64,12 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION UINT _nx_secure_tls_send_hellorequest(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *send_packet) { NX_PARAMETER_NOT_USED(tls_session); @@ -78,4 +82,4 @@ UINT _nx_secure_tls_send_hellorequest(NX_SECURE_TLS_SESSION *tls_session, NX_PAC return(NX_SECURE_TLS_SUCCESS); } - +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ diff --git a/nx_secure/src/nx_secure_tls_send_serverhello_extensions.c b/nx_secure/src/nx_secure_tls_send_serverhello_extensions.c index f5102850..9d45d741 100644 --- a/nx_secure/src/nx_secure_tls_send_serverhello_extensions.c +++ b/nx_secure/src/nx_secure_tls_send_serverhello_extensions.c @@ -24,7 +24,7 @@ #include "nx_secure_tls.h" -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION static UINT _nx_secure_tls_send_serverhello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, ULONG *packet_offset, @@ -56,7 +56,7 @@ static UINT _nx_secure_tls_send_serverhello_psk_extension(NX_SECURE_TLS_SESSION /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_send_serverhello_extensions PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -93,6 +93,9 @@ static UINT _nx_secure_tls_send_serverhello_psk_extension(NX_SECURE_TLS_SESSION /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_send_serverhello_extensions(NX_SECURE_TLS_SESSION *tls_session, @@ -101,12 +104,16 @@ UINT _nx_secure_tls_send_serverhello_extensions(NX_SECURE_TLS_SESSION *tls_sessi { ULONG length = *packet_offset; UCHAR *extension_offset; -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#if !defined(NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION) || (NX_SECURE_TLS_TLS_1_3_ENABLED) USHORT extension_length = 0; -#endif /* NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION */ +#endif /* !defined(NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION) || (NX_SECURE_TLS_TLS_1_3_ENABLED) */ USHORT total_extensions_length; UINT status = NX_SUCCESS; +#if defined(NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION) && (!NX_SECURE_TLS_TLS_1_3_ENABLED) + NX_PARAMETER_NOT_USED(tls_session); +#endif /* defined(NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION) && (!NX_SECURE_TLS_TLS_1_3_ENABLED) */ + if (available_size < (*packet_offset + 2u)) { @@ -122,7 +129,7 @@ UINT status = NX_SUCCESS; length += 2; total_extensions_length = 0; -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION #if (NX_SECURE_TLS_TLS_1_3_ENABLED) /* Renegotiation is deprecated in TLS 1.3 so don't send extension. */ if(!tls_session->nx_secure_tls_1_3) @@ -138,7 +145,7 @@ UINT status = NX_SUCCESS; return(status); } } -#endif /* NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION */ +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ #if (NX_SECURE_TLS_TLS_1_3_ENABLED) @@ -212,7 +219,7 @@ UINT status = NX_SUCCESS; /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_send_serverhello_sec_reneg_extension PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -251,10 +258,11 @@ UINT status = NX_SUCCESS; /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ /* 06-30-2020 Timothy Stapko Modified comment(s), improved */ /* buffer length verification, */ -/* resulting in version 6.0.1 */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION static UINT _nx_secure_tls_send_serverhello_sec_reneg_extension(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, ULONG *packet_offset, diff --git a/nx_secure/src/nx_secure_tls_server_handshake.c b/nx_secure/src/nx_secure_tls_server_handshake.c index 091b30f7..0e87e217 100644 --- a/nx_secure/src/nx_secure_tls_server_handshake.c +++ b/nx_secure/src/nx_secure_tls_server_handshake.c @@ -31,7 +31,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_server_handshake PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -81,7 +81,7 @@ /* Send ServerKeyExchange */ /* _nx_secure_tls_send_serverhello Send TLS ServerHello */ /* _nx_secure_tls_session_keys_set Set session keys */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -94,6 +94,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* released packet securely, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_server_handshake(NX_SECURE_TLS_SESSION *tls_session, UCHAR *packet_buffer, @@ -387,7 +390,7 @@ const NX_CRYPTO_METHOD *method_ptr = NX_NULL; if (status != NX_SUCCESS) { - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); break; } @@ -495,7 +498,7 @@ const NX_CRYPTO_METHOD *method_ptr = NX_NULL; if (status != NX_SECURE_TLS_SUCCESS) { - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); } } diff --git a/nx_secure/src/nx_secure_tls_session_create_ext.c b/nx_secure/src/nx_secure_tls_session_create_ext.c index 1d11ef7d..68e7f5de 100644 --- a/nx_secure/src/nx_secure_tls_session_create_ext.c +++ b/nx_secure/src/nx_secure_tls_session_create_ext.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_create_ext PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -80,6 +80,10 @@ /* fixed race condition for */ /* multithread transmission, */ /* resulting in version 6.0.1 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), and */ +/* added ECC initialization, */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -485,6 +489,13 @@ USHORT ciphersuite_table_size; NX_SECURE_X509_CRYPTO *cert_crypto; USHORT cert_crypto_size; +#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE +NX_CRYPTO_METHOD **curve_crypto_list = NX_NULL; +USHORT *supported_groups = NX_NULL; +USHORT ecc_curves_count = 0; +UINT supported_groups_bytes; +#endif + #if (NX_SECURE_TLS_TLS_1_0_ENABLED || NX_SECURE_TLS_TLS_1_1_ENABLED) const NX_CRYPTO_METHOD *crypto_method_md5; const NX_CRYPTO_METHOD *crypto_method_sha1; @@ -562,6 +573,59 @@ const NX_CRYPTO_METHOD *crypto_method_sha256; /* Advance the metadata area past the end of the crypto table. */ metadata_area += cipher_table_bytes; metadata_size -= cipher_table_bytes; + +#ifdef NX_SECURE_ENABLE_ECC_CIPHERSUITE + curve_crypto_list = (NX_CRYPTO_METHOD **)(&metadata_area[0]); + + /* Find ECC curves in the crypto array. */ + for (i = 0; i < crypto_array_size; i++) + { + if ((crypto_array[i] -> nx_crypto_algorithm & 0xFFFF0000) == NX_CRYPTO_EC_MASK) + { + if (metadata_size < sizeof(NX_CRYPTO_METHOD *)) + { + return(NX_SECURE_TLS_INSUFFICIENT_METADATA_SPACE); + } + curve_crypto_list[ecc_curves_count] = (NX_CRYPTO_METHOD *)crypto_array[i]; + ecc_curves_count++; + metadata_size -= sizeof(NX_CRYPTO_METHOD *); + } + } + + if (ecc_curves_count > 0) + { + metadata_area += ecc_curves_count * sizeof(NX_CRYPTO_METHOD *); + supported_groups = (USHORT *)(&metadata_area[0]); + + supported_groups_bytes = ecc_curves_count * sizeof(USHORT); + + /* Align length to 4 bytes. */ + if (supported_groups_bytes & 0x3) + { + supported_groups_bytes += 4 - (supported_groups_bytes & 0x3); + } + + if (metadata_size < supported_groups_bytes) + { + return(NX_SECURE_TLS_INSUFFICIENT_METADATA_SPACE); + } + + metadata_area += supported_groups_bytes; + metadata_size -= supported_groups_bytes; + + for (i = 0; i < ecc_curves_count; i++) + { + supported_groups[i] = (USHORT)(curve_crypto_list[i] -> nx_crypto_algorithm & 0xFFFF); + } + + status = _nx_secure_tls_ecc_initialize(tls_session, supported_groups, ecc_curves_count, (const NX_CRYPTO_METHOD **)curve_crypto_list); + if (status != NX_SUCCESS) + { + return(status); + } + } +#endif + } /* Get working pointers to our crypto methods. */ @@ -804,6 +868,7 @@ const NX_CRYPTO_METHOD *crypto_method_sha256; } _nx_secure_tls_created_count++; +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION #if (NX_SECURE_TLS_TLS_1_3_ENABLED) /* Flag to indicate when a session renegotiation is enabled. Enabled by default. */ if(tls_session->nx_secure_tls_1_3) @@ -815,6 +880,7 @@ const NX_CRYPTO_METHOD *crypto_method_sha256; { tls_session -> nx_secure_tls_renegotation_enabled = NX_TRUE; } +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ /* Set ID to check initialization status. */ tls_session -> nx_secure_tls_id = NX_SECURE_TLS_ID; diff --git a/nx_secure/src/nx_secure_tls_session_delete.c b/nx_secure/src/nx_secure_tls_session_delete.c index 9f0bdad0..41e8377b 100644 --- a/nx_secure/src/nx_secure_tls_session_delete.c +++ b/nx_secure/src/nx_secure_tls_session_delete.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_delete PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -67,6 +67,9 @@ /* fixed race condition for */ /* multithread transmission, */ /* resulting in version 6.0.1 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), and */ +/* fixed underflow issue, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_session_delete(NX_SECURE_TLS_SESSION *tls_session) @@ -108,7 +111,13 @@ UINT status; _nx_secure_tls_created_ptr = tls_session -> nx_secure_tls_created_next; } } - _nx_secure_tls_created_count--; + + /* We shouldn't need this conditional but occasionally automated code may + call delete after all sessions have already been deleted. */ + if(_nx_secure_tls_created_count > 0) + { + _nx_secure_tls_created_count--; + } /* Make sure the session is completely reset - set ID to zero for error checking. */ tls_session -> nx_secure_tls_id = 0; diff --git a/nx_secure/src/nx_secure_tls_session_end.c b/nx_secure/src/nx_secure_tls_session_end.c index 51d61de9..cb370206 100644 --- a/nx_secure/src/nx_secure_tls_session_end.c +++ b/nx_secure/src/nx_secure_tls_session_end.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_end PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -56,7 +56,7 @@ /* _nx_secure_tls_send_alert Generate the CloseNotify */ /* _nx_secure_tls_send_record Send the CloseNotify */ /* _nx_secure_tls_session_reset Clear out the session */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -69,6 +69,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* supported chained packet, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_session_end(NX_SECURE_TLS_SESSION *tls_session, UINT wait_option) @@ -78,9 +81,6 @@ UINT error_return; UINT send_close_notify; NX_PACKET *send_packet; NX_PACKET *tmp_ptr; -#ifdef NX_SECURE_KEY_CLEAR -NX_PACKET *current_packet; -#endif /* NX_SECURE_KEY_CLEAR */ /* Get the protection. */ tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER); @@ -91,33 +91,11 @@ NX_PACKET *current_packet; tmp_ptr = tls_session -> nx_secure_record_queue_header; tls_session -> nx_secure_record_queue_header = tmp_ptr -> nx_packet_queue_next; tmp_ptr -> nx_packet_queue_next = NX_NULL; -#ifdef NX_SECURE_KEY_CLEAR - /* Clear all data in chained packet. */ - current_packet = tmp_ptr; - while (current_packet) - { - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - (ULONG)current_packet -> nx_packet_append_ptr - - (ULONG)current_packet -> nx_packet_prepend_ptr); - current_packet = current_packet -> nx_packet_next; - } -#endif /* NX_SECURE_KEY_CLEAR */ - nx_packet_release(tmp_ptr); + nx_secure_tls_packet_release(tmp_ptr); } if (tls_session -> nx_secure_record_decrypted_packet) { -#ifdef NX_SECURE_KEY_CLEAR - /* Clear all data in chained packet. */ - current_packet = tls_session -> nx_secure_record_decrypted_packet; - while (current_packet) - { - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - (ULONG)current_packet -> nx_packet_append_ptr - - (ULONG)current_packet -> nx_packet_prepend_ptr); - current_packet = current_packet -> nx_packet_next; - } -#endif /* NX_SECURE_KEY_CLEAR */ - nx_packet_release(tls_session -> nx_secure_record_decrypted_packet); + nx_secure_tls_packet_release(tls_session -> nx_secure_record_decrypted_packet); tls_session -> nx_secure_record_decrypted_packet = NX_NULL; } @@ -178,7 +156,7 @@ NX_PACKET *current_packet; if (status) { /* Release the packet on send errors. */ - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); /* Release the protection. */ tx_mutex_put(&_nx_secure_tls_protection); diff --git a/nx_secure/src/nx_secure_tls_session_protocol_version_override.c b/nx_secure/src/nx_secure_tls_session_protocol_version_override.c index b0b3b25c..94336c4a 100644 --- a/nx_secure/src/nx_secure_tls_session_protocol_version_override.c +++ b/nx_secure/src/nx_secure_tls_session_protocol_version_override.c @@ -32,7 +32,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_protocol_version_override PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -66,6 +66,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_session_protocol_version_override(NX_SECURE_TLS_SESSION *tls_session, @@ -91,7 +94,9 @@ UINT _nx_secure_tls_session_protocol_version_override(NX_SECURE_TLS_SESSION *tl tls_session -> nx_secure_tls_protocol_version_override = protocol_version; #if (NX_SECURE_TLS_TLS_1_3_ENABLED) tls_session -> nx_secure_tls_1_3 = NX_FALSE; +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION tls_session -> nx_secure_tls_renegotation_enabled = NX_TRUE; +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ #endif } diff --git a/nx_secure/src/nx_secure_tls_session_receive.c b/nx_secure/src/nx_secure_tls_session_receive.c index f9c87d14..cccadda6 100644 --- a/nx_secure/src/nx_secure_tls_session_receive.c +++ b/nx_secure/src/nx_secure_tls_session_receive.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_receive PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -56,7 +56,6 @@ /* _nx_secure_tls_handshake_process Process TLS handshake */ /* _nx_secure_tls_session_receive_records */ /* Receive TLS records */ -/* nx_packet_release Release packet */ /* */ /* CALLED BY */ /* */ @@ -67,27 +66,31 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* supported chained packet, */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_session_receive(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET **packet_ptr_ptr, ULONG wait_option) { UINT status; +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION UINT local_initiated_renegotiation = NX_FALSE; -#ifdef NX_SECURE_KEY_CLEAR -NX_PACKET *current_packet; -#endif /* NX_SECURE_KEY_CLEAR */ +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ /* Session receive logic: * 1. Receive incoming packets * 2. Process records and receive while full record is not yet received. - * 3. If renegotiation inititated, process the renegotiation handshake. + * 3. If renegotiation initiated, process the renegotiation handshake. * 3a. Process entire handshake (receive TCP packets, process records) * 3b. Once handshake processed, receive any new packets, but only if * the remote host initiated the renegotiation. */ +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION #ifndef NX_SECURE_TLS_CLIENT_DISABLED if (tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_CLIENT && tls_session -> nx_secure_tls_client_state == NX_SECURE_TLS_CLIENT_STATE_RENEGOTIATING) @@ -103,30 +106,17 @@ NX_PACKET *current_packet; local_initiated_renegotiation = NX_TRUE; } #endif +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ /* Try receiving records from the remote host. */ status = _nx_secure_tls_session_receive_records(tls_session, packet_ptr_ptr, wait_option); +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION /* See if we have a renegotiation handshake. Continue processing following the hello message that was received. */ if (status == NX_SUCCESS && tls_session -> nx_secure_tls_renegotiation_handshake) { -#ifdef NX_SECURE_KEY_CLEAR - /* Clear all data in chained packet. */ - current_packet = *packet_ptr_ptr; - while (current_packet) - { - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - (ULONG)current_packet -> nx_packet_append_ptr - - (ULONG)current_packet -> nx_packet_prepend_ptr); - current_packet = current_packet -> nx_packet_next; - } -#endif /* NX_SECURE_KEY_CLEAR */ - - /* Release the incoming packet if we do receive it. */ - nx_packet_release(*packet_ptr_ptr); - /* Clear flag to prevent infinite recursion. */ tls_session -> nx_secure_tls_renegotiation_handshake = NX_FALSE; @@ -146,12 +136,16 @@ NX_PACKET *current_packet; status = _nx_secure_tls_session_receive_records(tls_session, packet_ptr_ptr, wait_option); } } - else if(status == NX_SECURE_TLS_POST_HANDSHAKE_RECEIVED) + else +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ { - /* Continue processing while we are receiving post-handshake messages. */ - while(status == NX_SECURE_TLS_POST_HANDSHAKE_RECEIVED) + if (status == NX_SECURE_TLS_POST_HANDSHAKE_RECEIVED) { - status = _nx_secure_tls_session_receive_records(tls_session, packet_ptr_ptr, wait_option); + /* Continue processing while we are receiving post-handshake messages. */ + while (status == NX_SECURE_TLS_POST_HANDSHAKE_RECEIVED) + { + status = _nx_secure_tls_session_receive_records(tls_session, packet_ptr_ptr, wait_option); + } } } diff --git a/nx_secure/src/nx_secure_tls_session_receive_records.c b/nx_secure/src/nx_secure_tls_session_receive_records.c index 86d49951..9379d2f3 100644 --- a/nx_secure/src/nx_secure_tls_session_receive_records.c +++ b/nx_secure/src/nx_secure_tls_session_receive_records.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_receive_records PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -58,7 +58,7 @@ /* _nx_secure_tls_process_record Process TLS record data */ /* _nx_secure_tls_send_alert Send TLS alert */ /* _nx_secure_tls_send_record Send the TLS record */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* nx_tcp_socket_receive Receive TCP data */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ @@ -74,6 +74,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* supported chained packet, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_session_receive_records(NX_SECURE_TLS_SESSION *tls_session, @@ -84,12 +87,13 @@ NX_PACKET *packet_ptr; NX_TCP_SOCKET *tcp_socket; ULONG bytes_processed = 0; ULONG packet_fragment_length; -NX_PACKET *tmp_ptr; NX_PACKET *send_packet = NX_NULL; UINT error_number; UINT alert_number; UINT alert_level; NX_PACKET *current_packet; +NX_PACKET *previous_packet; +UCHAR handshake_finished = NX_FALSE; /* Get the protection. */ tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER); @@ -145,73 +149,51 @@ NX_PACKET *current_packet; if (status == NX_SUCCESS || status == NX_SECURE_TLS_POST_HANDSHAKE_RECEIVED) { - /* Remove processed packets. */ - tls_session -> nx_secure_record_queue_length -= bytes_processed; - tmp_ptr = tls_session -> nx_secure_record_queue_header; - while (tmp_ptr) + /* Remove processed packets. Data in released packet will be cleared by nx_secure_tls_packet_release. */ + tls_session -> nx_secure_record_queue_header -> nx_packet_length -= bytes_processed; + current_packet = tls_session -> nx_secure_record_queue_header; + previous_packet = NX_NULL; + while (current_packet) { - if (bytes_processed >= tmp_ptr -> nx_packet_length) - { + packet_fragment_length = (ULONG)(current_packet -> nx_packet_append_ptr) - (ULONG)(current_packet -> nx_packet_prepend_ptr); - /* Remove entire packet. */ - bytes_processed -= tmp_ptr -> nx_packet_length; - tls_session -> nx_secure_record_queue_header = tmp_ptr -> nx_packet_queue_next; -#ifdef NX_SECURE_KEY_CLEAR - /* Clear all data in chained packet. */ - current_packet = tmp_ptr; - while (current_packet) - { - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - (ULONG)current_packet -> nx_packet_append_ptr - - (ULONG)current_packet -> nx_packet_prepend_ptr); - current_packet = current_packet -> nx_packet_next; - } -#endif /* NX_SECURE_KEY_CLEAR */ - nx_packet_release(tmp_ptr); - tmp_ptr = tls_session -> nx_secure_record_queue_header; + /* Determine if all data in the current fragment have been processed. */ + if (packet_fragment_length <= bytes_processed) + { + bytes_processed -= packet_fragment_length; } else { - - /* Only partial data been processed. */ - current_packet = tmp_ptr; - while (current_packet) - { - packet_fragment_length = (ULONG)(current_packet -> nx_packet_append_ptr) - (ULONG)(current_packet -> nx_packet_prepend_ptr); - - /* Determine if all data in the current fragment have been processed. */ - if (packet_fragment_length < bytes_processed) - { -#ifdef NX_SECURE_KEY_CLEAR - /* Remove all data of this fragment. */ - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - packet_fragment_length); -#endif /* NX_SECURE_KEY_CLEAR */ - current_packet -> nx_packet_prepend_ptr = current_packet -> nx_packet_append_ptr; - tmp_ptr -> nx_packet_length -= packet_fragment_length; - bytes_processed -= packet_fragment_length; - } - else - { -#ifdef NX_SECURE_KEY_CLEAR - /* Remove partial data of this fragment. */ - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - bytes_processed); -#endif /* NX_SECURE_KEY_CLEAR */ - current_packet -> nx_packet_prepend_ptr += bytes_processed; - tmp_ptr -> nx_packet_length -= bytes_processed; - bytes_processed = 0; - break; - } - current_packet = current_packet -> nx_packet_next; - } + current_packet -> nx_packet_prepend_ptr += bytes_processed; + bytes_processed = 0; break; } + previous_packet = current_packet; + current_packet = current_packet -> nx_packet_next; } - if (!tmp_ptr) + if (!current_packet) + { + nx_secure_tls_packet_release(tls_session -> nx_secure_record_queue_header); + tls_session -> nx_secure_record_queue_header = NX_NULL; + } + else if (previous_packet) { - tls_session -> nx_secure_record_queue_tail = NX_NULL; + + /* Release trimmed packets. */ + /* Packets from tls_session -> nx_secure_record_queue_header till previous_packet can be trimmed. */ + previous_packet -> nx_packet_next = NX_NULL; + + /* Update the length and last packet of remaining packets. */ + current_packet -> nx_packet_length = tls_session -> nx_secure_record_queue_header -> nx_packet_length; + current_packet -> nx_packet_last = tls_session -> nx_secure_record_queue_header -> nx_packet_last; + + /* Correct the last packet to be trimmed. */ + tls_session -> nx_secure_record_queue_header -> nx_packet_last = previous_packet; + nx_secure_tls_packet_release(tls_session -> nx_secure_record_queue_header); + + /* Update the remaining packets. */ + tls_session -> nx_secure_record_queue_header = current_packet; } if (bytes_processed) @@ -223,16 +205,35 @@ NX_PACKET *current_packet; return(NX_SECURE_TLS_INVALID_PACKET); } - if (tls_session -> nx_secure_record_decrypted_packet == NX_NULL) +#ifndef NX_SECURE_TLS_CLIENT_DISABLED + if ((tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_CLIENT) && + (tls_session -> nx_secure_tls_client_state == NX_SECURE_TLS_CLIENT_STATE_HANDSHAKE_FINISHED)) { - /* Release the protection. */ - tx_mutex_put(&_nx_secure_tls_protection); + handshake_finished = NX_TRUE; + } +#endif /* NX_SECURE_TLS_CLIENT_DISABLED */ - return(NX_SECURE_TLS_INVALID_PACKET); +#ifndef NX_SECURE_TLS_SERVER_DISABLED + if ((tls_session -> nx_secure_tls_socket_type == NX_SECURE_TLS_SESSION_TYPE_SERVER) && + (tls_session -> nx_secure_tls_server_state == NX_SECURE_TLS_SERVER_STATE_HANDSHAKE_FINISHED)) + { + handshake_finished = NX_TRUE; } +#endif /* NX_SECURE_TLS_CLIENT_DISABLED */ - *packet_ptr_ptr = tls_session -> nx_secure_record_decrypted_packet; - tls_session -> nx_secure_record_decrypted_packet = NX_NULL; + if (handshake_finished) + { + if (tls_session -> nx_secure_record_decrypted_packet == NX_NULL) + { + /* Release the protection. */ + tx_mutex_put(&_nx_secure_tls_protection); + + return(NX_SECURE_TLS_INVALID_PACKET); + } + + *packet_ptr_ptr = tls_session -> nx_secure_record_decrypted_packet; + tls_session -> nx_secure_record_decrypted_packet = NX_NULL; + } } else { @@ -275,7 +276,7 @@ NX_PACKET *current_packet; /* If we didn't send the alert successfully, we need to release the packet. */ if (status != NX_SUCCESS) { - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); } } diff --git a/nx_secure/src/nx_secure_tls_session_renegotiate.c b/nx_secure/src/nx_secure_tls_session_renegotiate.c index f5defe83..a0697aa5 100644 --- a/nx_secure/src/nx_secure_tls_session_renegotiate.c +++ b/nx_secure/src/nx_secure_tls_session_renegotiate.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_renegotiate PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -70,7 +70,7 @@ /* _nx_secure_tls_send_hellorequest Send HelloRequest */ /* _nx_secure_tls_session_receive_records */ /* Receive TLS records */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -83,25 +83,25 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* supported chained packet, */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION UINT _nx_secure_tls_session_renegotiate(NX_SECURE_TLS_SESSION *tls_session, UINT wait_option) { UINT status = NX_NOT_SUCCESSFUL; NX_PACKET *incoming_packet; NX_PACKET *send_packet; -#ifdef NX_SECURE_KEY_CLEAR -NX_PACKET *current_packet; -#endif /* NX_SECURE_KEY_CLEAR */ /* Get the protection. */ tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER); /* Reset the record queue. */ tls_session -> nx_secure_record_queue_header = NX_NULL; - tls_session -> nx_secure_record_queue_tail = NX_NULL; tls_session -> nx_secure_record_decrypted_packet = NX_NULL; - tls_session -> nx_secure_record_queue_length = 0; /* If the session isn't active, trying to renegotiate is an error! */ if (tls_session -> nx_secure_tls_remote_session_active != NX_TRUE || tls_session -> nx_secure_tls_local_session_active != NX_TRUE) @@ -111,6 +111,14 @@ NX_PACKET *current_packet; return(NX_SECURE_TLS_RENEGOTIATION_SESSION_INACTIVE); } +#if (NX_SECURE_TLS_TLS_1_3_ENABLED) + if (tls_session -> nx_secure_tls_1_3) + { + + return(NX_SECURE_TLS_NO_RENEGOTIATION_ERROR); + } +#endif + /* Make sure the remote host supports renegotiation. */ if(!tls_session -> nx_secure_tls_secure_renegotiation) { @@ -165,7 +173,7 @@ NX_PACKET *current_packet; /* Release the protection. */ tx_mutex_put(&_nx_secure_tls_protection); - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); return(status); } @@ -176,6 +184,7 @@ NX_PACKET *current_packet; /* Release the protection. */ tx_mutex_put(&_nx_secure_tls_protection); + /* Before handshake finished, incoming packet will not be set. */ status = _nx_secure_tls_session_receive_records(tls_session, &incoming_packet, wait_option); /* Get the protection. */ @@ -186,21 +195,6 @@ NX_PACKET *current_packet; { break; } - -#ifdef NX_SECURE_KEY_CLEAR - /* Clear all data in chained packet. */ - current_packet = incoming_packet; - while (current_packet) - { - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - (ULONG)current_packet -> nx_packet_append_ptr - - (ULONG)current_packet -> nx_packet_prepend_ptr); - current_packet = current_packet -> nx_packet_next; - } -#endif /* NX_SECURE_KEY_CLEAR */ - - /* On any error, the handshake has failed so break out of our processing loop and return. */ - nx_packet_release(incoming_packet); } } #endif @@ -238,7 +232,7 @@ NX_PACKET *current_packet; /* Release the protection. */ tx_mutex_put(&_nx_secure_tls_protection); - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); return(status); } @@ -251,6 +245,7 @@ NX_PACKET *current_packet; /* Release the protection. */ tx_mutex_put(&_nx_secure_tls_protection); + /* Before handshake finished, incoming packet will not be set. */ status = _nx_secure_tls_session_receive_records(tls_session, &incoming_packet, wait_option); /* Get the protection. */ @@ -261,21 +256,6 @@ NX_PACKET *current_packet; { break; } - -#ifdef NX_SECURE_KEY_CLEAR - /* Clear all data in chained packet. */ - current_packet = incoming_packet; - while (current_packet) - { - NX_SECURE_MEMSET(current_packet -> nx_packet_prepend_ptr, 0, - (ULONG)current_packet -> nx_packet_append_ptr - - (ULONG)current_packet -> nx_packet_prepend_ptr); - current_packet = current_packet -> nx_packet_next; - } -#endif /* NX_SECURE_KEY_CLEAR */ - - /* On any error, the handshake has failed so break out of our processing loop and return. */ - nx_packet_release(incoming_packet); } } #endif @@ -285,4 +265,4 @@ NX_PACKET *current_packet; return(status); } - +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ diff --git a/nx_secure/src/nx_secure_tls_session_renegotiate_callback_set.c b/nx_secure/src/nx_secure_tls_session_renegotiate_callback_set.c index 1b26e6d1..a7baf884 100644 --- a/nx_secure/src/nx_secure_tls_session_renegotiate_callback_set.c +++ b/nx_secure/src/nx_secure_tls_session_renegotiate_callback_set.c @@ -30,7 +30,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_renegotiate_callback_set PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -68,8 +68,12 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION UINT _nx_secure_tls_session_renegotiate_callback_set(NX_SECURE_TLS_SESSION *tls_session, ULONG (*func_ptr)(struct NX_SECURE_TLS_SESSION_STRUCT *session)) { @@ -78,4 +82,4 @@ UINT _nx_secure_tls_session_renegotiate_callback_set(NX_SECURE_TLS_SESSION *tls_ return(NX_SUCCESS); } - +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ diff --git a/nx_secure/src/nx_secure_tls_session_reset.c b/nx_secure/src/nx_secure_tls_session_reset.c index ea498f9c..0efe833c 100644 --- a/nx_secure/src/nx_secure_tls_session_reset.c +++ b/nx_secure/src/nx_secure_tls_session_reset.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_reset PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -68,6 +68,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_session_reset(NX_SECURE_TLS_SESSION *session_ptr) @@ -147,15 +150,16 @@ UINT temp_status; session_ptr -> nx_secure_tls_credentials.nx_secure_tls_active_certificate = NX_NULL; -#ifdef NX_SECURE_TLS_ENABLE_SECURE_RENEGOTIATION +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION session_ptr -> nx_secure_tls_secure_renegotiation = NX_FALSE; NX_SECURE_MEMSET(session_ptr -> nx_secure_tls_remote_verify_data, 0, NX_SECURE_TLS_FINISHED_HASH_SIZE); NX_SECURE_MEMSET(session_ptr -> nx_secure_tls_local_verify_data, 0, NX_SECURE_TLS_FINISHED_HASH_SIZE); -#endif /* Flag to indicate when a session renegotiation is taking place. */ session_ptr -> nx_secure_tls_renegotiation_handshake = NX_FALSE; + session_ptr -> nx_secure_tls_secure_renegotiation_verified = NX_FALSE; +#endif /* Flag to indicate when credentials have been received from the remote host. */ session_ptr -> nx_secure_tls_received_remote_credentials = NX_FALSE; diff --git a/nx_secure/src/nx_secure_tls_session_start.c b/nx_secure/src/nx_secure_tls_session_start.c index cb3a173b..7c46d423 100644 --- a/nx_secure/src/nx_secure_tls_session_start.c +++ b/nx_secure/src/nx_secure_tls_session_start.c @@ -29,7 +29,7 @@ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_session_start PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -61,7 +61,7 @@ /* _nx_secure_tls_handshake_process Process TLS handshake */ /* _nx_secure_tls_send_clienthello Send ClientHello */ /* _nx_secure_tls_send_handshake_record Send TLS handshake record */ -/* nx_packet_release Release packet */ +/* nx_secure_tls_packet_release Release packet */ /* tx_mutex_get Get protection mutex */ /* tx_mutex_put Put protection mutex */ /* */ @@ -74,6 +74,9 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* supported chained packet, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_session_start(NX_SECURE_TLS_SESSION *tls_session, NX_TCP_SOCKET *tcp_socket, @@ -96,9 +99,7 @@ NX_PACKET *send_packet; /* Reset the record queue. */ tls_session -> nx_secure_record_queue_header = NX_NULL; - tls_session -> nx_secure_record_queue_tail = NX_NULL; tls_session -> nx_secure_record_decrypted_packet = NX_NULL; - tls_session -> nx_secure_record_queue_length = 0; /* Make sure we are starting with a fresh session. */ tls_session -> nx_secure_tls_local_session_active = 0; @@ -170,7 +171,7 @@ NX_PACKET *send_packet; /* Release the protection. */ tx_mutex_put(&_nx_secure_tls_protection); - nx_packet_release(send_packet); + nx_secure_tls_packet_release(send_packet); return(status); } } diff --git a/nx_secure/src/nx_secure_tls_verify_mac.c b/nx_secure/src/nx_secure_tls_verify_mac.c index a5e25f68..8e4e0f35 100644 --- a/nx_secure/src/nx_secure_tls_verify_mac.c +++ b/nx_secure/src/nx_secure_tls_verify_mac.c @@ -25,13 +25,14 @@ #include "nx_secure_tls.h" static UCHAR _generated_hash[NX_SECURE_TLS_MAX_HASH_SIZE]; +static UCHAR _received_hash[NX_SECURE_TLS_MAX_HASH_SIZE]; /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_secure_tls_verify_mac PORTABLE C */ -/* 6.0.1 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -49,7 +50,8 @@ static UCHAR _generated_hash[NX_SECURE_TLS_MAX_HASH_SIZE]; /* tls_session TLS control block */ /* header_data TLS record header data */ /* header_length Length of header data */ -/* data TLS record payload data */ +/* packet_ptr TLS record packet */ +/* offset Offset to TLS record in packet*/ /* length Length of payload data */ /* */ /* OUTPUT */ @@ -72,18 +74,21 @@ static UCHAR _generated_hash[NX_SECURE_TLS_MAX_HASH_SIZE]; /* 06-30-2020 Timothy Stapko Modified comment(s), fixed */ /* AES-CBC padding oracle, */ /* resulting in version 6.0.1 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* supported chained packet, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ UINT _nx_secure_tls_verify_mac(NX_SECURE_TLS_SESSION *tls_session, UCHAR *header_data, - USHORT header_length, UCHAR *data, UINT *length) + USHORT header_length, NX_PACKET *packet_ptr, ULONG offset, UINT *length) { -UCHAR *mac_secret; -USHORT hash_size; -INT compare_result; -USHORT data_length; -UCHAR *received_hash; -UINT hash_length; -UCHAR header[6]; +UCHAR *mac_secret; +USHORT hash_size; +INT compare_result; +USHORT data_length; +UINT hash_length; +UCHAR header[6]; +ULONG bytes_copied; if (tls_session -> nx_secure_tls_session_ciphersuite == NX_NULL) { @@ -151,7 +156,7 @@ UCHAR header[6]; /* Generate the hash on the plaintext data. */ _nx_secure_tls_hash_record(tls_session, tls_session -> nx_secure_tls_remote_sequence_number, header, header_length, - data, (USHORT)(data_length), _generated_hash, &hash_length, mac_secret); + packet_ptr, offset, data_length, _generated_hash, &hash_length, mac_secret); /* Increment the sequence number. */ if ((tls_session -> nx_secure_tls_remote_sequence_number[0] + 1) == 0) @@ -161,9 +166,24 @@ UCHAR header[6]; } tls_session -> nx_secure_tls_remote_sequence_number[0]++; + if (hash_size == 0) + { + + /* For ciphersuite without explict hash, just return success. */ + return(NX_SECURE_TLS_SUCCESS); + } + /* Now, compare the hash we generated to the one we received. */ - received_hash = &data[data_length]; - compare_result = NX_SECURE_MEMCMP(received_hash, _generated_hash, hash_size); + if (nx_packet_data_extract_offset(packet_ptr, + offset + data_length, + _received_hash, hash_size, &bytes_copied) || + (bytes_copied != hash_size)) + { + + /* The record data was smaller than the selected hash... Error. */ + return(NX_SECURE_TLS_PADDING_CHECK_FAILED); + } + compare_result = NX_SECURE_MEMCMP(_received_hash, _generated_hash, hash_size); #ifdef NX_SECURE_KEY_CLEAR NX_SECURE_MEMSET(_generated_hash, 0, sizeof(_generated_hash)); diff --git a/nx_secure/src/nxe_secure_tls_session_renegotiate.c b/nx_secure/src/nxe_secure_tls_session_renegotiate.c index 0c943126..06daf941 100644 --- a/nx_secure/src/nxe_secure_tls_session_renegotiate.c +++ b/nx_secure/src/nxe_secure_tls_session_renegotiate.c @@ -33,7 +33,7 @@ NX_SECURE_CALLER_CHECKING_EXTERNS /* FUNCTION RELEASE */ /* */ /* _nxe_secure_tls_session_renegotiate PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -65,8 +65,12 @@ NX_SECURE_CALLER_CHECKING_EXTERNS /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION UINT _nxe_secure_tls_session_renegotiate(NX_SECURE_TLS_SESSION *tls_session, UINT wait_option) { UINT status = NX_SUCCESS; @@ -89,4 +93,5 @@ UINT status = NX_SUCCESS; return(status); } +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ diff --git a/nx_secure/src/nxe_secure_tls_session_renegotiate_callback_set.c b/nx_secure/src/nxe_secure_tls_session_renegotiate_callback_set.c index a916999e..66122cda 100644 --- a/nx_secure/src/nxe_secure_tls_session_renegotiate_callback_set.c +++ b/nx_secure/src/nxe_secure_tls_session_renegotiate_callback_set.c @@ -34,7 +34,7 @@ NX_SECURE_CALLER_CHECKING_EXTERNS /* FUNCTION RELEASE */ /* */ /* _nxe_secure_tls_session_renegotiate_callback_set PORTABLE C */ -/* 6.0 */ +/* 6.0.2 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ @@ -67,8 +67,12 @@ NX_SECURE_CALLER_CHECKING_EXTERNS /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Timothy Stapko Initial Version 6.0 */ +/* 08-14-2020 Timothy Stapko Modified comment(s), */ +/* fixed renegotiation bug, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ +#ifndef NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION UINT _nxe_secure_tls_session_renegotiate_callback_set(NX_SECURE_TLS_SESSION *tls_session, ULONG (*func_ptr)(NX_SECURE_TLS_SESSION *session)) { @@ -94,4 +98,5 @@ UINT status; return(status); } +#endif /* NX_SECURE_TLS_DISABLE_SECURE_RENEGOTIATION */ diff --git a/ports/arc_em/metaware/inc/nx_port.h b/ports/arc_em/metaware/inc/nx_port.h new file mode 100644 index 00000000..9f09190b --- /dev/null +++ b/ports/arc_em/metaware/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h ARCv2_EM/MetaWare */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo ARCv2_EM/MetaWare Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/arc_hs/metaware/inc/nx_port.h b/ports/arc_hs/metaware/inc/nx_port.h new file mode 100644 index 00000000..48aadaa4 --- /dev/null +++ b/ports/arc_hs/metaware/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h ARC_HS/MetaWare */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo ARC_HS/MetaWare Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a15/gnu/inc/nx_port.h b/ports/cortex_a15/gnu/inc/nx_port.h new file mode 100644 index 00000000..786e02e8 --- /dev/null +++ b/ports/cortex_a15/gnu/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A15/GNU */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A15/GNU Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a5/ac5/inc/nx_port.h b/ports/cortex_a5/ac5/inc/nx_port.h new file mode 100644 index 00000000..a65ff938 --- /dev/null +++ b/ports/cortex_a5/ac5/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A5/AC5 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A5/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a5/gnu/inc/nx_port.h b/ports/cortex_a5/gnu/inc/nx_port.h new file mode 100644 index 00000000..e2b6679f --- /dev/null +++ b/ports/cortex_a5/gnu/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A5/GNU */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A7/GNU Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a5/iar/inc/nx_port.h b/ports/cortex_a5/iar/inc/nx_port.h new file mode 100644 index 00000000..cd219ad1 --- /dev/null +++ b/ports/cortex_a5/iar/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A5/IAR */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A5/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a5x/ac6/inc/nx_port.h b/ports/cortex_a5x/ac6/inc/nx_port.h new file mode 100644 index 00000000..bed08888 --- /dev/null +++ b/ports/cortex_a5x/ac6/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A5x/AC6 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A5x/AC6 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a7/ac5/inc/nx_port.h b/ports/cortex_a7/ac5/inc/nx_port.h new file mode 100644 index 00000000..3ce62afc --- /dev/null +++ b/ports/cortex_a7/ac5/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A7/AC5 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A7/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a7/gnu/inc/nx_port.h b/ports/cortex_a7/gnu/inc/nx_port.h new file mode 100644 index 00000000..ce12970f --- /dev/null +++ b/ports/cortex_a7/gnu/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A7/GNU */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A7/GNU Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a7/iar/inc/nx_port.h b/ports/cortex_a7/iar/inc/nx_port.h new file mode 100644 index 00000000..e7d8333a --- /dev/null +++ b/ports/cortex_a7/iar/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A7/IAR */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A7/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a8/ac5/inc/nx_port.h b/ports/cortex_a8/ac5/inc/nx_port.h new file mode 100644 index 00000000..bf16248b --- /dev/null +++ b/ports/cortex_a8/ac5/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A8/AC5 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A8/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a8/gnu/inc/nx_port.h b/ports/cortex_a8/gnu/inc/nx_port.h new file mode 100644 index 00000000..7c024932 --- /dev/null +++ b/ports/cortex_a8/gnu/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A8/GNU */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A8/GNU Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a8/iar/inc/nx_port.h b/ports/cortex_a8/iar/inc/nx_port.h new file mode 100644 index 00000000..f7a42c1f --- /dev/null +++ b/ports/cortex_a8/iar/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A8/IAR */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A8/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a9/ac5/inc/nx_port.h b/ports/cortex_a9/ac5/inc/nx_port.h new file mode 100644 index 00000000..c15103bc --- /dev/null +++ b/ports/cortex_a9/ac5/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A9/AC5 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A9/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a9/gnu/inc/nx_port.h b/ports/cortex_a9/gnu/inc/nx_port.h new file mode 100644 index 00000000..6f3ed0ef --- /dev/null +++ b/ports/cortex_a9/gnu/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A9/GNU */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A9/GNU Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a9/iar/inc/nx_port.h b/ports/cortex_a9/iar/inc/nx_port.h new file mode 100644 index 00000000..cb16e5e8 --- /dev/null +++ b/ports/cortex_a9/iar/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A9/IAR */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A9/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_a9/rvds/inc/nx_port.h b/ports/cortex_a9/rvds/inc/nx_port.h new file mode 100644 index 00000000..c15103bc --- /dev/null +++ b/ports/cortex_a9/rvds/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-A9/AC5 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-A9/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m0/ac5/inc/nx_port.h b/ports/cortex_m0/ac5/inc/nx_port.h new file mode 100644 index 00000000..d4c48084 --- /dev/null +++ b/ports/cortex_m0/ac5/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M0/AC5 */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M0/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m0/gnu/inc/nx_port.h b/ports/cortex_m0/gnu/inc/nx_port.h index 121eca13..4427706f 100644 --- a/ports/cortex_m0/gnu/inc/nx_port.h +++ b/ports/cortex_m0/gnu/inc/nx_port.h @@ -26,7 +26,7 @@ /* PORT SPECIFIC C INFORMATION RELEASE */ /* */ /* nx_port.h Cortex-M0/GNU */ -/* 6.0 */ +/* 6.0.2 */ /* */ /* AUTHOR */ /* */ @@ -43,6 +43,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -144,21 +148,21 @@ extern TX_THREAD _tx_timer_thread; \ extern volatile ULONG _tx_thread_system_state; -#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ (_tx_thread_current_ptr == TX_NULL) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return(NX_CALLER_ERROR); -#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return(NX_CALLER_ERROR); -#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ return(NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ - ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ return(NX_CALLER_ERROR); @@ -169,18 +173,18 @@ #define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ extern volatile ULONG _tx_thread_system_state; -#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ (_tx_thread_current_ptr == TX_NULL)) \ return(NX_CALLER_ERROR); -#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ return(NX_CALLER_ERROR); -#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ return(NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ - ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ return(NX_CALLER_ERROR); #endif diff --git a/ports/cortex_m0/iar/inc/nx_port.h b/ports/cortex_m0/iar/inc/nx_port.h new file mode 100644 index 00000000..4de05c6c --- /dev/null +++ b/ports/cortex_m0/iar/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M0/IAR */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M0/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m3/ac5/inc/nx_port.h b/ports/cortex_m3/ac5/inc/nx_port.h new file mode 100644 index 00000000..c700d23e --- /dev/null +++ b/ports/cortex_m3/ac5/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M3/AC5 */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M3/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m3/gnu/inc/nx_port.h b/ports/cortex_m3/gnu/inc/nx_port.h index 7bd46c7d..36f67ca8 100644 --- a/ports/cortex_m3/gnu/inc/nx_port.h +++ b/ports/cortex_m3/gnu/inc/nx_port.h @@ -26,7 +26,7 @@ /* PORT SPECIFIC C INFORMATION RELEASE */ /* */ /* nx_port.h Cortex-M3/GNU */ -/* 6.0 */ +/* 6.0.2 */ /* */ /* AUTHOR */ /* */ @@ -43,6 +43,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -144,21 +148,21 @@ extern TX_THREAD _tx_timer_thread; \ extern volatile ULONG _tx_thread_system_state; -#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ (_tx_thread_current_ptr == TX_NULL) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return(NX_CALLER_ERROR); -#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return(NX_CALLER_ERROR); -#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ return(NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ - ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ return(NX_CALLER_ERROR); @@ -169,18 +173,18 @@ #define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ extern volatile ULONG _tx_thread_system_state; -#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ (_tx_thread_current_ptr == TX_NULL)) \ return(NX_CALLER_ERROR); -#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ return(NX_CALLER_ERROR); -#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ return(NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ - ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ return(NX_CALLER_ERROR); #endif diff --git a/ports/cortex_m3/iar/inc/nx_port.h b/ports/cortex_m3/iar/inc/nx_port.h new file mode 100644 index 00000000..32f30ee8 --- /dev/null +++ b/ports/cortex_m3/iar/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M3/IAR */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M3/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m3/keil/inc/nx_port.h b/ports/cortex_m3/keil/inc/nx_port.h new file mode 100644 index 00000000..3e00e91d --- /dev/null +++ b/ports/cortex_m3/keil/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M3/Keil */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M3/Keil Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m4/ac5/inc/nx_port.h b/ports/cortex_m4/ac5/inc/nx_port.h new file mode 100644 index 00000000..1b5d0c4f --- /dev/null +++ b/ports/cortex_m4/ac5/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M4/AC5 */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M4/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m4/gnu/inc/nx_port.h b/ports/cortex_m4/gnu/inc/nx_port.h index e85b2e39..076f4265 100644 --- a/ports/cortex_m4/gnu/inc/nx_port.h +++ b/ports/cortex_m4/gnu/inc/nx_port.h @@ -26,7 +26,7 @@ /* PORT SPECIFIC C INFORMATION RELEASE */ /* */ /* nx_port.h Cortex-M4/GNU */ -/* 6.0 */ +/* 6.0.2 */ /* */ /* AUTHOR */ /* */ @@ -43,6 +43,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -144,21 +148,21 @@ extern TX_THREAD _tx_timer_thread; \ extern volatile ULONG _tx_thread_system_state; -#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ (_tx_thread_current_ptr == TX_NULL) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return(NX_CALLER_ERROR); -#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return(NX_CALLER_ERROR); -#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ return(NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ - ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ return(NX_CALLER_ERROR); @@ -169,18 +173,18 @@ #define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ extern volatile ULONG _tx_thread_system_state; -#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ (_tx_thread_current_ptr == TX_NULL)) \ return(NX_CALLER_ERROR); -#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ return(NX_CALLER_ERROR); -#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ return(NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ - ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ return(NX_CALLER_ERROR); #endif diff --git a/ports/cortex_m4/iar/inc/nx_port.h b/ports/cortex_m4/iar/inc/nx_port.h new file mode 100644 index 00000000..35d7ea85 --- /dev/null +++ b/ports/cortex_m4/iar/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M4/IAR */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M4/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m4/keil/inc/nx_port.h b/ports/cortex_m4/keil/inc/nx_port.h new file mode 100644 index 00000000..2d01e59b --- /dev/null +++ b/ports/cortex_m4/keil/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M4/Keil */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M4/Keil Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m7/ac5/inc/nx_port.h b/ports/cortex_m7/ac5/inc/nx_port.h new file mode 100644 index 00000000..71df7720 --- /dev/null +++ b/ports/cortex_m7/ac5/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M7/AC5 */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M7/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_m7/gnu/inc/nx_port.h b/ports/cortex_m7/gnu/inc/nx_port.h index 10c7fab5..278f49d2 100644 --- a/ports/cortex_m7/gnu/inc/nx_port.h +++ b/ports/cortex_m7/gnu/inc/nx_port.h @@ -26,7 +26,7 @@ /* PORT SPECIFIC C INFORMATION RELEASE */ /* */ /* nx_port.h Cortex-M7/GNU */ -/* 6.0 */ +/* 6.0.2 */ /* */ /* AUTHOR */ /* */ @@ -43,6 +43,10 @@ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ /* */ /**************************************************************************/ @@ -144,21 +148,21 @@ extern TX_THREAD _tx_timer_thread; \ extern volatile ULONG _tx_thread_system_state; -#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ (_tx_thread_current_ptr == TX_NULL) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return(NX_CALLER_ERROR); -#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ (_tx_thread_current_ptr == &_tx_timer_thread)) \ return(NX_CALLER_ERROR); -#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ return(NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ - ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ return(NX_CALLER_ERROR); @@ -169,18 +173,18 @@ #define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ extern volatile ULONG _tx_thread_system_state; -#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ (_tx_thread_current_ptr == TX_NULL)) \ return(NX_CALLER_ERROR); -#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ return(NX_CALLER_ERROR); -#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ return(NX_CALLER_ERROR); #define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ - ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ return(NX_CALLER_ERROR); #endif diff --git a/ports/cortex_m7/iar/inc/nx_port.h b/ports/cortex_m7/iar/inc/nx_port.h new file mode 100644 index 00000000..fd220c7f --- /dev/null +++ b/ports/cortex_m7/iar/inc/nx_port.h @@ -0,0 +1,214 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-M7/IAR */ +/* 6.0.2 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* 08-14-2020 Yuxin Zhou Modified comment(s), and */ +/* corrected the code of */ +/* getting system state, */ +/* resulting in version 6.0.2 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((TX_THREAD_GET_SYSTEM_STATE()) && (TX_THREAD_GET_SYSTEM_STATE() < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (TX_THREAD_GET_SYSTEM_STATE()))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-M7/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_r4/ac5/inc/nx_port.h b/ports/cortex_r4/ac5/inc/nx_port.h new file mode 100644 index 00000000..69951d3c --- /dev/null +++ b/ports/cortex_r4/ac5/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-R4/AC5 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-R4/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_r4/ac6/inc/nx_port.h b/ports/cortex_r4/ac6/inc/nx_port.h new file mode 100644 index 00000000..dec646f2 --- /dev/null +++ b/ports/cortex_r4/ac6/inc/nx_port.h @@ -0,0 +1,199 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-R4/AC6 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +/* By default IPv6 is enabled. */ + +#ifndef FEATURE_NX_IPV6 +#define FEATURE_NX_IPV6 +#endif /* FEATURE_NX_IPV6 */ + +#ifdef NX_DISABLE_IPV6 +#undef FEATURE_NX_IPV6 +#endif /* !NX_DISABLE_IPV6 */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) (arg) = __builtin_bswap32(arg) +#define NX_CHANGE_USHORT_ENDIAN(arg) (arg) = __builtin_bswap16(arg) + + +#ifndef htonl +#define htonl(val) __builtin_bswap32(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __builtin_bswap32(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __builtin_bswap16(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __builtin_bswap16(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-R4/AC6 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_r4/gnu/inc/nx_port.h b/ports/cortex_r4/gnu/inc/nx_port.h new file mode 100644 index 00000000..e0e48c9a --- /dev/null +++ b/ports/cortex_r4/gnu/inc/nx_port.h @@ -0,0 +1,199 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-R4/GNU */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +/* By default IPv6 is enabled. */ + +#ifndef FEATURE_NX_IPV6 +#define FEATURE_NX_IPV6 +#endif /* FEATURE_NX_IPV6 */ + +#ifdef NX_DISABLE_IPV6 +#undef FEATURE_NX_IPV6 +#endif /* !NX_DISABLE_IPV6 */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) (arg) = __builtin_bswap32(arg) +#define NX_CHANGE_USHORT_ENDIAN(arg) (arg) = __builtin_bswap16(arg) + + +#ifndef htonl +#define htonl(val) __builtin_bswap32(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __builtin_bswap32(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __builtin_bswap16(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __builtin_bswap16(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-R4/GNU Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_r4/iar/inc/nx_port.h b/ports/cortex_r4/iar/inc/nx_port.h new file mode 100644 index 00000000..fb10a975 --- /dev/null +++ b/ports/cortex_r4/iar/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-R4/IAR */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-R4/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_r5/ac5/inc/nx_port.h b/ports/cortex_r5/ac5/inc/nx_port.h new file mode 100644 index 00000000..2bd52791 --- /dev/null +++ b/ports/cortex_r5/ac5/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-R5/AC5 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-R5/AC5 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_r5/gnu/inc/nx_port.h b/ports/cortex_r5/gnu/inc/nx_port.h new file mode 100644 index 00000000..7d25a334 --- /dev/null +++ b/ports/cortex_r5/gnu/inc/nx_port.h @@ -0,0 +1,199 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-R5/GNU */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +/* By default IPv6 is enabled. */ + +#ifndef FEATURE_NX_IPV6 +#define FEATURE_NX_IPV6 +#endif /* FEATURE_NX_IPV6 */ + +#ifdef NX_DISABLE_IPV6 +#undef FEATURE_NX_IPV6 +#endif /* !NX_DISABLE_IPV6 */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) (arg) = __builtin_bswap32(arg) +#define NX_CHANGE_USHORT_ENDIAN(arg) (arg) = __builtin_bswap16(arg) + + +#ifndef htonl +#define htonl(val) __builtin_bswap32(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __builtin_bswap32(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __builtin_bswap16(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __builtin_bswap16(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Cortex-R5/GNU Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/cortex_r5/iar/inc/nx_port.h b/ports/cortex_r5/iar/inc/nx_port.h new file mode 100644 index 00000000..4274690a --- /dev/null +++ b/ports/cortex_r5/iar/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Cortex-R5/IAR */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG i; \ + ULONG tmp; \ + i = (UINT)arg; \ + /* i = A, B, C, D */ \ + tmp = i ^ (((i) >> 16) | (i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + i = ((i) >> 8) | (i<<24); \ + /* i = D, A, B, C */ \ + i = i ^ ((tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Cortex-R5/IAR Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/linux/gnu/CMakeLists.txt b/ports/linux/gnu/CMakeLists.txt new file mode 100644 index 00000000..75c79531 --- /dev/null +++ b/ports/linux/gnu/CMakeLists.txt @@ -0,0 +1,9 @@ +target_sources(${PROJECT_NAME} PRIVATE + # {{BEGIN_TARGET_SOURCES}} + + # {{END_TARGET_SOURCES}} +) + +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/inc +) diff --git a/ports/linux/gnu/inc/nx_port.h b/ports/linux/gnu/inc/nx_port.h new file mode 100644 index 00000000..c3614e1c --- /dev/null +++ b/ports/linux/gnu/inc/nx_port.h @@ -0,0 +1,209 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Linux/GNU */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#ifdef TX_TIMER_TICKS_PER_SECOND +#define NX_IP_PERIODIC_RATE TX_TIMER_TICKS_PER_SECOND +#else +#define NX_IP_PERIODIC_RATE 100 +#endif +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG _i; \ + ULONG _tmp; \ + _i = (UINT)arg; \ + /* i = A, B, C, D */ \ + _tmp = _i ^ (((_i) >> 16) | (_i << 16)); \ + /* tmp = i ^ (i ROR 16) = A^C, B^D, C^A, D^B */ \ + _tmp &= 0xff00ffff; \ + /* tmp = A^C, 0, C^A, D^B */ \ + _i = ((_i) >> 8) | (_i<<24); \ + /* i = D, A, B, C */ \ + _i = _i ^ ((_tmp) >> 8); \ + /* i = D, C, B, A */ \ + arg = _i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = ((USHORT)((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) (USHORT)((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Linux/GNU Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + diff --git a/ports/win32/vs_2019/inc/nx_port.h b/ports/win32/vs_2019/inc/nx_port.h new file mode 100644 index 00000000..59cb221b --- /dev/null +++ b/ports/win32/vs_2019/inc/nx_port.h @@ -0,0 +1,210 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) Microsoft Corporation. All rights reserved. */ +/* */ +/* This software is licensed under the Microsoft Software License */ +/* Terms for Microsoft Azure RTOS. Full text of the license can be */ +/* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ +/* and in the root directory of this software. */ +/* */ +/**************************************************************************/ + + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** NetX Component */ +/** */ +/** Port Specific */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + + +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* nx_port.h Win32/VC2019 */ +/* 6.0.1 */ +/* */ +/* AUTHOR */ +/* */ +/* Yuxin Zhou, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This file contains data type definitions that make the NetX */ +/* real-time TCP/IP function identically on a variety of different */ +/* processor architectures. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* 06-30-2020 Yuxin Zhou Initial Version 6.0.1 */ +/* */ +/**************************************************************************/ + +#ifndef NX_PORT_H +#define NX_PORT_H + +/* Determine if the optional NetX user define file should be used. */ + +#ifdef NX_INCLUDE_USER_DEFINE_FILE + + +/* Yes, include the user defines in nx_user.h. The defines in this file may + alternately be defined on the command line. */ + +#include "nx_user.h" +#endif + + +/* Default to little endian, since this is what most ARM targets are. */ + +#define NX_LITTLE_ENDIAN 1 + + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + + +/* Define various constants for the port. */ + +#ifndef NX_IP_PERIODIC_RATE +#define NX_IP_PERIODIC_RATE 100 /* Default IP periodic rate of 1 second for + ports with 10ms timer interrupts. This + value may be defined instead at the + command line and this value will not be + used. */ +#endif + + +/* Define macros that swap the endian for little endian ports. */ +#ifdef NX_LITTLE_ENDIAN +#define NX_CHANGE_ULONG_ENDIAN(arg) \ + { \ + ULONG _i; \ + ULONG _tmp; \ + _i = (UINT)arg; \ + /* _i = A, B, C, D */ \ + _tmp = _i ^ (((_i) >> 16) | (_i << 16)); \ + /* _tmp = _i ^ (_i ROR 16) = A^C, B^D, C^A, D^B */ \ + _tmp &= 0xff00ffff; \ + /* _tmp = A^C, 0, C^A, D^B */ \ + _i = ((_i) >> 8) | (_i<<24); \ + /* _i = D, A, B, C */ \ + _i = _i ^ ((_tmp) >> 8); \ + /* _i = D, C, B, A */ \ + arg = _i; \ + } +#define NX_CHANGE_USHORT_ENDIAN(a) a = (((a >> 8) | (a << 8)) & 0xFFFF) + + +#define __SWAP32__(val) ((((val) & 0xFF000000) >> 24 ) | (((val) & 0x00FF0000) >> 8) \ + | (((val) & 0x0000FF00) << 8) | (((val) & 0x000000FF) << 24)) + +#define __SWAP16__(val) ((((val) & 0xFF00) >> 8) | (((val) & 0x00FF) << 8)) + + +#ifndef htonl +#define htonl(val) __SWAP32__(val) +#endif /* htonl */ +#ifndef ntohl +#define ntohl(val) __SWAP32__(val) +#endif /* htonl */ + +#ifndef htons +#define htons(val) __SWAP16__(val) +#endif /*htons */ + +#ifndef ntohs +#define ntohs(val) __SWAP16__(val) +#endif /*htons */ + + +#else +#define NX_CHANGE_ULONG_ENDIAN(a) +#define NX_CHANGE_USHORT_ENDIAN(a) + +#ifndef htons +#define htons(val) (val) +#endif /* htons */ + +#ifndef ntohs +#define ntohs(val) (val) +#endif /* ntohs */ + +#ifndef ntohl +#define ntohl(val) (val) +#endif + +#ifndef htonl +#define htonl(val) (val) +#endif /* htonl */ +#endif + + +/* Define several macros for the error checking shell in NetX. */ + +#ifndef TX_TIMER_PROCESS_IN_ISR + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern TX_THREAD _tx_timer_thread; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) || \ + (_tx_thread_current_ptr == &_tx_timer_thread)) \ + return(NX_CALLER_ERROR); + + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state) || (_tx_thread_current_ptr == &_tx_timer_thread))) \ + return(NX_CALLER_ERROR); + + +#else + + + +#define NX_CALLER_CHECKING_EXTERNS extern TX_THREAD *_tx_thread_current_ptr; \ + extern volatile ULONG _tx_thread_system_state; + +#define NX_THREADS_ONLY_CALLER_CHECKING if ((_tx_thread_system_state) || \ + (_tx_thread_current_ptr == TX_NULL)) \ + return(NX_CALLER_ERROR); + +#define NX_INIT_AND_THREADS_CALLER_CHECKING if (((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0)))) \ + return(NX_CALLER_ERROR); + +#define NX_NOT_ISR_CALLER_CHECKING if ((_tx_thread_system_state) && (_tx_thread_system_state < ((ULONG) 0xF0F0F0F0))) \ + return(NX_CALLER_ERROR); + +#define NX_THREAD_WAIT_CALLER_CHECKING if ((wait_option) && \ + ((_tx_thread_current_ptr == NX_NULL) || (_tx_thread_system_state))) \ + return(NX_CALLER_ERROR); + +#endif + + +/* Define the version ID of NetX. This may be utilized by the application. */ + +#ifdef NX_SYSTEM_INIT +CHAR _nx_version_id[] = + "Copyright (c) Microsoft Corporation. All rights reserved. * NetX Duo Win32/VS2019 Version 6.0.1 *"; +#else +extern CHAR _nx_version_id[]; +#endif + +#endif + |
