|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
TLS client over ra8_tls + ra8_net_pal (NetX Duo transport). More...
#include <stdint.h>#include <stdio.h>#include <string.h>#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_cgc.h"#include "ra8_err.h"#include "ra8_isr.h"#include "ra8_rsip.h"#include "ra8_time.h"#include "ra8_tls.h"#include "mbedtls/net_sockets.h"#include "mbedtls/platform.h"#include "mbedtls/ssl.h"#include "nx_api.h"#include "nx_ether_driver_ra8_eth.h"#include "psa/crypto.h"#include "tx_api.h"Go to the source code of this file.
Functions | |
| static void | demo_panic_halt (void) |
| Halt forever in WFI. | |
| static void | demo_setup_or_halt (void) |
| Bring CGC + the J-Link OB VCOM console + on-board Ethernet + RSIP up. | |
| static void | demo_print (const char *s) |
| Write a NUL-terminated string to the console. | |
| static ULONG | demo_pack_ip (const uint8_t *octets) |
| Pack a 4-octet IPv4 array into NetX's host-order ULONG. | |
| static void | demo_pack_mac (ULONG *msw, ULONG *lsw) |
| Pack the local MAC into the msw/lsw fields NetX expects. | |
| psa_status_t | mbedtls_psa_external_get_random (mbedtls_psa_external_random_context_t *context, uint8_t *output, size_t output_size, size_t *output_length) |
| PSA external RNG hook – feeds the RSIP TRNG straight into PSA. | |
| static void * | demo_calloc (size_t n, size_t size) |
| mbedtls_calloc hook backed by the ThreadX byte pool. | |
| static void | demo_free (void *p) |
| mbedtls_free hook backed by the ThreadX byte pool. | |
| static int | tls_bio_send (void *ctx, const uint8_t *buf, size_t len) |
| ra8_tls BIO send callback bound to nx_tcp_socket_send. | |
| static int | tls_bio_recv (void *ctx, uint8_t *buf, size_t len) |
| ra8_tls BIO recv callback bound to nx_tcp_socket_receive. | |
| static UINT | demo_netx_bring_up (void) |
| Bring NetX Duo up: pool, IP, gateway, ARP, TCP, ICMP. | |
| static UINT | demo_tcp_connect (void) |
| Open a NetX TCP socket and connect to the TLS endpoint. | |
| static ra8_err_t | demo_handshake (ra8_tls_session_t session) |
| Drive the ra8_tls handshake to completion (bounded poll loop). | |
| static ra8_err_t | demo_exchange (ra8_tls_session_t session, uint8_t *got, size_t got_cap) |
| Send one record and read one back over the TLS session. | |
| static void | demo_report (ra8_tls_session_t session) |
| Print the negotiated cipher + verification result to the console. | |
| static ra8_err_t | demo_run_tls (void) |
| Run the whole TLS session: open, handshake, exchange, report. | |
| static void | demo_thread_entry (ULONG thread_input) |
| ThreadX worker entry: PSA + NetX up, connect, run the TLS session. | |
| void | tx_application_define (void *first_unused_memory) |
| ThreadX system-define hook: build worker thread + byte pool. | |
| void | main (void) |
| Application entry. | |
Variables | |
| static const uint8_t | k_demo_mac [6] = {0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x03U} |
| Locally-administered unicast MAC for this board. | |
| static const uint8_t | k_demo_ip [4] |
| IPv4 address: 192.168.1.42. | |
| static const uint8_t | k_demo_mask [4] |
| Subnet mask: 255.255.255.0. | |
| static const uint8_t | k_demo_gw [4] |
| Default gateway + TLS endpoint: 192.168.1.1. | |
| static const char | k_demo_server_name [] = "endpoint.test" |
| SNI hostname advertised in the ClientHello. | |
| static const uint8_t | k_demo_record [] = "PING over ra8_tls\n" |
| The one application record this demo sends after the handshake. | |
| static NX_PACKET_POOL | s_packet_pool |
| static NX_IP | s_ip |
| static NX_TCP_SOCKET | s_tls_socket |
| static UCHAR | s_pool_memory [k_demo_pool_bytes] |
| static ULONG | s_ip_stack [k_demo_ip_stack/sizeof(ULONG)] |
| static ULONG | s_arp_cache [k_demo_arp_cache/sizeof(ULONG)] |
| static TX_THREAD | s_demo_thread |
| static UCHAR | s_demo_stack [k_demo_thread_stack] |
| static TX_BYTE_POOL | s_byte_pool |
| static UCHAR | s_byte_pool_memory [k_demo_byte_pool_size] |
| static CHAR | s_packet_pool_name [] = "ra8_eth_pool" |
| Persistent mutable names retained by NetX Duo and ThreadX objects. | |
| static CHAR | s_ip_name [] = "ra8_eth_ip" |
| static CHAR | s_socket_name [] = "tls4433" |
| static CHAR | s_byte_pool_name [] = "mbedtls_pool" |
| static CHAR | s_thread_name [] = "tls_worker" |
TLS client over ra8_tls + ra8_net_pal (NetX Duo transport).
Minimal TLS-client demo for issue #261. It brings the chip up the same way threadx_netx_tcp_echo does (CGC -> SCI console -> RMII pins -> RSIP), hands control to ThreadX, and on a single worker thread:
The TCP MSS is clamped with ra8_tls_mss_clamp so every segment fits inside the #21-pinned 128-byte MTU (128 - 20 IPv4 - 20 TCP == 88).
ra8_emulator runs the real firmware ELF, so a genuine handshake here needs (a) a crypto-complete TLS server on the wire and (b) a working entropy source under emulation. Today ra8_emulator's peer (board_net) is a plaintext TCP stack with no TLS and no RSIP/TRNG model, so it cannot complete an Mbed TLS handshake. Bringing up a board_net TLS-server endpoint (host-side mbedtls + a reverse TCP role + a TRNG model) is the follow-up that promotes this app to hw_validated/hil/; see README.md. Until then the transport + facade glue is proven by the host unit test tests/wireless/src/test_ra8_tls_net.c (which drives the same ra8_tls API over the ra8_net_pal loopback ring), and this app runs against a real openssl s_server on the bench.
Definition in file main.c.
| enum demo_config_t : uint32_t |
Compile-time settings for the TLS-client demo.
Mirrors the threadx_https_client sizing for NetX Duo + Mbed TLS; the ra8_tls session pool + one SSL context fit inside the ThreadX byte pool.
| enum demo_ip_octet_t : uint8_t |
| enum demo_ip_shift_t : uint8_t |
| enum demo_ipv4_t : uint16_t |
| enum demo_mac_idx_t : uint8_t |
| enum demo_mac_word_shift_t : uint8_t |
Shifts that pack the 6-byte MAC into msw/lsw ULONG pairs.
|
static |
mbedtls_calloc hook backed by the ThreadX byte pool.
Computes the requested byte count safely with overflow detection, performs a nonblocking pool allocation, clears the complete span, and returns it to Mbed TLS.
| [in] | n | Element count. |
| [in] | size | Element size in bytes. |
| nullptr | n is zero, size is zero, multiplication overflows, or pool is exhausted. |
| non-null | Pointer to zero-initialized allocated memory. |
Definition at line 385 of file main.c.
References memset(), s_byte_pool, and TX_SUCCESS.
Referenced by tx_application_define().
|
static |
Send one record and read one back over the TLS session.
| [in] | session | Open, handshaken ra8_tls session. |
| [out] | got | Receive buffer for the reply. |
| [in] | got_cap | Capacity of got in bytes. |
Definition at line 626 of file main.c.
References k_demo_io_max, k_demo_record, k_ra8_err_invalid_arg, k_ra8_err_would_block, k_ra8_ok, ra8_tls_recv(), and ra8_tls_send().
Referenced by demo_run_tls().
|
static |
mbedtls_free hook backed by the ThreadX byte pool.
| [in] | p | Pointer previously returned by demo_calloc (NULL OK). |
Definition at line 412 of file main.c.
Referenced by tx_application_define().
|
static |
Drive the ra8_tls handshake to completion (bounded poll loop).
| [in] | session | Open ra8_tls session handle. |
Definition at line 601 of file main.c.
References k_demo_handshake_max, k_ra8_err_timeout, k_ra8_err_would_block, and ra8_tls_handshake().
Referenced by demo_run_tls().
|
static |
Bring NetX Duo up: pool, IP, gateway, ARP, TCP, ICMP.
Definition at line 510 of file main.c.
References demo_pack_ip(), demo_pack_mac(), k_demo_gw, k_demo_ip, k_demo_ip_thread_pri, k_demo_mac, k_demo_mask, k_demo_packet_size, nx_ether_driver_ra8_eth(), nx_ether_driver_ra8_eth_set_mac(), s_arp_cache, s_ip, s_ip_name, s_ip_stack, s_packet_pool, s_packet_pool_name, and s_pool_memory.
Referenced by demo_thread_entry().
|
static |
Pack a 4-octet IPv4 array into NetX's host-order ULONG.
| [in] | octets | IPv4 address (4 bytes). Must not be NULL. |
Definition at line 296 of file main.c.
References k_demo_ip_oct_a, k_demo_ip_oct_b, k_demo_ip_oct_c, k_demo_ip_oct_d, k_demo_ip_shift_a, k_demo_ip_shift_b, k_demo_ip_shift_c, and k_demo_ip_shift_d.
Referenced by demo_netx_bring_up(), demo_netx_create_ip(), and demo_tcp_connect().
Pack the local MAC into the msw/lsw fields NetX expects.
| [out] | msw | Most-significant word (octets 0-1). Must not be NULL. |
| [out] | lsw | Least-significant word (octets 2-5). Must not be NULL. |
Definition at line 315 of file main.c.
References k_demo_mac, k_demo_mac_idx_0, k_demo_mac_idx_1, k_demo_mac_idx_2, k_demo_mac_idx_3, k_demo_mac_idx_4, k_demo_mac_idx_5, k_demo_mac_lsw_shift_b2, k_demo_mac_lsw_shift_b3, k_demo_mac_lsw_shift_b4, k_demo_mac_lsw_shift_b5, k_demo_mac_msw_shift_b0, and k_demo_mac_msw_shift_b1.
Referenced by demo_netx_bring_up(), and demo_netx_create_ip().
|
static |
|
static |
Write a NUL-terminated string to the console.
| [in] | s | NUL-terminated ASCII string. Must not be NULL. |
Definition at line 274 of file main.c.
References ra8_board_uart_console_write(), and strlen().
|
static |
Print the negotiated cipher + verification result to the console.
| [in] | session | Handshaken ra8_tls session. |
Definition at line 657 of file main.c.
References demo_print(), k_demo_verify_unset, k_ra8_tls_cipher_name_cap, ra8_tls_get_cipher_suite(), and ra8_tls_get_verify_result().
Referenced by demo_run_tls(), and main().
|
static |
Run the whole TLS session: open, handshake, exchange, report.
Definition at line 680 of file main.c.
References demo_exchange(), demo_handshake(), demo_print(), demo_report(), k_demo_mtu, k_demo_record_cap, k_demo_server_name, k_ra8_err_invalid_arg, k_ra8_ok, k_ra8_tls_verify_optional, ra8_tls_global_deinit(), ra8_tls_global_init(), ra8_tls_mss_clamp(), ra8_tls_session_close(), ra8_tls_session_open(), s_tls_socket, tls_bio_recv(), and tls_bio_send().
Referenced by demo_thread_entry().
|
static |
Bring CGC + the J-Link OB VCOM console + on-board Ethernet + RSIP up.
Definition at line 239 of file main.c.
References demo_panic_halt(), k_demo_baud, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_ethernet_init(), ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_rsip_init(), and ra8_time_init().
|
static |
Open a NetX TCP socket and connect to the TLS endpoint.
Definition at line 564 of file main.c.
References demo_pack_ip(), k_demo_connect_ticks, k_demo_gw, k_demo_recv_window, k_demo_socket_ttl, k_demo_tls_port, s_ip, s_socket_name, and s_tls_socket.
Referenced by demo_thread_entry().
|
static |
ThreadX worker entry: PSA + NetX up, connect, run the TLS session.
| [in] | thread_input | Unused. |
Definition at line 731 of file main.c.
References demo_netx_bring_up(), demo_print(), demo_run_tls(), demo_tcp_connect(), and k_ra8_ok.
Referenced by tx_application_define().
| void main | ( | void | ) |
Application entry.
The application entry point Reset_Handler hands control to.
Brings up clocks + UART + RMII + RSIP, then ThreadX.
Definition at line 797 of file main.c.
References demo_panic_halt(), demo_print(), demo_setup_or_halt(), and ra8_isr_globals_enable().
| psa_status_t mbedtls_psa_external_get_random | ( | mbedtls_psa_external_random_context_t * | context, |
| uint8_t * | output, | ||
| size_t | output_size, | ||
| size_t * | output_length ) |
PSA external RNG hook – feeds the RSIP TRNG straight into PSA.
With MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG the SSL layer pulls random bytes from this callback (via psa_generate_random) rather than an in-tree DRBG. Bound to ra8_rsip_trng_read.
| [in,out] | context | PSA per-process external RNG context (unused). |
| [out] | output | Output buffer. |
| [in] | output_size | Bytes requested. |
| [out] | output_length | Bytes actually produced. |
| PSA_SUCCESS | on success. |
| PSA_ERROR_INVALID_ARGUMENT | on a NULL output pointer. |
| PSA_ERROR_HARDWARE_FAILURE | if the RSIP TRNG returned an error. |
output holds output_size bytes on success.Definition at line 348 of file main.c.
References k_ra8_ok, and ra8_rsip_trng_read().
|
static |
ra8_tls BIO recv callback bound to nx_tcp_socket_receive.
| [in] | ctx | Opaque context (unused). |
| [out] | buf | Output buffer. |
| [in] | len | Maximum bytes to read. |
buf holds the returned bytes.Definition at line 477 of file main.c.
References k_demo_recv_timeout, and s_tls_socket.
Referenced by demo_run_tls().
|
static |
ra8_tls BIO send callback bound to nx_tcp_socket_send.
| [in] | ctx | Opaque context (unused – the file-scope socket is used). |
| [in] | buf | Ciphertext bytes the TLS layer wants to transmit. |
| [in] | len | Buffer length in bytes. |
Definition at line 434 of file main.c.
References k_demo_recv_timeout, s_packet_pool, and s_tls_socket.
Referenced by demo_run_tls().
| void tx_application_define | ( | void * | first_unused_memory | ) |
ThreadX system-define hook: build worker thread + byte pool.
| [in] | first_unused_memory | Free RAM from the ThreadX port; unused. |
Definition at line 764 of file main.c.
References demo_calloc(), demo_free(), demo_thread_entry(), k_demo_app_thread_pri, s_byte_pool, s_byte_pool_memory, s_byte_pool_name, s_demo_stack, s_demo_thread, s_thread_name, TX_AUTO_START, TX_NO_TIME_SLICE, and tx_thread_create.
|
static |
Default gateway + TLS endpoint: 192.168.1.1.
Definition at line 181 of file main.c.
Referenced by demo_netx_bring_up(), and demo_tcp_connect().
|
static |
IPv4 address: 192.168.1.42.
Definition at line 169 of file main.c.
Referenced by demo_netx_bring_up(), and demo_netx_create_ip().
|
static |
Locally-administered unicast MAC for this board.
Definition at line 166 of file main.c.
Referenced by demo_netx_bring_up(), demo_netx_create_ip(), and demo_pack_mac().
|
static |
Subnet mask: 255.255.255.0.
Definition at line 175 of file main.c.
Referenced by demo_netx_bring_up(), and demo_netx_create_ip().
|
static |
The one application record this demo sends after the handshake.
Definition at line 190 of file main.c.
Referenced by demo_exchange().
|
static |
SNI hostname advertised in the ClientHello.
Definition at line 187 of file main.c.
Referenced by demo_run_tls().
|
static |
|
static |
|
static |
Definition at line 211 of file main.c.
Referenced by tx_application_define().
|
static |
|
static |
|
static |
Persistent mutable names retained by NetX Duo and ThreadX objects.
Definition at line 208 of file main.c.
Referenced by demo_netx_bring_up(), demo_netx_create_ip(), and internal_demo_netx_bring_up().
|
static |
|
static |
Definition at line 212 of file main.c.
Referenced by demo_worker_spawn_intenb0_watchdog(), internal_spawn_rx_worker(), tx_application_define(), and tx_application_define().