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