Embedded Wireless Framework
ewf_adapter_api_tcp.h
Go to the documentation of this file.
1 /************************************************************************/
9 #ifndef __ewf_adapter_tcp__h__included__
10 #define __ewf_adapter_tcp__h__included__
11 
12 #include "ewf.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /************************************************************************/
26 struct _ewf_socket_tcp;
27 
29 typedef struct _ewf_socket_tcp ewf_socket_tcp;
30 
37 typedef ewf_result(*ewf_adapter_tcp_receive_callback)(ewf_socket_tcp* socket_ptr, const uint8_t* buffer_ptr, uint32_t buffer_length);
38 
44 
47 {
48  void* data_ptr;
49  ewf_adapter* adapter_ptr;
50  ewf_adapter_tcp_receive_callback receive_callback;
51  ewf_adapter_tcp_disconnect_callback disconnect_callback;
52 };
53 
54 #define EWF_VALIDATE_TCP_SOCKET_POINTER(socket_ptr) \
55 do { \
56  if ((socket_ptr == NULL) || \
57  (socket_ptr->adapter_ptr == NULL)) \
58  { \
59  EWF_LOG_ERROR("The TCP socket pointer is invalid.\n"); \
60  return EWF_RESULT_INVALID_FUNCTION_ARGUMENT; \
61  } \
62 } while(0)
63 
64 #define EWF_ADAPTER_TCP_SOCKET_CONTROL_SET_CONTEXT_ID ("!SetContextId")
65 #define EWF_ADAPTER_TCP_SOCKET_CONTROL_SET_CONNECTION_TIMEOUT ("!SetConnectionTimeout")
66 #define EWF_ADAPTER_TCP_SOCKET_CONTROL_IS_CONNECTED ("!IsConnected")
67 #define EWF_ADAPTER_TCP_SOCKET_CONTROL_IS_BOUND ("!IsBound")
68 #define EWF_ADAPTER_TCP_SOCKET_CONTROL_USES_TLS ("!UsesTLS")
69 #define EWF_ADAPTER_TCP_SOCKET_CONTROL_PEER_ADDRESSS ("!PeerAddress")
70 #define EWF_ADAPTER_TCP_SOCKET_CONTROL_LOCAL_ADDRESSS ("!LocalAddress")
71 #define EWF_ADAPTER_TCP_SOCKET_CONTROL_SENT_BYTES ("!SentBytes")
72 #define EWF_ADAPTER_TCP_SOCKET_CONTROL_RECEIVED_BYTES ("!ReceivedBytes")
73 
75 typedef struct _ewf_adapter_api_tcp
76 {
77  ewf_result(*open)(ewf_adapter* adapter_ptr, ewf_socket_tcp* socket_ptr);
78  ewf_result(*close)(ewf_socket_tcp* socket_ptr);
79 
80  ewf_result(*control)(ewf_socket_tcp* socket_ptr, const char* control_str, const uint8_t* buffer_ptr, uint32_t* buffer_length_ptr);
81 
82  ewf_result(*set_tls_configuration)(ewf_socket_tcp* socket_ptr, uint32_t tls_configuration_id);
83 
84  ewf_result(*bind)(ewf_socket_tcp* socket_ptr, uint32_t port);
85  ewf_result(*listen)(ewf_socket_tcp* socket_ptr);
86  ewf_result(*accept)(ewf_socket_tcp* socket_ptr, ewf_socket_tcp* socket_new_ptr);
87  ewf_result(*connect)(ewf_socket_tcp* socket_ptr, const char* server_str, uint32_t port);
88  ewf_result(*shutdown)(ewf_socket_tcp* socket_ptr);
89  ewf_result(*send)(ewf_socket_tcp* socket_ptr, const uint8_t* buffer_ptr, uint32_t buffer_length);
90  ewf_result(*receive)(ewf_socket_tcp* socket_ptr, uint8_t* buffer_ptr, uint32_t* buffer_length, bool wait);
91 
93 
100 ewf_result ewf_adapter_tcp_open(ewf_adapter* adapter_ptr, ewf_socket_tcp* socket_ptr);
101 
108 
118 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);
119 
125 ewf_result ewf_adapter_tcp_set_tls_configuration(ewf_socket_tcp* socket_ptr, uint32_t tls_configuration_id);
126 
133 ewf_result ewf_adapter_tcp_bind(ewf_socket_tcp* socket_ptr, uint32_t port);
134 
141 
149 ewf_result ewf_adapter_tcp_accept(ewf_socket_tcp* socket_ptr, ewf_socket_tcp* socket_new_ptr);
150 
158 ewf_result ewf_adapter_tcp_connect(ewf_socket_tcp* socket_ptr, const char* server_str, uint32_t port);
159 
166 
174 ewf_result ewf_adapter_tcp_send(ewf_socket_tcp* socket_ptr, const uint8_t* buffer_ptr, uint32_t buffer_length);
175 
184 ewf_result ewf_adapter_tcp_receive(ewf_socket_tcp* socket_ptr, uint8_t* buffer_ptr, uint32_t * buffer_length, bool wait);
185 
193 
201 
202 /************************************************************************/
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 #endif /* __ewf_adapter_tcp__h__included__ */
The Embedded Wireless Framework.
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.
Definition: ewf_adapter_api_tcp.c:46
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.
Definition: ewf_adapter_api_tcp.c:100
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.
Definition: ewf_adapter_api_tcp.c:82
struct _ewf_adapter_api_tcp ewf_adapter_api_tcp
The TCP API structure.
ewf_result ewf_adapter_tcp_listen(ewf_socket_tcp *socket_ptr)
Listens to incomming connections on a socket.
Definition: ewf_adapter_api_tcp.c:64
ewf_result ewf_adapter_tcp_shutdown(ewf_socket_tcp *socket_ptr)
Shutdown a TCP socket.
Definition: ewf_adapter_api_tcp.c:91
ewf_result(* ewf_adapter_tcp_disconnect_callback)(ewf_socket_tcp *socket_ptr)
A function pointer type for TCP disconnect callbacks.
Definition: ewf_adapter_api_tcp.h:43
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.
Definition: ewf_adapter_api_tcp.c:118
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.
Definition: ewf_adapter_api_tcp.c:109
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.
Definition: ewf_adapter_api_tcp.c:37
ewf_result ewf_adapter_tcp_bind(ewf_socket_tcp *socket_ptr, uint32_t port)
Binds a TCP socket to a port.
Definition: ewf_adapter_api_tcp.c:55
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.
Definition: ewf_adapter_api_tcp.c:73
ewf_result ewf_adapter_tcp_close(ewf_socket_tcp *socket_ptr)
Close a TCP socket.
Definition: ewf_adapter_api_tcp.c:28
ewf_result ewf_adapter_tcp_open(ewf_adapter *adapter_ptr, ewf_socket_tcp *socket_ptr)
Open a TCP socket.
Definition: ewf_adapter_api_tcp.c:21
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.
Definition: ewf_adapter_api_tcp.h:37
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.
Definition: ewf_adapter_api_tcp.c:125
enum _ewf_result ewf_result
Success and error result codes specific to the EWF API.
The TCP API structure.
Definition: ewf_adapter_api_tcp.h:76
The EWF network adapter control structure definition.
Definition: ewf_adapter.h:50
The TCP socket structure definition.
Definition: ewf_adapter_api_tcp.h:47