ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

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"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  demo_config_t : uint32_t {
  k_demo_baud = 115200U ,
  k_demo_thread_stack = 16384U ,
  k_demo_ip_thread_pri = 1U ,
  k_demo_app_thread_pri = 8U ,
  k_demo_packet_size = 1568U ,
  k_demo_pool_bytes = 32768U ,
  k_demo_byte_pool_size = 65536U ,
  k_demo_ip_stack = 4096U ,
  k_demo_arp_cache = 1024U ,
  k_demo_tls_port = 4433U ,
  k_demo_recv_window = 4096U ,
  k_demo_socket_ttl = 64U ,
  k_demo_recv_timeout = 200U ,
  k_demo_connect_ticks = 3000U ,
  k_demo_handshake_max = 20000U ,
  k_demo_io_max = 4000U ,
  k_demo_line_buf = 160U ,
  k_demo_record_cap = 64U ,
  k_demo_mtu = 128U ,
  k_demo_verify_unset
}
 Compile-time settings for the TLS-client demo. More...
enum  demo_ip_octet_t : uint8_t {
  k_demo_ip_oct_a = 0U ,
  k_demo_ip_oct_b = 1U ,
  k_demo_ip_oct_c = 2U ,
  k_demo_ip_oct_d = 3U
}
 Octet indices into a packed IPv4 address. More...
enum  demo_ip_shift_t : uint8_t {
  k_demo_ip_shift_a = 24U ,
  k_demo_ip_shift_b = 16U ,
  k_demo_ip_shift_c = 8U ,
  k_demo_ip_shift_d = 0U
}
 Bit shifts that pack a 4-octet IPv4 into NetX's ULONG. More...
enum  demo_mac_word_shift_t : uint8_t {
  k_demo_mac_msw_shift_b0 = 8U ,
  k_demo_mac_msw_shift_b1 = 0U ,
  k_demo_mac_lsw_shift_b2 = 24U ,
  k_demo_mac_lsw_shift_b3 = 16U ,
  k_demo_mac_lsw_shift_b4 = 8U ,
  k_demo_mac_lsw_shift_b5 = 0U
}
 Shifts that pack the 6-byte MAC into msw/lsw ULONG pairs. More...
enum  demo_ipv4_t : uint16_t {
  k_demo_ipaddr_0 = 192U ,
  k_demo_ipaddr_1 = 168U ,
  k_demo_ipaddr_2 = 1U ,
  k_demo_ipaddr_3 = 42U ,
  k_demo_netmask_b = 255U ,
  k_demo_gw_3 = 1U
}
 Demo IPv4 octets (board, gateway/endpoint, netmask). More...
enum  demo_mac_idx_t : uint8_t {
  k_demo_mac_idx_0 = 0U ,
  k_demo_mac_idx_1 = 1U ,
  k_demo_mac_idx_2 = 2U ,
  k_demo_mac_idx_3 = 3U ,
  k_demo_mac_idx_4 = 4U ,
  k_demo_mac_idx_5 = 5U
}
 MAC-address byte indices. More...

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"

Detailed Description

TLS client over ra8_tls + ra8_net_pal (NetX Duo transport).

Tag
[Ring 6 / APP] {World: S}

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:

  1. psa_crypto_init() (Mbed TLS 4.x sources randomness from PSA; the external-RNG hook below feeds it from the RSIP TRNG).
  2. Brings NetX Duo up as a TCP client at 192.168.1.42/24, gateway 192.168.1.1.
  3. Opens a TCP socket to a test TLS endpoint (default 192.168.1.1:4433) and connects.
  4. Opens an ra8_tls session whose BIO callbacks are bound to the NetX socket, then drives ra8_tls_handshake to completion.
  5. Sends one application record and reads one back.
  6. Prints the negotiated cipher suite and the peer-verification result through ra8_tls_get_cipher_suite / ra8_tls_get_verify_result.

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).

Why hw_pending (not emulator-gated)

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.

Author
Brighton Sikarskie
Date
2026-07-15
Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ demo_config_t

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.

Enumerator
k_demo_baud 

Demo baud.

k_demo_thread_stack 

Demo thread stack.

k_demo_ip_thread_pri 

