1 /* 2 * coap_tcp_internal.h -- TCP functions for libcoap 3 * 4 * Copyright (C) 2019--2023 Olaf Bergmann <bergmann@tzi.org> and others 5 * 6 * SPDX-License-Identifier: BSD-2-Clause 7 * 8 * This file is part of the CoAP library libcoap. Please see README for terms 9 * of use. 10 */ 11 12 /** 13 * @file coap_tcp_internal.h 14 * @brief CoAP TCP internal information 15 */ 16 17 #ifndef COAP_TCP_INTERNAL_H_ 18 #define COAP_TCP_INTERNAL_H_ 19 20 #include "coap_internal.h" 21 #include "coap_io.h" 22 23 /** 24 * @ingroup internal_api 25 * @defgroup tcp TCP Support 26 * Internal API for handling CoAP TCP (RFC8323) 27 * @{ 28 */ 29 30 #if !COAP_DISABLE_TCP 31 32 /** 33 * Create a new TCP socket and initiate the connection 34 * 35 * Internal function. 36 * 37 * @param sock Where socket information is to be filled in 38 * @param local_if The local address to use or NULL 39 * @param server The address to connect to 40 * @param default_port The port to use if not set in @p server 41 * @param local_addr Filled in after connection initiation with 42 * the local address 43 * @param remote_addr Filled in after connection initiation with 44 * the remote address 45 * 46 * @return @c 1 if succesful, @c 0 if failure of some sort 47 */ 48 int coap_socket_connect_tcp1(coap_socket_t *sock, 49 const coap_address_t *local_if, 50 const coap_address_t *server, 51 int default_port, 52 coap_address_t *local_addr, 53 coap_address_t *remote_addr); 54 55 /** 56 * Complete the TCP Connection 57 * 58 * Internal function. 59 * 60 * @param sock The socket information to use 61 * @param local_addr Filled in with the final local address 62 * @param remote_addr Filled in with the final remote address 63 * 64 * @return @c 1 if succesful, @c 0 if failure of some sort 65 */ 66 int coap_socket_connect_tcp2(coap_socket_t *sock, 67 coap_address_t *local_addr, 68 coap_address_t *remote_addr); 69 70 /** 71 * Create a new TCP socket and then listen for new incoming TCP sessions 72 * 73 * Internal function. 74 * 75 * @param sock Where socket information is to be filled in 76 * @param listen_addr The address to be listening for new incoming sessions 77 * @param bound_addr Filled in with the address that the TCP layer 78 * is listening on for new incoming TCP sessions 79 * 80 * @return @c 1 if succesful, @c 0 if failure of some sort 81 */ 82 int coap_socket_bind_tcp(coap_socket_t *sock, 83 const coap_address_t *listen_addr, 84 coap_address_t *bound_addr); 85 86 /** 87 * Accept a new incoming TCP session 88 * 89 * Internal function. 90 * 91 * @param server The socket information to use to accept the TCP connection 92 * @param new_client Filled in socket information with the new incoming 93 * session information 94 * @param local_addr Filled in with the local address 95 * @param remote_addr Filled in with the remote address 96 * 97 * @return @c 1 if succesful, @c 0 if failure of some sort 98 */ 99 int coap_socket_accept_tcp(coap_socket_t *server, 100 coap_socket_t *new_client, 101 coap_address_t *local_addr, 102 coap_address_t *remote_addr); 103 104 #endif /* !COAP_DISABLE_TCP */ 105 106 /** @} */ 107 108 #endif /* COAP_TCP_INTERNAL_H_ */ 109