Embedded Wireless Framework
ewf_adapter_bsd_sockets.h
Go to the documentation of this file.
1 /************************************************************************/
9 #ifndef __ewf_adapter_bsd_sockets__h__included__
10 #define __ewf_adapter_bsd_sockets__h__included__
11 
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <netdb.h>
16 #include <unistd.h>
17 
18 #include "ewf_adapter.h"
19 #include "ewf_allocator.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /************************************************************************/
33 #ifndef EWF_ADAPTER_BSD_SOCKETS_TCP_ENABLED
34 #define EWF_ADAPTER_BSD_SOCKETS_TCP_ENABLED (1)
35 #endif
36 
37 #ifndef EWF_ADAPTER_BSD_SOCKETS_UDP_ENABLED
38 #define EWF_ADAPTER_BSD_SOCKETS_UDP_ENABLED (1)
39 #endif
40 
41 /************************************************************************/
45 /************************************************************************/
57 extern ewf_adapter_api_control ewf_adapter_bsd_sockets_api_control;
58 
59 ewf_result ewf_adapter_bsd_sockets_start(ewf_adapter* adapter_ptr);
60 ewf_result ewf_adapter_bsd_sockets_stop(ewf_adapter* adapter_ptr);
61 
70 extern ewf_adapter_api_info ewf_adapter_bsd_sockets_api_info;
71 
72 ewf_result ewf_adapter_bsd_sockets_info(ewf_adapter* adapter_ptr);
73 ewf_result ewf_adapter_bsd_sockets_get_ipv4_address(ewf_adapter* adapter_ptr, uint32_t* address_ptr);
74 ewf_result ewf_adapter_bsd_sockets_get_ipv4_netmask(ewf_adapter* adapter_ptr, uint32_t* netmask_ptr);
75 ewf_result ewf_adapter_bsd_sockets_get_ipv4_gateway(ewf_adapter* adapter_ptr, uint32_t* gateway_ptr);
76 ewf_result ewf_adapter_bsd_sockets_get_ipv4_dns(ewf_adapter* adapter_ptr, uint32_t* dns);
77 
86 #if EWF_ADAPTER_BSD_SOCKETS_TCP_ENABLED
87 
88 extern ewf_adapter_api_tcp ewf_adapter_bsd_sockets_api_tcp;
89 
90 ewf_result ewf_adapter_bsd_sockets_tcp_open(ewf_adapter* adapter_ptr, ewf_socket_tcp* socket_ptr);
91 ewf_result ewf_adapter_bsd_sockets_tcp_close(ewf_socket_tcp* socket_ptr);
92 ewf_result ewf_adapter_bsd_sockets_tcp_control(ewf_socket_tcp* socket_ptr, const char* control_str, const uint8_t* buffer_ptr, uint32_t* buffer_length_ptr);
93 ewf_result ewf_adapter_bsd_sockets_tcp_set_tls_configuration(ewf_socket_tcp* socket_ptr, uint32_t tls_configuration_id);
94 ewf_result ewf_adapter_bsd_sockets_tcp_bind(ewf_socket_tcp* socket_ptr, uint32_t port);
95 ewf_result ewf_adapter_bsd_sockets_tcp_listen(ewf_socket_tcp* socket_ptr);
96 ewf_result ewf_adapter_bsd_sockets_tcp_accept(ewf_socket_tcp* socket_ptr, ewf_socket_tcp* socket_new_ptr);
97 ewf_result ewf_adapter_bsd_sockets_tcp_connect(ewf_socket_tcp* socket_ptr, const char* const server, uint32_t port);
98 ewf_result ewf_adapter_bsd_sockets_tcp_shutdown(ewf_socket_tcp* socket_ptr);
99 ewf_result ewf_adapter_bsd_sockets_tcp_send(ewf_socket_tcp* socket_ptr, const uint8_t* buffer_ptr, uint32_t buffer_length);
100 ewf_result ewf_adapter_bsd_sockets_tcp_receive(ewf_socket_tcp* socket_ptr, uint8_t* buffer_ptr, uint32_t* buffer_length, bool wait);
101 
102 #endif /* EWF_ADAPTER_BSD_SOCKETS_TCP_ENABLED */
103 
112 #if EWF_ADAPTER_BSD_SOCKETS_UDP_ENABLED
113 
114 extern ewf_adapter_api_udp ewf_adapter_bsd_sockets_api_udp;
115 
116 ewf_result ewf_adapter_bsd_sockets_udp_open(ewf_adapter* adapter_ptr, ewf_socket_udp* socket_ptr);
117 ewf_result ewf_adapter_bsd_sockets_udp_close(ewf_socket_udp* socket_ptr);
118 ewf_result ewf_adapter_bsd_sockets_udp_control(ewf_socket_udp* socket_ptr, const char* control_str, const uint8_t* buffer_ptr, uint32_t* buffer_length_ptr);
119 ewf_result ewf_adapter_bsd_sockets_udp_set_dtls_configuration(ewf_socket_udp* socket_ptr, uint32_t dtls_configuration_id);
120 ewf_result ewf_adapter_bsd_sockets_udp_bind(ewf_socket_udp* socket_ptr, uint32_t port);
121 ewf_result ewf_adapter_bsd_sockets_udp_shutdown(ewf_socket_udp* socket_ptr);
122 ewf_result ewf_adapter_bsd_sockets_udp_send_to(ewf_socket_udp* socket_ptr, const char* remote_address_str, uint32_t remote_port, const uint8_t* buffer_ptr, uint32_t buffer_length);
123 ewf_result ewf_adapter_bsd_sockets_udp_receive_from(ewf_socket_udp* socket_ptr, char* remote_address, uint32_t* remote_address_length_ptr, uint32_t* remote_port_ptr, char* buffer_ptr, uint32_t* buffer_length_ptr, bool wait);
124 
125 #endif /* EWF_ADAPTER_BSD_SOCKETS_UDP_ENABLED */
126 
129 /******************************************************************************
130  *
131  * Internal data
132  *
133  ******************************************************************************/
134 
143 {
144  volatile int s;
145 
147 
150 {
151  struct in_addr ipv4_address;
152  struct in_addr ipv4_netmask;
153  struct in_addr ipv4_gateway;
154  struct in_addr ipv4_dns;
155 
157 
166 #ifdef EWF_PARAMETER_CHECKING
167 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_HEADER(adapter_ptr) \
168 do { \
169 (adapter_ptr)->struct_magic = EWF_ADAPTER_STRUCT_MAGIC; \
170 (adapter_ptr)->struct_size = EWF_ADAPTER_STRUCT_SIZE; \
171 (adapter_ptr)->struct_version = EWF_ADAPTER_VERSION; \
172 (adapter_ptr)->struct_type = EWF_ADAPTER_TYPE_BSD_SOCKETS; \
173 } while(0)
174 #else
175 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_HEADER(adapter_ptr)
176 #endif /* EWF_PARAMETER_CHECKING */
177 
178 #if EWF_ADAPTER_BSD_SOCKETS_TCP_ENABLED
179 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_TCP_API(adapter_ptr) \
180 do { \
181 adapter_ptr->tcp_api_ptr = &ewf_adapter_bsd_sockets_api_tcp; \
182 } while(0)
183 #else
184 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_TCP_API(adapter_ptr)
185 #endif /* EWF_ADAPTER_BSD_SOCKETS_TCP_ENABLED */
186 
187 #if EWF_ADAPTER_BSD_SOCKETS_UDP_ENABLED
188 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_UDP_API(adapter_ptr) \
189 do { \
190 adapter_ptr->udp_api_ptr = &ewf_adapter_bsd_sockets_api_udp; \
191 } while(0)
192 #else
193 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_UDP_API(adapter_ptr)
194 #endif /* EWF_ADAPTER_BSD_SOCKETS_UDP_ENABLED */
195 
196 #if EWF_ADAPTER_BSD_SOCKETS_TLS_BASIC_ENABLED
197 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_TLS_BASIC_API(adapter_ptr) \
198 do { \
199 adapter_ptr->tls_basic_api_ptr = &ewf_adapter_bsd_sockets_api_tls_basic; \
200 } while(0)
201 #else
202 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_TLS_BASIC_API(adapter_ptr)
203 #endif /* EWF_ADAPTER_BSD_SOCKETS_TLS_BASIC_ENABLED */
204 
205 #if EWF_ADAPTER_BSD_SOCKETS_MQTT_BASIC_ENABLED
206 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_MQTT_BASIC_API(adapter_ptr) \
207 do { \
208 adapter_ptr->mqtt_basic_api_ptr = &ewf_adapter_bsd_sockets_api_mqtt_basic; \
209 } while(0)
210 #else
211 #define EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_MQTT_BASIC_API(adapter_ptr)
212 #endif /* EWF_ADAPTER_BSD_SOCKETS_MQTT_BASIC_ENABLED */
213 
220 #define EWF_ADAPTER_BSD_SOCKETS_STATIC_DECLARE(adapter_ptr, adapter_name_symb, data_allocator_ptr_param) \
221 do { \
222 static ewf_adapter_bsd_sockets ewf_adapter_bsd_sockets__implementation__##adapter_name_symb = {0}; \
223 static ewf_adapter ewf_adapter_bsd_sockets__##adapter_name_symb = {0}; \
224 ewf_adapter_bsd_sockets__##adapter_name_symb.implementation_ptr = &(ewf_adapter_bsd_sockets__implementation__##adapter_name_symb); \
225 adapter_ptr = &(ewf_adapter_bsd_sockets__##adapter_name_symb); \
226 EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_HEADER(adapter_ptr); \
227 ewf_adapter_bsd_sockets__##adapter_name_symb.control_api_ptr = &ewf_adapter_bsd_sockets_api_control; \
228 ewf_adapter_bsd_sockets__##adapter_name_symb.info_api_ptr = &ewf_adapter_bsd_sockets_api_info; \
229 EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_TCP_API(adapter_ptr); \
230 EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_UDP_API(adapter_ptr); \
231 EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_TLS_BASIC_API(adapter_ptr); \
232 EWF_ADAPTER_BSD_SOCKETS_INITIALIZE_MQTT_BASIC_API(adapter_ptr); \
233 } while(0)
234 
237 /************************************************************************/
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 #endif /* __ewf_adapter_bsd_sockets__h__included__ */
The Embedded Wireless Framework adapter API implementation.
struct _ewf_adapter_bsd_sockets ewf_adapter_bsd_sockets
The BSD sockets adapter driver data structure.
struct _ewf_adapter_bsd_sockets_socket ewf_adapter_bsd_sockets_socket
Internal structure for socket status
enum _ewf_result ewf_result
Success and error result codes specific to the EWF API.
The adapter control API type.
Definition: ewf_adapter_api_control.h:28
Definition: ewf_adapter_api_info.h:26
The TCP API structure.
Definition: ewf_adapter_api_tcp.h:76
The UDP API type.
Definition: ewf_adapter_api_udp.h:63
Internal structure for socket status
Definition: ewf_adapter_bsd_sockets.h:143
The BSD sockets adapter driver data structure.
Definition: ewf_adapter_bsd_sockets.h:150
The EWF network adapter control structure definition.
Definition: ewf_adapter.h:50
The TCP socket structure definition.
Definition: ewf_adapter_api_tcp.h:47
The UDP socket structure definition.
Definition: ewf_adapter_api_udp.h:40