RA Flexible Software Package Documentation  Release v5.2.0

 
NetX Duo WiFi Driver (rm_netxduo_wifi)

Overview

This module provides a NetX Duo driver that is implemented using the rm_wifi_onchip_silex driver.

Please refer to the NetXDuo documentation for further details.

Features

Configuration

Build Time Configurations for rm_netxduo_wifi

The following build time configurations are defined in fsp_cfg/middleware/rm_netxduo_wifi_cfg.h:

ConfigurationOptionsDefaultDescription
IP MTU (bytes)Value must be in the range [576, 1500] bytes.1500 IP MTU

Usage Notes

Connecting to a Wireless Network

NetX Duo does not support connecting to a wireless network directly and instead the driver functions should be called directly to establish a connection.

Unsupported NetX Duo Features

These features are currently not supported due to lack of support in the rm_wifi_onchip_silex driver or in the WiFi module hardware/firmware:

On Module Alternatives

Instead of using NetX Duo Software Addons the following features can be performed directly on the WiFi module by calling the appropriate function instead if desired:

Examples

Basic Example

This is a basic example of minimal use of the NetX Duo WiFi Driver in an application.

#define NETXDUO_EXAMPLE_IP_STACK_SIZE (2048U)
#define NETXDUO_EXAMPLE_ARP_CACHE_SIZE (2048U)
#define NETXDUO_EXAMPLE_PACKET_SIZE (1568U)
#define NETXDUO_EXAMPLE_PACKET_NUM (100U)
#define NETXDUO_EXAMPLE_PACKET_POOL_SIZE ((sizeof(NX_PACKET) + NETXDUO_EXAMPLE_PACKET_SIZE) * \
NETXDUO_EXAMPLE_PACKET_NUM)
#define NETXDUO_EXAMPLE_SSID "ssidName"
#define NETXDUO_EXAMPLE_PASSWORD "password"
static NX_IP g_ip0;
static NX_PACKET_POOL g_packet_pool0;
static uint8_t g_ip0_stack_memory[NETXDUO_EXAMPLE_IP_STACK_SIZE] BSP_ALIGN_VARIABLE(4);
static uint8_t g_packet_pool0_pool_memory[NETXDUO_EXAMPLE_PACKET_POOL_SIZE] BSP_ALIGN_VARIABLE(4);
extern wifi_onchip_silex_cfg_t g_wifi_onchip_silex_cfg;
void rm_netxduo_wifi_example ()
{
UINT status;
fsp_err_t err;
nx_system_initialize();
/* Open WiFi module */
err = rm_wifi_onchip_silex_open(&g_wifi_onchip_silex_cfg);
assert(FSP_SUCCESS == err);
/* Connect to desired AP */
err = rm_wifi_onchip_silex_connect(NETXDUO_EXAMPLE_SSID, eWiFiSecurityWPA2, NETXDUO_EXAMPLE_PASSWORD);
assert(FSP_SUCCESS == err);
/* Create a packet pool for the IP instance. */
status = nx_packet_pool_create(&g_packet_pool0,
"Packet Pool",
NETXDUO_EXAMPLE_PACKET_SIZE,
&g_packet_pool0_pool_memory[0],
NETXDUO_EXAMPLE_PACKET_POOL_SIZE);
assert(NX_SUCCESS == status);
/* Create an IP instance using the rm_netxduo_wifi driver and packet pool instance. */
status = nx_ip_create(&g_ip0,
"IP Instance",
IP_ADDRESS(192, 168, 1, 2),
IP_ADDRESS(255, 255, 255, 0),
&g_packet_pool0,
rm_netxduo_wifi,
&g_ip0_stack_memory[0],
sizeof(g_ip0_stack_memory),
0);
assert(NX_SUCCESS == status);
/* Enable all modules that are required by the application. */
status = nx_tcp_enable(&g_ip0);
assert(NX_SUCCESS == status);
status = nx_udp_enable(&g_ip0);
assert(NX_SUCCESS == status);
}

TLS Example

This is a basic example of connecting a TLS socket.