Demo IP thread priority.

k_demo_app_thread_pri 

Demo app thread priority.

k_demo_packet_size 

Demo packet size.

k_demo_pool_bytes 

Demo pool bytes.

k_demo_byte_pool_size 

Demo byte pool size.

k_demo_ip_stack 

Demo IP stack.

k_demo_arp_cache 

Demo arp cache.

k_demo_tls_port 

Default TLS endpoint port.

k_demo_recv_window 

Demo recv window.

k_demo_socket_ttl 

Demo socket ttl.

k_demo_recv_timeout 

Ticks; ~2 s at 100 Hz.

k_demo_connect_ticks 

Max ticks waiting for connect.

k_demo_handshake_max 

Bounded handshake poll count.

k_demo_io_max 

Bounded send/recv poll count.

k_demo_line_buf 

Result line buffer bytes.

k_demo_record_cap 

Inbound record buffer bytes.

k_demo_mtu 

#21 pinned link MTU.

k_demo_verify_unset 

Fail-closed verify sentinel: nonzero until the getter fills it.

Definition at line 80 of file main.c.

◆ demo_ip_octet_t

enum demo_ip_octet_t : uint8_t

Octet indices into a packed IPv4 address.

Enumerator
k_demo_ip_oct_a 

Demo IP oct a.

k_demo_ip_oct_b 

Demo IP oct b.

k_demo_ip_oct_c 

Demo IP oct c.

k_demo_ip_oct_d 

Demo IP oct d.

Definition at line 108 of file main.c.

◆ demo_ip_shift_t

enum demo_ip_shift_t : uint8_t

Bit shifts that pack a 4-octet IPv4 into NetX's ULONG.

Enumerator
k_demo_ip_shift_a 

Demo IP shift a.

k_demo_ip_shift_b 

Demo IP shift b.

k_demo_ip_shift_c 

Demo IP shift c.

k_demo_ip_shift_d 

Demo IP shift d.

Definition at line 119 of file main.c.

◆ demo_ipv4_t

enum demo_ipv4_t : uint16_t

Demo IPv4 octets (board, gateway/endpoint, netmask).

Enumerator
k_demo_ipaddr_0 

192.168.1.42 board.

k_demo_ipaddr_1 

Demo ipaddr 1.

k_demo_ipaddr_2 

Demo ipaddr 2.

k_demo_ipaddr_3 

Demo ipaddr 3.

k_demo_netmask_b 

255.255.255.0 (first three octets).

k_demo_gw_3 

192.168.1.1 gateway + TLS endpoint.

Definition at line 143 of file main.c.

◆ demo_mac_idx_t

enum demo_mac_idx_t : uint8_t

MAC-address byte indices.

Enumerator
k_demo_mac_idx_0 

Demo MAC index 0.

k_demo_mac_idx_1 

Demo MAC index 1.

k_demo_mac_idx_2 

Demo MAC index 2.

k_demo_mac_idx_3 

Demo MAC index 3.

k_demo_mac_idx_4 

Demo MAC index 4.

k_demo_mac_idx_5 

Demo MAC index 5.

Definition at line 156 of file main.c.

◆ demo_mac_word_shift_t

enum demo_mac_word_shift_t : uint8_t

Shifts that pack the 6-byte MAC into msw/lsw ULONG pairs.

Enumerator
k_demo_mac_msw_shift_b0 

Demo MAC msw shift b0.

k_demo_mac_msw_shift_b1 

Demo MAC msw shift b1.

k_demo_mac_lsw_shift_b2 

Demo MAC lsw shift b2.

k_demo_mac_lsw_shift_b3 

Demo MAC lsw shift b3.

k_demo_mac_lsw_shift_b4 

Demo MAC lsw shift b4.

k_demo_mac_lsw_shift_b5 

Demo MAC lsw shift b5.

Definition at line 130 of file main.c.

Function Documentation

◆ demo_calloc()

void * demo_calloc ( size_t n,
size_t size )
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.

