Embedded Wireless Framework
ewf_adapter_api_udp.h
Go to the documentation of this file.
1 /************************************************************************/
9 #ifndef __ewf_adapter_udp__h__included__
10 #define __ewf_adapter_udp__h__included__
11 
12 #include "ewf.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /************************************************************************/
26 struct _ewf_socket_udp;
27 
29 typedef struct _ewf_socket_udp ewf_socket_udp;
30 
36 typedef ewf_result(*ewf_adapter_udp_receive_callback)(ewf_socket_udp* socket_ptr, const char* server, uint32_t port, const char* buffer, uint32_t length);
37 
40 {
41  void* data_ptr;
42  ewf_adapter* adapter_ptr;
43  ewf_adapter_udp_receive_callback receive_callback;
44 };
45 
46 #define EWF_VALIDATE_UDP_SOCKET_POINTER(socket_ptr) \
47 do { \
48  if ((socket_ptr == NULL) || \
49  (socket_ptr->adapter_ptr == NULL)) \
50  { \
51  EWF_LOG_ERROR("The UDP socket pointer is invalid.\n"); \
52  return EWF_RESULT_INVALID_FUNCTION_ARGUMENT; \
53  } \
54 } while(0)
55 
56 #define EWF_ADAPTER_UDP_SOCKET_QUERY_IS_BOUND ("?IsBound")
57 #define EWF_ADAPTER_UDP_SOCKET_QUERY_USES_TLS ("?UsesTLS")
58 #define EWF_ADAPTER_UDP_SOCKET_QUERY_SENT_BYTES ("?SentBytes")
59 #define EWF_ADAPTER_UDP_SOCKET_QUERY_RECEIVED_BYTES ("?ReceivedBytes")
60 
62 typedef struct _ewf_adapter_api_udp
63 {
64  ewf_result(*open)(ewf_adapter* adapter_ptr, ewf_socket_udp* socket_ptr);
65  ewf_result(*close)(ewf_socket_udp* socket_ptr);
66 
67  ewf_result(*control)(ewf_socket_udp* socket_ptr, const char* control_str, const uint8_t* buffer_ptr, uint32_t* buffer_length_ptr);
68 
69  ewf_result(*set_dtls_configuration)(ewf_socket_udp* socket_ptr, uint32_t dtls_configuration_id);
70 
71  ewf_result(*bind)(ewf_socket_udp* socket_ptr, uint32_t local_port);
72  ewf_result(*shutdown)(ewf_socket_udp* socket_ptr);
73  ewf_result(*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);
74  ewf_result(*receive_from)(ewf_socket_udp* socket_ptr, char* remote_address, uint32_t* remote_address_length_ptr, uint32_t* remote_port_ptr, uint8_t* buffer_ptr, uint32_t* buffer_length_ptr, bool wait);
75 
77 
85 
92 
102 ewf_result ewf_adapter_udp_control(ewf_socket_udp* socket_ptr, const char* control_str, uint8_t* buffer_ptr, uint32_t* buffer_length_ptr);
103 
109 ewf_result ewf_adapter_udp_set_dtls_configuration(ewf_socket_udp* socket_ptr, uint32_t dtls_configuration_id);
110 
117 ewf_result ewf_adapter_udp_bind(ewf_socket_udp* socket_ptr, uint32_t local_port);
118 
125 
135 ewf_result ewf_adapter_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);
136 
148 ewf_result ewf_adapter_udp_receive_from(ewf_socket_udp* socket_ptr, char* remote_address, uint32_t* remote_address_length_ptr, uint32_t* remote_port_ptr, uint8_t* buffer_ptr, uint32_t* buffer_length_ptr, bool wait);
149 
157 
158 /************************************************************************/
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif /* __ewf_adapter_udp__h__included__ */
The Embedded Wireless Framework.
ewf_result(* ewf_adapter_udp_receive_callback)(ewf_socket_udp *socket_ptr, const char *server, uint32_t port, const char *buffer, uint32_t length)
A function pointer type for TCP receive callbacks.
Definition: ewf_adapter_api_udp.h:36
struct _ewf_adapter_api_udp ewf_adapter_api_udp
The UDP API type.
ewf_result ewf_adapter_udp_set_dtls_configuration(ewf_socket_udp *socket_ptr, uint32_t dtls_configuration_id)
Set the DTLS configuration for the socket.
Definition: ewf_adapter_api_udp.c:46
ewf_result ewf_adapter_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)
Send data over a UDP socket.
Definition: ewf_adapter_api_udp.c:64
ewf_result ewf_adapter_udp_receive_from(ewf_socket_udp *socket_ptr, char *remote_address, uint32_t *remote_address_length_ptr, uint32_t *remote_port_ptr, uint8_t *buffer_ptr, uint32_t *buffer_length_ptr, bool wait)
Receive data over a UDP socket.
Definition: ewf_adapter_api_udp.c:73
ewf_result ewf_adapter_udp_close(ewf_socket_udp *socket_ptr)
Close a UDP socket.
Definition: ewf_adapter_api_udp.c:28
ewf_result ewf_adapter_udp_shutdown(ewf_socket_udp *socket_ptr)
Shutdown a UDP socket.
ewf_result ewf_adapter_udp_control(ewf_socket_udp *socket_ptr, const char *control_str, uint8_t *buffer_ptr, uint32_t *buffer_length_ptr)
Control an UDP socket This is mainly used to funnel implementation specific functionality.
Definition: ewf_adapter_api_udp.c:37
ewf_result ewf_adapter_udp_open(ewf_adapter *adapter_ptr, ewf_socket_udp *socket_ptr)
Open a UDP socket.
Definition: ewf_adapter_api_udp.c:21
ewf_result ewf_adapter_udp_bind(ewf_socket_udp *socket_ptr, uint32_t local_port)
Binds an UDP socket to a local port.
Definition: ewf_adapter_api_udp.c:55
ewf_result ewf_adapter_udp_receive_callback_set(ewf_socket_udp *socket_ptr, ewf_adapter_udp_receive_callback callback)
Register a user UDP receive callback function.
Definition: ewf_adapter_api_udp.c:82
enum _ewf_result ewf_result
Success and error result codes specific to the EWF API.
The UDP API type.
Definition: ewf_adapter_api_udp.h:63
The EWF network adapter control structure definition.
Definition: ewf_adapter.h:50
The UDP socket structure definition.
Definition: ewf_adapter_api_udp.h:40