1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2018-11-10 ChenYong First version 9 */ 10 #ifndef __SAL_TLS_H__ 11 #define __SAL_TLS_H__ 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 #include <rtthread.h> 18 19 /* Protocol level for TLS. 20 * Here, the same socket protocol level for TLS as in Linux was used. 21 */ 22 #define SOL_TLS 282 23 24 /* Socket options for TLS */ 25 26 /* Socket option to select TLS credentials to use. */ 27 #define TLS_CRET_LIST 1 28 /* Socket option to set select ciphersuites to use. */ 29 #define TLS_CIPHERSUITE_LIST 2 30 /* Socket option to set peer verification level for TLS connection. */ 31 #define TLS_PEER_VERIFY 3 32 /* Socket option to set role for DTLS connection. */ 33 #define TLS_DTLS_ROLE 4 34 35 /* Protocol numbers for TLS protocols */ 36 #define PROTOCOL_TLS 256 37 #define PROTOCOL_DTLS 257 38 39 40 struct sal_proto_tls_ops 41 { 42 int (*init)(void); 43 void* (*socket)(int socket); 44 int (*connect)(void *sock); 45 int (*send)(void *sock, const void *data, size_t size); 46 int (*recv)(void *sock, void *mem, size_t len); 47 int (*closesocket)(void *sock); 48 49 int (*set_cret_list)(void *sock, const void *cert, size_t size); /* Set TLS credentials */ 50 int (*set_ciphersurite)(void *sock, const void* ciphersurite, size_t size); /* Set select ciphersuites */ 51 int (*set_peer_verify)(void *sock, const void* peer_verify, size_t size); /* Set peer verification */ 52 int (*set_dtls_role)(void *sock, const void *dtls_role, size_t size); /* Set role for DTLS */ 53 }; 54 55 struct sal_proto_tls 56 { 57 char name[RT_NAME_MAX]; /* TLS protocol name */ 58 const struct sal_proto_tls_ops *ops; /* SAL TLS protocol options */ 59 }; 60 61 /* SAL TLS protocol register */ 62 int sal_proto_tls_register(const struct sal_proto_tls *pt); 63 64 #ifdef __cplusplus 65 } 66 #endif 67 68 #endif /* __SAL_TLS_H__ */ 69