Embedded Wireless Framework
ewf_adapter_winsock2.h
Go to the documentation of this file.
1 /************************************************************************/
9 #ifndef __ewf_adapter_winsock2__h__included__
10 #define __ewf_adapter_winsock2__h__included__
11 
12 #include <WinSock2.h>
13 #include <ws2tcpip.h>
14 #include <Windows.h>
15 #include <WindowsX.h>
16 #include <iphlpapi.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_WINSOCK2_TCP_ENABLED
34 #define EWF_ADAPTER_WINSOCK2_TCP_ENABLED (1)
35 #endif
36 
37 #ifndef EWF_ADAPTER_WINSOCK2_UDP_ENABLED
38 #define EWF_ADAPTER_WINSOCK2_UDP_ENABLED (1)
39 #endif
40 
41 /************************************************************************/
45 /************************************************************************/
57 extern ewf_adapter_api_control ewf_adapter_winsock2_api_control;
58 
59 ewf_result ewf_adapter_winsock2_start(ewf_adapter* adapter_ptr);
60 ewf_result ewf_adapter_winsock2_stop(ewf_adapter* adapter_ptr);
61 
70 extern ewf_adapter_api_info ewf_adapter_winsock2_api_info;
71 
72 ewf_result ewf_adapter_winsock2_info(ewf_adapter* adapter_ptr);
73 ewf_result ewf_adapter_winsock2_get_ipv4_address(ewf_adapter* adapter_ptr, uint32_t* address_ptr);
74 ewf_result ewf_adapter_winsock2_get_ipv4_netmask(ewf_adapter* adapter_ptr, uint32_t* netmask_ptr);
75 ewf_result ewf_adapter_winsock2_get_ipv4_gateway(ewf_adapter* adapter_ptr, uint32_t* gateway_ptr);
76 ewf_result ewf_adapter_winsock2_get_ipv4_dns(ewf_adapter* adapter_ptr, uint32_t* dns);
77 
86 #if EWF_ADAPTER_WINSOCK2_TCP_ENABLED
87 
88 extern ewf_adapter_api_tcp ewf_adapter_winsock2_api_tcp;
89 
90 ewf_result ewf_adapter_winsock2_tcp_open(ewf_adapter* adapter_ptr, ewf_socket_tcp* socket_ptr);
91 ewf_result ewf_adapter_winsock2_tcp_close(ewf_socket_tcp* socket_ptr);
92 ewf_result ewf_adapter_winsock2_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_winsock2_tcp_set_tls_configuration(ewf_socket_tcp* socket_ptr, uint32_t tls_configuration_id);
94 ewf_result ewf_adapter_winsock2_tcp_bind(ewf_socket_tcp* socket_ptr, uint32_t port);
95 ewf_result ewf_adapter_winsock2_tcp_listen(ewf_socket_tcp* socket_ptr);
96 ewf_result ewf_adapter_winsock2_tcp_accept(ewf_socket_tcp* socket_ptr, ewf_socket_tcp* socket_new_ptr);
97 ewf_result ewf_adapter_winsock2_tcp_connect(ewf_socket_tcp* socket_ptr, const char* const server, uint32_t port);
98 ewf_result ewf_adapter_winsock2_tcp_shutdown(ewf_socket_tcp* socket_ptr);
99 ewf_result ewf_adapter_winsock2_tcp_send(ewf_socket_tcp* socket_ptr, const uint8_t* buffer_ptr, uint32_t buffer_length);
100 ewf_result ewf_adapter_winsock2_tcp_receive(ewf_socket_tcp* socket_ptr, uint8_t* buffer_ptr, uint32_t* buffer_length, bool wait);
101 
102 #endif /* EWF_ADAPTER_WINSOCK2_TCP_ENABLED */
103 
112 #if EWF_ADAPTER_WINSOCK2_UDP_ENABLED
113 
114 extern ewf_adapter_api_udp ewf_adapter_winsock2_api_udp;
115 
116 ewf_result ewf_adapter_winsock2_udp_open(ewf_adapter* adapter_ptr, ewf_socket_udp* socket_ptr);
117 ewf_result ewf_adapter_winsock2_udp_close(ewf_socket_udp* socket_ptr);
118 ewf_result ewf_adapter_winsock2_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_winsock2_udp_set_dtls_configuration(ewf_socket_udp* socket_ptr, uint32_t dtls_configuration_id);
120 ewf_result ewf_adapter_winsock2_udp_bind(ewf_socket_udp* socket_ptr, uint32_t port);
121 ewf_result ewf_adapter_winsock2_udp_shutdown(ewf_socket_udp* socket_ptr);
122 ewf_result ewf_adapter_winsock2_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_winsock2_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_WINSOCK2_UDP_ENABLED */
126 
129 /******************************************************************************
130  *
131  * Internal data
132  *
133  ******************************************************************************/
134 
143 {
144  volatile SOCKET s;
145 
147 
149 typedef struct _ewf_adapter_winsock2
150 {
151  WSADATA wsaData;
152  IN_ADDR ipv4_address;
153  IN_ADDR ipv4_netmask;
154  IN_ADDR ipv4_gateway;
155  IN_ADDR ipv4_dns;
156 
158 
167 #ifdef EWF_PARAMETER_CHECKING
168 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_HEADER(adapter_ptr) \
169 do { \
170 (adapter_ptr)->struct_magic = EWF_ADAPTER_STRUCT_MAGIC; \
171 (adapter_ptr)->struct_size = EWF_ADAPTER_STRUCT_SIZE; \
172 (adapter_ptr)->struct_version = EWF_ADAPTER_VERSION; \
173 (adapter_ptr)->struct_type = EWF_ADAPTER_TYPE_WINSOCK2; \
174 } while(0)
175 #else
176 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_HEADER(adapter_ptr)
177 #endif /* EWF_PARAMETER_CHECKING */
178 
179 #if EWF_ADAPTER_WINSOCK2_TCP_ENABLED
180 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_TCP_API(adapter_ptr) \
181 do { \
182 adapter_ptr->tcp_api_ptr = &ewf_adapter_winsock2_api_tcp; \
183 } while(0)
184 #else
185 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_TCP_API(adapter_ptr)
186 #endif /* EWF_ADAPTER_WINSOCK2_TCP_ENABLED */
187 
188 #if EWF_ADAPTER_WINSOCK2_UDP_ENABLED
189 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_UDP_API(adapter_ptr) \
190 do { \
191 adapter_ptr->udp_api_ptr = &ewf_adapter_winsock2_api_udp; \
192 } while(0)
193 #else
194 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_UDP_API(adapter_ptr)
195 #endif /* EWF_ADAPTER_WINSOCK2_UDP_ENABLED */
196 
197 #if EWF_ADAPTER_WINSOCK2_TLS_BASIC_ENABLED
198 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_TLS_BASIC_API(adapter_ptr) \
199 do { \
200 adapter_ptr->tls_basic_api_ptr = &ewf_adapter_winsock2_api_tls_basic; \
201 } while(0)
202 #else
203 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_TLS_BASIC_API(adapter_ptr)
204 #endif /* EWF_ADAPTER_WINSOCK2_TLS_BASIC_ENABLED */
205 
206 #if EWF_ADAPTER_WINSOCK2_MQTT_BASIC_ENABLED
207 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_MQTT_BASIC_API(adapter_ptr) \
208 do { \
209 adapter_ptr->mqtt_basic_api_ptr = &ewf_adapter_winsock2_api_mqtt_basic; \
210 } while(0)
211 #else
212 #define EWF_ADAPTER_WINSOCK2_INITIALIZE_MQTT_BASIC_API(adapter_ptr)
213 #endif /* EWF_ADAPTER_WINSOCK2_MQTT_BASIC_ENABLED */
214 
221 #define EWF_ADAPTER_WINSOCK2_STATIC_DECLARE(adapter_ptr, adapter_name_symb, data_allocator_ptr_param) \
222 do { \
223 static ewf_adapter_winsock2 ewf_adapter_winsock2__implementation__##adapter_name_symb = {0}; \
224 static ewf_adapter ewf_adapter_winsock2__##adapter_name_symb = {0}; \
225 ewf_adapter_winsock2__##adapter_name_symb.implementation_ptr = &(ewf_adapter_winsock2__implementation__##adapter_name_symb); \
226 adapter_ptr = &(ewf_adapter_winsock2__##adapter_name_symb); \
227 EWF_ADAPTER_WINSOCK2_INITIALIZE_HEADER(adapter_ptr); \
228 ewf_adapter_winsock2__##adapter_name_symb.control_api_ptr = &ewf_adapter_winsock2_api_control; \
229 ewf_adapter_winsock2__##adapter_name_symb.info_api_ptr = &ewf_adapter_winsock2_api_info; \
230 EWF_ADAPTER_WINSOCK2_INITIALIZE_TCP_API(adapter_ptr); \
231 EWF_ADAPTER_WINSOCK2_INITIALIZE_UDP_API(adapter_ptr); \
232 EWF_ADAPTER_WINSOCK2_INITIALIZE_TLS_BASIC_API(adapter_ptr); \
233 EWF_ADAPTER_WINSOCK2_INITIALIZE_MQTT_BASIC_API(adapter_ptr); \
234 } while(0)
235 
238 /************************************************************************/
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 #endif /* __ewf_adapter_winsock2__h__included__ */
The Embedded Wireless Framework adapter API implementation.
struct _ewf_adapter_winsock2 ewf_adapter_winsock2
The WinSock2 adapter driver data structure.
struct _ewf_adapter_winsock2_socket ewf_adapter_winsock2_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_winsock2.h:143
The WinSock2 adapter driver data structure.
Definition: ewf_adapter_winsock2.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