Parameters
[in]nElement count.
[in]sizeElement size in bytes.
Returns
Zeroed memory, or NULL on failure / overflow / zero request.
Return values
nullptrn is zero, size is zero, multiplication overflows, or pool is exhausted.
non-nullPointer to zero-initialized allocated memory.
Precondition
s_byte_pool has been created.
No pool mutex inversion exists in the calling context.
Postcondition
Returned block (if any) is zeroed.
Allocation failure leaves the byte pool unchanged.
Note
This hook never waits, preventing allocator deadlock inside TLS paths.
Since
0.1.0

Definition at line 385 of file main.c.

References memset(), s_byte_pool, and TX_SUCCESS.

Referenced by tx_application_define().

◆ demo_exchange()

ra8_err_t demo_exchange ( ra8_tls_session_t session,
uint8_t * got,
size_t got_cap )
static

Send one record and read one back over the TLS session.

Parameters
[in]sessionOpen, handshaken ra8_tls session.
[out]gotReceive buffer for the reply.
[in]got_capCapacity of got in bytes.
Returns
k_ra8_ok if a record was sent and a reply was received.
Precondition
session handshake completed; got non-NULL, got_cap >= 1.
Postcondition
On success at least one plaintext byte was exchanged each way.
Since
0.1.0

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().

◆ demo_free()

void demo_free ( void * p)
static

mbedtls_free hook backed by the ThreadX byte pool.

Parameters
[in]pPointer previously returned by demo_calloc (NULL OK).
Precondition
s_byte_pool has been created.
Postcondition
The block is returned to the pool.
Since
0.1.0

Definition at line 412 of file main.c.

Referenced by tx_application_define().

◆ demo_handshake()

ra8_err_t demo_handshake ( ra8_tls_session_t session)
static

Drive the ra8_tls handshake to completion (bounded poll loop).

Parameters
[in]sessionOpen ra8_tls session handle.
Returns
k_ra8_ok on a completed handshake, otherwise the facade error (or k_ra8_err_timeout if the poll budget is exhausted).
Precondition
session is open and its BIO is bound.
Postcondition
On k_ra8_ok the session is in the application-data state.
Since
0.1.0

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().

◆ demo_netx_bring_up()

UINT demo_netx_bring_up ( void )
static

Bring NetX Duo up: pool, IP, gateway, ARP, TCP, ICMP.

Returns
NX_SUCCESS on success, propagating NetX error codes.
Precondition
nx_system_initialize has run.
Postcondition
On success the IP stack is ready for outbound TCP.
Since
0.1.0

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().

◆ demo_pack_ip()

ULONG demo_pack_ip ( const uint8_t * octets)
static

Pack a 4-octet IPv4 array into NetX's host-order ULONG.

Parameters
[in]octetsIPv4 address (4 bytes). Must not be NULL.
Returns
Host-order packed address suitable for NetX.
Precondition
octets != NULL and holds 4 bytes.
Postcondition
No state is modified.
Since
0.1.0

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().

◆ demo_pack_mac()

void demo_pack_mac ( ULONG * msw,
ULONG * lsw )
static

Pack the local MAC into the msw/lsw fields NetX expects.

Parameters
[out]mswMost-significant word (octets 0-1). Must not be NULL.
[out]lswLeast-significant word (octets 2-5). Must not be NULL.
Precondition
msw != NULL and lsw != NULL.
Postcondition
*msw / *lsw hold the packed MAC halves.
Since
0.1.0

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().

◆ demo_panic_halt()

void demo_panic_halt ( void )
static

Halt forever in WFI.

Called on any fatal error.

Precondition
Called only after a fatal error.
Postcondition
CPU is parked.
Since
0.1.0

Definition at line 223 of file main.c.

◆ demo_print()

void demo_print ( const char * s)
static

Write a NUL-terminated string to the console.

Parameters
[in]sNUL-terminated ASCII string. Must not be NULL.
Precondition
s != NULL.
Postcondition
Bytes are queued in the console TX FIFO (best-effort).
Since
0.1.0

Definition at line 274 of file main.c.

References ra8_board_uart_console_write(), and strlen().

◆ demo_report()

void demo_report ( ra8_tls_session_t session)
static

Print the negotiated cipher + verification result to the console.

Parameters
[in]sessionHandshaken ra8_tls session.
Precondition
session handshake completed.
Postcondition
One [tls] cipher=... verify=... line has been emitted.
Since
0.1.0

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().

