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
- Packet Types Supported
- Configurable IP MTU
Configuration
Build Time Configurations for rm_netxduo_wifi
The following build time configurations are defined in fsp_cfg/middleware/rm_netxduo_wifi_cfg.h:
Configuration | Options | Default | Description |
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.
- rm_wifi_onchip_silex_open() should be called to initialize the WiFi module driver.
- rm_wifi_onchip_silex_scan() should be used to scan for access points.
- rm_wifi_onchip_silex_connect() should be used before opening a NetX IP instance in order to connect it to a network.
- rm_wifi_onchip_silex_network_info_get() should be used after an access point connection has been established to get DHCP acquired IP address, subnet mask, and gateway.
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:
- IPv6 functionality
- TCP/UDP server mode
- ARP is handled directly by the WiFi module
- DHCP is always enabled on module by the rm_wifi_onchip_silex driver, thus the software DHCP stack is unsupported.
- The source port will not be used when binding a TCP or UDP socket. Applications should set the source port to
NX_ANY_PORT
.
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:
- DNS: The user can preform a DNS lookup by calling rm_wifi_onchip_silex_dns_query.
- ICMP: The user can perform a ping by calling rm_wifi_onchip_silex_ping.
- SNTP: The WiFi module has multiple public APIs for time related functions:
- RM_WIFI_ONCHIP_SILEX_EpochTimeGet
- RM_WIFI_ONCHIP_SILEX_LocalTimeGet
- RM_WIFI_ONCHIP_SILEX_SntpEnableSet
- RM_WIFI_ONCHIP_SILEX_SntpServerIpAddressSet
- RM_WIFI_ONCHIP_SILEX_SntpTimeZoneSet
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);
void rm_netxduo_wifi_example ()
{
UINT status;
nx_system_initialize();
err = rm_wifi_onchip_silex_open(&g_wifi_onchip_silex_cfg);
assert(FSP_SUCCESS == err);
err = rm_wifi_onchip_silex_connect(NETXDUO_EXAMPLE_SSID,
eWiFiSecurityWPA2, NETXDUO_EXAMPLE_PASSWORD);
assert(FSP_SUCCESS == err);
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);
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);
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;
extern USHORT g_trusted_ca_length;
void rm_netxduo_wifi_tls_example ()
{
UINT status;
NX_TCP_SOCKET * p_socket;
NX_SECURE_TLS_SESSION tls_session;
nx_system_initialize();
status = nx_crypto_initialize();
assert(NX_SUCCESS == status);
err = rm_wifi_onchip_silex_open(&g_wifi_onchip_silex_cfg);
assert(FSP_SUCCESS == err);
err = rm_wifi_onchip_silex_connect(NETXDUO_EXAMPLE_SSID,
eWiFiSecurityWPA2, NETXDUO_EXAMPLE_PASSWORD);
assert(FSP_SUCCESS == err);
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);
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);
status = nx_tcp_enable(&g_ip0);
assert(NX_SUCCESS == status);
nx_secure_tls_initialize();
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);
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);
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);
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);
status = nx_secure_tls_trusted_certificate_add(&tls_session, &g_certificate);
assert(NX_SUCCESS == status);
status = nx_tcp_client_socket_bind(p_socket, NETXDUO_EXAMPLE_PORT, NX_WAIT_FOREVER);
assert(NX_SUCCESS == status);
status = nx_tcp_client_socket_connect(p_socket, NETXDUO_EXAMPLE_IP, NETXDUO_EXAMPLE_SERVER_PORT, NX_WAIT_FOREVER);
assert(NX_SUCCESS == status);
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;
NXD_ADDRESS g_ip_address = NETXDUO_TESTS_SERVER_IP;
nx_udp_socket_create(&g_ip, &udp_client_socket, "Socket 0", NX_IP_NORMAL, NX_FRAGMENT_OKAY, 0, 5);
nx_udp_socket_bind(&udp_client_socket, NETXDUO_TESTS_UDP_TX_PORT, TX_WAIT_FOREVER);
NX_PACKET * p_nx_packet = NX_NULL;
nx_packet_allocate(&g_packet_pool0, &p_nx_packet, NX_UDP_PACKET, NETXDUO_TESTS_SOCKET_TIMEOUT)
nx_packet_data_append(&p_nx_packet, "Hello World", 12, &g_packet_pool0, NX_WAIT_FOREVER);
nx_udp_socket_send(&udp_client_socket, &p_nx_packet, &g_ip_address, NETXDUO_TESTS_UDP_TX_PORT);
NX_PACKET * p_nx_packet_recv;
nx_udp_socket_receive(&udp_client_socket, &p_nx_packet_recv, NETXDUO_TESTS_SOCKET_TIMEOUT);
nx_udp_socket_unbind(&udp_client_socket);
nx_udp_socket_delete(&udp_client_socket);
}