nrfxlib API 2.7.99
Loading...
Searching...
No Matches
nrf_socket.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
15#ifndef NRF_SOCKET_H__
16#define NRF_SOCKET_H__
17
18#include <stdint.h>
19#include <stddef.h>
20#include <stdbool.h>
21
22#ifdef __cplusplus
23 #ifdef __GNUC__
24 /* GNU C++ compiler supports restrict as __restrict__ */
25 #define restrict __restrict__
26 #else
27 /* Other C++ compilers may not support restrict */
28 #define restrict
29 #endif
30#endif
31
32/* ssize_t is not part of the C library, but is defined by POSIX in <sys/types.h> */
33#ifdef __has_include
34 #if __has_include(<sys/types.h>)
35 #include <sys/types.h>
36 #else
37 /* <sys/types.h> missing, define ssize_t here */
38 typedef int32_t ssize_t;
39 #endif
40#else
41 /* __has_include() not supported, rely on build-system macro */
42 #ifdef NRF_MODEM_HAS_SYS_TYPES
43 #include <sys/types.h>
44 #else
45 typedef int32_t ssize_t;
46 #endif
47#endif
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
57#define NRF_MODEM_MAX_SOCKET_COUNT 8
58
65#define NRF_HTONS(x) ((uint16_t) ((((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8)))
66
68#define NRF_HTONL(x) ((uint32_t) ((((x) & 0xff000000) >> 24) | \
69 (((x) & 0x00ff0000) >> 8) | \
70 (((x) & 0x0000ff00) << 8) | \
71 (((x) & 0x000000ff) << 24)))
72
74#define NRF_NTOHS(x) NRF_HTONS(x)
75
77#define NRF_NTOHL(x) NRF_HTONL(x)
78
80#define nrf_htons(x) NRF_HTONS(x)
81
83#define nrf_htonl(x) NRF_HTONL(x)
84
86#define nrf_ntohs(x) NRF_NTOHS(x)
87
89#define nrf_ntohl(x) NRF_NTOHL(x)
90
92#define NRF_INET_ADDRSTRLEN 16
93
95#define NRF_INET6_ADDRSTRLEN 46
96
110#define NRF_AF_UNSPEC 0
112#define NRF_AF_INET 1
114#define NRF_AF_INET6 2
116#define NRF_AF_PACKET 3
124#define NRF_SOCK_STREAM 1
126#define NRF_SOCK_DGRAM 2
128#define NRF_SOCK_RAW 3
138#define NRF_IPPROTO_IP 0
140#define NRF_IPPROTO_TCP 6
142#define NRF_IPPROTO_UDP 17
144#define NRF_IPPROTO_IPV6 41
146#define NRF_IPPROTO_RAW 255
148#define NRF_IPPROTO_ALL 512
149
151#define NRF_SPROTO_TLS1v2 258
153#define NRF_SPROTO_DTLS1v2 273
154 /* nrf_socket_api_enumerators */
158
168#define NRF_SOCKET_TLS_MAX_MESSAGE_SIZE 2048
169
173#define NRF_SOCKET_TLS_MAX_SEC_TAG_LIST_SIZE 7
174
179#define NRF_SO_SEC_TAG_LIST 1
180
186#define NRF_SO_SEC_HOSTNAME 2
187
193#define NRF_SO_SEC_CIPHERSUITE_LIST 3
194
200#define NRF_SO_SEC_CIPHERSUITE_USED 4
201
206#define NRF_SO_SEC_PEER_VERIFY 5
207
212#define NRF_SO_SEC_ROLE 6
213
218#define NRF_SO_SEC_SESSION_CACHE 12
219
224#define NRF_SO_SEC_SESSION_CACHE_PURGE 13
225
230#define NRF_SO_SEC_DTLS_HANDSHAKE_TIMEO 14
231
238#define NRF_SO_SEC_DTLS_CID 15
239
246#define NRF_SO_SEC_DTLS_CID_STATUS 16
247
256#define NRF_SO_SEC_DTLS_CONN_SAVE 17
257
263#define NRF_SO_SEC_DTLS_CONN_LOAD 18
264
271#define NRF_SO_SEC_HANDSHAKE_STATUS 19
281#define NRF_SO_REUSEADDR 2
283#define NRF_SO_ERROR 4
285#define NRF_SO_RCVTIMEO 20
287#define NRF_SO_SNDTIMEO 21
291#define NRF_SO_SILENCE_ALL 30
293#define NRF_SO_IP_ECHO_REPLY 31
295#define NRF_SO_IPV6_ECHO_REPLY 32
297#define NRF_SO_EXCEPTIONAL_DATA 33
299#define NRF_SO_KEEPOPEN 34
301#define NRF_SO_BINDTOPDN 40
305#define NRF_SO_TCP_SRV_SESSTIMEO 55
307#define NRF_SO_POLLCB 60
311#define NRF_SO_RAI 61
312
321#define NRF_SO_RAI_NO_DATA 50
322
330#define NRF_SO_RAI_LAST 51
331
339#define NRF_SO_RAI_ONE_RESP 52
340
347#define NRF_SO_RAI_ONGOING 53
348
355#define NRF_SO_RAI_WAIT_MORE 54
363#define NRF_SOL_SOCKET 1
364#define NRF_SOL_SECURE 282
373#define NRF_MSG_PEEK 0x02
375#define NRF_MSG_DONTWAIT 0x40
377#define NRF_MSG_WAITALL 0x100
382#define NRF_MSG_WAITACK 0x200
392#define NRF_F_GETFL 3
394#define NRF_F_SETFL 4
404#define NRF_O_NONBLOCK 0x01
419#define NRF_RAI_NO_DATA 1
424#define NRF_RAI_LAST 2
429#define NRF_RAI_ONE_RESP 3
433#define NRF_RAI_ONGOING 4
437#define NRF_RAI_WAIT_MORE 5
448#define NRF_SO_SEC_PEER_VERIFY_NONE 0
450#define NRF_SO_SEC_PEER_VERIFY_OPTIONAL 1
452#define NRF_SO_SEC_PEER_VERIFY_REQUIRED 2
463#define NRF_SO_SEC_ROLE_CLIENT 0
465#define NRF_SO_SEC_ROLE_SERVER 1
477#define NRF_SO_SEC_SESSION_CACHE_DISABLED 0
479#define NRF_SO_SEC_SESSION_CACHE_ENABLED 1
491#define NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_NONE 0
493#define NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_1S 1
495#define NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_3S 3
497#define NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_7S 7
499#define NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_15S 15
501#define NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_31S 31
503#define NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_63S 63
505#define NRF_SO_SEC_DTLS_HANDSHAKE_TIMEOUT_123S 123
514#define NRF_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 0xC024
515#define NRF_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A
516#define NRF_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 0xC023
517#define NRF_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009
518#define NRF_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014
519#define NRF_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 0xC027
520#define NRF_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013
521#define NRF_TLS_PSK_WITH_AES_256_CBC_SHA 0x008D
522#define NRF_TLS_PSK_WITH_AES_128_CBC_SHA256 0x00AE
523#define NRF_TLS_PSK_WITH_AES_128_CBC_SHA 0x008C
524#define NRF_TLS_PSK_WITH_AES_128_CCM_8 0xC0A8
525#define NRF_TLS_EMPTY_RENEGOTIATIONINFO_SCSV 0x00FF
531#define NRF_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B
532#define NRF_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030
533#define NRF_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F
547#define NRF_SO_SEC_DTLS_CID_DISABLED 0
552#define NRF_SO_SEC_DTLS_CID_SUPPORTED 1
557#define NRF_SO_SEC_DTLS_CID_ENABLED 2
571#define NRF_SO_SEC_DTLS_CID_STATUS_DISABLED 0
575#define NRF_SO_SEC_DTLS_CID_STATUS_DOWNLINK 1
579#define NRF_SO_SEC_DTLS_CID_STATUS_UPLINK 2
583#define NRF_SO_SEC_DTLS_CID_STATUS_BIDIRECTIONAL 3
593#define NRF_SO_SEC_HANDSHAKE_STATUS_FULL 0
595#define NRF_SO_SEC_HANDSHAKE_STATUS_CACHED 1
611#define NRF_SEC_TAG_TLS_DECRYPT_BASE 2147483648
612#define NRF_SEC_TAG_TLS_DECRYPT_0 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 0)
613#define NRF_SEC_TAG_TLS_DECRYPT_1 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 1)
614#define NRF_SEC_TAG_TLS_DECRYPT_2 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 2)
615#define NRF_SEC_TAG_TLS_DECRYPT_3 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 3)
616#define NRF_SEC_TAG_TLS_DECRYPT_4 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 4)
617#define NRF_SEC_TAG_TLS_DECRYPT_5 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 5)
618#define NRF_SEC_TAG_TLS_DECRYPT_6 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 6)
619#define NRF_SEC_TAG_TLS_DECRYPT_7 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 7)
620#define NRF_SEC_TAG_TLS_DECRYPT_8 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 8)
621#define NRF_SEC_TAG_TLS_DECRYPT_9 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 9)
622#define NRF_SEC_TAG_TLS_DECRYPT_10 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 10)
623#define NRF_SEC_TAG_TLS_DECRYPT_11 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 11)
624#define NRF_SEC_TAG_TLS_DECRYPT_12 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 12)
625#define NRF_SEC_TAG_TLS_DECRYPT_13 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 13)
626#define NRF_SEC_TAG_TLS_DECRYPT_14 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 14)
627#define NRF_SEC_TAG_TLS_DECRYPT_15 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 15)
628#define NRF_SEC_TAG_TLS_DECRYPT_16 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 16)
629#define NRF_SEC_TAG_TLS_DECRYPT_17 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 17)
630#define NRF_SEC_TAG_TLS_DECRYPT_18 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 18)
631#define NRF_SEC_TAG_TLS_DECRYPT_19 (NRF_SEC_TAG_TLS_DECRYPT_BASE + 19)
644 uint32_t tv_sec;
646 uint32_t tv_usec;
647};
658typedef uint16_t nrf_in_port_t;
659
665typedef unsigned short int nrf_sa_family_t;
666
671 uint8_t s6_addr[16];
672};
673
677typedef uint32_t nrf_in_addr_t;
678
684};
685
689extern const struct nrf_in6_addr nrf_in6addr_any;
690
694extern const struct nrf_in_addr nrf_inaddr_any;
695
710};
711
724};
725
726typedef uint32_t nrf_socklen_t;
727typedef uint32_t nrf_nfds_t;
728
738 char sa_data[];
739};
740
741/* Flags for getaddrinfo() hints. */
742
744#define NRF_AI_CANONNAME 0x2
746#define NRF_AI_NUMERICSERV 0x400
754#define NRF_AI_PDNSERV 0x1000
755
774};
775
778 /* Pointer to next struct */
781 char *ifa_name;
783 uint32_t ifa_flags;
793 void *ifa_data;
794};
795
810typedef uint32_t nrf_sec_role_t;
811
820typedef uint32_t nrf_sec_tag_t;
821
832typedef uint32_t nrf_sec_session_cache_t;
833
844typedef uint32_t nrf_sec_peer_verify_t;
845
851typedef uint32_t nrf_sec_cipher_t;
852
870int nrf_socket(int family, int type, int protocol);
871
882int nrf_close(int fildes);
883
901int nrf_fcntl(int fd, int cmd, int flags);
902
916int nrf_connect(int socket, const struct nrf_sockaddr *address, nrf_socklen_t address_len);
917
931ssize_t nrf_send(int socket, const void *buffer, size_t length, int flags);
932
946ssize_t nrf_sendto(int socket, const void *message, size_t length, int flags,
947 const struct nrf_sockaddr *dest_addr, nrf_socklen_t dest_len);
948
960ssize_t nrf_recv(int socket, void *buffer, size_t length, int flags);
961
973ssize_t nrf_recvfrom(int socket, void *restrict buffer, size_t length, int flags,
974 struct nrf_sockaddr *restrict address, nrf_socklen_t *restrict address_len);
975
989 int fd;
991 short events;
993 short revents;
994};
995
997#define NRF_POLLIN 0x1
999#define NRF_POLLOUT 0x4
1001#define NRF_POLLERR 0x8
1003#define NRF_POLLHUP 0x10
1005#define NRF_POLLNVAL 0x20
1006
1008typedef void (*nrf_modem_pollcb_t)(struct nrf_pollfd *pollfd);
1009
1015 short events;
1020};
1021
1039int nrf_poll(struct nrf_pollfd fds[], nrf_nfds_t nfds, int timeout);
1040
1059int nrf_setsockopt(int socket, int level, int option_name,
1060 const void *option_value, nrf_socklen_t option_len);
1061
1072int nrf_getsockopt(int socket, int level, int option_name,
1073 void *restrict option_value, nrf_socklen_t *restrict option_len);
1074
1085int nrf_bind(int socket, const struct nrf_sockaddr *address, nrf_socklen_t address_len);
1086
1097int nrf_listen(int sock, int backlog);
1098
1110int nrf_accept(int socket, struct nrf_sockaddr *restrict address,
1111 nrf_socklen_t *restrict address_len);
1112
1129int nrf_inet_pton(int af, const char *restrict src, void *restrict dst);
1130
1138const char *nrf_inet_ntop(int af, const void *restrict src, char *restrict dst, nrf_socklen_t size);
1139
1156int nrf_getaddrinfo(const char *restrict nodename,
1157 const char *restrict servname,
1158 const struct nrf_addrinfo *restrict hints,
1159 struct nrf_addrinfo **restrict res);
1160
1169
1185int nrf_getifaddrs(struct nrf_ifaddrs **ifa);
1186
1196
1223int nrf_setdnsaddr(int family, const void *in_addr, nrf_socklen_t in_size);
1224
1227#ifdef __cplusplus
1228}
1229#endif
1230
1231#endif /* NRF_SOCKET_H__ */
uint32_t nrf_in_addr_t
IPv4 address.
Definition: nrf_socket.h:677
void nrf_freeifaddrs(struct nrf_ifaddrs *ifa)
Free address information returned by nrf_getifaddrs().
uint16_t nrf_in_port_t
Socket port type.
Definition: nrf_socket.h:658
const char * nrf_inet_ntop(int af, const void *restrict src, char *restrict dst, nrf_socklen_t size)
Convert IPv4 and IPv6 addresses between binary and text form.
const struct nrf_in6_addr nrf_in6addr_any
Global IPv6 any-address.
void nrf_freeaddrinfo(struct nrf_addrinfo *ai)
Free address information returned by nrf_getaddrinfo().
uint32_t nrf_nfds_t
Definition: nrf_socket.h:727
unsigned short int nrf_sa_family_t
Socket families.
Definition: nrf_socket.h:665
int nrf_setdnsaddr(int family, const void *in_addr, nrf_socklen_t in_size)
Set a secondary DNS address.
int nrf_getifaddrs(struct nrf_ifaddrs **ifa)
Get interface address information.
int nrf_inet_pton(int af, const char *restrict src, void *restrict dst)
Convert IPv4 and IPv6 addresses between binary and text form.
uint32_t nrf_socklen_t
Definition: nrf_socket.h:726
const struct nrf_in_addr nrf_inaddr_any
Global IPv4 any-address.
int nrf_getaddrinfo(const char *restrict nodename, const char *restrict servname, const struct nrf_addrinfo *restrict hints, struct nrf_addrinfo **restrict res)
Get address information.
void(* nrf_modem_pollcb_t)(struct nrf_pollfd *pollfd)
Definition: nrf_socket.h:1008
int nrf_getsockopt(int socket, int level, int option_name, void *restrict option_value, nrf_socklen_t *restrict option_len)
Get the socket options.
int nrf_close(int fildes)
Close a network socket.
int nrf_poll(struct nrf_pollfd fds[], nrf_nfds_t nfds, int timeout)
Poll multiple sockets for events.
ssize_t nrf_recvfrom(int socket, void *restrict buffer, size_t length, int flags, struct nrf_sockaddr *restrict address, nrf_socklen_t *restrict address_len)
Receive a message from a socket.
int nrf_accept(int socket, struct nrf_sockaddr *restrict address, nrf_socklen_t *restrict address_len)
Accept a new connection a socket.
int nrf_setsockopt(int socket, int level, int option_name, const void *option_value, nrf_socklen_t option_len)
Set the socket options.
int nrf_connect(int socket, const struct nrf_sockaddr *address, nrf_socklen_t address_len)
Connect a socket.
ssize_t nrf_recv(int socket, void *buffer, size_t length, int flags)
Receive a message from a connected socket.
int nrf_socket(int family, int type, int protocol)
Create a network socket.
ssize_t nrf_send(int socket, const void *buffer, size_t length, int flags)
Send a message on a connected socket.
int nrf_listen(int sock, int backlog)
Listen for socket connections and limit the queue of incoming connections.
int nrf_fcntl(int fd, int cmd, int flags)
Function for controlling file descriptor options.
ssize_t nrf_sendto(int socket, const void *message, size_t length, int flags, const struct nrf_sockaddr *dest_addr, nrf_socklen_t dest_len)
Send a message on a socket.
int nrf_bind(int socket, const struct nrf_sockaddr *address, nrf_socklen_t address_len)
Bind a name to a socket.
uint32_t nrf_sec_peer_verify_t
Peer verification level for the TLS connection.
Definition: nrf_socket.h:844
uint32_t nrf_sec_tag_t
Security tags used on the TLS socket.
Definition: nrf_socket.h:820
uint32_t nrf_sec_role_t
TLS role for the connection.
Definition: nrf_socket.h:810
uint32_t nrf_sec_cipher_t
An IANA cipher suite identifier.
Definition: nrf_socket.h:851
uint32_t nrf_sec_session_cache_t
Session cache configuration for the TLS connection.
Definition: nrf_socket.h:832
int32_t ssize_t
Definition: nrf_socket.h:45
struct nrf_sockaddr * ai_addr
Definition: nrf_socket.h:769
int ai_flags
Definition: nrf_socket.h:759
int ai_socktype
Definition: nrf_socket.h:763
int ai_family
Definition: nrf_socket.h:761
struct nrf_addrinfo * ai_next
Definition: nrf_socket.h:773
char * ai_canonname
Definition: nrf_socket.h:771
nrf_socklen_t ai_addrlen
Definition: nrf_socket.h:767
int ai_protocol
Definition: nrf_socket.h:765
Address information.
Definition: nrf_socket.h:757
struct nrf_sockaddr * ifa_addr
Definition: nrf_socket.h:785
char * ifa_name
Definition: nrf_socket.h:781
void * ifa_data
Definition: nrf_socket.h:793
struct nrf_sockaddr * ifa_netmask
Definition: nrf_socket.h:787
struct nrf_sockaddr * ifa_dstaddr
Definition: nrf_socket.h:791
struct nrf_sockaddr * ifa_broadaddr
Definition: nrf_socket.h:789
uint32_t ifa_flags
Definition: nrf_socket.h:783
struct nrf_ifaddrs * ifa_next
Definition: nrf_socket.h:779
Interface address information.
Definition: nrf_socket.h:777
uint8_t s6_addr[16]
Definition: nrf_socket.h:671
IPv6 address.
Definition: nrf_socket.h:670
nrf_in_addr_t s_addr
Definition: nrf_socket.h:683
IPv4 address structure.
Definition: nrf_socket.h:682
short events
Definition: nrf_socket.h:1015
bool oneshot
Definition: nrf_socket.h:1019
nrf_modem_pollcb_t callback
Definition: nrf_socket.h:1013
Definition: nrf_socket.h:1011
short revents
Definition: nrf_socket.h:993
short events
Definition: nrf_socket.h:991
int fd
Definition: nrf_socket.h:989
This structure is used to describe which events to poll for a given socket.
Definition: nrf_socket.h:987
uint8_t sin6_scope_id
Definition: nrf_socket.h:709
struct nrf_in6_addr sin6_addr
Definition: nrf_socket.h:707
nrf_sa_family_t sin6_family
Definition: nrf_socket.h:703
nrf_in_port_t sin6_port
Definition: nrf_socket.h:705
Address record for IPv6 addresses.
Definition: nrf_socket.h:701
nrf_sa_family_t sin_family
Definition: nrf_socket.h:719
struct nrf_in_addr sin_addr
Definition: nrf_socket.h:723
nrf_in_port_t sin_port
Definition: nrf_socket.h:721
Address record for IPv4 addresses.
Definition: nrf_socket.h:717
char sa_data[]
Definition: nrf_socket.h:738
nrf_sa_family_t sa_family
Definition: nrf_socket.h:736
Generic socket address.
Definition: nrf_socket.h:734
uint32_t tv_sec
Definition: nrf_socket.h:644
uint32_t tv_usec
Definition: nrf_socket.h:646
Structure specifying time interval.
Definition: nrf_socket.h:642