Embedded Wireless Framework
Data Structures | Macros | Typedefs | Functions
Adapter TCP API

TCP functions to listen, connect, send, receive and close sockets. More...

Data Structures

struct  _ewf_socket_tcp
 The TCP socket structure definition. More...
 
struct  _ewf_adapter_api_tcp
 The TCP API structure. More...
 

Macros

#define EWF_VALIDATE_TCP_SOCKET_POINTER(socket_ptr)
 
#define EWF_ADAPTER_TCP_SOCKET_CONTROL_SET_CONTEXT_ID   ("!SetContextId")
 
#define EWF_ADAPTER_TCP_SOCKET_CONTROL_SET_CONNECTION_TIMEOUT   ("!SetConnectionTimeout")
 
#define EWF_ADAPTER_TCP_SOCKET_CONTROL_IS_CONNECTED   ("!IsConnected")
 
#define EWF_ADAPTER_TCP_SOCKET_CONTROL_IS_BOUND   ("!IsBound")
 
#define EWF_ADAPTER_TCP_SOCKET_CONTROL_USES_TLS   ("!UsesTLS")
 
#define EWF_ADAPTER_TCP_SOCKET_CONTROL_PEER_ADDRESSS   ("!PeerAddress")
 
#define EWF_ADAPTER_TCP_SOCKET_CONTROL_LOCAL_ADDRESSS   ("!LocalAddress")
 
#define EWF_ADAPTER_TCP_SOCKET_CONTROL_SENT_BYTES   ("!SentBytes")
 
#define EWF_ADAPTER_TCP_SOCKET_CONTROL_RECEIVED_BYTES   ("!ReceivedBytes")
 

Typedefs

typedef struct _ewf_socket_tcp ewf_socket_tcp
 The TCP socket type.
 
typedef ewf_result(* ewf_adapter_tcp_receive_callback) (ewf_socket_tcp *socket_ptr, const uint8_t *buffer_ptr, uint32_t buffer_length)
 A function pointer type for TCP receive callbacks. More...
 
typedef ewf_result(* ewf_adapter_tcp_disconnect_callback) (ewf_socket_tcp *socket_ptr)
 A function pointer type for TCP disconnect callbacks. More...
 
typedef struct _ewf_adapter_api_tcp ewf_adapter_api_tcp
 The TCP API structure.
 

Functions

ewf_result ewf_adapter_tcp_open (ewf_adapter *adapter_ptr, ewf_socket_tcp *socket_ptr)
 Open a TCP socket. More...
 
ewf_result ewf_adapter_tcp_close (ewf_socket_tcp *socket_ptr)
 Close a TCP socket. More...
 
ewf_result ewf_adapter_tcp_control (ewf_socket_tcp *socket_ptr, const char *control_str, const uint8_t *buffer_ptr, uint32_t *buffer_length_ptr)
 Control a TCP socket This is mainly used to funnel implementation specific functionality. More...
 
ewf_result ewf_adapter_tcp_set_tls_configuration (ewf_socket_tcp *socket_ptr, uint32_t tls_configuration_id)
 Set the TLS context for the socket. More...
 
ewf_result ewf_adapter_tcp_bind (ewf_socket_tcp *socket_ptr, uint32_t port)
 Binds a TCP socket to a port. More...
 
ewf_result ewf_adapter_tcp_listen (ewf_socket_tcp *socket_ptr)
 Listens to incomming connections on a socket. More...
 
ewf_result ewf_adapter_tcp_accept (ewf_socket_tcp *socket_ptr, ewf_socket_tcp *socket_new_ptr)
 Accept a new connection on a listening TCP socket. More...
 
ewf_result ewf_adapter_tcp_connect (ewf_socket_tcp *socket_ptr, const char *server_str, uint32_t port)
 Connect a TCP socket to a server. More...
 
ewf_result ewf_adapter_tcp_shutdown (ewf_socket_tcp *socket_ptr)
 Shutdown a TCP socket. More...
 
ewf_result ewf_adapter_tcp_send (ewf_socket_tcp *socket_ptr, const uint8_t *buffer_ptr, uint32_t buffer_length)
 Send data over a TCP socket. More...
 
ewf_result ewf_adapter_tcp_receive (ewf_socket_tcp *socket_ptr, uint8_t *buffer_ptr, uint32_t *buffer_length, bool wait)
 Receive data over a TCP socket. More...
 
ewf_result ewf_adapter_tcp_receive_callback_set (ewf_socket_tcp *socket_ptr, ewf_adapter_tcp_receive_callback callback)
 Register a user TCP receive callback function. More...
 
ewf_result ewf_adapter_tcp_disconnect_callback_set (ewf_socket_tcp *socket_ptr, ewf_adapter_tcp_disconnect_callback callback)
 Register a user TCP disconnect callback function. More...
 

Detailed Description

TCP functions to listen, connect, send, receive and close sockets.

Macro Definition Documentation

◆ EWF_VALIDATE_TCP_SOCKET_POINTER

#define EWF_VALIDATE_TCP_SOCKET_POINTER (   socket_ptr)
Value:
do { \
if ((socket_ptr == NULL) || \
(socket_ptr->adapter_ptr == NULL)) \
{ \
EWF_LOG_ERROR("The TCP socket pointer is invalid.\n"); \
} \
} while(0)
@ EWF_RESULT_INVALID_FUNCTION_ARGUMENT
Definition: ewf.h:69