#define NETXDUO_EXAMPLE_CRYPTO_METADATA_BUFFER_SIZE (18000U)
#define NETXDUO_EXAMPLE_TLS_PACKET_REASSEMBLY_BUFFER_SIZE (4000U)
#define NETXDUO_EXAMPLE_PORT (3005U)
#define NETXDUO_EXAMPLE_SERVER_PORT (9050U)
#define NETXDUO_EXAMPLE_IP IP_ADDRESS(1, 2, 3, 5)
NX_SECURE_TLS_CRYPTO g_nx_crypto_tls_test_ciphers;
static UCHAR g_tls_crypto_metadata[NETXDUO_EXAMPLE_CRYPTO_METADATA_BUFFER_SIZE];
static UCHAR g_tls_packet_buffer[NETXDUO_EXAMPLE_TLS_PACKET_REASSEMBLY_BUFFER_SIZE];
static NX_SECURE_X509_CERT g_certificate;
extern const UCHAR g_trusted_ca_data; // User trusted certificates
extern USHORT g_trusted_ca_length;
void rm_netxduo_wifi_tls_example ()
{
UINT status;
fsp_err_t err;
NX_TCP_SOCKET * p_socket;
NX_SECURE_TLS_SESSION tls_session;
nx_system_initialize();
/* Initialize NetX Crypto */
status = nx_crypto_initialize();
assert(NX_SUCCESS == status);
/* Open WiFi module */
err = rm_wifi_onchip_silex_open(&g_wifi_onchip_silex_cfg);
assert(FSP_SUCCESS == err);
/* Connect to desired AP */
err = rm_wifi_onchip_silex_connect(NETXDUO_EXAMPLE_SSID, eWiFiSecurityWPA2, NETXDUO_EXAMPLE_PASSWORD);
assert(FSP_SUCCESS == err);
/* Create a packet pool for the IP instance. */
status = nx_packet_pool_create(&g_packet_pool0,
"Packet Pool",
NETXDUO_EXAMPLE_PACKET_SIZE,
&g_packet_pool0_pool_memory[0],
NETXDUO_EXAMPLE_PACKET_POOL_SIZE);
assert(NX_SUCCESS == status);
/* Create an IP instance using the rm_netxduo_wifi driver and packet pool instance. */
status = nx_ip_create(&g_ip0,
"IP Instance",
IP_ADDRESS(192, 168, 1, 2),
IP_ADDRESS(255, 255, 255, 0),
&g_packet_pool0,
rm_netxduo_wifi,
&g_ip0_stack_memory[0],
sizeof(g_ip0_stack_memory),
0);
assert(NX_SUCCESS == status);
/* Enable all modules that are required by the application. */
status = nx_tcp_enable(&g_ip0);
assert(NX_SUCCESS == status);
/* Initialize the NetX Secure TLS system. */
nx_secure_tls_initialize();
/* Create a TCP socket to use for the TLS session. */
status = nx_tcp_socket_create(&g_ip0,
p_socket,
"TLS Client Socket",
NX_IP_NORMAL,
NX_FRAGMENT_OKAY,
NX_IP_TIME_TO_LIVE,
1024 * 4,
NX_NULL,
NX_NULL);
assert(NX_SUCCESS == status);
/* Create a TLS session for our socket. This sets up the TLS session object for
* later use */
status =
nx_secure_tls_session_create(&tls_session,
&g_nx_crypto_tls_test_ciphers,
g_tls_crypto_metadata,
NETXDUO_EXAMPLE_CRYPTO_METADATA_BUFFER_SIZE);
assert(NX_SUCCESS == status);
/* Set the packet reassembly buffer for this TLS session. */
status = nx_secure_tls_session_packet_buffer_set(&tls_session,
g_tls_packet_buffer,
NETXDUO_EXAMPLE_TLS_PACKET_REASSEMBLY_BUFFER_SIZE);
assert(NX_SUCCESS == status);
/* Initialize an X.509 certificate with the CA root certificate data. */
status = nx_secure_x509_certificate_initialize(&g_certificate,
(UCHAR *) g_trusted_ca_data,
g_trusted_ca_length,
NX_NULL,
0,
NX_NULL,
0,
NX_SECURE_X509_KEY_TYPE_NONE);
assert(NX_SUCCESS == status);
/* Add the initialized certificate as a trusted root certificate. */
status = nx_secure_tls_trusted_certificate_add(&tls_session, &g_certificate);
assert(NX_SUCCESS == status);
/* Bind the socket to a port. */
status = nx_tcp_client_socket_bind(p_socket, NETXDUO_EXAMPLE_PORT, NX_WAIT_FOREVER);
assert(NX_SUCCESS == status);
/* Connect TCP socket */
status = nx_tcp_client_socket_connect(p_socket, NETXDUO_EXAMPLE_IP, NETXDUO_EXAMPLE_SERVER_PORT, NX_WAIT_FOREVER);
assert(NX_SUCCESS == status);
/* Start the TLS Session using the connected TCP socket. This function will
* ascertain from the TCP socket state that this is a TLS Client session. */
status = nx_secure_tls_session_start(&tls_session, p_socket, NX_WAIT_FOREVER);
assert(NX_SUCCESS == status);
}

UDP Example

This is a basic example of connecting a UDP socket.

#define NETXDUO_TESTS_SOCKET_TIMEOUT (3000)
#define NETXDUO_TESTS_UDP_TX_PORT (5000)
#define NETXDUO_TESTS_SERVER_IP (0xC0A80064)
void rm_netxduo_wifi_udp_example (void)
{
NX_UDP_SOCKET udp_client_socket;
/* IP Address of the remote socket. */
NXD_ADDRESS g_ip_address = NETXDUO_TESTS_SERVER_IP;
/* Create the socket. */
nx_udp_socket_create(&g_ip, &udp_client_socket, "Socket 0", NX_IP_NORMAL, NX_FRAGMENT_OKAY, 0, 5);
/* Bind to the UDP port. */
nx_udp_socket_bind(&udp_client_socket, NETXDUO_TESTS_UDP_TX_PORT, TX_WAIT_FOREVER);
NX_PACKET * p_nx_packet = NX_NULL;
/* Allocate a packet for message data */
nx_packet_allocate(&g_packet_pool0, &p_nx_packet, NX_UDP_PACKET, NETXDUO_TESTS_SOCKET_TIMEOUT)
/* Append message data to packet */
nx_packet_data_append(&p_nx_packet, "Hello World", 12, &g_packet_pool0, NX_WAIT_FOREVER);
/* Send UDP message to server */
nx_udp_socket_send(&udp_client_socket, &p_nx_packet, &g_ip_address, NETXDUO_TESTS_UDP_TX_PORT);
NX_PACKET * p_nx_packet_recv;
/* Receive any response from UDP server */
nx_udp_socket_receive(&udp_client_socket, &p_nx_packet_recv, NETXDUO_TESTS_SOCKET_TIMEOUT);
/* Unbind and delete the udp socket. */
nx_udp_socket_unbind(&udp_client_socket);
nx_udp_socket_delete(&udp_client_socket);
}