123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #ifndef LITEOS_LAB_IOT_LINK_NETWORK_DTLS_DTLS_AL_DTLS_AL_H_
- #define LITEOS_LAB_IOT_LINK_NETWORK_DTLS_DTLS_AL_DTLS_AL_H_
- #include <stdint.h>
- #include <stddef.h>
- typedef enum
- {
- EN_DTLS_AL_ERR_OK = 0,
- EN_DTLS_AL_ERR_PARA,
- EN_DTLS_AL_ERR_SYS,
- EN_DTLS_AL_ERR_SYSMEM,
- EN_DTLS_AL_ERR_NOCONFIG,
- EN_DTLS_AL_ERR_NETWORK,
- EN_DTLS_AL_ERR_SERVERCERTPARSE,
- EN_DTLS_AL_ERR_CLIENTCERTPARSE,
- EN_DTLS_AL_ERR_CLIENTPKPARSE,
- }en_dtls_al_err_t;
- typedef enum
- {
- EN_DTLS_AL_SECURITY_TYPE_NONE = 0,
- EN_DTLS_AL_SECURITY_TYPE_PSK,
- EN_DTLS_AL_SECURITY_TYPE_CERT,
- }en_dtls_al_security_type_t;
- typedef struct
- {
- uint8_t *psk_id;
- uint8_t *psk_key;
- int psk_id_len;
- int psk_key_len;
- }dtls_al_security_psk_t;
- typedef struct
- {
- uint8_t *server_ca;
- uint8_t *client_ca;
- uint8_t *client_pk;
- uint8_t *client_pk_pwd;
- int server_ca_len;
- int client_ca_len;
- int client_pk_len;
- int client_pk_pwd_len;
- char *server_name;
- }dtls_al_security_cert_t;
- typedef struct
- {
- en_dtls_al_security_type_t type;
- union
- {
- dtls_al_security_psk_t psk;
- dtls_al_security_cert_t cert;
- }u;
- }dtls_al_security_t;
- typedef struct
- {
- int istcp;
- int isclient;
- dtls_al_security_t security;
- }dtls_al_para_t;
- en_dtls_al_err_t dtls_al_new(dtls_al_para_t *para,void **handle);
- int dtls_al_connect(void *handle,const char *ip, const char *port, int timeout );
- int dtls_al_write(void *handle, uint8_t *msg, size_t len, int timeout );
- int dtls_al_read(void *handle,uint8_t *buf, size_t len,int timeout );
- en_dtls_al_err_t dtls_al_destroy(void *handle);
- typedef en_dtls_al_err_t (*fn_dtls_al_new)(dtls_al_para_t *para,void **handle);
- typedef int (*fn_dtls_al_connect)(void *handle,const char *server_ip, const char *server_port,int timeout);
- typedef int (*fn_dtls_al_write)(void *handle,uint8_t *msg, size_t len, int timeout);
- typedef int (*fn_dtls_al_read)(void *handle, uint8_t *buf, size_t len, int timeout);
- typedef en_dtls_al_err_t (*fn_dtls_al_destroy)(void *handle);
- typedef struct
- {
- fn_dtls_al_new io_new;
- fn_dtls_al_connect io_connect;
- fn_dtls_al_write io_write;
- fn_dtls_al_read io_read;
- fn_dtls_al_destroy io_destroy;
- }dtls_al_io_t;
- typedef struct
- {
- const char *name;
- dtls_al_io_t io;
- }dtls_al_t;
- int dtls_al_install(const dtls_al_t *dtls);
- int dtls_al_uninstall(const char*name);
- int dtls_imp_init(void);
- int dtls_al_init(void) ;
- #endif
|