Typedef Documentation

◆ ewf_adapter_tcp_disconnect_callback

typedef ewf_result(* ewf_adapter_tcp_disconnect_callback) (ewf_socket_tcp *socket_ptr)

A function pointer type for TCP disconnect callbacks.

Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_receive_callback

typedef ewf_result(* ewf_adapter_tcp_receive_callback) (ewf_socket_tcp *socket_ptr, const uint8_t *buffer_ptr, uint32_t buffer_length)

A function pointer type for TCP receive callbacks.

Parameters
[in]buffer_ptrA pointer to a buffer with the received data
[in]buffer_lengthThe length of the data pointed by buffer_ptr
Returns
ewf_result success and error conditions

Function Documentation

◆ ewf_adapter_tcp_accept()

ewf_result ewf_adapter_tcp_accept ( ewf_socket_tcp socket_ptr,
ewf_socket_tcp socket_new_ptr 
)

Accept a new connection on a listening TCP socket.

Parameters
[in]socket_ptrA pointer to a TCP socket
[in,out]socketa pointer to a variable that will hold the new TCP socket from the accepted connection
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_bind()

ewf_result ewf_adapter_tcp_bind ( ewf_socket_tcp socket_ptr,
uint32_t  port 
)

Binds a TCP socket to a port.

Parameters
[in]socket_ptrA pointer to a TCP socket
[in]portthe port number to bind to
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_close()

ewf_result ewf_adapter_tcp_close ( ewf_socket_tcp socket_ptr)

Close a TCP socket.

Parameters
[in]socket_ptrA pointer to a TCP socket
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_connect()

ewf_result ewf_adapter_tcp_connect ( ewf_socket_tcp socket_ptr,
const char *  server_str,
uint32_t  port 
)

Connect a TCP socket to a server.

Parameters
[in]socket_ptrA pointer to a TCP socket
[in]serverthe address or name of the server to connect to
[in]portthe port number to connect to
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_control()

ewf_result ewf_adapter_tcp_control ( ewf_socket_tcp socket_ptr,
const char *  control_str,
const uint8_t *  buffer_ptr,
uint32_t *  buffer_length_ptr 
)

Control a TCP socket This is mainly used to funnel implementation specific functionality.

Parameters
[in]socket_ptra pointer to a TCP socket
[in]control_stra pointer to NULL terminated string with the control command to issue
[in]buffer_ptra pointer to a buffer with additional data for the command
[in]buffer_length_ptrthe length of the buffer pointer by buffer_ptr on call, the size used on return
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_disconnect_callback_set()

ewf_result ewf_adapter_tcp_disconnect_callback_set ( ewf_socket_tcp socket_ptr,
ewf_adapter_tcp_disconnect_callback  callback 
)

Register a user TCP disconnect callback function.

Parameters
[in]socket_ptrA pointer to a TCP socket
[in]callbackthe function pointer to the user callback
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_listen()

ewf_result ewf_adapter_tcp_listen ( ewf_socket_tcp socket_ptr)

Listens to incomming connections on a socket.

Parameters
[in]socket_ptrA pointer to a TCP socket
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_open()

ewf_result ewf_adapter_tcp_open ( ewf_adapter adapter_ptr,
ewf_socket_tcp socket_ptr 
)

Open a TCP socket.

Parameters
[in]adapter_ptrA pointer to the adapter
[in,out]socket_ptrA pointer to a TCP socket
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_receive()

ewf_result ewf_adapter_tcp_receive ( ewf_socket_tcp socket_ptr,
uint8_t *  buffer_ptr,
uint32_t *  buffer_length,
bool  wait 
)

Receive data over a TCP socket.

Parameters
[in]socket_ptrA pointer to a TCP socket
[in,out]buffera pointer to the buffer that is going to receive the data
[in,out]buffer_lengtha pointer to an unsigned holds the size of the buffer on entry and the buffer_length and on return
[in]waita boolean indicating if the function should wait until data is available, true wait, false return immediately
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_receive_callback_set()

ewf_result ewf_adapter_tcp_receive_callback_set ( ewf_socket_tcp socket_ptr,
ewf_adapter_tcp_receive_callback  callback 
)

Register a user TCP receive callback function.

Parameters
[in]socket_ptrA pointer to a TCP socket
[in]callbackthe function pointer to the user callback
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_send()

ewf_result ewf_adapter_tcp_send ( ewf_socket_tcp socket_ptr,
const uint8_t *  buffer_ptr,
uint32_t  buffer_length 
)

Send data over a TCP socket.

Parameters
[in]socket_ptrA pointer to a TCP socket
[in]buffera pointer to the data to be sent
[in]buffer_lengththe number of bytes to be sent
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_set_tls_configuration()

ewf_result ewf_adapter_tcp_set_tls_configuration ( ewf_socket_tcp socket_ptr,
uint32_t  tls_configuration_id 
)

Set the TLS context for the socket.

Parameters
[in]socket_ptrA pointer to a TCP socket
Returns
ewf_result success and error conditions

◆ ewf_adapter_tcp_shutdown()

ewf_result ewf_adapter_tcp_shutdown ( ewf_socket_tcp socket_ptr)

Shutdown a TCP socket.

Parameters
[in]socket_ptrA pointer to a TCP socket
Returns
ewf_result success and error conditions