ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
48
49#include <stdint.h>
50#include <string.h>
51
52#include "ra8_attributes.h"
53#include "ra8_board_ek_ra8d2.h"
54#include "ra8_boot_entry.h"
55#include "ra8_cgc.h"
56#include "ra8_err.h"
57#include "ra8_eth.h"
58#include "ra8_isr.h"
59#include "ra8_rsip.h"
60#include "ra8_time.h"
61
62#ifndef RA8_OFF_TARGET
63/* Mbed TLS 4.x relocated the legacy crypto primitive headers under
64 * `mbedtls/private/`. The TLS / X.509 layer headers stay at the
65 * public top level. */
66#include "mbedtls/net_sockets.h"
67#include "mbedtls/platform.h"
68#include "mbedtls/private/ctr_drbg.h"
69#include "mbedtls/private/entropy.h"
70#include "mbedtls/private/sha256.h"
71#include "mbedtls/ssl.h"
72#include "mbedtls/x509_crt.h"
73#include "nx_api.h"
75#include "psa/crypto.h"
76#include "tx_api.h"
77#endif
78
109
120
131
144
157
159typedef enum : uint8_t {
160 k_ascii_cr = 0x0DU,
161 k_ascii_lf = 0x0AU,
163
173
174static const uint8_t s_demo_mac[6] = {0x02U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U};
175
177static const uint8_t s_demo_ip[4] = {k_demo_ipaddr_0,
181
184
187
200
202static const char s_demo_host_name[] = "www.example.com";
203
219static const uint8_t s_demo_cert_pin_sha256[32] = {
220 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
221 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
222 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,
223};
224
225#ifndef RA8_OFF_TARGET
226/* NetX Duo state. ThreadX requires statically-allocated control
227 * blocks (NASA Power of 10 Rule 3 -- no dynamic memory). */
228static NX_PACKET_POOL s_packet_pool;
229static NX_IP s_ip;
230static NX_TCP_SOCKET s_tls_socket;
234
235/* ThreadX worker thread + a byte pool that backs Mbed TLS's
236 * mbedtls_calloc / mbedtls_free hooks. */
239static TX_BYTE_POOL s_byte_pool;
241
242/* Mbed TLS state. Placed at file scope so the stack frame of the
243 * worker thread stays well below k_demo_thread_stack. */
244static mbedtls_ssl_context s_ssl;
245static mbedtls_ssl_config s_ssl_cfg;
246static mbedtls_ctr_drbg_context s_drbg;
247static mbedtls_entropy_context s_entropy;
248
252#endif /* !RA8_OFF_TARGET */
253
266{
267 while (1) {
268 __asm__ volatile("wfi");
269 }
270}
271
286{
287 uint32_t cpuclk0_hz = 0U;
288
289 if (ra8_cgc_init() != k_ra8_ok) {
291 }
294 }
295 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
297 }
300 }
303 }
304
305 /* Bring up the RSIP engine for its TRNG entropy source (used to
306 * seed Mbed TLS's CTR_DRBG). The BIST is a one-shot ~ms operation so
307 * we run it here at boot, not per request. */
308 const ra8_rsip_config_t rsip_cfg = {.run_bist = true};
309 if (ra8_rsip_init(&rsip_cfg) != k_ra8_ok) {
311 }
312}
313
326RA8_INTERNAL static void internal_demo_print(const char* s)
327{
328 if (s == (const char*)0) {
329 return;
330 }
331 size_t len = strlen(s);
332 (void)ra8_board_uart_console_write((const uint8_t*)s, len);
333}
334
348RA8_INTERNAL static void internal_demo_write_bytes(const uint8_t* buf, uint32_t len)
349{
350 if (buf == nullptr || len == 0U) {
351 return;
352 }
353 (void)ra8_board_uart_console_write(buf, (size_t)len);
354}
355
356#ifndef RA8_OFF_TARGET
371RA8_INTERNAL static ULONG internal_demo_pack_ip(const uint8_t* octets)
372{
373 return (((ULONG)octets[k_demo_ip_oct_a]) << (ULONG)k_demo_ip_shift_a) |
377}
378
401
417{
418 static CHAR s_packet_pool_name[] = "ra8_eth_pool";
419 static CHAR s_ip_name[] = "ra8_eth_ip";
420
421 UINT s = nx_packet_pool_create(&s_packet_pool,
425 (ULONG)sizeof(s_pool_memory));
426 if (s != NX_SUCCESS) {
427 return s;
428 }
429
432 s = nx_ip_create(&s_ip,
433 s_ip_name,
434 ip_addr,
435 ip_mask,
438 (VOID*)s_ip_stack,
439 (ULONG)sizeof(s_ip_stack),
441 if (s != NX_SUCCESS) {
442 return s;
443 }
444
445 ULONG msw = 0U;
446 ULONG lsw = 0U;
447 internal_demo_pack_mac(&msw, &lsw);
448 (void)nx_ip_interface_physical_address_set(&s_ip, 0U, msw, lsw, NX_TRUE);
449
450 /* Default gateway so packets to www.example.com leave the LAN. */
451 (void)nx_ip_gateway_address_set(&s_ip, internal_demo_pack_ip(s_demo_gw));
452
453 s = nx_arp_enable(&s_ip, (VOID*)s_arp_cache, (ULONG)sizeof(s_arp_cache));
454 if (s != NX_SUCCESS) {
455 return s;
456 }
457 s = nx_tcp_enable(&s_ip);
458 if (s != NX_SUCCESS) {
459 return s;
460 }
461 (void)nx_icmp_enable(&s_ip);
462 return NX_SUCCESS;
463}
464
480{
481 static CHAR s_socket_name[] = "https443";
482
483 UINT s = nx_tcp_socket_create(&s_ip,
486 NX_IP_NORMAL,
487 NX_FRAGMENT_OKAY,
490 NX_NULL,
491 NX_NULL);
492 if (s != NX_SUCCESS) {
493 return s;
494 }
495 s = nx_tcp_client_socket_bind(&s_tls_socket, NX_ANY_PORT, NX_WAIT_FOREVER);
496 if (s != NX_SUCCESS) {
497 return s;
498 }
500 s = nx_tcp_client_socket_connect(&s_tls_socket,
501 host_ip,
504 return s;
505}
506
524RA8_INTERNAL static int internal_demo_bio_send(void* ctx, const unsigned char* buf, size_t len)
525{
526 (void)ctx;
527 if (buf == nullptr || len == 0U) {
528 return 0;
529 }
530 if (len > sizeof(s_tls_send_staging)) {
531 return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
532 }
533 memcpy(s_tls_send_staging, buf, len);
534 NX_PACKET* pkt = NX_NULL;
535 UINT s = nx_packet_allocate(&s_packet_pool, &pkt, NX_TCP_PACKET, NX_WAIT_FOREVER);
536 if (s != NX_SUCCESS || pkt == NX_NULL) {
537 return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
538 }
539 s = nx_packet_data_append(pkt, s_tls_send_staging, (ULONG)len, &s_packet_pool, NX_WAIT_FOREVER);
540 if (s != NX_SUCCESS) {
541 (void)nx_packet_release(pkt);
542 return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
543 }
544 s = nx_tcp_socket_send(&s_tls_socket, pkt, (ULONG)k_demo_recv_timeout);
545 if (s != NX_SUCCESS) {
546 (void)nx_packet_release(pkt);
547 if (s == NX_NO_PACKET || s == NX_WINDOW_OVERFLOW) {
548 return MBEDTLS_ERR_SSL_WANT_WRITE;
549 }
550 return MBEDTLS_ERR_NET_SEND_FAILED;
551 }
552 return (int)len;
553}
554
573RA8_INTERNAL static int internal_demo_bio_recv(void* ctx, unsigned char* buf, size_t len)
574{
575 (void)ctx;
576 if (buf == nullptr || len == 0U) {
577 return 0;
578 }
579 NX_PACKET* pkt = NX_NULL;
580 UINT s = nx_tcp_socket_receive(&s_tls_socket, &pkt, (ULONG)k_demo_recv_timeout);
581 if (s == NX_NO_PACKET) {
582 return MBEDTLS_ERR_SSL_WANT_READ;
583 }
584 if (s != NX_SUCCESS || pkt == NX_NULL) {
585 return MBEDTLS_ERR_NET_RECV_FAILED;
586 }
587 ULONG copied = 0U;
588 (void)nx_packet_data_retrieve(pkt, (VOID*)buf, &copied);
589 (void)nx_packet_release(pkt);
590 if (copied > (ULONG)len) {
591 /* Should not happen with a 1568-byte pool packet, but cap. */
592 copied = (ULONG)len;
593 }
594 return (int)copied;
595}
596
619RA8_INTERNAL static int
620internal_demo_entropy_source(void* ctx, unsigned char* buf, size_t len, size_t* olen)
621{
622 (void)ctx;
623 if (buf == nullptr || olen == nullptr) {
624 return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
625 }
626 ra8_err_t err = ra8_rsip_trng_read((uint8_t*)buf, (uint32_t)len);
627 if (err != k_ra8_ok) {
628 return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
629 }
630 *olen = len;
631 return 0;
632}
633
634#ifndef DEMO_DISABLE_CERT_PIN
653{
654 const mbedtls_x509_crt* peer = mbedtls_ssl_get_peer_cert(&s_ssl);
655 if (peer == nullptr) {
656 return -1;
657 }
658 uint8_t got[32];
659 if (ra8_rsip_sha256(peer->raw.p, (uint32_t)peer->raw.len, got) != k_ra8_ok) {
660 return -1;
661 }
662 if (memcmp(got, s_demo_cert_pin_sha256, sizeof(got)) != 0) {
663 return -1;
664 }
665 return 0;
666}
667#endif /* !DEMO_DISABLE_CERT_PIN */
668
684{
685 size_t request_len = 0U;
686 const char* request_parts[] = {
687 "GET / HTTP/1.1\r\nHost: ",
689 "\r\nConnection: close\r\nUser-Agent: ra8d2-https-client/0.1\r\n\r\n",
690 };
691 s_request_buf[0] = '\0';
692 for (size_t i = 0U; i < (sizeof(request_parts) / sizeof(request_parts[0])); ++i) {
693 const size_t part_len = strlen(request_parts[i]);
694 if (part_len > (sizeof(s_request_buf) - request_len - 1U)) {
695 return -1;
696 }
697 (void)memcpy(&s_request_buf[request_len], request_parts[i], part_len);
698 request_len += part_len;
699 s_request_buf[request_len] = '\0';
700 }
701 if (request_len == 0U) {
702 return -1;
703 }
704 size_t written = 0U;
705 while (written < request_len) {
706 int rc = mbedtls_ssl_write(&s_ssl, s_request_buf + written, request_len - written);
707 if (rc == MBEDTLS_ERR_SSL_WANT_READ || rc == MBEDTLS_ERR_SSL_WANT_WRITE) {
708 continue;
709 }
710 if (rc < 0) {
711 return rc;
712 }
713 written += (size_t)rc;
714 }
715
716 /* Read until we've dumped k_demo_dump_bytes of body or the peer
717 * closes. */
718 uint32_t body_dumped = 0U;
719 uint8_t saw_header_end = 0U;
720 uint8_t match = 0U; /* tracks "\r\n\r\n" run. */
721 while (body_dumped < (uint32_t)k_demo_dump_bytes) {
722 int rc = mbedtls_ssl_read(&s_ssl, s_response_buf, sizeof(s_response_buf));
723 if (rc == MBEDTLS_ERR_SSL_WANT_READ || rc == MBEDTLS_ERR_SSL_WANT_WRITE) {
724 continue;
725 }
726 if (rc == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY || rc == 0) {
727 break;
728 }
729 if (rc < 0) {
730 return rc;
731 }
732 int start = 0;
733 if (saw_header_end == 0U) {
734 /* Walk byte-by-byte looking for CRLFCRLF. */
735 for (int i = 0; i < rc; i++) {
736 uint8_t c = s_response_buf[i];
737 if ((match == 0U && c == k_ascii_cr) || (match == 2U && c == k_ascii_cr)) {
738 match++;
739 } else if ((match == 1U && c == k_ascii_lf) || (match == 3U && c == k_ascii_lf)) {
740 match++;
741 } else {
742 match = 0U;
743 }
744 if (match == 4U) {
745 saw_header_end = 1U;
746 start = i + 1;
747 break;
748 }
749 }
750 if (saw_header_end == 0U) {
751 continue;
752 }
753 }
754 int avail = rc - start;
755 uint32_t take = (uint32_t)avail;
756 if (body_dumped + take > (uint32_t)k_demo_dump_bytes) {
757 take = (uint32_t)k_demo_dump_bytes - body_dumped;
758 }
760 body_dumped += take;
761 }
762 return 0;
763}
764
781{
782 mbedtls_ssl_init(&s_ssl);
783 mbedtls_ssl_config_init(&s_ssl_cfg);
784
785 /* Mbed TLS 4.x removed MBEDTLS_ENTROPY_C and MBEDTLS_CTR_DRBG_C from
786 * the standard build path; the SSL layer pulls random bytes from PSA
787 * crypto (psa_generate_random), which the firmware wires to the RSIP
788 * TRNG via the mbedtls_psa_external_get_random() implementation
789 * above. The legacy mbedtls_entropy_* / mbedtls_ctr_drbg_* setup
790 * dance is therefore no longer needed. We still need PSA itself
791 * online; internal_demo_thread_entry calls psa_crypto_init() before this. */
792 (void)internal_demo_entropy_source; /* Retained for reference; unused on 4.x. */
793 (void)s_drbg;
794 (void)s_entropy;
795
796 if (mbedtls_ssl_config_defaults(&s_ssl_cfg,
797 MBEDTLS_SSL_IS_CLIENT,
798 MBEDTLS_SSL_TRANSPORT_STREAM,
799 MBEDTLS_SSL_PRESET_DEFAULT) != 0) {
800 return -1;
801 }
802 /* No CA bundle is provisioned in this demo -- we authenticate the
803 * peer by SHA-256 cert-pin instead. ``OPTIONAL`` lets the
804 * handshake complete even with an empty trust store; the pin
805 * check below is what gates the GET. */
806 mbedtls_ssl_conf_authmode(&s_ssl_cfg, MBEDTLS_SSL_VERIFY_OPTIONAL);
807 /* Mbed TLS 4.x removed mbedtls_ssl_conf_rng() -- the SSL layer
808 * pulls random bytes from PSA crypto's psa_generate_random() now,
809 * which is wired up by demo_psa_init() below via the
810 * MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG hook
811 * (mbedtls_psa_external_get_random). */
812
813 if (mbedtls_ssl_setup(&s_ssl, &s_ssl_cfg) != 0) {
814 return -1;
815 }
816 if (mbedtls_ssl_set_hostname(&s_ssl, s_demo_host_name) != 0) {
817 return -1;
818 }
819 mbedtls_ssl_set_bio(&s_ssl, nullptr, internal_demo_bio_send, internal_demo_bio_recv, nullptr);
820
821 /* Drive the handshake to completion. */
822 int rc = 0;
823 while ((rc = mbedtls_ssl_handshake(&s_ssl)) != 0) {
824 if (rc != MBEDTLS_ERR_SSL_WANT_READ && rc != MBEDTLS_ERR_SSL_WANT_WRITE) {
825 return rc;
826 }
827 }
828#ifndef DEMO_DISABLE_CERT_PIN
830 internal_demo_print("[https] cert pin MISMATCH -- aborting\r\n");
831 return -1;
832 }
833 internal_demo_print("[https] handshake OK, cert pin matches, dumping body\r\n");
834#else
835 internal_demo_print("[https] handshake OK, cert pin DISABLED, dumping body\r\n");
836#endif
837 return internal_demo_http_get();
838}
839
853{
854 (void)thread_input;
855 /* Bring PSA crypto online before any TLS / X.509 work. The library
856 * lazy-initialises inside the SSL layer, but doing it explicitly
857 * here surfaces failures earlier and binds the RSIP-TRNG external
858 * RNG hook before the handshake's first random call. */
859 if (psa_crypto_init() != PSA_SUCCESS) {
860 internal_demo_print("[https] psa_crypto_init failed\r\n");
861 return;
862 }
863 internal_demo_print("[https] bringing NetX Duo up...\r\n");
864 if (internal_demo_netx_bring_up() != NX_SUCCESS) {
865 internal_demo_print("[https] NetX bring-up failed\r\n");
866 return;
867 }
868 internal_demo_print("[https] connecting to www.example.com:443\r\n");
869 if (internal_demo_tcp_connect() != NX_SUCCESS) {
870 internal_demo_print("[https] TCP connect failed\r\n");
871 return;
872 }
873 if (internal_demo_tls_session() != 0) {
874 internal_demo_print("[https] TLS session failed\r\n");
875 }
876 internal_demo_print("\r\n[https] done\r\n");
877}
878
896RA8_INTERNAL static void* internal_demo_calloc(size_t n, size_t size)
897{
898 if ((n == 0U) || (size == 0U)) {
899 return nullptr;
900 }
901 if (n > (SIZE_MAX / size)) {
902 return nullptr;
903 }
904 const size_t total = n * size;
905 VOID* p = NX_NULL;
906 if (tx_byte_allocate(&s_byte_pool, &p, (ULONG)total, TX_NO_WAIT) != TX_SUCCESS) {
907 return nullptr;
908 }
909 (void)memset((void*)p, 0, total);
910 return p;
911}
912
926{
927 if (p == nullptr) {
928 return;
929 }
930 (void)tx_byte_release(p);
931}
932
942void tx_application_define(void* first_unused_memory)
943{
944 static CHAR s_byte_pool_name[] = "mbedtls_pool";
945 static CHAR s_thread_name[] = "https_worker";
946
947 (void)first_unused_memory;
948
949 (void)tx_byte_pool_create(&s_byte_pool,
952 (ULONG)sizeof(s_byte_pool_memory));
953 mbedtls_platform_set_calloc_free(internal_demo_calloc, internal_demo_free);
954
955 nx_system_initialize();
956
960 0U,
962 (ULONG)sizeof(s_demo_stack),
967}
968#endif /* !RA8_OFF_TARGET */
969
976void main(void)
977{
980 internal_demo_print("[https] booting ThreadX + NetX Duo + Mbed TLS...\r\n");
981
982#ifndef RA8_OFF_TARGET
983 tx_kernel_enter();
984#endif
985
987}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static CHAR s_socket_name[]
Definition c6_cam_net.c:40
static CHAR s_ip_name[]
Definition c6_cam_net.c:38
static const uint8_t s_demo_ip[4]
IPv4 address: 192.168.1.42 / 255.255.255.0.
Definition main.c:177
static const uint8_t s_demo_host_ip[4]
Static IPv4 for www.example.com (legacy edge-of-net IP).
Definition main.c:196
demo_ip_octet_t
Octet indices into a packed IPv4 address.
Definition main.c:114
@ k_demo_ip_oct_d
Demo IP oct d.
Definition main.c:118
@ k_demo_ip_oct_c
Demo IP oct c.
Definition main.c:117
@ k_demo_ip_oct_b
Demo IP oct b.
Definition main.c:116
@ k_demo_ip_oct_a
Demo IP oct a.
Definition main.c:115
static const char s_demo_host_name[]
HTTP/1.1 Host header literal – matches the IP pin above.
Definition main.c:202
static void internal_demo_pack_mac(ULONG *msw, ULONG *lsw)
Pack the local MAC into the msw/lsw fields NetX expects.
Definition main.c:392
static int internal_demo_tls_session(void)
Run the TLS bring-up: DRBG, config, configured pin policy, GET, dump.
Definition main.c:780
static UINT internal_demo_tcp_connect(void)
Open a NetX Duo TCP socket and connect to www.example.com:443.
Definition main.c:479
static mbedtls_ssl_config s_ssl_cfg
Definition main.c:245
demo_ipv4_t
Demo IPv4 addresses (board, gateway, host) as octet enums.
Definition main.c:146
@ 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_hostip_3
Demo hostip 3.
Definition main.c:155
@ k_demo_netmask_b
255.255.255.0 (first three octets).
Definition main.c:151
@ k_demo_hostip_1
Demo hostip 1.
Definition main.c:153
@ k_demo_ipaddr_3
Demo ipaddr 3.
Definition main.c:150
@ k_demo_hostip_2
Demo hostip 2.
Definition main.c:154
@ k_demo_hostip_0
93.184.216.34 (www.example.com).
Definition main.c:152
@ k_demo_ipaddr_1
Demo ipaddr 1.
Definition main.c:148
static mbedtls_entropy_context s_entropy
Definition main.c:247
static const uint8_t s_demo_mask[4]
Subnet mask: 255.255.255.0.
Definition main.c:183
static TX_THREAD s_demo_thread
Definition main.c:237
static int internal_demo_http_get(void)
Issue the HTTP GET and dump the first k_demo_dump_bytes to SCI8.
Definition main.c:683
static int internal_demo_entropy_source(void *ctx, unsigned char *buf, size_t len, size_t *olen)
Pull entropy from the RSIP TRNG into Mbed TLS.
Definition main.c:620
static void internal_demo_write_bytes(const uint8_t *buf, uint32_t len)
Write an arbitrary byte buffer to SCI8 (no NUL required).
Definition main.c:348
demo_ip_shift_t
Bit shifts that pack a 4-octet IPv4 into NetX's ULONG.
Definition main.c:125
@ k_demo_ip_shift_a
Demo IP shift a.
Definition main.c:126
@ k_demo_ip_shift_d
Demo IP shift d.
Definition main.c:129
@ k_demo_ip_shift_b
Demo IP shift b.
Definition main.c:127
@ k_demo_ip_shift_c
Demo IP shift c.
Definition main.c:128
http_ascii_t
ASCII control bytes used by the HTTP line scanner.
Definition main.c:159
@ k_ascii_lf
Line feed.
Definition main.c:161
@ k_ascii_cr
Carriage return.
Definition main.c:160
demo_mac_word_shift_t
Shifts that pack the 6-byte MAC into msw/lsw ULONG pairs.
Definition main.c:136
@ k_demo_mac_lsw_shift_b2
Demo MAC lsw shift b2.
Definition main.c:139
@ k_demo_mac_lsw_shift_b4
Demo MAC lsw shift b4.
Definition main.c:141
@ k_demo_mac_lsw_shift_b3
Demo MAC lsw shift b3.
Definition main.c:140
@ k_demo_mac_lsw_shift_b5
Demo MAC lsw shift b5.
Definition main.c:142
@ k_demo_mac_msw_shift_b0
Demo MAC msw shift b0.
Definition main.c:137
@ k_demo_mac_msw_shift_b1
Demo MAC msw shift b1.
Definition main.c:138
static void internal_demo_print(const char *s)
Convenience wrapper to write a NUL-terminated string to SCI8.
Definition main.c:326
static void internal_demo_panic_halt(void)
Halt forever in WFI.
Definition main.c:265
static const uint8_t s_demo_cert_pin_sha256[32]
SHA-256 of the expected leaf certificate DER, compile-time pinned.
Definition main.c:219
static int internal_demo_bio_send(void *ctx, const unsigned char *buf, size_t len)
Mbed TLS BIO send callback bound to nx_tcp_socket_send.
Definition main.c:524
static UINT internal_demo_netx_bring_up(void)
Bring NetX Duo up: pool, IP, ARP, TCP, ICMP.
Definition main.c:416
static int internal_demo_verify_cert_pin(void)
Verify the peer's leaf certificate matches our compile-time pin.
Definition main.c:652
static ULONG s_ip_stack[k_demo_ip_stack/sizeof(ULONG)]
Definition main.c:232
demo_mac_idx_t
MAC-address byte indices.
Definition main.c:165
@ k_demo_mac_idx_0
Demo MAC index 0.
Definition main.c:166
@ k_demo_mac_idx_3
Demo MAC index 3.
Definition main.c:169
@ k_demo_mac_idx_5
Demo MAC index 5.
Definition main.c:171
@ k_demo_mac_idx_2
Demo MAC index 2.
Definition main.c:168
@ k_demo_mac_idx_1
Demo MAC index 1.
Definition main.c:167
@ k_demo_mac_idx_4
Demo MAC index 4.
Definition main.c:170
static NX_PACKET_POOL s_packet_pool
Definition main.c:228
static mbedtls_ssl_context s_ssl
Definition main.c:244
static void internal_demo_free(void *p)
mbedtls_free hook backed by the ThreadX byte pool.
Definition main.c:925
demo_config_t
Compile-time settings for the HTTPS client demo.
Definition main.c:87
@ k_demo_log_buf_bytes
Demo log buffer bytes.
Definition main.c:103
@ k_demo_recv_timeout
Ticks; ~2 s at TX_TIMER_TICKS_PER_SECOND=100.
Definition main.c:101
@ k_demo_socket_ttl
Demo socket ttl.
Definition main.c:100
@ k_demo_app_thread_pri
Demo app thread priority.
Definition main.c:91
@ k_demo_thread_stack
Demo thread stack.
Definition main.c:89
@ k_demo_handshake_max
Max ticks waiting for handshake.
Definition main.c:102
@ k_demo_https_port
Demo HTTPS port.
Definition main.c:98
@ k_demo_packet_count
Demo packet count.
Definition main.c:93
@ k_demo_dump_bytes
First 1 KiB of body to SCI8.
Definition main.c:104
@ k_demo_ip_thread_pri
Demo IP thread priority.
Definition main.c:90
@ k_demo_packet_size
Demo packet size.
Definition main.c:92
@ k_demo_byte_pool_size
Demo byte pool size.
Definition main.c:95
@ k_demo_baud
Demo baud.
Definition main.c:88
@ k_demo_arp_cache
Demo arp cache.
Definition main.c:97
@ k_demo_pool_bytes
Demo pool bytes.
Definition main.c:94
@ k_demo_drbg_seed_len
Bytes pulled from RSIP TRNG.
Definition main.c:107
@ k_demo_response_buf
Demo response buffer.
Definition main.c:106
@ k_demo_request_buf
Demo request buffer.
Definition main.c:105
@ k_demo_recv_window
Demo recv window.
Definition main.c:99
@ k_demo_ip_stack
Demo IP stack.
Definition main.c:96
static NX_IP s_ip
Definition main.c:229
static ULONG internal_demo_pack_ip(const uint8_t *octets)
Pack a 4-octet IPv4 array into NetX's host-order ULONG.
Definition main.c:371
static const uint8_t s_demo_gw[4]
Default gateway: 192.168.1.1.
Definition main.c:186
static void internal_demo_thread_entry(ULONG thread_input)
ThreadX worker entry: bring NetX up, run TLS session, dump body.
Definition main.c:852
static mbedtls_ctr_drbg_context s_drbg
Definition main.c:246
static UCHAR s_byte_pool_memory[k_demo_byte_pool_size]
Definition main.c:240
static UCHAR s_tls_send_staging[k_demo_pool_bytes]
Definition main.c:251
static UCHAR s_demo_stack[k_demo_thread_stack]
Definition main.c:238
static UCHAR s_response_buf[k_demo_response_buf]
Definition main.c:250
static TX_BYTE_POOL s_byte_pool
Definition main.c:239
static int internal_demo_bio_recv(void *ctx, unsigned char *buf, size_t len)
Mbed TLS BIO recv callback bound to nx_tcp_socket_receive.
Definition main.c:573
static NX_TCP_SOCKET s_tls_socket
Definition main.c:230
static void internal_demo_setup_or_halt(void)
Bring CGC + the J-Link OB VCOM console + on-board Ethernet + RSIP up.
Definition main.c:285
static void * internal_demo_calloc(size_t n, size_t size)
mbedtls_calloc hook backed by the ThreadX byte pool.
Definition main.c:896
static UCHAR s_request_buf[k_demo_request_buf]
Definition main.c:249
static ULONG s_arp_cache[k_demo_arp_cache/sizeof(ULONG)]
Definition main.c:233
static UCHAR s_pool_memory[k_demo_pool_bytes]
Definition main.c:231
static const uint8_t s_demo_mac[6]
Definition main.c:174
void tx_application_define(void *first_unused_memory)
ThreadX system-define hook: build worker thread + byte pool.
Definition main.c:942
static CHAR s_packet_pool_name[]
Persistent mutable names retained by NetX Duo and ThreadX objects.
Definition main.c:208
static CHAR s_thread_name[]
Definition main.c:212
static CHAR s_byte_pool_name[]
Definition main.c:211
NetX Duo network driver shim that bridges onto the RA8 ra8_eth HAL.
void nx_ether_driver_ra8_eth(NX_IP_DRIVER *driver_req)
NetX Duo network-driver entry point bridging onto ra8_eth_*.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_ethernet_init(void)
Bring up the on-board RGMII Ethernet PHY and RMAC1/ETHA1.
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Error Code Definitions for ra8-firmware.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Ethernet Switch Module (ESWM) + frame TX/RX driver.
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
size_t strlen(const char *s)
Calculate string length.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
Renesas Secure IP (RSIP-E50D) HAL driver – public API.
ra8_err_t ra8_rsip_init(const ra8_rsip_config_t *cfg)
Power on the RSIP engine and (optionally) run BIST.
Definition ra8_rsip.c:234
ra8_err_t ra8_rsip_trng_read(uint8_t *buf, uint32_t len)
Drain len bytes from the RSIP true RNG – fail-closed, no backend.
Definition ra8_rsip.c:338
ra8_err_t ra8_rsip_sha256(const uint8_t *msg, uint32_t msg_len, uint8_t *digest)
Compute SHA-256 of an in-memory buffer.
Definition ra8_rsip.c:397
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
#define TX_SUCCESS
#define tx_thread_create
#define TX_NO_TIME_SLICE
char CHAR
ThreadX-compatible CHAR (host stub).
#define TX_AUTO_START
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
Opaque thread stand-in for the host build.
Initial configuration for ra8_rsip_init.