◆ demo_run_tls()

ra8_err_t demo_run_tls ( void )
static

Run the whole TLS session: open, handshake, exchange, report.

Returns
k_ra8_ok on a completed exchange.
Precondition
demo_tcp_connect returned NX_SUCCESS.
Postcondition
The session has been closed and the facade deinitialised.
Since
0.1.0

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().

◆ demo_setup_or_halt()

void demo_setup_or_halt ( void )
static

Bring CGC + the J-Link OB VCOM console + on-board Ethernet + RSIP up.

Precondition
Reset_Handler / SystemInit complete.
Postcondition
On success the BSP console is sending at 115200 8N1, ETHA0 / RMAC0 are initialized, and the RSIP engine has finished BIST.
Since
0.1.0

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().

◆ demo_tcp_connect()

UINT demo_tcp_connect ( void )
static

Open a NetX TCP socket and connect to the TLS endpoint.

Returns
NX_SUCCESS on success.
Precondition
demo_netx_bring_up returned NX_SUCCESS.
Postcondition
On success s_tls_socket is connected and ready for I/O.
Since
0.1.0

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().

◆ demo_thread_entry()

void demo_thread_entry ( ULONG thread_input)
static

ThreadX worker entry: PSA + NetX up, connect, run the TLS session.

Parameters
[in]thread_inputUnused.
Precondition
nx_system_initialize has run.
Postcondition
Worker parks after the exchange or on the first failure.
Since
0.1.0

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().

◆ main()

void main ( void )

Application entry.

The application entry point Reset_Handler hands control to.

Brings up clocks + UART + RMII + RSIP, then ThreadX.

Precondition
Reset_Handler has copied .data and zeroed .bss.
Postcondition
On clean entry the kernel runs the worker thread once.
Since
0.1.0

Definition at line 797 of file main.c.

References demo_panic_halt(), demo_print(), demo_setup_or_halt(), and ra8_isr_globals_enable().

◆ mbedtls_psa_external_get_random()

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.

Parameters
[in,out]contextPSA per-process external RNG context (unused).
[out]outputOutput buffer.
[in]output_sizeBytes requested.
[out]output_lengthBytes actually produced.
Return values
PSA_SUCCESSon success.
PSA_ERROR_INVALID_ARGUMENTon a NULL output pointer.
PSA_ERROR_HARDWARE_FAILUREif the RSIP TRNG returned an error.
Precondition
RSIP has been initialized by ra8_rsip_init().
Postcondition
output holds output_size bytes on success.
Note
Not thread-safe; callers must serialise across threads.
Since
0.1.0

Definition at line 348 of file main.c.

References k_ra8_ok, and ra8_rsip_trng_read().

◆ tls_bio_recv()

int tls_bio_recv ( void * ctx,
uint8_t * buf,
size_t len )
static

ra8_tls BIO recv callback bound to nx_tcp_socket_receive.

Parameters
[in]ctxOpaque context (unused).
[out]bufOutput buffer.
[in]lenMaximum bytes to read.
Returns
Bytes copied, MBEDTLS_ERR_SSL_WANT_READ when nothing is ready yet, or a negative MBEDTLS_ERR_* on error.
Precondition
Socket s_tls_socket is connected.
Postcondition
On success buf holds the returned bytes.
Since
0.1.0

Definition at line 477 of file main.c.

References k_demo_recv_timeout, and s_tls_socket.

Referenced by demo_run_tls().

◆ tls_bio_send()

int tls_bio_send ( void * ctx,
const uint8_t * buf,
size_t len )
static

ra8_tls BIO send callback bound to nx_tcp_socket_send.

Parameters
[in]ctxOpaque context (unused – the file-scope socket is used).
[in]bufCiphertext bytes the TLS layer wants to transmit.
[in]lenBuffer length in bytes.
Returns
Bytes written, or a negative MBEDTLS_ERR_* code.
Precondition
Socket s_tls_socket is connected.
Postcondition
On success the bytes are queued for TX.
Since
0.1.0

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().

◆ tx_application_define()

void tx_application_define ( void * first_unused_memory)

