Embedded Wireless Framework
ewf_adapter_quectel_common.h
Go to the documentation of this file.
1 /************************************************************************/
9 #ifndef __ewf_adapter_quectel_common__h__included__
10 #define __ewf_adapter_quectel_common__h__included__
11 
12 #include "ewf_adapter.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /************************************************************************/
25 #ifndef EWF_ADAPTER_QUECTEL_COMMON_DEFAULT_TIMEOUT
26 #define EWF_ADAPTER_QUECTEL_COMMON_DEFAULT_TIMEOUT (EWF_PLATFORM_TICKS_PER_SECOND * 10)
27 #endif
28 
29 #ifndef EWF_ADAPTER_QUECTEL_COMMON_UFS_ENABLED
30 #define EWF_ADAPTER_QUECTEL_COMMON_UFS_ENABLED (1)
31 #endif
32 
33 #if !defined(EWF_ADAPTER_QUECTEL_COMMON_TLS_ENABLED) && !defined(EWF_ADAPTER_QUECTEL_COMMON_TLS_BASIC_ENABLED)
34 #if 1
35 #define EWF_ADAPTER_QUECTEL_COMMON_TLS_BASIC_ENABLED (1)
36 #define EWF_ADAPTER_QUECTEL_COMMON_TLS_ENABLED (0)
37 #else
38 #define EWF_ADAPTER_QUECTEL_COMMON_TLS_BASIC_ENABLED (0)
39 #define EWF_ADAPTER_QUECTEL_COMMON_TLS_ENABLED (1)
40 #endif
41 #endif
42 
43 #ifndef EWF_ADAPTER_QUECTEL_COMMON_TCP_ENABLED
44 #define EWF_ADAPTER_QUECTEL_COMMON_TCP_ENABLED (1)
45 #endif
46 
47 #ifndef EWF_ADAPTER_QUECTEL_COMMON_UDP_ENABLED
48 #define EWF_ADAPTER_QUECTEL_COMMON_UDP_ENABLED (1)
49 #endif
50 
51 #if !defined(EWF_ADAPTER_QUECTEL_COMMON_MQTT_ENABLED) && !defined(EWF_ADAPTER_QUECTEL_COMMON_MQTT_BASIC_ENABLED)
52 #if 1
53 #define EWF_ADAPTER_QUECTEL_COMMON_MQTT_BASIC_ENABLED (1)
54 #define EWF_ADAPTER_QUECTEL_COMMON_MQTT_ENABLED (0)
55 #else
56 #define EWF_ADAPTER_QUECTEL_COMMON_MQTT_BASIC_ENABLED (0)
57 #define EWF_ADAPTER_QUECTEL_COMMON_MQTT_ENABLED (1)
58 #endif
59 #endif
60 
61 #ifndef EWF_ADAPTER_QUECTEL_COMMON_INTERNET_SOCKET_POOL_SIZE
63 #define EWF_ADAPTER_QUECTEL_COMMON_INTERNET_SOCKET_POOL_SIZE (12)
64 #endif
65 
66 #ifndef EWF_ADAPTER_QUECTEL_COMMON_INTERNET_SOCKET_INVALID
68 #define EWF_ADAPTER_QUECTEL_COMMON_INTERNET_SOCKET_INVALID (-1)
69 #endif
70 
71 #ifndef EWF_ADAPTER_QUECTEL_COMMON_MQTT_SOCKET_POOL_SIZE
73 #define EWF_ADAPTER_QUECTEL_COMMON_MQTT_SOCKET_POOL_SIZE (12)
74 #endif
75 
76 #ifndef EWF_ADAPTER_QUECTEL_COMMON_MQTT_SOCKET_INVALID
78 #define EWF_ADAPTER_QUECTEL_COMMON_MQTT_SOCKET_INVALID (-1)
79 #endif
80 
82 #ifndef EWF_CONFIG_ADAPTER_QUECTEL_COMMON_ROOT_CA_CERTIFICATE_FILE_NAME
83 #define EWF_CONFIG_ADAPTER_QUECTEL_COMMON_ROOT_CA_CERTIFICATE_FILE_NAME ("root_ca_cert.pem")
84 #endif
85 
87 #ifndef EWF_CONFIG_ADAPTER_QUECTEL_COMMON_USER_CA_CERTIFICATE_FILE_NAME
88 #define EWF_CONFIG_ADAPTER_QUECTEL_COMMON_USER_CA_CERTIFICATE_FILE_NAME ("ca_cert.pem")
89 #endif
90 
98 #ifndef EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CA_CERTIFICATE_FILE_NAME
99 #define EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CA_CERTIFICATE_FILE_NAME ("root_ca_cert.pem")
100 #endif
101 
103 #ifndef EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CLIENT_CERTIFICATE_FILE_NAME
104 #define EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CLIENT_CERTIFICATE_FILE_NAME ("device_cert.pem")
105 #endif
106 
108 #ifndef EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CLIENT_PRIVATE_KEY_FILE_NAME
109 #define EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CLIENT_PRIVATE_KEY_FILE_NAME ("device_key.pem")
110 #endif
111 
113 #ifndef EWF_CONFIG_ADAPTER_QUECTEL_COMMON_ROOT_CA_CERTIFICATE_BUFFER_NAME
114 #define EWF_CONFIG_ADAPTER_QUECTEL_COMMON_ROOT_CA_CERTIFICATE_BUFFER_NAME (root_ca_cert_pem)
115 #endif
116 
118 #ifndef EWF_CONFIG_ADAPTER_QUECTEL_COMMON_USER_CA_CERTIFICATE_BUFFER_NAME
119 #define EWF_CONFIG_ADAPTER_QUECTEL_COMMON_USER_CA_CERTIFICATE_BUFFER_NAME (ca_cert_pem)
120 #endif
121 
123 #ifndef EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CLIENT_CERTIFICATE_BUFFER_NAME
124 #define EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CLIENT_CERTIFICATE_BUFFER_NAME (device_cert_pem)
125 #endif
126 
128 #ifndef EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CLIENT_PRIVATE_KEY_BUFFER_NAME
129 #define EWF_CONFIG_ADAPTER_QUECTEL_COMMON_CLIENT_PRIVATE_KEY_BUFFER_NAME (device_key_pem)
130 #endif
131 
132 /************************************************************************/
136 /************************************************************************/
143 /************************************************************************/
151 {
152  ewf_adapter_quectel_common_internet_socket_service_type_not_initialized,
153  ewf_adapter_quectel_common_internet_socket_service_type_tcp,
154  ewf_adapter_quectel_common_internet_socket_service_type_udp,
155  ewf_adapter_quectel_common_internet_socket_service_type_tcp_listener,
156  ewf_adapter_quectel_common_internet_socket_service_type_udp_listener,
157 
159 
162 {
163  void* socket_ptr;
164  uint32_t id;
165  uint16_t local_port;
167  volatile bool used : 1;
168  volatile bool open : 1;
169  volatile bool open_error : 1;
170  volatile bool conn : 1;
171  volatile bool conn_error : 1;
172 
174 
177 {
178  volatile bool open : 1;
179  volatile bool open_error : 1;
180  volatile bool conn : 1;
181  volatile bool conn_error : 1;
182 
184 
187 {
188  uint32_t default_timeout;
189 
190 #if EWF_ADAPTER_QUECTEL_COMMON_TCP_ENABLED || EWF_ADAPTER_QUECTEL_COMMON_UDP_ENABLED
193 #endif
194 
195 #if EWF_ADAPTER_QUECTEL_COMMON_MQTT_BASIC_ENABLED
197  volatile bool mqtt_basic_open;
198  volatile bool mqtt_basic_open_error;
199  volatile bool mqtt_basic_conn;
200  volatile bool mqtt_basic_conn_error;
201  volatile bool mqtt_basic_publish;
202  volatile bool mqtt_basic_subscribe;
203 #endif /* EWF_ADAPTER_QUECTEL_COMMON_MQTT_BASIC_ENABLED */
204 
205 #if EWF_ADAPTER_QUECTEL_COMMON_MQTT_ENABLED
208 
210  ewf_adapter_mqtt_message_callback mqtt_message_callback;
211 #endif /* EWF_ADAPTER_QUECTEL_COMMON_MQTT_ENABLED */
212 
214 
215 /************************************************************************/
219 /************************************************************************/
236 
242 
247 ewf_result ewf_adapter_quectel_common_context_configure(ewf_adapter* adapter_ptr, uint32_t ctx, uint32_t type, const char* apn, const char* username, const char* password, uint32_t authentication);
248 
253 ewf_result ewf_adapter_quectel_common_context_configure_dns(ewf_adapter* adapter_ptr, uint32_t ctx, const char* primary_dns, const char* secondary_dns);
254 
263 ewf_result ewf_adapter_quectel_common_ufs_start(ewf_adapter* adapter_ptr);
264 ewf_result ewf_adapter_quectel_common_ufs_stop(ewf_adapter* adapter_ptr);
265 
266 ewf_result ewf_adapter_quectel_common_ufs_urc_callback(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t buffer_length);
267 
273 
279 ewf_result ewf_adapter_quectel_common_ufs_delete(ewf_adapter* adapter_ptr, const char* filename_str);
280 
288 ewf_result ewf_adapter_quectel_common_ufs_upload(ewf_adapter* adapter_ptr, const char* filename_str, const uint8_t* buffer_ptr, uint32_t buffer_length);
289 
298 extern ewf_adapter_api_control ewf_adapter_quectel_common_api_control;
299 
300 ewf_result ewf_adapter_quectel_common_start(ewf_adapter* adapter_ptr);
301 ewf_result ewf_adapter_quectel_common_stop(ewf_adapter* adapter_ptr);
302 
311 extern ewf_adapter_api_info ewf_adapter_quectel_common_api_info;
312 
313 ewf_result ewf_adapter_quectel_common_info(ewf_adapter* adapter_ptr);
314 ewf_result ewf_adapter_quectel_common_get_ipv4_address(ewf_adapter* adapter_ptr, uint32_t* address_ptr);
315 ewf_result ewf_adapter_quectel_common_get_ipv4_netmask(ewf_adapter* adapter_ptr, uint32_t* netmask_ptr);
316 ewf_result ewf_adapter_quectel_common_get_ipv4_gateway(ewf_adapter* adapter_ptr, uint32_t* gateway_ptr);
317 ewf_result ewf_adapter_quectel_common_get_ipv4_dns(ewf_adapter* adapter_ptr, uint32_t* dns);
318 
327 ewf_result ewf_adapter_quectel_common_urc_callback(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t buffer_length);
328 
337 #if EWF_ADAPTER_QUECTEL_COMMON_TCP_ENABLED || EWF_ADAPTER_QUECTEL_COMMON_UDP_ENABLED
338 
339 ewf_result ewf_adapter_quectel_common_internet_start(ewf_adapter* adapter_ptr);
340 ewf_result ewf_adapter_quectel_common_internet_stop(ewf_adapter* adapter_ptr);
341 
342 ewf_result ewf_adapter_quectel_common_internet_urc_callback(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t buffer_length);
343 
344 #endif /* EWF_ADAPTER_QUECTEL_COMMON_TCP_ENABLED || EWF_ADAPTER_QUECTEL_COMMON_UDP_ENABLED */
345 
354 #if EWF_ADAPTER_QUECTEL_COMMON_TCP_ENABLED
355 
356 extern ewf_adapter_api_tcp ewf_adapter_quectel_common_api_tcp;
357 
358 ewf_result ewf_adapter_quectel_common_tcp_open(ewf_adapter* adapter_ptr, ewf_socket_tcp* socket_ptr);
359 ewf_result ewf_adapter_quectel_common_tcp_close(ewf_socket_tcp* socket_ptr);
360 ewf_result ewf_adapter_quectel_common_tcp_control(ewf_socket_tcp* socket_ptr, const char* control_str, const uint8_t* buffer_ptr, uint32_t* buffer_length_ptr);
361 ewf_result ewf_adapter_quectel_common_tcp_set_tls_configuration(ewf_socket_tcp* socket_ptr, uint32_t tls_configuration_id);
362 ewf_result ewf_adapter_quectel_common_tcp_bind(ewf_socket_tcp* socket_ptr, uint32_t local_port);
363 ewf_result ewf_adapter_quectel_common_tcp_listen(ewf_socket_tcp* socket_ptr);
364 ewf_result ewf_adapter_quectel_common_tcp_accept(ewf_socket_tcp* socket_ptr, ewf_socket_tcp* socket_new_ptr);
365 ewf_result ewf_adapter_quectel_common_tcp_connect(ewf_socket_tcp* socket_ptr, const char* const server, uint32_t port);
366 ewf_result ewf_adapter_quectel_common_tcp_shutdown(ewf_socket_tcp* socket_ptr);
367 ewf_result ewf_adapter_quectel_common_tcp_send(ewf_socket_tcp* socket_ptr, const uint8_t* buffer_ptr, uint32_t buffer_length);
368 ewf_result ewf_adapter_quectel_common_tcp_receive(ewf_socket_tcp* socket_ptr, uint8_t* buffer_ptr, uint32_t* buffer_length, bool wait);
369 
370 #endif /* EWF_ADAPTER_QUECTEL_COMMON_TCP_ENABLED */
371 
380 #if EWF_ADAPTER_QUECTEL_COMMON_UDP_ENABLED
381 
382 extern ewf_adapter_api_udp ewf_adapter_quectel_common_api_udp;
383 
384 ewf_result ewf_adapter_quectel_common_udp_open(ewf_adapter* adapter_ptr, ewf_socket_udp* socket_ptr);
385 ewf_result ewf_adapter_quectel_common_udp_close(ewf_socket_udp* socket_ptr);
386 ewf_result ewf_adapter_quectel_common_udp_control(ewf_socket_udp* socket_ptr, const char* control_str, const uint8_t* buffer_ptr, uint32_t* buffer_length_ptr);
387 ewf_result ewf_adapter_quectel_common_udp_set_dtls_configuration(ewf_socket_udp* socket_ptr, uint32_t dtls_configuration_id);
388 ewf_result ewf_adapter_quectel_common_udp_bind(ewf_socket_udp* socket_ptr, uint32_t port);
389 ewf_result ewf_adapter_quectel_common_udp_shutdown(ewf_socket_udp* socket_ptr);
390 ewf_result ewf_adapter_quectel_common_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);
391 ewf_result ewf_adapter_quectel_common_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);
392 
393 #endif /* EWF_ADAPTER_QUECTEL_COMMON_UDP_ENABLED */
394 
403 #if EWF_ADAPTER_QUECTEL_COMMON_TLS_BASIC_ENABLED
404 
405 extern ewf_adapter_api_tls_basic ewf_adapter_quectel_common_api_tls_basic;
406 
407 ewf_result ewf_adapter_quectel_common_tls_basic_start(ewf_adapter* adapter_ptr);
408 ewf_result ewf_adapter_quectel_common_tls_basic_stop(ewf_adapter* adapter_ptr);
409 
410 ewf_result ewf_adapter_quectel_common_tls_basic_urc_callback(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t buffer_length);
411 
412 ewf_result ewf_adapter_quectel_common_tls_basic_init(ewf_adapter* adapter_ptr);
413 ewf_result ewf_adapter_quectel_common_tls_basic_clean(ewf_adapter* adapter_ptr);
414 
415 #endif /* EWF_ADAPTER_QUECTEL_COMMON_TLS_BASIC_ENABLED */
416 
425 #if EWF_ADAPTER_QUECTEL_COMMON_MQTT_BASIC_ENABLED
426 
427 extern ewf_adapter_api_mqtt_basic ewf_adapter_quectel_common_api_mqtt_basic;
428 
429 ewf_result ewf_adapter_quectel_common_mqtt_basic_start(ewf_adapter* adapter_ptr);
430 ewf_result ewf_adapter_quectel_common_mqtt_basic_stop(ewf_adapter* adapter_ptr);
431 
432 ewf_result ewf_adapter_quectel_common_mqtt_basic_urc_callback(ewf_interface* interface_ptr, uint8_t* buffer_ptr, uint32_t buffer_length);
433 
434 ewf_result ewf_adapter_quectel_common_mqtt_basic_default_state_callback(ewf_adapter* adapter_ptr, const char* state_cstr, const char* param_cstr);
435 ewf_result ewf_adapter_quectel_common_mqtt_basic_default_message_callback(ewf_adapter* adapter_ptr, const char* topic_cstr, const char* payload_cstr);
436 
437 ewf_result ewf_adapter_quectel_common_mqtt_basic_connect(ewf_adapter* adapter_ptr, char const* server_str, uint32_t port, char const* clientid, char const* username, char const* password);
438 ewf_result ewf_adapter_quectel_common_mqtt_basic_disconnect(ewf_adapter* adapter_ptr);
439 ewf_result ewf_adapter_quectel_common_mqtt_basic_subscribe(ewf_adapter* adapter_ptr, char const* topic);
440 ewf_result ewf_adapter_quectel_common_mqtt_basic_unsubscribe(ewf_adapter* adapter_ptr, char const* topic);
441 ewf_result ewf_adapter_quectel_common_mqtt_basic_publish(ewf_adapter* adapter_ptr, const char* topic, const char* msg_cstr);
442 
443 #endif /* EWF_ADAPTER_QUECTEL_COMMON_MQTT_BASIC_ENABLED */
444 
447 /************************************************************************/
451 /************************************************************************/
455 #ifdef __cplusplus
456 }
457 #endif
458 
459 #endif /* __ewf_adapter_quectel_common__h__included__ */
The Embedded Wireless Framework adapter API implementation.
_ewf_adapter_common_internet_socket_service_type
The socket service type
Definition: ewf_adapter_espressif_common.h:79
ewf_result(* ewf_adapter_mqtt_message_callback)(ewf_socket_mqtt *socket_ptr, const char *topic_str, ewf_adapter_mqtt_message *message_ptr)
A function pointer type for MQTT message callbacks.
Definition: ewf_adapter_api_mqtt.h:50
ewf_result ewf_adapter_quectel_common_context_configure(ewf_adapter *adapter_ptr, uint32_t ctx, uint32_t type, const char *apn, const char *username, const char *password, uint32_t authentication)
Configure a context.
Definition: ewf_adapter_quectel_common_context.c:79
ewf_result ewf_adapter_quectel_common_context_deactivate(ewf_adapter *adapter_ptr, uint32_t ctx)
Deactivate a context.
Definition: ewf_adapter_quectel_common_context.c:46
ewf_result ewf_adapter_quectel_common_context_configure_dns(ewf_adapter *adapter_ptr, uint32_t ctx, const char *primary_dns, const char *secondary_dns)
Configure a context DNS.
Definition: ewf_adapter_quectel_common_context.c:140
ewf_result ewf_adapter_quectel_common_context_activate(ewf_adapter *adapter_ptr, uint32_t ctx)
Activate a context.
Definition: ewf_adapter_quectel_common_context.c:13
struct _ewf_adapter_quectel_common ewf_adapter_quectel_common
The Quectel common adapter data structure.
struct _ewf_adapter_quectel_common_internet_socket ewf_adapter_quectel_common_internet_socket
Internal structure for internet socket status
enum _ewf_adapter_common_internet_socket_service_type ewf_adapter_quectel_common_internet_socket_service_type
The socket service type
struct _ewf_adapter_quectel_common_mqtt_socket ewf_adapter_quectel_common_mqtt_socket
Internal structure for MQTT socket status
ewf_result ewf_adapter_quectel_common_ufs_delete(ewf_adapter *adapter_ptr, const char *filename_str)
Delete a file from the user file system.
Definition: ewf_adapter_quectel_common_ufs.c:54
ewf_result ewf_adapter_quectel_common_ufs_upload(ewf_adapter *adapter_ptr, const char *filename_str, const uint8_t *buffer_ptr, uint32_t buffer_length)
Upload a file to the user file system.
Definition: ewf_adapter_quectel_common_ufs.c:68
ewf_result ewf_adapter_quectel_common_ufs_list(ewf_adapter *adapter_ptr)
List the files in the user file system.
Definition: ewf_adapter_quectel_common_ufs.c:32
#define EWF_ADAPTER_QUECTEL_COMMON_INTERNET_SOCKET_POOL_SIZE
The total number of supported internet sockets in the adapter.
Definition: ewf_adapter_quectel_common.h:63
#define EWF_ADAPTER_QUECTEL_COMMON_MQTT_SOCKET_POOL_SIZE
The total number of supported MQTT sockets in the adapter.
Definition: ewf_adapter_quectel_common.h:73
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
Definition: ewf_adapter_api_mqtt_basic.h:55
The TCP API structure.
Definition: ewf_adapter_api_tcp.h:76
The TLS basic API structure.
Definition: ewf_adapter_api_tls_basic.h:29
The UDP API type.
Definition: ewf_adapter_api_udp.h:63
Internal structure for internet socket status
Definition: ewf_adapter_quectel_common.h:162
Internal structure for MQTT socket status
Definition: ewf_adapter_quectel_common.h:177
The Quectel common adapter data structure.
Definition: ewf_adapter_quectel_common.h:187
volatile bool mqtt_basic_open
Internal MQTT basic API socket 0 status
Definition: ewf_adapter_quectel_common.h:197
uint32_t default_timeout
Definition: ewf_adapter_quectel_common.h:188
The EWF network adapter control structure definition.
Definition: ewf_adapter.h:50
The interface structure definition.
Definition: ewf_interface.h:66
The TCP socket structure definition.
Definition: ewf_adapter_api_tcp.h:47
The UDP socket structure definition.
Definition: ewf_adapter_api_udp.h:40