2022-11-12 00:31:10 +08:00
|
|
|
/*
|
|
|
|
* @Author: jiejie
|
|
|
|
* @Github: https://github.com/jiejieTop
|
|
|
|
* @Date: 2019-12-09 21:31:02
|
|
|
|
* @LastEditTime: 2020-10-17 14:14:41
|
2023-07-09 23:12:21 +08:00
|
|
|
* @Description: the code belongs to jiejie, please keep the author information
|
|
|
|
* and source code according to the license.
|
2022-11-12 00:31:10 +08:00
|
|
|
*/
|
|
|
|
#ifndef _NETWORK_H_
|
|
|
|
#define _NETWORK_H_
|
|
|
|
|
|
|
|
#include "mqtt_defconfig.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2023-07-09 23:12:21 +08:00
|
|
|
#define NETWORK_CHANNEL_TCP 0
|
|
|
|
#define NETWORK_CHANNEL_TLS 1
|
2022-11-12 00:31:10 +08:00
|
|
|
|
|
|
|
typedef struct network {
|
2023-07-09 23:12:21 +08:00
|
|
|
const char* host;
|
|
|
|
const char* port;
|
|
|
|
int socket;
|
2022-11-12 00:31:10 +08:00
|
|
|
#ifndef MQTT_NETWORK_TYPE_NO_TLS
|
2023-07-09 23:12:21 +08:00
|
|
|
int channel; /* tcp or tls */
|
|
|
|
const char* ca_crt;
|
|
|
|
unsigned int ca_crt_len;
|
|
|
|
unsigned int timeout_ms; // SSL handshake timeout in millisecond
|
|
|
|
void* nettype_tls_params;
|
2022-11-12 00:31:10 +08:00
|
|
|
#endif
|
|
|
|
} network_t;
|
|
|
|
|
2023-07-09 23:12:21 +08:00
|
|
|
int network_init(network_t* n,
|
|
|
|
const char* host,
|
|
|
|
const char* port,
|
|
|
|
const char* ca);
|
|
|
|
int network_set_ca(network_t* n, const char* ca);
|
|
|
|
void network_set_channel(network_t* n, int channel);
|
|
|
|
int network_set_host_port(network_t* n, char* host, char* port);
|
2022-11-12 00:31:10 +08:00
|
|
|
int network_read(network_t* n, unsigned char* buf, int len, int timeout);
|
|
|
|
int network_write(network_t* n, unsigned char* buf, int len, int timeout);
|
|
|
|
int network_connect(network_t* n);
|
2023-07-09 23:12:21 +08:00
|
|
|
void network_disconnect(network_t* n);
|
2022-11-12 00:31:10 +08:00
|
|
|
void network_release(network_t* n);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|