ThreadX system-define hook: build worker thread + byte pool.

Parameters
[in]first_unused_memoryFree RAM from the ThreadX port; unused.
Precondition
tx_kernel_enter() has been called.
Postcondition
One worker thread is created and Mbed TLS's allocator is wired.
Since
0.1.0

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.

Variable Documentation

◆ k_demo_gw

const uint8_t k_demo_gw[4]
static
Initial value:
= {(uint8_t)k_demo_ipaddr_0,
(uint8_t)k_demo_ipaddr_1,
(uint8_t)k_demo_ipaddr_2,
(uint8_t)k_demo_gw_3}
@ k_demo_ipaddr_0
192.168.1.42 board.
Definition main.c:147
@ k_demo_ipaddr_2
Demo ipaddr 2.
Definition main.c:149
@ k_demo_ipaddr_1
Demo ipaddr 1.
Definition main.c:148
@ k_demo_gw_3
192.168.1.1 gateway + TLS endpoint.
Definition main.c:149

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().

◆ k_demo_ip

const uint8_t k_demo_ip[4]
static
Initial value:
= {(uint8_t)k_demo_ipaddr_0,
(uint8_t)k_demo_ipaddr_1,
(uint8_t)k_demo_ipaddr_2,
(uint8_t)k_demo_ipaddr_3}
@ k_demo_ipaddr_3
Demo ipaddr 3.
Definition main.c:150

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().

◆ k_demo_mac

const uint8_t k_demo_mac[6] = {0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x03U}
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().

◆ k_demo_mask

const uint8_t k_demo_mask[4]
static
Initial value:
= {(uint8_t)k_demo_netmask_b,
(uint8_t)k_demo_netmask_b,
(uint8_t)k_demo_netmask_b,
0U}
@ k_demo_netmask_b
255.255.255.0 (first three octets).
Definition main.c:151

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().

◆ k_demo_record

const uint8_t k_demo_record[] = "PING over ra8_tls\n"
static

The one application record this demo sends after the handshake.

Definition at line 190 of file main.c.

Referenced by demo_exchange().

◆ k_demo_server_name

const char k_demo_server_name[] = "endpoint.test"
static

SNI hostname advertised in the ClientHello.

Definition at line 187 of file main.c.

Referenced by demo_run_tls().

◆ s_arp_cache

ULONG s_arp_cache[k_demo_arp_cache/sizeof(ULONG)]
static

Definition at line 200 of file main.c.

◆ s_byte_pool

TX_BYTE_POOL s_byte_pool
static

Definition at line 205 of file main.c.

◆ s_byte_pool_memory

UCHAR s_byte_pool_memory[k_demo_byte_pool_size]
static

Definition at line 206 of file main.c.

◆ s_byte_pool_name

CHAR s_byte_pool_name[] = "mbedtls_pool"
static

Definition at line 211 of file main.c.

Referenced by tx_application_define().

◆ s_demo_stack

UCHAR s_demo_stack[k_demo_thread_stack]
static

Definition at line 204 of file main.c.

◆ s_demo_thread

TX_THREAD s_demo_thread
static

Definition at line 203 of file main.c.

◆ s_ip

NX_IP s_ip
static

Definition at line 196 of file main.c.

◆ s_ip_name

CHAR s_ip_name[] = "ra8_eth_ip"
static

Definition at line 209 of file main.c.

◆ s_ip_stack

ULONG s_ip_stack[k_demo_ip_stack/sizeof(ULONG)]
static

Definition at line 199 of file main.c.

◆ s_packet_pool

NX_PACKET_POOL s_packet_pool
static

Definition at line 195 of file main.c.

◆ s_packet_pool_name

CHAR s_packet_pool_name[] = "ra8_eth_pool"
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().

◆ s_pool_memory

UCHAR s_pool_memory[k_demo_pool_bytes]
static

Definition at line 198 of file main.c.

◆ s_socket_name

CHAR s_socket_name[] = "tls4433"
static

Definition at line 210 of file main.c.

◆ s_thread_name

CHAR s_thread_name[] = "tls_worker"
static

◆ s_tls_socket

NX_TCP_SOCKET s_tls_socket
static

Definition at line 197 of file main.c.