1c87c5fbaSopenharmony_ci/*
2c87c5fbaSopenharmony_ci * coap_netif_internal.h -- Netif Transport Layer Support for libcoap
3c87c5fbaSopenharmony_ci *
4c87c5fbaSopenharmony_ci * Copyright (C) 2023 Jon Shallow <supjps-libcoap@jpshallow.com>
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_netif_internal.h
14c87c5fbaSopenharmony_ci * @brief Internal CoAP Netif support
15c87c5fbaSopenharmony_ci */
16c87c5fbaSopenharmony_ci
17c87c5fbaSopenharmony_ci#ifndef COAP_NETIF_INTERNAL_H_
18c87c5fbaSopenharmony_ci#define COAP_NETIF_INTERNAL_H_
19c87c5fbaSopenharmony_ci
20c87c5fbaSopenharmony_ci#include "coap_internal.h"
21c87c5fbaSopenharmony_ci
22c87c5fbaSopenharmony_ci/**
23c87c5fbaSopenharmony_ci * @ingroup internal_api
24c87c5fbaSopenharmony_ci * @defgroup netif_internal Netif Support
25c87c5fbaSopenharmony_ci * Internal API for Netif Support.
26c87c5fbaSopenharmony_ci * This provides a layer that sits between CoAP/DTLS and Sockets.
27c87c5fbaSopenharmony_ci * @{
28c87c5fbaSopenharmony_ci */
29c87c5fbaSopenharmony_ci
30c87c5fbaSopenharmony_ci/**
31c87c5fbaSopenharmony_ci * Function interface to check whether netif for session is still available.
32c87c5fbaSopenharmony_ci *
33c87c5fbaSopenharmony_ci *  @param session          Session to check against.
34c87c5fbaSopenharmony_ci *
35c87c5fbaSopenharmony_ci * @return 1                If netif is available, else 0.
36c87c5fbaSopenharmony_ci */
37c87c5fbaSopenharmony_ciint coap_netif_available(coap_session_t *session);
38c87c5fbaSopenharmony_ci
39c87c5fbaSopenharmony_ci/**
40c87c5fbaSopenharmony_ci * Function interface to check whether netif for endpoint is still available.
41c87c5fbaSopenharmony_ci *
42c87c5fbaSopenharmony_ci *  @param endpoint         Endpoint to check against.
43c87c5fbaSopenharmony_ci *
44c87c5fbaSopenharmony_ci * @return 1                If netif is available, else 0.
45c87c5fbaSopenharmony_ci */
46c87c5fbaSopenharmony_ciint coap_netif_available_ep(coap_endpoint_t *endpoint);
47c87c5fbaSopenharmony_ci
48c87c5fbaSopenharmony_ci/**
49c87c5fbaSopenharmony_ci * Layer function interface for Netif datagram listem (udp).
50c87c5fbaSopenharmony_ci *
51c87c5fbaSopenharmony_ci * @param endpoint  Endpoint to do the listen on.
52c87c5fbaSopenharmony_ci * @param listen_addr The local address to bind.
53c87c5fbaSopenharmony_ci *
54c87c5fbaSopenharmony_ci * @return                 @c 1 OK, 0 on failure.
55c87c5fbaSopenharmony_ci */
56c87c5fbaSopenharmony_ciint coap_netif_dgrm_listen(coap_endpoint_t *endpoint,
57c87c5fbaSopenharmony_ci                           const coap_address_t *listen_addr);
58c87c5fbaSopenharmony_ci
59c87c5fbaSopenharmony_ci/**
60c87c5fbaSopenharmony_ci * Layer function interface for Netif datagram connect (udp).
61c87c5fbaSopenharmony_ci *
62c87c5fbaSopenharmony_ci * @param session  Session to do the connect on.
63c87c5fbaSopenharmony_ci * @param local_if The local interface to bind to or NULL.
64c87c5fbaSopenharmony_ci * @param server   The server to connect to.
65c87c5fbaSopenharmony_ci * @param default_port The Port to connect to if not defined.
66c87c5fbaSopenharmony_ci *
67c87c5fbaSopenharmony_ci * @return                 @c 1 OK, 0 on failure.
68c87c5fbaSopenharmony_ci */
69c87c5fbaSopenharmony_ciint coap_netif_dgrm_connect(coap_session_t *session,
70c87c5fbaSopenharmony_ci                            const coap_address_t *local_if,
71c87c5fbaSopenharmony_ci                            const coap_address_t *server, int default_port);
72c87c5fbaSopenharmony_ci
73c87c5fbaSopenharmony_ci/**
74c87c5fbaSopenharmony_ci * Function interface for layer data datagram receiving for sessions. This
75c87c5fbaSopenharmony_ci * function returns the number of bytes that have been read, or -1 on error.
76c87c5fbaSopenharmony_ci *
77c87c5fbaSopenharmony_ci * @param session  Session to receive data on.
78c87c5fbaSopenharmony_ci * @param packet   Where to put the received information
79c87c5fbaSopenharmony_ci *
80c87c5fbaSopenharmony_ci * @return                 >=0 Number of bytes read.
81c87c5fbaSopenharmony_ci *                          -1 Error of some sort (see errno).
82c87c5fbaSopenharmony_ci *                          -2 ICMP error response
83c87c5fbaSopenharmony_ci */
84c87c5fbaSopenharmony_cissize_t coap_netif_dgrm_read(coap_session_t *session, coap_packet_t *packet);
85c87c5fbaSopenharmony_ci
86c87c5fbaSopenharmony_ci/**
87c87c5fbaSopenharmony_ci * Function interface for layer data datagram receiving for endpoints. This
88c87c5fbaSopenharmony_ci * function returns the number of bytes that have been read, or -1 on error.
89c87c5fbaSopenharmony_ci *
90c87c5fbaSopenharmony_ci * @param endpoint Endpoint to receive data on.
91c87c5fbaSopenharmony_ci * @param packet   Where to put the received information
92c87c5fbaSopenharmony_ci *
93c87c5fbaSopenharmony_ci * @return                 >=0 Number of bytes read.
94c87c5fbaSopenharmony_ci *                          -1 Error of some sort (see errno).
95c87c5fbaSopenharmony_ci *                          -2 ICMP error response
96c87c5fbaSopenharmony_ci */
97c87c5fbaSopenharmony_cissize_t coap_netif_dgrm_read_ep(coap_endpoint_t *endpoint,
98c87c5fbaSopenharmony_ci                                coap_packet_t *packet);
99c87c5fbaSopenharmony_ci
100c87c5fbaSopenharmony_ci/**
101c87c5fbaSopenharmony_ci * Function interface for netif datagram data transmission. This function
102c87c5fbaSopenharmony_ci * returns the number of bytes that have been transmitted, or a value less
103c87c5fbaSopenharmony_ci * than zero on error.
104c87c5fbaSopenharmony_ci *
105c87c5fbaSopenharmony_ci * @param session          Session to send data on.
106c87c5fbaSopenharmony_ci * @param data             The data to send.
107c87c5fbaSopenharmony_ci * @param datalen          The actual length of @p data.
108c87c5fbaSopenharmony_ci *
109c87c5fbaSopenharmony_ci * @return                 The number of bytes written on success, or a value
110c87c5fbaSopenharmony_ci *                         less than zero on error.
111c87c5fbaSopenharmony_ci */
112c87c5fbaSopenharmony_cissize_t coap_netif_dgrm_write(coap_session_t *session, const uint8_t *data,
113c87c5fbaSopenharmony_ci                              size_t datalen);
114c87c5fbaSopenharmony_ci
115c87c5fbaSopenharmony_ci/**
116c87c5fbaSopenharmony_ci * Layer function interface for Netif stream listem (tcp).
117c87c5fbaSopenharmony_ci *
118c87c5fbaSopenharmony_ci * @param endpoint  Endpoint to do the listen on.
119c87c5fbaSopenharmony_ci * @param listen_addr The local address to bind.
120c87c5fbaSopenharmony_ci *
121c87c5fbaSopenharmony_ci * @return                 @c 1 OK, 0 on failure.
122c87c5fbaSopenharmony_ci */
123c87c5fbaSopenharmony_ciint coap_netif_strm_listen(coap_endpoint_t *endpoint,
124c87c5fbaSopenharmony_ci                           const coap_address_t *listen_addr);
125c87c5fbaSopenharmony_ci
126c87c5fbaSopenharmony_ci/**
127c87c5fbaSopenharmony_ci * Layer function interface for Netif stream accept.
128c87c5fbaSopenharmony_ci *
129c87c5fbaSopenharmony_ci * @param endpoint Endpoint to to do the accept on.
130c87c5fbaSopenharmony_ci * @param session  Session to to do the accept update on.
131c87c5fbaSopenharmony_ci *
132c87c5fbaSopenharmony_ci * @return                 @c 1 OK, 0 on failure.
133c87c5fbaSopenharmony_ci */
134c87c5fbaSopenharmony_ciint coap_netif_strm_accept(coap_endpoint_t *endpoint, coap_session_t *session);
135c87c5fbaSopenharmony_ci
136c87c5fbaSopenharmony_ci/**
137c87c5fbaSopenharmony_ci * Layer function interface for Netif stream connect (tcp).
138c87c5fbaSopenharmony_ci * Step 1 - initiate the connection.
139c87c5fbaSopenharmony_ci *
140c87c5fbaSopenharmony_ci * @param session  Session to do the connect on.
141c87c5fbaSopenharmony_ci * @param local_if The local interface to bind to or NULL.
142c87c5fbaSopenharmony_ci * @param server   The server to connect to.
143c87c5fbaSopenharmony_ci * @param default_port The Port to connect to if not defined.
144c87c5fbaSopenharmony_ci *
145c87c5fbaSopenharmony_ci * @return                 @c 1 OK, 0 on failure.
146c87c5fbaSopenharmony_ci */
147c87c5fbaSopenharmony_ciint coap_netif_strm_connect1(coap_session_t *session,
148c87c5fbaSopenharmony_ci                             const coap_address_t *local_if,
149c87c5fbaSopenharmony_ci                             const coap_address_t *server, int default_port);
150c87c5fbaSopenharmony_ci
151c87c5fbaSopenharmony_ci/**
152c87c5fbaSopenharmony_ci * Layer function interface for Netif stream connect (tcp).
153c87c5fbaSopenharmony_ci * Step 2 - complete the connection.
154c87c5fbaSopenharmony_ci *
155c87c5fbaSopenharmony_ci * @param session  Session to do the connect complete on.
156c87c5fbaSopenharmony_ci *
157c87c5fbaSopenharmony_ci * @return                 @c 1 OK, 0 on failure.
158c87c5fbaSopenharmony_ci */
159c87c5fbaSopenharmony_ciint coap_netif_strm_connect2(coap_session_t *session);
160c87c5fbaSopenharmony_ci
161c87c5fbaSopenharmony_ci/**
162c87c5fbaSopenharmony_ci * Function interface for layer data stream receiving. This function returns
163c87c5fbaSopenharmony_ci * the number of bytes that have been read, or -1 on error.
164c87c5fbaSopenharmony_ci *
165c87c5fbaSopenharmony_ci * @param session          Session to receive data on.
166c87c5fbaSopenharmony_ci * @param data             The data to receive.
167c87c5fbaSopenharmony_ci * @param datalen          The maximum length of @p data.
168c87c5fbaSopenharmony_ci *
169c87c5fbaSopenharmony_ci * @return                 >=0 Number of bytes read.
170c87c5fbaSopenharmony_ci *                         -1  Error of some sort (see errno).
171c87c5fbaSopenharmony_ci */
172c87c5fbaSopenharmony_cissize_t coap_netif_strm_read(coap_session_t *session, uint8_t *data,
173c87c5fbaSopenharmony_ci                             size_t datalen);
174c87c5fbaSopenharmony_ci
175c87c5fbaSopenharmony_ci/**
176c87c5fbaSopenharmony_ci * Function interface for netif stream data transmission. This function returns
177c87c5fbaSopenharmony_ci * the number of bytes that have been transmitted, or a value less than zero
178c87c5fbaSopenharmony_ci * on error. The number of bytes written may be less than datalen because of
179c87c5fbaSopenharmony_ci * congestion control.
180c87c5fbaSopenharmony_ci *
181c87c5fbaSopenharmony_ci * @param session          Session to send data on.
182c87c5fbaSopenharmony_ci * @param data             The data to send.
183c87c5fbaSopenharmony_ci * @param datalen          The actual length of @p data.
184c87c5fbaSopenharmony_ci *
185c87c5fbaSopenharmony_ci * @return                 The number of bytes written on success, or a value
186c87c5fbaSopenharmony_ci *                         less than zero on error.
187c87c5fbaSopenharmony_ci */
188c87c5fbaSopenharmony_cissize_t coap_netif_strm_write(coap_session_t *session,
189c87c5fbaSopenharmony_ci                              const uint8_t *data, size_t datalen);
190c87c5fbaSopenharmony_ci
191c87c5fbaSopenharmony_ci/**
192c87c5fbaSopenharmony_ci * Layer function interface for Netif close for a session.
193c87c5fbaSopenharmony_ci *
194c87c5fbaSopenharmony_ci * @param session  Session to do the netif close on.
195c87c5fbaSopenharmony_ci */
196c87c5fbaSopenharmony_civoid coap_netif_close(coap_session_t *session);
197c87c5fbaSopenharmony_ci
198c87c5fbaSopenharmony_ci/**
199c87c5fbaSopenharmony_ci * Layer function interface for Netif close for a endpoint.
200c87c5fbaSopenharmony_ci *
201c87c5fbaSopenharmony_ci * @param endpoint  Endpoint to do the netif close on.
202c87c5fbaSopenharmony_ci */
203c87c5fbaSopenharmony_civoid coap_netif_close_ep(coap_endpoint_t *endpoint);
204c87c5fbaSopenharmony_ci
205c87c5fbaSopenharmony_ci/** @} */
206c87c5fbaSopenharmony_ci
207c87c5fbaSopenharmony_ci#endif /* COAP_NETIF_INTERNAL_H */
208