Socket Working Flow
89
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
Socket
6.5.3.1
Layer 4: Transport
RAW sockets in layer 4 let the host application send and receive packets, which include the IP header.
Opening a RAW socket with TCP/UDP protocol means that all packets are forwarded directly to the RAW
socket, and if any other TCP/UDP socket is open, it does not receive any of these packets. RAW sockets
can work with any desired protocol, which should be specified when opening the socket.
By default all received packets include the IP header. If the IP header of the packet is not needed, it can
be removed by calling the API sl_SetSockOpt with the option SL_IP_RAW_RX_NO_HEADER.
Example:
#define
MY_PROTOCOL
90
_i16 Sd, Protocol = MY_PROTOCOL;
Sd = sl_Socket(SL_AF_INET
/* SL_AF_INET6 */
, SL_SOCK_RAW, Protocol);
if
( 0 > Sd )
{
// error
}
6.5.3.2
Layer 3: Network
RAW sockets in layer 3 let the host application send and receive packets, which include the network
header. When opening a RAW socket with UDP/TCP protocol, TCP/UDP packets are forwarded directly to
the RAW socket, and any other UDP/TCP sockets are useless. Calling sl_SetSockOpt with the option
SL_IP_HDRINCL must contain an IP header. IPv4 checksum is calculated and set by the SimpleLink
device. The received packet includes the IP header. This socket type is not supported for IPv6.
#define
MY_PROTOCOL
90
_i16 Sd, protocol = MY_PROTOCOL , Status;
_u32 IncludeIpHeader = 1;
Sd = sl_Socket(SL_AF_INET, SL_SOCK_RAW, protocol);
if
( 0 > Sd )
{
// error
}
Status = sl_SetSockOpt(Sd, SL_IPPROTO_IP, SL_IP_HDRINCL, & IncludeIpHeader,
sizeof
(IncludeIpHeader));
if
( Status )
{
// error
}
6.5.3.3
Layer 2: Data Link (Transceiver Mode, Not Connected)
The SimpleLink transceiver mode lets the host transmit Wi-Fi frames in disconnected mode only. The
SimpleLink network stack can be bypassed by using the layer 2 RAW socket. Layer 2 lets hosts
implement their own network stack and applications. For more information, see
i16 Sd;
Sd = sl_Socket(SL_AF_RF, SL_SOCK_DGRAM, Channel);
if
( 0 > Sd )
{
// error
}
The SimpleLink transceiver mode lets the host transmit Wi-Fi frames in disconnected mode only. For more
detailed information, see