|
| 1 | +/* |
| 2 | + * Copyright (c) 2021 Nordic Semiconductor |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef ZEPHYR_INCLUDE_NET_SOCKET_NCS_H_ |
| 8 | +#define ZEPHYR_INCLUDE_NET_SOCKET_NCS_H_ |
| 9 | + |
| 10 | +/** |
| 11 | + * @file |
| 12 | + * @brief NCS specific additions to the BSD sockets API definitions |
| 13 | + */ |
| 14 | + |
| 15 | +#ifdef __cplusplus |
| 16 | +extern "C" { |
| 17 | +#endif |
| 18 | + |
| 19 | +/* When CONFIG_NET_SOCKETS_OFFLOAD is enabled, offloaded sockets take precedence |
| 20 | + * when creating a new socket. Combine this flag with a socket type when |
| 21 | + * creating a socket, to enforce native socket creation (e. g. SOCK_STREAM | SOCK_NATIVE). |
| 22 | + * If it's desired to create a native TLS socket, but still offload the |
| 23 | + * underlying TCP/UDP socket, use e. g. SOCK_STREAM | SOCK_NATIVE_TLS. |
| 24 | + */ |
| 25 | +#define SOCK_NATIVE 0x80000000 |
| 26 | +#define SOCK_NATIVE_TLS 0x40000000 |
| 27 | + |
| 28 | +/** Define a base for NCS specific socket options to prevent overlaps with Zephyr's socket options. |
| 29 | + */ |
| 30 | +#define NET_SOCKET_NCS_BASE 1000 |
| 31 | + |
| 32 | +/* NCS specific TLS level socket options */ |
| 33 | + |
| 34 | +/** Socket option to set DTLS handshake timeout, specifically for nRF sockets. |
| 35 | + * The option accepts an integer, indicating the total handshake timeout, |
| 36 | + * including retransmissions, in seconds. |
| 37 | + * Accepted values for the option are: 1, 3, 7, 15, 31, 63, 123. |
| 38 | + */ |
| 39 | +#define TLS_DTLS_HANDSHAKE_TIMEO (NET_SOCKET_NCS_BASE + 18) |
| 40 | + |
| 41 | +/** Socket option to save DTLS connection, specifically for nRF sockets. |
| 42 | + */ |
| 43 | +#define TLS_DTLS_CONN_SAVE (NET_SOCKET_NCS_BASE + 19) |
| 44 | + |
| 45 | +/** Socket option to load DTLS connection, specifically for nRF sockets. |
| 46 | + */ |
| 47 | +#define TLS_DTLS_CONN_LOAD (NET_SOCKET_NCS_BASE + 20) |
| 48 | + |
| 49 | +/** Socket option to get result of latest TLS/DTLS completed handshakes end status, |
| 50 | + * specifically for nRF sockets. |
| 51 | + * The option accepts an integer, indicating the setting. |
| 52 | + * Accepted vaules for the option are: 0 and 1. |
| 53 | + */ |
| 54 | +#define TLS_DTLS_HANDSHAKE_STATUS (NET_SOCKET_NCS_BASE + 21) |
| 55 | + |
| 56 | +/* Valid values for TLS_DTLS_HANDSHAKE_TIMEO option */ |
| 57 | +#define TLS_DTLS_HANDSHAKE_TIMEO_NONE 0 /**< No timeout */ |
| 58 | +#define TLS_DTLS_HANDSHAKE_TIMEO_1S 1 /**< 1 second */ |
| 59 | +#define TLS_DTLS_HANDSHAKE_TIMEO_3S 3 /**< 1s + 2s */ |
| 60 | +#define TLS_DTLS_HANDSHAKE_TIMEO_7S 7 /**< 1s + 2s + 4s */ |
| 61 | +#define TLS_DTLS_HANDSHAKE_TIMEO_15S 15 /**< 1s + 2s + 4s + 8s */ |
| 62 | +#define TLS_DTLS_HANDSHAKE_TIMEO_31S 31 /**< 1s + 2s + 4s + 8s + 16s */ |
| 63 | +#define TLS_DTLS_HANDSHAKE_TIMEO_63S 63 /**< 1s + 2s + 4s + 8s + 16s + 32s */ |
| 64 | +#define TLS_DTLS_HANDSHAKE_TIMEO_123S 123 /**< 1s + 2s + 4s + 8s + 16s + 32s + 60s */ |
| 65 | + |
| 66 | +/* Valid values for TLS_DTLS_HANDSHAKE_STATUS option */ |
| 67 | +#define TLS_DTLS_HANDSHAKE_STATUS_FULL 0 |
| 68 | +#define TLS_DTLS_HANDSHAKE_STATUS_CACHED 1 |
| 69 | + |
| 70 | +/* NCS specific socket options */ |
| 71 | + |
| 72 | +/** sockopt: enable sending data as part of exceptional events */ |
| 73 | +#define SO_EXCEPTIONAL_DATA (NET_SOCKET_NCS_BASE + 33) |
| 74 | +/** sockopt: Keep socket open when its PDN connection is lost |
| 75 | + * or the device is put into flight mode. |
| 76 | + */ |
| 77 | +#define SO_KEEPOPEN (NET_SOCKET_NCS_BASE + 34) |
| 78 | +/** sockopt: bind to PDN */ |
| 79 | +#define SO_BINDTOPDN (NET_SOCKET_NCS_BASE + 40) |
| 80 | + |
| 81 | +/** sockopt: Release assistance indication (RAI). |
| 82 | + * The option accepts an integer, indicating the type of RAI. |
| 83 | + * Accepted values for the option are: @ref RAI_NO_DATA, @ref RAI_LAST, @ref RAI_ONE_RESP, |
| 84 | + * @ref RAI_ONGOING, @ref RAI_WAIT_MORE. |
| 85 | + */ |
| 86 | +#define SO_RAI (NET_SOCKET_NCS_BASE + 61) |
| 87 | + |
| 88 | +/** Release assistance indication (RAI). |
| 89 | + * Indicate that the application does not intend to send more data. |
| 90 | + * This applies immediately and lets the modem exit connected mode more |
| 91 | + * quickly. |
| 92 | + * |
| 93 | + * @note This requires the socket to be connected. |
| 94 | + */ |
| 95 | +#define RAI_NO_DATA 1 |
| 96 | +/** Release assistance indication (RAI). |
| 97 | + * Indicate that the application does not intend to send more data |
| 98 | + * after the next call to send() or sendto(). |
| 99 | + * This lets the modem exit connected mode more quickly after sending the data. |
| 100 | + */ |
| 101 | +#define RAI_LAST 2 |
| 102 | +/** Release assistance indication (RAI). |
| 103 | + * Indicate that the application is expecting to receive just one data packet |
| 104 | + * after the next call to send() or sendto(). |
| 105 | + * This lets the modem exit connected mode more quickly after having received the data. |
| 106 | + */ |
| 107 | +#define RAI_ONE_RESP 3 |
| 108 | +/** Release assistance indication (RAI). |
| 109 | + * Indicate that the socket is in active use by a client application. |
| 110 | + * This lets the modem stay in connected mode longer. |
| 111 | + */ |
| 112 | +#define RAI_ONGOING 4 |
| 113 | +/** Release assistance indication (RAI). |
| 114 | + * Indicate that the socket is in active use by a server application. |
| 115 | + * This lets the modem stay in connected mode longer. |
| 116 | + */ |
| 117 | +#define RAI_WAIT_MORE 5 |
| 118 | + |
| 119 | +/* NCS specific IPPROTO_ALL level socket options */ |
| 120 | + |
| 121 | +/** IPv4 and IPv6 protocol level (pseudo-val) for nRF sockets. */ |
| 122 | +#define IPPROTO_ALL 512 |
| 123 | +/** sockopt: disable all replies to unexpected traffics */ |
| 124 | +#define SO_SILENCE_ALL (NET_SOCKET_NCS_BASE + 30) |
| 125 | + |
| 126 | +/* NCS specific IPPROTO_IP level socket options */ |
| 127 | + |
| 128 | +/** sockopt: enable IPv4 ICMP replies */ |
| 129 | +#define SO_IP_ECHO_REPLY (NET_SOCKET_NCS_BASE + 31) |
| 130 | + |
| 131 | +/* NCS specific IPPROTO_IPV6 level socket options */ |
| 132 | + |
| 133 | +/** sockopt: enable IPv6 ICMP replies */ |
| 134 | +#define SO_IPV6_ECHO_REPLY (NET_SOCKET_NCS_BASE + 32) |
| 135 | + |
| 136 | +/** sockopt: Delay IPv6 address refresh during power saving mode */ |
| 137 | +#define SO_IPV6_DELAYED_ADDR_REFRESH (NET_SOCKET_NCS_BASE + 62) |
| 138 | + |
| 139 | +/* NCS specific TCP level socket options */ |
| 140 | + |
| 141 | +/** sockopt: Configurable TCP server session timeout in minutes. |
| 142 | + * Range is 0 to 135. 0 is no timeout and 135 is 2 h 15 min. Default is 0 (no timeout). |
| 143 | + */ |
| 144 | +#define SO_TCP_SRV_SESSTIMEO (NET_SOCKET_NCS_BASE + 55) |
| 145 | + |
| 146 | +/* NCS specific gettaddrinfo() flags */ |
| 147 | + |
| 148 | +/** Assume `service` contains a Packet Data Network (PDN) ID. |
| 149 | + * When specified together with the AI_NUMERICSERV flag, |
| 150 | + * `service` shall be formatted as follows: "port:pdn_id" |
| 151 | + * where "port" is the port number and "pdn_id" is the PDN ID. |
| 152 | + * Example: "8080:1", port 8080 PDN ID 1. |
| 153 | + * Example: "42:0", port 42 PDN ID 0. |
| 154 | + */ |
| 155 | +#define AI_PDNSERV 0x1000 |
| 156 | + |
| 157 | +/* NCS specific send() and sendto() flags */ |
| 158 | + |
| 159 | +/** Request a blocking send operation until the request is acknowledged. |
| 160 | + * When used in send() or sendto(), the request will not return until the |
| 161 | + * send operation is completed by lower layers, or until the timeout, given by the SO_SNDTIMEO |
| 162 | + * socket option, is reached. Valid timeout values are 1 to 600 seconds. |
| 163 | + */ |
| 164 | +#define MSG_WAITACK 0x200 |
| 165 | + |
| 166 | +#ifdef __cplusplus |
| 167 | +} |
| 168 | +#endif |
| 169 | + |
| 170 | +#endif /* ZEPHYR_INCLUDE_NET_SOCKET_NCS_H_ */ |
0 commit comments