1 /********************************************************************************
2  * @file  sl_si91x_socket_constants.h
3  *******************************************************************************
4  * # License
5  * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
6  *******************************************************************************
7  *
8  * SPDX-License-Identifier: Zlib
9  *
10  * The licensor of this software is Silicon Laboratories Inc.
11  *
12  * This software is provided 'as-is', without any express or implied
13  * warranty. In no event will the authors be held liable for any damages
14  * arising from the use of this software.
15  *
16  * Permission is granted to anyone to use this software for any purpose,
17  * including commercial applications, and to alter it and redistribute it
18  * freely, subject to the following restrictions:
19  *
20  * 1. The origin of this software must not be misrepresented; you must not
21  *    claim that you wrote the original software. If you use this software
22  *    in a product, an acknowledgment in the product documentation would be
23  *    appreciated but is not required.
24  * 2. Altered source versions must be plainly marked as such, and must not be
25  *    misrepresented as being the original software.
26  * 3. This notice may not be removed or altered from any source distribution.
27  *
28  ******************************************************************************/
29 
30 #pragma once
31 
32 #include <stdint.h>
33 #include "cmsis_os2.h"
34 
35 #ifndef BIT
36 #define BIT(a) ((uint32_t)1U << a)
37 #endif
38 
39 /******************************************************
40  *               Socket Configurations
41  ******************************************************/
42 #define SI91X_NO_ERROR 0 // This is returned by socket functions after successful execution
43 #define SI91X_UNDEFINED_ERROR \
44   0 // This value is set to errno global variable when a socket API failed due to unknown error.
45 
46 #define NUMBER_OF_SOCKETS 20
47 
48 #define SI91X_HOST_WAIT_FOR_SELECT_RSP 1000
49 
50 #define TCP_RX_WINDOW_SIZE 10
51 
52 #define DEFAULT_STREAM_MSS_SIZE_IPV4   1460
53 #define DEFAULT_DATAGRAM_MSS_SIZE_IPV4 1472
54 
55 #define DEFAULT_STREAM_MSS_SIZE_IPV6   1440
56 #define DEFAULT_DATAGRAM_MSS_SIZE_IPV6 1452
57 
58 #define MAX_TCP_RETRY_COUNT         10
59 #define DEFAULT_TCP_KEEP_ALIVE_TIME 1200
60 
61 #define SI91X_CERT_INDEX_0 0
62 #define SI91X_CERT_INDEX_1 1
63 #define SI91X_CERT_INDEX_2 2
64 
65 #define SL_SI91X_TLS_EXTENSION_SNI_TYPE  1 ///< TLS extension for SNI
66 #define SL_SI91X_TLS_EXTENSION_ALPN_TYPE 2 ///< TLS extension for ALPN
67 
68 #define SI91X_SOCKET_TCP_CLIENT 0x0000
69 #define SI91X_SOCKET_UDP_CLIENT 0x0001
70 #define SI91X_SOCKET_TCP_SERVER 0x0002
71 #define SI91X_SOCKET_LUDP       0x0004
72 
73 #define SI91X_SOCKET_FEAT_SSL                BIT(0) // SAPI maps both SSL and synchronous to BIT(0)
74 #define SI91X_SOCKET_FEAT_SYNCHRONOUS        BIT(0)
75 #define SI91X_SOCKET_FEAT_LTCP_ACCEPT        BIT(1)
76 #define SI91X_WEBSOCKET_FEAT                 BIT(1)
77 #define SI91X_SOCKET_FEAT_TCP_ACK_INDICATION BIT(2)
78 #define SI91X_SOCKET_FEAT_TCP_RX_WINDOW      BIT(4)
79 #define SI91X_SOCKET_FEAT_CERT_INDEX         BIT(5)
80 #define SI91X_HIGH_PERFORMANCE_SOCKET        BIT(7)
81 
82 #define MAX_RETRANSMISSION_TIME_VALUE 32
83 
84 /**
85  * @addtogroup SI91X_SOCKET_OPTION_NAME SiWx91x Socket Option Name
86  * @ingroup SI91X_SOCKET_FUNCTIONS
87  * @{
88  */
89 #define SL_SI91X_SO_RCVTIME                          20 ///< Enable receive timeout
90 #define SL_SI91X_SO_TCP_KEEPALIVE                    26 ///< To configure the TCP keep alive
91 #define SL_SI91X_SO_HIGH_PERFORMANCE_SOCKET          38 ///< To configure the high performance socket
92 #define SL_SI91X_SO_CERT_INDEX                       46 ///< To enable set certificate index
93 #define SL_SI91X_SO_SSL_ENABLE                       37 ///< To enable SSL
94 #define SL_SI91X_SO_SSL_V_1_0_ENABLE                 42 ///< To enable SSL 1.0
95 #define SL_SI91X_SO_SSL_V_1_1_ENABLE                 43 ///< To enable SSL 1.1
96 #define SL_SI91X_SO_SSL_V_1_2_ENABLE                 44 ///< To enable SSL 1.2
97 #define SL_SI91x_SO_TCP_ACK_INDICATION               45 ///< To enable TCP ACK indication feature
98 #define SL_SI91X_SO_MAX_RETRANSMISSION_TIMEOUT_VALUE 48 ///< to configure max retransmission timeout value
99 #define SL_SI91X_IP_TOS                              48 ///< To configure TOS
100 #define SL_SI91X_SO_SSL_V_1_3_ENABLE                 49 ///< To enable SSL 1.3
101 #define SL_SI91X_SO_MAXRETRY                         24 ///< To enable max TCP retry count
102 #define SL_SI91X_SO_MSS                              40 ///< To configure the TCP MSS
103 #define SL_SI91X_SO_SOCK_VAP_ID                      25 ///< To configure the socket VAP ID
104 #define SL_SI91X_SO_TLS_SNI                          47 ///< To configure the TLS SNI extension
105 #define SL_SI91X_SO_TLS_ALPN                         50 ///< To configure the TLS ALPN extension
106 /** @} */
107 
108 #define SHUTDOWN_BY_ID   0
109 #define SHUTDOWN_BY_PORT 1
110 /******************************************************
111  *                 SSL features
112  ******************************************************/
113 //Release 2.0 default ciphers
114 #define SSL_DEFAULT_CIPHERS                                                                    \
115   (BIT_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 | BIT_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256           \
116    | BIT_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 | BIT_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256     \
117    | BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 | BIT_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 \
118    | BIT_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA | BIT_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA           \
119    | BIT_TLS_DHE_RSA_WITH_AES_256_CBC_SHA | BIT_TLS_DHE_RSA_WITH_AES_128_CBC_SHA               \
120    | BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA | BIT_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA          \
121    | BIT_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA | BIT_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA)
122 
123 //Release 2.0 all configurable ciphers
124 #define SSL_RELEASE_2_0_ALL_CIPHERS                                                                                   \
125   (SSL_DEFAULT_CIPHERS | BIT_TLS_RSA_WITH_AES_256_CBC_SHA256 | BIT_TLS_RSA_WITH_AES_128_CBC_SHA256                    \
126    | BIT_TLS_RSA_WITH_AES_256_CBC_SHA | BIT_TLS_RSA_WITH_AES_128_CBC_SHA | BIT_TLS_RSA_WITH_AES_128_CCM_8             \
127    | BIT_TLS_RSA_WITH_AES_256_CCM_8 | BIT_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 | BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 \
128    | BIT_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 | BIT_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384                        \
129    | BIT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 | BIT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256              \
130    | BIT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256)
131 
132 #if defined(SLI_SI917) || defined(SLI_SI915)
133 #define SSL_EXT_CIPHERS SSL_TLSV1_3_ALL_CIPHERS
134 #endif
135 
136 #define SSL_ALL_CIPHERS SSL_RELEASE_2_0_ALL_CIPHERS
137 
138 //TLSv1.3 configurable ciphers
139 #if defined(SLI_SI917) || defined(SLI_SI915)
140 #define SSL_TLSV1_3_ALL_CIPHERS                                                                     \
141   (BIT_TLS13_AES_128_GCM_SHA256 | BIT_TLS13_AES_256_GCM_SHA384 | BIT_TLS13_CHACHA20_POLY1305_SHA256 \
142    | BIT_TLS13_AES_128_CCM_SHA256 | BIT_TLS13_AES_128_CCM_8_SHA256)
143 #endif
144 
145 #define BIT_TLS_RSA_WITH_AES_256_CBC_SHA256               BIT(0)
146 #define BIT_TLS_RSA_WITH_AES_128_CBC_SHA256               BIT(1)
147 #define BIT_TLS_RSA_WITH_AES_256_CBC_SHA                  BIT(2)
148 #define BIT_TLS_RSA_WITH_AES_128_CBC_SHA                  BIT(3)
149 #define BIT_TLS_RSA_WITH_AES_128_CCM_8                    BIT(4)
150 #define BIT_TLS_RSA_WITH_AES_256_CCM_8                    BIT(5)
151 #define BIT_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8            BIT(6)
152 #define BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8            BIT(7)
153 #define BIT_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256           BIT(8)
154 #define BIT_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384           BIT(9)
155 #define BIT_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256         BIT(10)
156 #define BIT_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384         BIT(11)
157 #define BIT_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256       BIT(12)
158 #define BIT_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384       BIT(13)
159 #define BIT_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256           BIT(14)
160 #define BIT_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256           BIT(15)
161 #define BIT_TLS_DHE_RSA_WITH_AES_256_CBC_SHA              BIT(16)
162 #define BIT_TLS_DHE_RSA_WITH_AES_128_CBC_SHA              BIT(17)
163 #define BIT_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384         BIT(18)
164 #define BIT_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256         BIT(19)
165 #define BIT_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA            BIT(20)
166 #define BIT_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA            BIT(21)
167 #define BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384       BIT(22)
168 #define BIT_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256       BIT(23)
169 #define BIT_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA          BIT(24)
170 #define BIT_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA             BIT(25)
171 #define BIT_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA           BIT(26)
172 #define BIT_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA         BIT(27)
173 #define BIT_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256   BIT(28)
174 #define BIT_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 BIT(29)
175 #define BIT_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256     BIT(30)
176 #define SSL_NEW_CIPHERS                                   BIT(31)
177 
178 // TLSv1.3 supported ciphers
179 #if defined(SLI_SI917) || defined(SLI_SI915)
180 #define BIT_TLS13_AES_128_GCM_SHA256       BIT(0)
181 #define BIT_TLS13_AES_256_GCM_SHA384       BIT(1)
182 #define BIT_TLS13_CHACHA20_POLY1305_SHA256 BIT(2)
183 #define BIT_TLS13_AES_128_CCM_SHA256       BIT(3)
184 #define BIT_TLS13_AES_128_CCM_8_SHA256     BIT(4)
185 #endif
186