FreeRTOS
|
Secure Sockets Interface. More...
#include <stdint.h>
#include <stddef.h>
#include "aws_secure_sockets_config.h"
#include "aws_secure_sockets_config_defaults.h"
#include "aws_lib_init.h"
Go to the source code of this file.
Data Structures | |
struct | SocketsSockaddr |
Socket address. More... | |
Macros | |
#define | Socklen_t uint32_t |
The "size_t" of secure sockets. More... | |
#define | SOCKETS_ERROR_NONE ( 0 ) |
#define | SOCKETS_SOCKET_ERROR ( -1 ) |
#define | SOCKETS_EWOULDBLOCK ( -11 ) |
#define | SOCKETS_ENOMEM ( -12 ) |
#define | SOCKETS_EINVAL ( -22 ) |
#define | SOCKETS_ENOPROTOOPT ( -109 ) |
#define | SOCKETS_ENOTCONN ( -126 ) |
#define | SOCKETS_EISCONN ( -127 ) |
#define | SOCKETS_ECLOSED ( -128 ) |
#define | SOCKETS_TLS_INIT_ERROR ( -1001 ) |
#define | SOCKETS_TLS_HANDSHAKE_ERROR ( -1002 ) |
#define | SOCKETS_TLS_SERVER_UNVERIFIED ( -1003 ) |
#define | SOCKETS_TLS_RECV_ERROR ( -1004 ) |
#define | SOCKETS_TLS_SEND_ERROR ( -1005 ) |
#define | SOCKETS_PERIPHERAL_RESET ( -1006 ) |
#define | SOCKETS_INVALID_SOCKET ( ( Socket_t ) ~0U ) |
Assigned to an Socket_t variable when the socket is not valid. | |
#define | SOCKETS_AF_INET ( 2 ) |
#define | SOCKETS_PF_INET SOCKETS_AF_INET |
#define | SOCKETS_AF_INET6 ( 10 ) |
#define | SOCKETS_SOCK_DGRAM ( 2 ) |
#define | SOCKETS_SOCK_STREAM ( 1 ) |
#define | SOCKETS_IPPROTO_UDP ( 17 ) |
#define | SOCKETS_IPPROTO_TCP ( 6 ) |
#define | SOCKETS_SO_RCVTIMEO ( 0 ) |
#define | SOCKETS_SO_SNDTIMEO ( 1 ) |
#define | SOCKETS_SO_SNDBUF ( 4 ) |
#define | SOCKETS_SO_RCVBUF ( 5 ) |
#define | SOCKETS_SO_SERVER_NAME_INDICATION ( 6 ) |
#define | SOCKETS_SO_TRUSTED_SERVER_CERTIFICATE ( 7 ) |
#define | SOCKETS_SO_REQUIRE_TLS ( 8 ) |
#define | SOCKETS_SO_NONBLOCK ( 9 ) |
#define | SOCKETS_SO_ALPN_PROTOCOLS ( 10 ) |
#define | SOCKETS_SO_WAKEUP_CALLBACK ( 17 ) |
#define | SOCKETS_SHUT_RD ( 0 ) |
#define | SOCKETS_SHUT_WR ( 1 ) |
#define | SOCKETS_SHUT_RDWR ( 2 ) |
#define | securesocketsMAX_DNS_NAME_LENGTH ( 253 ) |
Maximum length of an ASCII DNS name. | |
#define | securesocketsDEFAULT_TLS_DESTINATION_PORT 443 |
Well-known port numbers. | |
#define | socketsAWS_IOT_ALPN_MQTT "x-amzn-mqtt-ca" |
AWS IoT ALPN protocol name for MQTT over TLS on server port 443. | |
#define | SOCKETS_htonl(usIn) ( ( uint32_t ) ( usIn ) ) |
Convert an unsigned thirty-two-bit value from host endianness to network endianness. More... | |
#define | SOCKETS_ntohl(usIn) SOCKETS_htonl( usIn ) |
Convert an unsigned thirty-two-bit value from network endianness to host endianness. More... | |
#define | SOCKETS_htons(usIn) ( ( uint16_t ) ( usIn ) ) |
Convert an unsigned sixteen-bit value from host endianness to network endianness. More... | |
#define | SOCKETS_ntohs(usIn) SOCKETS_htons( usIn ) |
Convert an unsigned sixteen-bit value from network endianness to host endianness. More... | |
#define | SOCKETS_inet_addr_quick(ucOctet0, ucOctet1, ucOctet2, ucOctet3) |
#define | SOCKETS_inet_ntoa(ulIPAddress, pucBuffer) |
Typedefs | |
typedef void * | Socket_t |
The socket type. More... | |
typedef struct SocketsSockaddr | SocketsSockaddr_t |
Socket address. More... | |
Functions | |
lib_initDECLARE_LIB_INIT (SOCKETS_Init) | |
Secure Sockets library initialization function. More... | |
Socket_t | SOCKETS_Socket (int32_t lDomain, int32_t lType, int32_t lProtocol) |
Creates a TCP socket. More... | |
int32_t | SOCKETS_Connect (Socket_t xSocket, SocketsSockaddr_t *pxAddress, Socklen_t xAddressLength) |
Connects the socket to the specified IP address and port. More... | |
int32_t | SOCKETS_Recv (Socket_t xSocket, void *pvBuffer, size_t xBufferLength, uint32_t ulFlags) |
Receive data from a TCP socket. More... | |
int32_t | SOCKETS_Send (Socket_t xSocket, const void *pvBuffer, size_t xDataLength, uint32_t ulFlags) |
Transmit data to the remote socket. More... | |
int32_t | SOCKETS_Shutdown (Socket_t xSocket, uint32_t ulHow) |
Closes all or part of a full-duplex connection on the socket. More... | |
int32_t | SOCKETS_Close (Socket_t xSocket) |
Closes the socket and frees the related resources. More... | |
int32_t | SOCKETS_SetSockOpt (Socket_t xSocket, int32_t lLevel, int32_t lOptionName, const void *pvOptionValue, size_t xOptionLength) |
Manipulates the options for the socket. More... | |
uint32_t | SOCKETS_GetHostByName (const char *pcHostName) |
Resolve a host name using Domain Name Service. More... | |
Secure Sockets Interface.
Secure sockets is a portable layer for establishing a TCP/IP connection, with the option of using TLS.
Secure sockets is based on the Berkeley sockets API. A few difference general differences between Berkeley and SOCKETS are:
Definition in file aws_secure_sockets.h.
#define SOCKETS_htonl | ( | usIn | ) | ( ( uint32_t ) ( usIn ) ) |
Convert an unsigned thirty-two-bit value from host endianness to network endianness.
[in] | usIn | The unsigned thirty-two-bit value to convert. |
Definition at line 437 of file aws_secure_sockets.h.
#define SOCKETS_htons | ( | usIn | ) | ( ( uint16_t ) ( usIn ) ) |
Convert an unsigned sixteen-bit value from host endianness to network endianness.
[in] | usIn | The unsigned sixteen-bit value to convert. |
Definition at line 459 of file aws_secure_sockets.h.
#define SOCKETS_inet_addr_quick | ( | ucOctet0, | |
ucOctet1, | |||
ucOctet2, | |||
ucOctet3 | |||
) |
Definition at line 488 of file aws_secure_sockets.h.
#define SOCKETS_inet_ntoa | ( | ulIPAddress, | |
pucBuffer | |||
) |
Definition at line 494 of file aws_secure_sockets.h.
#define SOCKETS_ntohl | ( | usIn | ) | SOCKETS_htonl( usIn ) |
Convert an unsigned thirty-two-bit value from network endianness to host endianness.
[in] | usIn | The unsigned thirty-two-bit value to convert. |
Definition at line 446 of file aws_secure_sockets.h.
#define SOCKETS_ntohs | ( | usIn | ) | SOCKETS_htons( usIn ) |
Convert an unsigned sixteen-bit value from network endianness to host endianness.
[in] | usIn | The unsigned sixteen-bit value to convert. |
Definition at line 469 of file aws_secure_sockets.h.
#define Socklen_t uint32_t |
The "size_t" of secure sockets.
This type is used for compatibility with the expected Berkeley sockets naming.
Definition at line 70 of file aws_secure_sockets.h.
typedef void* Socket_t |
The socket type.
Data contained by the Socket_t type is port specific.
Definition at line 62 of file aws_secure_sockets.h.
typedef struct SocketsSockaddr SocketsSockaddr_t |
Socket address.
lib_initDECLARE_LIB_INIT | ( | SOCKETS_Init | ) |
Secure Sockets library initialization function.
This function does general initialization and setup. It must be called once and only once before calling any other function.
int32_t SOCKETS_Close | ( | Socket_t | xSocket | ) |
Closes the socket and frees the related resources.
[in] | xSocket | The handle of the socket to close. |
int32_t SOCKETS_Connect | ( | Socket_t | xSocket, |
SocketsSockaddr_t * | pxAddress, | ||
Socklen_t | xAddressLength | ||
) |
Connects the socket to the specified IP address and port.
The socket must first have been successfully created by a call to SOCKETS_Socket().
If this function returns an error the socket is considered invalid.
[in] | xSocket | The handle of the socket to be connected. |
[in] | pxAddress | A pointer to a SocketsSockaddr_t structure that contains the the address to connect the socket to. |
[in] | xAddressLength | Should be set to sizeof( SocketsSockaddr_t ). |
uint32_t SOCKETS_GetHostByName | ( | const char * | pcHostName | ) |
Resolve a host name using Domain Name Service.
[in] | pcHostName | The host name to resolve. |
int32_t SOCKETS_Recv | ( | Socket_t | xSocket, |
void * | pvBuffer, | ||
size_t | xBufferLength, | ||
uint32_t | ulFlags | ||
) |
Receive data from a TCP socket.
The socket must have already been created using a call to SOCKETS_Socket() and connected to a remote socket using SOCKETS_Connect().
[in] | xSocket | The handle of the socket from which data is being received. |
[out] | pvBuffer | The buffer into which the received data will be placed. |
[in] | xBufferLength | The maximum number of bytes which can be received. pvBuffer must be at least xBufferLength bytes long. |
[in] | ulFlags | Not currently used. Should be set to 0. |
int32_t SOCKETS_Send | ( | Socket_t | xSocket, |
const void * | pvBuffer, | ||
size_t | xDataLength, | ||
uint32_t | ulFlags | ||
) |
Transmit data to the remote socket.
The socket must have already been created using a call to SOCKETS_Socket() and connected to a remote socket using SOCKETS_Connect().
[in] | xSocket | The handle of the sending socket. |
[in] | pvBuffer | The buffer containing the data to be sent. |
[in] | xDataLength | The length of the data to be sent. |
[in] | ulFlags | Not currently used. Should be set to 0. |
int32_t SOCKETS_SetSockOpt | ( | Socket_t | xSocket, |
int32_t | lLevel, | ||
int32_t | lOptionName, | ||
const void * | pvOptionValue, | ||
size_t | xOptionLength | ||
) |
Manipulates the options for the socket.
[in] | xSocket | The handle of the socket to set the option for. |
[in] | lLevel | Not currently used. Should be set to 0. |
[in] | lOptionName | See Secure Socket Options. |
[in] | pvOptionValue | A buffer containing the value of the option to set. |
[in] | xOptionLength | The length of the buffer pointed to by pvOptionValue. |
int32_t SOCKETS_Shutdown | ( | Socket_t | xSocket, |
uint32_t | ulHow | ||
) |
Closes all or part of a full-duplex connection on the socket.
[in] | xSocket | The handle of the socket to shutdown. |
[in] | ulHow | SOCKETS_SHUT_RD, SOCKETS_SHUT_WR or SOCKETS_SHUT_RDWR. Secure Sockets Shutdown Flags |
Socket_t SOCKETS_Socket | ( | int32_t | lDomain, |
int32_t | lType, | ||
int32_t | lProtocol | ||
) |
Creates a TCP socket.
This call allocates memory and claims a socket resource.
[in] | lDomain | Must be set to SOCKETS_AF_INET. See Secure Socket Domains. |
[in] | lType | Set to SOCKETS_SOCK_STREAM to create a TCP socket. No other value is valid. See Secure Socket Types. |
[in] | lProtocol | Set to SOCKETS_IPPROTO_TCP to create a TCP socket. No other value is valid. See Secure Socket Protocols. |