diff options
| author | chenyong <[email protected]> | 2018-11-15 14:39:31 +0800 |
|---|---|---|
| committer | chenyong <[email protected]> | 2018-11-15 14:48:20 +0800 |
| commit | beaff7c09d4ae925f3d0269dc42a929468fd3745 (patch) | |
| tree | 3449a62f0f200c6751728fdbd904e05957350981 /components/net/sal_socket/include | |
| parent | 1353a41183a47b87ce9847532dfab6123d36d5d9 (diff) | |
[net][sal] Add SAL components TLS features support
Signed-off-by: chenyong <[email protected]>
Diffstat (limited to 'components/net/sal_socket/include')
| -rw-r--r-- | components/net/sal_socket/include/sal.h | 45 | ||||
| -rw-r--r-- | components/net/sal_socket/include/sal_tls.h | 68 | ||||
| -rw-r--r-- | components/net/sal_socket/include/socket/sys_socket/sys/socket.h | 3 |
3 files changed, 98 insertions, 18 deletions
diff --git a/components/net/sal_socket/include/sal.h b/components/net/sal_socket/include/sal.h index 68248742d6..17d44eef77 100644 --- a/components/net/sal_socket/include/sal.h +++ b/components/net/sal_socket/include/sal.h @@ -25,7 +25,7 @@ extern "C" { typedef uint32_t socklen_t; #endif -/* sal socket magic word */ +/* SAL socket magic word */ #define SAL_SOCKET_MAGIC 0x5A10 /* The maximum number of sockets structure */ @@ -38,12 +38,12 @@ typedef uint32_t socklen_t; #define SAL_PROTO_FAMILIES_NUM 4 #endif -/* sal socket offset */ +/* SAL socket offset */ #ifndef SAL_SOCKET_OFFSET #define SAL_SOCKET_OFFSET 0 #endif -struct proto_ops +struct sal_socket_ops { int (*socket) (int domain, int type, int protocol); int (*closesocket)(int s); @@ -64,30 +64,38 @@ struct proto_ops #endif }; +struct sal_proto_ops +{ + struct hostent* (*gethostbyname) (const char *name); + int (*gethostbyname_r)(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); + int (*getaddrinfo) (const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res); + void (*freeaddrinfo) (struct addrinfo *ai); +}; + struct sal_socket { - uint32_t magic; /* sal socket magic word */ + uint32_t magic; /* SAL socket magic word */ - int socket; /* sal socket descriptor */ + int socket; /* SAL socket descriptor */ int domain; int type; int protocol; - const struct proto_ops *ops; /* socket options */ - void *user_data; /* specific sal socket data */ + const struct sal_socket_ops *ops; /* socket options */ + + void *user_data; /* user-specific data */ +#ifdef SAL_USING_TLS + void *user_data_tls; /* user-specific TLS data */ +#endif }; -struct proto_family +struct sal_proto_family { - char name[RT_NAME_MAX]; int family; /* primary protocol families type */ int sec_family; /* secondary protocol families type */ - int (*create)(struct sal_socket *sal_socket, int type, int protocol); /* register socket options */ + int (*create)(struct sal_socket *sal_socket, int type, int protocol); /* register socket options */ - struct hostent* (*gethostbyname) (const char *name); - int (*gethostbyname_r)(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); - void (*freeaddrinfo) (struct addrinfo *ai); - int (*getaddrinfo) (const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res); + struct sal_proto_ops *ops; /* protocol family options */ }; /* SAL(Socket Abstraction Layer) initialize */ @@ -95,10 +103,11 @@ int sal_init(void); struct sal_socket *sal_get_socket(int sock); -/* protocol family register and unregister operate */ -int sal_proto_family_register(const struct proto_family *pf); -int sal_proto_family_unregister(const struct proto_family *pf); -struct proto_family *sal_proto_family_find(const char *name); +/* SAL protocol family register and unregister operate */ +int sal_proto_family_register(const struct sal_proto_family *pf); +int sal_proto_family_unregister(int family); +rt_bool_t sal_proto_family_is_registered(int family); +struct sal_proto_family *sal_proto_family_find(int family); #ifdef __cplusplus } diff --git a/components/net/sal_socket/include/sal_tls.h b/components/net/sal_socket/include/sal_tls.h new file mode 100644 index 0000000000..7681b313bd --- /dev/null +++ b/components/net/sal_socket/include/sal_tls.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2018-11-10 ChenYong First version + */ +#ifndef __SAL_TLS_H__ +#define __SAL_TLS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <rtthread.h> + +/* Protocol level for TLS. + * Here, the same socket protocol level for TLS as in Linux was used. + */ +#define SOL_TLS 282 + +/* Socket options for TLS */ + +/* Socket option to select TLS credentials to use. */ +#define TLS_CRET_LIST 1 +/* Socket option to set select ciphersuites to use. */ +#define TLS_CIPHERSUITE_LIST 2 +/* Socket option to set peer verification level for TLS connection. */ +#define TLS_PEER_VERIFY 3 +/* Socket option to set role for DTLS connection. */ +#define TLS_DTLS_ROLE 4 + +/* Protocol numbers for TLS protocols */ +#define PROTOCOL_TLS 256 +#define PROTOCOL_DTLS 257 + + +struct sal_proto_tls_ops +{ + int (*init)(void); + void* (*socket)(int socket); + int (*connect)(void *sock); + int (*send)(void *sock, const void *data, size_t size); + int (*recv)(void *sock, void *mem, size_t len); + int (*closesocket)(void *sock); + + int (*set_cret_list)(void *sock, const void *cert, size_t size); /* Set TLS credentials */ + int (*set_ciphersurite)(void *sock, const void* ciphersurite, size_t size); /* Set select ciphersuites */ + int (*set_peer_verify)(void *sock, const void* peer_verify, size_t size); /* Set peer verification */ + int (*set_dtls_role)(void *sock, const void *dtls_role, size_t size); /* Set role for DTLS */ +}; + +struct sal_proto_tls +{ + char name[RT_NAME_MAX]; /* TLS protocol name */ + const struct sal_proto_tls_ops *ops; /* SAL TLS protocol options */ +}; + +/* SAL TLS protocol register */ +int sal_proto_tls_register(const struct sal_proto_tls *pt); + +#ifdef __cplusplus +} +#endif + +#endif /* __SAL_TLS_H__ */ diff --git a/components/net/sal_socket/include/socket/sys_socket/sys/socket.h b/components/net/sal_socket/include/socket/sys_socket/sys/socket.h index dd2c3850a6..04470aa84a 100644 --- a/components/net/sal_socket/include/socket/sys_socket/sys/socket.h +++ b/components/net/sal_socket/include/socket/sys_socket/sys/socket.h @@ -14,6 +14,9 @@ #include <rtthread.h> #include <sal_socket.h> +#ifdef SAL_USING_TLS +#include <sal_tls.h> +#endif #ifdef __cplusplus extern "C" { |
