### Example TLS Setup Callback Implementation Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-mqtt/chapter1.md Provides an example implementation of a TLS setup callback function. This includes initializing the TLS module, creating a TLS session, allocating space for the remote certificate, and adding a CA certificate to the trusted store for server authentication. ```c UINT tls_setup_callback(NXD_MQTT_CLIENT *client_pt NX_SECURE_TLS_SESSION *session_ptr, NX_SECURE_TLS_CERTIFICATE *certificate_ptr, NX_SECURE_TLS_CERTIFICATE *trusted_certificate_ptr) { /* Initialize TLS module */ nx_secure_tls_initialize(); /* Create a TLS session */ nx_secure_tls_session_create(session_ptr, …); /* Need to allocate space for the certificate coming in from the broker. */ memset(certificate_ptr), 0, sizeof(NX_SECURE_TLS_CERTIFICATE)); nx_secure_tls_remote_certificate_allocate(session_ptr, certificate_ptr); /* Add a CA Certificate to our trusted store for verifying incoming server certificates. */ nx_secure_tls_certificate_initialize( trusted_certificate_ptr, ca_cert_der, ca_cert_der_len, NULL, 0); nx_secure_tls_trusted_certificate_add(session_ptr, trusted_certificate)); } ``` -------------------------------- ### GUIX Helloworld Example Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/guix/guix-example.md This C code defines the main entry point for the GUIX 'helloworld' example. It initializes the system and starts the application. ```c #include "gx_api.h" #ifdef GX_ பயன்பாடு_DEMO /***************************************************************************************** * * * GUIX_APPLICATION_START * * ***************************************************************************************** */ void GUIX_APPLICATION_START(void *first_entry) { /* Initialize GUIX. */ gx_system_initialize(); /* Install the default graphics driver. This is a placeholder and needs to be replaced with the actual driver for your hardware. */ gx_driver_setup_24bpp_rgb565(0); /* Start the GUIX application. */ gx_application_define(first_entry, GX_NULL, GX_NULL, GX_NULL); } #endif ``` -------------------------------- ### RTSP SETUP Method Example Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-rtsp/chapter1.md Shows the RTSP SETUP request and response for preparing the server for streaming. This method MUST be enabled by registering the nx_rtsp_server_setup_callback_set() callback. ```text RTSP Client -> RTSP Server: SETUP rtsp://10.0.0.55:554/trackID=0 RTSP/1.0 CSeq: 3 Transport: RTP/AVP;unicast;client_port=55612-55613 RTSP Server -> RTSP Client: RTSP/1.0 200 OK CSeq: 3 Server: RTSP Server Session: 15724;timeout=60 Transport: RTP/AVP;unicast;client_port=55612-55613;server_port=5004-5005;ssrc=6334 ``` -------------------------------- ### Example Usage of nx_web_http_client_head_secure_start Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-web-http/chapter3.md An example demonstrating how to initiate a secure HEAD request using nx_web_http_client_head_secure_start. This example shows setting up the server IP address and calling the function with authentication details and a TLS setup callback. ```C /* Connect to a remote HTTP server. */ server_ip_addr.nxd_ip_version = NX_IP_VERSION_V4; server_ip_addr.nxd_ip_address.v4 = IP_ADDRESS(1,2,3,5); /* Start the HEAD operation on the HTTP Client "my_client." */ status = nx_web_http_client_head_secure_start(&my_client, &server_ip_addr, NX_WEB_HTTPS_SERVER_PORT, "/TEST.HTM", "host.com", "myname", "mypassword", my_tls_setup_function, 1000); /* If status is NX_SUCCESS, the HEAD request for TEST.HTM is started and is so far successful. The client must now call *nx_web_http_client_response_body_get* to retrieve the server's response. */ ``` -------------------------------- ### Initialize and Send Custom HTTP GET Request Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-web-http/chapter3.md This example demonstrates connecting to a secure HTTPS server, initializing a custom GET request with headers, sending the request, and processing the response. Ensure the TLS setup callback is correctly implemented. ```C /* Connect to a remote HTTPS server. */ nx_web_http_client_secure_connect(&my_client, IP_ADDRESS(1,2,3,5), NX_WEB_HTTPS_SERVER_PORT, tls_setup_callback, NX_WAIT_FOREVER); /* Create a new GET request on the HTTP client instance. */ nx_web_http_client_request_initialize(&my_client, NX_WEB_HTTP_METHOD_GET, "https://192.168.1.150/test.txt ", "host.com", 0, /* Used by PUT and POST only */ NX_FALSE, NX_NULL, /* username */ NX_NULL, /* password */ NX_WAIT_FOREVER); /* Add a custom header to the GET request we just created. */ status = nx_web_http_client_request_header_add(&my_client, "Server", 6, "NetX Web HTTPS Server", 21, NX_WAIT_FOREVER); /* Start the GET operation to get a response from the HTTPS server. */ status = nx_web_http_client_request_send(&my_client, 1000); /* At this point, we need to handle the response from the server by repeatedly calling *nx_web_http_client_response_body_get* until the entire response is retrieved. */ get_status = NX_SUCCESS; while(get_status != NX_WEB_HTTP_GET_DONE) { get_status = nx_web_http_client_response_body_get(&my_client, &receive_packet, NX_WAIT_FOREVER); /* Process response packets… */ } ``` -------------------------------- ### NetX Duo SNTP Client Example Setup Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-sntp-client/chapter2.md Includes necessary headers and defines constants for the SNTP Client example. This setup is for a basic demonstration and may require modifications for specific hardware and network configurations. ```c /* This is a small demo of the NetX SNTP Client on the high-performance NetX TCP/IP stack. This demo relies on Thread, NetX and NetX SNTP Client API to execute the Simple Network Time Protocol in unicast and broadcast modes. */ #include #include "nx_api.h" #include "nx_ip.h" #include "nxd_sntp_client.h" /* Define SNTP packet size. */ #define NX_SNTP_CLIENT_PACKET_SIZE (NX_UDP_PACKET + 100) /* Define SNTP packet pool size. */ #define NX_SNTP_CLIENT_PACKET_POOL_SIZE (4 * (NX_SNTP_CLIENT_PACKET_SIZE + sizeof(NX_PACKET))) /* Define how often the demo checks for SNTP updates. */ #define DEMO_PERIODIC_CHECK_INTERVAL (1 * NX_IP_PERIODIC_RATE) /* Define how often we check on SNTP server status. We expect updates from the SNTP server about every hour using the SNTP Client defaults. For testing make this (much) shorter. */ #define CHECK_SNTP_UPDATES_TIMEOUT (180 * NX_IP_PERIODIC_RATE) /* Set up generic network driver for demo program. */ void _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req); /* Application defined services of the NetX SNTP Client. */ UINT leap_second_handler(NX_SNTP_CLIENT *client_ptr, UINT leap_indicator); UINT kiss_of_death_handler(NX_SNTP_CLIENT *client_ptr, UINT KOD_code); VOID time_update_callback(NX_SNTP_TIME_MESSAGE *time_update_ptr, NX_SNTP_TIME *local_time); /* Set up client thread and network resources. */ NX_PACKET_POOL client_packet_pool; NX_IP client_ip; TX_THREAD demo_client_thread; NX_SNTP_CLIENT demo_sntp_client; TX_EVENT_FLAGS_GROUP sntp_flags; #define DEMO_SNTP_UPDATE_EVENT 1 /* Configure the SNTP Client to use IPv6. If not enabled, the Client will use IPv4. Note: IPv6 must be enabled in NetX Duo for the Client to communicate over IPv6. */ #ifdef FEATURE_NX_IPV6 /* #define USE_IPV6 */ #endif /* FEATURE_NX_IPV6 */ ``` -------------------------------- ### Configure and Start DTLS Server Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-secure-dtls/chapter4.md This snippet demonstrates the setup and initialization of a DTLS server, including certificate configuration and starting the server. Ensure necessary buffers and crypto tables are defined. ```C /* Configure number of sessions per server. */ #define DTLS_SERVER_SESSIONS 3 /* Define parameters for X.509 client verification. */ #define MAX_CERT_SIZE (2000) /* 2KB expected maximum certificate size. */ #define CERTS_PER_SESSION (3) /* Assume maximum chain length of 3 certificates. */ #define CERT_BUFFER_SIZE (DTLS_SERVER_SESSIONS * CERTS_PER_SESSION * \ (MAX_CERT_SIZE + sizeof(NX_SECURE_X509_CERT)) /* Define our incoming certificate buffer. */ UCHAR client_certs_buffer[CERT_BUFFER_SIZE]; /* Our DTLS Server instance. */ NX_SECURE_DTLS_SERVER dtls_server; /* Certificate control block and data. */ NX_SECURE_X509_CERT trusted_ca_certificate; UCHAR certificate_der_data[] = { … }; /* Primary application thread for handling DTLS server operations. */ void dtls_server_thread(void) { UINT status; /* Setup DTLS Server instance. */ status = nx_secure_dtls_server_create(&dtls_server, &ip_instance, LOCAL_SERVER_PORT, NX_IP_PERIODIC_RATE, dtls_server_session_buffer, sizeof(dtls_server_session_buffer), &tls_crypto_table, crypto_metadata_buffer, sizeof(crypto_metadata_buffer), packet_buffer, sizeof(packet_buffer), dtls_server_connect_notify, dtls_server_receive_notify); /* Check for errors. */ /* Initialize trusted certificate with key and add to server. */ status = nx_secure_x509_certificate_initialize(&trusted_ca_certificate, certificate_der_data, sizeof(certificate_der_data), NX_NULL, 0, NX_NULL, 0, NX_SECURE_X509_KEY_TYPE_NONE); /* Add local server identity certificate to DTLS server with ID of 1. */ status = nx_secure_dtls_server_trusted_certificate_add(&dtls_server, &trusted_ca_certificate, 1); /* Configure client X.509 authentication and verification. */ status = nx_secure_dtls_server_x509_client_verify_configure(&dtls_server, CERTS_PER_SESSION, client_certs_buffer, sizeof(client_certs_buffer)); /* Start server. */ status = nx_secure_dtls_server_start(&dtls_server); /* Process client requests, etc… */ } ``` -------------------------------- ### Start, Sleep, Stop, and Unload Module Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/threadx-modules/chapter5.md This example demonstrates the sequence of starting a module, allowing it to run for a period, stopping it, and then unloading it. Ensure the module manager is initialized before calling these functions. ```c /* Start the module. */ txm_module_manager_start(&my_module); /* Let the module run for a while. */ tx_thread_sleep(20000); /* Stop the module. */ txm_module_manager_stop(&my_module); /* Unload the module. */ txm_module_manager_unload(&my_module); ``` -------------------------------- ### nx_dns_authority_zone_start_get Example Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-dns/chapter3.md Example demonstrating how to request the start of authority (SOA) record for a specified host. ```APIDOC ### Example ```C UCHAR record_buffer[50]; UINT record_count; NX_DNS_SOA_ENTRY *nx_dns_soa_entry_ptr; /* Request the start of authority zone(s) for the specified host. */ status = nx_dns_authority_zone_start_get(&client_dns, (UCHAR *)"www.my_example.com", record _buffer, sizeof(record_buffer), &record_count, 500); /* Check for DNS query error. */ if (status != NX_SUCCESS) { error_counter++; } else { /* If status is NX_SUCCESS a DNS query was successfully completed and SOA data is returned in soa_buffer. */ /* Set a local pointer to the SOA buffer. */ nx_dns_soa_entry_ptr = (NX_DNS_SOA_ENTRY *) record_buffer; printf("------------------------------------------------------\n"); printf("Test SOA: \n"); printf("serial = %d\n", nx_dns_soa_entry_ptr -> nx_dns_soa_serial ); printf("refresh = %d\n", nx_dns_soa_entry_ptr -> nx_dns_soa_refresh ); printf("retry = %d\n", nx_dns_soa_entry_ptr -> nx_dns_soa_retry ); printf("expire = %d\n", nx_dns_soa_entry_ptr -> nx_dns_soa_expire ); printf("minmum = %d\n", nx_dns_soa_entry_ptr -> nx_dns_soa_minmum ); if(nx_dns_soa_entry_ptr -> nx_dns_soa_host_mname_ptr) { printf("host mname = %s\n", nx_dns_soa_entry_ptr -> nx_dns_soa_host_mname_ptr); } else { printf("host mame is not set\n"); } if(nx_dns_soa_entry_ptr -> nx_dns_soa_host_rname_ptr) { printf("host rname = %s\n", nx_dns_soa_entry_ptr -> nx_dns_soa_host_rname_ptr); } else { printf("host rname is not set\n"); } } [Output] ---------------------------------------------------- Test SOA: serial = 2012111212 refresh = 7200 retry = 1800 expire = 1209600 minmum = 300 host mname = ns1.www.my_example.com host rname = dns-admin.www.my_example.com ``` ``` -------------------------------- ### Configure and Start DHCP Server Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-dhcp-server/chapter2.md This snippet shows the initial setup and start of the DHCP server, including setting network parameters and creating an IP address list. Ensure the DHCP server object is properly initialized before calling these functions. ```c status = nx_dhcp_create_server_ip_address_list(&dhcp_server, iface_index, START_IP_ADDRESS_LIST, END_IP_ADDRESS_LIST, &addresses_added); status = nx_dhcp_set_interface_network_parameters(&dhcp_server, iface_index, NX_DHCP_SUBNET_MASK, IP_ADDRESS(10,0,0,1), IP_ADDRESS(10,0,0,1)); /* Start the DHCP Server. */ status = nx_dhcp_server_start(&dhcp_server); ``` -------------------------------- ### NetX Duo HTTP Client Server Example Setup Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-http/Chapter2.md This C code sets up the necessary includes, defines constants, and declares variables for the NetX Duo HTTP client and server example. It configures network drivers, packet pools, and IP instances for both client and server sides. ```c #include "tx_api.h" #include "fx_api.h" #include "nx_api.h" #include "nxd_http_client.h" #include "nxd_http_server.h" #define DEMO_STACK_SIZE 2048 /* Set up FileX and file memory resources. */ CHAR *ram_disk_memory; FX_MEDIA ram_disk; unsigned char media_memory[512]; /* Define device drivers. */ extern void _fx_ram_driver(FX_MEDIA *media_ptr); VOID _nx_ram_network_driver(NX_IP_DRIVER *driver_req_ptr); #define USE_DUO /* Use the duo service (not legacy netx) */ #define IPTYPE 6 /* Send packets over IPv6 */ /* Set up the HTTP client. */ TX_THREAD client_thread; NX_PACKET_POOL client_pool; NX_HTTP_CLIENT my_client; NX_IP client_ip; #define CLIENT_PACKET_SIZE (NX_HTTP_SERVER_MIN_PACKET_SIZE * 2) void thread_client_entry(ULONG thread_input); #define HTTP_SERVER_ADDRESS IP_ADDRESS(1,2,3,4) #define HTTP_CLIENT_ADDRESS IP_ADDRESS(1,2,3,5) /* Set up the HTTP server */ NX_HTTP_SERVER my_server; NX_PACKET_POOL server_pool; TX_THREAD server_thread; NX_IP server_ip; #define SERVER_PACKET_SIZE (NX_HTTP_SERVER_MIN_PACKET_SIZE * 2) void thread_server_entry(ULONG thread_input); #ifdef FEATURE_NX_IPV6 NXD_ADDRESS server_ip_address; #endif ``` -------------------------------- ### Start HTTP GET Request Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-http/Chapter3.md Initiates an HTTP GET request. If successful, subsequent calls to nx_http_client_get_packet are needed to retrieve content. This example demonstrates a GET request with authentication and a timeout. ```c /* Start the GET operation on the HTTP Client "my_client." */ status = nx_http_client_get_start(&my_client, IP_ADDRESS(1,2,3,5), "/TEST.HTM", NX_NULL, 0, "myname", "mypassword", 1000); ``` -------------------------------- ### Start Encrypted HTTPS GET Request Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-web-http/chapter3.md Initiates a TLS-secured HTTPS GET request. Use this for standard encrypted GET operations. The application must provide a TLS setup callback for cryptography and credentials. ```C UINT nx_web_http_client_get_secure_start( NX_WEB_HTTP_CLIENT *client_ptr, NXD_ADDRESS ip_address, UINT server_port, CHAR *resource, CHAR *host, CHAR *username, CHAR *password, UINT (*tls_setup)( NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *tls_session), ULONG wait_option); ``` ```C /* Connect to a remote HTTP server. */ server_ip_addr.nxd_ip_version = NX_IP_VERSION_V4; server_ip_addr.nxd_ip_address.v4 = IP_ADDRESS(1,2,3,5); /* Start the GET operation on the HTTP Client "my_client." */ status = nx_web_http_client_get_secure_start(&my_client, &server_ip_addr, NX_WEB_HTTPS_SERVER_PORT, "/TEST.HTM", "host.com", "myname", "mypassword", my_tls_setup_function, 1000); /* If status is NX_SUCCESS, the GET request for TEST.HTM is started and is so far successful. The client must now call *nx_web_http_client_response_body_get* multiple times to retrieve the content associated with TEST.HTM. */ ``` -------------------------------- ### Set up a TLS Server Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-secure-tls/chapter4.md This example demonstrates the complete process of setting up a TLS server, including session creation, certificate initialization, TCP socket configuration, listening for connections, establishing the TLS session, data transfer, and cleanup. Ensure an IP instance named 'ip_0' is already created. ```C NX_TCP_SOCKET tcp_socket; NX_SECURE_TLS_SESSION tls_session; NX_SECURE_X509_CERT certificate; /* Initialize the TLS session structure. */ nx_secure_tls_session_create(&tls_session, &nx_crypto_tls_ciphers, crypto_metadata, sizeof(crypto_metadata)); /* Setup the TLS packet reassembly buffer. */ status = nx_secure_tls_session_packet_buffer_set(&tls_session, tls_packet_buffer, sizeof(tls_packet_buffer)); /* Initialize a certificate for the TLS server. */ status = nx_secure_x509_certificate_initialize(&certificate, certificate_data, 500, NX_NULL, 0, private_key, 64); /* If status is NX_SUCCESS, certificate is initialized. */ /* Add the certificate a local certificate to identify this TLS server. */ status = nx_secure_tls_add_local_certificate(&tls_session, &certificate); /* If status is NX_SUCCESS, certificate was added successfully. */ /* Create and start a TCP socket as a server. */ /* NOTE: This assumes an IP instance called "ip_0" has already been created. */ /* Create a TCP server socket on the previously created IP instance, with normal delivery, IP fragmentation enabled, default time to live, a 8192-byte receive window, no urgent callback routine, and the "client_disconnect" routine to handle disconnection initiated from the other end of the connection. */ status = nx_tcp_socket_create(&ip_0, &tcp_socket, "TLS Server Socket", NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 8192, NX_NULL, NX_NULL); /* If status is NX_SUCCESS, the TCP socket was created successfully. */ /* Start up a TCP server socket by listening on port 443 with a listen queue of size 5. */ status = nx_tcp_server_socket_listen(&ip_0, 443, &tcp_socket, 5, NX_NULL); /* Application main loop. */ while(1) { /* Accept incoming requests on the TCP socket. */ status = nx_tcp_server_socket_accept(&tcp_socket, NX_WAIT_FOREVER); /* At this point, the TCP socket should be established (but not the TLS session yet). */ /* Start the TLS session on our active TCP socket. */ status = nx_secure_tls_session_start(&tls_session, &tcp_socket, NX_WAIT_FOREVER); /* At this point, if status is NX_SUCCESS, the TLS session has been established. Application may now send/receive data through this channel. */ /* Send and receive data using the TLS session. */ /* Allocate TLS packets using nx_secure_tls_packet_allocate, write data with nx_packet_data_append, read data with nx_packet_data_extract_offset. */ /* Send TLS data. */ nx_secure_tls_session_send(&tls_session, &send_packet, NX_WAIT_FOREVER); nx_secure_tls_session_receive(&tls_session, &receive_packet_ptr, NX_WAIT_FOREVER); /* Once all application data is sent/received, end the TLS session. */ status = nx_secure_tls_session_end(&tls_session); /* If status is NX_SUCCESS, the TLS session has been closed properly. */ /* Now disconnect the TCP server socket from the client. */ nx_tcp_socket_disconnect(&tcp_socket, 200); /* Unaccept the TCP server socket. Note that unaccept is called even if disconnect or accept fails. */ nx_tcp_server_socket_unaccept(&tcp_socket); /* Setup server socket for listening with this socket again. */ nx_tcp_server_socket_relisten(&ip_0, 443, &tcp_socket); } /* When the server application is shut down, clean up the TLS session. */ nx_secure_tls_session_delete(&tls_session); /* Finally, clean up the TCP socket as well. */ nx_tcp_socket_delete(&tcp_socket); ``` -------------------------------- ### Start Secure HTTP GET Request Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-web-http/chapter3.md Initiates a secure GET request to a remote HTTP server. Requires TLS setup and provides extended options for connection parameters. The application must subsequently call nx_web_http_client_response_body_get to retrieve content. ```C /* Connect to a remote HTTP server. */ server_ip_addr.nxd_ip_version = NX_IP_VERSION_V4; server_ip_addr.nxd_ip_address.v4 = IP_ADDRESS(1,2,3,5); /* Start the GET operation on the HTTP Client "my_client." */ status = nx_web_http_client_get_secure_start_extended(&my_client, &server_ip_addr, NX_WEB_HTTPS_SERVER_PORT, "/TEST.HTM", sizeof("/TEST.HTM") – 1, "host.com", sizeof("host.com") – 1, "myname", sizeof("myname") – 1, "mypassword", sizeof("mypassword") – 1, my_tls_setup_function, 1000); /* If status is NX_SUCCESS, the GET request for TEST.HTM is started and is so far successful. The client must now call *nx_web_http_client_response_body_get* multiple times to retrieve the content associated with TEST.HTM. */ ``` -------------------------------- ### Start HTTP Client GET Request Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-web-http/chapter3.md Initiates an HTTP GET request to a remote server. Use this for basic GET operations where string lengths are implicitly handled. The function returns NX_SUCCESS if the request is started successfully, after which response body retrieval can begin. ```C /* Connect to a remote HTTP server. */ server_ip_addr.nxd_ip_version = NX_IP_VERSION_V4; server_ip_addr.nxd_ip_address.v4 = IP_ADDRESS(1,2,3,5); /* Start the GET operation on the HTTP Client "my_client." */ status = nx_web_http_client_get_start(&my_client, &server_ip_addr, NX_WEB_HTTP_SERVER_PORT, "/TEST.HTM", "host.com", "myname", "mypassword", 1000); /* If status is NX_SUCCESS, the GET request for TEST.HTM is started and is so far successful. The client must now call *nx_web_http_client_response_body_get* multiple times to retrieve the content associated with TEST.HTM. */ ``` -------------------------------- ### USBX Initialization Example Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/usbx/usbx-host-stack-2.md Example demonstrating the initialization of USBX in host mode, including system initialization, host stack initialization, host class registration, and host controller registration. ```APIDOC ## POST /api/initialize ### Description Initializes the USBX system and registers necessary components for host mode operation. ### Method POST ### Endpoint /api/initialize ### Parameters #### Request Body - **memory_ptr** (pointer) - Required - Pointer to the memory pool for USBX. - **memory_size** (ULONG) - Required - Size of the memory pool. - **host_controller_name** (string) - Required - Name of the host controller to register. - **host_controller_initialize_function** (function pointer) - Required - Initialization function for the host controller. - **host_controller_param1** (ULONG) - Required - Parameter 1 for host controller registration. - **host_controller_param2** (ULONG) - Required - Parameter 2 for host controller registration. - **host_classes** (array of objects) - Optional - List of host classes to register, each with `class_name` and `class_entry_address`. ### Request Example ```json { "memory_ptr": "0x100000", "memory_size": "128*1024", "host_controller_name": "ux_hcd_controller", "host_controller_initialize_function": "ux_hcd_controller_initialize", "host_controller_param1": "0x300000", "host_controller_param2": "0x0a", "host_classes": [ { "class_name": "ux_host_class_hub", "class_entry_address": "ux_host_class_hub_entry" }, { "class_name": "ux_host_class_storage", "class_entry_address": "ux_host_class_storage_entry" } ] } ``` ### Response #### Success Response (200) - **status** (UINT) - Indicates the overall success of the initialization process. UX_SUCCESS if all operations are successful. #### Response Example ```json { "status": "UX_SUCCESS" } ``` ``` -------------------------------- ### ux_host_class_pima_num_objects_get Example Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/usbx/usbx-host-stack-supplemental-2.md Example of how to get the number of objects on all containers matching a specific object format. ```APIDOC ## ux_host_class_pima_num_objects_get ### Description Obtain the number of objects on all containers matching a specified object format code. ### Method `ux_host_class_pima_num_objects_get` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **pima** (pointer) - Pointer to the pima class instance. - **pima_session** (pointer) - Pointer to PIMA session. - **storage_id** (uint32_t) - ID of the storage container. Use `UX_PICTBRIDGE_ALL_CONTAINERS` to specify all containers. - **object_format_code** (uint32_t) - Objects format code filter. See PIMA Object Format Codes section for possible values. ### Request Example ```C /* Get the number of objects on all containers matching a SCRIPT object. */ status = ux_host_class_pima_num_objects_get(pima, pima_session, UX_PICTBRIDGE_ALL_CONTAINERS, UX_PICTBRIDGE_OBJECT_SCRIPT); if (status != UX_SUCCESS) { /* Close the pima session. */ status = ux_host_class_pima_session_close(pima, pima_session); return(UX_PICTBRIDGE_ERROR_STORE_NOT_AVAILABLE); } else /* The number of objects is returned in the field: pima_session -> ux_host_class_pima_session_nb_objects */ ``` ### Response #### Success Response (UX_SUCCESS) - **pima_session->ux_host_class_pima_session_nb_objects** (uint32_t) - The number of objects found matching the criteria. ``` -------------------------------- ### NetX Duo Web HTTP Example System Setup Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-web-http/chapter2.md This C code sets up the necessary ThreadX, NetX Duo, and FileX components for an HTTP demo. It includes definitions for control blocks, packet pools, IP instances, and media, along with HTTP server and client objects. Cryptographic routines and TLS data buffers are also prepared. ```c /* This is a small demo of HTTPS on the high-performance NetX Duo TCP/IP stack. This demo relies on ThreadX, NetX Duo, and FileX to show an HTML transfer from the client and then back from the server. */ #include "tx_api.h" #include "fx_api.h" #include "nx_api.h" #include "nx_crypto.h" #include "nx_secure_tls_api.h" #include "nx_secure_x509.h" #include "nx_web_http_client.h" #include "nx_web_http_server.h" #define DEMO_STACK_SIZE 4096 /* Define the ThreadX and NetX object control blocks... */ TX_THREAD thread_0; TX_THREAD thread_1; NX_PACKET_POOL pool_0; NX_PACKET_POOL pool_1; NX_IP ip_0; NX_IP ip_1; FX_MEDIA ram_disk; /* Define HTTP objects. */ NX_WEB_HTTP_SERVER my_server; NX_WEB_HTTP_CLIENT my_client; /* Define the counters used in the demo application... */ ULONG error_counter; /* Define the RAM disk memory. */ UCHAR ram_disk_memory[32000]; /* Include cryptographic routines for TLS. */ extern const NX_SECURE_TLS_CRYPTO nx_crypto_tls_ciphers; /* Define TLS data for HTTPS. */ CHAR crypto_metadata[8928 * NX_WEB_HTTP_SESSION_MAX]; UCHAR tls_packet_buffer[16500]; /* NX_WEB_HTTP_SERVER_SESSION_MAX defaults to 2 in nx_web_http_server.h */ UCHAR server_tls_packet_buffer[16500 * NX_WEB_HTTP_SERVER_SESSION_MAX]; /* Define certificate containers. The server certificate is used to identify the NetX Web HTTPS server and the trusted certificate is used by the client to verify the server's identity certificate. */ NX_SECURE_X509_CERT server_certificate; NX_SECURE_X509_CERT trusted_certificate; /* Remote certificates need both an NX_SECURE_X509_CERT container and an associated buffer. The number of certificates depends on the remote host, but usually at least two certificates will be sent – the identity certificate for the host and the certificate that issued the identity certificate. */ NX_SECURE_X509_CERT remote_certificate, remote_issuer; UCHAR remote_cert_buffer[2000]; UCHAR remote_issuer_buffer[2000]; /* Certificate information for server and client (see NetX Duo Secure TLS reference on X.509 certificates for more information). Arrays are populated with binary versions Of certificates and keys and the corresponding "len" variables are assigned the lengths of that data. Trusted certificates do not need a private key. */ const UCHAR server_cert_der[] = { … }; const UINT server_cert_derlen = … ; const UCHAR server_cert_key_der[] = { … }; const UINT server_cert_key_derlen = … ; const UCHAR trusted_cert_der[] = { … }; const UINT trusted_cert_derlen = … ; /* Define function prototypes. */ void thread_0_entry(ULONG thread_input); VOID _fx_ram_driver(FX_MEDIA *media_ptr) ; void _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req); UINT authentication_check(NX_WEB_HTTP_SERVER *server_ptr, UINT request_type, CHAR *resource, CHAR **name, CHAR **password, CHAR **realm); UINT tls_setup_callback(NX_WEB_HTTP_CLIENT *client_ptr, NX_SECURE_TLS_SESSION *tls_session); ``` -------------------------------- ### NetX Duo TFTP Example Setup Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-tftp/chapter2.md This C code sets up the necessary ThreadX, NetX Duo, and TFTP components for a demonstration. It includes definitions for IP types, stack sizes, and object control blocks for threads, packet pools, and IP instances. It also defines TFTP client and server control blocks and application global variables. ```C /* This is a small demo of TFTP on the high-performance NetX TCP/IP stack. This demo relies on ThreadX and NetX Duo, to show a simple file transfer from the client and then back to the server. */ /* Indicate if using IPv6. */ #define USE_DUO /* If the host application is using NetX Duo, determine which IP version to use. Make sure IPv6 in NetX Duo is enabled if planning to use TFTP over IPv6 */ #ifdef USE_DUO #define IP_TYPE 6 #endif /* USE_DUO */ #include "tx_api.h" #include "nx_api.h" #include "nxd_tftp_client.h" #include "nxd_tftp_server.h" #ifndef NX_TFTP_NO_FILEX #include "fx_api.h" #endif #define DEMO_STACK_SIZE 4096 /* To use another file storage utility define this symbol: #define NX_TFTP_NO_FILEX */ /* Define the ThreadX, NetX, and FileX object control blocks... */ TX_THREAD server_thread; TX_THREAD client_thread; NX_PACKET_POOL server_pool; NX_IP server_ip; NX_PACKET_POOL client_pool; NX_IP client_ip; FX_MEDIA ram_disk; /* Define the NetX TFTP object control blocks. */ NX_TFTP_CLIENT client; NX_TFTP_SERVER server; /* Define the application global variables */ #define CLIENT_ADDRESS IP_ADDRESS(1, 2, 3, 5) #define SERVER_ADDRESS IP_ADDRESS(1, 2, 3, 4) NXD_ADDRESS server_ip_address; NXD_ADDRESS client_ip_address; UINT error_counter = 0; /* Define buffer used in the demo application. */ UCHAR buffer[255]; ULONG data_length; /* Define the memory area for the FileX RAM disk. */ #ifndef NX_TFTP_NO_FILEX UCHAR ram_disk_memory[32000]; UCHAR ram_disk_sector_cache[512]; #endif /* Define function prototypes. */ VOID _fx_ram_driver(FX_MEDIA *media_ptr); VOID _nx_ram_network_driver(NX_IP_DRIVER *driver_req_ptr); void client_thread_entry(ULONG thread_input); void server_thread_entry(ULONG thread_input); /* Define main entry point. */ int main() { /* Enter the ThreadX kernel. */ tx_kernel_enter(); } /* Define what the initial system looks like. */ void tx_application_define(void *first_unused_memory) { UINT status; UCHAR *pointer; /* Setup the working pointer. */ pointer = (UCHAR *) first_unused_memory; /* Create the main TFTP server thread. */ status = tx_thread_create(&server_thread, "TFTP Server Thread", server_thread_entry, 0, pointer, DEMO_STACK_SIZE, 4,4, TX_NO_TIME_SLICE, TX_AUTO_START); pointer += DEMO_STACK_SIZE ; /* Check for errors. */ if (status) error_counter++; /* Create the main TFTP client thread at a slightly lower priority. */ status = tx_thread_create(&client_thread, "TFTP Client Thread", client_thread_entry, 0, pointer, DEMO_STACK_SIZE, 5, 5, TX_NO_TIME_SLICE, TX_DONT_START); pointer += DEMO_STACK_SIZE ; /* Check for errors. */ if (status) error_counter++; /* Initialize the NetX system. */ nx_system_initialize(); /* Note: The data portion of a packet is exactly 512 bytes, but the packet payload size must be at least 580 bytes. The remaining bytes are used for the UDP, IP, and Ethernet headers and byte alignment requirements. */ ``` -------------------------------- ### Show GUIX Widget and Start System Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/guix/guix-example.md Use `gx_widget_show` to make a widget visible and `gx_system_start` to begin the GUIX event loop. Ensure all widgets are shown before starting the system. ```c gx_widget_show(&demo_root_window); /* let GUIX run! */ gx_system_start(); } ``` -------------------------------- ### Get PIMA Object Number Example Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/usbx/usbx-device-stack-supplemental-2.md Example implementation for retrieving the number of objects. This example forces the object count to 1, typically for XML scripts. ```c UINT ux_pictbridge_dpsclient_object_number_get(UX_SLAVE_CLASS_PIMA *pima, ULONG *number_objects) { /* We force the number of objects to be 1 only here. This will be the XML scripts. */ *number_objects = 1; return(UX_SUCCESS); } ``` -------------------------------- ### FileX Directory Operations Example Source: https://context7.com/eclipse-threadx/rtos-docs/llms.txt Demonstrates creating, setting default, enumerating, and deleting directories on FAT media using FileX APIs. ```c #include "fx_api.h" extern FX_MEDIA my_media; VOID directory_operations_example(void) { UINT status; CHAR entry_name[FX_MAX_LONG_NAME_LEN]; UINT attributes; ULONG size; /* Create a subdirectory */ status = fx_directory_create(&my_media, "subdir"); /* Set default directory */ status = fx_directory_default_set(&my_media, "/subdir"); /* List all entries in current directory */ status = fx_directory_first_entry_find(&my_media, entry_name); while (status == FX_SUCCESS) { /* Get entry information */ fx_directory_information_get(&my_media, entry_name, &attributes, &size, NULL, NULL, NULL, NULL, NULL, NULL); if (attributes & FX_DIRECTORY) { /* Entry is a directory */ } else { /* Entry is a file, size contains file size */ } /* Get next entry */ status = fx_directory_next_entry_find(&my_media, entry_name); } /* Return to root directory */ fx_directory_default_set(&my_media, "/"); /* Delete empty directory */ fx_directory_delete(&my_media, "subdir"); } ``` -------------------------------- ### Pictbridge Host Setup Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/usbx/usbx-host-stack-supplemental-4.md This section covers the initial setup for the Pictbridge host, including registering the Pima class and starting the Pictbridge DPS host. ```APIDOC ## Pictbridge Host Implementation The host implementation of Pictbridge is different from the client. The first thing to do in a Pictbridge host environment is to register the Pima class as the example below shows: ```C status = ux_host_stack_class_register(ux_system_host_class_pima_name, ux_host_class_pima_entry); if(status != UX_SUCCESS) return; ``` This class is the generic PTP layer sitting between the USB host stack and the Pictbridge layer. The next step is to initialize the Pictbridge default values for print services as follows. | Pictbridge field | Value | |------------------------|----------------------------------------| | DpsVersion[0] | 0x00010000 | | DpsVersion[1] | 0x00010001 | | DpsVersion[2] | 0x00000000 | | VendorSpecificVersion | 0x00010000 | | PrintServiceAvailable | 0x30010000 | | Qualities[0] | UX_PICTBRIDGE_QUALITIES_DEFAULT | | Qualities[1] | UX_PICTBRIDGE_QUALITIES_NORMAL | | Qualities[2] | UX_PICTBRIDGE_QUALITIES_DRAFT | | Qualities[3] | UX_PICTBRIDGE_QUALITIES_FINE | | PaperSizes[0] | UX_PICTBRIDGE_PAPER_SIZES_DEFAULT | | PaperSizes[1] | UX_PICTBRIDGE_PAPER_SIZES_4IX6I | | PaperSizes[2] | UX_PICTBRIDGE_PAPER_SIZES_L | | PaperSizes[3] | UX_PICTBRIDGE_PAPER_SIZES_2L | | PaperSizes[4] | UX_PICTBRIDGE_PAPER_SIZES_LETTER | | PaperTypes[0] | UX_PICTBRIDGE_PAPER_TYPES_DEFAULT | | PaperTypes[1] | UX_PICTBRIDGE_PAPER_TYPES_PLAIN | | PaperTypes[2] | UX_PICTBRIDGE_PAPER_TYPES_PHOTO | | FileTypes[0] | UX_PICTBRIDGE_FILE_TYPES_DEFAULT | | FileTypes[1] | UX_PICTBRIDGE_FILE_TYPES_EXIF_JPEG | | FileTypes[2] | UX_PICTBRIDGE_FILE_TYPES_JFIF | | FileTypes[3] | UX_PICTBRIDGE_FILE_TYPES_DPOF | | DatePrints[0] | UX_PICTBRIDGE_DATE_PRINTS_DEFAULT | | DatePrints[1] | UX_PICTBRIDGE_DATE_PRINTS_OFF | | DatePrints[2] | UX_PICTBRIDGE_DATE_PRINTS_ON | | FileNamePrints[0] | UX_PICTBRIDGE_FILE_NAME_PRINTS_DEFAULT | | FileNamePrints[1] | UX_PICTBRIDGE_FILE_NAME_PRINTS_OFF | | FileNamePrints[2] | UX_PICTBRIDGE_FILE_NAME_PRINTS_ON | | ImageOptimizes[0] | UX_PICTBRIDGE_IMAGE_OPTIMIZES_DEFAULT | | ImageOptimizes[1] | UX_PICTBRIDGE_IMAGE_OPTIMIZES_OFF | | ImageOptimizes[2] | UX_PICTBRIDGE_IMAGE_OPTIMIZES_ON | | Layouts[0] | UX_PICTBRIDGE_LAYOUTS_DEFAULT | | Layouts[1] | UX_PICTBRIDGE_LAYOUTS_1_UP_BORDER | | Layouts[2] | UX_PICTBRIDGE_LAYOUTS_INDEX_PRINT | | Layouts[3] | UX_PICTBRIDGE_LAYOUTS_1_UP_BORDERLESS | | FixedSizes[0] | UX_PICTBRIDGE_FIXED_SIZE_DEFAULT | | FixedSizes[1] | UX_PICTBRIDGE_FIXED_SIZE_35IX5I | | FixedSizes[2] | UX_PICTBRIDGE_FIXED_SIZE_4IX6I | | FixedSizes[3] | UX_PICTBRIDGE_FIXED_SIZE_5IX7I | | FixedSizes[4] | UX_PICTBRIDGE_FIXED_SIZE_7CMX10CM | | FixedSizes[5] | UX_PICTBRIDGE_FIXED_SIZE_LETTER | | FixedSizes[6] | UX_PICTBRIDGE_FIXED_SIZE_A4 | | Croppings[0] | UX_PICTBRIDGE_CROPPINGS_DEFAULT | | Croppings[1] | UX_PICTBRIDGE_CROPPINGS_OFF | | Croppings[2] | UX_PICTBRIDGE_CROPPINGS_ON | The state machine of the DPS host will be set to Idle and ready to accept a new print job. The host portion of Pictbridge can now be started as the example below shows. ```C /* Activate the pictbridge dpshost. */ status = ux_pictbridge_dpshost_start(&pictbridge, pima); if (status != UX_SUCCESS) return; ``` ``` -------------------------------- ### RTSP Setup Callback Implementation (Video) Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-rtsp/chapter2.md This callback handles RTSP SETUP requests for video streams. It includes placeholder comments for user implementation to create RTP sender sessions. ```c static UINT rtsp_setup_callback(NX_RTSP_CLIENT *rtsp_client_ptr, UCHAR *uri, UINT uri_length, NX_RTSP_TRANSPORT *transport_ptr) { UINT status; UINT rtp_port, rtcp_port, rtp_ssrc; /* Get the server RTP and RTCP ports. */ /* User implementation here to set value to rtp_port and rtcp_port. */ /* If using NetX Duo RTP service, RTP API (see details from the RTP user guide) is called as follows. */ /* status = nx_rtp_sender_port_get(&rtp_0, &rtp_port, &rtcp_port); if (status) { return(status); } */ if (strstr(uri, DEMO_RTSP_VIDEO_FILE_NAME)) { /* Setup the video session. */ /* User implementation here to use the client transport info to create the video session. */ /* If using NetX Duo RTP service, RTP API (see details from the RTP user guide) is called as follows. */ /* status = nx_rtp_sender_session_create(&rtp_0, &rtp_session_video, DEMO_RTP_PAYLOAD_TYPE_VIDEO, &(transport_ptr -> client_ip_address), transport_ptr -> client_rtp_port, transport_ptr -> client_rtcp_port); if (status) { return(status); } */ /* Obtain generated SSRC. */ /* User implementation here to set value to rtp_ssrc. */ /* If using NetX Duo RTP service, RTP API (see details from the RTP user guide) is called as follows. */ /* status = nx_rtp_sender_session_ssrc_get(&rtp_session_video, &rtp_ssrc); if (status) { return(status); } */ } else if (strstr(uri, DEMO_RTSP_AUDIO_FILE_NAME)) { /* Setup the audio session. */ /* User implementation here to use the client transport info to create the audio session. */ /* If using NetX Duo RTP service, RTP API (see details from the RTP user guide) is called as follows. */ /* status = nx_rtp_sender_session_create(&rtp_0, &rtp_session_audio, DEMO_RTP_PAYLOAD_TYPE_AUDIO, &(transport_ptr -> client_ip_address), transport_ptr -> client_rtp_port, transport_ptr -> client_rtcp_port); if (status) { ``` -------------------------------- ### Start HTTP GET Request (IPv4) Source: https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/netx-duo-http/Chapter3.md Initiates an HTTP GET request over IPv4. For IPv6, use nx_http_client_get_start_extended. This service is deprecated; consider migrating to nx_http_client_get_start_extended. ```c UINT nx_http_client_get_start( NX_HTTP_CLIENT *client_ptr, ULONG ip_address, CHAR *resource, CHAR *input_ptr, UINT input_size, CHAR *username, CHAR *password, ULONG wait_option); ```