Table of Contents

Example Summary

The TCP Echo Wi-Fi Ethernet showcases how TCP traffic can be routed between network interfaces. This is done by opening up a TCP server on both the Wi-Fi and Ethernet interfaces, when data comes to either interface it is routed to all clients connected to the other interface. Essentially TCP data is echo across to the alternate network interface.

Hardware Prerequisites

Project Zero code example requires the standard configuration of an MSP-EXP432E401Y LaunchPad with an attached CC3120BOOST BoosterPack or a CC3135BOOST BoosterPack. This hardware configuration with the MSP432E4 and the CC3120 is shown in the below image. The CC3135 is configured in a similar manner.

MSP432E401Y LaunchPad with CC3120 BoosterPack

You must also have a switch with an available Ethernet port. For this example we will connect the device via Ethernet and Wi-Fi to the same network. So the switch and access point must be on the same network.

Software Prerequisites

This example has been validated against the latest software versions listed in the Release Notes.

For more information on how to import this project into your IDE workspace and build/run, please refer to the Quick Start Guide.

Provisioning Method

Before compiling the example, you need to update the network_if.h file for wireless access point parameters. Look at the example below of a WPA2 secured network with SSID name F4153-2.4 and password msp432iot.

/* AP SSID                                                                    */
#define SSID_NAME               "F4153-2.4"
/* Security type (OPEN or WEP or WPA)                                         */
#define SECURITY_TYPE           SL_WLAN_SEC_TYPE_WPA_WPA2
/* Password of the secured AP                                                 */
#define SECURITY_KEY            "msp432iot"
#define SSID_LEN_MAX            32
#define BSSID_LEN_MAX           6

Please refer to the provisioning example and documentation for different ways to get your access point information onto your device.

Usage

Once the example code starts the output to the terminal will notify the user of the IP addresses for the Wi-Fi and Ethernet interfaces. These will be two separate IP addresses because each interface is running independently hosting a TCP server. You will also see several messages from the Ethernet and Wi-Fi stacks as they start up and connect to the network.

TCP Echo Initialization

Now that the device has started up you can begin to connect clients to each interface. Each interface allows for 3 simultaneous client connections. So you can have 3 clients connected to the TCP server running on the Ethernet interface and 3 connected to the TCP server running on the Wi-Fi interface.

To connect to the interface you can use a telnet application (PuTTY and Tera Term support this, along with others) to connect to the interface. The example runs the TCP server on port 1000, which can be configured in ethernet_wifi_tcp_echo.h.

Below is a screenshot of some settings in PuTTY to connect to a TCP server. You can see one of the interface IP addresses is used with port 1000.

TCP Server Connection

Once you have at least one client connected to the Ethernet and Wi-Fi interfaces, begin to type in one of the terminals. You should see what you type echoed back on all the clients connected by the other interface.

Software Design

The TCP echo example application works by starting a TCP server on both the Ethernet and Wi-Fi interfaces and listening on port 1000. There is no port clash in this example because the interfaces are totally separate. The Wi-Fi interface uses the SimpleLink socket APIs to create the TCP server while the Ethernet interface uses the traditional BSD socket APIs. Each interface has it’s own thread that is listening for connections on the TCP port.

Once a client connects to either interface, a new thread is created a “Reader” thread is created to continuously read from the socket until it’s closed. Each client effectively is running in it’s own thread and blocks when trying to read from the socket if there is no data. After reading a packet from the socket, the data is placed in a queue using the POSIX mqueue APIs.

Upon startup, writer threads are also created in the background for each interface. The Ethernet writer thread blocks on reading data from the Wi-Fi message queue, and vice versa. Once data comes into the queue, the writer thread writes the data to all connected clients on that interface. This effectively creates a data passthrough between the interfaces. The way it is implemented, data is broadcasted to all connected clients on the opposite interface.

This example could be extended to inspect the traffic between the interfaces to filter or modify the TCP data. This could be easily done by changing the data before putting it in the queue.